Skip to content
Merged
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
22 changes: 18 additions & 4 deletions crates/bevy_core_pipeline/src/blit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Plugin for BlitPlugin {

#[derive(Resource)]
pub struct BlitPipeline {
pub texture_bind_group: BindGroupLayout,
pub layout: BindGroupLayout,
pub sampler: Sampler,
pub fullscreen_shader: FullscreenShader,
pub fragment_shader: Handle<Shader>,
Expand All @@ -46,7 +46,7 @@ impl FromWorld for BlitPipeline {
fn from_world(render_world: &mut World) -> Self {
let render_device = render_world.resource::<RenderDevice>();

let texture_bind_group = render_device.create_bind_group_layout(
let layout = render_device.create_bind_group_layout(
"blit_bind_group_layout",
&BindGroupLayoutEntries::sequential(
ShaderStages::FRAGMENT,
Expand All @@ -60,14 +60,28 @@ impl FromWorld for BlitPipeline {
let sampler = render_device.create_sampler(&SamplerDescriptor::default());

BlitPipeline {
texture_bind_group,
layout,
sampler,
fullscreen_shader: render_world.resource::<FullscreenShader>().clone(),
fragment_shader: load_embedded_asset!(render_world, "blit.wgsl"),
}
}
}

impl BlitPipeline {
pub fn create_bind_group(
&self,
render_device: &RenderDevice,
src_texture: &TextureView,
) -> BindGroup {
render_device.create_bind_group(
None,
&self.layout,
&BindGroupEntries::sequential((src_texture, &self.sampler)),
)
}
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
pub struct BlitPipelineKey {
pub texture_format: TextureFormat,
Expand All @@ -81,7 +95,7 @@ impl SpecializedRenderPipeline for BlitPipeline {
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
RenderPipelineDescriptor {
label: Some("blit pipeline".into()),
layout: vec![self.texture_bind_group.clone()],
layout: vec![self.layout.clone()],
vertex: self.fullscreen_shader.to_vertex_state(),
fragment: Some(FragmentState {
shader: self.fragment_shader.clone(),
Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_core_pipeline/src/msaa_writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ impl ViewNode for MsaaWritebackNode {
occlusion_query_set: None,
};

let bind_group = render_context.render_device().create_bind_group(
None,
&blit_pipeline.texture_bind_group,
&BindGroupEntries::sequential((post_process.source, &blit_pipeline.sampler)),
);
let bind_group =
blit_pipeline.create_bind_group(render_context.render_device(), post_process.source);

let mut render_pass = render_context
.command_encoder()
Expand Down
25 changes: 11 additions & 14 deletions crates/bevy_core_pipeline/src/upscaling/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use bevy_ecs::{prelude::*, query::QueryItem};
use bevy_render::{
camera::{CameraOutputMode, ClearColor, ClearColorConfig, ExtractedCamera},
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_resource::{
BindGroup, BindGroupEntries, PipelineCache, RenderPassDescriptor, TextureViewId,
},
render_resource::{BindGroup, PipelineCache, RenderPassDescriptor, TextureViewId},
renderer::RenderContext,
view::ViewTarget,
};
Expand All @@ -30,9 +28,9 @@ impl ViewNode for UpscalingNode {
(target, upscaling_target, camera): QueryItem<Self::ViewQuery>,
world: &World,
) -> Result<(), NodeRunError> {
let pipeline_cache = world.get_resource::<PipelineCache>().unwrap();
let blit_pipeline = world.get_resource::<BlitPipeline>().unwrap();
let clear_color_global = world.get_resource::<ClearColor>().unwrap();
let pipeline_cache = world.resource::<PipelineCache>();
let blit_pipeline = world.resource::<BlitPipeline>();
let clear_color_global = world.resource::<ClearColor>();

let clear_color = if let Some(camera) = camera {
match camera.output_mode {
Expand All @@ -48,19 +46,18 @@ impl ViewNode for UpscalingNode {
ClearColorConfig::None => None,
};
let converted_clear_color = clear_color.map(Into::into);
let upscaled_texture = target.main_texture_view();
// texture to be upscaled to the output texture
let main_texture_view = target.main_texture_view();

let mut cached_bind_group = self.cached_texture_bind_group.lock().unwrap();
let bind_group = match &mut *cached_bind_group {
Some((id, bind_group)) if upscaled_texture.id() == *id => bind_group,
Some((id, bind_group)) if main_texture_view.id() == *id => bind_group,
cached_bind_group => {
let bind_group = render_context.render_device().create_bind_group(
None,
&blit_pipeline.texture_bind_group,
&BindGroupEntries::sequential((upscaled_texture, &blit_pipeline.sampler)),
);
let bind_group = blit_pipeline
.create_bind_group(render_context.render_device(), main_texture_view);

let (_, bind_group) = cached_bind_group.insert((upscaled_texture.id(), bind_group));
let (_, bind_group) =
cached_bind_group.insert((main_texture_view.id(), bind_group));
bind_group
}
};
Expand Down
Loading