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    asm!("OpDemoteToHelperInvocationEXT");
24}
25
26/// Returns `true` if the invocation is currently a helper invocation, otherwise
27/// result is `false`. An invocation is currently a helper invocation if it was
28/// originally invoked as a helper invocation or if it has been demoted to a
29/// helper invocation by [demote_to_helper_invocation].
30///
31/// - **Required Capabilities** `DemoteToHelperInvocationEXT`
32/// - **Required Extensions** `SPV_EXT_demote_to_helper_invocation`
33#[spirv_std_macros::gpu_only]
34#[doc(alias = "OpIsHelperInvocationEXT")]
35pub fn is_helper_invocation() -> bool {
36    let mut result = false;
37
38    unsafe {
39        asm! {
40            "%bool = OpTypeBool",
41            "%result = OpIsHelperInvocationEXT %bool",
42            "OpStore {result} %result",
43            result = in(reg) &mut result,
44        };
45    }
46
47    result
48}