summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/capability_checks/limits/maxTextureDimension2D.spec.ts
blob: 150e8c60976d037d6baeac04c2d7346743204dd4 (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
import { getGPU } from '../../../../../common/util/navigator_gpu.js';
import { kAllCanvasTypes, createCanvas } from '../../../../util/create_elements.js';

import { kMaximumLimitBaseParams, makeLimitTestGroup } from './limit_utils.js';

const limit = 'maxTextureDimension2D';
export const { g, description } = makeLimitTestGroup(limit);

g.test('createTexture,at_over')
  .desc(`Test using at and over ${limit} limit`)
  .params(kMaximumLimitBaseParams)
  .fn(async t => {
    const { limitTest, testValueName } = t.params;
    await t.testDeviceWithRequestedMaximumLimits(
      limitTest,
      testValueName,
      async ({ device, shouldError, testValue, actualLimit }) => {
        for (let dimensionIndex = 0; dimensionIndex < 2; ++dimensionIndex) {
          const size = [1, 1, 1];
          size[dimensionIndex] = testValue;

          await t.testForValidationErrorWithPossibleOutOfMemoryError(
            () => {
              const texture = device.createTexture({
                size,
                format: 'rgba8unorm',
                usage: GPUTextureUsage.TEXTURE_BINDING,
              });

              // MAINTENANCE_TODO: Remove this 'if' once the bug in chrome is fixed
              // This 'if' is only here because of a bug in Chrome
              // that generates an error calling destroy on an invalid texture.
              // This doesn't affect the test but the 'if' should be removed
              // once the Chrome bug is fixed.
              if (!shouldError) {
                texture.destroy();
              }
            },
            shouldError,
            `size: ${size}, actualLimit: ${actualLimit}`
          );
        }
      }
    );
  });

g.test('configure,at_over')
  .desc(`Test using at and over ${limit} limit`)
  .params(kMaximumLimitBaseParams.combine('canvasType', kAllCanvasTypes))
  .fn(async t => {
    const { limitTest, testValueName, canvasType } = t.params;
    await t.testDeviceWithRequestedMaximumLimits(
      limitTest,
      testValueName,
      async ({ device, shouldError, testValue, actualLimit }) => {
        for (let dimensionIndex = 0; dimensionIndex < 2; ++dimensionIndex) {
          const size = [1, 1];
          size[dimensionIndex] = testValue;

          // This should not fail, even if the size is too large but it might fail
          // if we're in a worker and HTMLCanvasElement does not exist.
          const canvas = createCanvas(t, canvasType, size[0], size[1])!;
          if (canvas) {
            const context = canvas.getContext('webgpu') as GPUCanvasContext;
            t.expect(!!context, 'should not fail to create context even if size is too large');

            await t.testForValidationErrorWithPossibleOutOfMemoryError(
              () => {
                context.configure({
                  device,
                  format: getGPU(t.rec).getPreferredCanvasFormat(),
                });
              },
              shouldError,
              `size: ${size}, actualLimit: ${actualLimit}`
            );
          }
        }
      }
    );
  });

g.test('getCurrentTexture,at_over')
  .desc(`Test using at and over ${limit} limit`)
  .params(kMaximumLimitBaseParams.combine('canvasType', kAllCanvasTypes))
  .fn(async t => {
    const { limitTest, testValueName, canvasType } = t.params;
    await t.testDeviceWithRequestedMaximumLimits(
      limitTest,
      testValueName,
      async ({ device, shouldError, testValue, actualLimit }) => {
        for (let dimensionIndex = 0; dimensionIndex < 2; ++dimensionIndex) {
          const size = [1, 1];
          size[dimensionIndex] = testValue;

          // Start with a small size so configure will succeed.
          // This should not fail, even if the size is too large but it might fail
          // if we're in a worker and HTMLCanvasElement does not exist.
          const canvas = createCanvas(t, canvasType, 1, 1)!;
          if (canvas) {
            const context = canvas.getContext('webgpu') as GPUCanvasContext;
            t.expect(!!context, 'should not fail to create context even if size is too large');

            context.configure({
              device,
              format: getGPU(t.rec).getPreferredCanvasFormat(),
            });

            if (canvas) {
              await t.testForValidationErrorWithPossibleOutOfMemoryError(
                () => {
                  canvas.width = size[0];
                  canvas.height = size[1];
                  const texture = context.getCurrentTexture();

                  // MAINTENANCE_TODO: Remove this 'if' once the bug in chrome is fixed
                  // This 'if' is only here because of a bug in Chrome
                  // that generates an error calling destroy on an invalid texture.
                  // This doesn't affect the test but the 'if' should be removed
                  // once the Chrome bug is fixed.
                  if (!shouldError) {
                    texture.destroy();
                  }
                },
                shouldError,
                `size: ${size}, actualLimit: ${actualLimit}`
              );
            }
          }
        }
      }
    );
  });