summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts')
-rw-r--r--dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts122
1 files changed, 122 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts
index 266b4f9a12..59e8607a5f 100644
--- a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts
+++ b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/types/alias.spec.ts
@@ -3,6 +3,7 @@ Validation tests for type aliases
`;
import { makeTestGroup } from '../../../../common/framework/test_group.js';
+import { keysOf } from '../../../../common/util/data_tables.js';
import { ShaderValidationTest } from '../shader_validation_test.js';
export const g = makeTestGroup(ShaderValidationTest);
@@ -121,3 +122,124 @@ alias T = ${t.params.target};
`;
t.expectCompileResult(t.params.target === 'i32', wgsl);
});
+
+const kTypes = [
+ 'bool',
+ 'i32',
+ 'u32',
+ 'f32',
+ 'f16',
+ 'vec2<i32>',
+ 'vec3<u32>',
+ 'vec4<f32>',
+ 'mat2x2<f32>',
+ 'mat2x3<f32>',
+ 'mat2x4<f32>',
+ 'mat3x2<f32>',
+ 'mat3x3<f32>',
+ 'mat3x4<f32>',
+ 'mat4x2<f32>',
+ 'mat4x3<f32>',
+ 'mat4x4<f32>',
+ 'array<u32>',
+ 'array<i32, 4>',
+ 'array<vec2<u32>, 8>',
+ 'S',
+ 'T',
+ 'atomic<u32>',
+ 'atomic<i32>',
+ 'ptr<function, u32>',
+ 'ptr<private, i32>',
+ 'ptr<workgroup, f32>',
+ 'ptr<uniform, vec2f>',
+ 'ptr<storage, vec2u>',
+ 'ptr<storage, vec3i, read>',
+ 'ptr<storage, vec4f, read_write>',
+ 'sampler',
+ 'sampler_comparison',
+ 'texture_1d<f32>',
+ 'texture_2d<u32>',
+ 'texture_2d_array<i32>',
+ 'texture_3d<f32>',
+ 'texture_cube<i32>',
+ 'texture_cube_array<u32>',
+ 'texture_multisampled_2d<f32>',
+ 'texture_depth_multisampled_2d',
+ 'texture_external',
+ 'texture_storage_1d<rgba8snorm, write>',
+ 'texture_storage_1d<r32uint, write>',
+ 'texture_storage_1d<r32sint, read_write>',
+ 'texture_storage_1d<r32float, read>',
+ 'texture_storage_2d<rgba16uint, write>',
+ 'texture_storage_2d_array<rg32float, write>',
+ 'texture_storage_3d<bgra8unorm, write>',
+ 'texture_depth_2d',
+ 'texture_depth_2d_array',
+ 'texture_depth_cube',
+ 'texture_depth_cube_array',
+
+ // Pre-declared aliases (spot check)
+ 'vec2f',
+ 'vec3u',
+ 'vec4i',
+ 'mat2x2f',
+
+ // User-defined aliases
+ 'anotherAlias',
+ 'random_alias',
+];
+
+g.test('any_type')
+ .desc('Test that any type can be aliased')
+ .params(u => u.combine('type', kTypes))
+ .beforeAllSubcases(t => {
+ if (t.params.type === 'f16') {
+ t.selectDeviceOrSkipTestCase('shader-f16');
+ }
+ })
+ .fn(t => {
+ const ty = t.params.type;
+ t.skipIf(
+ ty.includes('texture_storage') &&
+ ty.includes('read') &&
+ !t.hasLanguageFeature('readonly_and_readwrite_storage_textures'),
+ 'Missing language feature'
+ );
+ const enable = ty === 'f16' ? 'enable f16;' : '';
+ const code = `
+ ${enable}
+ struct S { x : u32 }
+ struct T { y : S }
+ alias anotherAlias = u32;
+ alias random_alias = i32;
+ alias myType = ${ty};`;
+ t.expectCompileResult(true, code);
+ });
+
+const kMatchCases = {
+ function_param: `
+ fn foo(x : u32) { }
+ fn bar() {
+ var x : alias_alias_u32;
+ foo(x);
+ }`,
+ constructor: `var<private> v : u32 = alias_u32(1);`,
+ template_param: `var<private> v : vec2<alias_u32> = vec2<u32>();`,
+ predeclared_alias: `var<private> v : vec2<alias_alias_u32> = vec2u();`,
+ struct_element: `
+ struct S { x : alias_u32 }
+ const c_u32 = 0u;
+ const c = S(c_u32);`,
+};
+
+g.test('match_non_alias')
+ .desc('Test that type checking succeeds using aliased and unaliased type')
+ .params(u => u.combine('case', keysOf(kMatchCases)))
+ .fn(t => {
+ const testcase = kMatchCases[t.params.case];
+ const code = `
+ alias alias_u32 = u32;
+ alias alias_alias_u32 = alias_u32;
+ ${testcase}`;
+ t.expectCompileResult(true, code);
+ });