Skip to content

Commit

Permalink
recreate bindgroup if uniform buffer has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Elabajaba committed Mar 13, 2023
1 parent 24a85bd commit 067612c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use bevy_render::{
extract_component::{ComponentUniforms, DynamicUniformIndex},
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, Operations, PipelineCache,
RenderPassColorAttachment, RenderPassDescriptor, TextureViewId,
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, BufferId, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId,
},
renderer::RenderContext,
view::{ExtractedView, ViewTarget},
Expand All @@ -25,7 +25,7 @@ pub struct CASNode {
),
With<ExtractedView>,
>,
cached_texture_bind_group: Mutex<Option<(TextureViewId, BindGroup)>>,
cached_bind_group: Mutex<Option<(BufferId, TextureViewId, BindGroup)>>,
}

impl CASNode {
Expand All @@ -34,7 +34,7 @@ impl CASNode {
pub fn new(world: &mut World) -> Self {
Self {
query: QueryState::new(world),
cached_texture_bind_group: Mutex::new(None),
cached_bind_group: Mutex::new(None),
}
}
}
Expand All @@ -61,17 +61,22 @@ impl Node for CASNode {

let Ok((target, pipeline, uniform_index)) = self.query.get_manual(world, view_entity) else { return Ok(()) };

let uniforms_id = uniforms.buffer().unwrap().id();
let Some(uniforms) = uniforms.binding() else { return Ok(()) };

let pipeline = pipeline_cache.get_render_pipeline(pipeline.0).unwrap();

let view_target = target.post_process_write();

let source = view_target.source;
let destination = view_target.destination;
let mut cached_bind_group = self.cached_texture_bind_group.lock().unwrap();

let mut cached_bind_group = self.cached_bind_group.lock().unwrap();
let bind_group = match &mut *cached_bind_group {
Some((id, bind_group)) if source.id() == *id => bind_group,
Some((buffer_id, texture_id, bind_group))
if source.id() == *texture_id && uniforms_id == *buffer_id =>
{
bind_group
}
cached_bind_group => {
let bind_group =
render_context
Expand All @@ -97,7 +102,7 @@ impl Node for CASNode {
],
});

let (_, bind_group) = cached_bind_group.insert((source.id(), bind_group));
let (_, _, bind_group) = cached_bind_group.insert((uniforms_id, source.id(), bind_group));
bind_group
}
};
Expand Down

0 comments on commit 067612c

Please sign in to comment.