The .inc consumers and the C++ host namespace moved to d3d_common in24bacbf, 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 at251e457also 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 since24bacbf. Not touched here. - Header / library / TU layout. embedded_shaders.{h,cpp} already live at src/common/d3d_common/ since24bacbf; 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.
84 lines
3 KiB
HLSL
84 lines
3 KiB
HLSL
// Pre-baked HLSL for
|
|
// GPU_HW_ShaderGen::GenerateAdaptiveDownsampleMipFragmentShader(first_pass).
|
|
//
|
|
// Backport of data/shaders/vulkan/adaptive_downsample_mip.frag.glsl
|
|
// to HLSL for the D3D backends. Originally "mipmap_energy.glsl"
|
|
// from parallel-rsx. Measures local "energy" (variance) across a
|
|
// 2x2 footprint and writes a scalar bias used downstream to choose
|
|
// mip levels.
|
|
//
|
|
// Variant axis (1 dimension, 2 blobs):
|
|
// FIRST_PASS (-D macro). When 1, the input alpha channel is
|
|
// irrelevant (the source mip 0 has no prior bias to carry) and
|
|
// get_bias operates on float3. When 0 (default), the alpha
|
|
// channel carries the bias from the prior pass and get_bias
|
|
// operates on float4. fxc dead-strips the unused arm at
|
|
// compile time.
|
|
//
|
|
// This used to be 2 distinct GLSL / HLSL source strings on the
|
|
// runtime path - shadergen.Generate*Fragment(first_pass=true) vs
|
|
// (false) produced different #define FIRST_PASS sites that hashed
|
|
// to different shader-cache entries. The Vulkan pre-bake folded
|
|
// these via spec constant id=100; on HLSL we use the equivalent
|
|
// -D macro since fxc has no spec-constant mechanism. 2 blobs.
|
|
//
|
|
// Suffix: f{0,1} encodes FIRST_PASS.
|
|
//
|
|
// Bindings: same UBO + samp0 as the blur pass. See
|
|
// adaptive_downsample_blur.ps.hlsl for the rationale.
|
|
|
|
cbuffer UBOBlock : register(b0)
|
|
{
|
|
float2 u_uv_min;
|
|
float2 u_uv_max;
|
|
float2 u_rcp_resolution;
|
|
float sample_level;
|
|
};
|
|
|
|
Texture2D samp0 : register(t0);
|
|
SamplerState samp0_ss : register(s0);
|
|
|
|
// Two overloads of get_bias - the float3 form is for FIRST_PASS=1
|
|
// (no prior alpha bias to carry), the float4 form is for
|
|
// FIRST_PASS=0 (feed-back).
|
|
float4 get_bias(float3 c00, float3 c01, float3 c10, float3 c11)
|
|
{
|
|
// Measure the "energy" (variance) in the pixels. If pixels are
|
|
// all the same (2D content), use maximum bias; otherwise taper
|
|
// off quickly back to 0 (edges).
|
|
float3 avg = 0.25 * (c00 + c01 + c10 + c11);
|
|
float s00 = dot(c00 - avg, c00 - avg);
|
|
float s01 = dot(c01 - avg, c01 - avg);
|
|
float s10 = dot(c10 - avg, c10 - avg);
|
|
float s11 = dot(c11 - avg, c11 - avg);
|
|
return float4(avg, 1.0 - log2(1000.0 * (s00 + s01 + s10 + s11) + 1.0));
|
|
}
|
|
|
|
float4 get_bias(float4 c00, float4 c01, float4 c10, float4 c11)
|
|
{
|
|
float avg = 0.25 * (c00.a + c01.a + c10.a + c11.a);
|
|
float4 bias = get_bias(c00.rgb, c01.rgb, c10.rgb, c11.rgb);
|
|
bias.a *= avg;
|
|
return bias;
|
|
}
|
|
|
|
void main(
|
|
in float2 v_tex0 : TEXCOORD0,
|
|
out float4 o_col0 : SV_Target0)
|
|
{
|
|
float2 uv = v_tex0 - (u_rcp_resolution * 0.25);
|
|
|
|
#if FIRST_PASS
|
|
float3 c00 = samp0.Sample(samp0_ss, uv, int2(0, 0)).rgb;
|
|
float3 c01 = samp0.Sample(samp0_ss, uv, int2(0, 1)).rgb;
|
|
float3 c10 = samp0.Sample(samp0_ss, uv, int2(1, 0)).rgb;
|
|
float3 c11 = samp0.Sample(samp0_ss, uv, int2(1, 1)).rgb;
|
|
o_col0 = get_bias(c00, c01, c10, c11);
|
|
#else
|
|
float4 c00 = samp0.Sample(samp0_ss, uv, int2(0, 0));
|
|
float4 c01 = samp0.Sample(samp0_ss, uv, int2(0, 1));
|
|
float4 c10 = samp0.Sample(samp0_ss, uv, int2(1, 0));
|
|
float4 c11 = samp0.Sample(samp0_ss, uv, int2(1, 1));
|
|
o_col0 = get_bias(c00, c01, c10, c11);
|
|
#endif
|
|
}
|