summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/capability_checks/limits/maxVertexBuffers.spec.ts
blob: 51cb44d55b89e017472feba0dddded821d9651a9 (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
import { kRenderEncoderTypes, kMaximumLimitBaseParams, makeLimitTestGroup } from './limit_utils.js';

function getPipelineDescriptor(device: GPUDevice, testValue: number): GPURenderPipelineDescriptor {
  const module = device.createShaderModule({
    code: `
      @vertex fn vs(@location(0) p: vec4f) -> @builtin(position) vec4f {
        return p;
      }`,
  });
  const buffers = new Array<GPUVertexBufferLayout>(testValue);
  buffers[testValue - 1] = {
    arrayStride: 16,
    attributes: [{ shaderLocation: 0, offset: 0, format: 'float32' }],
  };

  return {
    layout: 'auto',
    vertex: {
      module,
      buffers,
    },
  };
}

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

g.test('createRenderPipeline,at_over')
  .desc(`Test using at and over ${limit} limit in createRenderPipeline(Async)`)
  .params(kMaximumLimitBaseParams.combine('async', [false, true]))
  .fn(async t => {
    const { limitTest, testValueName, async } = t.params;
    await t.testDeviceWithRequestedMaximumLimits(
      limitTest,
      testValueName,
      async ({ device, testValue, shouldError, actualLimit }) => {
        const pipelineDescriptor = getPipelineDescriptor(device, testValue);
        const lastIndex = testValue - 1;

        await t.testCreateRenderPipeline(
          pipelineDescriptor,
          async,
          shouldError,
          `lastIndex: ${lastIndex}, actualLimit: ${actualLimit}, shouldError: ${shouldError}`
        );
      }
    );
  });

g.test('setVertexBuffer,at_over')
  .desc(`Test using at and over ${limit} limit in setVertexBuffer`)
  .params(kMaximumLimitBaseParams.combine('encoderType', kRenderEncoderTypes))
  .fn(async t => {
    const { limitTest, testValueName, encoderType } = t.params;
    await t.testDeviceWithRequestedMaximumLimits(
      limitTest,
      testValueName,
      async ({ device, testValue, shouldError, actualLimit }) => {
        const lastIndex = testValue - 1;

        const buffer = device.createBuffer({
          size: 16,
          usage: GPUBufferUsage.VERTEX,
        });

        await t.testGPURenderAndBindingCommandsMixin(
          encoderType,
          ({ passEncoder }) => {
            passEncoder.setVertexBuffer(lastIndex, buffer);
          },
          shouldError,
          `lastIndex: ${lastIndex}, actualLimit: ${actualLimit}, shouldError: ${shouldError}`
        );

        buffer.destroy();
      }
    );
  });

g.test('validate,maxBindGroupsPlusVertexBuffers')
  .desc(`Test that ${limit} <= maxBindGroupsPlusVertexBuffers`)
  .fn(t => {
    const { adapter, defaultLimit, adapterLimit } = t;
    t.expect(defaultLimit <= t.getDefaultLimit('maxBindGroupsPlusVertexBuffers'));
    t.expect(adapterLimit <= adapter.limits.maxBindGroupsPlusVertexBuffers);
  });