mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
Core adapter no longer uses any generics
This commit is contained in:
parent
04cadfb369
commit
3181251577
@ -530,10 +530,10 @@ impl<A: HalApi> Drop for BindGroupLayout<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(BindGroupLayout);
|
||||
crate::impl_resource_type_generic!(BindGroupLayout);
|
||||
crate::impl_labeled!(BindGroupLayout);
|
||||
crate::impl_parent_device!(BindGroupLayout);
|
||||
crate::impl_storage_item!(BindGroupLayout);
|
||||
crate::impl_storage_item_generic!(BindGroupLayout);
|
||||
|
||||
impl<A: HalApi> BindGroupLayout<A> {
|
||||
pub(crate) fn raw(&self) -> &dyn hal::DynBindGroupLayout {
|
||||
@ -761,10 +761,10 @@ impl<A: HalApi> PipelineLayout<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(PipelineLayout);
|
||||
crate::impl_resource_type_generic!(PipelineLayout);
|
||||
crate::impl_labeled!(PipelineLayout);
|
||||
crate::impl_parent_device!(PipelineLayout);
|
||||
crate::impl_storage_item!(PipelineLayout);
|
||||
crate::impl_storage_item_generic!(PipelineLayout);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
@ -985,10 +985,10 @@ impl<A: HalApi> BindGroup<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(BindGroup);
|
||||
crate::impl_resource_type_generic!(BindGroup);
|
||||
crate::impl_labeled!(BindGroup);
|
||||
crate::impl_parent_device!(BindGroup);
|
||||
crate::impl_storage_item!(BindGroup);
|
||||
crate::impl_storage_item_generic!(BindGroup);
|
||||
crate::impl_trackable!(BindGroup);
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
|
@ -1146,10 +1146,10 @@ impl<A: HalApi> RenderBundle<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(RenderBundle);
|
||||
crate::impl_resource_type_generic!(RenderBundle);
|
||||
crate::impl_labeled!(RenderBundle);
|
||||
crate::impl_parent_device!(RenderBundle);
|
||||
crate::impl_storage_item!(RenderBundle);
|
||||
crate::impl_storage_item_generic!(RenderBundle);
|
||||
crate::impl_trackable!(RenderBundle);
|
||||
|
||||
/// A render bundle's current index buffer state.
|
||||
|
@ -526,10 +526,10 @@ impl<A: HalApi> CommandBuffer<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(CommandBuffer);
|
||||
crate::impl_resource_type_generic!(CommandBuffer);
|
||||
crate::impl_labeled!(CommandBuffer);
|
||||
crate::impl_parent_device!(CommandBuffer);
|
||||
crate::impl_storage_item!(CommandBuffer);
|
||||
crate::impl_storage_item_generic!(CommandBuffer);
|
||||
|
||||
/// A stream of commands for a render pass or compute pass.
|
||||
///
|
||||
|
@ -56,7 +56,7 @@ impl Global {
|
||||
) -> Result<wgt::SurfaceCapabilities, instance::GetSurfaceSupportError> {
|
||||
profiling::scope!("Surface::get_capabilities");
|
||||
self.fetch_adapter_and_surface::<A, _, _>(surface_id, adapter_id, |adapter, surface| {
|
||||
let mut hal_caps = surface.get_capabilities::<A>(A::VARIANT, adapter)?;
|
||||
let mut hal_caps = surface.get_capabilities(adapter)?;
|
||||
|
||||
hal_caps.formats.sort_by_key(|f| !f.is_srgb());
|
||||
|
||||
@ -73,7 +73,7 @@ impl Global {
|
||||
|
||||
fn fetch_adapter_and_surface<
|
||||
A: HalApi,
|
||||
F: FnOnce(&Adapter<A>, &Surface) -> Result<B, instance::GetSurfaceSupportError>,
|
||||
F: FnOnce(&Adapter, &Surface) -> Result<B, instance::GetSurfaceSupportError>,
|
||||
B,
|
||||
>(
|
||||
&self,
|
||||
@ -1908,7 +1908,7 @@ impl Global {
|
||||
Err(_) => break 'error E::InvalidSurface,
|
||||
};
|
||||
|
||||
let caps = match surface.get_capabilities::<A>(A::VARIANT, &device.adapter) {
|
||||
let caps = match surface.get_capabilities(&device.adapter) {
|
||||
Ok(caps) => caps,
|
||||
Err(_) => break 'error E::UnsupportedQueueFamily,
|
||||
};
|
||||
|
@ -55,7 +55,7 @@ impl<A: HalApi> Queue<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(Queue);
|
||||
crate::impl_resource_type_generic!(Queue);
|
||||
// TODO: https://github.com/gfx-rs/wgpu/issues/4014
|
||||
impl<A: HalApi> Labeled for Queue<A> {
|
||||
fn label(&self) -> &str {
|
||||
@ -63,7 +63,7 @@ impl<A: HalApi> Labeled for Queue<A> {
|
||||
}
|
||||
}
|
||||
crate::impl_parent_device!(Queue);
|
||||
crate::impl_storage_item!(Queue);
|
||||
crate::impl_storage_item_generic!(Queue);
|
||||
|
||||
impl<A: HalApi> Drop for Queue<A> {
|
||||
fn drop(&mut self) {
|
||||
|
@ -79,7 +79,7 @@ use super::{
|
||||
/// trackers should be locked only when needed for the shortest time possible
|
||||
pub struct Device<A: HalApi> {
|
||||
raw: ManuallyDrop<Box<dyn hal::DynDevice>>,
|
||||
pub(crate) adapter: Arc<Adapter<A>>,
|
||||
pub(crate) adapter: Arc<Adapter>,
|
||||
pub(crate) queue: OnceCell<Weak<Queue<A>>>,
|
||||
queue_to_drop: OnceCell<Box<dyn hal::DynQueue>>,
|
||||
pub(crate) zero_buffer: ManuallyDrop<Box<dyn hal::DynBuffer>>,
|
||||
@ -222,7 +222,7 @@ impl<A: HalApi> Device<A> {
|
||||
pub(crate) fn new(
|
||||
raw_device: Box<dyn hal::DynDevice>,
|
||||
raw_queue: &dyn hal::DynQueue,
|
||||
adapter: &Arc<Adapter<A>>,
|
||||
adapter: &Arc<Adapter>,
|
||||
desc: &DeviceDescriptor,
|
||||
trace_path: Option<&std::path::Path>,
|
||||
instance_flags: wgt::InstanceFlags,
|
||||
@ -3656,6 +3656,6 @@ impl<A: HalApi> Device<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(Device);
|
||||
crate::impl_resource_type_generic!(Device);
|
||||
crate::impl_labeled!(Device);
|
||||
crate::impl_storage_item!(Device);
|
||||
crate::impl_storage_item_generic!(Device);
|
||||
|
@ -170,7 +170,7 @@ impl HubReport {
|
||||
///
|
||||
/// [`A::hub(global)`]: HalApi::hub
|
||||
pub struct Hub<A: HalApi> {
|
||||
pub(crate) adapters: Registry<Adapter<A>>,
|
||||
pub(crate) adapters: Registry<Adapter>,
|
||||
pub(crate) devices: Registry<Device<A>>,
|
||||
pub(crate) queues: Registry<Queue<A>>,
|
||||
pub(crate) pipeline_layouts: Registry<PipelineLayout<A>>,
|
||||
|
@ -136,21 +136,19 @@ impl crate::storage::StorageItem for Surface {
|
||||
}
|
||||
|
||||
impl Surface {
|
||||
pub fn get_capabilities<A: HalApi>(
|
||||
pub fn get_capabilities(
|
||||
&self,
|
||||
backend: Backend,
|
||||
adapter: &Adapter<A>,
|
||||
adapter: &Adapter,
|
||||
) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> {
|
||||
self.get_capabilities_with_raw(backend, &adapter.raw)
|
||||
self.get_capabilities_with_raw(&adapter.raw)
|
||||
}
|
||||
|
||||
pub fn get_capabilities_with_raw(
|
||||
&self,
|
||||
backend: Backend,
|
||||
adapter: &hal::DynExposedAdapter,
|
||||
) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> {
|
||||
let suf = self
|
||||
.raw(backend)
|
||||
.raw(adapter.backend())
|
||||
.ok_or(GetSurfaceSupportError::Unsupported)?;
|
||||
profiling::scope!("surface_capabilities");
|
||||
let caps = unsafe { adapter.adapter.surface_capabilities(suf) }
|
||||
@ -166,12 +164,11 @@ impl Surface {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Adapter<A: HalApi> {
|
||||
pub struct Adapter {
|
||||
pub(crate) raw: hal::DynExposedAdapter,
|
||||
_marker: std::marker::PhantomData<A>,
|
||||
}
|
||||
|
||||
impl<A: HalApi> Adapter<A> {
|
||||
impl Adapter {
|
||||
fn new(mut raw: hal::DynExposedAdapter) -> Self {
|
||||
// WebGPU requires this offset alignment as lower bound on all adapters.
|
||||
const MIN_BUFFER_OFFSET_ALIGNMENT_LOWER_BOUND: u32 = 32;
|
||||
@ -185,10 +182,7 @@ impl<A: HalApi> Adapter<A> {
|
||||
.min_storage_buffer_offset_alignment
|
||||
.max(MIN_BUFFER_OFFSET_ALIGNMENT_LOWER_BOUND);
|
||||
|
||||
Self {
|
||||
raw,
|
||||
_marker: std::marker::PhantomData,
|
||||
}
|
||||
Self { raw }
|
||||
}
|
||||
|
||||
pub fn is_surface_supported(&self, surface: &Surface) -> bool {
|
||||
@ -196,7 +190,7 @@ impl<A: HalApi> Adapter<A> {
|
||||
//
|
||||
// This could occur if the user is running their app on Wayland but Vulkan does not support
|
||||
// VK_KHR_wayland_surface.
|
||||
surface.get_capabilities(A::VARIANT, self).is_ok()
|
||||
surface.get_capabilities(self).is_ok()
|
||||
}
|
||||
|
||||
pub(crate) fn get_texture_format_features(
|
||||
@ -268,7 +262,7 @@ impl<A: HalApi> Adapter<A> {
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn create_device_and_queue_from_hal(
|
||||
fn create_device_and_queue_from_hal<A: HalApi>(
|
||||
self: &Arc<Self>,
|
||||
hal_device: hal::DynOpenDevice,
|
||||
desc: &DeviceDescriptor,
|
||||
@ -294,7 +288,7 @@ impl<A: HalApi> Adapter<A> {
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn create_device_and_queue(
|
||||
fn create_device_and_queue<A: HalApi>(
|
||||
self: &Arc<Self>,
|
||||
desc: &DeviceDescriptor,
|
||||
instance_flags: wgt::InstanceFlags,
|
||||
@ -707,9 +701,9 @@ impl Global {
|
||||
None
|
||||
}
|
||||
None => {
|
||||
let adapter = Adapter::<A>::new(list.swap_remove(*selected));
|
||||
log::info!("Adapter {:?} {:?}", A::VARIANT, adapter.raw.info);
|
||||
let id = HalApi::hub(self)
|
||||
let adapter = Adapter::new(list.swap_remove(*selected));
|
||||
log::info!("Adapter {:?}", adapter.raw.info);
|
||||
let id = A::hub(self)
|
||||
.adapters
|
||||
.prepare(new_id)
|
||||
.assign(Arc::new(adapter));
|
||||
@ -744,9 +738,8 @@ impl Global {
|
||||
adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu);
|
||||
}
|
||||
if let Some(surface) = compatible_surface {
|
||||
adapters.retain(|exposed| {
|
||||
surface.get_capabilities_with_raw(backend, exposed).is_ok()
|
||||
});
|
||||
adapters
|
||||
.retain(|exposed| surface.get_capabilities_with_raw(exposed).is_ok());
|
||||
}
|
||||
device_types.extend(adapters.iter().map(|ad| ad.info.device_type));
|
||||
(id, adapters)
|
||||
@ -890,13 +883,13 @@ impl Global {
|
||||
|
||||
let id = match A::VARIANT {
|
||||
#[cfg(vulkan)]
|
||||
Backend::Vulkan => fid.assign(Arc::new(Adapter::<A>::new(hal_adapter))),
|
||||
Backend::Vulkan => fid.assign(Arc::new(Adapter::new(hal_adapter))),
|
||||
#[cfg(metal)]
|
||||
Backend::Metal => fid.assign(Arc::new(Adapter::<A>::new(hal_adapter))),
|
||||
Backend::Metal => fid.assign(Arc::new(Adapter::new(hal_adapter))),
|
||||
#[cfg(dx12)]
|
||||
Backend::Dx12 => fid.assign(Arc::new(Adapter::<A>::new(hal_adapter))),
|
||||
Backend::Dx12 => fid.assign(Arc::new(Adapter::new(hal_adapter))),
|
||||
#[cfg(gles)]
|
||||
Backend::Gl => fid.assign(Arc::new(Adapter::<A>::new(hal_adapter))),
|
||||
Backend::Gl => fid.assign(Arc::new(Adapter::new(hal_adapter))),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
resource_log!("Created Adapter {:?}", id);
|
||||
|
@ -65,10 +65,10 @@ impl<A: HalApi> Drop for ShaderModule<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(ShaderModule);
|
||||
crate::impl_resource_type_generic!(ShaderModule);
|
||||
crate::impl_labeled!(ShaderModule);
|
||||
crate::impl_parent_device!(ShaderModule);
|
||||
crate::impl_storage_item!(ShaderModule);
|
||||
crate::impl_storage_item_generic!(ShaderModule);
|
||||
|
||||
impl<A: HalApi> ShaderModule<A> {
|
||||
pub(crate) fn raw(&self) -> &dyn hal::DynShaderModule {
|
||||
@ -262,10 +262,10 @@ impl<A: HalApi> Drop for ComputePipeline<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(ComputePipeline);
|
||||
crate::impl_resource_type_generic!(ComputePipeline);
|
||||
crate::impl_labeled!(ComputePipeline);
|
||||
crate::impl_parent_device!(ComputePipeline);
|
||||
crate::impl_storage_item!(ComputePipeline);
|
||||
crate::impl_storage_item_generic!(ComputePipeline);
|
||||
crate::impl_trackable!(ComputePipeline);
|
||||
|
||||
impl<A: HalApi> ComputePipeline<A> {
|
||||
@ -316,10 +316,10 @@ impl<A: HalApi> Drop for PipelineCache<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(PipelineCache);
|
||||
crate::impl_resource_type_generic!(PipelineCache);
|
||||
crate::impl_labeled!(PipelineCache);
|
||||
crate::impl_parent_device!(PipelineCache);
|
||||
crate::impl_storage_item!(PipelineCache);
|
||||
crate::impl_storage_item_generic!(PipelineCache);
|
||||
|
||||
impl<A: HalApi> PipelineCache<A> {
|
||||
pub(crate) fn raw(&self) -> &dyn hal::DynPipelineCache {
|
||||
@ -615,10 +615,10 @@ impl<A: HalApi> Drop for RenderPipeline<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(RenderPipeline);
|
||||
crate::impl_resource_type_generic!(RenderPipeline);
|
||||
crate::impl_labeled!(RenderPipeline);
|
||||
crate::impl_parent_device!(RenderPipeline);
|
||||
crate::impl_storage_item!(RenderPipeline);
|
||||
crate::impl_storage_item_generic!(RenderPipeline);
|
||||
crate::impl_trackable!(RenderPipeline);
|
||||
|
||||
impl<A: HalApi> RenderPipeline<A> {
|
||||
|
@ -135,10 +135,20 @@ pub(crate) trait ResourceType {
|
||||
const TYPE: &'static str;
|
||||
}
|
||||
|
||||
// TODO(#5124): Remove the typed version.
|
||||
#[macro_export]
|
||||
macro_rules! impl_resource_type_generic {
|
||||
($ty:ident) => {
|
||||
impl<A: HalApi> $crate::resource::ResourceType for $ty<A> {
|
||||
const TYPE: &'static str = stringify!($ty);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_resource_type {
|
||||
($ty:ident) => {
|
||||
impl<A: HalApi> $crate::resource::ResourceType for $ty<A> {
|
||||
impl $crate::resource::ResourceType for $ty {
|
||||
const TYPE: &'static str = stringify!($ty);
|
||||
}
|
||||
};
|
||||
@ -751,10 +761,10 @@ pub enum CreateBufferError {
|
||||
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(Buffer);
|
||||
crate::impl_resource_type_generic!(Buffer);
|
||||
crate::impl_labeled!(Buffer);
|
||||
crate::impl_parent_device!(Buffer);
|
||||
crate::impl_storage_item!(Buffer);
|
||||
crate::impl_storage_item_generic!(Buffer);
|
||||
crate::impl_trackable!(Buffer);
|
||||
|
||||
/// A buffer that has been marked as destroyed and is staged for actual deletion soon.
|
||||
@ -913,8 +923,8 @@ impl<A: HalApi> StagingBuffer<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(StagingBuffer);
|
||||
crate::impl_storage_item!(StagingBuffer);
|
||||
crate::impl_resource_type_generic!(StagingBuffer);
|
||||
crate::impl_storage_item_generic!(StagingBuffer);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FlushedStagingBuffer<A: HalApi> {
|
||||
@ -1498,10 +1508,10 @@ pub enum CreateTextureError {
|
||||
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(Texture);
|
||||
crate::impl_resource_type_generic!(Texture);
|
||||
crate::impl_labeled!(Texture);
|
||||
crate::impl_parent_device!(Texture);
|
||||
crate::impl_storage_item!(Texture);
|
||||
crate::impl_storage_item_generic!(Texture);
|
||||
crate::impl_trackable!(Texture);
|
||||
|
||||
impl<A: HalApi> Borrow<TextureSelector> for Texture<A> {
|
||||
@ -1666,10 +1676,10 @@ pub enum CreateTextureViewError {
|
||||
#[non_exhaustive]
|
||||
pub enum TextureViewDestroyError {}
|
||||
|
||||
crate::impl_resource_type!(TextureView);
|
||||
crate::impl_resource_type_generic!(TextureView);
|
||||
crate::impl_labeled!(TextureView);
|
||||
crate::impl_parent_device!(TextureView);
|
||||
crate::impl_storage_item!(TextureView);
|
||||
crate::impl_storage_item_generic!(TextureView);
|
||||
crate::impl_trackable!(TextureView);
|
||||
|
||||
/// Describes a [`Sampler`]
|
||||
@ -1775,10 +1785,10 @@ pub enum CreateSamplerError {
|
||||
MissingFeatures(#[from] MissingFeatures),
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(Sampler);
|
||||
crate::impl_resource_type_generic!(Sampler);
|
||||
crate::impl_labeled!(Sampler);
|
||||
crate::impl_parent_device!(Sampler);
|
||||
crate::impl_storage_item!(Sampler);
|
||||
crate::impl_storage_item_generic!(Sampler);
|
||||
crate::impl_trackable!(Sampler);
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
@ -1817,10 +1827,10 @@ impl<A: HalApi> Drop for QuerySet<A> {
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(QuerySet);
|
||||
crate::impl_resource_type_generic!(QuerySet);
|
||||
crate::impl_labeled!(QuerySet);
|
||||
crate::impl_parent_device!(QuerySet);
|
||||
crate::impl_storage_item!(QuerySet);
|
||||
crate::impl_storage_item_generic!(QuerySet);
|
||||
crate::impl_trackable!(QuerySet);
|
||||
|
||||
impl<A: HalApi> QuerySet<A> {
|
||||
|
@ -28,10 +28,20 @@ pub(crate) trait StorageItem: ResourceType {
|
||||
type Marker: Marker;
|
||||
}
|
||||
|
||||
// TODO(#5124): Remove the typed version.
|
||||
#[macro_export]
|
||||
macro_rules! impl_storage_item_generic {
|
||||
($ty:ident) => {
|
||||
impl<A: HalApi> $crate::storage::StorageItem for $ty<A> {
|
||||
type Marker = $crate::id::markers::$ty;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_storage_item {
|
||||
($ty:ident) => {
|
||||
impl<A: HalApi> $crate::storage::StorageItem for $ty<A> {
|
||||
impl $crate::storage::StorageItem for $ty {
|
||||
type Marker = $crate::id::markers::$ty;
|
||||
}
|
||||
};
|
||||
|
@ -12,6 +12,13 @@ pub struct DynExposedAdapter {
|
||||
pub capabilities: Capabilities,
|
||||
}
|
||||
|
||||
impl DynExposedAdapter {
|
||||
/// Returns the backend this adapter is using.
|
||||
pub fn backend(&self) -> wgt::Backend {
|
||||
self.info.backend
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Api> From<ExposedAdapter<A>> for DynExposedAdapter {
|
||||
fn from(exposed_adapter: ExposedAdapter<A>) -> Self {
|
||||
Self {
|
||||
|
Loading…
Reference in New Issue
Block a user