From f8209946e332a3cbeea246d82c5a58b234f32909 Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Sat, 12 Sep 2020 13:49:28 -0700 Subject: [PATCH 1/4] Update documentation for building shaders --- resources/shaders/README.md | 7 ++----- shaders/Makefile | 8 +++++--- shaders/README.md | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 shaders/README.md diff --git a/resources/shaders/README.md b/resources/shaders/README.md index 24bff80f..163ba3f1 100644 --- a/resources/shaders/README.md +++ b/resources/shaders/README.md @@ -1,7 +1,4 @@ This directory contains postprocessed versions of the shaders in the top-level `shaders/` directory, for convenience. Don't modify the shaders here; instead -modify the corresponding shaders in `shaders/` and rerun `make` in that -directory. - -You will need `glslangValidator` and `spirv-cross` installed to execute the -Makefile. On macOS, you can get these with `brew install glslang spirv-cross`. +modify the corresponding shaders in `shaders/` and rebuild them according to +`shaders/README.md`. \ No newline at end of file diff --git a/shaders/Makefile b/shaders/Makefile index 15d8a329..2154c2c4 100644 --- a/shaders/Makefile +++ b/shaders/Makefile @@ -58,6 +58,8 @@ OUT=\ GLSL_3_VERSION=330 GLSL_4_VERSION=430 + +GLSLANG?=glslangValidator GLSLANGFLAGS=--auto-map-locations -I. GLSLANGFLAGS_METAL=$(GLSLANGFLAGS) -DPF_ORIGIN_UPPER_LEFT=1 @@ -81,13 +83,13 @@ clean: rm -f $(OUT) build/metal/%.spv: %.glsl $(INCLUDES) - mkdir -p $(dir $@) && glslangValidator $(GLSLANGFLAGS_METAL) -G$(GLSL_VERSION) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -o $@ $< + mkdir -p $(dir $@) && $(GLSLANG) $(GLSLANGFLAGS_METAL) -G$(GLSL_VERSION) -S $(GLSL_SHADER_TYPE$(suffix $(basename $(notdir $<)))) -o $@ $< $(TARGET_DIR)/gl3/%.glsl: %.glsl $(INCLUDES) - 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 ) + 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 ) $(TARGET_DIR)/gl4/%.glsl: %.glsl $(INCLUDES) - 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 ) + 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 ) $(TARGET_DIR)/metal/%.metal: build/metal/%.spv mkdir -p $(dir $@) && echo $(HEADER) > $@ && ( $(SPIRVCROSS) $(SPIRVCROSSFLAGS) $< >> $@ ) || ( rm $@ && exit 1 ) diff --git a/shaders/README.md b/shaders/README.md new file mode 100644 index 00000000..31f847ae --- /dev/null +++ b/shaders/README.md @@ -0,0 +1,26 @@ +# Building the shaders + +You will need `glslangValidator` and `spirv-cross` installed to execute the +Makefile from this directory. You can speed up the build by parallelizing the +build: `make -j`. + +## macOS + +You can use [Homebrew](https://brew.sh/) to install the dependencies: + +```sh +brew install glslang spirv-cross +``` + +## Windows + +`glslangValidator` and `spirv-cross` are available by installing the +[Vulkan SDK](https://vulkan.lunarg.com/sdk/home). You'll also need some commands +like `make`, `rm`, etc. These are available on the +[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) +shell. You'll need to set these environment variables for `make` to succeed: + +```sh +export GLSLANG=glslangValidator.exe +export SPIRVCROSS=spirv-cross.exe +``` From 157332c66795cd0c255e751eab5eeb3082f7955a Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Sat, 12 Sep 2020 13:54:29 -0700 Subject: [PATCH 2/4] Add note about line endings --- shaders/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shaders/README.md b/shaders/README.md index 31f847ae..7c23a1d2 100644 --- a/shaders/README.md +++ b/shaders/README.md @@ -24,3 +24,8 @@ shell. You'll need to set these environment variables for `make` to succeed: export GLSLANG=glslangValidator.exe export SPIRVCROSS=spirv-cross.exe ``` + +Note: the Windows versions of `glslangValidator` and `spirv-cross` may change +the line endings of the generated output. Please take care to ensure that +unintended line ending changes aren't accidentally commited, for instance by +[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). From 493a2b92437e0fdddbe881e1c038aa6aba4941a2 Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Sat, 12 Sep 2020 13:59:16 -0700 Subject: [PATCH 3/4] Add note on when this document is relevant --- shaders/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shaders/README.md b/shaders/README.md index 7c23a1d2..d8c3b0e2 100644 --- a/shaders/README.md +++ b/shaders/README.md @@ -1,5 +1,9 @@ # Building the shaders +This document describes how to regenerate the shaders used by Pathfinder. Unless +you have modified files in this directory, regenerating the shaders is not +necessary to do most development on or use Pathfinder. + You will need `glslangValidator` and `spirv-cross` installed to execute the Makefile from this directory. You can speed up the build by parallelizing the build: `make -j`. From 9d69e67a0e799b295ba26e1a764a8f82a5a77404 Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Sat, 12 Sep 2020 14:01:57 -0700 Subject: [PATCH 4/4] Wording --- shaders/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shaders/README.md b/shaders/README.md index d8c3b0e2..9f9680a6 100644 --- a/shaders/README.md +++ b/shaders/README.md @@ -2,7 +2,7 @@ This document describes how to regenerate the shaders used by Pathfinder. Unless you have modified files in this directory, regenerating the shaders is not -necessary to do most development on or use Pathfinder. +necessary to use Pathfinder or do most kinds of development on it. You will need `glslangValidator` and `spirv-cross` installed to execute the Makefile from this directory. You can speed up the build by parallelizing the