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.
113 lines
4.4 KiB
HLSL
113 lines
4.4 KiB
HLSL
// Pre-baked VRAM write pixel shader for the D3D12 backend.
|
|
//
|
|
// Equivalent to GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(false)
|
|
// in src/core/gpu_hw_shadergen.cpp. Used by GPU_HW_D3D12::GetVRAMWritePipeline
|
|
// for the CPU->VRAM upload path - this is hit on every game's
|
|
// framebuffer streaming (pre-rendered backgrounds in FF7, FMV decode
|
|
// staging, sprite-page reloads in fighting games, etc., so it runs
|
|
// many times per frame in practice).
|
|
//
|
|
// Variant axis: PGXP_DEPTH = 0 or 1. PGXP-depth disabled / enabled -
|
|
// the runtime m_pgxp_depth_buffer toggle. Two .inc blobs:
|
|
// vram_write_ps_pgxp0.inc (PGXP_DEPTH = 0)
|
|
// vram_write_ps_pgxp1.inc (PGXP_DEPTH = 1)
|
|
//
|
|
// use_ssbo: the shadergen path takes a `bool use_ssbo` parameter, but
|
|
// the D3D12 caller always passes `false` (HLSL has no direct SSBO
|
|
// equivalent; the shadergen's use_ssbo=true branch is GLSL/Vulkan-only).
|
|
// So the D3D12 pre-bake only covers the texture-buffer path
|
|
// (Buffer<uint4> samp0), and the use_ssbo dimension collapses to a
|
|
// single value here.
|
|
//
|
|
// RESOLUTION_SCALE / VRAM_SIZE derive at runtime from u_resolution_scale
|
|
// in the cbuffer below (post-9d2b49d refactor). Same DXBC serves
|
|
// every resolution-scale value.
|
|
|
|
cbuffer UBOBlock : register(b0)
|
|
{
|
|
// 44-byte cbuffer. C++ side is GPU_HW::VRAMWriteUBOData (gpu_hw.h);
|
|
// the field order here MUST match the struct member order there.
|
|
uint2 u_base_coords;
|
|
uint2 u_end_coords;
|
|
uint2 u_size;
|
|
uint u_buffer_base_offset;
|
|
uint u_mask_or_bits;
|
|
float u_depth_value;
|
|
uint u_resolution_scale;
|
|
uint u_pad0;
|
|
};
|
|
|
|
// VRAM_SIZE / RESOLUTION_SCALE derive from u_resolution_scale - mirrors
|
|
// the WriteCBufferResolutionScaleAliases helper's #define output in
|
|
// gpu_hw_shadergen.cpp.
|
|
#define RESOLUTION_SCALE u_resolution_scale
|
|
#define VRAM_SIZE (uint2(1024u, 512u) * u_resolution_scale)
|
|
|
|
// Texture-buffer source for the CPU upload data. PSX VRAM writes are
|
|
// 16-bit RGBA5551 packed into the texel buffer; the shader does
|
|
// per-pixel address arithmetic + RGBA5551 -> RGBA8 conversion below.
|
|
// `Buffer<uint4>` here matches what shadergen.cpp's DeclareTextureBuffer
|
|
// emits for HLSL when is_int=true / is_unsigned=true.
|
|
Buffer<uint4> samp0 : register(t0);
|
|
|
|
// RGBA5551 -> RGBA8 unpack. PSX 16-bit colour layout (bits 0-4 R,
|
|
// 5-9 G, 10-14 B, 15 alpha/mask). Identical to the helper inlined by
|
|
// WriteCommonFunctions in the shadergen path.
|
|
float4 RGBA5551ToRGBA8(uint v)
|
|
{
|
|
uint r = (v & 31u);
|
|
uint g = ((v >> 5) & 31u);
|
|
uint b = ((v >> 10) & 31u);
|
|
uint a = ((v >> 15) & 1u);
|
|
return float4(float(r) / 31.0, float(g) / 31.0, float(b) / 31.0, float(a));
|
|
}
|
|
|
|
void main(
|
|
in float2 v_tex0 : TEXCOORD0,
|
|
in float4 v_pos : SV_Position,
|
|
out float o_depth : SV_Depth,
|
|
out float4 o_col0 : SV_Target0)
|
|
{
|
|
// Map upscaled framebuffer pixel back to native VRAM coord. The
|
|
// runtime sets the viewport in upscaled VRAM space; the divide by
|
|
// RESOLUTION_SCALE collapses N upscaled pixels into one native one
|
|
// so the texture-buffer lookup uses native VRAM addressing.
|
|
uint2 coords = uint2(uint(v_pos.x) / RESOLUTION_SCALE,
|
|
uint(v_pos.y) / RESOLUTION_SCALE);
|
|
|
|
// Discard out-of-range pixels. Same wrap-around-rect logic as
|
|
// vram_copy: (coord < base) && (coord >= end) means the pixel sits
|
|
// outside both halves of a wrapped rect.
|
|
if ((coords.x < u_base_coords.x && coords.x >= u_end_coords.x) ||
|
|
(coords.y < u_base_coords.y && coords.y >= u_end_coords.y))
|
|
{
|
|
discard;
|
|
}
|
|
|
|
// Offset from the start of the rect, with native-VRAM wrap-around
|
|
// handling on each axis. (VRAM_SIZE.x / RESOLUTION_SCALE) is just
|
|
// 1024 in native coords; written this way to match the shadergen
|
|
// body byte-for-byte so the optimization opportunities are
|
|
// identical.
|
|
uint2 offset;
|
|
offset.x = (coords.x < u_base_coords.x)
|
|
? ((VRAM_SIZE.x / RESOLUTION_SCALE) - u_base_coords.x + coords.x)
|
|
: (coords.x - u_base_coords.x);
|
|
offset.y = (coords.y < u_base_coords.y)
|
|
? ((VRAM_SIZE.y / RESOLUTION_SCALE) - u_base_coords.y + coords.y)
|
|
: (coords.y - u_base_coords.y);
|
|
|
|
// Linearise (offset.x, offset.y) into a 1-D buffer index, fetch the
|
|
// 16-bit texel from the upload buffer, OR in the mask bit, unpack
|
|
// to RGBA8.
|
|
uint buffer_offset = u_buffer_base_offset + (offset.y * u_size.x) + offset.x;
|
|
uint value = samp0.Load(int(buffer_offset)).r | u_mask_or_bits;
|
|
|
|
o_col0 = RGBA5551ToRGBA8(value);
|
|
|
|
#if PGXP_DEPTH
|
|
o_depth = 1.0;
|
|
#else
|
|
o_depth = (o_col0.a == 1.0) ? u_depth_value : 0.0;
|
|
#endif
|
|
}
|