Skip to content

Commit d516a27

Browse files
authored
Cache depth texture based on usage (#9565)
# Objective - Currently, the depth textures are cached based on the target. If multiple camera have the same target but a different `depth_texture_usage` bevy will just use the same texture and ignore that setting. ## Solution - Add the usage as a cache key
1 parent 9309d89 commit d516a27

File tree

1 file changed

+19
-8
lines changed
  • crates/bevy_core_pipeline/src/core_3d

1 file changed

+19
-8
lines changed

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,29 +340,40 @@ pub fn prepare_core_3d_depth_textures(
340340
),
341341
>,
342342
) {
343+
let mut render_target_usage = HashMap::default();
344+
for (_, camera, depth_prepass, camera_3d) in &views_3d {
345+
// Default usage required to write to the depth texture
346+
let mut usage: TextureUsages = camera_3d.depth_texture_usages.into();
347+
if depth_prepass.is_some() {
348+
// Required to read the output of the prepass
349+
usage |= TextureUsages::COPY_SRC;
350+
}
351+
render_target_usage
352+
.entry(camera.target.clone())
353+
.and_modify(|u| *u |= usage)
354+
.or_insert_with(|| usage);
355+
}
356+
343357
let mut textures = HashMap::default();
344-
for (entity, camera, depth_prepass, camera_3d) in &views_3d {
358+
for (entity, camera, _, _) in &views_3d {
345359
let Some(physical_target_size) = camera.physical_target_size else {
346360
continue;
347361
};
348362

349363
let cached_texture = textures
350364
.entry(camera.target.clone())
351365
.or_insert_with(|| {
352-
// Default usage required to write to the depth texture
353-
let mut usage = camera_3d.depth_texture_usages.into();
354-
if depth_prepass.is_some() {
355-
// Required to read the output of the prepass
356-
usage |= TextureUsages::COPY_SRC;
357-
}
358-
359366
// The size of the depth texture
360367
let size = Extent3d {
361368
depth_or_array_layers: 1,
362369
width: physical_target_size.x,
363370
height: physical_target_size.y,
364371
};
365372

373+
let usage = *render_target_usage
374+
.get(&camera.target.clone())
375+
.expect("The depth texture usage should already exist for this target");
376+
366377
let descriptor = TextureDescriptor {
367378
label: Some("view_depth_texture"),
368379
size,

0 commit comments

Comments
 (0)