Skip to content

Commit

Permalink
GPU/HW: Clear ROV depth on fill/copy/write
Browse files Browse the repository at this point in the history
It wasn't being specified before, whoops.
  • Loading branch information
stenzek committed Nov 27, 2024
1 parent eb390a9 commit 97700b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/core/gpu_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ bool GPU_HW::CompilePipelines(Error* error)
std::unique_ptr<GPUShader> fs = g_gpu_device->CreateShader(
GPUShaderStage::Fragment, shadergen.GetLanguage(),
shadergen.GenerateVRAMFillFragmentShader(ConvertToBoolUnchecked(wrapped), ConvertToBoolUnchecked(interlaced),
m_write_mask_as_depth),
m_write_mask_as_depth, needs_rov_depth),
error);
if (!fs)
return false;
Expand All @@ -1485,9 +1485,9 @@ bool GPU_HW::CompilePipelines(Error* error)

// VRAM copy
{
std::unique_ptr<GPUShader> fs =
g_gpu_device->CreateShader(GPUShaderStage::Fragment, shadergen.GetLanguage(),
shadergen.GenerateVRAMCopyFragmentShader(m_write_mask_as_depth), error);
std::unique_ptr<GPUShader> fs = g_gpu_device->CreateShader(
GPUShaderStage::Fragment, shadergen.GetLanguage(),
shadergen.GenerateVRAMCopyFragmentShader(m_write_mask_as_depth, needs_rov_depth), error);
if (!fs)
return false;

Expand Down Expand Up @@ -1516,7 +1516,7 @@ bool GPU_HW::CompilePipelines(Error* error)
const bool use_ssbo = features.texture_buffers_emulated_with_ssbo;
std::unique_ptr<GPUShader> fs = g_gpu_device->CreateShader(
GPUShaderStage::Fragment, shadergen.GetLanguage(),
shadergen.GenerateVRAMWriteFragmentShader(use_buffer, use_ssbo, m_write_mask_as_depth), error);
shadergen.GenerateVRAMWriteFragmentShader(use_buffer, use_ssbo, m_write_mask_as_depth, needs_rov_depth), error);
if (!fs)
return false;

Expand Down
33 changes: 25 additions & 8 deletions src/core/gpu_hw_shadergen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,14 +1453,17 @@ uint SampleVRAM(uint2 coords)
return ss.str();
}

std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, bool use_ssbo,
bool write_mask_as_depth) const
std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, bool use_ssbo, bool write_mask_as_depth,
bool write_depth_as_rt) const
{
Assert(!write_mask_as_depth || (write_mask_as_depth != write_depth_as_rt));

std::stringstream ss;
WriteHeader(ss);
WriteColorConversionFunctions(ss);

DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth);
DefineMacro(ss, "WRITE_DEPTH_AS_RT", write_depth_as_rt);
DefineMacro(ss, "USE_BUFFER", use_buffer);

ss << "CONSTANT float2 VRAM_SIZE = float2(" << VRAM_WIDTH << ".0, " << VRAM_HEIGHT << ".0);\n";
Expand Down Expand Up @@ -1496,7 +1499,7 @@ std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, b
ss << "#define GET_VALUE(buffer_offset) (LOAD_TEXTURE_BUFFER(samp0, int(buffer_offset)).r)\n\n";
}

DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, false, write_mask_as_depth);
DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1 + BoolToUInt32(write_depth_as_rt), false, write_mask_as_depth);
ss << R"(
{
float2 coords = floor(v_pos.xy / u_resolution_scale);
Expand All @@ -1523,20 +1526,25 @@ std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_buffer, b
o_col0 = RGBA5551ToRGBA8(value);
#if WRITE_MASK_AS_DEPTH
o_depth = (o_col0.a == 1.0) ? u_depth_value : 0.0;
#elif WRITE_DEPTH_AS_RT
o_col1 = float4(1.0f, 0.0f, 0.0f, 0.0f);
#endif
})";

return ss.str();
}

std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader(bool write_mask_as_depth) const
std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader(bool write_mask_as_depth, bool write_depth_as_rt) const
{
Assert(!write_mask_as_depth || (write_mask_as_depth != write_depth_as_rt));

// TODO: This won't currently work because we can't bind the texture to both the shader and framebuffer.
const bool msaa = false;

std::stringstream ss;
WriteHeader(ss);
DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth);
DefineMacro(ss, "WRITE_DEPTH_AS_RT", write_depth_as_rt);
DefineMacro(ss, "MSAA_COPY", msaa);

DeclareUniformBuffer(ss,
Expand All @@ -1545,7 +1553,8 @@ std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader(bool write_mask_as_
true);

DeclareTexture(ss, "samp0", 0, msaa);
DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, false, write_mask_as_depth, false, false, msaa);
DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1 + BoolToUInt32(write_depth_as_rt), false, write_mask_as_depth, false,
false, msaa);
ss << R"(
{
float2 dst_coords = floor(v_pos.xy);
Expand Down Expand Up @@ -1575,25 +1584,31 @@ std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader(bool write_mask_as_
o_col0 = float4(color.xyz, u_set_mask_bit ? 1.0 : color.a);
#if WRITE_MASK_AS_DEPTH
o_depth = (u_set_mask_bit ? 1.0f : ((o_col0.a == 1.0) ? u_depth_value : 0.0));
#elif WRITE_DEPTH_AS_RT
o_col1 = float4(1.0f, 0.0f, 0.0f, 0.0f);
#endif
})";

return ss.str();
}

std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced,
bool write_mask_as_depth) const
std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced, bool write_mask_as_depth,
bool write_depth_as_rt) const
{
Assert(!write_mask_as_depth || (write_mask_as_depth != write_depth_as_rt));

std::stringstream ss;
WriteHeader(ss);
DefineMacro(ss, "WRITE_MASK_AS_DEPTH", write_mask_as_depth);
DefineMacro(ss, "WRITE_DEPTH_AS_RT", write_depth_as_rt);
DefineMacro(ss, "WRAPPED", wrapped);
DefineMacro(ss, "INTERLACED", interlaced);

DeclareUniformBuffer(
ss, {"uint2 u_dst_coords", "uint2 u_end_coords", "float4 u_fill_color", "uint u_interlaced_displayed_field"}, true);

DeclareFragmentEntryPoint(ss, 0, 1, {}, interlaced || wrapped, 1, false, write_mask_as_depth, false, false, false);
DeclareFragmentEntryPoint(ss, 0, 1, {}, interlaced || wrapped, 1 + BoolToUInt32(write_depth_as_rt), false,
write_mask_as_depth, false, false, false);
ss << R"(
{
#if INTERLACED || WRAPPED
Expand All @@ -1617,6 +1632,8 @@ std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool
o_col0 = u_fill_color;
#if WRITE_MASK_AS_DEPTH
o_depth = u_fill_color.a;
#elif WRITE_DEPTH_AS_RT
o_col1 = float4(1.0f, 0.0f, 0.0f, 0.0f);
#endif
})";

Expand Down
8 changes: 5 additions & 3 deletions src/core/gpu_hw_shadergen.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class GPU_HW_ShaderGen : public ShaderGen
std::string GenerateWireframeGeometryShader() const;
std::string GenerateWireframeFragmentShader() const;
std::string GenerateVRAMReadFragmentShader(u32 resolution_scale, u32 multisamples) const;
std::string GenerateVRAMWriteFragmentShader(bool use_buffer, bool use_ssbo, bool write_mask_as_depth) const;
std::string GenerateVRAMCopyFragmentShader(bool write_mask_as_depth) const;
std::string GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced, bool write_mask_as_depth) const;
std::string GenerateVRAMWriteFragmentShader(bool use_buffer, bool use_ssbo, bool write_mask_as_depth,
bool write_depth_as_rt) const;
std::string GenerateVRAMCopyFragmentShader(bool write_mask_as_depth, bool write_depth_as_rt) const;
std::string GenerateVRAMFillFragmentShader(bool wrapped, bool interlaced, bool write_mask_as_depth,
bool write_depth_as_rt) const;
std::string GenerateVRAMUpdateDepthFragmentShader(bool msaa) const;
std::string GenerateVRAMExtractFragmentShader(u32 resolution_scale, u32 multisamples, bool color_24bit,
bool depth_buffer) const;
Expand Down

0 comments on commit 97700b8

Please sign in to comment.