Skip to content

Commit

Permalink
Update webgpu/types to 0.1.50 (#4029)
Browse files Browse the repository at this point in the history
This makes toneMapping optional which required updating a few tests to
use the nullish coalescing operator when accessing it.

New vertex formats are added that require updating capability_info.ts
(and tests for unorm8x4-bgra is added at the same time).

Finally dictionary types for copies are renamed throughout the CTS even
if deprecated aliases are available.
  • Loading branch information
Kangz authored Nov 4, 2024
1 parent e4718ba commit d2bd876
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 121 deletions.
17 changes: 9 additions & 8 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.49",
"@webgpu/types": "^0.1.50",
"ansi-colors": "4.1.3",
"babel-plugin-add-header-comment": "^1.0.3",
"babel-plugin-const-enum": "^1.2.0",
Expand Down
22 changes: 11 additions & 11 deletions src/webgpu/api/operation/command_buffer/image_copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const altDataGenerator = new DataArrayGenerator();

class ImageCopyTest extends TextureTestMixin(GPUTest) {
/**
* This is used for testing passing undefined members of `GPUImageDataLayout` instead of actual
* This is used for testing passing undefined members of `GPUTexelCopyBufferLayout` instead of actual
* values where possible. Passing arguments as values and not as objects so that they are passed
* by copy and not by reference.
*/
Expand All @@ -135,7 +135,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
rowsPerImage: number | undefined,
bytesPerRow: number | undefined,
changeBeforePass: ChangeBeforePass
): GPUImageDataLayout {
): GPUTexelCopyBufferLayout {
if (changeBeforePass === 'undefined') {
if (offset === 0) {
offset = undefined;
Expand All @@ -151,7 +151,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
}

/**
* This is used for testing passing undefined members of `GPUImageCopyTexture` instead of actual
* This is used for testing passing undefined members of `GPUTexelCopyTextureInfo` instead of actual
* values where possible and also for testing passing the origin as `[number, number, number]`.
* Passing arguments as values and not as objects so that they are passed by copy and not by
* reference.
Expand All @@ -163,7 +163,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
origin_z: number | undefined,
mipLevel: number | undefined,
changeBeforePass: ChangeBeforePass
): GPUImageCopyTexture {
): GPUTexelCopyTextureInfo {
let origin: GPUOrigin3D | undefined = { x: origin_x, y: origin_y, z: origin_z };

if (changeBeforePass === 'undefined') {
Expand Down Expand Up @@ -225,7 +225,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
buffer: GPUBuffer,
format: ColorTextureFormat,
size: Required<GPUExtent3DDict>,
dataLayout: Required<GPUImageDataLayout>
dataLayout: Required<GPUTexelCopyBufferLayout>
) {
if (isCompressedTextureFormat(format)) {
this.expectGPUBufferValuesEqual(buffer, expected);
Expand Down Expand Up @@ -323,7 +323,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
/** Run a CopyT2B command with appropriate arguments corresponding to `ChangeBeforePass` */
copyTextureToBufferWithAppliedArguments(
buffer: GPUBuffer,
{ offset, rowsPerImage, bytesPerRow }: Required<GPUImageDataLayout>,
{ offset, rowsPerImage, bytesPerRow }: Required<GPUTexelCopyBufferLayout>,
{ width, height, depthOrArrayLayers }: Required<GPUExtent3DDict>,
{ texture, mipLevel, origin }: TextureCopyViewWithRequiredOrigin,
changeBeforePass: ChangeBeforePass
Expand Down Expand Up @@ -363,7 +363,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
/** Put data into a part of the texture with an appropriate method. */
uploadLinearTextureDataToTextureSubBox(
textureCopyView: TextureCopyViewWithRequiredOrigin,
textureDataLayout: GPUImageDataLayout & { bytesPerRow: number },
textureDataLayout: GPUTexelCopyBufferLayout & { bytesPerRow: number },
copySize: Required<GPUExtent3DDict>,
partialData: Uint8Array,
method: InitMethod,
Expand Down Expand Up @@ -432,7 +432,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
copySize: Required<GPUExtent3DDict>,
format: ColorTextureFormat,
expected: Uint8Array,
expectedDataLayout: Required<GPUImageDataLayout>
expectedDataLayout: Required<GPUTexelCopyBufferLayout>
): void {
const size = [
actualTexture.width,
Expand Down Expand Up @@ -507,7 +507,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
checkSize: Required<GPUExtent3DDict>,
format: ColorTextureFormat,
expected: Uint8Array,
expectedDataLayout: Required<GPUImageDataLayout>,
expectedDataLayout: Required<GPUTexelCopyBufferLayout>,
changeBeforePass: ChangeBeforePass = 'none'
): void {
// The alignment is necessary because we need to copy and map data from this buffer.
Expand Down Expand Up @@ -573,7 +573,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
copyWholeTextureToBufferAndCheckContentsWithUpdatedData(
{ texture, mipLevel, origin }: TextureCopyViewWithRequiredOrigin,
fullTextureCopyLayout: TextureCopyLayout,
texturePartialDataLayout: Required<GPUImageDataLayout>,
texturePartialDataLayout: Required<GPUTexelCopyBufferLayout>,
copySize: Required<GPUExtent3DDict>,
format: ColorTextureFormat,
fullData: GPUBuffer,
Expand Down Expand Up @@ -632,7 +632,7 @@ class ImageCopyTest extends TextureTestMixin(GPUTest) {
checkMethod,
changeBeforePass = 'none',
}: {
textureDataLayout: Required<GPUImageDataLayout>;
textureDataLayout: Required<GPUTexelCopyBufferLayout>;
copySize: Required<GPUExtent3DDict>;
dataSize: number;
mipLevel?: number;
Expand Down
60 changes: 43 additions & 17 deletions src/webgpu/api/operation/vertex_state/correctness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,25 +427,51 @@ struct VSOutputs {

case 'unorm': {
if (formatInfo.bytesPerComponent === 'packed') {
assert(format === 'unorm10-10-10-2'); // This is the only packed format for now.
assert(bitSize === 0);

/* prettier-ignore */
const data = [
[ 0, 0, 0, 0],
[1023, 1023, 1023, 3],
[ 243, 567, 765, 2],
];
const vertexData = new Uint32Array(data.map(makeRgb10a2)).buffer;
const expectedData = new Float32Array(data.flat().map(normalizeRgb10a2)).buffer;

return {
shaderBaseType: 'f32',
testComponentCount: data.flat().length,
expectedData,
vertexData,
floatTolerance: 0.1 / 1023,
};
switch (format) {
case 'unorm10-10-10-2': {
/* prettier-ignore */
const data = [
[ 0, 0, 0, 0],
[1023, 1023, 1023, 3],
[ 243, 567, 765, 2],
];
const vertexData = new Uint32Array(data.map(makeRgb10a2)).buffer;
const expectedData = new Float32Array(data.flat().map(normalizeRgb10a2)).buffer;

return {
shaderBaseType: 'f32',
testComponentCount: data.flat().length,
expectedData,
vertexData,
floatTolerance: 0.1 / 1023,
};
}

case 'unorm8x4-bgra': {
const data = [42, 0, 1, 2, 3, 4, 128, 255];
const vertexData = new Uint8Array(data).buffer;
const expectedData = new Float32Array(
data.map(v => normalizedIntegerAsFloat(v, 8, false))
);

for (let i = 0; i + 2 < expectedData.length; i += 4) {
const r = expectedData[i + 0];
const b = expectedData[i + 2];
expectedData[i + 0] = b;
expectedData[i + 2] = r;
}

return {
shaderBaseType: 'f32',
testComponentCount: data.length,
expectedData: expectedData.buffer,
vertexData,
floatTolerance: 0.1 / 255,
};
}
}
}

/* prettier-ignore */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ g.test('configure,at_over')

// This should not fail, even if the size is too large but it might fail
// if we're in a worker and HTMLCanvasElement does not exist.
const canvas = createCanvas(t, canvasType, size[0], size[1])!;
const canvas = createCanvas(t, canvasType, size[0], size[1]);
if (canvas) {
const context = canvas.getContext('webgpu') as GPUCanvasContext;
t.expect(!!context, 'should not fail to create context even if size is too large');
Expand Down Expand Up @@ -96,7 +96,7 @@ g.test('getCurrentTexture,at_over')
// Start with a small size so configure will succeed.
// This should not fail, even if the size is too large but it might fail
// if we're in a worker and HTMLCanvasElement does not exist.
const canvas = createCanvas(t, canvasType, 1, 1)!;
const canvas = createCanvas(t, canvasType, 1, 1);
if (canvas) {
const context = canvas.getContext('webgpu') as GPUCanvasContext;
t.expect(!!context, 'should not fail to create context even if size is too large');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { ValidationTest } from '../../validation_test.js';

class F extends ValidationTest {
TestCopyTextureToTexture(
source: GPUImageCopyTexture,
destination: GPUImageCopyTexture,
source: GPUTexelCopyTextureInfo,
destination: GPUTexelCopyTextureInfo,
copySize: GPUExtent3D,
expectation: 'Success' | 'FinishError' | 'SubmitError'
): void {
Expand Down Expand Up @@ -691,7 +691,7 @@ TODO: Extend to 1D and 3D textures.`
g.test('copy_aspects')
.desc(
`
Test the validations on the member 'aspect' of GPUImageCopyTexture in CopyTextureToTexture().
Test the validations on the member 'aspect' of GPUTexelCopyTextureInfo in CopyTextureToTexture().
- for all the color and depth-stencil formats: the texture copy aspects must be both 'all'.
- for all the depth-only formats: the texture copy aspects must be either 'all' or 'depth-only'.
- for all the stencil-only formats: the texture copy aspects must be either 'all' or 'stencil-only'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { ValidationTest } from '../validation_test.js';

class ImageCopyTest extends ValidationTest {
testCopyBufferToTexture(
source: GPUImageCopyBuffer,
destination: GPUImageCopyTexture,
source: GPUTexelCopyBufferInfo,
destination: GPUTexelCopyTextureInfo,
copySize: GPUExtent3DStrict,
isSuccess: boolean
): void {
Expand All @@ -29,8 +29,8 @@ class ImageCopyTest extends ValidationTest {
}

testCopyTextureToBuffer(
source: GPUImageCopyTexture,
destination: GPUImageCopyBuffer,
source: GPUTexelCopyTextureInfo,
destination: GPUTexelCopyBufferInfo,
copySize: GPUExtent3DStrict,
isSuccess: boolean
): void {
Expand All @@ -40,9 +40,9 @@ class ImageCopyTest extends ValidationTest {
}

testWriteTexture(
destination: GPUImageCopyTexture,
destination: GPUTexelCopyTextureInfo,
uploadData: Uint8Array,
dataLayout: GPUImageDataLayout,
dataLayout: GPUTexelCopyBufferLayout,
copySize: GPUExtent3DStrict,
isSuccess: boolean
): void {
Expand Down
6 changes: 3 additions & 3 deletions src/webgpu/api/validation/image_copy/image_copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { ValidationTest } from '../validation_test.js';

export class ImageCopyTest extends ValidationTest {
testRun(
textureCopyView: GPUImageCopyTexture,
textureDataLayout: GPUImageDataLayout,
textureCopyView: GPUTexelCopyTextureInfo,
textureDataLayout: GPUTexelCopyBufferLayout,
size: GPUExtent3D,
{
method,
Expand Down Expand Up @@ -122,7 +122,7 @@ export class ImageCopyTest extends ValidationTest {
testBuffer(
buffer: GPUBuffer,
texture: GPUTexture,
textureDataLayout: GPUImageDataLayout,
textureDataLayout: GPUTexelCopyBufferLayout,
size: GPUExtent3D,
{
method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class CopyExternalImageToTextureTest extends ValidationTest {
}

runTest(
imageBitmapCopyView: GPUImageCopyExternalImage,
textureCopyView: GPUImageCopyTextureTagged,
imageBitmapCopyView: GPUCopyExternalImageSourceInfo,
textureCopyView: GPUCopyExternalImageDestInfo,
copySize: GPUExtent3D,
validationScopeSuccess: boolean,
exceptionName?: string
Expand Down
14 changes: 12 additions & 2 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export type VertexFormatInfo = {
/** Number of components. */
readonly componentCount: 1 | 2 | 3 | 4;
/** Size in bytes. */
readonly byteSize: 2 | 4 | 8 | 12 | 16;
readonly byteSize: 1 | 2 | 4 | 8 | 12 | 16;
/** The completely matching WGSL type for vertex format */
readonly wgslType:
| 'f32'
Expand All @@ -273,23 +273,32 @@ export const kVertexFormatInfo: {
['bytesPerComponent', 'type', 'componentCount', 'byteSize', 'wgslType'] as const,
[ , , , , ] as const, {
// 8 bit components
'uint8': [ 1, 'uint', 1, 1, 'u32'],
'uint8x2': [ 1, 'uint', 2, 2, 'vec2<u32>'],
'uint8x4': [ 1, 'uint', 4, 4, 'vec4<u32>'],
'sint8': [ 1, 'sint', 1, 1, 'i32'],
'sint8x2': [ 1, 'sint', 2, 2, 'vec2<i32>'],
'sint8x4': [ 1, 'sint', 4, 4, 'vec4<i32>'],
'unorm8': [ 1, 'unorm', 1, 1, 'f32'],
'unorm8x2': [ 1, 'unorm', 2, 2, 'vec2<f32>'],
'unorm8x4': [ 1, 'unorm', 4, 4, 'vec4<f32>'],
'snorm8': [ 1, 'snorm', 1, 1, 'f32'],
'snorm8x2': [ 1, 'snorm', 2, 2, 'vec2<f32>'],
'snorm8x4': [ 1, 'snorm', 4, 4, 'vec4<f32>'],
// 16 bit components
'uint16': [ 2, 'uint', 1, 2, 'u32'],
'uint16x2': [ 2, 'uint', 2, 4, 'vec2<u32>'],
'uint16x4': [ 2, 'uint', 4, 8, 'vec4<u32>'],
'sint16': [ 2, 'sint', 1, 2, 'i32'],
'sint16x2': [ 2, 'sint', 2, 4, 'vec2<i32>'],
'sint16x4': [ 2, 'sint', 4, 8, 'vec4<i32>'],
'unorm16': [ 2, 'unorm', 1, 2, 'f32'],
'unorm16x2': [ 2, 'unorm', 2, 4, 'vec2<f32>'],
'unorm16x4': [ 2, 'unorm', 4, 8, 'vec4<f32>'],
'snorm16': [ 2, 'snorm', 1, 2, 'f32'],
'snorm16x2': [ 2, 'snorm', 2, 4, 'vec2<f32>'],
'snorm16x4': [ 2, 'snorm', 4, 8, 'vec4<f32>'],
'float16': [ 2, 'float', 1, 2, 'f32'],
'float16x2': [ 2, 'float', 2, 4, 'vec2<f32>'],
'float16x4': [ 2, 'float', 4, 8, 'vec4<f32>'],
// 32 bit components
Expand All @@ -306,7 +315,8 @@ export const kVertexFormatInfo: {
'sint32x3': [ 4, 'sint', 3, 12, 'vec3<i32>'],
'sint32x4': [ 4, 'sint', 4, 16, 'vec4<i32>'],
// 32 bit packed
'unorm10-10-10-2': [ 'packed', 'unorm', 4, 4, 'vec4<f32>']
'unorm10-10-10-2': [ 'packed', 'unorm', 4, 4, 'vec4<f32>'],
'unorm8x4-bgra': [ 'packed', 'unorm', 4, 4, 'vec4<f32>'],
} as const);
/** List of all GPUVertexFormat values. */
export const kVertexFormats = keysOf(kVertexFormatInfo);
Expand Down
Loading

0 comments on commit d2bd876

Please sign in to comment.