Skip to content

Commit

Permalink
mesh_view_bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Nov 8, 2023
1 parent fabb71b commit 1b9708f
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 205 deletions.
66 changes: 20 additions & 46 deletions crates/bevy_core_pipeline/src/tonemapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use bevy_render::camera::Camera;
use bevy_render::extract_component::{ExtractComponent, ExtractComponentPlugin};
use bevy_render::extract_resource::{ExtractResource, ExtractResourcePlugin};
use bevy_render::render_asset::RenderAssets;
use bevy_render::render_resource::binding_types::{
sampler, texture_2d, texture_3d, uniform_buffer,
};
use bevy_render::renderer::RenderDevice;
use bevy_render::texture::{CompressedImageFormats, Image, ImageSampler, ImageType};
use bevy_render::view::{ViewTarget, ViewUniform};
Expand Down Expand Up @@ -248,35 +251,20 @@ impl SpecializedRenderPipeline for TonemappingPipeline {

impl FromWorld for TonemappingPipeline {
fn from_world(render_world: &mut World) -> Self {
let mut entries = vec![
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Buffer {
ty: BufferBindingType::Uniform,
has_dynamic_offset: true,
min_binding_size: Some(ViewUniform::min_size()),
},
count: None,
},
BindGroupLayoutEntry {
binding: 1,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
sample_type: TextureSampleType::Float { filterable: false },
view_dimension: TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
BindGroupLayoutEntry {
binding: 2,
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler(SamplerBindingType::NonFiltering),
count: None,
},
];
entries.extend(get_lut_bind_group_layout_entries([3, 4]));
let mut entries = DynamicBindGroupLayoutEntries::new_with_indices(
ShaderStages::FRAGMENT,
(
(0, uniform_buffer(true, Some(ViewUniform::min_size()))),
(
1,
texture_2d(TextureSampleType::Float { filterable: false }),
),
(2, sampler(SamplerBindingType::NonFiltering)),
),
);
let lut_layout_entries = get_lut_bind_group_layout_entries();
entries =
entries.extend_with_indices(((3, lut_layout_entries[0]), (4, lut_layout_entries[1])));

let tonemap_texture_bind_group = render_world
.resource::<RenderDevice>()
Expand Down Expand Up @@ -342,24 +330,10 @@ pub fn get_lut_bindings<'a>(
(&lut_image.texture_view, &lut_image.sampler)
}

pub fn get_lut_bind_group_layout_entries(bindings: [u32; 2]) -> [BindGroupLayoutEntry; 2] {
pub fn get_lut_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 2] {
[
BindGroupLayoutEntry {
binding: bindings[0],
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
sample_type: TextureSampleType::Float { filterable: true },
view_dimension: TextureViewDimension::D3,
multisampled: false,
},
count: None,
},
BindGroupLayoutEntry {
binding: bindings[1],
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler(SamplerBindingType::Filtering),
count: None,
},
texture_3d(TextureSampleType::Float { filterable: true }),
sampler(SamplerBindingType::Filtering),
]
}

Expand Down
10 changes: 4 additions & 6 deletions crates/bevy_pbr/src/environment_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ pub fn get_bindings<'a>(
(diffuse_map, specular_map, &fallback_image_cubemap.sampler)
}

pub fn get_bind_group_layout_entries(bindings: [u32; 3]) -> [BindGroupLayoutEntry; 3] {
pub fn get_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 3] {
[
texture_cube(TextureSampleType::Float { filterable: true })
.build(bindings[0], ShaderStages::FRAGMENT),
texture_cube(TextureSampleType::Float { filterable: true })
.build(bindings[1], ShaderStages::FRAGMENT),
sampler(SamplerBindingType::Filtering).build(bindings[2], ShaderStages::FRAGMENT),
texture_cube(TextureSampleType::Float { filterable: true }),
texture_cube(TextureSampleType::Float { filterable: true }),
sampler(SamplerBindingType::Filtering),
]
}
63 changes: 21 additions & 42 deletions crates/bevy_pbr/src/prepass/prepass_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,61 @@
use bevy_core_pipeline::prepass::ViewPrepassTextures;
use bevy_render::render_resource::{
BindGroupLayoutEntry, BindingType, ShaderStages, TextureAspect, TextureSampleType, TextureView,
TextureViewDescriptor, TextureViewDimension,
binding_types::{
texture_2d, texture_2d_multisampled, texture_2d_u32, texture_depth_2d,
texture_depth_2d_multisampled,
},
BindGroupLayoutEntryBuilder, TextureAspect, TextureSampleType, TextureView,
TextureViewDescriptor,
};
use bevy_utils::default;
use smallvec::SmallVec;

use crate::MeshPipelineViewLayoutKey;

pub fn get_bind_group_layout_entries(
bindings: [u32; 4],
layout_key: MeshPipelineViewLayoutKey,
) -> SmallVec<[BindGroupLayoutEntry; 4]> {
let mut result = SmallVec::<[BindGroupLayoutEntry; 4]>::new();
) -> SmallVec<[BindGroupLayoutEntryBuilder; 4]> {
let mut result = SmallVec::<[BindGroupLayoutEntryBuilder; 4]>::new();

let multisampled = layout_key.contains(MeshPipelineViewLayoutKey::MULTISAMPLED);

if layout_key.contains(MeshPipelineViewLayoutKey::DEPTH_PREPASS) {
result.push(
// Depth texture
BindGroupLayoutEntry {
binding: bindings[0],
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled,
sample_type: TextureSampleType::Depth,
view_dimension: TextureViewDimension::D2,
},
count: None,
if multisampled {
texture_depth_2d_multisampled()
} else {
texture_depth_2d()
},
);
}

if layout_key.contains(MeshPipelineViewLayoutKey::NORMAL_PREPASS) {
result.push(
// Normal texture
BindGroupLayoutEntry {
binding: bindings[1],
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled,
sample_type: TextureSampleType::Float { filterable: false },
view_dimension: TextureViewDimension::D2,
},
count: None,
if multisampled {
texture_2d_multisampled(TextureSampleType::Float { filterable: false })
} else {
texture_2d(TextureSampleType::Float { filterable: false })
},
);
}

if layout_key.contains(MeshPipelineViewLayoutKey::MOTION_VECTOR_PREPASS) {
result.push(
// Motion Vectors texture
BindGroupLayoutEntry {
binding: bindings[2],
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled,
sample_type: TextureSampleType::Float { filterable: false },
view_dimension: TextureViewDimension::D2,
},
count: None,
if multisampled {
texture_2d_multisampled(TextureSampleType::Float { filterable: false })
} else {
texture_2d(TextureSampleType::Float { filterable: false })
},
);
}

if layout_key.contains(MeshPipelineViewLayoutKey::DEFERRED_PREPASS) {
result.push(
// Deferred texture
BindGroupLayoutEntry {
binding: bindings[3],
visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture {
multisampled: false,
sample_type: TextureSampleType::Uint,
view_dimension: TextureViewDimension::D2,
},
count: None,
},
texture_2d_u32(),
);
}

Expand Down
Loading

0 comments on commit 1b9708f

Please sign in to comment.