diff --git a/data/shaders/d3d12/copy.ps.hlsl b/data/shaders/d3d12/copy.ps.hlsl new file mode 100644 index 00000000..d8475d8a --- /dev/null +++ b/data/shaders/d3d12/copy.ps.hlsl @@ -0,0 +1,25 @@ +// 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); +} diff --git a/src/common/d3d12/embedded_dxbc/copy_ps.inc b/src/common/d3d12/embedded_dxbc/copy_ps.inc new file mode 100644 index 00000000..182f8c41 --- /dev/null +++ b/src/common/d3d12/embedded_dxbc/copy_ps.inc @@ -0,0 +1,62 @@ +// Autogenerated from data/shaders/d3d12/copy.ps.hlsl. +// DO NOT EDIT. Regenerate with tools/regen_d3d12_dxbc.py. +// fxc /T ps_5_0 /E main /O3 (no /D) +// +// Included inside namespace D3D12::EmbeddedShaders in +// embedded_shaders.cpp. The matching extern declaration lives in +// embedded_shaders.h. + +const uint8_t k_copy_ps[] = { + 0x44, 0x58, 0x42, 0x43, 0x19, 0xeb, 0xec, 0xa1, 0x72, 0x68, 0xaf, 0x90, 0xfb, 0xba, 0xfa, 0xe4, + 0xd2, 0xbe, 0x05, 0x38, 0x01, 0x00, 0x00, 0x00, 0x28, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, + 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, + 0x00, 0xab, 0xab, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x00, 0xab, 0xab, 0x52, 0x44, 0x45, 0x46, 0x64, 0x01, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, + 0x00, 0x05, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x52, 0x44, 0x31, 0x31, + 0x3c, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x73, 0x61, 0x6d, 0x70, + 0x30, 0x5f, 0x73, 0x73, 0x00, 0xab, 0xab, 0xab, 0x73, 0x61, 0x6d, 0x70, 0x30, 0x00, 0xab, 0xab, + 0x55, 0x42, 0x4f, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0xab, 0xab, 0xab, 0xd4, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x55, 0x42, 0x4f, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0xab, 0xab, 0xab, + 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x1c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x73, 0x72, 0x63, 0x5f, 0x72, 0x65, + 0x63, 0x74, 0x00, 0xab, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x00, 0xab, 0x01, 0x00, 0x03, 0x00, + 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0x00, + 0x76, 0x6b, 0x64, 0x33, 0x64, 0x2d, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x31, 0x2e, 0x31, + 0x30, 0x20, 0x28, 0x57, 0x69, 0x6e, 0x65, 0x20, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x64, 0x29, + 0x00, 0xab, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x1c, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, + 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, + 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x05, 0x32, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, + 0xc2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x04, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x05, 0x32, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0xe6, 0x00, 0x10, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0x32, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x32, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x09, + 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, +}; +const size_t k_copy_ps_size_bytes = sizeof(k_copy_ps); diff --git a/src/common/d3d12/embedded_shaders.cpp b/src/common/d3d12/embedded_shaders.cpp index 421d7160..a10e3e23 100644 --- a/src/common/d3d12/embedded_shaders.cpp +++ b/src/common/d3d12/embedded_shaders.cpp @@ -18,5 +18,6 @@ namespace D3D12::EmbeddedShaders { #include "embedded_dxbc/fullscreen_quad_vs.inc" +#include "embedded_dxbc/copy_ps.inc" } // namespace D3D12::EmbeddedShaders diff --git a/src/common/d3d12/embedded_shaders.h b/src/common/d3d12/embedded_shaders.h index 80a74e1a..994a7940 100644 --- a/src/common/d3d12/embedded_shaders.h +++ b/src/common/d3d12/embedded_shaders.h @@ -51,4 +51,15 @@ namespace D3D12::EmbeddedShaders { extern const uint8_t k_fullscreen_quad_vs[]; extern const size_t k_fullscreen_quad_vs_size_bytes; +// Copy/blit pixel shader. Equivalent to +// ShaderGen::GenerateCopyFragmentShader() in D3D12 mode. Single +// texture sample with a cbuffer-driven source rect; zero state +// dependency (no MULTISAMPLING split, no RESOLUTION_SCALE bake-in, +// no preprocessor variant axes). Used by GetCopyPipeline for full- +// frame blits (presentation copies, downscaling). +// +// Source: data/shaders/d3d12/copy.ps.hlsl +extern const uint8_t k_copy_ps[]; +extern const size_t k_copy_ps_size_bytes; + } // namespace D3D12::EmbeddedShaders diff --git a/src/core/gpu_hw_d3d12.cpp b/src/core/gpu_hw_d3d12.cpp index 9a186dc7..1376230f 100644 --- a/src/core/gpu_hw_d3d12.cpp +++ b/src/core/gpu_hw_d3d12.cpp @@ -1803,20 +1803,20 @@ GPU_HW_D3D12::ComPtr GPU_HW_D3D12::GetCopyPipeline() const D3D12_SHADER_BYTECODE vs = GetFullscreenQuadVertexShader(); - if (!m_shadergen) - { - Log_ErrorPrint("GetCopyPipeline called before CompilePipelines constructed the shadergen"); - return {}; - } - ComPtr fs = m_shader_cache.GetPixelShader(m_shadergen->GenerateCopyFragmentShader()); - if (!fs) - return {}; + // Pre-baked DXBC blob, same shape as the VS - statically linked + // from src/common/d3d12/embedded_dxbc/copy_ps.inc, single variant, + // no shader_cache lookup, no D3DCompile, no m_shadergen + // dependency. The PSO compile below is the only remaining work. + const D3D12_SHADER_BYTECODE fs = { + D3D12::EmbeddedShaders::k_copy_ps, + D3D12::EmbeddedShaders::k_copy_ps_size_bytes, + }; D3D12::GraphicsPipelineBuilder gpbuilder; gpbuilder.SetRootSignature(m_single_sampler_root_signature.Get()); gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE); gpbuilder.SetVertexShader(vs.pShaderBytecode, static_cast(vs.BytecodeLength)); - gpbuilder.SetPixelShader(fs.Get()); + gpbuilder.SetPixelShader(fs.pShaderBytecode, static_cast(fs.BytecodeLength)); gpbuilder.SetNoCullRasterizationState(); gpbuilder.SetNoDepthTestState(); gpbuilder.SetNoBlendingState();