[rs] Add makefile for shader compilation

Add example shader compilation instructions

Arbitrary depth directory wildcard like globs aren't a thing in make wildcards.

Add phony targets as prerequisites of .PHONY
This commit is contained in:
Han Kruiger
2020-06-03 19:24:54 +02:00
parent d8e8268392
commit 969642cb75
2 changed files with 27 additions and 0 deletions

20
wgpu/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# This Makefile generates SPIR-V shaders from GLSL shaders in the examples.
shader_compiler = glslangValidator
# All input shaders.
glsls = $(wildcard examples/*/*.vert examples/*/*.frag examples/*/*.comp)
# All SPIR-V targets.
spirvs = $(addsuffix .spv,$(glsls))
.PHONY: default
default: $(spirvs)
# Rule for making a SPIR-V target.
$(spirvs): %.spv: %
$(shader_compiler) -V $< -o $@
.PHONY: clean
clean:
rm -f $(spirvs)

View File

@@ -68,6 +68,13 @@ Create an `index.html` file into `target/generated` directory and add the follow
Now run a web server locally inside the `target/generated` directory to see the `hello-triangle` in the browser.
e.g. `python -m http.server`
### How to compile the shaders in the examples
Currently, shaders in the examples are written in GLSL 4.50 and compiled to SPIR-V manually.
In the future [WGSL](https://gpuweb.github.io/gpuweb/wgsl.html) will be the shader language for WebGPU, but support is not implemented yet.
For now, the shaders can be compiled to SPIR-V by running `make`, which requires you to have `glslang`s `glslangValidator` binary.
## Friends
Shout out to the following projects that work best with wgpu-rs: