`examples/<name>/` was a tested surface in name only. The source-quality job had no examples check at all, and scripts/smoke_examples.sh accepted any process that had not printed one of its error markers: a project that died during startup, exited after a single frame, or crashed without a marker was reported as PASS. Nothing stopped a malformed or unregistered example from reaching dev, which is how 14 examples arrived without READMEs and 20 were never registered in the overview table. Source side - scripts/check_examples.py classifies every directory under examples/ as either runnable (main.nut plus a config.nut that assigns the engine `config` table) or as a reviewed non-runnable sample listed in NON_RUNNABLE_EXAMPLES with a reason. Both kinds must own a README.md and appear in examples/README.md. Stale exemptions and overview links to missing directories fail as well. - `make check/examples` and a new source-quality CI step run the gate. - scripts/tests/test_check_examples.py covers it and pins each failure mode against fixtures. Runtime side - scripts/smoke_examples.sh now enforces liveness, not just marker absence: every runnable example must still be running after MIN_RUN_SECONDS (default 2s; CI passes 2s), and a process that dies inside that window fails whatever its exit code. A clean self-exit after the window passes with an explicit note instead of being silently accepted as a pass. - The Linux CI step sets MIN_RUN_SECONDS=2 and keeps RUN_SECONDS=6, so the job's wall clock is unchanged (13.7 min of its 20 min budget on dev). Windows / GBK - scripts/utf8_stdio.py re-encodes stdout/stderr as UTF-8 and every scripts/*.py program calls it as the first statement of its __main__ block. On a Chinese Windows a redirected stream falls back to the ANSI code page (cp936), and printing a character that code page cannot encode (arrows, superscripts, bullet separators, emoji - all common in this repository) raised UnicodeEncodeError and turned a checker into a traceback. - The mirror image is input: read_text() without encoding= decoded UTF-8 repository text as cp936 and raised UnicodeDecodeError. - scripts/tests/test_utf8_stdio.py enforces both conventions for every script and test module; text file I/O and child-process decoding now pass encoding="utf-8" explicitly. - Unit-test invocations run with `python3 -X utf8` so the runner's own output never follows the host code page. Violations the new gates found on top of dev, fixed here: 14 examples shipped without a README (fluid3d, mesh-impact-lab, mesh-modifier-lab, spline-tube-lab on the earlier dev tip, plus pcg-depth-of-field, pcg-detail-overwrite, pcg-layer-culling, pcg-location-system, pcg-runtime-orchestration, pcg-scene-player-culling, pcg-snow-wind, pcg-thunder-strike, pcg-ui-scaler and pcg-underwater added by #397), 20 were missing from the overview table (those 14 plus archspace-editor, geometry-stroke-lab, interior-mapping, layered-animation, triplanar-decal, terrain-stamping), and scripts/export_meshret_onnx.py had no UTF-8 stdio guard. Verified locally: `python -m ruff check scripts` (All checks passed); scripts/check_test_manifest.py; scripts/check_quality_metadata.py; scripts/check_architecture_contracts.py --base HEAD; scripts/check_nodiscard.py; `make -n check/examples`; scripts/check_examples.py (125 examples: 118 runnable, 7 reviewed non-runnable); and `python -X utf8 -m unittest discover -s scripts/tests -p "test_*.py"` (155 tests, OK). The runtime half of the contract needs a Linux headless build, so it is verified by the CI examples smoke step rather than locally.
93 lines
3.3 KiB
Python
93 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Compile virtualgeometry GLSL compute/fragment shaders into .spv and .inc.
|
|
|
|
Run from the repo root (or pass a directory):
|
|
python3 scripts/compile_virtualgeometry_shaders.py
|
|
|
|
Emits, next to each .glsl/.comp/.frag/.vert source:
|
|
- <stem>.spv (raw SPIR-V binary, loaded at runtime)
|
|
- <stem>_spv.inc (embedded uint32 array for the backend)
|
|
The .inc files are #included by virtualgeometry/vulkan/VulkanVirtualGeometry.cpp.
|
|
|
|
Only VG_COMMON_GLSL is #included by the passes; the include dir is added via -I.
|
|
"""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import struct
|
|
import utf8_stdio
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
SHADERS = os.path.join(ROOT, "src", "modules", "virtualgeometry", "shaders")
|
|
|
|
STAGES = {".comp": "compute", ".vert": "vertex", ".frag": "fragment"}
|
|
|
|
|
|
def find_compiler():
|
|
for name in ("glslc", "glslangValidator"):
|
|
path = subprocess.run(["which", name], capture_output=True, text=True).stdout.strip()
|
|
if path:
|
|
return name, path
|
|
return None, None
|
|
|
|
|
|
def compile_one(compiler, src, out_spv, stage):
|
|
inc = os.path.join(SHADERS)
|
|
if compiler == "glslc":
|
|
cmd = ["glslc", "-I", inc, "-fshader-stage=" + stage, "-o", out_spv, src]
|
|
else:
|
|
cmd = ["glslangValidator", "-I", inc, "-S", stage, "-o", out_spv, src]
|
|
res = subprocess.run(cmd, capture_output=True, text=True)
|
|
if res.returncode != 0:
|
|
print("FAIL", src)
|
|
print(res.stdout)
|
|
print(res.stderr)
|
|
return False
|
|
return True
|
|
|
|
|
|
def emit_inc(spv, inc, symbol):
|
|
with open(spv, "rb") as f:
|
|
data = f.read()
|
|
assert len(data) % 4 == 0, "SPIR-V size must be word-aligned"
|
|
words = struct.unpack("<%dI" % (len(data) // 4), data)
|
|
lines = ["// Generated by compile_virtualgeometry_shaders.py. Do not edit."]
|
|
lines.append("#pragma once")
|
|
lines.append("static const uint32_t %s[] = {" % symbol)
|
|
for i in range(0, len(words), 6):
|
|
chunk = words[i:i + 6]
|
|
lines.append(" " + ", ".join("0x%08x" % w for w in chunk) + ",")
|
|
lines.append("};")
|
|
lines.append("static const size_t %s_count = sizeof(%s) / sizeof(%s[0]);" % (symbol, symbol, symbol))
|
|
with open(inc, "w", encoding="utf-8") as f:
|
|
f.write("\n".join(lines) + "\n")
|
|
|
|
|
|
def main():
|
|
compiler, _ = find_compiler()
|
|
if not compiler:
|
|
print("No GLSL compiler (glslc / glslangValidator) found on PATH.")
|
|
return 1
|
|
|
|
base_dir = sys.argv[1] if len(sys.argv) > 1 else SHADERS
|
|
for root, _, files in os.walk(base_dir):
|
|
for name in sorted(files):
|
|
ext = os.path.splitext(name)[1]
|
|
if ext not in STAGES or name == "vg_common.glsl":
|
|
continue
|
|
stem = os.path.splitext(name)[0]
|
|
src = os.path.join(root, name)
|
|
# Suffix with the stage so vg_resolve.vert and vg_resolve.frag don't collide.
|
|
spv = os.path.join(root, "%s_%s.spv" % (stem, STAGES[ext]))
|
|
inc = os.path.join(root, "%s_%s_spv.inc" % (stem, STAGES[ext]))
|
|
if not compile_one(compiler, src, spv, STAGES[ext]):
|
|
return 1
|
|
emit_inc(spv, inc, "%s_%s_spv" % (stem, STAGES[ext]))
|
|
print("compiled", os.path.relpath(spv, ROOT))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
utf8_stdio.enable_utf8_stdio()
|
|
sys.exit(main())
|