diff --git a/package-lock.json b/package-lock.json index 19429df6e283..368b20fce60d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,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.46", + "@webgpu/types": "^0.1.47", "ansi-colors": "4.1.3", "babel-plugin-add-header-comment": "^1.0.3", "babel-plugin-const-enum": "^1.2.0", @@ -1539,10 +1539,11 @@ "dev": true }, "node_modules/@webgpu/types": { - "version": "0.1.46", - "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.46.tgz", - "integrity": "sha512-2iogO6Zh0pTbKLGZuuGWEmJpF/fTABGs7G9wXxpn7s24XSJchSUIiMqIJHURi5zsMZRRTuXrV/3GLOkmOFjq5w==", - "dev": true + "version": "0.1.47", + "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.47.tgz", + "integrity": "sha512-vOUHDxj0azl7BSj4YAy6cc6q5s7F1KfF5GI1er/w6togN0MqzS/d8U+H0LH1XpLbFup+UaA7aMtia/aSx3DE0w==", + "dev": true, + "license": "BSD-3-Clause" }, "node_modules/abbrev": { "version": "1.1.1", @@ -10076,9 +10077,9 @@ "dev": true }, "@webgpu/types": { - "version": "0.1.46", - "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.46.tgz", - "integrity": "sha512-2iogO6Zh0pTbKLGZuuGWEmJpF/fTABGs7G9wXxpn7s24XSJchSUIiMqIJHURi5zsMZRRTuXrV/3GLOkmOFjq5w==", + "version": "0.1.47", + "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.47.tgz", + "integrity": "sha512-vOUHDxj0azl7BSj4YAy6cc6q5s7F1KfF5GI1er/w6togN0MqzS/d8U+H0LH1XpLbFup+UaA7aMtia/aSx3DE0w==", "dev": true }, "abbrev": { diff --git a/package.json b/package.json index c82fe0f2cba5..321dabb3891f 100644 --- a/package.json +++ b/package.json @@ -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.46", + "@webgpu/types": "^0.1.47", "ansi-colors": "4.1.3", "babel-plugin-add-header-comment": "^1.0.3", "babel-plugin-const-enum": "^1.2.0", diff --git a/src/webgpu/web_platform/canvas/configure.spec.ts b/src/webgpu/web_platform/canvas/configure.spec.ts index 65b0bc1f9d7b..7ac98e23b158 100644 --- a/src/webgpu/web_platform/canvas/configure.spec.ts +++ b/src/webgpu/web_platform/canvas/configure.spec.ts @@ -3,7 +3,7 @@ Tests for GPUCanvasContext.configure. TODO: - Test colorSpace -- Test viewFormats +- Test toneMapping `; import { makeTestGroup } from '../../../common/framework/test_group.js'; @@ -42,6 +42,16 @@ g.test('defaults') format: 'rgba8unorm', }); + const configuration = ctx.getConfiguration(); + assert(configuration !== null); + t.expect(configuration.device === t.device); + t.expect(configuration.format === 'rgba8unorm'); + t.expect(configuration.usage === GPUTextureUsage.RENDER_ATTACHMENT); + t.expect((configuration.viewFormats as GPUTextureFormat[]).length === 0); + t.expect(configuration.colorSpace === 'srgb'); + t.expect(configuration.toneMapping!.mode === 'standard'); + t.expect(configuration.alphaMode === 'opaque'); + const currentTexture = ctx.getCurrentTexture(); t.expect(currentTexture.format === 'rgba8unorm'); t.expect(currentTexture.usage === GPUTextureUsage.RENDER_ATTACHMENT); @@ -69,6 +79,9 @@ g.test('device') const ctx = canvas.getContext('webgpu'); assert(ctx instanceof GPUCanvasContext, 'Failed to get WebGPU context from canvas'); + // getConfiguration returns null before configure. + t.expect(ctx.getConfiguration() === null); + // Calling configure without a device should throw a TypeError. t.shouldThrow('TypeError', () => { ctx.configure({ @@ -85,8 +98,20 @@ g.test('device') ctx.configure({ device: t.device, format: 'rgba8unorm', + alphaMode: 'opaque', }); + // getConfiguration will succeed after configure. + const configuration = ctx.getConfiguration(); + assert(configuration !== null); + t.expect(configuration.device === t.device); + t.expect(configuration.format === 'rgba8unorm'); + t.expect(configuration.usage === GPUTextureUsage.RENDER_ATTACHMENT); + t.expect((configuration.viewFormats as GPUTextureFormat[]).length === 0); + t.expect(configuration.colorSpace === 'srgb'); + t.expect(configuration.toneMapping!.mode === 'standard'); + t.expect(configuration.alphaMode === 'opaque'); + // getCurrentTexture will succeed with a valid device. ctx.getCurrentTexture(); @@ -96,12 +121,27 @@ g.test('device') ctx.getCurrentTexture(); }); + // getConfiguration returns null after unconfigure. + t.expect(ctx.getConfiguration() === null); + // Should be able to successfully configure again after unconfiguring. ctx.configure({ device: t.device, format: 'rgba8unorm', + alphaMode: 'premultiplied', }); ctx.getCurrentTexture(); + + // getConfiguration will succeed after configure. + const newConfiguration = ctx.getConfiguration(); + assert(newConfiguration !== null); + t.expect(newConfiguration.device === t.device); + t.expect(newConfiguration.format === 'rgba8unorm'); + t.expect(newConfiguration.usage === GPUTextureUsage.RENDER_ATTACHMENT); + t.expect((newConfiguration.viewFormats as GPUTextureFormat[]).length === 0); + t.expect(newConfiguration.colorSpace === 'srgb'); + t.expect(newConfiguration.toneMapping!.mode === 'standard'); + t.expect(newConfiguration.alphaMode === 'premultiplied'); }); g.test('format') @@ -140,6 +180,9 @@ g.test('format') }); }, !validFormat); + const configuration = ctx.getConfiguration(); + t.expect(configuration!.format === format); + t.expectValidationError(() => { // Should always return a texture, whether the configured format was valid or not. const currentTexture = ctx.getCurrentTexture(); @@ -179,6 +222,9 @@ g.test('usage') usage, }); + const configuration = ctx.getConfiguration(); + t.expect(configuration!.usage === usage); + const currentTexture = ctx.getCurrentTexture(); t.expect(currentTexture instanceof GPUTexture); t.expect(currentTexture.usage === usage); @@ -289,6 +335,9 @@ g.test('alpha_mode') alphaMode, }); + const configuration = ctx.getConfiguration(); + t.expect(configuration!.alphaMode === alphaMode); + const currentTexture = ctx.getCurrentTexture(); t.expect(currentTexture instanceof GPUTexture); }); @@ -412,6 +461,10 @@ g.test('viewFormats') }); }, !compatible); + const viewFormats = ctx.getConfiguration()!.viewFormats!; + assert(Array.isArray(viewFormats)); + t.expect(viewFormats[0] === viewFormat); + // Likewise for getCurrentTexture(). let currentTexture: GPUTexture; t.expectValidationError(() => {