From e34d2e02611459ba91e7fbdbfc1f5405c46561d2 Mon Sep 17 00:00:00 2001 From: Krzysztof Jakubowski Date: Sun, 4 Feb 2024 21:26:32 +0100 Subject: [PATCH] Vulkan: added basic ray-tracing support --- include/fwk/vulkan/vulkan_instance.h | 1 + include/fwk/vulkan_base.h | 2 +- src/vulkan/vulkan_device.cpp | 11 +++++++++++ src/vulkan/vulkan_instance.cpp | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/fwk/vulkan/vulkan_instance.h b/include/fwk/vulkan/vulkan_instance.h index cbd9fb64..6f676c2a 100644 --- a/include/fwk/vulkan/vulkan_instance.h +++ b/include/fwk/vulkan/vulkan_instance.h @@ -59,6 +59,7 @@ struct VulkanPhysicalDeviceInfo { VkPhysicalDeviceMemoryProperties mem_properties; VkPhysicalDeviceSubgroupProperties subgroup_props; VkPhysicalDeviceSubgroupSizeControlProperties subgroup_control_props; + VkPhysicalDeviceRayTracingPipelinePropertiesKHR raytracing_pipeline_props; vector queue_families; vector extensions; VDepthStencilFormats supported_depth_stencil_formats; diff --git a/include/fwk/vulkan_base.h b/include/fwk/vulkan_base.h index 166d8795..1f809878 100644 --- a/include/fwk/vulkan_base.h +++ b/include/fwk/vulkan_base.h @@ -119,7 +119,7 @@ DEFINE_ENUM(VTexFilter, nearest, linear); DEFINE_ENUM(VTexAddress, repeat, mirror_repeat, clamp_to_edge, clamp_to_border, mirror_clamp_to_edge); -DEFINE_ENUM(VDeviceFeature, memory_budget, subgroup_size_control, shader_clock); +DEFINE_ENUM(VDeviceFeature, memory_budget, subgroup_size_control, shader_clock, ray_tracing); using VDeviceFeatures = EnumFlags; DEFINE_ENUM(VMemoryBlockType, slab, unmanaged, frame, invalid); diff --git a/src/vulkan/vulkan_device.cpp b/src/vulkan/vulkan_device.cpp index 5a924877..26f8ed4e 100644 --- a/src/vulkan/vulkan_device.cpp +++ b/src/vulkan/vulkan_device.cpp @@ -185,6 +185,15 @@ Ex VulkanDevice::initialize(const VDeviceSetup &setup) { m_features |= VDeviceFeature::shader_clock; } + vector raytracing_exts{{VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, + VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, + VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME}}; + if(allOf(raytracing_exts, + [&](const string &ext) { return anyOf(phys_info.extensions, ext); })) { + insertBack(exts, raytracing_exts); + m_features |= VDeviceFeature::ray_tracing; + } + makeSortedUnique(exts); for(auto ext : exts) @@ -214,6 +223,8 @@ Ex VulkanDevice::initialize(const VDeviceSetup &setup) { clock_features.pNext = &subgroup_features; } + VkPhysicalDeviceRayTracingPipelinePropertiesKHR prop; + vector c_exts = transform(exts, [](auto &str) { return str.c_str(); }); VkDeviceCreateInfo ci{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO}; ci.pQueueCreateInfos = queue_cis.data(); diff --git a/src/vulkan/vulkan_instance.cpp b/src/vulkan/vulkan_instance.cpp index bc031268..d748d48f 100644 --- a/src/vulkan/vulkan_instance.cpp +++ b/src/vulkan/vulkan_instance.cpp @@ -135,10 +135,13 @@ static VulkanPhysicalDeviceInfo physicalDeviceInfo(VkPhysicalDevice handle) { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES}; VkPhysicalDeviceSubgroupSizeControlProperties subgroup_control_props{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES}; + VkPhysicalDeviceRayTracingPipelinePropertiesKHR raytracing_props{ + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR}; VkPhysicalDeviceProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; props2.pNext = &subgroup_props; subgroup_props.pNext = &subgroup_control_props; + subgroup_control_props.pNext = &raytracing_props; vkGetPhysicalDeviceProperties2(handle, &props2); subgroup_props.pNext = nullptr; subgroup_control_props.pNext = nullptr; @@ -148,6 +151,7 @@ static VulkanPhysicalDeviceInfo physicalDeviceInfo(VkPhysicalDevice handle) { out.properties = props2.properties; out.subgroup_props = subgroup_props; out.subgroup_control_props = subgroup_control_props; + out.raytracing_pipeline_props = raytracing_props; out.vendor_id = VVendorId::unknown; if(props2.properties.vendorID == 4098) out.vendor_id = VVendorId::amd;