mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Split limits and private features, add tracing module
This commit is contained in:
committed by
Dzmitry Malyshau
parent
dc888446a3
commit
886d8b4c70
@@ -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<B: GfxBackend> CommandAllocator<B> {
|
||||
&self,
|
||||
device_id: Stored<DeviceId>,
|
||||
device: &B::Device,
|
||||
features: Features,
|
||||
limits: wgt::Limits,
|
||||
private_features: PrivateFeatures,
|
||||
lowest_active_index: SubmissionIndex,
|
||||
) -> CommandBuffer<B> {
|
||||
//debug_assert_eq!(device_id.backend(), B::VARIANT);
|
||||
@@ -108,7 +110,8 @@ impl<B: GfxBackend> CommandAllocator<B> {
|
||||
life_guard: LifeGuard::new(),
|
||||
trackers: TrackerSet::new(B::VARIANT),
|
||||
used_swap_chain: None,
|
||||
features,
|
||||
limits,
|
||||
private_features,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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);
|
||||
|
||||
@@ -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<B: hal::Backend> {
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
pub(crate) trackers: TrackerSet,
|
||||
pub(crate) used_swap_chain: Option<(Stored<id::SwapChainId>, B::Framebuffer)>,
|
||||
pub(crate) features: Features,
|
||||
limits: wgt::Limits,
|
||||
private_features: PrivateFeatures,
|
||||
}
|
||||
|
||||
impl<B: GfxBackend> CommandBuffer<B> {
|
||||
|
||||
@@ -430,7 +430,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
|
||||
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,
|
||||
|
||||
@@ -154,7 +154,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<B: hal::Backend> {
|
||||
// Life tracker should be locked right after the device and before anything else.
|
||||
life_tracker: Mutex<life::LifetimeTracker<B>>,
|
||||
temp_suspected: life::SuspectedResources,
|
||||
pub(crate) features: Features,
|
||||
pub(crate) private_features: PrivateFeatures,
|
||||
limits: wgt::Limits,
|
||||
}
|
||||
|
||||
impl<B: GfxBackend> Device<B> {
|
||||
@@ -204,7 +205,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
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<B: GfxBackend> Device<B> {
|
||||
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<B: GfxBackend> Device<B> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
// 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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.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),
|
||||
|
||||
@@ -509,6 +509,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&self,
|
||||
adapter_id: AdapterId,
|
||||
desc: &DeviceDescriptor,
|
||||
#[cfg(feature = "trace")] trace_path: Option<&std::path::Path>,
|
||||
id_in: Input<G, DeviceId>,
|
||||
) -> DeviceId {
|
||||
let hub = B::hub(self);
|
||||
@@ -574,7 +575,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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,
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
@@ -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<B: hal::Backend> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user