Skip to content

Commit 9199a89

Browse files
committed
Updated docs
1 parent 6cb0c06 commit 9199a89

File tree

3 files changed

+69
-29
lines changed

3 files changed

+69
-29
lines changed

docs/src/SUMMARY.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# Summary
22

33
- [Introduction](./introduction.md)
4-
- [Contributing to Rust-GPU]()
4+
- Contributing to Rust-GPU
55
- [Building](./building-rust-gpu.md)
66
- [Testing](./testing.md)
77
- ["Codegen args" (flags/options) supported by the Rust-GPU codegen backend](./codegen-args.md)
88
- [Minimizing bugs in SPIR-V](./spirv-minimization.md)
99
- [Publishing Rust-GPU on crates.io](./publishing-rust-gpu.md)
1010
- [Platform Support](./platform-support.md)
1111
- [Writing Shader Crates](./writing-shader-crates.md)
12-
- [Features]()
12+
- Features
1313
- [Attribute syntax](./attributes.md)
1414
- [Inline Assembly](./inline-asm.md)
1515
- [Image type syntax](./image.md)
16-
- [RFCs]()
17-
- [001. Resource Binding Syntax](./rfcs/001-resource-binding-syntax.md)

docs/src/publishing-rust-gpu.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
# Publishing rust-gpu on crates.io
22

33
This is a task list for the maintainers of rust-gpu to remember to do when publishing a new version
4-
of rust-gpu (probably not useful for contributors without access to embark's crates.io account :P)
4+
of rust-gpu (probably not useful for contributors without access to embark's crates.io account 😋)
55

6-
1. Bump all the versions in rust-gpu to the next one. I've found this command to be useful:
7-
`rg --files-with-matches alpha | xargs sed -i 's/0.4.0-alpha.10/0.4.0-alpha.12/g'` (replacing with
8-
whatever versions are relevant)
9-
2. Create a PR with that change. Wait for CI and a review, and merge it.
10-
3. Pull the merged `main` branch.
11-
4. Tag `main` with the version: `git tag v0.4.0-alpha.12`
12-
5. Push the tag: `git push origin v0.4.0-alpha.12`
13-
6. Publish the crates: `cd [crate] && cargo publish` (make sure `.cargo/credentials` is set to
14-
embark's token) - crates to be published, in order:
15-
1. crates/spirv-std/shared
16-
2. crates/spirv-std/macros
17-
3. crates/spirv-std
6+
The published crates and their relative locations are:
7+
1. `spirv-std-types` (`crates/spirv-std/shared`)
8+
2. `spirv-std-macros` (`crates/spirv-std/macros`)
9+
3. `spirv-std` (`crates/spirv-std`)
10+
4. `rustc_codegen_spirv-types` (`crates/rustc_codegen_spirv-types`)
11+
5. `rustc_codegen_spirv` (`crates/rustc_codegen_spirv`)
12+
6. `spirv-builder` (`crates/spirv-builder`)
13+
14+
Publishing the crates in above order prevents dependency issues.
15+
These are the steps:
16+
17+
1. Bump all the versions to the next one in the workspace's `Cargo.toml`. This project uses workspace
18+
inheritance, so this is the only place you'll find these actual versions. Make sure to pin the
19+
rust-gpu dependencies to their *exact* versions using the `=`-notation, such as: `=0.4.0`. All crates
20+
are built and published in tandem so you're not expected to be able to mix and match between versions.
21+
2. Add this new version to the table in `crates/spirv-builder/README.md` and make sure the correct
22+
nightly version is listed there as well.
23+
3. Create a PR with that change. Wait for CI and a review, and merge it.
24+
4. Pull the merged `main` branch.
25+
5. Tag `main` with the version: `git tag v0.4.0`
26+
6. Push the tag: `git push origin v0.4.0`
27+
7. Publish the crates: `cd [crate] && cargo publish` in the order of the list aboven (make sure
28+
`.cargo/credentials` is set to embark's token). The crates.io index might take some seconds to update
29+
causing an error if the crates are published in quick succession. Wait a couple of seconds and try
30+
again 🙂.

docs/src/writing-shader-crates.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,46 @@ There are two main ways to setup your shader project locally.
3131
flags in your cargo configuration to enable you to run `cargo build` in your
3232
shader crate.
3333

34-
3534
### Using `spirv-builder`
3635
If you're writing a bigger application and you want to integrate SPIR-V shader
3736
crates to display, it's recommended to use `spirv-builder` in a build script.
3837

3938
1. Copy the [`rust-toolchain`] file to your project. (You must use the same
40-
version of Rust as `rust-gpu`.)
39+
version of Rust as `rust-gpu`. Utimately, the build will fail with a nice
40+
error message when you don't use the exact same version)
4141
2. Reference `spirv-builder` in your Cargo.toml:
4242
```toml
4343
[build-dependencies]
44-
spirv-builder = { git = "https://github.com/EmbarkStudios/rust-gpu" }
44+
spirv-builder = "0.4"
4545
```
46-
(we currently do not publish spirv-builder on crates.io)
46+
All dependent crates are published on [crates.io](https://crates.io).
4747
3. Create a `build.rs` in your project root.
4848

4949
#### `build.rs`
50-
Paste the following into the `main` for your build script.
50+
Paste the following into `build.rs`
5151

5252
```rust,no_run
53-
SpirvBuilder::new(path_to_shader, target)
54-
.print_metadata(MetadataPrintout::Full)
55-
.build()?;
53+
use spirv_builder::{MetadataPrintout, SpirvBuilder};
54+
55+
fn main() {
56+
SpirvBuilder::new(shader_crate, target)
57+
.print_metadata(MetadataPrintout::Full)
58+
.build()
59+
.unwrap();
60+
}
5661
```
5762

58-
The values available for the `target` parameter are available
63+
Substituting `shader_crate` with a relative path to your shader crate. The values available for the `target` parameter are available
5964
[here](./platform-support.md). For example, if building for vulkan 1.1, use
6065
`"spirv-unknown-vulkan1.1"`.
6166

6267
The `SpirvBuilder` struct has numerous configuration options available, see
63-
rustdoc for documentation.
68+
[documentation](https://embarkstudios.github.io/rust-gpu/api/spirv_builder/struct.SpirvBuilder.html).
6469

6570
#### `main.rs`
71+
The following will directly include the shader module binary into your application.
6672
```rust,no_run
67-
const SHADER: &[u8] = include_bytes!(env!("<shader_name>.spv"));
73+
const SHADER: &[u8] = include_bytes!(env!("<shader_crate>.spv"));
6874
```
6975

7076
> **Note** If your shader name contains hyphens, the name of environment variable will be the name with hyphens changed to underscores.
@@ -100,7 +106,7 @@ necessary flags. Before you can do that however you need to do a couple of steps
100106
first to build the compiler backend.
101107

102108
1. Clone the `rust-gpu` repository
103-
3. `cargo build --release` in `rust-gpu`.
109+
2. `cargo build --release` in `rust-gpu`.
104110

105111
Now you should have a `librustc_codegen_spirv` dynamic library available in
106112
`target/release`. You'll need to keep this somewhere stable that you can
@@ -134,3 +140,26 @@ Now you should have `<project_name>.spv` SPIR-V file in `target/debug` that you
134140
can give to a renderer.
135141

136142
[`rust-toolchain`]: https://github.com/EmbarkStudios/rust-gpu/blob/main/rust-toolchain
143+
144+
## Writing your first shader
145+
146+
Configure your shader crate as a `"dylib"` type crate, and add `spirv-std` to its dependencies. The following example also enables the `glam` vector library.
147+
148+
```toml
149+
[dependencies]
150+
spirv-std = { version = "0.4", features = ["glam"] }
151+
```
152+
153+
Make sure your shader code uses the `no_std` attribute and makes the `spirv` attribute visibile in the global scope. Then, you're ready to write your first shader. Here's a very simple fragment shader called `main_fs` as an example that outputs the color red:
154+
155+
```rust,norun
156+
#![no_std]
157+
158+
use spirv_std::spirv;
159+
use spirv_std::glam::{vec4, Vec4};
160+
161+
#[spirv(fragment)]
162+
pub fn main_fs(output: &mut Vec4) {
163+
*output = vec4(1.0, 0.0, 0.0, 1.0);
164+
}
165+
```

0 commit comments

Comments
 (0)