The drawIndexedIndirect()
method of the GPURenderPassEncoder
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 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);
passEncoder.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);
passEncoder.drawIndexedIndirect(drawValues, 0);
passEncoder.end();
device.queue.submit([commandEncoder.finish()]);