summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/render_pass/storeOp.spec.ts
blob: 8aa63742a929c9383ada1d4c79e9e8a5fea58812 (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
export const description = `
API Validation Tests for RenderPass StoreOp.

Test Coverage:
  - Tests that when depthReadOnly is true, depthStoreOp must be 'store'.
    - When depthReadOnly is true and depthStoreOp is 'discard', an error should be generated.

  - Tests that when stencilReadOnly is true, stencilStoreOp must be 'store'.
    - When stencilReadOnly is true and stencilStoreOp is 'discard', an error should be generated.

  - Tests that the depthReadOnly value matches the stencilReadOnly value.
    - When depthReadOnly does not match stencilReadOnly, an error should be generated.

  - Tests that depthReadOnly and stencilReadOnly default to false.

TODO: test interactions with depthClearValue too
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { ValidationTest } from '../validation_test.js';

export const g = makeTestGroup(ValidationTest);

g.test('store_op_and_read_only')
  .paramsSimple([
    { readonly: true, _valid: true },
    // Using depthReadOnly=true and depthStoreOp='discard' should cause a validation error.
    { readonly: true, depthStoreOp: 'discard', _valid: false },
    // Using stencilReadOnly=true and stencilStoreOp='discard' should cause a validation error.
    { readonly: true, stencilStoreOp: 'discard', _valid: false },
    // Mismatched depthReadOnly and stencilReadOnly values should cause a validation error.
    { readonly: false, _valid: true },
    { readonly: false, depthReadOnly: true, _valid: false },
    { readonly: false, stencilReadOnly: true, _valid: false },
    // depthReadOnly and stencilReadOnly should default to false.
    { readonly: undefined, _valid: true },
    { readonly: undefined, depthReadOnly: true, _valid: false },
    { readonly: undefined, stencilReadOnly: true, _valid: false },
  ] as const)
  .fn(async t => {
    const {
      readonly,
      depthStoreOp = 'store',
      depthReadOnly = readonly,
      stencilStoreOp = 'store',
      stencilReadOnly = readonly,
      _valid,
    } = t.params;

    const depthAttachment = t.device.createTexture({
      format: 'depth24plus-stencil8',
      size: { width: 1, height: 1, depthOrArrayLayers: 1 },
      usage: GPUTextureUsage.RENDER_ATTACHMENT,
    });
    const depthAttachmentView = depthAttachment.createView();

    const encoder = t.device.createCommandEncoder();
    const pass = encoder.beginRenderPass({
      colorAttachments: [],
      depthStencilAttachment: {
        view: depthAttachmentView,
        depthLoadOp: 'load',
        depthStoreOp,
        depthReadOnly,
        stencilLoadOp: 'load',
        stencilStoreOp,
        stencilReadOnly,
      },
    });
    pass.end();

    t.expectValidationError(() => {
      encoder.finish();
    }, !_valid);
  });