summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/buffer/destroy.spec.ts
blob: e9297d699c0ecbd2c5a6165c3155bc4a3eb62b44 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
export const description = `
Validation tests for GPUBuffer.destroy.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { kBufferUsages } from '../../../capability_info.js';
import { GPUConst } from '../../../constants.js';
import { ValidationTest } from '../validation_test.js';

export const g = makeTestGroup(ValidationTest);

g.test('all_usages')
  .desc('Test destroying buffers of every usage type.')
  .paramsSubcasesOnly(u =>
    u //
      .combine('usage', kBufferUsages)
  )
  .fn(async t => {
    const { usage } = t.params;
    const buf = t.device.createBuffer({
      size: 4,
      usage,
    });

    buf.destroy();
  });

g.test('error_buffer')
  .desc('Test that error buffers may be destroyed without generating validation errors.')
  .fn(async t => {
    const buf = t.getErrorBuffer();
    buf.destroy();
  });

g.test('twice')
  .desc(
    `Test that destroying a buffer more than once is allowed.
      - Tests buffers which are mapped at creation or not
      - Tests buffers with various usages`
  )
  .paramsSubcasesOnly(u =>
    u //
      .combine('mappedAtCreation', [false, true])
      .combineWithParams([
        { size: 4, usage: GPUConst.BufferUsage.COPY_SRC },
        { size: 4, usage: GPUConst.BufferUsage.MAP_WRITE | GPUConst.BufferUsage.COPY_SRC },
        { size: 4, usage: GPUConst.BufferUsage.COPY_DST | GPUConst.BufferUsage.MAP_READ },
      ])
  )
  .fn(async t => {
    const buf = t.device.createBuffer(t.params);

    buf.destroy();
    buf.destroy();
  });

g.test('while_mapped')
  .desc(
    `Test destroying buffers while mapped or after being unmapped.
      - Tests {mappable, unmappable mapAtCreation, mappable mapAtCreation}
      - Tests while {mapped, mapped at creation, unmapped}`
  )
  .paramsSubcasesOnly(u =>
    u //
      .combine('mappedAtCreation', [false, true])
      .combine('unmapBeforeDestroy', [false, true])
      .combineWithParams([
        { usage: GPUConst.BufferUsage.COPY_SRC },
        { usage: GPUConst.BufferUsage.MAP_WRITE | GPUConst.BufferUsage.COPY_SRC },
        { usage: GPUConst.BufferUsage.COPY_DST | GPUConst.BufferUsage.MAP_READ },
        {
          usage: GPUConst.BufferUsage.MAP_WRITE | GPUConst.BufferUsage.COPY_SRC,
          mapMode: GPUConst.MapMode.WRITE,
        },
        {
          usage: GPUConst.BufferUsage.COPY_DST | GPUConst.BufferUsage.MAP_READ,
          mapMode: GPUConst.MapMode.READ,
        },
      ])
      .unless(p => p.mappedAtCreation === false && p.mapMode === undefined)
  )
  .fn(async t => {
    const { usage, mapMode, mappedAtCreation, unmapBeforeDestroy } = t.params;
    const buf = t.device.createBuffer({
      size: 4,
      usage,
      mappedAtCreation,
    });

    if (mapMode !== undefined) {
      if (mappedAtCreation) {
        buf.unmap();
      }
      await buf.mapAsync(mapMode);
    }
    if (unmapBeforeDestroy) {
      buf.unmap();
    }

    buf.destroy();
  });