|
|
Donner SVG 0.8.0-pre
SVG editor and embeddable C++20 engine.
|
Abstract GPU device: resource creation, queue writes, and submission with shared fail-closed validation. More...
#include "donner/gpu/Device.h"
Classes | |
| struct | MapWaitTestHooks |
| Waits for a pending mapping in slices, until it completes, the caller stops it, the budget runs out, or the device is lost. More... | |
Public Member Functions | |
| virtual | ~Device () |
| Destructor; expires the device-alive token (so handles that outlive the device release nothing) and frees all remaining resources. Backends that submit asynchronously must wait for in-flight submissions in their own destructor before backend state is torn down. | |
| Device (const Device &)=delete | |
| Device & | operator= (const Device &)=delete |
| Device (Device &&)=delete | |
| Device & | operator= (Device &&)=delete |
| uint64_t | deviceId () const |
| Process-unique identity of this device (starts at 1, never reused). Baked into every handle for cross-device validation. | |
| Result< Buffer > | createBuffer (const BufferDescriptor &descriptor) |
| Creates a buffer. | |
| Result< Texture > | createTexture (const TextureDescriptor &descriptor) |
| Creates a 2D texture. | |
| Result< TextureView > | createTextureView (const Texture &texture, const TextureViewDescriptor &descriptor) |
Creates a view of texture covering the whole texture. | |
| Result< Sampler > | createSampler (const SamplerDescriptor &descriptor) |
| Creates a sampler. | |
| Result< BindGroupLayout > | createBindGroupLayout (const BindGroupLayoutDescriptor &descriptor) |
| Creates a bind group layout. | |
| Result< BindGroup > | createBindGroup (const BindGroupDescriptor &descriptor) |
| Creates a bind group. | |
| Result< PipelineLayout > | createPipelineLayout (const PipelineLayoutDescriptor &descriptor) |
| Creates a pipeline layout. | |
| Result< ShaderModule > | createShaderModule (const ShaderModuleDescriptor &descriptor) |
| Creates a shader module from trusted generated source. | |
| Result< RenderPipeline > | createRenderPipeline (const RenderPipelineDescriptor &descriptor) |
| Creates a render pipeline. | |
| Result< ComputePipeline > | createComputePipeline (const ComputePipelineDescriptor &descriptor) |
| Creates a compute pipeline. | |
| Status | destroyBuffer (Buffer &&buffer) |
| Destroys a buffer (see the destroy contract above). | |
| Status | destroyTexture (Texture &&texture) |
| Destroys a texture (see the destroy contract above). | |
| Status | destroyTextureView (TextureView &&textureView) |
| Destroys a texture view (see the destroy contract above). | |
| Status | destroySampler (Sampler &&sampler) |
| Destroys a sampler (see the destroy contract above). | |
| Status | destroyBindGroupLayout (BindGroupLayout &&bindGroupLayout) |
| Destroys a bind group layout (see the destroy contract above). | |
| Status | destroyBindGroup (BindGroup &&bindGroup) |
| Destroys a bind group (see the destroy contract above). | |
| Status | destroyPipelineLayout (PipelineLayout &&pipelineLayout) |
| Destroys a pipeline layout (see the destroy contract above). | |
| Status | destroyShaderModule (ShaderModule &&shaderModule) |
| Destroys a shader module (see the destroy contract above). | |
| Status | destroyRenderPipeline (RenderPipeline &&renderPipeline) |
| Destroys a render pipeline (see the destroy contract above). | |
| Status | destroyComputePipeline (ComputePipeline &&computePipeline) |
| Destroys a compute pipeline (see the destroy contract above). | |
| Result< std::unique_ptr< CommandEncoder > > | createCommandEncoder () |
| Creates a command encoder recording against this device. The encoder must not outlive the device. | |
| Result< Surface > | createSurface (const SurfaceDescriptor &descriptor) |
| Creates a surface presenting to a platform object. | |
| Result< SurfaceCapabilities > | surfaceCapabilities (const Surface &surface) const |
What surface supports, for choosing a configuration. | |
| Status | configureSurface (const Surface &surface, const SurfaceConfiguration &configuration) |
Configures how surface presents, replacing any previous configuration. | |
| Result< SurfaceTexture > | acquireCurrentTexture (const Surface &surface) |
Acquires the texture for the next frame of surface. | |
| Result< SurfaceStatus > | presentSurface (const Surface &surface) |
Presents the texture acquired from surface and invalidates it. | |
| Status | abandonCurrentTexture (const Surface &surface) |
Releases the acquired texture of surface without presenting it, for a frame the caller decided not to show. | |
| Status | destroySurface (Surface &&surface) |
| Destroys a surface (see the destroy contract above). | |
| Result< BufferMapping > | mapBufferAsync (const Buffer &buffer, MapMode mode, uint64_t offsetBytes, uint64_t byteCount) |
Begins mapping a range of buffer for host access, and returns the handle that names the mapping. | |
| Result< MapWaitOutcome > | waitForMapping (const BufferMapping &mapping, const MapWaitParams ¶ms, const std::function< bool()> &shouldCancel, const MapWaitTestHooks &testHooks={}) |
| Result< std::span< const uint8_t > > | mappedBytes (const BufferMapping &mapping) const |
| Returns the mapped bytes of a completed mapping. | |
| Status | unmapBuffer (BufferMapping &&mapping) |
| Releases a mapping, invalidating the handle and every copy of it. | |
| Status | writeBuffer (const Buffer &buffer, uint64_t offsetBytes, std::span< const uint8_t > data) |
Writes data into buffer at offsetBytes. | |
| Status | writeTexture (const Texture &texture, std::span< const uint8_t > data, const TexelCopyBufferLayout &dataLayout, const Extent2d &writeSize) |
Writes texel rows from data into texture starting at texel (0, 0). | |
| Result< uint64_t > | submit (CommandBuffer commandBuffer) |
| Submits a finished command buffer, consuming it, and returns the assigned submission serial. | |
| void | poll () |
| Processes deferred destructions: releases the backend object of every destroyed resource whose last referencing submission has completed (completedSerial), and recycles its slot. | |
| uint64_t | lastSubmittedSerial () const |
| Serial assigned to the most recent submission (0 if none yet). | |
| virtual uint64_t | completedSerial () const =0 |
| Serial of the most recent submission the backend has finished executing (0 if none). The recording backend completes instantly, so this equals lastSubmittedSerial there. | |
Protected Member Functions | |
| Device () | |
| Constructor for backends; assigns the process-unique device identity. | |
| virtual Status | onCreateBuffer (uint32_t slotIndex, const BufferDescriptor &descriptor)=0 |
Backend hook: a buffer passed validation and occupies slotIndex. | |
| virtual Status | onCreateTexture (uint32_t slotIndex, const TextureDescriptor &descriptor)=0 |
Backend hook: a texture passed validation and occupies slotIndex. | |
| virtual Status | onCreateTextureView (uint32_t slotIndex, uint32_t textureSlotIndex, const TextureViewDescriptor &descriptor)=0 |
Backend hook: a texture view passed validation and occupies slotIndex. | |
| virtual Status | onCreateSampler (uint32_t slotIndex, const SamplerDescriptor &descriptor)=0 |
Backend hook: a sampler passed validation and occupies slotIndex. | |
| virtual Status | onCreateBindGroupLayout (uint32_t slotIndex, const BindGroupLayoutDescriptor &descriptor)=0 |
Backend hook: a bind group layout passed validation and occupies slotIndex. | |
| virtual Status | onCreateBindGroup (uint32_t slotIndex, const BindGroupDescriptor &descriptor)=0 |
Backend hook: a bind group passed validation and occupies slotIndex. | |
| virtual Status | onCreatePipelineLayout (uint32_t slotIndex, const PipelineLayoutDescriptor &descriptor)=0 |
Backend hook: a pipeline layout passed validation and occupies slotIndex. | |
| virtual Status | onCreateShaderModule (uint32_t slotIndex, const ShaderModuleDescriptor &descriptor)=0 |
Backend hook: a shader module passed validation and occupies slotIndex. | |
| virtual Status | onCreateRenderPipeline (uint32_t slotIndex, const RenderPipelineDescriptor &descriptor)=0 |
Backend hook: a render pipeline passed validation and occupies slotIndex. | |
| virtual Status | onCreateComputePipeline (uint32_t slotIndex, const ComputePipelineDescriptor &descriptor)=0 |
Backend hook: a compute pipeline passed validation and occupies slotIndex. | |
| virtual void | onDestroyResource (std::string_view resourceName, uint32_t slotIndex)=0 |
| Backend hook: a validated resource was destroyed. | |
| virtual Status | onWriteBuffer (uint32_t slotIndex, uint64_t offsetBytes, std::span< const uint8_t > data)=0 |
| Backend hook: a validated buffer write. | |
| virtual Status | onWriteTexture (uint32_t slotIndex, std::span< const uint8_t > data, const TexelCopyBufferLayout &dataLayout, const Extent2d &writeSize)=0 |
| Backend hook: a validated texture write. | |
| Status | validateBufferHandleForBackend (const Buffer &buffer) const |
| Validates a buffer handle for backend-provided auxiliary entry points (test readback helpers and similar), running the same null/device-identity/generation checks the template-method public API performs before its hooks. | |
| Status | validateTextureHandleForBackend (const Texture &texture) const |
| Validates a texture handle for backend-provided auxiliary entry points, running the same null/device-identity/generation checks the template-method public API performs. | |
| Status | validateTextureViewHandleForBackend (const TextureView &textureView) const |
| Validates a texture view handle for backend-provided auxiliary entry points: the view itself plus a re-resolution of its viewed texture, so a view of a destroyed (or slot-recycled) texture fails closed exactly like it does on the normal Device paths. | |
| Status | validateBufferMappingHandleForBackend (const BufferMapping &mapping) const |
| Validates a buffer-mapping handle for backend-provided auxiliary entry points, running the same null/device-identity/generation checks the template-method public API performs, so a stale handle cannot read state belonging to the slot's new occupant. | |
| virtual Status | onMapBufferAsync (uint32_t mappingSlotIndex, uint32_t bufferSlotIndex, MapMode mode, uint64_t offsetBytes, uint64_t byteCount) |
| Backend hook: begin mapping a buffer range. | |
| virtual MapSliceState | onWaitMappingSlice (uint32_t mappingSlotIndex, double sliceSeconds) |
Backend hook: wait up to sliceSeconds for a pending mapping and report what it found. | |
| virtual Result< std::span< const uint8_t > > | onMappedBytes (uint32_t mappingSlotIndex) const |
| Backend hook: bytes of a completed mapping. | |
| virtual void | onUnmapBuffer (uint32_t mappingSlotIndex) |
| Backend hook: release a mapping. | |
| virtual Status | onCreateSurface (uint32_t slotIndex, const SurfaceDescriptor &descriptor) |
| Backend hook: create a surface for a platform object. | |
| virtual Result< SurfaceCapabilities > | onSurfaceCapabilities (uint32_t slotIndex) const |
| Backend hook: what a surface supports. | |
| virtual Status | onConfigureSurface (uint32_t slotIndex, const SurfaceConfiguration &configuration) |
| Backend hook: apply a configuration. | |
| virtual Result< SurfaceStatus > | onAcquireCurrentTexture (uint32_t slotIndex, uint32_t textureSlotIndex) |
| Backend hook: acquire the next frame's texture and report the surface's state. | |
| virtual Result< SurfaceStatus > | onPresentSurface (uint32_t slotIndex) |
| Backend hook: present the acquired texture. | |
| virtual void | onAbandonCurrentTexture (uint32_t slotIndex) |
| Backend hook: drop the acquired texture without presenting. | |
| virtual Status | onSubmit (uint64_t submissionSerial, uint32_t commandBufferSlotIndex, std::span< const Command > commands)=0 |
| Backend hook: a validated command buffer was submitted. | |
Friends | |
| class | CommandEncoder |
Abstract GPU device: resource creation, queue writes, and submission with shared fail-closed validation.
The public API is non-virtual and validates every descriptor, handle, and byte range before delegating to protected on* virtuals (template-method pattern), so every backend - the deterministic RecordingDevice and the platform backends - inherits identical fail-closed behavior. Validation runs in release builds too: invalid input returns a GpuError, never asserts.
Enforced limits are documented in GpuLimits.h. Handle validation checks device identity (GpuErrorType::DeviceMismatch) and slot generation (GpuErrorType::InvalidHandle), so destroyed or foreign handles fail before reaching a backend.
Lifetime: handles are move-only RAII - dropping a live handle releases the resource, an explicit destroy*(std::move(handle)) call releases it early and reports errors, and device teardown frees everything that remains. A handle that outlives its device releases nothing (its device-alive token has expired). Destruction is deferred by submission serial: destroying a resource makes its handles and references stale immediately, but the backend object is kept alive - and its slot is not reused - until every submission referencing it has completed (completedSerial). Deferred backend releases are processed by poll and opportunistically by destroy* and submit.
Two resource kinds are intentionally exempt from submission pinning because commands never reference them: PipelineLayout and ShaderModule are consumed at pipeline creation only, so destroying one releases its backend object immediately. Backends must snapshot or retain whatever they need from them when the pipeline is created (Metal's compiled pipeline state retains its functions; the Vulkan backend must do the equivalent when it lands).
Thread affinity: a Device and everything created from it must be used from one thread at a time, matching the async-renderer worker ownership model.
| struct donner::gpu::Device::MapWaitTestHooks |
Waits for a pending mapping in slices, until it completes, the caller stops it, the budget runs out, or the device is lost.
shouldCancel is consulted before each slice, so a caller that changes its mind stops within one slice rather than at the end of the budget. Device loss ends the wait immediately: the mapping can never complete afterwards, and reporting it as a timeout would describe a permanent failure as a slow one.
| mapping | Live mapping of this device. |
| params | Slice length and total budget; both must be greater than zero. |
| shouldCancel | Consulted before each slice; may be empty for an uncancellable wait. Test seam for waitForMapping. Production callers pass none; a test injects a clock and a rest so a budget is verified deterministically and without spending it. |
Releases the acquired texture of surface without presenting it, for a frame the caller decided not to show.
| surface | Live surface with an acquired texture. |
| Result< SurfaceTexture > donner::gpu::Device::acquireCurrentTexture | ( | const Surface & | surface | ) |
Acquires the texture for the next frame of surface.
The texture is valid until the matching presentSurface, abandonCurrentTexture, or a reconfiguration - each of those invalidates it, so drawing into a presented texture is a reported validation failure rather than a write to a texture the platform now owns.
A non-success status can still come with a usable texture: a surface that has drifted out of date usually still presents, so the caller decides between drawing this frame and reconfiguring first.
| surface | Live, configured surface. |
|
pure virtual |
Serial of the most recent submission the backend has finished executing (0 if none). The recording backend completes instantly, so this equals lastSubmittedSerial there.
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
| Status donner::gpu::Device::configureSurface | ( | const Surface & | surface, |
| const SurfaceConfiguration & | configuration ) |
Configures how surface presents, replacing any previous configuration.
This is how a surface follows its window: a resize reconfigures with the new extent rather than creating a new surface, and it is the recovery from SurfaceStatus::Outdated. Reconfiguring abandons any texture currently acquired from the surface.
| surface | Live surface. |
| configuration | Format, usage, extent, pacing and alpha compositing. |
| Result< BindGroup > donner::gpu::Device::createBindGroup | ( | const BindGroupDescriptor & | descriptor | ) |
Creates a bind group.
Fails closed unless every layout binding is matched by exactly one entry whose resource is live, belongs to this device, matches the layout's BindingType, and carries the usage that binding type requires.
| descriptor | Validated bind group descriptor. |
| Result< BindGroupLayout > donner::gpu::Device::createBindGroupLayout | ( | const BindGroupLayoutDescriptor & | descriptor | ) |
Creates a bind group layout.
Fails closed on duplicate binding indices, out-of-limit binding counts or indices, or empty per-entry visibility.
| descriptor | Validated layout descriptor. |
| Result< Buffer > donner::gpu::Device::createBuffer | ( | const BufferDescriptor & | descriptor | ) |
Creates a buffer.
Fails closed on zero or oversized byteSize or empty usage.
| descriptor | Validated buffer descriptor. |
| Result< ComputePipeline > donner::gpu::Device::createComputePipeline | ( | const ComputePipelineDescriptor & | descriptor | ) |
Creates a compute pipeline.
Fails closed on invalid layout/module references, an empty entry point, or a workgroup size that is zero in any dimension, exceeds a per-axis cap, or declares more than kMaxComputeInvocationsPerWorkgroup invocations.
| descriptor | Validated pipeline descriptor. |
| Result< PipelineLayout > donner::gpu::Device::createPipelineLayout | ( | const PipelineLayoutDescriptor & | descriptor | ) |
Creates a pipeline layout.
Fails closed on out-of-limit group counts or invalid layout references.
| descriptor | Validated pipeline layout descriptor. |
| Result< RenderPipeline > donner::gpu::Device::createRenderPipeline | ( | const RenderPipelineDescriptor & | descriptor | ) |
Creates a render pipeline.
Fails closed on invalid layout/module references, empty entry points, vertex attributes that overflow their stride, duplicate shader locations, empty or out-of-limit target lists, or multisampleCount != 1.
| descriptor | Validated pipeline descriptor. |
| Result< Sampler > donner::gpu::Device::createSampler | ( | const SamplerDescriptor & | descriptor | ) |
Creates a sampler.
| descriptor | Validated sampler descriptor. |
| Result< ShaderModule > donner::gpu::Device::createShaderModule | ( | const ShaderModuleDescriptor & | descriptor | ) |
Creates a shader module from trusted generated source.
Fails closed on empty source text.
| descriptor | Validated shader module descriptor. |
| Result< Surface > donner::gpu::Device::createSurface | ( | const SurfaceDescriptor & | descriptor | ) |
Creates a surface presenting to a platform object.
The surface is not usable until configureSurface succeeds: a surface knows what it presents to, and a configuration knows how.
| descriptor | Label and platform object to present to. |
| Result< Texture > donner::gpu::Device::createTexture | ( | const TextureDescriptor & | descriptor | ) |
Creates a 2D texture.
Fails closed on zero or oversized extents, empty usage, or sampleCount != 1.
| descriptor | Validated texture descriptor. |
| Result< TextureView > donner::gpu::Device::createTextureView | ( | const Texture & | texture, |
| const TextureViewDescriptor & | descriptor ) |
Creates a view of texture covering the whole texture.
| texture | Texture to view; must be a live handle of this device. |
| descriptor | Validated view descriptor. |
Destroys a bind group (see the destroy contract above).
| bindGroup | Handle to destroy. |
| Status donner::gpu::Device::destroyBindGroupLayout | ( | BindGroupLayout && | bindGroupLayout | ) |
Destroys a bind group layout (see the destroy contract above).
| bindGroupLayout | Handle to destroy. |
Destroys a buffer (see the destroy contract above).
| buffer | Handle to destroy. |
| Status donner::gpu::Device::destroyComputePipeline | ( | ComputePipeline && | computePipeline | ) |
Destroys a compute pipeline (see the destroy contract above).
| computePipeline | Handle to destroy. |
| Status donner::gpu::Device::destroyPipelineLayout | ( | PipelineLayout && | pipelineLayout | ) |
Destroys a pipeline layout (see the destroy contract above).
| pipelineLayout | Handle to destroy. |
| Status donner::gpu::Device::destroyRenderPipeline | ( | RenderPipeline && | renderPipeline | ) |
Destroys a render pipeline (see the destroy contract above).
| renderPipeline | Handle to destroy. |
Destroys a sampler (see the destroy contract above).
| sampler | Handle to destroy. |
| Status donner::gpu::Device::destroyShaderModule | ( | ShaderModule && | shaderModule | ) |
Destroys a shader module (see the destroy contract above).
| shaderModule | Handle to destroy. |
Destroys a surface (see the destroy contract above).
| surface | Handle to destroy. |
Destroys a texture (see the destroy contract above).
| texture | Handle to destroy. |
| Status donner::gpu::Device::destroyTextureView | ( | TextureView && | textureView | ) |
Destroys a texture view (see the destroy contract above).
| textureView | Handle to destroy. |
| Result< BufferMapping > donner::gpu::Device::mapBufferAsync | ( | const Buffer & | buffer, |
| MapMode | mode, | ||
| uint64_t | offsetBytes, | ||
| uint64_t | byteCount ) |
Begins mapping a range of buffer for host access, and returns the handle that names the mapping.
The mapping is not readable yet: waitForMapping decides when it is. The returned handle is what keeps the mapped range reachable - unmapBuffer consumes it and every copy of it goes stale at that moment, so a read through a handle whose mapping has been released is a reported validation failure rather than a read of memory that is no longer there.
| buffer | Buffer to map; needs BufferUsage::MapRead. |
| mode | How the host will access the range. |
| offsetBytes | Byte offset of the mapped range. |
| byteCount | Length of the mapped range; must be nonzero and fit the buffer. |
| Result< std::span< const uint8_t > > donner::gpu::Device::mappedBytes | ( | const BufferMapping & | mapping | ) | const |
Returns the mapped bytes of a completed mapping.
Fails closed when the mapping is stale, belongs to another device, or has not completed: the span is only valid while the handle names a live, ready mapping.
| mapping | Live, completed mapping of this device. |
|
protectedvirtual |
Backend hook: drop the acquired texture without presenting.
| slotIndex | Slot of the surface. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedvirtual |
Backend hook: acquire the next frame's texture and report the surface's state.
| slotIndex | Slot of the surface. |
| textureSlotIndex | Slot the runtime allocated for the acquired texture. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedvirtual |
Backend hook: apply a configuration.
| slotIndex | Slot of the surface. |
| configuration | Configuration to apply. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedpure virtual |
Backend hook: a bind group passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a bind group layout passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a buffer passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a compute pipeline passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a pipeline layout passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a render pipeline passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a sampler passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a shader module passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedvirtual |
Backend hook: create a surface for a platform object.
Defaults to reporting presentation as unsupported, so a backend that cannot present needs no implementation.
| slotIndex | Slot the surface occupies. |
| descriptor | Label and platform object. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedpure virtual |
Backend hook: a texture passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a texture view passed validation and occupies slotIndex.
| slotIndex | Slot index of the new resource. |
| textureSlotIndex | Slot index of the viewed texture. |
| descriptor | Validated descriptor. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a validated resource was destroyed.
| resourceName | Resource type name, e.g. "buffer". |
| slotIndex | Slot index of the destroyed resource. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedvirtual |
Backend hook: begin mapping a buffer range.
Defaults to reporting the capability as unsupported, so a backend without host mapping needs no implementation and callers get a clean unsupported result rather than a missing symbol.
| mappingSlotIndex | Slot the mapping occupies. |
| bufferSlotIndex | Slot of the buffer being mapped. |
| mode | How the host will access the range. |
| offsetBytes | Byte offset of the mapped range. |
| byteCount | Length of the mapped range. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedvirtual |
Backend hook: bytes of a completed mapping.
| mappingSlotIndex | Slot of the mapping. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedvirtual |
Backend hook: present the acquired texture.
| slotIndex | Slot of the surface. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedpure virtual |
Backend hook: a validated command buffer was submitted.
| submissionSerial | Serial assigned to this submission. |
| commandBufferSlotIndex | Slot the command buffer occupied before being consumed. |
| commands | Validated commands, in recording order. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedvirtual |
Backend hook: what a surface supports.
| slotIndex | Slot of the surface. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedvirtual |
Backend hook: release a mapping.
| mappingSlotIndex | Slot of the mapping. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedvirtual |
Backend hook: wait up to sliceSeconds for a pending mapping and report what it found.
The runtime owns the deadline and the caller's cancellation; this reports only the mapping.
| mappingSlotIndex | Slot of the pending mapping. |
| sliceSeconds | Longest this call may block. |
Reimplemented in donner::geode::GeodeWgpuAdapterDevice.
|
protectedpure virtual |
Backend hook: a validated buffer write.
| slotIndex | Destination buffer slot. |
| offsetBytes | Destination byte offset. |
| data | Payload bytes. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
|
protectedpure virtual |
Backend hook: a validated texture write.
| slotIndex | Destination texture slot. |
| data | Payload bytes. |
| dataLayout | Row layout of data. |
| writeSize | Extent written in texels. |
Implemented in donner::geode::GeodeWgpuAdapterDevice, donner::gpu::metal::MetalDevice, donner::gpu::RecordingDevice, and donner::gpu::vulkan::VulkanDevice.
| void donner::gpu::Device::poll | ( | ) |
Processes deferred destructions: releases the backend object of every destroyed resource whose last referencing submission has completed (completedSerial), and recycles its slot.
Called opportunistically by destroy* and submit; call it directly after waiting for completion to reclaim resources promptly.
| Result< SurfaceStatus > donner::gpu::Device::presentSurface | ( | const Surface & | surface | ) |
Presents the texture acquired from surface and invalidates it.
Not every platform lets a caller present: where the host drives its own frame loop, the frame appears when the host shows it, and asking to present is rejected rather than performed. Such a surface still acquires and still invalidates its texture at the end of the frame through abandonCurrentTexture.
| surface | Live surface with an acquired texture. |
| Result< uint64_t > donner::gpu::Device::submit | ( | CommandBuffer | commandBuffer | ) |
Submits a finished command buffer, consuming it, and returns the assigned submission serial.
Serials start at 1 and increase by 1 per submission; a submission rejected here or by the backend does not consume a serial.
Every resource a recorded command references - including bind-group entry resources and the textures behind attachment and entry views - is re-validated against its recorded (slot, generation) identity, so a resource destroyed between recording and submission fails closed with GpuErrorType::InvalidHandle instead of reaching a backend. On success those resources are marked in-use by the new serial, which defers their backend destruction until the submission completes.
| commandBuffer | Command buffer to submit; consumed even on failure. |
| Result< SurfaceCapabilities > donner::gpu::Device::surfaceCapabilities | ( | const Surface & | surface | ) | const |
What surface supports, for choosing a configuration.
| surface | Live surface. |
| Status donner::gpu::Device::unmapBuffer | ( | BufferMapping && | mapping | ) |
Releases a mapping, invalidating the handle and every copy of it.
| mapping | Mapping to release; consumed either way (see the destroy contract above). |
Validates a buffer handle for backend-provided auxiliary entry points (test readback helpers and similar), running the same null/device-identity/generation checks the template-method public API performs before its hooks.
| buffer | Handle to validate. |
|
protected |
Validates a buffer-mapping handle for backend-provided auxiliary entry points, running the same null/device-identity/generation checks the template-method public API performs, so a stale handle cannot read state belonging to the slot's new occupant.
| mapping | Handle to validate. |
|
protected |
Validates a texture handle for backend-provided auxiliary entry points, running the same null/device-identity/generation checks the template-method public API performs.
| texture | Handle to validate. |
|
protected |
| Status donner::gpu::Device::writeBuffer | ( | const Buffer & | buffer, |
| uint64_t | offsetBytes, | ||
| std::span< const uint8_t > | data ) |
Writes data into buffer at offsetBytes.
Fails closed if the range does not fit (checked arithmetic) or the buffer lacks BufferUsage::CopyDst.
| buffer | Destination buffer. |
| offsetBytes | Destination byte offset. |
| data | Payload bytes. |
| Status donner::gpu::Device::writeTexture | ( | const Texture & | texture, |
| std::span< const uint8_t > | data, | ||
| const TexelCopyBufferLayout & | dataLayout, | ||
| const Extent2d & | writeSize ) |
Writes texel rows from data into texture starting at texel (0, 0).
Fails closed unless the texture has TextureUsage::CopyDst, dataLayout is 256-aligned and covers writeSize, writeSize fits in the texture, and the described rows fit inside data (checked arithmetic).
| texture | Destination texture. |
| data | Payload bytes laid out per dataLayout. |
| dataLayout | Row layout of data. |
| writeSize | Extent to write in texels. |