mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
This repository was an export of a private one; from this commit on it is where raea is developed. Contributions: CONTRIBUTING.md.
142 lines
9.7 KiB
Bash
Executable File
142 lines
9.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Bevy's own examples against their TSX ports (docs/control.feature FC0a): each example runs as Bevy wrote it
|
|
# (bench/bevy-parity's host, raea's Bevy, a fixed 60 fps clock) and as sdk/raea/bench/bevy-parity/<path>.tsx through
|
|
# raea, the same parity probe (systems/parity) in both, and they're compared three ways at each listed frame:
|
|
# pixels SSIM of the two frames (P26's ffmpeg ssim), passes at 0.98; and the worst 32 px tile's mean grey difference
|
|
# (0-255), passes at 24: whole-frame SSIM forgives a small subject (a sprite on the wrong cell scored 0.989)
|
|
# cost batch_keys (distinct mesh+material pairs drawn, about a draw call each), entities, frame_ms: passes when
|
|
# raea's batch_keys and frame time are at most 1.25x the example's (wall time is this machine's, same run);
|
|
# raea's frame time is its update's (frame_ms) plus React's step of a frame for its 3D (step_ms)
|
|
# world (not yet: entities and components over BRP)
|
|
#
|
|
# tools/bevy-parity [PATH ...] default: every row of bench/bevy-parity/runs.tsv
|
|
# tools/bevy-parity --report only rewrite docs/bevy-parity.md from docs/bevy-parity/results.jsonl
|
|
# Needs target/release/raea-bevy-parity and raea, built in two cargo runs (lane build -- cargo build --release -p
|
|
# raea-bevy-parity, then -p raea-cli --bin raea): the host turns on bevy_winit for Bevy's examples, and one run of both
|
|
# unifies it into raea, whose render then panics building a second event loop (RecreationAttempt). And Bevy v0.20.0 at
|
|
# BEVY_SRC (~/.cache/raea-vendor/bevy-0.20.0).
|
|
set -uo pipefail
|
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
cd "$ROOT" || exit 2
|
|
BEVY_SRC=${BEVY_SRC:-$HOME/.cache/raea-vendor/bevy-0.20.0}
|
|
HOST=${RAEA_PARITY_HOST:-$ROOT/target/release/raea-bevy-parity}
|
|
RAEA=${RAEA_BIN:-$ROOT/target/release/raea}
|
|
RUNS=bench/bevy-parity/runs.tsv
|
|
PORTS=sdk/raea/bench/bevy-parity
|
|
RES=docs/bevy-parity/results.jsonl
|
|
OUT=${TMPDIR:-/tmp}/raea-bevy-parity
|
|
export RAEA_SIGN=0 RAEA_MARK=0
|
|
mkdir -p docs/bevy-parity "$OUT"
|
|
|
|
report() {
|
|
local total ported pass
|
|
total=$(grep -c '^\[\[example\]\]' "$BEVY_SRC/Cargo.toml")
|
|
{
|
|
echo "# Bevy parity"
|
|
echo
|
|
echo "Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a). Generated by tools/bevy-parity;"
|
|
echo "don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys and"
|
|
echo "frame time at most 1.25x the example's). Wall time is one machine's, measured in the same run."
|
|
echo
|
|
ported=$(jq -s '[.[].example] | unique | length' "$RES" 2>/dev/null || echo 0)
|
|
pass=$(jq -s 'group_by(.example) | map(select(all(.pass))) | length' "$RES" 2>/dev/null || echo 0)
|
|
excluded=$(grep -c '^[^#]' docs/bevy-parity/excluded.tsv 2>/dev/null || echo 0)
|
|
echo "Examples: **$total**, ported **$ported**, passing **$pass**, excluded **$excluded** (docs/bevy-parity/excluded.tsv), left **$((total - pass - excluded))**."
|
|
echo
|
|
echo "raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the example"
|
|
echo "doesn't pay."
|
|
echo
|
|
echo "| example | frame | ssim | worst tile | batch keys (bevy / raea) | entities (bevy / raea) | meshes (bevy / raea) | materials (bevy / raea) | frame ms (bevy / raea = update + step) | pass | why |"
|
|
echo "|---|---:|---:|---:|---:|---:|---:|---:|---:|---|---|"
|
|
jq -r '"| \(.example) | \(.frame) | \(.ssim // "-") | \(.tile // "-") | \(.bevy.batch_keys) / \(.raea.batch_keys) | \(.bevy.entities) / \(.raea.entities) | \(.bevy.meshes) / \(.raea.meshes) | \(.bevy.materials) / \(.raea.materials) | \(.bevy.frame_ms) / \(.raea.cost_ms // .raea.frame_ms) = \(.raea.frame_ms) + \(.raea.step_ms // 0) | \(if .pass then "yes" else "no" end) | \(.why) |"' "$RES" 2>/dev/null
|
|
echo
|
|
echo "## Excluded"
|
|
echo
|
|
echo "| example | why |"
|
|
echo "|---|---|"
|
|
grep '^[^#]' docs/bevy-parity/excluded.tsv 2>/dev/null | awk -F'\t' '{ printf "| %s | %s |\n", $1, $2 }'
|
|
} > docs/bevy-parity.md
|
|
echo "docs/bevy-parity.md: $total examples, $ported ported, $pass passing, $excluded excluded"
|
|
}
|
|
|
|
[ "${1:-}" = "--report" ] && { report; exit 0; }
|
|
[ -x "$HOST" ] || { echo "no $HOST: lane build -- cargo build --release -p raea-bevy-parity" >&2; exit 2; }
|
|
[ -x "$RAEA" ] || { echo "no $RAEA" >&2; exit 2; }
|
|
|
|
# runs.tsv: path, the example's arguments, the frames probed
|
|
rows=()
|
|
while IFS=$'\t' read -r path args frames; do
|
|
[[ -z "$path" || "$path" == \#* ]] && continue
|
|
if [ $# -gt 0 ]; then
|
|
for want in "$@"; do [ "$want" = "$path" ] && rows+=("$path"$'\t'"$args"$'\t'"$frames"); done
|
|
else
|
|
rows+=("$path"$'\t'"$args"$'\t'"$frames")
|
|
fi
|
|
done < "$RUNS"
|
|
|
|
for row in "${rows[@]}"; do
|
|
IFS=$'\t' read -r path args frames <<< "$row"
|
|
[ "$args" = - ] && args=""
|
|
d="$OUT/${path//\//__}"
|
|
rm -rf "$d"; mkdir -p "$d/bevy" "$d/raea"
|
|
echo "== $path ($args) at frames $frames"
|
|
# the example as Bevy wrote it
|
|
# shellcheck disable=SC2086
|
|
if ! RAEA_PARITY="$d/bevy.jsonl" RAEA_PARITY_FRAMES="$frames" RAEA_PARITY_PNG="$d/bevy" RAEA_PARITY_EXIT=1 \
|
|
RAEA_PARITY_EXAMPLE="$path" BEVY_ASSET_ROOT="$BEVY_SRC" "$HOST" $args > "$d/bevy.log" 2>&1; then
|
|
echo " the example failed: $(tail -1 "$d/bevy.log")"
|
|
fi
|
|
tsx="$PORTS/$path.tsx"
|
|
# Bevy's assets beside the port, as staticFile finds them (/media/x falls back to the folder's assets/, as Bevy's
|
|
# asset root): models/animated/Fox.glb for many_foxes. A link, gitignored, never a copy
|
|
[ -d "$(dirname "$tsx")" ] && ln -sfn "$BEVY_SRC/assets" "$(dirname "$tsx")/assets"
|
|
for f in ${frames//,/ }; do
|
|
why=""
|
|
b=$(jq -c "select(.frame == $f)" "$d/bevy.jsonl" 2>/dev/null | tail -1)
|
|
[ -z "$b" ] && b='{"batch_keys":null,"entities":null,"meshes":null,"materials":null,"frame_ms":null}' && why="the example wrote no frame $f"
|
|
r='{"batch_keys":null,"entities":null,"meshes":null,"materials":null,"frame_ms":null}'
|
|
s=null
|
|
t=null
|
|
if [ ! -f "$tsx" ]; then
|
|
why="${why:+$why; }no port at $tsx"
|
|
elif ! RAEA_STARTUP_TRACE=$(perl -MTime::HiRes=time -e 'printf "%.1f", time * 1000') RAEA_PARITY="$d/raea-$f.jsonl" \
|
|
"$RAEA" render "$tsx" --frame "$f" -o "$d/raea/$f.png" > "$d/raea-$f.log" 2>&1; then
|
|
why="${why:+$why; }raea failed: $(grep -iE 'error|refused|panick' "$d/raea-$f.log" | tail -1 | cut -c1-140)"
|
|
else
|
|
# the counts from the last update before the readback; its time the median update after the first five (the
|
|
# last line holds the readback's stall, the first the load)
|
|
r=$(jq -s -c 'if length == 0 then null else (.[-1] + {frame_ms: ((.[5:] // .) | map(.frame_ms) | sort | .[length / 2 | floor])}) end' "$d/raea-$f.jsonl" 2>/dev/null)
|
|
[ -z "$r" ] || [ "$r" = null ] && r='{"batch_keys":null,"entities":null,"meshes":null,"materials":null,"frame_ms":null}'
|
|
# and what a frame costs before Bevy sees it: React stepped through it for its 3D (the startup trace's marks over
|
|
# the frames stepped after frame 0, whose step is the mount, as Bevy's setup is out of its frame time), which
|
|
# Bevy's example doesn't pay; the time check is on frame_ms + step_ms
|
|
step=$(perl -ne '$a = $1 if /startup:\s+([\d.]+) ms the 3D.s rows: frame 0 stepped/; ($b, $n) = ($1, $2) if /startup:\s+([\d.]+) ms the 3D.s rows: (\d+) frames stepped/; END { printf "%.3f", ($b - $a) / ($n - 1) if $n > 1 && defined $a }' "$d/raea-$f.log")
|
|
r=$(jq -c --argjson s "${step:-null}" '. + {step_ms: $s, cost_ms: (if .frame_ms == null then null else ((.frame_ms + ($s // 0)) * 1000 | round / 1000) end)}' <<< "$r")
|
|
if [ -f "$d/bevy/$f.png" ] && [ -f "$d/raea/$f.png" ]; then
|
|
s=$(ffmpeg -hide_banner -nostats -i "$d/bevy/$f.png" -i "$d/raea/$f.png" -lavfi "[0:v]format=rgb24[a];[1:v]format=rgb24[b];[a][b]ssim" -f null - 2>&1 | grep -o 'All:[0-9.]*' | cut -d: -f2)
|
|
s=${s:-null}
|
|
# the worst tile: the two frames' difference, grey, averaged over 32 px squares, its largest value
|
|
t=$(ffmpeg -hide_banner -loglevel error -i "$d/bevy/$f.png" -i "$d/raea/$f.png" -filter_complex "[0:v]format=rgb24[a];[1:v]format=rgb24[b];[a][b]blend=all_mode=difference,format=gray,scale=iw/32:ih/32:flags=area" -f rawvideo -pix_fmt gray - | od -An -tu1 -v | tr -s ' ' '\n' | sort -n | tail -1)
|
|
t=${t:-null}
|
|
else
|
|
why="${why:+$why; }a frame is missing"
|
|
fi
|
|
fi
|
|
jq -nc --arg ex "$path" --argjson f "$f" --argjson s "$s" --argjson t "$t" --argjson b "$b" --argjson r "$r" --arg why "$why" '
|
|
def within(x; y): (x != null and y != null and (y <= (x * 1.25) or y <= x + 1));
|
|
($s != null and $s >= 0.98 and $t != null and $t <= 24) as $px
|
|
| within($b.batch_keys; $r.batch_keys) as $draws
|
|
| within($b.frame_ms; ($r.cost_ms // $r.frame_ms)) as $time
|
|
| {example: $ex, frame: $f, ssim: $s, tile: $t, bevy: $b, raea: $r, pixels: $px, draws: $draws, time: $time,
|
|
pass: ($px and $draws and $time),
|
|
why: ([$why, (if $s != null and ($px | not) then "pixels \($s), worst tile \($t)" else empty end),
|
|
(if ($draws | not) and $r.batch_keys != null then "draws \($r.batch_keys) vs \($b.batch_keys)" else empty end),
|
|
(if ($time | not) and $r.frame_ms != null then "frame \($r.cost_ms // $r.frame_ms) ms (\($r.frame_ms) update + \($r.step_ms // 0) React step) vs \($b.frame_ms) ms" else empty end)]
|
|
| map(select(. != "")) | join("; "))}' > "$d/result-$f.json"
|
|
jq -r '" frame \(.frame): ssim \(.ssim // "-"), tile \(.tile // "-"), batch keys \(.bevy.batch_keys) / \(.raea.batch_keys), frame ms \(.bevy.frame_ms) / \(.raea.frame_ms): \(if .pass then "PASS" else "FAIL \(.why)" end)"' "$d/result-$f.json"
|
|
done
|
|
# replace this example's rows in the results
|
|
{ jq -c --arg ex "$path" 'select(.example != $ex)' "$RES" 2>/dev/null; cat "$d"/result-*.json | jq -c .; } > "$RES.new" && mv "$RES.new" "$RES"
|
|
done
|
|
report
|