The drawIndexedIndirect()
method of the GPURenderBundleEncoder
interface draws indexed primitives using parameters read from a GPUBuffer
.
drawIndexedIndirect(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);
bundleEncoder.setIndexBuffer(indexBuffer, "uint16");
const uint32 = new Uint32Array(5);
uint32[0] = 3;
uint32[1] = 1;
uint32[2] = 0;
uint32[3] = 0;
uint32[4] = 0;
const drawValues = device.createBuffer({
size: 20,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.INDIRECT,
});
device.queue.writeBuffer(drawValues, 0, uint32, 0, uint32.length);
bundleEncoder.drawIndexedIndirect(drawValues, 0);
const renderBundle = bundleEncoder.finish();