Skip to content

Commit

Permalink
Implement RAY_QUERY instead of RAY_TRACING_PIPELINE since there's no …
Browse files Browse the repository at this point in the history
…actual API surface for it
  • Loading branch information
tangmi committed Jan 26, 2021
1 parent 399737f commit 16c5212
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 58 deletions.
3 changes: 1 addition & 2 deletions examples/ray-tracing/main.rs
Expand Up @@ -150,8 +150,7 @@ fn main() {

let adapter = adapters.remove(0);

let required_features =
hal::Features::ACCELERATION_STRUCTURE | hal::Features::RAY_TRACING_PIPELINE;
let required_features = hal::Features::ACCELERATION_STRUCTURE; // | hal::Features::RAY_QUERY;

assert!(adapter
.physical_device
Expand Down
13 changes: 0 additions & 13 deletions src/backend/vulkan/src/conv.rs
Expand Up @@ -592,19 +592,6 @@ pub(crate) fn map_device_features(
} else {
None
},
ray_tracing_pipeline: if features.contains(Features::RAY_TRACING_PIPELINE) {
Some(
vk::PhysicalDeviceRayTracingPipelineFeaturesKHR::builder()
.ray_tracing_pipeline(features.contains(Features::RAY_TRACING_PIPELINE))
// .ray_tracing_pipeline_shader_group_handle_capture_replay()
// .ray_tracing_pipeline_shader_group_handle_capture_replay_mixed()
// .ray_tracing_pipeline_trace_rays_indirect()
// .ray_traversal_primitive_culling()
.build(),
)
} else {
None
},
}
}

Expand Down
49 changes: 11 additions & 38 deletions src/backend/vulkan/src/lib.rs
Expand Up @@ -32,7 +32,7 @@ use ash::{
extensions::{
self,
ext::{DebugReport, DebugUtils},
khr::{AccelerationStructure, DrawIndirectCount, RayTracingPipeline, Swapchain},
khr::{AccelerationStructure, DrawIndirectCount, RayQuery, Swapchain},
nv::MeshShader,
},
version::{DeviceV1_0, EntryV1_0, InstanceV1_0},
Expand Down Expand Up @@ -684,7 +684,6 @@ pub struct DeviceCreationFeatures {
imageless_framebuffers: Option<vk::PhysicalDeviceImagelessFramebufferFeaturesKHR>,
buffer_device_address: Option<vk::PhysicalDeviceBufferDeviceAddressFeaturesKHR>,
acceleration_structure: Option<vk::PhysicalDeviceAccelerationStructureFeaturesKHR>,
ray_tracing_pipeline: Option<vk::PhysicalDeviceRayTracingPipelineFeaturesKHR>,
}

impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
Expand Down Expand Up @@ -776,12 +775,11 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
enabled_extensions.push(extensions::khr::DeferredHostOperations::name());
}

if requested_features.contains(Features::RAY_TRACING_PIPELINE) {
enabled_extensions.push(RayTracingPipeline::name());
if requested_features.contains(Features::RAY_QUERY) {
enabled_extensions.push(RayQuery::name());

// TODO better handling of extension dependencies? These are required by VK_KHR_ray_tracing_pipeline
// TODO better handling of extension dependencies? These are required by VK_KHR_ray_query
enabled_extensions.push(vk::KhrSpirv14Fn::name());
enabled_extensions.push(vk::KhrShaderFloatControlsFn::name());
}

enabled_extensions
Expand Down Expand Up @@ -844,13 +842,6 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
info
};

let info =
if let Some(ref mut ray_tracing_pipeline) = enabled_features.ray_tracing_pipeline {
info.push_next(ray_tracing_pipeline)
} else {
info
};

match self.instance.inner.create_device(self.handle, &info, None) {
Ok(device) => device,
Err(e) => {
Expand Down Expand Up @@ -1069,7 +1060,7 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
let mut descriptor_indexing_features = None;
let mut buffer_device_address = None;
let mut acceleration_structure_features = None;
let mut ray_tracing_pipeline_features = None;
let mut ray_query_features = None;
let features = if let Some(ref get_device_properties) =
self.instance.get_physical_device_properties
{
Expand Down Expand Up @@ -1103,11 +1094,10 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
mut_ref.p_next = mem::replace(&mut features2.p_next, mut_ref as *mut _ as *mut _);
}

if self.supports_extension(RayTracingPipeline::name()) {
ray_tracing_pipeline_features =
Some(vk::PhysicalDeviceRayTracingPipelineFeaturesKHR::builder().build());
if self.supports_extension(RayQuery::name()) {
ray_query_features = Some(vk::PhysicalDeviceRayQueryFeaturesKHR::builder().build());

let mut_ref = ray_tracing_pipeline_features.as_mut().unwrap();
let mut_ref = ray_query_features.as_mut().unwrap();
mut_ref.p_next = mem::replace(&mut features2.p_next, mut_ref as *mut _ as *mut _);
}

Expand Down Expand Up @@ -1346,26 +1336,9 @@ impl adapter::PhysicalDevice<Backend> for PhysicalDevice {
// TODO
}
}
if let Some(ray_tracing_pipeline_features) = ray_tracing_pipeline_features {
if ray_tracing_pipeline_features.ray_tracing_pipeline == vk::TRUE {
bits |= Features::RAY_TRACING_PIPELINE;
}
if ray_tracing_pipeline_features.ray_tracing_pipeline_shader_group_handle_capture_replay
== vk::TRUE
{
// bits |= Features::RAY_TRACING_PIPELINE_SHADER_GROUP_HANDLE_CAPTURE_REPLAY;
}
if ray_tracing_pipeline_features
.ray_tracing_pipeline_shader_group_handle_capture_replay_mixed
== vk::TRUE
{
// bits |= Features::RAY_TRACING_PIPELINE_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_MIXED;
}
if ray_tracing_pipeline_features.ray_tracing_pipeline_trace_rays_indirect == vk::TRUE {
// bits |= Features::RAY_TRACING_PIPELINE_TRACE_RAYS_INDIRECT;
}
if ray_tracing_pipeline_features.ray_traversal_primitive_culling == vk::TRUE {
// bits |= Features::RAY_TRAVERSAL_PRIMITIVE_CULLING;
if let Some(ray_query_features) = ray_query_features {
if ray_query_features.ray_query == vk::TRUE {
bits |= Features::RAY_QUERY;
}
}
if let Some(buffer_device_address) = buffer_device_address {
Expand Down
7 changes: 2 additions & 5 deletions src/hal/src/lib.rs
Expand Up @@ -286,11 +286,8 @@ bitflags! {
// TODO this is not supported for other resource types yet
// const ACCELERATION_STRUCTURE_UPDATE_AFTER_BIND = 0x0010 << 112;

///
const RAY_TRACING_PIPELINE = 0x0020 << 112;

// ///
// const RAY_QUERY = 0x0040 << 112;
/// Support ray query functionality in shaders.
const RAY_QUERY = 0x0020 << 112;
}
}

Expand Down

0 comments on commit 16c5212

Please sign in to comment.