Skip to content

Commit e75b600

Browse files
authored
Add a test for many timestamp query sets (gpuweb#4494)
This test is because Metal has a limit of 32 timestamp query sets. Implementations are supposed to workaround this limit by allocating larger metal sets and having WebGPU set be subsets in those larger sets. This is particularly important as the limit is 32 per process so a few pages making a few queries would easily hit the limit and prevent other pages from running.
1 parent f5977ec commit e75b600

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
export const description = `
2+
API operations tests for timestamp queries.
3+
4+
Given the values returned are implementation defined
5+
there is not much we can test except that there are no errors.
6+
7+
- test query with
8+
- compute pass
9+
- render pass
10+
- 64k query objects
11+
`;
12+
13+
import { makeTestGroup } from '../../../../../common/framework/test_group.js';
14+
import { AllFeaturesMaxLimitsGPUTest } from '../../../../gpu_test.js';
15+
16+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
17+
18+
g.test('many_query_sets')
19+
.desc(
20+
`
21+
Test creating and using 64k query objects.
22+
23+
This test is because there is a Metal limit of 32 MTLCounterSampleBuffers
24+
Implementations are supposed to work around this limit by internally allocating
25+
larger MTLCounterSampleBuffers and having the WebGPU sets be subsets of those
26+
larger buffers.
27+
28+
This is particular important as the limit is 32 per process
29+
so a few pages making a few queries would easily hit the limit
30+
and prevent pages from running.
31+
`
32+
)
33+
.params(u =>
34+
u
35+
.combine('numQuerySets', [8, 16, 32, 64, 256, 65536] as const)
36+
.combine('stage', ['compute', 'render'] as const)
37+
)
38+
.fn(t => {
39+
const { stage, numQuerySets } = t.params;
40+
41+
t.skipIfDeviceDoesNotHaveFeature('timestamp-query');
42+
43+
const view = t
44+
.createTextureTracked({
45+
size: [1, 1, 1],
46+
format: 'rgba8unorm',
47+
usage: GPUTextureUsage.RENDER_ATTACHMENT,
48+
})
49+
.createView();
50+
const encoder = t.device.createCommandEncoder();
51+
52+
for (let i = 0; i < numQuerySets; ++i) {
53+
const querySet = t.createQuerySetTracked({
54+
type: 'timestamp',
55+
count: 2,
56+
});
57+
58+
switch (stage) {
59+
case 'compute': {
60+
const pass = encoder.beginComputePass({
61+
timestampWrites: {
62+
querySet,
63+
beginningOfPassWriteIndex: 0,
64+
endOfPassWriteIndex: 1,
65+
},
66+
});
67+
pass.end();
68+
break;
69+
}
70+
case 'render': {
71+
const pass = encoder.beginRenderPass({
72+
colorAttachments: [{ view, loadOp: 'load', storeOp: 'store' }],
73+
timestampWrites: {
74+
querySet,
75+
beginningOfPassWriteIndex: 0,
76+
endOfPassWriteIndex: 1,
77+
},
78+
});
79+
pass.end();
80+
break;
81+
}
82+
}
83+
}
84+
85+
const shouldError = false; // just expect no error
86+
t.expectValidationError(() => t.device.queue.submit([encoder.finish()]), shouldError);
87+
});
88+
89+
g.test('many_slots')
90+
.desc(
91+
`
92+
Test creating and using 4k query slots.
93+
94+
Metal has the limit that a MTLCounterSampleBuffer can be max 32k which is 4k slots.
95+
So, test we can use 4k slots across a few QuerySets
96+
`
97+
)
98+
.params(u => u.combine('stage', ['compute', 'render'] as const))
99+
.fn(t => {
100+
const { stage } = t.params;
101+
102+
t.skipIfDeviceDoesNotHaveFeature('timestamp-query');
103+
const kNumSlots = 4096;
104+
const kNumQuerySets = 4;
105+
106+
const view = t
107+
.createTextureTracked({
108+
size: [1, 1, 1],
109+
format: 'rgba8unorm',
110+
usage: GPUTextureUsage.RENDER_ATTACHMENT,
111+
})
112+
.createView();
113+
const encoder = t.device.createCommandEncoder();
114+
115+
for (let i = 0; i < kNumQuerySets; ++i) {
116+
const querySet = t.createQuerySetTracked({
117+
type: 'timestamp',
118+
count: kNumSlots,
119+
});
120+
121+
switch (stage) {
122+
case 'compute': {
123+
for (let slot = 0; slot < kNumSlots; slot += 2) {
124+
const pass = encoder.beginComputePass({
125+
timestampWrites: {
126+
querySet,
127+
beginningOfPassWriteIndex: slot,
128+
endOfPassWriteIndex: slot + 1,
129+
},
130+
});
131+
pass.end();
132+
}
133+
break;
134+
}
135+
case 'render': {
136+
for (let slot = 0; slot < kNumSlots; slot += 2) {
137+
const pass = encoder.beginRenderPass({
138+
colorAttachments: [{ view, loadOp: 'load', storeOp: 'store' }],
139+
timestampWrites: {
140+
querySet,
141+
beginningOfPassWriteIndex: slot,
142+
endOfPassWriteIndex: slot + 1,
143+
},
144+
});
145+
pass.end();
146+
}
147+
break;
148+
}
149+
}
150+
}
151+
152+
const shouldError = false; // just expect no error
153+
t.expectValidationError(() => t.device.queue.submit([encoder.finish()]), shouldError);
154+
});

0 commit comments

Comments
 (0)