1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
export const description = `
Test for texture_ok utils.
`;
import { makeTestGroup } from '../common/framework/test_group.js';
import { typedArrayFromParam, typedArrayParam } from '../common/util/util.js';
import { TexelView } from '../webgpu/util/texture/texel_view.js';
import { findFailedPixels } from '../webgpu/util/texture/texture_ok.js';
import { UnitTest } from './unit_test.js';
class F extends UnitTest {
test(act: string, exp: string): void {
this.expect(act === exp, 'got: ' + act.replace('\n', '⏎'));
}
}
export const g = makeTestGroup(F);
g.test('findFailedPixels')
.desc(
`
Test findFailedPixels passes what is expected to pass and fails what is expected
to fail. For example NaN === NaN should be true in a texture that allows NaN.
2 different representations of the same rgb9e5ufloat should compare as equal.
etc...
`
)
.params(u =>
u.combineWithParams([
// Sanity Check
{
format: 'rgba8unorm',
actual: typedArrayParam('Uint8Array', [0x00, 0x40, 0x80, 0xff]),
expected: typedArrayParam('Uint8Array', [0x00, 0x40, 0x80, 0xff]),
isSame: true,
},
// Slightly different values
{
format: 'rgba8unorm',
actual: typedArrayParam('Uint8Array', [0x00, 0x40, 0x80, 0xff]),
expected: typedArrayParam('Uint8Array', [0x00, 0x40, 0x81, 0xff]),
isSame: false,
},
// Different representations of the same value
{
format: 'rgb9e5ufloat',
actual: typedArrayParam('Uint8Array', [0x78, 0x56, 0x34, 0x12]),
expected: typedArrayParam('Uint8Array', [0xf0, 0xac, 0x68, 0x0c]),
isSame: true,
},
// Slightly different values
{
format: 'rgb9e5ufloat',
actual: typedArrayParam('Uint8Array', [0x78, 0x56, 0x34, 0x12]),
expected: typedArrayParam('Uint8Array', [0xf1, 0xac, 0x68, 0x0c]),
isSame: false,
},
// Test NaN === NaN
{
format: 'r32float',
actual: typedArrayParam('Float32Array', [parseFloat('abc')]),
expected: typedArrayParam('Float32Array', [parseFloat('def')]),
isSame: true,
},
// Sanity Check
{
format: 'r32float',
actual: typedArrayParam('Float32Array', [1.23]),
expected: typedArrayParam('Float32Array', [1.23]),
isSame: true,
},
// Slightly different values.
{
format: 'r32float',
actual: typedArrayParam('Uint32Array', [0x3f9d70a4]),
expected: typedArrayParam('Uint32Array', [0x3f9d70a5]),
isSame: false,
},
// Slightly different
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0x3ce]),
expected: typedArrayParam('Uint32Array', [0x3cf]),
isSame: false,
},
// Positive.Infinity === Positive.Infinity (red)
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0b11111000000]),
expected: typedArrayParam('Uint32Array', [0b11111000000]),
isSame: true,
},
// Positive.Infinity === Positive.Infinity (green)
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0b11111000000_00000000000]),
expected: typedArrayParam('Uint32Array', [0b11111000000_00000000000]),
isSame: true,
},
// Positive.Infinity === Positive.Infinity (blue)
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0b1111100000_00000000000_00000000000]),
expected: typedArrayParam('Uint32Array', [0b1111100000_00000000000_00000000000]),
isSame: true,
},
// NaN === NaN (red)
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0b11111000001]),
expected: typedArrayParam('Uint32Array', [0b11111000010]),
isSame: true,
},
// NaN === NaN (green)
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0b11111000100_00000000000]),
expected: typedArrayParam('Uint32Array', [0b11111001000_00000000000]),
isSame: true,
},
// NaN === NaN (blue)
{
format: 'rg11b10ufloat',
actual: typedArrayParam('Uint32Array', [0b1111110000_00000000000_00000000000]),
expected: typedArrayParam('Uint32Array', [0b1111101000_00000000000_00000000000]),
isSame: true,
},
] as const)
)
.fn(t => {
const { format, actual, expected, isSame } = t.params;
const actualData = new Uint8Array(typedArrayFromParam(actual).buffer);
const expectedData = new Uint8Array(typedArrayFromParam(expected).buffer);
const actTexelView = TexelView.fromTextureDataByReference(format, actualData, {
bytesPerRow: actualData.byteLength,
rowsPerImage: 1,
subrectOrigin: [0, 0, 0],
subrectSize: [1, 1, 1],
});
const expTexelView = TexelView.fromTextureDataByReference(format, expectedData, {
bytesPerRow: expectedData.byteLength,
rowsPerImage: 1,
subrectOrigin: [0, 0, 0],
subrectSize: [1, 1, 1],
});
const zero = { x: 0, y: 0, z: 0 };
const failedPixelsMessage = findFailedPixels(
format,
zero,
{ width: 1, height: 1, depthOrArrayLayers: 1 },
{ actTexelView, expTexelView },
{
maxFractionalDiff: 0,
}
);
t.expect(isSame === !failedPixelsMessage, failedPixelsMessage);
});
|