Skip to content

Conversation

Firestar99
Copy link
Member

@Firestar99 Firestar99 commented Sep 18, 2025

As discussed with @eddyb, we would like to versionize our spirv() macro so you can't accidentally combine two incompatible versions.

Also enables the addition of "stable spirv macros" that we can offer backward compat for. This will be used in #380 to allow glam to define it's VecN as rust-gpu vectors, for which it must refer to our "rustc tool" rust_gpu directly instead of going via our spirv() proc macro, which expands to our tool name.

@Firestar99

This comment was marked as outdated.

@Firestar99 Firestar99 force-pushed the tool_rename branch 2 times, most recently from 662f4be to 5b7acff Compare September 22, 2025 15:35
@Firestar99 Firestar99 changed the title rename tool from rust_gpu to rustc_codegen_spirv versionize rust_gpu tool to ensure codegen and spirv-std versions match Sep 22, 2025
// NOTE(shesp) Directly using `#[rust_gpu::spirv(...)]` because macro attributes are invalid in most contexts
// NOTE(shesp) Directly using `#[rust_gpu::spirv_v0_9(...)]` because macro attributes are invalid in most contexts

#[rust_gpu::spirv(
Copy link
Member Author

@Firestar99 Firestar99 Sep 22, 2025

Choose a reason for hiding this comment

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

This test is a problem. We can't replace every use with our spirv() proc macro, since some of these are in locations proc macros are illegal to place. Ideas?

Copy link
Member

Choose a reason for hiding this comment

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

Would it help to put a #[spirv()] (invoking the proc macro, but in a dummy way) on the outermost definition, in those cases (or even a whole module, though I think that might still be disallowed).

There's some pretty aggressive rewriting of any #[spirv(...)] anywhere inside the token stream, but I'm not sure what the limitations of that are.

If the empty list is an issue, we could make up something for this test, or just allow it as a noop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, the proc macro searches for the "regex" (#[spirv(.*)]) non-recursively. This includes the parenthesis on the outside (to filter for function params) and does not care for what comes after the spirv ident, it just replaces that with #[cfg_attr(target_arch = "spirv", rust_gpu::spirv($1))].

We could make it recurse properly, but I'm also slightly concerned about performance, if we were to attach that macro to a big function like entry points.

@Firestar99
Copy link
Member Author

Firestar99 commented Sep 22, 2025

@eddyb this is ready for review! Since the first one just moved a bunch of code, best reviewed without it or commit by commit.

Open Questions

  • tool name stays rust_gpu? yes (after discussing with eddyb)
  • what to do with the test?

Comment on lines 1 to 3
//! This is placed outside any crate, and included by both `spirv_std` and `rustc_codegen_spirv`.
//! I could have made a new crate, shared between the two, but decided against having even more small crates for sharing
//! types. Instead, you get this single small file to specify the versioned spirv attribute.
Copy link
Member

Choose a reason for hiding this comment

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

Can you try cargo publish -p spirv-std-macros --dry-run?

I don't see how this can work with crates.io publishing (this is the same reason crates/rustc_codegen_spirv/build.rs cannot just include_str!("../../rust-toolchain.toml")).

(Would be very happy to be wrong, and I do know that Cargo git dependencies result in the whole repo being checked out, it's just registry publishing we need to be careful about)

Copy link
Member Author

Choose a reason for hiding this comment

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

fails... will figure something out

Copy link
Member Author

@Firestar99 Firestar99 Oct 1, 2025

Choose a reason for hiding this comment

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

Moved it to spirv-std-types / spirv-std/shared, gave that crate an std feature and have rustc_codegen_spirv depend on it too.

Publish still fails as for some reason it wants to use the published spirv-std-types v0.9.0 instead of the local one, which doesn't have the std feature.

Just the test remains...

@Firestar99 Firestar99 force-pushed the tool_rename branch 2 times, most recently from febdddf to bdc2048 Compare October 2, 2025 11:05
@Firestar99
Copy link
Member Author

Firestar99 commented Oct 2, 2025

@eddyb this is ready for round 2 of reviews!

(most of the diff's LOC is blessing the invalid-target compiletest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants