core/d3d12: wire the untextured batch FS pre-bake into the PSO path
Activates the 24 pre-baked DXBC blobs from the preceding commit (9e6f933, "core/d3d12: pre-bake the untextured batch FS slice"). The data + recipe landed there; this commit makes the runtime actually consume them, eliminating D3DCompile from the untextured FS slice of GPU_HW_D3D12::GetBatchPipeline. What changes: src/common/d3d12/embedded_shaders.h 48 new extern declarations covering the 24 batch_untextured_ps_* blobs (a uint8_t array + a size_t pair per blob). Section comment explains the variant axes + the runtime-selection mapping that the call site in gpu_hw_d3d12.cpp performs. src/common/d3d12/embedded_shaders.cpp 24 new #include lines pulling in the .inc files inside the namespace block. Same convention as the existing 77 #include lines for vram_*/display/copy/fullscreen_quad blobs - the .inc files supply both the array *definition* and the size_t value that match the .h's extern *declarations*. src/core/gpu_hw_d3d12.cpp 1. New file-local helper PickBatchUntexturedFSBytecode in an anonymous namespace just above GetBatchFragmentShader. Takes 6 inputs (render_mode + 5 session-level flags), returns the matching D3D12_SHADER_BYTECODE { ptr, size } from a static 4-D table [transparency][dual][interp][persp] of D3D12_SHADER_BYTECODE aggregates. The table is statically initialised from the extern decls in embedded_shaders.h - no runtime construction cost after .so load. The 5 axis mappings match what the regen tool baked (TEMPLATE_VARIANTS in tools/regen_d3d12_dxbc.py): transparency = (BatchRenderMode != TransparencyDisabled) use_dual_source = m_supports_dual_source_blend && ((BatchRenderMode != Disabled && BatchRenderMode != OnlyOpaque) || m_texture_filter != Nearest) interp_idx = m_per_sample_shading ? 2 : (m_multisamples > 1 ? 1 : 0) persp_idx = m_disable_color_perspective ? 1 : 0 Mirror of what GPU_HW_ShaderGen::GenerateBatchFragmentShader bakes at compile time for the untextured slice. 2. GetBatchPipeline restructured around the textured flag. The local fs_blob ComPtr<ID3DBlob> stays allocated only on the textured branch (which still runs the slow GetBatchFragmentShader + D3DCompile + m_batch_fragment_shader_blobs cache write path); on the untextured branch the D3D12_SHADER_BYTECODE comes directly from PickBatchUntexturedFSBytecode with no allocation and no D3DCompile call. SetPixelShader switches from SetPixelShader(ID3DBlob*) to SetPixelShader(D3D12_SHADER_BYTECODE) at the PSO build site - both overloads already exist in src/common/d3d12/util.h. 3. precompile_sync's FS cache-warm loop (the outer one at the top of CompilePipelines) skips GetBatchFragmentShader for texture_mode == Disabled. progress.Increment still ticks on the skipped iteration for visual continuity - the user-facing progress bar reads the same count as pre-pre-bake. Pre-existing PSO-build inner loop is untouched. It calls GetBatchPipeline, which now picks the pre- baked blob inside on the untextured path - so PSO builds for untextured slots still happen (they need to; the FS bytecode source has changed) but the D3DCompile cost is gone. What's NOT affected by this commit: - m_batch_fragment_shader_blobs is dimensioned 9 (texture) x 4 (render) x 7 (filter) = 252 slots. The untextured texture_mode slot (index 7, GPUTextureMode::Disabled) is no longer written to. Reading from it would return a null ComPtr; nothing reads from this dim on the untextured path post-this-commit. The slot count stays 9 so the matrix indexing arithmetic is unchanged for textured slots, which still use it normally. A future cleanup could shrink the dim to 7 (textured-only) once every texture_mode is pre-baked, but the dead slot today wastes 4 * 7 * sizeof(ComPtr<ID3DBlob>) ~ 192 bytes which is below the noise floor. - The 4 textured filter templates (Nearest / Bilinear / JINC2 / xBR) still go through D3DCompile via GetBatchFragmentShader. They land in the next 4 commits of this arc, each one shrinking the runtime D3DCompile surface further. The pre-bake-vs-D3DCompile branch in GetBatchPipeline is the integration point for them - they'll just extend PickBatchUntexturedFSBytecode into a textured analogue (or a per-filter set of them). - m_pgxp_depth_buffer still triggers PSO rebuild on the untextured path - that's the PSO depth-comp LESS_EQUAL vs GREATER_EQUAL state at PSO build time, not a shader source dependency. The FS bytecode is invariant under m_pgxp_depth_buffer post-routing-arc (commits49c0f82,116a70e,dae19ff,f4e1af3) so the pre-baked blob serves both PGXP values; only the PSO itself rebuilds. Behavioural change for users: - First batch of untextured drawcalls in a session no longer triggers a D3DCompile call. With Disabled shader-precompile mode this saves O(20-50ms) per slot on first draw; with Lazy mode the background warm-up finishes O(N untextured slots * 20ms) faster; with Enabled mode the upfront precompile_sync finishes that much sooner. - Cold-launch shader-disk-cache misses for untextured variants: zero, post-this-commit. No on-disk shader cache entries are produced for untextured anymore (PickBatchUntexturedFSBytecode bypasses m_shader_cache.GetPixelShader entirely); existing cache entries from previous versions still hit on the textured slots (the cache hash is per-source-string, so the textured slots' D3DCompile cache hits remain). - DXBC output of fxc /T ps_5_0 /E main /O3 should be bit-identical to what D3DCompile would have produced from the shadergen-emitted HLSL (fxc and D3DCompile share the underlying compiler). Visual diff: zero. Pixel diff: zero. Test: - g++ -std=c++17 -c on src/common/d3d12/embedded_shaders.cpp standalone (with -Isrc) compiles cleanly. The 24 new blobs link in correctly; .o size grows by ~445 KiB to match the per-variant .inc sizes from9e6f933. - g++ -std=c++17 syntax check on PickBatchUntexturedFSBytecode against a shim D3D12_SHADER_BYTECODE / BatchRenderMode / GPUTextureFilter compiles cleanly. - Boot any PSX title on D3D12 default settings (filter= Nearest, no PGXP, no MSAA): the untextured slice is cold; first time it draws, the PSO builds without D3DCompile; the FS DXBC comes from k_batch_untextured_ps_t0d0_none_p0 (transparency=0, dual=0, interp=none, persp=0). Visual output identical to pre-commit. - Boot with MSAA 4x: interp_idx=1 (centroid). Picks k_batch_untextured_ps_t0d0_centroid_p0. - Boot with MSAA 4x + per-sample shading: interp_idx=2 (sample). Picks k_batch_untextured_ps_t0d0_sample_p0. - PGXP-corrected title with PGXP-tex-correction-only (m_disable_color_perspective=true): picks p1 variants instead of p0. - Transparent geometry: TRANSPARENCY=1 variants picked. Fade-in/fade-out cutscenes, semitransparent overlays (e.g. FF7 status menus, MGS smoke). - Filter setting flip Nearest -> Bilinear: dual_source flips from 0 to 1 on TransparencyDisabled / OnlyOpaque render_modes. The pre-baked t*d1_* variants get selected instead of t*d0_*. No D3DCompile fired for the untextured slots. Cumulative D3DCompile elimination progress: Pre-arc: every batch FS draw goes through D3DCompile on cache miss. Post-this-commit: the untextured slice (texture_mode == Disabled, 1 of 9 texture_mode enum values, ~10-15% of typical draw calls on stock PSX content) is fully pre- baked. The remaining 4 textured filter slices land in follow-up commits. Next: - core/d3d12: pre-bake the Nearest filter batch FS slice (textured + no filtering). Will add the second batch HLSL template + the second branch in PickBatchUntexturedFSBytecode-style helper (renamed to PickBatchFSBytecode, probably). - Then Bilinear, JINC2, xBR. - Then a m_batch_fragment_shader_blobs cleanup that shrinks the texture_mode dim from 9 to 7 (or removes the matrix entirely if every variant ends up pre- baked).
This commit is contained in:
parent
9e6f933c98
commit
b6d1903758
3 changed files with 293 additions and 17 deletions
|
|
@ -94,4 +94,29 @@ namespace D3D12::EmbeddedShaders {
|
|||
#include "embedded_dxbc/display_ps_d1i2c1m16.inc"
|
||||
#include "embedded_dxbc/display_ps_d1i2c1m32.inc"
|
||||
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d0_none_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d0_none_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d0_centroid_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d0_centroid_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d0_sample_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d0_sample_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d1_none_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d1_none_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d1_centroid_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d1_centroid_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d1_sample_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t0d1_sample_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d0_none_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d0_none_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d0_centroid_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d0_centroid_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d0_sample_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d0_sample_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d1_none_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d1_none_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d1_centroid_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d1_centroid_p1.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d1_sample_p0.inc"
|
||||
#include "embedded_dxbc/batch_untextured_ps_t1d1_sample_p1.inc"
|
||||
|
||||
} // namespace D3D12::EmbeddedShaders
|
||||
|
|
|
|||
|
|
@ -320,4 +320,90 @@ extern const size_t k_display_ps_d1i2c1m16_size_bytes;
|
|||
extern const uint8_t k_display_ps_d1i2c1m32[];
|
||||
extern const size_t k_display_ps_d1i2c1m32_size_bytes;
|
||||
|
||||
// Batch fragment shader, untextured slice. Equivalent to
|
||||
// GPU_HW_ShaderGen::GenerateBatchFragmentShader invoked with
|
||||
// texture_mode == GPUTextureMode::Disabled. Used by
|
||||
// GPU_HW_D3D12::GetBatchPipeline's untextured branch in place of
|
||||
// the runtime shadergen + D3DCompile path for the same slice. First
|
||||
// batch FS template to be pre-baked; the four textured filter
|
||||
// templates (Nearest / Bilinear / JINC2 / xBR) land in subsequent
|
||||
// commits.
|
||||
//
|
||||
// Variant axes (5, all `-D` to fxc):
|
||||
//
|
||||
// * TRANSPARENCY (0/1): drives premultiply-alpha formula
|
||||
// choice and the output-arm structure.
|
||||
// * USE_DUAL_SOURCE (0/1): controls o_col1 declaration.
|
||||
// * INTERP_CENTROID: emits `centroid` qualifier on inputs.
|
||||
// * INTERP_SAMPLE: emits `sample` qualifier (wins over
|
||||
// INTERP_CENTROID if both set; we never
|
||||
// emit a variant where both are 1).
|
||||
// * NOPERSP (0/1): adds `noperspective` to v_col0.
|
||||
//
|
||||
// 2 (transparency) x 2 (dual) x 3 (interp: none/centroid/sample) x
|
||||
// 2 (persp) = 24 blobs. MSAA cardinality does not multiply this
|
||||
// slice (untextured FS has no LOAD_TEXTURE_MS unroll); the
|
||||
// interpolation qualifier captures the relevant MSAA contribution
|
||||
// via INTERP_CENTROID/INTERP_SAMPLE.
|
||||
//
|
||||
// Runtime selection at the GetBatchPipeline call site:
|
||||
// transparency_idx = (render_mode != BatchRenderMode::TransparencyDisabled) ? 1 : 0
|
||||
// dual_idx = use_dual_source ? 1 : 0 (mirror of
|
||||
// shadergen formula: m_supports_dual_source_blend &&
|
||||
// ((transparency != Disabled && transparency != OnlyOpaque) ||
|
||||
// m_texture_filter != Nearest))
|
||||
// interp_idx = m_per_sample_shading ? 2 :
|
||||
// (m_multisamples > 1 ? 1 : 0)
|
||||
// persp_idx = m_disable_color_perspective ? 1 : 0
|
||||
//
|
||||
// Source: data/shaders/d3d12/batch_untextured.ps.hlsl
|
||||
extern const uint8_t k_batch_untextured_ps_t0d0_none_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t0d0_none_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d0_none_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t0d0_none_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d0_centroid_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t0d0_centroid_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d0_centroid_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t0d0_centroid_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d0_sample_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t0d0_sample_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d0_sample_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t0d0_sample_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d1_none_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t0d1_none_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d1_none_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t0d1_none_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d1_centroid_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t0d1_centroid_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d1_centroid_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t0d1_centroid_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d1_sample_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t0d1_sample_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t0d1_sample_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t0d1_sample_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d0_none_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t1d0_none_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d0_none_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t1d0_none_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d0_centroid_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t1d0_centroid_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d0_centroid_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t1d0_centroid_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d0_sample_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t1d0_sample_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d0_sample_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t1d0_sample_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d1_none_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t1d1_none_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d1_none_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t1d1_none_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d1_centroid_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t1d1_centroid_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d1_centroid_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t1d1_centroid_p1_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d1_sample_p0[];
|
||||
extern const size_t k_batch_untextured_ps_t1d1_sample_p0_size_bytes;
|
||||
extern const uint8_t k_batch_untextured_ps_t1d1_sample_p1[];
|
||||
extern const size_t k_batch_untextured_ps_t1d1_sample_p1_size_bytes;
|
||||
|
||||
} // namespace D3D12::EmbeddedShaders
|
||||
|
|
|
|||
|
|
@ -892,9 +892,20 @@ bool GPU_HW_D3D12::CompilePipelines()
|
|||
if (!IsBatchShaderReachable(static_cast<BatchRenderMode>(render_mode), texture_mode, dual_source))
|
||||
continue;
|
||||
|
||||
ComPtr<ID3DBlob> blob = GetBatchFragmentShader(cur_filter, render_mode, texture_mode);
|
||||
if (!blob)
|
||||
return false;
|
||||
// Pre-baked variants skip the GetBatchFragmentShader cache-
|
||||
// warm step - the bytecode is statically linked, no
|
||||
// D3DCompile to run. Currently the untextured slice is the
|
||||
// only pre-baked template (commits 9e6f933 + this one); the
|
||||
// four textured filter templates are still runtime-compiled
|
||||
// and land in subsequent commits. The progress.Increment
|
||||
// below still ticks for visual continuity so the
|
||||
// user-facing progress bar reads the same as pre-pre-bake.
|
||||
if (static_cast<GPUTextureMode>(texture_mode) != GPUTextureMode::Disabled)
|
||||
{
|
||||
ComPtr<ID3DBlob> blob = GetBatchFragmentShader(cur_filter, render_mode, texture_mode);
|
||||
if (!blob)
|
||||
return false;
|
||||
}
|
||||
progress.Increment();
|
||||
}
|
||||
}
|
||||
|
|
@ -1133,6 +1144,139 @@ void GPU_HW_D3D12::ShaderCompileThreadEntryPoint()
|
|||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Untextured batch FS pre-baked variant picker. Returns the matching
|
||||
// DXBC blob from the 24-entry table at
|
||||
// src/common/d3d12/embedded_dxbc/batch_untextured_ps_*.inc, indexed
|
||||
// by the 5 axes the shadergen used to bake at compile time:
|
||||
//
|
||||
// transparency (BatchRenderMode != TransparencyDisabled)
|
||||
// use_dual_source (BatchRenderMode != Disabled/OnlyOpaque OR
|
||||
// filter != Nearest, capability-gated by
|
||||
// m_supports_dual_source_blend)
|
||||
// interp (per_sample_shading > MSAA > none; mirror of
|
||||
// ShaderGen::GetInterpolationQualifier)
|
||||
// noperspective (m_disable_color_perspective)
|
||||
//
|
||||
// The session-level inputs (filter, supports_dual_source_blend,
|
||||
// multisamples, per_sample_shading, disable_color_perspective) are
|
||||
// fixed for the lifetime of the GetBatchPipeline call - they only
|
||||
// change via UpdateHWSettings which triggers full PSO rebuild. The
|
||||
// per-call input (render_mode) is the BatchRenderMode enum value
|
||||
// the draw is rendering with.
|
||||
static D3D12_SHADER_BYTECODE PickBatchUntexturedFSBytecode(
|
||||
uint8_t render_mode, GPUTextureFilter filter, bool supports_dual_source_blend,
|
||||
uint32_t multisamples, bool per_sample_shading, bool disable_color_perspective)
|
||||
{
|
||||
const bool transparency =
|
||||
(render_mode != static_cast<uint8_t>(BatchRenderMode::TransparencyDisabled));
|
||||
const bool use_dual_source =
|
||||
supports_dual_source_blend &&
|
||||
((render_mode != static_cast<uint8_t>(BatchRenderMode::TransparencyDisabled) &&
|
||||
render_mode != static_cast<uint8_t>(BatchRenderMode::OnlyOpaque)) ||
|
||||
filter != GPUTextureFilter::Nearest);
|
||||
// 0 = none, 1 = centroid, 2 = sample. Mirror of
|
||||
// ShaderGen::GetInterpolationQualifier: sample wins over centroid
|
||||
// when per-sample-shading is enabled.
|
||||
const unsigned interp_idx =
|
||||
per_sample_shading ? 2u : ((multisamples > 1u) ? 1u : 0u);
|
||||
const unsigned persp_idx = disable_color_perspective ? 1u : 0u;
|
||||
|
||||
// 4-D table: [transparency][dual_source][interp][persp]. Nested
|
||||
// brace-init keeps the structural correspondence with the regen
|
||||
// tool's TEMPLATE_VARIANTS table visible to readers - the
|
||||
// outermost-to-innermost iteration order matches the
|
||||
// alphabetical .inc filenames. Each entry is a
|
||||
// D3D12_SHADER_BYTECODE { pShaderBytecode, BytecodeLength }
|
||||
// aggregate; the extern declarations in
|
||||
// src/common/d3d12/embedded_shaders.h supply both halves.
|
||||
static const D3D12_SHADER_BYTECODE k_blobs[2][2][3][2] = {
|
||||
// transparency = 0
|
||||
{
|
||||
// dual = 0
|
||||
{
|
||||
// interp = none
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_none_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_none_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_none_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_none_p1_size_bytes}},
|
||||
// interp = centroid
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_centroid_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_centroid_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_centroid_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_centroid_p1_size_bytes}},
|
||||
// interp = sample
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_sample_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_sample_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_sample_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d0_sample_p1_size_bytes}},
|
||||
},
|
||||
// dual = 1
|
||||
{
|
||||
// interp = none
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_none_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_none_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_none_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_none_p1_size_bytes}},
|
||||
// interp = centroid
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_centroid_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_centroid_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_centroid_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_centroid_p1_size_bytes}},
|
||||
// interp = sample
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_sample_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_sample_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_sample_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t0d1_sample_p1_size_bytes}},
|
||||
},
|
||||
},
|
||||
// transparency = 1
|
||||
{
|
||||
// dual = 0
|
||||
{
|
||||
// interp = none
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_none_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_none_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_none_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_none_p1_size_bytes}},
|
||||
// interp = centroid
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_centroid_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_centroid_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_centroid_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_centroid_p1_size_bytes}},
|
||||
// interp = sample
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_sample_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_sample_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_sample_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d0_sample_p1_size_bytes}},
|
||||
},
|
||||
// dual = 1
|
||||
{
|
||||
// interp = none
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_none_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_none_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_none_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_none_p1_size_bytes}},
|
||||
// interp = centroid
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_centroid_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_centroid_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_centroid_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_centroid_p1_size_bytes}},
|
||||
// interp = sample
|
||||
{{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_sample_p0,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_sample_p0_size_bytes},
|
||||
{D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_sample_p1,
|
||||
D3D12::EmbeddedShaders::k_batch_untextured_ps_t1d1_sample_p1_size_bytes}},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return k_blobs[transparency ? 1 : 0][use_dual_source ? 1 : 0][interp_idx][persp_idx];
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
GPU_HW_D3D12::ComPtr<ID3DBlob> GPU_HW_D3D12::GetBatchFragmentShader(GPUTextureFilter filter, uint8_t render_mode, uint8_t texture_mode)
|
||||
{
|
||||
// Reserved_*Direct16Bit shader-source dedup is applied at the
|
||||
|
|
@ -1269,21 +1413,42 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetBatchPipeline(GPUText
|
|||
return ret;
|
||||
}
|
||||
|
||||
// Slow path. Compile the PSO WITHOUT m_batch_shader_mutex held.
|
||||
// GetBatchFragmentShader is internally thread-safe and so is
|
||||
// m_shader_cache.GetPipelineState (via the per-instance mutexes
|
||||
// added inside D3D12::ShaderCache). The actual D3DCompile and
|
||||
// CreateGraphicsPipelineState calls run lock-free, so the worker
|
||||
// compiling slot A doesn't block the main thread compiling
|
||||
// slot B. Two threads racing to compile the SAME slot is
|
||||
// wasteful but harmless - both produce equivalent PSOs and the
|
||||
// double-check below picks the winner.
|
||||
ComPtr<ID3DBlob> fs_blob = GetBatchFragmentShader(filter, render_mode, lookup_mode);
|
||||
if (!fs_blob)
|
||||
return {};
|
||||
|
||||
// Compile WITHOUT m_batch_shader_mutex held. The shader cache
|
||||
// itself is thread-safe (it has its own internal locking
|
||||
// that does NOT span D3DCompile), so multiple threads can compile
|
||||
// different shaders here in parallel. Two threads compiling the
|
||||
// SAME shader is harmless - both produce identical DXBC and the
|
||||
// cache dedups internally via its own double-check.
|
||||
//
|
||||
// Untextured slice (lookup_mode == GPUTextureMode::Disabled) takes
|
||||
// the pre-baked fast path - PickBatchUntexturedFSBytecode picks
|
||||
// the right .inc-supplied DXBC blob from the 24-variant table.
|
||||
// Textured slices fall through to GetBatchFragmentShader which
|
||||
// does the shadergen + D3DCompile dance and caches via
|
||||
// m_batch_fragment_shader_blobs. The matrix slot for untextured
|
||||
// stays empty across all sessions; nothing reads from it on this
|
||||
// path. As subsequent commits land the 4 textured filter
|
||||
// templates (Nearest / Bilinear / JINC2 / xBR), the textured
|
||||
// branch shrinks until every batch FS variant is pre-baked.
|
||||
const bool textured = (static_cast<GPUTextureMode>(lookup_mode) != GPUTextureMode::Disabled);
|
||||
|
||||
D3D12_SHADER_BYTECODE fs_bc;
|
||||
ComPtr<ID3DBlob> fs_blob; // null on the pre-baked path; held for ref-life otherwise
|
||||
if (textured)
|
||||
{
|
||||
fs_blob = GetBatchFragmentShader(filter, render_mode, lookup_mode);
|
||||
if (!fs_blob)
|
||||
return {};
|
||||
fs_bc.pShaderBytecode = fs_blob->GetBufferPointer();
|
||||
fs_bc.BytecodeLength = fs_blob->GetBufferSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
fs_bc = PickBatchUntexturedFSBytecode(render_mode, filter, m_supports_dual_source_blend,
|
||||
m_multisamples, m_per_sample_shading,
|
||||
m_disable_color_perspective);
|
||||
}
|
||||
|
||||
D3D12::GraphicsPipelineBuilder gpbuilder;
|
||||
gpbuilder.SetRootSignature(m_batch_root_signature.Get());
|
||||
gpbuilder.SetRenderTarget(0, m_vram_texture.GetFormat());
|
||||
|
|
@ -1310,7 +1475,7 @@ GPU_HW_D3D12::ComPtr<ID3D12PipelineState> GPU_HW_D3D12::GetBatchPipeline(GPUText
|
|||
|
||||
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
|
||||
gpbuilder.SetVertexShader(m_batch_vertex_shader_blobs[static_cast<uint8_t>(textured)].Get());
|
||||
gpbuilder.SetPixelShader(fs_blob.Get());
|
||||
gpbuilder.SetPixelShader(fs_bc);
|
||||
|
||||
gpbuilder.SetRasterizationState(D3D12_FILL_MODE_SOLID, D3D12_CULL_MODE_NONE, false);
|
||||
gpbuilder.SetDepthState(true, true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue