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

Vulkan Backend Not Doing Gamma Correction/sRGB Conversion #1646

Closed
zicklag opened this issue Jul 13, 2021 · 2 comments · Fixed by #1651
Closed

Vulkan Backend Not Doing Gamma Correction/sRGB Conversion #1646

zicklag opened this issue Jul 13, 2021 · 2 comments · Fixed by #1651

Comments

@zicklag
Copy link
Contributor

zicklag commented Jul 13, 2021

This was first reported in #1627, initially misinterpreted as a bug with the GL backend not being colored correctly

Description
Vulkan backend is not doing sRGB conversion or gamma correction resulting in a darker-than-normal image:

Repro steps
Run any of the examples such as cube or shadow using the Vulkan backend. Reproduced so far on:

  • Linux Nvidia Vulkan
  • Linux Intel Vulkan
  • Windows Intel Vulkan

Expected vs observed behavior

Expected:

screenshot-lines

Observed:

image

Extra materials
None applicable so far.

Platform
WGPU @ 4b4e393 on Linux with:

  • Intel(R) UHD Graphics (CML GT2)
  • Using GeForce GTX 1650
@kvark
Copy link
Member

kvark commented Jul 13, 2021

I checked Vulkan code, and it seems alright. Wgpu-core is asking for SRGB first, and Vulkan backend is expected to allow that. Would you be able to step through fn surface_capabilities on Vulkan adapter to see why SRGB isn't getting through?

@zicklag
Copy link
Contributor Author

zicklag commented Jul 14, 2021

Adding debug prints shows that the Bgra8UnformSrgb format is selected as the only available format:

[wgpu-hal/src/vulkan/adapter.rs:1057] format = Rgba8Unorm
[wgpu-hal/src/vulkan/adapter.rs:1063] supported = false
[wgpu-hal/src/vulkan/adapter.rs:1057] format = Rgba8UnormSrgb
[wgpu-hal/src/vulkan/adapter.rs:1063] supported = false
[wgpu-hal/src/vulkan/adapter.rs:1057] format = Bgra8Unorm
[wgpu-hal/src/vulkan/adapter.rs:1063] supported = false
[wgpu-hal/src/vulkan/adapter.rs:1057] format = Bgra8UnormSrgb
[wgpu-hal/src/vulkan/adapter.rs:1063] supported = true
[wgpu-hal/src/vulkan/adapter.rs:1068] formats = [
    Bgra8UnormSrgb,
]

But... I took a quick look at PrivateCapabilities::map_texture_format and I found that the Bgra8UnormSrgb was mapped to vulkan's B8G8R8_UNORM, not B8G8R8_SRGB! Fixing that works!

image

Thanks for telling me where to look @kvark !

I'll have a PR in a minute.

Edit: #1651

bors bot added a commit that referenced this issue Jul 14, 2021
1651: Fix Vulkan Backend Texture Format Mapping r=cwfitzgerald a=zicklag

Fixes the Bgra8UnormSrgb texture format.

**Connections**
Resolves #1646.

**Description**
Fixes the mappings between the `Bgra8UnormSrgb` and `Bgra8Unorm` texture formats and their Vulkan equivalents.

**Testing**
Tested on my Ubuntu 20.04 machine on:

- Intel(R) UHD Graphics (CML GT2) (Vulkan)
- GeForce GTX 1650 (Vulkan)


Co-authored-by: Zicklag <zicklag@katharostech.com>
@bors bors bot closed this as completed in 2896a6e Jul 14, 2021
zmerp pushed a commit to zmerp/wgpu that referenced this issue Jul 17, 2021
Fixes the Bgra8UnormSrgb texture format.

Resolves gfx-rs#1646.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants