From ecd7d0fc353ddfee440e8e75d4efe127f0853a9d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 27 Apr 2023 15:55:46 +1000 Subject: [PATCH] GS/HW: Fix pipeline/shader duplication --- pcsx2/GS/Renderers/Common/GSDevice.h | 2 ++ pcsx2/GS/Renderers/DX12/GSDevice12.h | 9 +++++---- pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp | 2 +- pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h | 6 +++--- pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h | 9 +++++---- pcsx2/ShaderCacheVersion.h | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pcsx2/GS/Renderers/Common/GSDevice.h b/pcsx2/GS/Renderers/Common/GSDevice.h index 8bacadb0e8..4b20087aa8 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.h +++ b/pcsx2/GS/Renderers/Common/GSDevice.h @@ -264,6 +264,7 @@ struct alignas(16) GSHWDrawConfig /// Returns true if the fixed index buffer should be used. __fi bool UseExpandIndexBuffer() const { return (expand == VSExpand::Point || expand == VSExpand::Sprite); } }; + static_assert(sizeof(VSSelector) == 1, "VSSelector is a single byte"); #pragma pack(pop) #pragma pack(push, 4) struct PSSelector @@ -382,6 +383,7 @@ struct alignas(16) GSHWDrawConfig no_color = no_color1 = 1; } }; + static_assert(sizeof(PSSelector) == 12, "PSSelector is 12 bytes"); #pragma pack(pop) struct PSSelectorHash { diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.h b/pcsx2/GS/Renderers/DX12/GSDevice12.h index 9711b44140..6169dcffeb 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.h +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.h @@ -51,15 +51,16 @@ public: u32 key; }; + GSHWDrawConfig::BlendState bs; GSHWDrawConfig::VSSelector vs; GSHWDrawConfig::DepthStencilSelector dss; GSHWDrawConfig::ColorMaskSelector cms; - GSHWDrawConfig::BlendState bs; + u8 pad; - __fi bool operator==(const PipelineSelector& p) const { return (memcmp(this, &p, sizeof(p)) == 0); } - __fi bool operator!=(const PipelineSelector& p) const { return (memcmp(this, &p, sizeof(p)) != 0); } + __fi bool operator==(const PipelineSelector& p) const { return BitEqual(*this, p); } + __fi bool operator!=(const PipelineSelector& p) const { return !BitEqual(*this, p); } - __fi PipelineSelector() { memset(this, 0, sizeof(*this)); } + __fi PipelineSelector() { std::memset(this, 0, sizeof(*this)); } }; static_assert(sizeof(PipelineSelector) == 24, "Pipeline selector is 24 bytes"); diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp index e40d28392d..66d72b80ad 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp @@ -2393,7 +2393,7 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config) psel.vs = config.vs; psel.ps.key_hi = config.ps.key_hi; psel.ps.key_lo = config.ps.key_lo; - psel.pad = 0; + std::memset(psel.pad, 0, sizeof(psel.pad)); SetupPipeline(psel); diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h index f161f7e3b7..d7a92c1242 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h @@ -130,10 +130,10 @@ public: { PSSelector ps; VSSelector vs; - u16 pad; + u8 pad[3]; - __fi bool operator==(const ProgramSelector& p) const { return (std::memcmp(this, &p, sizeof(*this)) == 0); } - __fi bool operator!=(const ProgramSelector& p) const { return (std::memcmp(this, &p, sizeof(*this)) != 0); } + __fi bool operator==(const ProgramSelector& p) const { return BitEqual(*this, p); } + __fi bool operator!=(const ProgramSelector& p) const { return !BitEqual(*this, p); } }; static_assert(sizeof(ProgramSelector) == 16, "Program selector is 16 bytes"); diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h index 69403253a7..690db5cc4f 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h @@ -57,15 +57,16 @@ public: u32 key; }; + GSHWDrawConfig::BlendState bs; GSHWDrawConfig::VSSelector vs; GSHWDrawConfig::DepthStencilSelector dss; GSHWDrawConfig::ColorMaskSelector cms; - GSHWDrawConfig::BlendState bs; + u8 pad; - __fi bool operator==(const PipelineSelector& p) const { return (memcmp(this, &p, sizeof(p)) == 0); } - __fi bool operator!=(const PipelineSelector& p) const { return (memcmp(this, &p, sizeof(p)) != 0); } + __fi bool operator==(const PipelineSelector& p) const { return BitEqual(*this, p); } + __fi bool operator!=(const PipelineSelector& p) const { return !BitEqual(*this, p); } - __fi PipelineSelector() { memset(this, 0, sizeof(*this)); } + __fi PipelineSelector() { std::memset(this, 0, sizeof(*this)); } __fi bool IsRTFeedbackLoop() const { return ((feedback_loop_flags & FeedbackLoopFlag_ReadAndWriteRT) != 0); } __fi bool IsTestingAndSamplingDepth() const { return ((feedback_loop_flags & FeedbackLoopFlag_ReadDS) != 0); } diff --git a/pcsx2/ShaderCacheVersion.h b/pcsx2/ShaderCacheVersion.h index 7ad59e8e89..1ee0e7eac4 100644 --- a/pcsx2/ShaderCacheVersion.h +++ b/pcsx2/ShaderCacheVersion.h @@ -15,4 +15,4 @@ /// Version number for GS and other shaders. Increment whenever any of the contents of the /// shaders change, to invalidate the cache. -static constexpr u32 SHADER_CACHE_VERSION = 24; +static constexpr u32 SHADER_CACHE_VERSION = 25;