mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 08:21:25 +01:00
Recycled identity management (#533)
This commit is contained in:
1 parent
272e423a5c
commit
0a30cf4b46
14 files changed
+397
-192
No files matched your search
@@ -9,7 +9,7 @@ use crate::{
|
||||
PhantomSlice,
|
||||
},
|
||||
device::{all_buffer_stages, BIND_BUFFER_ALIGNMENT},
|
||||
hub::{GfxBackend, Global, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
|
||||
id,
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ pub struct ComputePassDescriptor {
|
||||
|
||||
// Common routines between render/compute
|
||||
|
||||
impl<F> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn command_encoder_run_compute_pass<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
|
||||
@@ -19,7 +19,7 @@ use crate::{
|
||||
all_buffer_stages,
|
||||
all_image_stages,
|
||||
},
|
||||
hub::{GfxBackend, Global, Storage, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Storage, Token},
|
||||
id,
|
||||
resource::{Buffer, Texture},
|
||||
track::TrackerSet,
|
||||
@@ -205,7 +205,7 @@ pub struct RawRenderTargets {
|
||||
pub depth_stencil: RenderPassDepthStencilAttachmentDescriptor,
|
||||
}
|
||||
|
||||
impl<F> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn command_encoder_finish<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
MAX_VERTEX_BUFFERS,
|
||||
MAX_COLOR_TARGETS,
|
||||
},
|
||||
hub::{GfxBackend, Global, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
|
||||
id,
|
||||
pipeline::PipelineFlags,
|
||||
resource::TextureViewInner,
|
||||
@@ -281,7 +281,7 @@ impl State {
|
||||
|
||||
// Common routines between render/compute
|
||||
|
||||
impl<F> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn command_encoder_run_render_pass<B: GfxBackend>(
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use crate::{
|
||||
conv,
|
||||
device::{all_buffer_stages, all_image_stages},
|
||||
hub::{GfxBackend, Global, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
|
||||
id::{BufferId, CommandEncoderId, TextureId},
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ impl TextureCopyView {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn command_encoder_copy_buffer_to_buffer<B: GfxBackend>(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::{
|
||||
hub::{AllIdentityFilter, GfxBackend, Global, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
|
||||
id,
|
||||
resource,
|
||||
track::TrackerSet,
|
||||
@@ -204,6 +204,7 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
|
||||
fn wait_idle(&self, device: &B::Device) {
|
||||
if !self.active.is_empty() {
|
||||
log::debug!("Waiting for IDLE...");
|
||||
let status = unsafe {
|
||||
device.wait_for_fences(
|
||||
self.active.iter().map(|a| &a.fence),
|
||||
@@ -211,6 +212,7 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
CLEANUP_WAIT_MS * 1_000_000,
|
||||
)
|
||||
};
|
||||
log::debug!("...Done");
|
||||
assert_eq!(status, Ok(true), "GPU got stuck :(");
|
||||
}
|
||||
}
|
||||
@@ -268,9 +270,9 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
}
|
||||
|
||||
impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
pub(crate) fn triage_suspected<F: AllIdentityFilter>(
|
||||
pub(crate) fn triage_suspected<G: GlobalIdentityHandlerFactory>(
|
||||
&mut self,
|
||||
global: &Global<F>,
|
||||
global: &Global<G>,
|
||||
trackers: &Mutex<TrackerSet>,
|
||||
token: &mut Token<super::Device<B>>,
|
||||
) {
|
||||
@@ -282,7 +284,7 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
|
||||
for id in self.suspected_resources.bind_groups.drain(..) {
|
||||
if trackers.bind_groups.remove_abandoned(id) {
|
||||
hub.bind_groups.identity.free(id);
|
||||
hub.bind_groups.free_id(id);
|
||||
let res = guard.remove(id).unwrap();
|
||||
|
||||
assert!(res.used.bind_groups.is_empty());
|
||||
@@ -307,7 +309,7 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
|
||||
for id in self.suspected_resources.texture_views.drain(..) {
|
||||
if trackers.views.remove_abandoned(id) {
|
||||
hub.texture_views.identity.free(id);
|
||||
hub.texture_views.free_id(id);
|
||||
let res = guard.remove(id).unwrap();
|
||||
|
||||
let raw = match res.inner {
|
||||
@@ -334,7 +336,7 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
|
||||
for id in self.suspected_resources.textures.drain(..) {
|
||||
if trackers.textures.remove_abandoned(id) {
|
||||
hub.textures.identity.free(id);
|
||||
hub.textures.free_id(id);
|
||||
let res = guard.remove(id).unwrap();
|
||||
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
@@ -353,7 +355,7 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
|
||||
for id in self.suspected_resources.samplers.drain(..) {
|
||||
if trackers.samplers.remove_abandoned(id) {
|
||||
hub.samplers.identity.free(id);
|
||||
hub.samplers.free_id(id);
|
||||
let res = guard.remove(id).unwrap();
|
||||
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
@@ -372,7 +374,7 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
|
||||
for id in self.suspected_resources.buffers.drain(..) {
|
||||
if trackers.buffers.remove_abandoned(id) {
|
||||
hub.buffers.identity.free(id);
|
||||
hub.buffers.free_id(id);
|
||||
let res = guard.remove(id).unwrap();
|
||||
|
||||
let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
|
||||
@@ -386,8 +388,10 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn triage_mapped<F>(
|
||||
&mut self, global: &Global<F>, token: &mut Token<super::Device<B>>
|
||||
pub(crate) fn triage_mapped<G: GlobalIdentityHandlerFactory>(
|
||||
&mut self,
|
||||
global: &Global<G>,
|
||||
token: &mut Token<super::Device<B>>,
|
||||
) {
|
||||
if self.mapped.is_empty() {
|
||||
return;
|
||||
@@ -414,9 +418,9 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn triage_framebuffers<F>(
|
||||
pub(crate) fn triage_framebuffers<G: GlobalIdentityHandlerFactory>(
|
||||
&mut self,
|
||||
global: &Global<F>,
|
||||
global: &Global<G>,
|
||||
framebuffers: &mut FastHashMap<super::FramebufferKey, B::Framebuffer>,
|
||||
token: &mut Token<super::Device<B>>,
|
||||
) {
|
||||
@@ -477,9 +481,9 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn handle_mapping<F>(
|
||||
pub(crate) fn handle_mapping<G: GlobalIdentityHandlerFactory>(
|
||||
&mut self,
|
||||
global: &Global<F>,
|
||||
global: &Global<G>,
|
||||
raw: &B::Device,
|
||||
token: &mut Token<super::Device<B>>,
|
||||
) -> Vec<super::BufferMapPendingCallback> {
|
||||
|
||||
+44
-76
@@ -6,7 +6,7 @@ use crate::{
|
||||
binding_model,
|
||||
command,
|
||||
conv,
|
||||
hub::{AllIdentityFilter, GfxBackend, Global, IdentityFilter, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
|
||||
id,
|
||||
pipeline,
|
||||
resource,
|
||||
@@ -271,9 +271,9 @@ impl<B: GfxBackend> Device<B> {
|
||||
self.life_tracker.lock()
|
||||
}
|
||||
|
||||
fn maintain<'a, F: AllIdentityFilter>(
|
||||
fn maintain<'a, G: GlobalIdentityHandlerFactory>(
|
||||
&'a self,
|
||||
global: &Global<F>,
|
||||
global: &Global<G>,
|
||||
force_wait: bool,
|
||||
token: &mut Token<'a, Self>,
|
||||
) -> Vec<BufferMapPendingCallback> {
|
||||
@@ -490,12 +490,12 @@ impl<B: hal::Backend> Device<B> {
|
||||
}
|
||||
|
||||
|
||||
impl<F: IdentityFilter<id::BufferId>> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn device_create_buffer<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::BufferDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::BufferId>,
|
||||
) -> id::BufferId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -525,7 +525,7 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::BufferDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::BufferId>,
|
||||
) -> (id::BufferId, *mut u8) {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -644,14 +644,12 @@ impl<F: IdentityFilter<id::BufferId>> Global<F> {
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources.buffers.push(buffer_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::TextureId>> Global<F> {
|
||||
pub fn device_create_texture<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::TextureDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::TextureId>,
|
||||
) -> id::TextureId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -690,14 +688,12 @@ impl<F: IdentityFilter<id::TextureId>> Global<F> {
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources.textures.push(texture_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::TextureViewId>> Global<F> {
|
||||
pub fn texture_create_view<B: GfxBackend>(
|
||||
&self,
|
||||
texture_id: id::TextureId,
|
||||
desc: Option<&wgt::TextureViewDescriptor>,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::TextureViewId>,
|
||||
) -> id::TextureViewId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -801,14 +797,12 @@ impl<F: IdentityFilter<id::TextureViewId>> Global<F> {
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources.texture_views.push(texture_view_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::SamplerId>> Global<F> {
|
||||
pub fn device_create_sampler<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::SamplerDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::SamplerId>,
|
||||
) -> id::SamplerId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -866,14 +860,12 @@ impl<F: IdentityFilter<id::SamplerId>> Global<F> {
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources.samplers.push(sampler_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::BindGroupLayoutId>> Global<F> {
|
||||
pub fn device_create_bind_group_layout<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &binding_model::BindGroupLayoutDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::BindGroupLayoutId>,
|
||||
) -> id::BindGroupLayoutId {
|
||||
let mut token = Token::root();
|
||||
let hub = B::hub(self);
|
||||
@@ -942,14 +934,12 @@ impl<F: IdentityFilter<id::BindGroupLayoutId>> Global<F> {
|
||||
device_guard[bgl.device_id.value].raw.destroy_descriptor_set_layout(bgl.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::PipelineLayoutId>> Global<F> {
|
||||
pub fn device_create_pipeline_layout<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &binding_model::PipelineLayoutDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::PipelineLayoutId>,
|
||||
) -> id::PipelineLayoutId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -998,14 +988,12 @@ impl<F: IdentityFilter<id::PipelineLayoutId>> Global<F> {
|
||||
device_guard[pipeline_layout.device_id.value].raw.destroy_pipeline_layout(pipeline_layout.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
|
||||
pub fn device_create_bind_group<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &binding_model::BindGroupDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::BindGroupId>,
|
||||
) -> id::BindGroupId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1211,14 +1199,12 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources.bind_groups.push(bind_group_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::ShaderModuleId>> Global<F> {
|
||||
pub fn device_create_shader_module<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &pipeline::ShaderModuleDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::ShaderModuleId>,
|
||||
) -> id::ShaderModuleId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1253,14 +1239,12 @@ impl<F: IdentityFilter<id::ShaderModuleId>> Global<F> {
|
||||
device_guard[module.device_id.value].raw.destroy_shader_module(module.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::CommandEncoderId>> Global<F> {
|
||||
pub fn device_create_command_encoder<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
_desc: &wgt::CommandEncoderDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::CommandEncoderId>,
|
||||
) -> id::CommandEncoderId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1345,17 +1329,13 @@ impl<F: IdentityFilter<id::CommandEncoderId>> Global<F> {
|
||||
.suspected_resources.extend(&device.temp_suspected);
|
||||
device.com_allocator.discard(comb);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::CommandBufferId>> Global<F> {
|
||||
pub fn command_buffer_destroy<B: GfxBackend>(
|
||||
&self, command_buffer_id: id::CommandBufferId
|
||||
) {
|
||||
self.command_encoder_destroy::<B>(command_buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: AllIdentityFilter + IdentityFilter<id::CommandBufferId>> Global<F> {
|
||||
pub fn queue_submit<B: GfxBackend>(
|
||||
&self,
|
||||
queue_id: id::QueueId,
|
||||
@@ -1504,14 +1484,12 @@ impl<F: AllIdentityFilter + IdentityFilter<id::CommandBufferId>> Global<F> {
|
||||
|
||||
fire_map_callbacks(callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::RenderPipelineId>> Global<F> {
|
||||
pub fn device_create_render_pipeline<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &pipeline::RenderPipelineDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::RenderPipelineId>,
|
||||
) -> id::RenderPipelineId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1780,14 +1758,12 @@ impl<F: IdentityFilter<id::RenderPipelineId>> Global<F> {
|
||||
//TODO: track usage by GPU
|
||||
hub.render_pipelines.unregister(render_pipeline_id, &mut token);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::ComputePipelineId>> Global<F> {
|
||||
pub fn device_create_compute_pipeline<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &pipeline::ComputePipelineDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, id::ComputePipelineId>,
|
||||
) -> id::ComputePipelineId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1848,43 +1824,41 @@ impl<F: IdentityFilter<id::ComputePipelineId>> Global<F> {
|
||||
//TODO: track usage by GPU
|
||||
hub.compute_pipelines.unregister(compute_pipeline_id, &mut token);
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_swap_chain_descriptor(
|
||||
config: &mut hal::window::SwapchainConfig,
|
||||
caps: &hal::window::SurfaceCapabilities,
|
||||
) {
|
||||
let width = config.extent.width;
|
||||
let height = config.extent.height;
|
||||
if width < caps.extents.start().width
|
||||
|| width > caps.extents.end().width
|
||||
|| height < caps.extents.start().height
|
||||
|| height > caps.extents.end().height
|
||||
{
|
||||
log::warn!(
|
||||
"Requested size {}x{} is outside of the supported range: {:?}",
|
||||
width,
|
||||
height,
|
||||
caps.extents
|
||||
);
|
||||
}
|
||||
if !caps.present_modes.contains(config.present_mode) {
|
||||
log::warn!(
|
||||
"Surface does not support present mode: {:?}, falling back to {:?}",
|
||||
config.present_mode,
|
||||
hal::window::PresentMode::FIFO
|
||||
);
|
||||
config.present_mode = hal::window::PresentMode::FIFO;
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<id::SwapChainId>> Global<F> {
|
||||
pub fn device_create_swap_chain<B: GfxBackend>(
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
surface_id: id::SurfaceId,
|
||||
desc: &wgt::SwapChainDescriptor,
|
||||
) -> id::SwapChainId {
|
||||
fn validate_swap_chain_descriptor(
|
||||
config: &mut hal::window::SwapchainConfig,
|
||||
caps: &hal::window::SurfaceCapabilities,
|
||||
) {
|
||||
let width = config.extent.width;
|
||||
let height = config.extent.height;
|
||||
if width < caps.extents.start().width
|
||||
|| width > caps.extents.end().width
|
||||
|| height < caps.extents.start().height
|
||||
|| height > caps.extents.end().height
|
||||
{
|
||||
log::warn!(
|
||||
"Requested size {}x{} is outside of the supported range: {:?}",
|
||||
width,
|
||||
height,
|
||||
caps.extents
|
||||
);
|
||||
}
|
||||
if !caps.present_modes.contains(config.present_mode) {
|
||||
log::warn!(
|
||||
"Surface does not support present mode: {:?}, falling back to {:?}",
|
||||
config.present_mode,
|
||||
hal::window::PresentMode::FIFO
|
||||
);
|
||||
config.present_mode = hal::window::PresentMode::FIFO;
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("creating swap chain {:?}", desc);
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1945,9 +1919,7 @@ impl<F: IdentityFilter<id::SwapChainId>> Global<F> {
|
||||
swap_chain_guard.insert(sc_id, swap_chain);
|
||||
sc_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: AllIdentityFilter> Global<F> {
|
||||
pub fn device_poll<B: GfxBackend>(&self, device_id: id::DeviceId, force_wait: bool) {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -1990,9 +1962,7 @@ impl<F: AllIdentityFilter> Global<F> {
|
||||
|
||||
fire_map_callbacks(callbacks);
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: AllIdentityFilter + IdentityFilter<id::DeviceId>> Global<F> {
|
||||
pub fn device_destroy<B: GfxBackend>(&self, device_id: id::DeviceId) {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -2001,9 +1971,7 @@ impl<F: AllIdentityFilter + IdentityFilter<id::DeviceId>> Global<F> {
|
||||
drop(token);
|
||||
device.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Global<F> {
|
||||
pub fn buffer_map_async<B: GfxBackend>(
|
||||
&self,
|
||||
buffer_id: id::BufferId,
|
||||
|
||||
+101
-65
@@ -71,7 +71,7 @@ impl IdentityManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn free<I: TypedId>(&mut self, id: I) {
|
||||
pub fn free<I: TypedId + Debug>(&mut self, id: I) {
|
||||
let (index, epoch, _backend) = id.unzip();
|
||||
// avoid doing this check in release
|
||||
if cfg!(debug_assertions) {
|
||||
@@ -252,22 +252,13 @@ impl<'a, T> Drop for Token<'a, T> {
|
||||
}
|
||||
|
||||
|
||||
pub trait IdentityFilter<I>: Debug {
|
||||
pub trait IdentityHandler<I>: Debug {
|
||||
type Input: Clone + Debug;
|
||||
fn process(&self, id: Self::Input, backend: Backend) -> I;
|
||||
fn free(&self, id: I);
|
||||
}
|
||||
|
||||
impl<I: TypedId + Clone + Debug> IdentityFilter<I> for () {
|
||||
type Input = I;
|
||||
fn process(&self, id: I, _backend: Backend) -> I {
|
||||
//debug_assert_eq!(id.unzip().2, backend);
|
||||
id
|
||||
}
|
||||
fn free(&self, _id: I) {}
|
||||
}
|
||||
|
||||
impl<I: TypedId + Debug> IdentityFilter<I> for Mutex<IdentityManager> {
|
||||
impl<I: TypedId + Debug> IdentityHandler<I> for Mutex<IdentityManager> {
|
||||
type Input = PhantomData<I>;
|
||||
fn process(&self, _id: Self::Input, backend: Backend) -> I {
|
||||
self.lock().alloc(backend)
|
||||
@@ -277,32 +268,55 @@ impl<I: TypedId + Debug> IdentityFilter<I> for Mutex<IdentityManager> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Compound trait for all the things a device cares about
|
||||
/// for the matter of destruction/cleanup.
|
||||
pub trait AllIdentityFilter:
|
||||
IdentityFilter<BufferId>
|
||||
+ IdentityFilter<TextureId>
|
||||
+ IdentityFilter<TextureViewId>
|
||||
+ IdentityFilter<BindGroupId>
|
||||
+ IdentityFilter<SamplerId>
|
||||
{
|
||||
pub trait IdentityHandlerFactory<I> {
|
||||
type Filter: IdentityHandler<I>;
|
||||
fn spawn(&self) -> Self::Filter;
|
||||
}
|
||||
|
||||
impl AllIdentityFilter for Mutex<IdentityManager> {}
|
||||
impl AllIdentityFilter for () {}
|
||||
#[derive(Debug)]
|
||||
pub struct IdentityManagerFactory;
|
||||
|
||||
impl<I: TypedId + Debug> IdentityHandlerFactory<I> for IdentityManagerFactory {
|
||||
type Filter = Mutex<IdentityManager>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
Mutex::new(IdentityManager::default())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GlobalIdentityHandlerFactory:
|
||||
IdentityHandlerFactory<AdapterId> +
|
||||
IdentityHandlerFactory<DeviceId> +
|
||||
IdentityHandlerFactory<SwapChainId> +
|
||||
IdentityHandlerFactory<PipelineLayoutId> +
|
||||
IdentityHandlerFactory<ShaderModuleId> +
|
||||
IdentityHandlerFactory<BindGroupLayoutId> +
|
||||
IdentityHandlerFactory<BindGroupId> +
|
||||
IdentityHandlerFactory<CommandBufferId> +
|
||||
IdentityHandlerFactory<RenderPipelineId> +
|
||||
IdentityHandlerFactory<ComputePipelineId> +
|
||||
IdentityHandlerFactory<BufferId> +
|
||||
IdentityHandlerFactory<TextureId> +
|
||||
IdentityHandlerFactory<TextureViewId> +
|
||||
IdentityHandlerFactory<SamplerId> +
|
||||
IdentityHandlerFactory<SurfaceId>
|
||||
{}
|
||||
|
||||
impl GlobalIdentityHandlerFactory for IdentityManagerFactory {}
|
||||
|
||||
pub type Input<G, I> = <<G as IdentityHandlerFactory<I>>::Filter as IdentityHandler<I>>::Input;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Registry<T, I: TypedId, F> {
|
||||
pub(crate) identity: F,
|
||||
pub struct Registry<T, I: TypedId, F: IdentityHandlerFactory<I>> {
|
||||
identity: F::Filter,
|
||||
data: RwLock<Storage<T, I>>,
|
||||
backend: Backend,
|
||||
}
|
||||
|
||||
impl<T, I: TypedId, F: Default> Registry<T, I, F> {
|
||||
fn new(backend: Backend) -> Self {
|
||||
impl<T, I: TypedId, F: IdentityHandlerFactory<I>> Registry<T, I, F> {
|
||||
fn new(backend: Backend, factory: &F) -> Self {
|
||||
Registry {
|
||||
identity: F::default(),
|
||||
identity: factory.spawn(),
|
||||
data: RwLock::new(Storage {
|
||||
map: VecMap::new(),
|
||||
_phantom: PhantomData,
|
||||
@@ -312,7 +326,7 @@ impl<T, I: TypedId, F: Default> Registry<T, I, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, I: TypedId + Copy, F> Registry<T, I, F> {
|
||||
impl<T, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I, F> {
|
||||
pub fn register<A: Access<T>>(&self, id: I, value: T, _token: &mut Token<A>) {
|
||||
debug_assert_eq!(id.unzip().2, self.backend);
|
||||
let old = self.data.write().insert(id, value);
|
||||
@@ -334,10 +348,10 @@ impl<T, I: TypedId + Copy, F> Registry<T, I, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, I: TypedId + Copy, F: IdentityFilter<I>> Registry<T, I, F> {
|
||||
impl<T, I: TypedId + Copy, F: IdentityHandlerFactory<I>> Registry<T, I, F> {
|
||||
pub fn register_identity<A: Access<T>>(
|
||||
&self,
|
||||
id_in: F::Input,
|
||||
id_in: <F::Filter as IdentityHandler<I>>::Input,
|
||||
value: T,
|
||||
token: &mut Token<A>,
|
||||
) -> I {
|
||||
@@ -356,10 +370,14 @@ impl<T, I: TypedId + Copy, F: IdentityFilter<I>> Registry<T, I, F> {
|
||||
self.identity.free(id);
|
||||
(value, Token::new())
|
||||
}
|
||||
|
||||
pub fn free_id(&self, id: I) {
|
||||
self.identity.free(id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Hub<B: hal::Backend, F> {
|
||||
pub struct Hub<B: hal::Backend, F: GlobalIdentityHandlerFactory> {
|
||||
pub adapters: Registry<Adapter<B>, AdapterId, F>,
|
||||
pub devices: Registry<Device<B>, DeviceId, F>,
|
||||
pub swap_chains: Registry<SwapChain<B>, SwapChainId, F>,
|
||||
@@ -376,28 +394,28 @@ pub struct Hub<B: hal::Backend, F> {
|
||||
pub samplers: Registry<Sampler<B>, SamplerId, F>,
|
||||
}
|
||||
|
||||
impl<B: GfxBackend, F: Default> Default for Hub<B, F> {
|
||||
fn default() -> Self {
|
||||
impl<B: GfxBackend, F: GlobalIdentityHandlerFactory> Hub<B, F> {
|
||||
fn new(factory: &F) -> Self {
|
||||
Hub {
|
||||
adapters: Registry::new(B::VARIANT),
|
||||
devices: Registry::new(B::VARIANT),
|
||||
swap_chains: Registry::new(B::VARIANT),
|
||||
pipeline_layouts: Registry::new(B::VARIANT),
|
||||
shader_modules: Registry::new(B::VARIANT),
|
||||
bind_group_layouts: Registry::new(B::VARIANT),
|
||||
bind_groups: Registry::new(B::VARIANT),
|
||||
command_buffers: Registry::new(B::VARIANT),
|
||||
render_pipelines: Registry::new(B::VARIANT),
|
||||
compute_pipelines: Registry::new(B::VARIANT),
|
||||
buffers: Registry::new(B::VARIANT),
|
||||
textures: Registry::new(B::VARIANT),
|
||||
texture_views: Registry::new(B::VARIANT),
|
||||
samplers: Registry::new(B::VARIANT),
|
||||
adapters: Registry::new(B::VARIANT, factory),
|
||||
devices: Registry::new(B::VARIANT, factory),
|
||||
swap_chains: Registry::new(B::VARIANT, factory),
|
||||
pipeline_layouts: Registry::new(B::VARIANT, factory),
|
||||
shader_modules: Registry::new(B::VARIANT, factory),
|
||||
bind_group_layouts: Registry::new(B::VARIANT, factory),
|
||||
bind_groups: Registry::new(B::VARIANT, factory),
|
||||
command_buffers: Registry::new(B::VARIANT, factory),
|
||||
render_pipelines: Registry::new(B::VARIANT, factory),
|
||||
compute_pipelines: Registry::new(B::VARIANT, factory),
|
||||
buffers: Registry::new(B::VARIANT, factory),
|
||||
textures: Registry::new(B::VARIANT, factory),
|
||||
texture_views: Registry::new(B::VARIANT, factory),
|
||||
samplers: Registry::new(B::VARIANT, factory),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: hal::Backend, F> Drop for Hub<B, F> {
|
||||
impl<B: hal::Backend, F: GlobalIdentityHandlerFactory> Drop for Hub<B, F> {
|
||||
fn drop(&mut self) {
|
||||
use crate::resource::TextureViewInner;
|
||||
use hal::device::Device as _;
|
||||
@@ -482,8 +500,8 @@ impl<B: hal::Backend, F> Drop for Hub<B, F> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Hubs<F> {
|
||||
#[derive(Debug)]
|
||||
pub struct Hubs<F: GlobalIdentityHandlerFactory> {
|
||||
#[cfg(any(
|
||||
not(any(target_os = "ios", target_os = "macos")),
|
||||
feature = "gfx-backend-vulkan"
|
||||
@@ -497,19 +515,37 @@ pub struct Hubs<F> {
|
||||
dx11: Hub<backend::Dx11, F>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Global<F> {
|
||||
pub instance: Instance,
|
||||
pub surfaces: Registry<Surface, SurfaceId, F>,
|
||||
hubs: Hubs<F>,
|
||||
impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
|
||||
fn new(factory: &F) -> Self {
|
||||
Hubs {
|
||||
#[cfg(any(
|
||||
not(any(target_os = "ios", target_os = "macos")),
|
||||
feature = "gfx-backend-vulkan"
|
||||
))]
|
||||
vulkan: Hub::new(factory),
|
||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
||||
metal: Hub::new(factory),
|
||||
#[cfg(windows)]
|
||||
dx12: Hub::new(factory),
|
||||
#[cfg(windows)]
|
||||
dx11: Hub::new(factory),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Default> Global<F> {
|
||||
pub fn new(name: &str) -> Self {
|
||||
#[derive(Debug)]
|
||||
pub struct Global<G: GlobalIdentityHandlerFactory> {
|
||||
pub instance: Instance,
|
||||
pub surfaces: Registry<Surface, SurfaceId, G>,
|
||||
hubs: Hubs<G>,
|
||||
}
|
||||
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn new(name: &str, factory: G) -> Self {
|
||||
Global {
|
||||
instance: Instance::new(name, 1),
|
||||
surfaces: Registry::new(Backend::Empty),
|
||||
hubs: Hubs::default(),
|
||||
surfaces: Registry::new(Backend::Empty, &factory),
|
||||
hubs: Hubs::new(&factory),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,7 +565,7 @@ impl<F: Default> Global<F> {
|
||||
|
||||
pub trait GfxBackend: hal::Backend {
|
||||
const VARIANT: Backend;
|
||||
fn hub<F>(global: &Global<F>) -> &Hub<Self, F>;
|
||||
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G>;
|
||||
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface;
|
||||
}
|
||||
|
||||
@@ -539,7 +575,7 @@ pub trait GfxBackend: hal::Backend {
|
||||
))]
|
||||
impl GfxBackend for backend::Vulkan {
|
||||
const VARIANT: Backend = Backend::Vulkan;
|
||||
fn hub<F>(global: &Global<F>) -> &Hub<Self, F> {
|
||||
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G> {
|
||||
&global.hubs.vulkan
|
||||
}
|
||||
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface {
|
||||
@@ -550,7 +586,7 @@ impl GfxBackend for backend::Vulkan {
|
||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
||||
impl GfxBackend for backend::Metal {
|
||||
const VARIANT: Backend = Backend::Metal;
|
||||
fn hub<F>(global: &Global<F>) -> &Hub<Self, F> {
|
||||
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G> {
|
||||
&global.hubs.metal
|
||||
}
|
||||
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface {
|
||||
@@ -561,7 +597,7 @@ impl GfxBackend for backend::Metal {
|
||||
#[cfg(windows)]
|
||||
impl GfxBackend for backend::Dx12 {
|
||||
const VARIANT: Backend = Backend::Dx12;
|
||||
fn hub<F>(global: &Global<F>) -> &Hub<Self, F> {
|
||||
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G> {
|
||||
&global.hubs.dx12
|
||||
}
|
||||
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface {
|
||||
@@ -572,7 +608,7 @@ impl GfxBackend for backend::Dx12 {
|
||||
#[cfg(windows)]
|
||||
impl GfxBackend for backend::Dx11 {
|
||||
const VARIANT: Backend = Backend::Dx11;
|
||||
fn hub<F>(global: &Global<F>) -> &Hub<Self, F> {
|
||||
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G> {
|
||||
&global.hubs.dx11
|
||||
}
|
||||
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use crate::{
|
||||
backend,
|
||||
device::{Device, BIND_BUFFER_ALIGNMENT},
|
||||
hub::{GfxBackend, Global, IdentityFilter, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
|
||||
id::{AdapterId, DeviceId},
|
||||
power,
|
||||
};
|
||||
@@ -184,8 +184,8 @@ impl<I: Clone> AdapterInputs<'_, I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<AdapterId>> Global<F> {
|
||||
pub fn enumerate_adapters(&self, inputs: AdapterInputs<F::Input>) -> Vec<AdapterId> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn enumerate_adapters(&self, inputs: AdapterInputs<Input<G, AdapterId>>) -> Vec<AdapterId> {
|
||||
let instance = &self.instance;
|
||||
let mut token = Token::root();
|
||||
let mut adapters = Vec::new();
|
||||
@@ -258,7 +258,7 @@ impl<F: IdentityFilter<AdapterId>> Global<F> {
|
||||
pub fn pick_adapter(
|
||||
&self,
|
||||
desc: &RequestAdapterOptions,
|
||||
inputs: AdapterInputs<F::Input>,
|
||||
inputs: AdapterInputs<Input<G, AdapterId>>,
|
||||
) -> Option<AdapterId> {
|
||||
let instance = &self.instance;
|
||||
let mut device_types = Vec::new();
|
||||
@@ -432,12 +432,12 @@ impl<F: IdentityFilter<AdapterId>> Global<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<DeviceId>> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn adapter_request_device<B: GfxBackend>(
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
desc: &DeviceDescriptor,
|
||||
id_in: F::Input,
|
||||
id_in: Input<G, DeviceId>,
|
||||
) -> DeviceId {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
use crate::{
|
||||
conv,
|
||||
hub::{GfxBackend, Global, IdentityFilter, Token},
|
||||
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
|
||||
id::{DeviceId, SwapChainId, TextureViewId},
|
||||
resource,
|
||||
Features,
|
||||
@@ -93,11 +93,11 @@ pub enum SwapChainGetNextTextureError {
|
||||
GpuProcessingTimeout,
|
||||
}
|
||||
|
||||
impl<F: IdentityFilter<TextureViewId>> Global<F> {
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn swap_chain_get_next_texture<B: GfxBackend>(
|
||||
&self,
|
||||
swap_chain_id: SwapChainId,
|
||||
view_id_in: F::Input,
|
||||
view_id_in: Input<G, TextureViewId>,
|
||||
) -> Result<SwapChainOutput, SwapChainGetNextTextureError> {
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
@@ -10,8 +10,8 @@ mod device;
|
||||
pub use self::command::*;
|
||||
pub use self::device::*;
|
||||
|
||||
type Global = core::hub::Global<parking_lot::Mutex<core::hub::IdentityManager>>;
|
||||
type Global = core::hub::Global<core::hub::IdentityManagerFactory>;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref GLOBAL: Arc<Global> = Arc::new(Global::new("wgpu"));
|
||||
static ref GLOBAL: Arc<Global> = Arc::new(Global::new("wgpu", core::hub::IdentityManagerFactory));
|
||||
}
|
||||
@@ -9,7 +9,6 @@ autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated usi
|
||||
*/
|
||||
|
||||
typedef void WGPUEmpty;
|
||||
typedef struct WGPUGlobal WGPUGlobal;
|
||||
"""
|
||||
include_version = true
|
||||
braces = "SameLine"
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use core::id;
|
||||
|
||||
|
||||
pub type FactoryParam = *mut std::ffi::c_void;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IdentityRecycler<I> {
|
||||
fun: extern "C" fn(I, FactoryParam),
|
||||
param: FactoryParam,
|
||||
kind: &'static str,
|
||||
}
|
||||
|
||||
impl<I: id::TypedId + Clone + std::fmt::Debug> core::hub::IdentityHandler<I> for IdentityRecycler<I> {
|
||||
type Input = I;
|
||||
fn process(&self, id: I, _backend: wgt::Backend) -> I {
|
||||
log::debug!("process {} {:?}", self.kind, id);
|
||||
//debug_assert_eq!(id.unzip().2, backend);
|
||||
id
|
||||
}
|
||||
fn free(&self, id: I) {
|
||||
log::debug!("free {} {:?}", self.kind, id);
|
||||
(self.fun)(id, self.param);
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct IdentityRecyclerFactory {
|
||||
param: FactoryParam,
|
||||
free_adapter: extern "C" fn(id::AdapterId, FactoryParam),
|
||||
free_device: extern "C" fn(id::DeviceId, FactoryParam),
|
||||
free_swap_chain: extern "C" fn(id::SwapChainId, FactoryParam),
|
||||
free_pipeline_layout: extern "C" fn(id::PipelineLayoutId, FactoryParam),
|
||||
free_shader_module: extern "C" fn(id::ShaderModuleId, FactoryParam),
|
||||
free_bind_group_layout: extern "C" fn(id::BindGroupLayoutId, FactoryParam),
|
||||
free_bind_group: extern "C" fn(id::BindGroupId, FactoryParam),
|
||||
free_command_buffer: extern "C" fn(id::CommandBufferId, FactoryParam),
|
||||
free_render_pipeline: extern "C" fn(id::RenderPipelineId, FactoryParam),
|
||||
free_compute_pipeline: extern "C" fn(id::ComputePipelineId, FactoryParam),
|
||||
free_buffer: extern "C" fn(id::BufferId, FactoryParam),
|
||||
free_texture: extern "C" fn(id::TextureId, FactoryParam),
|
||||
free_texture_view: extern "C" fn(id::TextureViewId, FactoryParam),
|
||||
free_sampler: extern "C" fn(id::SamplerId, FactoryParam),
|
||||
free_surface: extern "C" fn(id::SurfaceId, FactoryParam),
|
||||
}
|
||||
|
||||
impl core::hub::IdentityHandlerFactory<id::AdapterId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::AdapterId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_adapter,
|
||||
param: self.param,
|
||||
kind: "adapter",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::DeviceId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::DeviceId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_device,
|
||||
param: self.param,
|
||||
kind: "device",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::SwapChainId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::SwapChainId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_swap_chain,
|
||||
param: self.param,
|
||||
kind: "swap_chain",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::PipelineLayoutId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::PipelineLayoutId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_pipeline_layout,
|
||||
param: self.param,
|
||||
kind: "pipeline_layout",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::ShaderModuleId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::ShaderModuleId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_shader_module,
|
||||
param: self.param,
|
||||
kind: "shader_module",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::BindGroupLayoutId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::BindGroupLayoutId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_bind_group_layout,
|
||||
param: self.param,
|
||||
kind: "bind_group_layout",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::BindGroupId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::BindGroupId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_bind_group,
|
||||
param: self.param,
|
||||
kind: "bind_group",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::CommandBufferId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::CommandBufferId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_command_buffer,
|
||||
param: self.param,
|
||||
kind: "command_buffer",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::RenderPipelineId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::RenderPipelineId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_render_pipeline,
|
||||
param: self.param,
|
||||
kind: "render_pipeline",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::ComputePipelineId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::ComputePipelineId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_compute_pipeline,
|
||||
param: self.param,
|
||||
kind: "compute_pipeline",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::BufferId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::BufferId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_buffer,
|
||||
param: self.param,
|
||||
kind: "buffer",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::TextureId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::TextureId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_texture,
|
||||
param: self.param,
|
||||
kind: "texture",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::TextureViewId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::TextureViewId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_texture_view,
|
||||
param: self.param,
|
||||
kind: "texture_view",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::SamplerId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::SamplerId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_sampler,
|
||||
param: self.param,
|
||||
kind: "sampler",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::hub::IdentityHandlerFactory<id::SurfaceId> for IdentityRecyclerFactory {
|
||||
type Filter = IdentityRecycler<id::SurfaceId>;
|
||||
fn spawn(&self) -> Self::Filter {
|
||||
IdentityRecycler {
|
||||
fun: self.free_surface,
|
||||
param: self.param,
|
||||
kind: "surface",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl core::hub::GlobalIdentityHandlerFactory for IdentityRecyclerFactory {}
|
||||
+8
-14
@@ -18,6 +18,7 @@ use parking_lot::Mutex;
|
||||
|
||||
use std::{ptr, slice};
|
||||
|
||||
pub mod identity;
|
||||
pub mod server;
|
||||
|
||||
|
||||
@@ -124,21 +125,14 @@ pub unsafe extern "C" fn wgpu_client_make_adapter_ids(
|
||||
id_length - ids.len()
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe as there is no guarantee that the given pointer is
|
||||
/// valid for `id_length` elements.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_client_kill_adapter_ids(
|
||||
client: &Client,
|
||||
ids: *const id::AdapterId,
|
||||
id_length: usize,
|
||||
) {
|
||||
let mut identity = client.identities.lock();
|
||||
let ids = slice::from_raw_parts(ids, id_length);
|
||||
for &id in ids {
|
||||
identity.select(id.backend()).adapters.free(id)
|
||||
}
|
||||
pub extern "C" fn wgpu_client_kill_adapter_id(client: &Client, id: id::AdapterId) {
|
||||
client
|
||||
.identities
|
||||
.lock()
|
||||
.select(id.backend())
|
||||
.adapters
|
||||
.free(id)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::identity::IdentityRecyclerFactory;
|
||||
|
||||
use core::{gfx_select, id};
|
||||
|
||||
use std::slice;
|
||||
|
||||
pub type Global = core::hub::Global<()>;
|
||||
|
||||
pub type Global = core::hub::Global<IdentityRecyclerFactory>;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_server_new() -> *mut Global {
|
||||
pub extern "C" fn wgpu_server_new(factory: IdentityRecyclerFactory) -> *mut Global {
|
||||
log::info!("Initializing WGPU server");
|
||||
Box::into_raw(Box::new(Global::new("wgpu")))
|
||||
Box::into_raw(Box::new(Global::new("wgpu", factory)))
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
|
||||
Reference in new issue
Block a user