@@ -152,6 +152,78 @@ function computeBlendOperation(
152
152
}
153
153
}
154
154
155
+ function calculateExpectedClampValue (
156
+ srcValue : number ,
157
+ dstValue : number ,
158
+ srcFactor : GPUBlendFactor ,
159
+ dstFactor : GPUBlendFactor
160
+ ) {
161
+ let srcFactorValue ;
162
+ let dstFactorValue ;
163
+
164
+ switch ( srcFactor ) {
165
+ case 'zero' :
166
+ srcFactorValue = 0 ;
167
+ break ;
168
+ // The default constant value is 0. So the src factor value of 'one-minus-constant' should be
169
+ // 1 - 0 = 1.
170
+ case 'one' :
171
+ case 'one-minus-constant' :
172
+ srcFactorValue = 1 ;
173
+ break ;
174
+ case 'src' :
175
+ case 'src-alpha' :
176
+ srcFactorValue = srcValue ;
177
+ break ;
178
+ case 'dst' :
179
+ srcFactorValue = dstValue ;
180
+ break ;
181
+ case 'one-minus-dst' :
182
+ srcFactorValue = 1 - dstValue ;
183
+ break ;
184
+ case 'one-minus-src' :
185
+ srcFactorValue = 1 - srcValue ;
186
+ break ;
187
+ case 'constant' : // The default constant value is 0.
188
+ srcFactorValue = 0 ;
189
+ break ;
190
+ default :
191
+ unreachable ( ) ;
192
+ }
193
+
194
+ switch ( dstFactor ) {
195
+ case 'zero' :
196
+ dstFactorValue = 0 ;
197
+ break ;
198
+ // The default constant value is 0. So the dst factor value of 'one-minus-constant' should be
199
+ // 1 - 0 = 1.
200
+ case 'one' :
201
+ case 'one-minus-constant' :
202
+ dstFactorValue = 1 ;
203
+ break ;
204
+ case 'src' :
205
+ case 'src-alpha' :
206
+ dstFactorValue = srcValue ;
207
+ break ;
208
+ case 'dst' :
209
+ dstFactorValue = dstValue ;
210
+ break ;
211
+ case 'one-minus-dst' :
212
+ dstFactorValue = 1 - dstValue ;
213
+ break ;
214
+ case 'one-minus-src' :
215
+ dstFactorValue = 1 - srcValue ;
216
+ break ;
217
+ case 'constant' : // The default constant value is 0.
218
+ dstFactorValue = 0 ;
219
+ break ;
220
+ default :
221
+ unreachable ( ) ;
222
+ }
223
+
224
+ return srcValue * srcFactorValue + dstValue * dstFactorValue ;
225
+ }
226
+
155
227
g . test ( 'blending,GPUBlendComponent' )
156
228
. desc (
157
229
`Test all combinations of parameters for GPUBlendComponent.
@@ -791,19 +863,36 @@ g.test('blending,clamping')
791
863
Test that clamping occurs at the correct points in the blend process: src value, src factor, dst
792
864
factor, and output.
793
865
- TODO: Need to test snorm formats.
794
- - TODO: Need to test src value, srcFactor and dstFactor.
795
866
`
796
867
)
797
868
. params ( u =>
798
869
u //
799
870
. combine ( 'format' , [ 'rgba8unorm' , 'rg16float' ] as const )
871
+ . combine ( 'srcFactor' , kBlendFactors )
872
+ . combine ( 'dstFactor' , kBlendFactors )
873
+ . filter ( t => {
874
+ return (
875
+ ! (
876
+ t . srcFactor === 'one-minus-src-alpha' ||
877
+ t . srcFactor === 'dst-alpha' ||
878
+ t . srcFactor === 'one-minus-dst-alpha' ||
879
+ t . srcFactor === 'src-alpha-saturated'
880
+ ) &&
881
+ ! (
882
+ t . dstFactor === 'one-minus-src-alpha' ||
883
+ t . dstFactor === 'dst-alpha' ||
884
+ t . dstFactor === 'one-minus-dst-alpha' ||
885
+ t . dstFactor === 'src-alpha-saturated'
886
+ )
887
+ ) ;
888
+ } )
800
889
. combine ( 'srcValue' , [ 0.4 , 0.6 , 0.8 , 1.0 ] )
801
890
. combine ( 'dstValue' , [ 0.2 , 0.4 ] )
802
891
)
803
892
. fn ( async t => {
804
- const { format, srcValue, dstValue } = t . params ;
893
+ const { format, srcFactor , dstFactor , srcValue, dstValue } = t . params ;
805
894
806
- const blendComponent = { srcFactor : 'one' , dstFactor : 'one' , operation : 'add' } as const ;
895
+ const blendComponent = { srcFactor, dstFactor, operation : 'add' } as const ;
807
896
808
897
const pipeline = t . device . createRenderPipeline ( {
809
898
layout : 'auto' ,
@@ -866,10 +955,13 @@ g.test('blending,clamping')
866
955
let expValue : number ;
867
956
switch ( format ) {
868
957
case 'rgba8unorm' : // unorm types should clamp if the sum of srcValue and dstValue exceeds 1.
869
- expValue = clamp ( srcValue + dstValue , { min : 0 , max : 1 } ) ;
958
+ expValue = clamp ( calculateExpectedClampValue ( srcValue , dstValue , srcFactor , dstFactor ) , {
959
+ min : 0 ,
960
+ max : 1 ,
961
+ } ) ;
870
962
break ;
871
963
case 'rg16float' : // float format types doesn't clamp.
872
- expValue = srcValue + dstValue ;
964
+ expValue = calculateExpectedClampValue ( srcValue , dstValue , srcFactor , dstFactor ) ;
873
965
break ;
874
966
}
875
967
0 commit comments