Skip to content

Commit 961a78f

Browse files
committed
update main docs
1 parent f62023f commit 961a78f

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

crates/cargo-gpu/src/main.rs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
11
//! Rust GPU shader crate builder.
22
//!
3-
//! This program manages installations of `spirv-builder-cli` and `rustc_codegen_spirv`.
4-
//! It uses these tools to compile Rust code into SPIR-V.
3+
//! This program and library allows you to easily compile your rust-gpu shaders,
4+
//! without requiring you to fix your entire project to a specific toolchain.
55
//!
66
//! # How it works
77
//!
8-
//! In order to build shader crates, we must invoke cargo/rustc with a special backend
9-
//! that performs the SPIR-V code generation. This backend is a dynamic library known
10-
//! by its project name `rustc_codegen_spirv`. The name of the artifact itself is
11-
//! OS-dependent.
8+
//! This program primarily manages installations of `rustc_codegen_spirv`, the
9+
//! codegen backend of rust-gpu to generate SPIR-V shader binaries. The codegen
10+
//! backend builds on internal, ever-changing interfaces of rustc, which requires
11+
//! fixing a version of rust-gpu to a specific version of the rustc compiler.
12+
//! Usually, this would require you to fix your entire project to that specific
13+
//! toolchain, but this project loosens that requirement by managing installations
14+
//! of `rustc_codegen_spirv` and their associated toolchains for you.
1215
//!
13-
//! There are a lot of special flags to wrangle and so we use a command line program
14-
//! that wraps `cargo` to perform the building of shader crates. This cli program is
15-
//! called `spirv-builder-cli`, which itself is a cli wrapper around the `spirv-builder`
16-
//! library.
16+
//! We continue to use rust-gpu's `spirv_builder` crate to pass the many additional
17+
//! parameters required to configure rustc and our codegen backend, but provide you
18+
//! with a toolchain agnostic version that you may use from stable rustc. And a
19+
//! `cargo gpu` cmdline utility to simplify shader building even more.
1720
//!
1821
//! ## Where the binaries are
1922
//!
20-
//! `cargo-gpu` maintains different versions `spirv-builder-cli` and `rustc_codegen_spirv`
21-
//! in a cache dir. The location is OS-dependent, for example on macOS it's in
22-
//! `~/Library/Caches/rust-gpu`. Specific versions live inside the cache dir, prefixed
23-
//! by their `spirv-builder` cargo dependency and rust toolchain pair.
23+
//! We store our prebuild `rustc_spirv_builder` binaries in the default cache
24+
//! directory of your OS:
25+
//! * Windows: `C:/users/<user>/AppData/Local/rust-gpu`
26+
//! * MacOS: `~/Library/Caches/rust-gpu`
27+
//! * Linux: `~/.cache/rust-gpu`
2428
//!
25-
//! Building a specific "binary pair" of `spirv-builder-cli` and `rustc_codegen_spirv`
26-
//! happens when there is no existing pair that matches the computed prefix, or if
27-
//! a force rebuild is specified on the command line.
29+
//! ## How we build the backend
2830
//!
29-
//! ## Building the "binary pairs"
30-
//!
31-
//! The source of `spirv-builder-cli` lives alongside this source file, in crate that
32-
//! is not included in the workspace. That same source code is also included statically
33-
//! in **this** source file.
34-
//!
35-
//! When `spirv-builder-cli` needs to be built, a new directory is created in the cache
36-
//! where the source to `spirv-builder-cli` is copied into, containing the specific cargo
37-
//! dependency for `spirv-builder` and the matching rust toolchain channel.
38-
//!
39-
//! Then `cargo` is invoked in that cache directory to build the pair of artifacts, which
40-
//! are then put into the top level of that cache directory.
41-
//!
42-
//! This pair of artifacts is then used to build shader crates.
31+
//! * retrieve the version of rust-gpu you want to use based on the version of the
32+
//! `spirv-std` dependency in your shader crate.
33+
//! * create a dummy project at `<cache_dir>/codegen/<version>/` that depends on
34+
//! `rustc_codegen_spirv`
35+
//! * use `cargo metadata` to `cargo update` the dummy project, which downloads the
36+
//! `rustc_codegen_spirv` crate into cargo's cache, and retrieve the path to the
37+
//! download location.
38+
//! * search for the required toolchain in `build.rs` of `rustc_codegen_spirv`
39+
//! * build it with the required toolchain version
40+
//! * copy out the binary and clean the target dir
4341
//!
4442
//! ## Building shader crates
4543
//!
4644
//! `cargo-gpu` takes a path to a shader crate to build, as well as a path to a directory
47-
//! to put the compiled `spv` source files. It also takes a path to an output mainifest
45+
//! to put the compiled `spv` source files. It also takes a path to an output manifest
4846
//! file where all shader entry points will be mapped to their `spv` source files. This
4947
//! manifest file can be used by build scripts (`build.rs` files) to generate linkage or
5048
//! conduct other post-processing, like converting the `spv` files into `wgsl` files,

0 commit comments

Comments
 (0)