Next single-variant non-batch shader in the D3D12 pre-bake arc, on top of fullscreen_quad_vs (dd54a73+77b255f). Picks the copy/blit fragment shader (GenerateCopyFragmentShader -> bound in GetCopyPipeline, used for full-frame blits during display presentation / downscaling). Why this one and not vram_copy / vram_update_depth / vram_fill / vram_read / display - which were the other candidates on the shortlist: * vram_update_depth: has an MSAA #ifdef split inside the body (LOAD_TEXTURE_MS vs LOAD_TEXTURE) plus a declare_sample_id in DeclareFragmentEntryPoint that depends on UsingMSAA(). So 2 variants minimum, more once we account for the MSAA sample count. * vram_copy: has a PGXP_DEPTH define, plus uses VRAM_SIZE which is compile-time-baked from m_resolution_scale * VRAM_WIDTH/ HEIGHT via the non-batch WriteCommonFunctions path. 2x pgxp_depth times ~5 resolution scale values minimum. * vram_fill: PGXP_DEPTH x wrapped x interlaced plus VRAM_SIZE via the same compile-time-bake path. 4x variants minimum, more after multiplying by resolution scale. * vram_read: VRAM_SIZE / RESOLUTION_SCALE bake-in via WriteCommonFunctions; the inner box-filter loop uses RESOLUTION_SCALE directly as the loop bound, so the variant count is one per scale value (5+). * display: depth_24bit x interlace_mode x smooth_chroma x UsingMSAA x RESOLUTION_SCALE - the multi-variant family with the biggest cost. Each of the above hits one of two structural issues that the infrastructure doesn't address yet: 1. RESOLUTION_SCALE / VRAM_SIZE are baked in compile-time for non-batch shaders via WriteCommonFunctions's batch_uniform_buffer=false path. The cbuffer-routed batch path (post-7b575a3) only applies to batch shaders. Migrating a non-batch shader that references these constants requires either one .inc per resolution scale value, or a refactor that lets non-batch shaders read u_resolution_scale from the cbuffer too. 2. The MSAA dimension multiplies every shader that calls LOAD_TEXTURE_MS in some branch. ShaderGen::GenerateCopyFragmentShader (NOT GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader - this is the plain blit one declared in shadergen.h, not the VRAM-coords copy in gpu_hw_shadergen.cpp) sidesteps all of this: * No WriteCommonFunctions call - so no RESOLUTION_SCALE, no VRAM_SIZE, no MULTISAMPLES bake-in. * No MSAA branch - takes a single Texture2D, not Texture2DMS. * No #define-controlled variants - the source string is identical on every call. * cbuffer-routed source rect (u_src_rect float4) - all runtime state lives in the UBO, none baked. So one pre-baked variant covers every caller. Same shape as fullscreen_quad_vs. Files in this patch: * data/shaders/d3d12/copy.ps.hlsl - standalone HLSL, ~16 lines, native HLSL syntax (no shadergen prelude, no aliases). cbuffer UBOBlock at register(b0), Texture2D samp0 at register(t0) + SamplerState samp0_ss at register(s0), one TEXCOORD0 input, one SV_Target0 output. Same source rect math as the original generated shader. * src/common/d3d12/embedded_dxbc/copy_ps.inc - autogenerated by tools/regen_d3d12_dxbc.py /T ps_5_0 /E main /O3. Generated in this submission environment via Wine's d3dcompiler_47.dll through the fxc_lite shim (see77b255ffor the full toolchain setup). 808 bytes of valid DXBC (magic 0x43425844 / "DXBC", four chunks: ISGN / OSGN / SHEX / STAT). * src/common/d3d12/embedded_shaders.h - extern declarations for k_copy_ps[] and k_copy_ps_size_bytes added below the existing fullscreen_quad_vs pair. Same comment format - documents the shader's role and the no-state-dependency rationale. * src/common/d3d12/embedded_shaders.cpp - second #include line for embedded_dxbc/copy_ps.inc inside the namespace block. Pattern matches what subsequent migrations will follow. * src/core/gpu_hw_d3d12.cpp - GetCopyPipeline body updated: - The ComPtr<ID3DBlob> fs = m_shader_cache.GetPixelShader( m_shadergen->GenerateCopyFragmentShader()) + null check replaced with a const D3D12_SHADER_BYTECODE fs = { ... } aggregate-init over the embedded blob. - The if (!m_shadergen) check is dropped - GetCopyPipeline no longer has any m_shadergen dependency. Other state (root signature, context, shader cache, mutex) was already initialised earlier than m_shadergen in the lifecycle, so removing the m_shadergen check doesn't open a 'called too early' window for this helper. - gpbuilder.SetPixelShader(fs.Get()) becomes gpbuilder.SetPixelShader(fs.pShaderBytecode, static_cast<uint32_t>(fs.BytecodeLength)) matching the existing SetVertexShader call form a few lines above. (Cleanup: a D3D12_SHADER_BYTECODE& overload on SetVertexShader / SetPixelShader in d3d12/util.h would elide the verbose unpack at all call sites - deferred to a follow-up patch so this one stays focused on the shader migration.) Progress unit count unchanged. GetCopyPipeline still costs one progress.Increment call in the precompile_sync block at the 'copy/blit (1)' entry of the 4 + 2 + 2 + 1 + 1 + 6 + 1 = 17 breakdown - the embedded shader removes the D3DCompile work, but the ID3D12Device::CreateGraphicsPipelineState call (the PSO compile) is what the progress tick actually corresponds to, and that still happens. Cost / behaviour: - Cold boot, shader_precompile_mode = Enabled: one fewer D3DCompile per first-touch of GetCopyPipeline (which is hit once per CompilePipelines pass). Combined with fullscreen_quad_vs, that's two non-batch shaders off the D3DCompile path. The bulk of the cold-boot ~1 min cost is still in the batch matrix (1164 cells) - this migration chips at a single non-batch unit, but it's the right next step structurally because it validates the .ps.hlsl side of the pipeline (fullscreen_quad_vs only validated .vs). - Lazy mode: same delta, on first lazy-fault of the copy pipeline. - Disabled: same delta, on first GetCopyPipeline call from the runloop (presentation copy / downscale). - Runtime: no behaviour change. The pre-baked DXBC binds at PSO creation; presentation copies / downscaling renders identically. Failure modes to watch for: - If Wine's d3dcompiler produces semantically different DXBC from Microsoft's fxc.exe for this specific shader (very unlikely given the simplicity - one texture sample, no branching, no flow control), the blit would render incorrectly. Visible immediately as a wrong / blank presentation. Easy to spot. - If the .inc file gets out of sync with copy.ps.hlsl (e.g. someone edits the .hlsl without re-running the regen script), the embedded blob would compile against the old shader source. The autogen header comment in the .inc documents the source it was generated from, and the regen script is idempotent (re-running it on an unchanged .hlsl produces byte-identical output), so getting the two back in sync is just `python3 tools/regen_d3d12_dxbc.py`. Test: - Build under USE_D3D12=1 succeeds. - Cold boot under shader_precompile_mode = Enabled. Progress bar reaches 100% at 17 non-batch units (unchanged). The copy/blit pipeline ticks the same as before; its PSO is built with the embedded PS blob. - Presentation / downscaling render correctly - GetCopyPipeline is called at presentation time from the host display layer. If the embedded PS is wrong, the framebuffer presents wrong on the first frame. - Toggle a non_dim setting (multisamples) to fire the full- flush branch. m_copy_pipeline is Reset() in DestroyPipelines; next CompilePipelines pass re-binds the embedded blob. - Toggle chroma_smoothing for the partial-flush branch - GetCopyPipeline isn't reached (only display pipelines clear), embedded blob undisturbed. Next in the arc: a util.h cleanup adding a SetVertexShader/SetPixelShader(D3D12_SHADER_BYTECODE&) overload so the .pShaderBytecode + static_cast<uint32_t>(.BytecodeLength) boilerplate disappears from call sites. After that, the RESOLUTION_SCALE cbuffer refactor for non-batch shaders opens up vram_copy / vram_update_depth / vram_fill / vram_read - the last single-variant or near-single-variant non-batch shaders before the batch matrix takes the rest of the arc.
25 lines
826 B
HLSL
25 lines
826 B
HLSL
// Pre-baked copy/blit pixel shader for the D3D12 backend.
|
|
//
|
|
// Equivalent to ShaderGen::GenerateCopyFragmentShader() in
|
|
// src/core/shadergen.cpp under HostDisplay::RenderAPI::D3D12. Used
|
|
// by GetCopyPipeline for general full-frame blits (presentation
|
|
// copies, downscaling). No state dependency at all - the shader has
|
|
// no shadergen prelude, no MULTISAMPLING split, no RESOLUTION_SCALE
|
|
// bake-in, and reads its single source rect from the cbuffer at
|
|
// runtime. One pre-baked variant covers every caller.
|
|
|
|
cbuffer UBOBlock : register(b0)
|
|
{
|
|
float4 u_src_rect;
|
|
};
|
|
|
|
Texture2D samp0 : register(t0);
|
|
SamplerState samp0_ss : register(s0);
|
|
|
|
void main(
|
|
in float2 v_tex0 : TEXCOORD0,
|
|
out float4 o_col0 : SV_Target0)
|
|
{
|
|
float2 coords = u_src_rect.xy + v_tex0 * u_src_rect.zw;
|
|
o_col0 = samp0.Sample(samp0_ss, coords);
|
|
}
|