upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/root_signature_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/root_signature_test.cpp')
-rw-r--r--runtime/test/root_signature_test.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/runtime/test/root_signature_test.cpp b/runtime/test/root_signature_test.cpp
index c7f726599..8ecf580ef 100644
--- a/runtime/test/root_signature_test.cpp
+++ b/runtime/test/root_signature_test.cpp
@@ -131,6 +131,39 @@ int main() {
131 check(!r.ok && r.error.find("64-dword") != std::string::npos, 131 check(!r.ok && r.error.find("64-dword") != std::string::npos,
132 "65 constants refused by cost limit"); 132 "65 constants refused by cost limit");
133 } 133 }
134 // 64 constants are within the cost limit, as on the host: pack() and the graphics stages refuse them only for
135 // the spill past the user SGPRs, and that is what the error says; compute spills them whole.
136 {
137 RootSignature sig;
138 sig.params = {consts(64)};
139 const PackResult r = pack(sig);
140 check(!r.ok && r.error.find("64-dword") == std::string::npos && r.error.find("spill") != std::string::npos,
141 "64 constants pass the cost limit (refused only as a spill)");
142 const StagePackResult p = pack_stage(sig, Stage::Pixel);
143 check(!p.ok && p.error.find("64-dword") == std::string::npos && p.error.find("spill") != std::string::npos,
144 "pack_stage: 64 constants pass the cost limit for a pixel shader (refused only as a spill)");
145 const StagePackResult c = pack_stage(sig, Stage::Compute);
146 check(c.ok && c.d3d12_cost == 64 && c.spill_dword == std::vector<uint32_t>({0}) && c.spill_dwords == 64,
147 "pack_stage: 64 constants pass the cost limit for compute, spilled whole");
148 sig.params = {consts(32), consts(0), consts(32)};
149 check(pack(sig).error.find("spill") != std::string::npos, "32 + 0 + 32 constants cost 64, not more");
150 }
151 // A constant parameter of 0 values is valid on the host (the serializer warns, CreateRootSignature answers
152 // S_OK). It takes no dwords and no cost: the parameters around it pack as if it were absent.
153 {
154 RootSignature sig;
155 sig.params = {consts(0), consts(2), consts(0), view(), consts(0)};
156 const PackResult r = pack(sig);
157 check(r.ok && r.dword_count == 2 + 2 && r.d3d12_cost == 2 + 2, "zero-value constants pack to no dwords");
158 check(r.provenance.size() == 4 && r.provenance[0].param_index == 1 && r.provenance[1].param_index == 1 &&
159 r.provenance[2].param_index == 3 && r.provenance[2].sub_index == 0 &&
160 r.provenance[3].param_index == 3 && r.provenance[3].sub_index == 1,
161 "zero-value constants leave no provenance; their neighbours keep their dwords");
162 RootSignature alone;
163 alone.params = {consts(0)};
164 const PackResult a = pack(alone);
165 check(a.ok && a.dword_count == 0 && a.d3d12_cost == 0, "a lone zero-value constant parameter packs");
166 }
134 // A count that wraps a 32-bit sum (1 + 0xFFFFFFFF) is still refused, not packed past dwords[32]. 167 // A count that wraps a 32-bit sum (1 + 0xFFFFFFFF) is still refused, not packed past dwords[32].
135 { 168 {
136 rt::rootsig::RootSignature sig; 169 rt::rootsig::RootSignature sig;
@@ -188,6 +221,19 @@ int main() {
188 const PackResult r = pack(d.sig); 221 const PackResult r = pack(d.sig);
189 check(r.ok && r.dword_count == 3 + 2, "parsed RTS0 packs to 5 dwords"); 222 check(r.ok && r.dword_count == 3 + 2, "parsed RTS0 packs to 5 dwords");
190 } 223 }
224 // The same blob with 0 values in its constant parameter: parsed and packed, the CBV taking the first dwords.
225 {
226 std::vector<uint8_t> payload = build_payload();
227 payload[56] = 0; // the constants' value count (payload at 48: register, space, count)
228 const DecodeResult d = parse_rts0(payload.data(), payload.size());
229 check(d.ok && d.sig.params.size() == 2 && d.sig.params[0].num_values == 0,
230 "RTS0 with a zero-value constant parameter parses");
231 const PackResult r = pack(d.sig);
232 check(r.ok && r.dword_count == 2 && r.provenance[0].param_index == 1, "zero-value RTS0 packs the CBV at 0");
233 const StagePackResult c = pack_stage(d.sig, Stage::Compute);
234 check(c.ok && c.first_sgpr.size() == 2 && c.first_sgpr[0] == 4 && c.first_sgpr[1] == 4 && c.end_sgpr == 6,
235 "pack_stage: zero-value RTS0 puts the CBV at s4");
236 }
191 237
192 // RTS0 controls: unknown version, wild offsets and truncation fail loudly. 238 // RTS0 controls: unknown version, wild offsets and truncation fail loudly.
193 { 239 {
@@ -541,9 +587,26 @@ int main() {
541 bad_param.type = static_cast<ParamType>(0xffffffffu); 587 bad_param.type = static_cast<ParamType>(0xffffffffu);
542 invalid_sig.params = {bad_param}; 588 invalid_sig.params = {bad_param};
543 check(!pack_stage(invalid_sig, Stage::Compute).ok, "pack_stage: invalid parameter enum rejected"); 589 check(!pack_stage(invalid_sig, Stage::Compute).ok, "pack_stage: invalid parameter enum rejected");
590 // Zero-value constants are accepted (the host takes them) and take no SGPRs: the next parameter starts where
591 // they would have.
544 RootSignature zero; 592 RootSignature zero;
545 zero.params = {consts(0)}; 593 zero.params = {consts(0)};
546 check(!pack_stage(zero, Stage::Compute).ok, "pack_stage: zero-value constants rejected"); 594 const StagePackResult lone = pack_stage(zero, Stage::Compute);
595 check(lone.ok && lone.first_sgpr.size() == 1 && lone.first_sgpr[0] == 4 && lone.end_sgpr == 4 &&
596 lone.spill_dwords == 0,
597 "pack_stage: zero-value constants accepted");
598 zero.params = {consts(1), consts(0), table(), consts(0), consts(26)};
599 const StagePackResult mixed = pack_stage(zero, Stage::Compute);
600 check(mixed.ok && mixed.first_sgpr.size() == 5 && mixed.first_sgpr[0] == 4 && mixed.first_sgpr[1] == 5 &&
601 mixed.first_sgpr[2] == 5 && mixed.first_sgpr[3] == 6 && mixed.first_sgpr[4] == 6 &&
602 mixed.end_sgpr == 32 && mixed.spill_dwords == 0 && mixed.d3d12_cost == 1 + 1 + 26,
603 "pack_stage: zero-value constants between others fill compute exactly, offsets unchanged");
604 // In the compute spill array a zero-value constant takes no dwords either: the next parameter shares its offset.
605 zero.params = {consts(28), table(), consts(0), consts(1)};
606 const StagePackResult spilled = pack_stage(zero, Stage::Compute);
607 check(spilled.ok && spilled.end_sgpr == 32 &&
608 spilled.spill_dword == std::vector<uint32_t>({kNoSpill, 0, 1, 1}) && spilled.spill_dwords == 2,
609 "pack_stage: zero-value constants in the compute spill array take no dwords");
547 RootSignature costly; 610 RootSignature costly;
548 costly.params = {consts(32), consts(33)}; 611 costly.params = {consts(32), consts(33)};
549 const StagePackResult costly_r = pack_stage(costly, Stage::Compute); 612 const StagePackResult costly_r = pack_stage(costly, Stage::Compute);