webgpu support

This commit is contained in:
Jorijn van der Graaf 2026-05-18 04:58:52 +02:00
commit dedf6b0467
22 changed files with 1656 additions and 324 deletions

View file

@ -50,6 +50,10 @@ import std;
import :Types;
import :Keys;
import Crafter.Event;
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
import :WebGPU;
import :DescriptorHeapWebGPU;
#endif
export namespace Crafter {
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
@ -61,6 +65,9 @@ export namespace Crafter {
};
struct RenderPass;
struct DescriptorHeapVulkan;
#else
struct RenderPass;
struct DescriptorHeapWebGPU;
#endif
struct Window {
@ -242,12 +249,21 @@ export namespace Crafter {
DescriptorHeapVulkan* descriptorHeap = nullptr;
std::optional<std::array<float, 4>> clearColor;
#else
// DOM mode: the page IS the window. `numFrames` stays as a public
// constant so cross-platform code can refer to Window::numFrames
// without #ifdef'ing the reference; nothing else lives here yet.
// V2 (WebGPU compute) will hang its GPUContext / swapchain texture
// members off this branch.
// DOM mode: the page IS the window. WebGPU device and canvas are
// owned JS-side (see additional/dom-webgpu.js); this struct just
// holds the per-Window state Crafter::Window users expect:
// a list of render passes and a pointer to the descriptor heap.
static constexpr std::uint8_t numFrames = 1;
std::uint32_t currentBuffer = 0;
std::vector<RenderPass*> passes;
DescriptorHeapWebGPU* descriptorHeap = nullptr;
std::optional<std::array<float, 4>> clearColor;
// DOM-mode StartInit/FinishInit are no-ops returning an opaque
// command-buffer marker so cross-platform user code (HelloUI's
// `auto init = window.StartInit();`) compiles unchanged.
WebGPUCommandEncoderRef StartInit();
void FinishInit();
#endif
};
}