From 142a0660d21da2d29a6a65429f332a072452d6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 28 Nov 2022 19:27:04 +0000 Subject: [PATCH] set AVAILABLE_STORAGE_BUFFER_BINDINGS to the actual number of buffers available (#6787) # Objective - Since #5900 3d examples fail in wasm ``` ERROR crates/bevy_render/src/render_resource/pipeline_cache.rs:660 failed to process shader: Unknown shader def: 'AVAILABLE_STORAGE_BUFFER_BINDINGS' ``` ## Solution - Fix it by always adding the shaderdef `AVAILABLE_STORAGE_BUFFER_BINDINGS` with the actual value, instead of 3 when 3 or more were available --- .../src/render_resource/pipeline_cache.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index ce5faf90997000..b13c39e1fbecc1 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -19,9 +19,7 @@ use bevy_utils::{ }; use std::{hash::Hash, iter::FusedIterator, mem, ops::Deref}; use thiserror::Error; -use wgpu::{ - BufferBindingType, PipelineLayoutDescriptor, VertexBufferLayout as RawVertexBufferLayout, -}; +use wgpu::{PipelineLayoutDescriptor, VertexBufferLayout as RawVertexBufferLayout}; use crate::render_resource::resource_macros::*; @@ -178,17 +176,10 @@ impl ShaderCache { shader_defs.push("SIXTEEN_BYTE_ALIGNMENT".into()); } - // 3 is the value from CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT declared in bevy_pbr - // Using the value directly here to avoid the cyclic dependency - if matches!( - render_device.get_supported_read_only_binding_type(3), - BufferBindingType::Storage { .. } - ) { - shader_defs.push(ShaderDefVal::Int( - String::from("AVAILABLE_STORAGE_BUFFER_BINDINGS"), - 3, - )); - } + shader_defs.push(ShaderDefVal::Int( + String::from("AVAILABLE_STORAGE_BUFFER_BINDINGS"), + render_device.limits().max_storage_buffers_per_shader_stage as i32, + )); debug!( "processing shader {:?}, with shader defs {:?}",