From 4f08331e5d7269d6c4f47dae597a1f7b662dbf06 Mon Sep 17 00:00:00 2001 From: StarArawn Date: Mon, 28 Jun 2021 09:07:39 -0400 Subject: [PATCH] Fixed issue where transform buffer wasn't creating new bindings on resize. --- pipelined/bevy_pbr2/src/render/light.rs | 3 +- pipelined/bevy_pbr2/src/render/mod.rs | 37 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pipelined/bevy_pbr2/src/render/light.rs b/pipelined/bevy_pbr2/src/render/light.rs index d9f9326c68fcc..f5f0b37619ea6 100644 --- a/pipelined/bevy_pbr2/src/render/light.rs +++ b/pipelined/bevy_pbr2/src/render/light.rs @@ -431,12 +431,13 @@ impl Draw for DrawShadowMesh { &[view_uniform_offset.offset], ); + let transform_bindgroup_key = mesh_meta.mesh_transform_bind_group_key.unwrap(); pass.set_bind_group( 1, mesh_meta .into_inner() .mesh_transform_bind_group - .as_ref() + .get_value(transform_bindgroup_key) .unwrap(), &[extracted_mesh.transform_binding_offset], ); diff --git a/pipelined/bevy_pbr2/src/render/mod.rs b/pipelined/bevy_pbr2/src/render/mod.rs index a974e3b157ad9..290ff0006aaef 100644 --- a/pipelined/bevy_pbr2/src/render/mod.rs +++ b/pipelined/bevy_pbr2/src/render/mod.rs @@ -436,7 +436,8 @@ struct MeshDrawInfo { pub struct MeshMeta { transform_uniforms: DynamicUniformVec, material_bind_groups: FrameSlabMap, - mesh_transform_bind_group: Option, + mesh_transform_bind_group: FrameSlabMap, + mesh_transform_bind_group_key: Option>, mesh_draw_info: Vec, } @@ -473,7 +474,9 @@ fn image_handle_to_view_sampler<'a>( &pbr_shaders.dummy_white_gpu_image.sampler, ), |image_handle| { - let gpu_image = gpu_images.get(image_handle).expect("only materials with valid textures should be drawn"); + let gpu_image = gpu_images + .get(image_handle) + .expect("only materials with valid textures should be drawn"); (&gpu_image.texture_view, &gpu_image.sampler) }, ) @@ -516,16 +519,21 @@ pub fn queue_meshes( } let transform_uniforms = &mesh_meta.transform_uniforms; - mesh_meta.mesh_transform_bind_group.get_or_insert_with(|| { - render_device.create_bind_group(&BindGroupDescriptor { - entries: &[BindGroupEntry { - binding: 0, - resource: transform_uniforms.binding(), - }], - label: None, - layout: &pbr_shaders.mesh_layout, - }) - }); + mesh_meta.mesh_transform_bind_group.next_frame(); + mesh_meta.mesh_transform_bind_group_key = + Some(mesh_meta.mesh_transform_bind_group.get_or_insert_with( + transform_uniforms.uniform_buffer().unwrap().id(), + || { + render_device.create_bind_group(&BindGroupDescriptor { + entries: &[BindGroupEntry { + binding: 0, + resource: transform_uniforms.binding(), + }], + label: None, + layout: &pbr_shaders.mesh_layout, + }) + }, + )); for (entity, view, view_lights, mut transparent_phase) in views.iter_mut() { // TODO: cache this? let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { @@ -750,7 +758,10 @@ impl Draw for DrawPbr { ); pass.set_bind_group( 1, - mesh_meta.mesh_transform_bind_group.as_ref().unwrap(), + mesh_meta + .mesh_transform_bind_group + .get_value(mesh_meta.mesh_transform_bind_group_key.unwrap()) + .unwrap(), &[extracted_mesh.transform_binding_offset], ); let mesh_draw_info = &mesh_meta.mesh_draw_info[draw_key];