Skip to content

Commit

Permalink
Add tests about creating bind group layouts with new storage texture …
Browse files Browse the repository at this point in the history
…accesses
  • Loading branch information
Jiawei-Shao committed Nov 22, 2023
1 parent 7dda75f commit 90482d6
Show file tree
Hide file tree
Showing 5 changed files with 814 additions and 125 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@types/serve-index": "^1.9.3",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@webgpu/types": "^0.1.38",
"@webgpu/types": "^0.1.39",
"ansi-colors": "4.1.3",
"babel-plugin-add-header-comment": "^1.0.3",
"babel-plugin-const-enum": "^1.2.0",
Expand Down
46 changes: 27 additions & 19 deletions src/webgpu/api/validation/createBindGroupLayout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ g.test('visibility,VERTEX_shader_stage_storage_texture_access')
.fn(t => {
const { shaderStage, access } = t.params;

const appliedSuccess = access ?? 'write-only';
const success = !(
(access ?? 'write-only') === 'write-only' && shaderStage & GPUShaderStage.VERTEX
(appliedSuccess === 'write-only' || appliedSuccess === 'read-write') &&
shaderStage & GPUShaderStage.VERTEX
);

t.expectValidationError(() => {
Expand All @@ -173,7 +175,7 @@ g.test('visibility,VERTEX_shader_stage_storage_texture_access')
{
binding: 0,
visibility: shaderStage,
storageTexture: { access, format: 'rgba8unorm' },
storageTexture: { access, format: 'r32uint' },
},
],
});
Expand Down Expand Up @@ -436,29 +438,35 @@ g.test('storage_texture,layout_dimension')
g.test('storage_texture,formats')
.desc(
`
Test that a validation error is generated if the format doesn't support the storage usage.
Test that a validation error is generated if the format doesn't support the storage usage. A
validation error is also generated if the format doesn't support the 'read-write' storage access
when the storage access is 'read-write'.
`
)
.params(u => u.combine('format', kAllTextureFormats))
.params(u =>
u.combine('format', kAllTextureFormats).combine('access', kStorageTextureAccessValues)
)
.beforeAllSubcases(t => {
t.selectDeviceForTextureFormatOrSkipTestCase(t.params.format);
})
.fn(t => {
const { format } = t.params;
const { format, access } = t.params;
const info = kTextureFormatInfo[format];

t.expectValidationError(
() => {
t.device.createBindGroupLayout({
entries: [
{
binding: 0,
visibility: GPUShaderStage.COMPUTE,
storageTexture: { format },
},
],
});
},
!info.color?.storage
);
let success = info.color?.storage;
if (access === 'read-write' && !info.color?.readWriteStorage) {
success = false;
}

t.expectValidationError(() => {
t.device.createBindGroupLayout({
entries: [
{
binding: 0,
visibility: GPUShaderStage.COMPUTE,
storageTexture: { format, access },
},
],
});
}, !success);
});
2 changes: 1 addition & 1 deletion src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export function storageTextureBindingTypeInfo(d: GPUStorageTextureBindingLayout)
};
}
/** List of all GPUStorageTextureAccess values. */
export const kStorageTextureAccessValues = ['write-only'] as const;
export const kStorageTextureAccessValues = ['read-only', 'read-write', 'write-only'] as const;
assertTypeTrue<TypeEqual<GPUStorageTextureAccess, (typeof kStorageTextureAccessValues)[number]>>();

/** GPUBindGroupLayoutEntry, but only the "union" fields, not the common fields. */
Expand Down
Loading

0 comments on commit 90482d6

Please sign in to comment.