https://bugs.freedesktop.org/show_bug.cgi?id=28341
Summary: Flickering screen in Neverball on drm-radeon-testing Product: Mesa Version: git Platform: Other OS/Version: All Status: NEW Severity: normal Priority: medium Component: Drivers/DRI/R600 AssignedTo: dri-devel@lists.freedesktop.org ReportedBy: magnus@jensenligan.se
Mesa and ddx patched with tiling patches from dri-devel mailing list. drm-radeon-testing kernel. HD3650 (rv635) AGP gpu.
When starting neverball the title screen flickers with black until the start of a level, graphics is then (almost) fine.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #1 from Alex Deucher agd5f@yahoo.com 2010-06-01 08:54:46 PDT --- Are there any CS related messages in your dmesg?
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #2 from Magnus Jensen magnus@jensenligan.se 2010-06-01 11:37:20 PDT --- Created an attachment (id=35995) --> (https://bugs.freedesktop.org/attachment.cgi?id=35995) dmesg/current
The last output from dmesg after running neverball for a few seconds. The notice about mesa being outdated is not valid in this case since, it still flickers whether i recompile mesa or not. I have got same error without that message.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #3 from Magnus Jensen magnus@jensenligan.se 2010-06-01 12:25:42 PDT --- Sorry. ignore my last attachment. These errors continue to spawn and i don't think they are related to neverball. i'm going to recompile mesa and ddx, and post another dmesg soon. Just waiting for a kernel compile to finish.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Magnus Jensen magnus@jensenligan.se changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #35995|0 |1 is obsolete| |
--- Comment #4 from Magnus Jensen magnus@jensenligan.se 2010-06-01 15:11:57 PDT --- Created an attachment (id=35997) --> (https://bugs.freedesktop.org/attachment.cgi?id=35997) dmesg-current
no radeon related stuff in dmesg output while running neverball (still flickers a lot) drm+mesa+ddx all latest from git. this do not occur with distro kernel (2.6.33.4)
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #5 from Andrew Randrianasulu randrik@mail.ru 2010-06-04 17:25:44 PDT --- I was under impression i hit same bug here on rv280 + wine + DeusEx, but after manually applying patches from http://article.gmane.org/gmane.comp.video.dri.devel/46630 i still have flickering intro. This is with git xserver ... should i wait for kernel-based solution for testing my case or open different bug?
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #6 from Alex Deucher agd5f@yahoo.com 2010-06-09 13:45:19 PDT --- possibly also related to bug 28383 and bug 28410.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #7 from Andy Furniss lists@andyfurniss.entadsl.com 2010-06-14 16:56:56 PDT --- (In reply to comment #6)
possibly also related to bug 28383 and bug 28410.
I am currently running with a patch that fixes 28383 but have just noticed that the mesa demo ipers does not render properly (with or without patch) - it's flashing until I reduce the LOD enough that the fps gets capped to refresh rate when it then renders OK.
It renders OK with swrast and if I boot an older kernel that uses the old vsync.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Mario Kleiner mario.kleiner@tuebingen.mpg.de changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |mario.kleiner@tuebingen.mpg | |.de
--- Comment #8 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-06-15 04:32:49 PDT --- Seems that some synchronisation in the radeon kernel drm driver is missing, which wasn't needed for the old synchronous vsync code;
Old glXSwapbuffers code was synchronous: glXSwapBuffers blocked until swap completion.
The new code just schedules a vblank event, then returns control to the client. The client submits further rendering commands into the command stream before the swap has completed, so you have a race-condition between the client submitting new commands for the post-swap backbuffer and the vblank event triggering submission of the "bufferswap blit" command buffer into the cs a couple of milliseconds after the glXSwapbuffers call. Depending on the relative timeing, it can happen that *new* rendering commands, e.g., glClear() get executed on the *old* backbuffer before it has been copied to the frontbuffer. Would result in random flickering or half-rendered frames overdrawn on top of old rendered frame.
The solution would be to add some synchronisation to the kernel driver: If a swapbuffers is pending and a client tries to submit command buffers for that drawable, block it until swap completion. This is what the intel drivers apparently do and what seems to be missing fromt the radeon driver.
Michel Daenzer confirmed my suspicion with some patch (conversation on dri-devel):
"The ideal solution would probably be to make the kernel block in the command stream (CS) submission ioctl if the CS renders to (and from?) a buffer object (BO) which is involved in a pending swap.
Meanwhile, the attached hacks for xf86-video-ati and Mesa seem to help here, YMMV."
He added this patch to mesa inside the Dri2Swapbuffers submission code, after the swap has been scheduled:
+ + /* Make sure we call to the server before rendering again, in case we need + * to block for the swap */ + dri2InvalidateBuffers(dpyPriv->dpy, pdraw->drawable);
This is what i found (also posted on dri-devel):
"I saw a similar flickering with latest Xorg stack (mesa master, xserver, ddx etc. master) and the 2.6.34 tree from radeon testing with my own toolkit on a R600 gpu. This setup uses the new dri sync & swap bits and changes how glXSwapbuffers works.
This shows flickering, but load and timing dependent...
.... glXXX rendering commands to draw image. glXSwapBuffers(); glBegin(GL_POINTS); glVertex2i(10,10); glEnd(); glFinish(); Take a swap completion timestamp here. glClear(); ...more rendering commands
-> I use this glVertex2i, .... glFinish() sequence to wait for swap completion and get a timestamp. This works on any os/gpu combo ever tested, but doesn't seem to work reliably anymore with the new radeon sync & swap bits in place. Display flickers, presumably because the glClear() executes almost immediately after the glXSwapBuffers is scheduled, and before the bufferswap has actually taken place -> Clear the backbuffer before swapping.
This however:
.... glXXX rendering commands to draw image. glXSwapBuffers(); glXWaitForSbcOML(...); glClear(); ...
does work, because the new glXWaitForSbcOML() blocks the client until swap completion, so glClear() can only get submitted to the gpu after the swap completed."
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Michel Dänzer michel@daenzer.net changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |glisse@freedesktop.org
--- Comment #9 from Michel Dänzer michel@daenzer.net 2010-07-09 08:24:20 PDT --- Jerome, do you have a plan for fixing this, or should we just stop exposing DRI2 vsync again until there's a solution?
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #10 from Michel Dänzer michel@daenzer.net 2010-07-14 02:30:55 PDT --- Does reverting xf86-video-ati Git commit 30591320ec46e491ba20904cc64f3405b51c6505 ('kms: add support for the MSC swap & sync API') fix this problem?
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #11 from Andy Furniss lists@andyfurniss.entadsl.com 2010-07-14 04:03:15 PDT --- (In reply to comment #10)
Does reverting xf86-video-ati Git commit 30591320ec46e491ba20904cc64f3405b51c6505 ('kms: add support for the MSC swap & sync API') fix this problem?
It doesn't revert on master for me.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #12 from Michel Dänzer michel@daenzer.net 2010-07-14 04:22:20 PDT --- Created an attachment (id=37035) View: https://bugs.freedesktop.org/attachment.cgi?id=37035 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37035
Revert xf86-video-ati commit 30591320ec46e491ba20904cc64f3405b51c6505
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #13 from Andy Furniss lists@andyfurniss.entadsl.com 2010-07-14 05:04:35 PDT --- (In reply to comment #12)
Created an attachment (id=37035)
View: https://bugs.freedesktop.org/attachment.cgi?id=37035 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37035
Revert xf86-video-ati commit 30591320ec46e491ba20904cc64f3405b51c6505
That fixes my two test cases - ipers and sauerbraten.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #14 from Andy Furniss lists@andyfurniss.entadsl.com 2010-07-16 06:02:09 PDT --- (In reply to comment #13)
(In reply to comment #12)
Created an attachment (id=37035)
View: https://bugs.freedesktop.org/attachment.cgi?id=37035 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37035
Revert xf86-video-ati commit 30591320ec46e491ba20904cc64f3405b51c6505
That fixes my two test cases - ipers and sauerbraten.
I see that with today's mesa master another workaround is possible.
vblank_mode=0 as an env (~/.drirc doesn't work for me) when running my test cases will fix the issue without the patch.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Shlomi Steinberg ssteinberg@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |ssteinberg@gmail.com
--- Comment #15 from Shlomi Steinberg ssteinberg@gmail.com 2010-07-16 08:16:32 PDT --- *** Bug 29098 has been marked as a duplicate of this bug. ***
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #16 from Jerome Glisse glisse@freedesktop.org 2010-07-22 10:00:00 PDT --- Created an attachment (id=37317) View: https://bugs.freedesktop.org/attachment.cgi?id=37317 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37317
Add flush,invalidate on swap with msc
Please try if attached patch fix the issue for you (apply against mesa no change needed in ddx)
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #17 from Shlomi Steinberg ssteinberg@gmail.com 2010-07-22 11:09:51 PDT --- Patched today's mesa git. Still need vblank_mode=0.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #18 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-07-22 13:23:07 PDT --- Jerome,
as far as i can see, your flush, invalidate patch is in the right direction, but the dri2InvalidateDrawable() call just increments drawable->dri2.stamp and the current radeon dri driver in current mesa isn't checking the drawable->dri2.stamp for changes.
The intel driver has checks like...
if (drawable->lastStamp != drawable->dri2.stamp) intel_update_renderbuffers(driContext, drawable);
... in various places. Similar checks and calls to radeon_update_renderbuffers() would probably do the trick, because that would call DRI2GetBuffersWithFormat() etc. which will throttle properly until a swap is completed.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Mario Kleiner mario.kleiner@tuebingen.mpg.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #37317|0 |1 is obsolete| |
--- Comment #19 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-07-25 08:15:20 PDT --- Created an attachment (id=37366) View: https://bugs.freedesktop.org/attachment.cgi?id=37366 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37366
Add flush, invalidate on dri2 swap, fixed.
Fixed version of Jerome's patch. The flush, invalidate extension was added at the wron place, therefore never called by the driver at dri2InvalidateBuffer() time.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #20 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-07-25 08:26:41 PDT --- Created an attachment (id=37368) View: https://bugs.freedesktop.org/attachment.cgi?id=37368 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37368
Proof of concept "fix" for R600/R700. Act on dri2InvalidateDrawable().
This patch together with the previous patch applied to current mesa git master eliminates the flicker problem on my tested apps with a R600 card.
A new function radeon_prepare_render() checks the timestamps that get updated by dri2InvalidateDrawable() to find out if a swap is in progress / buffers are invalidated. If so, it uses radeon_update_buffers() to get "new" buffers. That function will also throttle the client if a swap is still in progress. We'd need to add a call to radeon_prepare_render() to various places in the driver. This is what the intel driver does with intel_prepare_render() to avoid artifacts.
I've only added a check to r700DrawPrims() to see if it works at all. I don't know at which other locations such calls would be needed (and i'm a bloody beginner), so this is a pretty sketchy start.
-mario
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #21 from Shlomi Steinberg ssteinberg@gmail.com 2010-07-25 13:07:54 PDT --- Confirmed. Both patches fix etracer for me. r600, HD 3850.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Jerome Glisse glisse@freedesktop.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #37366|0 |1 is obsolete| | Attachment #37368|0 |1 is obsolete| |
--- Comment #22 from Jerome Glisse glisse@freedesktop.org 2010-07-26 12:26:20 PDT --- Created an attachment (id=37401) View: https://bugs.freedesktop.org/attachment.cgi?id=37401 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37401
Fix dri2 swap
Can you confirm that the attach patch fix the issue for you (i have tested it on r200,r300,r600 and it seems to work UMS/KMS while also fixing what i believe is the issue you reported on KMS+DRI2)
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #23 from Andrew Randrianasulu randrik@mail.ru 2010-07-26 14:30:28 PDT --- (In reply to comment #22)
Created an attachment (id=37401)
View: https://bugs.freedesktop.org/attachment.cgi?id=37401 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37401
Fix dri2 swap
Can you confirm that the attach patch fix the issue for you (i have tested it on r200,r300,r600 and it seems to work UMS/KMS while also fixing what i believe is the issue you reported on KMS+DRI2)
Works for me on RV280 (DRI2 + xserver git, 1.9.0 RC 5, kernel 2.6.35-rc5+). Tested with wine 1.2 and 3DMark2001, DeusEx_demo
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #24 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-07-26 17:31:53 PDT --- Jerome,
your Improved patch works on R600 for me as well, thanks for improving it and teaching me about the proper draw functions for non-r600 gpu's :-). It took me half a day to initially find r700DrawPrim() as the proper location for R600.
Looking at the code and comparing with the intel driver i think we should also add a radeon_prepare_render() to radeonReadPixels() in radeon_pixel_read.c, and the "copy from colorbuffer" path inside do_copy_texsubimage() in radeon_tex_copy.c ? Reading/Copying from the backbuffer/frontbuffer must also make sure it operates on the post-swap buffers, therefore wait for swap completion.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #25 from Andy Furniss lists@andyfurniss.entadsl.com 2010-07-27 03:26:58 PDT --- (In reply to comment #22)
Created an attachment (id=37401)
View: https://bugs.freedesktop.org/attachment.cgi?id=37401 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37401
Fix dri2 swap
Can you confirm that the attach patch fix the issue for you (i have tested it on r200,r300,r600 and it seems to work UMS/KMS while also fixing what i believe is the issue you reported on KMS+DRI2)
It fixes my test cases (ipers and sauerbraten) testing with rv770.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #26 from Andy Furniss lists@andyfurniss.entadsl.com 2010-07-27 06:47:43 PDT --- (In reply to comment #25)
(In reply to comment #22)
Created an attachment (id=37401)
View: https://bugs.freedesktop.org/attachment.cgi?id=37401 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37401
Fix dri2 swap
Can you confirm that the attach patch fix the issue for you (i have tested it on r200,r300,r600 and it seems to work UMS/KMS while also fixing what i believe is the issue you reported on KMS+DRI2)
It fixes my test cases (ipers and sauerbraten) testing with rv770.
I've found a regression caused by the patch, the mesa demo singlebuffer segfaults.
singlebuffer[11119]: segfault at bf634ff0 ip b77e2b97 sp bf634fd0 error 6 in libGL.so.1.2[b77a7000+4e000]
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #27 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-07-27 10:50:26 PDT --- Created an attachment (id=37414) View: https://bugs.freedesktop.org/attachment.cgi?id=37414 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37414
Fix frontbuffer rendering, avoid segfault in singlebuffer demo.
This patch on top of the other patch works for me with mesa's singlebuffer demo. It translants a little bit more logic from the intel driver to handle frontbuffer flushing and avoid infinite recursion which caused the segfault.
I had to do radeon->front_buffer_dirty = GL_FALSE before calling flushFrontBuffer to avoid infinite recursion, whereas intel does it the other way round. Either i'm missing something (very likely), or intel does something subtile differently (likely), or the intel driver should have the same infinite recursion bug and segfault in singlebuffer demo.
Anybody with an intel gpu to test singlebuffer demo?
https://bugs.freedesktop.org/show_bug.cgi?id=28341
--- Comment #28 from Andy Furniss lists@andyfurniss.entadsl.com 2010-07-27 11:30:10 PDT --- (In reply to comment #27)
Created an attachment (id=37414)
View: https://bugs.freedesktop.org/attachment.cgi?id=37414 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37414
Fix frontbuffer rendering, avoid segfault in singlebuffer demo.
This patch on top of the other patch works for me
Also fixes for me.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Mario Kleiner mario.kleiner@tuebingen.mpg.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #37401|0 |1 is obsolete| | Attachment #37414|0 |1 is obsolete| |
--- Comment #29 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-08-01 19:55:22 PDT --- Created an attachment (id=37513) View: https://bugs.freedesktop.org/attachment.cgi?id=37513 Review: https://bugs.freedesktop.org/review?bug=28341&attachment=37513
radeon: Add DRI2 flush extension support so we synchronize properly to bufferswaps.
Ok,
i've merged all previous working patches into this patch and retested on current mesa master.
I'll send this one to mesa-devel for inclusion.
https://bugs.freedesktop.org/show_bug.cgi?id=28341
Mario Kleiner mario.kleiner@tuebingen.mpg.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED
--- Comment #30 from Mario Kleiner mario.kleiner@tuebingen.mpg.de 2010-08-02 12:11:45 PDT --- Patch with fix now in mesa master. Closing as resolved.
dri-devel@lists.freedesktop.org