Skip to content

Commit

Permalink
GPU/HW: Fix ROV depth being written with semitransparency
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 9, 2025
1 parent 7d2898b commit d9c9b30
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/core/gpu_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,13 +1276,16 @@ bool GPU_HW::CompilePipelines(Error* error)
texture_mode - (sprite ? static_cast<u8>(BatchTextureMode::SpriteStart) : 0));
const bool use_rov =
(render_mode == static_cast<u8>(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<GPUTransparencyMode>(transparency_mode) ==
GPUTransparencyMode::Disabled);
const std::string fs = shadergen.GenerateBatchFragmentShader(
static_cast<BatchRenderMode>(render_mode), static_cast<GPUTransparencyMode>(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(
Expand Down
8 changes: 4 additions & 4 deletions src/core/gpu_hw_shadergen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/gpu_hw_shadergen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/shader_cache_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

#include "common/types.h"

static constexpr u32 SHADER_CACHE_VERSION = 26;
static constexpr u32 SHADER_CACHE_VERSION = 27;

0 comments on commit d9c9b30

Please sign in to comment.