From dc842ae289cec7031cf9bad4bd67a3767a0f5fb1 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 7 Dec 2023 02:55:02 -0500 Subject: [PATCH] Some minor cleanups (#4843) --- wgpu-core/src/binding_model.rs | 6 +----- wgpu-core/src/device/global.rs | 10 +++++----- wgpu-core/src/device/mod.rs | 6 +++--- wgpu-core/src/device/resource.rs | 21 +++++++++------------ wgpu-core/src/pipeline.rs | 6 +----- wgpu-core/src/registry.rs | 1 - wgpu-core/src/resource.rs | 18 ++++-------------- 7 files changed, 23 insertions(+), 45 deletions(-) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index f8cdba11ce..1b5cff8668 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -461,7 +461,6 @@ pub struct BindGroupLayout { pub(crate) dynamic_count: usize, pub(crate) count_validator: BindingTypeMaxCountValidator, pub(crate) info: ResourceInfo, - #[cfg(debug_assertions)] pub(crate) label: String, } @@ -489,10 +488,7 @@ impl Resource for BindGroupLayout { } fn label(&self) -> String { - #[cfg(debug_assertions)] - return self.label.clone(); - #[cfg(not(debug_assertions))] - return String::new(); + self.label.clone() } } impl BindGroupLayout { diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index f375bef6b1..7a6caec6c9 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -4,7 +4,7 @@ use crate::{ api_log, binding_model, command, conv, device::{ life::WaitIdleError, map_buffer, queue, DeviceError, DeviceLostClosure, HostMap, - IMPLICIT_FAILURE, + IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL, }, global::Global, hal_api::HalApi, @@ -1587,12 +1587,12 @@ impl Global { if pipeline_layout_guard.contains(ids.root_id) { pipeline_layout_guard.remove(ids.root_id); } - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); for &bgl_id in ids.group_ids.iter() { if bgl_guard.contains(bgl_id) { bgl_guard.remove(bgl_id); } - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } @@ -1721,12 +1721,12 @@ impl Global { if pipeline_layout_guard.contains(ids.root_id) { pipeline_layout_guard.remove(ids.root_id); } - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); for &bgl_id in ids.group_ids.iter() { if bgl_guard.contains(bgl_id) { bgl_guard.remove(bgl_id); } - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } (id, Some(error)) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index ad34876ebe..b8ebaf46c8 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -27,15 +27,15 @@ pub mod resource; pub mod trace; pub use {life::WaitIdleError, resource::Device}; -pub const SHADER_STAGE_COUNT: usize = 3; +pub const SHADER_STAGE_COUNT: usize = hal::MAX_CONCURRENT_SHADER_STAGES; // Should be large enough for the largest possible texture row. This // value is enough for a 16k texture with float4 format. pub(crate) const ZERO_BUFFER_SIZE: BufferAddress = 512 << 10; const CLEANUP_WAIT_MS: u32 = 5000; -const IMPLICIT_FAILURE: &str = "failed implicit"; -const EP_FAILURE: &str = "EP is invalid"; +const IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL: &str = "Implicit BindGroupLayout in the Error State"; +const ENTRYPOINT_FAILURE_ERROR: &str = "The given EntryPoint is Invalid"; pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor>; diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index e8f6802edb..815cdd80a9 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -53,8 +53,8 @@ use std::{ use super::{ life::{self, ResourceMaps}, queue::{self}, - DeviceDescriptor, DeviceError, ImplicitPipelineContext, UserClosures, EP_FAILURE, - IMPLICIT_FAILURE, ZERO_BUFFER_SIZE, + DeviceDescriptor, DeviceError, ImplicitPipelineContext, UserClosures, ENTRYPOINT_FAILURE_ERROR, + IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL, ZERO_BUFFER_SIZE, }; /// Structure describing a logical device. Some members are internally mutable, @@ -1422,7 +1422,6 @@ impl Device { device: self.clone(), interface: Some(interface), info: ResourceInfo::new(desc.label.borrow_or_default()), - #[cfg(debug_assertions)] label: desc.label.borrow_or_default().to_string(), }) } @@ -1464,7 +1463,6 @@ impl Device { device: self.clone(), interface: None, info: ResourceInfo::new(desc.label.borrow_or_default()), - #[cfg(debug_assertions)] label: desc.label.borrow_or_default().to_string(), }) } @@ -1724,14 +1722,13 @@ impl Device { Ok(BindGroupLayout { raw: Some(raw), device: self.clone(), - info: ResourceInfo::new(label.unwrap_or("")), + info: ResourceInfo::new(label.unwrap_or("")), dynamic_count: entry_map .values() .filter(|b| b.ty.has_dynamic_offset()) .count(), count_validator, entries: entry_map, - #[cfg(debug_assertions)] label: label.unwrap_or_default().to_string(), }) } @@ -2493,10 +2490,10 @@ impl Device { // that are not even in the storage. if let Some(ref ids) = implicit_context { let mut pipeline_layout_guard = hub.pipeline_layouts.write(); - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); let mut bgl_guard = hub.bind_group_layouts.write(); for &bgl_id in ids.group_ids.iter() { - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } @@ -2590,7 +2587,7 @@ impl Device { pipeline::CreateComputePipelineError::Internal(msg) } hal::PipelineError::EntryPoint(_stage) => { - pipeline::CreateComputePipelineError::Internal(EP_FAILURE.to_string()) + pipeline::CreateComputePipelineError::Internal(ENTRYPOINT_FAILURE_ERROR.to_string()) } })?; @@ -2622,9 +2619,9 @@ impl Device { //TODO: only lock mutable if the layout is derived let mut pipeline_layout_guard = hub.pipeline_layouts.write(); let mut bgl_guard = hub.bind_group_layouts.write(); - pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_FAILURE); + pipeline_layout_guard.insert_error(ids.root_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); for &bgl_id in ids.group_ids.iter() { - bgl_guard.insert_error(bgl_id, IMPLICIT_FAILURE); + bgl_guard.insert_error(bgl_id, IMPLICIT_BIND_GROUP_LAYOUT_ERROR_LABEL); } } @@ -3148,7 +3145,7 @@ impl Device { hal::PipelineError::EntryPoint(stage) => { pipeline::CreateRenderPipelineError::Internal { stage: hal::auxil::map_naga_stage(stage), - error: EP_FAILURE.to_string(), + error: ENTRYPOINT_FAILURE_ERROR.to_string(), } } })?; diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 50b5c91ce8..32a0ac880b 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -48,7 +48,6 @@ pub struct ShaderModule { pub(crate) device: Arc>, pub(crate) interface: Option, pub(crate) info: ResourceInfo, - #[cfg(debug_assertions)] pub(crate) label: String, } @@ -80,10 +79,7 @@ impl Resource for ShaderModule { } fn label(&self) -> String { - #[cfg(debug_assertions)] - return self.label.clone(); - #[cfg(not(debug_assertions))] - return String::new(); + self.label.clone() } } diff --git a/wgpu-core/src/registry.rs b/wgpu-core/src/registry.rs index 3e9003621f..0fe3b7dd13 100644 --- a/wgpu-core/src/registry.rs +++ b/wgpu-core/src/registry.rs @@ -88,7 +88,6 @@ impl> FutureId<'_, I, T> { pub fn assign_existing(self, value: &Arc) -> I { let mut data = self.data.write(); - #[cfg(debug_assertions)] debug_assert!(!data.contains(self.id)); data.insert(self.id, value.clone()); self.id diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 49d36a7acc..db9a376d40 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -70,7 +70,6 @@ pub struct ResourceInfo { submission_index: AtomicUsize, /// The `label` from the descriptor used to create the resource. - #[cfg(debug_assertions)] pub(crate) label: String, } @@ -90,25 +89,19 @@ impl ResourceInfo { id: None, identity: None, submission_index: AtomicUsize::new(0), - #[cfg(debug_assertions)] label: label.to_string(), } } - #[allow(unused_assignments)] pub(crate) fn label(&self) -> String where Id: Debug, { - let mut label = String::new(); - #[cfg(debug_assertions)] - { - label = format!("[{}] ", self.label); - } if let Some(id) = self.id.as_ref() { - label.push_str(format!("{:?}", id).as_str()); + format!("[{}] {:?}", self.label, id) + } else { + format!("[{}]", self.label) } - label } pub(crate) fn id(&self) -> Id { @@ -139,10 +132,7 @@ pub trait Resource: 'static + WasmNotSendSync { fn as_info(&self) -> &ResourceInfo; fn as_info_mut(&mut self) -> &mut ResourceInfo; fn label(&self) -> String { - #[cfg(debug_assertions)] - return self.as_info().label.clone(); - #[cfg(not(debug_assertions))] - return String::new(); + self.as_info().label.clone() } fn ref_count(self: &Arc) -> usize { Arc::strong_count(self)