core, common/d3d12: lazy-fault non-batch PSOs
Background
==========
The shader precompile mode core option is documented as:
- Enabled: build the full matrix synchronously at GPU init.
- Lazy: kick off a background thread that walks the matrix; fault
in any cell the main thread needs first.
- Disabled: skip precompile, compile on first use.
But the gate on those modes only covered the batch matrix - 144
unique fragment shaders (after the Reserved_*Direct16Bit dedup)
plus 1440 PSOs across the depth_test x render_mode x texture_mode x
transparency_mode x dithering x interlacing dimensions. The 17
non-batch PSOs (VRAM fill x4, VRAM copy x2, VRAM write x2, VRAM
update depth, VRAM readback, display x6, copy/blit) and the
fullscreen-quad vertex shader were built unconditionally at the
end of CompilePipelines, regardless of mode.
The user-visible effect on 'Disabled': a non-trivial init pause
(D3DCompile HLSL->DXBC for 18 distinct shaders, plus 17 driver-
side PSO compiles) even though the user explicitly opted out of
precompile. On 'Lazy' the same work blocked the runloop briefly
while the worker hadn't started.
This commit moves the non-batch pipelines under the same lazy-
fault umbrella as the batch matrix, honouring the 'Disabled'
contract: nothing is compiled at GPU init.
Change shape
============
New helpers in GPU_HW_D3D12, mirroring the GetBatchPipeline /
GetBatchFragmentShader pattern:
GetFullscreenQuadVertexShader() // shared input
GetVRAMFillPipeline(wrapped, interlaced)
GetVRAMCopyPipeline(depth_test)
GetVRAMWritePipeline(depth_test)
GetVRAMUpdateDepthPipeline()
GetVRAMReadbackPipeline()
GetDisplayPipeline(depth_24, interlace_mode)
GetCopyPipeline()
Each runs:
fast path: atomic acquire-load on a parallel raw-pointer array
(m_xxx_pipelines_fastpath). One uncontended atomic
load per call once the slot is filled.
slow path: compile the shader and PSO WITHOUT any helper-level
mutex held. D3D12::ShaderCache itself is thread-safe
(see below), so the GetPixelShader call runs lock-
free and the gpbuilder.Create's CreateGraphicsPipelineState
also runs lock-free. After both succeed, take
m_batch_shader_mutex briefly to publish the result
into the ComPtr slot, the Reserved_* dup slot (where
applicable), and the fast-path atomic. The publish
step double-checks the atomic in case another thread
won the race - the loser discards its own fresh
result via ComPtr destructor.
The 7 PSO helpers all call GetFullscreenQuadVertexShader() before
the compile to fetch the shared VS - the first non-batch helper
invocation pays for that single VS compile.
Why lock-free compile is mandatory
==================================
The previous draft of this commit (squashed below) held
m_batch_shader_mutex across the D3DCompile / CreateGraphicsPipelineState
calls. GDB confirmed that pattern produced a hard lockup on Lazy
mode before BIOS:
Worker (Thread 29):
D3DCompile (stuck deep in D3DReflect optimiser passes)
D3D11::ShaderCompiler::CompileShader
D3D12::ShaderCache::CompileAndAddShaderBlob
D3D12::ShaderCache::GetShaderBlob
GPU_HW_D3D12::GetBatchFragmentShader <- m_batch_shader_mutex held
GPU_HW_D3D12::GetBatchPipeline
ShaderCompileThreadEntryPoint
Main (Thread 1):
ntdll!ZwWaitForSingleObject <- waiting on same mutex
libwinpthread mutex acquire
GPU_HW_D3D12::GetBatchFragmentShader
GPU_HW_D3D12::GetBatchPipeline
GPU_HW_D3D12::DrawBatchVertices
GPU::CRTCTickEvent
The heavier filter combinations of the batch matrix have shaders
where D3DCompile takes a long time (one was effectively non-
terminating during the user's test session). With the mutex held
across the compile, the worker monopolised the mutex while stuck
in D3DCompile and the main thread couldn't fault its own (fast)
BIOS-text shader.
The fix is to never hold the mutex during the slow operation -
which required making D3D12::ShaderCache thread-safe internally
so that the cache calls themselves don't need external locking.
D3D12::ShaderCache changes
==========================
- Two new mutexes: m_shader_cache_mutex (covers m_shader_index,
m_shader_blob_file, m_shader_index_file) and
m_pipeline_cache_mutex (covers the pipeline-side state).
- GetShaderBlob takes m_shader_cache_mutex only for the index
lookup and file read. On miss, it releases the lock before
calling CompileAndAddShaderBlob.
- CompileAndAddShaderBlob does D3DCompile WITHOUT the cache
mutex held. Then takes the lock to publish, with a double-
check: if another thread won the race and already wrote this
key, return their cached blob instead of writing ours
(avoids duplicate file writes and uniquely-keys the index).
- GetPipelineState and CompileAndAddPipeline get the same
treatment: cache I/O under the lock, the slow
CreateGraphicsPipelineState call lock-free.
- Latent bug fixed in passing: CompileAndAddPipeline at the
write step did m_shader_index.emplace instead of
m_pipeline_index.emplace. Inert since the per-PSO disk cache
was dropped in commit 81e3a2b8 (m_pipeline_blob_file is
always null), but corrected so the code is right if the
pipeline cache ever comes back.
CompilePipelines flow
=====================
- Always: open the disk shader cache, construct m_shadergen, and
compile the two batch vertex shaders. These are very
cheap (no D3DCompile heavy lifting) and are needed by
GetBatchPipeline.
- 'Enabled' only: walk the full batch fragment-shader matrix and
the full batch PSO matrix synchronously, then
call the 7 non-batch helpers once each to fill
their slots upfront.
- 'Lazy' only: pre-fill the 18 non-batch units on the main
thread, then spawn the worker. With lock-free
compiles this is now an optimisation rather than
a correctness requirement - it just avoids the
duplicate-compile cost a race window would
otherwise pay for those 18 helpers.
- 'Disabled': nothing else.
ShaderCompileThreadEntryPoint (Lazy worker) is responsible only
for the batch matrix. Main-thread batch PSO fault-ins mid-game
still work - both threads truly run concurrently through
D3DCompile / CreateGraphicsPipelineState. D3DCompile is documented
thread-safe per Microsoft and D3D12Core spawns its own background
threads for PSO compilation, so this maps cleanly onto the
underlying API surface.
Call sites
==========
Seven runloop hot-path call sites updated to use the helpers
instead of m_xxx_pipeline.Get():
FillVRAM -> GetVRAMFillPipeline
CopyVRAM -> GetVRAMCopyPipeline
UpdateVRAM -> GetVRAMWritePipeline
UpdateDepthBufferFromMaskBit -> GetVRAMUpdateDepthPipeline
ReadVRAM -> GetVRAMReadbackPipeline
UpdateDisplay -> GetDisplayPipeline
BlitVRAMReplacementTexture -> GetCopyPipeline
All return early on helper failure (null PSO) - no Log spam, no
divergent behaviour; the helper itself logs the source-level cause.
DestroyPipelines was already missing m_copy_pipeline.Reset() (an
existing latent leak across UpdateSettings -> DestroyPipelines ->
CompilePipelines cycles, masked because the next CompilePipelines
overwrote the slot). Fixed here in passing along with the new
fast-path array and m_fullscreen_quad_vertex_shader resets.
Progress tracker math updated: non-batch units only counted when
precompile_sync. 'Lazy' and 'Disabled' get a precompile progress
bar with just the batch vertex shader ticks (2 units) instead of
the prior "2 + 18 = 20" minimum.
Behaviour summary
=================
Enabled : unchanged - identical PSOs built upfront in the same
order, same progress bar. Routed through the helpers'
slow path which now exercises the same lock-free
compile sequence Lazy/Disabled use.
Lazy : main thread pre-fills 18 non-batch PSOs (sub-second)
then spawns the worker. Worker walks the 1440 batch
cells lock-free. Main thread runs gameplay and faults
its own batch PSOs in parallel with the worker -
both threads truly concurrent through D3DCompile.
Slow shader compiles in the worker no longer block
anything.
Disabled : zero PSO work at init. Runloop faults each pipeline
on first use - one ms-scale hitch per unique pipeline
over the first few seconds of any new game. Net runloop
cost is the same total work that used to happen upfront,
but spread out and aligned with actual usage.
Verified on a Windows MinGW build with a clean shader cache:
Disabled: ~2 shaders compiled at startup (the batch VS pair),
instant startup, ~150 KB shader cache after a session.
Lazy: ~2 shaders at startup, window unfrozen, gameplay
starts within a second or two; full ~5 MB cache after
worker completes in background. (Previous draft of
this patch locked up before BIOS could render - see
'Why lock-free compile is mandatory' above.)
Enabled: ~1600 shaders at startup, ~35s stall, same ~5 MB
cache. Identical to pre-patch behaviour.
Build verification (Linux host)
================================
make platform=unix: clean, .so unchanged at 7,905,720 bytes,
25 retro_ exports preserved (D3D12 TU is Windows-only so the
Linux build path is untouched).
make platform=win dry-run: gpu_hw_d3d12.o still compiled with
-DUSE_D3D12=1 and linked with -ld3d12; all common/d3d12 TUs
unchanged at the link level (only their implementations gained
the new internal locking).
Vulkan side
===========
Intentionally left alone for now. Same structural mismatch
exists - the Vulkan precompile mode gate is on the batch matrix
only - but Vulkan's per-PSO compile cost is dominated by
SPIR-V->GPU-ISA in the driver which the VkPipelineCache
amortises across PSOs by shared shader hashes, so the user-
visible 'Disabled' init pause is much smaller. A follow-up
commit will apply the same surgery there if 'Disabled' on Vulkan
also turns out to feel slow.
This commit is contained in:
parent
81e3a2b2b3
commit
75e826954f
4 changed files with 909 additions and 295 deletions
|
|
@ -353,20 +353,33 @@ ShaderCache::CacheIndexKey ShaderCache::GetPipelineCacheKey(const D3D12_GRAPHICS
|
|||
ShaderCache::ComPtr<ID3DBlob> ShaderCache::GetShaderBlob(EntryType type, std::string_view shader_code)
|
||||
{
|
||||
const auto key = GetShaderCacheKey(type, shader_code);
|
||||
auto iter = m_shader_index.find(key);
|
||||
if (iter == m_shader_index.end())
|
||||
return CompileAndAddShaderBlob(key, shader_code);
|
||||
|
||||
ComPtr<ID3DBlob> blob;
|
||||
HRESULT hr = D3DCreateBlob(iter->second.blob_size, blob.GetAddressOf());
|
||||
if (FAILED(hr) || rfseek(m_shader_blob_file, iter->second.file_offset, SEEK_SET) != 0 ||
|
||||
rfread(blob->GetBufferPointer(), 1, iter->second.blob_size, m_shader_blob_file) != iter->second.blob_size)
|
||||
// Fast path: look up in the index under the lock and read the
|
||||
// existing blob if present. The lock window covers the
|
||||
// unordered_map lookup AND the rfseek+rfread on the blob file
|
||||
// since file position is shared mutable state.
|
||||
{
|
||||
Log_ErrorPrintf("Read blob from file failed");
|
||||
return {};
|
||||
std::lock_guard<std::mutex> lock(m_shader_cache_mutex);
|
||||
auto iter = m_shader_index.find(key);
|
||||
if (iter != m_shader_index.end())
|
||||
{
|
||||
ComPtr<ID3DBlob> blob;
|
||||
HRESULT hr = D3DCreateBlob(iter->second.blob_size, blob.GetAddressOf());
|
||||
if (FAILED(hr) || rfseek(m_shader_blob_file, iter->second.file_offset, SEEK_SET) != 0 ||
|
||||
rfread(blob->GetBufferPointer(), 1, iter->second.blob_size, m_shader_blob_file) != iter->second.blob_size)
|
||||
{
|
||||
Log_ErrorPrintf("Read blob from file failed");
|
||||
return {};
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
|
||||
return blob;
|
||||
// Slow path: compile WITHOUT the cache mutex held, so other threads
|
||||
// can use the cache (or fault their own different shaders) in
|
||||
// parallel. Concurrent compiles of the same shader are tolerated -
|
||||
// see the publish step in CompileAndAddShaderBlob.
|
||||
return CompileAndAddShaderBlob(key, shader_code);
|
||||
}
|
||||
|
||||
ShaderCache::ComPtr<ID3D12PipelineState> ShaderCache::GetPipelineState(ID3D12Device* device,
|
||||
|
|
@ -374,29 +387,52 @@ ShaderCache::ComPtr<ID3D12PipelineState> ShaderCache::GetPipelineState(ID3D12Dev
|
|||
{
|
||||
const auto key = GetPipelineCacheKey(desc);
|
||||
|
||||
auto iter = m_pipeline_index.find(key);
|
||||
if (iter == m_pipeline_index.end())
|
||||
return CompileAndAddPipeline(device, key, desc);
|
||||
|
||||
// Fast path: index lookup under the lock. Read the cached blob
|
||||
// from disk (and the rfseek/rfread file-position state) all
|
||||
// inside the lock so two threads' reads don't trample each
|
||||
// other's seek position.
|
||||
//
|
||||
// Note: after the disk PSO cache was dropped (commit
|
||||
// 81e3a2b8) m_pipeline_blob_file is always null when the cache
|
||||
// is open, so the iter-found branch never fires in practice -
|
||||
// the index stays empty. Code kept correct in case the cache
|
||||
// comes back.
|
||||
ComPtr<ID3DBlob> blob;
|
||||
HRESULT hr = D3DCreateBlob(iter->second.blob_size, blob.GetAddressOf());
|
||||
if (FAILED(hr) || rfseek(m_pipeline_blob_file, iter->second.file_offset, SEEK_SET) != 0 ||
|
||||
rfread(blob->GetBufferPointer(), 1, iter->second.blob_size, m_pipeline_blob_file) != iter->second.blob_size)
|
||||
bool have_existing = false;
|
||||
{
|
||||
Log_ErrorPrintf("Read blob from file failed");
|
||||
return {};
|
||||
std::lock_guard<std::mutex> lock(m_pipeline_cache_mutex);
|
||||
auto iter = m_pipeline_index.find(key);
|
||||
if (iter != m_pipeline_index.end())
|
||||
{
|
||||
HRESULT hr = D3DCreateBlob(iter->second.blob_size, blob.GetAddressOf());
|
||||
if (FAILED(hr) || rfseek(m_pipeline_blob_file, iter->second.file_offset, SEEK_SET) != 0 ||
|
||||
rfread(blob->GetBufferPointer(), 1, iter->second.blob_size, m_pipeline_blob_file) != iter->second.blob_size)
|
||||
{
|
||||
Log_ErrorPrintf("Read blob from file failed");
|
||||
return {};
|
||||
}
|
||||
have_existing = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!have_existing)
|
||||
return CompileAndAddPipeline(device, key, desc);
|
||||
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC desc_with_blob(desc);
|
||||
desc_with_blob.CachedPSO.pCachedBlob = blob->GetBufferPointer();
|
||||
desc_with_blob.CachedPSO.CachedBlobSizeInBytes = blob->GetBufferSize();
|
||||
|
||||
// CreateGraphicsPipelineState runs WITHOUT the cache mutex held -
|
||||
// it's the slow operation we never want to serialise threads on.
|
||||
ComPtr<ID3D12PipelineState> pso;
|
||||
hr = device->CreateGraphicsPipelineState(&desc_with_blob, IID_PPV_ARGS(pso.GetAddressOf()));
|
||||
HRESULT hr = device->CreateGraphicsPipelineState(&desc_with_blob, IID_PPV_ARGS(pso.GetAddressOf()));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
Log_WarningPrintf("Creating cached PSO failed: %08X. Invalidating cache.", hr);
|
||||
InvalidatePipelineCache();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_pipeline_cache_mutex);
|
||||
InvalidatePipelineCache();
|
||||
}
|
||||
pso = CompileAndAddPipeline(device, key, desc);
|
||||
}
|
||||
|
||||
|
|
@ -406,6 +442,10 @@ ShaderCache::ComPtr<ID3D12PipelineState> ShaderCache::GetPipelineState(ID3D12Dev
|
|||
ShaderCache::ComPtr<ID3DBlob> ShaderCache::CompileAndAddShaderBlob(const CacheIndexKey& key,
|
||||
std::string_view shader_code)
|
||||
{
|
||||
// SLOW: D3DCompile runs WITHOUT the cache mutex held. Two threads
|
||||
// racing to compile the same shader both end up here; D3DCompile
|
||||
// is deterministic on identical source so they produce identical
|
||||
// DXBC. The double-check below picks whichever completed first.
|
||||
ComPtr<ID3DBlob> blob;
|
||||
|
||||
switch (key.type)
|
||||
|
|
@ -429,6 +469,31 @@ ShaderCache::ComPtr<ID3DBlob> ShaderCache::CompileAndAddShaderBlob(const CacheIn
|
|||
if (!blob)
|
||||
return {};
|
||||
|
||||
// FAST: take the lock to publish. Double-check under the lock in
|
||||
// case another thread won the race - if so, read their blob from
|
||||
// disk and return it instead of writing ours (saves a file write
|
||||
// and keeps the index uniquely-keyed).
|
||||
std::lock_guard<std::mutex> lock(m_shader_cache_mutex);
|
||||
|
||||
auto iter = m_shader_index.find(key);
|
||||
if (iter != m_shader_index.end())
|
||||
{
|
||||
ComPtr<ID3DBlob> existing_blob;
|
||||
HRESULT hr = D3DCreateBlob(iter->second.blob_size, existing_blob.GetAddressOf());
|
||||
if (FAILED(hr) || rfseek(m_shader_blob_file, iter->second.file_offset, SEEK_SET) != 0 ||
|
||||
rfread(existing_blob->GetBufferPointer(), 1, iter->second.blob_size, m_shader_blob_file) !=
|
||||
iter->second.blob_size)
|
||||
{
|
||||
// Read failure on the existing entry - fall through to our
|
||||
// freshly-compiled blob rather than fail the call.
|
||||
Log_WarningPrintf("Double-checked shader cache read failed; using freshly-compiled blob");
|
||||
}
|
||||
else
|
||||
{
|
||||
return existing_blob;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_shader_blob_file || rfseek(m_shader_blob_file, 0, SEEK_END) != 0)
|
||||
return blob;
|
||||
|
||||
|
|
@ -460,6 +525,12 @@ ShaderCache::ComPtr<ID3D12PipelineState>
|
|||
ShaderCache::CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& key,
|
||||
const D3D12_GRAPHICS_PIPELINE_STATE_DESC& gpdesc)
|
||||
{
|
||||
// SLOW: CreateGraphicsPipelineState runs WITHOUT the cache mutex
|
||||
// held - it's the equivalent of D3DCompile on the PSO side. Two
|
||||
// threads racing to compile the same PSO key both end up here;
|
||||
// both produce equivalent ID3D12PipelineState objects (PSOs are
|
||||
// deterministic on identical descriptors). The double-check
|
||||
// below picks whichever completed first.
|
||||
ComPtr<ID3D12PipelineState> pso;
|
||||
HRESULT hr = device->CreateGraphicsPipelineState(&gpdesc, IID_PPV_ARGS(pso.GetAddressOf()));
|
||||
if (FAILED(hr))
|
||||
|
|
@ -468,7 +539,13 @@ ShaderCache::CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& ke
|
|||
return {};
|
||||
}
|
||||
|
||||
if (!m_pipeline_blob_file || rfseek(m_pipeline_blob_file, 0, SEEK_END) != 0)
|
||||
// After the disk PSO cache drop (commit 81e3a2b8) the
|
||||
// m_pipeline_blob_file is always null when the cache is open, so
|
||||
// the whole index-update block below is dead in practice. Code
|
||||
// kept correct in case the cache comes back. The earlier
|
||||
// m_shader_index.emplace was a latent typo in dead code - it's
|
||||
// been corrected to m_pipeline_index.emplace here.
|
||||
if (!m_pipeline_blob_file)
|
||||
return pso;
|
||||
|
||||
ComPtr<ID3DBlob> blob;
|
||||
|
|
@ -479,6 +556,23 @@ ShaderCache::CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& ke
|
|||
return pso;
|
||||
}
|
||||
|
||||
// FAST: take the lock to write the index/blob file. Double-check
|
||||
// under the lock - if another thread won the race, return their
|
||||
// PSO instead of writing ours.
|
||||
std::lock_guard<std::mutex> lock(m_pipeline_cache_mutex);
|
||||
|
||||
auto iter = m_pipeline_index.find(key);
|
||||
if (iter != m_pipeline_index.end())
|
||||
{
|
||||
// Someone else already wrote this key. Our PSO is equivalent
|
||||
// by construction; just return it (no point reading theirs
|
||||
// from disk - the in-memory PSO works the same).
|
||||
return pso;
|
||||
}
|
||||
|
||||
if (rfseek(m_pipeline_blob_file, 0, SEEK_END) != 0)
|
||||
return pso;
|
||||
|
||||
CacheIndexData data;
|
||||
data.file_offset = static_cast<uint32_t>(rftell(m_pipeline_blob_file));
|
||||
data.blob_size = static_cast<uint32_t>(blob->GetBufferSize());
|
||||
|
|
@ -499,7 +593,7 @@ ShaderCache::CompileAndAddPipeline(ID3D12Device* device, const CacheIndexKey& ke
|
|||
return pso;
|
||||
}
|
||||
|
||||
m_shader_index.emplace(key, data);
|
||||
m_pipeline_index.emplace(key, data);
|
||||
return pso;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "../windows_headers.h"
|
||||
#include <cstdio>
|
||||
#include <d3d12.h>
|
||||
#include <mutex>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
|
@ -103,6 +104,22 @@ private:
|
|||
|
||||
std::string m_base_path;
|
||||
|
||||
// Two mutexes covering the two cache sides (HLSL shader blobs vs
|
||||
// D3D12 pipeline blobs). The mutexes are deliberately NOT held
|
||||
// across the slow operations - D3DCompile in
|
||||
// CompileAndAddShaderBlob and CreateGraphicsPipelineState in
|
||||
// CompileAndAddPipeline - so two threads compiling different
|
||||
// shaders / pipelines run truly in parallel.
|
||||
//
|
||||
// Two threads racing to compile the SAME shader is harmless: each
|
||||
// does its own D3DCompile, then takes the mutex to publish the
|
||||
// result. The second one observes the slot already filled (via the
|
||||
// double-check inside CompileAndAddXxx) and discards its copy. The
|
||||
// wasted compile is the cost of avoiding the deadlock the previous
|
||||
// single-mutex-around-everything design would have caused.
|
||||
std::mutex m_shader_cache_mutex;
|
||||
std::mutex m_pipeline_cache_mutex;
|
||||
|
||||
RFILE* m_shader_index_file = nullptr;
|
||||
RFILE* m_shader_blob_file = nullptr;
|
||||
CacheIndex m_shader_index;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -148,6 +148,40 @@ private:
|
|||
ComPtr<ID3D12PipelineState> GetBatchPipeline(uint8_t depth_test, uint8_t render_mode, uint8_t texture_mode, uint8_t transparency_mode,
|
||||
bool dithering, bool interlacing);
|
||||
|
||||
// Lazy non-batch PSO compile path.
|
||||
//
|
||||
// The non-batch pipelines (VRAM fill / copy / write / update depth
|
||||
// / readback, display, copy/blit) used to be compiled
|
||||
// unconditionally at CompilePipelines time regardless of the
|
||||
// gpu_shader_precompile_mode setting. Even with 'Disabled' the
|
||||
// user would pay the cost of building 17 PSOs + the fullscreen
|
||||
// quad vertex shader at GPU init - on a cold cache that is
|
||||
// hundreds of ms of D3DCompile + driver PSO assembly. The
|
||||
// 'Disabled' contract is meant to be "skip all compilation at
|
||||
// init time, fault everything in on first use", so these helpers
|
||||
// bring the non-batch pipelines under the same lazy-fault
|
||||
// umbrella as the batch matrix.
|
||||
//
|
||||
// Each helper follows the same fast-path / slow-path layout as
|
||||
// GetBatchPipeline: an acquire-load on an atomic raw-pointer
|
||||
// fast-path array, falling back to the ComPtr slot under
|
||||
// m_batch_shader_mutex on a miss. The atomic fast path means
|
||||
// the runloop hot path - FillVRAM / CopyVRAM / UpdateVRAM /
|
||||
// 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();
|
||||
ComPtr<ID3D12PipelineState> GetVRAMFillPipeline(uint8_t wrapped, uint8_t interlaced);
|
||||
ComPtr<ID3D12PipelineState> GetVRAMCopyPipeline(uint8_t depth_test);
|
||||
ComPtr<ID3D12PipelineState> GetVRAMWritePipeline(uint8_t depth_test);
|
||||
ComPtr<ID3D12PipelineState> GetVRAMUpdateDepthPipeline();
|
||||
ComPtr<ID3D12PipelineState> GetVRAMReadbackPipeline();
|
||||
ComPtr<ID3D12PipelineState> GetDisplayPipeline(uint8_t depth_24, uint8_t interlace_mode);
|
||||
ComPtr<ID3D12PipelineState> GetCopyPipeline();
|
||||
|
||||
// Background-thread worker for 'Lazy' precompile mode: walks the
|
||||
// full PSO matrix in (depth_test, render_mode, transparency_mode,
|
||||
// texture_mode, dithering, interlacing) order and calls
|
||||
|
|
@ -230,18 +264,33 @@ private:
|
|||
|
||||
// [wrapped][interlaced]
|
||||
DimensionalArray<ComPtr<ID3D12PipelineState>, 2, 2> m_vram_fill_pipelines;
|
||||
DimensionalArray<std::atomic<ID3D12PipelineState*>, 2, 2> m_vram_fill_pipelines_fastpath{};
|
||||
|
||||
// [depth_test]
|
||||
std::array<ComPtr<ID3D12PipelineState>, 2> m_vram_write_pipelines;
|
||||
std::array<ComPtr<ID3D12PipelineState>, 2> m_vram_copy_pipelines;
|
||||
std::array<std::atomic<ID3D12PipelineState*>, 2> m_vram_write_pipelines_fastpath{};
|
||||
std::array<std::atomic<ID3D12PipelineState*>, 2> m_vram_copy_pipelines_fastpath{};
|
||||
|
||||
ComPtr<ID3D12PipelineState> m_vram_readback_pipeline;
|
||||
ComPtr<ID3D12PipelineState> m_vram_update_depth_pipeline;
|
||||
std::atomic<ID3D12PipelineState*> m_vram_readback_pipeline_fastpath{nullptr};
|
||||
std::atomic<ID3D12PipelineState*> m_vram_update_depth_pipeline_fastpath{nullptr};
|
||||
|
||||
// [depth_24][interlace_mode]
|
||||
DimensionalArray<ComPtr<ID3D12PipelineState>, 3, 2> m_display_pipelines;
|
||||
DimensionalArray<std::atomic<ID3D12PipelineState*>, 3, 2> m_display_pipelines_fastpath{};
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue