diff options
Diffstat (limited to 'contrib/SDL-3.2.8/test/testgpu/build-shaders.sh')
| -rwxr-xr-x | contrib/SDL-3.2.8/test/testgpu/build-shaders.sh | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/test/testgpu/build-shaders.sh b/contrib/SDL-3.2.8/test/testgpu/build-shaders.sh new file mode 100755 index 0000000..d76f9d6 --- /dev/null +++ b/contrib/SDL-3.2.8/test/testgpu/build-shaders.sh | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | # Rebuilds the shaders needed for the GPU cube test. | ||
| 2 | # For SPIR-V: requires glslangValidator and spirv-cross, which can be obtained from the LunarG Vulkan SDK. | ||
| 3 | # For DXBC compilation: requires FXC, which is part of the Windows SDK. | ||
| 4 | # For DXIL compilation, requires DXC, which can be obtained via the Windows SDK or via here: https://github.com/microsoft/DirectXShaderCompiler/releases | ||
| 5 | # For Metal compilation: requires Xcode | ||
| 6 | |||
| 7 | # On Windows, run this via Git Bash. | ||
| 8 | # To add the Windows SDK (FXC/DXC) to your path, run the command: | ||
| 9 | # `export PATH=$PATH:/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/x.x.x.x/x64/` | ||
| 10 | |||
| 11 | export MSYS_NO_PATHCONV=1 | ||
| 12 | |||
| 13 | # SPIR-V | ||
| 14 | glslangValidator cube.glsl -V -S vert -o cube.vert.spv --quiet -DVERTEX | ||
| 15 | glslangValidator cube.glsl -V -S frag -o cube.frag.spv --quiet | ||
| 16 | xxd -i cube.vert.spv | perl -w -p -e 's/\Aunsigned /const unsigned /;' > cube.vert.h | ||
| 17 | xxd -i cube.frag.spv | perl -w -p -e 's/\Aunsigned /const unsigned /;' > cube.frag.h | ||
| 18 | cat cube.vert.h cube.frag.h > testgpu_spirv.h | ||
| 19 | rm -f cube.vert.h cube.frag.h cube.vert.spv cube.frag.spv | ||
| 20 | |||
| 21 | # Platform-specific compilation | ||
| 22 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
| 23 | |||
| 24 | # FIXME: Needs to be updated! | ||
| 25 | |||
| 26 | # Xcode | ||
| 27 | generate_shaders() | ||
| 28 | { | ||
| 29 | fileplatform=$1 | ||
| 30 | compileplatform=$2 | ||
| 31 | sdkplatform=$3 | ||
| 32 | minversion=$4 | ||
| 33 | |||
| 34 | xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal1.1 -m$sdkplatform-version-min=$minversion -Wall -O3 -DVERTEX=1 -o ./cube.vert.air ./cube.metal || exit $? | ||
| 35 | xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal1.1 -m$sdkplatform-version-min=$minversion -Wall -O3 -o ./cube.frag.air ./cube.metal || exit $? | ||
| 36 | |||
| 37 | xcrun -sdk $sdkplatform metallib -o cube.vert.metallib cube.vert.air || exit $? | ||
| 38 | xcrun -sdk $sdkplatform metallib -o cube.frag.metallib cube.frag.air || exit $? | ||
| 39 | |||
| 40 | xxd -i cube.vert.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./cube.vert_$fileplatform.h | ||
| 41 | xxd -i cube.frag.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./cube.frag_$fileplatform.h | ||
| 42 | |||
| 43 | rm -f cube.vert.air cube.vert.metallib | ||
| 44 | rm -f cube.frag.air cube.frag.metallib | ||
| 45 | } | ||
| 46 | |||
| 47 | generate_shaders macos macos macosx 10.11 | ||
| 48 | generate_shaders ios ios iphoneos 8.0 | ||
| 49 | generate_shaders iphonesimulator ios iphonesimulator 8.0 | ||
| 50 | generate_shaders tvos ios appletvos 9.0 | ||
| 51 | generate_shaders tvsimulator ios appletvsimulator 9.0 | ||
| 52 | |||
| 53 | # Bundle together one mega-header | ||
| 54 | rm -f testgpu_metallib.h | ||
| 55 | echo "#if defined(SDL_PLATFORM_IOS)" >> testgpu_metallib.h | ||
| 56 | echo "#if TARGET_OS_SIMULATOR" >> testgpu_metallib.h | ||
| 57 | cat cube.vert_iphonesimulator.h >> testgpu_metallib.h | ||
| 58 | cat cube.frag_iphonesimulator.h >> testgpu_metallib.h | ||
| 59 | echo "#else" >> testgpu_metallib.h | ||
| 60 | cat cube.vert_ios.h >> testgpu_metallib.h | ||
| 61 | cat cube.frag_ios.h >> testgpu_metallib.h | ||
| 62 | echo "#endif" >> testgpu_metallib.h | ||
| 63 | echo "#elif defined(SDL_PLATFORM_TVOS)" >> testgpu_metallib.h | ||
| 64 | echo "#if TARGET_OS_SIMULATOR" >> testgpu_metallib.h | ||
| 65 | cat cube.vert_tvsimulator.h >> testgpu_metallib.h | ||
| 66 | cat cube.frag_tvsimulator.h >> testgpu_metallib.h | ||
| 67 | echo "#else" >> testgpu_metallib.h | ||
| 68 | cat cube.vert_tvos.h >> testgpu_metallib.h | ||
| 69 | cat cube.frag_tvos.h >> testgpu_metallib.h | ||
| 70 | echo "#endif" >> testgpu_metallib.h | ||
| 71 | echo "#else" >> testgpu_metallib.h | ||
| 72 | cat cube.vert_macos.h >> testgpu_metallib.h | ||
| 73 | cat cube.frag_macos.h >> testgpu_metallib.h | ||
| 74 | echo "#endif" >> testgpu_metallib.h | ||
| 75 | |||
| 76 | # Clean up | ||
| 77 | rm -f cube.vert_macos.h cube.frag_macos.h | ||
| 78 | rm -f cube.vert_iphonesimulator.h cube.frag_iphonesimulator.h | ||
| 79 | rm -f cube.vert_tvsimulator.h cube.frag_tvsimulator.h | ||
| 80 | rm -f cube.vert_ios.h cube.frag_ios.h | ||
| 81 | rm -f cube.vert_tvos.h cube.frag_tvos.h | ||
| 82 | |||
| 83 | elif [[ "$OSTYPE" == "cygwin"* ]] || [[ "$OSTYPE" == "msys"* ]]; then | ||
| 84 | |||
| 85 | # DXC | ||
| 86 | dxc cube.hlsl /E VSMain /T vs_6_0 /Fh cube.vert.h | ||
| 87 | dxc cube.hlsl /E PSMain /T ps_6_0 /Fh cube.frag.h | ||
| 88 | |||
| 89 | cat cube.vert.h | perl -w -p -e 's/BYTE/unsigned char/;s/g_VSMain/D3D12_CubeVert/;' > cube.vert.temp.h | ||
| 90 | cat cube.frag.h | perl -w -p -e 's/BYTE/unsigned char/;s/g_PSMain/D3D12_CubeFrag/;' > cube.frag.temp.h | ||
| 91 | cat cube.vert.temp.h cube.frag.temp.h > testgpu_dxil.h | ||
| 92 | rm -f cube.vert.h cube.frag.h cube.vert.temp.h cube.frag.temp.h | ||
| 93 | |||
| 94 | fi | ||
