diff options
Diffstat (limited to 'runtime/test/vk_texture_test.cpp')
| -rw-r--r-- | runtime/test/vk_texture_test.cpp | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/runtime/test/vk_texture_test.cpp b/runtime/test/vk_texture_test.cpp index a46338bf6..fafc8ef50 100644 --- a/runtime/test/vk_texture_test.cpp +++ b/runtime/test/vk_texture_test.cpp | |||
| @@ -34,23 +34,7 @@ static std::vector<uint32_t> read_spv(const char* p) { | |||
| 34 | return w; | 34 | return w; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | // Same hash as the translator's desc_lookup: FNV-1a over the 8 key dwords (whole dwords, not bytes). | 37 | #include "../src/descriptor_table.h" |
| 38 | static uint32_t key_hash(const uint32_t k[8]) { | ||
| 39 | uint32_t h = 2166136261u; | ||
| 40 | for (int i = 0; i < 8; i++) h = (h ^ k[i]) * 16777619u; | ||
| 41 | return h; | ||
| 42 | } | ||
| 43 | static void table_insert(std::vector<uint32_t>& t, const uint32_t key[8], uint32_t index) { | ||
| 44 | uint32_t mask = t[0], h = key_hash(key); | ||
| 45 | for (uint32_t k = 0; k < 8; k++) { | ||
| 46 | uint32_t slot = (h + k) & mask, base = slot * 10; | ||
| 47 | if (t[base + 10] == 0xA11CA7ED) continue; // pad dword marks a used slot (host-side only) | ||
| 48 | for (int j = 0; j < 8; j++) t[base + 1 + j] = key[j]; | ||
| 49 | t[base + 9] = index; | ||
| 50 | t[base + 10] = 0xA11CA7ED; | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | 38 | ||
| 55 | int main(int argc, char** argv) { | 39 | int main(int argc, char** argv) { |
| 56 | if (argc < 9) { std::fprintf(stderr, "usage: vk_texture_test vs fs out ptr_sgpr s0 s1 s2 s3\n"); return 2; } | 40 | if (argc < 9) { std::fprintf(stderr, "usage: vk_texture_test vs fs out ptr_sgpr s0 s1 s2 s3\n"); return 2; } |
| @@ -133,11 +117,10 @@ int main(int argc, char** argv) { | |||
| 133 | VkBufferDeviceAddressInfo bdai{VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO}; bdai.buffer = heap; | 117 | VkBufferDeviceAddressInfo bdai{VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO}; bdai.buffer = heap; |
| 134 | VkDeviceAddress heap_base = vkGetBufferDeviceAddress(dev, &bdai); | 118 | VkDeviceAddress heap_base = vkGetBufferDeviceAddress(dev, &bdai); |
| 135 | // Descriptor hash table: 16 slots. | 119 | // Descriptor hash table: 16 slots. |
| 136 | std::vector<uint32_t> table(1 + 16 * 10 + 10, 0); | 120 | leonida::DescriptorTable desc_table(16); |
| 137 | table[0] = 15; | 121 | desc_table.insert(tsharp, 1); |
| 138 | table_insert(table, tsharp, 1); | 122 | desc_table.insert(ssharp, 1); |
| 139 | table_insert(table, ssharp, 1); | 123 | const auto table = desc_table.build_gpu_buffer(true); |
| 140 | for (uint32_t s = 0; s <= 16; s++) if (s * 10 + 10 < table.size() && table[s * 10 + 10] == 0xA11CA7ED) table[s * 10 + 10] = 0; | ||
| 141 | VkBuffer tb; VkDeviceMemory tbm; void* tbp; | 124 | VkBuffer tb; VkDeviceMemory tbm; void* tbp; |
| 142 | CHECK(make_buffer(table.size() * 4, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, &tb, &tbm, &tbp)); | 125 | CHECK(make_buffer(table.size() * 4, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, &tb, &tbm, &tbp)); |
| 143 | std::memcpy(tbp, table.data(), table.size() * 4); | 126 | std::memcpy(tbp, table.data(), table.size() * 4); |