Skip to content

perf: engine optimization pass - #227

Merged
CanReader merged 34 commits into
stagingfrom
engine-optimization
Nov 3, 2026
Merged

CanReader merged 34 commits into
stagingfrom
engine-optimization

Conversation

@CanReader

Copy link
Copy Markdown
Owner

Performance pass based on an external audit. Every claim was checked against the code first; one commit per fix.

Changes

  • Render queue: commands come from per-frame arenas instead of a heap allocation plus a RefPtr control block each; no list copies per draw.
  • Vulkan: a material rebound in the same frame reuses its PBR descriptor set; SSAO linearizes sample depth instead of two mat4 transforms per tap.
  • Culling: SSE2 occluder raster and rect depth scan (bit-identical depth, identical visibility; scalar fallback kept).
  • OpenGL: vertex layout applied once per layout change (separate attribute formats), shadow viewport from tracked state, memoized light-space caster transforms, SSAO tap depth linearized.
  • D3D11/D3D12: cached rasterizer/depth-stencil states, depth-stencil state leak fixed, static_cast buffer binds, no busy spin on the stats query, memoized shadow caster transforms.
  • Scene: transform world matrix cached behind a dirty flag; culled meshes submit no transform/material state; plane/cylinder factories add the transform first; Arvo cull bounds; cached component lookups.
  • Physics: broadphase queried only from movable bodies, velocity-enlarged proxies, mesh narrowphase tests in place with a bounds early-out.
  • Assets/animation: models parsed once; keyframes found by binary search.
  • Containers/math: HashTable hashes keys by value (plus probe, duplicate-insert and double-free fixes), O(1) Queue pop, exact-size List copies and std::sort, debug-only Matrix bounds check.
  • Build: Release LTO and -fno-math-errno on the Engine target.
  • Bench: CPU_frame_ms benchmark column (frame CPU time excluding present).

Results (SleakCraft, Vulkan, 1600x900, render distance 12, base and new runs interleaved, medians)

before after
FPS (default config) ~212 ~220
CPU frame 2.05 ms 1.62 ms
Occlusion raster 1.17 ms 0.70 ms
GPU frame 2.07 ms 2.09 ms
FPS with SSAO/SSR/bloom ~150-160 ~184
SSAO pass 0.42 ms 0.37 ms

OpenGL: CPU frame -21%, FPS unchanged (present-bound at ~345).

Verification

  • Vulkan capture of the default scene is byte-identical to staging. With SSAO on, the only difference comes from the SSAO shader (swapping the old SPIR-V back in reproduces staging exactly).
  • OpenGL screenshots match staging.
  • D3D11/D3D12 only syntax-checked (zig, MinGW headers, Debug and Release); not run on Windows.
  • Physics, animation, model loading and the component changes were checked with standalone bit-identity harnesses but are barely exercised by SleakCraft; they should be tried in SleakSims.

Not done

  • Physics Step stays in Update (moving it to FixedUpdate without render interpolation would judder the player camera above 60 FPS).
  • GBuffer/bloom descriptor caching skipped (microseconds per frame, device-lost risk if invalidation is missed).
  • Skinned meshes in the GBuffer pass, TRS animation blending, intrusive RefPtr, vertex format split, -march=native and /fp:fast.

@CanReader
CanReader merged commit 82ba7bc into staging Nov 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant