Skip to content

Commit

Permalink
Generalized Compile.command script for built-in Metal shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBanana committed Aug 24, 2023
1 parent 8370e9a commit 07833d5
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions sources/Renderer/Metal/Shader/Builtin/Compile.command
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
LLGL_ROOT_DIR="$(dirname "$0")/../../../../../"
HEX_CONVERSION_SCRIPT="$LLGL_ROOT_DIR/scripts/ReadFileAsHexString.py"

cd $(dirname "$0")

# Get shader sources
SOURCES=(FillBufferByte4.metal)

if [ "$#" -ne 0 ]; then
SOURCES=("$@")
fi

for SRC in ${SOURCES[@]}; do
if [ ! -f "$SRC" ]; then
echo fatal: cannot find source file: $SRC
exit 1
fi
done

# Check if xcrun tool is available
which xcrun &> /dev/null
if [ $? -ne 0 ]; then
Expand All @@ -13,10 +29,13 @@ fi
# Compile shaders for macOS
METAL_SDKS=(macosx iphoneos iphonesimulator)

for SDK in ${METAL_SDKS[@]}; do
echo Compile Metal shaders for $SDK
xcrun -sdk $SDK metal -c FillBufferByte4.metal -o FillBufferByte4.${SDK}.air
xcrun -sdk $SDK metallib FillBufferByte4.${SDK}.air -o FillBufferByte4.${SDK}.metallib
for SRC in ${SOURCES[@]}; do
for SDK in ${METAL_SDKS[@]}; do
FILE="${SRC%.*}.${SDK}"
echo compile Metal shader $FILE
xcrun -sdk $SDK metal -c ${SRC} -o ${FILE}.air
xcrun -sdk $SDK metallib ${FILE}.air -o ${FILE}.metallib
done
done

# Check if Python 3 is avilable
Expand All @@ -27,9 +46,12 @@ if [ $? -ne 0 ]; then
fi

# Convert shader byte code into C header files
for SDK in ${METAL_SDKS[@]}; do
python3 "$HEX_CONVERSION_SCRIPT" FillBufferByte4.${SDK}.metallib -offsets cxx > FillBufferByte4.${SDK}.metallib.bin.inl
python3 "$HEX_CONVERSION_SCRIPT" FillBufferByte4.${SDK}.metallib -len -paren > FillBufferByte4.${SDK}.metallib.len.inl
for SRC in ${SOURCES[@]}; do
for SDK in ${METAL_SDKS[@]}; do
FILE="${SRC%.*}.${SDK}"
python3 "$HEX_CONVERSION_SCRIPT" ${FILE}.metallib -offsets cxx > ${FILE}.metallib.bin.inl
python3 "$HEX_CONVERSION_SCRIPT" ${FILE}.metallib -len -paren > ${FILE}.metallib.len.inl
done
done

echo Done
echo DONE

0 comments on commit 07833d5

Please sign in to comment.