mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 06:32:09 +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:
@@ -22,12 +22,22 @@
|
||||
|
||||
#include <QWindow>
|
||||
#include <QColor>
|
||||
#include <QString>
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
// Stage-1 wgpu viewport: opens a native QWindow, brings up a wgpu instance/
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "SidecarCache.h"
|
||||
#include "WgpuModelGpuData.h"
|
||||
|
||||
// Stage-2 wgpu viewport: opens a native QWindow, brings up a wgpu instance/
|
||||
// adapter/device, configures a surface against the platform-native window
|
||||
// handle, and clears to background_color_ on every UpdateRequest.
|
||||
// handle, and clears to background_color_ on every UpdateRequest. Models
|
||||
// loaded from `.ifcview` sidecars are uploaded as wgpu buffers (no draw
|
||||
// path yet — that's stage 3).
|
||||
//
|
||||
// Mirrors the lifecycle shape of the GL ViewportWindow so subsequent stages
|
||||
// can grow this into a full IFC renderer without restructuring the host.
|
||||
@@ -39,6 +49,27 @@ public:
|
||||
|
||||
void setBackgroundColor(const QColor& color);
|
||||
|
||||
// Queue a sidecar path to be loaded after wgpu init completes. Safe to
|
||||
// call before the window is exposed. The path is resolved against the
|
||||
// working directory and read via SidecarCache::readSidecar (which
|
||||
// normalises stem → .ifcview).
|
||||
void queueLoadSidecar(const QString& path);
|
||||
|
||||
// Synchronous load + GPU upload. Requires wgpu init to have completed
|
||||
// (i.e. the window has been exposed at least once). Returns the
|
||||
// assigned model_id, or 0 on failure.
|
||||
uint32_t loadSidecar(const QString& path);
|
||||
|
||||
// Restore a finalised model from a SidecarData struct: allocate wgpu
|
||||
// buffers, upload vertex/index/mesh/instance bytes, register in
|
||||
// models_gpu_. Replaces any existing state for model_id.
|
||||
void applyCachedModel(uint32_t model_id, SidecarData data);
|
||||
|
||||
void removeModel(uint32_t model_id);
|
||||
void resetScene();
|
||||
|
||||
size_t modelCount() const { return models_gpu_.size(); }
|
||||
|
||||
protected:
|
||||
void exposeEvent(QExposeEvent* event) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
@@ -51,6 +82,8 @@ private:
|
||||
void render();
|
||||
void shutdown();
|
||||
|
||||
void flushPendingSidecarQueue();
|
||||
|
||||
bool wgpu_initialized_ = false;
|
||||
bool surface_configured_ = false;
|
||||
int configured_w_ = 0;
|
||||
@@ -64,6 +97,13 @@ private:
|
||||
WGPUTextureFormat surface_format_ = WGPUTextureFormat_Undefined;
|
||||
|
||||
QColor background_color_ = QColor("#202329");
|
||||
|
||||
// Per-model state, keyed by viewport-assigned model_id.
|
||||
std::unordered_map<uint32_t, WgpuModelGpuData> models_gpu_;
|
||||
uint32_t next_model_id_ = 1;
|
||||
|
||||
// Sidecar paths queued before init completes.
|
||||
std::deque<QString> pending_sidecars_;
|
||||
};
|
||||
|
||||
#endif // WGPUVIEWPORTWINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user