diff --git a/crates/spirv-std/src/ray_tracing.rs b/crates/spirv-std/src/ray_tracing.rs index 23403feb66..8e10e14d3f 100644 --- a/crates/spirv-std/src/ray_tracing.rs +++ b/crates/spirv-std/src/ray_tracing.rs @@ -159,6 +159,22 @@ bitflags::bitflags! { } } +#[repr(u32)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[allow(clippy::upper_case_acronyms)] +pub enum CandidateIntersection { + Triangle = 0, + AABB = 1, +} + +#[repr(u32)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum CommittedIntersection { + None = 0, + Triangle = 1, + Generated = 2, +} + /// A ray query type which is an opaque object representing a ray traversal. #[spirv(ray_query)] pub struct RayQuery { @@ -276,24 +292,51 @@ impl RayQuery { asm!("OpRayQueryTerminateKHR {}", in(reg) self) } - /// Returns the type of the current candidate or committed intersection. + /// Returns the type of the current candidate intersection. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionTypeKHR")] #[inline] - pub unsafe fn get_intersection_type(&self) -> u32 { - let mut result = 0; + pub unsafe fn get_candidate_intersection_type(&self) -> CandidateIntersection { + let result: u32; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionTypeKHR %u32 {ray_query} %intersection", - "OpStore {result} %result", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionTypeKHR %u32 {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, - result = in(reg) &mut result, + result = out(reg) result, } - result + match result { + 0 => CandidateIntersection::Triangle, + 1 => CandidateIntersection::AABB, + _ => CandidateIntersection::Triangle, + } + } + + /// Returns the type of the current candidate intersection. + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionTypeKHR")] + #[inline] + pub unsafe fn get_committed_intersection_type(&self) -> CommittedIntersection { + let result: u32; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "{result} = OpRayQueryGetIntersectionTypeKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, + } + + match result { + 0 => CommittedIntersection::None, + 1 => CommittedIntersection::Triangle, + 2 => CommittedIntersection::Generated, + _ => CommittedIntersection::None, + } } /// Returns the "Ray Tmin" value used by the ray query. @@ -301,14 +344,13 @@ impl RayQuery { #[doc(alias = "OpRayQueryGetRayTMinKHR")] #[inline] pub unsafe fn get_ray_t_min(&self) -> f32 { - let mut result = 0.0; + let result; asm! { "%f32 = OpTypeFloat 32", - "%result = OpRayQueryGetRayTMinKHR %f32 {ray_query}", - "OpStore {result} %result", + "{result} = OpRayQueryGetRayTMinKHR %f32 {ray_query}", ray_query = in(reg) self, - result = in(reg) &mut result, + result = out(reg) result, } result @@ -319,14 +361,12 @@ impl RayQuery { #[doc(alias = "OpRayQueryGetRayFlagsKHR")] #[inline] pub unsafe fn get_ray_flags(&self) -> RayFlags { - let mut result = 0; + let result; asm! { - "%u32 = OpTypeInt 32 0", - "%result = OpRayQueryGetRayFlagsKHR %u32 {ray_query}", - "OpStore {result} %result", + "{result} = OpRayQueryGetRayFlagsKHR typeof{result} {ray_query}", ray_query = in(reg) self, - result = in(reg) &mut result, + result = out(reg) result, } RayFlags::from_bits_truncate(result) @@ -334,21 +374,46 @@ impl RayQuery { /// Gets the "T" value for the current or previous intersection considered /// in a ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. + /// The current intersection candidate must have a [`Self::get_candidate_intersection_type()`] + /// of [`CandidateIntersection::Triangle`]. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionTKHR")] #[inline] - pub unsafe fn get_intersection_t(&self) -> f32 { - let mut result = 0.0; + pub unsafe fn get_candidate_intersection_t(&self) -> f32 { + let result; asm! { - "%f32 = OpTypeFloat 32", "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionTKHR %f32 {ray_query} %intersection", - "OpStore {result} %result", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionTKHR typeof{result} {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, - result = in(reg) &mut result, + result = out(reg) result, + } + + result + } + + /// Gets the "T" value for the current or previous intersection considered + /// in a ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionTKHR")] + #[inline] + pub unsafe fn get_committed_intersection_t(&self) -> f32 { + let result; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "{result} = OpRayQueryGetIntersectionTKHR typeof{result} {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, } result @@ -356,20 +421,44 @@ impl RayQuery { /// Gets the custom index of the instance for the current intersection /// considered in a ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionInstanceCustomIndexKHR")] #[inline] - pub unsafe fn get_intersection_instance_custom_index(&self) -> u32 { - let mut result = 0; + pub unsafe fn get_candidate_intersection_instance_custom_index(&self) -> u32 { + let result; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionInstanceCustomIndexKHR %u32 {ray_query} %intersection", - "OpStore {result} %result", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionInstanceCustomIndexKHR %u32 {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, - result = in(reg) &mut result, + result = out(reg) result, + } + + result + } + + /// Gets the custom index of the instance for the current intersection + /// considered in a ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionInstanceCustomIndexKHR")] + #[inline] + pub unsafe fn get_committed_intersection_instance_custom_index(&self) -> u32 { + let result; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "{result} = OpRayQueryGetIntersectionInstanceCustomIndexKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, } result @@ -377,18 +466,43 @@ impl RayQuery { /// Gets the id of the instance for the current intersection considered in a /// ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionInstanceIdKHR")] #[inline] - pub unsafe fn get_intersection_instance_id(&self) -> u32 { - let mut result; + pub unsafe fn get_candidate_intersection_instance_id(&self) -> u32 { + let result; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionInstanceIdKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, + } + + result + } + + /// Gets the id of the instance for the current intersection considered in a + /// ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionInstanceIdKHR")] + #[inline] + pub unsafe fn get_committed_intersection_instance_id(&self) -> u32 { + let result; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", "{result} = OpRayQueryGetIntersectionInstanceIdKHR %u32 {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, result = out(reg) result, } @@ -397,22 +511,44 @@ impl RayQuery { /// Gets the shader binding table record offset for the current intersection /// considered in a ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR")] #[inline] - pub unsafe fn get_intersection_shader_binding_table_record_offset( - &self, - ) -> u32 { - let mut result = 0; + pub unsafe fn get_candidate_intersection_shader_binding_table_record_offset(&self) -> u32 { + let result; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR %u32 {ray_query} %intersection", - "OpStore {result} %result", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR %u32 {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, - result = in(reg) &mut result, + result = out(reg) result, + } + + result + } + + /// Gets the shader binding table record offset for the current intersection + /// considered in a ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR")] + #[inline] + pub unsafe fn get_committed_intersection_shader_binding_table_record_offset(&self) -> u32 { + let result; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "{result} = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, } result @@ -420,20 +556,44 @@ impl RayQuery { /// Gets the geometry index for the current intersection considered in a /// ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionGeometryIndexKHR")] #[inline] - pub unsafe fn get_intersection_geometry_index(&self) -> u32 { - let mut result = 0; + pub unsafe fn get_candidate_intersection_geometry_index(&self) -> u32 { + let result; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionGeometryIndexKHR %u32 {ray_query} %intersection", - "OpStore {result} %result", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionGeometryIndexKHR %u32 {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, - result = in(reg) &mut result, + result = out(reg) result, + } + + result + } + + /// Gets the geometry index for the current intersection considered in a + /// ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionGeometryIndexKHR")] + #[inline] + pub unsafe fn get_committed_intersection_geometry_index(&self) -> u32 { + let result; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "{result} = OpRayQueryGetIntersectionGeometryIndexKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, } result @@ -441,19 +601,67 @@ impl RayQuery { /// Gets the primitive index for the current intersection considered in a /// ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionPrimitiveIndexKHR")] #[inline] - pub unsafe fn get_intersection_primitive_index(&self) -> u32 { - let mut result = 0; + pub unsafe fn get_candidate_intersection_primitive_index(&self) -> u32 { + let result; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionPrimitiveIndexKHR %u32 {ray_query} %intersection", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionPrimitiveIndexKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, + } + + result + } + + /// Gets the primitive index for the current intersection considered in a + /// ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionPrimitiveIndexKHR")] + #[inline] + pub unsafe fn get_committed_intersection_primitive_index(&self) -> u32 { + let result; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "{result} = OpRayQueryGetIntersectionPrimitiveIndexKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, + } + + result + } + + /// Gets the second and third barycentric coordinates of the current + /// intersection considered in a ray query against the primitive it hit. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. + /// The current intersection candidate must have a [`Self::get_candidate_intersection_type()`] + /// of [`CandidateIntersection::Triangle`]. + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionBarycentricsKHR")] + #[inline] + pub unsafe fn get_candidate_intersection_barycentrics>(&self) -> V { + let mut result = Default::default(); + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 0", + "%result = OpRayQueryGetIntersectionBarycentricsKHR typeof*{result} {ray_query} %intersection", "OpStore {result} %result", ray_query = in(reg) self, - intersection = const INTERSECTION, result = in(reg) &mut result, } @@ -462,23 +670,24 @@ impl RayQuery { /// Gets the second and third barycentric coordinates of the current /// intersection considered in a ray query against the primitive it hit. + /// + /// There must be a current committed intersection. Its + /// [`Self::get_committed_intersection_type()`] must be [`CommittedIntersection::Triangle`]. + /// + /// TODO: Improve docs. Can't right now due to + /// #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionBarycentricsKHR")] #[inline] - pub unsafe fn get_intersection_barycentrics, const INTERSECTION: u32>( - &self, - ) -> V { + pub unsafe fn get_committed_intersection_barycentrics>(&self) -> V { let mut result = Default::default(); asm! { "%u32 = OpTypeInt 32 0", - "%f32 = OpTypeFloat 32", - "%f32x2 = OpTypeVector %f32 2", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionBarycentricsKHR %f32x2 {ray_query} %intersection", + "%intersection = OpConstant %u32 1", + "%result = OpRayQueryGetIntersectionBarycentricsKHR typeof*{result} {ray_query} %intersection", "OpStore {result} %result", ray_query = in(reg) self, - intersection = const INTERSECTION, result = in(reg) &mut result, } @@ -487,18 +696,46 @@ impl RayQuery { /// Returns whether the current intersection considered in a ray query was with /// the front face (`true`) or back face (`false`) of a primitive. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. + /// The current intersection candidate must have a [`Self::get_candidate_intersection_type()`] + /// of [`CandidateIntersection::Triangle`]. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionFrontFaceKHR")] #[inline] - pub unsafe fn get_intersection_front_face(&self) -> bool { - let mut result: u32; + pub unsafe fn get_candidate_intersection_front_face(&self) -> bool { + let result: u32; asm! { "%u32 = OpTypeInt 32 0", - "%intersection = OpConstant %u32 {intersection}", + "%intersection = OpConstant %u32 0", + "{result} = OpRayQueryGetIntersectionFrontFaceKHR %u32 {ray_query} %intersection", + ray_query = in(reg) self, + result = out(reg) result, + } + + result != 0 + } + + /// Returns whether the current intersection considered in a ray query was with + /// the front face (`true`) or back face (`false`) of a primitive. + /// + /// There must be a current committed intersection. Its + /// [`Self::get_committed_intersection_type()`] must be [`CommittedIntersection::Triangle`]. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionFrontFaceKHR")] + #[inline] + pub unsafe fn get_committed_intersection_front_face(&self) -> bool { + let result: u32; + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", "{result} = OpRayQueryGetIntersectionFrontFaceKHR %u32 {ray_query} %intersection", ray_query = in(reg) self, - intersection = const INTERSECTION, result = out(reg) result, } @@ -525,26 +762,45 @@ impl RayQuery { /// Gets the object-space ray direction for the current intersection considered /// in a ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionObjectRayDirectionKHR")] #[inline] - pub unsafe fn get_intersection_object_ray_direction< - V: Vector, - const INTERSECTION: u32, - >( - &self, - ) -> V { + pub unsafe fn get_candidate_intersection_object_ray_direction>(&self) -> V { let mut result = Default::default(); asm! { "%u32 = OpTypeInt 32 0", - "%f32 = OpTypeFloat 32", - "%f32x3 = OpTypeVector %f32 3", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionObjectRayDirectionKHR %f32x3 {ray_query} %intersection", + "%intersection = OpConstant %u32 0", + "%result = OpRayQueryGetIntersectionObjectRayDirectionKHR typeof*{result} {ray_query} %intersection", + "OpStore {result} %result", + ray_query = in(reg) self, + result = in(reg) &mut result, + } + + result + } + + /// Gets the object-space ray direction for the current intersection considered + /// in a ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionObjectRayDirectionKHR")] + #[inline] + pub unsafe fn get_committed_intersection_object_ray_direction>(&self) -> V { + let mut result = Default::default(); + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "%result = OpRayQueryGetIntersectionObjectRayDirectionKHR typeof*{result} {ray_query} %intersection", "OpStore {result} %result", ray_query = in(reg) self, - intersection = const INTERSECTION, result = in(reg) &mut result, } @@ -553,23 +809,45 @@ impl RayQuery { /// Gets the object-space ray origin for the current intersection considered in /// a ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionObjectRayOriginKHR")] #[inline] - pub unsafe fn get_intersection_object_ray_origin, const INTERSECTION: u32>( - &self, - ) -> V { + pub unsafe fn get_candidate_intersection_object_ray_origin>(&self) -> V { let mut result = Default::default(); asm! { "%u32 = OpTypeInt 32 0", - "%f32 = OpTypeFloat 32", - "%f32x3 = OpTypeVector %f32 3", - "%intersection = OpConstant %u32 {intersection}", - "%result = OpRayQueryGetIntersectionObjectRayOriginKHR %f32x3 {ray_query} %intersection", + "%intersection = OpConstant %u32 0", + "%result = OpRayQueryGetIntersectionObjectRayOriginKHR typeof*{result} {ray_query} %intersection", + "OpStore {result} %result", + ray_query = in(reg) self, + result = in(reg) &mut result, + } + + result + } + + /// Gets the object-space ray origin for the current intersection considered in + /// a ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionObjectRayOriginKHR")] + #[inline] + pub unsafe fn get_committed_intersection_object_ray_origin>(&self) -> V { + let mut result = Default::default(); + + asm! { + "%u32 = OpTypeInt 32 0", + "%intersection = OpConstant %u32 1", + "%result = OpRayQueryGetIntersectionObjectRayOriginKHR typeof*{result} {ray_query} %intersection", "OpStore {result} %result", ray_query = in(reg) self, - intersection = const INTERSECTION, result = in(reg) &mut result, } @@ -585,9 +863,7 @@ impl RayQuery { asm! { "%u32 = OpTypeInt 32 0", - "%f32 = OpTypeFloat 32", - "%f32x3 = OpTypeVector %f32 3", - "%result = OpRayQueryGetWorldRayDirectionKHR %f32x3 {ray_query}", + "%result = OpRayQueryGetWorldRayDirectionKHR typeof*{result} {ray_query}", "OpStore {result} %result", ray_query = in(reg) self, result = in(reg) &mut result, @@ -605,9 +881,7 @@ impl RayQuery { asm! { "%u32 = OpTypeInt 32 0", - "%f32 = OpTypeFloat 32", - "%f32x3 = OpTypeVector %f32 3", - "%result = OpRayQueryGetWorldRayOriginKHR %f32x3 {ray_query}", + "%result = OpRayQueryGetWorldRayOriginKHR typeof*{result} {ray_query}", "OpStore {result} %result", ray_query = in(reg) self, result = in(reg) &mut result, @@ -618,12 +892,12 @@ impl RayQuery { /// Gets a matrix that transforms values to world-space from the object-space of /// the current intersection considered in a ray query. + /// + /// [`Self::proceed()`] must have been called on this object, and it must have returned true. #[spirv_std_macros::gpu_only] #[doc(alias = "OpRayQueryGetIntersectionObjectToWorldKHR")] #[inline] - pub unsafe fn get_intersection_object_to_world, const INTERSECTION: u32>( - &self, - ) -> [V; 4] { + pub unsafe fn get_candidate_intersection_object_to_world>(&self) -> [V; 4] { let mut result = Default::default(); asm! { @@ -631,7 +905,40 @@ impl RayQuery { "%f32 = OpTypeFloat 32", "%f32x3 = OpTypeVector %f32 3", "%f32x3x4 = OpTypeMatrix %f32x3 4", - "%intersection = OpConstant %u32 {intersection}", + "%intersection = OpConstant %u32 0", + "%matrix = OpRayQueryGetIntersectionObjectToWorldKHR %f32x3x4 {ray_query} %intersection", + "%col0 = OpCompositeExtract %f32x3 %matrix 0", + "%col1 = OpCompositeExtract %f32x3 %matrix 1", + "%col2 = OpCompositeExtract %f32x3 %matrix 2", + "%col3 = OpCompositeExtract %f32x3 %matrix 3", + "%result = OpCompositeConstruct typeof*{result} %col0 %col1 %col2 %col3", + "OpStore {result} %result", + ray_query = in(reg) self, + result = in(reg) &mut result, + } + + result + } + + /// Gets a matrix that transforms values to world-space from the object-space of + /// the current intersection considered in a ray query. + /// + /// There must be a current committed intersection. + /// + /// TODO: Improve docs. Can't right now due to + /// + #[spirv_std_macros::gpu_only] + #[doc(alias = "OpRayQueryGetIntersectionObjectToWorldKHR")] + #[inline] + pub unsafe fn get_committed_intersection_object_to_world>(&self) -> [V; 4] { + let mut result = Default::default(); + + asm! { + "%u32 = OpTypeInt 32 0", + "%f32 = OpTypeFloat 32", + "%f32x3 = OpTypeVector %f32 3", + "%f32x3x4 = OpTypeMatrix %f32x3 4", + "%intersection = OpConstant %u32 1", "%matrix = OpRayQueryGetIntersectionObjectToWorldKHR %f32x3x4 {ray_query} %intersection", "%col0 = OpCompositeExtract %f32x3 %matrix 0", "%col1 = OpCompositeExtract %f32x3 %matrix 1", @@ -640,7 +947,6 @@ impl RayQuery { "%result = OpCompositeConstruct typeof*{result} %col0 %col1 %col2 %col3", "OpStore {result} %result", ray_query = in(reg) self, - intersection = const INTERSECTION, result = in(reg) &mut result, } diff --git a/tests/ui/arch/ray_query_get_intersection_barycentrics_khr.rs b/tests/ui/arch/ray_query_get_intersection_barycentrics_khr.rs index 22662a44a5..918449204e 100644 --- a/tests/ui/arch/ray_query_get_intersection_barycentrics_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_barycentrics_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let barycentric_coords: glam::Vec2 = handle.get_intersection_barycentrics::<_, 5>(); + let barycentric_coords: glam::Vec2 = handle.get_candidate_intersection_barycentrics(); + let barycentric_coords: glam::Vec2 = handle.get_committed_intersection_barycentrics(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_front_face_khr.rs b/tests/ui/arch/ray_query_get_intersection_front_face_khr.rs index 177cc6f9f2..9611097ca2 100644 --- a/tests/ui/arch/ray_query_get_intersection_front_face_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_front_face_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - assert!(handle.get_intersection_front_face::<5>()); + assert!(handle.get_candidate_intersection_front_face()); + assert!(handle.get_committed_intersection_front_face()); } } diff --git a/tests/ui/arch/ray_query_get_intersection_geometry_index_khr.rs b/tests/ui/arch/ray_query_get_intersection_geometry_index_khr.rs index 4c1a18ebe5..9c572dde71 100644 --- a/tests/ui/arch/ray_query_get_intersection_geometry_index_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_geometry_index_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let t = handle.get_intersection_geometry_index::<5>(); + let t = handle.get_candidate_intersection_geometry_index(); + let t = handle.get_committed_intersection_geometry_index(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_instance_custom_index_khr.rs b/tests/ui/arch/ray_query_get_intersection_instance_custom_index_khr.rs index 43e5121f7f..b8ad914d06 100644 --- a/tests/ui/arch/ray_query_get_intersection_instance_custom_index_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_instance_custom_index_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let index = handle.get_intersection_instance_custom_index::<5>(); + let index = handle.get_candidate_intersection_instance_custom_index(); + let index = handle.get_committed_intersection_instance_custom_index(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_instance_id_khr.rs b/tests/ui/arch/ray_query_get_intersection_instance_id_khr.rs index de688bb7a0..7cd5104299 100644 --- a/tests/ui/arch/ray_query_get_intersection_instance_id_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_instance_id_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let id = handle.get_intersection_instance_id::<5>(); + let id = handle.get_candidate_intersection_instance_id(); + let id = handle.get_committed_intersection_instance_id(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_object_ray_direction_khr.rs b/tests/ui/arch/ray_query_get_intersection_object_ray_direction_khr.rs index e17731efe2..e0e73ffa2b 100644 --- a/tests/ui/arch/ray_query_get_intersection_object_ray_direction_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_object_ray_direction_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let direction: glam::Vec3 = handle.get_intersection_object_ray_direction::<_, 5>(); + let direction: glam::Vec3 = handle.get_candidate_intersection_object_ray_direction(); + let direction: glam::Vec3 = handle.get_committed_intersection_object_ray_direction(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_object_ray_origin_khr.rs b/tests/ui/arch/ray_query_get_intersection_object_ray_origin_khr.rs index fe2d072eaa..06ca7a9a21 100644 --- a/tests/ui/arch/ray_query_get_intersection_object_ray_origin_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_object_ray_origin_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let origin: glam::Vec3 = handle.get_intersection_object_ray_origin::<_, 5>(); + let origin: glam::Vec3 = handle.get_candidate_intersection_object_ray_origin(); + let origin: glam::Vec3 = handle.get_committed_intersection_object_ray_origin(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_object_to_world_khr.rs b/tests/ui/arch/ray_query_get_intersection_object_to_world_khr.rs index e2a3adc35b..b80f3df483 100644 --- a/tests/ui/arch/ray_query_get_intersection_object_to_world_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_object_to_world_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let matrix: [glam::Vec3; 4] = handle.get_intersection_object_to_world::<_, 5>(); + let matrix: [glam::Vec3; 4] = handle.get_candidate_intersection_object_to_world(); + let matrix: [glam::Vec3; 4] = handle.get_committed_intersection_object_to_world(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_primitive_index_khr.rs b/tests/ui/arch/ray_query_get_intersection_primitive_index_khr.rs index 1345ba2243..e9e85cbc14 100644 --- a/tests/ui/arch/ray_query_get_intersection_primitive_index_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_primitive_index_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - handle.get_intersection_primitive_index::<5>(); + handle.get_candidate_intersection_primitive_index(); + handle.get_committed_intersection_primitive_index(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_shader_binding_table_record_offset_khr.rs b/tests/ui/arch/ray_query_get_intersection_shader_binding_table_record_offset_khr.rs index 0078beb8f0..8369029d62 100644 --- a/tests/ui/arch/ray_query_get_intersection_shader_binding_table_record_offset_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_shader_binding_table_record_offset_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let offset = handle.get_intersection_shader_binding_table_record_offset::<5>(); + let offset = handle.get_candidate_intersection_shader_binding_table_record_offset(); + let offset = handle.get_committed_intersection_shader_binding_table_record_offset(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_t_khr.rs b/tests/ui/arch/ray_query_get_intersection_t_khr.rs index 3af9948919..0df6ae4f5f 100644 --- a/tests/ui/arch/ray_query_get_intersection_t_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_t_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - let t = handle.get_intersection_t::<5>(); + let t = handle.get_candidate_intersection_t(); + let t = handle.get_committed_intersection_t(); } } diff --git a/tests/ui/arch/ray_query_get_intersection_type_khr.rs b/tests/ui/arch/ray_query_get_intersection_type_khr.rs index c390563612..b4df974b6c 100644 --- a/tests/ui/arch/ray_query_get_intersection_type_khr.rs +++ b/tests/ui/arch/ray_query_get_intersection_type_khr.rs @@ -9,6 +9,7 @@ pub fn main(#[spirv(descriptor_set = 0, binding = 0)] accel: &AccelerationStruct unsafe { spirv_std::ray_query!(let mut handle); handle.initialize(accel, RayFlags::NONE, 0, Vec3::ZERO, 0.0, Vec3::ZERO, 0.0); - handle.get_intersection_type::<5>(); + handle.get_candidate_intersection_type(); + handle.get_committed_intersection_type(); } }