upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src/root_signature.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 22:12:48 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 22:13:02 -0500
commit3ee0037fd3accba459d0d5ecd8acad831174d4d7 (patch)
tree55953ce44091103e4f7c4a2f45490be961282b27 /runtime/src/root_signature.cpp
parent9b8707c03dabb59ba2e29b9b0749d3c3eb1f3903 (diff)
parent5115f0887940595aa0f46fed7fc9db28b64151ff (diff)
Merge main into RT-DIRECT-HEAP-GRAPHICS (#1232)
This merges #1064 as prepared (its head + a merge of main), so it brings #1232 up to date with main and with #1064. #1232's branch carried #974 (merged into main since) and an older head of #1064 (7c47fd946). main already supplies the directly indexed heaps to graphics draws (integration #984): graphics_user_data() on DrawInstanced, DrawIndexedInstanced and DispatchMesh, at RootArgumentLayout::graphics_arguments_end (pack_stage(Stage::Pixel)'s end_sgpr, set when the console layout places the signature), LEONIDA_GRAPHICS_DIRECT_HEAPS=0, its notes for a signature on the s0 layout or one that fills s31, and d3d12_graphics_direct_heaps_test (recorded draws and the VS/PS GPU reads). That form stays. What this pull request adds beyond it is carried onto it: the mesh case. Conflicts (all taken from #1064's merged branch, then the PR's mesh parts carried over): - runtime/shims/d3d12_com.cpp: main's graphics_user_data()/with_direct_heaps() and notes. The PR's own graphics_user_data(), GetEnvironmentVariableA switch and no-room notes are main's in another form and dropped. Carried: the comment says a mesh shader reads push dword d as s(d + 8) through #974's window, so it gets the heaps after its arguments from s16 (main's comment still said the mesh stage gets none); and DispatchMesh reports once when a heap falls past the mesh window (push dword 24 and up, s32 for the mesh shader), the case raised in the review of #1232 (mesh_ok accepts arguments up to push dword 24). - runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp: main's (graphics_arguments_end from pixel.end_sgpr; the PR set it from its Spill::block form, which main did not take from #974). - runtime/test/glsl/cs_user_data.comp: main's (identical direct-indexing mode). - docs/d3d12_vulkan.md: main's section 3.4 with #1064's compute paragraph; the graphics paragraph's "a mesh shader ... is not modelled" replaced by the mesh window position, cited to issue #14 comment 7143020922 as a report not reproduced here, the window-overflow note and the mesh test. - runtime/test/d3d12_mesh_test.cpp (no conflict): the PR's recorded-argument checks kept (vertex and mesh draw with 4 constants, resource-only rebind, 23 constants, 30 constants); the 30-constant comment now says it keeps pack()'s s0 layout on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/root_signature.cpp')
-rw-r--r--runtime/src/root_signature.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/runtime/src/root_signature.cpp b/runtime/src/root_signature.cpp
index 3852c587c..10dd1e02c 100644
--- a/runtime/src/root_signature.cpp
+++ b/runtime/src/root_signature.cpp
@@ -48,7 +48,7 @@ PackResult pack(const RootSignature& sig) {
48 return out; 48 return out;
49} 49}
50 50
51StagePackResult pack_stage(const RootSignature& sig, Stage stage, Spill spill) { 51StagePackResult pack_stage(const RootSignature& sig, Stage stage) {
52 StagePackResult out; 52 StagePackResult out;
53 out.stage = stage; 53 out.stage = stage;
54 out.base = stage_base(stage); 54 out.base = stage_base(stage);
@@ -59,10 +59,18 @@ StagePackResult pack_stage(const RootSignature& sig, Stage stage, Spill spill) {
59 } 59 }
60 uint64_t cost = 0; // 64-bit, as in pack() 60 uint64_t cost = 0; // 64-bit, as in pack()
61 uint64_t next = out.base; 61 uint64_t next = out.base;
62 uint64_t spill_next = 0;
63 bool spilling = false;
62 std::vector<uint32_t> first; 64 std::vector<uint32_t> first;
65 std::vector<uint32_t> spill;
63 first.reserve(sig.params.size()); 66 first.reserve(sig.params.size());
67 spill.reserve(sig.params.size());
64 for (size_t i = 0; i < sig.params.size(); ++i) { 68 for (size_t i = 0; i < sig.params.size(); ++i) {
65 const RootParameter& p = sig.params[i]; 69 const RootParameter& p = sig.params[i];
70 if (p.type != ParamType::Constants && p.type != ParamType::Descriptor && p.type != ParamType::Table) {
71 out.error = "unknown root parameter type";
72 return out;
73 }
66 if (p.type == ParamType::Constants && p.num_values == 0) { 74 if (p.type == ParamType::Constants && p.num_values == 0) {
67 out.error = "root constant parameter needs at least 1 dword"; 75 out.error = "root constant parameter needs at least 1 dword";
68 return out; 76 return out;
@@ -73,28 +81,27 @@ StagePackResult pack_stage(const RootSignature& sig, Stage stage, Spill spill) {
73 return out; 81 return out;
74 } 82 }
75 const uint64_t dwords = stage_dwords(p.type, p.num_values); 83 const uint64_t dwords = stage_dwords(p.type, p.num_values);
76 if (out.first_spilled != SIZE_MAX) { // already in the argument block: every later parameter follows 84 if (!spilling && next + dwords <= kMaxUserSgprs) {
77 first.push_back(kNoSgpr); 85 first.push_back(static_cast<uint32_t>(next));
78 out.spilled_dwords += static_cast<uint32_t>(dwords); 86 spill.push_back(kNoSpill);
79 continue; 87 next += dwords;
80 } 88 } else if (stage == Stage::Compute) {
81 if (next + dwords > kMaxUserSgprs) { 89 // Compute packs this parameter and every later one contiguously into the spill array behind s[0:1]
82 // The console moves this parameter and every later one to the spill array behind s[0:1]. 90 // (docs/d3d12_vulkan.md §3.5 & §7). Total spill stays bounded by kMaxD3d12Cost (<= 64 dwords).
83 if (spill == Spill::refuse) { 91 spilling = true;
84 out.error = "root parameter " + std::to_string(i) + " does not fit in the user SGPRs from s" +
85 std::to_string(out.base) + " (spill array not modelled)";
86 return out;
87 }
88 out.first_spilled = i;
89 out.spilled_dwords = static_cast<uint32_t>(dwords);
90 first.push_back(kNoSgpr); 92 first.push_back(kNoSgpr);
91 continue; 93 spill.push_back(static_cast<uint32_t>(spill_next));
94 spill_next += dwords;
95 } else {
96 out.error = "root parameter " + std::to_string(i) + " does not fit in the user SGPRs from s" +
97 std::to_string(out.base) + " (spill array not modelled)";
98 return out;
92 } 99 }
93 first.push_back(static_cast<uint32_t>(next));
94 next += dwords;
95 } 100 }
96 out.first_sgpr = std::move(first); 101 out.first_sgpr = std::move(first);
102 out.spill_dword = std::move(spill);
97 out.end_sgpr = static_cast<uint32_t>(next); 103 out.end_sgpr = static_cast<uint32_t>(next);
104 out.spill_dwords = static_cast<uint32_t>(spill_next);
98 out.d3d12_cost = static_cast<uint32_t>(cost); 105 out.d3d12_cost = static_cast<uint32_t>(cost);
99 out.ok = true; 106 out.ok = true;
100 return out; 107 return out;