Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind group descriptor macro #9476

Closed
wants to merge 10 commits into from
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
90 changes: 31 additions & 59 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ use bevy_render::{
},
prelude::Color,
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_resource::*,
render_resource::{
BindGroup, Extent3d, LoadOp, Operations, PipelineCache, RenderPassColorAttachment,
RenderPassDescriptor, Sampler, Shader, SpecializedRenderPipelines, TextureDescriptor,
TextureDimension, TextureFormat, TextureUsages, TextureView, TextureViewDescriptor,
},
renderer::{RenderContext, RenderDevice},
texture::{CachedTexture, TextureCache},
view::ViewTarget,
Expand Down Expand Up @@ -169,30 +173,15 @@ impl ViewNode for BloomNode {

// First downsample pass
{
let downsampling_first_bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: Some("bloom_downsampling_first_bind_group"),
layout: &downsampling_pipeline_res.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
// Read from main texture directly
resource: BindingResource::TextureView(
view_target.main_texture_view(),
),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&bind_groups.sampler),
},
BindGroupEntry {
binding: 2,
resource: uniforms.clone(),
},
],
});
let downsampling_first_bind_group = render_context.create_bind_group(
"bloom_downsampling_first_bind_group",
&downsampling_pipeline_res.bind_group_layout,
[
view_target.main_texture_view().binding(),
bind_groups.sampler.binding(),
uniforms,
],
);

let view = &bloom_texture.view(0);
let mut downsampling_first_pass =
Expand Down Expand Up @@ -412,49 +401,32 @@ fn queue_bloom_bind_groups(

for (entity, bloom_texture) in &views {
let bind_group_count = bloom_texture.mip_count as usize - 1;
let uniforms = uniforms.binding().unwrap();

let mut downsampling_bind_groups = Vec::with_capacity(bind_group_count);
for mip in 1..bloom_texture.mip_count {
downsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor {
label: Some("bloom_downsampling_bind_group"),
layout: &downsampling_pipeline.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(&bloom_texture.view(mip - 1)),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(sampler),
},
BindGroupEntry {
binding: 2,
resource: uniforms.binding().unwrap(),
},
downsampling_bind_groups.push(render_device.create_bind_group(
"bloom_downsampling_bind_group",
&downsampling_pipeline.bind_group_layout,
[
bloom_texture.view(mip - 1).binding(),
sampler.binding(),
uniforms.clone(),
],
}));
));
}

let mut upsampling_bind_groups = Vec::with_capacity(bind_group_count);
for mip in (0..bloom_texture.mip_count).rev() {
upsampling_bind_groups.push(render_device.create_bind_group(&BindGroupDescriptor {
label: Some("bloom_upsampling_bind_group"),
layout: &upsampling_pipeline.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(&bloom_texture.view(mip)),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(sampler),
},
BindGroupEntry {
binding: 2,
resource: uniforms.binding().unwrap(),
},
upsampling_bind_groups.push(render_device.create_bind_group(
"bloom_upsampling_bind_group",
&upsampling_pipeline.bind_group_layout,
[
bloom_texture.view(mip).binding(),
sampler.binding(),
uniforms.clone(),
],
}));
));
}

commands.entity(entity).insert(BloomBindGroups {
Expand Down
36 changes: 11 additions & 25 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},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, BufferId, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, TextureViewId,
BindGroup, BufferId, Operations, PipelineCache, RenderPassColorAttachment,
RenderPassDescriptor, TextureViewId,
},
renderer::RenderContext,
view::{ExtractedView, ViewTarget},
Expand Down Expand Up @@ -72,29 +72,15 @@ impl Node for CASNode {
bind_group
}
cached_bind_group => {
let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: Some("cas_bind_group"),
layout: &sharpening_pipeline.texture_bind_group,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(view_target.source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(
&sharpening_pipeline.sampler,
),
},
BindGroupEntry {
binding: 2,
resource: uniforms,
},
],
});
let bind_group = render_context.create_bind_group(
"cas_bind_group",
&sharpening_pipeline.texture_bind_group,
[
view_target.source.binding(),
sharpening_pipeline.sampler.binding(),
uniforms,
],
);

let (_, _, bind_group) =
cached_bind_group.insert((uniforms_id, source.id(), bind_group));
Expand Down
27 changes: 7 additions & 20 deletions crates/bevy_core_pipeline/src/fxaa/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use bevy_ecs::query::QueryItem;
use bevy_render::{
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindingResource, FilterMode, Operations,
PipelineCache, RenderPassColorAttachment, RenderPassDescriptor, SamplerDescriptor,
TextureViewId,
BindGroup, FilterMode, Operations, PipelineCache, RenderPassColorAttachment,
RenderPassDescriptor, SamplerDescriptor, TextureViewId,
},
renderer::RenderContext,
view::ViewTarget,
Expand Down Expand Up @@ -61,23 +60,11 @@ impl ViewNode for FxaaNode {
..default()
});

let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: None,
layout: &fxaa_pipeline.texture_bind_group,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&sampler),
},
],
});
let bind_group = render_context.create_bind_group(
"fxaa_bind_group",
&fxaa_pipeline.texture_bind_group,
[source.binding(), sampler.binding()],
);

let (_, bind_group) = cached_bind_group.insert((source.id(), bind_group));
bind_group
Expand Down
25 changes: 8 additions & 17 deletions crates/bevy_core_pipeline/src/msaa_writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,14 @@ impl Node for MsaaWritebackNode {
depth_stencil_attachment: None,
};

let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: None,
layout: &blit_pipeline.texture_bind_group,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(post_process.source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&blit_pipeline.sampler),
},
],
});
let bind_group = render_context.create_bind_group(
"msaa_writeback_bind_group",
&blit_pipeline.texture_bind_group,
[
post_process.source.binding(),
blit_pipeline.sampler.binding(),
],
);

let mut render_pass = render_context
.command_encoder()
Expand Down
39 changes: 15 additions & 24 deletions crates/bevy_core_pipeline/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_asset::RenderAssets,
render_resource::{
BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingResource, BindingType, BlendState, BufferBindingType,
CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState,
DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState,
RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType,
SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState,
TextureFormat, TextureSampleType, TextureViewDimension, VertexState,
BindGroup, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
BlendState, BufferBindingType, CachedRenderPipelineId, ColorTargetState, ColorWrites,
CompareFunction, DepthBiasState, DepthStencilState, FragmentState, MultisampleState,
PipelineCache, PrimitiveState, RenderPipelineDescriptor, SamplerBindingType, Shader,
ShaderStages, ShaderType, SpecializedRenderPipeline, SpecializedRenderPipelines,
StencilFaceState, StencilState, TextureFormat, TextureSampleType, TextureViewDimension,
VertexState,
},
renderer::RenderDevice,
texture::{BevyDefault, Image},
Expand Down Expand Up @@ -221,24 +221,15 @@ fn queue_skybox_bind_groups(
if let (Some(skybox), Some(view_uniforms)) =
(images.get(&skybox.0), view_uniforms.uniforms.binding())
{
let bind_group = render_device.create_bind_group(&BindGroupDescriptor {
label: Some("skybox_bind_group"),
layout: &pipeline.bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(&skybox.texture_view),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::Sampler(&skybox.sampler),
},
BindGroupEntry {
binding: 2,
resource: view_uniforms,
},
let bind_group = render_device.create_bind_group(
"skybox_bind_group",
&pipeline.bind_group_layout,
[
skybox.texture_view.binding(),
skybox.sampler.binding(),
view_uniforms,
],
});
);

commands.entity(entity).insert(SkyboxBindGroup(bind_group));
}
Expand Down
65 changes: 19 additions & 46 deletions crates/bevy_core_pipeline/src/taa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use bevy_render::{
prelude::{Camera, Projection},
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_resource::{
BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingResource, BindingType, CachedRenderPipelineId,
ColorTargetState, ColorWrites, Extent3d, FilterMode, FragmentState, MultisampleState,
Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor,
RenderPipelineDescriptor, Sampler, SamplerBindingType, SamplerDescriptor, Shader,
ShaderStages, SpecializedRenderPipeline, SpecializedRenderPipelines, TextureDescriptor,
TextureDimension, TextureFormat, TextureSampleType, TextureUsages, TextureViewDimension,
BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
CachedRenderPipelineId, ColorTargetState, ColorWrites, Extent3d, FilterMode, FragmentState,
MultisampleState, Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment,
RenderPassDescriptor, RenderPipelineDescriptor, Sampler, SamplerBindingType,
SamplerDescriptor, Shader, ShaderStages, SpecializedRenderPipeline,
SpecializedRenderPipelines, TextureDescriptor, TextureDimension, TextureFormat,
TextureSampleType, TextureUsages, TextureViewDimension,
},
renderer::{RenderContext, RenderDevice},
texture::{BevyDefault, CachedTexture, TextureCache},
Expand Down Expand Up @@ -201,45 +201,18 @@ impl ViewNode for TAANode {
};
let view_target = view_target.post_process_write();

let taa_bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: Some("taa_bind_group"),
layout: &pipelines.taa_bind_group_layout,
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::TextureView(view_target.source),
},
BindGroupEntry {
binding: 1,
resource: BindingResource::TextureView(
&taa_history_textures.read.default_view,
),
},
BindGroupEntry {
binding: 2,
resource: BindingResource::TextureView(
&prepass_motion_vectors_texture.default_view,
),
},
BindGroupEntry {
binding: 3,
resource: BindingResource::TextureView(
&prepass_depth_texture.default_view,
),
},
BindGroupEntry {
binding: 4,
resource: BindingResource::Sampler(&pipelines.nearest_sampler),
},
BindGroupEntry {
binding: 5,
resource: BindingResource::Sampler(&pipelines.linear_sampler),
},
],
});
let taa_bind_group = render_context.create_bind_group(
"taa_bind_group",
&pipelines.taa_bind_group_layout,
[
view_target.source.binding(),
taa_history_textures.read.default_view.binding(),
prepass_motion_vectors_texture.default_view.binding(),
prepass_depth_texture.default_view.binding(),
pipelines.nearest_sampler.binding(),
pipelines.linear_sampler.binding(),
],
);

{
let mut taa_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
Expand Down
13 changes: 5 additions & 8 deletions crates/bevy_core_pipeline/src/tonemapping/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,11 @@ impl ViewNode for TonemappingNode {
[3, 4],
));

let bind_group =
render_context
.render_device()
.create_bind_group(&BindGroupDescriptor {
label: None,
layout: &tonemapping_pipeline.texture_bind_group,
entries: &entries,
});
let bind_group = render_context.create_bind_group(&BindGroupDescriptor {
label: None,
layout: &tonemapping_pipeline.texture_bind_group,
entries: &entries,
});

let (_, _, bind_group) =
cached_bind_group.insert((view_uniforms_id, source.id(), bind_group));
Expand Down
Loading
Loading