diff --git a/Utilities/GSL.h b/Utilities/GSL.h new file mode 100644 index 0000000000..aa74c93610 --- /dev/null +++ b/Utilities/GSL.h @@ -0,0 +1,14 @@ +#pragma once + +#define GSL_THROW_ON_CONTRACT_VIOLATION + +#pragma push_macro("new") +#pragma push_macro("Expects") +#pragma push_macro("Ensures") +#undef new +#undef Expects +#undef Ensures +#include +#pragma pop_macro("Ensures") +#pragma pop_macro("Expects") +#pragma pop_macro("new") diff --git a/Utilities/types.h b/Utilities/types.h index dd2f76e0a3..78facc95b7 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -28,6 +28,11 @@ using s16 = std::int16_t; using s32 = std::int32_t; using s64 = std::int64_t; +namespace gsl +{ + enum class byte : std::uint8_t; +} + // Specialization with static constexpr pair map[] member expected template struct bijective; diff --git a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp index 027dbf670c..30c13c6242 100644 --- a/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp @@ -991,7 +991,7 @@ void spursSysServiceProcessRequests(SPUThread& spu, SpursKernelContext* ctxt) bool updateWorkload = false; bool terminate = false; - vm::reservation_op(vm::cast(ctxt->spurs.addr() + offsetof(CellSpurs, wklState1), HERE), 128, [&]() + vm::reservation_op(vm::cast(ctxt->spurs.addr() + OFFSET_32(CellSpurs, wklState1), HERE), 128, [&]() { auto spurs = ctxt->spurs.get_ptr_priv(); diff --git a/rpcs3/Emu/Cell/Modules/cellSysmodule.cpp b/rpcs3/Emu/Cell/Modules/cellSysmodule.cpp index c8ffe495d0..b4718e11dc 100644 --- a/rpcs3/Emu/Cell/Modules/cellSysmodule.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSysmodule.cpp @@ -129,7 +129,7 @@ static const char* get_module_name(u16 id) static const char* get_module_id(u16 id) { - thread_local static char tls_id_name[8]; // for test + static thread_local char tls_id_name[8]; // for test switch (id) { diff --git a/rpcs3/Emu/Cell/Modules/cellSysutil.cpp b/rpcs3/Emu/Cell/Modules/cellSysutil.cpp index ecf5c77899..d5a9f94c12 100644 --- a/rpcs3/Emu/Cell/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSysutil.cpp @@ -53,7 +53,7 @@ cfg::map_entry g_cfg_sys_language(cfg::root.sys, "Language", static const char* get_systemparam_id_name(s32 id) { - thread_local static char tls_id_name[16]; // for test + static thread_local char tls_id_name[16]; // for test switch (id) { diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.h b/rpcs3/Emu/RSX/Common/BufferUtils.h index 2ba850af51..db825d0827 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.h +++ b/rpcs3/Emu/RSX/Common/BufferUtils.h @@ -1,5 +1,8 @@ #pragma once + #include + +#include "Utilities/GSL.h" #include "Emu/Memory/vm.h" #include "../RSXThread.h" diff --git a/rpcs3/Emu/RSX/Common/ProgramStateCache.h b/rpcs3/Emu/RSX/Common/ProgramStateCache.h index 3aae330991..604a4ecf54 100644 --- a/rpcs3/Emu/RSX/Common/ProgramStateCache.h +++ b/rpcs3/Emu/RSX/Common/ProgramStateCache.h @@ -4,6 +4,7 @@ #include "Emu/RSX/RSXVertexProgram.h" #include "Emu/Memory/vm.h" +#include "Utilities/GSL.h" enum class SHADER_TYPE { @@ -15,6 +16,7 @@ namespace program_hash_util { // Based on // https://github.com/AlexAltea/nucleus/blob/master/nucleus/gpu/rsx_pgraph.cpp + // TODO: eliminate it and implement independent hash utility union qword { u64 dword[2]; diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.h b/rpcs3/Emu/RSX/Common/TextureUtils.h index a59cfb2523..c88a6a558a 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.h +++ b/rpcs3/Emu/RSX/Common/TextureUtils.h @@ -1,6 +1,9 @@ #pragma once + #include "../RSXTexture.h" + #include +#include "Utilities/GSL.h" struct rsx_subresource_layout { diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index 41b440af38..4fd86dd9da 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "Utilities/GSL.h" #include "../GCM.h" #include diff --git a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp index a77e9fe28e..4590e7715d 100644 --- a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp @@ -306,7 +306,7 @@ void GLFragmentProgram::Compile() id = glCreateShader(GL_FRAGMENT_SHADER); const char* str = shader.c_str(); - const int strlen = gsl::narrow(shader.length()); + const int strlen = ::narrow(shader.length()); glShaderSource(id, 1, &str, &strlen); glCompileShader(id); diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp index 698aba27f1..36d7b638b9 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp @@ -261,7 +261,7 @@ void GLVertexProgram::Compile() id = glCreateShader(GL_VERTEX_SHADER); const char* str = shader.c_str(); - const int strlen = gsl::narrow(shader.length()); + const int strlen = ::narrow(shader.length()); glShaderSource(id, 1, &str, &strlen); glCompileShader(id); diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 6878d06b60..492f405459 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -9,6 +9,8 @@ #include "Common/BufferUtils.h" #include "rsx_methods.h" +#include "Utilities/GSL.h" + #define CMD_DEBUG 0 cfg::bool_entry g_cfg_rsx_write_color_buffers(cfg::root.video, "Write Color Buffers"); diff --git a/rpcs3/Emu/RSX/rsx_utils.h b/rpcs3/Emu/RSX/rsx_utils.h index 16328fb7a4..b45301d679 100644 --- a/rpcs3/Emu/RSX/rsx_utils.h +++ b/rpcs3/Emu/RSX/rsx_utils.h @@ -32,8 +32,8 @@ namespace rsx template void convert_linear_swizzle(void* input_pixels, void* output_pixels, u16 width, u16 height, bool input_is_swizzled) { - u16 log2width = gsl::narrow(ceil(log2(width))); - u16 log2height = gsl::narrow(ceil(log2(height))); + u16 log2width = ::narrow(ceil(log2(width))); + u16 log2height = ::narrow(ceil(log2(height))); // Max mask possible for square texture u32 x_mask = 0x55555555; diff --git a/rpcs3/GLGSRender.vcxproj b/rpcs3/GLGSRender.vcxproj index d74d690645..cd1d79c870 100644 --- a/rpcs3/GLGSRender.vcxproj +++ b/rpcs3/GLGSRender.vcxproj @@ -61,11 +61,6 @@ - - - true - - {c4a10229-4712-4bd2-b63e-50d93c67a038} diff --git a/rpcs3/Gui/RSXDebugger.cpp b/rpcs3/Gui/RSXDebugger.cpp index 09288e167f..a615edd205 100644 --- a/rpcs3/Gui/RSXDebugger.cpp +++ b/rpcs3/Gui/RSXDebugger.cpp @@ -11,6 +11,8 @@ #include "MemoryViewer.h" #include "RSXDebugger.h" +#include "Utilities/GSL.h" + enum GCMEnumTypes { CELL_GCM_ENUM, diff --git a/rpcs3/Loader/PSF.cpp b/rpcs3/Loader/PSF.cpp index 7292b2079f..8f23aef7f7 100644 --- a/rpcs3/Loader/PSF.cpp +++ b/rpcs3/Loader/PSF.cpp @@ -55,7 +55,7 @@ namespace psf { case format::string: case format::array: - return std::min(m_max_size, gsl::narrow(m_value_string.size() + (m_type == format::string))); + return std::min(m_max_size, ::narrow(m_value_string.size() + (m_type == format::string))); case format::integer: return SIZE_32(u32); @@ -157,14 +157,14 @@ namespace psf for (const auto& entry : psf) { def_table_t index; - index.key_off = gsl::narrow(key_offset); + index.key_off = ::narrow(key_offset); index.param_fmt = entry.second.type(); index.param_len = entry.second.size(); index.param_max = entry.second.max(); - index.data_off = gsl::narrow(data_offset); + index.data_off = ::narrow(data_offset); // Update offsets: - key_offset += gsl::narrow(entry.first.size() + 1); // key size + key_offset += ::narrow(entry.first.size() + 1); // key size data_offset += index.param_max; indices.push_back(index); @@ -177,9 +177,9 @@ namespace psf header_t header; header.magic = "\0PSF"_u32; header.version = 0x101; - header.off_key_table = gsl::narrow(sizeof(header_t) + sizeof(def_table_t) * psf.size()); - header.off_data_table = gsl::narrow(header.off_key_table + key_offset); - header.entries_num = gsl::narrow(psf.size()); + header.off_key_table = ::narrow(sizeof(header_t) + sizeof(def_table_t) * psf.size()); + header.off_data_table = ::narrow(header.off_key_table + key_offset); + header.entries_num = ::narrow(psf.size()); // Save header and indices std::vector result; result.reserve(header.off_data_table + data_offset); diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 0984a75514..7101a3d7d2 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -353,6 +353,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 78b9808d91..c85fb0186e 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1588,5 +1588,8 @@ Emu + + Utilities + \ No newline at end of file diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 726d8025de..0ab9cd9215 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -39,16 +39,6 @@ #include #include -#include "Utilities/types.h" - -#include -#define GSL_THROW_ON_CONTRACT_VIOLATION -#include -#include - -#undef Expects -#undef Ensures - using namespace std::string_literals; using namespace std::chrono_literals; @@ -58,6 +48,7 @@ using namespace std::chrono_literals; #define _PRGNAME_ "RPCS3" #define _PRGVER_ "0.0.0.9" +#include "Utilities/types.h" #include "Utilities/Macro.h" #include "Utilities/Platform.h" #include "Utilities/BEType.h"