mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
change FutureId.assign
to not return a clone of the resource passed to it
This commit is contained in:
parent
7f3e1bba14
commit
96255d484f
@ -180,7 +180,7 @@ impl Global {
|
||||
}
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(buffer);
|
||||
let id = fid.assign(buffer);
|
||||
|
||||
api_log!(
|
||||
"Device::create_buffer({:?}{}) -> {id:?}",
|
||||
@ -487,7 +487,7 @@ impl Global {
|
||||
Err(error) => break 'error error,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(texture);
|
||||
let id = fid.assign(texture);
|
||||
api_log!("Device::create_texture({desc:?}) -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -535,7 +535,7 @@ impl Global {
|
||||
Err(error) => break 'error error,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(texture);
|
||||
let id = fid.assign(texture);
|
||||
api_log!("Device::create_texture({desc:?}) -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -579,7 +579,7 @@ impl Global {
|
||||
|
||||
let buffer = device.create_buffer_from_hal(hal_buffer, desc);
|
||||
|
||||
let (id, _) = fid.assign(buffer);
|
||||
let id = fid.assign(buffer);
|
||||
api_log!("Device::create_buffer -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -693,7 +693,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(view);
|
||||
let id = fid.assign(view);
|
||||
|
||||
api_log!("Texture::create_view({texture_id:?}) -> {id:?}");
|
||||
|
||||
@ -768,7 +768,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(sampler);
|
||||
let id = fid.assign(sampler);
|
||||
api_log!("Device::create_sampler -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -855,10 +855,11 @@ impl Global {
|
||||
.set(binding_model::ExclusivePipeline::None)
|
||||
.unwrap();
|
||||
|
||||
let (id_inner, arc) = fid.take().unwrap().assign(Arc::new(bgl));
|
||||
let bgl = Arc::new(bgl);
|
||||
let id_inner = fid.take().unwrap().assign(bgl.clone());
|
||||
id = Some(id_inner);
|
||||
|
||||
Ok(arc)
|
||||
Ok(bgl)
|
||||
});
|
||||
|
||||
let layout = match bgl_result {
|
||||
@ -959,7 +960,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(Arc::new(layout));
|
||||
let id = fid.assign(Arc::new(layout));
|
||||
api_log!("Device::create_pipeline_layout -> {id:?}");
|
||||
return (id, None);
|
||||
};
|
||||
@ -1104,7 +1105,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(bind_group);
|
||||
let id = fid.assign(bind_group);
|
||||
|
||||
api_log!("Device::create_bind_group -> {id:?}");
|
||||
|
||||
@ -1208,7 +1209,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(Arc::new(shader));
|
||||
let id = fid.assign(Arc::new(shader));
|
||||
api_log!("Device::create_shader_module -> {id:?}");
|
||||
return (id, None);
|
||||
};
|
||||
@ -1262,7 +1263,7 @@ impl Global {
|
||||
Ok(shader) => shader,
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
let (id, _) = fid.assign(Arc::new(shader));
|
||||
let id = fid.assign(Arc::new(shader));
|
||||
api_log!("Device::create_shader_module_spirv -> {id:?}");
|
||||
return (id, None);
|
||||
};
|
||||
@ -1312,7 +1313,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(Arc::new(command_buffer));
|
||||
let id = fid.assign(Arc::new(command_buffer));
|
||||
api_log!("Device::create_command_encoder -> {id:?}");
|
||||
return (id.into_command_encoder_id(), None);
|
||||
};
|
||||
@ -1402,7 +1403,7 @@ impl Global {
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(render_bundle);
|
||||
let id = fid.assign(render_bundle);
|
||||
api_log!("RenderBundleEncoder::finish -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -1463,7 +1464,7 @@ impl Global {
|
||||
Err(err) => break 'error err,
|
||||
};
|
||||
|
||||
let (id, _) = fid.assign(query_set);
|
||||
let id = fid.assign(query_set);
|
||||
api_log!("Device::create_query_set -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -1659,7 +1660,7 @@ impl Global {
|
||||
}
|
||||
}
|
||||
|
||||
let (id, _) = fid.assign(pipeline);
|
||||
let id = fid.assign(pipeline);
|
||||
api_log!("Device::create_render_pipeline -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -1861,7 +1862,7 @@ impl Global {
|
||||
}
|
||||
}
|
||||
|
||||
let (id, _) = fid.assign(pipeline);
|
||||
let id = fid.assign(pipeline);
|
||||
api_log!("Device::create_compute_pipeline -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -1979,7 +1980,7 @@ impl Global {
|
||||
let cache = unsafe { device.create_pipeline_cache(desc) };
|
||||
match cache {
|
||||
Ok(cache) => {
|
||||
let (id, _) = fid.assign(Arc::new(cache));
|
||||
let id = fid.assign(Arc::new(cache));
|
||||
api_log!("Device::create_pipeline_cache -> {id:?}");
|
||||
return (id, None);
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ impl Global {
|
||||
prepare_staging_buffer(device, buffer_size.get(), device.instance_flags)?;
|
||||
|
||||
let fid = hub.staging_buffers.prepare(id_in);
|
||||
let (id, _) = fid.assign(Arc::new(staging_buffer));
|
||||
let id = fid.assign(Arc::new(staging_buffer));
|
||||
resource_log!("Queue::create_staging_buffer {id:?}");
|
||||
|
||||
Ok((id, staging_buffer_ptr))
|
||||
|
@ -545,7 +545,7 @@ impl Global {
|
||||
|
||||
if any_created {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
let (id, _) = self.surfaces.prepare(id_in).assign(Arc::new(surface));
|
||||
let id = self.surfaces.prepare(id_in).assign(Arc::new(surface));
|
||||
Ok(id)
|
||||
} else {
|
||||
Err(CreateSurfaceError::FailedToCreateSurfaceForAnyBackend(
|
||||
@ -583,7 +583,7 @@ impl Global {
|
||||
gl: None,
|
||||
};
|
||||
|
||||
let (id, _) = self.surfaces.prepare(id_in).assign(Arc::new(surface));
|
||||
let id = self.surfaces.prepare(id_in).assign(Arc::new(surface));
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
@ -609,7 +609,7 @@ impl Global {
|
||||
gl: None,
|
||||
};
|
||||
|
||||
let (id, _) = self.surfaces.prepare(id_in).assign(Arc::new(surface));
|
||||
let id = self.surfaces.prepare(id_in).assign(Arc::new(surface));
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
@ -716,7 +716,7 @@ impl Global {
|
||||
for raw in hal_adapters {
|
||||
let adapter = Adapter::new(raw);
|
||||
log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info);
|
||||
let (id, _) = hub.adapters.prepare(id_backend).assign(Arc::new(adapter));
|
||||
let id = hub.adapters.prepare(id_backend).assign(Arc::new(adapter));
|
||||
list.push(id);
|
||||
}
|
||||
}
|
||||
@ -763,7 +763,7 @@ impl Global {
|
||||
None => {
|
||||
let adapter = Adapter::new(list.swap_remove(*selected));
|
||||
log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info);
|
||||
let (id, _) = HalApi::hub(self)
|
||||
let id = HalApi::hub(self)
|
||||
.adapters
|
||||
.prepare(new_id)
|
||||
.assign(Arc::new(adapter));
|
||||
@ -947,7 +947,7 @@ impl Global {
|
||||
|
||||
let fid = A::hub(self).adapters.prepare(input);
|
||||
|
||||
let (id, _adapter): (_, Arc<Adapter<A>>) = match A::VARIANT {
|
||||
let id = match A::VARIANT {
|
||||
#[cfg(vulkan)]
|
||||
Backend::Vulkan => fid.assign(Arc::new(Adapter::new(hal_adapter))),
|
||||
#[cfg(metal)]
|
||||
@ -1078,12 +1078,13 @@ impl Global {
|
||||
Ok((device, queue)) => (device, queue),
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
let (device_id, _) = device_fid.assign(device);
|
||||
let device_id = device_fid.assign(device);
|
||||
resource_log!("Created Device {:?}", device_id);
|
||||
|
||||
let device = hub.devices.get(device_id).unwrap();
|
||||
|
||||
let (queue_id, queue) = queue_fid.assign(Arc::new(queue));
|
||||
let queue = Arc::new(queue);
|
||||
let queue_id = queue_fid.assign(queue.clone());
|
||||
resource_log!("Created Queue {:?}", queue_id);
|
||||
|
||||
device.set_queue(queue);
|
||||
@ -1129,12 +1130,13 @@ impl Global {
|
||||
Ok(device) => device,
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
let (device_id, _) = devices_fid.assign(device);
|
||||
let device_id = devices_fid.assign(device);
|
||||
resource_log!("Created Device {:?}", device_id);
|
||||
|
||||
let device = hub.devices.get(device_id).unwrap();
|
||||
|
||||
let (queue_id, queue) = queues_fid.assign(Arc::new(queue));
|
||||
let queue = Arc::new(queue);
|
||||
let queue_id = queues_fid.assign(queue.clone());
|
||||
resource_log!("Created Queue {:?}", queue_id);
|
||||
|
||||
device.set_queue(queue);
|
||||
|
@ -218,16 +218,16 @@ impl Global {
|
||||
true,
|
||||
);
|
||||
|
||||
let (id, resource) = fid.assign(Arc::new(texture));
|
||||
log::debug!("Created CURRENT Surface Texture {:?}", id);
|
||||
let texture = Arc::new(texture);
|
||||
|
||||
{
|
||||
// register it in the device tracker as uninitialized
|
||||
let mut trackers = device.trackers.lock();
|
||||
trackers
|
||||
.textures
|
||||
.insert_single(&resource, hal::TextureUses::UNINITIALIZED);
|
||||
}
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
.textures
|
||||
.insert_single(&texture, hal::TextureUses::UNINITIALIZED);
|
||||
|
||||
let id = fid.assign(texture);
|
||||
log::debug!("Created CURRENT Surface Texture {:?}", id);
|
||||
|
||||
if present.acquired_texture.is_some() {
|
||||
return Err(SurfaceError::AlreadyAcquired);
|
||||
|
@ -76,10 +76,10 @@ impl<T: StorageItem> FutureId<'_, T> {
|
||||
/// Assign a new resource to this ID.
|
||||
///
|
||||
/// Registers it with the registry.
|
||||
pub fn assign(self, value: Arc<T>) -> (Id<T::Marker>, Arc<T>) {
|
||||
pub fn assign(self, value: Arc<T>) -> Id<T::Marker> {
|
||||
let mut data = self.data.write();
|
||||
data.insert(self.id, value);
|
||||
(self.id, data.get(self.id).unwrap().clone())
|
||||
self.id
|
||||
}
|
||||
|
||||
/// Assign an existing resource to a new ID.
|
||||
@ -189,7 +189,7 @@ mod tests {
|
||||
for _ in 0..1000 {
|
||||
let value = Arc::new(TestData);
|
||||
let new_id = registry.prepare(None);
|
||||
let (id, _) = new_id.assign(value);
|
||||
let id = new_id.assign(value);
|
||||
registry.unregister(id);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user