webgpu improvements

This commit is contained in:
Jorijn van der Graaf 2026-05-24 13:32:08 +02:00
commit 8347467e1e
18 changed files with 1932 additions and 153 deletions

View file

@ -98,13 +98,9 @@ void UIRenderer::DispatchImages(GraphicsCommandBuffer /*cmd*/, std::uint32_t buf
if (itemCount == 0) return;
UIDispatchHeader hdr = FillHeader(bufferSlot, itemCount, clipRectPx);
auto handle = heap_->bufferTable[bufferSlot];
// For DispatchImages, the WGSL expects a texture + sampler in group 3.
// The library v1 doesn't expose user-image registration on DOM (out of
// scope per plan). If the user calls DispatchImages without a registered
// image, fall back to using the font atlas binding — the user's items
// should reference texSlot/sampSlot but on DOM those are ignored. For
// now, route through the font atlas texture if available; otherwise
// skip the dispatch.
// Backward-compatible fallback: callers that don't pass a texture
// get the font atlas. Useful for tests, useless for real content.
// New code should use the 6-arg overload below.
if (fontAtlasImageSlot_) {
auto texHandle = heap_->imageTable[fontAtlasImageSlot_];
auto sampHandle = heap_->samplerTable[fontAtlasSamplerSlot_];
@ -115,6 +111,21 @@ void UIRenderer::DispatchImages(GraphicsCommandBuffer /*cmd*/, std::uint32_t buf
}
}
void UIRenderer::DispatchImages(GraphicsCommandBuffer /*cmd*/, std::uint32_t bufferSlot,
std::uint32_t itemCount,
std::uint16_t imageSlot, std::uint16_t samplerSlot,
std::array<float,4> clipRectPx) {
if (itemCount == 0) return;
UIDispatchHeader hdr = FillHeader(bufferSlot, itemCount, clipRectPx);
auto handle = heap_->bufferTable[bufferSlot];
auto texHandle = heap_->imageTable[imageSlot];
auto sampHandle = heap_->samplerTable[samplerSlot];
WebGPU::wgpuDispatchImages(handle, &hdr,
static_cast<std::int32_t>(TilesFor(window_->width)),
static_cast<std::int32_t>(TilesFor(window_->height)),
texHandle, sampHandle);
}
void UIRenderer::DispatchText(GraphicsCommandBuffer /*cmd*/, std::uint32_t bufferSlot,
std::uint32_t itemCount,
std::array<float,4> clipRectPx) {
@ -168,6 +179,7 @@ void UIRenderer::Dispatch(GraphicsCommandBuffer /*cmd*/, const GraphicsComputeSh
case UICustomBindingKind::Sampler:
if (slot < heap_->samplerTable.size()) handle = heap_->samplerTable[slot];
break;
default: break;
}
handles.push_back(handle);
}