Skip to content

Commit

Permalink
fast-fail in as_bind_group (#12513)
Browse files Browse the repository at this point in the history
# Objective

prevent gpu buffer allocations when running `as_bind_group` for assets
with texture dependencies that are not yet available.

## Solution

reorder the binding creation so that fallible items are created first.
  • Loading branch information
robtfm committed Mar 18, 2024
1 parent 3549ae9 commit 26f2d3f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/bevy_render/macros/src/as_bind_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ pub fn derive_as_bind_group(ast: syn::DeriveInput) -> Result<TokenStream> {

let fallback_image = get_fallback_image(&render_path, dimension);

binding_impls.push(quote! {
// insert fallible texture-based entries at 0 so that if we fail here, we exit before allocating any buffers
binding_impls.insert(0, quote! {
( #binding_index,
#render_path::render_resource::OwnedBindingResource::TextureView({
let handle: Option<&#asset_path::Handle<#render_path::texture::Image>> = (&self.#field_name).into();
Expand Down Expand Up @@ -311,7 +312,8 @@ pub fn derive_as_bind_group(ast: syn::DeriveInput) -> Result<TokenStream> {

let fallback_image = get_fallback_image(&render_path, *dimension);

binding_impls.push(quote! {
// insert fallible texture-based entries at 0 so that if we fail here, we exit before allocating any buffers
binding_impls.insert(0, quote! {
(
#binding_index,
#render_path::render_resource::OwnedBindingResource::TextureView({
Expand Down Expand Up @@ -353,7 +355,8 @@ pub fn derive_as_bind_group(ast: syn::DeriveInput) -> Result<TokenStream> {

let fallback_image = get_fallback_image(&render_path, *dimension);

binding_impls.push(quote! {
// insert fallible texture-based entries at 0 so that if we fail here, we exit before allocating any buffers
binding_impls.insert(0, quote! {
(
#binding_index,
#render_path::render_resource::OwnedBindingResource::Sampler({
Expand Down

0 comments on commit 26f2d3f

Please sign in to comment.