Bug 105161 - KHR_blend_equation_advanced doesn't work in GLSL 1.10-1.40 shaders
Summary: KHR_blend_equation_advanced doesn't work in GLSL 1.10-1.40 shaders
Status: RESOLVED MOVED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: 17.3
Hardware: Other All
: medium normal
Assignee: Kenneth Graunke
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-19 11:25 UTC by Allan Sandfeld Jensen
Modified: 2019-09-18 20:26 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Allan Sandfeld Jensen 2018-02-19 11:25:30 UTC
I noticed your drivers are advertising support for blend_advanced and blend_advanced_coherent, but couldn't understand why it still didn't work. I traced it down to you enforcing that fragment shaders needs to enable which advanced blend equation they work with, something the NVidia driver does not.

I think it would be in your best interest to only warn on that and not abort the operation. If you can't do it correctly without that hint, that is of course acceptable, it is there for a reason, but it seems you are only doing the validation for the sake of strictness, and that is hurting your drivers compatibility.
Comment 1 Allan Sandfeld Jensen 2018-02-19 11:26:23 UTC
I traced the issue to this commit:

commit acf57fcf7ff7e60c3550da7b6dda7ad8b69195bd
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Sat Aug 20 12:51:03 2016 -0700

    mesa: Add draw time validation for advanced blending modes.
    
    v2: Add null checks (requested by Curro).
    
    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
    Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Comment 2 Allan Sandfeld Jensen 2018-02-19 13:19:05 UTC
Note. I have been unable to get it to work at all in compatibility-mode desktop OpenGL. The following code only works in core mode: 

#ifdef GL_KHR_blend_equation_advanced
#extension GL_KHR_blend_equation_advanced : require
layout(blend_support_all_equations) out;
#endif

because layout is not identified in basic OpenGL 2.0, and while

#ifdef GL_KHR_blend_equation_advanced
#extension GL_ARB_explicit_attrib_location : enable
#extension GL_KHR_blend_equation_advanced : require
layout(blend_support_all_equations) out;
#endif

parses, it doesn't actually change anything. Mesa still reports: 
Mesa: User error: GL_INVALID_OPERATION in fragment shader does not allow advanced blending mode (GL_MULTIPLY)

With NVidia drivers, I don't need any changes to fragment shaders.
Comment 3 Ilia Mirkin 2018-02-19 14:39:45 UTC
The specification is available at

https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_blend_equation_advanced.txt

If you find the NVIDIA drivers doing something different than what's written there, feel free to report the bug to them.

If you find mesa drivers doing something different, please do let us know.

If either implementation has a bug, it would also make sense to request a VK-GL-CTS test that enforces the correct behavior (https://github.com/KhronosGroup/VK-GL-CTS/issues).
Comment 4 Ilia Mirkin 2018-02-19 14:43:18 UTC
Specifically, the ext spec says,

"""
    A draw-time error will be generated in the OpenGL API if an application
    attempts to render using an advanced blending equation without having a
    matching layout qualifier specified in the active fragment shader.
"""

So pretty sure mesa is in the right here, and NVIDIA is buggy. (And as an aside, the mesa implementation relies on the options being supplied properly, since code is inserted conditionally into the shader. I'm guessing NVIDIA just has a global library and doesn't care.)
Comment 5 Kenneth Graunke 2018-02-19 17:42:17 UTC
Yep, the error is correct and required by the spec.  That's a bug in the NVIDIA drivers, and it would be good to have a VK-GL-CTS test to enforce it.

The fact that layout qualifiers don't parse correctly in legacy shading language versions is our bug.  I'll send a patch shortly.
Comment 6 Allan Sandfeld Jensen 2018-02-21 18:51:38 UTC
Right. I think NVidia can get away with it because this requirement is new in the KHR version, they also implement the original NV version which doesnt have it (and like is OpenGL norm, they share the same GL defines).

Anyway since you are actually using the declaration and it has significant impact in compile time of the shader, I withdraw my complaint and suggestion.
Comment 7 Kenneth Graunke 2018-02-22 01:51:49 UTC
layout qualifier parsing in legacy shaders should be fixed with:

commit 183ce5e629ee973d72a3e8b3361aa2de196cc203
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Mon Feb 19 09:35:46 2018 -0800

    glsl: Parse 'layout' as a token with advanced blending or bindless
    
    Both KHR_blend_equation_advanced and ARB_bindless_texture provide
    layout qualifiers, and are exposed in compatibility contexts.  We
    need to parse the layout qualifier as a token in order for those
    to work, but forgot to extend this check.
    
    ARB_shader_image_load_store would need a similar treatment, but we
    don't expose that in legacy OpenGL contexts.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105161
    Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Comment 8 Allan Sandfeld Jensen 2018-02-22 13:04:30 UTC
That would fix the parsing in compatibility shaders. It doesn't make it work.

I found after digging into mesa code that I needed:

#extension GL_ARB_fragment_coord_conventions : enable

Otherwise the layout qualifiers are only passed, but not passed on. I am not sure if that is a bug, but there was nothing in the spec that suggested you need to manually activate that extension as well to get it the layout qualifier to work.
Comment 9 Allan Sandfeld Jensen 2018-02-22 13:06:04 UTC
The problem is the check in linker.cpp (link_fs_inout_layout_qualifiers):

   if (linked_shader->Stage != MESA_SHADER_FRAGMENT ||
       (prog->data->Version < 150 &&
        !prog->ARB_fragment_coord_conventions_enable))
      return;
Comment 10 GitLab Migration User 2019-09-18 20:26:52 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/mesa/mesa/issues/1022.


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.