diff --git a/components/script/dom/gpubuffer.rs b/components/script/dom/gpubuffer.rs index 330e6a27efd..04b8a9ed982 100644 --- a/components/script/dom/gpubuffer.rs +++ b/components/script/dom/gpubuffer.rs @@ -26,9 +26,10 @@ use std::ffi::c_void; use std::ops::Range; use std::ptr::NonNull; use std::rc::Rc; +use std::string::String; use webgpu::{ - wgpu::device::HostMap, WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse, - WebGPUResponseResult, + identity::WebGPUOpResult, wgpu::device::HostMap, WebGPU, WebGPUBuffer, WebGPURequest, + WebGPUResponse, WebGPUResponseResult, }; const RANGE_OFFSET_ALIGN_MASK: u64 = 8; @@ -204,10 +205,6 @@ impl GPUBufferMethods for GPUBuffer { comp: InRealm, ) -> Rc { let promise = Promise::new_in_current_realm(&self.global(), comp); - if self.state.get() != GPUBufferState::Unmapped { - promise.reject_error(Error::Abort); - return promise; - } let range_size = if let Some(s) = size { s } else if offset >= self.size { @@ -216,10 +213,23 @@ impl GPUBufferMethods for GPUBuffer { } else { self.size - offset }; + let scope_id = self.device.use_current_scope(); + if self.state.get() != GPUBufferState::Unmapped { + self.device.handle_server_msg( + scope_id, + WebGPUOpResult::ValidationError(String::from("Buffer is not Unmapped")), + ); + promise.reject_error(Error::Abort); + return promise; + } let host_map = match mode { GPUMapModeConstants::READ => HostMap::Read, GPUMapModeConstants::WRITE => HostMap::Write, _ => { + self.device.handle_server_msg( + scope_id, + WebGPUOpResult::ValidationError(String::from("Invalid MapModeFlags")), + ); promise.reject_error(Error::Abort); return promise; }, @@ -231,6 +241,8 @@ impl GPUBufferMethods for GPUBuffer { if let Err(e) = self.channel.0.send(WebGPURequest::BufferMapAsync { sender, buffer_id: self.buffer.0, + device_id: self.device.id().0, + scope_id, host_map, map_range: map_range.clone(), }) { diff --git a/components/webgpu/lib.rs b/components/webgpu/lib.rs index 3fed81811e3..d73fd4045d4 100644 --- a/components/webgpu/lib.rs +++ b/components/webgpu/lib.rs @@ -67,6 +67,8 @@ pub enum WebGPURequest { BufferMapAsync { sender: IpcSender, buffer_id: id::BufferId, + device_id: id::DeviceId, + scope_id: Option, host_map: HostMap, map_range: std::ops::Range, }, @@ -407,6 +409,8 @@ impl<'a> WGPU<'a> { WebGPURequest::BufferMapAsync { sender, buffer_id, + device_id, + scope_id, host_map, map_range, } => { @@ -456,11 +460,12 @@ impl<'a> WGPU<'a> { }; let global = &self.global; let result = gfx_select!(buffer_id => global.buffer_map_async(buffer_id, map_range, operation)); - if let Err(e) = result { + if let Err(ref e) = result { if let Err(w) = sender.send(Err(format!("{:?}", e))) { warn!("Failed to send BufferMapAsync Response ({:?})", w); } } + self.send_result(device_id, scope_id, result); }, WebGPURequest::BufferMapComplete(buffer_id) => { self.buffer_maps.remove(&buffer_id);