Skip to content

[Merged by Bors] - WebGL2 support#3039

Closed
mrk-its wants to merge 8 commits intobevyengine:pipelined-renderingfrom
mrk-its:webgl2
Closed

[Merged by Bors] - WebGL2 support#3039
mrk-its wants to merge 8 commits intobevyengine:pipelined-renderingfrom
mrk-its:webgl2

Conversation

@mrk-its
Copy link
Copy Markdown
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
}
}

fn handle_initial_window_events(world: &mut World, event_loop: &EventLoop<()>) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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".


# misc
wgpu = { version = "0.11.0", features = ["spirv"] }
wgpu = { version = "0.11.0", features = ["spirv", "webgl"] }
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

bors bot commented Oct 29, 2021

Build failed:

@cart
Copy link
Copy Markdown
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
Copy Markdown
Contributor

bors bot commented Oct 29, 2021

Build failed:

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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