upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/vk_bindless_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/vk_bindless_test.cpp
parentf29ca7bacae9507f83e8c56abdb604bd4efb4cf1 (diff)
parenta73a57e1339be072baf5522351c8ec7f1482b56b (diff)
Merge main into fix/null-descriptor-generated-dir
Diffstat (limited to 'runtime/test/vk_bindless_test.cpp')
-rw-r--r--runtime/test/vk_bindless_test.cpp306
1 files changed, 291 insertions, 15 deletions
diff --git a/runtime/test/vk_bindless_test.cpp b/runtime/test/vk_bindless_test.cpp
index 194df74a9..dc33e7d91 100644
--- a/runtime/test/vk_bindless_test.cpp
+++ b/runtime/test/vk_bindless_test.cpp
@@ -738,6 +738,222 @@ int main(int argc, char** argv) {
738 return submit() == VK_SUCCESS && ok; 738 return submit() == VK_SUCCESS && ok;
739 }; 739 };
740 740
741 const float orange_pixel[4] = {1.0f, 128.0f / 255.0f, 0.0f, 1.0f};
742 const float fallback_pixels[4] = {0.0f, 0.0f, 0.0f, 0.0f};
743
744 // The mirror (BindlessSet::MirrorViews): a 2D-array T# read by a 2D op finds its slice 0 bound in the 2D
745 // arrays at the T#'s own index. The index spaces are per dimension and dense, so slot N of one dimension
746 // and a 2D-array image's mirror slot N coincide: the set records which image owns a mirror slot, not just
747 // that it is used.
748 {
749 // A 2D-array image of two layers (layer 0 orange, layer 1 blue) with its own 2D-array and storage views
750 // plus a 2D view of layer 0, which is what a mirror binds. The storage view puts the index in the
751 // storage range, as in the index-space checks below.
752 const auto make_layered = [&](VkImage* image, VkImageView* layers, VkImageView* layer0) {
753 VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
754 ii.imageType = VK_IMAGE_TYPE_2D;
755 ii.format = VK_FORMAT_R8G8B8A8_UNORM;
756 ii.extent = {1, 1, 1};
757 ii.mipLevels = 1;
758 ii.arrayLayers = 2;
759 ii.samples = VK_SAMPLE_COUNT_1_BIT;
760 ii.tiling = VK_IMAGE_TILING_OPTIMAL;
761 ii.usage = sampled_usage | VK_IMAGE_USAGE_STORAGE_BIT;
762 VkResult r = vkCreateImage(dev, &ii, nullptr, image);
763 if (r) return r;
764 VkMemoryRequirements mr;
765 vkGetImageMemoryRequirements(dev, *image, &mr);
766 VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
767 ai.allocationSize = mr.size;
768 ai.memoryTypeIndex = memtype(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
769 VkDeviceMemory m = VK_NULL_HANDLE;
770 if ((r = vkAllocateMemory(dev, &ai, nullptr, &m))) return r;
771 allocations.push_back(m);
772 if ((r = vkBindImageMemory(dev, *image, m, 0))) return r;
773 VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
774 vi.image = *image;
775 vi.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
776 vi.format = VK_FORMAT_R8G8B8A8_UNORM;
777 vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2};
778 if ((r = vkCreateImageView(dev, &vi, nullptr, layers))) return r;
779 vi.viewType = VK_IMAGE_VIEW_TYPE_2D;
780 vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
781 return vkCreateImageView(dev, &vi, nullptr, layer0);
782 };
783 const auto upload_layered = [&](VkImage image) {
784 constexpr std::uint32_t blue = 0xffff0000u; // r = 0, g = 0, b = 255, a = 255
785 std::memcpy(static_cast<char*>(upload_map) + 1028, &blue, 4);
786 VkResult r = vkResetCommandBuffer(cmd, 0);
787 if (r) return r;
788 if ((r = vkBeginCommandBuffer(cmd, &begin))) return r;
789 VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
790 b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
791 b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
792 b.image = image;
793 b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2};
794 b.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
795 b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
796 vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0,
797 nullptr, 0, nullptr, 1, &b);
798 for (std::uint32_t layer = 0; layer < 2; ++layer) {
799 VkBufferImageCopy c{};
800 c.bufferOffset = 1024 + layer * 4;
801 c.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, layer, 1};
802 c.imageExtent = {1, 1, 1};
803 vkCmdCopyBufferToImage(cmd, upload, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &c);
804 }
805 b.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
806 b.newLayout = VK_IMAGE_LAYOUT_GENERAL; // sampled and storage
807 b.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
808 b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
809 vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0,
810 nullptr, 0, nullptr, 1, &b);
811 return submit();
812 };
813 // A 3D image with a storage view: its own index space, whose slot numbers are the 2D arrays' too.
814 const auto make_volume = [&](VkImage* image, VkImageView* view) {
815 VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
816 ii.imageType = VK_IMAGE_TYPE_3D;
817 ii.format = VK_FORMAT_R8G8B8A8_UNORM;
818 ii.extent = {1, 1, 1};
819 ii.mipLevels = 1;
820 ii.arrayLayers = 1;
821 ii.samples = VK_SAMPLE_COUNT_1_BIT;
822 ii.tiling = VK_IMAGE_TILING_OPTIMAL;
823 ii.usage = sampled_usage | VK_IMAGE_USAGE_STORAGE_BIT;
824 VkResult r = vkCreateImage(dev, &ii, nullptr, image);
825 if (r) return r;
826 VkMemoryRequirements mr;
827 vkGetImageMemoryRequirements(dev, *image, &mr);
828 VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
829 ai.allocationSize = mr.size;
830 ai.memoryTypeIndex = memtype(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
831 VkDeviceMemory m = VK_NULL_HANDLE;
832 if ((r = vkAllocateMemory(dev, &ai, nullptr, &m))) return r;
833 allocations.push_back(m);
834 if ((r = vkBindImageMemory(dev, *image, m, 0))) return r;
835 VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
836 vi.image = *image;
837 vi.viewType = VK_IMAGE_VIEW_TYPE_3D;
838 vi.format = VK_FORMAT_R8G8B8A8_UNORM;
839 vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
840 return vkCreateImageView(dev, &vi, nullptr, view);
841 };
842 const auto add_mirrored = [&](VkImageView layers, VkImageView layer0, std::uint32_t* index,
843 std::uint32_t* kind) {
844 StorageViews storage;
845 storage.as_float = layers;
846 BindlessSet::MirrorViews mirror{};
847 mirror.sampled = layer0;
848 mirror.sampled_layout = VK_IMAGE_LAYOUT_GENERAL;
849 mirror.storage.as_float = layer0;
850 *index = set.add_image(ImageDimension::dim_2d_array, layers, VK_IMAGE_LAYOUT_GENERAL, storage, 0,
851 &mirror, kind);
852 return *index != 0;
853 };
854 const auto draw_with = [&](const DescriptorKey& key) {
855 std::memcpy(static_cast<char*>(heap_map) + table_va, key.data(), 32);
856 return draw();
857 };
858
859 const std::uint32_t free_2d = set.free_images(ImageDimension::dim_2d);
860 const std::uint32_t free_array = set.free_images(ImageDimension::dim_2d_array);
861 VkImage layered = VK_NULL_HANDLE;
862 VkImageView layered_view = VK_NULL_HANDLE, layer0 = VK_NULL_HANDLE;
863 CHECK(make_layered(&layered, &layered_view, &layer0));
864 CHECK(upload_layered(layered));
865
866 std::uint32_t index = 0, kind = 0;
867 EXPECT(add_mirrored(layered_view, layer0, &index, &kind));
868 // The allocation is in both index spaces: the T#'s dimension and the 2D arrays (the mirror's slot).
869 EXPECT(set.free_images(ImageDimension::dim_2d) == free_2d - 1);
870 EXPECT(set.free_images(ImageDimension::dim_2d_array) == free_array - 1);
871 // The entry names the 2D-array arrays and their storage arrays, and the 2D ones the mirror is bound in.
872 EXPECT(kind == (kind_sampled_bit(1) | kind_storage_bit(1) | kind_sampled_bit(0) | kind_storage_bit(0)));
873 EXPECT(set.image_kind_at(ImageDimension::dim_2d_array, index) == kind);
874 EXPECT(set.image_kind_at(ImageDimension::dim_2d, index) ==
875 (kind_sampled_bit(0) | kind_storage_bit(0)));
876 EXPECT(set.insert_key(tsharp, index, kind));
877 EXPECT(flush());
878 CHECK(draw());
879 compare("mirror: a 2D-array T# read by a 2D op", orange_pixel);
880 // Removing the image puts the 2D slot back to its fallback. Its entry still names 2D (the kind it had),
881 // so a 2D op reads that slot: it must hold zeros, not the removed mirror.
882 EXPECT(set.erase_key(tsharp));
883 set.remove_image(ImageDimension::dim_2d_array, index);
884 EXPECT(flush());
885 EXPECT((set.image_kind_at(ImageDimension::dim_2d_array, index) & kind_sampled_bit(0)) == 0);
886 EXPECT(set.free_images(ImageDimension::dim_2d) == free_2d);
887 EXPECT(set.free_images(ImageDimension::dim_2d_array) == free_array);
888 EXPECT(set.insert_key(tsharp, index, kind));
889 EXPECT(flush());
890 CHECK(draw());
891 compare("mirror: removed, the 2D slot holds the fallback", fallback_pixels);
892 EXPECT(set.erase_key(tsharp));
893
894 // The aliasing scenario the owner records: a 2D-array image with its mirror at slot N and a 3D image at
895 // its own index N (both index spaces are dense, so both take the lowest storage slot). Neither may claim
896 // the other's slot, and removing either must leave the other's binding alone.
897 VkImage layered2 = VK_NULL_HANDLE;
898 VkImageView layered2_view = VK_NULL_HANDLE, layer0_2 = VK_NULL_HANDLE;
899 CHECK(make_layered(&layered2, &layered2_view, &layer0_2));
900 CHECK(upload_layered(layered2));
901 std::uint32_t array_index = 0, array_kind = 0;
902 EXPECT(add_mirrored(layered2_view, layer0_2, &array_index, &array_kind));
903 VkImage volume = VK_NULL_HANDLE;
904 VkImageView volume_view = VK_NULL_HANDLE;
905 CHECK(make_volume(&volume, &volume_view));
906 StorageViews volume_storage;
907 volume_storage.as_float = volume_view;
908 const std::uint32_t volume_index = set.add_image(ImageDimension::dim_3d, volume_view,
909 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, volume_storage);
910 EXPECT(volume_index != 0 && volume_index == array_index); // the same slot number, two index spaces
911 const std::uint32_t volume_kind = set.image_kind_at(ImageDimension::dim_3d, volume_index);
912 // The 3D image does not own the 2D mirror: a 2D op reading its T# takes the 2D fallback.
913 EXPECT(volume_kind == (kind_sampled_bit(2) | kind_storage_bit(2)));
914 EXPECT((volume_kind & kind_sampled_bit(0)) == 0);
915 EXPECT(set.image_kind_at(ImageDimension::dim_2d_array, array_index) == array_kind);
916 DescriptorKey volume_key = tsharp; // the same FORMAT (word 1), a different key
917 volume_key[7] ^= 0x10u;
918 EXPECT(set.insert_key(tsharp, array_index, array_kind));
919 EXPECT(set.insert_key(volume_key, volume_index, volume_kind));
920 EXPECT(flush());
921 CHECK(draw_with(volume_key));
922 compare("alias: a 3D T# at another image's mirror slot", fallback_pixels);
923 CHECK(draw_with(tsharp));
924 compare("alias: the mirror, with the 3D image at the same slot", orange_pixel);
925 // Removing the 3D image must not take the 2D-array image's mirror with it.
926 EXPECT(set.erase_key(volume_key));
927 set.remove_image(ImageDimension::dim_3d, volume_index);
928 EXPECT(flush());
929 EXPECT(set.image_kind_at(ImageDimension::dim_2d_array, array_index) == array_kind);
930 CHECK(draw_with(tsharp));
931 compare("alias: the mirror survives the 3D image's removal", orange_pixel);
932 // And removing the 2D-array image frees the 2D slot: a 3D image at that slot number names no mirror.
933 const std::uint32_t volume_again = set.add_image(ImageDimension::dim_3d, volume_view,
934 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, volume_storage);
935 EXPECT(volume_again == volume_index);
936 EXPECT(set.insert_key(volume_key, volume_again, set.image_kind_at(ImageDimension::dim_3d, volume_again)));
937 EXPECT(set.erase_key(tsharp));
938 set.remove_image(ImageDimension::dim_2d_array, array_index);
939 EXPECT(flush());
940 EXPECT((set.image_kind_at(ImageDimension::dim_3d, volume_again) & kind_sampled_bit(0)) == 0);
941 EXPECT(set.free_images(ImageDimension::dim_2d) == free_2d);
942 CHECK(draw_with(volume_key));
943 compare("alias: no mirror once the 2D-array image is gone", fallback_pixels);
944 EXPECT(set.erase_key(volume_key));
945 set.remove_image(ImageDimension::dim_3d, volume_again);
946 EXPECT(flush());
947 // The steps below expect tsharp at the heap's T# again.
948 std::memcpy(static_cast<char*>(heap_map) + table_va, tsharp.data(), 32);
949 vkDestroyImageView(dev, volume_view, nullptr);
950 vkDestroyImage(dev, volume, nullptr);
951 for (const VkImageView view : {layered_view, layer0, layered2_view, layer0_2})
952 vkDestroyImageView(dev, view, nullptr);
953 vkDestroyImage(dev, layered, nullptr);
954 vkDestroyImage(dev, layered2, nullptr);
955 }
956
741 // Index spaces. An image with storage views gets an index the storage arrays hold; one without goes above 957 // Index spaces. An image with storage views gets an index the storage arrays hold; one without goes above
742 // them where the dimension has room. A dimension that is full gives 0, and removed indices come back. 958 // them where the dimension has room. A dimension that is full gives 0, and removed indices come back.
743 StorageViews as_storage; 959 StorageViews as_storage;
@@ -763,6 +979,61 @@ int main(int argc, char** argv) {
763 const std::uint32_t sampler_index = set.add_sampler(nearest); 979 const std::uint32_t sampler_index = set.add_sampler(nearest);
764 EXPECT(decoy_sampler == 1 && sampler_index == 2 && set.free_samplers() == set.sampler_capacity() - 3); 980 EXPECT(decoy_sampler == 1 && sampler_index == 2 && set.free_samplers() == set.sampler_capacity() - 3);
765 981
982 // The T#'s own type is the truth. This shader samples in 2D; the 3D image's index is 1 in the 3D arrays,
983 // and index 1 of the 2D arrays is `stored_view` (its own image, a red texel). The entry says the index is
984 // bound in the 3D arrays only, so the 2D read must use the 2D array's fallback and read zeros - not
985 // `stored_view`, which is what indexing the instruction's array with the other dimension's index would do.
986 {
987 EXPECT(stored_index == 1);
988 VkImage volume = VK_NULL_HANDLE;
989 VkImageView volume_view = VK_NULL_HANDLE;
990 {
991 const VkImageUsageFlags usage =
992 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
993 VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
994 ii.imageType = VK_IMAGE_TYPE_3D;
995 ii.format = VK_FORMAT_R8G8B8A8_UNORM;
996 ii.extent = {2, 2, 2};
997 ii.mipLevels = 1;
998 ii.arrayLayers = 1;
999 ii.samples = VK_SAMPLE_COUNT_1_BIT;
1000 ii.tiling = VK_IMAGE_TILING_OPTIMAL;
1001 ii.usage = usage;
1002 CHECK(vkCreateImage(dev, &ii, nullptr, &volume));
1003 VkMemoryRequirements mr;
1004 vkGetImageMemoryRequirements(dev, volume, &mr);
1005 VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
1006 ai.allocationSize = mr.size;
1007 ai.memoryTypeIndex = memtype(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
1008 VkDeviceMemory memory = VK_NULL_HANDLE;
1009 CHECK(vkAllocateMemory(dev, &ai, nullptr, &memory));
1010 allocations.push_back(memory);
1011 CHECK(vkBindImageMemory(dev, volume, memory, 0));
1012 VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
1013 vi.image = volume;
1014 vi.viewType = VK_IMAGE_VIEW_TYPE_3D;
1015 vi.format = VK_FORMAT_R8G8B8A8_UNORM;
1016 vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
1017 CHECK(vkCreateImageView(dev, &vi, nullptr, &volume_view));
1018 }
1019 // A storage view puts it in the low index region, so its index is 1: the same slot number as
1020 // `stored_view` in the 2D arrays, which a dimension-blind read would pick up.
1021 StorageViews volume_storage;
1022 volume_storage.as_float = volume_view;
1023 const std::uint32_t volume_index = set.add_image(ImageDimension::dim_3d, volume_view,
1024 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, volume_storage);
1025 EXPECT(volume_index == stored_index); // the same slot number, a different index space
1026 EXPECT(set.insert_key(tsharp, volume_index, ImageDimension::dim_3d));
1027 EXPECT(flush());
1028 EXPECT(draw() == VK_SUCCESS);
1029 const float zeros[4] = {0.0f, 0.0f, 0.0f, 0.0f};
1030 compare("a 3D T# read by a 2D op", zeros);
1031 EXPECT(set.erase_key(tsharp));
1032 set.remove_image(ImageDimension::dim_3d, volume_index);
1033 vkDestroyImageView(dev, volume_view, nullptr);
1034 vkDestroyImage(dev, volume, nullptr);
1035 }
1036
766 if (atomic_mode) { 1037 if (atomic_mode) {
767 // ps_imgatomic.asm: image_atomic_umax/umin/or on three 8x8 r32ui images and umax on a 4x4x4 one, from 1038 // ps_imgatomic.asm: image_atomic_umax/umin/or on three 8x8 r32ui images and umax on a 4x4x4 one, from
768 // every pixel of the 64x64 draw (64 pixels per 2D texel), each found through its own T# key. Odd 1039 // every pixel of the 64x64 draw (64 pixels per 2D texel), each found through its own T# key. Odd
@@ -815,7 +1086,8 @@ int main(int argc, char** argv) {
815 indices[k] = set.add_image(k == 3 ? ImageDimension::dim_3d : ImageDimension::dim_2d, views[k], 1086 indices[k] = set.add_image(k == 3 ? ImageDimension::dim_3d : ImageDimension::dim_2d, views[k],
816 VK_IMAGE_LAYOUT_GENERAL, storage); 1087 VK_IMAGE_LAYOUT_GENERAL, storage);
817 EXPECT(indices[k] != 0); 1088 EXPECT(indices[k] != 0);
818 EXPECT(set.insert_key(keys[k], indices[k])); 1089 EXPECT(set.insert_key(keys[k], indices[k],
1090 k == 3 ? ImageDimension::dim_3d : ImageDimension::dim_2d));
819 } 1091 }
820 EXPECT(flush()); 1092 EXPECT(flush());
821 1093
@@ -963,9 +1235,10 @@ int main(int argc, char** argv) {
963 const auto target = (slots - 4 + i % kDescriptorProbes) & (slots - 1); 1235 const auto target = (slots - 4 + i % kDescriptorProbes) & (slots - 1);
964 while ((hash_descriptor_key(key) & (slots - 1)) != target) ++key[7]; 1236 while ((hash_descriptor_key(key) & (slots - 1)) != target) ++key[7];
965 } 1237 }
966 for (std::uint32_t i = 0; i < kDescriptorProbes; ++i) set.insert_key(keys[i], decoy_index); 1238 for (std::uint32_t i = 0; i < kDescriptorProbes; ++i)
1239 set.insert_key(keys[i], decoy_index, ImageDimension::dim_2d);
967 EXPECT(!set.flush_replaces_table() && flush()); 1240 EXPECT(!set.flush_replaces_table() && flush());
968 EXPECT(set.insert_key(keys.back(), gradient_index)); 1241 EXPECT(set.insert_key(keys.back(), gradient_index, ImageDimension::dim_2d));
969 EXPECT(slot_count() == slots && set.flush_replaces_table()); 1242 EXPECT(slot_count() == slots && set.flush_replaces_table());
970 EXPECT(flush() && !set.flush_replaces_table()); 1243 EXPECT(flush() && !set.flush_replaces_table());
971 for (const auto& key : keys) { 1244 for (const auto& key : keys) {
@@ -979,12 +1252,13 @@ int main(int argc, char** argv) {
979 std::uint32_t ahead = 0; 1252 std::uint32_t ahead = 0;
980 for (std::uint32_t k = 1; ahead < 3; ++k) { 1253 for (std::uint32_t k = 1; ahead < 3; ++k) {
981 if ((hash_descriptor_key(numbered(k)) & (slots - 1)) != home) continue; 1254 if ((hash_descriptor_key(numbered(k)) & (slots - 1)) != home) continue;
982 set.insert_key(numbered(k), decoy_index); 1255 set.insert_key(numbered(k), decoy_index, ImageDimension::dim_2d);
983 ++ahead; 1256 ++ahead;
984 } 1257 }
985 set.insert_key(tsharp, gradient_index); 1258 set.insert_key(tsharp, gradient_index, ImageDimension::dim_2d);
986 set.insert_key(make_ssharp_key(ssharp.data()), sampler_index); 1259 set.insert_key(make_ssharp_key(ssharp.data()), sampler_index);
987 for (std::uint32_t k = 100000; k < 100006; ++k) set.insert_key(numbered(k), decoy_index); 1260 for (std::uint32_t k = 100000; k < 100006; ++k)
1261 set.insert_key(numbered(k), decoy_index, ImageDimension::dim_2d);
988 const std::uint32_t depth = probe_depth(table.build_gpu_buffer(), tsharp); 1262 const std::uint32_t depth = probe_depth(table.build_gpu_buffer(), tsharp);
989 EXPECT(slot_count() == slots && depth == 3 && !set.flush_replaces_table()); 1263 EXPECT(slot_count() == slots && depth == 3 && !set.flush_replaces_table());
990 EXPECT(flush()); 1264 EXPECT(flush());
@@ -1000,9 +1274,10 @@ int main(int argc, char** argv) {
1000 compare("2 miss", zeros); 1274 compare("2 miss", zeros);
1001 1275
1002 // 3. The table grows: a new, larger buffer behind binding 2. 1276 // 3. The table grows: a new, larger buffer behind binding 2.
1003 set.insert_key(tsharp, gradient_index); 1277 set.insert_key(tsharp, gradient_index, ImageDimension::dim_2d);
1004 EXPECT(!set.flush_replaces_table()); // one more entry, in place 1278 EXPECT(!set.flush_replaces_table()); // one more entry, in place
1005 for (std::uint32_t k = 200000; k < 200200; ++k) set.insert_key(numbered(k), decoy_index); 1279 for (std::uint32_t k = 200000; k < 200200; ++k)
1280 set.insert_key(numbered(k), decoy_index, ImageDimension::dim_2d);
1006 EXPECT(slot_count() > slots && table.lookup(tsharp) == gradient_index && set.flush_replaces_table()); 1281 EXPECT(slot_count() > slots && table.lookup(tsharp) == gradient_index && set.flush_replaces_table());
1007 const VkDescriptorSet before_growth = set.set(); 1282 const VkDescriptorSet before_growth = set.set();
1008 const std::uint64_t made_before = set.generations_made(); 1283 const std::uint64_t made_before = set.generations_made();
@@ -1020,12 +1295,13 @@ int main(int argc, char** argv) {
1020 const float orange_colour[4] = {1.0f, 128.0f / 255.0f, 0.0f, 1.0f}; 1295 const float orange_colour[4] = {1.0f, 128.0f / 255.0f, 0.0f, 1.0f};
1021 // Rewriting the same mapping is a no-op. Changing it makes a new generation even with no table growth. 1296 // Rewriting the same mapping is a no-op. Changing it makes a new generation even with no table growth.
1022 const std::uint32_t grown_slots = slot_count(); 1297 const std::uint32_t grown_slots = slot_count();
1023 EXPECT(set.insert_key(tsharp, gradient_index) && !set.flush_replaces_table()); 1298 EXPECT(set.insert_key(tsharp, gradient_index, ImageDimension::dim_2d) && !set.flush_replaces_table());
1024 EXPECT(set.insert_key(tsharp, decoy_index) && slot_count() == grown_slots && set.flush_replaces_table()); 1299 EXPECT(set.insert_key(tsharp, decoy_index, ImageDimension::dim_2d) && slot_count() == grown_slots &&
1300 set.flush_replaces_table());
1025 EXPECT(flush() && !set.flush_replaces_table()); 1301 EXPECT(flush() && !set.flush_replaces_table());
1026 CHECK(draw()); 1302 CHECK(draw());
1027 compare("4 rebound", orange_colour); 1303 compare("4 rebound", orange_colour);
1028 EXPECT(set.insert_key(tsharp, gradient_index) && set.flush_replaces_table()); 1304 EXPECT(set.insert_key(tsharp, gradient_index, ImageDimension::dim_2d) && set.flush_replaces_table());
1029 EXPECT(flush()); 1305 EXPECT(flush());
1030 CHECK(draw()); 1306 CHECK(draw());
1031 compare("5 restored", nullptr); 1307 compare("5 restored", nullptr);
@@ -1033,7 +1309,7 @@ int main(int argc, char** argv) {
1033 // A submit that never reached the queue must keep the table upload pending: the retry has to see the new 1309 // A submit that never reached the queue must keep the table upload pending: the retry has to see the new
1034 // mapping instead of the fallback or the old index (a recovered submit failure, the case a device reports 1310 // mapping instead of the fallback or the old index (a recovered submit failure, the case a device reports
1035 // through table_upload_result(false)). 1311 // through table_upload_result(false)).
1036 EXPECT(set.insert_key(tsharp, decoy_index) && set.flush_replaces_table()); 1312 EXPECT(set.insert_key(tsharp, decoy_index, ImageDimension::dim_2d) && set.flush_replaces_table());
1037 vkResetCommandBuffer(cmd, 0); 1313 vkResetCommandBuffer(cmd, 0);
1038 CHECK(vkBeginCommandBuffer(cmd, &begin)); 1314 CHECK(vkBeginCommandBuffer(cmd, &begin));
1039 EXPECT(set.flush(cmd, 1)); // recorded in a command buffer that is never submitted 1315 EXPECT(set.flush(cmd, 1)); // recorded in a command buffer that is never submitted
@@ -1043,7 +1319,7 @@ int main(int argc, char** argv) {
1043 EXPECT(flush()); 1319 EXPECT(flush());
1044 CHECK(draw()); 1320 CHECK(draw());
1045 compare("6 rebound after a failed submit", orange_colour); 1321 compare("6 rebound after a failed submit", orange_colour);
1046 EXPECT(set.insert_key(tsharp, gradient_index) && set.flush_replaces_table()); 1322 EXPECT(set.insert_key(tsharp, gradient_index, ImageDimension::dim_2d) && set.flush_replaces_table());
1047 EXPECT(flush()); 1323 EXPECT(flush());
1048 1324
1049 // Another view at the same index, then removal of the index. 1325 // Another view at the same index, then removal of the index.
@@ -1066,7 +1342,7 @@ int main(int argc, char** argv) {
1066 far_image = set.add_image(ImageDimension::dim_2d, gradient_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); 1342 far_image = set.add_image(ImageDimension::dim_2d, gradient_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
1067 for (std::uint32_t i = 0; i < 2100; ++i) far_sampler = set.add_sampler(nearest); 1343 for (std::uint32_t i = 0; i < 2100; ++i) far_sampler = set.add_sampler(nearest);
1068 EXPECT(far_image > 5000 && far_sampler > 2100); 1344 EXPECT(far_image > 5000 && far_sampler > 2100);
1069 set.insert_key(tsharp, far_image); 1345 set.insert_key(tsharp, far_image, ImageDimension::dim_2d);
1070 set.insert_key(make_ssharp_key(ssharp.data()), far_sampler); 1346 set.insert_key(make_ssharp_key(ssharp.data()), far_sampler);
1071 EXPECT(flush()); 1347 EXPECT(flush());
1072 CHECK(draw()); 1348 CHECK(draw());
@@ -1087,7 +1363,7 @@ int main(int argc, char** argv) {
1087 const float blue[4] = {0, 0, 128.0f / 255.0f, 1}; // stored image uses the first gradient texel 1363 const float blue[4] = {0, 0, 128.0f / 255.0f, 1}; // stored image uses the first gradient texel
1088 compare("11 reused high slot", blue); 1364 compare("11 reused high slot", blue);
1089 1365
1090 EXPECT(set.insert_key(tsharp, neighbour)); 1366 EXPECT(set.insert_key(tsharp, neighbour, ImageDimension::dim_2d));
1091 EXPECT(flush()); 1367 EXPECT(flush());
1092 CHECK(draw()); 1368 CHECK(draw());
1093 compare("12 live neighbour", orange_colour); 1369 compare("12 live neighbour", orange_colour);