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

View File

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

View File

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

View File

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

View File

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

View File

@ -118,8 +118,8 @@ pub fn op_webgpu_create_compute_pipeline(
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
Some(wgpu_core::device::ImplicitPipelineIds {
root_id: (),
group_ids: &[(); MAX_BIND_GROUPS],
root_id: None,
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(
device,
&descriptor,
(),
None,
implicit_pipelines
));
@ -159,7 +159,7 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
.get::<WebGpuComputePipeline>(compute_pipeline_rid)?;
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 =
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::Auto(GPUAutoLayoutMode::Auto) => {
Some(wgpu_core::device::ImplicitPipelineIds {
root_id: (),
group_ids: &[(); MAX_BIND_GROUPS],
root_id: None,
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(
device,
&descriptor,
(),
None,
implicit_pipelines
));
@ -425,7 +425,7 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
.get::<WebGpuRenderPipeline>(render_pipeline_rid)?;
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 =
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(
device,
&descriptor,
()
None
) => state, WebGpuSampler)
}

View File

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

View File

@ -75,6 +75,7 @@ pub fn op_webgpu_surface_configure(
present_mode: args.present_mode.unwrap_or_default(),
alpha_mode: args.alpha_mode,
view_formats: args.view_formats,
desired_maximum_frame_latency: 2,
};
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 = 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 {
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(
device,
&descriptor,
()
None
));
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(
texture,
&descriptor,
()
None
) => state, WebGpuTextureView)
}

View File

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

View File

@ -12,21 +12,6 @@ use wgc::device::trace;
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 {
fn encode_commands<A: wgc::hal_api::HalApi>(
&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>(
&self,
encoder: wgc::id::CommandEncoderId,
@ -169,7 +154,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::CreateBuffer(id, desc) => {
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 {
panic!("{e}");
}
@ -182,7 +167,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::CreateTexture(id, desc) => {
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 {
panic!("{e}");
}
@ -199,7 +184,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
desc,
} => {
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 {
panic!("{e}");
}
@ -209,7 +194,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::CreateSampler(id, desc) => {
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 {
panic!("{e}");
}
@ -219,13 +204,13 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::GetSurfaceTexture { id, parent_id } => {
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()
.texture_id
.unwrap();
}
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 {
panic!("{e}");
}
@ -235,7 +220,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::CreatePipelineLayout(id, desc) => {
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 {
panic!("{e}");
}
@ -245,7 +230,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::CreateBindGroup(id, desc) => {
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 {
panic!("{e}");
}
@ -264,7 +249,8 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
} else {
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 {
println!("shader compilation error:\n---{code}\n---\n{e}");
}
@ -282,11 +268,11 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
implicit_context
.as_ref()
.map(|ic| wgc::device::ImplicitPipelineIds {
root_id: ic.root_id,
group_ids: &ic.group_ids,
root_id: Some(ic.root_id),
group_ids: wgc::id::as_option_slice(&ic.group_ids),
});
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 {
panic!("{e}");
}
@ -304,11 +290,11 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
implicit_context
.as_ref()
.map(|ic| wgc::device::ImplicitPipelineIds {
root_id: ic.root_id,
group_ids: &ic.group_ids,
root_id: Some(ic.root_id),
group_ids: wgc::id::as_option_slice(&ic.group_ids),
});
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 {
panic!("{e}");
}
@ -322,7 +308,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
let (_, error) = self.render_bundle_encoder_finish::<A>(
bundle,
&wgt::RenderBundleDescriptor { label: desc.label },
id,
Some(id),
);
if let Some(e) = error {
panic!("{e}");
@ -333,7 +319,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
}
Action::CreateQuerySet { id, desc } => {
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 {
panic!("{e}");
}
@ -375,7 +361,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
let (encoder, error) = self.device_create_command_encoder::<A>(
device,
&wgt::CommandEncoderDescriptor { label: None },
comb_manager.process(device.backend()).transmute(),
Some(comb_manager.process(device.backend()).transmute()),
);
if let Some(e) = error {
panic!("{e}");

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ use crate::{
global::Global,
hal_api::HalApi,
id::{self, Id},
identity::GlobalIdentityHandlerFactory,
init_tracker::MemoryInitKind,
resource::QuerySet,
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>(
&self,
command_encoder_id: id::CommandEncoderId,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
use core::fmt;
use std::error::Error;
use crate::{gfx_select, global::Global, identity::IdentityManagerFactory};
use crate::{gfx_select, global::Global};
pub struct ErrorFormatter<'a> {
writer: &'a mut dyn fmt::Write,
global: &'a Global<IdentityManagerFactory>,
global: &'a Global,
}
impl<'a> ErrorFormatter<'a> {
@ -94,7 +94,7 @@ pub trait PrettyError: Error + Sized {
pub fn format_pretty_any(
writer: &mut dyn fmt::Write,
global: &Global<IdentityManagerFactory>,
global: &Global,
error: &(dyn Error + 'static),
) {
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 crate::{
hal_api::HalApi,
hub::{HubReport, Hubs},
identity::GlobalIdentityHandlerFactory,
instance::{Instance, Surface},
registry::{Registry, RegistryReport},
resource_log,
@ -44,38 +43,31 @@ impl GlobalReport {
}
}
pub struct Global<G: GlobalIdentityHandlerFactory> {
pub struct Global {
pub instance: Instance,
pub surfaces: Registry<Surface>,
pub(crate) hubs: Hubs,
_phantom: PhantomData<G>,
}
impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn new(name: &str, factory: G, instance_desc: wgt::InstanceDescriptor) -> Self {
impl Global {
pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self {
profiling::scope!("Global::new");
Self {
instance: Instance::new(name, instance_desc),
surfaces: Registry::without_backend(&factory),
hubs: Hubs::new(&factory),
_phantom: PhantomData,
surfaces: Registry::without_backend(),
hubs: Hubs::new(),
}
}
/// # Safety
///
/// Refer to the creation of wgpu-hal Instance for every backend.
pub unsafe fn from_hal_instance<A: HalApi>(
name: &str,
factory: G,
hal_instance: A::Instance,
) -> Self {
pub unsafe fn from_hal_instance<A: HalApi>(name: &str, hal_instance: A::Instance) -> Self {
profiling::scope!("Global::new");
Self {
instance: A::create_instance_from_hal(name, hal_instance),
surfaces: Registry::without_backend(&factory),
hubs: Hubs::new(&factory),
_phantom: PhantomData,
surfaces: Registry::without_backend(),
hubs: Hubs::new(),
}
}
@ -89,13 +81,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// # Safety
///
/// - 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");
Self {
instance,
surfaces: Registry::without_backend(&factory),
hubs: Hubs::new(&factory),
_phantom: PhantomData,
surfaces: Registry::without_backend(),
hubs: Hubs::new(),
}
}
@ -137,7 +128,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
impl Drop for Global {
fn drop(&mut self) {
profiling::scope!("Global::drop");
resource_log!("Global::drop");
@ -175,7 +166,7 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
}
#[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) {}
test_internal(global)
}

View File

@ -3,7 +3,6 @@ use wgt::{Backend, WasmNotSendSync};
use crate::{
global::Global,
hub::Hub,
identity::GlobalIdentityHandlerFactory,
instance::{HalSurface, Instance, Surface},
};
@ -11,7 +10,7 @@ pub trait HalApi: hal::Api + 'static + WasmNotSendSync {
const VARIANT: Backend;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> 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>>;
}
@ -23,7 +22,7 @@ impl HalApi for hal::api::Empty {
fn instance_as_hal(_: &Instance) -> Option<&Self::Instance> {
unimplemented!("called empty api")
}
fn hub<G: GlobalIdentityHandlerFactory>(_: &Global<G>) -> &Hub<Self> {
fn hub(_: &Global) -> &Hub<Self> {
unimplemented!("called empty api")
}
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> {
instance.vulkan.as_ref()
}
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.vulkan
}
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> {
instance.metal.as_ref()
}
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.metal
}
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> {
instance.dx12.as_ref()
}
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.dx12
}
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> {
instance.gl.as_ref()
}
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self> {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.gl
}
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:
```ignore
impl<G: GlobalIdentityHandlerFactory> Global<G> {
impl Global {
/* ... */
pub fn device_create_buffer<A: HalApi>(
&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.
Producing true identifiers from `id_in` values is the job of an
[`crate::identity::IdentityManager`], but only if the `IdentityHandlerFactory`
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.
[`crate::identity::IdentityManager`] or ids will be received from outside through `Option<Id>` arguments.
## Id allocation and streaming
@ -105,7 +97,6 @@ as much, allowing subsequent operations using that id to be properly
flagged as errors as well.
[`gfx_select`]: crate::gfx_select
[`Input`]: crate::identity::IdentityHandlerFactory::Input
[`process`]: crate::identity::IdentityManager::process
[`Id<R>`]: crate::id::Id
[wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E
@ -118,7 +109,6 @@ use crate::{
command::{CommandBuffer, RenderBundle},
device::{queue::Queue, Device},
hal_api::HalApi,
identity::GlobalIdentityHandlerFactory,
instance::{Adapter, HalSurface, Surface},
pipeline::{ComputePipeline, RenderPipeline, ShaderModule},
registry::{Registry, RegistryReport},
@ -199,25 +189,25 @@ pub struct Hub<A: HalApi> {
}
impl<A: HalApi> Hub<A> {
fn new<F: GlobalIdentityHandlerFactory>(factory: &F) -> Self {
fn new() -> Self {
Self {
adapters: Registry::new(A::VARIANT, factory),
devices: Registry::new(A::VARIANT, factory),
queues: Registry::new(A::VARIANT, factory),
pipeline_layouts: Registry::new(A::VARIANT, factory),
shader_modules: Registry::new(A::VARIANT, factory),
bind_group_layouts: Registry::new(A::VARIANT, factory),
bind_groups: Registry::new(A::VARIANT, factory),
command_buffers: Registry::new(A::VARIANT, factory),
render_bundles: Registry::new(A::VARIANT, factory),
render_pipelines: Registry::new(A::VARIANT, factory),
compute_pipelines: Registry::new(A::VARIANT, factory),
query_sets: Registry::new(A::VARIANT, factory),
buffers: Registry::new(A::VARIANT, factory),
staging_buffers: Registry::new(A::VARIANT, factory),
textures: Registry::new(A::VARIANT, factory),
texture_views: Registry::new(A::VARIANT, factory),
samplers: Registry::new(A::VARIANT, factory),
adapters: Registry::new(A::VARIANT),
devices: Registry::new(A::VARIANT),
queues: Registry::new(A::VARIANT),
pipeline_layouts: Registry::new(A::VARIANT),
shader_modules: Registry::new(A::VARIANT),
bind_group_layouts: Registry::new(A::VARIANT),
bind_groups: Registry::new(A::VARIANT),
command_buffers: Registry::new(A::VARIANT),
render_bundles: Registry::new(A::VARIANT),
render_pipelines: Registry::new(A::VARIANT),
compute_pipelines: Registry::new(A::VARIANT),
query_sets: Registry::new(A::VARIANT),
buffers: Registry::new(A::VARIANT),
staging_buffers: Registry::new(A::VARIANT),
textures: Registry::new(A::VARIANT),
texture_views: Registry::new(A::VARIANT),
samplers: Registry::new(A::VARIANT),
}
}
@ -313,18 +303,18 @@ pub struct Hubs {
}
impl Hubs {
pub(crate) fn new<F: GlobalIdentityHandlerFactory>(factory: &F) -> Self {
pub(crate) fn new() -> Self {
Self {
#[cfg(vulkan)]
vulkan: Hub::new(factory),
vulkan: Hub::new(),
#[cfg(metal)]
metal: Hub::new(factory),
metal: Hub::new(),
#[cfg(dx12)]
dx12: Hub::new(factory),
dx12: Hub::new(),
#[cfg(gles)]
gl: Hub::new(factory),
gl: Hub::new(),
#[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.
pub fn into_raw_slice<T: Marker>(ids: &[Id<T>]) -> &[RawId] {
// SAFETY: Any Id<T> is repr(transparent) over `RawId`.
/// Coerce a slice of identifiers into a slice of optional raw identifiers.
///
/// 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()) }
}

View File

@ -2,10 +2,10 @@ use parking_lot::Mutex;
use wgt::Backend;
use crate::{
id::{self, Id, Marker},
id::{Id, Marker},
Epoch, FastHashMap, Index,
};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use std::{fmt::Debug, marker::PhantomData};
/// 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]
fn test_epoch_end_of_life() {
use crate::id;
let man = IdentityManager::<id::markers::Buffer>::new();
let forced_id = man.mark_as_used(id::BufferId::zip(0, 1, Backend::Empty));
assert_eq!(forced_id.unzip().0, 0);

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ use wgt::WasmNotSendSync;
const LABEL: &str = "label";
pub struct ContextWgpuCore(wgc::global::Global<wgc::identity::IdentityManagerFactory>);
pub struct ContextWgpuCore(wgc::global::Global);
impl Drop for ContextWgpuCore {
fn drop(&mut self) {
@ -46,13 +46,7 @@ impl fmt::Debug for ContextWgpuCore {
impl ContextWgpuCore {
pub unsafe fn from_hal_instance<A: wgc::hal_api::HalApi>(hal_instance: A::Instance) -> Self {
Self(unsafe {
wgc::global::Global::from_hal_instance::<A>(
"wgpu",
wgc::identity::IdentityManagerFactory,
hal_instance,
)
})
Self(unsafe { wgc::global::Global::from_hal_instance::<A>("wgpu", hal_instance) })
}
/// # Safety
@ -63,25 +57,23 @@ impl ContextWgpuCore {
}
pub unsafe fn from_core_instance(core_instance: wgc::instance::Instance) -> Self {
Self(unsafe {
wgc::global::Global::from_instance(wgc::identity::IdentityManagerFactory, core_instance)
})
Self(unsafe { wgc::global::Global::from_instance(core_instance) })
}
pub(crate) fn global(&self) -> &wgc::global::Global<wgc::identity::IdentityManagerFactory> {
pub(crate) fn global(&self) -> &wgc::global::Global {
&self.0
}
pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec<wgc::id::AdapterId> {
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>(
&self,
hal_adapter: hal::ExposedAdapter<A>,
) -> 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<
@ -112,8 +104,8 @@ impl ContextWgpuCore {
hal_device,
&desc.map_label(|l| l.map(Borrowed)),
trace_dir,
(),
(),
None,
None,
)
};
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 (id, error) = unsafe {
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 {
self.handle_error(
@ -169,7 +161,7 @@ impl ContextWgpuCore {
hal_buffer,
device.id,
&desc.map_label(|l| l.map(Borrowed)),
(),
None,
)
};
if let Some(cause) = error {
@ -509,11 +501,7 @@ impl crate::Context for ContextWgpuCore {
type PopErrorScopeFuture = Ready<Option<crate::Error>>;
fn init(instance_desc: wgt::InstanceDescriptor) -> Self {
Self(wgc::global::Global::new(
"wgpu",
wgc::identity::IdentityManagerFactory,
instance_desc,
))
Self(wgc::global::Global::new("wgpu", instance_desc))
}
unsafe fn instance_create_surface(
@ -526,29 +514,29 @@ impl crate::Context for ContextWgpuCore {
raw_window_handle,
} => unsafe {
self.0
.instance_create_surface(raw_display_handle, raw_window_handle, ())?
.instance_create_surface(raw_display_handle, raw_window_handle, None)?
},
#[cfg(metal)]
SurfaceTargetUnsafe::CoreAnimationLayer(layer) => unsafe {
self.0.instance_create_surface_metal(layer, ())
self.0.instance_create_surface_metal(layer, None)
},
#[cfg(dx12)]
SurfaceTargetUnsafe::CompositionVisual(visual) => unsafe {
self.0.instance_create_surface_from_visual(visual, ())
self.0.instance_create_surface_from_visual(visual, None)
},
#[cfg(dx12)]
SurfaceTargetUnsafe::SurfaceHandle(surface_handle) => unsafe {
self.0
.instance_create_surface_from_surface_handle(surface_handle, ())
.instance_create_surface_from_surface_handle(surface_handle, None)
},
#[cfg(dx12)]
SurfaceTargetUnsafe::SwapChainPanel(swap_chain_panel) => unsafe {
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,
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, ())))
}
@ -587,8 +575,8 @@ impl crate::Context for ContextWgpuCore {
*adapter,
&desc.map_label(|l| l.map(Borrowed)),
trace_dir,
(),
()
None,
None
));
if let Some(err) = error {
return ready(Err(err.into()));
@ -741,7 +729,7 @@ impl crate::Context for ContextWgpuCore {
.lock()
.expect("Surface was not configured?");
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 }) => {
let (id, data) = {
@ -861,7 +849,7 @@ impl crate::Context for ContextWgpuCore {
ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"),
};
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 {
self.handle_error(
@ -888,7 +876,7 @@ impl crate::Context for ContextWgpuCore {
shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() },
};
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 {
self.handle_error(
@ -913,7 +901,7 @@ impl crate::Context for ContextWgpuCore {
entries: Borrowed(desc.entries),
};
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 {
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(
*device,
&descriptor,
()
None
));
if let Some(cause) = 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(
*device,
&descriptor,
()
None
));
if let Some(cause) = error {
self.handle_error(
@ -1104,8 +1092,8 @@ impl crate::Context for ContextWgpuCore {
let implicit_pipeline_ids = match desc.layout {
Some(_) => None,
None => Some(wgc::device::ImplicitPipelineIds {
root_id: (),
group_ids: &[(); wgc::MAX_BIND_GROUPS],
root_id: None,
group_ids: &[None; wgc::MAX_BIND_GROUPS],
}),
};
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(
*device,
&descriptor,
(),
None,
implicit_pipeline_ids
));
if let Some(cause) = error {
@ -1163,8 +1151,8 @@ impl crate::Context for ContextWgpuCore {
let implicit_pipeline_ids = match desc.layout {
Some(_) => None,
None => Some(wgc::device::ImplicitPipelineIds {
root_id: (),
group_ids: &[(); wgc::MAX_BIND_GROUPS],
root_id: None,
group_ids: &[None; wgc::MAX_BIND_GROUPS],
}),
};
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(
*device,
&descriptor,
(),
None,
implicit_pipeline_ids
));
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(
*device,
&desc.map_label(|l| l.map(Borrowed)),
()
None
));
if let Some(cause) = 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(
*device,
&wgt_desc,
()
None
));
if let Some(cause) = 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(
*device,
&descriptor,
()
None
));
if let Some(cause) = 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(
*device,
&desc.map_label(|l| l.map(Borrowed)),
()
None
));
if let Some(cause) = error {
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(
*device,
&desc.map_label(|l| l.map(Borrowed)),
()
None
));
if let Some(cause) = error {
self.handle_error(
@ -1520,7 +1508,7 @@ impl crate::Context for ContextWgpuCore {
},
};
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 {
self.handle_error(
@ -1654,7 +1642,7 @@ impl crate::Context for ContextWgpuCore {
_pipeline_data: &Self::ComputePipelineData,
index: u32,
) -> (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 {
panic!("Error reflecting bind group {index}: {err}");
}
@ -1667,7 +1655,7 @@ impl crate::Context for ContextWgpuCore {
_pipeline_data: &Self::RenderPipelineData,
index: u32,
) -> (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 {
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(
encoder_data,
&desc.map_label(|l| l.map(Borrowed)),
()
None
));
if let Some(err) = error {
self.handle_error_fatal(err, "RenderBundleEncoder::finish");
@ -2118,7 +2106,7 @@ impl crate::Context for ContextWgpuCore {
size: wgt::BufferSize,
) -> Option<Box<dyn crate::context::QueueWriteBuffer>> {
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 {
buffer_id,