mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-31 00:46:36 +00:00
wgpu backend: load .ifcview sidecars onto GPU buffers
Stage 2 of the wgpu port. WgpuViewportWindow gains a queueLoadSidecar API (called from the minimal driver before init) and an applyCachedModel that runs after init: reads via SidecarCache::readSidecar, allocates four wgpu buffers per model (vertex storage, index, mesh-quant storage, instance storage), uploads via wgpuQueueWriteBuffer, retains a CPU mirror of the MeshInfo/InstanceCpu arrays for the cull and picking paths that arrive in later stages. MeshGpu (the per-mesh quantization basis) is derived from MeshInfo on the fly; InstanceGpu (transform + ids) is derived from InstanceCpu and uses the cached float transform — composing from placement_transformation against federation-stage matrices lands when stage 5 wires those. SidecarCache.cpp is compiled into IfcViewerWgpu directly: it's pure C++ with no Qt/OCCT/IFC-parse deps, so dragging in the IfcViewer static lib for one source file would be wasteful. This duplication goes away once src/ifcviewer-core/ is extracted (task #12). Verified on a synthesised v13 sidecar (4 verts, 6 indices, 1 mesh, 1 instance) and a multi-sidecar load that assigns successive model_ids. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file is part of IfcOpenShell. *
|
||||
* *
|
||||
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the Lesser GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3.0 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* IfcOpenShell is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* Lesser GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the Lesser GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef WGPUMODELGPUDATA_H
|
||||
#define WGPUMODELGPUDATA_H
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "InstancedGeometry.h"
|
||||
|
||||
// Per-model wgpu state. Mirrors the GL backend's ModelGpuData but with
|
||||
// wgpu handles. Stage 2 only allocates and uploads the four core buffers;
|
||||
// bind groups, pipelines, BVH and cull scratch land in later stages.
|
||||
//
|
||||
// All vertex/index/mesh/instance bytes are uploaded once at load time via
|
||||
// wgpuQueueWriteBuffer. The vertex storage buffer is read by the vertex
|
||||
// shader (vertex pulling), not used as a classic vertex buffer — there is
|
||||
// no input-assembler vertex layout to match.
|
||||
struct WgpuModelGpuData {
|
||||
// Raw VBO bytes at the INSTANCED_VERTEX_STRIDE_BYTES layout (12 B/vertex).
|
||||
// Bound as a read-only storage buffer in the vertex shader.
|
||||
WGPUBuffer vertex_storage = nullptr;
|
||||
// Mesh-local u32 indices. base_vertex applied at draw time so a single
|
||||
// index buffer per model is shared across meshes.
|
||||
WGPUBuffer index_buffer = nullptr;
|
||||
// MeshGpu[] — per-mesh quantization basis (aabb_min/max as vec4 pair).
|
||||
// Derived from MeshInfo on upload.
|
||||
WGPUBuffer mesh_storage = nullptr;
|
||||
// InstanceGpu[] — per-instance transform + ids. Derived from InstanceCpu
|
||||
// on upload. Stage 2 stores the cached `transform`; later stages will
|
||||
// recompose from placement_transformation when stage matrices change.
|
||||
WGPUBuffer instance_storage = nullptr;
|
||||
|
||||
// Size mirrors for stats / range checks.
|
||||
size_t vertex_bytes = 0;
|
||||
uint32_t index_count = 0;
|
||||
uint32_t mesh_count = 0;
|
||||
uint32_t instance_count = 0;
|
||||
|
||||
// CPU side, kept for cull / picking / federation recompose.
|
||||
std::vector<MeshInfo> meshes;
|
||||
std::vector<InstanceCpu> instances;
|
||||
|
||||
bool hidden = false;
|
||||
};
|
||||
|
||||
// Release every wgpu handle in `m` and clear its size mirrors. Safe to call
|
||||
// repeatedly; idempotent on already-released entries.
|
||||
void releaseWgpuModelGpuData(WgpuModelGpuData& m);
|
||||
|
||||
#endif // WGPUMODELGPUDATA_H
|
||||
Reference in New Issue
Block a user