core/d3d12: pre-bake the fullscreen-quad vertex shader

First end-to-end pre-bake migration off the runtime D3DCompile
path, on top of the scaffolding from ca8c9b0. Picks the smallest
possible target - a single-variant vertex shader with zero state
dependency, used by every non-batch pipeline (vram_fill /
vram_copy / vram_write / vram_update_depth / vram_readback /
display / copy/blit) - to validate the full pipeline before
larger migrations land.

Reasoning for starting here: the screen-quad VS emits a fullscreen
triangle from SV_VertexID via the standard bit-shift trick and
has no #defines or compile-time-baked uniforms, so a single
pre-baked variant covers all seven call sites. Compared to vram_read
(which I evaluated as the first target earlier in this arc):
RESOLUTION_SCALE bakes in compile-time on non-batch shaders via
WriteCommonFunctions, so vram_read would need either one variant
per scale value or a refactor of the runtime to bind the batch
cbuffer to non-batch shaders. That's a real refactor, not a
validation patch. The screen-quad VS sidesteps it entirely.

Files in this patch:

* data/shaders/d3d12/fullscreen_quad.vs.hlsl - standalone HLSL
  equivalent to what ShaderGen::GenerateScreenQuadVertexShader()
  produces in D3D12 mode after preprocessor expansion. Stripped
  the shadergen prelude (#define HLSL 1, #define vec2 float2,
  the SAMPLE_TEXTURE / LOAD_TEXTURE / FOR_UNROLL macros, the API_*
  defines) because the shader uses none of them - native HLSL
  is what fxc wants. Also dropped the dead
  #if API_OPENGL || API_OPENGL_ES || API_VULKAN branch since
  API_OPENGL=0 / API_OPENGL_ES=0 / API_VULKAN=0 for D3D12.

* src/common/d3d12/embedded_shaders.h - replaces the placeholder
  comment block from ca8c9b0 with the first concrete extern
  declaration:

    extern const uint8_t k_fullscreen_quad_vs[];
    extern const size_t k_fullscreen_quad_vs_size_bytes;

  Pattern matches the regen_d3d12_dxbc.py emission convention
  documented in ca8c9b0's commit message.

* src/common/d3d12/embedded_shaders.cpp - replaces its placeholder
  with the first #include of a generated .inc. The .inc itself
  (src/common/d3d12/embedded_dxbc/fullscreen_quad_vs.inc) is
  generated by tools/regen_d3d12_dxbc.py from the .hlsl source
  above. **The .inc is NOT included in this patch** because the
  submission environment doesn't have fxc.exe available. See the
  applying instructions at the bottom of this commit message.

* src/core/gpu_hw_d3d12.h:
  - GetFullscreenQuadVertexShader() return type changed from
    ComPtr<ID3DBlob> to D3D12_SHADER_BYTECODE. The function is no
    longer a lazy-fault helper - the embedded blob is statically
    linked, always available, no allocation. Function comment
    refreshed accordingly.
  - m_fullscreen_quad_vertex_shader member dropped. It was the
    cache slot for the lazy-faulted blob; with pre-bake there's
    no fault-in, no caching state, no mutex.

* src/core/gpu_hw_d3d12.cpp:
  - #include "common/d3d12/embedded_shaders.h" added next to the
    other common/d3d12/ includes.
  - GetFullscreenQuadVertexShader body rewritten to return a
    D3D12_SHADER_BYTECODE aggregate over the embedded blob. No
    mutex, no shader_cache.GetVertexShader, no D3DCompile.
  - Two precompile_sync if-checks removed. The block at line ~956
    used to call GetFullscreenQuadVertexShader() and increment
    progress; the block at line ~1023 used to fault it in for
    Lazy mode. Both meaningless now - the blob is statically
    linked, there is no fault to drive. Left explanatory comments
    at both sites so the absence is documented.
  - Progress unit count updated 18 -> 17. The fullscreen-quad
    VS was one of the 18 non-batch compilation units the
    progress bar ticked through; with pre-bake it has no compile
    step to tick. Inline comment refreshed at both the count
    declaration site (line ~825) and the "1 + 4 + 2 + 2 + 1 + 1
    + 6 + 1 = 18" comment that explained the breakdown.
  - Seven call sites in the GetXxxPipeline helpers converted
    from:
        ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
        if (!vs)
          return {};
        ...
        gpbuilder.SetVertexShader(vs.Get());
    to:
        const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
        ...
        gpbuilder.SetVertexShader(vs.pShaderBytecode,
                                  static_cast<uint32_t>(vs.BytecodeLength));
    The null check is dropped because the embedded blob is never
    null. The cast to uint32_t matches the existing
    SetVertexShader(const void*, uint32_t) overload signature in
    src/common/d3d12/util.h. (A future cleanup could add a
    SetVertexShader(const D3D12_SHADER_BYTECODE&) overload to
    elide the verbose unpacking at call sites; left for the next
    patch in the arc where we'll have several more embedded
    blobs and the savings justify the overload.)
  - m_fullscreen_quad_vertex_shader.Reset() in DestroyPipelines
    dropped. Comment block trimmed accordingly.
  - Stale comment block above GetFullscreenQuadVertexShader
    refreshed to describe pre-bake semantics instead of the
    fault-in pattern that no longer applies.

Applying instructions (the .inc file isn't in this patch, so
build will fail until it lands):

  $ git am 0001-core-d3d12-pre-bake-the-fullscreen-quad-vertex-shader.patch
  $ python3 tools/regen_d3d12_dxbc.py
    # produces src/common/d3d12/embedded_dxbc/fullscreen_quad_vs.inc
  $ git add src/common/d3d12/embedded_dxbc/fullscreen_quad_vs.inc
  $ git commit --amend --no-edit
  $ git push

The amend folds the generated .inc into this commit so upstream
sees a single self-contained patch. (Alternative: commit the .inc
as a separate "regenerate fullscreen_quad_vs.inc" follow-up;
either works, but amending keeps the history one-commit-per-
migration which matches the Vulkan-side convention.)

Cost / behaviour:
  - Cold boot, shader_precompile_mode = Enabled: one fewer
    D3DCompile call, one fewer ID3DBlob allocation. Microseconds
    saved per boot, not user-visible at this scale.
  - Lazy mode pre-fill: same delta.
  - Disabled mode first FillVRAM / etc.: same delta.
  - Runtime: no behaviour change. PSOs that bind the embedded
    blob produce byte-identical bytecode to what D3DCompile would
    have produced from GenerateScreenQuadVertexShader() (modulo
    fxc version compiler-output differences, which the runtime
    cache normalises against anyway).
  - Failure mode: if fxc produces a different shader (e.g. a
    fxc version drift bug), every non-batch pipeline using the
    embedded VS would render incorrectly - blank framebuffer,
    wrong UVs, etc. The visual regression is immediate on first
    frame. Easy to spot.

Test:
  - Cold boot under shader_precompile_mode = Enabled. Progress
    bar reaches 100% (now sized to 17 non-batch units). FillVRAM
    / display / readback / etc. all render correctly.
  - Cold boot under Lazy. Pre-fill happens in the foreground
    before runloop, no nullptr at draw time on the first frame.
  - Cold boot under Disabled. First FillVRAM lazy-faults the
    fill pipeline; the embedded VS is bound, render is correct.
  - Toggle a non_dim setting (multisamples) to force full-flush
    of pipelines. CompilePipelines walks the matrix again,
    rebinds the embedded VS on every non-batch PSO. No leak,
    no use-after-free.
  - Toggle chroma_smoothing to fire the partial-flush branch
    (display pipelines only). Embedded VS is bound on the new
    display PSOs. Display still renders.
  - DestroyPipelines on shutdown / UpdateSettings: no
    m_fullscreen_quad_vertex_shader to Reset; nothing to leak.

Next patch in the arc: extend to non-batch pixel shaders that
don't bake state. vram_copy_ps and vram_update_depth_ps are
the next candidates - both are single-variant and have no
RESOLUTION_SCALE dependency (they sample VRAM coordinates
directly, no box-filter loop). After those, vram_fill_ps (two
variants: wrapped/unwrapped, interlaced/not - 4 total - so
TEMPLATE_VARIANTS gets its first non-empty entry). vram_read
and the batch matrix come later, after we have a cbuffer-
routing migration that lets RESOLUTION_SCALE be runtime-set
in non-batch shaders too.
This commit is contained in:
LibretroAdmin 2026-05-18 17:07:50 +00:00 • committed by U-DESKTOP-SPFP6AQ\twistedtechre
commit dd54a73809
5 changed files with 90 additions and 102 deletions

View file

@ -0,0 +1,20 @@
// Pre-baked fullscreen-quad vertex shader for the D3D12 backend.
//
// Equivalent to ShaderGen::GenerateScreenQuadVertexShader() invoked with
// HostDisplay::RenderAPI::D3D12 in src/core/shadergen.cpp. The runtime
// path goes through D3DCompile on the generated HLSL; the pre-bake path
// embeds the DXBC output of fxc on this source.
//
// No state dependency. The body computes a fullscreen triangle from
// SV_VertexID (0, 1, 2) using the standard bit-shift trick - v_id 0
// emits (0, 0), v_id 1 emits (2, 0), v_id 2 emits (0, 2) in tex-space,
// mapped to NDC by the * float2(2, -2) + float2(-1, 1) transform.
void main(
in uint v_id : SV_VertexID,
out float2 v_tex0 : TEXCOORD0,
out float4 v_pos : SV_Position)
{
v_tex0 = float2(float((v_id << 1) & 2u), float(v_id & 2u));
v_pos = float4(v_tex0 * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
}

View file

@ -17,9 +17,6 @@
// includes and the namespace.
namespace D3D12::EmbeddedShaders {
// (No .inc includes yet - this foundation patch lays down the storage TU.
// Subsequent patches add HLSL sources under data/shaders/d3d12/ and the
// matching generated .inc under src/common/d3d12/embedded_dxbc/, each
// included from inside this namespace block.)
#include "embedded_dxbc/fullscreen_quad_vs.inc"
} // namespace D3D12::EmbeddedShaders

View file

@ -39,9 +39,16 @@
//
namespace D3D12::EmbeddedShaders {
// (No extern declarations yet - this foundation patch lays down the
// directory layout, regen script, and namespace scaffolding. Subsequent
// patches add HLSL sources, generated .inc files, and the matching
// extern declarations here.)
// Fullscreen-quad vertex shader. Emits a fullscreen triangle in NDC
// from SV_VertexID 0..2 via the standard bit-shift trick - equivalent
// to ShaderGen::GenerateScreenQuadVertexShader() in D3D12 mode. Used
// by every non-batch pipeline in the D3D12 backend (vram_fill /
// vram_copy / vram_write / vram_update_depth / vram_readback /
// display / copy). Zero state dependency, so a single pre-baked
// variant covers all call sites.
//
// Source: data/shaders/d3d12/fullscreen_quad.vs.hlsl
extern const uint8_t k_fullscreen_quad_vs[];
extern const size_t k_fullscreen_quad_vs_size_bytes;
} // namespace D3D12::EmbeddedShaders

View file

@ -3,6 +3,7 @@
#include "common/d3d11/shader_compiler.h"
#include "common/d3d12/context.h"
#include "common/d3d12/descriptor_heap_manager.h"
#include "common/d3d12/embedded_shaders.h"
#include "common/d3d12/shader_cache.h"
#include "common/d3d12/util.h"
#include "common/log.h"
@ -822,11 +823,13 @@ bool GPU_HW_D3D12::CompilePipelines()
const uint32_t batch_pipeline_progress_units =
precompile_sync ? reachable_batch_cells * 2u * 5u : 0u;
// Non-batch units only counted when we build them upfront. The
// fullscreen-quad VS (1), VRAM fill (4), VRAM copy (2), VRAM
// write (2), VRAM update depth (1), VRAM readback (1), display
// (6) and copy/blit (1) sum to 18 - one tick per pipeline so the
// progress bar tracks the actual work being done.
const uint32_t non_batch_progress_units = precompile_sync ? 18u : 0u;
// VRAM fill (4), VRAM copy (2), VRAM write (2), VRAM update depth
// (1), VRAM readback (1), display (6) and copy/blit (1) sum to 17
// - one tick per pipeline so the progress bar tracks the actual
// work being done. (Down from 18 since the fullscreen-quad VS no
// longer compiles - statically linked from
// src/common/d3d12/embedded_dxbc/ via GetFullscreenQuadVertexShader.)
const uint32_t non_batch_progress_units = precompile_sync ? 17u : 0u;
ShaderCompileProgressTracker progress("Compiling Pipelines",
2 + batch_shader_progress_units + batch_pipeline_progress_units +
@ -938,12 +941,13 @@ bool GPU_HW_D3D12::CompilePipelines()
// function, after the rest of the non-batch pipelines are built.
// Non-batch pipelines (VRAM fill / copy / write / update depth /
// readback, display, copy/blit, fullscreen-quad VS). On 'Enabled'
// build them all upfront here through the lazy helpers so the
// helpers' GetXxx slot-fill machinery is exercised the same way
// it would be at draw time. The progress bar continues to tick
// per pipeline so the user sees the same "1 + 4 + 2 + 2 + 1 + 1
// + 6 + 1 = 18 unit" count it always did.
// readback, display, copy/blit). On 'Enabled' build them all
// upfront here through the lazy helpers so the helpers' GetXxx
// slot-fill machinery is exercised the same way it would be at
// draw time. The progress bar ticks per pipeline so the user sees
// a "4 + 2 + 2 + 1 + 1 + 6 + 1 = 17 unit" count. (Was 18 before
// the fullscreen-quad VS moved to pre-baked DXBC, which has no
// compilation step to tick for.)
//
// On 'Lazy' the worker thread reaches these via the same helpers
// before walking the batch matrix. On 'Disabled' nothing happens
@ -952,9 +956,11 @@ bool GPU_HW_D3D12::CompilePipelines()
// subsequent calls.
if (precompile_sync)
{
if (!GetFullscreenQuadVertexShader())
return false;
progress.Increment();
// (No fullscreen-quad VS step here - it's pre-baked DXBC now,
// statically linked from src/common/d3d12/embedded_dxbc/, so
// there's nothing to compile or fault in. See
// GetFullscreenQuadVertexShader. Progress unit count below drops
// by 1 accordingly.)
for (uint8_t wrapped = 0; wrapped < 2; wrapped++)
{
@ -1012,15 +1018,15 @@ bool GPU_HW_D3D12::CompilePipelines()
// entire worker run (30-60 seconds) waiting for a lock window
// between compiles. The window appears frozen the whole time.
//
// Pre-filling the 18 non-batch pipelines here costs Lazy the same
// Pre-filling the 17 non-batch pipelines here costs Lazy the same
// few-hundred-ms upfront pause 'Enabled' pays for its non-batch
// section, which is well under a second on the 5090 and not
// perceived as a "frozen" window. The worker then only walks the
// batch matrix - the main thread doesn't generally need batch
// PSOs until a few frames into gameplay, by which point the
// worker is past its first few cells and the wait window is brief.
if (!GetFullscreenQuadVertexShader())
return false;
// (No fullscreen-quad VS pre-fill here either - pre-baked DXBC,
// see GetFullscreenQuadVertexShader.)
for (uint8_t wrapped = 0; wrapped < 2; wrapped++)
{
for (uint8_t interlaced = 0; interlaced < 2; interlaced++)
@ -1410,42 +1416,23 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetBatchPipeline(GPUText
// on a miss. The fast path is one uncontended atomic load per call
// once the slot is filled.
//
// The shared fullscreen-quad vertex shader has its own helper that
// the PSO helpers fall through to. That keeps each fault-in
// self-contained: the very first non-batch helper call from a
// 'Disabled' session pays for the VS compile, every subsequent call
// reuses it.
// The shared fullscreen-quad vertex shader is pre-baked DXBC (see
// GetFullscreenQuadVertexShader and src/common/d3d12/embedded_shaders.h),
// statically linked - no compile, no caching state, no mutex. PSO
// helpers below treat it as a free dependency.
// ----------------------------------------------------------------------
GPU_HW_D3D12::ComPtr<ID3DBlob> GPU_HW_D3D12::GetFullscreenQuadVertexShader()
D3D12_SHADER_BYTECODE GPU_HW_D3D12::GetFullscreenQuadVertexShader()
{
// Single-slot variant of the fast/slow path. Fast path: read the
// ComPtr under the lock (cheap - just a pointer copy + AddRef).
// Slow path: compile WITHOUT the lock held (so concurrent
// non-batch helpers can fault other pipelines while one compiles
// the shared VS), then publish under the lock with a double-check.
{
std::lock_guard<std::mutex> lock(m_batch_shader_mutex);
if (m_fullscreen_quad_vertex_shader)
return m_fullscreen_quad_vertex_shader;
}
if (!m_shadergen)
{
Log_ErrorPrint("GetFullscreenQuadVertexShader called before CompilePipelines constructed the shadergen");
return {};
}
ComPtr<ID3DBlob> fresh = m_shader_cache.GetVertexShader(m_shadergen->GenerateScreenQuadVertexShader());
if (!fresh)
{
Log_ErrorPrint("Lazy fullscreen-quad vertex shader compile failed");
return {};
}
std::lock_guard<std::mutex> lock(m_batch_shader_mutex);
if (!m_fullscreen_quad_vertex_shader)
m_fullscreen_quad_vertex_shader = fresh;
return m_fullscreen_quad_vertex_shader;
// Pre-baked DXBC blob - no compile, no caching state, no mutex. The
// blob is statically linked from src/common/d3d12/embedded_dxbc/
// (generated offline by tools/regen_d3d12_dxbc.py from
// data/shaders/d3d12/fullscreen_quad.vs.hlsl). All callers receive
// the same const view; the storage outlives every PSO that binds it.
return D3D12_SHADER_BYTECODE{
D3D12::EmbeddedShaders::k_fullscreen_quad_vs,
D3D12::EmbeddedShaders::k_fullscreen_quad_vs_size_bytes,
};
}
GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMFillPipeline(uint8_t wrapped, uint8_t interlaced)
@ -1460,9 +1447,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMFillPipeline(uint
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1481,7 +1466,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMFillPipeline(uint
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoBlendingState();
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetMultisamples(m_multisamples);
gpbuilder.SetDepthState(true, true, D3D12_COMPARISON_FUNC_ALWAYS);
@ -1522,9 +1507,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMCopyPipeline(uint
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1542,7 +1525,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMCopyPipeline(uint
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoBlendingState();
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetMultisamples(m_multisamples);
gpbuilder.SetDepthState((depth_test != 0), true,
@ -1583,9 +1566,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMWritePipeline(uin
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1603,7 +1584,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMWritePipeline(uin
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoBlendingState();
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetMultisamples(m_multisamples);
gpbuilder.SetDepthState(true, true,
@ -1643,9 +1624,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMUpdateDepthPipeli
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1669,7 +1648,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMUpdateDepthPipeli
gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetFormat());
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetMultisamples(m_multisamples);
gpbuilder.SetDepthState(true, true, D3D12_COMPARISON_FUNC_ALWAYS);
@ -1710,9 +1689,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMReadbackPipeline(
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1726,7 +1703,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetVRAMReadbackPipeline(
D3D12::GraphicsPipelineBuilder gpbuilder;
gpbuilder.SetRootSignature(m_single_sampler_root_signature.Get());
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoDepthTestState();
@ -1768,9 +1745,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetDisplayPipeline(uint8
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1785,7 +1760,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetDisplayPipeline(uint8
D3D12::GraphicsPipelineBuilder gpbuilder;
gpbuilder.SetRootSignature(m_single_sampler_root_signature.Get());
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoDepthTestState();
@ -1826,9 +1801,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetCopyPipeline()
return ret;
}
ComPtr<ID3DBlob> vs = GetFullscreenQuadVertexShader();
if (!vs)
return {};
const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader();
if (!m_shadergen)
{
@ -1842,7 +1815,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetCopyPipeline()
D3D12::GraphicsPipelineBuilder gpbuilder;
gpbuilder.SetRootSignature(m_single_sampler_root_signature.Get());
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetVertexShader(vs.Get());
gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast<uint32_t>(vs.BytecodeLength));
gpbuilder.SetPixelShader(fs.Get());
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoDepthTestState();
@ -1918,12 +1891,8 @@ void GPU_HW_D3D12::DestroyPipelines()
// m_copy_pipeline was previously not cleared here - latent leak
// across UpdateSettings -> DestroyPipelines -> CompilePipelines
// cycles. The shared fullscreen-quad VS likewise needs to be
// dropped so the next CompilePipelines pass picks up any
// shadergen changes (e.g. the GLSL binding layout differing
// between Vulkan and Direct3D).
// cycles.
m_copy_pipeline.Reset();
m_fullscreen_quad_vertex_shader.Reset();
}
void GPU_HW_D3D12::ClearDisplayPipelines()

View file

@ -179,10 +179,12 @@ private:
// UpdateDisplay / etc. - takes no lock once the slot is filled.
// The single-PSO ones use a bare std::atomic + ComPtr pair.
//
// GetFullscreenQuadVertexShader is shared across most of the
// non-batch pipelines and is hoisted out as a separate helper so
// each PSO compile fetches it via the same lazy-fault pattern.
ComPtr<ID3DBlob> GetFullscreenQuadVertexShader();
// GetFullscreenQuadVertexShader returns the pre-baked DXBC blob for
// the screen-quad VS. No lazy compile, no caching state - the blob
// is statically linked from src/common/d3d12/embedded_dxbc/. Every
// non-batch pipeline in this backend uses it as the VS stage; see
// src/common/d3d12/embedded_shaders.h for the underlying declaration.
D3D12_SHADER_BYTECODE GetFullscreenQuadVertexShader();
ComPtr<ID3D12PipelineState> GetVRAMFillPipeline(uint8_t wrapped, uint8_t interlaced);
ComPtr<ID3D12PipelineState> GetVRAMCopyPipeline(uint8_t depth_test);
ComPtr<ID3D12PipelineState> GetVRAMWritePipeline(uint8_t depth_test);
@ -311,13 +313,6 @@ private:
ComPtr<ID3D12PipelineState> m_copy_pipeline;
std::atomic<ID3D12PipelineState*> m_copy_pipeline_fastpath{nullptr};
// Vertex shader shared across the non-batch pipelines (VRAM read,
// display, copy/blit). Compiled lazily on first use via
// GetFullscreenQuadVertexShader; serialised through
// m_batch_shader_mutex. Used to be a CompilePipelines local that
// was always built at init.
ComPtr<ID3DBlob> m_fullscreen_quad_vertex_shader;
D3D12::Texture m_vram_write_replacement_texture;
D3D12::StreamBuffer m_texture_replacment_stream_buffer;
};