Bug 101596

Summary: Blender renders black UI elements
Product: Mesa Reporter: Sebastian Parborg <darkdefende>
Component: Drivers/Gallium/radeonsiAssignee: Default DRI bug account <dri-devel>
Status: RESOLVED FIXED QA Contact: Default DRI bug account <dri-devel>
Severity: normal    
Priority: medium CC: darkdefende, dark_sylinc, maraeo
Version: git   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: glxinfo output
Blender before matcap
blender after matcap
Patch to fix bug

Description Sebastian Parborg 2017-06-26 12:18:36 UTC
Created attachment 132251 [details]
glxinfo output

It seems like a recent change to llvm or mesa broke blender on radeonsi. It works fine with llvm 4 and mesa 17.1.3.

Steps to reproduce:

1. Open the blender default cube scene.

2. Open the "N" panel by pressing N while your mouse cursor is in the 3d view.

3. Scroll down to the "Shading" tab and check "Matcap"

4. Now UI elements becomes black (and more and more will become black as you use the program)

See the attached screenshots

I should also point out that it is not only matcaps that triggers this. However, it is the fastest way to trigger this.

I have attached the output of glxinfo.

BTW, there is also a other long standing problem where you have to use tripple buffering in blender with radeonsi or the UI is messed up. I didn't find any bug for this either, but it has been a problem for a long time so I don't know if this is known?
Comment 1 Sebastian Parborg 2017-06-26 12:19:02 UTC
Created attachment 132252 [details]
Blender before matcap
Comment 2 Sebastian Parborg 2017-06-26 12:19:24 UTC
Created attachment 132253 [details]
blender after matcap
Comment 3 Sebastian Parborg 2017-06-26 22:38:22 UTC
I've narrowed it down to this commit:
https://cgit.freedesktop.org/mesa/mesa/commit/?id=56a28ace35c513ba22d754192127c359c28ed7e5

It seems like that is the one that breaks it.
Comment 4 Matias N. Goldberg 2017-07-05 03:22:00 UTC
+1
I get this error too.

This bug is NOT https://bugs.freedesktop.org/show_bug.cgi?id=97059 which gets fixed by either using DRI2 or selecting Triple Buffer in Blender.

This error started after I pulled latest git; and a faster way to reproduce it is to simply click on the Materials pane; where automatically everything starts going wrong within Blender.

I tried debugging the problem but came out short. My guess was either in the vertex shader's key.clamp_color would become true for the same variant where it used to be false, or that the same would happen in the pixel shader with clamp_color/persample_shading/ati_fs/external (i.e. test if any of st_fp_variant_key members changed but the same variant was being used).

However all shaders appear to be using consistent settings, which leaves me puzzled.

As Sebastian Parborg, undoing the changes "st_update_fp" fixes the problem.
Comment 5 Matias N. Goldberg 2017-07-05 03:33:51 UTC
Mystery solved:

When I click the material button, this function is hit:

1  st_get_fp_variant    st_program.c       1326 0x7fbb34c5c595 
2  get_color_fp_variant st_cb_drawpixels.c 963  0x7fbb34c0ae87 
3  st_DrawPixels        st_cb_drawpixels.c 1115 0x7fbb34c0b3ea 
4  _mesa_DrawPixels     drawpix.c          163  0x7fbb3499d954 
5  ??                                           0x55b9c4a159d5 
6  ??                                           0x55b9c4a15d20 
7  ??                                           0x55b9c4a3e15c 
8  ??                                           0x55b9c4a3f956 
9  ui_draw_but                                  0x55b9c4a428cb 
10 UI_block_draw                                0x55b9c49f700a 
11 UI_panels_draw                               0x55b9c4a23ede 
12 ED_region_panels                             0x55b9c4b11bbd 
13 ??                                           0x55b9c484050e 
14 ED_region_do_draw                            0x55b9c4b10837 
15 wm_draw_update                               0x55b9c4817a96 
16 WM_main                                      0x55b9c4813008 
17 main                                         0x55b9c47d015e 

get_color_fp_variant ends up calling st_get_fp_variant even though st->has_shareable_shaders is set; and st_get_fp_variant ends up creating a new variant.

st_get_fp_variant will create a new variant and add it to the front of the linked list:
fpv->next = stfp->variants;
stfp->variants = fpv;

Therefore later on st_update_fp thinks only one variant should be there, and tries to use the first one, which is the new one created by _mesa_DrawPixels; which is wrong, triggering all the glitches.
Comment 6 Michel Dänzer 2017-07-05 03:36:08 UTC
Marek, any ideas?
Comment 7 Matias N. Goldberg 2017-07-05 03:41:18 UTC
As I keep reading the code and getting familiar, everything starts making sense:

/**
* If a shader can be created when we get its source.
* This means it has only 1 variant, not counting glBitmap and
* glDrawPixels.
*/
boolean shader_has_one_variant[MESA_SHADER_STAGES];

The problem is that after glDrawPixels creates its own variant; st_update_fp will end up using glDrawPixels' variant, instead of the non-glDrawPixels one.

The same problem happens if glBitmap is used.

One simple solution would be to add the variant to the end of the linked list, but this may affect the performance profile of radeonsi (i.e. assuming variations created last are more likely to be used than variations created first).
The performance concerns can be negated by adding the variation to the end of the linked list ONLY if glDrawPixels or glBitmap is the caller.
Comment 8 Matias N. Goldberg 2017-07-05 17:05:47 UTC
Created attachment 132462 [details] [review]
Patch to fix bug

This patch fixes the problem by correctly handling glDrawPixel & glBitmap variations (both the cases where glDrawPixel was called before or after the standard variation has been generated), and fixes Blender.
Comment 9 Sebastian Parborg 2017-07-05 17:53:10 UTC
Thanks for fixing it, the patch seems to work nicely for me too.
Comment 10 Michel Dänzer 2017-07-06 00:59:35 UTC
Please send the patch to the mesa-dev mailing list for review.
Comment 11 Marek Olšák 2017-07-07 23:52:27 UTC
Pushed the fix as f728435e1f872af3efcd6b9215e8d722d35090cc. Closing.
Comment 12 Matias N. Goldberg 2017-07-08 02:41:47 UTC
Thank you for adding this commit despite my futile email!

I am getting up to speed with Mesa's patch submission process, but I wouldn't have had the time to fully read it until next week and resubmit the patch.

Thanks for taking the time to review it and include it!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.