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

web: Automatically chosen preferred renderer #10831

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WindowMode,
Letterbox,
LogLevel,
RenderBackend,
} from "./load-options";

export const DEFAULT_CONFIG: Required<BaseLoadOptions> = {
Expand Down Expand Up @@ -35,5 +36,5 @@ export const DEFAULT_CONFIG: Required<BaseLoadOptions> = {
publicPath: null,
polyfills: true,
playerVersion: null,
preferredRenderer: null,
preferredRenderer: RenderBackend.Automatic,
};
7 changes: 6 additions & 1 deletion web/packages/core/src/load-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ export const enum WindowMode {
* The available backends may change in future releases.
*/
export const enum RenderBackend {
/**
* Lets Ruffle select which renderer to use.
*/
Automatic = "",

/**
* An [in-development API](https://caniuse.com/webgpu) that will be preferred if available in the future.
* Should behave the same as wgpu-webgl, except with lower overhead and thus better performance.
Expand Down Expand Up @@ -384,7 +389,7 @@ export interface BaseLoadOptions {
* The available values in order of default preference are:
* "webgpu", "wgpu-webgl", "webgl", "canvas".
*
* @default null
* @default RenderBackend.Automatic
*/
preferredRenderer?: RenderBackend | null;

Expand Down
1 change: 1 addition & 0 deletions web/packages/extension/assets/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</div>
<div class="option select">
<select id="preferred_renderer">
<option value="">Automatic</option>
<option value="webgpu">WebGPU</option>
<option value="wgpu-webgl">Wgpu (via WebGL)</option>
<option value="webgl">WebGL</option>
Expand Down
8 changes: 5 additions & 3 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,11 @@ async fn create_renderer(

let mut renderer_list = vec!["webgpu", "wgpu-webgl", "webgl", "canvas"];
if let Some(preferred_renderer) = &config.preferred_renderer {
if let Some(pos) = renderer_list.iter().position(|&r| r == preferred_renderer) {
renderer_list.remove(pos);
renderer_list.insert(0, preferred_renderer.as_str());
if !preferred_renderer.is_empty() {
if let Some(pos) = renderer_list.iter().position(|&r| r == preferred_renderer) {
renderer_list.remove(pos);
renderer_list.insert(0, preferred_renderer.as_str());
}
}
}

Expand Down