summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/operation/onSubmittedWorkDone.spec.ts
blob: 8b0647e7ef9e02accaa50e5985f0f643e643be72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export const description = `
Tests for the behavior of GPUQueue.onSubmittedWorkDone().

Note that any promise timeouts will be detected by the framework.
`;

import { makeTestGroup } from '../../../common/framework/test_group.js';
import { range } from '../../../common/util/util.js';
import { GPUTest } from '../../gpu_test.js';

export const g = makeTestGroup(GPUTest);

g.test('without_work')
  .desc(`Await onSubmittedWorkDone once without having submitted any work.`)
  .fn(async t => {
    await t.queue.onSubmittedWorkDone();
  });

g.test('with_work')
  .desc(`Await onSubmittedWorkDone once after submitting some work (writeBuffer).`)
  .fn(async t => {
    const buffer = t.device.createBuffer({ size: 4, usage: GPUBufferUsage.COPY_DST });
    t.queue.writeBuffer(buffer, 0, new Uint8Array(4));
    await t.queue.onSubmittedWorkDone();
  });

g.test('many,serial')
  .desc(`Await 1000 onSubmittedWorkDone calls in serial.`)
  .fn(async t => {
    for (let i = 0; i < 1000; ++i) {
      await t.queue.onSubmittedWorkDone();
    }
  });

g.test('many,parallel')
  .desc(`Await 1000 onSubmittedWorkDone calls in parallel with Promise.all().`)
  .fn(async t => {
    const promises = range(1000, () => t.queue.onSubmittedWorkDone());
    await Promise.all(promises);
  });

g.test('many,parallel_order')
  .desc(`Issue 200 onSubmittedWorkDone calls and make sure they resolve in the right order.`)
  .fn(async t => {
    const promises = [];
    let lastResolved = -1;
    for (const i of range(200, i => i)) {
      promises.push(
        t.queue.onSubmittedWorkDone().then(() => {
          t.expect(i === lastResolved + 1);
          lastResolved++;
        })
      );
    }
    await Promise.all(promises);
  });