Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions crates/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ pub fn prepare_core_views_system(
* bit depth for better performance */
usage: TextureUsages::RENDER_ATTACHMENT,
},
false,
);
commands.entity(entity).insert(ViewDepthTexture {
texture: cached_texture.texture,
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_core_pipeline/src/main_pass_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ impl Node for MainPassDriverNode {
_render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
if let Some(camera_2d) = world.resource::<ActiveCamera<Camera2d>>().get() {
if let Some(camera_3d) = world.resource::<ActiveCamera<Camera3d>>().get() {
graph.run_sub_graph(
crate::draw_2d_graph::NAME,
vec![SlotValue::Entity(camera_2d)],
crate::draw_3d_graph::NAME,
vec![SlotValue::Entity(camera_3d)],
)?;
}

if let Some(camera_3d) = world.resource::<ActiveCamera<Camera3d>>().get() {
if let Some(camera_2d) = world.resource::<ActiveCamera<Camera2d>>().get() {
graph.run_sub_graph(
crate::draw_3d_graph::NAME,
vec![SlotValue::Entity(camera_3d)],
crate::draw_2d_graph::NAME,
vec![SlotValue::Entity(camera_2d)],
)?;
}

Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ pub fn prepare_lights(
label: Some("point_light_shadow_map_texture"),
usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING,
},
false,
);
let directional_light_depth_texture = texture_cache.get(
&render_device,
Expand All @@ -788,6 +789,7 @@ pub fn prepare_lights(
label: Some("directional_light_shadow_map_texture"),
usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING,
},
false,
);
let mut view_lights = Vec::new();

Expand Down
14 changes: 9 additions & 5 deletions crates/bevy_render/src/texture/texture_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use bevy_ecs::prelude::ResMut;
use bevy_utils::{Entry, HashMap};
use wgpu::{TextureDescriptor, TextureViewDescriptor};

/// The internal representation of a [`CachedTexture`] used to track whether it was recently used
/// and is currently taken.
/// The internal representation of a [`CachedTexture`] used to track whether it was recently used,
/// is currently taken and is it shared.
struct CachedTextureMeta {
texture: Texture,
default_view: TextureView,
taken: bool,
frames_since_last_use: usize,
shared: bool,
}

/// A cached GPU [`Texture`] with corresponding [`TextureView`].
Expand All @@ -31,17 +32,18 @@ pub struct TextureCache {
}

impl TextureCache {
/// Retrieves a texture that matches the `descriptor`. If no matching one is found a new
/// [`CachedTexture`] is created.
/// Retrieves a free or shared texture that matches the `descriptor`. If no matching one is found
/// a new [`CachedTexture`] is created.
pub fn get(
&mut self,
render_device: &RenderDevice,
descriptor: TextureDescriptor<'static>,
shared: bool,
) -> CachedTexture {
match self.textures.entry(descriptor) {
Entry::Occupied(mut entry) => {
for texture in entry.get_mut().iter_mut() {
if !texture.taken {
if (shared && texture.shared) || !texture.taken {
texture.frames_since_last_use = 0;
texture.taken = true;
return CachedTexture {
Expand All @@ -58,6 +60,7 @@ impl TextureCache {
default_view: default_view.clone(),
frames_since_last_use: 0,
taken: true,
shared,
});
CachedTexture {
texture,
Expand All @@ -72,6 +75,7 @@ impl TextureCache {
default_view: default_view.clone(),
taken: true,
frames_since_last_use: 0,
shared,
}]);
CachedTexture {
texture,
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ fn prepare_view_targets(
format: TextureFormat::bevy_default(),
usage: TextureUsages::RENDER_ATTACHMENT,
},
true,
);
Some(sampled_texture.default_view.clone())
} else {
Expand Down