From 75eb28afc35958efc94aef2fe1d72c6650a0dc51 Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Fri, 8 Mar 2024 13:40:27 -0800 Subject: [PATCH 1/7] webgpu,shader,validation,types,textures --- src/webgpu/listing_meta.json | 4 + .../shader/validation/types/textures.spec.ts | 98 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/webgpu/shader/validation/types/textures.spec.ts diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index 065f3f8e9fda..b2f56667c330 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1,5 +1,6 @@ { "_comment": "SEMI AUTO-GENERATED: Please read docs/adding_timing_metadata.md.", + "": { "subcaseMS": 0.000 }, "webgpu:api,operation,adapter,requestAdapter:requestAdapter:*": { "subcaseMS": 152.083 }, "webgpu:api,operation,adapter,requestAdapter:requestAdapter_no_parameters:*": { "subcaseMS": 384.601 }, "webgpu:api,operation,adapter,requestAdapterInfo:adapter_info:*": { "subcaseMS": 136.601 }, @@ -2144,6 +2145,9 @@ "webgpu:shader,validation,types,struct:no_indirect_recursion_via_array_size:*": { "subcaseMS": 0.900 }, "webgpu:shader,validation,types,struct:no_indirect_recursion_via_struct_attribute:*": { "subcaseMS": 1.467 }, "webgpu:shader,validation,types,struct:no_indirect_recursion_via_struct_member_nested_in_alias:*": { "subcaseMS": 0.950 }, + "webgpu:shader,validation,types,textures:storage_texture_types:*": { "subcaseMS": 187.927 }, + "webgpu:shader,validation,types,textures:texel_formats,as_value:*": { "subcaseMS": 0.573 }, + "webgpu:shader,validation,types,textures:texel_formats:*": { "subcaseMS": 1864.440 }, "webgpu:shader,validation,types,vector:vector:*": { "subcaseMS": 1.295 }, "webgpu:shader,validation,uniformity,uniformity:basics:*": { "subcaseMS": 1.467 }, "webgpu:shader,validation,uniformity,uniformity:binary_expressions:*": { "subcaseMS": 1.758 }, diff --git a/src/webgpu/shader/validation/types/textures.spec.ts b/src/webgpu/shader/validation/types/textures.spec.ts new file mode 100644 index 000000000000..ce3aec97e166 --- /dev/null +++ b/src/webgpu/shader/validation/types/textures.spec.ts @@ -0,0 +1,98 @@ +export const description = ` +Validation tests for various texture types in shaders. + +TODO: +- Sampled Texture Types +- Multisampled Texture Types +- External Sampled Texture Types +- Depth Texture Types +- Sampler Types +`; + +import { makeTestGroup } from '../../../../common/framework/test_group.js'; +import { + isTextureFormatUsableAsStorageFormat, + kAllTextureFormats, + kColorTextureFormats, + kTextureFormatInfo, +} from '../../../format_info.js'; +import { getPlainTypeInfo } from '../../../util/shader.js'; +import { ShaderValidationTest } from '../shader_validation_test.js'; + +export const g = makeTestGroup(ShaderValidationTest); + +g.test('texel_formats') + .desc( + 'Test channels and channel format of various texel formats when using as the storage texture format' + ) + .params(u => + u + .combine('format', kColorTextureFormats) + .filter(p => kTextureFormatInfo[p.format].color.storage) + .beginSubcases() + .combine('shaderScalarType', ['f32', 'u32', 'i32', 'bool', 'f16'] as const) + ) + .beforeAllSubcases(t => { + if (t.params.shaderScalarType === 'f16') { + t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] }); + } + + if (!isTextureFormatUsableAsStorageFormat(t.params.format, t.isCompatibility)) { + t.skip('storage usage is unsupported'); + } + }) + .fn(t => { + const { format, shaderScalarType } = t.params; + const info = kTextureFormatInfo[format]; + const validShaderScalarType = getPlainTypeInfo(info.color.type); + const shaderValueType = `vec4<${shaderScalarType}>`; + const wgsl = ` + @group(0) @binding(0) var tex: texture_storage_2d<${format}, read>; + @compute @workgroup_size(1) fn main() { + let v : ${shaderValueType} = textureLoad(tex, vec2u(0)); + _ = v; + } +`; + t.expectCompileResult(validShaderScalarType === shaderScalarType, wgsl); + }); + +g.test('texel_formats,as_value') + .desc('Test that texel format cannot be used as value') + .fn(t => { + const wgsl = ` + @compute @workgroup_size(1) fn main() { + var i = rgba8unorm; + } +`; + t.expectCompileResult(false, wgsl); + }); + +g.test('storage_texture_types') + .desc( + `Test that for texture_storage_xx +- format must be an enumerant for one of the texel formats for storage textures +- access must be an enumerant for one of the access modes +` + ) + .params(u => + u + .combine('format', kAllTextureFormats) + .combine('access', ['read', 'write', 'read_write'] as const) + ) + .fn(t => { + const { format, access } = t.params; + const info = kTextureFormatInfo[format]; + let storage = info.color?.storage || info.depth?.storage || info.stencil?.storage || false; + if (t.isCompatibility) { + // Adjust if storage is supported under compatibility mode for formats in kCompatModeUnsupportedStorageTextureFormats. + storage = isTextureFormatUsableAsStorageFormat(format, t.isCompatibility); + } + const readWriteStorage = + info.color?.readWriteStorage || + info.depth?.readWriteStorage || + info.stencil?.readWriteStorage || + false; + const valid = access === 'read_write' ? readWriteStorage : storage; + const wgsl = `@group(0) @binding(0) var tex: texture_storage_2d<${format}, ${access}>;`; + t.expectCompileResult(valid, wgsl); + }); From 26aea4be0f1de26fc2557e0f83718b9c3a50ef5d Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Fri, 8 Mar 2024 13:49:23 -0800 Subject: [PATCH 2/7] switch param order, filter out bgra8unorm --- src/webgpu/shader/validation/types/textures.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/webgpu/shader/validation/types/textures.spec.ts b/src/webgpu/shader/validation/types/textures.spec.ts index ce3aec97e166..1156badce9e3 100644 --- a/src/webgpu/shader/validation/types/textures.spec.ts +++ b/src/webgpu/shader/validation/types/textures.spec.ts @@ -76,8 +76,10 @@ g.test('storage_texture_types') ) .params(u => u - .combine('format', kAllTextureFormats) .combine('access', ['read', 'write', 'read_write'] as const) + .combine('format', kAllTextureFormats) + // bgra8unorm-storage feature is tested at webgpu,api,validation,texture,bgra8unorm_storage + .filter(p => p.format !== 'bgra8unorm') ) .fn(t => { const { format, access } = t.params; From e8b62179770fc8e4d2362d5def28850a2ae977a7 Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Fri, 8 Mar 2024 13:51:22 -0800 Subject: [PATCH 3/7] fix listing_meta --- src/webgpu/listing_meta.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index b2f56667c330..7c8a0d6c387a 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1,6 +1,5 @@ { "_comment": "SEMI AUTO-GENERATED: Please read docs/adding_timing_metadata.md.", - "": { "subcaseMS": 0.000 }, "webgpu:api,operation,adapter,requestAdapter:requestAdapter:*": { "subcaseMS": 152.083 }, "webgpu:api,operation,adapter,requestAdapter:requestAdapter_no_parameters:*": { "subcaseMS": 384.601 }, "webgpu:api,operation,adapter,requestAdapterInfo:adapter_info:*": { "subcaseMS": 136.601 }, @@ -2145,9 +2144,9 @@ "webgpu:shader,validation,types,struct:no_indirect_recursion_via_array_size:*": { "subcaseMS": 0.900 }, "webgpu:shader,validation,types,struct:no_indirect_recursion_via_struct_attribute:*": { "subcaseMS": 1.467 }, "webgpu:shader,validation,types,struct:no_indirect_recursion_via_struct_member_nested_in_alias:*": { "subcaseMS": 0.950 }, - "webgpu:shader,validation,types,textures:storage_texture_types:*": { "subcaseMS": 187.927 }, - "webgpu:shader,validation,types,textures:texel_formats,as_value:*": { "subcaseMS": 0.573 }, - "webgpu:shader,validation,types,textures:texel_formats:*": { "subcaseMS": 1864.440 }, + "webgpu:shader,validation,types,textures:storage_texture_types:*": { "subcaseMS": 167.510 }, + "webgpu:shader,validation,types,textures:texel_formats,as_value:*": { "subcaseMS": 0.518 }, + "webgpu:shader,validation,types,textures:texel_formats:*": { "subcaseMS": 1707.432 }, "webgpu:shader,validation,types,vector:vector:*": { "subcaseMS": 1.295 }, "webgpu:shader,validation,uniformity,uniformity:basics:*": { "subcaseMS": 1.467 }, "webgpu:shader,validation,uniformity,uniformity:binary_expressions:*": { "subcaseMS": 1.758 }, From 4b25fea35141a12f3e33ded2ccd3498ac0f88dc2 Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Tue, 12 Mar 2024 10:56:08 -0700 Subject: [PATCH 4/7] add bgra8unorm --- src/webgpu/shader/validation/types/textures.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webgpu/shader/validation/types/textures.spec.ts b/src/webgpu/shader/validation/types/textures.spec.ts index 1156badce9e3..5447becac0c7 100644 --- a/src/webgpu/shader/validation/types/textures.spec.ts +++ b/src/webgpu/shader/validation/types/textures.spec.ts @@ -72,14 +72,14 @@ g.test('storage_texture_types') `Test that for texture_storage_xx - format must be an enumerant for one of the texel formats for storage textures - access must be an enumerant for one of the access modes + +Note: bgra8unorm need bgra8unorm-storage feature to enable storage usable. ` ) .params(u => u .combine('access', ['read', 'write', 'read_write'] as const) .combine('format', kAllTextureFormats) - // bgra8unorm-storage feature is tested at webgpu,api,validation,texture,bgra8unorm_storage - .filter(p => p.format !== 'bgra8unorm') ) .fn(t => { const { format, access } = t.params; From 01d19dafc251170bab3c273c0937734df8b8d42b Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Tue, 12 Mar 2024 13:17:08 -0700 Subject: [PATCH 5/7] reinterpret spec fixes --- .../shader/validation/types/textures.spec.ts | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/webgpu/shader/validation/types/textures.spec.ts b/src/webgpu/shader/validation/types/textures.spec.ts index 5447becac0c7..a89b316e7d5d 100644 --- a/src/webgpu/shader/validation/types/textures.spec.ts +++ b/src/webgpu/shader/validation/types/textures.spec.ts @@ -67,34 +67,30 @@ g.test('texel_formats,as_value') t.expectCompileResult(false, wgsl); }); +const kAccessModes = ['read', 'write', 'read_write']; + g.test('storage_texture_types') .desc( `Test that for texture_storage_xx - format must be an enumerant for one of the texel formats for storage textures - access must be an enumerant for one of the access modes -Note: bgra8unorm need bgra8unorm-storage feature to enable storage usable. +Besides, the shader compilation should always pass regardless of whether the format supports the usage indicated by the access or not. ` ) .params(u => - u - .combine('access', ['read', 'write', 'read_write'] as const) - .combine('format', kAllTextureFormats) + u.combine('access', [...kAccessModes, 'storage'] as const).combine('format', kAllTextureFormats) ) .fn(t => { const { format, access } = t.params; const info = kTextureFormatInfo[format]; - let storage = info.color?.storage || info.depth?.storage || info.stencil?.storage || false; + let isFormatValid = + info.color?.storage || info.depth?.storage || info.stencil?.storage || false; if (t.isCompatibility) { // Adjust if storage is supported under compatibility mode for formats in kCompatModeUnsupportedStorageTextureFormats. - storage = isTextureFormatUsableAsStorageFormat(format, t.isCompatibility); + isFormatValid = isTextureFormatUsableAsStorageFormat(format, t.isCompatibility); } - const readWriteStorage = - info.color?.readWriteStorage || - info.depth?.readWriteStorage || - info.stencil?.readWriteStorage || - false; - const valid = access === 'read_write' ? readWriteStorage : storage; + const isAccessValid = kAccessModes.includes(access); const wgsl = `@group(0) @binding(0) var tex: texture_storage_2d<${format}, ${access}>;`; - t.expectCompileResult(valid, wgsl); + t.expectCompileResult(isFormatValid && isAccessValid, wgsl); }); From 48a5158c87746d8320e6add5f01c9fd02b1885db Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Wed, 13 Mar 2024 13:19:57 -0700 Subject: [PATCH 6/7] Fix comment --- src/webgpu/shader/validation/types/textures.spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/webgpu/shader/validation/types/textures.spec.ts b/src/webgpu/shader/validation/types/textures.spec.ts index a89b316e7d5d..df36eb185cbb 100644 --- a/src/webgpu/shader/validation/types/textures.spec.ts +++ b/src/webgpu/shader/validation/types/textures.spec.ts @@ -86,10 +86,6 @@ Besides, the shader compilation should always pass regardless of whether the for const info = kTextureFormatInfo[format]; let isFormatValid = info.color?.storage || info.depth?.storage || info.stencil?.storage || false; - if (t.isCompatibility) { - // Adjust if storage is supported under compatibility mode for formats in kCompatModeUnsupportedStorageTextureFormats. - isFormatValid = isTextureFormatUsableAsStorageFormat(format, t.isCompatibility); - } const isAccessValid = kAccessModes.includes(access); const wgsl = `@group(0) @binding(0) var tex: texture_storage_2d<${format}, ${access}>;`; t.expectCompileResult(isFormatValid && isAccessValid, wgsl); From 12b6a91e9f8965c880ba0d3bb31f5c1ed5fab3df Mon Sep 17 00:00:00 2001 From: Shrek Shao Date: Wed, 13 Mar 2024 13:21:55 -0700 Subject: [PATCH 7/7] fix const --- src/webgpu/shader/validation/types/textures.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgpu/shader/validation/types/textures.spec.ts b/src/webgpu/shader/validation/types/textures.spec.ts index df36eb185cbb..904fa4721b8d 100644 --- a/src/webgpu/shader/validation/types/textures.spec.ts +++ b/src/webgpu/shader/validation/types/textures.spec.ts @@ -84,7 +84,7 @@ Besides, the shader compilation should always pass regardless of whether the for .fn(t => { const { format, access } = t.params; const info = kTextureFormatInfo[format]; - let isFormatValid = + const isFormatValid = info.color?.storage || info.depth?.storage || info.stencil?.storage || false; const isAccessValid = kAccessModes.includes(access); const wgsl = `@group(0) @binding(0) var tex: texture_storage_2d<${format}, ${access}>;`;