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
This commit is contained in:
parent
9309d89bb8
commit
d516a27dc6
@ -340,8 +340,22 @@ pub fn prepare_core_3d_depth_textures(
|
|||||||
),
|
),
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
|
let mut render_target_usage = HashMap::default();
|
||||||
|
for (_, camera, depth_prepass, camera_3d) in &views_3d {
|
||||||
|
// Default usage required to write to the depth texture
|
||||||
|
let mut usage: TextureUsages = camera_3d.depth_texture_usages.into();
|
||||||
|
if depth_prepass.is_some() {
|
||||||
|
// Required to read the output of the prepass
|
||||||
|
usage |= TextureUsages::COPY_SRC;
|
||||||
|
}
|
||||||
|
render_target_usage
|
||||||
|
.entry(camera.target.clone())
|
||||||
|
.and_modify(|u| *u |= usage)
|
||||||
|
.or_insert_with(|| usage);
|
||||||
|
}
|
||||||
|
|
||||||
let mut textures = HashMap::default();
|
let mut textures = HashMap::default();
|
||||||
for (entity, camera, depth_prepass, camera_3d) in &views_3d {
|
for (entity, camera, _, _) in &views_3d {
|
||||||
let Some(physical_target_size) = camera.physical_target_size else {
|
let Some(physical_target_size) = camera.physical_target_size else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@ -349,13 +363,6 @@ pub fn prepare_core_3d_depth_textures(
|
|||||||
let cached_texture = textures
|
let cached_texture = textures
|
||||||
.entry(camera.target.clone())
|
.entry(camera.target.clone())
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| {
|
||||||
// Default usage required to write to the depth texture
|
|
||||||
let mut usage = camera_3d.depth_texture_usages.into();
|
|
||||||
if depth_prepass.is_some() {
|
|
||||||
// Required to read the output of the prepass
|
|
||||||
usage |= TextureUsages::COPY_SRC;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The size of the depth texture
|
// The size of the depth texture
|
||||||
let size = Extent3d {
|
let size = Extent3d {
|
||||||
depth_or_array_layers: 1,
|
depth_or_array_layers: 1,
|
||||||
@ -363,6 +370,10 @@ pub fn prepare_core_3d_depth_textures(
|
|||||||
height: physical_target_size.y,
|
height: physical_target_size.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let usage = *render_target_usage
|
||||||
|
.get(&camera.target.clone())
|
||||||
|
.expect("The depth texture usage should already exist for this target");
|
||||||
|
|
||||||
let descriptor = TextureDescriptor {
|
let descriptor = TextureDescriptor {
|
||||||
label: Some("view_depth_texture"),
|
label: Some("view_depth_texture"),
|
||||||
size,
|
size,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user