OverviewFilesCommitsIssuesDocsReleasesPeers

dc-terrain / tests / gate_hblk_compile.sh

70 lines · bash ref:
#!/bin/sh
# Does the heightfield density shader COMPILE, exactly as assembled?
#
# _build_custom_shader() is HEADER + body + MAIN (dc_shader_source.h:721). This
# reproduces that from the SAME constants -- dumped by a C++ probe rather than
# transcribed -- around the body the generator actually emitted, and runs glslc.
#
# The failure it exists for is specific: a body that does not compile leaves the
# world empty while every log line looks healthy. The CONTROL is the same
# assembly with a deliberately broken body, which must be REJECTED; without it
# a glslc that silently accepted anything would read as a pass.
#
#   tests/gate_hblk_compile.sh /tmp/hblk_body.glsl
set -e
BODY="${1:-/tmp/hblk_body.glsl}"
DIR=$(cd "$(dirname "$0")/.." && pwd)

[ -f "$BODY" ] || { echo "missing $BODY -- run the godot emission gate first"; exit 2; }

g++ -O0 -std=c++17 -I "$DIR/libdc/include" -o /tmp/dump_density_parts \
    "$DIR/tests/dump_density_parts.cpp"
/tmp/dump_density_parts /tmp/density_header.glsl /tmp/density_main.glsl

cat /tmp/density_header.glsl > /tmp/hblk_full.comp
printf '\n' >> /tmp/hblk_full.comp
cat "$BODY" >> /tmp/hblk_full.comp
printf '\n' >> /tmp/hblk_full.comp
cat /tmp/density_main.glsl >> /tmp/hblk_full.comp

echo "assembled $(wc -c < /tmp/hblk_full.comp) bytes"
if glslc -fshader-stage=compute /tmp/hblk_full.comp -o /tmp/hblk_full.spv 2>/tmp/hblk_err.txt; then
    echo "  COMPILE   PASS   ($(wc -c < /tmp/hblk_full.spv) bytes of SPIR-V)"
else
    echo "  COMPILE   FAIL"
    head -20 /tmp/hblk_err.txt
    exit 1
fi

# CONTROL: break the body and require rejection.
#
# THE ANCHOR IS THE ENTRY POINT, because that is the one line every emission
# mode contains. The previous anchor was `float y_range = M_CEIL_Y - M_FLOOR_Y;`,
# which appears ONLY in the lookdev wrapper's text -- so on an engine-wrapper
# dump this took the SKIPPED branch and exited 2, and the gate was blind on
# exactly the path most changes touch. It had a comment saying anchoring on a
# mode-specific line was the mistake, and then did it.
#
# Renaming the function rather than dropping a semicolon also makes the control
# stronger: it proves the assembled MAIN actually calls the body. A body that
# compiles but is never called would pass a syntax-error control.
sed '0,/float evaluate_density(/s//float evaluate_density_NOT_CALLED(/' \
    "$BODY" > /tmp/hblk_broken.glsl
if ! cmp -s "$BODY" /tmp/hblk_broken.glsl; then
    cat /tmp/density_header.glsl > /tmp/hblk_broken.comp
    printf '\n' >> /tmp/hblk_broken.comp
    cat /tmp/hblk_broken.glsl >> /tmp/hblk_broken.comp
    printf '\n' >> /tmp/hblk_broken.comp
    cat /tmp/density_main.glsl >> /tmp/hblk_broken.comp
    if glslc -fshader-stage=compute /tmp/hblk_broken.comp -o /dev/null 2>/dev/null; then
        echo "  CONTROL   broken body ACCEPTED -- this gate is blind"
        exit 2
    fi
    echo "  CONTROL   broken body REJECTED (gate can fail)"
else
    echo "  CONTROL   SKIPPED -- substitution not present to break"
    exit 2
fi
echo ""
echo "VERDICT: the assembled heightfield density shader compiles."