Skip to content

Commit

Permalink
fix webgl2 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed May 3, 2023
1 parent b911823 commit c6c8c22
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/core_2d/main_pass_2d_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Node for MainPass2dNode {

// WebGL2 quirk: if ending with a render pass with a custom viewport, the viewport isn't
// reset for the next render pass so add an empty render pass without a custom viewport
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
if camera.viewport.is_some() {
#[cfg(feature = "trace")]
let _reset_viewport_pass_2d = info_span!("reset_viewport_pass_2d").entered();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Node for MainTransparentPass3dNode {

// WebGL2 quirk: if ending with a render pass with a custom viewport, the viewport isn't
// reset for the next render pass so add an empty render pass without a custom viewport
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
if camera.viewport.is_some() {
#[cfg(feature = "trace")]
let _reset_viewport_pass_3d = info_span!("reset_viewport_pass_3d").entered();
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl CascadeShadowConfigBuilder {

impl Default for CascadeShadowConfigBuilder {
fn default() -> Self {
if cfg!(feature = "webgl") {
if cfg!(all(feature = "webgl", target_arch = "wasm32")) {
// Currently only support one cascade in webgl.
Self {
num_cascades: 1,
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ pub struct GpuLights {
// NOTE: this must be kept in sync with the same constants in pbr.frag
pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256;
pub const MAX_DIRECTIONAL_LIGHTS: usize = 10;
#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
pub const MAX_CASCADES_PER_LIGHT: usize = 4;
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
pub const MAX_CASCADES_PER_LIGHT: usize = 1;
pub const SHADOW_FORMAT: TextureFormat = TextureFormat::Depth32Float;

Expand Down Expand Up @@ -683,13 +683,13 @@ pub fn prepare_lights(
let mut point_lights: Vec<_> = point_lights.iter().collect::<Vec<_>>();
let mut directional_lights: Vec<_> = directional_lights.iter().collect::<Vec<_>>();

#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
let max_texture_array_layers = render_device.limits().max_texture_array_layers as usize;
#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
let max_texture_cubes = max_texture_array_layers / 6;
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
let max_texture_array_layers = 1;
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
let max_texture_cubes = 1;

if !*max_directional_lights_warning_emitted && directional_lights.len() > MAX_DIRECTIONAL_LIGHTS
Expand Down Expand Up @@ -1162,9 +1162,9 @@ pub fn prepare_lights(
.create_view(&TextureViewDescriptor {
label: Some("point_light_shadow_map_array_texture_view"),
format: None,
#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
dimension: Some(TextureViewDimension::CubeArray),
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
dimension: Some(TextureViewDimension::Cube),
aspect: TextureAspect::All,
base_mip_level: 0,
Expand All @@ -1177,9 +1177,9 @@ pub fn prepare_lights(
.create_view(&TextureViewDescriptor {
label: Some("directional_light_shadow_map_array_texture_view"),
format: None,
#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
dimension: Some(TextureViewDimension::D2Array),
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
dimension: Some(TextureViewDimension::D2),
aspect: TextureAspect::All,
base_mip_level: 0,
Expand Down
16 changes: 10 additions & 6 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ impl FromWorld for MeshPipeline {
ty: BindingType::Texture {
multisampled: false,
sample_type: TextureSampleType::Depth,
#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
view_dimension: TextureViewDimension::CubeArray,
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
view_dimension: TextureViewDimension::Cube,
},
count: None,
Expand All @@ -354,9 +354,9 @@ impl FromWorld for MeshPipeline {
ty: BindingType::Texture {
multisampled: false,
sample_type: TextureSampleType::Depth,
#[cfg(not(feature = "webgl"))]
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
view_dimension: TextureViewDimension::D2Array,
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
view_dimension: TextureViewDimension::D2,
},
count: None,
Expand Down Expand Up @@ -444,7 +444,9 @@ impl FromWorld for MeshPipeline {
let tonemapping_lut_entries = get_lut_bind_group_layout_entries([14, 15]);
entries.extend_from_slice(&tonemapping_lut_entries);

if cfg!(not(feature = "webgl")) || (cfg!(feature = "webgl") && !multisampled) {
if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32")))
|| (cfg!(all(feature = "webgl", target_arch = "wasm32")) && !multisampled)
{
entries.extend_from_slice(&prepass::get_bind_group_layout_entries(
[16, 17, 18],
multisampled,
Expand Down Expand Up @@ -1065,7 +1067,9 @@ pub fn queue_mesh_view_bind_groups(
entries.extend_from_slice(&tonemapping_luts);

// When using WebGL, we can't have a depth texture with multisampling
if cfg!(not(feature = "webgl")) || (cfg!(feature = "webgl") && msaa.samples() == 1) {
if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32")))
|| (cfg!(all(feature = "webgl", target_arch = "wasm32")) && msaa.samples() == 1)
{
entries.extend_from_slice(&prepass::get_bindings(
prepass_textures,
&mut fallback_images,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct GlobalsUniform {
/// It wraps to zero when it reaches the maximum value of a u32.
frame_count: u32,
/// WebGL2 structs must be 16 byte aligned.
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
_wasm_padding: f32,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl ShaderCache {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let mut shader_defs = shader_defs.to_vec();
#[cfg(feature = "webgl")]
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
{
shader_defs.push("NO_ARRAY_TEXTURES_SUPPORT".into());
shader_defs.push("SIXTEEN_BYTE_ALIGNMENT".into());
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_render/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct WgpuSettings {

impl Default for WgpuSettings {
fn default() -> Self {
let default_backends = if cfg!(feature = "webgl") {
let default_backends = if cfg!(all(feature = "webgl", target_arch = "wasm32")) {
Backends::GL
} else {
Backends::all()
Expand All @@ -55,7 +55,8 @@ impl Default for WgpuSettings {

let priority = settings_priority_from_env().unwrap_or(WgpuSettingsPriority::Functionality);

let limits = if cfg!(feature = "webgl") || matches!(priority, WgpuSettingsPriority::WebGL2)
let limits = if cfg!(all(feature = "webgl", target_arch = "wasm32"))
|| matches!(priority, WgpuSettingsPriority::WebGL2)
{
wgpu::Limits::downlevel_webgl2_defaults()
} else {
Expand Down

0 comments on commit c6c8c22

Please sign in to comment.