Skip to content

Commit

Permalink
render: Integrate fix-shaders.sh into build-shaders.sh
Browse files Browse the repository at this point in the history
By writing the fxc and dxc output to a temporary file and then
converting that temporary file to the desired filename, we avoid
the incompatible semantics of sed -i on GNU systems (sed -i does not
create a backup filename, and does not take an argument unless it is
"bundled") and macOS (sed -i requires an argument, possibly empty).

Resolves: libsdl-org#10878
Signed-off-by: Simon McVittie <[email protected]>
  • Loading branch information
smcv committed Sep 17, 2024
1 parent 7edd43c commit 2b1d1cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/render/gpu/shaders/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.hlsl
*.metal
*.spv
*.tmp.h
25 changes: 19 additions & 6 deletions src/render/gpu/shaders/build-shaders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ rm -f "$spirv_bundle"
[ "$USE_SPIRV_CROSS" != 0 ] && [ "$USE_DXC" != 0 ] && rm -f "$dxil60_bundle"

make-header() {
xxd -i "$1" | sed -e 's/^unsigned /const unsigned /g' > "$1.h"
xxd -i "$1" | sed \
-e 's/^unsigned /const unsigned /g' \
-e 's,^const,static const,' \
> "$1.h"
}

compile-hlsl-dxbc() {
Expand All @@ -36,8 +39,14 @@ compile-hlsl-dxbc() {
local output_basename="$3"
local var_name="$(echo "$output_basename" | sed -e 's/\./_/g')"

fxc "$src" /E main /T $2 /Fh "$output_basename.h" || exit $?
sed -i "s/g_main/$var_name/;s/\r//g" "$output_basename.h"
fxc "$src" /E main /T $2 /Fh "$output_basename.tmp.h" || exit $?
sed \
-e "s/g_main/$var_name/;s/\r//g" \
-e 's,^const,static const,' \
-e 's,const unsigned,const signed,' \
< "$output_basename.tmp.h" \
> "$output_basename.h"
rm -f "$output_basename.tmp.h"
}

compile-hlsl-dxil() {
Expand All @@ -46,8 +55,13 @@ compile-hlsl-dxil() {
local output_basename="$3"
local var_name="$(echo "$output_basename" | sed -e 's/\./_/g')"

dxc "$src" -E main -T $2 -Fh "$output_basename.h" -O3 || exit $?
sed -i "s/g_main/$var_name/;s/\r//g" "$output_basename.h"
dxc "$src" -E main -T $2 -Fh "$output_basename.tmp.h" -O3 || exit $?
sed \
-e "s/g_main/$var_name/;s/\r//g" \
-e 's,^const,static const,' \
< "$output_basename.tmp.h" \
> "$output_basename.h"
rm -f "$output_basename.tmp.h"
}

for i in *.vert *.frag; do
Expand Down Expand Up @@ -90,4 +104,3 @@ for i in *.vert *.frag; do
make-header "$metal"
echo "#include \"$metal.h\"" >> "$metal_bundle"
done
./fix-shaders.sh
6 changes: 0 additions & 6 deletions src/render/gpu/shaders/fix-shaders.sh

This file was deleted.

0 comments on commit 2b1d1cd

Please sign in to comment.