From 2bd2307479d6eb5108361363ad029e62d6e134ad Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 29 Jul 2026 15:56:04 -0400 Subject: [PATCH 1/3] Add frag_depth qualifier execution test Adds an execution test that the greater and less qualifiers are accepted on the frag_depth builtin. Issue: gpuweb/gpuweb#5342 --- .../api/operation/rendering/depth.spec.ts | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/webgpu/api/operation/rendering/depth.spec.ts b/src/webgpu/api/operation/rendering/depth.spec.ts index 8dc70fc2f322..5dc3c95c4ca4 100644 --- a/src/webgpu/api/operation/rendering/depth.spec.ts +++ b/src/webgpu/api/operation/rendering/depth.spec.ts @@ -537,3 +537,104 @@ g.test('reverse_depth') }, ]); }); + +g.test('fragment_depth_qualifiers') + .desc( + `Validates that less and greater qualifiers to @builtin(frag_depth) are accepted.` + ) + .params(u => + u.combine('mode', ['less', 'greater']) + ) + .fn(async t => { + t.skipIfLanguageFeatureNotSupported('fragment_depth'); + + const { mode } = t.params; + + const textureWidth = 1; + const textureHeight = 1; + const colorFormat = 'rgba8unorm'; + const depthFormat = 'depth32float'; + + const val = mode === "less" ? "0.4" : "0.6"; + const pipeline = t.device.createRenderPipeline({ + layout: 'auto', + vertex: { + module: t.device.createShaderModule({ + code: ` + @vertex + fn main() -> @builtin(position) vec4f { + return vec4f(0, 0, 0, 1); + } + `, + }), + }, + fragment: { + module: t.device.createShaderModule({ + code: ` + requires fragment_depth; + + struct Output { + @location(0) color: vec4f, + @builtin(frag_depth, ${mode}) depth: f32, + } + + @fragment + fn main() -> Output { + return Output(vec4f(0, 1, 0, 1), ${val}); + } + `, + }), + targets: [{ format: colorFormat }], + }, + primitive: { topology: 'point-list' }, + depthStencil: { + format: depthFormat, + depthWriteEnabled: true, + depthCompare: mode as GPUCompareFunction, + }, + }); + + const colorTexture = t.device.createTexture({ + size: [textureWidth, textureHeight], + format: colorFormat, + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, + }); + + const depthTexture = t.device.createTexture({ + size: [textureWidth, textureHeight], + format: depthFormat, + usage: GPUTextureUsage.RENDER_ATTACHMENT, + }); + + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginRenderPass({ + colorAttachments: [ + { + view: colorTexture.createView(), + clearValue: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, + loadOp: 'clear', + storeOp: 'store', + }, + ], + depthStencilAttachment: { + view: depthTexture.createView(), + depthClearValue: 0.5, + depthLoadOp: 'clear', + depthStoreOp: 'store', + }, + }); + + pass.setPipeline(pipeline); + pass.draw(3); + pass.end(); + + t.device.queue.submit([encoder.finish()]); + + const expectedColor = new Uint8Array([0, 255, 0, 255]) + ttu.expectSinglePixelComparisonsAreOkInTexture(t, { texture: colorTexture }, [ + { + coord: { x: 0, y: 0 }, + exp: expectedColor, + }, + ]); + }); From f9e835101c7125308aba6c50520b8ac98c58cfe6 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 29 Jul 2026 16:08:18 -0400 Subject: [PATCH 2/3] lint fixes --- src/webgpu/api/operation/rendering/depth.spec.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/webgpu/api/operation/rendering/depth.spec.ts b/src/webgpu/api/operation/rendering/depth.spec.ts index 5dc3c95c4ca4..5fef244fe005 100644 --- a/src/webgpu/api/operation/rendering/depth.spec.ts +++ b/src/webgpu/api/operation/rendering/depth.spec.ts @@ -539,12 +539,8 @@ g.test('reverse_depth') }); g.test('fragment_depth_qualifiers') - .desc( - `Validates that less and greater qualifiers to @builtin(frag_depth) are accepted.` - ) - .params(u => - u.combine('mode', ['less', 'greater']) - ) + .desc(`Validates that less and greater qualifiers to @builtin(frag_depth) are accepted.`) + .params(u => u.combine('mode', ['less', 'greater'])) .fn(async t => { t.skipIfLanguageFeatureNotSupported('fragment_depth'); @@ -555,7 +551,7 @@ g.test('fragment_depth_qualifiers') const colorFormat = 'rgba8unorm'; const depthFormat = 'depth32float'; - const val = mode === "less" ? "0.4" : "0.6"; + const val = mode === 'less' ? '0.4' : '0.6'; const pipeline = t.device.createRenderPipeline({ layout: 'auto', vertex: { @@ -594,13 +590,13 @@ g.test('fragment_depth_qualifiers') }, }); - const colorTexture = t.device.createTexture({ + const colorTexture = t.createTextureTracked({ size: [textureWidth, textureHeight], format: colorFormat, usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, }); - const depthTexture = t.device.createTexture({ + const depthTexture = t.createTextureTracked({ size: [textureWidth, textureHeight], format: depthFormat, usage: GPUTextureUsage.RENDER_ATTACHMENT, @@ -630,7 +626,7 @@ g.test('fragment_depth_qualifiers') t.device.queue.submit([encoder.finish()]); - const expectedColor = new Uint8Array([0, 255, 0, 255]) + const expectedColor = new Uint8Array([0, 255, 0, 255]); ttu.expectSinglePixelComparisonsAreOkInTexture(t, { texture: colorTexture }, [ { coord: { x: 0, y: 0 }, From 93e962588385cb1242fbcb2adf44673499b1624f Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 29 Jul 2026 16:14:10 -0400 Subject: [PATCH 3/3] fix async --- src/webgpu/api/operation/rendering/depth.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgpu/api/operation/rendering/depth.spec.ts b/src/webgpu/api/operation/rendering/depth.spec.ts index 5fef244fe005..8e0a51a4cc91 100644 --- a/src/webgpu/api/operation/rendering/depth.spec.ts +++ b/src/webgpu/api/operation/rendering/depth.spec.ts @@ -541,7 +541,7 @@ g.test('reverse_depth') g.test('fragment_depth_qualifiers') .desc(`Validates that less and greater qualifiers to @builtin(frag_depth) are accepted.`) .params(u => u.combine('mode', ['less', 'greater'])) - .fn(async t => { + .fn(t => { t.skipIfLanguageFeatureNotSupported('fragment_depth'); const { mode } = t.params;