Skip to content

Commit ba1aca3

Browse files
committed
fix example mesh2d_manual in wasm/webgl2 (#12753)
# Objective - Example `mesh2d_manual` crashes in wasm/webgl2, as reported in bevyengine/bevy-website#1123 (comment) ``` wgpu error: Validation Error Caused by: In a RenderPass note: encoder = `<CommandBuffer-(0, 1, Gl)>` In a set_push_constant command Provided push constant is for stage(s) ShaderStages(VERTEX), however the pipeline layout has no push constant range for the stage(s) ShaderStages(VERTEX) ``` ## Solution - Properly declare the push constant as in https://github.com/bevyengine/bevy/blob/4508077297a92295d8b6fb6b07a63b547deac1e0/crates/bevy_sprite/src/mesh2d/mesh.rs#L514-L524
1 parent be32339 commit ba1aca3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

examples/2d/mesh2d_manual.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use bevy::{
1616
render_resource::{
1717
BlendState, ColorTargetState, ColorWrites, Face, FragmentState, FrontFace,
1818
MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PrimitiveTopology,
19-
RenderPipelineDescriptor, SpecializedRenderPipeline, SpecializedRenderPipelines,
20-
TextureFormat, VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
19+
PushConstantRange, RenderPipelineDescriptor, ShaderStages, SpecializedRenderPipeline,
20+
SpecializedRenderPipelines, TextureFormat, VertexBufferLayout, VertexFormat,
21+
VertexState, VertexStepMode,
2122
},
2223
texture::BevyDefault,
2324
view::{ExtractedView, ViewTarget, VisibleEntities},
@@ -157,6 +158,18 @@ impl SpecializedRenderPipeline for ColoredMesh2dPipeline {
157158
false => TextureFormat::bevy_default(),
158159
};
159160

161+
let mut push_constant_ranges = Vec::with_capacity(1);
162+
if cfg!(all(
163+
feature = "webgl2",
164+
target_arch = "wasm32",
165+
not(feature = "webgpu")
166+
)) {
167+
push_constant_ranges.push(PushConstantRange {
168+
stages: ShaderStages::VERTEX,
169+
range: 0..4,
170+
});
171+
}
172+
160173
RenderPipelineDescriptor {
161174
vertex: VertexState {
162175
// Use our custom shader
@@ -184,7 +197,7 @@ impl SpecializedRenderPipeline for ColoredMesh2dPipeline {
184197
// Bind group 1 is the mesh uniform
185198
self.mesh2d_pipeline.mesh_layout.clone(),
186199
],
187-
push_constant_ranges: Vec::new(),
200+
push_constant_ranges,
188201
primitive: PrimitiveState {
189202
front_face: FrontFace::Ccw,
190203
cull_mode: Some(Face::Back),

0 commit comments

Comments
 (0)