Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,23 @@ pub struct BindGroupLayout<B: hal::Backend> {
pub(crate) desc_counts: DescriptorCounts,
pub(crate) dynamic_count: usize,
pub(crate) count_validator: BindingTypeMaxCountValidator,
#[cfg(debug_assertions)]
pub(crate) label: String,
}

impl<B: hal::Backend> crate::hub::Resource for BindGroupLayout<B> {
const TYPE: &'static str = "BindGroupLayout";

fn life_guard(&self) -> &LifeGuard {
unreachable!()
}

fn label(&self) -> &str {
#[cfg(debug_assertions)]
return &self.label;
#[cfg(not(debug_assertions))]
return "";
}
}

#[derive(Clone, Debug, Error)]
Expand Down Expand Up @@ -488,6 +505,14 @@ impl<B: hal::Backend> PipelineLayout<B> {
}
}

impl<B: hal::Backend> crate::hub::Resource for PipelineLayout<B> {
const TYPE: &'static str = "PipelineLayout";

fn life_guard(&self) -> &LifeGuard {
&self.life_guard
}
}

#[repr(C)]
#[derive(Clone, Debug, Hash, PartialEq)]
#[cfg_attr(feature = "trace", derive(Serialize))]
Expand Down Expand Up @@ -585,6 +610,14 @@ impl<B: hal::Backend> Borrow<()> for BindGroup<B> {
}
}

impl<B: hal::Backend> crate::hub::Resource for BindGroup<B> {
const TYPE: &'static str = "BindGroup";

fn life_guard(&self) -> &LifeGuard {
&self.life_guard
}
}

#[derive(Clone, Debug, Error)]
pub enum GetBindGroupLayoutError {
#[error("pipeline is invalid")]
Expand Down
7 changes: 7 additions & 0 deletions wgpu-core/src/command/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::{
PrivateFeatures, Stored, SubmissionIndex,
};

#[cfg(debug_assertions)]
use crate::LabelHelpers;

use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _};
use parking_lot::Mutex;
use thiserror::Error;
Expand Down Expand Up @@ -80,9 +83,11 @@ impl<B: GfxBackend> CommandAllocator<B> {
device: &B::Device,
limits: wgt::Limits,
private_features: PrivateFeatures,
label: &crate::Label,
#[cfg(feature = "trace")] enable_tracing: bool,
) -> Result<CommandBuffer<B>, CommandAllocatorError> {
//debug_assert_eq!(device_id.backend(), B::VARIANT);
let _ = label; // silence warning on release
let thread_id = thread::current().id();
let mut inner = self.inner.lock();

Expand Down Expand Up @@ -126,6 +131,8 @@ impl<B: GfxBackend> CommandAllocator<B> {
} else {
None
},
#[cfg(debug_assertions)]
label: label.to_string_or_default(),
})
}
}
Expand Down
12 changes: 10 additions & 2 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::{
span,
track::{TrackerSet, UsageConflict},
validation::check_buffer_usage,
Label, LifeGuard, RefCount, Stored, MAX_BIND_GROUPS,
Label, LabelHelpers, LifeGuard, RefCount, Stored, MAX_BIND_GROUPS,
};
use arrayvec::ArrayVec;
use std::{
Expand Down Expand Up @@ -354,6 +354,14 @@ impl Borrow<RefCount> for RenderBundle {
}
}

impl crate::hub::Resource for RenderBundle {
const TYPE: &'static str = "RenderBundle";

fn life_guard(&self) -> &LifeGuard {
&self.life_guard
}
}

#[derive(Debug)]
struct IndexState {
buffer: Option<id::BufferId>,
Expand Down Expand Up @@ -1018,7 +1026,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
},
used: state.trackers,
context: bundle_encoder.context,
life_guard: LifeGuard::new(),
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
}
};

Expand Down
17 changes: 17 additions & 0 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub struct CommandBuffer<B: hal::Backend> {
private_features: PrivateFeatures,
#[cfg(feature = "trace")]
pub(crate) commands: Option<Vec<crate::device::trace::Command>>,
#[cfg(debug_assertions)]
pub(crate) label: String,
}

impl<B: GfxBackend> CommandBuffer<B> {
Expand Down Expand Up @@ -101,6 +103,21 @@ impl<B: GfxBackend> CommandBuffer<B> {
}
}

impl<B: hal::Backend> crate::hub::Resource for CommandBuffer<B> {
const TYPE: &'static str = "CommandBuffer";

fn life_guard(&self) -> &crate::LifeGuard {
unreachable!()
}

fn label(&self) -> &str {
#[cfg(debug_assertions)]
return &self.label;
#[cfg(not(debug_assertions))]
return "";
}
}

#[derive(Copy, Clone, Debug)]
pub struct BasePassRef<'a, C> {
pub commands: &'a [C],
Expand Down
24 changes: 18 additions & 6 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum TransferError {
#[error("source buffer/texture is missing the `COPY_SRC` usage flag")]
MissingCopySrcUsageFlag,
#[error("destination buffer/texture is missing the `COPY_DST` usage flag")]
MissingCopyDstUsageFlag,
MissingCopyDstUsageFlag(Option<BufferId>, Option<TextureId>),
#[error("copy of {start_offset}..{end_offset} would end up overruning the bounds of the {side:?} buffer of size {buffer_size}")]
BufferOverrun {
start_offset: BufferAddress,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub enum TransferError {
pub enum CopyError {
#[error(transparent)]
Encoder(#[from] CommandEncoderError),
#[error(transparent)]
#[error("Copy error")]
Transfer(#[from] TransferError),
}

Expand Down Expand Up @@ -349,7 +349,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.as_ref()
.ok_or(TransferError::InvalidBuffer(destination))?;
if !dst_buffer.usage.contains(BufferUsage::COPY_DST) {
Err(TransferError::MissingCopyDstUsageFlag)?
Err(TransferError::MissingCopyDstUsageFlag(
Some(destination),
None,
))?
}
barriers.extend(dst_pending.map(|pending| pending.into_hal(dst_buffer)));

Expand Down Expand Up @@ -465,7 +468,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.as_ref()
.ok_or(TransferError::InvalidTexture(destination.texture))?;
if !dst_texture.usage.contains(TextureUsage::COPY_DST) {
Err(TransferError::MissingCopyDstUsageFlag)?
Err(TransferError::MissingCopyDstUsageFlag(
None,
Some(destination.texture),
))?
}
let dst_barriers = dst_pending.map(|pending| pending.into_hal(dst_texture));

Expand Down Expand Up @@ -591,7 +597,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.as_ref()
.ok_or(TransferError::InvalidBuffer(destination.buffer))?;
if !dst_buffer.usage.contains(BufferUsage::COPY_DST) {
Err(TransferError::MissingCopyDstUsageFlag)?
Err(TransferError::MissingCopyDstUsageFlag(
Some(destination.buffer),
None,
))?
}
let dst_barrier = dst_barriers.map(|pending| pending.into_hal(dst_buffer));

Expand Down Expand Up @@ -731,7 +740,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.as_ref()
.ok_or(TransferError::InvalidTexture(destination.texture))?;
if !dst_texture.usage.contains(TextureUsage::COPY_DST) {
Err(TransferError::MissingCopyDstUsageFlag)?
Err(TransferError::MissingCopyDstUsageFlag(
None,
Some(destination.texture),
))?
}
barriers.extend(dst_pending.map(|pending| pending.into_hal(dst_texture)));

Expand Down
Loading