mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 14:01:08 +01:00
Move erroring of map_async into wgc (#10228)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
5 files changed
+31
-34
No files matched your search
+23
-19
@@ -36,7 +36,10 @@ pub enum BufferError {
|
||||
Canceled(#[from] oneshot::Canceled),
|
||||
#[class("DOMExceptionOperationError")]
|
||||
#[error(transparent)]
|
||||
Access(#[from] wgpu_core::resource::BufferAccessError),
|
||||
Access(wgpu_core::resource::BufferAccessError),
|
||||
#[class("DOMExceptionAbortError")]
|
||||
#[error("{0}")]
|
||||
Aborted(&'static str),
|
||||
#[class("DOMExceptionOperationError")]
|
||||
#[error("{0}")]
|
||||
Operation(&'static str),
|
||||
@@ -45,9 +48,18 @@ pub enum BufferError {
|
||||
Other(#[from] JsErrorBox),
|
||||
}
|
||||
|
||||
pub struct GPUBuffer {
|
||||
pub error_handler: super::error::ErrorHandler,
|
||||
impl From<wgpu_core::resource::BufferAccessError> for BufferError {
|
||||
fn from(err: wgpu_core::resource::BufferAccessError) -> Self {
|
||||
match err {
|
||||
wgpu_core::resource::BufferAccessError::Device(
|
||||
wgpu_core::device::DeviceError::Lost,
|
||||
) => BufferError::Aborted("Device lost"),
|
||||
err => BufferError::Access(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GPUBuffer {
|
||||
pub wgpu_buffer: Arc<wgpu_core::resource::Buffer>,
|
||||
pub wgpu_device: Arc<wgpu_core::device::Device>,
|
||||
|
||||
@@ -144,22 +156,14 @@ impl GPUBuffer {
|
||||
sender.send(status).unwrap();
|
||||
});
|
||||
|
||||
let err = self
|
||||
.wgpu_buffer
|
||||
.map_async(
|
||||
offset,
|
||||
size,
|
||||
wgpu_core::resource::BufferMapOperation {
|
||||
host: mode,
|
||||
callback: Some(callback),
|
||||
},
|
||||
)
|
||||
.err();
|
||||
|
||||
if err.is_some() {
|
||||
self.error_handler.push_error(err);
|
||||
return Err(BufferError::Operation("validation error occurred"));
|
||||
}
|
||||
self.wgpu_buffer.map_async(
|
||||
offset,
|
||||
size,
|
||||
wgpu_core::resource::BufferMapOperation {
|
||||
host: mode,
|
||||
callback: Some(callback),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let done = Rc::new(RefCell::new(false));
|
||||
|
||||
@@ -191,7 +191,6 @@ impl GPUDevice {
|
||||
let wgpu_buffer = self.wgpu_device.create_buffer(&wgpu_descriptor);
|
||||
|
||||
Ok(GPUBuffer {
|
||||
error_handler: self.error_handler.clone(),
|
||||
wgpu_buffer,
|
||||
wgpu_device: self.wgpu_device.clone(),
|
||||
label: descriptor.label,
|
||||
|
||||
@@ -1135,7 +1135,7 @@ impl Global {
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
op: BufferMapOperation,
|
||||
) -> Result<SubmissionIndex, BufferAccessError> {
|
||||
) -> Option<SubmissionIndex> {
|
||||
let hub = self.hub.borrow();
|
||||
|
||||
let buffer = hub.buffers.get(buffer_id);
|
||||
|
||||
@@ -674,7 +674,7 @@ impl Buffer {
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferAddress>,
|
||||
op: BufferMapOperation,
|
||||
) -> Result<SubmissionIndex, BufferAccessError> {
|
||||
) -> Option<SubmissionIndex> {
|
||||
profiling::scope!("Buffer::map_async");
|
||||
api_log!(
|
||||
"Buffer::map_async {:?} offset {offset:?} size {size:?} op: {op:?}",
|
||||
@@ -683,11 +683,13 @@ impl Buffer {
|
||||
|
||||
self.try_map_async(offset, size, op)
|
||||
.map_err(|(mut operation, err)| {
|
||||
self.device
|
||||
.handle_error(err.clone(), Some(&self.label), "Buffer::map_async");
|
||||
if let Some(callback) = operation.callback.take() {
|
||||
callback(Err(err.clone()));
|
||||
callback(Err(err));
|
||||
}
|
||||
err
|
||||
})
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Try to schedule buffer mapping.
|
||||
|
||||
@@ -1704,16 +1704,8 @@ impl dispatch::BufferInterface for CoreBuffer {
|
||||
})),
|
||||
};
|
||||
|
||||
match self
|
||||
.wgpu_buffer
|
||||
.map_async(range.start, Some(range.end - range.start), operation)
|
||||
{
|
||||
Ok(_) => (),
|
||||
Err(cause) => self
|
||||
.wgpu_buffer
|
||||
.device()
|
||||
.handle_error_nolabel(cause, "Buffer::map_async"),
|
||||
}
|
||||
self.wgpu_buffer
|
||||
.map_async(range.start, Some(range.end - range.start), operation);
|
||||
}
|
||||
|
||||
fn get_mapped_range(
|
||||
|
||||
Reference in new issue
Block a user