Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
donner::gpu::CommandEncoder Class Reference

Records and validates GPU commands for one command buffer (design 0053 "Command model"). More...

#include "donner/gpu/CommandEncoder.h"

Public Member Functions

 CommandEncoder (const CommandEncoder &)=delete
CommandEncoder & operator= (const CommandEncoder &)=delete
 CommandEncoder (CommandEncoder &&)=delete
CommandEncoder & operator= (CommandEncoder &&)=delete
 ~CommandEncoder ()=default
 Destructor. Discards recorded commands unless finish transferred them.
Result< RenderPassEncoder * > beginRenderPass (const RenderPassDescriptor &descriptor)
 Begins a render pass and returns its pass encoder.
Status copyTextureToBuffer (const TexelCopyTextureInfo &source, const Buffer &destination, const TexelCopyBufferLayout &destinationLayout, const Extent2d &copySize)
 Records a texture-to-buffer copy (readback staging).
Result< CommandBufferfinish ()
 Finishes recording and registers the command buffer with the device.

Friends

class Device
class RenderPassEncoder

Detailed Description

Records and validates GPU commands for one command buffer (design 0053 "Command model").

The encoder is a fail-closed state machine: every operation validates handle liveness, device identity, usage flags, bounds, and pass state before recording. The first error latches and poisons the encoder - every subsequent operation, including finish, returns that first error - so a failure cannot be silently skipped and the root cause is always the reported error. Obtain encoders via Device::createCommandEncoder; the encoder must not outlive its device.

Known gap: destroying a resource that a recorded-but-unsubmitted command buffer references is not yet validated; commands are checked at recording time only. Deferred-destruction validation arrives with the resource-lifetime and submission packet (design 0053 change sequence step 3).

Member Function Documentation

◆ beginRenderPass()

Result< RenderPassEncoder * > donner::gpu::CommandEncoder::beginRenderPass ( const RenderPassDescriptor & descriptor)

Begins a render pass and returns its pass encoder.

Fails with GpuErrorType::InvalidState if a pass is already active. Attachment views must be live, share one extent, and their textures need TextureUsage::RenderAttachment.

The returned pointer is owned by this encoder and remains valid until the encoder is destroyed.

Parameters
descriptorValidated render pass descriptor.

◆ copyTextureToBuffer()

Status donner::gpu::CommandEncoder::copyTextureToBuffer ( const TexelCopyTextureInfo & source,
const Buffer & destination,
const TexelCopyBufferLayout & destinationLayout,
const Extent2d & copySize )

Records a texture-to-buffer copy (readback staging).

Not allowed inside a render pass. destinationLayout must be 256-aligned and cover copySize, copySize must fit in the source texture, and the described rows must fit in destination (checked arithmetic).

Parameters
sourceSource texture; needs TextureUsage::CopySrc.
destinationDestination buffer; needs BufferUsage::CopyDst.
destinationLayoutRow layout in the destination buffer.
copySizeCopy extent in texels.

◆ finish()

Result< CommandBuffer > donner::gpu::CommandEncoder::finish ( )

Finishes recording and registers the command buffer with the device.

Fails with the first recorded error if any operation failed, or with GpuErrorType::InvalidState if a pass is still active or the encoder already finished.


The documentation for this class was generated from the following file: