Skip to content

Commit a2798bc

Browse files
authored
op: Implement 'color_write_mask,channel_work' in color_target_state.spec.ts (#2011)
This PR adds a new test to ensure that write masks works alone or with multiple channels. Issue: #1835
1 parent 21a8e06 commit a2798bc

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

src/webgpu/api/operation/rendering/color_target_state.spec.ts

+93
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
kEncodableTextureFormats,
1616
kTextureFormatInfo,
1717
} from '../../../capability_info.js';
18+
import { GPUConst } from '../../../constants.js';
1819
import { GPUTest } from '../../../gpu_test.js';
1920
import { float32ToFloat16Bits } from '../../../util/conversion.js';
2021
import { TexelView } from '../../../util/texture/texel_view.js';
@@ -621,6 +622,98 @@ g.test('blend_constant,not_inherited')
621622
t.expectOK(result);
622623
});
623624

625+
g.test('color_write_mask,channel_work')
626+
.desc(`Test that the color write mask works alone or with multiple channels.`)
627+
.params(u =>
628+
u
629+
.combine('mask1', [
630+
GPUConst.ColorWrite.RED,
631+
GPUConst.ColorWrite.GREEN,
632+
GPUConst.ColorWrite.BLUE,
633+
GPUConst.ColorWrite.ALPHA,
634+
])
635+
.combine('mask2', [
636+
GPUConst.ColorWrite.RED,
637+
GPUConst.ColorWrite.GREEN,
638+
GPUConst.ColorWrite.BLUE,
639+
GPUConst.ColorWrite.ALPHA,
640+
])
641+
)
642+
.fn(async t => {
643+
const { mask1, mask2 } = t.params;
644+
645+
const format = 'rgba8unorm';
646+
const kSize = 1;
647+
const masks = [mask1, mask2];
648+
649+
let r = 0,
650+
g = 0,
651+
b = 0,
652+
a = 0;
653+
for (let i = 0; i < 2; i++) {
654+
switch (masks[i]) {
655+
case GPUColorWrite.RED:
656+
r = 1;
657+
break;
658+
case GPUColorWrite.GREEN:
659+
g = 1;
660+
break;
661+
case GPUColorWrite.BLUE:
662+
b = 1;
663+
break;
664+
case GPUColorWrite.ALPHA:
665+
a = 1;
666+
break;
667+
}
668+
}
669+
670+
const testPipeline = t.createRenderPipelineForTest({
671+
format,
672+
writeMask: masks[0] | masks[1],
673+
});
674+
675+
const renderTarget = t.device.createTexture({
676+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
677+
size: [kSize, kSize],
678+
format,
679+
});
680+
681+
const kBaseColorData = new Float32Array([32, 64, 128, 192]);
682+
683+
const commandEncoder = t.device.createCommandEncoder();
684+
{
685+
const renderPass = commandEncoder.beginRenderPass({
686+
colorAttachments: [
687+
{
688+
view: renderTarget.createView(),
689+
loadOp: 'load',
690+
storeOp: 'store',
691+
},
692+
],
693+
});
694+
renderPass.setPipeline(testPipeline);
695+
renderPass.setBindGroup(
696+
0,
697+
t.createBindGroupForTest(testPipeline.getBindGroupLayout(0), kBaseColorData)
698+
);
699+
renderPass.draw(3);
700+
renderPass.end();
701+
}
702+
t.device.queue.submit([commandEncoder.finish()]);
703+
704+
const expColor = { R: r, G: g, B: b, A: a };
705+
const expTexelView = TexelView.fromTexelsAsColors(format, coords => expColor);
706+
707+
const result = await textureContentIsOKByT2B(
708+
t,
709+
{ texture: renderTarget },
710+
[kSize, kSize],
711+
{ expTexelView },
712+
{ maxDiffULPsForNormFormat: 1 }
713+
);
714+
t.expectOK(result);
715+
});
716+
624717
g.test('color_write_mask,blending_disabled')
625718
.desc(
626719
`Test that the color write mask works when blending is disabled or set to the defaults

0 commit comments

Comments
 (0)