GPU instancing: streamer, viewport, shaders rewritten

Commit A of the instancing migration (Phase 3a).  The streamer now runs
the iterator with use-world-coords=false and dedupes by the geometry's
representation id, emitting a MeshChunk once per unique geometry and an
InstanceChunk per placement.  The viewport keeps geometry in local
coordinates (28 B/vertex, down from 32) and applies the per-instance
transform in the vertex shader via an std430 SSBO indexed by
gl_InstanceID + a per-draw uniform offset.  After streaming finishes
finalizeModel() stable-sorts instances by mesh_id, assigns each mesh a
contiguous range, and uploads the SSBO; render then issues one
glDrawElementsInstancedBaseVertex per mesh.

BvhAccel is reshaped to operate on a generic BvhItem (world AABB +
model_id) so it can drive instance-level culling, but the path is not
wired in yet -- every instance is drawn every frame in this commit.
Progressive-during-streaming rendering is likewise disabled: a model
appears when its SSBO is uploaded, not incrementally.  Sidecar cache
is stubbed (reads miss, writes are no-ops); the v4 on-disk format with
MeshInfo + InstanceGpu sections lands in Commit B.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-04-12 19:53:06 +10:00
parent 8c8ef5c32b
commit 07a5c59359
11 changed files with 836 additions and 1432 deletions
+4 -7
View File
@@ -26,15 +26,13 @@
#include <string>
#include <vector>
#include <atomic>
#include <functional>
#include <memory>
#include <mutex>
#include <deque>
#include "../ifcparse/file.h"
#include "../ifcgeom/Iterator.h"
#include "ViewportWindow.h"
#include "InstancedGeometry.h"
struct ElementInfo {
uint32_t object_id;
@@ -67,15 +65,14 @@ public:
signals:
void progressChanged(int percent);
void elementReady(UploadChunk chunk);
void meshReady(MeshChunk chunk);
void instanceReady(InstanceChunk chunk);
void finished();
void errorOccurred(const QString& message);
private:
void run(const std::string& path, int num_threads);
UploadChunk convertElement(const IfcGeom::TriangulationElement* elem, uint32_t object_id);
std::unique_ptr<ifcopenshell::file> ifc_file_;
std::unique_ptr<QThread> worker_thread_;
std::atomic<bool> running_{false};
@@ -85,7 +82,7 @@ private:
std::mutex elements_mutex_;
std::vector<ElementInfo> pending_elements_;
uint32_t next_object_id_ = 1; // 0 = no object
uint32_t next_object_id_ = 1;
uint32_t model_id_ = 0;
};