Skip to content

Commit

Permalink
op: Add 'color_write_mask,blending_disabled' to blending.spec.ts (#1994)
Browse files Browse the repository at this point in the history
* 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

* nits: test names, description, and minor detail

Co-authored-by: Kai Ninomiya <[email protected]>
  • Loading branch information
Gyuyoung and kainino0x authored Nov 21, 2022
1 parent fa3aad6 commit 21a8e06
Showing 1 changed file with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function computeBlendOperation(
}
}

g.test('GPUBlendComponent')
g.test('blending,GPUBlendComponent')
.desc(
`Test all combinations of parameters for GPUBlendComponent.
Expand Down Expand Up @@ -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.`
Expand Down Expand Up @@ -425,7 +425,7 @@ g.test('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';
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -621,14 +621,76 @@ g.test('simple_blend_constant,blend_constant_non_inherited')
t.expectOK(result);
});

g.test('clamp,blend_factor')
g.test('color_write_mask,blending_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;

const blend = t.params.disabled ? undefined : { color: {}, alpha: {} };

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('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();

0 comments on commit 21a8e06

Please sign in to comment.