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: use get_preferred_canvas_format() to fill SurfaceCapabilities #3744

Merged
merged 6 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Bottom level categories:

- Disable suballocation on Intel Iris(R) Xe. By @xiaopengli89 in [#3668](https://github.com/gfx-rs/wgpu/pull/3668)

#### WebGPU

- Use `get_preferred_canvas_format()` to fill `formats` of `SurfaceCapabilities`. By @jinleili in [#3744](https://github.com/gfx-rs/wgpu/pull/3744)

### Examples

#### General
Expand Down
25 changes: 20 additions & 5 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,13 +1113,28 @@ impl crate::context::Context for Context {
_adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData,
) -> wgt::SurfaceCapabilities {
let mut formats = vec![
wgt::TextureFormat::Rgba8Unorm,
wgt::TextureFormat::Bgra8Unorm,
wgt::TextureFormat::Rgba16Float,
];
let mapped_formats: Vec<_> = formats
.iter()
.map(|format| map_texture_format(*format))
.collect();
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
// Preferred canvas format will only be either "rgba8unorm" or "bgra8unorm".
// https://www.w3.org/TR/webgpu/#dom-gpu-getpreferredcanvasformat
let preferred_format = self.0.get_preferred_canvas_format();
if let Some(index) = mapped_formats
.iter()
.position(|format| *format == preferred_format)
{
formats.swap(0, index);
}
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved

wgt::SurfaceCapabilities {
// https://gpuweb.github.io/gpuweb/#supported-context-formats
formats: vec![
wgt::TextureFormat::Bgra8Unorm,
wgt::TextureFormat::Rgba8Unorm,
wgt::TextureFormat::Rgba16Float,
],
formats,
// Doesn't really have meaning on the web.
present_modes: vec![wgt::PresentMode::Fifo],
alpha_modes: vec![wgt::CompositeAlphaMode::Opaque],
Expand Down