From a92179b4cb3f3e2088d3739034ad3848b0d7aa69 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Tue, 18 Aug 2026 01:32:30 +0200 Subject: Rework feature detection Change target spriv version to support untyped pointers in shaders --- build.bat | 2 +- include/vk-device.hpp | 2 - shaders/transmittance_lut.comp | 14 ++-- src/vk-device.cpp | 146 ++++++++++++++++------------------------- 4 files changed, 62 insertions(+), 102 deletions(-) diff --git a/build.bat b/build.bat index 7a8be5c..84a2d1d 100644 --- a/build.bat +++ b/build.bat @@ -36,7 +36,7 @@ set L_FLAGS=/WX /SUBSYSTEM:CONSOLE /stack:0x10000000,10000000 :: set L_FLAGS=/WX /SUBSYSTEM:CONSOLE /NODEFAULTLIB /stack:0x100000,100000 :: set L_FLAGS=/WX /SUBSYSTEM:CONSOLE /NODEFAULTLIB -set SHADERS_C_FLAGS=-I shaders\include -std=460 +set SHADERS_C_FLAGS=-I shaders\include -std=460 --target-spv=spv1.6 set DEBUG_C_FLAGS= set DEBUG_L_FLAGS= diff --git a/include/vk-device.hpp b/include/vk-device.hpp index 913a28b..5be416b 100644 --- a/include/vk-device.hpp +++ b/include/vk-device.hpp @@ -95,8 +95,6 @@ class vkdevice { void create_device(); - bool device_support_features(VkPhysicalDevice physical_dev); - queue queues[static_cast(QueueType::MAX)]; static constexpr size_t max_allocable_command_buffers = 16; diff --git a/shaders/transmittance_lut.comp b/shaders/transmittance_lut.comp index f932d69..207184c 100644 --- a/shaders/transmittance_lut.comp +++ b/shaders/transmittance_lut.comp @@ -8,15 +8,11 @@ layout(descriptor_heap) uniform texture2D textures[]; layout(descriptor_heap, rgba32f) uniform image2D images[]; layout(descriptor_heap) uniform sampler samplers[]; -layout(buffer_reference) readonly buffer draw_params { +layout(push_constant) uniform buffers { uint output_image_index; uint width; uint height; uint pad; -}; - -layout(push_constant) uniform buffers { - layout(offset = 16) draw_params draw; } regs; vec2 sphere_intersection ( in vec3 orig, in vec3 dir, float radius ) { @@ -43,7 +39,7 @@ void main() { const float top_radius = 6420.f; const float atmosphere_radius = top_radius - ground_radius; - vec2 uvs = vec2(coords) / vec2(regs.draw.width, regs.draw.height); + vec2 uvs = vec2(coords) / vec2(regs.width, regs.height); float cos_mu = uvs.y * 2.f - 1.f; float mu = acos(cos_mu); @@ -73,9 +69,9 @@ void main() { } // val.x = t; - // imageStore(images[nonuniformEXT(regs.draw.output_image_index)], coords, val); + // imageStore(images[nonuniformEXT(regs.output_image_index)], coords, val); // return; - imageStore(images[nonuniformEXT(regs.draw.output_image_index)], coords, vec4(t, 0.f, 0.f, 1.f)); + imageStore(images[nonuniformEXT(regs.output_image_index)], coords, vec4(t, 0.f, 0.f, 1.f)); return; vec3 transmittance = vec3(0.f); @@ -95,5 +91,5 @@ void main() { color.xyz = vec3(0.f); color.x = t; - imageStore(images[nonuniformEXT(regs.draw.output_image_index)], coords, color); + imageStore(images[nonuniformEXT(regs.output_image_index)], coords, color); } diff --git a/src/vk-device.cpp b/src/vk-device.cpp index bf18610..7be2d22 100644 --- a/src/vk-device.cpp +++ b/src/vk-device.cpp @@ -25,7 +25,16 @@ VkPhysicalDeviceDescriptorHeapPropertiesEXT descriptor_heap_props { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_PROPERTIES_EXT, }; -void create_heaps(size_t max_images, size_t max_samplers) { +struct physical_device_features { + VkPhysicalDeviceFeatures2 physical_device_features2; + VkPhysicalDeviceVulkan12Features physical_device_12_features; + VkPhysicalDeviceVulkan13Features physical_device_13_features; + VkPhysicalDeviceVulkan14Features physical_device_14_features; + VkPhysicalDeviceDescriptorHeapFeaturesEXT descriptor_heap_features; + VkPhysicalDeviceShaderUntypedPointersFeaturesKHR shader_untyped_pointers_features; +}; + +static void create_heaps(size_t max_images, size_t max_samplers) { // create image heap { image_heap = vkdevice::get().create_buffer({ @@ -55,7 +64,7 @@ void create_heaps(size_t max_images, size_t max_samplers) { } } -device_semaphore create_semaphore(const semaphore_desc& desc, const char* name) { +static device_semaphore create_semaphore(const semaphore_desc& desc, const char* name) { device_semaphore semaphore { .value = desc.initial_value, }; @@ -861,7 +870,33 @@ void vkdevice::create_instance() { void vkdevice::create_device() { // pick physical device - // TODO: change put this in another scope + struct physical_device_features features = { + .physical_device_features2 = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, + .pNext = &features.physical_device_12_features, + }, + .physical_device_12_features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, + .pNext = &features.physical_device_13_features, + }, + .physical_device_13_features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, + .pNext = &features.physical_device_14_features, + }, + .physical_device_14_features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES, + .pNext = &features.descriptor_heap_features, + }, + .descriptor_heap_features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_FEATURES_EXT, + .pNext = &features.shader_untyped_pointers_features, + }, + .shader_untyped_pointers_features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_UNTYPED_POINTERS_FEATURES_KHR, + .pNext = nullptr, + }, + }; + { u32 physical_devices_count = 0U; vkEnumeratePhysicalDevices(instance, &physical_devices_count, nullptr); @@ -877,9 +912,24 @@ void vkdevice::create_device() { for (u32 physical_device_index = 0U; physical_device_index < physical_devices_count; physical_device_index++) { VkPhysicalDevice physical_dev = physical_devices[physical_device_index]; - if (device_support_features(physical_dev)) { - physical_device = physical_dev; + vkGetPhysicalDeviceProperties2(physical_dev, &physical_device_props); + vkGetPhysicalDeviceFeatures2(physical_dev, &features.physical_device_features2); + + if (features.physical_device_12_features.timelineSemaphore == VK_TRUE && + features.physical_device_12_features.bufferDeviceAddress == VK_TRUE && + features.physical_device_12_features.runtimeDescriptorArray == VK_TRUE && + features.physical_device_12_features.shaderStorageImageArrayNonUniformIndexing == VK_TRUE && + features.physical_device_12_features.shaderSampledImageArrayNonUniformIndexing == VK_TRUE && + features.physical_device_12_features.descriptorBindingPartiallyBound == VK_TRUE && + features.physical_device_12_features.descriptorBindingUpdateUnusedWhilePending == VK_TRUE && + features.physical_device_12_features.imagelessFramebuffer == VK_TRUE && + features.physical_device_13_features.synchronization2 == VK_TRUE && + features.physical_device_13_features.dynamicRendering == VK_TRUE && + features.physical_device_14_features.maintenance5 == VK_TRUE && + features.descriptor_heap_features.descriptorHeap == VK_TRUE && + features.shader_untyped_pointers_features.shaderUntypedPointers == VK_TRUE) { + physical_device = physical_dev; break; } } @@ -924,41 +974,9 @@ void vkdevice::create_device() { VK_KHR_SHADER_UNTYPED_POINTERS_EXTENSION_NAME, }; - VkPhysicalDeviceVulkan12Features physical_device_12_features{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, - .pNext = nullptr, - .shaderSampledImageArrayNonUniformIndexing = VK_TRUE, - .shaderStorageImageArrayNonUniformIndexing = VK_TRUE, - .descriptorBindingUpdateUnusedWhilePending = VK_TRUE, - .descriptorBindingPartiallyBound = VK_TRUE, - .runtimeDescriptorArray = VK_TRUE, - .timelineSemaphore = VK_TRUE, - .bufferDeviceAddress = VK_TRUE, - }; - - VkPhysicalDeviceVulkan13Features physical_device_13_features{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, - .pNext = &physical_device_12_features, - .synchronization2 = VK_TRUE, - .dynamicRendering = VK_TRUE, - }; - - VkPhysicalDeviceDescriptorHeapFeaturesEXT descriptor_heap_features { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_HEAP_FEATURES_EXT, - .pNext = &physical_device_13_features, - .descriptorHeap = VK_TRUE, - .descriptorHeapCaptureReplay = VK_TRUE, - }; - - VkPhysicalDeviceShaderUntypedPointersFeaturesKHR shader_untyped_pointers_features { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_UNTYPED_POINTERS_FEATURES_KHR, - .pNext = &descriptor_heap_features, - .shaderUntypedPointers = VK_TRUE, - }; - VkDeviceCreateInfo create_info{ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, - .pNext = &shader_untyped_pointers_features, + .pNext = &features.physical_device_features2, .flags = 0U, .queueCreateInfoCount = static_cast(QueueType::MAX), .pQueueCreateInfos = queue_create_infos, @@ -1014,58 +1032,6 @@ void vkdevice::create_device() { } -bool vkdevice::device_support_features(VkPhysicalDevice physical_dev) { - // limits - vkGetPhysicalDeviceProperties2(physical_dev, &physical_device_props); - - // Vulkan 1.2 physical device features support - { - VkPhysicalDeviceVulkan12Features vulkan_12_features{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, - }; - - VkPhysicalDeviceFeatures2 physical_device_features{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, - .pNext = &vulkan_12_features, - }; - - vkGetPhysicalDeviceFeatures2(physical_dev, &physical_device_features); - - if (vulkan_12_features.bufferDeviceAddress == VK_FALSE || - vulkan_12_features.runtimeDescriptorArray == VK_FALSE || - vulkan_12_features.shaderStorageImageArrayNonUniformIndexing == VK_FALSE || - vulkan_12_features.shaderSampledImageArrayNonUniformIndexing == VK_FALSE || - vulkan_12_features.descriptorBindingPartiallyBound == VK_FALSE || - vulkan_12_features.descriptorBindingUpdateUnusedWhilePending == VK_FALSE || - vulkan_12_features.imagelessFramebuffer == VK_FALSE) { - return false; - } - } - - // Vulkan 1.3 physical device features support - { - VkPhysicalDeviceVulkan13Features vulkan_13_features{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, - .pNext = nullptr, - }; - - VkPhysicalDeviceFeatures2 physical_device_features{ - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, - .pNext = &vulkan_13_features, - }; - - vkGetPhysicalDeviceFeatures2(physical_dev, &physical_device_features); - - if (vulkan_13_features.synchronization2 == VK_FALSE || - vulkan_13_features.dynamicRendering == VK_FALSE) { - return false; - } - } - - return true; -} - - idlist<> device_texture::sampled_indices = {}; idlist<> device_texture::storage_indices = {}; idlist<> device_sampler::sampler_indices = {}; -- cgit v1.3