Optimize rendering: frame pacing, UI culling, render scale and GPU scratch buffers

This commit is contained in:
shen
2026-10-08 17:06:17 -07:00
parent d7adbb3014
commit 08cc8865be
5 changed files with 180 additions and 72 deletions
+8
View File
@@ -91,6 +91,14 @@ Verification:
Remaining for genuine playable equivalence: full AVA2 packet coverage and error/disconnect recovery for unsupported packets, map Warp/global-to-local coordinate transformation and original loading resources, actor/combat/skills/quest/UI/render behavior, locale/codepage and metadata APIs, full pack handling, isolated real AVA2 server validation and Android APK/device verification. Socket integration does not establish those behaviors.
### 2026-10-08: rendering performance optimizations (Frame Pacing, UI Box Culling, Render Scale, Scratch Buffers)
Ported high-impact rendering optimizations identified in metin2-client audit across Phase 1 and Phase 2:
1. Frame Pacing & FPS Cap: Added `--fps-cap` CLI flag and `MT_FPS_CAP` / `AVA2_FPS_CAP` environment variables. Defaults to 60 FPS for desktop interactive play and 0 (unthrottled) for automated `--frames N` test runs. Fixed-cadence pacing via `std::this_thread::sleep_until` and late re-anchoring eliminates frame delta oscillation on high-refresh ProMotion/120Hz/144Hz displays.
2. UI Fast Box Culling: Implemented screen-boundary fast bounding box rejection in `CWindow::Render()`, `CGraphicTextInstance::Render()`, and `CSlotWindow::OnRender()` against logical screen resolution `(0, 0, sw, sh)` to eliminate redundant GPU draw calls and texture/vertex overhead for off-screen UI elements.
3. 3D Render Scale Pipeline: Added `--render-scale` CLI flag and `MT_RENDER_SCALE` / `AVA2_RENDER_SCALE` environment variables (clamped 0.25..1.0, default 0.75 on Android, 1.0 on desktop). When render scale < 1.0, 3D world renders into reduced-resolution `gpu_scene_texture` (`SDL_TEXTUREACCESS_TARGET`) with hardware linear upscaling, while 2D UI remains at 100% native resolution. Added `Gr2SceneRenderer::SetLogicalSize` to maintain accurate mouse picking and TextTail screen projections. Minimap radar rendering isolated to a dedicated 128x128 streaming texture.
4. GPU Geometry Scratch Buffers: Replaced per-draw heap vector allocations (`xverts`, `vertices`, `indices`, `sortedDraws`) in `Gr2SceneRenderer::RenderSceneGPU` with persistent member scratch buffers, eliminating thousands of memory allocations and deallocations per second.
Validation: Both macOS host and Android arm64 NDK 27 (`build/android-core`) compile cleanly; all 41 CTest unit tests pass; parity audits verify 0 placeholder bindings, 46 Windows module signatures, and 395 packet constants.
### 2026-10-05: character wire layout and retained state
Compared exclusively with upstream AVA2 Windows Packet.h and PythonNetworkStreamPhaseGameActor.cpp. Equipment parts are six (including arrow type), shining parts three. Corrected AdditionalInfo to 75 bytes (conqueror level, language, shining) and Update to 56 bytes (conqueror level, shining). Retain arrow type, sash, conqueror level, state flags and affect/shining arrays in actor state; accept zero speed updates. Ignore mismatched additional-info VID as Windows does; bound name reads. Generated oracle now extracts original equipment/shining enums and character declarations with active Windows feature guards; asserts sizes and offsets. Fragmented literal-length additional-info/update followed by ping verifies framing and unmatched VID handling.
Validation: macOS build passed; 17 nonvisual CTests passed; Android arm64 libmain.so built. The existing render_3d test remains excluded due to its unresolved timeout. No real server/device verification. Remaining: actual shining/affect rendering, race/equipment model mapping, map coordinate conversion, alternate actor packets, renewal death layout, and the broader Python/gameplay placeholder inventory. This milestone does not establish full Windows parity.