Files
shinyobjectz 450f8e4a97 FC0a: ui/widgets/standard_widgets under scripted input: the menu opens, its popup placed by Bevy's Popover
The bar can now drive an interactive example. A row of bench/bevy-parity/runs.tsv may name an input script, in the format `raea play --input-script` takes ({"FRAME": ["Pointer:X:Y:down"]}). The example gets it as RAEA_PARITY_INPUT: systems/parity input.rs writes bevy_picking's PointerInput messages on the picture the cameras draw into. The port's pictures then come from `raea play` under the same script; cost still comes from the render.

Gaps found and patched on the way:
- raea play sent its pointer only to useInput, never to page elements, so a composition's onClick never ran. The live step now hit tests the pointer on the page (BevyPage::hit_path) and sends its React handlers the events a browser fires, in a browser's order: over/out, enter/leave, move, down/up, and click on what both the press and the release were over (runtime/live pointer.rs).
- bevy_ui_widgets' Popover: Node takes `popover` ({positions: [{side, align, gap}], window_margin}). raea's Blitz places the popup after layout beside its parent's box (inside its border), at the first placement the window hides least, as position_popover does (vendor/blitz-dom bevy_popover.rs). It's drawn and hit tested there. Node also takes bevy_picking's handlers (onClick, onPointerDown/Up/Over/Out/Enter/Leave/Move; sdk/render ui-pick.ts). The page bridge keeps data-raea-bevy-popover.
- After any state change in play, bevy text was drawn broken at min-content width: raea's bevy_text min-content measure breaks lines at width 0, and a box whose layout taffy kept from its cache never broke them back. A measure now puts back the lines a laid-out box keeps (blitz-dom inline.rs, TextLayout::performed_width).

The port's Button reads "Hover" and "Press" as set_button_style has it; the menu button toggles spawn_menu's popup of four items, each lit while hovered; activating an item closes the menu. Under a click on Menu, then the pointer on the first item: 0.994691, worst tile 17. Without the toggle, the popover, GlobalZIndex or hover, with the side flipped, a 6 px gap, three items or 90% width, the bar fails; a gray border passes it and the probe catches it (7217 px off against 6465). conformance/ui-pick.test.tsx; blitz-dom bevy_popover tests; runtime/live pointer test.
2026-11-08 02:24:37 -08:00

152 lines
11 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
# A row's fourth column (optional) is an input script for an interactive example, the file `raea play
# --input-script` takes ({"FRAME": ["Pointer:X:Y:down", keys...]}): the example gets it as RAEA_PARITY_INPUT
# (systems/parity input.rs, bevy_picking's pointer), and the port's pictures are `raea play`'s under it (its cost
# still the render's, which has no input)
# 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 input; do
[[ -z "$path" || "$path" == \#* ]] && continue
if [ $# -gt 0 ]; then
for want in "$@"; do [ "$want" = "$path" ] && rows+=("$path"$'\t'"$args"$'\t'"$frames"$'\t'"${input:--}"); done
else
rows+=("$path"$'\t'"$args"$'\t'"$frames"$'\t'"${input:--}")
fi
done < "$RUNS"
for row in "${rows[@]}"; do
IFS=$'\t' read -r path args frames input <<< "$row"
[ "$args" = - ] && args=""
[ "$input" = - ] && input=""
inenv=()
[ -n "$input" ] && inenv=(RAEA_PARITY_INPUT="$ROOT/$input")
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 ! env ${inenv[@]+"${inenv[@]}"} 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)"
elif [ -n "$input" ] && ! "$RAEA" play "$tsx" --offscreen --size "$(magick identify -format '%wx%h' "$d/bevy/$f.png" 2>/dev/null || echo 1280x720)" --input-script "$ROOT/$input" \
--snapshot "$(perl -e "printf '%.4f', $f / 60")" "$d/raea/$f.png" --seconds "$(perl -e "printf '%.4f', ($f + 14) / 60")" > "$d/raea-play-$f.log" 2>&1; then
why="${why:+$why; }raea play failed: $(grep -iE 'error|refused|panick' "$d/raea-play-$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