Skip to content

Commit b1b2090

Browse files
committed
centralise the shaderdefs that should always be defined
1 parent 34e80c5 commit b1b2090

File tree

6 files changed

+23
-49
lines changed

6 files changed

+23
-49
lines changed

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ x11 = ["bevy_winit/x11"]
5555
subpixel_glyph_atlas = ["bevy_text/subpixel_glyph_atlas"]
5656

5757
# Optimise for WebGL2
58-
webgl = ["bevy_core_pipeline/webgl", "bevy_pbr/webgl", "bevy_render/webgl", "bevy_sprite/webgl"]
58+
webgl = ["bevy_core_pipeline/webgl", "bevy_pbr/webgl", "bevy_render/webgl"]
5959

6060
# enable systems that allow for automated testing on CI
6161
bevy_ci_testing = ["bevy_app/bevy_ci_testing", "bevy_render/ci_limits"]

crates/bevy_pbr/src/render/light.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ pub struct ShadowPipeline {
212212
pub skinned_mesh_layout: BindGroupLayout,
213213
pub point_light_sampler: Sampler,
214214
pub directional_light_sampler: Sampler,
215-
pub clustered_forward_buffer_binding_type: BufferBindingType,
216215
}
217216

218217
// TODO: this pattern for initializing the shaders / pipeline isn't ideal. this should be handled by the asset system
@@ -221,9 +220,6 @@ impl FromWorld for ShadowPipeline {
221220
let world = world.cell();
222221
let render_device = world.resource::<RenderDevice>();
223222

224-
let clustered_forward_buffer_binding_type = render_device
225-
.get_supported_read_only_binding_type(CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT);
226-
227223
let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
228224
entries: &[
229225
// View
@@ -268,7 +264,6 @@ impl FromWorld for ShadowPipeline {
268264
compare: Some(CompareFunction::GreaterEqual),
269265
..Default::default()
270266
}),
271-
clustered_forward_buffer_binding_type,
272267
}
273268
}
274269
}
@@ -330,13 +325,6 @@ impl SpecializedMeshPipeline for ShadowPipeline {
330325
bind_group_layout.push(self.mesh_layout.clone());
331326
}
332327

333-
if !matches!(
334-
self.clustered_forward_buffer_binding_type,
335-
BufferBindingType::Storage { .. }
336-
) {
337-
shader_defs.push(String::from("NO_STORAGE_BUFFERS_SUPPORT"));
338-
}
339-
340328
let vertex_buffer_layout = layout.get_layout(&vertex_attributes)?;
341329

342330
Ok(RenderPipelineDescriptor {

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -573,18 +573,6 @@ impl SpecializedMeshPipeline for MeshPipeline {
573573
vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(4));
574574
}
575575

576-
// TODO: consider exposing this in shaders in a more generally useful way, such as:
577-
// # if AVAILABLE_STORAGE_BUFFER_BINDINGS == 3
578-
// /* use storage buffers here */
579-
// # elif
580-
// /* use uniforms here */
581-
if !matches!(
582-
self.clustered_forward_buffer_binding_type,
583-
BufferBindingType::Storage { .. }
584-
) {
585-
shader_defs.push(String::from("NO_STORAGE_BUFFERS_SUPPORT"));
586-
}
587-
588576
let mut bind_group_layout = vec![self.view_layout.clone()];
589577
if layout.contains(Mesh::ATTRIBUTE_JOINT_INDEX)
590578
&& layout.contains(Mesh::ATTRIBUTE_JOINT_WEIGHT)
@@ -615,9 +603,6 @@ impl SpecializedMeshPipeline for MeshPipeline {
615603
depth_write_enabled = true;
616604
}
617605

618-
#[cfg(feature = "webgl")]
619-
shader_defs.push(String::from("NO_ARRAY_TEXTURES_SUPPORT"));
620-
621606
Ok(RenderPipelineDescriptor {
622607
vertex: VertexState {
623608
shader: MESH_SHADER_HANDLE.typed::<Shader>(),

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use bevy_ecs::system::{Res, ResMut};
1515
use bevy_utils::{default, tracing::error, Entry, HashMap, HashSet};
1616
use std::{hash::Hash, mem, ops::Deref, sync::Arc};
1717
use thiserror::Error;
18-
use wgpu::{PipelineLayoutDescriptor, ShaderModule, VertexBufferLayout as RawVertexBufferLayout};
18+
use wgpu::{
19+
BufferBindingType, PipelineLayoutDescriptor, ShaderModule,
20+
VertexBufferLayout as RawVertexBufferLayout,
21+
};
1922

2023
enum PipelineDescriptor {
2124
RenderPipelineDescriptor(Box<RenderPipelineDescriptor>),
@@ -117,9 +120,26 @@ impl ShaderCache {
117120
let module = match data.processed_shaders.entry(shader_defs.to_vec()) {
118121
Entry::Occupied(entry) => entry.into_mut(),
119122
Entry::Vacant(entry) => {
123+
let mut shader_defs = shader_defs.to_vec();
124+
#[cfg(feature = "webgl")]
125+
shader_defs.push(String::from("NO_ARRAY_TEXTURES_SUPPORT"));
126+
127+
// TODO: 3 is the value from CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT declared in bevy_pbr
128+
// consider exposing this in shaders in a more generally useful way, such as:
129+
// # if AVAILABLE_STORAGE_BUFFER_BINDINGS == 3
130+
// /* use storage buffers here */
131+
// # elif
132+
// /* use uniforms here */
133+
if !matches!(
134+
render_device.get_supported_read_only_binding_type(3),
135+
BufferBindingType::Storage { .. }
136+
) {
137+
shader_defs.push(String::from("NO_STORAGE_BUFFERS_SUPPORT"));
138+
}
139+
120140
let processed = self.processor.process(
121141
shader,
122-
shader_defs,
142+
&shader_defs,
123143
&self.shaders,
124144
&self.import_path_shaders,
125145
)?;

crates/bevy_sprite/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ repository = "https://github.com/bevyengine/bevy"
88
license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

11-
[features]
12-
webgl = []
13-
1411
[dependencies]
1512
# bevy
1613
bevy_app = { path = "../bevy_app", version = "0.8.0-dev" }

crates/bevy_sprite/src/mesh2d/mesh.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub struct Mesh2dPipeline {
136136
pub mesh_layout: BindGroupLayout,
137137
// This dummy white texture is to be used in place of optional textures
138138
pub dummy_white_gpu_image: GpuImage,
139-
pub clustered_forward_buffer_binding_type: BufferBindingType,
140139
}
141140

142141
impl FromWorld for Mesh2dPipeline {
@@ -159,10 +158,6 @@ impl FromWorld for Mesh2dPipeline {
159158
label: Some("mesh2d_view_layout"),
160159
});
161160

162-
// 3 is the value from CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT that is declared in bevy_pbr
163-
let clustered_forward_buffer_binding_type =
164-
render_device.get_supported_read_only_binding_type(3);
165-
166161
let mesh_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
167162
entries: &[BindGroupLayoutEntry {
168163
binding: 0,
@@ -226,7 +221,6 @@ impl FromWorld for Mesh2dPipeline {
226221
view_layout,
227222
mesh_layout,
228223
dummy_white_gpu_image,
229-
clustered_forward_buffer_binding_type,
230224
}
231225
}
232226
}
@@ -322,16 +316,6 @@ impl SpecializedMeshPipeline for Mesh2dPipeline {
322316
vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(4));
323317
}
324318

325-
#[cfg(feature = "webgl")]
326-
shader_defs.push(String::from("NO_ARRAY_TEXTURES_SUPPORT"));
327-
328-
if !matches!(
329-
self.clustered_forward_buffer_binding_type,
330-
BufferBindingType::Storage { .. }
331-
) {
332-
shader_defs.push(String::from("NO_STORAGE_BUFFERS_SUPPORT"));
333-
}
334-
335319
let vertex_buffer_layout = layout.get_layout(&vertex_attributes)?;
336320

337321
Ok(RenderPipelineDescriptor {

0 commit comments

Comments
 (0)