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

Return Rgba8UnormSrgb instead of Bgra8UnormSrgb as default swapchain format for WebGL target #1284

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 8 additions & 2 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,14 @@ impl<B: GfxBackend> Adapter<B> {
return Err(GetSwapChainPreferredFormatError::NotFound);
}

// If no formats were returned, use Bgra8UnormSrgb
Ok(wgt::TextureFormat::Bgra8UnormSrgb)
let is_webgl = cfg!(gl) && cfg!(target_arch = "wasm32");
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 we should be fixing this at the wgpu-core level.
The semantics of supported_formats is:

If None is returned then the surface has no preferred format and the application may use any desired format.

Obviously, this isn't the case for WebGL. So our OpenGL backend has to return a reasonable set of formats here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gfx-rs fix - gfx-rs/gfx#3699

Obviously, this isn't the case for WebGL. So our OpenGL backend has to return a reasonable set of formats here

Why we return any formats here if supported_formats is none instead of return None to users?

Copy link
Member

Choose a reason for hiding this comment

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

Here? Because in wgpu the get_swap_chain_preferred_format has to return one format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for explain! gfx-rs fix should be enough.


// If no formats were returned, use Bgra8UnormSrgb (native/WebGPU) and Rgba8UnormSrgb (WebGL)
if is_webgl {
Ok(wgt::TextureFormat::Rgba8UnormSrgb)
} else {
Ok(wgt::TextureFormat::Bgra8UnormSrgb)
}
}

pub(crate) fn get_texture_format_features(
Expand Down