Unbox unnecessarily boxed function

This commit is contained in:
Lachlan Sneff 2020-03-26 22:38:50 -04:00
parent 86981d9a80
commit bcd7744c5b
5 changed files with 35 additions and 29 deletions

View File

@ -554,10 +554,10 @@ impl<B: GfxBackend> LifetimeTracker<B> {
let buffer = &mut buffer_guard[buffer_id];
let mapping = buffer.pending_mapping.take().unwrap();
let result = match mapping.op {
resource::BufferMapOperation::Read(..) => {
resource::BufferMapOperation::Read { .. } => {
super::map_buffer(raw, buffer, mapping.range, super::HostMap::Read)
}
resource::BufferMapOperation::Write(..) => {
resource::BufferMapOperation::Write { .. } => {
super::map_buffer(raw, buffer, mapping.range, super::HostMap::Write)
}
};

View File

@ -181,11 +181,11 @@ fn fire_map_callbacks<I: IntoIterator<Item = BufferMapPendingCallback>>(callback
}
};
match operation {
resource::BufferMapOperation::Read(on_read) => {
on_read(status, ptr)
resource::BufferMapOperation::Read { callback, userdata } => unsafe {
callback(status, ptr, userdata)
}
resource::BufferMapOperation::Write(on_write) => {
on_write(status, ptr)
resource::BufferMapOperation::Write { callback, userdata } => unsafe {
callback(status, ptr, userdata)
}
}
}

View File

@ -31,8 +31,14 @@ pub enum BufferMapAsyncStatus {
}
pub enum BufferMapOperation {
Read(Box<dyn FnOnce(BufferMapAsyncStatus, *const u8)>),
Write(Box<dyn FnOnce(BufferMapAsyncStatus, *mut u8)>),
Read {
callback: crate::device::BufferMapReadCallback,
userdata: *mut u8,
},
Write {
callback: crate::device::BufferMapWriteCallback,
userdata: *mut u8,
}
}
//TODO: clarify if/why this is needed here
@ -42,8 +48,8 @@ unsafe impl Sync for BufferMapOperation {}
impl fmt::Debug for BufferMapOperation {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let op = match *self {
BufferMapOperation::Read(_) => "read",
BufferMapOperation::Write(_) => "write",
BufferMapOperation::Read { .. } => "read",
BufferMapOperation::Write { .. } => "write",
};
write!(fmt, "BufferMapOperation <{}>", op)
}
@ -52,13 +58,13 @@ impl fmt::Debug for BufferMapOperation {
impl BufferMapOperation {
pub(crate) fn call_error(self) {
match self {
BufferMapOperation::Read(callback) => {
BufferMapOperation::Read { callback, userdata } => {
log::error!("wgpu_buffer_map_read_async failed: buffer mapping is pending");
callback(BufferMapAsyncStatus::Error, std::ptr::null());
unsafe { callback(BufferMapAsyncStatus::Error, std::ptr::null(), userdata); }
}
BufferMapOperation::Write(callback) => {
BufferMapOperation::Write { callback, userdata } => {
log::error!("wgpu_buffer_map_write_async failed: buffer mapping is pending");
callback(BufferMapAsyncStatus::Error, std::ptr::null_mut());
unsafe { callback(BufferMapAsyncStatus::Error, std::ptr::null_mut(), userdata); }
}
}
}

View File

@ -380,11 +380,11 @@ pub extern "C" fn wgpu_buffer_map_read_async(
callback: core::device::BufferMapReadCallback,
userdata: *mut u8,
) {
let operation = core::resource::BufferMapOperation::Read(
Box::new(move |status, data| unsafe {
callback(status, data, userdata)
}),
);
let operation = core::resource::BufferMapOperation::Read {
callback,
userdata,
};
gfx_select!(buffer_id => GLOBAL.buffer_map_async(buffer_id, wgt::BufferUsage::MAP_READ, start .. start + size, operation))
}
@ -396,11 +396,11 @@ pub extern "C" fn wgpu_buffer_map_write_async(
callback: core::device::BufferMapWriteCallback,
userdata: *mut u8,
) {
let operation = core::resource::BufferMapOperation::Write(
Box::new(move |status, data| unsafe {
callback(status, data, userdata)
}),
);
let operation = core::resource::BufferMapOperation::Write {
callback,
userdata,
};
gfx_select!(buffer_id => GLOBAL.buffer_map_async(buffer_id, wgt::BufferUsage::MAP_WRITE, start .. start + size, operation))
}

View File

@ -123,11 +123,11 @@ pub extern "C" fn wgpu_server_buffer_map_read(
callback: core::device::BufferMapReadCallback,
userdata: *mut u8,
) {
let operation = core::resource::BufferMapOperation::Read(
Box::new(move |status, data| unsafe {
callback(status, data, userdata)
}),
);
let operation = core::resource::BufferMapOperation::Read {
callback,
userdata,
};
gfx_select!(buffer_id => global.buffer_map_async(
buffer_id,
wgt::BufferUsage::MAP_READ,