mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
ifcviewer: move wgpu lifecycle state ownership into ViewportCore
First chunk of the #84 ViewportCore extraction. The seven wgpu lifecycle handles (instance, adapter, device, queue, surface, surface_format, surface_configured) now live as ViewportCore members; ViewportWindow keeps reference aliases pointing at ViewportCore's storage so its existing render-method bodies don't need a `core_.` prefix added at every call site — 230+ touches deferred until each method moves across. Member init order in ViewportWindow's constructor: core_(this) → constructs ViewportCore with host_=this instance_(core_.instance_) → binds the alias to core_'s field … same for adapter/device/queue/surface/… Friend declaration on ViewportCore::ViewportWindow lets the references bind to its private fields. The friend bond shrinks each commit as render methods (and their `device_` / `queue_` references) migrate into ViewportCore proper; the goal state is no friend and no aliases. Next #84 chunks (separate commits) move pipelines, models_gpu_, pool_, streaming_thread_, then the render/cull/encode methods. Each leaves the desktop build green. Builds: desktop / bonsai / web all green. Tests 100/100.
This commit is contained in:
@@ -20,17 +20,20 @@
|
||||
#ifndef VIEWPORTCORE_H
|
||||
#define VIEWPORTCORE_H
|
||||
|
||||
// Platform-agnostic render core. Owns the wgpu state + scene state +
|
||||
// per-frame render path. Talks to its embedder through ViewportHost
|
||||
// (window/canvas surface, scheduling, notifications) — has no Qt or
|
||||
// browser dependencies of its own.
|
||||
// Platform-agnostic render core. Owns the wgpu lifecycle state +
|
||||
// (eventually) scene state + per-frame render path. Talks to its
|
||||
// embedder through ViewportHost (window/canvas surface, scheduling,
|
||||
// notifications) — has no Qt or browser dependencies of its own.
|
||||
//
|
||||
// Empty for now: this header / TU is the placeholder for the
|
||||
// incremental Path-A refactor (#77-#86). Each subsequent commit moves
|
||||
// one subsystem out of ViewportWindow.cpp into here and updates the
|
||||
// public surface accordingly. Until that work lands, ViewportWindow
|
||||
// retains its render body; this class is just the target for the
|
||||
// move.
|
||||
// First migration target (#84-a): wgpu instance/adapter/device/queue/
|
||||
// surface ownership. The next subsystems (pipelines, models, render
|
||||
// path) move incrementally across subsequent commits — each leaving
|
||||
// the desktop build green. ViewportWindow currently holds reference
|
||||
// members pointing back at ViewportCore's storage so its body doesn't
|
||||
// have to acquire a `core_.` prefix on every wgpu touch. Those
|
||||
// references shrink as render methods themselves move over.
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#include "ViewportHost.h"
|
||||
|
||||
@@ -44,8 +47,28 @@ public:
|
||||
|
||||
ViewportHost* host() const { return host_; }
|
||||
|
||||
// Friend access for ViewportWindow's reference proxies. As each
|
||||
// render method moves into ViewportCore it stops needing these
|
||||
// (it touches the fields directly); once everything has migrated
|
||||
// the friend declaration goes away.
|
||||
friend class ViewportWindow;
|
||||
|
||||
private:
|
||||
ViewportHost* host_;
|
||||
|
||||
// ---- wgpu lifecycle state ------------------------------------------------
|
||||
//
|
||||
// Plain pointers (wgpu C handles); zero-init means "not yet
|
||||
// initialised". Owned by ViewportCore now; reference members in
|
||||
// ViewportWindow alias these so the existing call sites don't
|
||||
// need to change to use a `core_.` prefix.
|
||||
WGPUInstance instance_ = nullptr;
|
||||
WGPUAdapter adapter_ = nullptr;
|
||||
WGPUDevice device_ = nullptr;
|
||||
WGPUQueue queue_ = nullptr;
|
||||
WGPUSurface surface_ = nullptr;
|
||||
WGPUTextureFormat surface_format_ = WGPUTextureFormat_Undefined;
|
||||
bool surface_configured_ = false;
|
||||
};
|
||||
|
||||
#endif // VIEWPORTCORE_H
|
||||
|
||||
@@ -606,7 +606,19 @@ static WGPUStringView svFromCStr(const char* s) {
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ViewportWindow::ViewportWindow(QWindow* parent)
|
||||
: QWindow(parent) {
|
||||
: QWindow(parent),
|
||||
core_(this),
|
||||
// Bind reference aliases to ViewportCore's storage so the
|
||||
// existing `device_` / `queue_` / … sites in this TU keep
|
||||
// working unchanged. Each reference goes away as its owning
|
||||
// render method moves into ViewportCore.
|
||||
instance_ (core_.instance_),
|
||||
adapter_ (core_.adapter_),
|
||||
device_ (core_.device_),
|
||||
queue_ (core_.queue_),
|
||||
surface_ (core_.surface_),
|
||||
surface_format_ (core_.surface_format_),
|
||||
surface_configured_(core_.surface_configured_) {
|
||||
// wgpu doesn't need a GL context; we just need a real native window
|
||||
// whose backing layer matches the GPU API wgpu will drive.
|
||||
//
|
||||
|
||||
@@ -634,16 +634,25 @@ private:
|
||||
void recomposeAndUploadModel(uint32_t model_id);
|
||||
|
||||
bool wgpu_initialized_ = false;
|
||||
bool surface_configured_ = false;
|
||||
int configured_w_ = 0;
|
||||
int configured_h_ = 0;
|
||||
|
||||
WGPUInstance instance_ = nullptr;
|
||||
WGPUAdapter adapter_ = nullptr;
|
||||
WGPUDevice device_ = nullptr;
|
||||
WGPUQueue queue_ = nullptr;
|
||||
WGPUSurface surface_ = nullptr;
|
||||
WGPUTextureFormat surface_format_ = WGPUTextureFormat_Undefined;
|
||||
// ---- wgpu lifecycle state aliases ----------------------------------
|
||||
//
|
||||
// Actual storage lives in core_ (declared below; ViewportWindow is a
|
||||
// friend of ViewportCore so these references can bind). Existing
|
||||
// member-access sites in ViewportWindow.cpp keep working unchanged —
|
||||
// they just resolve to core_.device_ etc. through these references.
|
||||
// Each one is removed when its owning render method moves into
|
||||
// ViewportCore (#84-b onwards).
|
||||
ViewportCore core_;
|
||||
WGPUInstance& instance_;
|
||||
WGPUAdapter& adapter_;
|
||||
WGPUDevice& device_;
|
||||
WGPUQueue& queue_;
|
||||
WGPUSurface& surface_;
|
||||
WGPUTextureFormat& surface_format_;
|
||||
bool& surface_configured_;
|
||||
|
||||
// Render pipeline + bind group layouts (built once after init).
|
||||
WGPUShaderModule main_shader_module_ = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user