ifcviewer: extract ChunkPlanner + InstanceCompose; add Tier-1 test trio

The chunk planner (Morton sort + greedy pack) and instance composition
(federation × placement matrix chain + world-AABB derive) were inline
helpers in ViewportWindow.cpp. Pulled both out as free-function modules
so the math + lookup logic can be exercised without a Qt window or a
wgpu device. ViewportWindow now delegates; InstanceLookup is a using-
alias to InstanceCompose::InstanceLookup.

Also added an addSubBufferForTesting / clearSubPoolsForTesting seam to
BufferPool so the sub-allocator invariants can be pinned with fake
WGPUBuffer handles. The fakes are never dereferenced; the guard drops
the sub-pools before destructor would call wgpuBufferRelease.

Three new test binaries under src/ifcviewer/tests/, 33 cases / 173
assertions: BufferPool first-fit + alignment + coalescing + multi-
sub-pool isolation; ChunkPlanner Morton split / interleave / stable
sort / greedy-pack monotonicity and single-mesh-oversize; InstanceCompose
identity / translation / order-of-multiplication / large-placement
cancellation against federation false origin / column-major writeback /
findInstance lookup paths.
This commit is contained in:
Dion Moult
2026-06-04 17:19:24 +10:00
parent 749476d1a7
commit 1fe4570860
12 changed files with 1315 additions and 165 deletions
+4 -6
View File
@@ -42,6 +42,7 @@
#include "SidecarCache.h"
#include "BufferPool.h"
#include "InstanceCompose.h"
#include "ModelGpuData.h"
#include "OverlayRenderer.h"
#include "SelectionState.h"
@@ -382,12 +383,9 @@ public:
// Pure CPU lookup: object_id → owning model + mesh + raw placement
// matrix (column-major, pre-CoordinateOperation / FederatedFalseOrigin
// / ModelTransformation). Mirrors GL ViewportWindow::InstanceLookup
// so Measurement.cpp ports unchanged.
struct InstanceLookup {
uint32_t model_id = 0;
uint32_t mesh_id = 0;
double placement_transformation[16]{};
};
// so Measurement.cpp ports unchanged. The canonical struct lives in
// InstanceCompose so the lookup can be unit-tested without Qt.
using InstanceLookup = InstanceCompose::InstanceLookup;
bool findInstance(uint32_t object_id, InstanceLookup& out) const;
// A point that actually lies on the model's first instance — the