Skip to content

Commit

Permalink
Add multi draw tests for rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirtsu55 committed Nov 8, 2024
1 parent b9f32fd commit 82dc3ad
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
39 changes: 30 additions & 9 deletions src/webgpu/api/operation/rendering/draw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TypedArrayBufferView,
TypedArrayBufferViewConstructor,
} from '../../../../common/util/util.js';
import { kFeatureNames } from '../../../capability_info.js';
import { GPUTest, TextureTestMixin } from '../../../gpu_test.js';
import { PerPixelComparison } from '../../../util/texture/texture_ok.js';

Expand All @@ -22,6 +23,7 @@ class DrawTest extends TextureTestMixin(GPUTest) {
instanceCount: number | undefined;
indexed: boolean;
indirect: boolean;
multiDraw: boolean;
vertexBufferOffset: number;
indexBufferOffset: number | undefined;
baseVertex: number | undefined;
Expand All @@ -34,6 +36,7 @@ class DrawTest extends TextureTestMixin(GPUTest) {
instanceCount: opts.instanceCount ?? 1,
indexed: opts.indexed,
indirect: opts.indirect,
multiDraw: opts.multiDraw,
vertexBufferOffset: opts.vertexBufferOffset,
indexBufferOffset: opts.indexBufferOffset ?? 0,
baseVertex: opts.baseVertex ?? 0,
Expand Down Expand Up @@ -221,10 +224,14 @@ struct Output {
defaulted.baseVertex,
defaulted.firstInstance,
] as const;
renderPass.drawIndexedIndirect(
this.makeBufferWithContents(new Uint32Array(args), GPUBufferUsage.INDIRECT),
0
);
const drawArgsBuffer = this.makeBufferWithContents(new Uint32Array(args), GPUBufferUsage.INDIRECT);

if (defaulted.multiDraw) {
renderPass.multiDrawIndexedIndirect(drawArgsBuffer, 0, 1);
}
else {
renderPass.drawIndexedIndirect(drawArgsBuffer, 0);
}
} else {
const args = [
opts.count,
Expand Down Expand Up @@ -261,10 +268,15 @@ struct Output {
defaulted.firstIndex,
defaulted.firstInstance,
] as const;
renderPass.drawIndirect(
this.makeBufferWithContents(new Uint32Array(args), GPUBufferUsage.INDIRECT),
0
);

const drawArgsBuffer = this.makeBufferWithContents(new Uint32Array(args), GPUBufferUsage.INDIRECT);

if(defaulted.multiDraw) {
renderPass.multiDrawIndirect(drawArgsBuffer, 0, 1);
} else {
renderPass.drawIndirect(drawArgsBuffer, 0);
}

} else {
const args = [opts.count, opts.instanceCount, opts.firstIndex, opts.firstInstance] as const;
renderPass.draw.apply(renderPass, [...args]);
Expand Down Expand Up @@ -343,14 +355,21 @@ Params:
.combine('instance_count', [0, 1, 4] as const)
.combine('indexed', [false, true])
.combine('indirect', [false, true])
.combine('multiDraw', [false, true])
.combine('vertex_buffer_offset', [0, 32] as const)
.expand('index_buffer_offset', p => (p.indexed ? ([0, 16] as const) : [undefined]))
.expand('base_vertex', p => (p.indexed ? ([0, 9] as const) : [undefined]))
)
.beforeAllSubcases(t => {
const features : GPUFeatureName[] = [];
if (t.params.first_instance > 0 && t.params.indirect) {
t.selectDeviceOrSkipTestCase('indirect-first-instance');
features.push('indirect-first-instance');
}
if(t.params.multiDraw) {
features.push('multi-draw-indirect' as GPUFeatureName);
}

t.selectDeviceOrSkipTestCase(features);
})
.fn(t => {
t.checkTriangleDraw({
Expand All @@ -360,6 +379,7 @@ Params:
instanceCount: t.params.instance_count,
indexed: t.params.indexed,
indirect: t.params.indirect,
multiDraw: t.params.multiDraw,
vertexBufferOffset: t.params.vertex_buffer_offset,
indexBufferOffset: t.params.index_buffer_offset,
baseVertex: t.params.base_vertex,
Expand Down Expand Up @@ -398,6 +418,7 @@ g.test('default_arguments')
instanceCount: t.params.instance_count,
indexed: t.params.mode === 'drawIndexed',
indirect: false, // indirect
multiDraw: false, // multiDraw
vertexBufferOffset: kVertexBufferOffset,
indexBufferOffset: kIndexBufferOffset,
baseVertex: t.params.base_vertex,
Expand Down
23 changes: 20 additions & 3 deletions src/webgpu/api/operation/rendering/indirect_draw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Params:
.params(u =>
u
.combine('isIndexed', [true, false])
.combine('isMultiDraw', [true, false])
.beginSubcases()
.expand('indirectOffset', p => {
const indirectDrawParametersSize = p.isIndexed
Expand All @@ -161,8 +162,14 @@ Params:
] as const;
})
)
.beforeAllSubcases(t => {
if(!t.params.isMultiDraw)
return;
const features: GPUFeatureName[] = ['multi-draw-indirect' as GPUFeatureName];
t.selectDeviceOrSkipTestCase(features);
})
.fn(t => {
const { isIndexed, indirectOffset } = t.params;
const { isIndexed, isMultiDraw, indirectOffset } = t.params;

const vertexBuffer = t.MakeVertexBuffer(isIndexed);
const indirectBuffer = t.MakeIndirectBuffer(isIndexed, indirectOffset);
Expand Down Expand Up @@ -226,9 +233,19 @@ Params:

if (isIndexed) {
renderPass.setIndexBuffer(t.MakeIndexBuffer(), 'uint32', 0);
renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
if(isMultiDraw) {
renderPass.multiDrawIndexedIndirect(indirectBuffer, indirectOffset, 1);
}
else {
renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
}
} else {
renderPass.drawIndirect(indirectBuffer, indirectOffset);
if(isMultiDraw) {
renderPass.multiDrawIndirect(indirectBuffer, indirectOffset, 1);
}
else {
renderPass.drawIndirect(indirectBuffer, indirectOffset);
}
}
renderPass.end();
t.queue.submit([commandEncoder.finish()]);
Expand Down
12 changes: 12 additions & 0 deletions src/webgpu/api/validation/encoding/encoder_open_state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const kRenderPassEncoderCommandInfo: {
drawIndexed: {},
drawIndexedIndirect: {},
drawIndirect: {},
multiDrawIndexedIndirect: {},
multiDrawIndirect: {},
setIndexBuffer: {},
setBindGroup: {},
setVertexBuffer: {},
Expand Down Expand Up @@ -336,6 +338,16 @@ g.test('render_pass_commands')
renderPass.drawIndirect(buffer, 1);
}
break;
case 'multiDrawIndirect':
{
renderPass.multiDrawIndirect(buffer, 0, 0);
}
break;
case 'multiDrawIndexedIndirect':
{
renderPass.multiDrawIndexedIndirect(buffer, 0, 0);
}
break;
case 'setIndexBuffer':
{
renderPass.setIndexBuffer(buffer, 'uint32');
Expand Down

0 comments on commit 82dc3ad

Please sign in to comment.