Skip to content

Commit 2da63bc

Browse files
authored
Merge pull request #34 from tombh/support-all-spirv-builder-config
Support for setting config in shader's `Cargo.toml`
2 parents 91b5094 + 0347ae5 commit 2da63bc

File tree

21 files changed

+1208
-511
lines changed

21 files changed

+1208
-511
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ members = [
44
]
55

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

912
# This currently needs to be excluded because it depends on a version of `rust-gpu` that
@@ -51,5 +54,4 @@ pub_with_shorthand = { level = "allow", priority = 1 }
5154
partial_pub_fields = { level = "allow", priority = 1 }
5255
pattern_type_mismatch = { level = "allow", priority = 1 }
5356
std_instead_of_alloc = { level = "allow", priority = 1 }
54-
55-
57+
arbitrary_source_item_ordering = { level = "allow", priority = 1 }

README.md

Lines changed: 125 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -54,193 +54,195 @@ the usage instructions the backend and nightly Rust version are referred to as "
5454
5555
## Usage
5656

57+
All the following arguments for the `build` and `install` commands can also be set in the shader crate's `Cargo.toml`
58+
file. In general usage that would be the recommended way to set config. See `crates/shader-crate-template/Cargo.toml`
59+
for an example.
60+
5761
````
58-
Commands:
59-
install Install rust-gpu compiler artifacts
60-
build Compile a shader crate to SPIR-V
61-
toml Compile a shader crate according to the `cargo gpu build` parameters found in the given toml file
62-
show Show some useful values
63-
help Print this message or the help of the given subcommand(s)
62+
Commands:
63+
install Install rust-gpu compiler artifacts
64+
build Compile a shader crate to SPIR-V
65+
show Show some useful values
66+
help Print this message or the help of the given subcommand(s)
6467
65-
Options:
66-
-h, --help
67-
Print help
68+
Options:
69+
-h, --help
70+
Print help
6871
69-
-V, --version
70-
Print version
72+
-V, --version
73+
Print version
7174
7275
7376
* Install
77+
Install rust-gpu compiler artifacts
7478
75-
Install rust-gpu compiler artifacts
76-
77-
Usage: cargo-gpu install [OPTIONS]
79+
Usage: cargo-gpu install [OPTIONS]
7880
79-
Options:
80-
--shader-crate <SHADER_CRATE>
81-
Directory containing the shader crate to compile
81+
Options:
82+
--shader-crate <SHADER_CRATE>
83+
Directory containing the shader crate to compile
8284
83-
[default: ./]
85+
[default: ./]
8486
85-
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
86-
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
87+
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
88+
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
8789
88-
--spirv-builder-version <SPIRV_BUILDER_VERSION>
89-
Version of `spirv-builder` dependency.
90-
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
91-
version such as "0.9.0".
92-
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
93-
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
90+
--spirv-builder-version <SPIRV_BUILDER_VERSION>
91+
Version of `spirv-builder` dependency.
92+
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
93+
version such as "0.9.0".
94+
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
95+
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
9496
95-
--rust-toolchain <RUST_TOOLCHAIN>
96-
Rust toolchain channel to use to build `spirv-builder`.
97+
--rust-toolchain <RUST_TOOLCHAIN>
98+
Rust toolchain channel to use to build `spirv-builder`.
9799
98-
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
100+
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
99101
100-
--force-spirv-cli-rebuild
101-
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
102+
--force-spirv-cli-rebuild
103+
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
102104
103-
--auto-install-rust-toolchain
104-
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
105+
--auto-install-rust-toolchain
106+
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
105107
106-
-h, --help
107-
Print help (see a summary with '-h')
108+
-h, --help
109+
Print help (see a summary with '-h')
108110
109111
110112
* Build
113+
Compile a shader crate to SPIR-V
111114
112-
Compile a shader crate to SPIR-V
113-
114-
Usage: cargo-gpu build [OPTIONS]
115-
116-
Options:
117-
--shader-crate <SHADER_CRATE>
118-
Directory containing the shader crate to compile
115+
Usage: cargo-gpu build [OPTIONS]
119116
120-
[default: ./]
117+
Options:
118+
--shader-crate <SHADER_CRATE>
119+
Directory containing the shader crate to compile
121120
122-
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
123-
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
121+
[default: ./]
124122
125-
--spirv-builder-version <SPIRV_BUILDER_VERSION>
126-
Version of `spirv-builder` dependency.
127-
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
128-
version such as "0.9.0".
129-
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
130-
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
123+
--spirv-builder-source <SPIRV_BUILDER_SOURCE>
124+
Source of `spirv-builder` dependency Eg: "https://github.com/Rust-GPU/rust-gpu"
131125
132-
--rust-toolchain <RUST_TOOLCHAIN>
133-
Rust toolchain channel to use to build `spirv-builder`.
126+
--spirv-builder-version <SPIRV_BUILDER_VERSION>
127+
Version of `spirv-builder` dependency.
128+
* If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
129+
version such as "0.9.0".
130+
* If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
131+
as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
134132
135-
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
133+
--rust-toolchain <RUST_TOOLCHAIN>
134+
Rust toolchain channel to use to build `spirv-builder`.
136135
137-
--force-spirv-cli-rebuild
138-
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
136+
This must be compatible with the `spirv_builder` argument as defined in the `rust-gpu` repo.
139137
140-
--auto-install-rust-toolchain
141-
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
138+
--force-spirv-cli-rebuild
139+
Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt
142140
143-
--shader-target <SHADER_TARGET>
144-
Shader target
141+
--auto-install-rust-toolchain
142+
Assume "yes" to "Install Rust toolchain: [y/n]" prompt
145143
146-
[default: spirv-unknown-vulkan1.2]
144+
-o, --output-dir <OUTPUT_DIR>
145+
Path to the output directory for the compiled shaders
147146
148-
--no-default-features
149-
Set cargo default-features
147+
[default: ./]
150148
151-
--features <FEATURES>
152-
Set cargo features
149+
--no-default-features
150+
Set cargo default-features
153151
154-
-o, --output-dir <OUTPUT_DIR>
155-
Path to the output directory for the compiled shaders
152+
--features <FEATURES>
153+
Set cargo features
156154
157-
[default: ./]
155+
--target <TARGET>
156+
`rust-gpu` compile target
158157
159-
-h, --help
160-
Print help (see a summary with '-h')
158+
[default: spirv-unknown-vulkan1.2]
161159
160+
--shader-target <SHADER_TARGET>
161+
Shader target
162162
163-
* Toml
163+
[default: spirv-unknown-vulkan1.2]
164164
165-
Compile a shader crate according to the `cargo gpu build` parameters found in the given toml file
165+
--deny-warnings
166+
Treat warnings as errors during compilation
166167
167-
Usage: cargo-gpu toml [PATH]
168+
--debug
169+
Compile shaders in debug mode
168170
169-
Arguments:
170-
[PATH]
171-
Path to a workspace or package Cargo.toml file.
171+
--capability <CAPABILITY>
172+
Enables the provided SPIR-V capabilities. See: `impl core::str::FromStr for spirv_builder::Capability`
172173
173-
Must include a [[workspace | package].metadata.rust-gpu.build] section where
174-
arguments to `cargo gpu build` are listed.
174+
--extension <EXTENSION>
175+
Enables the provided SPIR-V extensions. See <https://github.com/KhronosGroup/SPIRV-Registry> for all extensions
175176
176-
Path arguments like `output-dir` and `shader-manifest` must be relative to
177-
the location of the Cargo.toml file.
177+
--multimodule
178+
Compile one .spv file per entry point
178179
179-
Example:
180+
--spirv-metadata <SPIRV_METADATA>
181+
Set the level of metadata included in the SPIR-V binary
180182
181-
```toml
182-
[package.metadata.rust-gpu.build.spirv-builder]
183-
git = "https://github.com/Rust-GPU/rust-gpu.git"
184-
rev = "0da80f8"
183+
[default: none]
185184
186-
[package.metadata.rust-gpu.build]
187-
output-dir = "shaders"
188-
shader-manifest = "shaders/manifest.json"
189-
```
185+
--relax-struct-store
186+
Allow store from one struct type to a different type with compatible layout and members
190187
191-
Calling `cargo gpu toml {path/to/Cargo.toml}` with a Cargo.toml that
192-
contains the example above would compile the crate and place the compiled
193-
`.spv` files and manifest in a directory "shaders".
188+
--relax-logical-pointer
189+
Allow allocating an object of a pointer type and returning a pointer value from a function in logical addressing mode
194190
195-
[default: ./Cargo.toml]
191+
--relax-block-layout
192+
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
196193
197-
Options:
198-
-h, --help
199-
Print help (see a summary with '-h')
194+
--uniform-buffer-standard-layout
195+
Enable `VK_KHR_uniform_buffer_standard_layout` when checking standard uniform buffer layouts
200196
197+
--scalar-block-layout
198+
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
201199
202-
* Show
203-
204-
Show some useful values
200+
--skip-block-layout
201+
Skip checking standard uniform / storage buffer layout. Overrides any --relax-block-layout or --scalar-block-layout option
205202
206-
Usage: cargo-gpu show <COMMAND>
203+
--preserve-bindings
204+
Preserve unused descriptor bindings. Useful for reflection
207205
208-
Commands:
209-
cache-directory Displays the location of the cache directory
210-
spirv-source The source location of spirv-std
211-
help Print this message or the help of the given subcommand(s)
206+
-h, --help
207+
Print help (see a summary with '-h')
212208
213-
Options:
214-
-h, --help
215-
Print help
216209
210+
* Show
211+
Show some useful values
217212
218-
* Cache-directory
219-
220-
Displays the location of the cache directory
213+
Usage: cargo-gpu show <COMMAND>
221214
222-
Usage: cargo-gpu show cache-directory
215+
Commands:
216+
cache-directory Displays the location of the cache directory
217+
spirv-source The source location of spirv-std
218+
help Print this message or the help of the given subcommand(s)
223219
224-
Options:
225-
-h, --help
226-
Print help
220+
Options:
221+
-h, --help
222+
Print help
227223
228224
229-
* Spirv-source
225+
* Cache-directory
226+
Displays the location of the cache directory
230227
231-
The source location of spirv-std
228+
Usage: cargo-gpu show cache-directory
232229
233-
Usage: cargo-gpu show spirv-source [OPTIONS]
230+
Options:
231+
-h, --help
232+
Print help
234233
235-
Options:
236-
--shader-crate <SHADER_CRATE>
237-
The location of the shader-crate to inspect to determine its spirv-std dependency
238234
239-
[default: ./]
235+
* Spirv-source
236+
The source location of spirv-std
240237
241-
-h, --help
242-
Print help
238+
Usage: cargo-gpu show spirv-source [OPTIONS]
243239
240+
Options:
241+
--shader-crate <SHADER_CRATE>
242+
The location of the shader-crate to inspect to determine its spirv-std dependency
244243
244+
[default: ./]
245245
246+
-h, --help
247+
Print help
246248
````

crates/cargo-gpu/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build = "build.rs"
1111

1212
[dependencies]
1313
anyhow.workspace = true
14-
spirv-builder-cli = { path = "../spirv-builder-cli", default-features = false }
14+
spirv-builder-cli = { path = "../spirv-builder-cli", default-features = false, features = ["rspirv-latest"] }
1515
clap.workspace = true
1616
directories.workspace = true
1717
env_logger.workspace = true
@@ -41,6 +41,6 @@ codegen-units = 256
4141
opt-level = 3
4242
incremental = true
4343
codegen-units = 256
44-
44+
4545
[lints]
4646
workspace = true

0 commit comments

Comments
 (0)