Skip to content

Commit

Permalink
Add target argument to spirv-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Apr 1, 2021
1 parent d6ff9cd commit 7f2825c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
7 changes: 5 additions & 2 deletions crates/spirv-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ pub struct SpirvBuilder {
release: bool,
spirv_version: Option<(u8, u8)>,
memory_model: Option<MemoryModel>,
target: String,
}

impl SpirvBuilder {
pub fn new(path_to_crate: impl AsRef<Path>) -> Self {
pub fn new(path_to_crate: impl AsRef<Path>, target: impl Into<String>) -> Self {
Self {
path_to_crate: path_to_crate.as_ref().to_owned(),
print_metadata: true,
release: true,
spirv_version: None,
memory_model: None,
target: target.into(),
}
}

Expand Down Expand Up @@ -250,7 +253,7 @@ fn invoke_rustc(builder: &SpirvBuilder, multimodule: bool) -> Result<PathBuf, Sp
"-Z",
"build-std=core",
"--target",
"spirv-unknown-unknown",
&*builder.target,
]);
if builder.release {
cargo.arg("--release");
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-builder/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn setup(src: &str) -> Result<PathBuf, Box<dyn Error>> {

fn build(src: &str) -> PathBuf {
let project = setup(src).expect("Failed to set up project");
crate::SpirvBuilder::new(&project)
crate::SpirvBuilder::new(&project, "spirv-unknown-spv1.3")
.print_metadata(false)
.release(false)
.build()
Expand Down
39 changes: 39 additions & 0 deletions docs/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ The `rust-gpu` project currently supports a limited number of platforms and grap
| WGPU | 0.6 | Primary | Uses a translation layer to Metal/DX12
| OpenGL | ??? | Tertiary |

### SPIR-V Targets

- `spirv-unknown-spv1.0`
- `spirv-unknown-spv1.1`
- `spirv-unknown-spv1.2`
- `spirv-unknown-spv1.3`
- `spirv-unknown-spv1.4`
- `spirv-unknown-spv1.5`

### Vulkan Targets

- `spirv-unknown-vulkan1.0`
- `spirv-unknown-vulkan1.1`
- `spirv-unknown-vulkan1.1spv1.4`
- `spirv-unknown-vulkan1.2`

### WebGPU Targets

- `spirv-unknown-webgpu0`

### OpenGL Targets

- `spirv-unknown-opengl4.0`
- `spirv-unknown-opengl4.1`
- `spirv-unknown-opengl4.2`
- `spirv-unknown-opengl4.3`
- `spirv-unknown-opengl4.5`

### OpenCL Targets

- `spirv-unknown-opencl1.2`
- `spirv-unknown-opencl1.2embedded`
- `spirv-unknown-opencl2.0`
- `spirv-unknown-opencl2.0embedded`
- `spirv-unknown-opencl2.1`
- `spirv-unknown-opencl2.1embedded`
- `spirv-unknown-opencl2.2`
- `spirv-unknown-opencl2.2embedded`

## GPU

Currently we don't have specific generations of GPUs for support, as long they support Vulkan 1.1+ with the latest officially installed drivers it should be able build and run the examples. You can check your Vulkan version using the [`vulkaninfo`] command from the `vulkan-sdk`.
Expand Down
15 changes: 7 additions & 8 deletions docs/src/writing-shader-crates.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can now test out and try building shaders with rust-gpu from the browser!
and run shaders on the web.
- [Shader Playground] A playground for building and checking the output of
shader code similar to godbolt or play.rust-lang.org.

[SHADERed]: https://shadered.org/template
[shader playground]: http://shader-playground.timjones.io/9d744d5893beb6a8f129fda50ad4aeeb

Expand Down Expand Up @@ -70,15 +70,14 @@ Now you should have a `librustc_codegen_spirv` dynamic library available in
`target/release`. You'll need to keep this somewhere stable that you can
reference from your shader project.

Now we need to add our `.cargo/config` file. This tells cargo to build for the
`spirv-unknown-unknown` target, and provides a path to the codegen backend for
that target. We have to also provide `-Zbuild-std` as the
`spirv-unknown-unknown` sysroot is not currently available in the
default installation.
Now we need to add our `.cargo/config` file. This is a configuration file that
tells cargo how to build for SPIR-V. You need provide the target you're
compiling for (see [platform support](./platform-support.md)) and provide a path to your built `rustc_codegen_spirv` dynamic
library. We have to also provide `-Zbuild-std`.

```toml
[build]
target = "spirv-unknown-unknown"
target = "spirv-unknown-spv1.3"
rustflags = [
"-Zcodegen-backend=<path_to_librustc_codegen_spirv>",
"-Zsymbol-mangling-version=v0"
Expand All @@ -88,7 +87,7 @@ rustflags = [
build-std=["core"]
```

Now we can build our crate with cargo as normal.
Now we can build our crate with cargo as normal.
```bash
cargo build
```
Expand Down
2 changes: 1 addition & 1 deletion examples/multibuilder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use spirv_builder::SpirvBuilder;

fn main() {
let result = SpirvBuilder::new("../shaders/sky-shader")
let result = SpirvBuilder::new("../shaders/sky-shader", "spirv-unknown-spv1.3")
.print_metadata(false)
.spirv_version(1, 0)
.build_multimodule()
Expand Down
2 changes: 1 addition & 1 deletion examples/runners/wgpu/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use spirv_builder::SpirvBuilder;
use std::error::Error;

fn build_shader(path_to_create: &str) -> Result<(), Box<dyn Error>> {
SpirvBuilder::new(path_to_create)
SpirvBuilder::new(path_to_create, "spirv-unknown-vulkan1.1")
.spirv_version(1, 0)
.build()?;
Ok(())
Expand Down

0 comments on commit 7f2825c

Please sign in to comment.