Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 11 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/w3c-image-capture": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@webgpu/types": "^0.1.71",
"@webgpu/types": "^0.1.72",
"ansi-colors": "4.1.3",
"babel-plugin-add-header-comment": "^1.0.3",
"babel-plugin-const-enum": "^1.2.0",
Expand Down
46 changes: 46 additions & 0 deletions src/webgpu/api/operation/vertex_state/correctness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ function normalizeRgb10a2(rgba: number, index: number): number {
return rgba / normalizationFactor;
}

function makeRgb10a2Signed(rgba: Array<number>): number {
const [r, g, b, a] = rgba;
// Check the input fits in i32, then check it's in range for i10 or i2.
assert((r | 0) === r && r >= -512 && r <= 511);
assert((g | 0) === g && g >= -512 && g <= 511);
assert((b | 0) === b && b >= -512 && b <= 511);
assert((a | 0) === a && a >= -2 && a <= 1);
const r_bits = r & 0x3ff;
const g_bits = g & 0x3ff;
const b_bits = b & 0x3ff;
const a_bits = a & 0x3;
return r_bits | (g_bits << 10) | (b_bits << 20) | (a_bits << 30);
}

function normalizeRgb10a2Signed(val: number, index: number): number {
const isAlpha = index % 4 === 3;
const maxVal = isAlpha ? 1 : 511;
return Math.max(val / maxVal, -1.0);
}

type TestData = {
shaderBaseType: string;
floatTolerance?: number;
Expand Down Expand Up @@ -379,6 +399,32 @@ struct VSOutputs {
}

case 'snorm': {
if (formatInfo.bytesPerComponent === 'packed') {
assert(bitSize === 0);
switch (format as string) {
case 'snorm10-10-10-2': {
/* prettier-ignore */
const data = [
[ 0, 0, 0, 0],
[ 511, 511, 511, 1],
[-512, -512, -512, -2],
[ 243, -123, 342, -1],
];
const vertexData = new Uint32Array(data.map(makeRgb10a2Signed)).buffer;
const expectedData = new Float32Array(data.flat().map(normalizeRgb10a2Signed)).buffer;

return {
shaderBaseType: 'f32',
testComponentCount: data.flat().length,
expectedData,
vertexData,
floatTolerance: 0.1 / 511,
};
}
default:
unreachable();
}
}
/* prettier-ignore */
const data = [
42,
Expand Down
1 change: 1 addition & 0 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export const kVertexFormatInfo: {
// 32 bit packed
'unorm10-10-10-2': [ 'packed', 'unorm', 4, 4, 'vec4<f32>'],
'unorm8x4-bgra': [ 'packed', 'unorm', 4, 4, 'vec4<f32>'],
'snorm10-10-10-2': [ 'packed', 'snorm', 4, 4, 'vec4<f32>'],
Comment thread
wangra-google marked this conversation as resolved.
} as const);
/** List of all GPUVertexFormat values. */
export const kVertexFormats = keysOf(kVertexFormatInfo);
Expand Down
Loading