ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
57.85k stars 9.92k forks source link

Glitches in OpenGL/DX renderers on Intel GPU #3033

Open smok95 opened 4 years ago

smok95 commented 4 years ago

(you may also go to Demo>About Window, and click "Config/Build Information" to obtain a bunch of detailed information that you can paste here)

Version/Branch of Dear ImGui:

Dear ImGui 1.76 WIP (17502)
--------------------------------
sizeof(size_t): 4, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _MSC_VER=1924
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx10
io.ConfigFlags: 0x00000021
 NavEnableKeyboard
 NoMouseCursorChange
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1167.00,728.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Dear ImGui 1.76 WIP (17502)
--------------------------------
sizeof(size_t): 4, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _MSC_VER=1924
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x00000006
 HasMouseCursors
 HasSetMousePos
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1268.00,357.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Compiler: msvc1924(vs2019) / msvc1600(vs2010) Operating System: windows 7 64bit / windows 10 Pro 64bit (1909, OS Build:18363.657)

My Issue/Question: what an awesome project. Thank you for your hard work!

I did download source code and build examples using vs2019( and vs2010) (I had never change source code.)

and ran an example program. (I did a test on windows 7 64bit and Windows 10 64bit with vs2010 and vs2019)

Please watch the below screenshots and gif animation carefully. Irregularly something(small line?) blink slightly

I wonder why does this happen.

Screenshots/Video imgui_blink_something

imgui_blink_something1 imgui_blink_something2

ocornut commented 4 years ago

My feeling is that it may be an issue with OpenGL drivers.

smok95 commented 4 years ago

Thanks very much for quick reply It also has same issue with directx. If it was a opengl drivers issue, is it also directx drivers issue? Thanks

ocornut commented 4 years ago

Maybe it is a hardware issue? I find it surprising that this kind of effect would happen with the example app accross multiple backends.

ocornut commented 4 years ago

You can open Tools>Metrics and look at the polygon count, try to record a video and see if the polygon count changed when the glitch happen.

smok95 commented 4 years ago

Thank you very much I will check just as you said.

djdeath commented 4 years ago

Are you using an Intel GPU? I've noticed the same on my laptop.

smok95 commented 4 years ago

Yes, I'm using an Intel GPU(UHD Graphics 630)

jon-dez commented 4 years ago

If it helps narrow down this issue I'd also like to mention that the same thing happens on my laptop with Intel UHD Graphics 620 when using OpenGl 3.

Seems consistent with both of you guys.

ocornut commented 4 years ago

OK so this looks very real, and even more surprising if it happens with multiple graphics API. I don’t think I myself have the knowledge to begin to guess what we might be doing wrong.

If you have issue on your machine, could you try running variety of examples and see where the bug happens for you (do you have it with dx9/dx11/dx12/vulkan as well?).

Myszkoj commented 2 years ago

I noticed that those glitches tend to be at least partially dependant on the mouse cursor. When I move it fast over many controls glitches start to statistically mimic movement of the cursor. Do you use some custom cursor rendering, or do you change it through OS events?

Myszkoj commented 2 years ago

Ok, I don't know if this is coincidance, but in my case they have color of the text. I changed my theme so that text color was always different than other GUI elements. What is more interesting is that sometimes glitches had color of the text from a previous test, so if I changed it to red, they show up red, but if I changed it to green they show up red few times, and then green. I assume that ImGui treats font rendering the same as any other element(it renders one or two triangles with UV on the texture/glyph atlas), so there is probably an array with vertex/color data per quad. There is usually a lot of characters compared to other GUI elements so text color is more common in that buffer. My guess is that those glitches are remnants of the previous iteration in that buffer. At some point when I was designing my own control I looked at polyline rendering(or something similar) and you basically append the buffer with the assumption that you will use N amount of triangles/quads, but if you use less than that you have to shift back the remaining, unused triangles/quads. Does that sound familiar, or I remember something incorrectly? Maybe there is a bug in one of those functions and you return wrong amount of space in the buffer? That's the only explenation that I can think of why those glitches would have those colors.

ocornut commented 2 years ago

There's no bug of that sort in the ImDrawList functions, it's entirely a bug between the backend code and the driver. Perhaps double-buffering those buffer would help but normally as I understand it shouldn't be necessary.

Myszkoj commented 2 years ago

Then how do you explain the color behaviors? They are definitely not random.

Myszkoj commented 2 years ago

Are those draw lists cleared to zeros every frame, or you simply set current buffer size to 0?

ocornut commented 2 years ago

Then how do you explain the color behaviors? They are definitely not random.

It's probably using data from Frame N+1 on Frame N or vice-versa, it makes sense. I suppose if backends has N in-flight buffers (where N can be configured by user to be 2 or 3). But it only happens with Intel GPU drivers afaik, what is your GPU and driver version? Can you try updating drivers?

Are those draw lists cleared to zeros every frame, or you simply set current buffer size to 0?

The later, we don't superfluously clear data we don't need to clear. It wouldn't be a correct solution to clear them either way.

PS: This is not an IRC channel, please avoid spamming either threads with oneliner questions. This needs thoughtful research. Each of your message here are e-mailed to ~1000 people.

Myszkoj commented 2 years ago

Keeping buffer from the previous frame and setting its size to 0 at the beginning of the new frame is of course a good idea. It was just a guess and at that time, it looked for me like a random quad with undefined state caused by some pointer shifting logic, but I was wrong. I can confirm that problem disappears when I switch to NVIDIA gpu. My intel card: Intel UHD Graphics 630 Drivers at the time glitch occurs: 27.20.100.9664 (newest according to windows). I looked inside ImGui::ImGui_ImplOpenGL3_RenderDrawData function and noticed that you create and destroy vertex array object every frame. Maybe there is something wrong with vbo-vao binding in the intel drivers(new vao binds storage of the vbo from the previous frame). I tried to make this vao global and generate it in ImGui_ImplOpenGL3_CreateDeviceObjects and destroy in ImGui_ImplOpenGL3_DestroyDeviceObjects, but it doesn't work and I don't have a knowlage of your code to make it work and test. Anyway, sorry for the spam and that I couldn't help.

Voxtric commented 2 years ago

I've been having this exact issue as well. I've gone down quite a rabbit hole in trying to figure it out, and I have managed to impact this but never eliminate it. What I've tried and the results below:

One thing I've definitely noticed is that it occurs more frequently when there are large amounts of filled rectangles on the screen. For example, I have a window with a lot of drop downs and it was barely happening. I changed those drop downs to use the collapsible header style, and the issue became much more frequent.

Jack-Ji commented 2 years ago

I'm experiencing simillar problems with windows11/Opengl3/Intel graphics card, here's what I did:

The imgui window will flicker from time to time, even disappear completely some time. BTW, I'm using version 1.86.