The drawIndirect()
method of the GPURenderBundleEncoder
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 GPURenderBundleEncoder
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 bundleEncoder = device.createRenderBundleEncoder(descriptor);
bundleEncoder.setPipeline(renderPipeline);
bundleEncoder.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);
bundleEncoder.drawIndirect(drawValues, 0);
const renderBundle = bundleEncoder.finish();