ifcviewer: quantize VBO to 16 B/vertex (sidecar v6)

Position now u16x3 normalized against each mesh's local AABB; normal
oct-encoded to i16x2; RGBA8 colour unchanged. Per-mesh dequant basis
lives in a new MeshGpu SSBO at binding 2; both main and pick shaders
mix() against it before applying the instance transform.

Drops VBO and sidecar size by ~43 % (28 -> 16 B/vert), which matters
mostly for warm-load downloads of precomputed sidecars and steady-state
VRAM. LodBuilder dequantizes positions into a scratch buffer before
calling meshopt, since meshoptimizer needs float positions.

Also fixes a streaming-time crash in cullAndUploadVisible: bvh_items
was only populated at finalize, but the linear fallback indexes it
during streaming. Mirror BvhItem appends in uploadInstanceChunk so the
hot path stays valid before the BVH is built.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-04-14 21:54:15 +10:00
parent 09ffdd2028
commit 574bcfa6c5
9 changed files with 299 additions and 72 deletions
+7 -4
View File
@@ -37,7 +37,9 @@ static constexpr uint32_t SIDECAR_MAGIC = 0x49465657; // "IFVW"
// v5 = MeshInfo extended with lod1_ebo_byte_offset + lod1_index_count (56 B).
// sd.indices may contain an appended LOD1 index slice for each mesh
// where meshoptimizer decimation produced useful output.
static constexpr uint32_t SIDECAR_VERSION = 5;
// v6 = VBO vertices quantized to 16 B/vertex (pos u16x3 + normal oct i16x2 +
// color u8x4). Dequant basis is per-mesh MeshInfo.local_aabb_min/max.
static constexpr uint32_t SIDECAR_VERSION = 6;
static constexpr uint32_t SIDECAR_ENDIAN = 0x01020304;
// Fixed-size element record. Strings are stored as (offset, length) pairs
@@ -56,10 +58,11 @@ struct PackedElementInfo {
};
// Everything needed to display an already-tessellated model without
// re-running the iterator. v4 schema: instanced geometry.
// re-running the iterator. v6 schema: instanced + quantized geometry.
struct SidecarData {
// Per-model GPU geometry (local coords). 28 bytes/vertex.
std::vector<float> vertices;
// Per-model GPU geometry (local coords). Raw VBO bytes at the
// INSTANCED_VERTEX_STRIDE_BYTES layout (16 B/vertex as of v6).
std::vector<uint8_t> vertices;
std::vector<uint32_t> indices;
// Mesh dictionary and per-instance data.