diff options
| author | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-23 00:19:13 +0100 |
|---|---|---|
| committer | Vonsek <45567075+Vonsek@users.noreply.github.com> | 2026-11-23 00:19:13 +0100 |
| commit | fcda84bb0d2c6abb99e42409f413025d00ddb4be (patch) | |
| tree | 27a5ee092be10547ffa5b4447ee050c623c62850 /runtime/test/vk_harness.cpp | |
| parent | 3a1ed28bebf374321149bc4bbffc005ea6f691c4 (diff) | |
| parent | 3986b50821272791333c00df80bdb8526a8fdb9c (diff) | |
Merge hw4-ps-oracle into hw4-ps-formats (#3499)
docs/shader_validation.md
tools/ps_oracle.py
AI-assisted.
Diffstat (limited to 'runtime/test/vk_harness.cpp')
| -rw-r--r-- | runtime/test/vk_harness.cpp | 232 |
1 files changed, 228 insertions, 4 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp index 89505eab3..7bd679f10 100644 --- a/runtime/test/vk_harness.cpp +++ b/runtime/test/vk_harness.cpp | |||
| @@ -23,12 +23,18 @@ | |||
| 23 | // VKH_SUBGROUP_SIZE=32|64 requires that subgroup size of the fragment shader (or of the compute or geometry | 23 | // VKH_SUBGROUP_SIZE=32|64 requires that subgroup size of the fragment shader (or of the compute or geometry |
| 24 | // stage under test); stderr says "fragment subgroup size: N" when it took effect and | 24 | // stage under test); stderr says "fragment subgroup size: N" when it took effect and |
| 25 | // "... not available" when the device cannot require it (exit code stays 0). | 25 | // "... not available" when the device cannot require it (exit code stays 0). |
| 26 | // VKH_TEX_RGBA=<file> binds a 2D RGBA8 texture (u32 width, u32 height, width*height*4 bytes) at bindless | ||
| 27 | // set 0 image index 1 (with 1x1 magenta at index 0), writes a T# at VKH_TSHARP_VA | ||
| 28 | // (default 0x100) in the 64 KiB heap, and registers VKH_SSHARP (4 comma-separated | ||
| 29 | // dwords, default 0x92,0xc00000,0x14500000,0) at sampler index 1. | ||
| 26 | // | 30 | // |
| 27 | #define VK_NO_PROTOTYPES | 31 | #define VK_NO_PROTOTYPES |
| 28 | #include "vulkan_loader.h" | 32 | #include "vulkan_loader.h" |
| 29 | #include "vk_device_pick.h" | 33 | #include "vk_device_pick.h" |
| 30 | #include "vk_shader_fma.h" | 34 | #include "vk_shader_fma.h" |
| 31 | #include "vk_pc_tail.h" | 35 | #include "vk_pc_tail.h" |
| 36 | #include "../src/descriptor_table.h" | ||
| 37 | #include "../src/gfx10_descriptors.h" | ||
| 32 | 38 | ||
| 33 | #include <cctype> | 39 | #include <cctype> |
| 34 | #include <cstddef> | 40 | #include <cstddef> |
| @@ -185,6 +191,55 @@ int main(int argc, char** argv) { | |||
| 185 | heap_bytes, heap_env); | 191 | heap_bytes, heap_env); |
| 186 | return 2; | 192 | return 2; |
| 187 | } | 193 | } |
| 194 | const char* tex_rgba_path = std::getenv("VKH_TEX_RGBA"); | ||
| 195 | if (tex_rgba_path && !*tex_rgba_path) tex_rgba_path = nullptr; | ||
| 196 | uint32_t tsharp_va = 0x100; | ||
| 197 | uint32_t ssharp[8] = {0x92, 0xc00000, 0x14500000, 0, | ||
| 198 | 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu}; | ||
| 199 | uint32_t tex_w = 0, tex_h = 0; | ||
| 200 | std::vector<uint8_t> tex_pixels; | ||
| 201 | if (tex_rgba_path) { | ||
| 202 | if (const char* va_env = std::getenv("VKH_TSHARP_VA"); va_env && *va_env) { | ||
| 203 | const char* p = va_env; | ||
| 204 | if (!parse_u32(p, tsharp_va) || *p || (tsharp_va & 3u) || tsharp_va > heap_bytes - 32) { | ||
| 205 | std::fprintf(stderr, "VKH_TSHARP_VA: expected 4-byte aligned offset at most 0x%x, got \"%s\"\n", | ||
| 206 | heap_bytes - 32, va_env); | ||
| 207 | return 2; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | if (const char* ss_env = std::getenv("VKH_SSHARP"); ss_env && *ss_env) { | ||
| 211 | const char* p = ss_env; | ||
| 212 | for (int i = 0; i < 4; ++i) { | ||
| 213 | if (i && *p++ != ',') { | ||
| 214 | std::fprintf(stderr, "VKH_SSHARP: expected 4 comma-separated dwords, got \"%s\"\n", ss_env); | ||
| 215 | return 2; | ||
| 216 | } | ||
| 217 | if (!parse_u32(p, ssharp[i])) { | ||
| 218 | std::fprintf(stderr, "VKH_SSHARP: expected 4 comma-separated dwords, got \"%s\"\n", ss_env); | ||
| 219 | return 2; | ||
| 220 | } | ||
| 221 | } | ||
| 222 | if (*p) { | ||
| 223 | std::fprintf(stderr, "VKH_SSHARP: expected 4 comma-separated dwords, got \"%s\"\n", ss_env); | ||
| 224 | return 2; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | std::ifstream tf(tex_rgba_path, std::ios::binary); | ||
| 228 | uint32_t hdr[2] = {}; | ||
| 229 | if (!tf.read(reinterpret_cast<char*>(hdr), 8) || hdr[0] == 0 || hdr[1] == 0 || | ||
| 230 | uint64_t(hdr[0]) * uint64_t(hdr[1]) > (1ull << 26)) { | ||
| 231 | std::fprintf(stderr, "VKH_TEX_RGBA: invalid header in %s\n", tex_rgba_path); | ||
| 232 | return 1; | ||
| 233 | } | ||
| 234 | tex_w = hdr[0]; | ||
| 235 | tex_h = hdr[1]; | ||
| 236 | tex_pixels.resize(size_t(tex_w) * size_t(tex_h) * 4); | ||
| 237 | if (!tf.read(reinterpret_cast<char*>(tex_pixels.data()), std::streamsize(tex_pixels.size()))) { | ||
| 238 | std::fprintf(stderr, "VKH_TEX_RGBA: truncated pixel data in %s\n", tex_rgba_path); | ||
| 239 | return 1; | ||
| 240 | } | ||
| 241 | } | ||
| 242 | const bool need_heap = heap_env != nullptr || tex_rgba_path != nullptr; | ||
| 188 | gipa = load_vulkan(); | 243 | gipa = load_vulkan(); |
| 189 | if (!gipa) return 1; | 244 | if (!gipa) return 1; |
| 190 | VkInstance inst = VK_NULL_HANDLE; | 245 | VkInstance inst = VK_NULL_HANDLE; |
| @@ -365,13 +420,22 @@ int main(int argc, char** argv) { | |||
| 365 | chain = &f13; | 420 | chain = &f13; |
| 366 | } | 421 | } |
| 367 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | 422 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; |
| 368 | if (heap_env || mesh_compute) { | 423 | if (need_heap || mesh_compute) { |
| 369 | // 77 is the "this device cannot run the test" code that check.py and run_gpu_tests.py report as SKIP. | 424 | // 77 is the "this device cannot run the test" code that check.py and run_gpu_tests.py report as SKIP. |
| 370 | if (!f12q.bufferDeviceAddress) { | 425 | if (!f12q.bufferDeviceAddress) { |
| 371 | std::fprintf(stderr, "unsupported: %s needs bufferDeviceAddress\n", heap_env ? "VKH_HEAP" : "VKH_MESH_COMPUTE"); | 426 | std::fprintf(stderr, "unsupported: %s needs bufferDeviceAddress\n", |
| 427 | tex_rgba_path ? "VKH_TEX_RGBA" : heap_env ? "VKH_HEAP" : "VKH_MESH_COMPUTE"); | ||
| 372 | return 77; | 428 | return 77; |
| 373 | } | 429 | } |
| 374 | f12.bufferDeviceAddress = VK_TRUE; | 430 | f12.bufferDeviceAddress = VK_TRUE; |
| 431 | if (tex_rgba_path) { | ||
| 432 | if (!f12q.runtimeDescriptorArray || !f12q.descriptorIndexing) { | ||
| 433 | std::fprintf(stderr, "unsupported: VKH_TEX_RGBA needs runtimeDescriptorArray and descriptorIndexing\n"); | ||
| 434 | return 77; | ||
| 435 | } | ||
| 436 | f12.runtimeDescriptorArray = VK_TRUE; | ||
| 437 | f12.descriptorIndexing = VK_TRUE; | ||
| 438 | } | ||
| 375 | f12.pNext = chain; | 439 | f12.pNext = chain; |
| 376 | chain = &f12; | 440 | chain = &f12; |
| 377 | } | 441 | } |
| @@ -425,10 +489,17 @@ int main(int argc, char** argv) { | |||
| 425 | } | 489 | } |
| 426 | feats.shaderFloat64 = VK_TRUE; | 490 | feats.shaderFloat64 = VK_TRUE; |
| 427 | } | 491 | } |
| 428 | if (heap_env || mesh_compute) { | 492 | if (need_heap || mesh_compute) { |
| 429 | if (!f2q.features.shaderInt64) { std::fprintf(stderr, "unsupported: 64-bit addresses need shaderInt64\n"); return 77; } | 493 | if (!f2q.features.shaderInt64) { std::fprintf(stderr, "unsupported: 64-bit addresses need shaderInt64\n"); return 77; } |
| 430 | feats.shaderInt64 = VK_TRUE; // heap and --mesh-compute output addresses are 64-bit | 494 | feats.shaderInt64 = VK_TRUE; // heap and --mesh-compute output addresses are 64-bit |
| 431 | } | 495 | } |
| 496 | if (tex_rgba_path) { | ||
| 497 | if (!f2q.features.shaderSampledImageArrayDynamicIndexing) { | ||
| 498 | std::fprintf(stderr, "unsupported: VKH_TEX_RGBA needs shaderSampledImageArrayDynamicIndexing\n"); | ||
| 499 | return 77; | ||
| 500 | } | ||
| 501 | feats.shaderSampledImageArrayDynamicIndexing = VK_TRUE; | ||
| 502 | } | ||
| 432 | dci.pEnabledFeatures = &feats; | 503 | dci.pEnabledFeatures = &feats; |
| 433 | VkDevice dev; | 504 | VkDevice dev; |
| 434 | CHECK(vkCreateDevice(pd, &dci, nullptr, &dev)); | 505 | CHECK(vkCreateDevice(pd, &dci, nullptr, &dev)); |
| @@ -603,8 +674,27 @@ int main(int argc, char** argv) { | |||
| 603 | const VkShaderStageFlags pcs = (mesh ? VK_SHADER_STAGE_MESH_BIT_EXT : VK_SHADER_STAGE_VERTEX_BIT) | | 674 | const VkShaderStageFlags pcs = (mesh ? VK_SHADER_STAGE_MESH_BIT_EXT : VK_SHADER_STAGE_VERTEX_BIT) | |
| 604 | VK_SHADER_STAGE_FRAGMENT_BIT | (gs_path ? VK_SHADER_STAGE_GEOMETRY_BIT : 0) | | 675 | VK_SHADER_STAGE_FRAGMENT_BIT | (gs_path ? VK_SHADER_STAGE_GEOMETRY_BIT : 0) | |
| 605 | (mesh_compute ? VK_SHADER_STAGE_COMPUTE_BIT : 0); | 676 | (mesh_compute ? VK_SHADER_STAGE_COMPUTE_BIT : 0); |
| 677 | VkDescriptorSetLayout dsl = VK_NULL_HANDLE; | ||
| 678 | VkDescriptorSet ds = VK_NULL_HANDLE; | ||
| 679 | VkImage tex_fallback_img = VK_NULL_HANDLE, tex_img = VK_NULL_HANDLE; | ||
| 680 | VkBuffer tex_staging = VK_NULL_HANDLE; | ||
| 681 | if (tex_rgba_path) { | ||
| 682 | LOADD(vkCreateDescriptorSetLayout); | ||
| 683 | VkDescriptorSetLayoutBinding dslb[3]{}; | ||
| 684 | dslb[0] = {0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 2, VK_SHADER_STAGE_ALL, nullptr}; | ||
| 685 | dslb[1] = {1, VK_DESCRIPTOR_TYPE_SAMPLER, 2, VK_SHADER_STAGE_ALL, nullptr}; | ||
| 686 | dslb[2] = {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr}; | ||
| 687 | VkDescriptorSetLayoutCreateInfo dslci{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; | ||
| 688 | dslci.bindingCount = 3; | ||
| 689 | dslci.pBindings = dslb; | ||
| 690 | CHECK(vkCreateDescriptorSetLayout(dev, &dslci, nullptr, &dsl)); | ||
| 691 | } | ||
| 606 | VkPushConstantRange pcr{pcs, 0, pc_bytes}; | 692 | VkPushConstantRange pcr{pcs, 0, pc_bytes}; |
| 607 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 693 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 694 | if (dsl) { | ||
| 695 | pli.setLayoutCount = 1; | ||
| 696 | pli.pSetLayouts = &dsl; | ||
| 697 | } | ||
| 608 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 698 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; |
| 609 | // --pc-tail-ubo: the tail block at set 1 (set 0 stays empty here), one slot for the one draw. | 699 | // --pc-tail-ubo: the tail block at set 1 (set 0 stays empty here), one slot for the one draw. |
| 610 | leonida::vk_test::PcTail tail; | 700 | leonida::vk_test::PcTail tail; |
| @@ -757,7 +847,9 @@ int main(int argc, char** argv) { | |||
| 757 | std::memcpy(imap, mesh_indices.data(), mesh_indices.size() * 4); | 847 | std::memcpy(imap, mesh_indices.data(), mesh_indices.size() * 4); |
| 758 | } | 848 | } |
| 759 | void* heap_map = nullptr; | 849 | void* heap_map = nullptr; |
| 760 | if (heap_env) { | 850 | uint32_t tsharp[8] = {0x11111111, leonida::gfx10::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM) << 20, 0x33333333, |
| 851 | 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888}; | ||
| 852 | if (need_heap) { | ||
| 761 | LOADD(vkGetBufferDeviceAddress); | 853 | LOADD(vkGetBufferDeviceAddress); |
| 762 | VkBufferCreateInfo hbi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | 854 | VkBufferCreateInfo hbi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; |
| 763 | hbi.size = heap_bytes; | 855 | hbi.size = heap_bytes; |
| @@ -774,12 +866,108 @@ int main(int argc, char** argv) { | |||
| 774 | void* hp; CHECK(vkMapMemory(dev, hmem, 0, heap_bytes, 0, &hp)); | 866 | void* hp; CHECK(vkMapMemory(dev, hmem, 0, heap_bytes, 0, &hp)); |
| 775 | heap_map = hp; | 867 | heap_map = hp; |
| 776 | std::memset(hp, 0, heap_bytes); | 868 | std::memset(hp, 0, heap_bytes); |
| 869 | if (tex_rgba_path) std::memcpy(static_cast<char*>(hp) + tsharp_va, tsharp, 32); | ||
| 777 | for (auto [addr, word] : heap_words) std::memcpy(static_cast<char*>(hp) + addr, &word, 4); | 870 | for (auto [addr, word] : heap_words) std::memcpy(static_cast<char*>(hp) + addr, &word, 4); |
| 778 | VkBufferDeviceAddressInfo hda{VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO}; | 871 | VkBufferDeviceAddressInfo hda{VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO}; |
| 779 | hda.buffer = heap; | 872 | hda.buffer = heap; |
| 780 | const uint64_t base = vkGetBufferDeviceAddress(dev, &hda); | 873 | const uint64_t base = vkGetBufferDeviceAddress(dev, &hda); |
| 781 | pc[32] = uint32_t(base); pc[33] = uint32_t(base >> 32); | 874 | pc[32] = uint32_t(base); pc[33] = uint32_t(base >> 32); |
| 782 | } | 875 | } |
| 876 | if (tex_rgba_path) { | ||
| 877 | LOADD(vkCreateSampler); LOADD(vkCreateDescriptorPool); LOADD(vkAllocateDescriptorSets); | ||
| 878 | LOADD(vkUpdateDescriptorSets); | ||
| 879 | leonida::DescriptorTable desc_table(16); | ||
| 880 | desc_table.insert(tsharp, 1); | ||
| 881 | desc_table.insert(ssharp, 1); | ||
| 882 | const auto table = desc_table.build_gpu_buffer(true); | ||
| 883 | VkBuffer tb = VK_NULL_HANDLE; | ||
| 884 | VkDeviceMemory tbm = VK_NULL_HANDLE; | ||
| 885 | void* tbp = nullptr; | ||
| 886 | { | ||
| 887 | VkBufferCreateInfo tbi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | ||
| 888 | tbi.size = table.size() * 4; tbi.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; | ||
| 889 | CHECK(vkCreateBuffer(dev, &tbi, nullptr, &tb)); | ||
| 890 | VkMemoryRequirements tmr; vkGetBufferMemoryRequirements(dev, tb, &tmr); | ||
| 891 | VkMemoryAllocateInfo tai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; | ||
| 892 | tai.allocationSize = tmr.size; | ||
| 893 | tai.memoryTypeIndex = memtype(tmr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); | ||
| 894 | CHECK(vkAllocateMemory(dev, &tai, nullptr, &tbm)); | ||
| 895 | CHECK(vkBindBufferMemory(dev, tb, tbm, 0)); | ||
| 896 | CHECK(vkMapMemory(dev, tbm, 0, tbi.size, 0, &tbp)); | ||
| 897 | std::memcpy(tbp, table.data(), table.size() * 4); | ||
| 898 | } | ||
| 899 | auto make_sampled_tex = [&](uint32_t tw, uint32_t th, VkImage& out_img, VkImageView& out_view) -> int { | ||
| 900 | VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; | ||
| 901 | ii.imageType = VK_IMAGE_TYPE_2D; ii.format = VK_FORMAT_R8G8B8A8_UNORM; ii.extent = {tw, th, 1}; | ||
| 902 | ii.mipLevels = 1; ii.arrayLayers = 1; ii.samples = VK_SAMPLE_COUNT_1_BIT; | ||
| 903 | ii.tiling = VK_IMAGE_TILING_OPTIMAL; | ||
| 904 | ii.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; | ||
| 905 | CHECK(vkCreateImage(dev, &ii, nullptr, &out_img)); | ||
| 906 | VkMemoryRequirements mr; vkGetImageMemoryRequirements(dev, out_img, &mr); | ||
| 907 | VkMemoryAllocateInfo mai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; | ||
| 908 | mai.allocationSize = mr.size; | ||
| 909 | mai.memoryTypeIndex = memtype(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); | ||
| 910 | VkDeviceMemory mem; CHECK(vkAllocateMemory(dev, &mai, nullptr, &mem)); | ||
| 911 | CHECK(vkBindImageMemory(dev, out_img, mem, 0)); | ||
| 912 | VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; | ||
| 913 | vi.image = out_img; vi.viewType = VK_IMAGE_VIEW_TYPE_2D; vi.format = VK_FORMAT_R8G8B8A8_UNORM; | ||
| 914 | vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; | ||
| 915 | CHECK(vkCreateImageView(dev, &vi, nullptr, &out_view)); | ||
| 916 | return 0; | ||
| 917 | }; | ||
| 918 | VkImageView tex_views[2]{}; | ||
| 919 | if (make_sampled_tex(1, 1, tex_fallback_img, tex_views[0]) || | ||
| 920 | make_sampled_tex(tex_w, tex_h, tex_img, tex_views[1])) return 1; | ||
| 921 | { | ||
| 922 | const VkDeviceSize stage_bytes = 4 + tex_pixels.size(); | ||
| 923 | VkBufferCreateInfo sbi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | ||
| 924 | sbi.size = stage_bytes; sbi.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; | ||
| 925 | CHECK(vkCreateBuffer(dev, &sbi, nullptr, &tex_staging)); | ||
| 926 | VkMemoryRequirements smr; vkGetBufferMemoryRequirements(dev, tex_staging, &smr); | ||
| 927 | VkMemoryAllocateInfo sai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; | ||
| 928 | sai.allocationSize = smr.size; | ||
| 929 | sai.memoryTypeIndex = memtype(smr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); | ||
| 930 | VkDeviceMemory smem; CHECK(vkAllocateMemory(dev, &sai, nullptr, &smem)); | ||
| 931 | CHECK(vkBindBufferMemory(dev, tex_staging, smem, 0)); | ||
| 932 | void* sp = nullptr; CHECK(vkMapMemory(dev, smem, 0, stage_bytes, 0, &sp)); | ||
| 933 | const uint32_t magenta = 0xFFFF00FFu; | ||
| 934 | std::memcpy(sp, &magenta, 4); | ||
| 935 | std::memcpy(static_cast<char*>(sp) + 4, tex_pixels.data(), tex_pixels.size()); | ||
| 936 | } | ||
| 937 | VkSampler samplers[2]{}; | ||
| 938 | VkSamplerCreateInfo def_sci{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; | ||
| 939 | def_sci.magFilter = VK_FILTER_NEAREST; def_sci.minFilter = VK_FILTER_NEAREST; | ||
| 940 | CHECK(vkCreateSampler(dev, &def_sci, nullptr, &samplers[0])); | ||
| 941 | const leonida::gfx10::SamplerWords sw{ssharp[0], ssharp[1], ssharp[2], ssharp[3]}; | ||
| 942 | VkSamplerCreateInfo sci = leonida::gfx10::vulkan_sampler(leonida::gfx10::decode(sw)); | ||
| 943 | sci.anisotropyEnable = VK_FALSE; | ||
| 944 | CHECK(vkCreateSampler(dev, &sci, nullptr, &samplers[1])); | ||
| 945 | VkDescriptorPoolSize dps[3] = { | ||
| 946 | {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 2}, | ||
| 947 | {VK_DESCRIPTOR_TYPE_SAMPLER, 2}, | ||
| 948 | {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, | ||
| 949 | }; | ||
| 950 | VkDescriptorPoolCreateInfo dpci{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; | ||
| 951 | dpci.maxSets = 1; dpci.poolSizeCount = 3; dpci.pPoolSizes = dps; | ||
| 952 | VkDescriptorPool dpool; CHECK(vkCreateDescriptorPool(dev, &dpci, nullptr, &dpool)); | ||
| 953 | VkDescriptorSetAllocateInfo dsai{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; | ||
| 954 | dsai.descriptorPool = dpool; dsai.descriptorSetCount = 1; dsai.pSetLayouts = &dsl; | ||
| 955 | CHECK(vkAllocateDescriptorSets(dev, &dsai, &ds)); | ||
| 956 | VkDescriptorImageInfo img_infos[2] = { | ||
| 957 | {VK_NULL_HANDLE, tex_views[0], VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}, | ||
| 958 | {VK_NULL_HANDLE, tex_views[1], VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}, | ||
| 959 | }; | ||
| 960 | VkDescriptorImageInfo smp_infos[2] = { | ||
| 961 | {samplers[0], VK_NULL_HANDLE, VK_IMAGE_LAYOUT_UNDEFINED}, | ||
| 962 | {samplers[1], VK_NULL_HANDLE, VK_IMAGE_LAYOUT_UNDEFINED}, | ||
| 963 | }; | ||
| 964 | VkDescriptorBufferInfo tbl_info{tb, 0, VK_WHOLE_SIZE}; | ||
| 965 | VkWriteDescriptorSet writes[3]{}; | ||
| 966 | writes[0] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, ds, 0, 0, 2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, img_infos}; | ||
| 967 | writes[1] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, ds, 1, 0, 2, VK_DESCRIPTOR_TYPE_SAMPLER, smp_infos}; | ||
| 968 | writes[2] = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, nullptr, ds, 2, 0, 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, nullptr, &tbl_info}; | ||
| 969 | vkUpdateDescriptorSets(dev, 3, writes, 0, nullptr); | ||
| 970 | } | ||
| 783 | const uint64_t mesh_groups = uint64_t(groups[0]) * groups[1] * groups[2]; | 971 | const uint64_t mesh_groups = uint64_t(groups[0]) * groups[1] * groups[2]; |
| 784 | if (mesh_compute) { | 972 | if (mesh_compute) { |
| 785 | LOADD(vkGetBufferDeviceAddress); | 973 | LOADD(vkGetBufferDeviceAddress); |
| @@ -818,6 +1006,38 @@ int main(int argc, char** argv) { | |||
| 818 | std::memcpy(pc, shifts, sizeof(shifts)); | 1006 | std::memcpy(pc, shifts, sizeof(shifts)); |
| 819 | } | 1007 | } |
| 820 | auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants")); | 1008 | auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants")); |
| 1009 | if (tex_rgba_path) { | ||
| 1010 | LOADD(vkCmdPipelineBarrier); LOADD(vkCmdCopyBufferToImage); | ||
| 1011 | VkImageMemoryBarrier to_dst[2]{}; | ||
| 1012 | for (int i = 0; i < 2; ++i) { | ||
| 1013 | to_dst[i].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; | ||
| 1014 | to_dst[i].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; | ||
| 1015 | to_dst[i].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; | ||
| 1016 | to_dst[i].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; | ||
| 1017 | to_dst[i].image = i == 0 ? tex_fallback_img : tex_img; | ||
| 1018 | to_dst[i].subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; | ||
| 1019 | } | ||
| 1020 | vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, | ||
| 1021 | 0, nullptr, 0, nullptr, 2, to_dst); | ||
| 1022 | VkBufferImageCopy c0{}; | ||
| 1023 | c0.bufferOffset = 0; c0.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; c0.imageExtent = {1, 1, 1}; | ||
| 1024 | vkCmdCopyBufferToImage(cmd, tex_staging, tex_fallback_img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &c0); | ||
| 1025 | VkBufferImageCopy c1{}; | ||
| 1026 | c1.bufferOffset = 4; c1.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; c1.imageExtent = {tex_w, tex_h, 1}; | ||
| 1027 | vkCmdCopyBufferToImage(cmd, tex_staging, tex_img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &c1); | ||
| 1028 | VkImageMemoryBarrier to_ro[2]{}; | ||
| 1029 | for (int i = 0; i < 2; ++i) { | ||
| 1030 | to_ro[i].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; | ||
| 1031 | to_ro[i].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; | ||
| 1032 | to_ro[i].dstAccessMask = VK_ACCESS_SHADER_READ_BIT; | ||
| 1033 | to_ro[i].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; | ||
| 1034 | to_ro[i].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; | ||
| 1035 | to_ro[i].image = i == 0 ? tex_fallback_img : tex_img; | ||
| 1036 | to_ro[i].subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; | ||
| 1037 | } | ||
| 1038 | vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, | ||
| 1039 | 0, nullptr, 0, nullptr, 2, to_ro); | ||
| 1040 | } | ||
| 821 | if (mesh_compute) { | 1041 | if (mesh_compute) { |
| 822 | // The mesh shader as compute, then make its stores visible to the vertex shader's reads. | 1042 | // The mesh shader as compute, then make its stores visible to the vertex shader's reads. |
| 823 | LOADD(vkCmdDispatch); | 1043 | LOADD(vkCmdDispatch); |
| @@ -843,6 +1063,10 @@ int main(int argc, char** argv) { | |||
| 843 | std::fprintf(stderr, "mesh workgroups: %u x %u x %u\n", groups[0], groups[1], groups[2]); | 1063 | std::fprintf(stderr, "mesh workgroups: %u x %u x %u\n", groups[0], groups[1], groups[2]); |
| 844 | } | 1064 | } |
| 845 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); | 1065 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); |
| 1066 | if (ds) { | ||
| 1067 | LOADD(vkCmdBindDescriptorSets); | ||
| 1068 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl, 0, 1, &ds, 0, nullptr); | ||
| 1069 | } | ||
| 846 | push(cmd, pl, pcs, 0, pc_bytes, pc); | 1070 | push(cmd, pl, pcs, 0, pc_bytes, pc); |
| 847 | if (tail_block) { | 1071 | if (tail_block) { |
| 848 | LOADD(vkCmdBindDescriptorSets); | 1072 | LOADD(vkCmdBindDescriptorSets); |