public sealed class WebGpuDeviceThe WebGPU device: everything the RHI can do, done twice over.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
This class contains no WebGPU calls. It talks to IWebGpuBinding, which is native Dawn or wgpu on a desktop and navigator.gpu in a browser — the two surface implementations docs/plan/05 asks for. Translation, validation, handle lifetime and command replay are therefore written once and are identical on both, and all of it is testable against a fake binding on a machine with neither.
Handles index tables this object owns. Nothing here is finalisable and nothing is reference-counted by the collector: a GPU object's lifetime belongs to the renderer.
Destruction is deferred, and WebGPU makes that easy rather than hard. Releasing a WebGPU object drops a reference; the implementation keeps the object alive until the work that names it has finished, which is exactly the guarantee Vulkan does not give. The frame-delayed retirement below is therefore belt and braces rather than the load-bearing part — and it stays, because the RHI's contract is stated in frames and a backend that quietly relied on someone else's reference counting would be one binding upgrade from being wrong.
Fields and properties (9)
public IGraphicsAdapter AdapterThe adapter this device runs on.
public GraphicsDeviceFeatures FeaturesWhat it can do.
public ICommandSubmitter GraphicsQueueThe queue that can do everything.
public ICommandSubmitter ComputeQueueThe compute queue, which is GraphicsQueue where the hardware has only one.
public ICommandSubmitter TransferQueueThe transfer queue, which is GraphicsQueue where the hardware has only one.
public int FramesInFlightHow many frames may be recorded before the first has to have finished.
public long FrameCountHow many frames BeginFrame has started.
public int LiveResourceCountHow many resources are alive, across every kind.
public const string EntryPointThe entry point every module the engine compiles exposes.
Methods (38)
public static bool TryCreate(NativeWebGpuOptions options, out WebGpuDevice? device, out string? reason)Creates a device, reporting failure rather than throwing.
public WebGpuDevice(IWebGpuBinding binding)Creates a device over a binding.
public WebGpuDevice(IWebGpuBinding binding, WebGpuDeviceOptions options)Creates a device over a binding.
public ICommandList BeginCommandList(QueueKind kind = Graphics, string name = "")Takes a command list to record into.
public void BeginFrame()Marks the start of a frame, retiring whatever the oldest in-flight frame held.
public void EndFrame()Marks the end of a frame.
public void WaitIdle()Blocks until every queue is idle.
public void Dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public PipelineHandle CreateGraphicsPipeline(in GraphicsPipelineDescription description)Compiles a graphics pipeline.
public PipelineHandle CreateComputePipeline(in ComputePipelineDescription description)Compiles a compute pipeline.
public ISwapChain CreateSwapChain(in SwapChainDescription description)Creates a swapchain for a window surface.
public QueryPoolHandle CreateQueryPool(in QueryPoolDescription description)public void Destroy(QueryPoolHandle handle)Returns a query pool.
public bool TryResolveQueries(QueryPoolHandle pool, int first, Span<ulong> results)Reads out whatever a pool's queries have answered.
public AccelerationStructureSizes GetAccelerationStructureSizes(in AccelerationStructureBuildInput input)public AccelerationStructureHandle CreateAccelerationStructure(in AccelerationStructureDescription description)Creates an acceleration structure — empty until a build fills it.
public ulong GetAccelerationStructureAddress(AccelerationStructureHandle handle)The GPU address a top-level build's instances refer to a bottom level by.
public void Destroy(AccelerationStructureHandle handle)Returns an acceleration structure.
public BufferHandle CreateBuffer(in BufferDescription description)Creates a buffer.
public TextureHandle CreateTexture(in TextureDescription description)Creates a texture.
public TextureViewHandle CreateTextureView(TextureHandle texture, PixelFormat format = Undefined, int baseMipLevel = 0, int mipLevelCount = 0, int baseArrayLayer = 0, int arrayLayerCount = 0)Creates a view of part of a texture.
public SamplerHandle CreateSampler(in SamplerDescription description)Creates a sampler.
public ShaderHandle CreateShader(ShaderStage stage, ReadOnlySpan<byte> bytecode, string name = "")public DescriptorSetLayoutHandle CreateDescriptorSetLayout(in DescriptorSetLayoutDescription description)Creates a descriptor-set layout.
public PipelineLayoutHandle CreatePipelineLayout(in PipelineLayoutDescription description)public DescriptorSetHandle CreateDescriptorSet(DescriptorSetLayoutHandle layout, string name = "")Creates a descriptor set.
public void UpdateDescriptorSet(DescriptorSetHandle descriptors, ReadOnlySpan<DescriptorWrite> writes)public void Write(BufferHandle buffer, long offset, ReadOnlySpan<byte> data)Writes into a host-visible buffer.
public void Read(BufferHandle buffer, long offset, Span<byte> destination)Reads out of a readback buffer.
public void Destroy(BufferHandle handle)Returns a buffer.
public void Destroy(TextureHandle handle)Returns a texture.
public void Destroy(TextureViewHandle handle)Returns a texture view.
public void Destroy(SamplerHandle handle)Returns a sampler.
public void Destroy(ShaderHandle handle)Returns a shader module.
public void Destroy(PipelineHandle handle)Returns a pipeline.
public void Destroy(PipelineLayoutHandle handle)Returns a pipeline layout.
public void Destroy(DescriptorSetLayoutHandle handle)Returns a descriptor-set layout.
public void Destroy(DescriptorSetHandle handle)Returns a descriptor set.
Used by (8)
- NativeWebGpuTestsVixen.Graphics.WebGPU.Tests
- WebGpuCommandListVixen.Graphics.WebGPU
- WebGpuCommandTestsVixen.Graphics.WebGPU.Tests
- WebGpuDeviceTestsVixen.Graphics.WebGPU.Tests
- WebGpuQueueVixen.Graphics.WebGPU
- WebGpuRequirementVixen.Graphics.WebGPU.Tests
- WebGpuSwapChainVixen.Graphics.WebGPU
- GraphicsHostVixen.App