From 7c2252609d8f21dfe9f49d2b0cdf80cefc13b2f5 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 23 Nov 2026 01:44:40 +0100 Subject: D3D-448: console root-argument layout, measured for compute and used there rt::rootsig::pack_stage() lays a root signature out for one stage the way the console compiler does: root order from the stage base, a table one dword (its 32-bit VA), a root view two, constants one per value, and the first parameter that does not fit refused (the spill array behind s[0:1] is not modelled). Compute (base s4) is measured: on the package's FidelityFX DLL, whose 29 compute containers carry their RTS0 next to the console-compiled program, base plus span equals RSRC2 USER_SGPR in 29 of 29, and root_sig_contract.py --model console finds all 20 translated programs compatible (the s0 model contradicts 7). VS/PS/GS s8 and MS s16 stay a census hypothesis. The compute bind point now uses this layout; graphics keeps pack(), since every stage reads one push-constant block and a mesh shader (s16) and a pixel shader (s8) would collide. A signature carries both layouts; binding it where its layout refused it invalidates the list. Test fixtures follow: the compute GLSL shaders read the new places, and the asm fixtures a D3D12 compute PSO runs are built with LEONIDA_USER_DATA_SHIFT=4 (compute_fixture.py shifts every SGPR and the RSRC2 user count), so the standalone harness keeps using them at s0. Co-Authored-By: Claude Opus 5.5 --- runtime/src/root_signature.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'runtime/src/root_signature.cpp') diff --git a/runtime/src/root_signature.cpp b/runtime/src/root_signature.cpp index 844f1b580..a0eb96cce 100644 --- a/runtime/src/root_signature.cpp +++ b/runtime/src/root_signature.cpp @@ -48,6 +48,48 @@ PackResult pack(const RootSignature& sig) { return out; } +StagePackResult pack_stage(const RootSignature& sig, Stage stage) { + StagePackResult out; + out.stage = stage; + out.base = stage_base(stage); + out.end_sgpr = out.base; + if (sig.params.size() > 64) { + out.error = "root signature has more than 64 root parameters"; + return out; + } + uint64_t cost = 0; // 64-bit, as in pack() + uint64_t next = out.base; + std::vector first; + first.reserve(sig.params.size()); + for (size_t i = 0; i < sig.params.size(); ++i) { + const RootParameter& p = sig.params[i]; + if (p.type == ParamType::Constants && p.num_values == 0) { + out.error = "root constant parameter needs at least 1 dword"; + return out; + } + cost += param_cost(p.type, p.num_values); + if (cost > kMaxD3d12Cost) { + out.error = "root signature exceeds the 64-dword D3D12 cost limit"; + return out; + } + const uint64_t dwords = stage_dwords(p.type, p.num_values); + if (next + dwords > kMaxUserSgprs) { + // The console moves this parameter and every later one to the spill array behind s[0:1]; that array's + // layout is not modelled here, so refuse rather than drop arguments. + out.error = "root parameter " + std::to_string(i) + " does not fit in the user SGPRs from s" + + std::to_string(out.base) + " (spill array not modelled)"; + return out; + } + first.push_back(static_cast(next)); + next += dwords; + } + out.first_sgpr = std::move(first); + out.end_sgpr = static_cast(next); + out.d3d12_cost = static_cast(cost); + out.ok = true; + return out; +} + namespace { void put_u32(std::vector& out, uint32_t v) { -- cgit v1.2.3