summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/encoding/createRenderBundleEncoder.spec.ts
blob: 11e411b1d0ac2c84b6bdad23ebc8a3fa9e0bb05b (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
export const description = `
createRenderBundleEncoder validation tests.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { range } from '../../../../common/util/util.js';
import {
  kAllTextureFormats,
  kDepthStencilFormats,
  kTextureFormatInfo,
  kMaxColorAttachments,
  kRenderableColorTextureFormats,
} from '../../../capability_info.js';
import { ValidationTest } from '../validation_test.js';

export const g = makeTestGroup(ValidationTest);

g.test('attachment_state,limits,maxColorAttachments')
  .desc(`Tests that attachment state must have <= device.limits.maxColorAttachments.`)
  .params(u =>
    u.beginSubcases().combine(
      'colorFormatCount',
      range(kMaxColorAttachments + 1, i => i + 1) // 1-9
    )
  )
  .fn(async t => {
    const { colorFormatCount } = t.params;
    t.expectValidationError(() => {
      t.device.createRenderBundleEncoder({
        colorFormats: Array(colorFormatCount).fill('r8unorm'),
      });
    }, colorFormatCount > t.device.limits.maxColorAttachments);
  });

g.test('attachment_state,limits,maxColorAttachmentBytesPerSample,aligned')
  .desc(
    `
    Tests that the total color attachment bytes per sample <=
    device.limits.maxColorAttachmentBytesPerSample when using the same format (aligned) for multiple
    attachments.
    `
  )
  .params(u =>
    u
      .combine('format', kRenderableColorTextureFormats)
      .beginSubcases()
      .combine(
        'colorFormatCount',
        range(kMaxColorAttachments, i => i + 1)
      )
  )
  .fn(async t => {
    const { format, colorFormatCount } = t.params;
    const info = kTextureFormatInfo[format];
    const shouldError =
      info.renderTargetPixelByteCost === undefined ||
      info.renderTargetPixelByteCost * colorFormatCount >
        t.device.limits.maxColorAttachmentBytesPerSample;

    t.expectValidationError(() => {
      t.device.createRenderBundleEncoder({
        colorFormats: Array(colorFormatCount).fill(format),
      });
    }, shouldError);
  });

g.test('attachment_state,limits,maxColorAttachmentBytesPerSample,unaligned')
  .desc(
    `
    Tests that the total color attachment bytes per sample <=
    device.limits.maxColorAttachmentBytesPerSample when using various sets of (potentially)
    unaligned formats.
    `
  )
  .params(u =>
    u.combineWithParams([
      // Alignment causes the first 1 byte R8Unorm to become 4 bytes. So even though
      // 1+4+8+16+1 < 32, the 4 byte alignment requirement of R32Float makes the first R8Unorm
      // become 4 and 4+4+8+16+1 > 32. Re-ordering this so the R8Unorm's are at the end, however
      // is allowed: 4+8+16+1+1 < 32.
      {
        formats: [
          'r8unorm',
          'r32float',
          'rgba8unorm',
          'rgba32float',
          'r8unorm',
        ] as GPUTextureFormat[],
        _shouldError: false,
      },
      {
        formats: [
          'r32float',
          'rgba8unorm',
          'rgba32float',
          'r8unorm',
          'r8unorm',
        ] as GPUTextureFormat[],
        _shouldError: true,
      },
    ])
  )
  .fn(async t => {
    const { formats, _shouldError } = t.params;

    t.expectValidationError(() => {
      t.device.createRenderBundleEncoder({
        colorFormats: formats,
      });
    }, _shouldError);
  });

g.test('attachment_state,empty_color_formats')
  .desc(`Tests that if no colorFormats are given, a depthStencilFormat must be specified.`)
  .params(u =>
    u.beginSubcases().combine('depthStencilFormat', [undefined, 'depth24plus-stencil8'] as const)
  )
  .fn(async t => {
    const { depthStencilFormat } = t.params;
    t.expectValidationError(() => {
      t.device.createRenderBundleEncoder({
        colorFormats: [],
        depthStencilFormat,
      });
    }, depthStencilFormat === undefined);
  });

g.test('valid_texture_formats')
  .desc(
    `
    Tests that createRenderBundleEncoder only accepts valid formats for its attachments.
      - colorFormats
      - depthStencilFormat
    `
  )
  .params(u =>
    u //
      .combine('format', kAllTextureFormats)
      .beginSubcases()
      .combine('attachment', ['color', 'depthStencil'])
  )
  .beforeAllSubcases(t => {
    const { format } = t.params;
    t.selectDeviceForTextureFormatOrSkipTestCase(format);
  })
  .fn(async t => {
    const { format, attachment } = t.params;

    const colorRenderable =
      kTextureFormatInfo[format].renderable && kTextureFormatInfo[format].color;

    const depthStencil = kTextureFormatInfo[format].depth || kTextureFormatInfo[format].stencil;

    switch (attachment) {
      case 'color': {
        t.expectValidationError(() => {
          t.device.createRenderBundleEncoder({
            colorFormats: [format],
          });
        }, !colorRenderable);

        break;
      }
      case 'depthStencil': {
        t.expectValidationError(() => {
          t.device.createRenderBundleEncoder({
            colorFormats: [],
            depthStencilFormat: format,
          });
        }, !depthStencil);

        break;
      }
    }
  });

g.test('depth_stencil_readonly')
  .desc(
    `
    Tests that createRenderBundleEncoder validation of depthReadOnly and stencilReadOnly
      - With depth-only formats
      - With stencil-only formats
      - With depth-stencil-combined formats
    `
  )
  .params(u =>
    u //
      .combine('depthStencilFormat', kDepthStencilFormats)
      .beginSubcases()
      .combine('depthReadOnly', [false, true])
      .combine('stencilReadOnly', [false, true])
  )
  .beforeAllSubcases(t => {
    const { depthStencilFormat } = t.params;
    t.selectDeviceForTextureFormatOrSkipTestCase(depthStencilFormat);
  })
  .fn(async t => {
    const { depthStencilFormat, depthReadOnly, stencilReadOnly } = t.params;

    let shouldError = false;
    if (
      kTextureFormatInfo[depthStencilFormat].depth &&
      kTextureFormatInfo[depthStencilFormat].stencil &&
      depthReadOnly !== stencilReadOnly
    ) {
      shouldError = true;
    }

    t.expectValidationError(() => {
      t.device.createRenderBundleEncoder({
        colorFormats: [],
        depthStencilFormat,
        depthReadOnly,
        stencilReadOnly,
      });
    }, shouldError);
  });

g.test('depth_stencil_readonly_with_undefined_depth')
  .desc(
    `
    Tests that createRenderBundleEncoder validation of depthReadOnly and stencilReadOnly is ignored
    if there is no depthStencilFormat set.
    `
  )
  .params(u =>
    u //
      .beginSubcases()
      .combine('depthReadOnly', [false, true])
      .combine('stencilReadOnly', [false, true])
  )
  .fn(async t => {
    const { depthReadOnly, stencilReadOnly } = t.params;

    t.device.createRenderBundleEncoder({
      colorFormats: ['bgra8unorm'],
      depthReadOnly,
      stencilReadOnly,
    });
  });