diff options
author | Samson <16504129+sagudev@users.noreply.github.com> | 2024-08-04 19:19:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-04 17:19:46 +0000 |
commit | 5e59988c87c40e84b0228021798455175699e824 (patch) | |
tree | 8b769306723d7fcb94b8a4af18528ab7ff790a9f /components/webgpu | |
parent | b366a02318def70948f8ff6ed321e433b721ece4 (diff) | |
download | servo-5e59988c87c40e84b0228021798455175699e824.tar.gz servo-5e59988c87c40e84b0228021798455175699e824.zip |
webgpu: Use wgpu's instead of string errors and update limits handling (#32925)
* Use wgpu specific errors
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* fixup expect
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* WIP
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* Fix records erasing enforcerange
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* page can already be destroyed
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* Support more limits
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* Set good results
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* Set OK (not PASS) expect CRASH
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* fixup expectation
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* bad expectations
https://github.com/gfx-rs/wgpu/issues/6075
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* set bad expectation
render bundleencoder needs to be rewritten
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Diffstat (limited to 'components/webgpu')
-rw-r--r-- | components/webgpu/ipc_messages/to_dom.rs | 22 | ||||
-rw-r--r-- | components/webgpu/wgpu_thread.rs | 55 |
2 files changed, 37 insertions, 40 deletions
diff --git a/components/webgpu/ipc_messages/to_dom.rs b/components/webgpu/ipc_messages/to_dom.rs index 8ae5553685b..ef64675e82a 100644 --- a/components/webgpu/ipc_messages/to_dom.rs +++ b/components/webgpu/ipc_messages/to_dom.rs @@ -7,6 +7,8 @@ use ipc_channel::ipc::IpcSharedMemory; use serde::{Deserialize, Serialize}; use wgc::pipeline::CreateShaderModuleError; +use wgpu_core::instance::{RequestAdapterError, RequestDeviceError}; +use wgpu_core::resource::BufferAccessError; pub use {wgpu_core as wgc, wgpu_types as wgt}; use crate::identity::*; @@ -64,21 +66,19 @@ pub struct Adapter { } #[derive(Debug, Deserialize, Serialize)] -pub struct Device { - pub device_id: WebGPUDevice, - pub queue_id: WebGPUQueue, - pub descriptor: wgt::DeviceDescriptor<Option<String>>, -} - -#[derive(Debug, Deserialize, Serialize)] #[allow(clippy::large_enum_variant)] pub enum WebGPUResponse { /// WebGPU is disabled None, - // TODO: use wgpu errors - Adapter(Result<Adapter, String>), - Device(Result<Device, String>), - BufferMapAsync(Result<IpcSharedMemory, String>), + Adapter(Result<Adapter, RequestAdapterError>), + Device( + ( + WebGPUDevice, + WebGPUQueue, + Result<wgt::DeviceDescriptor<Option<String>>, RequestDeviceError>, + ), + ), + BufferMapAsync(Result<IpcSharedMemory, BufferAccessError>), SubmittedWorkDone, PoppedErrorScope(Result<Option<Error>, PopError>), CompilationInfo(Option<ShaderCompilationInfo>), diff --git a/components/webgpu/wgpu_thread.rs b/components/webgpu/wgpu_thread.rs index 27111823e41..d1f9744b32c 100644 --- a/components/webgpu/wgpu_thread.rs +++ b/components/webgpu/wgpu_thread.rs @@ -38,8 +38,8 @@ use crate::gpu_error::ErrorScope; use crate::poll_thread::Poller; use crate::render_commands::apply_render_command; use crate::{ - Adapter, ComputePassId, Device, Error, PopError, PresentationData, RenderPassId, Transmute, - WebGPU, WebGPUAdapter, WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse, + Adapter, ComputePassId, Error, PopError, PresentationData, RenderPassId, Transmute, WebGPU, + WebGPUAdapter, WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse, }; pub const PRESENTATION_BUFFER_COUNT: usize = 10; @@ -189,23 +189,21 @@ impl WGPU { let callback = BufferMapCallback::from_rust(Box::from( move |result: BufferAccessResult| { drop(token); - let response = result - .map(|_| { - let global = &glob; - let (slice_pointer, range_size) = gfx_select!(buffer_id => + let response = result.map(|_| { + let global = &glob; + let (slice_pointer, range_size) = gfx_select!(buffer_id => global.buffer_get_mapped_range(buffer_id, 0, None)) - .unwrap(); - // SAFETY: guarantee to be safe from wgpu - let data = unsafe { - slice::from_raw_parts( - slice_pointer.as_ptr(), - range_size as usize, - ) - }; + .unwrap(); + // SAFETY: guarantee to be safe from wgpu + let data = unsafe { + slice::from_raw_parts( + slice_pointer.as_ptr(), + range_size as usize, + ) + }; - IpcSharedMemory::from_bytes(data) - }) - .map_err(|e| e.to_string()); + IpcSharedMemory::from_bytes(data) + }); if let Err(e) = resp_sender.send(WebGPUResponse::BufferMapAsync(response)) { @@ -226,13 +224,14 @@ impl WGPU { operation )); self.poller.wake(); - if let Err(ref e) = result { + if let Err(e) = &result { if let Err(w) = - sender.send(WebGPUResponse::BufferMapAsync(Err(e.to_string()))) + sender.send(WebGPUResponse::BufferMapAsync(Err(e.to_owned()))) { warn!("Failed to send BufferMapAsync Response ({:?})", w); } } + // Per spec we also need to raise validation error here self.maybe_dispatch_wgpu_error(device_id, result.err()); }, WebGPURequest::CommandEncoderFinish { @@ -691,8 +690,7 @@ impl WGPU { limits, channel: WebGPU(self.sender.clone()), } - }) - .map_err(|e| e.to_string()); + }); if let Err(e) = sender.send(WebGPUResponse::Adapter(response)) { warn!( @@ -722,8 +720,11 @@ impl WGPU { Some(device_id), Some(device_id.transmute()), )); + let device = WebGPUDevice(device_id); + let queue = WebGPUQueue(queue_id); if let Some(e) = error { - if let Err(e) = sender.send(WebGPUResponse::Device(Err(e.to_string()))) + if let Err(e) = + sender.send(WebGPUResponse::Device((device, queue, Err(e)))) { warn!( "Failed to send response to WebGPURequest::RequestDevice ({})", @@ -732,8 +733,6 @@ impl WGPU { } continue; } - let device = WebGPUDevice(device_id); - let queue = WebGPUQueue(queue_id); { self.devices .lock() @@ -777,11 +776,9 @@ impl WGPU { } })); gfx_select!(device_id => global.device_set_device_lost_closure(device_id, callback)); - if let Err(e) = sender.send(WebGPUResponse::Device(Ok(Device { - device_id: device, - queue_id: queue, - descriptor, - }))) { + if let Err(e) = + sender.send(WebGPUResponse::Device((device, queue, Ok(descriptor)))) + { warn!( "Failed to send response to WebGPURequest::RequestDevice ({})", e |