Skip to content

Commit f99f926

Browse files
authored
Updates max*BufferBindingSize limit tests to adhere to maxBufferSize (#2339)
1 parent d88504e commit f99f926

File tree

2 files changed

+54
-37
lines changed

2 files changed

+54
-37
lines changed

src/webgpu/api/validation/capability_checks/limits/maxStorageBufferBindingSize.spec.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { align, roundDown } from '../../../../util/math.js';
44
import {
55
kMaximumLimitBaseParams,
66
makeLimitTestGroup,
7+
LimitMode,
8+
getDefaultLimit,
79
MaximumLimitValueTest,
810
MaximumTestValue,
9-
kMaximumLimitValueTestKeys,
1011
} from './limit_utils.js';
1112

1213
const BufferParts = {
@@ -28,6 +29,9 @@ function getSizeAndOffsetForBufferPart(device: GPUDevice, bufferPart: BufferPart
2829

2930
const kStorageBufferRequiredSizeAlignment = 4;
3031

32+
// We also need to update the maxBufferSize limit when testing.
33+
const kExtraLimits = { maxBufferSize: 'maxLimit' as LimitMode };
34+
3135
function getDeviceLimitToRequest(
3236
limitValueTest: MaximumLimitValueTest,
3337
defaultLimit: number,
@@ -104,6 +108,13 @@ g.test('createBindGroup,at_over')
104108
});
105109

106110
const { size, offset } = getSizeAndOffsetForBufferPart(device, bufferPart, testValue);
111+
112+
// If the size of the buffer exceeds the related but separate maxBufferSize limit, we can
113+
// skip the validation since the allocation will fail with a validation error.
114+
if (size > device.limits.maxBufferSize) {
115+
return;
116+
}
117+
107118
device.pushErrorScope('out-of-memory');
108119
const storageBuffer = t.trackForCleanup(
109120
device.createBuffer({
@@ -134,19 +145,15 @@ g.test('createBindGroup,at_over')
134145
`size: ${size}, offset: ${offset}, testValue: ${testValue}`
135146
);
136147
}
137-
}
148+
},
149+
kExtraLimits
138150
);
139151
});
140152

141153
g.test('validate,maxBufferSize')
142154
.desc(`Test that ${limit} <= maxBufferSize`)
143-
.params(u => u.combine('limitTest', kMaximumLimitValueTestKeys))
144-
.fn(async t => {
145-
const { limitTest } = t.params;
146-
const { defaultLimit, adapterLimit: maximumLimit } = t;
147-
const requestedLimit = getDeviceLimitToRequest(limitTest, defaultLimit, maximumLimit);
148-
149-
await t.testDeviceWithSpecificLimits(requestedLimit, 0, ({ device, actualLimit }) => {
150-
t.expect(actualLimit <= device.limits.maxBufferSize);
151-
});
155+
.fn(t => {
156+
const { adapter, defaultLimit, adapterLimit } = t;
157+
t.expect(defaultLimit <= getDefaultLimit('maxBufferSize'));
158+
t.expect(adapterLimit <= adapter.limits.maxBufferSize);
152159
});

src/webgpu/api/validation/capability_checks/limits/maxUniformBufferBindingSize.spec.ts

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { keysOf } from '../../../../../common/util/data_tables.js';
22

33
import {
4+
LimitMode,
5+
getDefaultLimit,
46
kMaximumLimitBaseParams,
5-
kMaximumLimitValueTestKeys,
67
makeLimitTestGroup,
78
} from './limit_utils.js';
89

@@ -26,6 +27,9 @@ function getSizeAndOffsetForBufferPart(device: GPUDevice, bufferPart: BufferPart
2627
const limit = 'maxUniformBufferBindingSize';
2728
export const { g, description } = makeLimitTestGroup(limit);
2829

30+
// We also need to update the maxBufferSize limit when testing.
31+
const kExtraLimits = { maxBufferSize: 'maxLimit' as LimitMode };
32+
2933
g.test('createBindGroup,at_over')
3034
.desc(`Test using at and over ${limit} limit`)
3135
.params(kMaximumLimitBaseParams.combine('bufferPart', kBufferPartsKeys))
@@ -46,6 +50,13 @@ g.test('createBindGroup,at_over')
4650
});
4751

4852
const { size, offset } = getSizeAndOffsetForBufferPart(device, bufferPart, testValue);
53+
54+
// If the size of the buffer exceeds the related but separate maxBufferSize limit, we can
55+
// skip the validation since the allocation will fail with a validation error.
56+
if (size > device.limits.maxBufferSize) {
57+
return;
58+
}
59+
4960
device.pushErrorScope('out-of-memory');
5061
const uniformBuffer = t.trackForCleanup(
5162
device.createBuffer({
@@ -56,36 +67,35 @@ g.test('createBindGroup,at_over')
5667
const outOfMemoryError = await device.popErrorScope();
5768

5869
if (!outOfMemoryError) {
59-
await t.expectValidationError(() => {
60-
device.createBindGroup({
61-
layout: bindGroupLayout,
62-
entries: [
63-
{
64-
binding: 0,
65-
resource: {
66-
buffer: uniformBuffer,
67-
offset,
68-
size: testValue,
70+
await t.expectValidationError(
71+
() => {
72+
device.createBindGroup({
73+
layout: bindGroupLayout,
74+
entries: [
75+
{
76+
binding: 0,
77+
resource: {
78+
buffer: uniformBuffer,
79+
offset,
80+
size: testValue,
81+
},
6982
},
70-
},
71-
],
72-
});
73-
}, shouldError);
83+
],
84+
});
85+
},
86+
shouldError,
87+
`size: ${size}, offset: ${offset}, testValue: ${testValue}`
88+
);
7489
}
75-
}
90+
},
91+
kExtraLimits
7692
);
7793
});
7894

7995
g.test('validate,maxBufferSize')
8096
.desc(`Test that ${limit} <= maxBufferSize`)
81-
.params(u => u.combine('limitTest', kMaximumLimitValueTestKeys))
82-
.fn(async t => {
83-
const { limitTest } = t.params;
84-
await t.testDeviceWithRequestedMaximumLimits(
85-
limitTest,
86-
'atLimit',
87-
({ device, actualLimit }) => {
88-
t.expect(actualLimit <= device.limits.maxBufferSize);
89-
}
90-
);
97+
.fn(t => {
98+
const { adapter, defaultLimit, adapterLimit } = t;
99+
t.expect(defaultLimit <= getDefaultLimit('maxBufferSize'));
100+
t.expect(adapterLimit <= adapter.limits.maxBufferSize);
91101
});

0 commit comments

Comments
 (0)