Skip to content

Commit 7447b0a

Browse files
authored
Mini Blit refactor (#20118)
# Objective - Clean up usage of BlitPipeline ## Solution - add `create_bind_group` method - adjust some field and variable names for clarity ## Testing - ran 3d_scene
1 parent 6671575 commit 7447b0a

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

crates/bevy_core_pipeline/src/blit/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Plugin for BlitPlugin {
3636

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

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

6262
BlitPipeline {
63-
texture_bind_group,
63+
layout,
6464
sampler,
6565
fullscreen_shader: render_world.resource::<FullscreenShader>().clone(),
6666
fragment_shader: load_embedded_asset!(render_world, "blit.wgsl"),
6767
}
6868
}
6969
}
7070

71+
impl BlitPipeline {
72+
pub fn create_bind_group(
73+
&self,
74+
render_device: &RenderDevice,
75+
src_texture: &TextureView,
76+
) -> BindGroup {
77+
render_device.create_bind_group(
78+
None,
79+
&self.layout,
80+
&BindGroupEntries::sequential((src_texture, &self.sampler)),
81+
)
82+
}
83+
}
84+
7185
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
7286
pub struct BlitPipelineKey {
7387
pub texture_format: TextureFormat,
@@ -81,7 +95,7 @@ impl SpecializedRenderPipeline for BlitPipeline {
8195
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
8296
RenderPipelineDescriptor {
8397
label: Some("blit pipeline".into()),
84-
layout: vec![self.texture_bind_group.clone()],
98+
layout: vec![self.layout.clone()],
8599
vertex: self.fullscreen_shader.to_vertex_state(),
86100
fragment: Some(FragmentState {
87101
shader: self.fragment_shader.clone(),

crates/bevy_core_pipeline/src/msaa_writeback.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ impl ViewNode for MsaaWritebackNode {
9898
occlusion_query_set: None,
9999
};
100100

101-
let bind_group = render_context.render_device().create_bind_group(
102-
None,
103-
&blit_pipeline.texture_bind_group,
104-
&BindGroupEntries::sequential((post_process.source, &blit_pipeline.sampler)),
105-
);
101+
let bind_group =
102+
blit_pipeline.create_bind_group(render_context.render_device(), post_process.source);
106103

107104
let mut render_pass = render_context
108105
.command_encoder()

crates/bevy_core_pipeline/src/upscaling/node.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use bevy_ecs::{prelude::*, query::QueryItem};
33
use bevy_render::{
44
camera::{CameraOutputMode, ClearColor, ClearColorConfig, ExtractedCamera},
55
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
6-
render_resource::{
7-
BindGroup, BindGroupEntries, PipelineCache, RenderPassDescriptor, TextureViewId,
8-
},
6+
render_resource::{BindGroup, PipelineCache, RenderPassDescriptor, TextureViewId},
97
renderer::RenderContext,
108
view::ViewTarget,
119
};
@@ -30,9 +28,9 @@ impl ViewNode for UpscalingNode {
3028
(target, upscaling_target, camera): QueryItem<Self::ViewQuery>,
3129
world: &World,
3230
) -> Result<(), NodeRunError> {
33-
let pipeline_cache = world.get_resource::<PipelineCache>().unwrap();
34-
let blit_pipeline = world.get_resource::<BlitPipeline>().unwrap();
35-
let clear_color_global = world.get_resource::<ClearColor>().unwrap();
31+
let pipeline_cache = world.resource::<PipelineCache>();
32+
let blit_pipeline = world.resource::<BlitPipeline>();
33+
let clear_color_global = world.resource::<ClearColor>();
3634

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

5352
let mut cached_bind_group = self.cached_texture_bind_group.lock().unwrap();
5453
let bind_group = match &mut *cached_bind_group {
55-
Some((id, bind_group)) if upscaled_texture.id() == *id => bind_group,
54+
Some((id, bind_group)) if main_texture_view.id() == *id => bind_group,
5655
cached_bind_group => {
57-
let bind_group = render_context.render_device().create_bind_group(
58-
None,
59-
&blit_pipeline.texture_bind_group,
60-
&BindGroupEntries::sequential((upscaled_texture, &blit_pipeline.sampler)),
61-
);
56+
let bind_group = blit_pipeline
57+
.create_bind_group(render_context.render_device(), main_texture_view);
6258

63-
let (_, bind_group) = cached_bind_group.insert((upscaled_texture.id(), bind_group));
59+
let (_, bind_group) =
60+
cached_bind_group.insert((main_texture_view.id(), bind_group));
6461
bind_group
6562
}
6663
};

0 commit comments

Comments
 (0)