Skip to content

Commit 418a795

Browse files
committed
op: Add 'srcFactor' and 'dstFactor' to the parameters in 'blending,clamping' test
This PR adds srcFactor and dstFactor to the parameters of 'blending,clamping' test in color_target_state.spec.ts. Issue: #1835
1 parent 861b209 commit 418a795

File tree

1 file changed

+93
-5
lines changed

1 file changed

+93
-5
lines changed

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

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,74 @@ function computeBlendOperation(
152152
}
153153
}
154154

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+
case 'one':
169+
case 'one-minus-constant':
170+
srcFactorValue = 1;
171+
break;
172+
case 'src':
173+
case 'src-alpha':
174+
srcFactorValue = srcValue;
175+
break;
176+
case 'dst':
177+
srcFactorValue = dstValue;
178+
break;
179+
case 'one-minus-dst':
180+
srcFactorValue = 1 - dstValue;
181+
break;
182+
case 'one-minus-src':
183+
srcFactorValue = 1 - srcValue;
184+
break;
185+
case 'constant':
186+
srcFactorValue = 0;
187+
break;
188+
default:
189+
unreachable();
190+
}
191+
192+
switch (dstFactor) {
193+
case 'zero':
194+
dstFactorValue = 0;
195+
break;
196+
case 'one':
197+
case 'one-minus-constant':
198+
dstFactorValue = 1;
199+
break;
200+
case 'src':
201+
case 'src-alpha':
202+
dstFactorValue = srcValue;
203+
break;
204+
case 'dst':
205+
dstFactorValue = dstValue;
206+
break;
207+
case 'one-minus-dst':
208+
dstFactorValue = 1 - dstValue;
209+
break;
210+
case 'one-minus-src':
211+
dstFactorValue = 1 - srcValue;
212+
break;
213+
case 'constant':
214+
dstFactorValue = 0;
215+
break;
216+
default:
217+
unreachable();
218+
}
219+
220+
return srcValue * srcFactorValue + dstValue * dstFactorValue;
221+
}
222+
155223
g.test('blending,GPUBlendComponent')
156224
.desc(
157225
`Test all combinations of parameters for GPUBlendComponent.
@@ -791,19 +859,36 @@ g.test('blending,clamping')
791859
Test that clamping occurs at the correct points in the blend process: src value, src factor, dst
792860
factor, and output.
793861
- TODO: Need to test snorm formats.
794-
- TODO: Need to test src value, srcFactor and dstFactor.
795862
`
796863
)
797864
.params(u =>
798865
u //
799866
.combine('format', ['rgba8unorm', 'rg16float'] as const)
867+
.combine('srcFactor', kBlendFactors)
868+
.combine('dstFactor', kBlendFactors)
869+
.filter(t => {
870+
return (
871+
!(
872+
t.srcFactor === 'one-minus-src-alpha' ||
873+
t.srcFactor === 'dst-alpha' ||
874+
t.srcFactor === 'one-minus-dst-alpha' ||
875+
t.srcFactor === 'src-alpha-saturated'
876+
) &&
877+
!(
878+
t.dstFactor === 'one-minus-src-alpha' ||
879+
t.dstFactor === 'dst-alpha' ||
880+
t.dstFactor === 'one-minus-dst-alpha' ||
881+
t.dstFactor === 'src-alpha-saturated'
882+
)
883+
);
884+
})
800885
.combine('srcValue', [0.4, 0.6, 0.8, 1.0])
801886
.combine('dstValue', [0.2, 0.4])
802887
)
803888
.fn(async t => {
804-
const { format, srcValue, dstValue } = t.params;
889+
const { format, srcFactor, dstFactor, srcValue, dstValue } = t.params;
805890

806-
const blendComponent = { srcFactor: 'one', dstFactor: 'one', operation: 'add' } as const;
891+
const blendComponent = { srcFactor, dstFactor, operation: 'add' } as const;
807892

808893
const pipeline = t.device.createRenderPipeline({
809894
layout: 'auto',
@@ -866,10 +951,13 @@ g.test('blending,clamping')
866951
let expValue: number;
867952
switch (format) {
868953
case 'rgba8unorm': // unorm types should clamp if the sum of srcValue and dstValue exceeds 1.
869-
expValue = clamp(srcValue + dstValue, { min: 0, max: 1 });
954+
expValue = clamp(calculateExpectedClampValue(srcValue, dstValue, srcFactor, dstFactor), {
955+
min: 0,
956+
max: 1,
957+
});
870958
break;
871959
case 'rg16float': // float format types doesn't clamp.
872-
expValue = srcValue + dstValue;
960+
expValue = calculateExpectedClampValue(srcValue, dstValue, srcFactor, dstFactor);
873961
break;
874962
}
875963

0 commit comments

Comments
 (0)