Skip to content

Commit 8bf791d

Browse files
committed
Included README.md files for published crates
1 parent 6a35586 commit 8bf791d

File tree

9 files changed

+119
-0
lines changed

9 files changed

+119
-0
lines changed

crates/rustc_codegen_spirv-types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "rustc_codegen_spirv-types"
33
description = "SPIR-V backend types shared between rustc_codegen_spirv and spirv-builder"
4+
documentation = "https://embarkstudios.github.io/rust-gpu/api/rustc_codegen_spirv_types/index.html"
45
version.workspace = true
56
authors.workspace = true
67
edition.workspace = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `rustc_codegen_spirv-types`
2+
3+
SPIR-V backend types shared between `rustc_codegen_spirv` and `spirv-builder`. Please refer to [`spirv-builder`](https://crates.io/crates/spirv-builder) for more information.

crates/rustc_codegen_spirv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "rustc_codegen_spirv"
33
description = "SPIR-V code generator backend for rustc"
4+
documentation = "https://embarkstudios.github.io/rust-gpu/api/rustc_codegen_spirv/index.html"
45
version.workspace = true
56
authors.workspace = true
67
edition.workspace = true

crates/rustc_codegen_spirv/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `rustc_codegen_spirv`
2+
3+
Compiler backend for the `SPIR-V` target architecture. This crate is not intended to be used directly. Please refer to [`spirv-builder`](https://crates.io/crates/spirv-builder) for more information.
4+
5+
## Documentation
6+
7+
Because of its nature, this crate can only be built using a very specific nightly version of the Rust toolchain. As such, the `docs.rs` build of the API documentation will likely fail. Please refer to the [documentation in the `rust-gpu` github repo](https://embarkstudios.github.io/rust-gpu/api/rustc_codegen_spirv/index.html) for properly built docs.

crates/spirv-builder/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "spirv-builder"
33
description = "Helper for building shaders with rust-gpu"
4+
# Documentation currently fails on docs.rs, but it doesn't have to. See https://github.com/EmbarkStudios/rust-gpu/issues/970
5+
documentation = "https://embarkstudios.github.io/rust-gpu/api/spirv_builder/index.html"
46
version.workspace = true
57
authors.workspace = true
68
edition.workspace = true

crates/spirv-builder/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!-- inline html -->
2+
<!-- markdownlint-disable-file MD033 -->
3+
# `spirv-builder`
4+
5+
![Rust version](https://img.shields.io/badge/rust-1.66.0_nightly--2022--10--29-purple.svg)
6+
7+
This crate gives you `SpirvBuilder`, a tool to build shaders using [rust-gpu][rustgpu].
8+
9+
It takes care of pulling in the `SPIR-V` backend for Rust, `rustc_codegen_spirv`, and invoking a nested build using appropriate compiler options, some of which may be set using the `SpirvBuilder` API.
10+
11+
## Example
12+
13+
```rust
14+
use spirv_builder::{MetadataPrintout, SpirvBuilder};
15+
16+
fn main() {
17+
SpirvBuilder::new("my_shaders", "spirv-unknown-vulkan1.1")
18+
.print_metadata(MetadataPrintout::Full)
19+
.build()
20+
.unwrap();
21+
}
22+
```
23+
24+
This example will build a shader crate called `my_shaders`. You typically insert this code in your crate's `build.rs` that requires the shader binary. The path to the shader module's binary will be set in the `my_shaders.spv` environment variable, which you can include in your project using something along the lines of:
25+
26+
```rust
27+
const SHADER: &[u8] = include_bytes!(env!("my_shaders.spv"));
28+
```
29+
30+
## Building with `spirv-builder`
31+
32+
Because of its nature, `rustc_codegen_spirv`, and therefore `spirv-builder` by extension, require the use of a very specific nightly toolchain of Rust.
33+
34+
**The current toolchain is: `nightly-2022-10-29`.**
35+
36+
Toolchains for previous versions of `spirv-builder`:
37+
38+
|Version|Toolchain|
39+
|-|-|
40+
|`0.4.0`|`nightly-2022-10-29`|
41+
|`0.4.0-alpha.16` - `0.4.0-alpha.17`|`nightly-2022-10-01`|
42+
|`0.4.0-alpha.15`|`nightly-2022-08-29`|
43+
|`0.4.0-alpha.13` - `0.4.0-alpha.14`|`nightly-2022-04-11`|
44+
45+
The nightly toolchain has to match *exactly*. Starting with `0.4.0-alpha.15`, the commit hash of your local toolchain is checked and you'll get a build error when building `rustc_codegen_spirv` with the wrong toolchain. If you want to experiment with different versions, this check can be omitted by defining the environment variable `RUSTGPU_SKIP_TOOLCHAIN_CHECK`<sup>since `0.4.0-alpha.16`</sup>. Keep in mind that, as `rustc_codegen_spirv` is heavily dependent on `rustc`'s internal API, diverging too much from the required toolchain will quickly result in compile errors.
46+
47+
[rustgpu]: https://github.com/EmbarkStudios/rust-gpu/

crates/spirv-std/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# `spirv-std`
2+
3+
Core functions, traits, and more that make up a “standard library” for SPIR-V for use in [rust-gpu](https://github.com/EmbarkStudios/rust-gpu#readme).
4+
5+
This crate gives a `rust-gpu` shader access to the required `#![spirv(..)]` attribute, as well as povide all kinds of APIs that allows a shader to access GPU resources such as textures and buffers. Optionally, through the use of the `"glam"` feature, it includes some boilerplate trait implementations to make `glam` vector types compatible with these APIs.
6+
7+
## 🚨 BREAKING 🚨
8+
9+
As of `0.4.0-alpha.16`, your shaders will require a different preamble. See [this doc][migration] for more information.
10+
11+
## Example
12+
13+
![Sky shader](https://github.com/EmbarkStudios/rust-gpu/raw/main/docs/assets/sky.jpg)
14+
15+
```rust
16+
use spirv_std::spirv;
17+
use glam::{Vec3, Vec4, vec2, vec3};
18+
19+
#[spirv(fragment)]
20+
pub fn main(
21+
#[spirv(frag_coord)] in_frag_coord: &Vec4,
22+
#[spirv(push_constant)] constants: &ShaderConstants,
23+
output: &mut Vec4,
24+
) {
25+
let frag_coord = vec2(in_frag_coord.x, in_frag_coord.y);
26+
let mut uv = (frag_coord - 0.5 * vec2(constants.width as f32, constants.height as f32))
27+
/ constants.height as f32;
28+
uv.y = -uv.y;
29+
30+
let eye_pos = vec3(0.0, 0.0997, 0.2);
31+
let sun_pos = vec3(0.0, 75.0, -1000.0);
32+
let dir = get_ray_dir(uv, eye_pos, sun_pos);
33+
34+
// evaluate Preetham sky model
35+
let color = sky(dir, sun_pos);
36+
37+
*output = tonemap(color).extend(1.0)
38+
}
39+
```
40+
41+
See [source][source] for full details.
42+
43+
## Getting started
44+
45+
Check out [The `rust-gpu` Dev Guide][gpu-guide] for information on how to get started with using it in your projects.
46+
47+
Experiment with rust-gpu shaders in-browser at [SHADERed][shadered].
48+
49+
[migration]: https://github.com/EmbarkStudios/rust-gpu/blob/main/docs/src/migration-to-register-tool.md
50+
[source]: https://github.com/EmbarkStudios/rust-gpu/blob/main/examples/shaders/sky-shader/src/lib.rs
51+
[gpu-guide]: https://embarkstudios.github.io/rust-gpu/book/
52+
[shadered]: https://shadered.org/shaders?language=rust&sort=hot

crates/spirv-std/macros/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `spirv-std-macros`
2+
3+
This crate implements macros required for `spirv-std`. Most importantly, it implements the `#![spirv(..)]` attribute macro required for use in shader code. Please refer to [`spirv-std`](https://crates.io/crates/spirv-std) for more information.

crates/spirv-std/shared/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `spirv-std-types`
2+
3+
Small shared crate, to share definitions between [`spirv-std`](https://crates.io/crates/spirv-std) and [`spirv-std-macros`](https://crates.io/crates/spirv-std-macros). Please refer to [`spirv-std`](https://crates.io/crates/spirv-std) for more information.

0 commit comments

Comments
 (0)