spirv_std/arch/ray_tracing.rs
1#[cfg(target_arch = "spirv")]
2use core::arch::asm;
3
4/// Reports an intersection back to the traversal infrastructure.
5///
6/// If the intersection occurred within the current ray interval, the
7/// intersection confirmation is performed (see the API specification for more
8/// details). If the value of Hit falls outside the current ray interval, the
9/// hit is rejected.
10///
11/// Returns True if the hit was accepted by the ray interval and the intersection was confirmed. Returns False otherwise.
12///
13/// - `hit` is the floating point parametric value along ray for the intersection.
14/// - `hit_kind` is the integer hit kind reported back to other shaders and
15/// accessible by the `hit kind` builtin.
16///
17/// This instruction is allowed only in IntersectionKHR execution model.
18///
19/// This instruction is a shader call instruction which may invoke shaders with
20/// the `any_hit` execution model.
21#[spirv_std_macros::gpu_only]
22#[doc(alias = "OpReportIntersectionKHR")]
23#[inline]
24pub unsafe fn report_intersection(hit: f32, hit_kind: u32) -> bool {
25 let mut result = false;
26
27 asm! {
28 "%bool = OpTypeBool",
29 "%result = OpReportIntersectionKHR %bool {hit} {hit_kind}",
30 "OpStore {result} %result",
31 result = in(reg) &mut result,
32 hit = in(reg) hit,
33 hit_kind = in(reg) hit_kind,
34 };
35
36 result
37}
38
39/// Ignores the current potential intersection, terminating the invocation that
40/// executes it, and continues the ray traversal. This instruction is allowed
41/// only in `any_hit` execution model.
42#[spirv_std_macros::gpu_only]
43#[doc(alias = "OpIgnoreIntersectionKHR")]
44#[inline]
45pub unsafe fn ignore_intersection() -> ! {
46 asm!("OpIgnoreIntersectionKHR", options(noreturn));
47}
48
49/// Terminates the invocation that executes it, stops the ray traversal, accepts
50/// the current hit, and invokes the `closest_hit` execution model
51/// (if active). This instruction is allowed only in the `any_hit`
52/// execution model.
53#[spirv_std_macros::gpu_only]
54#[doc(alias = "OpTerminateRayKHR")]
55#[inline]
56pub unsafe fn terminate_ray() -> ! {
57 asm!("OpTerminateRayKHR", options(noreturn));
58}
59
60/// Invoke a callable shader.
61///
62/// - `INDEX` is the index into the SBT table to select callable shader
63/// to execute.
64/// - `data` is a pointer to the callable data to pass into the called shader.
65/// `data` must have a storage class of `callable_data`
66/// or `incoming_callable_data`.
67///
68/// This instruction is allowed only in `ray_generation`, `closest_hit`,
69/// `miss` and `callable` execution models.
70///
71/// This instruction is a shader call instruction which will invoke a shader
72/// with the `callable` execution model.
73#[spirv_std_macros::gpu_only]
74#[doc(alias = "OpExecuteCallableKHR")]
75#[inline]
76pub unsafe fn execute_callable<T, const ID: usize>(data: &T) {
77 asm! {
78 "%u32 = OpTypeInt 32 0",
79 "%id = OpConstant %u32 {id}",
80 "OpExecuteCallableKHR %id {data}",
81 id = const ID,
82 data = in(reg) data,
83 };
84}