OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / tools / shader_gate.sh

34 lines · bash ref:
#!/usr/bin/env bash
# Compile-gate a Godot shader. FAILS on compile errors.
#
# shader_probe.gd cannot detect a compile failure -- Godot exposes no error
# state on the Shader resource, so the script happily reported "COMPILED" for a
# shader the renderer had just rejected. The authority is the renderer's own
# stderr. This greps it and sets the exit code, which is what makes this a gate
# rather than a print statement.
set -uo pipefail
SHADER="${1:?usage: shader_gate.sh res://path/to.gdshader [res://probe.gd]}"
# Some shaders need setup a generic probe cannot do -- the ocean shader's
# `global uniform`s must be registered before it will compile at all. Such a
# shader brings its own probe; the VERDICT still comes from the renderer's
# stderr either way, which is the whole point of this script.
PROBE="${2:-res://scenes/test/shader_probe.gd}"
PROBE_ARGS=(-- --shader "$SHADER")
[ "$PROBE" = "res://scenes/test/shader_probe.gd" ] || PROBE_ARGS=()
. "$(dirname "$0")/../scripts/engine.sh"   # sets GODOT
cd "$(dirname "$0")/.." || exit 2
LOG=$(mktemp)
DISPLAY="${DISPLAY:-:0}" timeout 300 "$GODOT" --path . --rendering-driver vulkan \
    --script "$PROBE" "${PROBE_ARGS[@]}" >"$LOG" 2>&1
if grep -qE "SHADER ERROR|Shader compilation failed" "$LOG"; then
    echo "FAIL — $SHADER did not compile:"
    grep -E "SHADER ERROR|^E +[0-9]+->|Shader compilation failed" "$LOG" | head -20
    rm -f "$LOG"; exit 1
fi
if ! grep -qE "survived 30 (lit )?frames" "$LOG"; then
    echo "FAIL — probe did not reach 30 frames (crash or timeout):"; tail -20 "$LOG"
    rm -f "$LOG"; exit 1
fi
echo "PASS — $SHADER compiled"
rm -f "$LOG"