Skip to content

Commit

Permalink
Some minor cleanups (gfx-rs#4843)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored and bradwerth committed Dec 8, 2023
1 parent a40d208 commit 05b65f7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 45 deletions.
6 changes: 1 addition & 5 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ pub struct BindGroupLayout<A: HalApi> {
pub(crate) dynamic_count: usize,
pub(crate) count_validator: BindingTypeMaxCountValidator,
pub(crate) info: ResourceInfo<BindGroupLayoutId>,
#[cfg(debug_assertions)]
pub(crate) label: String,
}

Expand Down Expand Up @@ -489,10 +488,7 @@ impl<A: HalApi> Resource<BindGroupLayoutId> for BindGroupLayout<A> {
}

fn label(&self) -> String {
#[cfg(debug_assertions)]
return self.label.clone();
#[cfg(not(debug_assertions))]
return String::new();
self.label.clone()
}
}
impl<A: HalApi> BindGroupLayout<A> {
Expand Down
10 changes: 5 additions & 5 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1587,12 +1587,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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);
}
}

Expand Down Expand Up @@ -1721,12 +1721,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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))
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Label<'a>>;

Expand Down
21 changes: 9 additions & 12 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1426,7 +1426,6 @@ impl<A: HalApi> Device<A> {
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(),
})
}
Expand Down Expand Up @@ -1468,7 +1467,6 @@ impl<A: HalApi> Device<A> {
device: self.clone(),
interface: None,
info: ResourceInfo::new(desc.label.borrow_or_default()),
#[cfg(debug_assertions)]
label: desc.label.borrow_or_default().to_string(),
})
}
Expand Down Expand Up @@ -1728,14 +1726,13 @@ impl<A: HalApi> Device<A> {
Ok(BindGroupLayout {
raw: Some(raw),
device: self.clone(),
info: ResourceInfo::new(label.unwrap_or("<BindGroupLayoyt>")),
info: ResourceInfo::new(label.unwrap_or("<BindGroupLayout>")),
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(),
})
}
Expand Down Expand Up @@ -2497,10 +2494,10 @@ impl<A: HalApi> Device<A> {
// 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);
}
}

Expand Down Expand Up @@ -2594,7 +2591,7 @@ impl<A: HalApi> Device<A> {
pipeline::CreateComputePipelineError::Internal(msg)
}
hal::PipelineError::EntryPoint(_stage) => {
pipeline::CreateComputePipelineError::Internal(EP_FAILURE.to_string())
pipeline::CreateComputePipelineError::Internal(ENTRYPOINT_FAILURE_ERROR.to_string())
}
})?;

Expand Down Expand Up @@ -2626,9 +2623,9 @@ impl<A: HalApi> Device<A> {
//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);
}
}

Expand Down Expand Up @@ -3152,7 +3149,7 @@ impl<A: HalApi> Device<A> {
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(),
}
}
})?;
Expand Down
6 changes: 1 addition & 5 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub struct ShaderModule<A: HalApi> {
pub(crate) device: Arc<Device<A>>,
pub(crate) interface: Option<validation::Interface>,
pub(crate) info: ResourceInfo<ShaderModuleId>,
#[cfg(debug_assertions)]
pub(crate) label: String,
}

Expand Down Expand Up @@ -80,10 +79,7 @@ impl<A: HalApi> Resource<ShaderModuleId> for ShaderModule<A> {
}

fn label(&self) -> String {
#[cfg(debug_assertions)]
return self.label.clone();
#[cfg(not(debug_assertions))]
return String::new();
self.label.clone()
}
}

Expand Down
1 change: 0 additions & 1 deletion wgpu-core/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl<I: id::TypedId + Copy, T: Resource<I>> FutureId<'_, I, T> {

pub fn assign_existing(self, value: &Arc<T>) -> I {
let mut data = self.data.write();
#[cfg(debug_assertions)]
debug_assert!(!data.contains(self.id));
data.insert(self.id, value.clone());
self.id
Expand Down
18 changes: 4 additions & 14 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ pub struct ResourceInfo<Id: TypedId> {
submission_index: AtomicUsize,

/// The `label` from the descriptor used to create the resource.
#[cfg(debug_assertions)]
pub(crate) label: String,
}

Expand All @@ -90,25 +89,19 @@ impl<Id: TypedId> ResourceInfo<Id> {
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 {
Expand Down Expand Up @@ -139,10 +132,7 @@ pub trait Resource<Id: TypedId>: 'static + WasmNotSendSync {
fn as_info(&self) -> &ResourceInfo<Id>;
fn as_info_mut(&mut self) -> &mut ResourceInfo<Id>;
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<Self>) -> usize {
Arc::strong_count(self)
Expand Down

0 comments on commit 05b65f7

Please sign in to comment.