diff options
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/stress/queue')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/stress/queue/README.txt | 1 | ||||
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/stress/queue/submit.spec.ts | 102 |
2 files changed, 103 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/stress/queue/README.txt b/dom/webgpu/tests/cts/checkout/src/stress/queue/README.txt new file mode 100644 index 0000000000..adb4ec40ce --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/stress/queue/README.txt @@ -0,0 +1 @@ +Stress tests covering GPUQueue usage. diff --git a/dom/webgpu/tests/cts/checkout/src/stress/queue/submit.spec.ts b/dom/webgpu/tests/cts/checkout/src/stress/queue/submit.spec.ts new file mode 100644 index 0000000000..fcce353272 --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/stress/queue/submit.spec.ts @@ -0,0 +1,102 @@ +export const description = ` +Stress tests for command submission to GPUQueue objects. +`; + +import { makeTestGroup } from '../../common/framework/test_group.js'; +import { iterRange } from '../../common/util/util.js'; +import { GPUTest } from '../../webgpu/gpu_test.js'; + +export const g = makeTestGroup(GPUTest); + +g.test('huge_command_buffer') + .desc( + `Tests submission of huge command buffers to a GPUQueue. Huge buffers are +encoded by chaining together long sequences of compute passes, with expected +results verified at the end of the test.` + ) + .fn(t => { + const kNumElements = 64; + const data = new Uint32Array([...iterRange(kNumElements, x => x)]); + const buffer = t.makeBufferWithContents(data, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC); + const pipeline = t.device.createComputePipeline({ + layout: 'auto', + compute: { + module: t.device.createShaderModule({ + code: ` + struct Buffer { data: array<u32>, }; + @group(0) @binding(0) var<storage, read_write> buffer: Buffer; + @compute @workgroup_size(1) fn main( + @builtin(global_invocation_id) id: vec3<u32>) { + buffer.data[id.x] = buffer.data[id.x] + 1u; + } + `, + }), + entryPoint: 'main', + }, + }); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [{ binding: 0, resource: { buffer } }], + }); + const encoder = t.device.createCommandEncoder(); + const kNumIterations = 500_000; + for (let i = 0; i < kNumIterations; ++i) { + const pass = encoder.beginComputePass(); + pass.setPipeline(pipeline); + pass.setBindGroup(0, bindGroup); + pass.dispatchWorkgroups(kNumElements); + pass.end(); + } + t.device.queue.submit([encoder.finish()]); + t.expectGPUBufferValuesEqual( + buffer, + new Uint32Array([...iterRange(kNumElements, x => x + kNumIterations)]) + ); + }); + +g.test('many_command_buffers') + .desc( + `Tests submission of a huge number of command buffers to a GPUQueue by a single +submit() call.` + ) + .fn(t => { + const kNumElements = 64; + const data = new Uint32Array([...iterRange(kNumElements, x => x)]); + const buffer = t.makeBufferWithContents(data, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC); + const pipeline = t.device.createComputePipeline({ + layout: 'auto', + compute: { + module: t.device.createShaderModule({ + code: ` + struct Buffer { data: array<u32>, }; + @group(0) @binding(0) var<storage, read_write> buffer: Buffer; + @compute @workgroup_size(1) fn main( + @builtin(global_invocation_id) id: vec3<u32>) { + buffer.data[id.x] = buffer.data[id.x] + 1u; + } + `, + }), + entryPoint: 'main', + }, + }); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [{ binding: 0, resource: { buffer } }], + }); + const kNumIterations = 500_000; + const buffers = []; + for (let i = 0; i < kNumIterations; ++i) { + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginComputePass(); + pass.setPipeline(pipeline); + pass.setBindGroup(0, bindGroup); + pass.dispatchWorkgroups(kNumElements); + pass.end(); + buffers.push(encoder.finish()); + } + t.device.queue.submit(buffers); + t.expectGPUBufferValuesEqual( + buffer, + new Uint32Array([...iterRange(kNumElements, x => x + kNumIterations)]) + ); + }); |