upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/descriptor_table_test.cpp
diff options
context:
space:
mode:
authorTauwni <102470988+Tauwni@users.noreply.github.com>2026-11-26 12:19:12 +0100
committerTauwni <102470988+Tauwni@users.noreply.github.com>2026-11-26 12:19:12 +0100
commitbeffaa9a476ca1b3dfd9cfa55e39eafbb1f5eec6 (patch)
tree32877805bf4eb46d9a89d5753db6b5a2b06dc845 /runtime/test/descriptor_table_test.cpp
parentf29ca7bacae9507f83e8c56abdb604bd4efb4cf1 (diff)
parenta73a57e1339be072baf5522351c8ec7f1482b56b (diff)
Merge main into fix/null-descriptor-generated-dir
Diffstat (limited to 'runtime/test/descriptor_table_test.cpp')
-rw-r--r--runtime/test/descriptor_table_test.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/runtime/test/descriptor_table_test.cpp b/runtime/test/descriptor_table_test.cpp
index 387bd0c60..287d68cde 100644
--- a/runtime/test/descriptor_table_test.cpp
+++ b/runtime/test/descriptor_table_test.cpp
@@ -546,6 +546,49 @@ int test_capacity_overflow() {
546 return 0; 546 return 0;
547} 547}
548 548
549// The entry's last dword is what a `descriptor_table` tagged module reads next to the index: the occupied bit and
550// the arrays the index is bound in (kind_sampled_bit / kind_storage_bit). A plain module never reads it, so a table
551// inserted without a kind must serialize exactly as before (marker, no kind bits).
552int test_kind_word() {
553 DescriptorTable table(16);
554 const DescriptorKey image = make_tsharp_key(std::array<std::uint32_t, 8>{0x00001000u, 0x00000000u, 0u, 0u,
555 0u, 0u, 0u, 0u}.data());
556 const std::uint32_t kind = kind_sampled_bit(1) | kind_storage_bit(1);
557 EXPECT(table.insert(image, 5, kind));
558 EXPECT(table.lookup(image) == 5);
559 const auto words = table.build_gpu_buffer();
560 EXPECT(words[0] == 15);
561 const std::uint32_t slot = (hash_descriptor_key(image.data(), DescriptorHashKind::fnv1a) & 15);
562 if (words[1 + slot * 10 + 8] != 5) return 1; // find the slot the key landed in
563 EXPECT((words[1 + slot * 10 + 9] & kSlotOccupiedMarker) != 0);
564 EXPECT((words[1 + slot * 10 + 9] & kKindMask) == kind);
565
566 // A plain entry: the marker and no kind bits, as before the marker existed.
567 const DescriptorKey plain = make_tsharp_key(std::array<std::uint32_t, 8>{0x00002000u, 0u, 0u, 0u, 0u, 0u, 0u,
568 0u}.data());
569 EXPECT(table.insert(plain, 6));
570 std::uint32_t found[10];
571 EXPECT(table.read_slot(slot, found));
572 (void)found;
573 DescriptorEntry entry{};
574 entry.kind = kSlotOccupiedMarker;
575 EXPECT(slot_occupied(entry) && slot_kind(entry) == 0);
576
577 // The same index with a new kind is a change the GPU copy needs.
578 EXPECT(table.insert_or_update(image.data(), 5, kind_sampled_bit(2)) ==
579 DescriptorTable::InsertResult::replaced);
580 EXPECT(table.insert_or_update(image.data(), 5, kind_sampled_bit(2)) ==
581 DescriptorTable::InsertResult::unchanged);
582 const auto changed = table.take_changes();
583 EXPECT(!changed.slots.empty() || changed.all);
584
585 // clear_occupied drops the marker but keeps the kind, which is what a shader reads.
586 const auto gpu = table.build_gpu_buffer(true);
587 EXPECT((gpu[1 + slot * 10 + 9] & kSlotOccupiedMarker) == 0);
588 EXPECT((gpu[1 + slot * 10 + 9] & kKindMask) == kind_sampled_bit(2));
589 return 0;
590}
591
549int main() { 592int main() {
550 EXPECT(test_unresolvable_hash_collision() == 0); 593 EXPECT(test_unresolvable_hash_collision() == 0);
551 EXPECT(test_capacity_overflow() == 0); 594 EXPECT(test_capacity_overflow() == 0);
@@ -565,6 +608,7 @@ int main() {
565 EXPECT(test_multithreaded_insert_and_lookup() == 0); 608 EXPECT(test_multithreaded_insert_and_lookup() == 0);
566 EXPECT(test_clear_resets_table() == 0); 609 EXPECT(test_clear_resets_table() == 0);
567 EXPECT(test_erase_and_reinsert() == 0); 610 EXPECT(test_erase_and_reinsert() == 0);
611 EXPECT(test_kind_word() == 0);
568 612
569 std::printf("descriptor_table_test: all tests passed (0 failures)\n"); 613 std::printf("descriptor_table_test: all tests passed (0 failures)\n");
570 return 0; 614 return 0;