diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/webgpu/tests/cts/checkout/src/stress/shaders/non_halting.spec.ts | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/stress/shaders/non_halting.spec.ts')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/stress/shaders/non_halting.spec.ts | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/stress/shaders/non_halting.spec.ts b/dom/webgpu/tests/cts/checkout/src/stress/shaders/non_halting.spec.ts new file mode 100644 index 0000000000..b88aa083b3 --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/stress/shaders/non_halting.spec.ts @@ -0,0 +1,194 @@ +export const description = ` +Stress tests covering robustness in the presence of non-halting shaders. +`; + +import { makeTestGroup } from '../../common/framework/test_group.js'; +import { GPUTest } from '../../webgpu/gpu_test.js'; + +export const g = makeTestGroup(GPUTest); + +g.test('compute') + .desc( + `Tests execution of compute passes with non-halting dispatch operations. + +This is expected to hang for a bit, but it should ultimately result in graceful +device loss.` + ) + .fn(async t => { + const data = new Uint32Array([0]); + const buffer = t.makeBufferWithContents(data, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC); + const module = t.device.createShaderModule({ + code: ` + struct Buffer { data: u32, }; + @group(0) @binding(0) var<storage, read_write> buffer: Buffer; + @compute @workgroup_size(1) fn main() { + loop { + if (buffer.data == 1u) { + break; + } + buffer.data = buffer.data + 2u; + } + } + `, + }); + const pipeline = t.device.createComputePipeline({ + layout: 'auto', + compute: { module, entryPoint: 'main' }, + }); + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginComputePass(); + pass.setPipeline(pipeline); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [{ binding: 0, resource: { buffer } }], + }); + pass.setBindGroup(0, bindGroup); + pass.dispatchWorkgroups(1); + pass.end(); + t.device.queue.submit([encoder.finish()]); + await t.device.lost; + }); + +g.test('vertex') + .desc( + `Tests execution of render passes with a non-halting vertex stage. + +This is expected to hang for a bit, but it should ultimately result in graceful +device loss.` + ) + .fn(async t => { + const module = t.device.createShaderModule({ + code: ` + struct Data { counter: u32, increment: u32, }; + @group(0) @binding(0) var<uniform> data: Data; + @vertex fn vmain() -> @builtin(position) vec4<f32> { + var counter: u32 = data.counter; + loop { + if (counter % 2u == 1u) { + break; + } + counter = counter + data.increment; + } + return vec4<f32>(1.0, 1.0, 0.0, f32(counter)); + } + @fragment fn fmain() -> @location(0) vec4<f32> { + return vec4<f32>(1.0); + } + `, + }); + + const pipeline = t.device.createRenderPipeline({ + layout: 'auto', + vertex: { module, entryPoint: 'vmain', buffers: [] }, + primitive: { topology: 'point-list' }, + fragment: { + targets: [{ format: 'rgba8unorm' }], + module, + entryPoint: 'fmain', + }, + }); + const uniforms = t.makeBufferWithContents(new Uint32Array([0, 2]), GPUBufferUsage.UNIFORM); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [ + { + binding: 0, + resource: { buffer: uniforms }, + }, + ], + }); + const renderTarget = t.device.createTexture({ + size: [1, 1], + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, + format: 'rgba8unorm', + }); + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginRenderPass({ + colorAttachments: [ + { + view: renderTarget.createView(), + clearValue: [0, 0, 0, 0], + loadOp: 'clear', + storeOp: 'store', + }, + ], + }); + pass.setPipeline(pipeline); + pass.setBindGroup(0, bindGroup); + pass.draw(1); + pass.end(); + t.device.queue.submit([encoder.finish()]); + await t.device.lost; + }); + +g.test('fragment') + .desc( + `Tests execution of render passes with a non-halting fragment stage. + +This is expected to hang for a bit, but it should ultimately result in graceful +device loss.` + ) + .fn(async t => { + const module = t.device.createShaderModule({ + code: ` + struct Data { counter: u32, increment: u32, }; + @group(0) @binding(0) var<uniform> data: Data; + @vertex fn vmain() -> @builtin(position) vec4<f32> { + return vec4<f32>(0.0, 0.0, 0.0, 1.0); + } + @fragment fn fmain() -> @location(0) vec4<f32> { + var counter: u32 = data.counter; + loop { + if (counter % 2u == 1u) { + break; + } + counter = counter + data.increment; + } + return vec4<f32>(1.0 / f32(counter), 0.0, 0.0, 1.0); + } + `, + }); + + const pipeline = t.device.createRenderPipeline({ + layout: 'auto', + vertex: { module, entryPoint: 'vmain', buffers: [] }, + primitive: { topology: 'point-list' }, + fragment: { + targets: [{ format: 'rgba8unorm' }], + module, + entryPoint: 'fmain', + }, + }); + const uniforms = t.makeBufferWithContents(new Uint32Array([0, 2]), GPUBufferUsage.UNIFORM); + const bindGroup = t.device.createBindGroup({ + layout: pipeline.getBindGroupLayout(0), + entries: [ + { + binding: 0, + resource: { buffer: uniforms }, + }, + ], + }); + const renderTarget = t.device.createTexture({ + size: [1, 1], + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, + format: 'rgba8unorm', + }); + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginRenderPass({ + colorAttachments: [ + { + view: renderTarget.createView(), + clearValue: [0, 0, 0, 0], + loadOp: 'clear', + storeOp: 'store', + }, + ], + }); + pass.setPipeline(pipeline); + pass.setBindGroup(0, bindGroup); + pass.draw(1); + pass.end(); + t.device.queue.submit([encoder.finish()]); + await t.device.lost; + }); |