diff options
Diffstat (limited to 'ext/webgpu/01_webgpu.js')
-rw-r--r-- | ext/webgpu/01_webgpu.js | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index 3e8978fef..c8258621f 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -10,11 +10,10 @@ import { core, primordials } from "ext:core/mod.js"; const ops = core.ops; import * as webidl from "ext:deno_webidl/00_webidl.js"; import { EventTarget } from "ext:deno_web/02_event.js"; -import DOMException from "ext:deno_web/01_dom_exception.js"; +import { DOMException } from "ext:deno_web/01_dom_exception.js"; import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; const { ArrayBuffer, - ArrayBufferIsView, ArrayIsArray, ArrayPrototypeFilter, ArrayPrototypeMap, @@ -45,10 +44,13 @@ const { SymbolIterator, TypeError, Uint32Array, - Uint32ArrayPrototype, Uint8Array, } = primordials; const { + isDataView, + isTypedArray, +} = core; +const { op_webgpu_buffer_get_map_async, op_webgpu_request_adapter, op_webgpu_request_adapter_info, @@ -1690,17 +1692,14 @@ class GPUQueue { }); /** @type {ArrayBufferLike} */ let abLike = data; - if (ArrayBufferIsView(data)) { - if (TypedArrayPrototypeGetSymbolToStringTag(data) !== undefined) { - // TypedArray - abLike = TypedArrayPrototypeGetBuffer( - /** @type {Uint8Array} */ (data), - ); - } else { - // DataView - abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data)); - } + if (isTypedArray(data)) { + abLike = TypedArrayPrototypeGetBuffer( + /** @type {Uint8Array} */ (data), + ); + } else if (isDataView(data)) { + abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data)); } + const { err } = ops.op_webgpu_write_buffer( device.rid, bufferRid, @@ -1744,16 +1743,12 @@ class GPUQueue { /** @type {ArrayBufferLike} */ let abLike = data; - if (ArrayBufferIsView(data)) { - if (TypedArrayPrototypeGetSymbolToStringTag(data) !== undefined) { - // TypedArray - abLike = TypedArrayPrototypeGetBuffer( - /** @type {Uint8Array} */ (data), - ); - } else { - // DataView - abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data)); - } + if (isTypedArray(data)) { + abLike = TypedArrayPrototypeGetBuffer( + /** @type {Uint8Array} */ (data), + ); + } else if (isDataView(data)) { + abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data)); } const { err } = ops.op_webgpu_write_texture( @@ -3778,10 +3773,8 @@ class GPURenderPassEncoder { selfContext: "this", }); if ( - !(ObjectPrototypeIsPrototypeOf( - Uint32ArrayPrototype, - dynamicOffsetsData, - )) + TypedArrayPrototypeGetSymbolToStringTag(dynamicOffsetsData) !== + "Uint32Array" ) { dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []); dynamicOffsetsDataStart = 0; @@ -4337,10 +4330,8 @@ class GPUComputePassEncoder { selfContext: "this", }); if ( - !(ObjectPrototypeIsPrototypeOf( - Uint32ArrayPrototype, - dynamicOffsetsData, - )) + TypedArrayPrototypeGetSymbolToStringTag(dynamicOffsetsData) !== + "Uint32Array" ) { dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []); dynamicOffsetsDataStart = 0; @@ -4555,10 +4546,8 @@ class GPURenderBundleEncoder { selfContext: "this", }); if ( - !(ObjectPrototypeIsPrototypeOf( - Uint32ArrayPrototype, - dynamicOffsetsData, - )) + TypedArrayPrototypeGetSymbolToStringTag(dynamicOffsetsData) !== + "Uint32Array" ) { dynamicOffsetsData = new Uint32Array(dynamicOffsetsData ?? []); dynamicOffsetsDataStart = 0; |