build-shaders.sh 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. # On Windows, run this via Git Bash.
  7. # To add the Windows SDK (FXC/DXC) to your path, run the command:
  8. # `export PATH=$PATH:/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/x.x.x.x/x64/`
  9. export MSYS_NO_PATHCONV=1
  10. # SPIR-V
  11. glslangValidator cube.glsl -V -S vert -o cube.vert.spv --quiet -DVERTEX
  12. glslangValidator cube.glsl -V -S frag -o cube.frag.spv --quiet
  13. xxd -i cube.vert.spv | perl -w -p -e 's/\Aunsigned /const unsigned /;' > cube.vert.h
  14. xxd -i cube.frag.spv | perl -w -p -e 's/\Aunsigned /const unsigned /;' > cube.frag.h
  15. cat cube.vert.h cube.frag.h > testgpu_spirv.h
  16. rm -f cube.vert.h cube.frag.h cube.vert.spv cube.frag.spv
  17. # Platform-specific compilation
  18. if [[ "$OSTYPE" == "darwin"* ]]; then
  19. # FIXME: Needs to be updated!
  20. # Xcode
  21. generate_shaders()
  22. {
  23. fileplatform=$1
  24. compileplatform=$2
  25. sdkplatform=$3
  26. minversion=$4
  27. 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 $?
  28. xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal1.1 -m$sdkplatform-version-min=$minversion -Wall -O3 -o ./cube.frag.air ./cube.metal || exit $?
  29. xcrun -sdk $sdkplatform metallib -o cube.vert.metallib cube.vert.air || exit $?
  30. xcrun -sdk $sdkplatform metallib -o cube.frag.metallib cube.frag.air || exit $?
  31. xxd -i cube.vert.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./cube.vert_$fileplatform.h
  32. xxd -i cube.frag.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./cube.frag_$fileplatform.h
  33. rm -f cube.vert.air cube.vert.metallib
  34. rm -f cube.frag.air cube.frag.metallib
  35. }
  36. generate_shaders macos macos macosx 10.11
  37. generate_shaders ios ios iphoneos 8.0
  38. generate_shaders iphonesimulator ios iphonesimulator 8.0
  39. generate_shaders tvos ios appletvos 9.0
  40. generate_shaders tvsimulator ios appletvsimulator 9.0
  41. # Bundle together one mega-header
  42. rm -f testgpu_metallib.h
  43. echo "#if defined(SDL_PLATFORM_IOS)" >> testgpu_metallib.h
  44. echo "#if TARGET_OS_SIMULATOR" >> testgpu_metallib.h
  45. cat cube.vert_iphonesimulator.h >> testgpu_metallib.h
  46. cat cube.frag_iphonesimulator.h >> testgpu_metallib.h
  47. echo "#else" >> testgpu_metallib.h
  48. cat cube.vert_ios.h >> testgpu_metallib.h
  49. cat cube.frag_ios.h >> testgpu_metallib.h
  50. echo "#endif" >> testgpu_metallib.h
  51. echo "#elif defined(SDL_PLATFORM_TVOS)" >> testgpu_metallib.h
  52. echo "#if TARGET_OS_SIMULATOR" >> testgpu_metallib.h
  53. cat cube.vert_tvsimulator.h >> testgpu_metallib.h
  54. cat cube.frag_tvsimulator.h >> testgpu_metallib.h
  55. echo "#else" >> testgpu_metallib.h
  56. cat cube.vert_tvos.h >> testgpu_metallib.h
  57. cat cube.frag_tvos.h >> testgpu_metallib.h
  58. echo "#endif" >> testgpu_metallib.h
  59. echo "#else" >> testgpu_metallib.h
  60. cat cube.vert_macos.h >> testgpu_metallib.h
  61. cat cube.frag_macos.h >> testgpu_metallib.h
  62. echo "#endif" >> testgpu_metallib.h
  63. # Clean up
  64. rm -f cube.vert_macos.h cube.frag_macos.h
  65. rm -f cube.vert_iphonesimulator.h cube.frag_iphonesimulator.h
  66. rm -f cube.vert_tvsimulator.h cube.frag_tvsimulator.h
  67. rm -f cube.vert_ios.h cube.frag_ios.h
  68. rm -f cube.vert_tvos.h cube.frag_tvos.h
  69. elif [[ "$OSTYPE" == "cygwin"* ]] || [[ "$OSTYPE" == "msys"* ]]; then
  70. # DXC
  71. dxc cube.hlsl /E VSMain /T vs_6_0 /Fh cube.vert.h
  72. dxc cube.hlsl /E PSMain /T ps_6_0 /Fh cube.frag.h
  73. cat cube.vert.h | perl -w -p -e 's/BYTE/unsigned char/;s/g_VSMain/D3D12_CubeVert/;' > cube.vert.temp.h
  74. cat cube.frag.h | perl -w -p -e 's/BYTE/unsigned char/;s/g_PSMain/D3D12_CubeFrag/;' > cube.frag.temp.h
  75. cat cube.vert.temp.h cube.frag.temp.h > testgpu_dxil.h
  76. rm -f cube.vert.h cube.frag.h cube.vert.temp.h cube.frag.temp.h
  77. fi