Skip to content

Commit e9eab3d

Browse files
authored
Add debug info to fragment builtins. (#4602)
This lets you visualize the expected results.
1 parent 3a8f51b commit e9eab3d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/webgpu/shader/execution/shader_io/fragment_builtins.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,33 @@ function checkSampleRectsApproximatelyEqual({
748748
return undefined;
749749
}
750750

751+
function showExpected(
752+
t: GPUTest,
753+
width: number,
754+
height: number,
755+
sampleCount: number,
756+
expected: Float32Array
757+
) {
758+
t.debug(() => {
759+
const lineSep = ` ${range(width, () => '+-- x --- y --- z --- w --').join('')}+`;
760+
const lines = [''];
761+
for (let y = 0; y < height; ++y) {
762+
lines.push(lineSep);
763+
for (let sampleIndex = 0; sampleIndex < sampleCount; ++sampleIndex) {
764+
const line = [];
765+
for (let x = 0; x < width; ++x) {
766+
const offset = ((y * width + x) * sampleCount + sampleIndex) * 4;
767+
const v = [...expected.slice(offset, offset + 4)];
768+
line.push(`${v.map(v => v.toFixed(3)).join(' ')}`);
769+
}
770+
lines.push(`s${sampleIndex}: | ${line.join(' | ')} |`);
771+
}
772+
}
773+
lines.push(lineSep);
774+
return lines.join('\n');
775+
});
776+
}
777+
751778
g.test('inputs,position')
752779
.desc(
753780
`
@@ -820,6 +847,8 @@ g.test('inputs,position')
820847
interpolateFn: computeFragmentPosition,
821848
});
822849

850+
showExpected(t, width, height, sampleCount, expected);
851+
823852
// Since @builtin(position) is always a fragment position, never a sample position, check
824853
// the first coordinate. It should be 0.5, 0.5 always. This is just to double check
825854
// that computeFragmentPosition is generating the correct values.
@@ -909,6 +938,8 @@ g.test('inputs,interStage')
909938
interpolateFn: await createInterStageInterpolationFn(t, interStagePoints, type, sampling),
910939
});
911940

941+
showExpected(t, width, height, sampleCount, expected);
942+
912943
t.expectOK(
913944
checkSampleRectsApproximatelyEqual({
914945
width,
@@ -1048,6 +1079,8 @@ g.test('inputs,interStage,centroid')
10481079
),
10491080
});
10501081

1082+
showExpected(t, width, height, sampleCount, expected);
1083+
10511084
t.expectOK(
10521085
checkSampleRectsApproximatelyEqual({
10531086
width,
@@ -1127,6 +1160,8 @@ g.test('inputs,sample_index')
11271160
interpolateFn: computeFragmentSampleIndex,
11281161
});
11291162

1163+
showExpected(t, width, height, sampleCount, expected);
1164+
11301165
t.expectOK(
11311166
checkSampleRectsApproximatelyEqual({
11321167
width,
@@ -1242,6 +1277,8 @@ g.test('inputs,front_facing')
12421277
interpolateFn: computeFragmentFrontFacing,
12431278
});
12441279

1280+
showExpected(t, width, height, sampleCount, expected);
1281+
12451282
assert(expected.indexOf(0) >= 0, 'expect some values to be 0');
12461283
assert(expected.findIndex(v => v !== 0) >= 0, 'expect some values to be non 0');
12471284

@@ -1416,6 +1453,8 @@ g.test('inputs,sample_mask')
14161453
interpolateFn: computeSampleMask,
14171454
});
14181455

1456+
showExpected(t, width, height, sampleCount, expected);
1457+
14191458
t.expectOK(
14201459
checkSampleRectsApproximatelyEqual({
14211460
width,

0 commit comments

Comments
 (0)