Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - WebGL2 support #3039

Closed
wants to merge 8 commits into from

Conversation

mrk-its
Copy link
Member

@mrk-its mrk-its commented Oct 27, 2021

Objective

Make possible to use wgpu gles backend on in the browser (wasm32 + WebGL2).

Solution

It is built on top of old @cart patch initializing windows before wgpu. Also:

  • initializes wgpu with Backends::GL and proper wgpu::Limits on wasm32
  • changes default texture format to wgpu::TextureFormat::Rgba8UnormSrgb

@DJMcNab DJMcNab added A-Rendering Drawing game state to the screen O-Web Specific to web (WASM) builds S-Needs-Review labels Oct 27, 2021
@@ -525,3 +529,22 @@ fn handle_create_window_events(
});
}
}

fn handle_initial_window_events(world: &mut World, event_loop: &EventLoop<()>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this in the winit_runner_with and keep the EventLoop argument of winit_runner_with?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cart ? (it is your code :) But it seems handle_initial_window_events needs to be called as is, because we need to have a window when renderer_plugin is initialized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup sadly its an order of operations thing. We need to init these windows before the RenderPlugin is setup, not before the app starts running.

@@ -42,7 +42,7 @@ pub trait BevyDefault {

impl BevyDefault for wgpu::TextureFormat {
fn bevy_default() -> Self {
if cfg!(target_os = "android") {
if cfg!(target_os = "android") || cfg!(target_arch = "wasm32") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use rgba everywhere? Are there any advantages to bgra on other platforms?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember hearing that a lot of hardware only supports (or prefers) bgra swap chains.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wgpu used to use bgra as a default in their examples, but it looks like at some point they switched to rgba. @kvark is there any reason to default to bgra at this point?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we can default to RGBA. Originally, we weren't sure if RGBA is really supported everywhere for presentation, as weird as it sounds.

Backends::PRIMARY
} else {
Backends::GL
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wgpu be changed to default to webgl on wasm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it would be great to prefer webgpu over webgl if available (probably). I'll try to figure out how to do it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its worth blocking on this, but I agree that its a "nice to have".

@@ -29,7 +29,7 @@ bevy_utils = { path = "../../crates/bevy_utils", version = "0.5.0" }
image = { version = "0.23.12", default-features = false }

# misc
wgpu = { version = "0.11.0", features = ["spirv"] }
wgpu = { version = "0.11.0", features = ["spirv", "webgl"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this feature be enabled only in wasm? That's possible now with edition 2021

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably, taking a look

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fixed this

@cart
Copy link
Member

cart commented Oct 29, 2021

Just pushed a change to only enable the wgpu webgl feature on wasm. I think this is good to go. Some follow ups to do:

  • Default to rgba on all platforms if theres no reason not to
  • Fix bevy_pbr2 to work on wasm
  • Make bevy build on wasm without needing to mess with defaults (we should solve this after merging into main + removing the old renderer)
  • Try defaulting to WebGPU on platforms where it is available

@cart
Copy link
Member

cart commented Oct 29, 2021

bors r+

bors bot pushed a commit that referenced this pull request Oct 29, 2021
# Objective

Make possible to use wgpu gles backend on in the browser (wasm32 + WebGL2). 

## Solution

It is built on top of old @cart patch initializing windows before wgpu. Also:
- initializes wgpu with `Backends::GL` and proper `wgpu::Limits` on wasm32
- changes default texture format to `wgpu::TextureFormat::Rgba8UnormSrgb`



Co-authored-by: Mariusz Kryński <[email protected]>
@cart
Copy link
Member

cart commented Oct 29, 2021

Also I can confirm that bevymark_pipelined does work on wasm/webgl2 if i disable the following features: bevy_audio, bevy_dynamic_plugin, bevy_wgpu, bevy_pbr2, render, mp3

@bors
Copy link
Contributor

bors bot commented Oct 29, 2021

Build failed:

@cart
Copy link
Member

cart commented Oct 29, 2021

bors r+

bors bot pushed a commit that referenced this pull request Oct 29, 2021
# Objective

Make possible to use wgpu gles backend on in the browser (wasm32 + WebGL2). 

## Solution

It is built on top of old @cart patch initializing windows before wgpu. Also:
- initializes wgpu with `Backends::GL` and proper `wgpu::Limits` on wasm32
- changes default texture format to `wgpu::TextureFormat::Rgba8UnormSrgb`



Co-authored-by: Mariusz Kryński <[email protected]>
@bors
Copy link
Contributor

bors bot commented Oct 29, 2021

Build failed:

Comment on lines 36 to 37
use winit::platform::unix::EventLoopExtUnix;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cfg before should be removed also

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bawhaha well that wasn't smart of me

@cart
Copy link
Member

cart commented Oct 29, 2021

bors r+

bors bot pushed a commit that referenced this pull request Oct 29, 2021
# Objective

Make possible to use wgpu gles backend on in the browser (wasm32 + WebGL2). 

## Solution

It is built on top of old @cart patch initializing windows before wgpu. Also:
- initializes wgpu with `Backends::GL` and proper `wgpu::Limits` on wasm32
- changes default texture format to `wgpu::TextureFormat::Rgba8UnormSrgb`



Co-authored-by: Mariusz Kryński <[email protected]>
@bors
Copy link
Contributor

bors bot commented Oct 29, 2021

Pull request successfully merged into pipelined-rendering.

Build succeeded:

@bors bors bot changed the title WebGL2 support [Merged by Bors] - WebGL2 support Oct 29, 2021
@bors bors bot closed this Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen O-Web Specific to web (WASM) builds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants