diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 436bb550ad..6eb18b1853 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -4,7 +4,8 @@ use super::CommandBuffer; use crate::{ - hub::GfxBackend, id::DeviceId, track::TrackerSet, Features, LifeGuard, Stored, SubmissionIndex, + hub::GfxBackend, id::DeviceId, track::TrackerSet, LifeGuard, PrivateFeatures, Stored, + SubmissionIndex, }; use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _}; @@ -76,7 +77,8 @@ impl CommandAllocator { &self, device_id: Stored, device: &B::Device, - features: Features, + limits: wgt::Limits, + private_features: PrivateFeatures, lowest_active_index: SubmissionIndex, ) -> CommandBuffer { //debug_assert_eq!(device_id.backend(), B::VARIANT); @@ -108,7 +110,8 @@ impl CommandAllocator { life_guard: LifeGuard::new(), trackers: TrackerSet::new(B::VARIANT), used_swap_chain: None, - features, + limits, + private_features, } } } diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 1a10985682..baa8820228 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -78,7 +78,7 @@ impl Global { let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); let cmb = &mut cmb_guard[encoder_id]; let raw = cmb.raw.last_mut().unwrap(); - let mut binder = Binder::new(cmb.features.max_bind_groups); + let mut binder = Binder::new(cmb.limits.max_bind_groups); let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token); let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 9529afc0f8..8a57b2cf4c 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -19,7 +19,7 @@ use crate::{ id, resource::{Buffer, Texture}, track::TrackerSet, - Features, LifeGuard, Stored, + LifeGuard, PrivateFeatures, Stored, }; use peek_poke::PeekPoke; @@ -138,7 +138,8 @@ pub struct CommandBuffer { pub(crate) life_guard: LifeGuard, pub(crate) trackers: TrackerSet, pub(crate) used_swap_chain: Option<(Stored, B::Framebuffer)>, - pub(crate) features: Features, + limits: wgt::Limits, + private_features: PrivateFeatures, } impl CommandBuffer { diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 3c06037fdc..3c51e6bebd 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -430,7 +430,10 @@ impl Global { }; Some(hal::pass::Attachment { - format: Some(conv::map_texture_format(view.format, device.features)), + format: Some(conv::map_texture_format( + view.format, + device.private_features, + )), samples: view.samples, ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op), stencil_ops: conv::map_load_store_ops( @@ -494,7 +497,10 @@ impl Global { }; colors.push(hal::pass::Attachment { - format: Some(conv::map_texture_format(view.format, device.features)), + format: Some(conv::map_texture_format( + view.format, + device.private_features, + )), samples: view.samples, ops: conv::map_load_store_ops(at.load_op, at.store_op), stencil_ops: hal::pass::AttachmentOps::DONT_CARE, @@ -540,7 +546,10 @@ impl Global { }; resolves.push(hal::pass::Attachment { - format: Some(conv::map_texture_format(view.format, device.features)), + format: Some(conv::map_texture_format( + view.format, + device.private_features, + )), samples: view.samples, ops: hal::pass::AttachmentOps::new( hal::pass::AttachmentLoadOp::DontCare, @@ -787,7 +796,7 @@ impl Global { }; let mut state = State { - binder: Binder::new(cmb.features.max_bind_groups), + binder: Binder::new(cmb.limits.max_bind_groups), blend_color: OptionalState::Unused, stencil_reference: OptionalState::Unused, pipeline: OptionalState::Required, diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 81c704438a..7fd861f544 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -154,7 +154,7 @@ impl Global { assert!(dst_texture.usage.contains(TextureUsage::COPY_DST)); let dst_barriers = dst_pending.map(|pending| pending.into_hal(dst_texture)); - let bytes_per_texel = conv::map_texture_format(dst_texture.format, cmb.features) + let bytes_per_texel = conv::map_texture_format(dst_texture.format, cmb.private_features) .surface_desc() .bits as u32 / BITS_PER_BYTE; @@ -218,7 +218,7 @@ impl Global { assert!(dst_buffer.usage.contains(BufferUsage::COPY_DST)); let dst_barrier = dst_barriers.map(|pending| pending.into_hal(dst_buffer)); - let bytes_per_texel = conv::map_texture_format(src_texture.format, cmb.features) + let bytes_per_texel = conv::map_texture_format(src_texture.format, cmb.private_features) .surface_desc() .bits as u32 / BITS_PER_BYTE; diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 9e9de04073..d3de887984 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use crate::{binding_model, Features}; +use crate::{binding_model, PrivateFeatures}; use wgt::{ BlendDescriptor, BlendFactor, Color, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode, DepthStencilStateDescriptor, Extent3d, FrontFace, IndexFormat, Origin3d, @@ -323,7 +323,7 @@ fn map_stencil_operation(stencil_operation: StencilOperation) -> hal::pso::Stenc pub(crate) fn map_texture_format( texture_format: TextureFormat, - features: Features, + private_features: PrivateFeatures, ) -> hal::format::Format { use hal::format::Format as H; use wgt::TextureFormat as Tf; @@ -378,14 +378,14 @@ pub(crate) fn map_texture_format( // Depth and stencil formats Tf::Depth32Float => H::D32Sfloat, Tf::Depth24Plus => { - if features.supports_texture_d24_s8 { + if private_features.supports_texture_d24_s8 { H::D24UnormS8Uint } else { H::D32Sfloat } } Tf::Depth24PlusStencil8 => { - if features.supports_texture_d24_s8 { + if private_features.supports_texture_d24_s8 { H::D24UnormS8Uint } else { H::D32SfloatS8Uint diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index d7bd2b8a4a..f797e72a30 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -7,7 +7,7 @@ use crate::{ hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token}, id, pipeline, resource, swap_chain, track::{BufferState, TextureState, TrackerSet}, - FastHashMap, Features, LifeGuard, Stored, + FastHashMap, LifeGuard, PrivateFeatures, Stored, }; use arrayvec::ArrayVec; @@ -193,7 +193,8 @@ pub struct Device { // Life tracker should be locked right after the device and before anything else. life_tracker: Mutex>, temp_suspected: life::SuspectedResources, - pub(crate) features: Features, + pub(crate) private_features: PrivateFeatures, + limits: wgt::Limits, } impl Device { @@ -204,7 +205,7 @@ impl Device { mem_props: hal::adapter::MemoryProperties, non_coherent_atom_size: u64, supports_texture_d24_s8: bool, - max_bind_groups: u32, + limits: wgt::Limits, ) -> Self { // don't start submission index at zero let life_guard = LifeGuard::new(); @@ -238,10 +239,10 @@ impl Device { framebuffers: Mutex::new(FastHashMap::default()), life_tracker: Mutex::new(life::LifetimeTracker::new()), temp_suspected: life::SuspectedResources::default(), - features: Features { - max_bind_groups, + private_features: PrivateFeatures { supports_texture_d24_s8, }, + limits, } } @@ -364,7 +365,7 @@ impl Device { desc.array_layer_count, desc.sample_count, ); - let format = conv::map_texture_format(desc.format, self.features); + let format = conv::map_texture_format(desc.format, self.private_features); let aspects = format.surface_desc().aspects; let usage = conv::map_texture_usage(desc.usage, aspects); @@ -752,7 +753,7 @@ impl Global { .create_image_view( &texture.raw, view_kind, - conv::map_texture_format(format, device.features), + conv::map_texture_format(format, device.private_features), hal::format::Swizzle::NO, range.clone(), ) @@ -980,7 +981,7 @@ impl Global { slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length) }; - assert!(desc.bind_group_layouts_length <= (device.features.max_bind_groups as usize), + assert!(desc.bind_group_layouts_length <= (device.limits.max_bind_groups as usize), "Cannot set a bind group which is beyond the `max_bind_groups` limit requested on device creation"); // TODO: push constants @@ -1317,7 +1318,8 @@ impl Global { let mut command_buffer = device.com_allocator.allocate( dev_stored, &device.raw, - device.features, + device.limits.clone(), + device.private_features, lowest_active_index, ); unsafe { @@ -1685,7 +1687,7 @@ impl Global { colors: color_states .iter() .map(|at| hal::pass::Attachment { - format: Some(conv::map_texture_format(at.format, device.features)), + format: Some(conv::map_texture_format(at.format, device.private_features)), samples: sc, ops: hal::pass::AttachmentOps::PRESERVE, stencil_ops: hal::pass::AttachmentOps::DONT_CARE, @@ -1698,7 +1700,7 @@ impl Global { // or depth/stencil resolve modes but satisfy the other compatibility conditions. resolves: ArrayVec::new(), depth_stencil: depth_stencil_state.map(|at| hal::pass::Attachment { - format: Some(conv::map_texture_format(at.format, device.features)), + format: Some(conv::map_texture_format(at.format, device.private_features)), samples: sc, ops: hal::pass::AttachmentOps::PRESERVE, stencil_ops: hal::pass::AttachmentOps::PRESERVE, @@ -2011,7 +2013,7 @@ impl Global { .max(*caps.image_count.start()) .min(*caps.image_count.end()); let mut config = - swap_chain::swap_chain_descriptor_to_hal(&desc, num_frames, device.features); + swap_chain::swap_chain_descriptor_to_hal(&desc, num_frames, device.private_features); if let Some(formats) = formats { assert!( formats.contains(&config.format), diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index c49e412695..a1795e1e15 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -509,6 +509,7 @@ impl Global { &self, adapter_id: AdapterId, desc: &DeviceDescriptor, + #[cfg(feature = "trace")] trace_path: Option<&std::path::Path>, id_in: Input, ) -> DeviceId { let hub = B::hub(self); @@ -574,7 +575,9 @@ impl Global { mem_props, limits.non_coherent_atom_size as u64, supports_texture_d24_s8, - desc.limits.max_bind_groups, + desc.limits.clone(), + #[cfg(feature = "trace")] + trace_path, ) }; diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 5fb9988422..3974160ea4 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -122,8 +122,7 @@ pub struct U32Array { } #[derive(Clone, Copy, Debug)] -pub(crate) struct Features { - pub max_bind_groups: u32, +struct PrivateFeatures { pub supports_texture_d24_s8: bool, } diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index c7ae49a949..19e2c7dca3 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -36,7 +36,7 @@ use crate::{ conv, hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token}, id::{DeviceId, SwapChainId, TextureViewId}, - resource, Features, LifeGuard, Stored, + resource, LifeGuard, PrivateFeatures, Stored, }; use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _}; @@ -59,12 +59,12 @@ pub struct SwapChain { pub(crate) fn swap_chain_descriptor_to_hal( desc: &SwapChainDescriptor, num_frames: u32, - features: Features, + private_features: PrivateFeatures, ) -> hal::window::SwapchainConfig { let mut config = hal::window::SwapchainConfig::new( desc.width, desc.height, - conv::map_texture_format(desc.format, features), + conv::map_texture_format(desc.format, private_features), num_frames, ); //TODO: check for supported @@ -114,8 +114,11 @@ impl Global { } Err(e) => { log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e); - let desc = - swap_chain_descriptor_to_hal(&sc.desc, sc.num_frames, device.features); + let desc = swap_chain_descriptor_to_hal( + &sc.desc, + sc.num_frames, + device.private_features, + ); unsafe { suf.configure_swapchain(&device.raw, desc).unwrap(); suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap()