mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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>
This commit is contained in:
parent
b366a02318
commit
5e59988c87
8 changed files with 496 additions and 871 deletions
|
@ -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::*;
|
||||
|
@ -63,22 +65,20 @@ pub struct Adapter {
|
|||
pub channel: WebGPU,
|
||||
}
|
||||
|
||||
#[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>),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue