H1: make bench, render budgets, and a third of the figure draw calls
make bench (tools/bench.sh, tools/bench_report.gd) measures the server's p50/p99/max tick with 24 bots on three seeds over a whole match, and the client's draw calls, primitives, objects, nodes and memory at six moments of a match rendered in the capture container. It fails on anything over the budgets now recorded in docs/ARCHITECTURE.md: p99 tick 12 ms, 2,000 draw calls and 2,000,000 primitives per frame (all passes), 1 GiB video and 512 MiB static memory. Every capture now reports its frame's render counts in a "render" field. The first run put the barge, with 24 figures together, at 2,197 draw calls. Each figure part had one surface per colour (about 43 per figure, drawn again for shadows). FigureRig now merges a part's surfaces into one per finish (coat, gilt, plain) and carries the Palette colours as vertex colours, with shared materials. The barge is down to 1,207 draw calls, with the same triangles and the same look. Frame rates on a real GPU are not measured here; that stays with R6. Closes #54 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
# H1: repeatable performance benchmark.
|
||||
#
|
||||
# Server: runs the headless server with 24 bots, unthrottled, for BENCH_TICKS ticks on
|
||||
# each of BENCH_SEEDS seeds, and reads its p50/p99/max tick time.
|
||||
# Client: renders the moments of the match `make match` saved (whole island, barge,
|
||||
# landed, a build, the final players) and a crowded pine forest in the capture
|
||||
# container, and reads each frame's draw calls, primitives, objects and memory.
|
||||
#
|
||||
# tools/bench_report.gd checks every number against the budgets in
|
||||
# docs/ARCHITECTURE.md and writes build/bench/report.txt and report.json.
|
||||
#
|
||||
# Software rendering counts what is drawn, not how fast: frame rates on a real GPU are
|
||||
# left to the hands-on playtest (R6).
|
||||
#
|
||||
# tools/bench.sh about 3 minutes; needs Docker for the client
|
||||
# BENCH_SEEDS="2 7" BENCH_TICKS=6000 tools/bench.sh
|
||||
# BENCH_CLIENT=0 tools/bench.sh the server only
|
||||
set -uo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
|
||||
seeds="${BENCH_SEEDS:-2 7 20261109}"
|
||||
ticks="${BENCH_TICKS:-12000}"
|
||||
client="${BENCH_CLIENT:-1}"
|
||||
[[ "$ticks" =~ ^[0-9]+$ ]] || { echo "bench FAIL: bad BENCH_TICKS '$ticks'"; exit 2; }
|
||||
out="build/bench"
|
||||
mkdir -p "$out"
|
||||
rm -f "$out"/*.jsonl
|
||||
status=0
|
||||
|
||||
for seed in $seeds; do
|
||||
[[ "$seed" =~ ^[0-9]+$ ]] || { echo "bench FAIL: bad seed '$seed'"; exit 2; }
|
||||
echo "bench: server, seed $seed, $ticks ticks, 24 bots" >&2
|
||||
raw="$(timeout --signal=KILL 900 nice -n 15 tools/godot.sh -- --server --seed="$seed" --bots=24 --ticks="$ticks" --unthrottled 2>&1)"
|
||||
code=$?
|
||||
line="$(grep -m1 '"event":"stats"' <<<"$raw" || true)"
|
||||
if [[ "$code" -ne 0 || -z "$line" ]]; then
|
||||
echo "bench FAIL: the server on seed $seed exited $code"
|
||||
grep -v '^{' <<<"$raw" | tail -n 10
|
||||
status=1
|
||||
continue
|
||||
fi
|
||||
echo "$line" >>"$out/server.jsonl"
|
||||
done
|
||||
|
||||
if [[ "$client" == "1" ]]; then
|
||||
if [[ ! -f build/match/match.tclog ]]; then
|
||||
echo "bench: no saved match yet; playing one (make match)" >&2
|
||||
tools/match.sh >/dev/null || { echo "bench FAIL: make match failed"; exit 1; }
|
||||
fi
|
||||
for stage in match_lobby match_barge match_landed match_built match_final props_forest; do
|
||||
echo "bench: client, $stage" >&2
|
||||
if ! report="$(tools/capture.sh "$stage" "captures/bench_$stage.png" 2>/dev/null)"; then
|
||||
echo "bench FAIL: the $stage capture failed"
|
||||
status=1
|
||||
continue
|
||||
fi
|
||||
echo "$report" | grep -m1 '^{' >>"$out/client.jsonl"
|
||||
done
|
||||
fi
|
||||
|
||||
tools/godot.sh --script res://tools/bench_report.gd -- --dir="res://$out" --client="$client" || status=1
|
||||
exit "$status"
|
||||
@@ -0,0 +1,130 @@
|
||||
## H1: reads what tools/bench.sh measured, checks it against the performance budgets in
|
||||
## docs/ARCHITECTURE.md, and writes report.txt and report.json beside the logs.
|
||||
##
|
||||
## tools/godot.sh --script res://tools/bench_report.gd -- --dir=res://build/bench [--client=0]
|
||||
##
|
||||
## Exits 0 when everything is within budget, 1 when something isn't or nothing was
|
||||
## measured, 2 on a bad command line.
|
||||
extends SceneTree
|
||||
|
||||
## Server: the 99th percentile simulation tick, with 24 players (ServerLoop's budget).
|
||||
const SERVER_P99_USEC: int = ServerLoop.TICK_BUDGET_USEC
|
||||
## Client, per frame, every pass counted (shadows included). Set for a mid-range desktop
|
||||
## GPU from 2018 on, with room left for effects and the HUD.
|
||||
const CLIENT_DRAW_CALLS: int = 2000
|
||||
const CLIENT_PRIMITIVES: int = 2_000_000
|
||||
## Video memory the renderer reports using: fits a 2 GB card with room to spare.
|
||||
const CLIENT_VIDEO_MEM_BYTES: int = 1024 * 1024 * 1024
|
||||
## The engine's own static memory on the CPU side.
|
||||
const CLIENT_STATIC_MEM_BYTES: int = 512 * 1024 * 1024
|
||||
|
||||
var _failures: Array[String] = []
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
var dir: String = ""
|
||||
var want_client: bool = true
|
||||
for arg: String in OS.get_cmdline_user_args():
|
||||
if arg.begins_with("--dir="):
|
||||
dir = arg.trim_prefix("--dir=")
|
||||
elif arg.begins_with("--client="):
|
||||
want_client = arg.trim_prefix("--client=") != "0"
|
||||
else:
|
||||
printerr("bench_report: unknown argument '%s'" % arg)
|
||||
quit(2)
|
||||
return
|
||||
if dir.is_empty():
|
||||
printerr("bench_report: --dir is needed")
|
||||
quit(2)
|
||||
return
|
||||
var result: Dictionary = check(_read(dir.path_join("server.jsonl")), _read(dir.path_join("client.jsonl")), want_client)
|
||||
var text: String = describe(result)
|
||||
for failure: String in _failures:
|
||||
text += "bench FAIL: %s\n" % failure
|
||||
if _failures.is_empty():
|
||||
text += "bench: ok (everything within budget)\n"
|
||||
print(text.strip_edges())
|
||||
_write(dir.path_join("report.txt"), text)
|
||||
result["failures"] = _failures
|
||||
_write(dir.path_join("report.json"), JSON.stringify(result, "\t") + "\n")
|
||||
quit(0 if _failures.is_empty() else 1)
|
||||
|
||||
|
||||
## Checks parsed server "stats" lines and client capture reports. Returns the
|
||||
## measurements; failures go in `_failures`.
|
||||
func check(server: Array[Dictionary], client: Array[Dictionary], want_client: bool) -> Dictionary:
|
||||
var result: Dictionary = {"server": [], "client": []}
|
||||
if server.is_empty():
|
||||
_fail("no server runs were measured")
|
||||
for stats: Dictionary in server:
|
||||
var row: Dictionary = {
|
||||
"seed": int(stats.get("seed", -1)), "ticks": int(stats.get("ticks", 0)),
|
||||
"p50_us": int(stats.get("p50_us", -1)), "p99_us": int(stats.get("p99_us", -1)),
|
||||
"max_us": int(stats.get("max_us", -1)), "over_budget": int(stats.get("over_budget", 0)),
|
||||
}
|
||||
(result["server"] as Array).append(row)
|
||||
if row["p99_us"] < 0 or row["p99_us"] > SERVER_P99_USEC:
|
||||
_fail("server seed %d: p99 tick %d us is over the %d us budget" % [row["seed"], row["p99_us"], SERVER_P99_USEC])
|
||||
if want_client and client.is_empty():
|
||||
_fail("no client frames were measured")
|
||||
for capture: Dictionary in client:
|
||||
var render: Dictionary = capture.get("render", {})
|
||||
var row: Dictionary = {"scene": String(capture.get("scene", "?")).get_file().get_basename()}
|
||||
for key: String in ["draw_calls", "primitives", "objects", "visible_draw_calls", "visible_primitives", "shadow_draw_calls", "video_mem_bytes", "static_mem_bytes", "nodes"]:
|
||||
row[key] = int(render.get(key, -1))
|
||||
(result["client"] as Array).append(row)
|
||||
_limit(row, "draw_calls", CLIENT_DRAW_CALLS)
|
||||
_limit(row, "primitives", CLIENT_PRIMITIVES)
|
||||
_limit(row, "video_mem_bytes", CLIENT_VIDEO_MEM_BYTES)
|
||||
_limit(row, "static_mem_bytes", CLIENT_STATIC_MEM_BYTES)
|
||||
result["budgets"] = {
|
||||
"server_p99_us": SERVER_P99_USEC, "draw_calls": CLIENT_DRAW_CALLS, "primitives": CLIENT_PRIMITIVES,
|
||||
"video_mem_bytes": CLIENT_VIDEO_MEM_BYTES, "static_mem_bytes": CLIENT_STATIC_MEM_BYTES,
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
## The measurements as a plain table.
|
||||
func describe(result: Dictionary) -> String:
|
||||
var text: String = "Server (24 bots, unthrottled; budget p99 %d us)\n" % SERVER_P99_USEC
|
||||
text += " %-10s %7s %8s %8s %8s %6s\n" % ["seed", "ticks", "p50 us", "p99 us", "max us", "over"]
|
||||
for row: Dictionary in result["server"]:
|
||||
text += " %-10d %7d %8d %8d %8d %6d\n" % [row["seed"], row["ticks"], row["p50_us"], row["p99_us"], row["max_us"], row["over_budget"]]
|
||||
if not (result["client"] as Array).is_empty():
|
||||
text += "Client frame (software rendering: counts, not speed; budgets %d draw calls, %d primitives, %d MiB video, %d MiB static)\n" % [
|
||||
CLIENT_DRAW_CALLS, CLIENT_PRIMITIVES, CLIENT_VIDEO_MEM_BYTES >> 20, CLIENT_STATIC_MEM_BYTES >> 20]
|
||||
text += " %-14s %6s %6s %9s %8s %7s %8s %8s %6s\n" % ["frame", "draws", "shadow", "prims", "objects", "visible", "video MB", "static MB", "nodes"]
|
||||
for row: Dictionary in result["client"]:
|
||||
text += " %-14s %6d %6d %9d %8d %7d %8d %8d %6d\n" % [
|
||||
row["scene"], row["draw_calls"], row["shadow_draw_calls"], row["primitives"], row["objects"],
|
||||
row["visible_draw_calls"], row["video_mem_bytes"] >> 20, row["static_mem_bytes"] >> 20, row["nodes"]]
|
||||
return text
|
||||
|
||||
|
||||
func _limit(row: Dictionary, key: String, budget: int) -> void:
|
||||
var value: int = row[key]
|
||||
if value < 0:
|
||||
_fail("%s: no %s was reported" % [row["scene"], key])
|
||||
elif value > budget:
|
||||
_fail("%s: %s %d is over the %d budget" % [row["scene"], key, value, budget])
|
||||
|
||||
|
||||
func _fail(message: String) -> void:
|
||||
_failures.append(message)
|
||||
|
||||
|
||||
func _read(path: String) -> Array[Dictionary]:
|
||||
var lines: Array[Dictionary] = []
|
||||
if not FileAccess.file_exists(path):
|
||||
return lines
|
||||
for line: String in FileAccess.get_file_as_string(path).split("\n", false):
|
||||
var parsed: Variant = JSON.parse_string(line)
|
||||
if parsed is Dictionary:
|
||||
lines.append(parsed)
|
||||
return lines
|
||||
|
||||
|
||||
func _write(path: String, text: String) -> void:
|
||||
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
|
||||
if file != null:
|
||||
file.store_string(text)
|
||||
@@ -0,0 +1 @@
|
||||
uid://h25fcqsxrse1
|
||||
@@ -57,5 +57,26 @@ func _capture() -> void:
|
||||
stats["adapter"] = RenderingServer.get_video_adapter_name()
|
||||
stats["blank"] = blank
|
||||
stats["saved"] = error == OK
|
||||
stats["render"] = render_counts()
|
||||
print("CAPTURE " + JSON.stringify(stats))
|
||||
quit(0 if error == OK and (not blank or _allow_blank) else 1)
|
||||
|
||||
|
||||
## H1: what the last frame cost to draw. "draw_calls", "primitives" and "objects" cover
|
||||
## every pass (shadows included); "visible_*" only the main camera pass. Memory is in
|
||||
## bytes. Counts, not timings: software rendering says nothing about real frame rates.
|
||||
func render_counts() -> Dictionary:
|
||||
var counts: Dictionary = {
|
||||
"draw_calls": int(Performance.get_monitor(Performance.RENDER_TOTAL_DRAW_CALLS_IN_FRAME)),
|
||||
"primitives": int(Performance.get_monitor(Performance.RENDER_TOTAL_PRIMITIVES_IN_FRAME)),
|
||||
"objects": int(Performance.get_monitor(Performance.RENDER_TOTAL_OBJECTS_IN_FRAME)),
|
||||
"visible_draw_calls": root.get_render_info(Viewport.RENDER_INFO_TYPE_VISIBLE, Viewport.RENDER_INFO_DRAW_CALLS_IN_FRAME),
|
||||
"visible_primitives": root.get_render_info(Viewport.RENDER_INFO_TYPE_VISIBLE, Viewport.RENDER_INFO_PRIMITIVES_IN_FRAME),
|
||||
"shadow_draw_calls": root.get_render_info(Viewport.RENDER_INFO_TYPE_SHADOW, Viewport.RENDER_INFO_DRAW_CALLS_IN_FRAME),
|
||||
"video_mem_bytes": int(Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED)),
|
||||
"texture_mem_bytes": int(Performance.get_monitor(Performance.RENDER_TEXTURE_MEM_USED)),
|
||||
"buffer_mem_bytes": int(Performance.get_monitor(Performance.RENDER_BUFFER_MEM_USED)),
|
||||
"static_mem_bytes": OS.get_static_memory_usage(),
|
||||
"nodes": int(Performance.get_monitor(Performance.OBJECT_NODE_COUNT)),
|
||||
}
|
||||
return counts
|
||||
|
||||
Reference in New Issue
Block a user