spirv_std/arch/
demote_to_helper_invocation_ext.rs

1#[cfg(target_arch = "spirv")]
2use core::arch::asm;
3
4/// Demote fragment shader invocation to a helper invocation. Equivalvent to
5/// `discard()` in HLSL. Any stores to memory after this instruction are
6/// suppressed and the fragment does not write outputs to the framebuffer.
7///
8/// Unlike [`super::kill`], this does not necessarily terminate the invocation. It
9/// is not considered a flow control instruction (flow control does not become
10/// non-uniform) and does not terminate the block.
11///
12/// - **Required Capabilities** `DemoteToHelperInvocationEXT`
13/// - **Required Extensions** `SPV_EXT_demote_to_helper_invocation`
14///
15/// # Safety
16/// After this instruction executes, the value of a `helper_invocation` builtin
17/// variable is undefined. Use `is_helper_invocation` to determine whether
18/// invocations are helper invocations in the presence
19/// of [demote_to_helper_invocation].
20#[spirv_std_macros::gpu_only]
21#[doc(alias = "OpDemoteToHelperInvocationEXT", alias = "discard")]
22pub unsafe fn demote_to_helper_invocation() {
23    unsafe {
24        asm!("OpDemoteToHelperInvocationEXT");
25    }
26}
27
28/// Returns `true` if the invocation is currently a helper invocation, otherwise
29/// result is `false`. An invocation is currently a helper invocation if it was
30/// originally invoked as a helper invocation or if it has been demoted to a
31/// helper invocation by [demote_to_helper_invocation].
32///
33/// - **Required Capabilities** `DemoteToHelperInvocationEXT`
34/// - **Required Extensions** `SPV_EXT_demote_to_helper_invocation`
35#[spirv_std_macros::gpu_only]
36#[doc(alias = "OpIsHelperInvocationEXT")]
37pub fn is_helper_invocation() -> bool {
38    let mut result = false;
39
40    unsafe {
41        asm! {
42            "%bool = OpTypeBool",
43            "%result = OpIsHelperInvocationEXT %bool",
44            "OpStore {result} %result",
45            result = in(reg) &mut result,
46        };
47    }
48
49    result
50}