From eb3ed61dada4f4bc855509a86ea6949aa93cc57a Mon Sep 17 00:00:00 2001 From: Gyuyoung Kim Date: Thu, 17 Nov 2022 10:30:53 -0800 Subject: [PATCH 1/2] op: Add 'color_write_mask,blending_disabled' to blending.spec.ts This PR adds a new test to ensure that color write mask works when blending is disabled. Issue: #1835 --- ...ing.spec.ts => color_target_state.spec.ts} | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) rename src/webgpu/api/operation/rendering/{blending.spec.ts => color_target_state.spec.ts} (90%) diff --git a/src/webgpu/api/operation/rendering/blending.spec.ts b/src/webgpu/api/operation/rendering/color_target_state.spec.ts similarity index 90% rename from src/webgpu/api/operation/rendering/blending.spec.ts rename to src/webgpu/api/operation/rendering/color_target_state.spec.ts index f8fe60303933..92c86d241e86 100644 --- a/src/webgpu/api/operation/rendering/blending.spec.ts +++ b/src/webgpu/api/operation/rendering/color_target_state.spec.ts @@ -150,7 +150,7 @@ function computeBlendOperation( } } -g.test('GPUBlendComponent') +g.test('blending_GPUBlendComponent') .desc( `Test all combinations of parameters for GPUBlendComponent. @@ -339,7 +339,7 @@ const kBlendableFormats = kEncodableTextureFormats.filter(f => { return info.renderable && info.sampleType === 'float'; }); -g.test('formats') +g.test('blending_formats') .desc( `Test blending results works for all formats that support it, and that blending is not applied for formats that do not. Blending should be done in linear space for srgb formats.` @@ -621,6 +621,67 @@ g.test('simple_blend_constant,blend_constant_non_inherited') t.expectOK(result); }); +g.test('color_write_mask,blending_disabled') + .desc(`Test that the color write mask works when blending is disabled.`) + .params(u => u.combine('disabled', [false, true])) + .fn(async t => { + const format = 'rgba8unorm'; + const kSize = 1; + + // This blend component always shows the src values. + const blendComponent = { srcFactor: 'one', dstFactor: 'zero', operation: 'add' } as const; + const blend = t.params.disabled ? undefined : { color: blendComponent, alpha: blendComponent }; + + const testPipeline = t.createRenderPipelineForTest({ + format, + blend, + writeMask: GPUColorWrite.RED, + }); + + const renderTarget = t.device.createTexture({ + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, + size: [kSize, kSize], + format, + }); + + const kBaseColorData = new Float32Array([32, 64, 128, 192]); + + const commandEncoder = t.device.createCommandEncoder(); + { + const renderPass = commandEncoder.beginRenderPass({ + colorAttachments: [ + { + view: renderTarget.createView(), + loadOp: 'load', + storeOp: 'store', + }, + ], + }); + renderPass.setPipeline(testPipeline); + renderPass.setBindGroup( + 0, + t.createBindGroupForTest(testPipeline.getBindGroupLayout(0), kBaseColorData) + ); + // Draw [1,1,1,1] with `src * 1 + dst * 0`. So the + // result is `[1,1,1,1] * [1,1,1,1] + [0,0,0,0] * 0` = [1,1,1,1]. + renderPass.draw(3); + renderPass.end(); + } + t.device.queue.submit([commandEncoder.finish()]); + + const expColor = { R: 1, G: 0, B: 0, A: 0 }; + const expTexelView = TexelView.fromTexelsAsColors(format, coords => expColor); + + const result = await textureContentIsOKByT2B( + t, + { texture: renderTarget }, + [kSize, kSize], + { expTexelView }, + { maxDiffULPsForNormFormat: 1 } + ); + t.expectOK(result); + }); + g.test('clamp,blend_factor') .desc('For fixed-point formats, test that the blend factor is clamped in the blend equation.') .unimplemented(); From cf1596686310ee3ec6ef82341329e7a07e7e79fe Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Mon, 21 Nov 2022 15:20:49 -0800 Subject: [PATCH 2/2] nits: test names, description, and minor detail --- .../rendering/color_target_state.spec.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/webgpu/api/operation/rendering/color_target_state.spec.ts b/src/webgpu/api/operation/rendering/color_target_state.spec.ts index 92c86d241e86..fca3a23d8e30 100644 --- a/src/webgpu/api/operation/rendering/color_target_state.spec.ts +++ b/src/webgpu/api/operation/rendering/color_target_state.spec.ts @@ -150,7 +150,7 @@ function computeBlendOperation( } } -g.test('blending_GPUBlendComponent') +g.test('blending,GPUBlendComponent') .desc( `Test all combinations of parameters for GPUBlendComponent. @@ -339,7 +339,7 @@ const kBlendableFormats = kEncodableTextureFormats.filter(f => { return info.renderable && info.sampleType === 'float'; }); -g.test('blending_formats') +g.test('blending,formats') .desc( `Test blending results works for all formats that support it, and that blending is not applied for formats that do not. Blending should be done in linear space for srgb formats.` @@ -425,7 +425,7 @@ g.test('blending_formats') t.expectOK(result); }); -g.test('simple_blend_constant,initial_blend_constant') +g.test('blend_constant,initial') .desc(`Test that the blend constant is set to [0,0,0,0] at the beginning of a pass.`) .fn(async t => { const format = 'rgba8unorm'; @@ -481,7 +481,7 @@ g.test('simple_blend_constant,initial_blend_constant') t.expectOK(result); }); -g.test('simple_blend_constant,setting_blend_constant') +g.test('blend_constant,setting') .desc(`Test that setting the blend constant to the RGBA values works at the beginning of a pass.`) .paramsSubcasesOnly([ { r: 1.0, g: 1.0, b: 1.0, a: 1.0 }, @@ -544,7 +544,7 @@ g.test('simple_blend_constant,setting_blend_constant') t.expectOK(result); }); -g.test('simple_blend_constant,blend_constant_non_inherited') +g.test('blend_constant,not_inherited') .desc(`Test that the blending constant is not inherited between render passes.`) .fn(async t => { const format = 'rgba8unorm'; @@ -622,15 +622,16 @@ g.test('simple_blend_constant,blend_constant_non_inherited') }); g.test('color_write_mask,blending_disabled') - .desc(`Test that the color write mask works when blending is disabled.`) + .desc( + `Test that the color write mask works when blending is disabled or set to the defaults + (which has the same blending result).` + ) .params(u => u.combine('disabled', [false, true])) .fn(async t => { const format = 'rgba8unorm'; const kSize = 1; - // This blend component always shows the src values. - const blendComponent = { srcFactor: 'one', dstFactor: 'zero', operation: 'add' } as const; - const blend = t.params.disabled ? undefined : { color: blendComponent, alpha: blendComponent }; + const blend = t.params.disabled ? undefined : { color: {}, alpha: {} }; const testPipeline = t.createRenderPipelineForTest({ format, @@ -682,14 +683,14 @@ g.test('color_write_mask,blending_disabled') t.expectOK(result); }); -g.test('clamp,blend_factor') +g.test('blending,clamp,blend_factor') .desc('For fixed-point formats, test that the blend factor is clamped in the blend equation.') .unimplemented(); -g.test('clamp,blend_color') +g.test('blending,clamp,blend_color') .desc('For fixed-point formats, test that the blend color is clamped in the blend equation.') .unimplemented(); -g.test('clamp,blend_result') +g.test('blending,clamp,blend_result') .desc('For fixed-point formats, test that the blend result is clamped in the blend equation.') .unimplemented();