From f96e7a91567381e5226e8ee713ac65f0c22c6a46 Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:23:59 +0200 Subject: [PATCH] GS/HW: Rename dfmt to dst_fmt. It was confusing whenever the d meant depth or destination, this should make the code easier to read. --- bin/resources/shaders/dx11/tfx.fx | 10 +++++----- bin/resources/shaders/opengl/tfx_fs.glsl | 8 ++++---- bin/resources/shaders/vulkan/tfx.glsl | 10 +++++----- pcsx2/GS/Renderers/Common/GSDevice.h | 2 +- pcsx2/GS/Renderers/DX11/GSDevice11.cpp | 2 +- pcsx2/GS/Renderers/DX12/GSDevice12.cpp | 2 +- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 16 ++++++++-------- pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm | 2 +- pcsx2/GS/Renderers/Metal/GSMTLSharedHeader.h | 2 +- pcsx2/GS/Renderers/Metal/tfx.metal | 10 +++++----- pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp | 2 +- pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp | 2 +- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index da7875c418..6df8453f4b 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -55,7 +55,7 @@ #define PS_SHUFFLE_SAME 0 #define PS_READ_BA 0 #define PS_READ16_SRC 0 -#define PS_DFMT 0 +#define PS_DST_FMT 0 #define PS_DEPTH_FMT 0 #define PS_PAL_FMT 0 #define PS_CHANNEL_FETCH 0 @@ -797,7 +797,7 @@ void ps_color_clamp_wrap(inout float3 C) // so we need to limit the color depth on dithered items if (SW_BLEND || PS_DITHER || PS_FBMASK) { - if (PS_DFMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV) + if (PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV) C += 7.0f; // Need to round up, not down since the shader will invert // Standard Clamp @@ -805,7 +805,7 @@ void ps_color_clamp_wrap(inout float3 C) C = clamp(C, (float3)0.0f, (float3)255.0f); // In 16 bits format, only 5 bits of color are used. It impacts shadows computation of Castlevania - if (PS_DFMT == FMT_16 && PS_BLEND_MIX == 0) + if (PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0) C = (float3)((int3)C & (int3)0xF8); else if (PS_COLCLIP == 1 || PS_HDR == 1) C = (float3)((int3)C & (int3)0xFF); @@ -999,12 +999,12 @@ PS_OUTPUT ps_main(PS_INPUT input) } // Alpha correction - if (PS_DFMT == FMT_16) + if (PS_DST_FMT == FMT_16) { float A_one = 128.0f; // alpha output will be 0x80 C.a = PS_FBA ? A_one : step(A_one, C.a) * A_one; } - else if ((PS_DFMT == FMT_32) && PS_FBA) + else if ((PS_DST_FMT == FMT_32) && PS_FBA) { float A_one = 128.0f; if (C.a < A_one) C.a += A_one; diff --git a/bin/resources/shaders/opengl/tfx_fs.glsl b/bin/resources/shaders/opengl/tfx_fs.glsl index 7ce7835d96..6ad4b84145 100644 --- a/bin/resources/shaders/opengl/tfx_fs.glsl +++ b/bin/resources/shaders/opengl/tfx_fs.glsl @@ -740,7 +740,7 @@ void ps_color_clamp_wrap(inout vec3 C) // so we need to limit the color depth on dithered items #if SW_BLEND || PS_DITHER || PS_FBMASK -#if PS_DFMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV +#if PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV C += 7.0f; // Need to round up, not down since the shader will invert #endif @@ -756,7 +756,7 @@ void ps_color_clamp_wrap(inout vec3 C) // Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy // GS: Color = 1, Alpha = 255 => output 1 // GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875 -#if PS_DFMT == FMT_16 && PS_BLEND_MIX == 0 +#if PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0 // In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania C = vec3(ivec3(C) & ivec3(0xF8)); #elif PS_COLCLIP == 1 || PS_HDR == 1 @@ -1018,10 +1018,10 @@ void ps_main() #endif // Correct the ALPHA value based on the output format -#if (PS_DFMT == FMT_16) +#if (PS_DST_FMT == FMT_16) float A_one = 128.0f; // alpha output will be 0x80 C.a = (PS_FBA != 0) ? A_one : step(128.0f, C.a) * A_one; -#elif (PS_DFMT == FMT_32) && (PS_FBA != 0) +#elif (PS_DST_FMT == FMT_32) && (PS_FBA != 0) if(C.a < 128.0f) C.a += 128.0f; #endif diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl index 18a911f197..4d8ff1c2a6 100644 --- a/bin/resources/shaders/vulkan/tfx.glsl +++ b/bin/resources/shaders/vulkan/tfx.glsl @@ -281,7 +281,7 @@ void main() #define PS_READ_BA 0 #define PS_WRITE_RG 0 #define PS_READ16_SRC 0 -#define PS_DFMT 0 +#define PS_DST_FMT 0 #define PS_DEPTH_FMT 0 #define PS_PAL_FMT 0 #define PS_CHANNEL_FETCH 0 @@ -988,7 +988,7 @@ void ps_color_clamp_wrap(inout vec3 C) // so we need to limit the color depth on dithered items #if SW_BLEND || PS_DITHER || PS_FBMASK -#if PS_DFMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV +#if PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV C += 7.0f; // Need to round up, not down since the shader will invert #endif @@ -1004,7 +1004,7 @@ void ps_color_clamp_wrap(inout vec3 C) // Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy // GS: Color = 1, Alpha = 255 => output 1 // GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875 -#if PS_DFMT == FMT_16 && PS_BLEND_MIX == 0 +#if PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0 // In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania C = vec3(ivec3(C) & ivec3(0xF8)); #elif PS_COLCLIP == 1 || PS_HDR == 1 @@ -1245,10 +1245,10 @@ void main() #endif // Correct the ALPHA value based on the output format -#if (PS_DFMT == FMT_16) +#if (PS_DST_FMT == FMT_16) float A_one = 128.0f; // alpha output will be 0x80 C.a = (PS_FBA != 0) ? A_one : step(128.0f, C.a) * A_one; -#elif (PS_DFMT == FMT_32) && (PS_FBA != 0) +#elif (PS_DST_FMT == FMT_32) && (PS_FBA != 0) if(C.a < 128.0f) C.a += 128.0f; #endif diff --git a/pcsx2/GS/Renderers/Common/GSDevice.h b/pcsx2/GS/Renderers/Common/GSDevice.h index 178fbf7ca6..187f51e554 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.h +++ b/pcsx2/GS/Renderers/Common/GSDevice.h @@ -289,7 +289,7 @@ struct alignas(16) GSHWDrawConfig // Format u32 aem_fmt : 2; u32 pal_fmt : 2; - u32 dfmt : 2; // 0 → 32-bit, 1 → 24-bit, 2 → 16-bit + u32 dst_fmt : 2; // 0 → 32-bit, 1 → 24-bit, 2 → 16-bit u32 depth_fmt : 2; // 0 → None, 1 → 32-bit, 2 → 16-bit, 3 → RGBA // Alpha extension/Correction u32 aem : 1; diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp index 2c34305ed5..e646a797f4 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp @@ -1680,7 +1680,7 @@ void GSDevice11::SetupPS(const PSSelector& sel, const GSHWDrawConfig::PSConstant sm.AddMacro("PS_CHANNEL_FETCH", sel.channel); sm.AddMacro("PS_TALES_OF_ABYSS_HLE", sel.tales_of_abyss_hle); sm.AddMacro("PS_URBAN_CHAOS_HLE", sel.urban_chaos_hle); - sm.AddMacro("PS_DFMT", sel.dfmt); + sm.AddMacro("PS_DST_FMT", sel.dst_fmt); sm.AddMacro("PS_DEPTH_FMT", sel.depth_fmt); sm.AddMacro("PS_PAL_FMT", sel.pal_fmt); sm.AddMacro("PS_HDR", sel.hdr); diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index faf44c008a..fee13e2c5f 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -2819,7 +2819,7 @@ const ID3DBlob* GSDevice12::GetTFXPixelShader(const GSHWDrawConfig::PSSelector& sm.AddMacro("PS_CHANNEL_FETCH", sel.channel); sm.AddMacro("PS_TALES_OF_ABYSS_HLE", sel.tales_of_abyss_hle); sm.AddMacro("PS_URBAN_CHAOS_HLE", sel.urban_chaos_hle); - sm.AddMacro("PS_DFMT", sel.dfmt); + sm.AddMacro("PS_DST_FMT", sel.dst_fmt); sm.AddMacro("PS_DEPTH_FMT", sel.depth_fmt); sm.AddMacro("PS_PAL_FMT", sel.pal_fmt); sm.AddMacro("PS_HDR", sel.hdr); diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index d5ce02e267..1f463f2c24 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -3123,7 +3123,7 @@ void GSRendererHW::EmulateTextureShuffleAndFbmask(GSTextureCache::Target* rt, GS if (m_texture_shuffle) { m_conf.ps.shuffle = 1; - m_conf.ps.dfmt = GSLocalMemory::PSM_FMT_32; + m_conf.ps.dst_fmt = GSLocalMemory::PSM_FMT_32; bool write_ba; bool read_ba; @@ -3233,7 +3233,7 @@ void GSRendererHW::EmulateTextureShuffleAndFbmask(GSTextureCache::Target* rt, GS } else { - m_conf.ps.dfmt = GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmt; + m_conf.ps.dst_fmt = GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmt; // Don't allow only unused bits on 16bit format to enable fbmask, // let's set the mask to 0 in such cases. @@ -3275,14 +3275,14 @@ void GSRendererHW::EmulateTextureShuffleAndFbmask(GSTextureCache::Target* rt, GS if (!PRIM->ABE || !(~ff_fbmask & ~zero_fbmask & 0x7) || !g_gs_device->Features().texture_barrier) { GL_INS("FBMASK Unsafe SW emulated fb_mask:%x on %d bits format", m_cached_ctx.FRAME.FBMSK, - (m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16) ? 16 : 32); + (m_conf.ps.dst_fmt == GSLocalMemory::PSM_FMT_16) ? 16 : 32); m_conf.require_one_barrier = true; } else { // The safe and accurate path (but slow) GL_INS("FBMASK SW emulated fb_mask:%x on %d bits format", m_cached_ctx.FRAME.FBMSK, - (m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16) ? 16 : 32); + (m_conf.ps.dst_fmt == GSLocalMemory::PSM_FMT_16) ? 16 : 32); m_conf.require_full_barrier = true; } } @@ -3490,7 +3490,7 @@ void GSRendererHW::EmulateBlending(int rt_alpha_min, int rt_alpha_max, bool& DAT // PABE: Check condition early as an optimization. const bool PABE = PRIM->ABE && m_draw_env->PABE.PABE && (GetAlphaMinMax().max < 128); // FBMASK: Color is not written, no need to do blending. - const u32 temp_fbmask = m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16 ? 0x00F8F8F8 : 0x00FFFFFF; + const u32 temp_fbmask = m_conf.ps.dst_fmt == GSLocalMemory::PSM_FMT_16 ? 0x00F8F8F8 : 0x00FFFFFF; const bool FBMASK = (m_cached_ctx.FRAME.FBMSK & temp_fbmask) == temp_fbmask; // No blending or coverage anti-aliasing so early exit @@ -3541,7 +3541,7 @@ void GSRendererHW::EmulateBlending(int rt_alpha_min, int rt_alpha_max, bool& DAT m_conf.ps.blend_c = 2; } // 24 bits doesn't have an alpha channel so use 128 (1.0f) fix factor as equivalent. - else if (m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_24) + else if (m_conf.ps.dst_fmt == GSLocalMemory::PSM_FMT_24) { AFIX = 128; m_conf.ps.blend_c = 2; @@ -5016,9 +5016,9 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta } // Before emulateblending, dither will be used - m_conf.ps.dither = GSConfig.Dithering > 0 && m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_16 && env.DTHE.DTHE; + m_conf.ps.dither = GSConfig.Dithering > 0 && m_conf.ps.dst_fmt == GSLocalMemory::PSM_FMT_16 && env.DTHE.DTHE; - if (m_conf.ps.dfmt == GSLocalMemory::PSM_FMT_24) + if (m_conf.ps.dst_fmt == GSLocalMemory::PSM_FMT_24) { // Disable writing of the alpha channel m_conf.colormask.wa = 0; diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm index 945c438a4a..8a7329de73 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -1788,7 +1788,7 @@ void GSDeviceMTL::MRESetHWPipelineState(GSHWDrawConfig::VSSelector vssel, GSHWDr setFnConstantB(m_fn_constants, pssel.iip, GSMTLConstantIndex_IIP); setFnConstantI(m_fn_constants, pssel.aem_fmt, GSMTLConstantIndex_PS_AEM_FMT); setFnConstantI(m_fn_constants, pssel.pal_fmt, GSMTLConstantIndex_PS_PAL_FMT); - setFnConstantI(m_fn_constants, pssel.dfmt, GSMTLConstantIndex_PS_DFMT); + setFnConstantI(m_fn_constants, pssel.dst_fmt, GSMTLConstantIndex_PS_DST_FMT); setFnConstantI(m_fn_constants, pssel.depth_fmt, GSMTLConstantIndex_PS_DEPTH_FMT); setFnConstantB(m_fn_constants, pssel.aem, GSMTLConstantIndex_PS_AEM); setFnConstantB(m_fn_constants, pssel.fba, GSMTLConstantIndex_PS_FBA); diff --git a/pcsx2/GS/Renderers/Metal/GSMTLSharedHeader.h b/pcsx2/GS/Renderers/Metal/GSMTLSharedHeader.h index d8818034db..e5ef243531 100644 --- a/pcsx2/GS/Renderers/Metal/GSMTLSharedHeader.h +++ b/pcsx2/GS/Renderers/Metal/GSMTLSharedHeader.h @@ -167,7 +167,7 @@ enum GSMTLFnConstants GSMTLConstantIndex_VS_EXPAND_TYPE, GSMTLConstantIndex_PS_AEM_FMT, GSMTLConstantIndex_PS_PAL_FMT, - GSMTLConstantIndex_PS_DFMT, + GSMTLConstantIndex_PS_DST_FMT, GSMTLConstantIndex_PS_DEPTH_FMT, GSMTLConstantIndex_PS_AEM, GSMTLConstantIndex_PS_FBA, diff --git a/pcsx2/GS/Renderers/Metal/tfx.metal b/pcsx2/GS/Renderers/Metal/tfx.metal index 8af47db53f..81edce08d5 100644 --- a/pcsx2/GS/Renderers/Metal/tfx.metal +++ b/pcsx2/GS/Renderers/Metal/tfx.metal @@ -26,7 +26,7 @@ constant bool VS_POINT_SIZE [[function_constant(GSMTLConstantIndex_VS_PO constant uint VS_EXPAND_TYPE_RAW [[function_constant(GSMTLConstantIndex_VS_EXPAND_TYPE)]]; constant uint PS_AEM_FMT [[function_constant(GSMTLConstantIndex_PS_AEM_FMT)]]; constant uint PS_PAL_FMT [[function_constant(GSMTLConstantIndex_PS_PAL_FMT)]]; -constant uint PS_DFMT [[function_constant(GSMTLConstantIndex_PS_DFMT)]]; +constant uint PS_DST_FMT [[function_constant(GSMTLConstantIndex_PS_DST_FMT)]]; constant uint PS_DEPTH_FMT [[function_constant(GSMTLConstantIndex_PS_DEPTH_FMT)]]; constant bool PS_AEM [[function_constant(GSMTLConstantIndex_PS_AEM)]]; constant bool PS_FBA [[function_constant(GSMTLConstantIndex_PS_FBA)]]; @@ -855,7 +855,7 @@ struct PSMain if (!SW_BLEND && !PS_DITHER && !PS_FBMASK) return; - if (PS_DFMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV) + if (PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0 && PS_ROUND_INV) C.rgb += 7.f; // Need to round up, not down since the shader will invert // Correct the Color value based on the output format @@ -868,7 +868,7 @@ struct PSMain // Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy // GS: Color = 1, Alpha = 255 => output 1 // GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875 - if (PS_DFMT == FMT_16 && PS_BLEND_MIX == 0) + if (PS_DST_FMT == FMT_16 && PS_BLEND_MIX == 0) // In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania C.rgb = float3(short3(C.rgb) & 0xF8); else if (PS_COLCLIP || PS_HDR) @@ -1062,12 +1062,12 @@ struct PSMain float4 alpha_blend = SW_AD_TO_HW ? float4(trunc(current_color.a * 255.5f) / 128.f) : float4(C.a / 128.f); - if (PS_DFMT == FMT_16) + if (PS_DST_FMT == FMT_16) { float A_one = 128.f; C.a = (PS_FBA) ? A_one : step(128.f, C.a) * A_one; } - else if (PS_DFMT == FMT_32 && PS_FBA) + else if (PS_DST_FMT == FMT_32 && PS_FBA) { if (C.a < 128.f) C.a += 128.f; diff --git a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp index e502f0814c..829e887e0c 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp @@ -1350,7 +1350,7 @@ std::string GSDeviceOGL::GetPSSource(const PSSelector& sel) + fmt::format("#define PS_ADJT {}\n", sel.adjt) + fmt::format("#define PS_AEM_FMT {}\n", sel.aem_fmt) + fmt::format("#define PS_PAL_FMT {}\n", sel.pal_fmt) - + fmt::format("#define PS_DFMT {}\n", sel.dfmt) + + fmt::format("#define PS_DST_FMT {}\n", sel.dst_fmt) + fmt::format("#define PS_DEPTH_FMT {}\n", sel.depth_fmt) + fmt::format("#define PS_CHANNEL_FETCH {}\n", sel.channel) + fmt::format("#define PS_URBAN_CHAOS_HLE {}\n", sel.urban_chaos_hle) diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index ee2a6dd285..6dbab5c21b 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -4658,7 +4658,7 @@ VkShaderModule GSDeviceVK::GetTFXFragmentShader(const GSHWDrawConfig::PSSelector AddMacro(ss, "PS_ADJT", sel.adjt); AddMacro(ss, "PS_AEM_FMT", sel.aem_fmt); AddMacro(ss, "PS_PAL_FMT", sel.pal_fmt); - AddMacro(ss, "PS_DFMT", sel.dfmt); + AddMacro(ss, "PS_DST_FMT", sel.dst_fmt); AddMacro(ss, "PS_DEPTH_FMT", sel.depth_fmt); AddMacro(ss, "PS_CHANNEL_FETCH", sel.channel); AddMacro(ss, "PS_URBAN_CHAOS_HLE", sel.urban_chaos_hle);