Add frag_depth validation tests. (#4679)
Some checks are pending
push / build (push) Waiting to run

Add validation tests for the `fragment_depth` extension.

Issue: https://github.com/gpuweb/gpuweb/issues/5342
This commit is contained in:
dan sinclair 2026-07-29 13:04:05 -04:00 committed by GitHub
parent a152afa827
commit dc20b8682a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 5 deletions

View file

@ -991,6 +991,7 @@ export const kKnownWGSLLanguageFeatures = [
'linear_indexing',
'texture_formats_tier1',
'immediate_address_space',
'fragment_depth',
'buffer_view',
] as const;

View file

@ -437,7 +437,7 @@ g.test('reuse_builtin_name')
t.expectCompileResult(true, code);
});
const kTests = {
const kBuiltinTests = {
pos: {
src: `@builtin(position)`,
pass: true,
@ -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')
@ -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);
});