-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for setting config in shader's Cargo.toml
#34
base: main
Are you sure you want to change the base?
Conversation
I'll have a look at those failing tests tomorrow. |
Cargo.toml
0e871d0
to
1bcaef6
Compare
Neat, I actually have usecase for this. I need to enable some shader features. |
Great work!
They don't have to both exist, but they have to boil down to the same thing (if I'm not mistaken) - we have to be able to determine the target specification file to give to That said, I don't think we'll ever use anything but the explicit path-to-specification-file method. |
Yes! This is why we're prioritizing this work :) |
21d6294
to
0b738cd
Compare
Thanks! So let's see if we can come to a conclusion about the old/new way of defining the target.
Ideally we want a little automation? For example something like, if the user doesn't provide an absolute path then we assume that the string is the name of an existing target that Either way I think we'll want something like BTW I've also just pushed a little change that attempts to end-to-end test the changes by altering the cargo install --path crates/cargo-gpu
cargo gpu install --shader-crate crates/shader-crate-template --auto-install-rust-toolchain
sed -i 's/^output-dir =.*/output-dir = \/tmp\/testshaders/' crates/shader-crate-template/Cargo.toml
cargo gpu build --shader-crate crates/shader-crate-template
ls -lah /tmp/test-shaders It seems a bit hacky. Can anybody think of another way? Like is there another config that we can change and detect in the final built shader? Edit: the end-to-test is actually surfacing a bug! I think it's to do with |
67bf4a5
to
bcd23c2
Compare
About defining a target - the new way is similar to the old way, but we control the paths at shader crate compile time, as opposed to them being hard coded at But I think it would be easy enough to create one more option, something like |
I think that's a fine idea, I'll create an issue for that and we can tackle it after this? |
4d9b238
to
6eee8b3
Compare
6eee8b3
to
743cb3d
Compare
Okay, for now I've just hidden the From my side this looks ready to merge, or at least ready to give a good testing to. I still want to add the |
743cb3d
to
7564036
Compare
This is particularly useful when `--auto-install-rust-toolchain` is used as the consent prompt isn't show and no indication at all of what's happening was given.
7564036
to
cfdf4ed
Compare
I added the I also looked into a |
@tombh could we write a small wrapper over the enum just to provide our own (de)serialization? Would that be easier? |
I'd love to! I'm not sure how though, do you have any ideas? Another thing I tried was to type alias, making the external type internal, so I'm very open to trying other ideas 🤓 |
Found another bug and pushed the fix. Copypasting the new commit's message:
|
I'll take a crack at the |
I see what you mean - it's not that values need serialization, we just need to enumerate all values. This is a much easier problem to solve, so long as you don't think too hard ;) How about something like this? /// Iterator over all `Capability` variants.
pub fn capability_variants_iter() -> impl Iterator<Item = spirv::Capability> {
// Since spirv::Capability is repr(u32) we can iterate over
// u32s until some maximum
#[expect(clippy::as_conversions, reason = "We know all variants are repr(u32)")]
let last_capability = spirv::Capability::CacheControlsINTEL as u32;
(0..=last_capability).filter_map(spirv::Capability::from_u32)
} |
...and if we really need to be complete you could iterate |
9414478
to
e536de6
Compare
Ohhhhh, that's really good 😏 Thank you! Pushed ✨ |
Is this all ready to go now? |
From my perspective yes. There's a new bug I've found from working on #39, though it only happens in certain cases of changing the |
There is also https://docs.rs/strum/latest/strum/derive.EnumIter.html. We use strum in the rust-gpu examples. |
Yes, that's what I was using, but @schell found a much simpler method 🤓 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! This is amazing work. Great job 👍 .
I just had a nitpick or two, but it's no big deal. Feel free to merge when you're ready!
|
||
// Move `/install/spirv_install` to `/install` | ||
let spirv_install = cli_args_json | ||
.pointer("/install/spirv_install") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow! This is a really helpful function that I didn't know existed! Thanks! 🙇
// `clippy::exit` seems to be a false positive in `main()`. | ||
// See: https://github.com/rust-lang/rust-clippy/issues/13518 | ||
#[expect(clippy::restriction, reason = "Our central place for safely exiting")] | ||
std::process::exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 good catch.
# Dependencies for CPU code | ||
[target.'cfg(not(target_arch = "spirv"))'.dependencies] | ||
glam = { version = "0.29", features = ["std"] } | ||
|
||
[package.metadata.rust-gpu.build] | ||
# Where to output the compiled shader. Defaults to where `cargo gpu` is called from. | ||
# TODO: Should it default to the root of the shader crate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably should default to the root of the shader crate, but we can keep that for later.
# Set shader crate's cargo features. | ||
features = [] | ||
# The compile target. | ||
# TODO: `cargo gpu show targets` for all available options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we have an issue for it #36
use spirv_0_2 as spirv; | ||
|
||
#[cfg(any(feature = "spirv-builder-0_10", feature = "rspirv-latest"))] | ||
use spirv_0_3 as spirv; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever use of features and deps! I didn't know you could do this.
Values are set in the TOML section: `[package.metadata.rust-gpu.*]`. So now the priority, from least to most, is: * Workspace metadata * Shader crate's metadata * CLI args Fixes Rust-GPU#15 Notable changes: * All `clap` args for the `build` and `install` subcommands are now defined in the `spirv-builder-cli` crate. This makes passing all the config between `cargo gpu` and `spirv-builder-cli` trivial as `serde` now does all the heavy lifting of creating and reading the JSON arguments. * There is no longer a `toml` subcommand. The shader crate's `Cargo.toml`s are always read and their configs used as the base for CLI args to override.
Because our `spirv-builder-cli` can modify itself to comply with various versions of `spirv-builder` from `rust-gpu`, then we also need to match the version of `spirv` that we use to get `spirv::Capabilities`. Namely that `rust-gpu <= v0.9.0` uses `spirv = "0.2.0"` and that `rust-gpu >= "v0.9.0"` uses `spirv = "0.3.0". Another solution to this could be to re-export `spirv` from `spirv-builder`. But I'm not sure that would avoid compiling the entirety of `spirv-builder` (which depends on specific Rust nightly versions), and besides, it's not trivial to retroactively add re-exports to already-published version of `rust-gpu`.
e536de6
to
0347ae5
Compare
Great, this is ready then. I'd merge it but I don't have push permissions. |
Managed to find quite an elegant solution where
serde_json
is doing all the heavy lifting. We even have automatic type checking on the config set in the shader crate'sCargo.toml
!Values are set in the TOML section:
[package.metadata.rust-gpu.*]
.So now the priority, from least to most, is:
Fixes #15
Notable changes:
clap
args for thebuild
andinstall
subcommands are nowdefined in the
spirv-builder-cli
crate. This makes passing all theconfig between
cargo gpu
andspirv-builder-cli
trivial asserde
now does all the heavy lifting of creating and reading the JSON
arguments.
toml
subcommand. The shader crate'sCargo.toml
sare always read and their configs used as the base for CLI args to
override.
TODO:
get_cargo_toml_as_json()
function to parse theshader crate's
spirv-std
dependency. This will simplify the codeand be more reliable. See Use
cargo metadata
to parsespirv-std
dep from shader crate #37cargo gpu show targets
See Addcargo gpu show targets
#36cargo gpu show capabilities
cargo gpu show extensions
target
andshader_target
arguments, are they both needed?