Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,9 @@
"webgpu:shader,validation,types,atomics:type:*": { "subcaseMS": 1.050 },
"webgpu:shader,validation,types,matrix:invalid:*": { "subcaseMS": 68.086 },
"webgpu:shader,validation,types,matrix:valid:*": { "subcaseMS": 67.784 },
"webgpu:shader,validation,types,pointer:access_mode:*": { "subcaseMS": 16.078 },
"webgpu:shader,validation,types,pointer:address_space:*": { "subcaseMS": 523.598 },
"webgpu:shader,validation,types,pointer:type:*": { "subcaseMS": 11.764 },
"webgpu:shader,validation,types,ref:not_typeable_alias:*": { "subcaseMS": 6.872 },
"webgpu:shader,validation,types,ref:not_typeable_let:*": { "subcaseMS": 6.670 },
"webgpu:shader,validation,types,ref:not_typeable_param:*": { "subcaseMS": 5.951 },
Expand Down
121 changes: 121 additions & 0 deletions src/webgpu/shader/validation/types/pointer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
export const description = 'Test pointer type validation';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It's also worth pointing to shader,validation,decl,ptr_spelling:"*"

That has a test that verifies that ptr<storage,X> defaults to read-only. (It's covered in the let_ptr_writes test, but admittedly it's not super-easy to see.)

There's some overlap, but it's good overlap, as these tests are easier to read


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);

g.test('address_space')
.desc('Test address spaces in pointer type parameterization')
.params(u =>
u.combine('aspace', [
'function',
'private',
'workgroup',
'storage',
'uniform',
'handle',
'bad_aspace',
] as const)
)
.fn(t => {
const code = `alias T = ptr<${t.params.aspace}, u32>;`;
const success = t.params.aspace !== 'handle' && t.params.aspace !== 'bad_aspace';
t.expectCompileResult(success, code);
});

g.test('access_mode')
.desc('Test access mode in pointer type parameterization')
.params(u =>
u
.combine('aspace', ['function', 'private', 'storage', 'uniform', 'workgroup'] as const)
.combine('access', ['read', 'write', 'read_write'])
)
.fn(t => {
// Default access mode is tested above.
const code = `alias T = ptr<${t.params.aspace}, u32, ${t.params.access}>;`;
const success = t.params.aspace === 'storage' && t.params.access !== 'write';
t.expectCompileResult(success, code);
});

interface TypeCase {
type: string;
storable: boolean;
f16?: boolean;
aspace?: string;
}

const kTypeCases: Record<string, TypeCase> = {
// Scalars
bool: { type: `bool`, storable: true, aspace: 'function' },
u32: { type: `u32`, storable: true },
i32: { type: `i32`, storable: true },
f32: { type: `f32`, storable: true },
f16: { type: `f16`, storable: true, f16: true },

// Vectors
vec2u: { type: `vec2u`, storable: true },
vec3i: { type: `vec3i`, storable: true },
vec4f: { type: `vec4f`, storable: true },
vec2_bool: { type: `vec2<bool>`, storable: true, aspace: 'workgroup' },
vec3h: { type: `vec3h`, storable: true, f16: true },

// Matrices
mat2x2f: { type: `mat2x2f`, storable: true },
mat3x4h: { type: `mat3x4h`, storable: true, f16: true },

// Atomics
atomic_u32: { type: `atomic<u32>`, storable: true },
atomic_i32: { type: `atomic<i32>`, storable: true },

// Arrays
array_sized_u32: { type: `array<u32, 4>`, storable: true },
array_sized_vec4f: { type: `array<vec4f, 16>`, storable: true },
array_sized_S: { type: `array<S, 2>`, storable: true },
array_runtime_u32: { type: `array<u32>`, storable: true },
array_runtime_S: { type: `array<S>`, storable: true },
array_runtime_atomic_u32: { type: `array<atomic<u32>>`, storable: true },
array_override_u32: { type: `array<u32, o>`, storable: true, aspace: 'workgroup' },

// Structs
struct_S: { type: `S`, storable: true },
struct_T: { type: `T`, storable: true },

// Pointers
ptr_function_u32: { type: `ptr<function, u32>`, storable: false },
ptr_workgroup_bool: { type: `ptr<workgroup, bool>`, storable: false },

// Sampler (while storable, can only be in the handle address space)
sampler: { type: `sampler`, storable: false },

// Texture (while storable, can only be in the handle address space)
texture_2d: { type: `texture_2d<f32>`, storable: false },

// Alias
alias: { type: `u32_alias`, storable: true },

// Reference
reference: { type: `ref<function, u32>`, storable: false, aspace: 'function' },
};

g.test('type')
.desc('Tests that pointee type must be storable')
.params(u => u.combine('case', keysOf(kTypeCases)))
.beforeAllSubcases(t => {
if (kTypeCases[t.params.case].f16) {
t.selectDeviceOrSkipTestCase('shader-f16');
}
})
.fn(t => {
const testcase = kTypeCases[t.params.case];
const aspace = testcase.aspace ?? 'storage';
const access = testcase.type.includes('atomic') ? ', read_write' : '';
const code = `${testcase.f16 ? 'enable f16;' : ''}
override o : u32;
struct S { x : u32 }
struct T { s : array<S> }
alias u32_alias = u32;
alias Type = ptr<${aspace}, ${testcase.type}${access}>;`;
t.expectCompileResult(testcase.storable, code);
});