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>
83 lines
3.5 KiB
GDScript
83 lines
3.5 KiB
GDScript
## Renders a scene for a number of frames and saves the last one as a PNG.
|
|
## Runs inside the tidewall-capture container via tools/capture.sh, never on the host
|
|
## display. Prints one JSON line with the image statistics and exits:
|
|
## 0 saved and not blank, 1 blank or failed, 2 bad arguments.
|
|
##
|
|
## --scene=res://...tscn --out=res://captures/x.png [--frames=N] [--allow-blank]
|
|
extends SceneTree
|
|
|
|
var _scene: String = ""
|
|
var _out: String = ""
|
|
var _frames: int = 30
|
|
var _allow_blank: bool = false
|
|
|
|
|
|
func _initialize() -> void:
|
|
for arg: String in OS.get_cmdline_user_args():
|
|
if arg.begins_with("--scene="):
|
|
_scene = arg.trim_prefix("--scene=")
|
|
elif arg.begins_with("--out="):
|
|
_out = arg.trim_prefix("--out=")
|
|
elif arg.begins_with("--frames=") and arg.trim_prefix("--frames=").is_valid_int():
|
|
_frames = maxi(arg.trim_prefix("--frames=").to_int(), 1)
|
|
elif arg == "--allow-blank":
|
|
_allow_blank = true
|
|
else:
|
|
printerr("capture: unknown argument '%s'" % arg)
|
|
quit(2)
|
|
return
|
|
if _scene.is_empty() or _out.is_empty():
|
|
printerr("capture: --scene and --out are required")
|
|
quit(2)
|
|
return
|
|
if DisplayServer.get_name() == "headless":
|
|
printerr("capture: no display; run this through tools/capture.sh")
|
|
quit(2)
|
|
return
|
|
_capture.call_deferred()
|
|
|
|
|
|
func _capture() -> void:
|
|
var packed: PackedScene = load(_scene) as PackedScene
|
|
if packed == null:
|
|
printerr("capture: can't load scene '%s'" % _scene)
|
|
quit(1)
|
|
return
|
|
root.add_child(packed.instantiate())
|
|
for _index: int in _frames:
|
|
await process_frame
|
|
await RenderingServer.frame_post_draw
|
|
var image: Image = root.get_texture().get_image()
|
|
var stats: Dictionary = ImageStats.measure(image)
|
|
var blank: bool = ImageStats.is_blank(stats)
|
|
var error: Error = image.save_png(_out)
|
|
stats["scene"] = _scene
|
|
stats["size"] = [image.get_width(), image.get_height()]
|
|
stats["renderer"] = RenderingServer.get_current_rendering_method()
|
|
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
|