GPURenderBundleEncoder: drawIndirect() method
The drawIndirect()
method of the GPURenderBundleEncoder
interface draws primitives using parameters read from a GPUBuffer
.
Syntax
drawIndirect(indirectBuffer, indirectOffset)
Parameters
-
indirectBuffer
-
A GPUBuffer
containing the vertexCount
, instanceCount
, firstVertex
, and firstInstance
values needed to carry out the drawing operation. The buffer must contain a tightly packed block of four 32-bit unsigned integer values representing the values (16 bytes total), given in the same order as the arguments for GPURenderBundleEncoder.draw()
. So for example:
const uint32 = new Uint32Array(4);
uint32[0] = 3;
uint32[1] = 1;
uint32[2] = 0;
uint32[3] = 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 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.
Examples
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();
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 |
drawIndirect |
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