diff --git a/src/webgpu/capability_info.ts b/src/webgpu/capability_info.ts index 871dcad08168..b13e310bcf9c 100644 --- a/src/webgpu/capability_info.ts +++ b/src/webgpu/capability_info.ts @@ -991,6 +991,7 @@ export const kKnownWGSLLanguageFeatures = [ 'linear_indexing', 'texture_formats_tier1', 'immediate_address_space', + 'fragment_depth', 'buffer_view', ] as const; diff --git a/src/webgpu/shader/validation/shader_io/builtins.spec.ts b/src/webgpu/shader/validation/shader_io/builtins.spec.ts index 5dff7e70b227..270d46fbcb57 100644 --- a/src/webgpu/shader/validation/shader_io/builtins.spec.ts +++ b/src/webgpu/shader/validation/shader_io/builtins.spec.ts @@ -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 { return vec4(.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); + });