5.3 KiB
Performance work — handoff for next session (P1)
Where we are
Goal: stable 60 FPS @ 1920x1080 on this machine (AMD Ryzen 5 4500U / Renoir
Vega iGPU, 6 CU, shared memory, Mesa 26.2.7). The goal is met. P0 is done and
committed. Continue with P1 below if more headroom is wanted (e.g. for
--post-fx, bigger hordes, or weaker GPUs).
Measured results
| Scenario | Before | Now |
|---|---|---|
| 1834x1032, 17 enemies, raw | 40 FPS, GPU 20.1 ms, 230 draws | 60 FPS, GPU ~7.6 ms, 163 draws |
| 1920x1080 fullscreen, raw | — | 60 FPS, GPU 7.9 ms, 184 draws |
| 58 s horde (24 enemies, 12 proj, 35 shards) | — | 59 FPS, GPU 5.4 ms, 246 draws |
| Trilinear concrete filter | — | 60 FPS, GPU 2.6 ms |
Aniso 8x concrete filter (--aniso 8) |
— | 19 FPS, GPU 40.0 ms (leave off on this GPU) |
CPU section times are tiny: Sim 0.03 ms, Scene ~1.2 ms, UI ~1.5 ms. Present
(~14 ms) is EndDrawing() waiting for VSync — not a cost to optimize.
Tooling (already in place)
- F10 toggles the profiler overlay: CPU bars (Sim/Scene/Post/UI/Present), GPU
time, draw calls, entity counts. Code:
src/render/profiler.{hpp,cpp}. - GPU time uses two alternating
GL_TIME_ELAPSEDqueries loaded viaglXGetProcAddress. Mesa'sGL_QUERY_RESULT_AVAILABLEcheck always returned false here, sobegin_gpu()does a blocking read of the query from two frames ago (profiler.cpp:88) — safe and accurate, do not "fix" it back. - Draw-call counting is via macros wrapping
DrawCube/DrawCylinderinpresenter.cpp,models.cpp,debris.cpp, plus manualPROF_DRAW_CALL()inconcrete.cpp,aura.cppandmain.cpp's post chain.
How to measure reproducibly
cmake --build build -j6
# 10 s sample, 17-ish enemies:
timeout 16 ./build/cntrl --seed 42 --bot --no-damage \
--screenshot /tmp/opencode/p1_sample.png --screenshot-at 10
# true 1080p: add --fullscreen
# late horde: add --screenshot-at 58 and raise timeout to 70
# post-FX chain (bloom only runs here): add --post-fx
Read the overlay in the PNG (crop top 280x240 and enlarge). The in-game bottom HUD FPS line is a second sanity check.
What was done in P0
- Concrete triplanar -> baked UVs.
write_boxinsrc/render/concrete.cpp:49bakes one planar UV per axis-aligned face;concrete.vs/fsdo 3 texture fetches instead of 9 and dropped a per-vertex matrix inverse. Textures got explicit mipmaps. This alone halved GPU time. - Static prop culling.
ViewCull(presenter.cpp:53) is now passed into the office suite, plaza, floor props and doors viadraw_environment(game, cull). - FX batching.
QuadBatch(presenter.cpp:212) merges all blob shadows and camera-facing glows into twoRL_QUADSdraws instead of one per particle. - Graphics option plumbing.
src/render/graphics_settings.{hpp,cpp}holdsgfx::graphics_settings().concrete_filter(Trilinear default / Aniso 4x / 8x).--aniso 0|4|8selects it;ConcreteMaterial::apply_texture_filter()(concrete.cpp:196) +Presenter::apply_graphics_settings()(presenter.cpp:485) are the runtime hook for the M8 menu. Roadmap M8 records the deferred menu UI.
P1 work (next, in priority order)
-
Bake Hiss fluid noise to a texture — biggest remaining GPU cost.
assets/shaders/actor.fs:99-124runs severalvnoise()calls (each = 4hash21), domain-warp sin/cos, ridges and extra hashes per Hiss pixel. Generate a small scrolling 2-channel noise texture once at init (CPU or a Blender bake) and replace the block with 2 texture fetches + a few ALU. Keep a cheap 1-noise fallback for low quality. TheuHiss > 0.001branch is uniform per draw, so clean actors already skip it. Touchsrc/render/models.cpp:56-132andmodels.hppto own the texture. Validate with--hiss-test(close-up of a buffed Hiss Brute) and a late horde. -
Cheaper bloom (only active with
--post-fx).main.cpp:269-270uses half-res bloom buffers;bloom_blur.fsis 9-tap. Options: quarter-res buffers (4x less blur work), 5-tap bilinear-paired blur, fold the bright pass into the first blur to remove one full-screen pass, or skip blur on alternate frames.post_fx.fs:19-21also uses asin()hash — swap in the trig-freehash21fromactor.fs:29-34. -
Uniform / bind reduction for actors.
ModelBank::draw(src/render/models.cpp:165-215) issues ~11SetShaderValuecalls per actor andDrawModelExrebinds material maps every draw. Cache the last value per uniform (rig/glow/hiss are constant per model type), group draws by model type, or pack per-actor data into one UBO update per frame. -
Optional P2 (only if still short):
--render-scale 0.75internal render target upscaled in the final pass, auto-enabled on iGPUs; draw translucent glow cylinders withrlDisableDepthMask()last.
Gotchas
- Window is clamped to monitor height minus 48 unless
--fullscreen, so default capture is 1834x1032; use--fullscreento test true 1080p. --post-fxis opt-in; without it the bloom chain does not run, so P1 bloom work must be measured with that flag.- Keep Trilinear as the default filter. Aniso 8x is a user-facing option for stronger GPUs, not a default.
- Do not add comments unless asked; existing code style is
snake_case,PascalCasetypes,kConstant.