diff --git a/data/shaders/d3d12/vram_update_depth.ps.hlsl b/data/shaders/d3d12/vram_update_depth.ps.hlsl new file mode 100644 index 00000000..4f64aa80 --- /dev/null +++ b/data/shaders/d3d12/vram_update_depth.ps.hlsl @@ -0,0 +1,64 @@ +// Pre-baked VRAM update-depth pixel shader for the D3D12 backend. +// +// Equivalent to GPU_HW_ShaderGen::GenerateVRAMUpdateDepthFragmentShader() +// in src/core/gpu_hw_shadergen.cpp. Used by +// GPU_HW_D3D12::GetVRAMUpdateDepthPipeline for the depth-only pass +// that propagates the colour-texture alpha channel (which doubles +// as the PSX 16-bit "mask" bit) into the depth buffer after VRAM +// uploads. Hit on every CPU->VRAM upload completion path in +// games that toggle the mask bit (most native rendering, and any +// game's transparency-using sprite layer). +// +// Variant axis: MULTISAMPLING = 0 or 1. Two .inc blobs: +// vram_update_depth_ps_msaa0.inc (MULTISAMPLING = 0) +// vram_update_depth_ps_msaa1.inc (MULTISAMPLING = 1) +// +// First MSAA texture-binding variant exercise. Unlike vram_copy / +// vram_write / vram_fill which only differ in body branches, this +// shader's two variants have different *binding* types: +// +// MSAA=0: Texture2D samp0 (.Load(int3(coords, mip)) form) +// MSAA=1: Texture2DMS samp0 (.Load(coords, sample) form) +// +// SV_SampleIndex is also conditionally declared in the entry point +// for the MSAA path (HLSL forces per-sample shading when a shader +// declares SV_SampleIndex; D3D12 PSO MSAA setting must match the +// shader expectation). The pattern below sets up runtime selection +// in GetVRAMUpdateDepthPipeline using m_multisamples > 1, which is +// the same predicate UsingMSAA() returns in the shadergen path. +// +// This shader has no cbuffer - GenerateVRAMUpdateDepthFragmentShader +// doesn't call DeclareUniformBuffer. v_tex0 is declared but unused +// (the shadergen entry-point template emits texcoord inputs +// unconditionally; matching it here for the input signature alone - +// the optimiser drops the dead read). + +#if MULTISAMPLING + Texture2DMS samp0 : register(t0); + SamplerState samp0_ss : register(s0); +#else + Texture2D samp0 : register(t0); + SamplerState samp0_ss : register(s0); +#endif + +void main( + in float2 v_tex0 : TEXCOORD0, + in float4 v_pos : SV_Position, +#if MULTISAMPLING + in uint f_sample_index : SV_SampleIndex, +#endif + out float o_depth : SV_Depth) +{ +#if MULTISAMPLING + // Per-sample load. f_sample_index is declared by the entry-point + // signature above and ranges 0 .. (samples - 1). HLSL invokes the + // shader once per sample because SV_SampleIndex is present, so + // one Load picks the right sample slice every invocation. + o_depth = samp0.Load(int2(v_pos.xy), f_sample_index).a; +#else + // Mip 0, point fetch. samp0.Load takes (coords.x, coords.y, mip) + // packed in an int3 for non-MS Texture2D. No filtering - this is + // a 1:1 pixel-aligned propagation step, not a resampling pass. + o_depth = samp0.Load(int3(int2(v_pos.xy), 0)).a; +#endif +} diff --git a/src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa0.inc b/src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa0.inc new file mode 100644 index 00000000..7fc4ae43 --- /dev/null +++ b/src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa0.inc @@ -0,0 +1,53 @@ +// Autogenerated from data/shaders/d3d12/vram_update_depth.ps.hlsl. +// DO NOT EDIT. Regenerate with tools/regen_d3d12_dxbc.py. +// fxc /T ps_5_0 /E main /O3 /DMULTISAMPLING=0 +// +// Included inside namespace D3D12::EmbeddedShaders in +// embedded_shaders.cpp. The matching extern declaration lives in +// embedded_shaders.h. + +const uint8_t k_vram_update_depth_ps_msaa0[] = { + 0x44, 0x58, 0x42, 0x43, 0x96, 0x5c, 0x23, 0xde, 0x0e, 0x5b, 0xa1, 0x74, 0x1a, 0x01, 0xe0, 0x3d, + 0x84, 0xd8, 0x7a, 0xb0, 0x01, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, + 0x04, 0x02, 0x00, 0x00, 0x52, 0x44, 0x45, 0x46, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x05, 0xff, 0xff, + 0x00, 0x81, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x52, 0x44, 0x31, 0x31, 0x3c, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x61, 0x6d, 0x70, 0x30, 0x00, 0x4d, 0x69, + 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, + 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, + 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0xab, 0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x03, 0x00, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, + 0x00, 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0xab, 0xab, 0xab, + 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x0e, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x44, 0x65, 0x70, 0x74, 0x68, + 0x00, 0xab, 0xab, 0xab, 0x53, 0x48, 0x45, 0x58, 0xa8, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, + 0x2a, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x00, 0x01, 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x64, 0x20, 0x00, 0x04, 0x32, 0x10, 0x10, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x02, 0x01, 0xc0, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x05, 0x32, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, + 0xc2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x89, + 0xc2, 0x00, 0x00, 0x80, 0x43, 0x55, 0x15, 0x00, 0x12, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x79, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x04, 0x01, 0xc0, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3e, 0x00, 0x00, 0x01, 0x53, 0x54, 0x41, 0x54, 0x94, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +const size_t k_vram_update_depth_ps_msaa0_size_bytes = sizeof(k_vram_update_depth_ps_msaa0); diff --git a/src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa1.inc b/src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa1.inc new file mode 100644 index 00000000..3c2a001b --- /dev/null +++ b/src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa1.inc @@ -0,0 +1,57 @@ +// Autogenerated from data/shaders/d3d12/vram_update_depth.ps.hlsl. +// DO NOT EDIT. Regenerate with tools/regen_d3d12_dxbc.py. +// fxc /T ps_5_0 /E main /O3 /DMULTISAMPLING=1 +// +// Included inside namespace D3D12::EmbeddedShaders in +// embedded_shaders.cpp. The matching extern declaration lives in +// embedded_shaders.h. + +const uint8_t k_vram_update_depth_ps_msaa1[] = { + 0x44, 0x58, 0x42, 0x43, 0x4e, 0x17, 0x16, 0x5a, 0x35, 0x2a, 0x68, 0xbc, 0xd4, 0xf6, 0x72, 0x7c, + 0xc2, 0x21, 0x45, 0x78, 0x01, 0x00, 0x00, 0x00, 0xdc, 0x02, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x44, 0x01, 0x00, 0x00, 0x78, 0x01, 0x00, 0x00, + 0x40, 0x02, 0x00, 0x00, 0x52, 0x44, 0x45, 0x46, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x05, 0xff, 0xff, + 0x00, 0x81, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x52, 0x44, 0x31, 0x31, 0x3c, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x61, 0x6d, 0x70, 0x30, 0x00, 0x4d, 0x69, + 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, + 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, + 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0xab, 0x49, 0x53, 0x47, 0x4e, 0x74, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x03, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, + 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x53, 0x56, 0x5f, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x49, 0x6e, + 0x64, 0x65, 0x78, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x0e, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x44, + 0x65, 0x70, 0x74, 0x68, 0x00, 0xab, 0xab, 0xab, 0x53, 0x48, 0x45, 0x58, 0xc0, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x00, 0x01, 0x58, 0x20, 0x00, 0x04, + 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x64, 0x20, 0x00, 0x04, + 0x32, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x63, 0x08, 0x00, 0x04, + 0x12, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x02, + 0x01, 0xc0, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x05, + 0x32, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x08, 0xc2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2e, 0x00, 0x00, 0x8b, 0x02, 0x01, 0x00, 0x80, 0x43, 0x55, 0x15, 0x00, 0x12, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x79, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0a, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x04, + 0x01, 0xc0, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, + 0x53, 0x54, 0x41, 0x54, 0x94, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +const size_t k_vram_update_depth_ps_msaa1_size_bytes = sizeof(k_vram_update_depth_ps_msaa1); diff --git a/src/common/d3d12/embedded_shaders.cpp b/src/common/d3d12/embedded_shaders.cpp index d812a00f..8a8be086 100644 --- a/src/common/d3d12/embedded_shaders.cpp +++ b/src/common/d3d12/embedded_shaders.cpp @@ -31,5 +31,7 @@ namespace D3D12::EmbeddedShaders { #include "embedded_dxbc/vram_fill_ps_p1w0i1.inc" #include "embedded_dxbc/vram_fill_ps_p1w1i0.inc" #include "embedded_dxbc/vram_fill_ps_p1w1i1.inc" +#include "embedded_dxbc/vram_update_depth_ps_msaa0.inc" +#include "embedded_dxbc/vram_update_depth_ps_msaa1.inc" } // namespace D3D12::EmbeddedShaders diff --git a/src/common/d3d12/embedded_shaders.h b/src/common/d3d12/embedded_shaders.h index 4533453a..a62e17bf 100644 --- a/src/common/d3d12/embedded_shaders.h +++ b/src/common/d3d12/embedded_shaders.h @@ -126,4 +126,24 @@ extern const size_t k_vram_fill_ps_p1w1i0_size_bytes; extern const uint8_t k_vram_fill_ps_p1w1i1[]; extern const size_t k_vram_fill_ps_p1w1i1_size_bytes; +// VRAM update-depth pixel shader. Equivalent to +// GPU_HW_ShaderGen::GenerateVRAMUpdateDepthFragmentShader() in D3D12 +// mode. Used by GPU_HW_D3D12::GetVRAMUpdateDepthPipeline for the +// depth-only pass that propagates colour-texture alpha (the PSX +// mask bit) into the depth buffer after every CPU->VRAM upload. +// +// First MSAA texture-binding variant. The msaa0 / msaa1 blobs +// differ in the binding type (Texture2D vs Texture2DMS), +// the body Load form, and the presence of SV_SampleIndex in the +// entry-point signature. Runtime selection uses m_multisamples > 1 +// (same predicate as the shadergen UsingMSAA() helper) so the +// shader's per-sample-shading expectation matches the PSO's MSAA +// configuration. +// +// Source: data/shaders/d3d12/vram_update_depth.ps.hlsl +extern const uint8_t k_vram_update_depth_ps_msaa0[]; +extern const size_t k_vram_update_depth_ps_msaa0_size_bytes; +extern const uint8_t k_vram_update_depth_ps_msaa1[]; +extern const size_t k_vram_update_depth_ps_msaa1_size_bytes; + } // namespace D3D12::EmbeddedShaders diff --git a/src/core/gpu_hw_d3d12.cpp b/src/core/gpu_hw_d3d12.cpp index 3fdfe643..e5739019 100644 --- a/src/core/gpu_hw_d3d12.cpp +++ b/src/core/gpu_hw_d3d12.cpp @@ -1664,14 +1664,22 @@ GPU_HW_D3D12::ComPtr GPU_HW_D3D12::GetVRAMUpdateDepthPipeli const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader(); - if (!m_shadergen) - { - Log_ErrorPrint("GetVRAMUpdateDepthPipeline called before CompilePipelines constructed the shadergen"); - return {}; - } - ComPtr fs = m_shader_cache.GetPixelShader(m_shadergen->GenerateVRAMUpdateDepthFragmentShader()); - if (!fs) - return {}; + // Pre-baked DXBC blob - 2 variants on MULTISAMPLING. Unlike the + // PGXP / WRAPPED / INTERLACED axes on the other VRAM ops, MSAA + // here means the two blobs have different *binding* types + // (Texture2D vs Texture2DMS) plus a conditional + // SV_SampleIndex input. The PSO's MSAA configuration must match + // the shader's expectation - we pick the msaa1 blob when + // m_multisamples > 1 (the same predicate the shadergen path's + // UsingMSAA() helper uses). gpbuilder.SetMultisamples below + // continues to drive the PSO MSAA state from m_multisamples + // unchanged. + const D3D12_SHADER_BYTECODE fs = + (m_multisamples > 1) + ? D3D12_SHADER_BYTECODE{D3D12::EmbeddedShaders::k_vram_update_depth_ps_msaa1, + D3D12::EmbeddedShaders::k_vram_update_depth_ps_msaa1_size_bytes} + : D3D12_SHADER_BYTECODE{D3D12::EmbeddedShaders::k_vram_update_depth_ps_msaa0, + D3D12::EmbeddedShaders::k_vram_update_depth_ps_msaa0_size_bytes}; // VRAM update depth differs from the other VRAM ops in three // ways: it uses m_batch_root_signature (the regular ops use the @@ -1687,7 +1695,7 @@ GPU_HW_D3D12::ComPtr GPU_HW_D3D12::GetVRAMUpdateDepthPipeli gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE); gpbuilder.SetNoCullRasterizationState(); gpbuilder.SetVertexShader(vs); - gpbuilder.SetPixelShader(fs.Get()); + gpbuilder.SetPixelShader(fs); gpbuilder.SetMultisamples(m_multisamples); gpbuilder.SetDepthState(true, true, D3D12_COMPARISON_FUNC_ALWAYS); gpbuilder.SetBlendState(0, false, D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD, D3D12_BLEND_ONE, diff --git a/tools/regen_d3d12_dxbc.py b/tools/regen_d3d12_dxbc.py index b63aa752..6de2b37f 100755 --- a/tools/regen_d3d12_dxbc.py +++ b/tools/regen_d3d12_dxbc.py @@ -90,6 +90,18 @@ TEMPLATE_VARIANTS = { ("p1w1i0", ["PGXP_DEPTH=1", "WRAPPED=1", "INTERLACED=0"]), ("p1w1i1", ["PGXP_DEPTH=1", "WRAPPED=1", "INTERLACED=1"]), ], + # vram_update_depth_ps: first MSAA texture-binding variant. Two + # variants on MULTISAMPLING; unlike the body-branch variants + # above, the two blobs have different texture *binding* types + # (Texture2D vs Texture2DMS) plus a conditional + # SV_SampleIndex input on the MSAA path. Runtime selection in + # GetVRAMUpdateDepthPipeline picks between them via + # m_multisamples > 1 (same predicate as the shadergen + # UsingMSAA() helper). + "vram_update_depth.ps.hlsl": [ + ("msaa0", ["MULTISAMPLING=0"]), + ("msaa1", ["MULTISAMPLING=1"]), + ], }