Skip to content

Commit 23b9e18

Browse files
committed
rebased
1 parent f930970 commit 23b9e18

File tree

3 files changed

+74
-122
lines changed

3 files changed

+74
-122
lines changed

crates/bevy_core_pipeline/src/bloom/mod.rs

Lines changed: 47 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -230,106 +230,75 @@ impl Node for BloomNode {
230230
});
231231

232232
let view = &bloom_texture.view(0);
233-
let mut downsampling_first_pass =
234-
render_context.begin_tracked_render_pass(RenderPassDescriptor {
235-
label: Some("bloom_downsampling_first_pass"),
236-
color_attachments: &[Some(RenderPassColorAttachment {
237-
view,
238-
resolve_target: None,
239-
ops: Operations::default(),
240-
})],
241-
depth_stencil_attachment: None,
242-
});
243-
downsampling_first_pass.set_render_pipeline(downsampling_first_pipeline);
244-
downsampling_first_pass.set_bind_group(
245-
0,
246-
&downsampling_first_bind_group,
247-
&[uniform_index.index()],
248-
);
249-
downsampling_first_pass.draw(0..3, 0..1);
233+
234+
render_context
235+
.render_pass(view_entity)
236+
.set_label("bloom_downsampling_first_pass")
237+
.add_color_attachment(view)
238+
.begin()
239+
.set_pipeline(downsampling_first_pipeline)
240+
.set_bind_group(0, &downsampling_first_bind_group, &[uniform_index.index()])
241+
.draw(0..3, 0..1);
250242
}
251243

252244
// Other downsample passes
253245
for mip in 1..bloom_texture.mip_count {
246+
let down_sampling_bind_group = &bind_groups.downsampling_bind_groups[mip as usize - 1];
254247
let view = &bloom_texture.view(mip);
255-
let mut downsampling_pass =
256-
render_context.begin_tracked_render_pass(RenderPassDescriptor {
257-
label: Some("bloom_downsampling_pass"),
258-
color_attachments: &[Some(RenderPassColorAttachment {
259-
view,
260-
resolve_target: None,
261-
ops: Operations::default(),
262-
})],
263-
depth_stencil_attachment: None,
264-
});
265-
downsampling_pass.set_render_pipeline(downsampling_pipeline);
266-
downsampling_pass.set_bind_group(
267-
0,
268-
&bind_groups.downsampling_bind_groups[mip as usize - 1],
269-
&[uniform_index.index()],
270-
);
271-
downsampling_pass.draw(0..3, 0..1);
248+
249+
render_context
250+
.render_pass(view_entity)
251+
.set_label("bloom_downsampling_pass")
252+
.add_color_attachment(view)
253+
.begin()
254+
.set_pipeline(downsampling_pipeline)
255+
.set_bind_group(0, down_sampling_bind_group, &[uniform_index.index()])
256+
.draw(0..3, 0..1);
272257
}
273258

274259
// Upsample passes except the final one
275260
for mip in (1..bloom_texture.mip_count).rev() {
276-
let view = &bloom_texture.view(mip - 1);
277-
let mut upsampling_pass =
278-
render_context.begin_tracked_render_pass(RenderPassDescriptor {
279-
label: Some("bloom_upsampling_pass"),
280-
color_attachments: &[Some(RenderPassColorAttachment {
281-
view,
282-
resolve_target: None,
283-
ops: Operations {
284-
load: LoadOp::Load,
285-
store: true,
286-
},
287-
})],
288-
depth_stencil_attachment: None,
289-
});
290-
upsampling_pass.set_render_pipeline(upsampling_pipeline);
291-
upsampling_pass.set_bind_group(
292-
0,
293-
&bind_groups.upsampling_bind_groups[(bloom_texture.mip_count - mip - 1) as usize],
294-
&[uniform_index.index()],
295-
);
296261
let blend = compute_blend_factor(
297262
bloom_settings,
298263
mip as f32,
299264
(bloom_texture.mip_count - 1) as f32,
300265
);
301-
upsampling_pass.set_blend_constant(Color::rgb_linear(blend, blend, blend));
302-
upsampling_pass.draw(0..3, 0..1);
266+
let upsampling_bind_group =
267+
&bind_groups.upsampling_bind_groups[(bloom_texture.mip_count - mip - 1) as usize];
268+
let view = &bloom_texture.view(mip - 1);
269+
270+
render_context
271+
.render_pass(view_entity)
272+
.set_label("bloom_upsampling_pass")
273+
.add_color_attachment(view)
274+
.set_color_ops(LoadOp::Load, true)
275+
.begin()
276+
.set_pipeline(upsampling_pipeline)
277+
.set_bind_group(0, upsampling_bind_group, &[uniform_index.index()])
278+
.set_blend_constant(Color::rgb_linear(blend, blend, blend))
279+
.draw(0..3, 0..1);
303280
}
304281

305282
// Final upsample pass
306283
// This is very similar to the above upsampling passes with the only difference
307284
// being the pipeline (which itself is barely different) and the color attachment
308285
{
309-
let mut upsampling_final_pass =
310-
render_context.begin_tracked_render_pass(RenderPassDescriptor {
311-
label: Some("bloom_upsampling_final_pass"),
312-
color_attachments: &[Some(view_target.get_unsampled_color_attachment(
313-
Operations {
314-
load: LoadOp::Load,
315-
store: true,
316-
},
317-
))],
318-
depth_stencil_attachment: None,
319-
});
320-
upsampling_final_pass.set_render_pipeline(upsampling_final_pipeline);
321-
upsampling_final_pass.set_bind_group(
322-
0,
323-
&bind_groups.upsampling_bind_groups[(bloom_texture.mip_count - 1) as usize],
324-
&[uniform_index.index()],
325-
);
326-
if let Some(viewport) = camera.viewport.as_ref() {
327-
upsampling_final_pass.set_camera_viewport(viewport);
328-
}
329286
let blend =
330287
compute_blend_factor(bloom_settings, 0.0, (bloom_texture.mip_count - 1) as f32);
331-
upsampling_final_pass.set_blend_constant(Color::rgb_linear(blend, blend, blend));
332-
upsampling_final_pass.draw(0..3, 0..1);
288+
let upsample_final_bind_group =
289+
&bind_groups.upsampling_bind_groups[(bloom_texture.mip_count - 1) as usize];
290+
291+
render_context
292+
.render_pass(view_entity)
293+
.set_label("bloom_upsampling_final_pass")
294+
.add_view_target_unsampled(view_target)
295+
.set_color_ops(LoadOp::Load, true)
296+
.begin()
297+
.set_camera_viewport(camera)
298+
.set_pipeline(upsampling_final_pipeline)
299+
.set_bind_group(0, upsample_final_bind_group, &[uniform_index.index()])
300+
.set_blend_constant(Color::rgb_linear(blend, blend, blend))
301+
.draw(0..3, 0..1);
333302
}
334303

335304
render_context.command_encoder().pop_debug_group();

crates/bevy_core_pipeline/src/prepass/node.rs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ use bevy_ecs::prelude::*;
22
use bevy_ecs::query::QueryState;
33
use bevy_render::{
44
camera::ExtractedCamera,
5-
prelude::Color,
65
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
76
render_phase::RenderPhase,
8-
render_resource::{
9-
LoadOp, Operations, RenderPassColorAttachment, RenderPassDepthStencilAttachment,
10-
RenderPassDescriptor,
11-
},
7+
render_resource::LoadOp,
128
renderer::RenderContext,
139
view::{ExtractedView, ViewDepthTexture},
1410
};
@@ -69,50 +65,37 @@ impl Node for PrepassNode {
6965
return Ok(());
7066
};
7167

72-
let mut color_attachments = vec![];
73-
if let Some(view_normals_texture) = &view_prepass_textures.normal {
74-
color_attachments.push(Some(RenderPassColorAttachment {
75-
view: &view_normals_texture.default_view,
76-
resolve_target: None,
77-
ops: Operations {
78-
load: LoadOp::Clear(Color::BLACK.into()),
79-
store: true,
80-
},
81-
}));
82-
}
83-
8468
{
8569
// Set up the pass descriptor with the depth attachment and optional color attachments
86-
let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
87-
label: Some("prepass"),
88-
color_attachments: &color_attachments,
89-
depth_stencil_attachment: Some(RenderPassDepthStencilAttachment {
90-
view: &view_depth_texture.view,
91-
depth_ops: Some(Operations {
92-
load: LoadOp::Clear(0.0),
93-
store: true,
94-
}),
95-
stencil_ops: None,
96-
}),
97-
});
98-
99-
if let Some(viewport) = camera.viewport.as_ref() {
100-
render_pass.set_camera_viewport(viewport);
101-
}
70+
71+
let render_pass = render_context.render_pass(view_entity).set_label("prepass");
72+
73+
let render_pass = if let Some(view_normals_texture) = &view_prepass_textures.normal {
74+
render_pass.add_color_attachment(&view_normals_texture.default_view)
75+
} else {
76+
render_pass
77+
};
78+
79+
let mut render_pass = render_pass
80+
.set_depth_stencil_attachment(&view_depth_texture.view)
81+
.set_depth_ops(LoadOp::Clear(0.0), true)
82+
.begin();
83+
84+
render_pass.set_camera_viewport(camera);
10285

10386
// Always run opaque pass to ensure screen is cleared
10487
{
10588
// Run the prepass, sorted front-to-back
10689
#[cfg(feature = "trace")]
10790
let _opaque_prepass_span = info_span!("opaque_prepass").entered();
108-
opaque_prepass_phase.render(&mut render_pass, world, view_entity);
91+
render_pass.render_phase(opaque_prepass_phase, world);
10992
}
11093

11194
if !alpha_mask_prepass_phase.items.is_empty() {
11295
// Run the prepass, sorted front-to-back
11396
#[cfg(feature = "trace")]
11497
let _alpha_mask_prepass_span = info_span!("alpha_mask_prepass").entered();
115-
alpha_mask_prepass_phase.render(&mut render_pass, world, view_entity);
98+
render_pass.render_phase(opaque_prepass_phase, world);
11699
}
117100
}
118101

crates/bevy_render/src/render_resource/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ pub use wgpu::{
2828
util::BufferInitDescriptor, AdapterInfo as WgpuAdapterInfo, AddressMode, BindGroupDescriptor,
2929
BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType,
3030
BlendComponent, BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBinding,
31-
BufferBindingType, BufferDescriptor, BufferSize, BufferUsages, ColorTargetState, ColorWrites,
32-
CommandEncoder, CommandEncoderDescriptor, CompareFunction, ComputePass, ComputePassDescriptor,
33-
ComputePipelineDescriptor as RawComputePipelineDescriptor, DepthBiasState, DepthStencilState,
34-
Extent3d, Face, Features as WgpuFeatures, FilterMode, FragmentState as RawFragmentState,
35-
FrontFace, ImageCopyBuffer, ImageCopyBufferBase, ImageCopyTexture, ImageCopyTextureBase,
36-
ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits as WgpuLimits, LoadOp, MapMode,
37-
MultisampleState, Operations, Origin3d, PipelineLayout, PipelineLayoutDescriptor, PolygonMode,
38-
PrimitiveState, PrimitiveTopology, PushConstantRange, RenderPassColorAttachment,
39-
RenderPassDepthStencilAttachment, RenderPassDescriptor,
31+
BufferBindingType, BufferDescriptor, BufferSize, BufferUsages, Color as RawColor,
32+
ColorTargetState, ColorWrites, CommandEncoder, CommandEncoderDescriptor, CompareFunction,
33+
ComputePass, ComputePassDescriptor, ComputePipelineDescriptor as RawComputePipelineDescriptor,
34+
DepthBiasState, DepthStencilState, Extent3d, Face, Features as WgpuFeatures, FilterMode,
35+
FragmentState as RawFragmentState, FrontFace, ImageCopyBuffer, ImageCopyBufferBase,
36+
ImageCopyTexture, ImageCopyTextureBase, ImageDataLayout, ImageSubresourceRange, IndexFormat,
37+
Limits as WgpuLimits, LoadOp, MapMode, MultisampleState, Operations, Origin3d, PipelineLayout,
38+
PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, PushConstantRange,
39+
RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor,
4040
RenderPipelineDescriptor as RawRenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor,
4141
ShaderModule, ShaderModuleDescriptor, ShaderSource, ShaderStages, StencilFaceState,
4242
StencilOperation, StencilState, StorageTextureAccess, TextureAspect, TextureDescriptor,

0 commit comments

Comments
 (0)