From dedf6b04671efbe35ecf9d77749d172047229f65 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Mon, 18 May 2026 04:58:52 +0200 Subject: [PATCH] webgpu support --- additional/dom-webgpu.js | 751 ++++++++++++++++++ examples/HelloDom/serve.sh | 2 - examples/HelloUI/main.cpp | 36 +- examples/HelloUI/project.cpp | 17 + .../Crafter.Graphics-FontAtlas.cpp | 62 +- .../Crafter.Graphics-UI-Shared.cpp | 86 ++ .../Crafter.Graphics-UI-WebGPU.cpp | 140 ++++ implementations/Crafter.Graphics-UI.cpp | 80 +- implementations/Crafter.Graphics-Window.cpp | 65 +- ...Crafter.Graphics-DescriptorHeapWebGPU.cppm | 185 +++++ interfaces/Crafter.Graphics-Font.cppm | 15 +- interfaces/Crafter.Graphics-FontAtlas.cppm | 65 +- .../Crafter.Graphics-GraphicsTypes.cppm | 42 + interfaces/Crafter.Graphics-RenderPass.cppm | 9 +- interfaces/Crafter.Graphics-UI.cppm | 175 ++-- interfaces/Crafter.Graphics-UIComponents.cppm | 6 - interfaces/Crafter.Graphics-WebGPU.cppm | 75 ++ interfaces/Crafter.Graphics-WebGPUBuffer.cppm | 85 ++ .../Crafter.Graphics-WebGPUComputeShader.cppm | 25 + interfaces/Crafter.Graphics-Window.cppm | 26 +- interfaces/Crafter.Graphics.cppm | 5 + project.cpp | 26 +- 22 files changed, 1655 insertions(+), 323 deletions(-) create mode 100644 additional/dom-webgpu.js delete mode 100755 examples/HelloDom/serve.sh create mode 100644 implementations/Crafter.Graphics-UI-Shared.cpp create mode 100644 implementations/Crafter.Graphics-UI-WebGPU.cpp create mode 100644 interfaces/Crafter.Graphics-DescriptorHeapWebGPU.cppm create mode 100644 interfaces/Crafter.Graphics-GraphicsTypes.cppm create mode 100644 interfaces/Crafter.Graphics-WebGPU.cppm create mode 100644 interfaces/Crafter.Graphics-WebGPUBuffer.cppm create mode 100644 interfaces/Crafter.Graphics-WebGPUComputeShader.cppm diff --git a/additional/dom-webgpu.js b/additional/dom-webgpu.js new file mode 100644 index 0000000..81eafe3 --- /dev/null +++ b/additional/dom-webgpu.js @@ -0,0 +1,751 @@ +/* +Crafter.Graphics WebGPU bridge — DOM mode UI compute pipeline. + +Surface model (high-level, deliberately not 1:1 with WebGPU): + - JS owns the GPUDevice/queue/compute pipelines/bind-group cache. + - C++ owns slot allocation and per-frame logic; it calls into ~15 imports. + - Standard UI shaders are embedded as WGSL strings at the bottom of this + file and compiled once at startup. + +Ping-pong output strategy (per Decision 2 in plan): + - Two rgba8unorm storage textures sized to the canvas. + - Each Dispatch reads `prev` (sampled), writes `out` (storage, write-only). + - JS swaps the two between dispatches, so item-order overdraw works. + - At frame end, the current `out` is blitted to the canvas via + copyTextureToTexture (canvas configured as rgba8unorm to match). + +This file is loaded as