Skip to content

[Epic] Build a GPU-driven distant-terrain LOD pipeline #923

Description

@MichaelFisher1997

Objective

Evolve ZigCraft distant terrain into a measured hybrid CPU/GPU architecture capable of approaching Distant Horizons-like quality and scale without assuming that every workload belongs on GPU.

Architectural assessment

The current system is predominantly CPU-driven: procedural sampling, mesh generation, hierarchy scheduling, visibility/coverage checks, streaming, persistence, and default direct draw submission occur on CPU. The GPU mainly transforms and shades uploaded conventional vertices. Terrain MDI exists but is optional, while the LOD GPU-culling switch currently falls back to CPU behavior.

The architecture can improve substantially without a rewrite through visibility, threading, MDI, transfer, and synchronization work. Reaching genuinely large horizons with high quality likely requires the Phase 4 representation change: compact far-terrain tiles plus GPU-driven visibility/submission. Procedural generation, persistence, edits, and policy should remain CPU-owned unless measurements prove otherwise.

Current responsibility map

Work Current owner Target owner
Procedural terrain sampling CPU workers CPU workers, cheaper/reused for far levels
Persistence and edit provenance CPU/update path Async CPU I/O/workers
Region hierarchy and scheduling CPU CPU
Mesh construction CPU workers CPU near LOD; GPU-friendly compact representation for far LOD
Frustum/coverage culling CPU, repeated by layer CPU broad policy + GPU high-cardinality culling
Draw submission CPU direct draws; optional terrain MDI GPU-compacted indirect terrain and water
Uploads/lifetime CPU staging with global idle paths Async ring staging + fence/timeline retirement
Terrain/water shading GPU GPU, with cheaper far-water/material paths

Ranked concerns

  1. Repeated CPU visibility and chunk-coverage work, including terrain/water duplication.
  2. Direct per-region submission because MDI is disabled by default and water remains direct.
  3. Dense CPU-generated far meshes, expensive representative sampling, and large vertex uploads.
  4. Repeated global state scans/sorts and long-lived manager lock participation.
  5. Synchronous cache activity on the update path.
  6. vkDeviceWaitIdle during eviction/pool operations and avoidable upload copies.
  7. Incomplete memory accounting and unmanaged pool slack/shadow allocations.
  8. No production GPU culling/indirect-command compaction.
  9. Far-water shader cost and fragment-discard handoff waste.

Phased delivery

Dependency graph

Phase 0 instrumentation
 ├─ Phase 1 CPU/MDI improvements ─────┐
 ├─ Phase 2 transfer/lifetime ────────┼─ Phase 3 GPU culling
 └─ visual + memory baselines ────────┘          │
                                                  ▼
                                  Phase 4 compact far tiles
                                                  │
                                                  ▼
                                  Phase 5 quality/hardening

Within each phase, workstreams marked parallel may be developed concurrently. Shared RHI/Vulkan contract changes and resource-lifetime changes must merge sequentially behind explicit interfaces.

Global constraints

  • Optimize based on p95/p99 and attributed timings, not average FPS alone.
  • Compare CPU and GPU paths at realistic candidate counts; small jobs may remain faster on CPU.
  • Avoid GPU readback in generation/streaming loops.
  • Maintain feature-gated fallbacks for hardware lacking required indirect/timeline capabilities.
  • Never trade hidden VRAM growth or synchronization hitches for apparent CPU gains.
  • Validate visual stability, edits, persistence, cancellation, and memory pressure alongside speed.
  • Mesh shaders are optional research, not a prerequisite; compute + conventional indirect rendering comes first.

Epic completion criteria

  • CPU/GPU responsibilities match the target map and are backed by measurements.
  • Large-horizon traversal stays within agreed p95/p99 CPU, GPU, RAM, and VRAM budgets.
  • Normal streaming has no global device-idle synchronization.
  • GPU culling and indirect submission have validated CPU fallbacks.
  • Far LOD upload and geometry memory scale with compact tiles rather than expanded vertices.
  • Automated benchmark and visual suites prevent performance, seam, transition, and handoff regressions.

Validation matrix

For every phase, test stationary views, forward traversal, rapid rotation, teleport/eviction pressure, edits, save/reload, and long-running low-memory scenarios. Use nix develop --command for all builds/tests and bounded headless graphics runs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions