Skip to content
This repository was archived by the owner on Oct 31, 2025. It is now read-only.

Add gpu_only proc macro#392

Merged
XAMPPRocky merged 1 commit intomainfrom
gpu-macro
Jan 25, 2021
Merged

Add gpu_only proc macro#392
XAMPPRocky merged 1 commit intomainfrom
gpu-macro

Conversation

@XAMPPRocky
Copy link
Copy Markdown
Member

@XAMPPRocky XAMPPRocky commented Jan 22, 2021

This PR adds a #[gpu_only] macro to spirv-std-macros, which essentially expands to the following. Which we were doing a lot in the code already, and will only add more in the future.

#[gpu_only]
fn foo() {
    // SPIR-V fn body.
}

// Generates

fn foo() {
     #[cfg(target_arch = "spriv")] {
        // SPIR-V fn body.
     }
     
     #[cfg(not(target_arch = "spriv"))] {
         unimplemented!()
     }
}

@XAMPPRocky XAMPPRocky requested review from VZout and khyperia January 22, 2021 15:33
@XAMPPRocky XAMPPRocky requested a review from eddyb as a code owner January 22, 2021 15:33
@XAMPPRocky XAMPPRocky force-pushed the gpu-macro branch 2 times, most recently from f8de018 to a097088 Compare January 25, 2021 07:09
/// Calls the `OpDemoteToHelperInvocationEXT` instruction, which corresponds to discard() in HLSL
#[spirv_std_macros::gpu_only]
pub fn demote_to_helper_invocation() {
#[cfg(target_arch = "spirv")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just calling out the change of semantics here for others, but I probably don't care either way.

@khyperia
Copy link
Copy Markdown
Contributor

how does this handle unused argument warnings on the CPU?

Comment on lines +45 to +46
// Don't warn on unused arguments on the CPU side.
#[cfg_attr(not(target_arch = "spirv"), allow(unused_variables))]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this handle unused argument warnings on the CPU?

It adds allow(unused_variables) when compiled for CPU targets.

@XAMPPRocky XAMPPRocky merged commit 353bb96 into main Jan 25, 2021
@XAMPPRocky XAMPPRocky deleted the gpu-macro branch January 25, 2021 10:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants