Skip to content

Commit d88504e

Browse files
authored
Add validation tests on BGRA8Unorm canvas with StorageBinding usage (#2348)
* Add validation tests on BGRA8Unorm canvas with StorageBinding usage This patch adds the validation tests about configuring an BGRA8Unorm canvas with StorageBinding usage. * Fix typo * Address reviewer's comments
1 parent 8d827d0 commit d88504e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

src/webgpu/api/validation/texture/bgra8unorm_storage.spec.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ Tests for capabilities added by bgra8unorm-storage flag.
33
`;
44

55
import { makeTestGroup } from '../../../../common/framework/test_group.js';
6+
import { assert } from '../../../../common/util/util.js';
7+
import { kTextureUsages } from '../../../capability_info.js';
68
import { GPUConst } from '../../../constants.js';
9+
import { kAllCanvasTypes, createCanvas } from '../../../util/create_elements.js';
710
import { ValidationTest } from '../validation_test.js';
811

912
class BGRA8UnormStorageValidationTests extends ValidationTest {
@@ -108,3 +111,95 @@ if the feature bgra8unorm-storage is not enabled.
108111

109112
t.testCreateShaderModuleWithBGRA8UnormStorage(shaderType, false);
110113
});
114+
115+
g.test('configure_storage_usage_on_canvas_context_without_bgra8unorm_storage')
116+
.desc(
117+
`
118+
Test that it is invalid to configure a GPUCanvasContext to 'GPUStorageBinding' usage with
119+
'bgra8unorm' format on a GPUDevice with 'bgra8unorm-storage' disabled.
120+
`
121+
)
122+
.params(u =>
123+
u
124+
.combine('canvasType', kAllCanvasTypes)
125+
.beginSubcases()
126+
.expand('usage', p => {
127+
const usageSet = new Set<number>();
128+
for (const usage0 of kTextureUsages) {
129+
for (const usage1 of kTextureUsages) {
130+
usageSet.add(usage0 | usage1);
131+
}
132+
}
133+
return usageSet;
134+
})
135+
)
136+
.fn(t => {
137+
const { canvasType, usage } = t.params;
138+
const canvas = createCanvas(t, canvasType, 1, 1);
139+
const ctx = canvas.getContext('webgpu');
140+
assert(ctx instanceof GPUCanvasContext, 'Failed to get WebGPU context from canvas');
141+
142+
const requiredStorageBinding = !!(usage & GPUTextureUsage.STORAGE_BINDING);
143+
t.expectValidationError(() => {
144+
ctx.configure({
145+
device: t.device,
146+
format: 'bgra8unorm',
147+
usage,
148+
});
149+
}, requiredStorageBinding);
150+
});
151+
152+
g.test('configure_storage_usage_on_canvas_context_with_bgra8unorm_storage')
153+
.desc(
154+
`
155+
Test that it is valid to configure a GPUCanvasContext with GPUStorageBinding usage and a GPUDevice
156+
with 'bgra8unorm-storage' enabled.
157+
`
158+
)
159+
.beforeAllSubcases(t => {
160+
t.selectDeviceOrSkipTestCase('bgra8unorm-storage');
161+
})
162+
.params(u =>
163+
u
164+
.combine('canvasType', kAllCanvasTypes)
165+
.beginSubcases()
166+
.expand('usage', p => {
167+
const usageSet = new Set<number>();
168+
for (const usage of kTextureUsages) {
169+
usageSet.add(usage | GPUConst.TextureUsage.STORAGE_BINDING);
170+
}
171+
return usageSet;
172+
})
173+
)
174+
.fn(t => {
175+
const { canvasType, usage } = t.params;
176+
const canvas = createCanvas(t, canvasType, 1, 1);
177+
const ctx = canvas.getContext('webgpu');
178+
assert(ctx instanceof GPUCanvasContext, 'Failed to get WebGPU context from canvas');
179+
180+
ctx.configure({
181+
device: t.device,
182+
format: 'bgra8unorm',
183+
usage,
184+
});
185+
186+
const currentTexture = ctx.getCurrentTexture();
187+
const bindGroupLayout = t.device.createBindGroupLayout({
188+
entries: [
189+
{
190+
binding: 0,
191+
visibility: GPUShaderStage.FRAGMENT,
192+
storageTexture: { access: 'write-only', format: currentTexture.format },
193+
},
194+
],
195+
});
196+
t.device.createBindGroup({
197+
layout: bindGroupLayout,
198+
entries: [
199+
{
200+
binding: 0,
201+
resource: currentTexture.createView(),
202+
},
203+
],
204+
});
205+
});

0 commit comments

Comments
 (0)