From 412480b3262811a59fcee5b1997542c123761ace Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Wed, 31 Aug 2022 22:56:34 -0500 Subject: [PATCH] GS: Don't add 10 to date flag to indicate initialization We already have 1 and 2 dedicated to the job --- bin/resources/shaders/dx11/tfx.fx | 8 ++++---- bin/resources/shaders/vulkan/tfx.glsl | 19 +++++-------------- pcsx2/GS/Renderers/Common/GSDevice.h | 2 +- pcsx2/GS/Renderers/DX12/GSDevice12.cpp | 9 +++++---- pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp | 6 +++--- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index 6686e3270a..f54de2cd1f 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -102,7 +102,7 @@ struct PS_INPUT #else nointerpolation float4 c : COLOR0; #endif -#if PS_DATE > 10 || PS_DATE == 3 +#if PS_DATE >= 1 && PS_DATE <= 3 uint primid : SV_PrimitiveID; #endif }; @@ -110,7 +110,7 @@ struct PS_INPUT struct PS_OUTPUT { #if !PS_NO_COLOR -#if PS_DATE > 10 +#if PS_DATE == 1 || PS_DATE == 2 float c : SV_Target; #else float4 c0 : SV_Target0; @@ -918,12 +918,12 @@ PS_OUTPUT ps_main(PS_INPUT input) #endif // Get first primitive that will write a failling alpha value -#if PS_DATE == 11 +#if PS_DATE == 1 // DATM == 0 // Pixel with alpha equal to 1 will failed (128-255) output.c = (C.a > 127.5f) ? float(input.primid) : float(0x7FFFFFFF); -#elif PS_DATE == 12 +#elif PS_DATE == 2 // DATM == 1 // Pixel with alpha equal to 0 will failed (0-127) diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl index fa426e59d8..463e8f41dc 100644 --- a/bin/resources/shaders/vulkan/tfx.glsl +++ b/bin/resources/shaders/vulkan/tfx.glsl @@ -348,7 +348,7 @@ void main() #define SW_BLEND (PS_BLEND_A || PS_BLEND_B || PS_BLEND_D) #define SW_BLEND_NEEDS_RT (PS_BLEND_A == 1 || PS_BLEND_B == 1 || PS_BLEND_C == 1 || PS_BLEND_D == 1) -#define PS_FEEDBACK_LOOP_IS_NEEDED (PS_TEX_IS_FB == 1 || PS_FBMASK || SW_BLEND_NEEDS_RT || (PS_DATE < 10 && (((PS_DATE & 3) == 1 || (PS_DATE & 3) == 2)))) +#define PS_FEEDBACK_LOOP_IS_NEEDED (PS_TEX_IS_FB == 1 || PS_FBMASK || SW_BLEND_NEEDS_RT || (PS_DATE >= 5)) layout(std140, set = 0, binding = 1) uniform cb1 { @@ -1110,10 +1110,6 @@ void ps_blend(inout vec4 Color, inout float As) #endif } -#if PS_DATE == 1 || PS_DATE == 2 || PS_DATE == 11 || PS_DATE == 12 -layout(early_fragment_tests) in; -#endif - void main() { #if PS_SCANMSK & 2 @@ -1121,7 +1117,7 @@ void main() if ((int(gl_FragCoord.y) & 1) == (PS_SCANMSK & 1)) discard; #endif -#if PS_DATE < 10 && (((PS_DATE & 3) == 1 || (PS_DATE & 3) == 2)) +#if PS_DATE >= 5 #if PS_WRITE_RG == 1 // Pseudo 16 bits access. @@ -1139,15 +1135,10 @@ void main() #endif if (bad) { -#if PS_DATE >= 5 discard; -#else - // imageStore(img_prim_min, ivec2(gl_FragCoord.xy), ivec4(-1)); - return; -#endif } -#endif // PS_DATE < 10 && (((PS_DATE & 3) == 1 || (PS_DATE & 3) == 2)) +#endif // PS_DATE >= 5 #if PS_DATE == 3 int stencil_ceil = int(texelFetch(PrimMinTexture, ivec2(gl_FragCoord.xy), 0).r); @@ -1208,13 +1199,13 @@ void main() #endif // Get first primitive that will write a failling alpha value -#if PS_DATE == 1 || PS_DATE == 11 +#if PS_DATE == 1 // DATM == 0 // Pixel with alpha equal to 1 will failed (128-255) o_col0 = (C.a > 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF); -#elif PS_DATE == 2 || PS_DATE == 12 +#elif PS_DATE == 2 // DATM == 1 // Pixel with alpha equal to 0 will failed (0-127) diff --git a/pcsx2/GS/Renderers/Common/GSDevice.h b/pcsx2/GS/Renderers/Common/GSDevice.h index 2b4fbda422..a9e6d0f9af 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.h +++ b/pcsx2/GS/Renderers/Common/GSDevice.h @@ -312,7 +312,7 @@ struct alignas(16) GSHWDrawConfig // Flat/goround shading u32 iip : 1; // Pixel test - u32 date : 4; + u32 date : 3; u32 atst : 3; // Color sampling u32 fst : 1; // Investigate to do it on the VS diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index a95573cfa3..5f19ea28d4 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -33,6 +33,7 @@ #include static bool IsDATMConvertShader(ShaderConvert i) { return (i == ShaderConvert::DATM_0 || i == ShaderConvert::DATM_1); } +static bool IsDATEModePrimIDInit(u32 flag) { return flag == 1 || flag == 2; } static D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE GetLoadOpForTexture(GSTexture12* tex) { @@ -1601,8 +1602,9 @@ GSDevice12::ComPtr GSDevice12::CreateTFXPipeline(const Pipe if (p.rt) { gpb.SetRenderTarget(0, - (p.ps.date >= 10) ? DXGI_FORMAT_R32_FLOAT : - (p.ps.hdr ? DXGI_FORMAT_R32G32B32A32_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM)); + IsDATEModePrimIDInit(p.ps.date) ? DXGI_FORMAT_R32_FLOAT : + p.ps.hdr ? DXGI_FORMAT_R32G32B32A32_FLOAT : + DXGI_FORMAT_R8G8B8A8_UNORM); } if (p.ds) gpb.SetDepthStencilFormat(DXGI_FORMAT_D32_FLOAT_S8X24_UINT); @@ -1642,7 +1644,7 @@ GSDevice12::ComPtr GSDevice12::CreateTFXPipeline(const Pipe } // Blending - if (p.ps.date >= 10) + if (IsDATEModePrimIDInit(p.ps.date)) { // image DATE prepass gpb.SetBlendState(0, true, D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_MIN, D3D12_BLEND_ONE, @@ -2406,7 +2408,6 @@ GSTexture12* GSDevice12::SetupPrimitiveTrackingDATE(GSHWDrawConfig& config, Pipe init_pipe.bs = {}; init_pipe.rt = true; init_pipe.ps.blend_a = init_pipe.ps.blend_b = init_pipe.ps.blend_c = init_pipe.ps.blend_d = false; - init_pipe.ps.date += 10; init_pipe.ps.no_color = false; init_pipe.ps.no_color1 = true; if (BindDrawPipeline(init_pipe)) diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index 069003f0ce..d326c38b12 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -36,6 +36,7 @@ static u32 s_debug_scope_depth = 0; #endif static bool IsDATMConvertShader(ShaderConvert i) { return (i == ShaderConvert::DATM_0 || i == ShaderConvert::DATM_1); } +static bool IsDATEModePrimIDInit(u32 flag) { return flag == 1 || flag == 2; } static VkAttachmentLoadOp GetLoadOpForTexture(GSTextureVK* tex) { @@ -2035,7 +2036,7 @@ VkPipeline GSDeviceVK::CreateTFXPipeline(const PipelineSelector& p) // Common state gpb.SetPipelineLayout(m_tfx_pipeline_layout); - if (p.ps.date >= 10) + if (IsDATEModePrimIDInit(p.ps.date)) { // DATE image prepass gpb.SetRenderPass(m_date_image_setup_render_passes[p.ds][0], 0); @@ -2083,7 +2084,7 @@ VkPipeline GSDeviceVK::CreateTFXPipeline(const PipelineSelector& p) } // Blending - if (p.ps.date >= 10) + if (IsDATEModePrimIDInit(p.ps.date)) { // image DATE prepass gpb.SetBlendAttachment(0, true, VK_BLEND_FACTOR_ONE, VK_BLEND_FACTOR_ZERO, VK_BLEND_OP_MIN, VK_BLEND_FACTOR_ONE, @@ -2837,7 +2838,6 @@ GSTextureVK* GSDeviceVK::SetupPrimitiveTrackingDATE(GSHWDrawConfig& config) pipe.feedback_loop = false; pipe.rt = true; pipe.ps.blend_a = pipe.ps.blend_b = pipe.ps.blend_c = pipe.ps.blend_d = false; - pipe.ps.date += 10; pipe.ps.no_color = false; pipe.ps.no_color1 = true; if (BindDrawPipeline(pipe))