Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache depth texture based on usage #9565

Merged
merged 3 commits into from
Sep 4, 2023
Merged
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
27 changes: 19 additions & 8 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,29 +344,40 @@ 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();
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 {
continue;
};

let cached_texture = textures
.entry(camera.target.clone())
.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
let size = Extent3d {
depth_or_array_layers: 1,
width: physical_target_size.x,
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 {
label: Some("view_depth_texture"),
size,
Expand Down