summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/encoding/queries/begin_end.spec.ts
blob: 580675e1183fe145eb4697d76e069e3639115da0 (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
export const description = `
Validation for encoding begin/endable queries.

TODO: pipeline statistics queries are removed from core; consider moving tests to another suite.
TODO: tests for pipeline statistics queries:
- balance: {
    - begin 0, end 1
    - begin 1, end 0
    - begin 1, end 1
    - begin 2, end 2
    - }
    - x= {
        - render pass + pipeline statistics
        - compute pass + pipeline statistics
        - }
`;

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

import { beginRenderPassWithQuerySet, createQuerySetWithType } from './common.js';

export const g = makeTestGroup(ValidationTest);

g.test('occlusion_query,begin_end_balance')
  .desc(
    `
Tests that begin/end occlusion queries mismatch on render pass:
- begin n queries, then end m queries, for various n and m.
  `
  )
  .paramsSubcasesOnly([
    { begin: 0, end: 1 },
    { begin: 1, end: 0 },
    { begin: 1, end: 1 }, // control case
    { begin: 1, end: 2 },
    { begin: 2, end: 1 },
  ] as const)
  .fn(async t => {
    const { begin, end } = t.params;

    const occlusionQuerySet = createQuerySetWithType(t, 'occlusion', 2);

    const encoder = t.createEncoder('render pass', { occlusionQuerySet });
    for (let i = 0; i < begin; i++) {
      encoder.encoder.beginOcclusionQuery(i);
    }
    for (let j = 0; j < end; j++) {
      encoder.encoder.endOcclusionQuery();
    }
    encoder.validateFinishAndSubmit(begin === end, true);
  });

g.test('occlusion_query,begin_end_invalid_nesting')
  .desc(
    `
Tests the invalid nesting of begin/end occlusion queries:
- begin index 0, end, begin index 0, end (control case)
- begin index 0, begin index 0, end, end
- begin index 0, begin index 1, end, end
  `
  )
  .paramsSubcasesOnly([
    { calls: [0, 'end', 1, 'end'], _valid: true }, // control case
    { calls: [0, 0, 'end', 'end'], _valid: false },
    { calls: [0, 1, 'end', 'end'], _valid: false },
  ] as const)
  .fn(async t => {
    const { calls, _valid } = t.params;

    const occlusionQuerySet = createQuerySetWithType(t, 'occlusion', 2);

    const encoder = t.createEncoder('render pass', { occlusionQuerySet });
    for (const i of calls) {
      if (i !== 'end') {
        encoder.encoder.beginOcclusionQuery(i);
      } else {
        encoder.encoder.endOcclusionQuery();
      }
    }
    encoder.validateFinishAndSubmit(_valid, true);
  });

g.test('occlusion_query,disjoint_queries_with_same_query_index')
  .desc(
    `
Tests that two disjoint occlusion queries cannot be begun with same query index on same render pass:
- begin index 0, end, begin index 0, end
- call on {same (invalid), different (control case)} render pass
  `
  )
  .paramsSubcasesOnly(u => u.combine('isOnSameRenderPass', [false, true]))
  .fn(async t => {
    const querySet = createQuerySetWithType(t, 'occlusion', 1);

    const encoder = t.device.createCommandEncoder();
    const pass = beginRenderPassWithQuerySet(t, encoder, querySet);
    pass.beginOcclusionQuery(0);
    pass.endOcclusionQuery();

    if (t.params.isOnSameRenderPass) {
      pass.beginOcclusionQuery(0);
      pass.endOcclusionQuery();
      pass.end();
    } else {
      pass.end();
      const otherPass = beginRenderPassWithQuerySet(t, encoder, querySet);
      otherPass.beginOcclusionQuery(0);
      otherPass.endOcclusionQuery();
      otherPass.end();
    }

    t.expectValidationError(() => {
      encoder.finish();
    }, t.params.isOnSameRenderPass);
  });

g.test('nesting')
  .desc(
    `
Tests that whether it's allowed to nest various types of queries:
- call {occlusion, pipeline-statistics, timestamp} query in same type or other type.
  `
  )
  .paramsSubcasesOnly([
    { begin: 'occlusion', nest: 'timestamp', end: 'occlusion', _valid: true },
    { begin: 'occlusion', nest: 'occlusion', end: 'occlusion', _valid: false },
    { begin: 'occlusion', nest: 'pipeline-statistics', end: 'occlusion', _valid: true },
    {
      begin: 'occlusion',
      nest: 'pipeline-statistics',
      end: 'pipeline-statistics',
      _valid: true,
    },
    {
      begin: 'pipeline-statistics',
      nest: 'timestamp',
      end: 'pipeline-statistics',
      _valid: true,
    },
    {
      begin: 'pipeline-statistics',
      nest: 'pipeline-statistics',
      end: 'pipeline-statistics',
      _valid: false,
    },
    {
      begin: 'pipeline-statistics',
      nest: 'occlusion',
      end: 'pipeline-statistics',
      _valid: true,
    },
    { begin: 'pipeline-statistics', nest: 'occlusion', end: 'occlusion', _valid: true },
    { begin: 'timestamp', nest: 'occlusion', end: 'occlusion', _valid: true },
    {
      begin: 'timestamp',
      nest: 'pipeline-statistics',
      end: 'pipeline-statistics',
      _valid: true,
    },
  ] as const)
  .unimplemented();