The drawIndirect()
method of the GPURenderPassEncoder
interface draws primitives using parameters read from a GPUBuffer
.
drawIndirect(indirectBuffer, indirectOffset)
The following criteria must be met when calling drawIndirect()
, otherwise a GPUValidationError
is generated and the GPURenderPassEncoder
becomes invalid:
-
indirectBuffer
's GPUBuffer.usage
contains the GPUBufferUsage.INDIRECT
flag. -
indirectOffset
+ the total size specified by the value parameters in the indirectBuffer
is less than or equal to the indirectBuffer
's GPUBuffer.size
. -
indirectOffset
is a multiple of 4.
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
passEncoder.setPipeline(renderPipeline);
passEncoder.setVertexBuffer(0, vertexBuffer);
const uint32 = new Uint32Array(4);
uint32[0] = 3;
uint32[1] = 1;
uint32[2] = 0;
uint32[3] = 0;
const drawValues = device.createBuffer({
size: 16,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.INDIRECT,
});
device.queue.writeBuffer(drawValues, 0, uint32, 0, uint32.length);
passEncoder.drawIndirect(drawValues, 0);
passEncoder.end();
device.queue.submit([commandEncoder.finish()]);