deno.com

class GPUCommandEncoder

implements GPUObjectBase

Used to record GPU commands for later execution by the GPU.

Examples #

#
// Create a command encoder
const commandEncoder = device.createCommandEncoder({
  label: "Main Command Encoder"
});

// Record a copy from one buffer to another
commandEncoder.copyBufferToBuffer(
  sourceBuffer, 0, // Source buffer and offset
  destinationBuffer, 0, // Destination buffer and offset
  sourceBuffer.size // Size to copy
);

// Begin a compute pass to execute a compute shader
const computePass = commandEncoder.beginComputePass();
computePass.setPipeline(computePipeline);
computePass.setBindGroup(0, bindGroup);
computePass.dispatchWorkgroups(32, 1, 1); // Run 32 workgroups
computePass.end();

// Begin a render pass to draw to a texture
const renderPass = commandEncoder.beginRenderPass({
  colorAttachments: [{
    view: textureView,
    clearValue: { r: 0.0, g: 0.0, b: 0.0, a: 1.0 },
    loadOp: "clear",
    storeOp: "store"
  }]
});
renderPass.setPipeline(renderPipeline);
renderPass.draw(3, 1, 0, 0); // Draw a triangle
renderPass.end();

// Finish encoding and submit to GPU
const commandBuffer = commandEncoder.finish();
device.queue.submit([commandBuffer]);

Properties #

#label: string

Methods #

#clearBuffer(
destination: GPUBuffer,
destinationOffset?: number,
size?: number,
): undefined
#copyBufferToBuffer(
source: GPUBuffer,
sourceOffset: number,
destination: GPUBuffer,
destinationOffset: number,
size: number,
): undefined
#insertDebugMarker(markerLabel: string): undefined
#popDebugGroup(): undefined
#pushDebugGroup(groupLabel: string): undefined
#resolveQuerySet(
querySet: GPUQuerySet,
firstQuery: number,
queryCount: number,
destination: GPUBuffer,
destinationOffset: number,
): undefined
#writeTimestamp(
querySet: GPUQuerySet,
queryIndex: number,
): undefined