core/d3d12: pre-bake the VRAM update-depth pixel shader

First MSAA texture-binding variant pre-bake. Where vram_copy /
vram_write / vram_fill split on PGXP_DEPTH / WRAPPED / INTERLACED
which are body-branch flags only, vram_update_depth_ps splits on
MULTISAMPLING which changes the *binding type* of samp0
(Texture2D vs Texture2DMS<float4>) plus adds a conditional
SV_SampleIndex input to the entry-point signature. This exercises
the indexed-lookup runtime selection in territory that vram_read_ps
and display_ps will need too.

vram_update_depth runs the depth-only pass that propagates colour-
texture alpha (the PSX mask bit) into the depth buffer after every
CPU->VRAM upload. It's hit on every UpdateVRAM completion path in
games that toggle the mask bit, which means most native rendering
plus any title's transparency layer.

Variant axis: MULTISAMPLING on/off only (2 blobs). msaa0 is the
Texture2D path with .Load(int3(coords, mip)) form; msaa1 is the
Texture2DMS<float4> path with .Load(coords, sample) form and
SV_SampleIndex as an additional entry-point input. HLSL forces
per-sample shading on the msaa1 variant because SV_SampleIndex is
declared, so the PSO MSAA configuration (gpbuilder.SetMultisamples)
must match the shader's per-sample expectation - runtime selection
uses m_multisamples > 1 (same predicate as the shadergen
UsingMSAA() helper).

Files added:

* data/shaders/d3d12/vram_update_depth.ps.hlsl: standalone HLSL
  matching GenerateVRAMUpdateDepthFragmentShader's D3D12 output.
  No cbuffer - the shadergen function never calls
  DeclareUniformBuffer. v_tex0 declared but unused (matches the
  shadergen entry-point template which emits texcoord inputs
  unconditionally; the optimiser drops the dead read). #if
  MULTISAMPLING block switches both the binding and the body Load
  form; the SamplerState is declared for both variants to match
  shadergen byte-for-byte (Texture2DMS doesn't need a sampler for
  Load, but the dead binding is free at runtime).

* src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa0.inc:
  DXBC for /DMULTISAMPLING=0 (Texture2D path). 672 bytes.
* src/common/d3d12/embedded_dxbc/vram_update_depth_ps_msaa1.inc:
  DXBC for /DMULTISAMPLING=1 (Texture2DMS<float4> path). 732
  bytes (60B larger for the per-sample shading flag in STAT plus
  the SV_SampleIndex input in ISGN).

Both built with Microsoft fxc; full RDEF/ISGN/OSGN/SHEX/STAT
chunk set; creator stamped "Microsoft (R) HLSL Shader Compiler
10.1". Validator (check_microsoft_creator in
tools/regen_d3d12_dxbc.py) passes both.

Files modified:

* tools/regen_d3d12_dxbc.py: TEMPLATE_VARIANTS gains the
  vram_update_depth.ps.hlsl entry with two rows (msaa0, msaa1).

* src/common/d3d12/embedded_shaders.h: 2 extern declarations
  added. Header docblock explains the MSAA binding-type difference
  vs the body-branch variants above.

* src/common/d3d12/embedded_shaders.cpp: 2 #include lines for
  the new .inc files.

* src/core/gpu_hw_d3d12.cpp GetVRAMUpdateDepthPipeline:
  shadergen call + m_shader_cache.GetPixelShader path replaced
  with a ternary on m_multisamples > 1 picking between the two
  D3D12_SHADER_BYTECODE structs. gpbuilder.SetMultisamples is
  unchanged - it drives the PSO MSAA state from m_multisamples
  directly. The m_shadergen-not-yet-built check is dropped for
  this path since the embedded blobs are statically linked.

The "match the PSO MSAA configuration to the shader expectation"
discipline is the load-bearing piece here. SV_SampleIndex in the
shader forces per-sample shading; the PSO must be configured with
matching MSAA sample count or the runtime will reject PSO creation
(D3D12 PSO validation does cross-check the rasterizer sample count
against the PS expectation). The pattern below scales naturally
to vram_read_ps and display_ps where M (the sample count itself)
also varies.

Cost matrix delta (D3D12) for vram_update_depth_ps:
  Cold-flip multisamples toggle: ~50 ms D3DCompile + ~10 ms PSO
                                 -> ~10 ms PSO only.
  Disk-cache-warm: ~1 ms -> 0 ms.
  Resolution scale toggle: 0 ms (no scale dependency).
  Note: the multisamples toggle itself triggers a much larger
  rebuild cascade (every MSAA-sensitive PSO across the GPU
  matrix), so vram_update_depth_ps's share is small in absolute
  terms - but it's the first proof point for the technique.

The shadergen GenerateVRAMUpdateDepthFragmentShader function is
left intact in gpu_hw_shadergen.cpp - OpenGL / Vulkan / D3D11
still call it through their runtime shader-cache paths. Only
D3D12 bypasses it now.

Test:
  - Build: D3D12 backend links without unresolved symbols.
    Specific risk: a typo in the MSAA-path entry signature would
    surface here (SV_SampleIndex semantic name, ordering vs
    SV_Position).
  - Runtime, MSAA disabled (default): every CPU->VRAM upload
    must continue to propagate mask bits correctly. Test signal:
    any game with mask-bit-using transparent sprites (FF7 spell
    effects, Tekken 3 ring-out smoke, MGS guard-search beams).
    Failure mode: transparency rendering wrong (sprites drawn at
    wrong depth, mask-bit-disabled pixels showing through layers
    that should occlude them).
  - Runtime, MSAA enabled (Multi-Sample Antialiasing core option
    set to 2x / 4x / 8x): same transparency tests, but per-sample
    depth propagation. The msaa1 blob is selected and the PS runs
    once per sample. Failure mode would be MSAA edges around
    transparent sprite boundaries flashing or disappearing because
    per-sample depth wasn't propagated.
  - MSAA toggle (1x -> 4x): triggers full PSO rebuild cascade as
    today. The vram_update_depth_ps portion now picks msaa1
    blob[1] instead of falling through D3DCompile. Cold-flip
    time drops by the D3DCompile share (~50 ms for this one
    shader).
  - Resolution scale toggle: no PSO recompile (blob is scale-
    independent); next UpdateVRAM completion uses the same PSO.

Next per the same template now that MSAA-binding is validated:
vram_read_ps (M MSAA variants on top of the 2980961 cbuffer
routing - first multi-axis MSAA-binding variant), then display_ps
(12xM variants - the prize set).
This commit is contained in:
LibretroAdmin 2026-05-18 21:25:13 +00:00 • committed by U-DESKTOP-SPFP6AQ\twistedtechre
commit 91f8c32ef0
7 changed files with 225 additions and 9 deletions

View file

@ -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<float4> 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<float4> 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
}

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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<float4>),
// 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

View file

@ -1664,14 +1664,22 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMUpdateDepthPipeli
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
Log_ErrorPrint("GetVRAMUpdateDepthPipeline called before CompilePipelines constructed the shadergen");
return {};
}
ComPtr<ID3DBlob> 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<float4>) 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<ID3D12PipelineState> 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,

View file

@ -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<float4>) 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"]),
],
}