@@ -15,6 +15,7 @@ import {
15
15
kEncodableTextureFormats ,
16
16
kTextureFormatInfo ,
17
17
} from '../../../capability_info.js' ;
18
+ import { GPUConst } from '../../../constants.js' ;
18
19
import { GPUTest } from '../../../gpu_test.js' ;
19
20
import { float32ToFloat16Bits } from '../../../util/conversion.js' ;
20
21
import { TexelView } from '../../../util/texture/texel_view.js' ;
@@ -621,6 +622,98 @@ g.test('blend_constant,not_inherited')
621
622
t . expectOK ( result ) ;
622
623
} ) ;
623
624
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
+
624
717
g . test ( 'color_write_mask,blending_disabled' )
625
718
. desc (
626
719
`Test that the color write mask works when blending is disabled or set to the defaults
0 commit comments