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:
Samson 2024-08-04 19:19:46 +02:00 committed by GitHub
parent b366a02318
commit 5e59988c87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 496 additions and 871 deletions

View file

@ -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