From d9c9b3038d5140eaa8ae0c8a61ba8b1cb7ccf1f3 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 9 Jan 2025 21:03:49 +1000 Subject: [PATCH] GPU/HW: Fix ROV depth being written with semitransparency --- src/core/gpu_hw.cpp | 5 ++++- src/core/gpu_hw_shadergen.cpp | 8 ++++---- src/core/gpu_hw_shadergen.h | 2 +- src/core/shader_cache_version.h | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index c61948ab35..9ef622d8fc 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1276,13 +1276,16 @@ bool GPU_HW::CompilePipelines(Error* error) texture_mode - (sprite ? static_cast(BatchTextureMode::SpriteStart) : 0)); const bool use_rov = (render_mode == static_cast(BatchRenderMode::ShaderBlend) && m_use_rov_for_shader_blend); + const bool rov_depth_test = (use_rov && depth_test != 0); + const bool rov_depth_write = (rov_depth_test && static_cast(transparency_mode) == + GPUTransparencyMode::Disabled); const std::string fs = shadergen.GenerateBatchFragmentShader( static_cast(render_mode), static_cast(transparency_mode), shader_texmode, sprite ? m_sprite_texture_filtering : m_texture_filtering, upscaled, msaa, per_sample_shading, uv_limits, !sprite && force_round_texcoords, true_color, ConvertToBoolUnchecked(dithering), scaled_dithering, disable_color_perspective, ConvertToBoolUnchecked(interlacing), ConvertToBoolUnchecked(check_mask), m_write_mask_as_depth, - use_rov, needs_rov_depth, (depth_test != 0)); + use_rov, needs_rov_depth, rov_depth_test, rov_depth_write); if (!(batch_fragment_shaders[depth_test][render_mode][transparency_mode][texture_mode][check_mask] [dithering][interlacing] = g_gpu_device->CreateShader( diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index dc0a957353..734850c688 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -733,13 +733,12 @@ std::string GPU_HW_ShaderGen::GenerateBatchFragmentShader( GPUTextureFilter texture_filtering, bool upscaled, bool msaa, bool per_sample_shading, bool uv_limits, bool force_round_texcoords, bool true_color, bool dithering, bool scaled_dithering, bool disable_color_perspective, bool interlacing, bool check_mask, bool write_mask_as_depth, bool use_rov, bool use_rov_depth, - bool rov_depth_test) const + bool rov_depth_test, bool rov_depth_write) const { DebugAssert(!true_color || !dithering); // Should not be doing dithering+true color. - // TODO: don't write depth for shader blend DebugAssert(transparency == GPUTransparencyMode::Disabled || render_mode == GPU_HW::BatchRenderMode::ShaderBlend); - DebugAssert(!rov_depth_test || (use_rov && use_rov_depth)); + DebugAssert((!rov_depth_test && !rov_depth_write) || (use_rov && use_rov_depth)); const bool textured = (texture_mode != GPU_HW::BatchTextureMode::Disabled); const bool palette = @@ -773,6 +772,7 @@ std::string GPU_HW_ShaderGen::GenerateBatchFragmentShader( DefineMacro(ss, "USE_ROV", use_rov); DefineMacro(ss, "USE_ROV_DEPTH", use_rov_depth); DefineMacro(ss, "ROV_DEPTH_TEST", rov_depth_test); + DefineMacro(ss, "ROV_DEPTH_WRITE", rov_depth_write); DefineMacro(ss, "USE_DUAL_SOURCE", use_dual_source); DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth); DefineMacro(ss, "FORCE_ROUND_TEXCOORDS", force_round_texcoords); @@ -1124,7 +1124,7 @@ float4 SampleFromVRAM(TEXPAGE_VALUE texpage, float2 coords) if (!discarded) { ROV_STORE(rov_color, fragpos, o_col0); - #if USE_ROV_DEPTH + #if USE_ROV_DEPTH && ROV_DEPTH_WRITE ROV_STORE(rov_depth, fragpos, float4(v_pos.z, 0.0, 0.0, 0.0)); #endif } diff --git a/src/core/gpu_hw_shadergen.h b/src/core/gpu_hw_shadergen.h index 05053a6b86..2158e29eb2 100644 --- a/src/core/gpu_hw_shadergen.h +++ b/src/core/gpu_hw_shadergen.h @@ -24,7 +24,7 @@ class GPU_HW_ShaderGen : public ShaderGen bool force_round_texcoords, bool true_color, bool dithering, bool scaled_dithering, bool disable_color_perspective, bool interlacing, bool check_mask, bool write_mask_as_depth, bool use_rov, bool use_rov_depth, - bool rov_depth_test) const; + bool rov_depth_test, bool rov_depth_write) const; std::string GenerateWireframeGeometryShader() const; std::string GenerateWireframeFragmentShader() const; std::string GenerateVRAMReadFragmentShader(u32 resolution_scale, u32 multisamples) const; diff --git a/src/core/shader_cache_version.h b/src/core/shader_cache_version.h index 6713855c65..fe51e47005 100644 --- a/src/core/shader_cache_version.h +++ b/src/core/shader_cache_version.h @@ -5,4 +5,4 @@ #include "common/types.h" -static constexpr u32 SHADER_CACHE_VERSION = 26; +static constexpr u32 SHADER_CACHE_VERSION = 27;