Skip to content

Commit

Permalink
Vulkan: added basic ray-tracing support
Browse files Browse the repository at this point in the history
  • Loading branch information
nadult committed Feb 4, 2024
1 parent 364bb0e commit e34d2e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/fwk/vulkan/vulkan_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct VulkanPhysicalDeviceInfo {
VkPhysicalDeviceMemoryProperties mem_properties;
VkPhysicalDeviceSubgroupProperties subgroup_props;
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_control_props;
VkPhysicalDeviceRayTracingPipelinePropertiesKHR raytracing_pipeline_props;
vector<VkQueueFamilyProperties> queue_families;
vector<string> extensions;
VDepthStencilFormats supported_depth_stencil_formats;
Expand Down
2 changes: 1 addition & 1 deletion include/fwk/vulkan_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VDeviceFeature>;

DEFINE_ENUM(VMemoryBlockType, slab, unmanaged, frame, invalid);
Expand Down
11 changes: 11 additions & 0 deletions src/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ Ex<void> VulkanDevice::initialize(const VDeviceSetup &setup) {
m_features |= VDeviceFeature::shader_clock;
}

vector<string> 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)
Expand Down Expand Up @@ -214,6 +223,8 @@ Ex<void> VulkanDevice::initialize(const VDeviceSetup &setup) {
clock_features.pNext = &subgroup_features;
}

VkPhysicalDeviceRayTracingPipelinePropertiesKHR prop;

vector<const char *> c_exts = transform(exts, [](auto &str) { return str.c_str(); });
VkDeviceCreateInfo ci{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
ci.pQueueCreateInfos = queue_cis.data();
Expand Down
4 changes: 4 additions & 0 deletions src/vulkan/vulkan_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit e34d2e0

Please sign in to comment.