Skip to content

Commit bb0aaab

Browse files
committed
comment & clippy fixes
1 parent e63a90f commit bb0aaab

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

wgpu-core/src/command/memory_init.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,21 @@ impl CommandBufferTextureMemoryActions {
5555
action: &TextureInitTrackerAction,
5656
texture_guard: &Storage<Texture<A>, TextureId>,
5757
) -> SurfacesInDiscardState {
58-
// TODO: Do not add MemoryInitKind::NeedsInitializedMemory to init_actions if a surface is part of the discard list
59-
// in that case it doesn't need to be initialized prior to the command buffer execution
58+
let mut immediately_necessary_clears = SurfacesInDiscardState::new();
6059

6160
// Note that within a command buffer we may stack arbitrary memory init actions on the same texture
6261
// Since we react to them in sequence, they are going to be dropped again at queue submit
62+
//
63+
// We don't need to add MemoryInitKind::NeedsInitializedMemory to init_actions if a surface is part of the discard list.
64+
// But that would mean splitting up the action which is more than we'd win here.
6365
self.init_actions
6466
.extend(match texture_guard.get(action.id) {
6567
Ok(texture) => texture.initialization_status.check_action(action),
66-
Err(_) => None,
68+
Err(_) => return immediately_necessary_clears, // texture no longer exists
6769
});
6870

6971
// We expect very few discarded surfaces at any point in time which is why a simple linear search is likely best.
7072
// (i.e. most of the time self.discards is empty!)
71-
let mut immediately_necessary_clears = SurfacesInDiscardState::new();
7273
self.discards.retain(|discarded_surface| {
7374
if discarded_surface.texture == action.id
7475
&& action.range.layer_range.contains(&discarded_surface.layer)
@@ -335,7 +336,7 @@ impl<A: hal::Api> BakedCommands<A> {
335336
}
336337
}
337338

338-
if zero_buffer_copy_regions.len() > 0 {
339+
if !zero_buffer_copy_regions.is_empty() {
339340
unsafe {
340341
self.encoder.copy_buffer_to_texture(
341342
&device.zero_buffer,

wgpu-core/src/command/render.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -647,27 +647,20 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
647647
));
648648
}
649649

650-
if !ds_aspects.contains(hal::FormatAspects::DEPTH) {
651-
Self::add_pass_texture_init_actions(
652-
&at.stencil,
653-
&mut cmd_buf.texture_memory_actions,
654-
view,
655-
texture_guard,
656-
&mut pending_discard_init_fixups,
657-
);
658-
} else if !ds_aspects.contains(hal::FormatAspects::STENCIL) {
650+
if !ds_aspects.contains(hal::FormatAspects::STENCIL)
651+
|| (at.stencil.load_op == at.depth.load_op
652+
&& at.stencil.store_op == at.depth.store_op)
653+
{
659654
Self::add_pass_texture_init_actions(
660655
&at.depth,
661656
&mut cmd_buf.texture_memory_actions,
662657
view,
663658
texture_guard,
664659
&mut pending_discard_init_fixups,
665660
);
666-
} else if at.stencil.load_op == at.depth.load_op
667-
&& at.stencil.store_op == at.depth.store_op
668-
{
661+
} else if !ds_aspects.contains(hal::FormatAspects::DEPTH) {
669662
Self::add_pass_texture_init_actions(
670-
&at.depth,
663+
&at.stencil,
671664
&mut cmd_buf.texture_memory_actions,
672665
view,
673666
texture_guard,

wgpu-core/src/device/queue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
534534

535535
let layers_to_initialize = dst.initialization_status.mips
536536
[destination.mip_level as usize]
537-
.drain(init_layer_range.clone());
537+
.drain(init_layer_range);
538538

539539
let mut zero_buffer_copy_regions = Vec::new();
540540
if size.width == dst.desc.size.width && size.height == dst.desc.size.height {
@@ -551,7 +551,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
551551
}
552552
}
553553
unsafe {
554-
if zero_buffer_copy_regions.len() > 0 {
554+
if !zero_buffer_copy_regions.is_empty() {
555555
encoder.copy_buffer_to_texture(
556556
&device.zero_buffer,
557557
dst_raw,
@@ -787,7 +787,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
787787
.initialize_buffer_memory(&mut *trackers, &mut *buffer_guard)
788788
.map_err(|err| QueueSubmitError::DestroyedBuffer(err.0))?;
789789
baked
790-
.initialize_texture_memory(&mut *trackers, &mut *texture_guard, &device)
790+
.initialize_texture_memory(&mut *trackers, &mut *texture_guard, device)
791791
.map_err(|err| QueueSubmitError::DestroyedTexture(err.0))?;
792792
//Note: stateless trackers are not merged:
793793
// device already knows these resources exist.

wgpu/tests/zero_init_texture_after_discard.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn copy_texture_to_buffer(
265265
) {
266266
encoder.copy_texture_to_buffer(
267267
wgpu::ImageCopyTexture {
268-
texture: &texture,
268+
texture,
269269
mip_level: 0,
270270
origin: wgpu::Origin3d { x: 0, y: 0, z: 0 },
271271
aspect: wgpu::TextureAspect::All,

0 commit comments

Comments
 (0)