From 260d977861863b485d5cdc94167c7a8ecd553760 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Mon, 18 Mar 2024 16:27:18 -0700 Subject: [PATCH] WGSL validation tests for textureLoad and textureStore --- src/webgpu/gpu_test.ts | 20 + src/webgpu/listing_meta.json | 9 + .../call/builtin/textureLoad.spec.ts | 370 ++++++++++++++++++ .../call/builtin/textureStore.spec.ts | 168 ++++++++ 4 files changed, 567 insertions(+) create mode 100644 src/webgpu/shader/validation/expression/call/builtin/textureLoad.spec.ts create mode 100644 src/webgpu/shader/validation/expression/call/builtin/textureStore.spec.ts diff --git a/src/webgpu/gpu_test.ts b/src/webgpu/gpu_test.ts index 1f021218d290..d22db9330f71 100644 --- a/src/webgpu/gpu_test.ts +++ b/src/webgpu/gpu_test.ts @@ -283,6 +283,26 @@ export class GPUTestSubcaseBatchState extends SubcaseBatchState { ); } } + + /** Skips this test case if the `langFeature` is *not* supported. */ + skipIfLanguageFeatureNotSupported(langFeature: WGSLLanguageFeature) { + if (!this.hasLanguageFeature(langFeature)) { + this.skip(`WGSL language feature '${langFeature}' is not supported`); + } + } + + /** Skips this test case if the `langFeature` is supported. */ + skipIfLanguageFeatureSupported(langFeature: WGSLLanguageFeature) { + if (this.hasLanguageFeature(langFeature)) { + this.skip(`WGSL language feature '${langFeature}' is supported`); + } + } + + /** returns true iff the `langFeature` is supported */ + hasLanguageFeature(langFeature: WGSLLanguageFeature) { + const lf = getGPU(this.recorder).wgslLanguageFeatures; + return lf !== undefined && lf.has(langFeature); + } } /** diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index 6712c5d7df14..9f59f6c79341 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1975,6 +1975,12 @@ "webgpu:shader,validation,expression,call,builtin,sqrt:values:*": { "subcaseMS": 0.302 }, "webgpu:shader,validation,expression,call,builtin,tan:integer_argument:*": { "subcaseMS": 1.734 }, "webgpu:shader,validation,expression,call,builtin,tan:values:*": { "subcaseMS": 0.350 }, + "webgpu:shader,validation,expression,call,builtin,textureLoad:array_index_argument,non_storage:*": { "subcaseMS": 1.358 }, + "webgpu:shader,validation,expression,call,builtin,textureLoad:array_index_argument,storage:*": { "subcaseMS": 1.906 }, + "webgpu:shader,validation,expression,call,builtin,textureLoad:coords_argument,non_storage:*": { "subcaseMS": 1.717 }, + "webgpu:shader,validation,expression,call,builtin,textureLoad:coords_argument,storage:*": { "subcaseMS": 1.750 }, + "webgpu:shader,validation,expression,call,builtin,textureLoad:level_argument,non_storage:*": { "subcaseMS": 1.113 }, + "webgpu:shader,validation,expression,call,builtin,textureLoad:sample_index_argument,non_storage:*": { "subcaseMS": 1.395 }, "webgpu:shader,validation,expression,call,builtin,textureSample:array_index_argument:*": { "subcaseMS": 1.888 }, "webgpu:shader,validation,expression,call,builtin,textureSample:coords_argument:*": { "subcaseMS": 1.342 }, "webgpu:shader,validation,expression,call,builtin,textureSample:offset_argument,non_const:*": { "subcaseMS": 1.604 }, @@ -2009,6 +2015,9 @@ "webgpu:shader,validation,expression,call,builtin,textureSampleLevel:level_argument:*": { "subcaseMS": 1.422 }, "webgpu:shader,validation,expression,call,builtin,textureSampleLevel:offset_argument,non_const:*": { "subcaseMS": 1.604 }, "webgpu:shader,validation,expression,call,builtin,textureSampleLevel:offset_argument:*": { "subcaseMS": 1.401 }, + "webgpu:shader,validation,expression,call,builtin,textureStore:array_index_argument:*": { "subcaseMS": 1.240 }, + "webgpu:shader,validation,expression,call,builtin,textureStore:coords_argument:*": { "subcaseMS": 1.350 }, + "webgpu:shader,validation,expression,call,builtin,textureStore:value_argument:*": { "subcaseMS": 1.442 }, "webgpu:shader,validation,expression,call,builtin,unpack4xI8:args:*": { "subcaseMS": 23.923 }, "webgpu:shader,validation,expression,call,builtin,unpack4xI8:must_use:*": { "subcaseMS": 35.200 }, "webgpu:shader,validation,expression,call,builtin,unpack4xI8:supported:*": { "subcaseMS": 24.150 }, diff --git a/src/webgpu/shader/validation/expression/call/builtin/textureLoad.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/textureLoad.spec.ts new file mode 100644 index 000000000000..9138b2ecc67c --- /dev/null +++ b/src/webgpu/shader/validation/expression/call/builtin/textureLoad.spec.ts @@ -0,0 +1,370 @@ +const builtin = 'textureLoad'; +export const description = ` +Validation tests for the ${builtin}() builtin. + +* test textureLoad coords parameter must be correct type +* test textureLoad array_index parameter must be correct type +* test textureLoad level parameter must be correct type +* test textureLoad sample_index parameter must be correct type +`; + +import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; +import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; +import { assert } from '../../../../../../common/util/util.js'; +import { kAllTextureFormats, kTextureFormatInfo } from '../../../../../format_info.js'; +import { + Type, + kAllScalarsAndVectors, + isConvertible, + ScalarType, + VectorType, + isUnsignedType, +} from '../../../../../util/conversion.js'; +import { ShaderValidationTest } from '../../../shader_validation_test.js'; + +type TextureLoadArguments = { + coordsArgTypes: readonly [ScalarType | VectorType, ScalarType | VectorType]; + usesMultipleTypes?: boolean; // texture can use f32, i32, u32 + hasArrayIndexArg?: boolean; + hasLevelArg?: boolean; + hasSampleIndexArg?: boolean; +}; + +const kCoords1DTypes = [Type.i32, Type.u32] as const; +const kCoords2DTypes = [Type.vec2i, Type.vec2u] as const; +const kCoords3DTypes = [Type.vec3i, Type.vec3u] as const; + +const kValidTextureLoadParameterTypesForNonStorageTextures: { [n: string]: TextureLoadArguments } = + { + texture_1d: { usesMultipleTypes: true, coordsArgTypes: kCoords1DTypes, hasLevelArg: true }, + texture_2d: { usesMultipleTypes: true, coordsArgTypes: kCoords2DTypes, hasLevelArg: true }, + texture_2d_array: { + usesMultipleTypes: true, + coordsArgTypes: kCoords2DTypes, + hasArrayIndexArg: true, + hasLevelArg: true, + }, + texture_3d: { usesMultipleTypes: true, coordsArgTypes: kCoords3DTypes, hasLevelArg: true }, + texture_multisampled_2d: { + usesMultipleTypes: true, + coordsArgTypes: kCoords2DTypes, + hasSampleIndexArg: true, + }, + texture_depth_2d: { coordsArgTypes: kCoords2DTypes, hasLevelArg: true }, + texture_depth_2d_array: { + coordsArgTypes: kCoords2DTypes, + hasArrayIndexArg: true, + hasLevelArg: true, + }, + texture_depth_multisampled_2d: { coordsArgTypes: kCoords2DTypes, hasSampleIndexArg: true }, + texture_external: { coordsArgTypes: kCoords2DTypes }, + }; + +const kValidTextureLoadParameterTypesForStorageTextures: { [n: string]: TextureLoadArguments } = { + texture_storage_1d: { coordsArgTypes: [Type.i32, Type.u32] }, + texture_storage_2d: { coordsArgTypes: [Type.vec2i, Type.vec2u] }, + texture_storage_2d_array: { + coordsArgTypes: [Type.vec2i, Type.vec2u], + hasArrayIndexArg: true, + }, + texture_storage_3d: { coordsArgTypes: [Type.vec3i, Type.vec3u] }, +} as const; + +const kNonStorageTextureTypes = keysOf(kValidTextureLoadParameterTypesForNonStorageTextures); +const kStorageTextureTypes = keysOf(kValidTextureLoadParameterTypesForStorageTextures); +const kValuesTypes = objectsToRecord(kAllScalarsAndVectors); + +const kTexelType: { [n: string]: Type } = { + f32: Type.vec4f, + i32: Type.vec4i, + u32: Type.vec4u, +} as const; + +const kTexelTypes = keysOf(kTexelType); + +export const g = makeTestGroup(ShaderValidationTest); + +g.test('coords_argument,non_storage') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#textureload') + .desc( + ` +Validates that only incorrect coords arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kNonStorageTextureTypes) + .combine('coordType', keysOf(kValuesTypes)) + .beginSubcases() + .expand('texelType', t => + kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].usesMultipleTypes + ? kTexelTypes + : [''] + ) + .combine('value', [-1, 0, 1] as const) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.coordType]) || t.value >= 0) + ) + .fn(t => { + const { textureType, coordType, texelType, value } = t.params; + const coordArgType = kValuesTypes[coordType]; + const { coordsArgTypes, hasArrayIndexArg, hasLevelArg, hasSampleIndexArg } = + kValidTextureLoadParameterTypesForNonStorageTextures[textureType]; + + const texelTypeWGSL = texelType ? `<${texelType}>` : ''; + const coordWGSL = coordArgType.create(value).wgsl(); + const arrayWGSL = hasArrayIndexArg ? ', 0' : ''; + const levelWGSL = hasLevelArg ? ', 0' : ''; + const sampleIndexWGSL = hasSampleIndexArg ? ', 0' : ''; + + const code = ` +@group(0) @binding(0) var t: ${textureType}${texelTypeWGSL}; +@fragment fn fs() -> @location(0) vec4f { + _ = textureLoad(t, ${coordWGSL}${arrayWGSL}${levelWGSL}${sampleIndexWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(coordArgType, coordsArgTypes[0]) || + isConvertible(coordArgType, coordsArgTypes[1]); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('coords_argument,storage') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#textureload') + .desc( + ` +Validates that only incorrect coords arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kStorageTextureTypes) + .combine('coordType', keysOf(kValuesTypes)) + .beginSubcases() + .combine('format', kAllTextureFormats) + // filter to only storage texture formats. + .filter(t => !!kTextureFormatInfo[t.format].color?.storage) + .combine('value', [-1, 0, 1] as const) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.coordType]) || t.value >= 0) + ) + .beforeAllSubcases(t => + t.skipIfLanguageFeatureNotSupported('readonly_and_readwrite_storage_textures') + ) + .fn(t => { + const { textureType, coordType, format, value } = t.params; + const coordArgType = kValuesTypes[coordType]; + const { coordsArgTypes, hasArrayIndexArg } = + kValidTextureLoadParameterTypesForStorageTextures[textureType]; + + const coordWGSL = coordArgType.create(value).wgsl(); + const arrayWGSL = hasArrayIndexArg ? ', 0' : ''; + + const code = ` +@group(0) @binding(0) var t: ${textureType}<${format}, read>; +@fragment fn fs() -> @location(0) vec4f { + _ = textureLoad(t, ${coordWGSL}${arrayWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(coordArgType, coordsArgTypes[0]) || + isConvertible(coordArgType, coordsArgTypes[1]); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('array_index_argument,non_storage') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#textureload') + .desc( + ` +Validates that only incorrect array_index arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kNonStorageTextureTypes) + // filter out types with no array_index + .filter( + t => !!kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].hasArrayIndexArg + ) + .combine('arrayIndexType', keysOf(kValuesTypes)) + .beginSubcases() + .expand('texelType', t => + kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].usesMultipleTypes + ? kTexelTypes + : [''] + ) + .combine('value', [-1, 0, 1]) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.arrayIndexType]) || t.value >= 0) + ) + .fn(t => { + const { textureType, arrayIndexType, texelType, value } = t.params; + const arrayIndexArgType = kValuesTypes[arrayIndexType]; + const args = [arrayIndexArgType.create(value)]; + const { coordsArgTypes, hasLevelArg } = + kValidTextureLoadParameterTypesForNonStorageTextures[textureType]; + + const texelTypeWGSL = texelType ? `<${texelType}>` : ''; + const coordWGSL = coordsArgTypes[0].create(0).wgsl(); + const arrayWGSL = args.map(arg => arg.wgsl()).join(', '); + const levelWGSL = hasLevelArg ? ', 0' : ''; + + const code = ` +@group(0) @binding(0) var t: ${textureType}${texelTypeWGSL}; +@fragment fn fs() -> @location(0) vec4f { + _ = textureLoad(t, ${coordWGSL}, ${arrayWGSL}${levelWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(arrayIndexArgType, Type.i32) || isConvertible(arrayIndexArgType, Type.u32); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('array_index_argument,storage') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#textureload') + .desc( + ` +Validates that only incorrect array_index arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kStorageTextureTypes) + // filter out types with no array_index + .filter( + t => !!kValidTextureLoadParameterTypesForStorageTextures[t.textureType].hasArrayIndexArg + ) + .combine('arrayIndexType', keysOf(kValuesTypes)) + .beginSubcases() + .combine('format', kAllTextureFormats) + // filter to only storage texture formats. + .filter(t => !!kTextureFormatInfo[t.format].color?.storage) + .combine('value', [-1, 0, 1]) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.arrayIndexType]) || t.value >= 0) + ) + .beforeAllSubcases(t => + t.skipIfLanguageFeatureNotSupported('readonly_and_readwrite_storage_textures') + ) + .fn(t => { + const { textureType, arrayIndexType, format, value } = t.params; + const arrayIndexArgType = kValuesTypes[arrayIndexType]; + const args = [arrayIndexArgType.create(value)]; + const { coordsArgTypes, hasLevelArg } = + kValidTextureLoadParameterTypesForStorageTextures[textureType]; + + const coordWGSL = coordsArgTypes[0].create(0).wgsl(); + const arrayWGSL = args.map(arg => arg.wgsl()).join(', '); + const levelWGSL = hasLevelArg ? ', 0' : ''; + + const code = ` +@group(0) @binding(0) var t: ${textureType}<${format}, read>; +@fragment fn fs() -> @location(0) vec4f { + _ = textureLoad(t, ${coordWGSL}, ${arrayWGSL}${levelWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(arrayIndexArgType, Type.i32) || isConvertible(arrayIndexArgType, Type.u32); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('level_argument,non_storage') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#textureload') + .desc( + ` +Validates that only incorrect level arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kNonStorageTextureTypes) + // filter out types with no level + .filter( + t => !!kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].hasLevelArg + ) + .combine('levelType', keysOf(kValuesTypes)) + .beginSubcases() + .expand('texelType', t => + kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].usesMultipleTypes + ? kTexelTypes + : [''] + ) + .combine('value', [-1, 0, 1]) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.levelType]) || t.value >= 0) + ) + .fn(t => { + const { textureType, levelType, texelType, value } = t.params; + const levelArgType = kValuesTypes[levelType]; + const { coordsArgTypes, hasArrayIndexArg } = + kValidTextureLoadParameterTypesForNonStorageTextures[textureType]; + + const texelTypeWGSL = texelType ? `<${texelType}>` : ''; + const coordWGSL = coordsArgTypes[0].create(0).wgsl(); + const arrayWGSL = hasArrayIndexArg ? ', 0' : ''; + const levelWGSL = levelArgType.create(value).wgsl(); + + const code = ` +@group(0) @binding(0) var t: ${textureType}${texelTypeWGSL}; +@fragment fn fs() -> @location(0) vec4f { + _ = textureLoad(t, ${coordWGSL}${arrayWGSL}, ${levelWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(levelArgType, Type.i32) || isConvertible(levelArgType, Type.u32); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('sample_index_argument,non_storage') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#textureload') + .desc( + ` +Validates that only incorrect sample_index arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kNonStorageTextureTypes) + // filter out types with no sample_index + .filter( + t => !!kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].hasSampleIndexArg + ) + .combine('sampleIndexType', keysOf(kValuesTypes)) + .beginSubcases() + .expand('texelType', t => + kValidTextureLoadParameterTypesForNonStorageTextures[t.textureType].usesMultipleTypes + ? kTexelTypes + : [''] + ) + .combine('value', [-1, 0, 1]) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.sampleIndexType]) || t.value >= 0) + ) + .fn(t => { + const { textureType, sampleIndexType, texelType, value } = t.params; + const sampleIndexArgType = kValuesTypes[sampleIndexType]; + const { coordsArgTypes, hasArrayIndexArg, hasLevelArg } = + kValidTextureLoadParameterTypesForNonStorageTextures[textureType]; + assert(!hasLevelArg); + + const texelTypeWGSL = texelType ? `<${texelType}>` : ''; + const coordWGSL = coordsArgTypes[0].create(0).wgsl(); + const arrayWGSL = hasArrayIndexArg ? ', 0' : ''; + const sampleIndexWGSL = sampleIndexArgType.create(value).wgsl(); + + const code = ` +@group(0) @binding(0) var t: ${textureType}${texelTypeWGSL}; +@fragment fn fs() -> @location(0) vec4f { + _ = textureLoad(t, ${coordWGSL}${arrayWGSL}, ${sampleIndexWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(sampleIndexArgType, Type.i32) || isConvertible(sampleIndexArgType, Type.u32); + t.expectCompileResult(expectSuccess, code); + }); diff --git a/src/webgpu/shader/validation/expression/call/builtin/textureStore.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/textureStore.spec.ts new file mode 100644 index 000000000000..66133777323b --- /dev/null +++ b/src/webgpu/shader/validation/expression/call/builtin/textureStore.spec.ts @@ -0,0 +1,168 @@ +const builtin = 'textureStore'; +export const description = ` +Validation tests for the ${builtin}() builtin. + +* test textureStore coords parameter must be correct type +* test textureStore array_index parameter must be correct type +* test textureStore value parameter must be correct type +`; + +import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; +import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; +import { kAllTextureFormats, kTextureFormatInfo } from '../../../../../format_info.js'; +import { + Type, + kAllScalarsAndVectors, + isConvertible, + ScalarType, + VectorType, + isUnsignedType, +} from '../../../../../util/conversion.js'; +import { ShaderValidationTest } from '../../../shader_validation_test.js'; + +const kTextureColorTypeToType = { + sint: Type.vec4i, + uint: Type.vec4u, + float: Type.vec4f, + 'unfilterable-float': Type.vec4f, +}; + +type TextureStoreArguments = { + coordsArgTypes: readonly [ScalarType | VectorType, ScalarType | VectorType]; + hasArrayIndexArg?: boolean; +}; + +const kValidTextureStoreParameterTypes: { [n: string]: TextureStoreArguments } = { + texture_storage_1d: { coordsArgTypes: [Type.i32, Type.u32] }, + texture_storage_2d: { coordsArgTypes: [Type.vec2i, Type.vec2u] }, + texture_storage_2d_array: { + coordsArgTypes: [Type.vec2i, Type.vec2u], + hasArrayIndexArg: true, + }, + texture_storage_3d: { coordsArgTypes: [Type.vec3i, Type.vec3u] }, +} as const; + +const kTextureTypes = keysOf(kValidTextureStoreParameterTypes); +const kValuesTypes = objectsToRecord(kAllScalarsAndVectors); + +export const g = makeTestGroup(ShaderValidationTest); + +g.test('coords_argument') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#texturestore') + .desc( + ` +Validates that only incorrect coords arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', keysOf(kValidTextureStoreParameterTypes)) + .combine('coordType', keysOf(kValuesTypes)) + .beginSubcases() + .combine('value', [-1, 0, 1] as const) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.coordType]) || t.value >= 0) + ) + .fn(t => { + const { textureType, coordType, value } = t.params; + const coordArgType = kValuesTypes[coordType]; + const { coordsArgTypes, hasArrayIndexArg } = kValidTextureStoreParameterTypes[textureType]; + + const coordWGSL = coordArgType.create(value).wgsl(); + const arrayWGSL = hasArrayIndexArg ? ', 0' : ''; + const format = 'rgba8unorm'; + const valueWGSL = 'vec4f(0)'; + + const code = ` +@group(0) @binding(0) var t: ${textureType}<${format},write>; +@fragment fn fs() -> @location(0) vec4f { + textureStore(t, ${coordWGSL}${arrayWGSL}, ${valueWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(coordArgType, coordsArgTypes[0]) || + isConvertible(coordArgType, coordsArgTypes[1]); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('array_index_argument') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#texturestore') + .desc( + ` +Validates that only incorrect array_index arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kTextureTypes) + // filter out types with no array_index + .filter(t => !!kValidTextureStoreParameterTypes[t.textureType].hasArrayIndexArg) + .combine('arrayIndexType', keysOf(kValuesTypes)) + .beginSubcases() + .combine('value', [-9, -8, 0, 7, 8]) + // filter out unsigned types with negative values + .filter(t => !isUnsignedType(kValuesTypes[t.arrayIndexType]) || t.value >= 0) + ) + .fn(t => { + const { textureType, arrayIndexType, value } = t.params; + const arrayIndexArgType = kValuesTypes[arrayIndexType]; + const args = [arrayIndexArgType.create(value)]; + const { coordsArgTypes } = kValidTextureStoreParameterTypes[textureType]; + + const coordWGSL = coordsArgTypes[0].create(0).wgsl(); + const arrayWGSL = args.map(arg => arg.wgsl()).join(', '); + const format = 'rgba8unorm'; + const valueWGSL = 'vec4f(0)'; + + const code = ` +@group(0) @binding(0) var t: ${textureType}<${format}, write>; +@fragment fn fs() -> @location(0) vec4f { + textureStore(t, ${coordWGSL}, ${arrayWGSL}, ${valueWGSL}); + return vec4f(0); +} +`; + const expectSuccess = + isConvertible(arrayIndexArgType, Type.i32) || isConvertible(arrayIndexArgType, Type.u32); + t.expectCompileResult(expectSuccess, code); + }); + +g.test('value_argument') + .specURL('https://gpuweb.github.io/gpuweb/wgsl/#texturestore') + .desc( + ` +Validates that only incorrect value arguments are rejected by ${builtin} +` + ) + .params(u => + u + .combine('textureType', kTextureTypes) + .combine('valueType', keysOf(kValuesTypes)) + .beginSubcases() + .combine('format', kAllTextureFormats) + // filter to only storage texture formats. + .filter(t => !!kTextureFormatInfo[t.format].color?.storage) + .combine('value', [0, 1, 2]) + ) + .fn(t => { + const { textureType, valueType, format, value } = t.params; + const valueArgType = kValuesTypes[valueType]; + const args = [valueArgType.create(value)]; + const { coordsArgTypes, hasArrayIndexArg } = kValidTextureStoreParameterTypes[textureType]; + + const coordWGSL = coordsArgTypes[0].create(0).wgsl(); + const arrayWGSL = hasArrayIndexArg ? ', 0' : ''; + const valueWGSL = args.map(arg => arg.wgsl()).join(', '); + + const code = ` +@group(0) @binding(0) var t: ${textureType}<${format}, write>; +@fragment fn fs() -> @location(0) vec4f { + textureStore(t, ${coordWGSL}${arrayWGSL}, ${valueWGSL}); + return vec4f(0); +} +`; + const colorType = kTextureFormatInfo[format].color?.type; + const requiredValueType = kTextureColorTypeToType[colorType!]; + const expectSuccess = isConvertible(valueArgType, requiredValueType); + t.expectCompileResult(expectSuccess, code); + });