mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
make Device.create_buffer
return an Arc<Buffer>
This commit is contained in:
parent
b8c5b2275e
commit
7b387007a8
@ -161,7 +161,7 @@ impl Global {
|
||||
let hub = A::hub(self);
|
||||
let fid = hub.buffers.prepare(id_in);
|
||||
|
||||
let mut to_destroy: ArrayVec<resource::Buffer<A>, 2> = ArrayVec::new();
|
||||
let mut to_destroy: ArrayVec<Arc<resource::Buffer<A>>, 2> = ArrayVec::new();
|
||||
let error = 'error: {
|
||||
let device = match hub.devices.get(device_id) {
|
||||
Ok(device) => device,
|
||||
@ -233,7 +233,7 @@ impl Global {
|
||||
mapped_at_creation: false,
|
||||
};
|
||||
let stage = match device.create_buffer(&stage_desc, true) {
|
||||
Ok(stage) => Arc::new(stage),
|
||||
Ok(stage) => stage,
|
||||
Err(e) => {
|
||||
to_destroy.push(buffer);
|
||||
break 'error e;
|
||||
@ -265,7 +265,7 @@ impl Global {
|
||||
hal::BufferUses::COPY_DST
|
||||
};
|
||||
|
||||
let (id, resource) = fid.assign(Arc::new(buffer));
|
||||
let (id, resource) = fid.assign(buffer);
|
||||
api_log!(
|
||||
"Device::create_buffer({:?}{}) -> {id:?}",
|
||||
desc.label.as_deref().unwrap_or(""),
|
||||
@ -288,10 +288,11 @@ impl Global {
|
||||
// Error path
|
||||
|
||||
for buffer in to_destroy {
|
||||
let device = Arc::clone(&buffer.device);
|
||||
device
|
||||
buffer
|
||||
.device
|
||||
.clone()
|
||||
.lock_life()
|
||||
.schedule_resource_destruction(queue::TempResource::Buffer(Arc::new(buffer)), !0);
|
||||
.schedule_resource_destruction(queue::TempResource::Buffer(buffer), !0);
|
||||
}
|
||||
|
||||
let id = fid.assign_error();
|
||||
|
@ -559,7 +559,7 @@ impl<A: HalApi> Device<A> {
|
||||
self: &Arc<Self>,
|
||||
desc: &resource::BufferDescriptor,
|
||||
transient: bool,
|
||||
) -> Result<Buffer<A>, resource::CreateBufferError> {
|
||||
) -> Result<Arc<Buffer<A>>, resource::CreateBufferError> {
|
||||
self.check_is_valid()?;
|
||||
|
||||
if desc.size > self.limits.max_buffer_size {
|
||||
@ -641,7 +641,7 @@ impl<A: HalApi> Device<A> {
|
||||
};
|
||||
let buffer = unsafe { self.raw().create_buffer(&hal_desc) }.map_err(DeviceError::from)?;
|
||||
|
||||
Ok(Buffer {
|
||||
let buffer = Buffer {
|
||||
raw: Snatchable::new(buffer),
|
||||
device: self.clone(),
|
||||
usage: desc.usage,
|
||||
@ -655,7 +655,9 @@ impl<A: HalApi> Device<A> {
|
||||
label: desc.label.to_string(),
|
||||
tracking_data: TrackingData::new(self.tracker_indices.buffers.clone()),
|
||||
bind_groups: Mutex::new(rank::BUFFER_BIND_GROUPS, Vec::new()),
|
||||
})
|
||||
};
|
||||
let buffer = Arc::new(buffer);
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub(crate) fn create_texture_from_hal(
|
||||
|
Loading…
Reference in New Issue
Block a user