Skip to content

Commit f1f9df5

Browse files
authored
Merge pull request #441 from tangmi/build-shader-docs
Add docs for building shaders on Windows
2 parents badf37a + 9d69e67 commit f1f9df5

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

resources/shaders/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
This directory contains postprocessed versions of the shaders in the top-level
22
`shaders/` directory, for convenience. Don't modify the shaders here; instead
3-
modify the corresponding shaders in `shaders/` and rerun `make` in that
4-
directory.
5-
6-
You will need `glslangValidator` and `spirv-cross` installed to execute the
7-
Makefile. On macOS, you can get these with `brew install glslang spirv-cross`.
3+
modify the corresponding shaders in `shaders/` and rebuild them according to
4+
`shaders/README.md`.

shaders/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ OUT=\
5858

5959
GLSL_3_VERSION=330
6060
GLSL_4_VERSION=430
61+
62+
GLSLANG?=glslangValidator
6163
GLSLANGFLAGS=--auto-map-locations -I.
6264
GLSLANGFLAGS_METAL=$(GLSLANGFLAGS) -DPF_ORIGIN_UPPER_LEFT=1
6365

@@ -81,13 +83,13 @@ clean:
8183
rm -f $(OUT)
8284

8385
build/metal/%.spv: %.glsl $(INCLUDES)
84-
mkdir -p $(dir $@) && glslangValidator $(GLSLANGFLAGS_METAL) -G$(GLSL_VERSION) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -o $@ $<
86+
mkdir -p $(dir $@) && $(GLSLANG) $(GLSLANGFLAGS_METAL) -G$(GLSL_VERSION) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -o $@ $<
8587

8688
$(TARGET_DIR)/gl3/%.glsl: %.glsl $(INCLUDES)
87-
mkdir -p $(dir $@) && echo $(GLSL_VERSION_HEADER) > $@ && echo $(HEADER) >> $@ && ( glslangValidator $(GLSLANGFLAGS) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -E $< | sed $(GLSL_SED_ARGS) >> $@ ) || ( rm $@ && exit 1 )
89+
mkdir -p $(dir $@) && echo $(GLSL_VERSION_HEADER) > $@ && echo $(HEADER) >> $@ && ( $(GLSLANG) $(GLSLANGFLAGS) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -E $< | sed $(GLSL_SED_ARGS) >> $@ ) || ( rm $@ && exit 1 )
8890

8991
$(TARGET_DIR)/gl4/%.glsl: %.glsl $(INCLUDES)
90-
mkdir -p $(dir $@) && echo $(GLSL_VERSION_HEADER) > $@ && echo $(HEADER) >> $@ && ( glslangValidator $(GLSLANGFLAGS) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -E $< | sed $(GLSL_SED_ARGS) >> $@ ) || ( rm $@ && exit 1 )
92+
mkdir -p $(dir $@) && echo $(GLSL_VERSION_HEADER) > $@ && echo $(HEADER) >> $@ && ( $(GLSLANG) $(GLSLANGFLAGS) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -E $< | sed $(GLSL_SED_ARGS) >> $@ ) || ( rm $@ && exit 1 )
9193

9294
$(TARGET_DIR)/metal/%.metal: build/metal/%.spv
9395
mkdir -p $(dir $@) && echo $(HEADER) > $@ && ( $(SPIRVCROSS) $(SPIRVCROSSFLAGS) $< >> $@ ) || ( rm $@ && exit 1 )

shaders/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Building the shaders
2+
3+
This document describes how to regenerate the shaders used by Pathfinder. Unless
4+
you have modified files in this directory, regenerating the shaders is not
5+
necessary to use Pathfinder or do most kinds of development on it.
6+
7+
You will need `glslangValidator` and `spirv-cross` installed to execute the
8+
Makefile from this directory. You can speed up the build by parallelizing the
9+
build: `make -j`.
10+
11+
## macOS
12+
13+
You can use [Homebrew](https://brew.sh/) to install the dependencies:
14+
15+
```sh
16+
brew install glslang spirv-cross
17+
```
18+
19+
## Windows
20+
21+
`glslangValidator` and `spirv-cross` are available by installing the
22+
[Vulkan SDK](https://vulkan.lunarg.com/sdk/home). You'll also need some commands
23+
like `make`, `rm`, etc. These are available on the
24+
[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
25+
shell. You'll need to set these environment variables for `make` to succeed:
26+
27+
```sh
28+
export GLSLANG=glslangValidator.exe
29+
export SPIRVCROSS=spirv-cross.exe
30+
```
31+
32+
Note: the Windows versions of `glslangValidator` and `spirv-cross` may change
33+
the line endings of the generated output. Please take care to ensure that
34+
unintended line ending changes aren't accidentally commited, for instance by
35+
[configuring Git to automatically handle line endings](https://docs.github.com/en/github/using-git/configuring-git-to-handle-line-endings#global-settings-for-line-endings).

0 commit comments

Comments
 (0)