Record validation error in mapAsync()

This commit is contained in:
Kunal Mohan 2020-08-02 14:25:18 +05:30
parent cd8d9162e6
commit 8eff1d74de
2 changed files with 24 additions and 7 deletions

View file

@ -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<Promise> {
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(),
}) {

View file

@ -67,6 +67,8 @@ pub enum WebGPURequest {
BufferMapAsync {
sender: IpcSender<WebGPUResponseResult>,
buffer_id: id::BufferId,
device_id: id::DeviceId,
scope_id: Option<u64>,
host_map: HostMap,
map_range: std::ops::Range<u64>,
},
@ -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);