sysgpu: supersede WebGPU with new sysgpu graphics API
This is a tracking issue for ongoing development of Dusk. Dusk started as a WGPU implementation (and is one today) but is being developed beyond that, into a new graphics API called DGPU. We are making some key changes to the WGPU API, for specific reasons, and this issue is for tracking those changes / decisions.
Proposals / decisions made:
- WebGPU API divergences
- ✅ Native render graph support
- ✅ Remove
next_in_chain - ✅ All Mach and Dawn extensions become non-extensions (just become part of the API) if desirable
- ✅ D3D StructuredBuffers
- ✅ Streaming Uniforms
- Shading language divergences
- ✅ Remove WGSL support in favor of Zig-inspired shading language
- ✅ Explicit adapter enumeration/selection
- Goals
- ✅ First-class C API support
- ✅ Ability to intercept API calls / wrap implementation in Zig (like
gpu.Interface) - ✅ Backends:
- Direct3D 12
- Vulkan (1.0?)
- Metal
- WebGPU (Dawn native fallback, browser)
Things worth considering if we can improve:
- The
autolayout footgun discord bufferGetMappedRangereturningnullwith no error string / explanation of why- Removing
arrayLength - Binding model / default pipeline layout
- Remove mapAsync entirely if we can cover the same use-cases other ways
- We've talked through upload cases that I think are good enough to remove it. Readback will need some way for the application to know its done.
- Introduce fences / application level synchronization? e.g. this
- Replace
getCurrentTextureViewwith something that allows for e.g. 2 frames in flight/3 swap chain buffers. - Having to write code like this is a bit painful/ugly
- Replace
- Enable waitable swap chains with different frame count than buffer count (Intel article for details)
Will Mach still run in browsers that only support native WGPU?
Yes, DGPU will have a WebGPU backend
Two changes I would like to add to the list:
D3D StructuredBuffers
- WebGPU implementation requires use of ByteAddressBuffer
- StructuredBuffer is faster on many GPUs (see https://github.com/sebbbi/perftest) but requires stride be specified in the binding layout
Streaming Uniforms
- WebGPU cannot make use of Push/Root Constants or Metal set buffer bytes (although this is being discussed as an explicit feature for later versions)
- We can expose a higher-level API for updating uniforms on the encoder
- This simplifies application use (no need to manage dynamic offsets on bind groups) and enables use of these features in the backend
Vertex/Fragment linkage
HLSL vertex-fragment linkage requires stage variables to be in the same order, and all variables in the later stage must be present in the earlier stage. When HLSL is generated at pipeline generation time, input/output structs can be sorted and unused vertex outputs eliminated. Offline compilation will require the shaders to match.
Optional Input Assembler
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT should not be passed for root signatures unless needed. Add a flag to PipelineLayout to indicate that vertex buffers are used by the pipeline.
MSAA Depth Resolve
Add support for MSAA depth targets in render passes