Skip to content

Commit b8c462a

Browse files
authored
[core] fix missing applies of DISCARD_HAL_LABELS (#7991)
1 parent d9a6b4f commit b8c462a

File tree

14 files changed

+73
-23
lines changed

14 files changed

+73
-23
lines changed

wgpu-core/src/command/clear.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
device::{DeviceError, MissingFeatures},
1010
get_lowest_common_denom,
1111
global::Global,
12+
hal_label,
1213
id::{BufferId, CommandEncoderId, TextureId},
1314
init_tracker::{MemoryInitKind, TextureInitRange},
1415
resource::{
@@ -272,6 +273,7 @@ impl Global {
272273
&device.alignments,
273274
device.zero_buffer.as_ref(),
274275
&snatch_guard,
276+
device.instance_flags,
275277
)?;
276278

277279
Ok(())
@@ -287,6 +289,7 @@ pub(crate) fn clear_texture<T: TextureTrackerSetSingle>(
287289
alignments: &hal::Alignments,
288290
zero_buffer: &dyn hal::DynBuffer,
289291
snatch_guard: &SnatchGuard<'_>,
292+
instance_flags: wgt::InstanceFlags,
290293
) -> Result<(), ClearError> {
291294
let dst_raw = dst_texture.try_raw(snatch_guard)?;
292295

@@ -345,11 +348,11 @@ pub(crate) fn clear_texture<T: TextureTrackerSetSingle>(
345348
),
346349
TextureClearMode::Surface { .. } => {
347350
drop(clear_mode);
348-
clear_texture_via_render_passes(dst_texture, range, true, encoder)?
351+
clear_texture_via_render_passes(dst_texture, range, true, encoder, instance_flags)?
349352
}
350353
TextureClearMode::RenderPass { is_color, .. } => {
351354
drop(clear_mode);
352-
clear_texture_via_render_passes(dst_texture, range, is_color, encoder)?
355+
clear_texture_via_render_passes(dst_texture, range, is_color, encoder, instance_flags)?
353356
}
354357
TextureClearMode::None => {
355358
return Err(ClearError::NoValidTextureClearMode(
@@ -459,6 +462,7 @@ fn clear_texture_via_render_passes(
459462
range: TextureInitRange,
460463
is_color: bool,
461464
encoder: &mut dyn hal::DynCommandEncoder,
465+
instance_flags: wgt::InstanceFlags,
462466
) -> Result<(), ClearError> {
463467
assert_eq!(dst_texture.desc.dimension, wgt::TextureDimension::D2);
464468

@@ -513,7 +517,10 @@ fn clear_texture_via_render_passes(
513517
unsafe {
514518
encoder
515519
.begin_render_pass(&hal::RenderPassDescriptor {
516-
label: Some("(wgpu internal) clear_texture clear pass"),
520+
label: hal_label(
521+
Some("(wgpu internal) clear_texture clear pass"),
522+
instance_flags,
523+
),
517524
extent,
518525
sample_count: dst_texture.desc.sample_count,
519526
color_attachments,

wgpu-core/src/command/compute.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,10 @@ impl Global {
756756
//
757757
// Use that buffer to insert barriers and clear discarded images.
758758
let transit = encoder
759-
.open_pass(Some("(wgpu internal) Pre Pass"))
759+
.open_pass(hal_label(
760+
Some("(wgpu internal) Pre Pass"),
761+
self.instance.flags,
762+
))
760763
.map_pass_err(pass_scope)?;
761764
fixup_discarded_surfaces(
762765
pending_discard_init_fixups.into_iter(),

wgpu-core/src/command/memory_init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub(crate) fn fixup_discarded_surfaces<InitIter: Iterator<Item = TextureSurfaceD
149149
&device.alignments,
150150
device.zero_buffer.as_ref(),
151151
snatch_guard,
152+
device.instance_flags,
152153
)
153154
.unwrap();
154155
}
@@ -304,6 +305,7 @@ impl BakedCommands {
304305
&device.alignments,
305306
device.zero_buffer.as_ref(),
306307
snatch_guard,
308+
device.instance_flags,
307309
);
308310

309311
// A Texture can be destroyed between the command recording

wgpu-core/src/command/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl InnerCommandEncoder {
565565
pub(crate) fn open(&mut self) -> Result<&mut dyn hal::DynCommandEncoder, DeviceError> {
566566
if !self.is_open {
567567
self.is_open = true;
568-
let hal_label = hal_label(Some(&self.label), self.device.instance_flags);
568+
let hal_label = hal_label(Some(self.label.as_str()), self.device.instance_flags);
569569
unsafe { self.raw.begin_encoding(hal_label) }
570570
.map_err(|e| self.device.handle_hal_error(e))?;
571571
}

wgpu-core/src/command/render.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ impl RenderPassInfo {
14571457
raw: &mut dyn hal::DynCommandEncoder,
14581458
snatch_guard: &SnatchGuard,
14591459
scope: &mut UsageScope<'_>,
1460+
instance_flags: wgt::InstanceFlags,
14601461
) -> Result<(), RenderPassErrorInner> {
14611462
profiling::scope!("RenderPassInfo::finish");
14621463
unsafe {
@@ -1497,7 +1498,10 @@ impl RenderPassInfo {
14971498
)
14981499
};
14991500
let desc = hal::RenderPassDescriptor::<'_, _, dyn hal::DynTextureView> {
1500-
label: Some("(wgpu internal) Zero init discarded depth/stencil aspect"),
1501+
label: hal_label(
1502+
Some("(wgpu internal) Zero init discarded depth/stencil aspect"),
1503+
instance_flags,
1504+
),
15011505
extent: view.render_extent.unwrap(),
15021506
sample_count: view.samples,
15031507
color_attachments: &[],
@@ -2201,6 +2205,7 @@ impl Global {
22012205
state.general.raw_encoder,
22022206
state.general.snatch_guard,
22032207
&mut state.general.scope,
2208+
self.instance.flags,
22042209
)
22052210
.map_pass_err(pass_scope)?;
22062211

@@ -2217,7 +2222,10 @@ impl Global {
22172222

22182223
{
22192224
let transit = encoder
2220-
.open_pass(Some("(wgpu internal) Pre Pass"))
2225+
.open_pass(hal_label(
2226+
Some("(wgpu internal) Pre Pass"),
2227+
self.instance.flags,
2228+
))
22212229
.map_pass_err(pass_scope)?;
22222230

22232231
fixup_discarded_surfaces(

wgpu-core/src/command/transfer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ fn handle_texture_init(
618618
&device.alignments,
619619
device.zero_buffer.as_ref(),
620620
snatch_guard,
621+
device.instance_flags,
621622
)?;
622623
}
623624
}

wgpu-core/src/device/queue.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::{
2727
device::{DeviceError, WaitIdleError},
2828
get_lowest_common_denom,
2929
global::Global,
30+
hal_label,
3031
id::{self, BlasId, QueueId},
3132
init_tracker::{has_copy_partial_init_tracker_coverage, TextureInitRange},
3233
lock::{rank, Mutex, MutexGuard, RwLock, RwLockWriteGuard},
@@ -57,6 +58,7 @@ impl Queue {
5758
pub(crate) fn new(
5859
device: Arc<Device>,
5960
raw: Box<dyn hal::DynQueue>,
61+
instance_flags: wgt::InstanceFlags,
6062
) -> Result<Self, DeviceError> {
6163
let pending_encoder = device
6264
.command_allocator
@@ -70,7 +72,7 @@ impl Queue {
7072
}
7173
};
7274

73-
let mut pending_writes = PendingWrites::new(pending_encoder);
75+
let mut pending_writes = PendingWrites::new(pending_encoder, instance_flags);
7476

7577
let zero_buffer = device.zero_buffer.as_ref();
7678
pending_writes.activate();
@@ -328,17 +330,22 @@ pub(crate) struct PendingWrites {
328330
dst_buffers: FastHashMap<TrackerIndex, Arc<Buffer>>,
329331
dst_textures: FastHashMap<TrackerIndex, Arc<Texture>>,
330332
copied_blas_s: FastHashMap<TrackerIndex, Arc<Blas>>,
333+
instance_flags: wgt::InstanceFlags,
331334
}
332335

333336
impl PendingWrites {
334-
pub fn new(command_encoder: Box<dyn hal::DynCommandEncoder>) -> Self {
337+
pub fn new(
338+
command_encoder: Box<dyn hal::DynCommandEncoder>,
339+
instance_flags: wgt::InstanceFlags,
340+
) -> Self {
335341
Self {
336342
command_encoder,
337343
is_recording: false,
338344
temp_resources: Vec::new(),
339345
dst_buffers: FastHashMap::default(),
340346
dst_textures: FastHashMap::default(),
341347
copied_blas_s: FastHashMap::default(),
348+
instance_flags,
342349
}
343350
}
344351

@@ -423,7 +430,10 @@ impl PendingWrites {
423430
if !self.is_recording {
424431
unsafe {
425432
self.command_encoder
426-
.begin_encoding(Some("(wgpu internal) PendingWrites"))
433+
.begin_encoding(hal_label(
434+
Some("(wgpu internal) PendingWrites"),
435+
self.instance_flags,
436+
))
427437
.unwrap();
428438
}
429439
self.is_recording = true;
@@ -816,6 +826,7 @@ impl Queue {
816826
&self.device.alignments,
817827
self.device.zero_buffer.as_ref(),
818828
&snatch_guard,
829+
self.device.instance_flags,
819830
)
820831
.map_err(QueueWriteError::from)?;
821832
}
@@ -1068,6 +1079,7 @@ impl Queue {
10681079
&self.device.alignments,
10691080
self.device.zero_buffer.as_ref(),
10701081
&self.device.snatchable_lock.read(),
1082+
self.device.instance_flags,
10711083
)
10721084
.map_err(QueueWriteError::from)?;
10731085
}
@@ -1221,7 +1233,10 @@ impl Queue {
12211233
};
12221234

12231235
// execute resource transitions
1224-
if let Err(e) = baked.encoder.open_pass(Some("(wgpu internal) Transit")) {
1236+
if let Err(e) = baked.encoder.open_pass(hal_label(
1237+
Some("(wgpu internal) Transit"),
1238+
self.device.instance_flags,
1239+
)) {
12251240
break 'error Err(e.into());
12261241
}
12271242

@@ -1256,8 +1271,10 @@ impl Queue {
12561271
// Note: we could technically do it after all of the command buffers,
12571272
// but here we have a command encoder by hand, so it's easier to use it.
12581273
if !used_surface_textures.is_empty() {
1259-
if let Err(e) = baked.encoder.open_pass(Some("(wgpu internal) Present"))
1260-
{
1274+
if let Err(e) = baked.encoder.open_pass(hal_label(
1275+
Some("(wgpu internal) Present"),
1276+
self.device.instance_flags,
1277+
)) {
12611278
break 'error Err(e.into());
12621279
}
12631280
let texture_barriers = trackers

wgpu-core/src/device/ray_tracing.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
api_log,
99
device::Device,
1010
global::Global,
11+
hal_label,
1112
id::{self, BlasId, TlasId},
1213
lock::RwLock,
1314
lock::{rank, Mutex},
@@ -231,7 +232,7 @@ impl Device {
231232
self.alignments.raw_tlas_instance_size * desc.max_instances.max(1) as usize;
232233
let instance_buffer = unsafe {
233234
self.raw().create_buffer(&hal::BufferDescriptor {
234-
label: Some("(wgpu-core) instances_buffer"),
235+
label: hal_label(Some("(wgpu-core) instances_buffer"), self.instance_flags),
235236
size: instance_buffer_size as u64,
236237
usage: wgt::BufferUses::COPY_DST
237238
| wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,

wgpu-core/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl Adapter {
776776
let device = Device::new(hal_device.device, self, desc, instance_flags)?;
777777
let device = Arc::new(device);
778778

779-
let queue = Queue::new(device.clone(), hal_device.queue)?;
779+
let queue = Queue::new(device.clone(), hal_device.queue, instance_flags)?;
780780
let queue = Arc::new(queue);
781781

782782
device.set_queue(&queue);

wgpu-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a> LabelHelpers<'a> for Label<'a> {
141141
}
142142
}
143143

144-
pub fn hal_label(opt: Option<&str>, flags: wgt::InstanceFlags) -> Option<&str> {
144+
pub fn hal_label<T: AsRef<str>>(opt: Option<T>, flags: wgt::InstanceFlags) -> Option<T> {
145145
if flags.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS) {
146146
return None;
147147
}

0 commit comments

Comments
 (0)