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
1 change: 1 addition & 0 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ export const kKnownWGSLLanguageFeatures = [
'linear_indexing',
'texture_formats_tier1',
'immediate_address_space',
'fragment_depth',
'buffer_view',
] as const;

Expand Down
66 changes: 61 additions & 5 deletions src/webgpu/shader/validation/shader_io/builtins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ g.test('reuse_builtin_name')
t.expectCompileResult(true, code);
});

const kTests = {
const kBuiltinTests = {
pos: {
src: `@builtin(position)`,
pass: true,
Expand Down Expand Up @@ -496,17 +496,17 @@ const kTests = {
},
};

g.test('parse')
g.test('parse_builtin')
.desc(`Test that @builtin is parsed correctly.`)
.params(u => u.combine('builtin', keysOf(kTests)))
.params(u => u.combine('builtin', keysOf(kBuiltinTests)))
.fn(t => {
const src = kTests[t.params.builtin].src;
const src = kBuiltinTests[t.params.builtin].src;
const code = `
@vertex
fn main() -> ${src} vec4<f32> {
return vec4<f32>(.4, .2, .3, .1);
}`;
t.expectCompileResult(kTests[t.params.builtin].pass, code);
t.expectCompileResult(kBuiltinTests[t.params.builtin].pass, code);
});

g.test('placement')
Expand Down Expand Up @@ -577,3 +577,59 @@ g.test('placement')

t.expectCompileResult(scope === undefined || t.params.attribute[scope], code);
});

const kFragDepthTests = {
unset: {
src: `@builtin(frag_depth)`,
pass: true,
requires_feature: false,
},
less: {
src: `@builtin(frag_depth, less)`,
pass: true,
requires_feature: true,
},
greater: {
src: `@builtin(frag_depth, greater)`,
pass: true,
requires_feature: true,
},
trailing_comma: {
src: `@builtin(frag_depth, less,)`,
pass: true,
requires_feature: true,
},
missing_enum: {
src: `@builtin(frag_depth,)`,
pass: true,
requires_feature: false,
},
invalid_enum: {
src: `@builtin(frag_depth, any)`,
pass: false,
requires_feature: false,
},
missing_comma: {
src: `@builtin(frag_depth greater)`,
pass: false,
requires_feature: false,
},
};

g.test('parse_frag_depth')
.desc(`Test that @builtin is parsed correctly.`)
.params(u => u.combine('builtin', keysOf(kFragDepthTests)))
.fn(t => {
const data = kFragDepthTests[t.params.builtin];

if (data.requires_feature) {
t.skipIfLanguageFeatureNotSupported('fragment_depth');
}

const code = `
@fragment
fn main() -> ${data.src} f32 {
return .5;
}`;
t.expectCompileResult(data.pass, code);
});
Loading