Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op: Implement 'default_blend_constant,setting_blend_constant' test in blending.spec.ts #1984

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion src/webgpu/api/operation/rendering/blending.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ g.test('formats')
t.expectOK(result);
});

g.test('default_blend_constant,initial_blend_constant')
g.test('simple_blend_constant,initial_blend_constant')
.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,6 +481,69 @@ g.test('default_blend_constant,initial_blend_constant')
t.expectOK(result);
});

g.test('simple_blend_constant,setting_blend_constant')
.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 },
{ r: 0.5, g: 1.0, b: 0.5, a: 0.0 },
{ r: 0.0, g: 0.0, b: 0.0, a: 0.0 },
])
.fn(async t => {
const { r, g, b, a } = t.params;

const format = 'rgba8unorm';
const kSize = 1;
const kWhiteColorData = new Float32Array([255, 255, 255, 255]);

const blendComponent = { srcFactor: 'constant', dstFactor: 'one', operation: 'add' } as const;
const testPipeline = t.createRenderPipelineForTest({
format,
blend: { color: blendComponent, alpha: blendComponent },
});

const renderTarget = t.device.createTexture({
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
size: [kSize, kSize],
format,
});

const commandEncoder = t.device.createCommandEncoder();
const renderPass = commandEncoder.beginRenderPass({
colorAttachments: [
{
view: renderTarget.createView(),
loadOp: 'load',
storeOp: 'store',
},
],
});
renderPass.setPipeline(testPipeline);
renderPass.setBlendConstant({ r, g, b, a });
renderPass.setBindGroup(
0,
t.createBindGroupForTest(testPipeline.getBindGroupLayout(0), kWhiteColorData)
);
renderPass.draw(3);
// Draw [1,1,1,1] with `src * constant + dst * 1`. The blend constant to [r,g,b,a], so the
// result is `[1,1,1,1] * [r,g,b,a] + [0,0,0,0] * 1` = [r,g,b,a].
renderPass.end();
t.device.queue.submit([commandEncoder.finish()]);

// Check that the blend constant is the same as the given constant after setting the constant
// via setBlendConstant.
const expColor = { R: r, G: g, B: b, A: a };
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();
Expand Down