core/d3d12: skip batch matrix rebuild on chroma_smoothing-only flip
Final 'unnecessary recompile' in the cbuffer-refactor patch series:
chroma_smoothing is a DefineMacro inside
GenerateDisplayFragmentShader only - it never reaches the batch
FS, the batch VS, or any of the VRAM ops PSOs. But every previous
patch in this series kept it in shader_source_changed, so on
D3D12 a chroma toggle still drove the full DestroyPipelines +
CompilePipelines round trip and walked the ~1164-PSO batch matrix
synchronously when shader_precompile_mode = Enabled. Same
multi-tens-of-seconds pause the user kept hitting.
Add a new narrower out-parameter to GPU_HW::UpdateHWSettings:
display_only_source_changed (default nullptr, opt-in for callers)
It is true only when chroma_smoothing flipped AND nothing else in
the shader-source-affecting set changed. The asymmetric carve-out
is intentional - multisamples / per_sample_shading affect the
VRAM fill / copy / write / update depth non-batch PSOs too (see
the gpbuilder.SetMultisamples calls), so a generic
'non-batch source changed' signal wouldn't actually buy a clean
partial-rebuild path; chroma_smoothing is the one non-batch source
that's truly localised to the display FS. shader_precompile_mode
is excluded for a separate reason - flipping it is a request to
walk the matrix synchronously NOW, which the full destroy +
rebuild correctly handles.
GPU_HW_D3D12::UpdateSettings checks the new signal first inside
the shader_source_changed gate. The display-only branch calls a
new helper, ClearDisplayPipelines, that drops only
m_display_pipelines + m_display_pipelines_fastpath (6 slots, 2x3
over (depth_24, interlace_mode)). The batch matrix, the batch
shader blobs, the VRAM ops PSOs, the copy PSO, and the
fullscreen-quad VS all stay valid because none of them carry
chroma_smoothing as ctor or compile-time state. The next
UpdateDisplay's GetDisplayPipeline lazy-faults each cleared slot
with HLSL re-generated against the new m_chroma_smoothing - which
UpdateHWSettings has already written into the member by the time
ClearDisplayPipelines runs.
UpdateSettings also handles the precompile_mode contract on the
rebuild side now that the partial-clear branch skips
CompilePipelines:
Enabled: pre-fault the six display PSOs synchronously so the
first UpdateDisplay after the toggle doesn't stutter.
Six D3DCompile + six PSO creates run in roughly a
second on a modern GPU.
Lazy: relaunch the background worker that
StopShaderCompileThread joined at the top of
UpdateSettings. The worker only walks the batch
matrix, so it doesn't care about chroma_smoothing -
keeping it stopped after a chroma toggle would just
starve mid-warmup sessions of further background
fill. Display PSOs themselves are faulted on first
use, same as the standing Lazy contract for the
non-batch pipelines.
Disabled: nothing to do - matches 'skip all compilation at
init', display PSOs fault on first use.
The other rebuild branches (only_dim_changed, full destroy) are
unchanged - they're hit only when something the batch matrix
genuinely depends on changed, and the dim-cache / full-flush
paths from 10c53b8 + 418eb14 already do the right thing there.
Vulkan, D3D11, and OpenGL UpdateSettings keep their existing
calls to UpdateHWSettings (no display_only_source_changed param
passed) and therefore keep their existing behaviour - full
destroy + rebuild on chroma_smoothing. The default-nullptr
parameter design means none of them have to change to compile;
optimising those backends for the same case is left as follow-up
work.
Cost matrix after this patch (D3D12, default settings,
shader_precompile_mode = Enabled, ~1164 reachable PSOs):
Toggle Before (10c53b8) After this patch
chroma_smoothing ~1 minute ~1 second
(full matrix walk) (6 display PSOs)
texture_filter (warm) instant unchanged
texture_filter (cold) ~1 minute unchanged
(new sub-cube)
resolution_scale framebuffer resize unchanged
true_color zero unchanged
scaled_dithering zero unchanged
multisamples ~1 minute unchanged (necessary)
per_sample_shading ~1 minute unchanged (necessary)
uv_limits ~1 minute unchanged (necessary)
pgxp_depth ~1 minute unchanged (necessary)
disable_color_persp. ~1 minute unchanged (necessary)
shader_precompile_mode ~1 minute unchanged (intentional)
Every remaining 'still pays' toggle in the matrix is one that
genuinely invalidates batch HLSL across the board; no further
free wins survive in the D3D12 UpdateSettings path.
Test:
- D3D12, shader_precompile = Enabled. Toggle 24-bit chroma
smoothing on / off: ~1 second pause (6 display PSO rebuilds),
no batch matrix progress OSD. Batch draw remains hot - no
stutter on the next frame.
- Same toggle under Lazy: instant. Worker is paused for the
duration of UpdateSettings, then relaunched; display PSOs
lazy-fault on first UpdateDisplay (visible as a single-frame
stutter on the first refresh, identical to Lazy's standing
behaviour for any non-batch PSO).
- Same toggle under Disabled: instant. Display PSOs fault on
first UpdateDisplay.
- Toggle chroma_smoothing AT THE SAME TIME as another setting
(e.g. via batch settings reload): display_only_source_changed
returns false (other_source_diff is true), the only_dim or
full-flush branch fires as before.
This commit is contained in:
parent
10c53b8524
commit
57ac62e792
4 changed files with 118 additions and 9 deletions
|
|
@ -160,7 +160,7 @@ bool GPU_HW::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool u
|
|||
|
||||
void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed,
|
||||
bool* only_dim_changed, bool* downsample_changed,
|
||||
bool* shader_source_changed)
|
||||
bool* shader_source_changed, bool* display_only_source_changed)
|
||||
{
|
||||
const uint32_t resolution_scale = CalculateResolutionScale();
|
||||
const uint32_t multisamples = std::min(m_max_multisamples, g_settings.gpu_multisamples);
|
||||
|
|
@ -259,6 +259,43 @@ void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed,
|
|||
(m_shader_precompile_mode != g_settings.gpu_shader_precompile_mode);
|
||||
}
|
||||
|
||||
// display_only_source_changed: true when shader_source_changed
|
||||
// fired SOLELY because chroma_smoothing flipped, and every other
|
||||
// shader-source-affecting setting stayed put. chroma_smoothing
|
||||
// is the one setting in the shader_source_changed set that
|
||||
// never reaches the batch matrix or the VRAM ops PSOs - it's a
|
||||
// DefineMacro in GenerateDisplayFragmentShader only, see
|
||||
// gpu_hw_shadergen.cpp:1056. Splitting it out lets a backend
|
||||
// service a chroma toggle by invalidating just the 6-slot
|
||||
// display PSO cache and letting it lazy-fault on the next
|
||||
// UpdateDisplay, instead of throwing away the 1164-PSO batch
|
||||
// matrix and 12-or-so non-batch VRAM ops PSOs that don't care.
|
||||
//
|
||||
// The non-batch / batch split here is asymmetric on purpose:
|
||||
// multisamples / per_sample_shading also affect non-batch PSOs
|
||||
// (VRAM fill / copy / write / update depth - see the
|
||||
// gpbuilder.SetMultisamples calls in gpu_hw_d3d12.cpp around
|
||||
// line 1439-1627) so a 'non-batch source changed' signal
|
||||
// wouldn't carve out a clean partial-rebuild path the way
|
||||
// chroma_smoothing does. shader_precompile_mode is similarly
|
||||
// excluded here - a precompile mode flip is a request to walk
|
||||
// the matrix synchronously NOW, which the full
|
||||
// DestroyPipelines + CompilePipelines path handles correctly
|
||||
// and a display-only clear obviously does not.
|
||||
if (display_only_source_changed)
|
||||
{
|
||||
const bool chroma_diff = (m_chroma_smoothing != g_settings.gpu_24bit_chroma_smoothing);
|
||||
const bool other_source_diff =
|
||||
(m_texture_filtering != g_settings.gpu_texture_filter) ||
|
||||
(m_multisamples != multisamples) ||
|
||||
(m_per_sample_shading != per_sample_shading) ||
|
||||
(m_using_uv_limits != use_uv_limits) ||
|
||||
(m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer()) ||
|
||||
(m_disable_color_perspective != disable_color_perspective) ||
|
||||
(m_shader_precompile_mode != g_settings.gpu_shader_precompile_mode);
|
||||
*display_only_source_changed = chroma_diff && !other_source_diff;
|
||||
}
|
||||
|
||||
m_resolution_scale = resolution_scale;
|
||||
m_multisamples = multisamples;
|
||||
m_per_sample_shading = per_sample_shading;
|
||||
|
|
|
|||
|
|
@ -220,7 +220,8 @@ protected:
|
|||
void UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed,
|
||||
bool* only_dim_changed = nullptr,
|
||||
bool* downsample_changed = nullptr,
|
||||
bool* shader_source_changed = nullptr);
|
||||
bool* shader_source_changed = nullptr,
|
||||
bool* display_only_source_changed = nullptr);
|
||||
|
||||
virtual void UpdateVRAMReadTexture();
|
||||
virtual void UpdateDepthBufferFromMaskBit() = 0;
|
||||
|
|
|
|||
|
|
@ -421,8 +421,14 @@ void GPU_HW_D3D12::UpdateSettings()
|
|||
// changed case; when set without shader_source_changed it picks
|
||||
// out the cbuffer-only case (which the gate at the bottom
|
||||
// implicitly handles by checking shader_source_changed).
|
||||
bool framebuffer_changed, shaders_changed, only_dim_changed, shader_source_changed;
|
||||
UpdateHWSettings(&framebuffer_changed, &shaders_changed, &only_dim_changed, nullptr, &shader_source_changed);
|
||||
//
|
||||
// display_only_source_changed: chroma_smoothing flipped and
|
||||
// nothing else affecting shader source changed. The batch matrix
|
||||
// and VRAM ops PSOs stay valid; only the 6-slot display PSO
|
||||
// cache needs to go.
|
||||
bool framebuffer_changed, shaders_changed, only_dim_changed, shader_source_changed, display_only_source_changed;
|
||||
UpdateHWSettings(&framebuffer_changed, &shaders_changed, &only_dim_changed, nullptr, &shader_source_changed,
|
||||
&display_only_source_changed);
|
||||
|
||||
if (framebuffer_changed)
|
||||
{
|
||||
|
|
@ -440,7 +446,48 @@ void GPU_HW_D3D12::UpdateSettings()
|
|||
|
||||
if (shader_source_changed)
|
||||
{
|
||||
if (only_dim_changed)
|
||||
if (display_only_source_changed)
|
||||
{
|
||||
// chroma_smoothing flipped and nothing else - clear just the
|
||||
// display PSO cache; the next UpdateDisplay's
|
||||
// GetDisplayPipeline lazy-faults each (depth_24, interlace_mode)
|
||||
// slot with HLSL re-generated against the new
|
||||
// m_chroma_smoothing. Cost is 6 D3DCompile + 6 PSO creates
|
||||
// (a couple of seconds) instead of the full ~1164-PSO
|
||||
// matrix walk.
|
||||
ClearDisplayPipelines();
|
||||
|
||||
// Honour the precompile_mode contract for the rebuild side:
|
||||
// Enabled: pre-fault the six display PSOs synchronously so
|
||||
// the first UpdateDisplay after the toggle doesn't
|
||||
// stutter. Six D3DCompile + six PSO creates run in
|
||||
// roughly a second on the user's RTX 5090, well
|
||||
// under the multi-tens-of-seconds the full matrix
|
||||
// walk used to take.
|
||||
// Lazy: relaunch the background worker we stopped above
|
||||
// so the batch matrix continues to warm up. The
|
||||
// display PSOs get faulted on first use - same as
|
||||
// Lazy's normal contract for the non-batch
|
||||
// pipelines.
|
||||
// Disabled: no worker, no pre-fault. Display PSOs are
|
||||
// faulted on first use, matching the
|
||||
// "skip all compilation at init" contract.
|
||||
const GPUShaderPrecompileMode precompile_mode = g_settings.gpu_shader_precompile_mode;
|
||||
if (precompile_mode == GPUShaderPrecompileMode::Enabled)
|
||||
{
|
||||
for (uint8_t depth_24 = 0; depth_24 < 2; depth_24++)
|
||||
{
|
||||
for (uint8_t interlace_mode = 0; interlace_mode < 3; interlace_mode++)
|
||||
(void)GetDisplayPipeline(depth_24, interlace_mode);
|
||||
}
|
||||
}
|
||||
else if (precompile_mode == GPUShaderPrecompileMode::Lazy)
|
||||
{
|
||||
m_shader_compile_thread_quit.store(false, std::memory_order_relaxed);
|
||||
m_shader_compile_thread = std::thread(&GPU_HW_D3D12::ShaderCompileThreadEntryPoint, this);
|
||||
}
|
||||
}
|
||||
else if (only_dim_changed)
|
||||
{
|
||||
// Filter changed but nothing in non_dim_diff (and the cbuffer-
|
||||
// only members in dim_diff don't move HLSL, so this is
|
||||
|
|
@ -464,10 +511,10 @@ void GPU_HW_D3D12::UpdateSettings()
|
|||
else
|
||||
{
|
||||
// Full flush: a non-dim shader-affecting change
|
||||
// (multisamples / per-sample shading / UV limits / chroma
|
||||
// smoothing / PGXP depth / colour perspective / precompile
|
||||
// mode) invalidates EVERY sub-cube because those settings
|
||||
// bake into the HLSL identically for every filter slot.
|
||||
// (multisamples / per-sample shading / UV limits / PGXP depth
|
||||
// / colour perspective / precompile mode) invalidates EVERY
|
||||
// sub-cube because those settings bake into the HLSL
|
||||
// identically for every filter slot.
|
||||
DestroyPipelines();
|
||||
CompilePipelines();
|
||||
}
|
||||
|
|
@ -1879,6 +1926,29 @@ void GPU_HW_D3D12::DestroyPipelines()
|
|||
m_fullscreen_quad_vertex_shader.Reset();
|
||||
}
|
||||
|
||||
void GPU_HW_D3D12::ClearDisplayPipelines()
|
||||
{
|
||||
// Partial destroy: drop just the display PSO cache. Used by
|
||||
// UpdateSettings on a chroma_smoothing-only flip - chroma_smoothing
|
||||
// is a DefineMacro inside GenerateDisplayFragmentShader only, so
|
||||
// the batch matrix and the VRAM ops PSOs stay valid. The next
|
||||
// UpdateDisplay call's GetDisplayPipeline will lazy-fault each
|
||||
// (depth_24, interlace_mode) slot with HLSL re-generated against
|
||||
// the new m_chroma_smoothing.
|
||||
//
|
||||
// No StopShaderCompileThread / m_shadergen.reset needed - the
|
||||
// worker only walks the batch matrix, and m_shadergen doesn't
|
||||
// hold chroma_smoothing as ctor state (GenerateDisplayFragmentShader
|
||||
// takes it as a per-call parameter from the member
|
||||
// m_chroma_smoothing, which UpdateHWSettings has already updated by
|
||||
// the time we land here). UpdateSettings has already executed the
|
||||
// command list to completion via g_d3d12_context->ExecuteCommandList(true),
|
||||
// so no in-flight draw references these PSOs.
|
||||
m_display_pipelines_fastpath.enumerate(
|
||||
[](std::atomic<ID3D12PipelineState*>& s) { s.store(nullptr, std::memory_order_relaxed); });
|
||||
m_display_pipelines = {};
|
||||
}
|
||||
|
||||
bool GPU_HW_D3D12::CreateTextureReplacementStreamBuffer()
|
||||
{
|
||||
if (m_texture_replacment_stream_buffer.IsValid())
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ private:
|
|||
|
||||
bool CompilePipelines();
|
||||
void DestroyPipelines();
|
||||
void ClearDisplayPipelines();
|
||||
|
||||
// Lazy batch-fragment-shader-blob + PSO compile path.
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue