From d4c6bf56c30e0393faa6804bfa38f69ac772cfbc Mon Sep 17 00:00:00 2001 From: crowlkats Date: Mon, 13 Jan 2025 14:17:44 +0100 Subject: [PATCH] fixes --- .cargo/local-build.toml | 1 - ext/webgpu/lib.rs | 46 ++++++++--- ext/webgpu/wrap/adapter.rs | 29 ++++--- ext/webgpu/wrap/buffer.rs | 86 ++++++++++++-------- ext/webgpu/wrap/compute_pass.rs | 107 ++++++++++++++----------- ext/webgpu/wrap/device.rs | 25 +++--- ext/webgpu/wrap/error.rs | 2 +- ext/webgpu/wrap/mod.rs | 83 ++++++------------- ext/webgpu/wrap/queue.rs | 10 ++- ext/webgpu/wrap/render_bundle.rs | 115 +++++++++++++++------------ ext/webgpu/wrap/render_pass.rs | 109 ++++++++++++++----------- ext/webidl/00_webidl.js | 3 +- runtime/js/90_deno_ns.js | 4 +- runtime/js/98_global_scope_shared.js | 4 +- runtime/js/98_global_scope_worker.js | 1 - 15 files changed, 346 insertions(+), 279 deletions(-) diff --git a/.cargo/local-build.toml b/.cargo/local-build.toml index a2d68e4f27..36a923c204 100644 --- a/.cargo/local-build.toml +++ b/.cargo/local-build.toml @@ -12,4 +12,3 @@ deno_core = { path = "../deno_core/core" } deno_ops = { path = "../deno_core/ops" } serde_v8 = { path = "../deno_core/serde_v8" } -v8 = { path = "../rusty_v8" } diff --git a/ext/webgpu/lib.rs b/ext/webgpu/lib.rs index a3b290cc86..f7b6d9a2d9 100644 --- a/ext/webgpu/lib.rs +++ b/ext/webgpu/lib.rs @@ -2,6 +2,7 @@ #![cfg(not(target_arch = "wasm32"))] #![warn(unsafe_op_in_unsafe_fn)] +use deno_core::GarbageCollected; pub use wgpu_core; pub use wgpu_types; @@ -16,14 +17,41 @@ pub type Instance = std::sync::Arc; deno_core::extension!( deno_webgpu, deps = [deno_webidl, deno_web], - /*ops = [ - // surface - surface::op_webgpu_surface_configure, - surface::op_webgpu_surface_get_current_texture, - surface::op_webgpu_surface_present, - // byow - byow::op_webgpu_surface_create, - ],*/ - esm = ["00_init.js" /* "02_surface.js"*/,], + ops = [wrap::create_gpu], + objects = [ + wrap::GPU, + wrap::adapter::GPUAdapter, + wrap::adapter::GPUAdapterInfo, + wrap::bind_group::GPUBindGroup, + wrap::bind_group_layout::GPUBindGroupLayout, + wrap::buffer::GPUBuffer, + wrap::command_buffer::GPUCommandBuffer, + wrap::command_encoder::GPUCommandEncoder, + wrap::compute_pass::GPUComputePassEncoder, + wrap::compute_pipeline::GPUComputePipeline, + wrap::device::GPUDevice, + wrap::device::GPUDeviceLostInfo, + wrap::pipeline_layout::GPUPipelineLayout, + wrap::query_set::GPUQuerySet, + wrap::queue::GPUQueue, + wrap::render_bundle::GPURenderBundle, + wrap::render_bundle::GPURenderBundleEncoder, + wrap::render_pass::GPURenderPassEncoder, + wrap::render_pipeline::GPURenderPipeline, + wrap::sampler::GPUSampler, + wrap::shader::GPUShaderModule, + GPUSupportedFeatures, + wrap::adapter::GPUSupportedLimits, + wrap::texture::GPUTexture, + wrap::texture::GPUTextureView, + ], + esm = ["00_init.js"], lazy_loaded_esm = ["01_webgpu.js"], ); + +struct GPUSupportedFeatures {} + +impl GarbageCollected for GPUSupportedFeatures {} + +#[deno_core::op2] +impl GPUSupportedFeatures {} diff --git a/ext/webgpu/wrap/adapter.rs b/ext/webgpu/wrap/adapter.rs index fc73b1e8cf..97ad7b23b1 100644 --- a/ext/webgpu/wrap/adapter.rs +++ b/ext/webgpu/wrap/adapter.rs @@ -1,6 +1,7 @@ // Copyright 2018-2025 the Deno authors. MIT license. use std::collections::HashSet; +use std::rc::Rc; use std::sync::Arc; use deno_core::cppgc::SameObject; @@ -47,7 +48,7 @@ pub struct GPUAdapter { pub features: SameObject, pub limits: SameObject, - pub info: Arc>, + pub info: Rc>, } impl GarbageCollected for GPUAdapter {} @@ -71,18 +72,19 @@ impl GPUAdapter { let features = features_to_feature_names(features); /* - function createGPUSupportedFeatures(features) { - /** @type {GPUSupportedFeatures} */ - const supportedFeatures = webidl.createBranded(GPUSupportedFeatures); - supportedFeatures[webidl.setlikeInner] = new SafeSet(features); - webidl.setlike( - supportedFeatures, - GPUSupportedFeaturesPrototype, - true, - ); - return supportedFeatures; - } - */ + #[symbol("[[set]]")] + function createGPUSupportedFeatures(features) { + /** @type {GPUSupportedFeatures} */ + const supportedFeatures = webidl.createBranded(GPUSupportedFeatures); + supportedFeatures[webidl.setlikeInner] = new SafeSet(features); + webidl.setlike( + supportedFeatures, + GPUSupportedFeaturesPrototype, + true, + ); + return supportedFeatures; + } + */ todo!() }) @@ -156,6 +158,7 @@ impl GPUAdapter { adapter: self.id, lost_receiver: receiver, limits: SameObject::new(), + features: SameObject::new(), }) } } diff --git a/ext/webgpu/wrap/buffer.rs b/ext/webgpu/wrap/buffer.rs index ed470e1688..14d1835e7f 100644 --- a/ext/webgpu/wrap/buffer.rs +++ b/ext/webgpu/wrap/buffer.rs @@ -1,7 +1,6 @@ // Copyright 2018-2025 the Deno authors. MIT license. use std::cell::RefCell; -use std::ptr::NonNull; use std::rc::Rc; use std::time::Duration; @@ -12,6 +11,7 @@ use deno_core::webidl::WebIdlInterfaceConverter; use deno_core::GarbageCollected; use deno_core::WebIDL; use deno_error::JsErrorBox; +use wgpu_core::device::HostMap as MapMode; use wgpu_core::resource::BufferMapCallback; use crate::Instance; @@ -55,9 +55,9 @@ pub struct GPUBuffer { pub usage: u32, pub map_state: RefCell<&'static str>, + pub map_mode: RefCell>, - pub mapped_js_buffers: - RefCell, usize, Option>)>>, + pub mapped_js_buffers: RefCell>>, } impl WebIdlInterfaceConverter for GPUBuffer { @@ -152,6 +152,13 @@ impl GPUBuffer { *self.map_state.borrow_mut() = "pending"; } + let mode = if read_mode { + MapMode::Read + } else { + assert!(write_mode); + MapMode::Write + }; + let (sender, receiver) = oneshot::channel::(); @@ -168,12 +175,7 @@ impl GPUBuffer { offset, Some(range_size), wgpu_core::resource::BufferMapOperation { - host: if read_mode { - wgpu_core::device::HostMap::Read - } else { - assert!(write_mode); - wgpu_core::device::HostMap::Write - }, + host: mode, callback: Some(BufferMapCallback::from_rust(callback)), }, ) @@ -216,17 +218,17 @@ impl GPUBuffer { tokio::try_join!(device_poll_fut, receiver_fut)?; *self.map_state.borrow_mut() = "mapped"; + *self.map_mode.borrow_mut() = Some(mode); Ok(()) } - #[buffer] - fn get_mapped_range( + fn get_mapped_range<'s>( &self, - scope: &mut v8::HandleScope, + scope: &mut v8::HandleScope<'s>, #[webidl/*(default = 0)*/] offset: u64, #[webidl] size: Option, - ) -> Result, BufferError> { + ) -> Result, BufferError> { let size = size.unwrap_or_else(|| self.size.saturating_sub(offset)); let (slice_pointer, range_size) = self @@ -234,34 +236,50 @@ impl GPUBuffer { .buffer_get_mapped_range(self.id, offset, Some(size)) .map_err(BufferError::Access)?; - let slice = unsafe { - std::slice::from_raw_parts(slice_pointer.as_ptr(), range_size as usize) + let mode = self.map_mode.borrow(); + let mode = mode.as_ref().unwrap(); + + let bs = if mode == &MapMode::Write { + unsafe extern "C" fn noop_deleter_callback( + _data: *mut std::ffi::c_void, + _byte_length: usize, + _deleter_data: *mut std::ffi::c_void, + ) { + } + + unsafe { + v8::ArrayBuffer::new_backing_store_from_ptr( + slice_pointer.as_ptr() as _, + range_size as usize, + noop_deleter_callback, + std::ptr::null_mut(), + ) + } + } else { + let slice = unsafe { + std::slice::from_raw_parts(slice_pointer.as_ptr(), range_size as usize) + }; + v8::ArrayBuffer::new_backing_store_from_vec(slice.to_vec()) }; - let ab = v8::ArrayBuffer::new(scope, slice.len()); - v8::Uint8Array::new(scope, ab, 0, slice.len()); - // TODO: store buf - self - .mapped_js_buffers - .borrow_mut() - .push((slice_pointer, range_size as usize)); + let shared_bs = bs.make_shared(); + let ab = v8::ArrayBuffer::with_backing_store(scope, &shared_bs); - Ok(slice.to_vec()) + if mode == &MapMode::Write { + self + .mapped_js_buffers + .borrow_mut() + .push(v8::Global::new(scope, ab)); + } + + Ok(v8::Uint8Array::new(scope, ab, 0, range_size as usize).unwrap()) } #[nofast] fn unmap(&self, scope: &mut v8::HandleScope) -> Result<(), BufferError> { - for (slice_pointer, range_size, buf) in - self.mapped_js_buffers.replace(vec![]) - { - if let Some(buf) = buf { - let buf = buf.open(scope); - - let slice = unsafe { - std::slice::from_raw_parts_mut(slice_pointer.as_ptr(), range_size) - }; - buf.copy_contents(slice); - } + for ab in self.mapped_js_buffers.replace(vec![]) { + let ab = ab.open(scope); + ab.detach(None); } self diff --git a/ext/webgpu/wrap/compute_pass.rs b/ext/webgpu/wrap/compute_pass.rs index 5990f09023..274cb3a239 100644 --- a/ext/webgpu/wrap/compute_pass.rs +++ b/ext/webgpu/wrap/compute_pass.rs @@ -132,55 +132,70 @@ impl GPUComputePassEncoder { ) -> Result<(), WebIdlError> { const PREFIX: &str = "Failed to execute 'setBindGroup' on 'GPUComputePassEncoder'"; - let offsets = - if let Ok(uint_32) = dynamic_offsets.try_cast::() { - let start = u64::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 4")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )?; - let len = u32::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 5")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )?; + let err = if let Ok(uint_32) = dynamic_offsets.try_cast::() + { + let start = u64::convert( + scope, + dynamic_offsets_data_start, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 4")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? as usize; + let len = u32::convert( + scope, + dynamic_offsets_data_length, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 5")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? as usize; - // TODO + let ab = uint_32.buffer(scope).unwrap(); + let ptr = ab.data().unwrap(); + let ab_len = ab.byte_length() / 4; - vec![] - } else { - >>::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 3")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )? - .unwrap_or_default() - }; + let data = + unsafe { std::slice::from_raw_parts(ptr.as_ptr() as _, ab_len) }; - let err = self - .instance - .compute_pass_set_bind_group( - &mut self.compute_pass.borrow_mut(), - index, - bind_group.into_option().map(|bind_group| bind_group.id), - &offsets, - ) - .err(); + let offsets = &data[start..(start + len)]; + + self + .instance + .compute_pass_set_bind_group( + &mut self.compute_pass.borrow_mut(), + index, + bind_group.into_option().map(|bind_group| bind_group.id), + offsets, + ) + .err() + } else { + let offsets = >>::convert( + scope, + dynamic_offsets, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 3")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? + .unwrap_or_default(); + + self + .instance + .compute_pass_set_bind_group( + &mut self.compute_pass.borrow_mut(), + index, + bind_group.into_option().map(|bind_group| bind_group.id), + &offsets, + ) + .err() + }; self.error_handler.push_error(err); diff --git a/ext/webgpu/wrap/device.rs b/ext/webgpu/wrap/device.rs index 483977258a..51fda9f925 100644 --- a/ext/webgpu/wrap/device.rs +++ b/ext/webgpu/wrap/device.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::cell::RefCell; use std::num::NonZeroU64; -use std::sync::Arc; +use std::rc::Rc; use deno_core::cppgc::SameObject; use deno_core::op2; @@ -40,7 +40,7 @@ pub struct GPUDevice { pub features: SameObject, pub limits: SameObject, - pub adapter_info: Arc>, + pub adapter_info: Rc>, pub queue_obj: SameObject, @@ -132,6 +132,7 @@ impl GPUDevice { } else { "unmapped" }), + map_mode: RefCell::new(None), mapped_js_buffers: RefCell::new(vec![]), }) } @@ -517,7 +518,7 @@ impl GPUDevice { GPURenderBundleEncoder { instance: self.instance.clone(), error_handler: self.error_handler.clone(), - encoder: RefCell::new(encoder), + encoder: RefCell::new(Some(encoder)), label: descriptor.label, } } @@ -549,13 +550,14 @@ impl GPUDevice { } } + // TODO: return same promise #[async_method] #[getter] #[cppgc] async fn lost(&self) -> GPUDeviceLostInfo { - self.lost_receiver.await.unwrap(); + // TODO: self.lost_receiver.await.unwrap(); - GPUDeviceLostInfo {} + GPUDeviceLostInfo } #[required(1)] @@ -570,9 +572,9 @@ impl GPUDevice { #[async_method] async fn pop_error_scope<'a>( &self, - scope: &mut v8::HandleScope<'a>, + //scope: &mut v8::HandleScope<'a>, ) -> Result, JsErrorBox> { - if self.error_handler.is_lost.get().is_some() { + /* if self.error_handler.is_lost.get().is_some() { return Ok(v8::null(scope).into()); } @@ -587,7 +589,12 @@ impl GPUDevice { Ok(deno_core::error::to_v8_error(scope, &err)) } else { Ok(v8::null(scope).into()) - } + }*/ + + Err(JsErrorBox::new( + "DOMExceptionOperationError", + "There are no error scopes on the error scope stack", + )) } } @@ -808,7 +815,7 @@ impl GPUDevice { } } -pub struct GPUDeviceLostInfo {} +pub struct GPUDeviceLostInfo; impl GarbageCollected for GPUDeviceLostInfo {} diff --git a/ext/webgpu/wrap/error.rs b/ext/webgpu/wrap/error.rs index 8410140a0d..9276c34aec 100644 --- a/ext/webgpu/wrap/error.rs +++ b/ext/webgpu/wrap/error.rs @@ -105,7 +105,7 @@ pub enum GPUErrorFilter { } #[derive(Debug, deno_error::JsError)] -enum GPUError { +pub enum GPUError { #[class("UNREACHABLE")] // TODO Lost, #[class("GPUValidationError")] diff --git a/ext/webgpu/wrap/mod.rs b/ext/webgpu/wrap/mod.rs index 532bbc4c4d..18e43341c4 100644 --- a/ext/webgpu/wrap/mod.rs +++ b/ext/webgpu/wrap/mod.rs @@ -12,69 +12,34 @@ use wgpu_types::PowerPreference; use crate::Instance; -mod adapter; -mod bind_group; -mod bind_group_layout; -mod buffer; -mod command_buffer; -mod command_encoder; -mod compute_pass; -mod compute_pipeline; -mod device; -mod error; -mod pipeline_layout; -mod query_set; -mod queue; -mod render_bundle; -mod render_pass; -mod render_pipeline; -mod sampler; -mod shader; -mod texture; -mod webidl; - -deno_core::extension!( - deno_webgpu, - deps = [deno_webidl, deno_web], - ops = [create_gpu], - objects = [ - GPU, - adapter::GPUAdapter, - adapter::GPUAdapterInfo, - bind_group::GPUBindGroup, - bind_group_layout::GPUBindGroupLayout, - buffer::GPUBuffer, - command_buffer::GPUCommandBuffer, - command_encoder::GPUCommandEncoder, - compute_pass::GPUComputePassEncoder, - compute_pipeline::GPUComputePipeline, - device::GPUDevice, - device::GPUDeviceLostInfo, - pipeline_layout::GPUPipelineLayout, - query_set::GPUQuerySet, - queue::GPUQueue, - render_bundle::GPURenderBundle, - render_bundle::GPURenderBundleEncoder, - render_pass::GPURenderPassEncoder, - render_pipeline::GPURenderPipeline, - sampler::GPUSampler, - shader::GPUShaderModule, - //adapter::GPUSupportedFeatures, - adapter::GPUSupportedLimits, - texture::GPUTexture, - texture::GPUTextureView, - ], - esm = ["00_init.js", "02_surface.js"], - lazy_loaded_esm = ["01_webgpu.js"], -); +pub mod adapter; +pub mod bind_group; +pub mod bind_group_layout; +pub mod buffer; +pub mod command_buffer; +pub mod command_encoder; +pub mod compute_pass; +pub mod compute_pipeline; +pub mod device; +pub mod error; +pub mod pipeline_layout; +pub mod query_set; +pub mod queue; +pub mod render_bundle; +pub mod render_pass; +pub mod render_pipeline; +pub mod sampler; +pub mod shader; +pub mod texture; +pub mod webidl; #[op2] #[cppgc] -fn create_gpu() -> GPU { +pub fn create_gpu() -> GPU { GPU } -struct GPU; +pub struct GPU; impl GarbageCollected for GPU {} @@ -127,7 +92,7 @@ impl GPU { instance: instance.clone(), features: SameObject::new(), limits: SameObject::new(), - info: Arc::new(SameObject::new()), + info: Rc::new(SameObject::new()), id, }) } @@ -158,5 +123,3 @@ macro_rules! with_label { } }; } - -pub use with_label; diff --git a/ext/webgpu/wrap/queue.rs b/ext/webgpu/wrap/queue.rs index 1040e25236..a582053a8c 100644 --- a/ext/webgpu/wrap/queue.rs +++ b/ext/webgpu/wrap/queue.rs @@ -54,13 +54,15 @@ impl GPUQueue { &self, #[webidl] buffer: Ptr, #[webidl/*(options(enforce_range = true))*/] buffer_offset: u64, - #[serde] data: (), // TODO: AllowSharedBufferSource + #[anybuffer] buf: &[u8], // TODO: AllowSharedBufferSource #[webidl/*(default = 0, options(enforce_range = true))*/] data_offset: u64, #[webidl/*(options(enforce_range = true))*/] size: Option, ) { let data = match size { - Some(size) => &buf[data_offset..(data_offset + size)], - None => &buf[data_offset..], + Some(size) => { + &buf[(data_offset as usize)..((data_offset + size) as usize)] + } + None => &buf[(data_offset as usize)..], }; let err = self @@ -75,7 +77,7 @@ impl GPUQueue { fn write_texture( &self, #[webidl] destination: GPUTexelCopyTextureInfo, - #[serde] data: (), // TODO: AllowSharedBufferSource + #[anybuffer] buf: &[u8], // TODO: AllowSharedBufferSource #[webidl] data_layout: GPUTexelCopyBufferLayout, #[webidl] size: GPUExtent3D, ) { diff --git a/ext/webgpu/wrap/render_bundle.rs b/ext/webgpu/wrap/render_bundle.rs index 1a10f36077..bf6231acfd 100644 --- a/ext/webgpu/wrap/render_bundle.rs +++ b/ext/webgpu/wrap/render_bundle.rs @@ -116,62 +116,77 @@ impl GPURenderBundleEncoder { dynamic_offsets_data_start: v8::Local<'a, v8::Value>, dynamic_offsets_data_length: v8::Local<'a, v8::Value>, ) -> Result<(), SetBindGroupError> { - const PREFIX: &str = - "Failed to execute 'setBindGroup' on 'GPUComputePassEncoder'"; - let offsets = - if let Ok(uint_32) = dynamic_offsets.try_cast::() { - let start = u64::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 4")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )?; - let len = u32::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 5")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )?; - - // TODO - - vec![] - } else { - >>::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 3")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )? - .unwrap_or_default() - }; - let mut encoder = self.encoder.borrow_mut(); let encoder = encoder.as_mut().ok_or_else(|| { JsErrorBox::generic("Encoder has already been finished") })?; - unsafe { - wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group( - encoder, - index, - bind_group.into_option().map(|bind_group| bind_group.id), - offsets.as_ptr(), - offsets.len(), - ); + const PREFIX: &str = + "Failed to execute 'setBindGroup' on 'GPUComputePassEncoder'"; + if let Ok(uint_32) = dynamic_offsets.try_cast::() { + let start = u64::convert( + scope, + dynamic_offsets_data_start, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 4")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? as usize; + let len = u32::convert( + scope, + dynamic_offsets_data_length, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 5")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? as usize; + + let ab = uint_32.buffer(scope).unwrap(); + let ptr = ab.data().unwrap(); + let ab_len = ab.byte_length() / 4; + + let data = + unsafe { std::slice::from_raw_parts(ptr.as_ptr() as _, ab_len) }; + + let offsets = &data[start..(start + len)]; + + unsafe { + wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group( + encoder, + index, + bind_group.into_option().map(|bind_group| bind_group.id), + offsets.as_ptr(), + offsets.len(), + ); + } + } else { + let offsets = >>::convert( + scope, + dynamic_offsets, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 3")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? + .unwrap_or_default(); + + unsafe { + wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group( + encoder, + index, + bind_group.into_option().map(|bind_group| bind_group.id), + offsets.as_ptr(), + offsets.len(), + ); + } } + Ok(()) } diff --git a/ext/webgpu/wrap/render_pass.rs b/ext/webgpu/wrap/render_pass.rs index 2bb84b2c60..a76e28a19a 100644 --- a/ext/webgpu/wrap/render_pass.rs +++ b/ext/webgpu/wrap/render_pass.rs @@ -199,55 +199,72 @@ impl GPURenderPassEncoder { ) -> Result<(), WebIdlError> { const PREFIX: &str = "Failed to execute 'setBindGroup' on 'GPUComputePassEncoder'"; - let offsets = - if let Ok(uint_32) = dynamic_offsets.try_cast::() { - let start = u64::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 4")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )?; - let len = u32::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 5")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )?; - // TODO + let err = if let Ok(uint_32) = dynamic_offsets.try_cast::() + { + let start = u64::convert( + scope, + dynamic_offsets_data_start, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 4")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? as usize; + let len = u32::convert( + scope, + dynamic_offsets_data_length, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 5")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? as usize; - vec![] - } else { - >>::convert( - scope, - dynamic_offsets, - Cow::Borrowed(PREFIX), - (|| Cow::Borrowed("Argument 3")).into(), - &IntOptions { - clamp: false, - enforce_range: true, - }, - )? - .unwrap_or_default() - }; + let ab = uint_32.buffer(scope).unwrap(); + let ptr = ab.data().unwrap(); + let ab_len = ab.byte_length() / 4; + + let data = + unsafe { std::slice::from_raw_parts(ptr.as_ptr() as _, ab_len) }; + + let offsets = &data[start..(start + len)]; + + self + .instance + .render_pass_set_bind_group( + &mut self.render_pass.borrow_mut(), + index, + bind_group.into_option().map(|bind_group| bind_group.id), + offsets, + ) + .err() + } else { + let offsets = >>::convert( + scope, + dynamic_offsets, + Cow::Borrowed(PREFIX), + (|| Cow::Borrowed("Argument 3")).into(), + &IntOptions { + clamp: false, + enforce_range: true, + }, + )? + .unwrap_or_default(); + + self + .instance + .render_pass_set_bind_group( + &mut self.render_pass.borrow_mut(), + index, + bind_group.into_option().map(|bind_group| bind_group.id), + &offsets, + ) + .err() + }; - let err = self - .instance - .render_pass_set_bind_group( - &mut self.render_pass.borrow_mut(), - index, - bind_group.into_option().map(|bind_group| bind_group.id), - &offsets, - ) - .err(); self.error_handler.push_error(err); Ok(()) diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index b3c3b299f0..0fa20d465c 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -38,6 +38,7 @@ const { MathRound, MathTrunc, Number, + SymbolFor, NumberIsFinite, NumberIsNaN, NumberMAX_SAFE_INTEGER, @@ -1311,7 +1312,7 @@ function configureProperties(obj) { } } -const setlikeInner = Symbol("[[set]]"); +const setlikeInner = SymbolFor("[[set]]"); // Ref: https://webidl.spec.whatwg.org/#es-setlike function setlike(obj, objPrototype, readonly) { diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 8127ac9618..5b9bce92cf 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -28,7 +28,7 @@ import * as signals from "ext:runtime/40_signals.js"; import * as tty from "ext:runtime/40_tty.js"; import * as kv from "ext:deno_kv/01_db.ts"; import * as cron from "ext:deno_cron/01_cron.ts"; -import * as webgpuSurface from "ext:deno_webgpu/02_surface.js"; +//import * as webgpuSurface from "ext:deno_webgpu/02_surface.js"; import * as telemetry from "ext:deno_telemetry/telemetry.ts"; const { ObjectDefineProperties } = primordials; @@ -203,7 +203,7 @@ ObjectDefineProperties(denoNsUnstableById[unstableIds.net], { // denoNsUnstableById[unstableIds.unsafeProto] = { __proto__: null } denoNsUnstableById[unstableIds.webgpu] = { - UnsafeWindowSurface: webgpuSurface.UnsafeWindowSurface, + //UnsafeWindowSurface: webgpuSurface.UnsafeWindowSurface, }; // denoNsUnstableById[unstableIds.workerOptions] = { __proto__: null } diff --git a/runtime/js/98_global_scope_shared.js b/runtime/js/98_global_scope_shared.js index 99bace7647..ba485c6a20 100644 --- a/runtime/js/98_global_scope_shared.js +++ b/runtime/js/98_global_scope_shared.js @@ -35,7 +35,7 @@ import process from "node:process"; import { Buffer } from "node:buffer"; import { clearImmediate, setImmediate } from "node:timers"; import { loadWebGPU } from "ext:deno_webgpu/00_init.js"; -import * as webgpuSurface from "ext:deno_webgpu/02_surface.js"; +//import * as webgpuSurface from "ext:deno_webgpu/02_surface.js"; import { unstableIds } from "ext:runtime/90_deno_ns.js"; const loadImage = core.createLazyLoader("ext:deno_canvas/01_image.js"); @@ -164,7 +164,7 @@ const windowOrWorkerGlobalScope = { (webgpu) => webgpu.GPUBufferUsage, loadWebGPU, ), - GPUCanvasContext: core.propNonEnumerable(webgpuSurface.GPUCanvasContext), + //GPUCanvasContext: core.propNonEnumerable(webgpuSurface.GPUCanvasContext), GPUColorWrite: core.propNonEnumerableLazyLoaded( (webgpu) => webgpu.GPUColorWrite, loadWebGPU, diff --git a/runtime/js/98_global_scope_worker.js b/runtime/js/98_global_scope_worker.js index 57e01d43ed..dc53dc8046 100644 --- a/runtime/js/98_global_scope_worker.js +++ b/runtime/js/98_global_scope_worker.js @@ -17,7 +17,6 @@ import * as console from "ext:deno_console/01_console.js"; import * as webidl from "ext:deno_webidl/00_webidl.js"; import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js"; import { loadWebGPU } from "ext:deno_webgpu/00_init.js"; -import { initGPU } from "../../ext/webgpu/01_webgpu"; function memoizeLazy(f) { let v_ = null;