core: pre-bake the downsample fragment shaders
Backport of the 4 Vulkan downsample shader templates to HLSL for
the D3D backends. Lands the data + recipe; no C++ wiring yet.
Activation in the next commit swaps the D3D11 backend's runtime
shadergen + D3DCompile calls in GPU_HW_D3D11::CompileShaders for
the matching pre-baked pickers.
D3D12 currently has no downsample implementation - the backend
inherits m_downsample_mode = Disabled and m_supports_adaptive_
downsampling = false from GPU_HW. Adding D3D12 downsample is a
separate phase that will reuse the pre-baked blobs this commit
lands; the d3d_common location (24bacbf) means there is no path-
churn to repeat.
Templates (4 HLSL files, 22 reachable variants total):
data/shaders/d3d12/adaptive_downsample_blur.ps.hlsl
Mirror of mipmap_blur.glsl from parallel-rsx. 3x3 weighted
kernel on the alpha channel of the prior-pass mip. No
variant axes - the body references no compile-time toggles
and no RESOLUTION_SCALE.
-> 1 variant (no /D).
data/shaders/d3d12/adaptive_downsample_mip.ps.hlsl
Mirror of mipmap_energy.glsl from parallel-rsx. Measures
"energy" (variance) across a 2x2 footprint and writes a
scalar bias used by composite to choose mip levels. One
axis:
FIRST_PASS (0/1) - the Vulkan template uses spec const
id=100; HLSL has no spec-constant mechanism so we use
-D FIRST_PASS=1 and fxc dead-strips the unused arm.
-> 2 variants. Suffix f{0,1}.
data/shaders/d3d12/adaptive_downsample_composite.ps.hlsl
Mirror of mipmap_resolve.glsl from parallel-rsx. Reads the
per-pixel mip-bias scalar (samp1, the blur pass output) and
samples the colour pyramid (samp0) at the per-pixel mip
level. One axis:
RESOLUTION_SCALE (integer literal) - drives RCP_VRAM_SIZE
and the mip multiplier. Adaptive mode forces RESOLUTION_SCALE
to a power of 2 in [2, m_max_resolution_scale] via
GPU_HW::CalculateResolutionScale (gpu_hw.cpp:391). With
D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION / VRAM_WIDTH the cap
is 16, so the reachable set is {2, 4, 8, 16}.
-> 4 variants. Suffix s{2,4,8,16}.
data/shaders/d3d12/box_sample_downsample.ps.hlsl
Box-filter downsample - averages a RESOLUTION_SCALE x
RESOLUTION_SCALE block of upscaled texels back down to one
PSX-native-resolution pixel. One axis:
RESOLUTION_SCALE (integer literal) - drives base_coords
scaling, the two inner loop bounds, and the averaging
divisor. Box mode accepts any RESOLUTION_SCALE in
[2, m_max_resolution_scale] (no power-of-2 constraint,
unlike Adaptive); the cap is 16, so the reachable set is
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}.
Scale=1 disables downsampling entirely (GetDownsampleMode
gpu_hw.cpp:399), so we don't bake a variant for it.
-> 15 variants. Suffix s{2..16}.
Each .inc is small. blur is 2292 bytes of DXBC; mip is
1844/1872 bytes per FIRST_PASS arm; composite is 900 bytes per
scale (RESOLUTION_SCALE folds at fxc time to a literal in the
operand encoding without growing the bytecode length); box is
1044 bytes per scale (md5 differs across scales, confirming the
literal is embedded distinctly even though the byte count is
overhead-dominated). Total embedded payload: ~28 KiB across the
22 blobs - negligible compared to the batch FS slices.
The HLSL is API-neutral; the same .inc files serve both D3D11
(which has the runtime downsample path that the activation
commit swaps out) and D3D12 (which has no downsample
implementation yet but inherits the pre-baked blobs for the
follow-up phase). fxc /T ps_5_0 /E main /O3 emits DXBC that
both backends consume identically. The d3d_common location set
up at 24bacbf is the right home for these.
What changes:
data/shaders/d3d12/{adaptive_downsample_blur,
adaptive_downsample_mip,
adaptive_downsample_composite,
box_sample_downsample}.ps.hlsl
4 new files. Each carries a top-of-file comment describing
the Vulkan-side origin, the variant axes (or lack thereof),
bindings (cbuffer / textures / sampler slots), and the
/D macro names with reachable values.
tools/regen_d3d12_dxbc.py
TEMPLATE_VARIANTS gains 3 entries: adaptive_downsample_mip,
adaptive_downsample_composite, box_sample_downsample. Each
entry documents its axes and the reachable variant range.
adaptive_downsample_blur is intentionally NOT listed - it
falls through to the script's no-variants-table fallback
(compile once with no /D defines, emit a single
.inc with the base identifier), which produces the right
output (k_adaptive_downsample_blur_ps).
src/common/d3d_common/embedded_dxbc/
22 new .inc files:
adaptive_downsample_blur_ps.inc (1)
adaptive_downsample_mip_ps_{f0,f1}.inc (2)
adaptive_downsample_composite_ps_{s2,s4,s8,s16}.inc (4)
box_sample_downsample_ps_{s2..s16}.inc (15)
What doesn't change in this commit:
- src/common/d3d_common/embedded_shaders.{h,cpp}: untouched.
No extern declarations for the new blobs yet. Adding them
without consumers would yield -Wunused warnings the build
treats as errors. Both the externs and the picker functions
land together in the activation commit.
- src/core/gpu_hw_d3d11.cpp: untouched. The 5 shadergen calls
in CompileShaders (lines 1203/1205/1207/1209/1220) still go
through shader_cache.GetPixelShader on the runtime
shadergen + D3DCompile path. Activation commit replaces
them with D3DCommon::EmbeddedShaders picker + CreatePixelShader.
- src/core/gpu_hw_d3d12.cpp: untouched. No downsample
implementation exists yet. The D3D12 phase is a separate
project that ports the D3D11 downsample machinery (110 lines
across DownsampleFramebufferAdaptive +
DownsampleFramebufferBoxFilter plus ~50 lines of texture/
view creation in CompileShaders) to D3D12's command-list /
explicit-barrier model, sets m_supports_adaptive_downsampling
= true on the D3D12 SetCapabilities path, and consumes the
pre-baked blobs from this commit.
- Visual output: zero diff. D3D11 still uses runtime D3DCompile;
D3D12 still has no downsample.
Test:
- Hand-compile of representative variants via
/tmp/fxc_lite/fxc_lite.exe /T ps_5_0 /E main /O3:
blur: 2292 bytes (no /D)
mip f0: 1872 bytes (FIRST_PASS=0)
mip f1: 1844 bytes (FIRST_PASS=1)
composite s4: 900 bytes (RESOLUTION_SCALE=4)
composite s16: 900 bytes (RESOLUTION_SCALE=16)
box s2: 1044 bytes
box s8: 1044 bytes
box s16: 1044 bytes
All compile cleanly; no fxc warnings or errors. md5sum
across box scales 2/4/8/16 confirms each scale produces a
distinct DXBC byte sequence (literal RESOLUTION_SCALE is
embedded per variant), not 4 identical blobs.
- python3 tools/regen_d3d12_dxbc.py --fxc /tmp/fxc_lite/fxc_lite.exe
--wine /usr/bin/wine emits 182 .inc files total: 160
pre-existing + 22 downsample. No regressions on the existing
batch FS / display / vram_* blobs - they regenerate
bit-identical (same HLSL, same fxc invocation).
Cumulative pre-bake variant count:
Pre-arc: 75 264 (every axis a -D)
Post-cbuffer-routing arc: 1 176
Post-c01f8ae / a7f5717 (D3D12 batch FS): 84 baked + live
Post-this-commit (downsample blobs on disk): 22 additional baked
(consumers wired in the activation commit)
Next:
- Activation: add 22 new (uint8_t array + size_t) extern pairs
+ #include lines to D3DCommon::EmbeddedShaders, add 4 picker
functions (Box / AdaptiveMip / AdaptiveBlur / AdaptiveComposite),
and rewrite the 5 shadergen calls in GPU_HW_D3D11::CompileShaders
to use the pickers + D3D11::ShaderCompiler::CreatePixelShader.
Same shape as the b6d1903 / a7f5717 batch FS activations.
- Phase 2 (separate effort, not part of the pre-bake arc):
port the D3D11 downsample machinery to D3D12 - PSO builds,
explicit resource barriers, texture/mip-view creation - and
set m_supports_adaptive_downsampling = true on the D3D12
backend. The pre-baked blobs are already in place by then.
2026-05-19 09:08:21 +00:00
|
|
|
// Pre-baked HLSL for
|
|
|
|
|
// GPU_HW_ShaderGen::GenerateBoxSampleDownsampleFragmentShader().
|
|
|
|
|
//
|
|
|
|
|
// Backport of data/shaders/vulkan/box_sample_downsample.frag.glsl
|
|
|
|
|
// to HLSL for the D3D backends. Used when m_downsample_mode = Box:
|
|
|
|
|
// averages a RESOLUTION_SCALE x RESOLUTION_SCALE block of upscaled
|
|
|
|
|
// texels back down to a single PSX-native-resolution pixel.
|
|
|
|
|
//
|
|
|
|
|
// Variant axis (1 dimension, 15 blobs):
|
|
|
|
|
// RESOLUTION_SCALE (-D macro, integer literal). Drives:
|
|
|
|
|
// - base_coords block-origin scaling
|
|
|
|
|
// - the two inner loop bounds (so fxc can unroll at compile
|
|
|
|
|
// time)
|
|
|
|
|
// - the final averaging divisor (RESOLUTION_SCALE^2)
|
|
|
|
|
//
|
|
|
|
|
// The Vulkan template uses spec constant id=0 here; on HLSL we
|
|
|
|
|
// use -D RESOLUTION_SCALE=N at fxc time so the inner loops become
|
|
|
|
|
// fixed-trip-count and fxc fully unrolls them in the DXBC.
|
|
|
|
|
// Reachable values for the Box downsample mode are [2,
|
|
|
|
|
// m_max_resolution_scale]. With D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION
|
|
|
|
|
// = 16384 and VRAM_WIDTH = 1024 the cap is 16, so the reachable
|
|
|
|
|
// set is {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
|
|
|
// -> 15 variants. RESOLUTION_SCALE=1 disables downsampling entirely
|
|
|
|
|
// (see GPU_HW::GetDownsampleMode in gpu_hw.cpp:399) so we don't
|
|
|
|
|
// bake a variant for it.
|
|
|
|
|
//
|
|
|
|
|
// Note on loop unrolling: at scale=16 the inner body runs 256
|
|
|
|
|
// times. fxc unrolls fully when RESOLUTION_SCALE is a literal at
|
|
|
|
|
// /D-time, which is fine for this pass - the downsample runs once
|
|
|
|
|
// per frame, not per drawcall, and the post-c532a34 throughput
|
|
|
|
|
// budget at PSX framerates handles 256 LOAD_TEXTURE ops per
|
|
|
|
|
// downsampled pixel comfortably even at 4K + 16x.
|
|
|
|
|
//
|
|
|
|
|
// Suffix: s{2..16}.
|
|
|
|
|
//
|
|
|
|
|
// Bindings:
|
|
|
|
|
// Texture2D samp0 at register(t0) : high-res render target
|
|
|
|
|
// SamplerState samp0_ss at register(s0)
|
|
|
|
|
//
|
|
|
|
|
// The Box mode does not bind the SmoothingUBOData cbuffer (it's
|
|
|
|
|
// only used by the Adaptive mip / blur / composite passes), so
|
|
|
|
|
// no cbuffer is declared here.
|
|
|
|
|
//
|
core/d3d: fix box downsample PS signature for D3D12 PSO linkage
The pre-baked box_sample_downsample.ps.hlsl declared only
SV_Position as its pixel-shader input. With no preceding TEXCOORD0,
fxc packed SV_Position at input register 0. The fullscreen-quad
vertex shader these PSOs bind emits TEXCOORD0 at output register 0
and SV_Position at output register 1, so on D3D12 the PS input
register 0 had no matching VS output carrying the POSITION system
value. D3D12 links VS-output to PS-input by register at
CreateGraphicsPipelineState time, so the box PSO failed to compile
and the build returned null. UpdateDisplay then bound that null
pipeline (SetPipelineState dereferences its argument), faulting
inside D3D12Core when downsampling was switched on at runtime.
Declare an (unused) TEXCOORD0 input ahead of SV_Position so fxc
packs SV_Position at register 1, matching the vertex shader output
and the display pixel shaders (which likewise keep an unused
TEXCOORD0 at register 0). fxc preserves declared-but-unread inputs
in the signature, so the resolved layout is TEXCOORD0->reg0,
SV_Position->reg1 for every scale variant. This is also what
GenerateBoxSampleDownsampleFragmentShader already emits via
DeclareFragmentEntryPoint(ss, 0, 1, ...). D3D11 was unaffected
because CreatePixelShader does not validate against the bound VS.
Regenerated all 15 box DXBC variants (s2..s16).
2026-05-20 11:29:01 +00:00
|
|
|
// Box composite reads v_pos.xy (SV_Position) and ignores the
|
|
|
|
|
// interpolated texcoord. The unused v_tex0 : TEXCOORD0 input must
|
|
|
|
|
// still be declared FIRST so fxc packs SV_Position at input
|
|
|
|
|
// register 1, matching the fullscreen-quad vertex shader's output
|
|
|
|
|
// signature (TEXCOORD0 -> reg0, SV_Position -> reg1). D3D12's
|
|
|
|
|
// CreateGraphicsPipelineState links VS-output to PS-input by
|
|
|
|
|
// register; if SV_Position landed at PS input register 0 (which
|
|
|
|
|
// happens when TEXCOORD0 is omitted) it would have no matching VS
|
|
|
|
|
// output and PSO creation would fail (returning null). This mirrors
|
|
|
|
|
// GenerateBoxSampleDownsampleFragmentShader's
|
|
|
|
|
// DeclareFragmentEntryPoint(ss, 0, 1, ...) which likewise declares
|
|
|
|
|
// the texcoord, and the display pixel shaders, which keep an unused
|
|
|
|
|
// TEXCOORD0 at reg0 for the same reason. D3D11 tolerated the missing
|
|
|
|
|
// input because CreatePixelShader does not validate against the VS.
|
core: pre-bake the downsample fragment shaders
Backport of the 4 Vulkan downsample shader templates to HLSL for
the D3D backends. Lands the data + recipe; no C++ wiring yet.
Activation in the next commit swaps the D3D11 backend's runtime
shadergen + D3DCompile calls in GPU_HW_D3D11::CompileShaders for
the matching pre-baked pickers.
D3D12 currently has no downsample implementation - the backend
inherits m_downsample_mode = Disabled and m_supports_adaptive_
downsampling = false from GPU_HW. Adding D3D12 downsample is a
separate phase that will reuse the pre-baked blobs this commit
lands; the d3d_common location (24bacbf) means there is no path-
churn to repeat.
Templates (4 HLSL files, 22 reachable variants total):
data/shaders/d3d12/adaptive_downsample_blur.ps.hlsl
Mirror of mipmap_blur.glsl from parallel-rsx. 3x3 weighted
kernel on the alpha channel of the prior-pass mip. No
variant axes - the body references no compile-time toggles
and no RESOLUTION_SCALE.
-> 1 variant (no /D).
data/shaders/d3d12/adaptive_downsample_mip.ps.hlsl
Mirror of mipmap_energy.glsl from parallel-rsx. Measures
"energy" (variance) across a 2x2 footprint and writes a
scalar bias used by composite to choose mip levels. One
axis:
FIRST_PASS (0/1) - the Vulkan template uses spec const
id=100; HLSL has no spec-constant mechanism so we use
-D FIRST_PASS=1 and fxc dead-strips the unused arm.
-> 2 variants. Suffix f{0,1}.
data/shaders/d3d12/adaptive_downsample_composite.ps.hlsl
Mirror of mipmap_resolve.glsl from parallel-rsx. Reads the
per-pixel mip-bias scalar (samp1, the blur pass output) and
samples the colour pyramid (samp0) at the per-pixel mip
level. One axis:
RESOLUTION_SCALE (integer literal) - drives RCP_VRAM_SIZE
and the mip multiplier. Adaptive mode forces RESOLUTION_SCALE
to a power of 2 in [2, m_max_resolution_scale] via
GPU_HW::CalculateResolutionScale (gpu_hw.cpp:391). With
D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION / VRAM_WIDTH the cap
is 16, so the reachable set is {2, 4, 8, 16}.
-> 4 variants. Suffix s{2,4,8,16}.
data/shaders/d3d12/box_sample_downsample.ps.hlsl
Box-filter downsample - averages a RESOLUTION_SCALE x
RESOLUTION_SCALE block of upscaled texels back down to one
PSX-native-resolution pixel. One axis:
RESOLUTION_SCALE (integer literal) - drives base_coords
scaling, the two inner loop bounds, and the averaging
divisor. Box mode accepts any RESOLUTION_SCALE in
[2, m_max_resolution_scale] (no power-of-2 constraint,
unlike Adaptive); the cap is 16, so the reachable set is
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}.
Scale=1 disables downsampling entirely (GetDownsampleMode
gpu_hw.cpp:399), so we don't bake a variant for it.
-> 15 variants. Suffix s{2..16}.
Each .inc is small. blur is 2292 bytes of DXBC; mip is
1844/1872 bytes per FIRST_PASS arm; composite is 900 bytes per
scale (RESOLUTION_SCALE folds at fxc time to a literal in the
operand encoding without growing the bytecode length); box is
1044 bytes per scale (md5 differs across scales, confirming the
literal is embedded distinctly even though the byte count is
overhead-dominated). Total embedded payload: ~28 KiB across the
22 blobs - negligible compared to the batch FS slices.
The HLSL is API-neutral; the same .inc files serve both D3D11
(which has the runtime downsample path that the activation
commit swaps out) and D3D12 (which has no downsample
implementation yet but inherits the pre-baked blobs for the
follow-up phase). fxc /T ps_5_0 /E main /O3 emits DXBC that
both backends consume identically. The d3d_common location set
up at 24bacbf is the right home for these.
What changes:
data/shaders/d3d12/{adaptive_downsample_blur,
adaptive_downsample_mip,
adaptive_downsample_composite,
box_sample_downsample}.ps.hlsl
4 new files. Each carries a top-of-file comment describing
the Vulkan-side origin, the variant axes (or lack thereof),
bindings (cbuffer / textures / sampler slots), and the
/D macro names with reachable values.
tools/regen_d3d12_dxbc.py
TEMPLATE_VARIANTS gains 3 entries: adaptive_downsample_mip,
adaptive_downsample_composite, box_sample_downsample. Each
entry documents its axes and the reachable variant range.
adaptive_downsample_blur is intentionally NOT listed - it
falls through to the script's no-variants-table fallback
(compile once with no /D defines, emit a single
.inc with the base identifier), which produces the right
output (k_adaptive_downsample_blur_ps).
src/common/d3d_common/embedded_dxbc/
22 new .inc files:
adaptive_downsample_blur_ps.inc (1)
adaptive_downsample_mip_ps_{f0,f1}.inc (2)
adaptive_downsample_composite_ps_{s2,s4,s8,s16}.inc (4)
box_sample_downsample_ps_{s2..s16}.inc (15)
What doesn't change in this commit:
- src/common/d3d_common/embedded_shaders.{h,cpp}: untouched.
No extern declarations for the new blobs yet. Adding them
without consumers would yield -Wunused warnings the build
treats as errors. Both the externs and the picker functions
land together in the activation commit.
- src/core/gpu_hw_d3d11.cpp: untouched. The 5 shadergen calls
in CompileShaders (lines 1203/1205/1207/1209/1220) still go
through shader_cache.GetPixelShader on the runtime
shadergen + D3DCompile path. Activation commit replaces
them with D3DCommon::EmbeddedShaders picker + CreatePixelShader.
- src/core/gpu_hw_d3d12.cpp: untouched. No downsample
implementation exists yet. The D3D12 phase is a separate
project that ports the D3D11 downsample machinery (110 lines
across DownsampleFramebufferAdaptive +
DownsampleFramebufferBoxFilter plus ~50 lines of texture/
view creation in CompileShaders) to D3D12's command-list /
explicit-barrier model, sets m_supports_adaptive_downsampling
= true on the D3D12 SetCapabilities path, and consumes the
pre-baked blobs from this commit.
- Visual output: zero diff. D3D11 still uses runtime D3DCompile;
D3D12 still has no downsample.
Test:
- Hand-compile of representative variants via
/tmp/fxc_lite/fxc_lite.exe /T ps_5_0 /E main /O3:
blur: 2292 bytes (no /D)
mip f0: 1872 bytes (FIRST_PASS=0)
mip f1: 1844 bytes (FIRST_PASS=1)
composite s4: 900 bytes (RESOLUTION_SCALE=4)
composite s16: 900 bytes (RESOLUTION_SCALE=16)
box s2: 1044 bytes
box s8: 1044 bytes
box s16: 1044 bytes
All compile cleanly; no fxc warnings or errors. md5sum
across box scales 2/4/8/16 confirms each scale produces a
distinct DXBC byte sequence (literal RESOLUTION_SCALE is
embedded per variant), not 4 identical blobs.
- python3 tools/regen_d3d12_dxbc.py --fxc /tmp/fxc_lite/fxc_lite.exe
--wine /usr/bin/wine emits 182 .inc files total: 160
pre-existing + 22 downsample. No regressions on the existing
batch FS / display / vram_* blobs - they regenerate
bit-identical (same HLSL, same fxc invocation).
Cumulative pre-bake variant count:
Pre-arc: 75 264 (every axis a -D)
Post-cbuffer-routing arc: 1 176
Post-c01f8ae / a7f5717 (D3D12 batch FS): 84 baked + live
Post-this-commit (downsample blobs on disk): 22 additional baked
(consumers wired in the activation commit)
Next:
- Activation: add 22 new (uint8_t array + size_t) extern pairs
+ #include lines to D3DCommon::EmbeddedShaders, add 4 picker
functions (Box / AdaptiveMip / AdaptiveBlur / AdaptiveComposite),
and rewrite the 5 shadergen calls in GPU_HW_D3D11::CompileShaders
to use the pickers + D3D11::ShaderCompiler::CreatePixelShader.
Same shape as the b6d1903 / a7f5717 batch FS activations.
- Phase 2 (separate effort, not part of the pre-bake arc):
port the D3D11 downsample machinery to D3D12 - PSO builds,
explicit resource barriers, texture/mip-view creation - and
set m_supports_adaptive_downsampling = true on the D3D12
backend. The pre-baked blobs are already in place by then.
2026-05-19 09:08:21 +00:00
|
|
|
|
|
|
|
|
#ifndef RESOLUTION_SCALE
|
core: rename data/shaders/d3d12 -> data/shaders/d3d_common
The .inc consumers and the C++ host namespace moved to d3d_common
in 24bacbf, but the HLSL sources and the regen tool kept their
d3d12 tags for "historical / churn-avoidance reasons" - the
commit message there explicitly flagged it as deferred cleanup
("data/shaders/d3d12 -> data/shaders/d3d_common + tool rename.
Currently kept as d3d12 for historical/churn-avoidance
reasons"). With the downsample foundation landed at 251e457
also putting its HLSL under data/shaders/d3d12/ (despite being
consumed only by D3D11 today, with D3D12 consumption arriving
in a later phase), the naming inconsistency is now actively
confusing. This commit completes the rename.
What changes (mechanically, via git mv + sweep):
data/shaders/d3d12/ -> data/shaders/d3d_common/
Whole directory renames via git mv. 16 files move:
README.md + 10 .hlsl source templates (5 batch + display +
copy + vram_{copy,fill,read,update_depth,write} +
fullscreen_quad + 4 downsample). Each .hlsl content
is unchanged except where a comment string referenced the
old path (3 files: box_sample_downsample.ps.hlsl,
adaptive_downsample_composite.ps.hlsl, vram_fill.ps.hlsl).
tools/regen_d3d12_dxbc.py -> tools/regen_d3d_common_dxbc.py
Renamed via git mv. The HLSL_DIR constant repointed to the
new HLSL directory; the .inc preamble template updated to
emit the new paths; the top-of-file comment updated to
drop the "kept as d3d12 for historical reasons" note now
that it doesn't apply. Behaviour unchanged: same HLSL ->
fxc /T ps_5_0 /E main /O3 -> same .inc bytes.
src/common/d3d_common/embedded_dxbc/*.inc (182 files)
Preamble line 1 updated:
// Autogenerated from data/shaders/d3d12/<name>.hlsl.
-> // Autogenerated from data/shaders/d3d_common/<name>.hlsl.
Preamble line 2 updated:
// DO NOT EDIT. Regenerate with tools/regen_d3d12_dxbc.py.
-> // DO NOT EDIT. Regenerate with tools/regen_d3d_common_dxbc.py.
The byte arrays themselves are bit-identical pre/post-commit
(fxc emits identical DXBC from the same HLSL source). Only
the two comment lines of each .inc change.
src/common/d3d_common/embedded_shaders.h
14 doc comments updated:
"// Source: data/shaders/d3d12/<name>.hlsl"
-> "// Source: data/shaders/d3d_common/<name>.hlsl"
Plus the top-of-file rationale block updated to drop the
d3d12-tagged path reference.
src/core/gpu_hw_d3d12.cpp
Two comment lines referencing the old data/shaders/d3d12/
path and the old regen tool name. The pre-bake call sites
themselves were already namespace-qualified (D3DCommon::
EmbeddedShaders::*) and need no change.
data/shaders/d3d_common/README.md
8 doc references to the old paths updated.
What doesn't change in this commit:
- DXBC byte content. fxc is deterministic on identical source +
flags; the post-rename HLSL is byte-identical to the
pre-rename HLSL except for comment text, and comments don't
survive into the compiled bytecode. Re-running
tools/regen_d3d_common_dxbc.py produces .inc files that
match this commit's preamble lines + the pre-existing byte
arrays.
- C++ namespaces. Already D3DCommon::EmbeddedShaders since
24bacbf. Not touched here.
- Header / library / TU layout. embedded_shaders.{h,cpp}
already live at src/common/d3d_common/ since 24bacbf;
embedded_dxbc/ already lives at
src/common/d3d_common/embedded_dxbc/. This commit completes
the symmetric rename on the data-side and tools-side.
- Build system files (CMakeLists.txt, Makefile.libretro):
none of them references the data/shaders directory tree or
the regen tool - the data is consumed at HLSL-source-edit
time only, not at build time. Untouched.
- Runtime behaviour: zero diff across D3D11 + D3D12. Same
blobs, same pickers, same PSOs.
Test:
- git status post-rename shows 16 renames + 184 minor edits
(preamble-only diffs in the .inc files + comment-only diffs
in the regen tool + embedded_shaders.h + gpu_hw_d3d12.cpp).
No moved file's content changed structurally.
- Hand-compile of a representative variant
(box_sample_downsample at RESOLUTION_SCALE=4) post-rename:
1044 bytes DXBC, identical to pre-rename.
- String search across the tree: zero remaining references to
"data/shaders/d3d12" or "regen_d3d12_dxbc" outside of
.git history.
Next:
- Activation commit for the downsample pre-bake: add 22 extern
pairs + 22 #include lines to embedded_shaders.{h,cpp},
add 4 picker functions, rewrite the 5 shadergen calls in
GPU_HW_D3D11::CompileShaders. The d3d_common naming is now
coherent across HLSL sources, regen tool, .inc files, host
TU, and host namespace - new pre-bake additions don't have
to thread the old d3d12 naming.
- Phase 2 (separate effort): port the D3D11 downsample
machinery to D3D12 - PSOs, explicit resource barriers,
texture / mip-view creation - and set
m_supports_adaptive_downsampling = true on the D3D12 caps
path. The pre-baked blobs are already in place by then.
2026-05-19 09:19:36 +00:00
|
|
|
# error "Compile with /D RESOLUTION_SCALE=<N>. See TEMPLATE_VARIANTS in tools/regen_d3d_common_dxbc.py."
|
core: pre-bake the downsample fragment shaders
Backport of the 4 Vulkan downsample shader templates to HLSL for
the D3D backends. Lands the data + recipe; no C++ wiring yet.
Activation in the next commit swaps the D3D11 backend's runtime
shadergen + D3DCompile calls in GPU_HW_D3D11::CompileShaders for
the matching pre-baked pickers.
D3D12 currently has no downsample implementation - the backend
inherits m_downsample_mode = Disabled and m_supports_adaptive_
downsampling = false from GPU_HW. Adding D3D12 downsample is a
separate phase that will reuse the pre-baked blobs this commit
lands; the d3d_common location (24bacbf) means there is no path-
churn to repeat.
Templates (4 HLSL files, 22 reachable variants total):
data/shaders/d3d12/adaptive_downsample_blur.ps.hlsl
Mirror of mipmap_blur.glsl from parallel-rsx. 3x3 weighted
kernel on the alpha channel of the prior-pass mip. No
variant axes - the body references no compile-time toggles
and no RESOLUTION_SCALE.
-> 1 variant (no /D).
data/shaders/d3d12/adaptive_downsample_mip.ps.hlsl
Mirror of mipmap_energy.glsl from parallel-rsx. Measures
"energy" (variance) across a 2x2 footprint and writes a
scalar bias used by composite to choose mip levels. One
axis:
FIRST_PASS (0/1) - the Vulkan template uses spec const
id=100; HLSL has no spec-constant mechanism so we use
-D FIRST_PASS=1 and fxc dead-strips the unused arm.
-> 2 variants. Suffix f{0,1}.
data/shaders/d3d12/adaptive_downsample_composite.ps.hlsl
Mirror of mipmap_resolve.glsl from parallel-rsx. Reads the
per-pixel mip-bias scalar (samp1, the blur pass output) and
samples the colour pyramid (samp0) at the per-pixel mip
level. One axis:
RESOLUTION_SCALE (integer literal) - drives RCP_VRAM_SIZE
and the mip multiplier. Adaptive mode forces RESOLUTION_SCALE
to a power of 2 in [2, m_max_resolution_scale] via
GPU_HW::CalculateResolutionScale (gpu_hw.cpp:391). With
D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION / VRAM_WIDTH the cap
is 16, so the reachable set is {2, 4, 8, 16}.
-> 4 variants. Suffix s{2,4,8,16}.
data/shaders/d3d12/box_sample_downsample.ps.hlsl
Box-filter downsample - averages a RESOLUTION_SCALE x
RESOLUTION_SCALE block of upscaled texels back down to one
PSX-native-resolution pixel. One axis:
RESOLUTION_SCALE (integer literal) - drives base_coords
scaling, the two inner loop bounds, and the averaging
divisor. Box mode accepts any RESOLUTION_SCALE in
[2, m_max_resolution_scale] (no power-of-2 constraint,
unlike Adaptive); the cap is 16, so the reachable set is
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}.
Scale=1 disables downsampling entirely (GetDownsampleMode
gpu_hw.cpp:399), so we don't bake a variant for it.
-> 15 variants. Suffix s{2..16}.
Each .inc is small. blur is 2292 bytes of DXBC; mip is
1844/1872 bytes per FIRST_PASS arm; composite is 900 bytes per
scale (RESOLUTION_SCALE folds at fxc time to a literal in the
operand encoding without growing the bytecode length); box is
1044 bytes per scale (md5 differs across scales, confirming the
literal is embedded distinctly even though the byte count is
overhead-dominated). Total embedded payload: ~28 KiB across the
22 blobs - negligible compared to the batch FS slices.
The HLSL is API-neutral; the same .inc files serve both D3D11
(which has the runtime downsample path that the activation
commit swaps out) and D3D12 (which has no downsample
implementation yet but inherits the pre-baked blobs for the
follow-up phase). fxc /T ps_5_0 /E main /O3 emits DXBC that
both backends consume identically. The d3d_common location set
up at 24bacbf is the right home for these.
What changes:
data/shaders/d3d12/{adaptive_downsample_blur,
adaptive_downsample_mip,
adaptive_downsample_composite,
box_sample_downsample}.ps.hlsl
4 new files. Each carries a top-of-file comment describing
the Vulkan-side origin, the variant axes (or lack thereof),
bindings (cbuffer / textures / sampler slots), and the
/D macro names with reachable values.
tools/regen_d3d12_dxbc.py
TEMPLATE_VARIANTS gains 3 entries: adaptive_downsample_mip,
adaptive_downsample_composite, box_sample_downsample. Each
entry documents its axes and the reachable variant range.
adaptive_downsample_blur is intentionally NOT listed - it
falls through to the script's no-variants-table fallback
(compile once with no /D defines, emit a single
.inc with the base identifier), which produces the right
output (k_adaptive_downsample_blur_ps).
src/common/d3d_common/embedded_dxbc/
22 new .inc files:
adaptive_downsample_blur_ps.inc (1)
adaptive_downsample_mip_ps_{f0,f1}.inc (2)
adaptive_downsample_composite_ps_{s2,s4,s8,s16}.inc (4)
box_sample_downsample_ps_{s2..s16}.inc (15)
What doesn't change in this commit:
- src/common/d3d_common/embedded_shaders.{h,cpp}: untouched.
No extern declarations for the new blobs yet. Adding them
without consumers would yield -Wunused warnings the build
treats as errors. Both the externs and the picker functions
land together in the activation commit.
- src/core/gpu_hw_d3d11.cpp: untouched. The 5 shadergen calls
in CompileShaders (lines 1203/1205/1207/1209/1220) still go
through shader_cache.GetPixelShader on the runtime
shadergen + D3DCompile path. Activation commit replaces
them with D3DCommon::EmbeddedShaders picker + CreatePixelShader.
- src/core/gpu_hw_d3d12.cpp: untouched. No downsample
implementation exists yet. The D3D12 phase is a separate
project that ports the D3D11 downsample machinery (110 lines
across DownsampleFramebufferAdaptive +
DownsampleFramebufferBoxFilter plus ~50 lines of texture/
view creation in CompileShaders) to D3D12's command-list /
explicit-barrier model, sets m_supports_adaptive_downsampling
= true on the D3D12 SetCapabilities path, and consumes the
pre-baked blobs from this commit.
- Visual output: zero diff. D3D11 still uses runtime D3DCompile;
D3D12 still has no downsample.
Test:
- Hand-compile of representative variants via
/tmp/fxc_lite/fxc_lite.exe /T ps_5_0 /E main /O3:
blur: 2292 bytes (no /D)
mip f0: 1872 bytes (FIRST_PASS=0)
mip f1: 1844 bytes (FIRST_PASS=1)
composite s4: 900 bytes (RESOLUTION_SCALE=4)
composite s16: 900 bytes (RESOLUTION_SCALE=16)
box s2: 1044 bytes
box s8: 1044 bytes
box s16: 1044 bytes
All compile cleanly; no fxc warnings or errors. md5sum
across box scales 2/4/8/16 confirms each scale produces a
distinct DXBC byte sequence (literal RESOLUTION_SCALE is
embedded per variant), not 4 identical blobs.
- python3 tools/regen_d3d12_dxbc.py --fxc /tmp/fxc_lite/fxc_lite.exe
--wine /usr/bin/wine emits 182 .inc files total: 160
pre-existing + 22 downsample. No regressions on the existing
batch FS / display / vram_* blobs - they regenerate
bit-identical (same HLSL, same fxc invocation).
Cumulative pre-bake variant count:
Pre-arc: 75 264 (every axis a -D)
Post-cbuffer-routing arc: 1 176
Post-c01f8ae / a7f5717 (D3D12 batch FS): 84 baked + live
Post-this-commit (downsample blobs on disk): 22 additional baked
(consumers wired in the activation commit)
Next:
- Activation: add 22 new (uint8_t array + size_t) extern pairs
+ #include lines to D3DCommon::EmbeddedShaders, add 4 picker
functions (Box / AdaptiveMip / AdaptiveBlur / AdaptiveComposite),
and rewrite the 5 shadergen calls in GPU_HW_D3D11::CompileShaders
to use the pickers + D3D11::ShaderCompiler::CreatePixelShader.
Same shape as the b6d1903 / a7f5717 batch FS activations.
- Phase 2 (separate effort, not part of the pre-bake arc):
port the D3D11 downsample machinery to D3D12 - PSO builds,
explicit resource barriers, texture/mip-view creation - and
set m_supports_adaptive_downsampling = true on the D3D12
backend. The pre-baked blobs are already in place by then.
2026-05-19 09:08:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Texture2D samp0 : register(t0);
|
|
|
|
|
SamplerState samp0_ss : register(s0);
|
|
|
|
|
|
|
|
|
|
void main(
|
core/d3d: fix box downsample PS signature for D3D12 PSO linkage
The pre-baked box_sample_downsample.ps.hlsl declared only
SV_Position as its pixel-shader input. With no preceding TEXCOORD0,
fxc packed SV_Position at input register 0. The fullscreen-quad
vertex shader these PSOs bind emits TEXCOORD0 at output register 0
and SV_Position at output register 1, so on D3D12 the PS input
register 0 had no matching VS output carrying the POSITION system
value. D3D12 links VS-output to PS-input by register at
CreateGraphicsPipelineState time, so the box PSO failed to compile
and the build returned null. UpdateDisplay then bound that null
pipeline (SetPipelineState dereferences its argument), faulting
inside D3D12Core when downsampling was switched on at runtime.
Declare an (unused) TEXCOORD0 input ahead of SV_Position so fxc
packs SV_Position at register 1, matching the vertex shader output
and the display pixel shaders (which likewise keep an unused
TEXCOORD0 at register 0). fxc preserves declared-but-unread inputs
in the signature, so the resolved layout is TEXCOORD0->reg0,
SV_Position->reg1 for every scale variant. This is also what
GenerateBoxSampleDownsampleFragmentShader already emits via
DeclareFragmentEntryPoint(ss, 0, 1, ...). D3D11 was unaffected
because CreatePixelShader does not validate against the bound VS.
Regenerated all 15 box DXBC variants (s2..s16).
2026-05-20 11:29:01 +00:00
|
|
|
in float2 v_tex0 : TEXCOORD0,
|
core: pre-bake the downsample fragment shaders
Backport of the 4 Vulkan downsample shader templates to HLSL for
the D3D backends. Lands the data + recipe; no C++ wiring yet.
Activation in the next commit swaps the D3D11 backend's runtime
shadergen + D3DCompile calls in GPU_HW_D3D11::CompileShaders for
the matching pre-baked pickers.
D3D12 currently has no downsample implementation - the backend
inherits m_downsample_mode = Disabled and m_supports_adaptive_
downsampling = false from GPU_HW. Adding D3D12 downsample is a
separate phase that will reuse the pre-baked blobs this commit
lands; the d3d_common location (24bacbf) means there is no path-
churn to repeat.
Templates (4 HLSL files, 22 reachable variants total):
data/shaders/d3d12/adaptive_downsample_blur.ps.hlsl
Mirror of mipmap_blur.glsl from parallel-rsx. 3x3 weighted
kernel on the alpha channel of the prior-pass mip. No
variant axes - the body references no compile-time toggles
and no RESOLUTION_SCALE.
-> 1 variant (no /D).
data/shaders/d3d12/adaptive_downsample_mip.ps.hlsl
Mirror of mipmap_energy.glsl from parallel-rsx. Measures
"energy" (variance) across a 2x2 footprint and writes a
scalar bias used by composite to choose mip levels. One
axis:
FIRST_PASS (0/1) - the Vulkan template uses spec const
id=100; HLSL has no spec-constant mechanism so we use
-D FIRST_PASS=1 and fxc dead-strips the unused arm.
-> 2 variants. Suffix f{0,1}.
data/shaders/d3d12/adaptive_downsample_composite.ps.hlsl
Mirror of mipmap_resolve.glsl from parallel-rsx. Reads the
per-pixel mip-bias scalar (samp1, the blur pass output) and
samples the colour pyramid (samp0) at the per-pixel mip
level. One axis:
RESOLUTION_SCALE (integer literal) - drives RCP_VRAM_SIZE
and the mip multiplier. Adaptive mode forces RESOLUTION_SCALE
to a power of 2 in [2, m_max_resolution_scale] via
GPU_HW::CalculateResolutionScale (gpu_hw.cpp:391). With
D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION / VRAM_WIDTH the cap
is 16, so the reachable set is {2, 4, 8, 16}.
-> 4 variants. Suffix s{2,4,8,16}.
data/shaders/d3d12/box_sample_downsample.ps.hlsl
Box-filter downsample - averages a RESOLUTION_SCALE x
RESOLUTION_SCALE block of upscaled texels back down to one
PSX-native-resolution pixel. One axis:
RESOLUTION_SCALE (integer literal) - drives base_coords
scaling, the two inner loop bounds, and the averaging
divisor. Box mode accepts any RESOLUTION_SCALE in
[2, m_max_resolution_scale] (no power-of-2 constraint,
unlike Adaptive); the cap is 16, so the reachable set is
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}.
Scale=1 disables downsampling entirely (GetDownsampleMode
gpu_hw.cpp:399), so we don't bake a variant for it.
-> 15 variants. Suffix s{2..16}.
Each .inc is small. blur is 2292 bytes of DXBC; mip is
1844/1872 bytes per FIRST_PASS arm; composite is 900 bytes per
scale (RESOLUTION_SCALE folds at fxc time to a literal in the
operand encoding without growing the bytecode length); box is
1044 bytes per scale (md5 differs across scales, confirming the
literal is embedded distinctly even though the byte count is
overhead-dominated). Total embedded payload: ~28 KiB across the
22 blobs - negligible compared to the batch FS slices.
The HLSL is API-neutral; the same .inc files serve both D3D11
(which has the runtime downsample path that the activation
commit swaps out) and D3D12 (which has no downsample
implementation yet but inherits the pre-baked blobs for the
follow-up phase). fxc /T ps_5_0 /E main /O3 emits DXBC that
both backends consume identically. The d3d_common location set
up at 24bacbf is the right home for these.
What changes:
data/shaders/d3d12/{adaptive_downsample_blur,
adaptive_downsample_mip,
adaptive_downsample_composite,
box_sample_downsample}.ps.hlsl
4 new files. Each carries a top-of-file comment describing
the Vulkan-side origin, the variant axes (or lack thereof),
bindings (cbuffer / textures / sampler slots), and the
/D macro names with reachable values.
tools/regen_d3d12_dxbc.py
TEMPLATE_VARIANTS gains 3 entries: adaptive_downsample_mip,
adaptive_downsample_composite, box_sample_downsample. Each
entry documents its axes and the reachable variant range.
adaptive_downsample_blur is intentionally NOT listed - it
falls through to the script's no-variants-table fallback
(compile once with no /D defines, emit a single
.inc with the base identifier), which produces the right
output (k_adaptive_downsample_blur_ps).
src/common/d3d_common/embedded_dxbc/
22 new .inc files:
adaptive_downsample_blur_ps.inc (1)
adaptive_downsample_mip_ps_{f0,f1}.inc (2)
adaptive_downsample_composite_ps_{s2,s4,s8,s16}.inc (4)
box_sample_downsample_ps_{s2..s16}.inc (15)
What doesn't change in this commit:
- src/common/d3d_common/embedded_shaders.{h,cpp}: untouched.
No extern declarations for the new blobs yet. Adding them
without consumers would yield -Wunused warnings the build
treats as errors. Both the externs and the picker functions
land together in the activation commit.
- src/core/gpu_hw_d3d11.cpp: untouched. The 5 shadergen calls
in CompileShaders (lines 1203/1205/1207/1209/1220) still go
through shader_cache.GetPixelShader on the runtime
shadergen + D3DCompile path. Activation commit replaces
them with D3DCommon::EmbeddedShaders picker + CreatePixelShader.
- src/core/gpu_hw_d3d12.cpp: untouched. No downsample
implementation exists yet. The D3D12 phase is a separate
project that ports the D3D11 downsample machinery (110 lines
across DownsampleFramebufferAdaptive +
DownsampleFramebufferBoxFilter plus ~50 lines of texture/
view creation in CompileShaders) to D3D12's command-list /
explicit-barrier model, sets m_supports_adaptive_downsampling
= true on the D3D12 SetCapabilities path, and consumes the
pre-baked blobs from this commit.
- Visual output: zero diff. D3D11 still uses runtime D3DCompile;
D3D12 still has no downsample.
Test:
- Hand-compile of representative variants via
/tmp/fxc_lite/fxc_lite.exe /T ps_5_0 /E main /O3:
blur: 2292 bytes (no /D)
mip f0: 1872 bytes (FIRST_PASS=0)
mip f1: 1844 bytes (FIRST_PASS=1)
composite s4: 900 bytes (RESOLUTION_SCALE=4)
composite s16: 900 bytes (RESOLUTION_SCALE=16)
box s2: 1044 bytes
box s8: 1044 bytes
box s16: 1044 bytes
All compile cleanly; no fxc warnings or errors. md5sum
across box scales 2/4/8/16 confirms each scale produces a
distinct DXBC byte sequence (literal RESOLUTION_SCALE is
embedded per variant), not 4 identical blobs.
- python3 tools/regen_d3d12_dxbc.py --fxc /tmp/fxc_lite/fxc_lite.exe
--wine /usr/bin/wine emits 182 .inc files total: 160
pre-existing + 22 downsample. No regressions on the existing
batch FS / display / vram_* blobs - they regenerate
bit-identical (same HLSL, same fxc invocation).
Cumulative pre-bake variant count:
Pre-arc: 75 264 (every axis a -D)
Post-cbuffer-routing arc: 1 176
Post-c01f8ae / a7f5717 (D3D12 batch FS): 84 baked + live
Post-this-commit (downsample blobs on disk): 22 additional baked
(consumers wired in the activation commit)
Next:
- Activation: add 22 new (uint8_t array + size_t) extern pairs
+ #include lines to D3DCommon::EmbeddedShaders, add 4 picker
functions (Box / AdaptiveMip / AdaptiveBlur / AdaptiveComposite),
and rewrite the 5 shadergen calls in GPU_HW_D3D11::CompileShaders
to use the pickers + D3D11::ShaderCompiler::CreatePixelShader.
Same shape as the b6d1903 / a7f5717 batch FS activations.
- Phase 2 (separate effort, not part of the pre-bake arc):
port the D3D11 downsample machinery to D3D12 - PSO builds,
explicit resource barriers, texture/mip-view creation - and
set m_supports_adaptive_downsampling = true on the D3D12
backend. The pre-baked blobs are already in place by then.
2026-05-19 09:08:21 +00:00
|
|
|
in float4 v_pos : SV_Position,
|
|
|
|
|
out float4 o_col0 : SV_Target0)
|
|
|
|
|
{
|
|
|
|
|
float3 color = float3(0.0, 0.0, 0.0);
|
|
|
|
|
uint2 base_coords = uint2(v_pos.xy) * uint2(RESOLUTION_SCALE, RESOLUTION_SCALE);
|
|
|
|
|
for (uint offset_x = 0u; offset_x < RESOLUTION_SCALE; offset_x++)
|
|
|
|
|
{
|
|
|
|
|
for (uint offset_y = 0u; offset_y < RESOLUTION_SCALE; offset_y++)
|
|
|
|
|
color += samp0.Load(int3(int2(base_coords + uint2(offset_x, offset_y)), 0)).rgb;
|
|
|
|
|
}
|
|
|
|
|
color /= float(RESOLUTION_SCALE * RESOLUTION_SCALE);
|
|
|
|
|
o_col0 = float4(color, 1.0);
|
|
|
|
|
}
|