Consolidate all the registries together

This commit is contained in:
Dzmitry Malyshau 2018-10-02 12:18:54 -04:00
parent 1fd05608fb
commit d713f3e380
6 changed files with 125 additions and 109 deletions

View File

@ -1,6 +1,6 @@
use hal; use hal;
use registry::{self, Items, Registry}; use registry::{HUB, Items, Registry};
use { use {
Stored, Stored,
CommandBufferId, ComputePassId CommandBufferId, ComputePassId
@ -25,11 +25,11 @@ impl<B: hal::Backend> ComputePass<B> {
pub extern "C" fn wgpu_compute_pass_end_pass( pub extern "C" fn wgpu_compute_pass_end_pass(
pass_id: ComputePassId, pass_id: ComputePassId,
) -> CommandBufferId { ) -> CommandBufferId {
let pass = registry::COMPUTE_PASS_REGISTRY let pass = HUB.compute_passes
.lock() .lock()
.take(pass_id); .take(pass_id);
registry::COMMAND_BUFFER_REGISTRY HUB.command_buffers
.lock() .lock()
.get_mut(pass.cmb_id.0) .get_mut(pass.cmb_id.0)
.raw = Some(pass.raw); .raw = Some(pass.raw);

View File

@ -12,7 +12,7 @@ use {
Color, Origin3d, Stored, Color, Origin3d, Stored,
BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId, BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId,
}; };
use registry::{self, Items, Registry}; use registry::{HUB, Items, Registry};
use std::thread::ThreadId; use std::thread::ThreadId;
@ -86,13 +86,13 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
command_buffer_id: CommandBufferId, command_buffer_id: CommandBufferId,
_descriptor: RenderPassDescriptor<TextureViewId>, _descriptor: RenderPassDescriptor<TextureViewId>,
) -> RenderPassId { ) -> RenderPassId {
let mut cmb_guard = registry::COMMAND_BUFFER_REGISTRY.lock(); let mut cmb_guard = HUB.command_buffers.lock();
let mut cmb = cmb_guard.get_mut(command_buffer_id); let cmb = cmb_guard.get_mut(command_buffer_id);
let raw = cmb.raw.take().unwrap(); let raw = cmb.raw.take().unwrap();
let mut device_guard = registry::DEVICE_REGISTRY.lock(); let device_guard = HUB.devices.lock();
let device = &device_guard.get(cmb.device_id.0).raw; let _device = &device_guard.get(cmb.device_id.0).raw;
//let render_pass = device.create_render_pass(); //let render_pass = device.create_render_pass();
//let framebuffer = device.create_framebuffer(); //let framebuffer = device.create_framebuffer();
@ -106,7 +106,7 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
hal::SubpassContents::Inline, hal::SubpassContents::Inline,
);*/ );*/
registry::RENDER_PASS_REGISTRY HUB.render_passes
.lock() .lock()
.register(RenderPass::new(raw, command_buffer_id)) .register(RenderPass::new(raw, command_buffer_id))
} }
@ -115,12 +115,12 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
pub extern "C" fn wgpu_command_buffer_begin_compute_pass( pub extern "C" fn wgpu_command_buffer_begin_compute_pass(
command_buffer_id: CommandBufferId, command_buffer_id: CommandBufferId,
) -> ComputePassId { ) -> ComputePassId {
let mut cmb_guard = registry::COMMAND_BUFFER_REGISTRY.lock(); let mut cmb_guard = HUB.command_buffers.lock();
let mut cmb = cmb_guard.get_mut(command_buffer_id); let cmb = cmb_guard.get_mut(command_buffer_id);
let raw = cmb.raw.take().unwrap(); let raw = cmb.raw.take().unwrap();
registry::COMPUTE_PASS_REGISTRY HUB.compute_passes
.lock() .lock()
.register(ComputePass::new(raw, command_buffer_id)) .register(ComputePass::new(raw, command_buffer_id))
} }

View File

@ -1,7 +1,7 @@
use hal; use hal;
use hal::command::RawCommandBuffer; use hal::command::RawCommandBuffer;
use registry::{self, Items, Registry}; use registry::{HUB, Items, Registry};
use { use {
Stored, Stored,
CommandBufferId, RenderPassId, CommandBufferId, RenderPassId,
@ -26,12 +26,12 @@ impl<B: hal::Backend> RenderPass<B> {
pub extern "C" fn wgpu_render_pass_end_pass( pub extern "C" fn wgpu_render_pass_end_pass(
pass_id: RenderPassId, pass_id: RenderPassId,
) -> CommandBufferId { ) -> CommandBufferId {
let mut pass = registry::RENDER_PASS_REGISTRY let mut pass = HUB.render_passes
.lock() .lock()
.take(pass_id); .take(pass_id);
pass.raw.end_render_pass(); pass.raw.end_render_pass();
registry::COMMAND_BUFFER_REGISTRY HUB.command_buffers
.lock() .lock()
.get_mut(pass.cmb_id.0) .get_mut(pass.cmb_id.0)
.raw = Some(pass.raw); .raw = Some(pass.raw);

View File

@ -1,15 +1,17 @@
use hal::command::RawCommandBuffer;
use hal::queue::RawCommandQueue;
use hal::{self, Device as _Device};
use {back, binding_model, command, conv, memory, pipeline}; use {back, binding_model, command, conv, memory, pipeline};
use registry::{HUB, Items, Registry};
use registry::{self, Items, Registry};
use std::{ffi, iter, slice};
use { use {
AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId, AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId,
DeviceId, PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId, DeviceId, PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId,
}; };
use hal::command::RawCommandBuffer;
use hal::queue::RawCommandQueue;
use hal::{self, Device as _Device};
use std::{ffi, slice};
pub struct Device<B: hal::Backend> { pub struct Device<B: hal::Backend> {
pub(crate) raw: B::Device, pub(crate) raw: B::Device,
queue_group: hal::QueueGroup<B, hal::General>, queue_group: hal::QueueGroup<B, hal::General>,
@ -42,7 +44,7 @@ pub extern "C" fn wgpu_device_create_bind_group_layout(
desc: binding_model::BindGroupLayoutDescriptor, desc: binding_model::BindGroupLayoutDescriptor,
) -> BindGroupLayoutId { ) -> BindGroupLayoutId {
let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) }; let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) };
let device_guard = registry::DEVICE_REGISTRY.lock(); let device_guard = HUB.devices.lock();
let device = device_guard.get(device_id); let device = device_guard.get(device_id);
let descriptor_set_layout = device.raw.create_descriptor_set_layout( let descriptor_set_layout = device.raw.create_descriptor_set_layout(
bindings.iter().map(|binding| { bindings.iter().map(|binding| {
@ -56,7 +58,7 @@ pub extern "C" fn wgpu_device_create_bind_group_layout(
}), }),
&[], &[],
); );
registry::BIND_GROUP_LAYOUT_REGISTRY HUB.bind_group_layouts
.lock() .lock()
.register(binding_model::BindGroupLayout { .register(binding_model::BindGroupLayout {
raw: descriptor_set_layout, raw: descriptor_set_layout,
@ -68,17 +70,17 @@ pub extern "C" fn wgpu_device_create_pipeline_layout(
device_id: DeviceId, device_id: DeviceId,
desc: binding_model::PipelineLayoutDescriptor, desc: binding_model::PipelineLayoutDescriptor,
) -> PipelineLayoutId { ) -> PipelineLayoutId {
let bind_group_layout_guard = registry::BIND_GROUP_LAYOUT_REGISTRY.lock(); let bind_group_layout_guard = HUB.bind_group_layouts.lock();
let descriptor_set_layouts = let descriptor_set_layouts =
unsafe { slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length) } unsafe { slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length) }
.iter() .iter()
.map(|id| bind_group_layout_guard.get(id.clone())) .map(|id| bind_group_layout_guard.get(id.clone()))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let device_guard = registry::DEVICE_REGISTRY.lock(); let device_guard = HUB.devices.lock();
let device = &device_guard.get(device_id).raw; let device = &device_guard.get(device_id).raw;
let pipeline_layout = let pipeline_layout =
device.create_pipeline_layout(descriptor_set_layouts.iter().map(|d| &d.raw), &[]); // TODO: push constants device.create_pipeline_layout(descriptor_set_layouts.iter().map(|d| &d.raw), &[]); // TODO: push constants
registry::PIPELINE_LAYOUT_REGISTRY HUB.pipeline_layouts
.lock() .lock()
.register(binding_model::PipelineLayout { .register(binding_model::PipelineLayout {
raw: pipeline_layout, raw: pipeline_layout,
@ -90,7 +92,7 @@ pub extern "C" fn wgpu_device_create_blend_state(
_device_id: DeviceId, _device_id: DeviceId,
desc: pipeline::BlendStateDescriptor, desc: pipeline::BlendStateDescriptor,
) -> BlendStateId { ) -> BlendStateId {
registry::BLEND_STATE_REGISTRY HUB.blend_states
.lock() .lock()
.register(pipeline::BlendState { .register(pipeline::BlendState {
raw: conv::map_blend_state_descriptor(desc), raw: conv::map_blend_state_descriptor(desc),
@ -102,7 +104,7 @@ pub extern "C" fn wgpu_device_create_depth_stencil_state(
_device_id: DeviceId, _device_id: DeviceId,
desc: pipeline::DepthStencilStateDescriptor, desc: pipeline::DepthStencilStateDescriptor,
) -> DepthStencilStateId { ) -> DepthStencilStateId {
registry::DEPTH_STENCIL_STATE_REGISTRY HUB.depth_stencil_states
.lock() .lock()
.register(pipeline::DepthStencilState { .register(pipeline::DepthStencilState {
raw: conv::map_depth_stencil_state(desc), raw: conv::map_depth_stencil_state(desc),
@ -114,12 +116,12 @@ pub extern "C" fn wgpu_device_create_shader_module(
device_id: DeviceId, device_id: DeviceId,
desc: pipeline::ShaderModuleDescriptor, desc: pipeline::ShaderModuleDescriptor,
) -> ShaderModuleId { ) -> ShaderModuleId {
let device_guard = registry::DEVICE_REGISTRY.lock(); let device_guard = HUB.devices.lock();
let device = &device_guard.get(device_id).raw; let device = &device_guard.get(device_id).raw;
let shader = device let shader = device
.create_shader_module(unsafe { slice::from_raw_parts(desc.code.bytes, desc.code.length) }) .create_shader_module(unsafe { slice::from_raw_parts(desc.code.bytes, desc.code.length) })
.unwrap(); .unwrap();
registry::SHADER_MODULE_REGISTRY HUB.shader_modules
.lock() .lock()
.register(ShaderModule { raw: shader }) .register(ShaderModule { raw: shader })
} }
@ -129,14 +131,14 @@ pub extern "C" fn wgpu_device_create_command_buffer(
device_id: DeviceId, device_id: DeviceId,
_desc: command::CommandBufferDescriptor, _desc: command::CommandBufferDescriptor,
) -> CommandBufferId { ) -> CommandBufferId {
let mut device_guard = registry::DEVICE_REGISTRY.lock(); let mut device_guard = HUB.devices.lock();
let device = device_guard.get_mut(device_id); let device = device_guard.get_mut(device_id);
let mut cmd_buf = device.com_allocator.allocate(device_id, &device.raw); let mut cmd_buf = device.com_allocator.allocate(device_id, &device.raw);
cmd_buf.raw.as_mut().unwrap().begin( cmd_buf.raw.as_mut().unwrap().begin(
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT, hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
hal::command::CommandBufferInheritanceInfo::default(), hal::command::CommandBufferInheritanceInfo::default(),
); );
registry::COMMAND_BUFFER_REGISTRY.lock().register(cmd_buf) HUB.command_buffers.lock().register(cmd_buf)
} }
#[no_mangle] #[no_mangle]
@ -150,28 +152,48 @@ pub extern "C" fn wgpu_queue_submit(
command_buffer_ptr: *const CommandBufferId, command_buffer_ptr: *const CommandBufferId,
command_buffer_count: usize, command_buffer_count: usize,
) { ) {
let mut device_guard = registry::DEVICE_REGISTRY.lock(); let mut device_guard = HUB.devices.lock();
let device = device_guard.get_mut(queue_id); let device = device_guard.get_mut(queue_id);
let command_buffer_ids = let mut command_buffer_guard = HUB.command_buffers.lock();
unsafe { slice::from_raw_parts(command_buffer_ptr, command_buffer_count) }; let command_buffer_ids = unsafe {
//TODO: submit at once, requires `get_all()` slice::from_raw_parts(command_buffer_ptr, command_buffer_count)
let mut command_buffer_guard = registry::COMMAND_BUFFER_REGISTRY.lock(); };
// finish all the command buffers first
for &cmb_id in command_buffer_ids { for &cmb_id in command_buffer_ids {
let mut cmd_buf = command_buffer_guard.take(cmb_id); command_buffer_guard
{ .get_mut(cmb_id)
let mut raw = cmd_buf.raw.as_mut().unwrap(); .raw
raw.finish(); .as_mut()
let submission = hal::queue::RawSubmission { .unwrap()
cmd_buffers: iter::once(raw), .finish();
wait_semaphores: &[], }
signal_semaphores: &[],
}; // now prepare the GPU submission
unsafe { {
device.queue_group.queues[0] let submission = hal::queue::RawSubmission {
.as_raw_mut() cmd_buffers: command_buffer_ids
.submit_raw(submission, None); .iter()
} .map(|&cmb_id| {
command_buffer_guard
.get(cmb_id)
.raw
.as_ref()
.unwrap()
}),
wait_semaphores: &[],
signal_semaphores: &[],
};
unsafe {
device.queue_group.queues[0]
.as_raw_mut()
.submit_raw(submission, None);
} }
}
// finally, return the command buffers to the allocator
for &cmb_id in command_buffer_ids {
let cmd_buf = command_buffer_guard.take(cmb_id);
device.com_allocator.submit(cmd_buf); device.com_allocator.submit(cmd_buf);
} }
} }
@ -181,7 +203,7 @@ pub extern "C" fn wgpu_device_create_attachment_state(
device_id: DeviceId, device_id: DeviceId,
desc: pipeline::AttachmentStateDescriptor, desc: pipeline::AttachmentStateDescriptor,
) -> AttachmentStateId { ) -> AttachmentStateId {
let device_guard = registry::DEVICE_REGISTRY.lock(); let device_guard = HUB.devices.lock();
let device = &device_guard.get(device_id).raw; let device = &device_guard.get(device_id).raw;
let color_formats = unsafe { let color_formats = unsafe {
@ -224,7 +246,7 @@ pub extern "C" fn wgpu_device_create_attachment_state(
depth_stencil_format, depth_stencil_format,
}; };
registry::ATTACHMENT_STATE_REGISTRY HUB.attachment_states
.lock() .lock()
.register(at_state) .register(at_state)
} }
@ -240,12 +262,12 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
height: 100, height: 100,
}; };
let device_guard = registry::DEVICE_REGISTRY.lock(); let device_guard = HUB.devices.lock();
let device = &device_guard.get(device_id).raw; let device = &device_guard.get(device_id).raw;
let pipeline_layout_guard = registry::PIPELINE_LAYOUT_REGISTRY.lock(); let pipeline_layout_guard = HUB.pipeline_layouts.lock();
let layout = &pipeline_layout_guard.get(desc.layout).raw; let layout = &pipeline_layout_guard.get(desc.layout).raw;
let pipeline_stages = unsafe { slice::from_raw_parts(desc.stages, desc.stages_length) }; let pipeline_stages = unsafe { slice::from_raw_parts(desc.stages, desc.stages_length) };
let shader_module_guard = registry::SHADER_MODULE_REGISTRY.lock(); let shader_module_guard = HUB.shader_modules.lock();
let shaders = { let shaders = {
let mut vertex = None; let mut vertex = None;
let mut fragment = None; let mut fragment = None;
@ -303,7 +325,7 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
primitive_restart: hal::pso::PrimitiveRestart::Disabled, // TODO primitive_restart: hal::pso::PrimitiveRestart::Disabled, // TODO
}; };
let blend_state_guard = registry::BLEND_STATE_REGISTRY.lock(); let blend_state_guard = HUB.blend_states.lock();
let blend_state = unsafe { slice::from_raw_parts(desc.blend_state, desc.blend_state_length) } let blend_state = unsafe { slice::from_raw_parts(desc.blend_state, desc.blend_state_length) }
.iter() .iter()
.map(|id| blend_state_guard.get(id.clone()).raw) .map(|id| blend_state_guard.get(id.clone()).raw)
@ -314,7 +336,7 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
targets: blend_state, targets: blend_state,
}; };
let depth_stencil_state_guard = registry::DEPTH_STENCIL_STATE_REGISTRY.lock(); let depth_stencil_state_guard = HUB.depth_stencil_states.lock();
let depth_stencil = depth_stencil_state_guard.get(desc.depth_stencil_state).raw; let depth_stencil = depth_stencil_state_guard.get(desc.depth_stencil_state).raw;
// TODO // TODO
@ -341,7 +363,7 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
depth_bounds: None, depth_bounds: None,
}; };
let attachment_state_guard = registry::ATTACHMENT_STATE_REGISTRY.lock(); let attachment_state_guard = HUB.attachment_states.lock();
let attachment_state = attachment_state_guard.get(desc.attachment_state); let attachment_state = attachment_state_guard.get(desc.attachment_state);
// TODO // TODO
@ -377,7 +399,7 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
.create_graphics_pipeline(&pipeline_desc, None) .create_graphics_pipeline(&pipeline_desc, None)
.unwrap(); .unwrap();
registry::RENDER_PIPELINE_REGISTRY HUB.render_pipelines
.lock() .lock()
.register(pipeline::RenderPipeline { raw: pipeline }) .register(pipeline::RenderPipeline { raw: pipeline })
} }

View File

@ -1,6 +1,6 @@
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice}; use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
use registry::{self, Items, Registry}; use registry::{HUB, Items, Registry};
use {AdapterId, Device, DeviceId, InstanceId}; use {AdapterId, Device, DeviceId, InstanceId};
#[repr(C)] #[repr(C)]
@ -35,7 +35,7 @@ pub extern "C" fn wgpu_create_instance() -> InstanceId {
))] ))]
{ {
let inst = ::back::Instance::create("wgpu", 1); let inst = ::back::Instance::create("wgpu", 1);
registry::INSTANCE_REGISTRY.lock().register(inst) HUB.instances.lock().register(inst)
} }
#[cfg(not(any( #[cfg(not(any(
feature = "gfx-backend-vulkan", feature = "gfx-backend-vulkan",
@ -52,7 +52,7 @@ pub extern "C" fn wgpu_instance_get_adapter(
instance_id: InstanceId, instance_id: InstanceId,
desc: AdapterDescriptor, desc: AdapterDescriptor,
) -> AdapterId { ) -> AdapterId {
let instance_guard = registry::INSTANCE_REGISTRY.lock(); let instance_guard = HUB.instances.lock();
let instance = instance_guard.get(instance_id); let instance = instance_guard.get(instance_id);
let (mut low, mut high, mut other) = (None, None, None); let (mut low, mut high, mut other) = (None, None, None);
for adapter in instance.enumerate_adapters() { for adapter in instance.enumerate_adapters() {
@ -67,7 +67,7 @@ pub extern "C" fn wgpu_instance_get_adapter(
PowerPreference::LowPower => low.or(high), PowerPreference::LowPower => low.or(high),
PowerPreference::HighPerformance | PowerPreference::Default => high.or(low), PowerPreference::HighPerformance | PowerPreference::Default => high.or(low),
}; };
registry::ADAPTER_REGISTRY HUB.adapters
.lock() .lock()
.register(some.or(other).unwrap()) .register(some.or(other).unwrap())
} }
@ -77,11 +77,11 @@ pub extern "C" fn wgpu_adapter_create_device(
adapter_id: AdapterId, adapter_id: AdapterId,
_desc: DeviceDescriptor, _desc: DeviceDescriptor,
) -> DeviceId { ) -> DeviceId {
let mut adapter_guard = registry::ADAPTER_REGISTRY.lock(); let mut adapter_guard = HUB.adapters.lock();
let adapter = adapter_guard.get_mut(adapter_id); let adapter = adapter_guard.get_mut(adapter_id);
let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap(); let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap();
let mem_props = adapter.physical_device.memory_properties(); let mem_props = adapter.physical_device.memory_properties();
registry::DEVICE_REGISTRY HUB.devices
.lock() .lock()
.register(Device::new(device, queue_group, mem_props)) .register(Device::new(device, queue_group, mem_props))
} }

View File

@ -17,9 +17,9 @@ use {
}; };
#[cfg(not(feature = "remote"))] #[cfg(not(feature = "remote"))]
pub(crate) type Id = *mut c_void; pub type Id = *mut c_void;
#[cfg(feature = "remote")] #[cfg(feature = "remote")]
pub(crate) type Id = u32; pub type Id = u32;
type Item<'a, T> = &'a T; type Item<'a, T> = &'a T;
type ItemMut<'a, T> = &'a mut T; type ItemMut<'a, T> = &'a mut T;
@ -29,12 +29,11 @@ type ItemsGuard<'a, T> = LocalItems<T>;
#[cfg(feature = "remote")] #[cfg(feature = "remote")]
type ItemsGuard<'a, T> = MutexGuard<'a, RemoteItems<T>>; type ItemsGuard<'a, T> = MutexGuard<'a, RemoteItems<T>>;
pub(crate) trait Registry<T> { pub trait Registry<T>: Default {
fn new() -> Self;
fn lock(&self) -> ItemsGuard<T>; fn lock(&self) -> ItemsGuard<T>;
} }
pub(crate) trait Items<T> { pub trait Items<T> {
fn register(&mut self, handle: T) -> Id; fn register(&mut self, handle: T) -> Id;
fn get(&self, id: Id) -> Item<T>; fn get(&self, id: Id) -> Item<T>;
fn get_mut(&mut self, id: Id) -> ItemMut<T>; fn get_mut(&mut self, id: Id) -> ItemMut<T>;
@ -42,7 +41,7 @@ pub(crate) trait Items<T> {
} }
#[cfg(not(feature = "remote"))] #[cfg(not(feature = "remote"))]
pub(crate) struct LocalItems<T> { pub struct LocalItems<T> {
marker: PhantomData<T>, marker: PhantomData<T>,
} }
@ -66,18 +65,19 @@ impl<T> Items<T> for LocalItems<T> {
} }
#[cfg(not(feature = "remote"))] #[cfg(not(feature = "remote"))]
pub(crate) struct LocalRegistry<T> { pub struct LocalRegistry<T> {
marker: PhantomData<T>, marker: PhantomData<T>,
} }
#[cfg(not(feature = "remote"))] #[cfg(not(feature = "remote"))]
impl<T> Registry<T> for LocalRegistry<T> { impl<T> Default for LocalRegistry<T> {
fn new() -> Self { fn default() -> Self {
LocalRegistry { LocalRegistry {
marker: PhantomData, marker: PhantomData,
} }
} }
}
#[cfg(not(feature = "remote"))]
impl<T> Registry<T> for LocalRegistry<T> {
fn lock(&self) -> ItemsGuard<T> { fn lock(&self) -> ItemsGuard<T> {
LocalItems { LocalItems {
marker: PhantomData, marker: PhantomData,
@ -86,7 +86,7 @@ impl<T> Registry<T> for LocalRegistry<T> {
} }
#[cfg(feature = "remote")] #[cfg(feature = "remote")]
pub(crate) struct RemoteItems<T> { pub struct RemoteItems<T> {
next_id: Id, next_id: Id,
tracked: FastHashMap<Id, T>, tracked: FastHashMap<Id, T>,
free: Vec<Id>, free: Vec<Id>,
@ -132,18 +132,19 @@ impl<T> Items<T> for RemoteItems<T> {
} }
#[cfg(feature = "remote")] #[cfg(feature = "remote")]
pub(crate) struct RemoteRegistry<T> { pub struct RemoteRegistry<T> {
items: Arc<Mutex<RemoteItems<T>>>, items: Arc<Mutex<RemoteItems<T>>>,
} }
#[cfg(feature = "remote")] #[cfg(feature = "remote")]
impl<T> Registry<T> for RemoteRegistry<T> { impl<T> Default for RemoteRegistry<T> {
fn new() -> Self { fn default() -> Self {
RemoteRegistry { RemoteRegistry {
items: Arc::new(Mutex::new(RemoteItems::new())), items: Arc::new(Mutex::new(RemoteItems::new())),
} }
} }
}
#[cfg(feature = "remote")]
impl<T> Registry<T> for RemoteRegistry<T> {
fn lock(&self) -> ItemsGuard<T> { fn lock(&self) -> ItemsGuard<T> {
self.items.lock() self.items.lock()
} }
@ -154,30 +155,23 @@ type ConcreteRegistry<T> = LocalRegistry<T>;
#[cfg(feature = "remote")] #[cfg(feature = "remote")]
type ConcreteRegistry<T> = RemoteRegistry<T>; type ConcreteRegistry<T> = RemoteRegistry<T>;
lazy_static! { #[derive(Default)]
pub(crate) static ref ADAPTER_REGISTRY: ConcreteRegistry<AdapterHandle> = pub struct Hub {
ConcreteRegistry::new(); pub(crate) instances: ConcreteRegistry<InstanceHandle>,
pub(crate) static ref ATTACHMENT_STATE_REGISTRY: ConcreteRegistry<AttachmentStateHandle> = pub(crate) adapters: ConcreteRegistry<AdapterHandle>,
ConcreteRegistry::new(); pub(crate) devices: ConcreteRegistry<DeviceHandle>,
pub(crate) static ref BIND_GROUP_LAYOUT_REGISTRY: ConcreteRegistry<BindGroupLayoutHandle> = pub(crate) pipeline_layouts: ConcreteRegistry<PipelineLayoutHandle>,
ConcreteRegistry::new(); pub(crate) bind_group_layouts: ConcreteRegistry<BindGroupLayoutHandle>,
pub(crate) static ref BLEND_STATE_REGISTRY: ConcreteRegistry<BlendStateHandle> = pub(crate) attachment_states: ConcreteRegistry<AttachmentStateHandle>,
ConcreteRegistry::new(); pub(crate) blend_states: ConcreteRegistry<BlendStateHandle>,
pub(crate) static ref DEPTH_STENCIL_STATE_REGISTRY: ConcreteRegistry<DepthStencilStateHandle> = pub(crate) depth_stencil_states: ConcreteRegistry<DepthStencilStateHandle>,
ConcreteRegistry::new(); pub(crate) shader_modules: ConcreteRegistry<ShaderModuleHandle>,
pub(crate) static ref DEVICE_REGISTRY: ConcreteRegistry<DeviceHandle> = ConcreteRegistry::new(); pub(crate) command_buffers: ConcreteRegistry<CommandBufferHandle>,
pub(crate) static ref COMMAND_BUFFER_REGISTRY: ConcreteRegistry<CommandBufferHandle> = pub(crate) render_pipelines: ConcreteRegistry<RenderPipelineHandle>,
ConcreteRegistry::new(); pub(crate) render_passes: ConcreteRegistry<RenderPassHandle>,
pub(crate) static ref INSTANCE_REGISTRY: ConcreteRegistry<InstanceHandle> = pub(crate) compute_passes: ConcreteRegistry<ComputePassHandle>,
ConcreteRegistry::new(); }
pub(crate) static ref PIPELINE_LAYOUT_REGISTRY: ConcreteRegistry<PipelineLayoutHandle> =
ConcreteRegistry::new(); lazy_static! {
pub(crate) static ref RENDER_PIPELINE_REGISTRY: ConcreteRegistry<RenderPipelineHandle> = pub static ref HUB: Hub = Hub::default();
ConcreteRegistry::new();
pub(crate) static ref SHADER_MODULE_REGISTRY: ConcreteRegistry<ShaderModuleHandle> =
ConcreteRegistry::new();
pub(crate) static ref RENDER_PASS_REGISTRY: ConcreteRegistry<RenderPassHandle> =
ConcreteRegistry::new();
pub(crate) static ref COMPUTE_PASS_REGISTRY: ConcreteRegistry<ComputePassHandle> =
ConcreteRegistry::new();
} }