Remove G parameter in Global<G> and generic IdentityHandlerFactory (#5159)

This commit is contained in:
John-John Tedro 2024-01-29 15:37:57 +01:00 committed by GitHub
parent 6e020a079e
commit 950d765a4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
34 changed files with 299 additions and 452 deletions

View File

@ -208,7 +208,7 @@ pub fn op_webgpu_create_bind_group_layout(
gfx_put!(device => instance.device_create_bind_group_layout( gfx_put!(device => instance.device_create_bind_group_layout(
device, device,
&descriptor, &descriptor,
() None
) => state, WebGpuBindGroupLayout) ) => state, WebGpuBindGroupLayout)
} }
@ -243,7 +243,7 @@ pub fn op_webgpu_create_pipeline_layout(
gfx_put!(device => instance.device_create_pipeline_layout( gfx_put!(device => instance.device_create_pipeline_layout(
device, device,
&descriptor, &descriptor,
() None
) => state, super::pipeline::WebGpuPipelineLayout) ) => state, super::pipeline::WebGpuPipelineLayout)
} }
@ -322,6 +322,6 @@ pub fn op_webgpu_create_bind_group(
gfx_put!(device => instance.device_create_bind_group( gfx_put!(device => instance.device_create_bind_group(
device, device,
&descriptor, &descriptor,
() None
) => state, WebGpuBindGroup) ) => state, WebGpuBindGroup)
} }

View File

@ -64,7 +64,7 @@ pub fn op_webgpu_create_buffer(
gfx_put!(device => instance.device_create_buffer( gfx_put!(device => instance.device_create_buffer(
device, device,
&descriptor, &descriptor,
() None
) => state, WebGpuBuffer) ) => state, WebGpuBuffer)
} }

View File

@ -113,7 +113,7 @@ pub fn op_webgpu_render_bundle_encoder_finish(
&wgpu_core::command::RenderBundleDescriptor { &wgpu_core::command::RenderBundleDescriptor {
label: Some(label), label: Some(label),
}, },
() None
) => state, WebGpuRenderBundle) ) => state, WebGpuRenderBundle)
} }

View File

@ -61,7 +61,7 @@ pub fn op_webgpu_create_command_encoder(
gfx_put!(device => instance.device_create_command_encoder( gfx_put!(device => instance.device_create_command_encoder(
device, device,
&descriptor, &descriptor,
() None
) => state, WebGpuCommandEncoder) ) => state, WebGpuCommandEncoder)
} }

View File

@ -96,8 +96,7 @@ fn check_unstable(state: &OpState, api_name: &str) {
} }
} }
pub type Instance = pub type Instance = std::sync::Arc<wgpu_core::global::Global>;
std::sync::Arc<wgpu_core::global::Global<wgpu_core::identity::IdentityManagerFactory>>;
struct WebGpuAdapter(Instance, wgpu_core::id::AdapterId); struct WebGpuAdapter(Instance, wgpu_core::id::AdapterId);
impl Resource for WebGpuAdapter { impl Resource for WebGpuAdapter {
@ -410,7 +409,6 @@ pub async fn op_webgpu_request_adapter(
} else { } else {
state.put(std::sync::Arc::new(wgpu_core::global::Global::new( state.put(std::sync::Arc::new(wgpu_core::global::Global::new(
"webgpu", "webgpu",
wgpu_core::identity::IdentityManagerFactory,
wgpu_types::InstanceDescriptor { wgpu_types::InstanceDescriptor {
backends, backends,
flags: wgpu_types::InstanceFlags::from_build_config(), flags: wgpu_types::InstanceFlags::from_build_config(),
@ -428,7 +426,7 @@ pub async fn op_webgpu_request_adapter(
}; };
let res = instance.request_adapter( let res = instance.request_adapter(
&descriptor, &descriptor,
wgpu_core::instance::AdapterInputs::Mask(backends, |_| ()), wgpu_core::instance::AdapterInputs::Mask(backends, |_| None),
); );
let adapter = match res { let adapter = match res {
@ -675,8 +673,8 @@ pub async fn op_webgpu_request_device(
adapter, adapter,
&descriptor, &descriptor,
std::env::var("DENO_WEBGPU_TRACE").ok().as_ref().map(std::path::Path::new), std::env::var("DENO_WEBGPU_TRACE").ok().as_ref().map(std::path::Path::new),
(), None,
() None
)); ));
if let Some(err) = maybe_err { if let Some(err) = maybe_err {
return Err(DomExceptionOperationError::new(&err.to_string()).into()); return Err(DomExceptionOperationError::new(&err.to_string()).into());
@ -773,6 +771,6 @@ pub fn op_webgpu_create_query_set(
gfx_put!(device => instance.device_create_query_set( gfx_put!(device => instance.device_create_query_set(
device, device,
&descriptor, &descriptor,
() None
) => state, WebGpuQuerySet) ) => state, WebGpuQuerySet)
} }

View File

@ -118,8 +118,8 @@ pub fn op_webgpu_create_compute_pipeline(
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None, GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => { GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
Some(wgpu_core::device::ImplicitPipelineIds { Some(wgpu_core::device::ImplicitPipelineIds {
root_id: (), root_id: None,
group_ids: &[(); MAX_BIND_GROUPS], group_ids: &[None; MAX_BIND_GROUPS],
}) })
} }
}; };
@ -127,7 +127,7 @@ pub fn op_webgpu_create_compute_pipeline(
let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline( let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline(
device, device,
&descriptor, &descriptor,
(), None,
implicit_pipelines implicit_pipelines
)); ));
@ -159,7 +159,7 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
.get::<WebGpuComputePipeline>(compute_pipeline_rid)?; .get::<WebGpuComputePipeline>(compute_pipeline_rid)?;
let compute_pipeline = compute_pipeline_resource.1; let compute_pipeline = compute_pipeline_resource.1;
let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, ())); let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, None));
let label = let label =
gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout)); gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout));
@ -392,8 +392,8 @@ pub fn op_webgpu_create_render_pipeline(
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None, GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => { GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
Some(wgpu_core::device::ImplicitPipelineIds { Some(wgpu_core::device::ImplicitPipelineIds {
root_id: (), root_id: None,
group_ids: &[(); MAX_BIND_GROUPS], group_ids: &[None; MAX_BIND_GROUPS],
}) })
} }
}; };
@ -401,7 +401,7 @@ pub fn op_webgpu_create_render_pipeline(
let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline( let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline(
device, device,
&descriptor, &descriptor,
(), None,
implicit_pipelines implicit_pipelines
)); ));
@ -425,7 +425,7 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
.get::<WebGpuRenderPipeline>(render_pipeline_rid)?; .get::<WebGpuRenderPipeline>(render_pipeline_rid)?;
let render_pipeline = render_pipeline_resource.1; let render_pipeline = render_pipeline_resource.1;
let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, ())); let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, None));
let label = let label =
gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout)); gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout));

View File

@ -74,6 +74,6 @@ pub fn op_webgpu_create_sampler(
gfx_put!(device => instance.device_create_sampler( gfx_put!(device => instance.device_create_sampler(
device, device,
&descriptor, &descriptor,
() None
) => state, WebGpuSampler) ) => state, WebGpuSampler)
} }

View File

@ -49,6 +49,6 @@ pub fn op_webgpu_create_shader_module(
device, device,
&descriptor, &descriptor,
source, source,
() None
) => state, WebGpuShaderModule) ) => state, WebGpuShaderModule)
} }

View File

@ -75,6 +75,7 @@ pub fn op_webgpu_surface_configure(
present_mode: args.present_mode.unwrap_or_default(), present_mode: args.present_mode.unwrap_or_default(),
alpha_mode: args.alpha_mode, alpha_mode: args.alpha_mode,
view_formats: args.view_formats, view_formats: args.view_formats,
desired_maximum_frame_latency: 2,
}; };
let err = gfx_select!(device => instance.surface_configure(surface, device, &conf)); let err = gfx_select!(device => instance.surface_configure(surface, device, &conf));
@ -97,7 +98,7 @@ pub fn op_webgpu_surface_get_current_texture(
let surface_resource = state.resource_table.get::<WebGpuSurface>(surface_rid)?; let surface_resource = state.resource_table.get::<WebGpuSurface>(surface_rid)?;
let surface = surface_resource.1; let surface = surface_resource.1;
let output = gfx_select!(device => instance.surface_get_current_texture(surface, ()))?; let output = gfx_select!(device => instance.surface_get_current_texture(surface, None))?;
match output.status { match output.status {
SurfaceStatus::Good | SurfaceStatus::Suboptimal => { SurfaceStatus::Good | SurfaceStatus::Suboptimal => {

View File

@ -83,7 +83,7 @@ pub fn op_webgpu_create_texture(
let (val, maybe_err) = gfx_select!(device => instance.device_create_texture( let (val, maybe_err) = gfx_select!(device => instance.device_create_texture(
device, device,
&descriptor, &descriptor,
() None
)); ));
let rid = state.resource_table.add(WebGpuTexture { let rid = state.resource_table.add(WebGpuTexture {
@ -128,6 +128,6 @@ pub fn op_webgpu_create_texture_view(
gfx_put!(texture => instance.texture_create_view( gfx_put!(texture => instance.texture_create_view(
texture, texture,
&descriptor, &descriptor,
() None
) => state, WebGpuTextureView) ) => state, WebGpuTextureView)
} }

View File

@ -3,7 +3,7 @@
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
fn main() { fn main() {
use player::{GlobalPlay as _, IdentityPassThroughFactory}; use player::GlobalPlay as _;
use wgc::{device::trace, gfx_select}; use wgc::{device::trace, gfx_select};
use std::{ use std::{
@ -49,11 +49,7 @@ fn main() {
.build(&event_loop) .build(&event_loop)
.unwrap(); .unwrap();
let global = wgc::global::Global::new( let global = wgc::global::Global::new("player", wgt::InstanceDescriptor::default());
"player",
IdentityPassThroughFactory,
wgt::InstanceDescriptor::default(),
);
let mut command_buffer_id_manager = wgc::identity::IdentityManager::new(); let mut command_buffer_id_manager = wgc::identity::IdentityManager::new();
#[cfg(feature = "winit")] #[cfg(feature = "winit")]
@ -61,7 +57,7 @@ fn main() {
global.instance_create_surface( global.instance_create_surface(
window.display_handle().unwrap().into(), window.display_handle().unwrap().into(),
window.window_handle().unwrap().into(), window.window_handle().unwrap().into(),
wgc::id::Id::zip(0, 1, wgt::Backend::Empty), Some(wgc::id::Id::zip(0, 1, wgt::Backend::Empty)),
) )
} }
.unwrap(); .unwrap();
@ -79,9 +75,7 @@ fn main() {
#[cfg(not(feature = "winit"))] #[cfg(not(feature = "winit"))]
compatible_surface: None, compatible_surface: None,
}, },
wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)], |id| { wgc::instance::AdapterInputs::IdSet(&[wgc::id::AdapterId::zip(0, 0, backend)]),
id.backend()
}),
) )
.expect("Unable to find an adapter for selected backend"); .expect("Unable to find an adapter for selected backend");
@ -92,8 +86,8 @@ fn main() {
adapter, adapter,
&desc, &desc,
None, None,
id, Some(id),
id.transmute() Some(id.transmute())
)); ));
if let Some(e) = error { if let Some(e) = error {
panic!("{:?}", e); panic!("{:?}", e);

View File

@ -12,21 +12,6 @@ use wgc::device::trace;
use std::{borrow::Cow, fs, path::Path}; use std::{borrow::Cow, fs, path::Path};
pub struct IdentityPassThroughFactory;
impl<T: wgc::id::Marker> wgc::identity::IdentityHandlerFactory<T> for IdentityPassThroughFactory {
type Input = wgc::id::Id<T>;
fn input_to_id(id_in: Self::Input) -> wgc::id::Id<T> {
id_in
}
fn autogenerate_ids() -> bool {
false
}
}
impl wgc::identity::GlobalIdentityHandlerFactory for IdentityPassThroughFactory {}
pub trait GlobalPlay { pub trait GlobalPlay {
fn encode_commands<A: wgc::hal_api::HalApi>( fn encode_commands<A: wgc::hal_api::HalApi>(
&self, &self,
@ -42,7 +27,7 @@ pub trait GlobalPlay {
); );
} }
impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> { impl GlobalPlay for wgc::global::Global {
fn encode_commands<A: wgc::hal_api::HalApi>( fn encode_commands<A: wgc::hal_api::HalApi>(
&self, &self,
encoder: wgc::id::CommandEncoderId, encoder: wgc::id::CommandEncoderId,
@ -169,7 +154,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::CreateBuffer(id, desc) => { Action::CreateBuffer(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_buffer::<A>(device, &desc, id); let (_, error) = self.device_create_buffer::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -182,7 +167,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::CreateTexture(id, desc) => { Action::CreateTexture(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_texture::<A>(device, &desc, id); let (_, error) = self.device_create_texture::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -199,7 +184,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
desc, desc,
} => { } => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.texture_create_view::<A>(parent_id, &desc, id); let (_, error) = self.texture_create_view::<A>(parent_id, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -209,7 +194,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::CreateSampler(id, desc) => { Action::CreateSampler(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_sampler::<A>(device, &desc, id); let (_, error) = self.device_create_sampler::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -219,13 +204,13 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::GetSurfaceTexture { id, parent_id } => { Action::GetSurfaceTexture { id, parent_id } => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
self.surface_get_current_texture::<A>(parent_id, id) self.surface_get_current_texture::<A>(parent_id, Some(id))
.unwrap() .unwrap()
.texture_id .texture_id
.unwrap(); .unwrap();
} }
Action::CreateBindGroupLayout(id, desc) => { Action::CreateBindGroupLayout(id, desc) => {
let (_, error) = self.device_create_bind_group_layout::<A>(device, &desc, id); let (_, error) = self.device_create_bind_group_layout::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -235,7 +220,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::CreatePipelineLayout(id, desc) => { Action::CreatePipelineLayout(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_pipeline_layout::<A>(device, &desc, id); let (_, error) = self.device_create_pipeline_layout::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -245,7 +230,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::CreateBindGroup(id, desc) => { Action::CreateBindGroup(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_bind_group::<A>(device, &desc, id); let (_, error) = self.device_create_bind_group::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -264,7 +249,8 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} else { } else {
panic!("Unknown shader {}", data); panic!("Unknown shader {}", data);
}; };
let (_, error) = self.device_create_shader_module::<A>(device, &desc, source, id); let (_, error) =
self.device_create_shader_module::<A>(device, &desc, source, Some(id));
if let Some(e) = error { if let Some(e) = error {
println!("shader compilation error:\n---{code}\n---\n{e}"); println!("shader compilation error:\n---{code}\n---\n{e}");
} }
@ -282,11 +268,11 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
implicit_context implicit_context
.as_ref() .as_ref()
.map(|ic| wgc::device::ImplicitPipelineIds { .map(|ic| wgc::device::ImplicitPipelineIds {
root_id: ic.root_id, root_id: Some(ic.root_id),
group_ids: &ic.group_ids, group_ids: wgc::id::as_option_slice(&ic.group_ids),
}); });
let (_, error) = let (_, error) =
self.device_create_compute_pipeline::<A>(device, &desc, id, implicit_ids); self.device_create_compute_pipeline::<A>(device, &desc, Some(id), implicit_ids);
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -304,11 +290,11 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
implicit_context implicit_context
.as_ref() .as_ref()
.map(|ic| wgc::device::ImplicitPipelineIds { .map(|ic| wgc::device::ImplicitPipelineIds {
root_id: ic.root_id, root_id: Some(ic.root_id),
group_ids: &ic.group_ids, group_ids: wgc::id::as_option_slice(&ic.group_ids),
}); });
let (_, error) = let (_, error) =
self.device_create_render_pipeline::<A>(device, &desc, id, implicit_ids); self.device_create_render_pipeline::<A>(device, &desc, Some(id), implicit_ids);
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -322,7 +308,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
let (_, error) = self.render_bundle_encoder_finish::<A>( let (_, error) = self.render_bundle_encoder_finish::<A>(
bundle, bundle,
&wgt::RenderBundleDescriptor { label: desc.label }, &wgt::RenderBundleDescriptor { label: desc.label },
id, Some(id),
); );
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
@ -333,7 +319,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} }
Action::CreateQuerySet { id, desc } => { Action::CreateQuerySet { id, desc } => {
self.device_maintain_ids::<A>(device).unwrap(); self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_query_set::<A>(device, &desc, id); let (_, error) = self.device_create_query_set::<A>(device, &desc, Some(id));
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");
} }
@ -375,7 +361,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
let (encoder, error) = self.device_create_command_encoder::<A>( let (encoder, error) = self.device_create_command_encoder::<A>(
device, device,
&wgt::CommandEncoderDescriptor { label: None }, &wgt::CommandEncoderDescriptor { label: None },
comb_manager.process(device.backend()).transmute(), Some(comb_manager.process(device.backend()).transmute()),
); );
if let Some(e) = error { if let Some(e) = error {
panic!("{e}"); panic!("{e}");

View File

@ -10,7 +10,7 @@
!*/ !*/
#![cfg(not(target_arch = "wasm32"))] #![cfg(not(target_arch = "wasm32"))]
use player::{GlobalPlay, IdentityPassThroughFactory}; use player::GlobalPlay;
use std::{ use std::{
fs::{read_to_string, File}, fs::{read_to_string, File},
io::{Read, Seek, SeekFrom}, io::{Read, Seek, SeekFrom},
@ -100,7 +100,7 @@ impl Test<'_> {
fn run( fn run(
self, self,
dir: &Path, dir: &Path,
global: &wgc::global::Global<IdentityPassThroughFactory>, global: &wgc::global::Global,
adapter: wgc::id::AdapterId, adapter: wgc::id::AdapterId,
test_num: u32, test_num: u32,
) { ) {
@ -114,8 +114,8 @@ impl Test<'_> {
required_limits: wgt::Limits::default(), required_limits: wgt::Limits::default(),
}, },
None, None,
device_id, Some(device_id),
device_id.transmute() Some(device_id.transmute())
)); ));
if let Some(e) = error { if let Some(e) = error {
panic!("{:?}", e); panic!("{:?}", e);
@ -203,7 +203,6 @@ impl Corpus {
let global = wgc::global::Global::new( let global = wgc::global::Global::new(
"test", "test",
IdentityPassThroughFactory,
wgt::InstanceDescriptor { wgt::InstanceDescriptor {
backends: corpus.backends, backends: corpus.backends,
flags: wgt::InstanceFlags::debugging(), flags: wgt::InstanceFlags::debugging(),
@ -221,9 +220,7 @@ impl Corpus {
force_fallback_adapter: false, force_fallback_adapter: false,
compatible_surface: None, compatible_surface: None,
}, },
wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)], |id| { wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)]),
id.backend()
}),
) { ) {
Ok(adapter) => adapter, Ok(adapter) => adapter,
Err(_) => continue, Err(_) => continue,

View File

@ -10,7 +10,6 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
id::{BufferId, CommandEncoderId, DeviceId, TextureId}, id::{BufferId, CommandEncoderId, DeviceId, TextureId},
identity::GlobalIdentityHandlerFactory,
init_tracker::{MemoryInitKind, TextureInitRange}, init_tracker::{MemoryInitKind, TextureInitRange},
resource::{Resource, Texture, TextureClearMode}, resource::{Resource, Texture, TextureClearMode},
track::{TextureSelector, TextureTracker}, track::{TextureSelector, TextureTracker},
@ -71,7 +70,7 @@ whereas subesource range specified start {subresource_base_array_layer} and coun
Device(#[from] DeviceError), Device(#[from] DeviceError),
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn command_encoder_clear_buffer<A: HalApi>( pub fn command_encoder_clear_buffer<A: HalApi>(
&self, &self,
command_encoder_id: CommandEncoderId, command_encoder_id: CommandEncoderId,

View File

@ -18,7 +18,6 @@ use crate::{
hal_api::HalApi, hal_api::HalApi,
hal_label, id, hal_label, id,
id::DeviceId, id::DeviceId,
identity::GlobalIdentityHandlerFactory,
init_tracker::MemoryInitKind, init_tracker::MemoryInitKind,
pipeline, pipeline,
resource::{self}, resource::{self},
@ -340,7 +339,7 @@ impl<A: HalApi> State<A> {
// Common routines between render/compute // Common routines between render/compute
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn command_encoder_run_compute_pass<A: HalApi>( pub fn command_encoder_run_compute_pass<A: HalApi>(
&self, &self,
encoder_id: id::CommandEncoderId, encoder_id: id::CommandEncoderId,

View File

@ -27,10 +27,7 @@ use crate::snatch::SnatchGuard;
use crate::init_tracker::BufferInitTrackerAction; use crate::init_tracker::BufferInitTrackerAction;
use crate::resource::{Resource, ResourceInfo, ResourceType}; use crate::resource::{Resource, ResourceInfo, ResourceType};
use crate::track::{Tracker, UsageScope}; use crate::track::{Tracker, UsageScope};
use crate::{ use crate::{api_log, global::Global, hal_api::HalApi, id, resource_log, Label};
api_log, global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory,
resource_log, Label,
};
use hal::CommandEncoder as _; use hal::CommandEncoder as _;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -410,7 +407,7 @@ pub enum CommandEncoderError {
Device(#[from] DeviceError), Device(#[from] DeviceError),
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn command_encoder_finish<A: HalApi>( pub fn command_encoder_finish<A: HalApi>(
&self, &self,
encoder_id: id::CommandEncoderId, encoder_id: id::CommandEncoderId,

View File

@ -8,7 +8,6 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
id::{self, Id}, id::{self, Id},
identity::GlobalIdentityHandlerFactory,
init_tracker::MemoryInitKind, init_tracker::MemoryInitKind,
resource::QuerySet, resource::QuerySet,
storage::Storage, storage::Storage,
@ -346,7 +345,7 @@ pub(super) fn end_pipeline_statistics_query<A: HalApi>(
} }
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn command_encoder_write_timestamp<A: HalApi>( pub fn command_encoder_write_timestamp<A: HalApi>(
&self, &self,
command_encoder_id: id::CommandEncoderId, command_encoder_id: id::CommandEncoderId,

View File

@ -20,7 +20,6 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
hal_label, id, hal_label, id,
identity::GlobalIdentityHandlerFactory,
init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction}, init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction},
pipeline::{self, PipelineFlags}, pipeline::{self, PipelineFlags},
resource::{Buffer, QuerySet, Texture, TextureView, TextureViewNotRenderableReason}, resource::{Buffer, QuerySet, Texture, TextureView, TextureViewNotRenderableReason},
@ -1303,7 +1302,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
// Common routines between render/compute // Common routines between render/compute
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn command_encoder_run_render_pass<A: HalApi>( pub fn command_encoder_run_render_pass<A: HalApi>(
&self, &self,
encoder_id: id::CommandEncoderId, encoder_id: id::CommandEncoderId,

View File

@ -9,7 +9,6 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
id::{BufferId, CommandEncoderId, DeviceId, TextureId}, id::{BufferId, CommandEncoderId, DeviceId, TextureId},
identity::GlobalIdentityHandlerFactory,
init_tracker::{ init_tracker::{
has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange, has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange,
TextureInitTrackerAction, TextureInitTrackerAction,
@ -554,7 +553,7 @@ fn handle_dst_texture_init<A: HalApi>(
Ok(()) Ok(())
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn command_encoder_copy_buffer_to_buffer<A: HalApi>( pub fn command_encoder_copy_buffer_to_buffer<A: HalApi>(
&self, &self,
command_encoder_id: CommandEncoderId, command_encoder_id: CommandEncoderId,

View File

@ -8,9 +8,7 @@ use crate::{
}, },
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
id::markers,
id::{self, AdapterId, DeviceId, QueueId, SurfaceId}, id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
identity::{GlobalIdentityHandlerFactory, Input},
init_tracker::TextureInitTracker, init_tracker::TextureInitTracker,
instance::{self, Adapter, Surface}, instance::{self, Adapter, Surface},
pipeline, present, pipeline, present,
@ -36,7 +34,7 @@ use std::{
use super::{ImplicitPipelineIds, InvalidDevice, UserClosures}; use super::{ImplicitPipelineIds, InvalidDevice, UserClosures};
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn adapter_is_surface_supported<A: HalApi>( pub fn adapter_is_surface_supported<A: HalApi>(
&self, &self,
adapter_id: AdapterId, adapter_id: AdapterId,
@ -147,12 +145,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &resource::BufferDescriptor, desc: &resource::BufferDescriptor,
id_in: Input<G, markers::Buffer>, id_in: Option<id::BufferId>,
) -> (id::BufferId, Option<CreateBufferError>) { ) -> (id::BufferId, Option<CreateBufferError>) {
profiling::scope!("Device::create_buffer"); profiling::scope!("Device::create_buffer");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.buffers.prepare::<G, _>(id_in); let fid = hub.buffers.prepare(id_in);
let mut to_destroy: ArrayVec<resource::Buffer<A>, 2> = ArrayVec::new(); let mut to_destroy: ArrayVec<resource::Buffer<A>, 2> = ArrayVec::new();
let error = loop { let error = loop {
@ -310,20 +308,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// [`device_create_buffer`]: Global::device_create_buffer /// [`device_create_buffer`]: Global::device_create_buffer
/// [`usage`]: https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-usage /// [`usage`]: https://www.w3.org/TR/webgpu/#dom-gputexturedescriptor-usage
/// [`wgpu_types::BufferUsages`]: wgt::BufferUsages /// [`wgpu_types::BufferUsages`]: wgt::BufferUsages
pub fn create_buffer_error<A: HalApi>(&self, id_in: Input<G, markers::Buffer>, label: Label) { pub fn create_buffer_error<A: HalApi>(&self, id_in: Option<id::BufferId>, label: Label) {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.buffers.prepare::<G, _>(id_in); let fid = hub.buffers.prepare(id_in);
fid.assign_error(label.borrow_or_default()); fid.assign_error(label.borrow_or_default());
} }
pub fn create_render_bundle_error<A: HalApi>( pub fn create_render_bundle_error<A: HalApi>(
&self, &self,
id_in: Input<G, markers::RenderBundle>, id_in: Option<id::RenderBundleId>,
label: Label, label: Label,
) { ) {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.render_bundles.prepare::<G, _>(id_in); let fid = hub.render_bundles.prepare(id_in);
fid.assign_error(label.borrow_or_default()); fid.assign_error(label.borrow_or_default());
} }
@ -331,9 +329,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// Assign `id_in` an error with the given `label`. /// Assign `id_in` an error with the given `label`.
/// ///
/// See `create_buffer_error` for more context and explaination. /// See `create_buffer_error` for more context and explaination.
pub fn create_texture_error<A: HalApi>(&self, id_in: Input<G, markers::Texture>, label: Label) { pub fn create_texture_error<A: HalApi>(&self, id_in: Option<id::TextureId>, label: Label) {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.textures.prepare::<G, _>(id_in); let fid = hub.textures.prepare(id_in);
fid.assign_error(label.borrow_or_default()); fid.assign_error(label.borrow_or_default());
} }
@ -546,13 +544,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &resource::TextureDescriptor, desc: &resource::TextureDescriptor,
id_in: Input<G, markers::Texture>, id_in: Option<id::TextureId>,
) -> (id::TextureId, Option<resource::CreateTextureError>) { ) -> (id::TextureId, Option<resource::CreateTextureError>) {
profiling::scope!("Device::create_texture"); profiling::scope!("Device::create_texture");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.textures.prepare::<G, _>(id_in); let fid = hub.textures.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -600,13 +598,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal_texture: A::Texture, hal_texture: A::Texture,
device_id: DeviceId, device_id: DeviceId,
desc: &resource::TextureDescriptor, desc: &resource::TextureDescriptor,
id_in: Input<G, markers::Texture>, id_in: Option<id::TextureId>,
) -> (id::TextureId, Option<resource::CreateTextureError>) { ) -> (id::TextureId, Option<resource::CreateTextureError>) {
profiling::scope!("Device::create_texture_from_hal"); profiling::scope!("Device::create_texture_from_hal");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.textures.prepare::<G, _>(id_in); let fid = hub.textures.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -674,12 +672,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal_buffer: A::Buffer, hal_buffer: A::Buffer,
device_id: DeviceId, device_id: DeviceId,
desc: &resource::BufferDescriptor, desc: &resource::BufferDescriptor,
id_in: Input<G, markers::Buffer>, id_in: Option<id::BufferId>,
) -> (id::BufferId, Option<CreateBufferError>) { ) -> (id::BufferId, Option<CreateBufferError>) {
profiling::scope!("Device::create_buffer"); profiling::scope!("Device::create_buffer");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.buffers.prepare::<G, _>(id_in); let fid = hub.buffers.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -784,13 +782,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
texture_id: id::TextureId, texture_id: id::TextureId,
desc: &resource::TextureViewDescriptor, desc: &resource::TextureViewDescriptor,
id_in: Input<G, markers::TextureView>, id_in: Option<id::TextureViewId>,
) -> (id::TextureViewId, Option<resource::CreateTextureViewError>) { ) -> (id::TextureViewId, Option<resource::CreateTextureViewError>) {
profiling::scope!("Texture::create_view"); profiling::scope!("Texture::create_view");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.texture_views.prepare::<G, _>(id_in); let fid = hub.texture_views.prepare(id_in);
let error = loop { let error = loop {
let texture = match hub.textures.get(texture_id) { let texture = match hub.textures.get(texture_id) {
@ -874,12 +872,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &resource::SamplerDescriptor, desc: &resource::SamplerDescriptor,
id_in: Input<G, markers::Sampler>, id_in: Option<id::SamplerId>,
) -> (id::SamplerId, Option<resource::CreateSamplerError>) { ) -> (id::SamplerId, Option<resource::CreateSamplerError>) {
profiling::scope!("Device::create_sampler"); profiling::scope!("Device::create_sampler");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.samplers.prepare::<G, _>(id_in); let fid = hub.samplers.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -935,7 +933,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &binding_model::BindGroupLayoutDescriptor, desc: &binding_model::BindGroupLayoutDescriptor,
id_in: Input<G, markers::BindGroupLayout>, id_in: Option<id::BindGroupLayoutId>,
) -> ( ) -> (
id::BindGroupLayoutId, id::BindGroupLayoutId,
Option<binding_model::CreateBindGroupLayoutError>, Option<binding_model::CreateBindGroupLayoutError>,
@ -943,7 +941,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
profiling::scope!("Device::create_bind_group_layout"); profiling::scope!("Device::create_bind_group_layout");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.bind_group_layouts.prepare::<G, _>(id_in); let fid = hub.bind_group_layouts.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1005,7 +1003,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
return (id.unwrap(), None); return (id.unwrap(), None);
}; };
let fid = hub.bind_group_layouts.prepare::<G, _>(id_in); let fid = hub.bind_group_layouts.prepare(id_in);
let id = fid.assign_error(desc.label.borrow_or_default()); let id = fid.assign_error(desc.label.borrow_or_default());
(id, Some(error)) (id, Some(error))
} }
@ -1034,7 +1032,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &binding_model::PipelineLayoutDescriptor, desc: &binding_model::PipelineLayoutDescriptor,
id_in: Input<G, markers::PipelineLayout>, id_in: Option<id::PipelineLayoutId>,
) -> ( ) -> (
id::PipelineLayoutId, id::PipelineLayoutId,
Option<binding_model::CreatePipelineLayoutError>, Option<binding_model::CreatePipelineLayoutError>,
@ -1042,7 +1040,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
profiling::scope!("Device::create_pipeline_layout"); profiling::scope!("Device::create_pipeline_layout");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.pipeline_layouts.prepare::<G, _>(id_in); let fid = hub.pipeline_layouts.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1095,12 +1093,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &binding_model::BindGroupDescriptor, desc: &binding_model::BindGroupDescriptor,
id_in: Input<G, markers::BindGroup>, id_in: Option<id::BindGroupId>,
) -> (id::BindGroupId, Option<binding_model::CreateBindGroupError>) { ) -> (id::BindGroupId, Option<binding_model::CreateBindGroupError>) {
profiling::scope!("Device::create_bind_group"); profiling::scope!("Device::create_bind_group");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.bind_groups.prepare::<G, _>(id_in); let fid = hub.bind_groups.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1179,7 +1177,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device_id: DeviceId, device_id: DeviceId,
desc: &pipeline::ShaderModuleDescriptor, desc: &pipeline::ShaderModuleDescriptor,
source: pipeline::ShaderModuleSource, source: pipeline::ShaderModuleSource,
id_in: Input<G, markers::ShaderModule>, id_in: Option<id::ShaderModuleId>,
) -> ( ) -> (
id::ShaderModuleId, id::ShaderModuleId,
Option<pipeline::CreateShaderModuleError>, Option<pipeline::CreateShaderModuleError>,
@ -1187,7 +1185,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
profiling::scope!("Device::create_shader_module"); profiling::scope!("Device::create_shader_module");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.shader_modules.prepare::<G, _>(id_in); let fid = hub.shader_modules.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1257,7 +1255,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device_id: DeviceId, device_id: DeviceId,
desc: &pipeline::ShaderModuleDescriptor, desc: &pipeline::ShaderModuleDescriptor,
source: Cow<[u32]>, source: Cow<[u32]>,
id_in: Input<G, markers::ShaderModule>, id_in: Option<id::ShaderModuleId>,
) -> ( ) -> (
id::ShaderModuleId, id::ShaderModuleId,
Option<pipeline::CreateShaderModuleError>, Option<pipeline::CreateShaderModuleError>,
@ -1265,7 +1263,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
profiling::scope!("Device::create_shader_module"); profiling::scope!("Device::create_shader_module");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.shader_modules.prepare::<G, _>(id_in); let fid = hub.shader_modules.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1319,14 +1317,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &wgt::CommandEncoderDescriptor<Label>, desc: &wgt::CommandEncoderDescriptor<Label>,
id_in: Input<G, markers::CommandEncoder>, id_in: Option<id::CommandEncoderId>,
) -> (id::CommandEncoderId, Option<DeviceError>) { ) -> (id::CommandEncoderId, Option<DeviceError>) {
profiling::scope!("Device::create_command_encoder"); profiling::scope!("Device::create_command_encoder");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub let fid = hub.command_buffers.prepare(id_in.map(|id| id.transmute()));
.command_buffers
.prepare::<G, markers::CommandEncoder>(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1416,13 +1412,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
bundle_encoder: command::RenderBundleEncoder, bundle_encoder: command::RenderBundleEncoder,
desc: &command::RenderBundleDescriptor, desc: &command::RenderBundleDescriptor,
id_in: Input<G, markers::RenderBundle>, id_in: Option<id::RenderBundleId>,
) -> (id::RenderBundleId, Option<command::RenderBundleError>) { ) -> (id::RenderBundleId, Option<command::RenderBundleError>) {
profiling::scope!("RenderBundleEncoder::finish"); profiling::scope!("RenderBundleEncoder::finish");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.render_bundles.prepare::<G, _>(id_in); let fid = hub.render_bundles.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(bundle_encoder.parent()) { let device = match hub.devices.get(bundle_encoder.parent()) {
@ -1486,12 +1482,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &resource::QuerySetDescriptor, desc: &resource::QuerySetDescriptor,
id_in: Input<G, markers::QuerySet>, id_in: Option<id::QuerySetId>,
) -> (id::QuerySetId, Option<resource::CreateQuerySetError>) { ) -> (id::QuerySetId, Option<resource::CreateQuerySetError>) {
profiling::scope!("Device::create_query_set"); profiling::scope!("Device::create_query_set");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.query_sets.prepare::<G, _>(id_in); let fid = hub.query_sets.prepare(id_in);
let error = loop { let error = loop {
let device = match hub.devices.get(device_id) { let device = match hub.devices.get(device_id) {
@ -1560,8 +1556,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &pipeline::RenderPipelineDescriptor, desc: &pipeline::RenderPipelineDescriptor,
id_in: Input<G, markers::RenderPipeline>, id_in: Option<id::RenderPipelineId>,
implicit_pipeline_ids: Option<ImplicitPipelineIds<G>>, implicit_pipeline_ids: Option<ImplicitPipelineIds<'_>>,
) -> ( ) -> (
id::RenderPipelineId, id::RenderPipelineId,
Option<pipeline::CreateRenderPipelineError>, Option<pipeline::CreateRenderPipelineError>,
@ -1570,7 +1566,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.render_pipelines.prepare::<G, _>(id_in); let fid = hub.render_pipelines.prepare(id_in);
let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub)); let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub));
let implicit_error_context = implicit_context.clone(); let implicit_error_context = implicit_context.clone();
@ -1639,7 +1635,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
pipeline_id: id::RenderPipelineId, pipeline_id: id::RenderPipelineId,
index: u32, index: u32,
id_in: Input<G, markers::BindGroupLayout>, id_in: Option<id::BindGroupLayoutId>,
) -> ( ) -> (
id::BindGroupLayoutId, id::BindGroupLayoutId,
Option<binding_model::GetBindGroupLayoutError>, Option<binding_model::GetBindGroupLayoutError>,
@ -1652,10 +1648,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(_) => break binding_model::GetBindGroupLayoutError::InvalidPipeline, Err(_) => break binding_model::GetBindGroupLayoutError::InvalidPipeline,
}; };
let id = match pipeline.layout.bind_group_layouts.get(index as usize) { let id = match pipeline.layout.bind_group_layouts.get(index as usize) {
Some(bg) => hub Some(bg) => hub.bind_group_layouts.prepare(id_in).assign_existing(bg),
.bind_group_layouts
.prepare::<G, _>(id_in)
.assign_existing(bg),
None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index), None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index),
}; };
return (id, None); return (id, None);
@ -1663,7 +1656,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub let id = hub
.bind_group_layouts .bind_group_layouts
.prepare::<G, _>(id_in) .prepare(id_in)
.assign_error("<derived>"); .assign_error("<derived>");
(id, Some(error)) (id, Some(error))
} }
@ -1698,8 +1691,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
device_id: DeviceId, device_id: DeviceId,
desc: &pipeline::ComputePipelineDescriptor, desc: &pipeline::ComputePipelineDescriptor,
id_in: Input<G, markers::ComputePipeline>, id_in: Option<id::ComputePipelineId>,
implicit_pipeline_ids: Option<ImplicitPipelineIds<G>>, implicit_pipeline_ids: Option<ImplicitPipelineIds<'_>>,
) -> ( ) -> (
id::ComputePipelineId, id::ComputePipelineId,
Option<pipeline::CreateComputePipelineError>, Option<pipeline::CreateComputePipelineError>,
@ -1708,7 +1701,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.compute_pipelines.prepare::<G, _>(id_in); let fid = hub.compute_pipelines.prepare(id_in);
let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub)); let implicit_context = implicit_pipeline_ids.map(|ipi| ipi.prepare(hub));
let implicit_error_context = implicit_context.clone(); let implicit_error_context = implicit_context.clone();
@ -1772,7 +1765,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
pipeline_id: id::ComputePipelineId, pipeline_id: id::ComputePipelineId,
index: u32, index: u32,
id_in: Input<G, markers::BindGroupLayout>, id_in: Option<id::BindGroupLayoutId>,
) -> ( ) -> (
id::BindGroupLayoutId, id::BindGroupLayoutId,
Option<binding_model::GetBindGroupLayoutError>, Option<binding_model::GetBindGroupLayoutError>,
@ -1786,10 +1779,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}; };
let id = match pipeline.layout.bind_group_layouts.get(index as usize) { let id = match pipeline.layout.bind_group_layouts.get(index as usize) {
Some(bg) => hub Some(bg) => hub.bind_group_layouts.prepare(id_in).assign_existing(bg),
.bind_group_layouts
.prepare::<G, _>(id_in)
.assign_existing(bg),
None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index), None => break binding_model::GetBindGroupLayoutError::InvalidGroupIndex(index),
}; };
@ -1798,7 +1788,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub let id = hub
.bind_group_layouts .bind_group_layouts
.prepare::<G, _>(id_in) .prepare(id_in)
.assign_error("<derived>"); .assign_error("<derived>");
(id, Some(error)) (id, Some(error))
} }

View File

@ -2,9 +2,7 @@ use crate::{
binding_model, binding_model,
hal_api::HalApi, hal_api::HalApi,
hub::Hub, hub::Hub,
id, id::{BindGroupLayoutId, PipelineLayoutId},
id::markers,
identity::{GlobalIdentityHandlerFactory, Input},
resource::{Buffer, BufferAccessResult}, resource::{Buffer, BufferAccessResult},
resource::{BufferAccessError, BufferMapOperation}, resource::{BufferAccessError, BufferMapOperation},
resource_log, Label, DOWNLEVEL_ERROR_MESSAGE, resource_log, Label, DOWNLEVEL_ERROR_MESSAGE,
@ -459,23 +457,23 @@ pub struct MissingDownlevelFlags(pub wgt::DownlevelFlags);
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ImplicitPipelineContext { pub struct ImplicitPipelineContext {
pub root_id: id::PipelineLayoutId, pub root_id: PipelineLayoutId,
pub group_ids: ArrayVec<id::BindGroupLayoutId, { hal::MAX_BIND_GROUPS }>, pub group_ids: ArrayVec<BindGroupLayoutId, { hal::MAX_BIND_GROUPS }>,
} }
pub struct ImplicitPipelineIds<'a, G: GlobalIdentityHandlerFactory> { pub struct ImplicitPipelineIds<'a> {
pub root_id: Input<G, markers::PipelineLayout>, pub root_id: Option<PipelineLayoutId>,
pub group_ids: &'a [Input<G, markers::BindGroupLayout>], pub group_ids: &'a [Option<BindGroupLayoutId>],
} }
impl<G: GlobalIdentityHandlerFactory> ImplicitPipelineIds<'_, G> { impl ImplicitPipelineIds<'_> {
fn prepare<A: HalApi>(self, hub: &Hub<A>) -> ImplicitPipelineContext { fn prepare<A: HalApi>(self, hub: &Hub<A>) -> ImplicitPipelineContext {
ImplicitPipelineContext { ImplicitPipelineContext {
root_id: hub.pipeline_layouts.prepare::<G, _>(self.root_id).into_id(), root_id: hub.pipeline_layouts.prepare(self.root_id).into_id(),
group_ids: self group_ids: self
.group_ids .group_ids
.iter() .iter()
.map(|id_in| hub.bind_group_layouts.prepare::<G, _>(*id_in).into_id()) .map(|id_in| hub.bind_group_layouts.prepare(*id_in).into_id())
.collect(), .collect(),
} }
} }

View File

@ -12,9 +12,7 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
hal_label, hal_label,
id::markers,
id::{self, QueueId}, id::{self, QueueId},
identity::{GlobalIdentityHandlerFactory, Input},
init_tracker::{has_copy_partial_init_tracker_coverage, TextureInitRange}, init_tracker::{has_copy_partial_init_tracker_coverage, TextureInitRange},
resource::{ resource::{
Buffer, BufferAccessError, BufferMapState, DestroyedBuffer, DestroyedTexture, Resource, Buffer, BufferAccessError, BufferMapState, DestroyedBuffer, DestroyedTexture, Resource,
@ -365,7 +363,7 @@ pub enum QueueSubmitError {
//TODO: move out common parts of write_xxx. //TODO: move out common parts of write_xxx.
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn queue_write_buffer<A: HalApi>( pub fn queue_write_buffer<A: HalApi>(
&self, &self,
queue_id: QueueId, queue_id: QueueId,
@ -439,7 +437,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
queue_id: QueueId, queue_id: QueueId,
buffer_size: wgt::BufferSize, buffer_size: wgt::BufferSize,
id_in: Input<G, markers::StagingBuffer>, id_in: Option<id::StagingBufferId>,
) -> Result<(id::StagingBufferId, *mut u8), QueueWriteError> { ) -> Result<(id::StagingBufferId, *mut u8), QueueWriteError> {
profiling::scope!("Queue::create_staging_buffer"); profiling::scope!("Queue::create_staging_buffer");
let hub = A::hub(self); let hub = A::hub(self);
@ -454,7 +452,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (staging_buffer, staging_buffer_ptr) = let (staging_buffer, staging_buffer_ptr) =
prepare_staging_buffer(device, buffer_size.get(), device.instance_flags)?; prepare_staging_buffer(device, buffer_size.get(), device.instance_flags)?;
let fid = hub.staging_buffers.prepare::<G, _>(id_in); let fid = hub.staging_buffers.prepare(id_in);
let (id, _) = fid.assign(staging_buffer); let (id, _) = fid.assign(staging_buffer);
resource_log!("Queue::create_staging_buffer {id:?}"); resource_log!("Queue::create_staging_buffer {id:?}");

View File

@ -1,11 +1,11 @@
use core::fmt; use core::fmt;
use std::error::Error; use std::error::Error;
use crate::{gfx_select, global::Global, identity::IdentityManagerFactory}; use crate::{gfx_select, global::Global};
pub struct ErrorFormatter<'a> { pub struct ErrorFormatter<'a> {
writer: &'a mut dyn fmt::Write, writer: &'a mut dyn fmt::Write,
global: &'a Global<IdentityManagerFactory>, global: &'a Global,
} }
impl<'a> ErrorFormatter<'a> { impl<'a> ErrorFormatter<'a> {
@ -94,7 +94,7 @@ pub trait PrettyError: Error + Sized {
pub fn format_pretty_any( pub fn format_pretty_any(
writer: &mut dyn fmt::Write, writer: &mut dyn fmt::Write,
global: &Global<IdentityManagerFactory>, global: &Global,
error: &(dyn Error + 'static), error: &(dyn Error + 'static),
) { ) {
let mut fmt = ErrorFormatter { writer, global }; let mut fmt = ErrorFormatter { writer, global };

View File

@ -1,11 +1,10 @@
use std::{marker::PhantomData, sync::Arc}; use std::sync::Arc;
use wgt::Backend; use wgt::Backend;
use crate::{ use crate::{
hal_api::HalApi, hal_api::HalApi,
hub::{HubReport, Hubs}, hub::{HubReport, Hubs},
identity::GlobalIdentityHandlerFactory,
instance::{Instance, Surface}, instance::{Instance, Surface},
registry::{Registry, RegistryReport}, registry::{Registry, RegistryReport},
resource_log, resource_log,
@ -44,38 +43,31 @@ impl GlobalReport {
} }
} }
pub struct Global<G: GlobalIdentityHandlerFactory> { pub struct Global {
pub instance: Instance, pub instance: Instance,
pub surfaces: Registry<Surface>, pub surfaces: Registry<Surface>,
pub(crate) hubs: Hubs, pub(crate) hubs: Hubs,
_phantom: PhantomData<G>,
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn new(name: &str, factory: G, instance_desc: wgt::InstanceDescriptor) -> Self { pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self {
profiling::scope!("Global::new"); profiling::scope!("Global::new");
Self { Self {
instance: Instance::new(name, instance_desc), instance: Instance::new(name, instance_desc),
surfaces: Registry::without_backend(&factory), surfaces: Registry::without_backend(),
hubs: Hubs::new(&factory), hubs: Hubs::new(),
_phantom: PhantomData,
} }
} }
/// # Safety /// # Safety
/// ///
/// Refer to the creation of wgpu-hal Instance for every backend. /// Refer to the creation of wgpu-hal Instance for every backend.
pub unsafe fn from_hal_instance<A: HalApi>( pub unsafe fn from_hal_instance<A: HalApi>(name: &str, hal_instance: A::Instance) -> Self {
name: &str,
factory: G,
hal_instance: A::Instance,
) -> Self {
profiling::scope!("Global::new"); profiling::scope!("Global::new");
Self { Self {
instance: A::create_instance_from_hal(name, hal_instance), instance: A::create_instance_from_hal(name, hal_instance),
surfaces: Registry::without_backend(&factory), surfaces: Registry::without_backend(),
hubs: Hubs::new(&factory), hubs: Hubs::new(),
_phantom: PhantomData,
} }
} }
@ -89,13 +81,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// # Safety /// # Safety
/// ///
/// - The raw handles obtained from the Instance must not be manually destroyed /// - The raw handles obtained from the Instance must not be manually destroyed
pub unsafe fn from_instance(factory: G, instance: Instance) -> Self { pub unsafe fn from_instance(instance: Instance) -> Self {
profiling::scope!("Global::new"); profiling::scope!("Global::new");
Self { Self {
instance, instance,
surfaces: Registry::without_backend(&factory), surfaces: Registry::without_backend(),
hubs: Hubs::new(&factory), hubs: Hubs::new(),
_phantom: PhantomData,
} }
} }
@ -137,7 +128,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} }
} }
impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> { impl Drop for Global {
fn drop(&mut self) { fn drop(&mut self) {
profiling::scope!("Global::drop"); profiling::scope!("Global::drop");
resource_log!("Global::drop"); resource_log!("Global::drop");
@ -175,7 +166,7 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
} }
#[cfg(send_sync)] #[cfg(send_sync)]
fn _test_send_sync(global: &Global<crate::identity::IdentityManagerFactory>) { fn _test_send_sync(global: &Global) {
fn test_internal<T: Send + Sync>(_: T) {} fn test_internal<T: Send + Sync>(_: T) {}
test_internal(global) test_internal(global)
} }

View File

@ -3,7 +3,6 @@ use wgt::{Backend, WasmNotSendSync};
use crate::{ use crate::{
global::Global, global::Global,
hub::Hub, hub::Hub,
identity::GlobalIdentityHandlerFactory,
instance::{HalSurface, Instance, Surface}, instance::{HalSurface, Instance, Surface},
}; };
@ -11,7 +10,7 @@ pub trait HalApi: hal::Api + 'static + WasmNotSendSync {
const VARIANT: Backend; const VARIANT: Backend;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance; fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance;
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance>; fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance>;
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self>; fn hub(global: &Global) -> &Hub<Self>;
fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>>; fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>>;
} }
@ -23,7 +22,7 @@ impl HalApi for hal::api::Empty {
fn instance_as_hal(_: &Instance) -> Option<&Self::Instance> { fn instance_as_hal(_: &Instance) -> Option<&Self::Instance> {
unimplemented!("called empty api") unimplemented!("called empty api")
} }
fn hub<G: GlobalIdentityHandlerFactory>(_: &Global<G>) -> &Hub<Self> { fn hub(_: &Global) -> &Hub<Self> {
unimplemented!("called empty api") unimplemented!("called empty api")
} }
fn get_surface(_: &Surface) -> Option<&HalSurface<Self>> { fn get_surface(_: &Surface) -> Option<&HalSurface<Self>> {
@ -44,7 +43,7 @@ impl HalApi for hal::api::Vulkan {
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> {
instance.vulkan.as_ref() instance.vulkan.as_ref()
} }
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> { fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.vulkan &global.hubs.vulkan
} }
fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> { fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> {
@ -65,7 +64,7 @@ impl HalApi for hal::api::Metal {
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> {
instance.metal.as_ref() instance.metal.as_ref()
} }
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> { fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.metal &global.hubs.metal
} }
fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> { fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> {
@ -86,7 +85,7 @@ impl HalApi for hal::api::Dx12 {
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> {
instance.dx12.as_ref() instance.dx12.as_ref()
} }
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> { fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.dx12 &global.hubs.dx12
} }
fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> { fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> {
@ -108,7 +107,7 @@ impl HalApi for hal::api::Gles {
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> { fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance> {
instance.gl.as_ref() instance.gl.as_ref()
} }
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> { fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.gl &global.hubs.gl
} }
fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> { fn get_surface(surface: &Surface) -> Option<&HalSurface<Self>> {

View File

@ -40,7 +40,7 @@ specify the id, and they all return the id used. For example, the
declaration of `Global::device_create_buffer` looks like this: declaration of `Global::device_create_buffer` looks like this:
```ignore ```ignore
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
/* ... */ /* ... */
pub fn device_create_buffer<A: HalApi>( pub fn device_create_buffer<A: HalApi>(
&self, &self,
@ -60,15 +60,7 @@ itself to choose ids always pass `()`. In either case, the id
ultimately assigned is returned as the first element of the tuple. ultimately assigned is returned as the first element of the tuple.
Producing true identifiers from `id_in` values is the job of an Producing true identifiers from `id_in` values is the job of an
[`crate::identity::IdentityManager`], but only if the `IdentityHandlerFactory` [`crate::identity::IdentityManager`] or ids will be received from outside through `Option<Id>` arguments.
create it and then generated by it, otherwise ids will be received from outside.
`Global::new` expects a `factory` argument that
implements the [`GlobalIdentityHandlerFactory`] trait, which extends
[`crate::identity::IdentityHandlerFactory<I>`] for each resource id type `I`. This
trait, in turn, has a `spawn` method that constructs an
`crate::identity::IdentityManager` for the `Global` to use,
if ids should be generated by wgpu or will return None otherwise.
## Id allocation and streaming ## Id allocation and streaming
@ -105,7 +97,6 @@ as much, allowing subsequent operations using that id to be properly
flagged as errors as well. flagged as errors as well.
[`gfx_select`]: crate::gfx_select [`gfx_select`]: crate::gfx_select
[`Input`]: crate::identity::IdentityHandlerFactory::Input
[`process`]: crate::identity::IdentityManager::process [`process`]: crate::identity::IdentityManager::process
[`Id<R>`]: crate::id::Id [`Id<R>`]: crate::id::Id
[wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E [wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E
@ -118,7 +109,6 @@ use crate::{
command::{CommandBuffer, RenderBundle}, command::{CommandBuffer, RenderBundle},
device::{queue::Queue, Device}, device::{queue::Queue, Device},
hal_api::HalApi, hal_api::HalApi,
identity::GlobalIdentityHandlerFactory,
instance::{Adapter, HalSurface, Surface}, instance::{Adapter, HalSurface, Surface},
pipeline::{ComputePipeline, RenderPipeline, ShaderModule}, pipeline::{ComputePipeline, RenderPipeline, ShaderModule},
registry::{Registry, RegistryReport}, registry::{Registry, RegistryReport},
@ -199,25 +189,25 @@ pub struct Hub<A: HalApi> {
} }
impl<A: HalApi> Hub<A> { impl<A: HalApi> Hub<A> {
fn new<F: GlobalIdentityHandlerFactory>(factory: &F) -> Self { fn new() -> Self {
Self { Self {
adapters: Registry::new(A::VARIANT, factory), adapters: Registry::new(A::VARIANT),
devices: Registry::new(A::VARIANT, factory), devices: Registry::new(A::VARIANT),
queues: Registry::new(A::VARIANT, factory), queues: Registry::new(A::VARIANT),
pipeline_layouts: Registry::new(A::VARIANT, factory), pipeline_layouts: Registry::new(A::VARIANT),
shader_modules: Registry::new(A::VARIANT, factory), shader_modules: Registry::new(A::VARIANT),
bind_group_layouts: Registry::new(A::VARIANT, factory), bind_group_layouts: Registry::new(A::VARIANT),
bind_groups: Registry::new(A::VARIANT, factory), bind_groups: Registry::new(A::VARIANT),
command_buffers: Registry::new(A::VARIANT, factory), command_buffers: Registry::new(A::VARIANT),
render_bundles: Registry::new(A::VARIANT, factory), render_bundles: Registry::new(A::VARIANT),
render_pipelines: Registry::new(A::VARIANT, factory), render_pipelines: Registry::new(A::VARIANT),
compute_pipelines: Registry::new(A::VARIANT, factory), compute_pipelines: Registry::new(A::VARIANT),
query_sets: Registry::new(A::VARIANT, factory), query_sets: Registry::new(A::VARIANT),
buffers: Registry::new(A::VARIANT, factory), buffers: Registry::new(A::VARIANT),
staging_buffers: Registry::new(A::VARIANT, factory), staging_buffers: Registry::new(A::VARIANT),
textures: Registry::new(A::VARIANT, factory), textures: Registry::new(A::VARIANT),
texture_views: Registry::new(A::VARIANT, factory), texture_views: Registry::new(A::VARIANT),
samplers: Registry::new(A::VARIANT, factory), samplers: Registry::new(A::VARIANT),
} }
} }
@ -313,18 +303,18 @@ pub struct Hubs {
} }
impl Hubs { impl Hubs {
pub(crate) fn new<F: GlobalIdentityHandlerFactory>(factory: &F) -> Self { pub(crate) fn new() -> Self {
Self { Self {
#[cfg(vulkan)] #[cfg(vulkan)]
vulkan: Hub::new(factory), vulkan: Hub::new(),
#[cfg(metal)] #[cfg(metal)]
metal: Hub::new(factory), metal: Hub::new(),
#[cfg(dx12)] #[cfg(dx12)]
dx12: Hub::new(factory), dx12: Hub::new(),
#[cfg(gles)] #[cfg(gles)]
gl: Hub::new(factory), gl: Hub::new(),
#[cfg(all(not(vulkan), not(metal), not(dx12), not(gles)))] #[cfg(all(not(vulkan), not(metal), not(dx12), not(gles)))]
empty: Hub::new(factory), empty: Hub::new(),
} }
} }
} }

View File

@ -71,9 +71,15 @@ impl RawId {
} }
} }
/// Coerce a slice of identifiers into a slice of raw identifiers. /// Coerce a slice of identifiers into a slice of optional raw identifiers.
pub fn into_raw_slice<T: Marker>(ids: &[Id<T>]) -> &[RawId] { ///
// SAFETY: Any Id<T> is repr(transparent) over `RawId`. /// There's two reasons why we know this is correct:
/// * `Option<T>` is guarnateed to be niche-filled to 0's.
/// * The `T` in `Option<T>` can inhabit any representation except 0's, since
/// its underlying representation is `NonZero*`.
pub fn as_option_slice<T: Marker>(ids: &[Id<T>]) -> &[Option<Id<T>>] {
// SAFETY: Any Id<T> is repr(transparent) over `Option<RawId>`, since both
// are backed by non-zero types.
unsafe { std::slice::from_raw_parts(ids.as_ptr().cast(), ids.len()) } unsafe { std::slice::from_raw_parts(ids.as_ptr().cast(), ids.len()) }
} }

View File

@ -2,10 +2,10 @@ use parking_lot::Mutex;
use wgt::Backend; use wgt::Backend;
use crate::{ use crate::{
id::{self, Id, Marker}, id::{Id, Marker},
Epoch, FastHashMap, Index, Epoch, FastHashMap, Index,
}; };
use std::{fmt::Debug, marker::PhantomData, sync::Arc}; use std::{fmt::Debug, marker::PhantomData};
/// A simple structure to allocate [`Id`] identifiers. /// A simple structure to allocate [`Id`] identifiers.
/// ///
@ -112,74 +112,10 @@ impl<T: Marker> IdentityManager<T> {
} }
} }
/// A type that can produce [`IdentityManager`] filters for ids of type `I`.
///
/// See the module-level documentation for details.
pub trait IdentityHandlerFactory<T: Marker> {
type Input: Copy;
/// Create an [`IdentityManager<I>`] implementation that can
/// transform proto-ids into ids of type `I`.
/// It can return None if ids are passed from outside
/// and are not generated by wgpu
///
/// [`IdentityManager<I>`]: IdentityManager
fn spawn(&self) -> Arc<IdentityManager<T>> {
Arc::new(IdentityManager::new())
}
fn autogenerate_ids() -> bool;
fn input_to_id(id_in: Self::Input) -> Id<T>;
}
/// A global identity handler factory based on [`IdentityManager`].
///
/// Each of this type's `IdentityHandlerFactory<I>::spawn` methods
/// returns a `Mutex<IdentityManager<I>>`, which allocates fresh `I`
/// ids itself, and takes `()` as its proto-id type.
#[derive(Debug)]
pub struct IdentityManagerFactory;
impl<T: Marker> IdentityHandlerFactory<T> for IdentityManagerFactory {
type Input = ();
fn autogenerate_ids() -> bool {
true
}
fn input_to_id(_id_in: Self::Input) -> Id<T> {
unreachable!("It should not be called")
}
}
/// A factory that can build [`IdentityManager`]s for all resource
/// types.
pub trait GlobalIdentityHandlerFactory:
IdentityHandlerFactory<id::markers::Adapter>
+ IdentityHandlerFactory<id::markers::Device>
+ IdentityHandlerFactory<id::markers::PipelineLayout>
+ IdentityHandlerFactory<id::markers::ShaderModule>
+ IdentityHandlerFactory<id::markers::BindGroupLayout>
+ IdentityHandlerFactory<id::markers::BindGroup>
+ IdentityHandlerFactory<id::markers::CommandBuffer>
+ IdentityHandlerFactory<id::markers::RenderBundle>
+ IdentityHandlerFactory<id::markers::RenderPipeline>
+ IdentityHandlerFactory<id::markers::ComputePipeline>
+ IdentityHandlerFactory<id::markers::QuerySet>
+ IdentityHandlerFactory<id::markers::Buffer>
+ IdentityHandlerFactory<id::markers::StagingBuffer>
+ IdentityHandlerFactory<id::markers::Texture>
+ IdentityHandlerFactory<id::markers::TextureView>
+ IdentityHandlerFactory<id::markers::Sampler>
+ IdentityHandlerFactory<id::markers::Surface>
+ IdentityHandlerFactory<id::markers::Queue>
+ IdentityHandlerFactory<id::markers::CommandEncoder>
{
}
impl GlobalIdentityHandlerFactory for IdentityManagerFactory {}
pub type Input<G, I> = <G as IdentityHandlerFactory<I>>::Input;
#[test] #[test]
fn test_epoch_end_of_life() { fn test_epoch_end_of_life() {
use crate::id;
let man = IdentityManager::<id::markers::Buffer>::new(); let man = IdentityManager::<id::markers::Buffer>::new();
let forced_id = man.mark_as_used(id::BufferId::zip(0, 1, Backend::Empty)); let forced_id = man.mark_as_used(id::BufferId::zip(0, 1, Backend::Empty));
assert_eq!(forced_id.unzip().0, 0); assert_eq!(forced_id.unzip().0, 0);

View File

@ -7,8 +7,7 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
id::markers, id::markers,
id::{AdapterId, DeviceId, QueueId, SurfaceId}, id::{AdapterId, DeviceId, Id, Marker, QueueId, SurfaceId},
identity::{GlobalIdentityHandlerFactory, Input},
present::Presentation, present::Presentation,
resource::{Resource, ResourceInfo, ResourceType}, resource::{Resource, ResourceInfo, ResourceType},
resource_log, LabelHelpers, DOWNLEVEL_WARNING_MESSAGE, resource_log, LabelHelpers, DOWNLEVEL_WARNING_MESSAGE,
@ -157,7 +156,7 @@ pub struct Surface {
impl Resource for Surface { impl Resource for Surface {
const TYPE: ResourceType = "Surface"; const TYPE: ResourceType = "Surface";
type Marker = crate::id::markers::Surface; type Marker = markers::Surface;
fn as_info(&self) -> &ResourceInfo<Self> { fn as_info(&self) -> &ResourceInfo<Self> {
&self.info &self.info
@ -388,7 +387,7 @@ impl<A: HalApi> Adapter<A> {
impl<A: HalApi> Resource for Adapter<A> { impl<A: HalApi> Resource for Adapter<A> {
const TYPE: ResourceType = "Adapter"; const TYPE: ResourceType = "Adapter";
type Marker = crate::id::markers::Adapter; type Marker = markers::Adapter;
fn as_info(&self) -> &ResourceInfo<Self> { fn as_info(&self) -> &ResourceInfo<Self> {
&self.info &self.info
@ -439,15 +438,15 @@ pub enum RequestDeviceError {
UnsupportedFeature(wgt::Features), UnsupportedFeature(wgt::Features),
} }
pub enum AdapterInputs<'a, I> { pub enum AdapterInputs<'a, M: Marker> {
IdSet(&'a [I], fn(&I) -> Backend), IdSet(&'a [Id<M>]),
Mask(Backends, fn(Backend) -> I), Mask(Backends, fn(Backend) -> Option<Id<M>>),
} }
impl<I: Copy> AdapterInputs<'_, I> { impl<M: Marker> AdapterInputs<'_, M> {
fn find(&self, b: Backend) -> Option<I> { fn find(&self, b: Backend) -> Option<Option<Id<M>>> {
match *self { match *self {
Self::IdSet(ids, ref fun) => ids.iter().find(|id| fun(id) == b).copied(), Self::IdSet(ids) => Some(Some(ids.iter().find(|id| id.backend() == b).copied()?)),
Self::Mask(bits, ref fun) => { Self::Mask(bits, ref fun) => {
if bits.contains(b.into()) { if bits.contains(b.into()) {
Some(fun(b)) Some(fun(b))
@ -472,7 +471,7 @@ pub enum RequestAdapterError {
InvalidSurface(SurfaceId), InvalidSurface(SurfaceId),
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
/// # Safety /// # Safety
/// ///
/// - `display_handle` must be a valid object to create a surface upon. /// - `display_handle` must be a valid object to create a surface upon.
@ -483,7 +482,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
display_handle: raw_window_handle::RawDisplayHandle, display_handle: raw_window_handle::RawDisplayHandle,
window_handle: raw_window_handle::RawWindowHandle, window_handle: raw_window_handle::RawWindowHandle,
id_in: Input<G, markers::Surface>, id_in: Option<SurfaceId>,
) -> Result<SurfaceId, hal::InstanceError> { ) -> Result<SurfaceId, hal::InstanceError> {
profiling::scope!("Instance::create_surface"); profiling::scope!("Instance::create_surface");
@ -531,7 +530,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
raw: hal_surface, raw: hal_surface,
}; };
let (id, _) = self.surfaces.prepare::<G, _>(id_in).assign(surface); let (id, _) = self.surfaces.prepare(id_in).assign(surface);
Ok(id) Ok(id)
} }
@ -542,7 +541,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub unsafe fn instance_create_surface_metal( pub unsafe fn instance_create_surface_metal(
&self, &self,
layer: *mut std::ffi::c_void, layer: *mut std::ffi::c_void,
id_in: Input<G, markers::Surface>, id_in: Option<SurfaceId>,
) -> SurfaceId { ) -> SurfaceId {
profiling::scope!("Instance::create_surface_metal"); profiling::scope!("Instance::create_surface_metal");
@ -566,7 +565,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}, },
}; };
let (id, _) = self.surfaces.prepare::<G, _>(id_in).assign(surface); let (id, _) = self.surfaces.prepare(id_in).assign(surface);
id id
} }
@ -577,7 +576,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub unsafe fn instance_create_surface_from_visual( pub unsafe fn instance_create_surface_from_visual(
&self, &self,
visual: *mut std::ffi::c_void, visual: *mut std::ffi::c_void,
id_in: Input<G, markers::Surface>, id_in: Option<SurfaceId>,
) -> SurfaceId { ) -> SurfaceId {
profiling::scope!("Instance::instance_create_surface_from_visual"); profiling::scope!("Instance::instance_create_surface_from_visual");
@ -597,7 +596,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}, },
}; };
let (id, _) = self.surfaces.prepare::<G, _>(id_in).assign(surface); let (id, _) = self.surfaces.prepare(id_in).assign(surface);
id id
} }
@ -608,7 +607,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub unsafe fn instance_create_surface_from_surface_handle( pub unsafe fn instance_create_surface_from_surface_handle(
&self, &self,
surface_handle: *mut std::ffi::c_void, surface_handle: *mut std::ffi::c_void,
id_in: Input<G, markers::Surface>, id_in: Option<SurfaceId>,
) -> SurfaceId { ) -> SurfaceId {
profiling::scope!("Instance::instance_create_surface_from_surface_handle"); profiling::scope!("Instance::instance_create_surface_from_surface_handle");
@ -630,7 +629,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}, },
}; };
let (id, _) = self.surfaces.prepare::<G, _>(id_in).assign(surface); let (id, _) = self.surfaces.prepare(id_in).assign(surface);
id id
} }
@ -641,7 +640,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub unsafe fn instance_create_surface_from_swap_chain_panel( pub unsafe fn instance_create_surface_from_swap_chain_panel(
&self, &self,
swap_chain_panel: *mut std::ffi::c_void, swap_chain_panel: *mut std::ffi::c_void,
id_in: Input<G, markers::Surface>, id_in: Option<SurfaceId>,
) -> SurfaceId { ) -> SurfaceId {
profiling::scope!("Instance::instance_create_surface_from_swap_chain_panel"); profiling::scope!("Instance::instance_create_surface_from_swap_chain_panel");
@ -663,7 +662,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}, },
}; };
let (id, _) = self.surfaces.prepare::<G, _>(id_in).assign(surface); let (id, _) = self.surfaces.prepare(id_in).assign(surface);
id id
} }
@ -672,11 +671,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
api_log!("Surface::drop {id:?}"); api_log!("Surface::drop {id:?}");
fn unconfigure<G: GlobalIdentityHandlerFactory, A: HalApi>( fn unconfigure<A: HalApi>(global: &Global, surface: &AnySurface, present: &Presentation) {
global: &Global<G>,
surface: &AnySurface,
present: &Presentation,
) {
let hub = HalApi::hub(global); let hub = HalApi::hub(global);
if let Some(hal_surface) = surface.downcast_ref::<A>() { if let Some(hal_surface) = surface.downcast_ref::<A>() {
if let Some(device) = present.device.downcast_ref::<A>() { if let Some(device) = present.device.downcast_ref::<A>() {
@ -689,13 +684,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if let Some(surface) = Arc::into_inner(surface.unwrap()) { if let Some(surface) = Arc::into_inner(surface.unwrap()) {
if let Some(present) = surface.presentation.lock().take() { if let Some(present) = surface.presentation.lock().take() {
#[cfg(vulkan)] #[cfg(vulkan)]
unconfigure::<_, hal::api::Vulkan>(self, &surface.raw, &present); unconfigure::<hal::api::Vulkan>(self, &surface.raw, &present);
#[cfg(metal)] #[cfg(metal)]
unconfigure::<_, hal::api::Metal>(self, &surface.raw, &present); unconfigure::<hal::api::Metal>(self, &surface.raw, &present);
#[cfg(dx12)] #[cfg(dx12)]
unconfigure::<_, hal::api::Dx12>(self, &surface.raw, &present); unconfigure::<hal::api::Dx12>(self, &surface.raw, &present);
#[cfg(gles)] #[cfg(gles)]
unconfigure::<_, hal::api::Gles>(self, &surface.raw, &present); unconfigure::<hal::api::Gles>(self, &surface.raw, &present);
} }
self.instance.destroy_surface(surface); self.instance.destroy_surface(surface);
@ -708,7 +703,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self, &self,
_: A, _: A,
instance: &Option<A::Instance>, instance: &Option<A::Instance>,
inputs: &AdapterInputs<Input<G, markers::Adapter>>, inputs: &AdapterInputs<markers::Adapter>,
list: &mut Vec<AdapterId>, list: &mut Vec<AdapterId>,
) { ) {
let inst = match *instance { let inst = match *instance {
@ -727,15 +722,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
for raw in hal_adapters { for raw in hal_adapters {
let adapter = Adapter::new(raw); let adapter = Adapter::new(raw);
log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info); log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info);
let (id, _) = hub.adapters.prepare::<G, _>(id_backend).assign(adapter); let (id, _) = hub.adapters.prepare(id_backend).assign(adapter);
list.push(id); list.push(id);
} }
} }
pub fn enumerate_adapters( pub fn enumerate_adapters(&self, inputs: AdapterInputs<markers::Adapter>) -> Vec<AdapterId> {
&self,
inputs: AdapterInputs<Input<G, markers::Adapter>>,
) -> Vec<AdapterId> {
profiling::scope!("Instance::enumerate_adapters"); profiling::scope!("Instance::enumerate_adapters");
api_log!("Instance::enumerate_adapters"); api_log!("Instance::enumerate_adapters");
@ -766,7 +758,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
fn select<A: HalApi>( fn select<A: HalApi>(
&self, &self,
selected: &mut usize, selected: &mut usize,
new_id: Option<Input<G, markers::Adapter>>, new_id: Option<AdapterId>,
mut list: Vec<hal::ExposedAdapter<A>>, mut list: Vec<hal::ExposedAdapter<A>>,
) -> Option<AdapterId> { ) -> Option<AdapterId> {
match selected.checked_sub(list.len()) { match selected.checked_sub(list.len()) {
@ -777,10 +769,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
None => { None => {
let adapter = Adapter::new(list.swap_remove(*selected)); let adapter = Adapter::new(list.swap_remove(*selected));
log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info); log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info);
let (id, _) = HalApi::hub(self) let (id, _) = HalApi::hub(self).adapters.prepare(new_id).assign(adapter);
.adapters
.prepare::<G, _>(new_id.unwrap())
.assign(adapter);
Some(id) Some(id)
} }
} }
@ -789,22 +778,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn request_adapter( pub fn request_adapter(
&self, &self,
desc: &RequestAdapterOptions, desc: &RequestAdapterOptions,
inputs: AdapterInputs<Input<G, markers::Adapter>>, inputs: AdapterInputs<markers::Adapter>,
) -> Result<AdapterId, RequestAdapterError> { ) -> Result<AdapterId, RequestAdapterError> {
profiling::scope!("Instance::request_adapter"); profiling::scope!("Instance::request_adapter");
api_log!("Instance::request_adapter"); api_log!("Instance::request_adapter");
fn gather<A: HalApi, I: Copy>( fn gather<A: HalApi>(
_: A, _: A,
instance: Option<&A::Instance>, instance: Option<&A::Instance>,
inputs: &AdapterInputs<I>, inputs: &AdapterInputs<markers::Adapter>,
compatible_surface: Option<&Surface>, compatible_surface: Option<&Surface>,
force_software: bool, force_software: bool,
device_types: &mut Vec<wgt::DeviceType>, device_types: &mut Vec<wgt::DeviceType>,
) -> (Option<I>, Vec<hal::ExposedAdapter<A>>) { ) -> (Option<Id<markers::Adapter>>, Vec<hal::ExposedAdapter<A>>) {
let id = inputs.find(A::VARIANT); let id = inputs.find(A::VARIANT);
match instance { match (id, instance) {
Some(inst) if id.is_some() => { (Some(id), Some(inst)) => {
let mut adapters = unsafe { inst.enumerate_adapters() }; let mut adapters = unsafe { inst.enumerate_adapters() };
if force_software { if force_software {
adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu); adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu);
@ -824,7 +813,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device_types.extend(adapters.iter().map(|ad| ad.info.device_type)); device_types.extend(adapters.iter().map(|ad| ad.info.device_type));
(id, adapters) (id, adapters)
} }
_ => (id, Vec::new()), _ => (None, Vec::new()),
} }
} }
@ -955,11 +944,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub unsafe fn create_adapter_from_hal<A: HalApi>( pub unsafe fn create_adapter_from_hal<A: HalApi>(
&self, &self,
hal_adapter: hal::ExposedAdapter<A>, hal_adapter: hal::ExposedAdapter<A>,
input: Input<G, markers::Adapter>, input: Option<AdapterId>,
) -> AdapterId { ) -> AdapterId {
profiling::scope!("Instance::create_adapter_from_hal"); profiling::scope!("Instance::create_adapter_from_hal");
let fid = A::hub(self).adapters.prepare::<G, _>(input); let fid = A::hub(self).adapters.prepare(input);
let (id, _adapter): (_, Arc<Adapter<A>>) = match A::VARIANT { let (id, _adapter): (_, Arc<Adapter<A>>) = match A::VARIANT {
#[cfg(vulkan)] #[cfg(vulkan)]
@ -1066,21 +1055,21 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} }
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn adapter_request_device<A: HalApi>( pub fn adapter_request_device<A: HalApi>(
&self, &self,
adapter_id: AdapterId, adapter_id: AdapterId,
desc: &DeviceDescriptor, desc: &DeviceDescriptor,
trace_path: Option<&std::path::Path>, trace_path: Option<&std::path::Path>,
device_id_in: Input<G, markers::Device>, device_id_in: Option<DeviceId>,
queue_id_in: Input<G, markers::Queue>, queue_id_in: Option<QueueId>,
) -> (DeviceId, QueueId, Option<RequestDeviceError>) { ) -> (DeviceId, QueueId, Option<RequestDeviceError>) {
profiling::scope!("Adapter::request_device"); profiling::scope!("Adapter::request_device");
api_log!("Adapter::request_device"); api_log!("Adapter::request_device");
let hub = A::hub(self); let hub = A::hub(self);
let device_fid = hub.devices.prepare::<G, markers::Device>(device_id_in); let device_fid = hub.devices.prepare(device_id_in);
let queue_fid = hub.queues.prepare::<G, markers::Queue>(queue_id_in); let queue_fid = hub.queues.prepare(queue_id_in);
let error = loop { let error = loop {
let adapter = match hub.adapters.get(adapter_id) { let adapter = match hub.adapters.get(adapter_id) {
@ -1121,14 +1110,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal_device: OpenDevice<A>, hal_device: OpenDevice<A>,
desc: &DeviceDescriptor, desc: &DeviceDescriptor,
trace_path: Option<&std::path::Path>, trace_path: Option<&std::path::Path>,
device_id_in: Input<G, markers::Device>, device_id_in: Option<DeviceId>,
queue_id_in: Input<G, markers::Queue>, queue_id_in: Option<QueueId>,
) -> (DeviceId, QueueId, Option<RequestDeviceError>) { ) -> (DeviceId, QueueId, Option<RequestDeviceError>) {
profiling::scope!("Global::create_device_from_hal"); profiling::scope!("Global::create_device_from_hal");
let hub = A::hub(self); let hub = A::hub(self);
let devices_fid = hub.devices.prepare::<G, markers::Device>(device_id_in); let devices_fid = hub.devices.prepare(device_id_in);
let queues_fid = hub.queues.prepare::<G, markers::Queue>(queue_id_in); let queues_fid = hub.queues.prepare(queue_id_in);
let error = loop { let error = loop {
let adapter = match hub.adapters.get(adapter_id) { let adapter = match hub.adapters.get(adapter_id) {

View File

@ -289,7 +289,7 @@ define_backend_caller! { gfx_if_empty, gfx_if_empty_hidden, "empty" if all(
/// where the `device_create_buffer` method is defined like this: /// where the `device_create_buffer` method is defined like this:
/// ///
/// ```ignore /// ```ignore
/// impl<...> Global<...> { /// impl Global {
/// pub fn device_create_buffer<A: HalApi>(&self, ...) -> ... /// pub fn device_create_buffer<A: HalApi>(&self, ...) -> ...
/// { ... } /// { ... }
/// } /// }

View File

@ -22,10 +22,7 @@ use crate::{
device::{DeviceError, MissingDownlevelFlags, WaitIdleError}, device::{DeviceError, MissingDownlevelFlags, WaitIdleError},
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
hal_label, hal_label, id,
id::markers,
id::{SurfaceId, TextureId},
identity::{GlobalIdentityHandlerFactory, Input},
init_tracker::TextureInitTracker, init_tracker::TextureInitTracker,
resource::{self, ResourceInfo}, resource::{self, ResourceInfo},
snatch::Snatchable, snatch::Snatchable,
@ -43,7 +40,7 @@ const FRAME_TIMEOUT_MS: u32 = 1000;
pub(crate) struct Presentation { pub(crate) struct Presentation {
pub(crate) device: AnyDevice, pub(crate) device: AnyDevice,
pub(crate) config: wgt::SurfaceConfiguration<Vec<wgt::TextureFormat>>, pub(crate) config: wgt::SurfaceConfiguration<Vec<wgt::TextureFormat>>,
pub(crate) acquired_texture: Option<TextureId>, pub(crate) acquired_texture: Option<id::TextureId>,
} }
#[derive(Clone, Debug, Error)] #[derive(Clone, Debug, Error)]
@ -119,20 +116,20 @@ impl From<WaitIdleError> for ConfigureSurfaceError {
#[derive(Debug)] #[derive(Debug)]
pub struct SurfaceOutput { pub struct SurfaceOutput {
pub status: Status, pub status: Status,
pub texture_id: Option<TextureId>, pub texture_id: Option<id::TextureId>,
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
pub fn surface_get_current_texture<A: HalApi>( pub fn surface_get_current_texture<A: HalApi>(
&self, &self,
surface_id: SurfaceId, surface_id: id::SurfaceId,
texture_id_in: Input<G, markers::Texture>, texture_id_in: Option<id::TextureId>,
) -> Result<SurfaceOutput, SurfaceError> { ) -> Result<SurfaceOutput, SurfaceError> {
profiling::scope!("SwapChain::get_next_texture"); profiling::scope!("SwapChain::get_next_texture");
let hub = A::hub(self); let hub = A::hub(self);
let fid = hub.textures.prepare::<G, _>(texture_id_in); let fid = hub.textures.prepare(texture_id_in);
let surface = self let surface = self
.surfaces .surfaces
@ -281,7 +278,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn surface_present<A: HalApi>( pub fn surface_present<A: HalApi>(
&self, &self,
surface_id: SurfaceId, surface_id: id::SurfaceId,
) -> Result<Status, SurfaceError> { ) -> Result<Status, SurfaceError> {
profiling::scope!("SwapChain::present"); profiling::scope!("SwapChain::present");
@ -379,7 +376,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn surface_texture_discard<A: HalApi>( pub fn surface_texture_discard<A: HalApi>(
&self, &self,
surface_id: SurfaceId, surface_id: id::SurfaceId,
) -> Result<(), SurfaceError> { ) -> Result<(), SurfaceError> {
profiling::scope!("SwapChain::discard"); profiling::scope!("SwapChain::discard");

View File

@ -4,8 +4,8 @@ use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use wgt::Backend; use wgt::Backend;
use crate::{ use crate::{
id::{self, Id, Marker}, id::Id,
identity::{IdentityHandlerFactory, IdentityManager}, identity::IdentityManager,
resource::Resource, resource::Resource,
storage::{Element, InvalidId, Storage}, storage::{Element, InvalidId, Storage},
}; };
@ -44,16 +44,16 @@ pub struct Registry<T: Resource> {
} }
impl<T: Resource> Registry<T> { impl<T: Resource> Registry<T> {
pub(crate) fn new<F: IdentityHandlerFactory<T::Marker>>(backend: Backend, factory: &F) -> Self { pub(crate) fn new(backend: Backend) -> Self {
Self { Self {
identity: factory.spawn(), identity: Arc::new(IdentityManager::new()),
storage: RwLock::new(Storage::new()), storage: RwLock::new(Storage::new()),
backend, backend,
} }
} }
pub(crate) fn without_backend<F: IdentityHandlerFactory<T::Marker>>(factory: &F) -> Self { pub(crate) fn without_backend() -> Self {
Self::new(Backend::Empty, factory) Self::new(Backend::Empty)
} }
} }
@ -108,17 +108,14 @@ impl<T: Resource> FutureId<'_, T> {
} }
impl<T: Resource> Registry<T> { impl<T: Resource> Registry<T> {
pub(crate) fn prepare<F, U: Marker>(&self, id_in: F::Input) -> FutureId<T> pub(crate) fn prepare(&self, id_in: Option<Id<T::Marker>>) -> FutureId<T> {
where
F: IdentityHandlerFactory<U>,
T::Marker: id::transmute::Transmute<U>,
{
FutureId { FutureId {
id: if F::autogenerate_ids() { id: match id_in {
self.identity.process(self.backend) Some(id_in) => {
} else { self.identity.mark_as_used(id_in);
self.identity id_in
.mark_as_used(F::input_to_id(id_in).transmute()) }
None => self.identity.process(self.backend),
}, },
identity: self.identity.clone(), identity: self.identity.clone(),
data: &self.storage, data: &self.storage,

View File

@ -9,7 +9,7 @@ use crate::{
global::Global, global::Global,
hal_api::HalApi, hal_api::HalApi,
id::{AdapterId, BufferId, DeviceId, Id, Marker, SurfaceId, TextureId}, id::{AdapterId, BufferId, DeviceId, Id, Marker, SurfaceId, TextureId},
identity::{GlobalIdentityHandlerFactory, IdentityManager}, identity::IdentityManager,
init_tracker::{BufferInitTracker, TextureInitTracker}, init_tracker::{BufferInitTracker, TextureInitTracker},
resource, resource_log, resource, resource_log,
snatch::{ExclusiveSnatchGuard, SnatchGuard, Snatchable}, snatch::{ExclusiveSnatchGuard, SnatchGuard, Snatchable},
@ -926,7 +926,7 @@ impl<A: HalApi> Texture<A> {
} }
} }
impl<G: GlobalIdentityHandlerFactory> Global<G> { impl Global {
/// # Safety /// # Safety
/// ///
/// - The raw texture handle must not be manually destroyed /// - The raw texture handle must not be manually destroyed

View File

@ -28,7 +28,7 @@ use wgt::WasmNotSendSync;
const LABEL: &str = "label"; const LABEL: &str = "label";
pub struct ContextWgpuCore(wgc::global::Global<wgc::identity::IdentityManagerFactory>); pub struct ContextWgpuCore(wgc::global::Global);
impl Drop for ContextWgpuCore { impl Drop for ContextWgpuCore {
fn drop(&mut self) { fn drop(&mut self) {
@ -46,13 +46,7 @@ impl fmt::Debug for ContextWgpuCore {
impl ContextWgpuCore { impl ContextWgpuCore {
pub unsafe fn from_hal_instance<A: wgc::hal_api::HalApi>(hal_instance: A::Instance) -> Self { pub unsafe fn from_hal_instance<A: wgc::hal_api::HalApi>(hal_instance: A::Instance) -> Self {
Self(unsafe { Self(unsafe { wgc::global::Global::from_hal_instance::<A>("wgpu", hal_instance) })
wgc::global::Global::from_hal_instance::<A>(
"wgpu",
wgc::identity::IdentityManagerFactory,
hal_instance,
)
})
} }
/// # Safety /// # Safety
@ -63,25 +57,23 @@ impl ContextWgpuCore {
} }
pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self { pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self {
Self(unsafe { Self(unsafe { wgc::global::Global::from_instance(core_instance) })
wgc::global::Global::from_instance(wgc::identity::IdentityManagerFactory, core_instance)
})
} }
pub(crate) fn global(&self) -> &wgc::global::Global<wgc::identity::IdentityManagerFactory> { pub(crate) fn global(&self) -> &wgc::global::Global {
&self.0 &self.0
} }
pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec<wgc::id::AdapterId> { pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec<wgc::id::AdapterId> {
self.0 self.0
.enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| ())) .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| None))
} }
pub unsafe fn create_adapter_from_hal<A: wgc::hal_api::HalApi>( pub unsafe fn create_adapter_from_hal<A: wgc::hal_api::HalApi>(
&self, &self,
hal_adapter: hal::ExposedAdapter<A>, hal_adapter: hal::ExposedAdapter<A>,
) -> wgc::id::AdapterId { ) -> wgc::id::AdapterId {
unsafe { self.0.create_adapter_from_hal(hal_adapter, ()) } unsafe { self.0.create_adapter_from_hal(hal_adapter, None) }
} }
pub unsafe fn adapter_as_hal< pub unsafe fn adapter_as_hal<
@ -112,8 +104,8 @@ impl ContextWgpuCore {
hal_device, hal_device,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
trace_dir, trace_dir,
(), None,
(), None,
) )
}; };
if let Some(err) = error { if let Some(err) = error {
@ -141,7 +133,7 @@ impl ContextWgpuCore {
let descriptor = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec()); let descriptor = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec());
let (id, error) = unsafe { let (id, error) = unsafe {
self.0 self.0
.create_texture_from_hal::<A>(hal_texture, device.id, &descriptor, ()) .create_texture_from_hal::<A>(hal_texture, device.id, &descriptor, None)
}; };
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -169,7 +161,7 @@ impl ContextWgpuCore {
hal_buffer, hal_buffer,
device.id, device.id,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
(), None,
) )
}; };
if let Some(cause) = error { if let Some(cause) = error {
@ -509,11 +501,7 @@ impl crate::Context for ContextWgpuCore {
type PopErrorScopeFuture = Ready<Option<crate::Error>>; type PopErrorScopeFuture = Ready<Option<crate::Error>>;
fn init(instance_desc: wgt::InstanceDescriptor) -> Self { fn init(instance_desc: wgt::InstanceDescriptor) -> Self {
Self(wgc::global::Global::new( Self(wgc::global::Global::new("wgpu", instance_desc))
"wgpu",
wgc::identity::IdentityManagerFactory,
instance_desc,
))
} }
unsafe fn instance_create_surface( unsafe fn instance_create_surface(
@ -526,29 +514,29 @@ impl crate::Context for ContextWgpuCore {
raw_window_handle, raw_window_handle,
} => unsafe { } => unsafe {
self.0 self.0
.instance_create_surface(raw_display_handle, raw_window_handle, ())? .instance_create_surface(raw_display_handle, raw_window_handle, None)?
}, },
#[cfg(metal)] #[cfg(metal)]
SurfaceTargetUnsafe::CoreAnimationLayer(layer) => unsafe { SurfaceTargetUnsafe::CoreAnimationLayer(layer) => unsafe {
self.0.instance_create_surface_metal(layer, ()) self.0.instance_create_surface_metal(layer, None)
}, },
#[cfg(dx12)] #[cfg(dx12)]
SurfaceTargetUnsafe::CompositionVisual(visual) => unsafe { SurfaceTargetUnsafe::CompositionVisual(visual) => unsafe {
self.0.instance_create_surface_from_visual(visual, ()) self.0.instance_create_surface_from_visual(visual, None)
}, },
#[cfg(dx12)] #[cfg(dx12)]
SurfaceTargetUnsafe::SurfaceHandle(surface_handle) => unsafe { SurfaceTargetUnsafe::SurfaceHandle(surface_handle) => unsafe {
self.0 self.0
.instance_create_surface_from_surface_handle(surface_handle, ()) .instance_create_surface_from_surface_handle(surface_handle, None)
}, },
#[cfg(dx12)] #[cfg(dx12)]
SurfaceTargetUnsafe::SwapChainPanel(swap_chain_panel) => unsafe { SurfaceTargetUnsafe::SwapChainPanel(swap_chain_panel) => unsafe {
self.0 self.0
.instance_create_surface_from_swap_chain_panel(swap_chain_panel, ()) .instance_create_surface_from_swap_chain_panel(swap_chain_panel, None)
}, },
}; };
@ -571,7 +559,7 @@ impl crate::Context for ContextWgpuCore {
force_fallback_adapter: options.force_fallback_adapter, force_fallback_adapter: options.force_fallback_adapter,
compatible_surface: options.compatible_surface.map(|surface| surface.id.into()), compatible_surface: options.compatible_surface.map(|surface| surface.id.into()),
}, },
wgc::instance::AdapterInputs::Mask(wgt::Backends::all(), |_| ()), wgc::instance::AdapterInputs::Mask(wgt::Backends::all(), |_| None),
); );
ready(id.ok().map(|id| (id, ()))) ready(id.ok().map(|id| (id, ())))
} }
@ -587,8 +575,8 @@ impl crate::Context for ContextWgpuCore {
*adapter, *adapter,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
trace_dir, trace_dir,
(), None,
() None
)); ));
if let Some(err) = error { if let Some(err) = error {
return ready(Err(err.into())); return ready(Err(err.into()));
@ -741,7 +729,7 @@ impl crate::Context for ContextWgpuCore {
.lock() .lock()
.expect("Surface was not configured?"); .expect("Surface was not configured?");
match wgc::gfx_select!( match wgc::gfx_select!(
device_id => self.0.surface_get_current_texture(*surface, ()) device_id => self.0.surface_get_current_texture(*surface, None)
) { ) {
Ok(wgc::present::SurfaceOutput { status, texture_id }) => { Ok(wgc::present::SurfaceOutput { status, texture_id }) => {
let (id, data) = { let (id, data) = {
@ -861,7 +849,7 @@ impl crate::Context for ContextWgpuCore {
ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"), ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"),
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = wgc::gfx_select!(
device => self.0.device_create_shader_module(*device, &descriptor, source, ()) device => self.0.device_create_shader_module(*device, &descriptor, source, None)
); );
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -888,7 +876,7 @@ impl crate::Context for ContextWgpuCore {
shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() }, shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() },
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = wgc::gfx_select!(
device => self.0.device_create_shader_module_spirv(*device, &descriptor, Borrowed(&desc.source), ()) device => self.0.device_create_shader_module_spirv(*device, &descriptor, Borrowed(&desc.source), None)
); );
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -913,7 +901,7 @@ impl crate::Context for ContextWgpuCore {
entries: Borrowed(desc.entries), entries: Borrowed(desc.entries),
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = wgc::gfx_select!(
device => self.0.device_create_bind_group_layout(*device, &descriptor, ()) device => self.0.device_create_bind_group_layout(*device, &descriptor, None)
); );
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1027,7 +1015,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_bind_group( let (id, error) = wgc::gfx_select!(device => self.0.device_create_bind_group(
*device, *device,
&descriptor, &descriptor,
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1069,7 +1057,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_pipeline_layout( let (id, error) = wgc::gfx_select!(device => self.0.device_create_pipeline_layout(
*device, *device,
&descriptor, &descriptor,
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1104,8 +1092,8 @@ impl crate::Context for ContextWgpuCore {
let implicit_pipeline_ids = match desc.layout { let implicit_pipeline_ids = match desc.layout {
Some(_) => None, Some(_) => None,
None => Some(wgc::device::ImplicitPipelineIds { None => Some(wgc::device::ImplicitPipelineIds {
root_id: (), root_id: None,
group_ids: &[(); wgc::MAX_BIND_GROUPS], group_ids: &[None; wgc::MAX_BIND_GROUPS],
}), }),
}; };
let descriptor = pipe::RenderPipelineDescriptor { let descriptor = pipe::RenderPipelineDescriptor {
@ -1134,7 +1122,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_render_pipeline( let (id, error) = wgc::gfx_select!(device => self.0.device_create_render_pipeline(
*device, *device,
&descriptor, &descriptor,
(), None,
implicit_pipeline_ids implicit_pipeline_ids
)); ));
if let Some(cause) = error { if let Some(cause) = error {
@ -1163,8 +1151,8 @@ impl crate::Context for ContextWgpuCore {
let implicit_pipeline_ids = match desc.layout { let implicit_pipeline_ids = match desc.layout {
Some(_) => None, Some(_) => None,
None => Some(wgc::device::ImplicitPipelineIds { None => Some(wgc::device::ImplicitPipelineIds {
root_id: (), root_id: None,
group_ids: &[(); wgc::MAX_BIND_GROUPS], group_ids: &[None; wgc::MAX_BIND_GROUPS],
}), }),
}; };
let descriptor = pipe::ComputePipelineDescriptor { let descriptor = pipe::ComputePipelineDescriptor {
@ -1179,7 +1167,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_compute_pipeline( let (id, error) = wgc::gfx_select!(device => self.0.device_create_compute_pipeline(
*device, *device,
&descriptor, &descriptor,
(), None,
implicit_pipeline_ids implicit_pipeline_ids
)); ));
if let Some(cause) = error { if let Some(cause) = error {
@ -1210,7 +1198,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_buffer( let (id, error) = wgc::gfx_select!(device => self.0.device_create_buffer(
*device, *device,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1238,7 +1226,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_texture( let (id, error) = wgc::gfx_select!(device => self.0.device_create_texture(
*device, *device,
&wgt_desc, &wgt_desc,
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1283,7 +1271,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_sampler( let (id, error) = wgc::gfx_select!(device => self.0.device_create_sampler(
*device, *device,
&descriptor, &descriptor,
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1305,7 +1293,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_query_set( let (id, error) = wgc::gfx_select!(device => self.0.device_create_query_set(
*device, *device,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error_nolabel(&device_data.error_sink, cause, "Device::create_query_set"); self.handle_error_nolabel(&device_data.error_sink, cause, "Device::create_query_set");
@ -1321,7 +1309,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_command_encoder( let (id, error) = wgc::gfx_select!(device => self.0.device_create_command_encoder(
*device, *device,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
() None
)); ));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1520,7 +1508,7 @@ impl crate::Context for ContextWgpuCore {
}, },
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = wgc::gfx_select!(
texture => self.0.texture_create_view(*texture, &descriptor, ()) texture => self.0.texture_create_view(*texture, &descriptor, None)
); );
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
@ -1654,7 +1642,7 @@ impl crate::Context for ContextWgpuCore {
_pipeline_data: &Self::ComputePipelineData, _pipeline_data: &Self::ComputePipelineData,
index: u32, index: u32,
) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) {
let (id, error) = wgc::gfx_select!(*pipeline => self.0.compute_pipeline_get_bind_group_layout(*pipeline, index, ())); let (id, error) = wgc::gfx_select!(*pipeline => self.0.compute_pipeline_get_bind_group_layout(*pipeline, index, None));
if let Some(err) = error { if let Some(err) = error {
panic!("Error reflecting bind group {index}: {err}"); panic!("Error reflecting bind group {index}: {err}");
} }
@ -1667,7 +1655,7 @@ impl crate::Context for ContextWgpuCore {
_pipeline_data: &Self::RenderPipelineData, _pipeline_data: &Self::RenderPipelineData,
index: u32, index: u32,
) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) {
let (id, error) = wgc::gfx_select!(*pipeline => self.0.render_pipeline_get_bind_group_layout(*pipeline, index, ())); let (id, error) = wgc::gfx_select!(*pipeline => self.0.render_pipeline_get_bind_group_layout(*pipeline, index, None));
if let Some(err) = error { if let Some(err) = error {
panic!("Error reflecting bind group {index}: {err}"); panic!("Error reflecting bind group {index}: {err}");
} }
@ -2064,7 +2052,7 @@ impl crate::Context for ContextWgpuCore {
let (id, error) = wgc::gfx_select!(encoder_data.parent() => self.0.render_bundle_encoder_finish( let (id, error) = wgc::gfx_select!(encoder_data.parent() => self.0.render_bundle_encoder_finish(
encoder_data, encoder_data,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
() None
)); ));
if let Some(err) = error { if let Some(err) = error {
self.handle_error_fatal(err, "RenderBundleEncoder::finish"); self.handle_error_fatal(err, "RenderBundleEncoder::finish");
@ -2118,7 +2106,7 @@ impl crate::Context for ContextWgpuCore {
size: wgt::BufferSize, size: wgt::BufferSize,
) -> Option<Box<dyn crate::context::QueueWriteBuffer>> { ) -> Option<Box<dyn crate::context::QueueWriteBuffer>> {
match wgc::gfx_select!( match wgc::gfx_select!(
*queue => self.0.queue_create_staging_buffer(*queue, size, ()) *queue => self.0.queue_create_staging_buffer(*queue, size, None)
) { ) {
Ok((buffer_id, ptr)) => Some(Box::new(QueueWriteBuffer { Ok((buffer_id, ptr)) => Some(Box::new(QueueWriteBuffer {
buffer_id, buffer_id,