Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions bin/resources/shaders/dx11/convert.fx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ float depth32_to_depth24(float d)
return uint_to_depth24(depth_to_uint(d));
}

float4 primid_to_rgba8(float p)
{
return uint_to_rgba8(asuint(p));
}

#if defined(__ps_copy__)
OUTPUT_TYPE ps_copy(PS_INPUT input) : OUTPUT_SV
{
Expand Down Expand Up @@ -323,6 +328,13 @@ OUTPUT_TYPE ps_convert_depth32_depth24(PS_INPUT input) : OUTPUT_SV
}
#endif

#if defined(__ps_convert_primid_rgba8__)
OUTPUT_TYPE ps_convert_primid_rgba8(PS_INPUT input) : OUTPUT_SV
{
return primid_to_rgba8(sample_c(input.t));
}
#endif

#define SAMPLE_RGBA_DEPTH_BILN(CONVERT_FN) \
uint width, height; \
Texture.GetDimensions(width, height); \
Expand Down Expand Up @@ -650,9 +662,9 @@ float ps_primid_image_init_0(PS_INPUT input) : SV_Target
{
float c;
if ((127.5f / 255.0f) < sample_c(input.t).a) // < 0x80 pass (== 0x80 should not pass)
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
Expand All @@ -662,9 +674,9 @@ float ps_primid_image_init_1(PS_INPUT input) : SV_Target
{
float c;
if (sample_c(input.t).a < (127.5f / 255.0f)) // >= 0x80 pass
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
Expand All @@ -674,9 +686,9 @@ float ps_primid_image_init_2(PS_INPUT input) : SV_Target
{
float c;
if ((254.5f / 255.0f) < sample_c(input.t).a) // < 0x80 pass (== 0x80 should not pass)
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
Expand All @@ -686,9 +698,9 @@ float ps_primid_image_init_3(PS_INPUT input) : SV_Target
{
float c;
if (sample_c(input.t).a < (254.5f / 255.0f)) // >= 0x80 pass
c = float(-1);
c = float(PRIMID_MIN);
else
c = float(0x7FFFFFFF);
c = float(PRIMID_MAX);
return c;
}
#endif
Expand Down
22 changes: 17 additions & 5 deletions bin/resources/shaders/opengl/convert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ float depth32_to_depth24(float d)
return uint_to_depth24(depth_to_uint(d));
}

vec4 primid_to_rgba8(float p)
{
return uint_to_rgba8(floatBitsToUint(p));
}

#ifdef ps_copy
void ps_copy()
{
Expand Down Expand Up @@ -212,6 +217,13 @@ void ps_convert_depth32_depth24()
}
#endif

#ifdef ps_convert_primid_rgba8
void ps_convert_primid_rgba8()
{
OUTPUT = primid_to_rgba8(sample_c());
}
#endif

#define SAMPLE_RGBA_DEPTH_BILN(CONVERT_FN) \
ivec2 dims = textureSize(TextureSampler, 0); \
vec2 top_left_f = PSin_t * vec2(dims) - 0.5f; \
Expand Down Expand Up @@ -615,23 +627,23 @@ void ps_yuv()

void main()
{
o_col0 = vec4(0x7FFFFFFF);
o_col0 = vec4(PRIMID_MAX);

#ifdef ps_primid_image_init_0
if((127.5f / 255.0f) < sample_c().a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_1
if(sample_c().a < (127.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_2
if((254.5f / 255.0f) < sample_c().a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_3
if(sample_c().a < (254.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
}
#endif
Expand Down
22 changes: 17 additions & 5 deletions bin/resources/shaders/vulkan/convert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ float depth32_to_depth24(float d)
return uint_to_depth24(depth_to_uint(d));
}

vec4 primid_to_rgba8(float p)
{
return uint_to_rgba8(floatBitsToUint(p));
}

#ifdef ps_copy
void ps_copy()
{
Expand Down Expand Up @@ -281,6 +286,13 @@ void ps_convert_depth32_depth24()
}
#endif

#ifdef ps_convert_primid_rgba8
void ps_convert_primid_rgba8()
{
OUTPUT = primid_to_rgba8(sample_c(v_tex));
}
#endif

#define SAMPLE_RGBA_DEPTH_BILN(CONVERT_FN) \
ivec2 dims = textureSize(samp0, 0); \
vec2 top_left_f = v_tex * vec2(dims) - 0.5f; \
Expand Down Expand Up @@ -628,23 +640,23 @@ void ps_yuv()

void main()
{
o_col0 = vec4(0x7FFFFFFF);
o_col0 = vec4(PRIMID_MAX);

#ifdef ps_primid_image_init_0
if((127.5f / 255.0f) < sample_c(v_tex).a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_1
if(sample_c(v_tex).a < (127.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_2
if((254.5f / 255.0f) < sample_c(v_tex).a) // < 0x80 pass (== 0x80 should not pass)
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
#ifdef ps_primid_image_init_3
if(sample_c(v_tex).a < (254.5f / 255.0f)) // >= 0x80 pass
o_col0 = vec4(-1);
o_col0 = vec4(PRIMID_MIN);
#endif
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/GS/Renderers/Common/GSDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const char* ShaderEntryPoint(ShaderConvert value)
case ShaderConvert::RGB5A1_TO_DEPTH16: return "ps_convert_rgb5a1_depth16";
case ShaderConvert::DEPTH32_TO_DEPTH24: return "ps_convert_depth32_depth24";
case ShaderConvert::DEPTH_COPY: return "ps_depth_copy";
case ShaderConvert::PRIMID_TO_RGBA8: return "ps_convert_primid_rgba8";
case ShaderConvert::DOWNSAMPLE_COPY: return "ps_downsample_copy";
case ShaderConvert::RGBA_TO_8I: return "ps_convert_rgba_8i";
case ShaderConvert::RGB5A1_TO_8I: return "ps_convert_rgb5a1_8i";
Expand Down Expand Up @@ -109,6 +110,7 @@ const char* ShaderConvertName(ShaderConvert shader)
ENTRY(RGBA8_TO_DEPTH16);
ENTRY(RGB5A1_TO_DEPTH16);
ENTRY(DEPTH32_TO_DEPTH24);
ENTRY(PRIMID_TO_RGBA8);
ENTRY(DOWNSAMPLE_COPY);
ENTRY(RGBA_TO_8I);
ENTRY(RGB5A1_TO_8I);
Expand Down
9 changes: 9 additions & 0 deletions pcsx2/GS/Renderers/Common/GSDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum class ShaderConvert
RGBA8_TO_DEPTH16,
RGB5A1_TO_DEPTH16,
DEPTH32_TO_DEPTH24,
PRIMID_TO_RGBA8,
DOWNSAMPLE_COPY,
RGBA_TO_8I,
RGB5A1_TO_8I,
Expand Down Expand Up @@ -122,6 +123,7 @@ static inline constexpr bool HasColorOutput(ShaderConvert shader)
case ShaderConvert::DEPTH32_TO_RGBA8:
case ShaderConvert::DEPTH32_TO_RGB8:
case ShaderConvert::DEPTH16_TO_RGB5A1:
case ShaderConvert::PRIMID_TO_RGBA8:
case ShaderConvert::DOWNSAMPLE_COPY:
case ShaderConvert::RGBA_TO_8I:
case ShaderConvert::RGB5A1_TO_8I:
Expand Down Expand Up @@ -162,6 +164,7 @@ static inline constexpr bool HasFloat32Input(ShaderConvert shader)
case ShaderConvert::DEPTH32_TO_RGB8:
case ShaderConvert::DEPTH16_TO_RGB5A1:
case ShaderConvert::DEPTH32_TO_DEPTH24:
case ShaderConvert::PRIMID_TO_RGBA8:
return true;
default:
return false;
Expand Down Expand Up @@ -526,6 +529,10 @@ static inline ShaderConvertSelector GetConvertShader(GSTexture::Format src, GSTe
pxAssert(false);
}
break;
case GSTexture::Format::PrimID:
pxAssert(dst == GSTexture::Format::Color);
shader = ShaderConvert::PRIMID_TO_RGBA8;
break;
default:
pxAssert(false);
break;
Expand Down Expand Up @@ -1277,6 +1284,8 @@ struct alignas(16) GSHWDrawConfig
SetDATM datm;
bool line_expand;

const std::string* dump_primid_path; // for debugging only

struct AlphaPass
{
alignas(8) PSSelector ps;
Expand Down
11 changes: 11 additions & 0 deletions pcsx2/GS/Renderers/Common/GSShaderEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@ enum class PS_ROV_DEPTH : uint32_t
READ_ONLY = 2,
};

#if defined(__METAL_VERSION__)
#define CONSTANT constant
#else
#define CONSTANT
#endif

static constexpr CONSTANT int PRIMID_MAX = (1 << 24) - 1;
static constexpr CONSTANT int PRIMID_MIN = -1;

#undef CONSTANT

} // namespace GSShader
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/Common/GSTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool GSTexture::Save(const std::string& fn)
{
// Depth textures need special treatment - we have a stencil component.
// Just re-use the existing conversion shader instead.
if (m_format == Format::DepthStencil || m_format == Format::DepthColor)
if (m_format == Format::DepthStencil || m_format == Format::DepthColor || m_format == Format::PrimID)
{
GSTexture* temp = g_gs_device->CreateRenderTarget(GetWidth(), GetHeight(), Format::Color, false);
if (!temp)
Expand Down
7 changes: 7 additions & 0 deletions pcsx2/GS/Renderers/DX11/GSDevice11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ bool GSDevice11::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)

ShaderMacro sm_ps;
sm_ps.AddMacro("PIXEL_SHADER", 1);
sm_ps.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm_ps.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm_ps.AddMacro("HAS_BILN", static_cast<int>(shader.Biln()));
sm_ps.AddMacro("HAS_STENCIL_OUTPUT", static_cast<int>(shader.StencilOutput()));
sm_ps.AddMacro("HAS_INTEGER_OUTPUT", static_cast<int>(shader.IntegerOutputBpp() != 0));
Expand Down Expand Up @@ -582,6 +584,8 @@ bool GSDevice11::Create(GSVSyncMode vsync_mode, bool allow_present_throttle)
const std::string entry_point_macro = WrapEntryPointMacro(entry_point);
ShaderMacro sm_ps;
sm_ps.AddMacro("PIXEL_SHADER", 1);
sm_ps.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm_ps.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm_ps.AddMacro(entry_point_macro.c_str(), 1);
m_date.primid_init_ps[i] = m_shader_cache.GetPixelShader(m_dev.get(), *convert_hlsl, sm_ps.GetPtr(), entry_point.c_str());
if (!m_date.primid_init_ps[i])
Expand Down Expand Up @@ -3299,6 +3303,9 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config)
g_gs_device->SetColorClipTexture(nullptr);
}
}

if (primid_texture && config.dump_primid_path)
primid_texture->Save(*config.dump_primid_path);
}

void GSDevice11::FeedbackCopyAndBind(const GSHWDrawConfig& config,
Expand Down
19 changes: 13 additions & 6 deletions pcsx2/GS/Renderers/DX12/GSDevice12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,8 @@ bool GSDevice12::CompileConvertPipelines()

ShaderMacro sm;
sm.AddMacro("PIXEL_SHADER", 1);
sm.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm.AddMacro("HAS_BILN", static_cast<int>(shader.Biln()));
sm.AddMacro("HAS_STENCIL_OUTPUT", static_cast<int>(shader.StencilOutput()));
sm.AddMacro("HAS_INTEGER_OUTPUT", static_cast<int>(shader.IntegerOutputBpp() != 0));
Expand Down Expand Up @@ -2930,6 +2932,8 @@ bool GSDevice12::CompileConvertPipelines()

ShaderMacro sm;
sm.AddMacro("PIXEL_SHADER", "1");
sm.AddMacro("PRIMID_MAX", GSShader::PRIMID_MAX);
sm.AddMacro("PRIMID_MIN", GSShader::PRIMID_MIN);
sm.AddMacro(entry_point_macro.c_str(), "1");

ComPtr<ID3DBlob> ps(m_shader_cache.GetPixelShader(*source, sm.GetPtr(), entry_point.c_str()));
Expand Down Expand Up @@ -4696,12 +4700,6 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config)
config.alpha_second_pass.require_full_barrier);
}

if (date_image)
Recycle(date_image);

if (draw_rt_clone)
Recycle(draw_rt_clone);

// now blit the colclip texture back to the original target
if (colclip_rt)
{
Expand Down Expand Up @@ -4733,6 +4731,15 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config)
g_gs_device->SetColorClipTexture(nullptr);
}
}

if (date_image && config.dump_primid_path)
date_image->Save(*config.dump_primid_path);

if (date_image)
Recycle(date_image);

if (draw_rt_clone)
Recycle(draw_rt_clone);
}

void GSDevice12::SendHWDraw(const PipelineSelector& pipe, const GSHWDrawConfig& config, GSTexture12* draw_rt,
Expand Down
10 changes: 10 additions & 0 deletions pcsx2/GS/Renderers/HW/GSRendererHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6048,6 +6048,16 @@ void GSRendererHW::EmulateDATESelectMethod(DATEOptions& date_options, GSTextureC
pxAssert(!(date_options.barrier && date_options.stencil_one));
pxAssert(!(date_options.primid && date_options.stencil_one));
pxAssert(!(date_options.primid && date_options.barrier));

if (date_options.primid && GSConfig.ShouldDump(s_n, g_perfmon.GetFrame()) && GSConfig.SaveRT)
{
m_dump_primid_path = GetDrawDumpPath("%05lld_f%05lld_primid.bmp", s_n, g_perfmon.GetFrame());
m_conf.dump_primid_path = &m_dump_primid_path;
}
else
{
m_conf.dump_primid_path = nullptr;
}
}

void GSRendererHW::EmulateDATEGetConfig(DATEOptions& date_options, bool scale_rt_alpha, GSDevice::RecycledTexture& temp_ds)
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/GS/Renderers/HW/GSRendererHW.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ class GSRendererHW : public GSRenderer
std::unique_ptr<GSTextureCacheSW::Texture> m_sw_texture[7 + 1];
std::unique_ptr<GSVirtualAlignedClass<32>> m_sw_rasterizer;

std::string m_dump_primid_path;

public:
GSRendererHW();
virtual ~GSRendererHW() override;
Expand Down
3 changes: 3 additions & 0 deletions pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,9 @@ static bool usesStencil(GSHWDrawConfig::DestinationAlphaMode dstalpha)
}
}

if (primid_tex && config.dump_primid_path)
primid_tex->Save(*config.dump_primid_path);

if (primid_tex)
Recycle(primid_tex);
}}
Expand Down
Loading
Loading