mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-16 17:02:32 +00:00
Some minor cleanups (#4843)
This commit is contained in:
parent
2c2145c3a6
commit
dc842ae289
@ -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,
|
||||
}
|
||||
|
||||
@ -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> {
|
||||
|
@ -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<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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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))
|
||||
|
@ -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>>;
|
||||
|
||||
|
@ -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<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(),
|
||||
})
|
||||
}
|
||||
@ -1464,7 +1463,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(),
|
||||
})
|
||||
}
|
||||
@ -1724,14 +1722,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(),
|
||||
})
|
||||
}
|
||||
@ -2493,10 +2490,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2590,7 +2587,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())
|
||||
}
|
||||
})?;
|
||||
|
||||
@ -2622,9 +2619,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3148,7 +3145,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(),
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user