Skip to content

Commit

Permalink
Merge #84 #85
Browse files Browse the repository at this point in the history
84: Create buffer mapped r=kvark a=swiftcoder

I haven't really taken a swing at error handling here, posting it up early for feedback on the API.

85: Unpin nightly date for bindings generation r=kvark a=grovesNL

rust-lang/rust#57915 allows us to run bindings generation with nightly again, so we shouldn't have to pin to an older nightly date anymore (assuming everyone has a recent nightly).

Co-authored-by: Tristam MacDonald <[email protected]>
Co-authored-by: Joshua Groves <[email protected]>
  • Loading branch information
3 people committed Mar 1, 2019
2 parents 4eecce1 + a661b5b commit 8f0d4cb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ pub fn device_track_buffer(
device_id: DeviceId,
buffer_id: BufferId,
ref_count: RefCount,
flags: resource::BufferUsageFlags,
) {
let query = HUB.devices
.read()
[device_id].trackers
.lock()
.buffers
.query(buffer_id, &ref_count, resource::BufferUsageFlags::empty());
.query(buffer_id, &ref_count, flags);
assert!(query.initialized);
}

Expand All @@ -488,7 +489,30 @@ pub extern "C" fn wgpu_device_create_buffer(
let buffer = device_create_buffer(device_id, desc);
let ref_count = buffer.life_guard.ref_count.clone();
let id = HUB.buffers.register_local(buffer);
device_track_buffer(device_id, id, ref_count);
device_track_buffer(device_id, id, ref_count, resource::BufferUsageFlags::empty());
id
}

#[cfg(feature = "local")]
#[no_mangle]
pub extern "C" fn wgpu_device_create_buffer_mapped(
device_id: DeviceId,
desc: &resource::BufferDescriptor,
mapped_ptr_out: *mut *mut u8
) -> BufferId {
let buffer = device_create_buffer(device_id, desc);

let device_guard = HUB.devices.read();
let device = &device_guard[device_id];

if let Ok(ptr) = unsafe { device.raw.map_memory(&buffer.memory, 0..(desc.size as u64)) } {
unsafe{ *mapped_ptr_out = ptr; }
}

let ref_count = buffer.life_guard.ref_count.clone();
let id = HUB.buffers.register_local(buffer);
device_track_buffer(device_id, id, ref_count, resource::BufferUsageFlags::MAP_WRITE);

id
}

Expand Down

0 comments on commit 8f0d4cb

Please sign in to comment.