bevy icon indicating copy to clipboard operation
bevy copied to clipboard

get proper texture format after the renderer is initialized, fix #3897

Open VitalyAnkh opened this issue 1 year ago • 6 comments

Objective

There is no Srgb support on some GPU and display protocols (for example, Nvidia's GPUs with Wayland). Thus TextureFormat::bevy_default() which returns Rgba8UnormSrgb or Bgra8UnormSrgb will cause panics on such platforms. This patch will resolve this problem. Fix #3897

Solution

Make initialize_renderer expose wgpu::Adapter and use wgpu::Adapter to get proper TextureFormat.

Changelog

  • Fixed #3897

VitalyAnkh avatar Jul 21 '22 08:07 VitalyAnkh

@superdump Thanks for your kind reply! Now I have removed the unused dbg!. The latest code now add AvailableTextureFormat resource to the World and use it for future use. I know the available TextureFormat should be computed per Surface, but it's still better than hard-coded values. And then we don't need to expose Adapter now but the code still does so now (if Bevy developers think it's useful, could I do it in another PR?). And I add a GpuImage field to UiPipeline to specify correct TextureFormat in impl<S: SpecializedRenderPipeline> SpecializedRenderPipelines<S>. The code still needs much tuning, but it could fix #3897 correctly now.

VitalyAnkh avatar Jul 21 '22 14:07 VitalyAnkh

Oops... It fails on x11 now. I will push more fixes.

VitalyAnkh avatar Jul 21 '22 14:07 VitalyAnkh

I think this PR could pass all checks now and with this, there won't be any "no available texture formats" error anymore. But the design still needs discussion. For example, should I expose Adapter in the World? And to make MeshPipe UiPipeline and SpritePipeline get the right TextureFormat, I add a GpuImage field to them, should I do this? Are there better ways to solve this problem?

VitalyAnkh avatar Jul 22 '22 11:07 VitalyAnkh

I've just run into the issue that this PR addresses. Any plans on getting it merged?

bemyak avatar Sep 05 '22 09:09 bemyak

@superdump @alice-i-cecile hi, what do you think about this PR? What should I do to get this merged?

VitalyAnkh avatar Sep 05 '22 09:09 VitalyAnkh

I’ll give this another look over soon. I would like to have reviewed this and other things already but life is what it is. I appreciate your patience.

superdump avatar Sep 06 '22 03:09 superdump

Friendly bumping @superdump and @alice-i-cecile to review this PR :heart:

bemyak avatar Sep 29 '22 13:09 bemyak

@alice-i-cecile @devil-ira Hi! Following your kind reviews, I have updated this PR. All the problems you proposed should be resolved. Please let me know if there is anything that should be improved, thanks!

VitalyAnkh avatar Sep 30 '22 06:09 VitalyAnkh

The latest force push makes prepare_view_targets use Res<RenderTextureFormat> other than Res<AvailableTextureFormats> to get proper texture format. It doesn't touch codes that have been reviewed.

VitalyAnkh avatar Sep 30 '22 13:09 VitalyAnkh

I had some trouble with refresh rates with a multi-monitor setup, so I switched to wayland and then bumped into this issue myself. I tried this PR, and while it does run, the colors aren't correct. poroporo

irate-devil avatar Oct 07 '22 16:10 irate-devil

@devil-ira This works as expected. The texture format in your image should be Bgra8Unorm other than Bgra8UnormSrgb, so it's definitely not correct. The real problem is winit (v0.26.0) on Nvidia GPU and Wayland can't get surface with Srgb colors, but this problem has been resolved in https://github.com/rust-windowing/glutin/pull/1435. After bevy migrates to the new winit the color should be correct. Bevy should work on Nvidia and Wayland with the new winit, even without this PR, but I think it's reasonable to get texture format at runtime other than pre-defined.

VitalyAnkh avatar Oct 07 '22 19:10 VitalyAnkh

After bevy migrates to the new winit the color should be correct. Bevy should work on Nvidia and Wayland with the new winit, even without this PR

Correction: Bevy also needs wgpu v0.14.0(https://github.com/gfx-rs/wgpu/releases/tag/v0.14.0) to have the winit Srgb issues fixed.

VitalyAnkh avatar Oct 07 '22 20:10 VitalyAnkh