GPURenderPassEncoder: drawIndexedIndirect() method
The drawIndexedIndirect()
method of the GPURenderPassEncoder
interface draws indexed primitives using parameters read from a GPUBuffer
.
Syntax
drawIndexedIndirect(indirectBuffer, indirectOffset)
Parameters
-
indirectBuffer
-
A GPUBuffer
containing the indexCount
, instanceCount
, firstIndex
, baseVertex
, and firstInstance
values needed to carry out the drawing operation. The buffer must contain a tightly packed block of five 32-bit unsigned integer values representing the values (20 bytes total), given in the same order as the arguments for GPURenderPassEncoder.drawIndexed()
. So for example:
const uint32 = new Uint32Array(5);
uint32[0] = 3;
uint32[1] = 1;
uint32[2] = 0;
uint32[3] = 0;
uint32[4] = 0;
device.queue.writeBuffer(buffer, 0, uint32, 0, uint32.length);
-
indirectOffset
-
The offset, in bytes, into indirectBuffer
where the value data begins.
Return value
Validation
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.
Examples
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()]);
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
drawIndexedIndirect |
113Currently supported on ChromeOS, macOS, and Windows only.
|
113Currently supported on ChromeOS, macOS, and Windows only.
|
previewCurrently supported on Linux and Windows only.
|
No |
99Currently supported on ChromeOS, macOS, and Windows only.
|
No |
No |
No |
No |
No |
No |
No |
See also