mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-31 00:46:36 +00:00
wgpu cull: chunk-level frustum cull replaces BVH walk
cullModelCpuCompute previously had two paths: a flat linear scan over
all instances (default), or a BVH-stack walk (--bvh, gated off because
it regressed on dense scenes — the BVH built per instance but its
interior-node AABBs spanned huge chunks of model so most subtrees
straddled the frustum and the walk overhead beat the rejection win).
With spatial chunk planning (commit 4d3617420) chunks ARE already a
one-level spatial partition of the model, with tight per-chunk AABBs.
So the same wholesale-reject behaviour falls out of just walking
m.chunks: frustum-test each chunk's AABB once, and on hit, iterate
its (new) instance_ids list. No per-node traversal overhead, no
dependency on rebuilding a BVH alongside the chunk plan.
Changes:
- Chunk gains an instance_ids vector, populated in both apply paths
alongside the per-chunk AABB accumulation.
- cullModelCpuCompute drops the if-bvh / else-linear-scan dichotomy
in favour of `for chunk: frustum-test then iterate c.instance_ids`.
- Per-model ModelBvh field, buildModelBvhOne call sites, BvhAccel.cpp
in CMakeLists, bvh_enabled_ field, and --bvh CLI flag all removed —
dead code now that chunk-cull subsumes them.
- BvhAccel.{h,cpp} stay in src/ifcviewer for the GL backend's use.
Benchmark (big federation, --streaming, close camera): avg 37 fps
(was 36) / median 53 (was 53). Same order on the metric — the
parallelism across models was already amortising frustum-check cost,
so the per-chunk early-out saves only fragments of cull wall time.
Real cull-perf win will come from chunk-level HiZ (potentially) or
GPU compute cull (task #17). What this commit really delivers is
architectural simplification + removal of a dead-but-not-dropped
code path.
Pixel-identical to non-streaming on basic.ifc.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "BvhAccel.h"
|
||||
#include "InstancedGeometry.h"
|
||||
#include "WgpuBufferPool.h"
|
||||
|
||||
@@ -157,6 +156,14 @@ struct WgpuModelGpuData {
|
||||
// point at the correct chunk-local offsets.
|
||||
std::vector<uint32_t> mesh_ids;
|
||||
|
||||
// Instance indices belonging to this chunk (i.e. whose mesh lives
|
||||
// in this chunk). Built at chunk-planning time. Lets cull iterate
|
||||
// chunks as the outer loop, frustum-test the chunk AABB once,
|
||||
// and skip every instance inside in one shot when the chunk is
|
||||
// off-screen — far cheaper than the per-instance frustum check
|
||||
// on flat-scan culls of 1M+ instance scenes.
|
||||
std::vector<uint32_t> instance_ids;
|
||||
|
||||
// LRU marker for streaming eviction. Updated to the window's
|
||||
// streaming_frame_idx_ every frame the chunk is rendered (i.e.
|
||||
// total_visible_draws > 0). The evictor picks the smallest value
|
||||
@@ -205,12 +212,11 @@ struct WgpuModelGpuData {
|
||||
std::vector<MeshInfo> meshes;
|
||||
std::vector<InstanceCpu> instances;
|
||||
|
||||
// Per-model BVH over the instances' world AABBs. Built once at
|
||||
// applyCachedModel; consumed by cullModelCpuCompute to reject whole
|
||||
// subtrees against frustum + HiZ without descending. Critical for
|
||||
// 100+ model / 1M+ instance scenes — turns O(N) per-instance cull
|
||||
// into ~O(visible_count + log N).
|
||||
ModelBvh bvh;
|
||||
// Spatial chunk-cull replaced the per-model BVH walk — chunks are
|
||||
// already a one-level spatial partition of the instances, so a
|
||||
// single frustum test per chunk gives the same wholesale-reject
|
||||
// win without the BVH's per-node traversal overhead. The BVH field
|
||||
// is gone; cull iterates m.chunks instead.
|
||||
|
||||
bool hidden = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user