Skip to content

Commit dbaa9e3

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 dbaa9e3

File tree

1 file changed

+97
-5
lines changed

1 file changed

+97
-5
lines changed

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

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,78 @@ 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+
// 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+
155227
g.test('blending,GPUBlendComponent')
156228
.desc(
157229
`Test all combinations of parameters for GPUBlendComponent.
@@ -791,19 +863,36 @@ g.test('blending,clamping')
791863
Test that clamping occurs at the correct points in the blend process: src value, src factor, dst
792864
factor, and output.
793865
- TODO: Need to test snorm formats.
794-
- TODO: Need to test src value, srcFactor and dstFactor.
795866
`
796867
)
797868
.params(u =>
798869
u //
799870
.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+
})
800889
.combine('srcValue', [0.4, 0.6, 0.8, 1.0])
801890
.combine('dstValue', [0.2, 0.4])
802891
)
803892
.fn(async t => {
804-
const { format, srcValue, dstValue } = t.params;
893+
const { format, srcFactor, dstFactor, srcValue, dstValue } = t.params;
805894

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

808897
const pipeline = t.device.createRenderPipeline({
809898
layout: 'auto',
@@ -866,10 +955,13 @@ g.test('blending,clamping')
866955
let expValue: number;
867956
switch (format) {
868957
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+
});
870962
break;
871963
case 'rg16float': // float format types doesn't clamp.
872-
expValue = srcValue + dstValue;
964+
expValue = calculateExpectedClampValue(srcValue, dstValue, srcFactor, dstFactor);
873965
break;
874966
}
875967

0 commit comments

Comments
 (0)