Skip to content

Commit

Permalink
Support for setting config in shader's Cargo.toml
Browse files Browse the repository at this point in the history
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 #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.

TODO:
* [ ] Reuse the `get_cargo_toml_as_json()` function to parse the
      shader crate's `spirv-std` dependency. This will simplify the code
      and be more reliable.
* [ ] `cargo gpu show targets`
* [ ] `cargo gpu show capabilities`
* [ ] `cargo gpu show etensions`
* [ ] I'm still a bit confused about the `target` and `shader_target`
      arguments, are they both needed?
  • Loading branch information
tombh committed Jan 10, 2025
1 parent 955afa4 commit 743cb3d
Show file tree
Hide file tree
Showing 20 changed files with 1,133 additions and 503 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ members = [
]

exclude = [
# Can't be included because it depends on a specific Rust toolchain and considering that
# the reason it exists is to prevent Rust toolchain requirements from polluting workspaces
# then let's just not try to workaround it.
"crates/spirv-builder-cli",

# This currently needs to be excluded because it depends on a version of `rust-gpu` that
Expand Down Expand Up @@ -51,5 +54,4 @@ pub_with_shorthand = { level = "allow", priority = 1 }
partial_pub_fields = { level = "allow", priority = 1 }
pattern_type_mismatch = { level = "allow", priority = 1 }
std_instead_of_alloc = { level = "allow", priority = 1 }


arbitrary_source_item_ordering = { level = "allow", priority = 1 }
248 changes: 125 additions & 123 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,193 +54,195 @@ the usage instructions the backend and nightly Rust version are referred to as "
## Usage

All the following arguments for the `build` and `install` commands can also be set in the shader crate's `Cargo.toml`
file. In general usage that would be the recommended way to set config. See `crates/shader-crate-template/Cargo.toml`
for an example.

````
Commands:
install Install rust-gpu compiler artifacts
build Compile a shader crate to SPIR-V
toml Compile a shader crate according to the `cargo gpu build` parameters found in the given toml file
show Show some useful values
help Print this message or the help of the given subcommand(s)
Commands:
install Install rust-gpu compiler artifacts
build Compile a shader crate to SPIR-V
show Show some useful values
help Print this message or the help of the given subcommand(s)
Options:
-h, --help
Print help
Options:
-h, --help
Print help
-V, --version
Print version
-V, --version
Print version
* Install
Install rust-gpu compiler artifacts
Install rust-gpu compiler artifacts
Usage: cargo-gpu install [OPTIONS]
Usage: cargo-gpu install [OPTIONS]
Options:
--shader-crate <SHADER_CRATE>
Directory containing the shader crate to compile
Options:
--shader-crate <SHADER_CRATE>
Directory containing the shader crate to compile
[default: ./]
[default: ./]
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
--spirv-builder-version <SPIRV_BUILDER_VERSION>
Version of `spirv-builder` dependency.
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
version such as "0.9.0".
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
--spirv-builder-version <SPIRV_BUILDER_VERSION>
Version of `spirv-builder` dependency.
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
version such as "0.9.0".
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
--rust-toolchain <RUST_TOOLCHAIN>
Rust toolchain channel to use to build `spirv-builder`.
--rust-toolchain <RUST_TOOLCHAIN>
Rust toolchain channel to use to build `spirv-builder`.
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
--force-spirv-cli-rebuild
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
--force-spirv-cli-rebuild
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
--auto-install-rust-toolchain
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
--auto-install-rust-toolchain
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
-h, --help
Print help (see a summary with '-h')
-h, --help
Print help (see a summary with '-h')
* Build
Compile a shader crate to SPIR-V
Compile a shader crate to SPIR-V
Usage: cargo-gpu build [OPTIONS]
Options:
--shader-crate <SHADER_CRATE>
Directory containing the shader crate to compile
Usage: cargo-gpu build [OPTIONS]
[default: ./]
Options:
--shader-crate <SHADER_CRATE>
Directory containing the shader crate to compile
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
[default: ./]
--spirv-builder-version <SPIRV_BUILDER_VERSION>
Version of `spirv-builder` dependency.
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
version such as "0.9.0".
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
--rust-toolchain <RUST_TOOLCHAIN>
Rust toolchain channel to use to build `spirv-builder`.
--spirv-builder-version <SPIRV_BUILDER_VERSION>
Version of `spirv-builder` dependency.
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
version such as "0.9.0".
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
--rust-toolchain <RUST_TOOLCHAIN>
Rust toolchain channel to use to build `spirv-builder`.
--force-spirv-cli-rebuild
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
--auto-install-rust-toolchain
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
--force-spirv-cli-rebuild
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
--shader-target <SHADER_TARGET>
Shader target
--auto-install-rust-toolchain
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
[default: spirv-unknown-vulkan1.2]
-o, --output-dir <OUTPUT_DIR>
Path to the output directory for the compiled shaders
--no-default-features
Set cargo default-features
[default: ./]
--features <FEATURES>
Set cargo features
--no-default-features
Set cargo default-features
-o, --output-dir <OUTPUT_DIR>
Path to the output directory for the compiled shaders
--features <FEATURES>
Set cargo features
[default: ./]
--target <TARGET>
`rust-gpu` compile target
-h, --help
Print help (see a summary with '-h')
[default: spirv-unknown-vulkan1.2]
--shader-target <SHADER_TARGET>
Shader target
* Toml
[default: spirv-unknown-vulkan1.2]
Compile a shader crate according to the `cargo gpu build` parameters found in the given toml file
--deny-warnings
Treat warnings as errors during compilation
Usage: cargo-gpu toml [PATH]
--debug
Compile shaders in debug mode
Arguments:
[PATH]
Path to a workspace or package Cargo.toml file.
--capability <CAPABILITY>
Enables the provided SPIR-V capabilities. See: `impl core::str::FromStr for spirv_builder::Capability`
Must include a [[workspace | package].metadata.rust-gpu.build] section where
arguments to `cargo gpu build` are listed.
--extension <EXTENSION>
Enables the provided SPIR-V extensions. See <https://github.com/KhronosGroup/SPIRV-Registry> for all extensions
Path arguments like `output-dir` and `shader-manifest` must be relative to
the location of the Cargo.toml file.
--multimodule
Compile one .spv file per entry point
Example:
--spirv-metadata <SPIRV_METADATA>
Set the level of metadata included in the SPIR-V binary
```toml
[package.metadata.rust-gpu.build.spirv-builder]
git = "https://github.com/Rust-GPU/rust-gpu.git"
rev = "0da80f8"
[default: none]
[package.metadata.rust-gpu.build]
output-dir = "shaders"
shader-manifest = "shaders/manifest.json"
```
--relax-struct-store
Allow store from one struct type to a different type with compatible layout and members
Calling `cargo gpu toml {path/to/Cargo.toml}` with a Cargo.toml that
contains the example above would compile the crate and place the compiled
`.spv` files and manifest in a directory "shaders".
--relax-logical-pointer
Allow allocating an object of a pointer type and returning a pointer value from a function in logical addressing mode
[default: ./Cargo.toml]
--relax-block-layout
Enable `VK_KHR_relaxed_block_layout` when checking standard uniform, storage buffer, and push constant layouts. This is the default when targeting Vulkan 1.1 or later
Options:
-h, --help
Print help (see a summary with '-h')
--uniform-buffer-standard-layout
Enable `VK_KHR_uniform_buffer_standard_layout` when checking standard uniform buffer layouts
--scalar-block-layout
Enable `VK_EXT_scalar_block_layout` when checking standard uniform, storage buffer, and push constant layouts. Scalar layout rules are more permissive than relaxed block layout so in effect this will override the --relax-block-layout option
* Show
Show some useful values
--skip-block-layout
Skip checking standard uniform / storage buffer layout. Overrides any --relax-block-layout or --scalar-block-layout option
Usage: cargo-gpu show <COMMAND>
--preserve-bindings
Preserve unused descriptor bindings. Useful for reflection
Commands:
cache-directory Displays the location of the cache directory
spirv-source The source location of spirv-std
help Print this message or the help of the given subcommand(s)
-h, --help
Print help (see a summary with '-h')
Options:
-h, --help
Print help
* Show
Show some useful values
* Cache-directory
Displays the location of the cache directory
Usage: cargo-gpu show <COMMAND>
Usage: cargo-gpu show cache-directory
Commands:
cache-directory Displays the location of the cache directory
spirv-source The source location of spirv-std
help Print this message or the help of the given subcommand(s)
Options:
-h, --help
Print help
Options:
-h, --help
Print help
* Spirv-source
* Cache-directory
Displays the location of the cache directory
The source location of spirv-std
Usage: cargo-gpu show cache-directory
Usage: cargo-gpu show spirv-source [OPTIONS]
Options:
-h, --help
Print help
Options:
--shader-crate <SHADER_CRATE>
The location of the shader-crate to inspect to determine its spirv-std dependency
[default: ./]
* Spirv-source
The source location of spirv-std
-h, --help
Print help
Usage: cargo-gpu show spirv-source [OPTIONS]
Options:
--shader-crate <SHADER_CRATE>
The location of the shader-crate to inspect to determine its spirv-std dependency
[default: ./]
-h, --help
Print help
````
2 changes: 1 addition & 1 deletion crates/cargo-gpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ codegen-units = 256
opt-level = 3
incremental = true
codegen-units = 256

[lints]
workspace = true
Loading

0 comments on commit 743cb3d

Please sign in to comment.