-
Notifications
You must be signed in to change notification settings - Fork 953
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
Fastclear Bug With Intel Mesa Adapters on the GL Backend #1627
Comments
I'm just realizing that the lighter color of the clear color is actually because the entire render is actually lighter than it should be, not just the clear color. By forcing the pixel format of the renderbuffer to Export From Renderdoc: Screenshot of app ( for the same capture as above renderdoc export ): Edit: Additional note, the pixelated edges seems to be related to the alpha channel of the framebuffer. The reason changing the pixel format fixed the issue is because I took out the alpha channel. Another way to fix it that works is to set |
Hey, I think I might have gotten it! #1628. Not 100% sure it's a final solution, but we can continue discussion in the PR ( I put extra comments in there ). |
So this is actually a long standing bug on Intel cards on Linux with srgb. I'm not sure how we actually should be working around this reasonably, but it likely needs to be internal with shader rewriting. I'll take a look at your pr later tonight. |
@cwfitzgerald do you have a reference to the bug somewhere? Is this related to |
@kvark I've never actually filed this as I first hit it back when I was a baby graphics programmer and didn't know how to do such things :) I need to collect the information around it (as I suspect #725 is related) and file it up to the appropriate places. Maybe I'll hit up mesa on IRC now that that's a thing I know I can do. @zicklag Thank you for filing this! It is a very detailed issue which is always much appreciated! So a couple housekeeping things first. Do the reftests work correctly on gl on your machine? You can test this by running So looking at the images, it looks like what you put as the "expected" image is actually completely missing gamma correction and the erroneous image properly has error correction (though with artifacts). I can reproduce this lack of srgb conversion on my intel/linux machine on both vulkan and GL. I also confirmed on a separate machine that the darker image shows that there is no proper SRGB transformation going on when there is supposed to be. So this is 100% a driver bug at this point. As a user, you can so srgb conversion in your fragment shader or tonemapping pass with a regular framebuffer and it will work as expected. There won't be a simple fix for this unfortunately. Basically we're going need to:
This has some major hurtles that needs to be crossed first:
|
Injecting shader code isn't very practical for this, since we wouldn't be able to blend in proper space, anyway. |
So the blocking around the triangle is caused by https://gitlab.freedesktop.org/mesa/mesa/-/issues/2565. Can you run with the env flag The issue about vk not properly doing srgb seems unrelated. |
@zicklag are you using wayland? |
No, I'm running X11. PS: I'm going to look through your comments and test out what you suggested probably within the next few hours. |
Interesting, the original issue was different behavior on wayland. Thanks for testing! |
No problem! :D
No. Neither the
Oh, that's interesting. Makes sense now that I look at the screenshots in the example dirs. :) The reftests for Vulkan will interestingly still pass despite the sRGB difference. Not sure if that's expected.
That fixed it! Nice to know that something so simple was actually a driver bug and not something wrong with the code. I didn't write the code, but I couldn't figure out for the life of me why a So, in summary, there are 3 separate issues here, if I understand correctly:
That leaves the actionable items to be:
Does that sound about right? |
Another data point I just realized is that in my experiment to port Bevy's latest rendering branch from WGPU 0.9 to WGPU master I found out that everything looked darker, which is probably because of the gamma correction/sRGB conversion problem ( I don't know the difference 😁 ) I could possibly try to do a git bisect to see what commit caused it. Though it might be some massive commit like "switch to wgpu-hal" or something... Also, this is with the Vulkan backend, GL isn't working yet. WGPU 0.9: WGPU master: |
Yeah, the last time that I can find vulkan gamma working correctly was this commit: 1920606. And the first time I can find it broken ( where it also compiles on Linux ) is this commit: 5578222. It was the move to using |
Could you upload what the files
Yeah I think this is a swapchain thing, the reftests are headless so don't deal with the swapchain.
Yeah my haswell rig has srgb issues on both vk and gl.
Yup! Thank you for this amazingly clear issue!
Yeah I kinda feared that. Thanks for taking a look at the difference. I'm surprised this is only manifesting on intel though. |
Yep. It's just failing because of the intel fastclear bug. When passing ( screenshot-actual, screenshot-difference )
Interesting. Could it have to do with the EGL version, maybe? It seems that sRGB is only enabled for egl > 1.5: Lines 541 to 545 in c41efb0
|
oh. yeah that would do it XD This is gonna be fun to try to work around, though GL already relies on a blit, so it should be possible. |
So I can reproduce the srgb issue on intel/vulkan/windows, so issue 1 is definitely a vulkan backend issue. |
Yeah, I'm still looking around for what might cause it, but I haven't found anything yet. The swapchain creation looks nearly exactly the same as the gfx backend, so I'm looking around other places but nothing has stood out to me. Let me know if you want to open separate issues for these, I don't care either way, but on the topic of the Intel fastclear bug, from my tests we can avoid it by setting the environment variable inside the GL backend at instance creation, but unfortunately the environment variable needs to be set before we load the X11 ( and I'm assuming wayland, too ) display. This means we can't do it while enumerating adapters, which is where it would be nicest to do it because we could wait to add the environment variable until we found out that they were actually using an Intel Mesa adapter. Do you think it's safe enough just to set the |
Yeh we probably should split out the bugs into separate issues, this one could be for the fast clear issue. If you can do it, that'd be great, otherwise I'll do it a bit later today.
Yeah this should be fine, as long as we always set it on linux. It shouldn't affect any other adapters as it's an env only for the intel cards. This is a fine (if slow) short term solution, but we should work to see if we can find a way to prevent the bug from occurring at all because this is pessimising intel cards w/o the bug. |
This works around a Mesa bug on Intel cards: - https://gitlab.freedesktop.org/mesa/mesa/-/issues/2565 - gfx-rs#1627 (comment)
Great. I opened #1645 with the short-term solution, and I renamed this issue to be specific to the fastclear bug. I'll open a new issue for the Vulkan sRGB bug. |
1645: Disable Intel Fastclear in GL Backend r=kvark a=zicklag This works around a Mesa bug on Intel cards: - https://gitlab.freedesktop.org/mesa/mesa/-/issues/2565 - #1627 (comment) **Connections** Related to pixelated edges in GL backend brought up in #1627. **Description** This just adds the `INTEL_DEBUG=nofc` environment variable setting when creating an `Instance` using the GL backend in `wgpu_hal`. This is just a workaround until the mesa bug is fixed. I wanted to wait until adapters were enumerated to determine that the user wanted to use an Intel Mesa adapter, but the environment variable has to be set before the x11 display was opened so that wasn't an option. This may not be the strategy we want to take with this one, but it seems relatively harmless. Because the environment variable prefixed with `INTEL` anyway, it might not effect devices other than the ones we want to, which would be good. **Testing** I tested this on Ubuntu 20.04 with Mesa Intel(R) UHD Graphics (CML GT2) on using the GL backend. Co-authored-by: Zicklag <zicklag@katharostech.com>
This works around a Mesa bug on Intel cards: - https://gitlab.freedesktop.org/mesa/mesa/-/issues/2565 - gfx-rs#1627 (comment)
So I think we should do the following for dealing with the fastclear bug:
|
Just finished taking both of those measures and it now succesfully works around the bug on both desktop and WebGL. 🎉 Currently it's in my WebGL branch. I'm not sure if it's helpful or not, but let me know if you want me to split it out to a separate PR for just the desktop fastclear fix instead of leaving it merged with WebGL. |
Amazing! Yes splitting it out would be preferred, it'll make it easier to review. |
There you go! Created #1717. It turned out a little messier than I had hoped because, in order to draw the triangle for the shader clear, I had to add a bunch of boolean state values to keep track of whether I'm not sure if there's a simpler way to do that, but it's all I could come up with. Let me know if you have any ideas! |
Description
When using the OpenGL backend on Linux the clear color seems to behaving strangely. For one, the color itself is lighter than it should be. For two, the borders around any objects drawn on top of the clear color have an even lighter, pixelated version of the clear color.
I'm currently troubleshooting but I opened the issue to start the discussion. With my experimentation so far it seems completely related to the act of clearing the draw framebuffer. All other rendering and examples seem to work fine, and if you have an example where you can't see the clear color, such as the skybox example, everything looks great.
Also I've noticed some weird related behavior in my Renderdoc captures:
When I launch the example with Renderdoc it has the same problem as running it without Renderdoc ( which makes sense ):
And when I view the renderbuffer contents after the initial clear in renderdoc, it shows the clear color like it shows in the render, lighter than it should be:
The clear color shows the same in the draw step, all the way until the final framebuffer blit, where it is dark enough ( but still with pixelated edges ):
Yet, when I hover over the pixels in the image, the little thumbnail at the bottom shows the wrong ligher color:
Very strange.
I found that I could get rid of the pixelated edges by forcing the renderbuffer pixel format to be
RGBA8
, but the color was still off. I think thats the closest lead I have and I'm going to look into how different pixel formats efffect it, and maybe try binding the framebuffer storage to a texture instead of a renderbuffer and see if that makes any difference.PS: Very excited that the new GL backend on
wgpu-hal
is working for all the examples! This is the first time I've tried it that theshadow
,boids
, andskybox
examples have worked. I might try to tackle #1617, but I figured I'd try to get this one out of the way first. :)Repro steps
Run the
cube
orshadow
example with the OpenGL backend.Expected vs observed behavior
There should be no pixelated edges around objects and the clear color should be darker.
Expected:
Actual ( I think it's fine if the lines for the trangles aren't there, the issue is the background color ) :
Extra materials
Shadow example:
Platform
Running WGPU
cube
orshadow
examples on Linux Pop!_OS ( Ubuntu ) 20.04. Adapter info:The text was updated successfully, but these errors were encountered: