mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 03:14:33 +00:00
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:
@@ -17,22 +17,28 @@
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
// NOTE: Sidecar format v3 is being rewritten to v4 (instanced geometry layout).
|
||||
// During the instancing rewrite (Commit A) the cache is a no-op: reads always
|
||||
// miss and writes always succeed without producing a file. Commit B will
|
||||
// re-introduce the on-disk format with MeshInfo + InstanceGpu sections.
|
||||
|
||||
#ifndef SIDECARCACHE_H
|
||||
#define SIDECARCACHE_H
|
||||
|
||||
#include "BvhAccel.h"
|
||||
#include "InstancedGeometry.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
static constexpr uint32_t SIDECAR_MAGIC = 0x49465657; // "IFVW"
|
||||
static constexpr uint32_t SIDECAR_VERSION = 3;
|
||||
static constexpr uint32_t SIDECAR_VERSION = 4;
|
||||
static constexpr uint32_t SIDECAR_ENDIAN = 0x01020304;
|
||||
|
||||
// Fixed-size element record for the sidecar. Strings are stored as
|
||||
// (offset, length) pairs into a separate string table.
|
||||
// Fixed-size element record. Strings are stored as (offset, length) pairs
|
||||
// into a separate string table.
|
||||
struct PackedElementInfo {
|
||||
uint32_t object_id;
|
||||
uint32_t model_id;
|
||||
@@ -46,30 +52,27 @@ struct PackedElementInfo {
|
||||
uint32_t type_length;
|
||||
};
|
||||
|
||||
// Everything the viewer needs to display a model without tessellating.
|
||||
// Everything needed to display an already-tessellated model without
|
||||
// re-running the iterator. v4 schema: instanced geometry.
|
||||
struct SidecarData {
|
||||
// GPU geometry (ready to upload as-is)
|
||||
std::vector<float> vertices; // interleaved, 8 floats per vertex
|
||||
std::vector<uint32_t> indices; // global (already remapped)
|
||||
// Per-model GPU geometry (local coords). 28 bytes/vertex.
|
||||
std::vector<float> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
|
||||
// Per-object metadata
|
||||
std::vector<ObjectDrawInfo> draw_info;
|
||||
// Mesh dictionary and per-instance data.
|
||||
std::vector<MeshInfo> meshes; // indexed by local_mesh_id
|
||||
std::vector<InstanceCpu> instances; // sorted by mesh_id
|
||||
|
||||
// Element tree metadata
|
||||
// Element tree metadata.
|
||||
std::vector<PackedElementInfo> elements;
|
||||
std::string string_table; // concatenated UTF-8
|
||||
|
||||
// BVH acceleration
|
||||
std::shared_ptr<BvhSet> bvh_set;
|
||||
std::string string_table;
|
||||
};
|
||||
|
||||
// Write a full sidecar next to the IFC file.
|
||||
// Returns true on success.
|
||||
// v4 writer/reader are stubbed for Commit A — no disk I/O happens.
|
||||
bool writeSidecar(const std::string& ifc_path,
|
||||
const SidecarData& data,
|
||||
uint64_t ifc_file_size);
|
||||
|
||||
// Read a sidecar. Returns nullopt on any failure (missing, stale, corrupt).
|
||||
std::optional<SidecarData> readSidecar(const std::string& ifc_path,
|
||||
uint64_t ifc_file_size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user