upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorVictor Garcia <victorgf2011@gmail.com>2026-11-23 01:44:40 +0100
committerVictor Garcia <victorgf2011@gmail.com>2026-11-23 01:44:40 +0100
commit7c2252609d8f21dfe9f49d2b0cdf80cefc13b2f5 (patch)
tree567269e052e5a0ec705d7214624d77724699cca5 /runtime/src
parentaa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/root_signature.cpp42
-rw-r--r--runtime/src/root_signature.h61
2 files changed, 103 insertions, 0 deletions
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) {
48 return out; 48 return out;
49} 49}
50 50
51StagePackResult pack_stage(const RootSignature& sig, Stage stage) {
52 StagePackResult out;
53 out.stage = stage;
54 out.base = stage_base(stage);
55 out.end_sgpr = out.base;
56 if (sig.params.size() > 64) {
57 out.error = "root signature has more than 64 root parameters";
58 return out;
59 }
60 uint64_t cost = 0; // 64-bit, as in pack()
61 uint64_t next = out.base;
62 std::vector<uint32_t> first;
63 first.reserve(sig.params.size());
64 for (size_t i = 0; i < sig.params.size(); ++i) {
65 const RootParameter& p = sig.params[i];
66 if (p.type == ParamType::Constants && p.num_values == 0) {
67 out.error = "root constant parameter needs at least 1 dword";
68 return out;
69 }
70 cost += param_cost(p.type, p.num_values);
71 if (cost > kMaxD3d12Cost) {
72 out.error = "root signature exceeds the 64-dword D3D12 cost limit";
73 return out;
74 }
75 const uint64_t dwords = stage_dwords(p.type, p.num_values);
76 if (next + dwords > kMaxUserSgprs) {
77 // The console moves this parameter and every later one to the spill array behind s[0:1]; that array's
78 // layout is not modelled here, so refuse rather than drop arguments.
79 out.error = "root parameter " + std::to_string(i) + " does not fit in the user SGPRs from s" +
80 std::to_string(out.base) + " (spill array not modelled)";
81 return out;
82 }
83 first.push_back(static_cast<uint32_t>(next));
84 next += dwords;
85 }
86 out.first_sgpr = std::move(first);
87 out.end_sgpr = static_cast<uint32_t>(next);
88 out.d3d12_cost = static_cast<uint32_t>(cost);
89 out.ok = true;
90 return out;
91}
92
51namespace { 93namespace {
52 94
53void put_u32(std::vector<uint8_t>& out, uint32_t v) { 95void put_u32(std::vector<uint8_t>& out, uint32_t v) {
diff --git a/runtime/src/root_signature.h b/runtime/src/root_signature.h
index bd1bfd036..376962940 100644
--- a/runtime/src/root_signature.h
+++ b/runtime/src/root_signature.h
@@ -117,6 +117,67 @@ constexpr uint32_t kMaxD3d12Cost = 64;
117// D3D12 cost limit, or holds more than 64 root parameters. 117// D3D12 cost limit, or holds more than 64 root parameters.
118[[nodiscard]] PackResult pack(const RootSignature& sig); 118[[nodiscard]] PackResult pack(const RootSignature& sig);
119 119
120// The console layout of root arguments in a stage's user SGPRs (docs/d3d12_vulkan.md section 3.5, D3D-448).
121//
122// Parameters go in root-signature order from the stage's first root-argument SGPR, each while it fits whole:
123// a 32-bit constant takes one SGPR per value, a root CBV/SRV/UAV two (its 64-bit VA), a descriptor table ONE
124// (the 32-bit VA of its first descriptor; the heaps live below 4 GiB). Static samplers take none.
125//
126// How each part is known:
127// - compute, base s4: measured. The console compiler's output (section 7) and the package's FidelityFX DLL, whose
128// 29 compute containers carry their RTS0 next to the console-compiled program: base s4 plus the signature's span
129// in this layout equals the program's RSRC2 USER_SGPR count in 29 of 29, and the programs read the tables and
130// root CBVs at exactly these SGPRs (tools/rootsig_census.py --disasm). The game's compute census agrees (lowest
131// pointer s4, one-dword tables).
132// - vertex/pixel/geometry s8 and mesh s16: a hypothesis from the corpus census only (lowest pointer SGPR per stage);
133// no signature confirms them, and visibility is not modelled (every parameter takes its place in every stage).
134// A parameter that does not fit goes to the console's spill array behind s[0:1] (compute, section 7) together with
135// every parameter after it; that array is not modelled, so such a signature is refused, never truncated.
136enum class Stage : uint32_t { Vertex = 0, Pixel = 1, Geometry = 2, Compute = 3, Mesh = 4 };
137
138[[nodiscard]] constexpr uint32_t stage_base(Stage stage) noexcept {
139 switch (stage) {
140 case Stage::Compute:
141 return 4;
142 case Stage::Mesh:
143 return 16;
144 case Stage::Vertex:
145 case Stage::Pixel:
146 case Stage::Geometry:
147 return 8;
148 }
149 return 8;
150}
151
152// User SGPRs one parameter takes in the console layout (see Stage).
153[[nodiscard]] constexpr uint32_t stage_dwords(ParamType type, uint32_t num_values) noexcept {
154 switch (type) {
155 case ParamType::Constants:
156 return num_values;
157 case ParamType::Descriptor:
158 return 2;
159 case ParamType::Table:
160 return 1;
161 }
162 return 0;
163}
164
165constexpr uint32_t kNoSgpr = 0xFFFFFFFFu;
166
167struct StagePackResult {
168 bool ok = false;
169 std::string error; // set when !ok; names the refusing parameter
170 Stage stage = Stage::Compute;
171 uint32_t base = 0; // stage_base(stage)
172 std::vector<uint32_t> first_sgpr; // per parameter: its first user SGPR (kNoSgpr when the signature is refused)
173 uint32_t end_sgpr = 0; // one past the last SGPR used: the RSRC2 USER_SGPR count the layout implies
174 uint32_t d3d12_cost = 0; // cost against the 64-dword D3D12 limit
175};
176
177// Lays the parameters out for `stage` in the console layout. Fails like pack() on more than 64 parameters, a
178// constant parameter of 0 values or the 64-dword cost limit, and on any parameter that would spill.
179[[nodiscard]] StagePackResult pack_stage(const RootSignature& sig, Stage stage);
180
120// D3D12 cost of one parameter against the 64-dword limit. 181// D3D12 cost of one parameter against the 64-dword limit.
121[[nodiscard]] constexpr uint32_t param_cost(ParamType type, uint32_t num_values) noexcept { 182[[nodiscard]] constexpr uint32_t param_cost(ParamType type, uint32_t num_values) noexcept {
122 switch (type) { 183 switch (type) {