Skip to content

Commit

Permalink
wgsl: Test that you cannot type ref (gpuweb#3644)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrprice authored Apr 11, 2024
1 parent bee411b commit f33acad
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,10 @@
"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,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 },
"webgpu:shader,validation,types,ref:not_typeable_var:*": { "subcaseMS": 56.105 },
"webgpu:shader,validation,types,struct:no_direct_recursion:*": { "subcaseMS": 0.951 },
"webgpu:shader,validation,types,struct:no_indirect_recursion:*": { "subcaseMS": 0.901 },
"webgpu:shader,validation,types,struct:no_indirect_recursion_via_array_element:*": { "subcaseMS": 0.901 },
Expand Down
57 changes: 57 additions & 0 deletions src/webgpu/shader/validation/types/ref.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export const description = `
Validation tests for ref types
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { ShaderValidationTest } from '../shader_validation_test.js';

export const g = makeTestGroup(ShaderValidationTest);

const kTypes = ['bool', 'i32', 'f32', 'vec2i', 'mat2x2f', 'array<i32, 4>', 'S'];

g.test('not_typeable_var')
.desc('Test that `ref` cannot be typed in a shader as an explicit var decl type.')
.params(u => u.combine('type', kTypes).combine('ref', [false, true]))
.fn(t => {
let ty = t.params.type;
if (t.params.ref) {
ty = `ref<private, ${ty}>`;
}
const code = `
struct S { a : u32 }
var<private> foo : ${ty};`;
t.expectCompileResult(!t.params.ref, code);
});

g.test('not_typeable_let')
.desc('Test that `ref` cannot be typed in a shader as a let decl type.')
.params(u => u.combine('type', kTypes).combine('view', ['ptr', 'ref']))
.fn(t => {
const code = `
struct S { a : u32 }
fn foo() {
var a : ${t.params.type};
let b : ${t.params.view}<function, ${t.params.type}> = &a;
}`;
t.expectCompileResult(t.params.view === 'ptr', code);
});

g.test('not_typeable_param')
.desc('Test that `ref` cannot be typed in a shader as a function parameter type.')
.params(u => u.combine('type', kTypes).combine('view', ['ptr', 'ref']))
.fn(t => {
const code = `
struct S { a : u32 }
fn foo(a : ${t.params.view}<private, ${t.params.type}>) {}`;
t.expectCompileResult(t.params.view === 'ptr', code);
});

g.test('not_typeable_alias')
.desc('Test that `ref` cannot be typed in a shader as an alias type.')
.params(u => u.combine('type', kTypes).combine('view', ['ptr', 'ref']))
.fn(t => {
const code = `
struct S { a : u32 }
alias a = ${t.params.view}<private, ${t.params.type}>;`;
t.expectCompileResult(t.params.view === 'ptr', code);
});

0 comments on commit f33acad

Please sign in to comment.