Skip to content

Commit

Permalink
Add 'buffer,usage' test to createBindGroup.spec.ts (#1820)
Browse files Browse the repository at this point in the history
The specification says that the resource buffer type should include
'UNIFORM' if the BindGroup entry defines buffer and the buffer's type
is 'uniform'. So this PR adds a test to ensure that a validation error
is generated when the usage doesn't contain 'UNIFORM'.

Issue: #884
  • Loading branch information
Gyuyoung authored Sep 5, 2022
1 parent 888ada8 commit 25c9f4e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/webgpu/api/validation/createBindGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
bufferBindingEntries,
bufferBindingTypeInfo,
kBindableResources,
kBufferUsages,
kTextureUsages,
kTextureViewDimensions,
sampledAndStorageBindingEntries,
Expand Down Expand Up @@ -743,3 +744,52 @@ g.test('storage_texture,mip_level_count')
});
}, mipLevelCount !== 1);
});

g.test('buffer,usage')
.desc(
`
Test that the buffer usage contains 'uniform' if the BindGroup entry defines
buffer and it's type is 'uniform'.
`
)
.params(u =>
u //
// If usage0 and usage1 are the same, the usage being test is a single usage. Otherwise, it's
// a combined usage.
.combine('usage0', kBufferUsages)
.combine('usage1', kBufferUsages)
.unless(
({ usage0, usage1 }) =>
((usage0 | usage1) & (GPUConst.BufferUsage.MAP_READ | GPUConst.BufferUsage.MAP_WRITE)) !==
0
)
)
.fn(async t => {
const { usage0, usage1 } = t.params;

const usage = usage0 | usage1;

const bindGroupLayout = t.device.createBindGroupLayout({
entries: [
{
binding: 0,
visibility: GPUShaderStage.COMPUTE,
buffer: { type: 'uniform' },
},
],
});

const buffer = t.device.createBuffer({
size: 4,
usage,
});

const isValid = GPUBufferUsage.UNIFORM & usage;

t.expectValidationError(() => {
t.device.createBindGroup({
entries: [{ binding: 0, resource: { buffer } }],
layout: bindGroupLayout,
});
}, !isValid);
});

0 comments on commit 25c9f4e

Please sign in to comment.