compile_shaders.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. set -x
  3. set -e
  4. cd `dirname "$0"`
  5. shadernames=(FullscreenVert BlitFrom2D BlitFrom2DArray BlitFrom3D BlitFromCube BlitFromCubeArray)
  6. generate_shaders()
  7. {
  8. fileplatform=$1
  9. compileplatform=$2
  10. sdkplatform=$3
  11. minversion=$4
  12. for shadername in "${shadernames[@]}"; do
  13. xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal2.0 -m$sdkplatform-version-min=$minversion -Wall -O3 -D COMPILE_$shadername -o ./$shadername.air ./Metal_Blit.metal || exit $?
  14. xcrun -sdk $sdkplatform metallib -o $shadername.metallib $shadername.air || exit $?
  15. xxd -i $shadername.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./${shadername}_$fileplatform.h
  16. rm -f $shadername.air $shadername.metallib
  17. done
  18. }
  19. generate_shaders macos macos macosx 10.11
  20. generate_shaders ios ios iphoneos 11.0
  21. generate_shaders iphonesimulator ios iphonesimulator 11.0
  22. generate_shaders tvos ios appletvos 11.0
  23. generate_shaders tvsimulator ios appletvsimulator 11.0
  24. # Bundle together one mega-header
  25. catShaders()
  26. {
  27. target=$1
  28. for shadername in "${shadernames[@]}"; do
  29. cat ${shadername}_$target.h >> Metal_Blit.h
  30. done
  31. }
  32. rm -f Metal_Blit.h
  33. echo "#if defined(SDL_PLATFORM_IOS)" >> Metal_Blit.h
  34. echo "#if TARGET_OS_SIMULATOR" >> Metal_Blit.h
  35. catShaders iphonesimulator
  36. echo "#else" >> Metal_Blit.h
  37. catShaders ios
  38. echo "#endif" >> Metal_Blit.h
  39. echo "#elif defined(SDL_PLATFORM_TVOS)" >> Metal_Blit.h
  40. echo "#if TARGET_OS_SIMULATOR" >> Metal_Blit.h
  41. catShaders tvsimulator
  42. echo "#else" >> Metal_Blit.h
  43. catShaders tvos
  44. echo "#endif" >> Metal_Blit.h
  45. echo "#else" >> Metal_Blit.h
  46. catShaders macos
  47. echo "#endif" >> Metal_Blit.h
  48. # Clean up
  49. cleanupShaders()
  50. {
  51. target=$1
  52. for shadername in "${shadernames[@]}"; do
  53. rm -f ${shadername}_$target.h
  54. done
  55. }
  56. cleanupShaders iphonesimulator
  57. cleanupShaders ios
  58. cleanupShaders tvsimulator
  59. cleanupShaders tvos
  60. cleanupShaders macos