Replace <const INTERSECTION: u32> with two functions (#750)

* Replace <const INTERSECTION: u32> with two functions

* Fix doc URLs
This commit is contained in:
Ashley Hauck 2021-09-07 11:30:56 +02:00 committed by GitHub
parent 6807c5973d
commit eeb67ae748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 430 additions and 112 deletions

View File

@ -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<const INTERSECTION: u32>(&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<const INTERSECTION: u32>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<const INTERSECTION: u32>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<const INTERSECTION: u32>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<const INTERSECTION: u32>(
&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<const INTERSECTION: u32>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<const INTERSECTION: u32>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<V: Vector<f32, 2>>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[spirv_std_macros::gpu_only]
#[doc(alias = "OpRayQueryGetIntersectionBarycentricsKHR")]
#[inline]
pub unsafe fn get_intersection_barycentrics<V: Vector<f32, 2>, const INTERSECTION: u32>(
&self,
) -> V {
pub unsafe fn get_committed_intersection_barycentrics<V: Vector<f32, 2>>(&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<const INTERSECTION: u32>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[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<f32, 3>,
const INTERSECTION: u32,
>(
&self,
) -> V {
pub unsafe fn get_candidate_intersection_object_ray_direction<V: Vector<f32, 3>>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[spirv_std_macros::gpu_only]
#[doc(alias = "OpRayQueryGetIntersectionObjectRayDirectionKHR")]
#[inline]
pub unsafe fn get_committed_intersection_object_ray_direction<V: Vector<f32, 3>>(&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<V: Vector<f32, 3>, const INTERSECTION: u32>(
&self,
) -> V {
pub unsafe fn get_candidate_intersection_object_ray_origin<V: Vector<f32, 3>>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[spirv_std_macros::gpu_only]
#[doc(alias = "OpRayQueryGetIntersectionObjectRayOriginKHR")]
#[inline]
pub unsafe fn get_committed_intersection_object_ray_origin<V: Vector<f32, 3>>(&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<V: Vector<f32, 3>, const INTERSECTION: u32>(
&self,
) -> [V; 4] {
pub unsafe fn get_candidate_intersection_object_to_world<V: Vector<f32, 3>>(&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
/// <https://github.com/KhronosGroup/SPIRV-Registry/issues/128>
#[spirv_std_macros::gpu_only]
#[doc(alias = "OpRayQueryGetIntersectionObjectToWorldKHR")]
#[inline]
pub unsafe fn get_committed_intersection_object_to_world<V: Vector<f32, 3>>(&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,
}

View File

@ -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();
}
}

View File

@ -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());
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}