From ab53a8f85a2df28e901cfee0951681416b0b28cd Mon Sep 17 00:00:00 2001 From: Jiajia Qin Date: Wed, 29 Mar 2023 16:09:30 +0800 Subject: [PATCH] webgpu: upgrade webgpu/types (#7528) --- package.json | 2 +- tfjs-backend-webgpu/src/base.ts | 1 + tfjs-backend-webgpu/src/kernels/FromPixels.ts | 18 ++++-------------- tfjs-core/package.json | 2 +- yarn.lock | 8 ++++---- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index e350899d7e4..240733800f3 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@types/semver": "^7.3.9", "@types/shelljs": "^0.8.7", "@types/webgl-ext": "0.0.30", - "@webgpu/types": "0.1.21", + "@webgpu/types": "0.1.30", "ajv": "~6.12.3", "argparse": "^1.0.10", "chalk": "~2.4.2", diff --git a/tfjs-backend-webgpu/src/base.ts b/tfjs-backend-webgpu/src/base.ts index e8a5db4d4df..7edc3b87180 100644 --- a/tfjs-backend-webgpu/src/base.ts +++ b/tfjs-backend-webgpu/src/base.ts @@ -54,6 +54,7 @@ if (isWebGPUSupported()) { 'maxComputeWorkgroupsPerDimension': adapterLimits.maxComputeWorkgroupsPerDimension, 'maxStorageBufferBindingSize': adapterLimits.maxStorageBufferBindingSize, + 'maxBufferSize': adapterLimits.maxBufferSize, }; const device: GPUDevice = await adapter.requestDevice(deviceDescriptor); diff --git a/tfjs-backend-webgpu/src/kernels/FromPixels.ts b/tfjs-backend-webgpu/src/kernels/FromPixels.ts index 4b4c12a357a..982cdc7ad33 100644 --- a/tfjs-backend-webgpu/src/kernels/FromPixels.ts +++ b/tfjs-backend-webgpu/src/kernels/FromPixels.ts @@ -30,7 +30,6 @@ export const fromPixelsConfig: KernelConfig = { let fromPixels2DContext: CanvasRenderingContext2D; let willReadFrequently = env().getBool('CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU'); -const videoToTextureMap = new Map(); export function fromPixels(args: { inputs: FromPixelsInputs, @@ -72,21 +71,13 @@ export function fromPixels(args: { if (isImageBitmap || isCanvas || isVideoOrImage) { let textureInfo: TextureInfo; if (importVideo) { - const videoElement = pixels as HTMLVideoElement; - if (!(videoToTextureMap.has(videoElement)) || - (videoToTextureMap.get(videoElement) as GPUExternalTexture).expired) { - const externalTextureDescriptor = {source: videoElement}; - videoToTextureMap.set( - videoElement, - backend.device.importExternalTexture(externalTextureDescriptor)); - } - textureInfo = { width, height, format: null, usage: null, - texture: videoToTextureMap.get(videoElement) as GPUExternalTexture + texture: backend.device.importExternalTexture( + {source: pixels as HTMLVideoElement}) }; } else { if (isVideoOrImage) { @@ -95,9 +86,8 @@ export function fromPixels(args: { if (fromPixels2DContext == null || newWillReadFrequently !== willReadFrequently) { willReadFrequently = newWillReadFrequently; - fromPixels2DContext = - document.createElement('canvas').getContext( - '2d', {willReadFrequently}); + fromPixels2DContext = document.createElement('canvas').getContext( + '2d', {willReadFrequently}); } fromPixels2DContext.canvas.width = width; fromPixels2DContext.canvas.height = height; diff --git a/tfjs-core/package.json b/tfjs-core/package.json index 7e1741413db..a5ff43870f1 100644 --- a/tfjs-core/package.json +++ b/tfjs-core/package.json @@ -41,7 +41,7 @@ "@types/offscreencanvas": "~2019.7.0", "@types/seedrandom": "^2.4.28", "@types/webgl-ext": "0.0.30", - "@webgpu/types": "0.1.21", + "@webgpu/types": "0.1.30", "long": "4.0.0", "node-fetch": "~2.6.1", "seedrandom": "^3.0.5" diff --git a/yarn.lock b/yarn.lock index c162d1c332a..1a76932d5e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -502,10 +502,10 @@ resolved "https://registry.yarnpkg.com/@verdaccio/ui-theme/-/ui-theme-6.0.0-6-next.23.tgz#268da5091e1e9264fe87b8b94c0ac596e9e54879" integrity sha512-GXpEPdZJm6o+2VAxzUsKaiDriS+5enqr7Gjrb2Bttcd+IkOuC8lDsoFHxIv0ib4JudZJ/aKsRYL3TN2AetPFjw== -"@webgpu/types@0.1.21": - version "0.1.21" - resolved "https://registry.yarnpkg.com/@webgpu/types/-/types-0.1.21.tgz#b181202daec30d66ccd67264de23814cfd176d3a" - integrity sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow== +"@webgpu/types@0.1.30": + version "0.1.30" + resolved "https://registry.npmmirror.com/@webgpu/types/-/types-0.1.30.tgz#b6406dc4a1c1e0d469028ceb30ddffbbd2fa706c" + integrity sha512-9AXJSmL3MzY8ZL//JjudA//q+2kBRGhLBFpkdGksWIuxrMy81nFrCzj2Am+mbh8WoU6rXmv7cY5E3rdlyru2Qg== "@xmldom/xmldom@^0.7.3": version "0.7.5"