Skip to content

Commit

Permalink
automatic min_size
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Nov 23, 2023
1 parent ce55027 commit 009cf1e
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl FromWorld for BloomDownsamplingPipeline {
// Sampler binding
sampler(SamplerBindingType::Filtering),
// Downsampling settings binding
uniform_buffer(true, Some(BloomUniforms::min_size())),
uniform_buffer::<BloomUniforms>(true),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl FromWorld for BloomUpsamplingPipeline {
// Sampler
sampler(SamplerBindingType::Filtering),
// BloomUniforms
uniform_buffer(true, Some(BloomUniforms::min_size())),
uniform_buffer::<BloomUniforms>(true),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl FromWorld for CASPipeline {
texture_2d(TextureSampleType::Float { filterable: true }),
sampler(SamplerBindingType::Filtering),
// CAS Settings
uniform_buffer(true, Some(CASUniform::min_size())),
uniform_buffer::<CASUniform>(true),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy_render::{
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries,
CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState,
DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState,
RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType,
RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages,
SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState,
TextureFormat, TextureSampleType, VertexState,
},
Expand Down Expand Up @@ -88,7 +88,7 @@ impl SkyboxPipeline {
(
texture_cube(TextureSampleType::Float { filterable: true }),
sampler(SamplerBindingType::Filtering),
uniform_buffer(true, Some(ViewUniform::min_size()))
uniform_buffer::<ViewUniform>(true)
.visibility(ShaderStages::VERTEX_FRAGMENT),
),
),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/tonemapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl FromWorld for TonemappingPipeline {
let mut entries = DynamicBindGroupLayoutEntries::new_with_indices(
ShaderStages::FRAGMENT,
(
(0, uniform_buffer(true, Some(ViewUniform::min_size()))),
(0, uniform_buffer::<ViewUniform>(true)),
(
1,
texture_2d(TextureSampleType::Float { filterable: false }),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Plugin for GizmoPlugin {
"LineGizmoUniform layout",
&BindGroupLayoutEntries::single(
ShaderStages::VERTEX,
uniform_buffer(true, Some(LineGizmoUniform::min_size())),
uniform_buffer::<LineGizmoUniform>(true),
),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/deferred/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl FromWorld for DeferredLightingLayout {
"deferred_lighting_layout",
&BindGroupLayoutEntries::single(
ShaderStages::VERTEX_FRAGMENT,
uniform_buffer(false, Some(PbrDeferredLightingDepthId::min_size())),
uniform_buffer::<PbrDeferredLightingDepthId>(false),
),
);
Self {
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ impl<M: Material> FromWorld for PrepassPipeline<M> {
ShaderStages::VERTEX_FRAGMENT,
(
// View
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
// Globals
uniform_buffer(false, Some(GlobalsUniform::min_size())),
uniform_buffer::<GlobalsUniform>(false),
// PreviousViewProjection
uniform_buffer(true, Some(PreviousViewProjection::min_size())),
uniform_buffer::<PreviousViewProjection>(true),
),
),
);
Expand All @@ -251,9 +251,9 @@ impl<M: Material> FromWorld for PrepassPipeline<M> {
ShaderStages::VERTEX_FRAGMENT,
(
// View
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
// Globals
uniform_buffer(false, Some(GlobalsUniform::min_size())),
uniform_buffer::<GlobalsUniform>(false),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/render/mesh_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ mod layout_entry {
use crate::MeshUniform;
use bevy_render::{
render_resource::{
binding_types::uniform_buffer, BindGroupLayoutEntry, BindingType, BufferSize,
binding_types::uniform_buffer_sized, BindGroupLayoutEntry, BindingType, BufferSize,
GpuArrayBuffer, ShaderStages, TextureSampleType, TextureViewDimension,
},
renderer::RenderDevice,
};

fn buffer(binding: u32, size: u64, visibility: ShaderStages) -> BindGroupLayoutEntry {
uniform_buffer(true, BufferSize::new(size)).build(binding, visibility)
uniform_buffer_sized(true, BufferSize::new(size)).build(binding, visibility)
}
pub(super) fn model(render_device: &RenderDevice, binding: u32) -> BindGroupLayoutEntry {
GpuArrayBuffer::<MeshUniform>::binding_layout(render_device)
Expand Down
13 changes: 6 additions & 7 deletions crates/bevy_pbr/src/render/mesh_view_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use bevy_render::{
},
BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindGroupLayoutEntryBuilder, BindingType,
BufferBindingType, DynamicBindGroupEntries, DynamicBindGroupLayoutEntries,
SamplerBindingType, ShaderStages, ShaderType, TextureFormat, TextureSampleType,
SamplerBindingType, ShaderStages, TextureFormat, TextureSampleType,
},
renderer::RenderDevice,
texture::{BevyDefault, FallbackImageCubemap, FallbackImageMsaa, FallbackImageZero, Image},
Expand Down Expand Up @@ -159,7 +159,7 @@ fn buffer_layout(
min_binding_size: Option<NonZeroU64>,
) -> BindGroupLayoutEntryBuilder {
match buffer_binding_type {
BufferBindingType::Uniform => uniform_buffer(has_dynamic_offset, min_binding_size),
BufferBindingType::Uniform => uniform_buffer_sized(has_dynamic_offset, min_binding_size),
BufferBindingType::Storage { read_only } => {
if read_only {
storage_buffer_read_only(has_dynamic_offset, min_binding_size)
Expand All @@ -181,11 +181,10 @@ fn layout_entries(
// View
(
0,
uniform_buffer(true, Some(ViewUniform::min_size()))
.visibility(ShaderStages::VERTEX_FRAGMENT),
uniform_buffer::<ViewUniform>(true).visibility(ShaderStages::VERTEX_FRAGMENT),
),
// Lights
(1, uniform_buffer(true, Some(GpuLights::min_size()))),
(1, uniform_buffer::<GpuLights>(true)),
// Point Shadow Texture Cube Array
(
2,
Expand Down Expand Up @@ -240,9 +239,9 @@ fn layout_entries(
),
),
// Globals
(9, uniform_buffer(false, Some(GlobalsUniform::min_size()))),
(9, uniform_buffer::<GlobalsUniform>(false)),
// Fog
(10, uniform_buffer(true, Some(GpuFog::min_size()))),
(10, uniform_buffer::<GpuFog>(true)),
// Screen space ambient occlusion texture
(
11,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/ssao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl FromWorld for SsaoPipelines {
ShaderStages::COMPUTE,
(
sampler(SamplerBindingType::NonFiltering),
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
),
),
);
Expand Down Expand Up @@ -387,7 +387,7 @@ impl FromWorld for SsaoPipelines {
texture_2d_u32(),
texture_storage_2d(TextureFormat::R16Float, StorageTextureAccess::WriteOnly),
texture_storage_2d(TextureFormat::R32Uint, StorageTextureAccess::WriteOnly),
uniform_buffer(false, Some(GlobalsUniform::min_size())),
uniform_buffer::<GlobalsUniform>(false),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ pub mod binding_types {
use crate::render_resource::{
BufferBindingType, SamplerBindingType, TextureSampleType, TextureViewDimension,
};
use encase::ShaderType;
use std::num::NonZeroU64;
use wgpu::{BindingType, StorageTextureAccess, TextureFormat};

Expand Down Expand Up @@ -385,7 +386,11 @@ pub mod binding_types {
.into_bind_group_layout_entry_builder()
}

pub fn uniform_buffer(
pub fn uniform_buffer<T: ShaderType>(has_dynamic_offset: bool) -> BindGroupLayoutEntryBuilder {
uniform_buffer_sized(has_dynamic_offset, Some(T::min_size()))
}

pub fn uniform_buffer_sized(
has_dynamic_offset: bool,
min_binding_size: Option<NonZeroU64>,
) -> BindGroupLayoutEntryBuilder {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/render_resource/gpu_array_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
binding_types::{storage_buffer, uniform_buffer},
binding_types::{storage_buffer, uniform_buffer_sized},
BindGroupLayoutEntryBuilder, StorageBuffer,
};
use crate::{
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<T: GpuArrayBufferable> GpuArrayBuffer<T> {

pub fn binding_layout(device: &RenderDevice) -> BindGroupLayoutEntryBuilder {
if device.limits().max_storage_buffers_per_shader_stage == 0 {
uniform_buffer(
uniform_buffer_sized(
true,
// BatchedUniformBuffer uses a MaxCapacityArray that is runtime-sized, so we use
// None here and let wgpu figure out the size.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/mesh2d/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ impl FromWorld for Mesh2dPipeline {
ShaderStages::VERTEX_FRAGMENT,
(
// View
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer(false, Some(GlobalsUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
uniform_buffer::<GlobalsUniform>(false),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl FromWorld for SpritePipeline {
"sprite_view_layout",
&BindGroupLayoutEntries::single(
ShaderStages::VERTEX_FRAGMENT,
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/render/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl FromWorld for UiPipeline {
"ui_view_layout",
&BindGroupLayoutEntries::single(
ShaderStages::VERTEX_FRAGMENT,
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/render/ui_material_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl<M: UiMaterial> FromWorld for UiMaterialPipeline<M> {
"ui_view_layout",
&BindGroupLayoutEntries::single(
ShaderStages::VERTEX_FRAGMENT,
uniform_buffer(true, Some(ViewUniform::min_size())),
uniform_buffer::<ViewUniform>(true),
),
);
UiMaterialPipeline {
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/post_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl FromWorld for PostProcessPipeline {
// The sampler that will be used to sample the screen texture
sampler(SamplerBindingType::Filtering),
// The settings uniform that will control the effect
uniform_buffer(false, Some(PostProcessSettings::min_size())),
uniform_buffer::<PostProcessSettings>(false),
),
),
);
Expand Down

0 comments on commit 009cf1e

Please sign in to comment.