You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add spirv-tools and spirv-tools-sys crates to wrap usage of spirv-tools (#179)
* Add spirv-headers and spirv-tools as submodules
* Add simple generator and the generated code needed for compilation
* Add first pass on spirv-tools-sys
* Add first pass on spirv-tools
* Replace invocation of spirv-opt with spirv-tools crate
* Use C++11
* Placate clippy
* Add validation, replacing spirv-val with the spirv-tools crate
* Fix MSVC warning
* Use patched spirv-tools
* Fixup metadata
* Add same compiler flags as "official" build scripts
* Update spirv-tools and generated files
* Fixup
* Add assembler and example
* Use assembler in tests
* Oops, fix macos TARGET_OS
* write -> write_all
* Start splitting spirv-tools into a compiled vs tool feature set
* Checkpointing
* Checkpoint
* Boop
* Get tests to work both with installed and compiled tools
* Cleanup CI config
* Splits steps to clearly show how long each part of a longer (eg test)
step actually takes
* Label all steps
* Explicitly disable submodule checkout
* Rustfmt
* Rename features for consistency and fix clippy warnings
* Split "core" crates from examples
* Add run_clippy bash script
* Add test script
* Remove x flag
* Newline
* Actually print out errors from running val/opt
* Revert drive-by import merging
* Change intro to take the changes this PR has into account
* Actually run tests on Windows
* Fetch only the host target to reduce fetch times
* Add more info when a spirv tool returns a non-zero exit code
* Rustfmt
* Switch tool assembler to use files to see if it fixes windows
* Use files for input and output for now until I can figure out Windows being dumb
* Fix API docs generation
* Compile and use C++ code to check Windows issue
* Return to use installed tools
1. Install the prerequisites using the provided setup script. From the root of the project, run:
10
15
11
16
MacOS, Linux:
17
+
12
18
```shell
13
19
sh setup.sh
14
20
```
15
21
16
22
Windows:
17
-
```
23
+
24
+
```shell
18
25
setup.bat
19
26
```
20
27
21
28
The setup script installs nightly Rust (required for now, see [#78](https://github.com/EmbarkStudios/rust-gpu/issues/78) for tracking issue).
22
29
23
-
1. Install [SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools#downloads) and add it to your PATH (for now, eventually we will automatically build and link it instead of calling executables)
30
+
1. **optional**Install [SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools#downloads) and add it to your `PATH`. You can skip this step if you just want to run examples with the defaults. See [Using installed SPIRV-Tools](#using-installed-spirv-tools) if you decide to go with this option.
24
31
25
32
1. Next, look at the [examples](examples) folder. There are two projects here: [examples/example-shader](examples/example-shader) and [examples/example-runner](examples/example-runner). The example-shader project is a "GPU crate", one that will be compiled to a SPIR-V module. The example-runner project is a normal, CPU crate that uses vulkan to consume the example-shader SPIR-V module to display a shader.
26
33
@@ -36,15 +43,13 @@ how to use and develop on Rust-GPU.
36
43
37
44
Be aware that this project is in a very early phase - if the above doesn't work, please [file an issue](https://github.com/EmbarkStudios/rust-gpu/issues)!
38
45
39
-
## Getting started, for power users who don't want to use spirv-builder.
46
+
## Getting started, for power users who don't want to use spirv-builder
40
47
41
48
If you would like to build the compiler, `rustc_codegen_spirv` is the relevant folder. Install the prerequisites, as above, then, `cd rustc_codegen_spirv && cargo build`. This produces an .so file, located at `./target/debug/librustc_codegen_spirv.so` (or `.dll`/`.dylib` depending on your platform).
42
49
43
50
This file is a dynamically loaded backend for rustc - you may tell rustc to use it as a backend through the `-Z codegen-backend=...` flag. To pass this to rustc through cargo, set the environment variable `RUSTFLAGS="-Z codegen-backend=$PATH_TO_FILE"`.
44
51
45
-
Then, when building a GPU crate, we need to configure some flags when we call cargo. First, we need to build libcore
46
-
ourselves - we obviously have no SPIR-V libcore installed on our system! Use the flag `-Z build-std=core`. Then, we need
47
-
to tell rustc to generate SPIR-V instead of x86 code: `--target spirv-unknown-unknown`.
52
+
Then, when building a GPU crate, we need to configure some flags when we call cargo. First, we need to build libcore ourselves - we obviously have no SPIR-V libcore installed on our system! Use the flag `-Z build-std=core`. Then, we need to tell rustc to generate SPIR-V instead of x86 code: `--target spirv-unknown-unknown`.
48
53
49
54
Overall, building your own SPIR-V crate looks like:
50
55
@@ -61,3 +66,15 @@ To create a GPU crate, look at the [examples/example-shader](examples/example-sh
61
66
62
67
This is all a little convoluted, hence the [spirv-builder](spirv-builder) crate handles a lot of this.
63
68
69
+
## Using installed SPIRV-Tools
70
+
71
+
By default, all of the crates and examples in this repo will compile the `spirv-tools-sys` crate, including a lot of C++ code from [SPIRV-Tools](https://github.com/EmbarkStudios/SPIRV-Tools). If you don't want to build the C++ code because you already have [SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools#downloads) installed, or just don't want to spend more time compiling, you can build/run the crate with the `use-installed-tools` feature.
You should see `warning: use-installed-tools feature on, skipping compilation of C++ code` during the compilation, but otherwise the build will function just the same as if you compiled the C++ code, with the exception that it will fail if you don't have SPIRV-Tools installed correctly.
0 commit comments