Bug 93731 - glUniformSubroutinesuiv segfaults when subroutine uniform is bound to a specific location
Summary: glUniformSubroutinesuiv segfaults when subroutine uniform is bound to a speci...
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: 11.0
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-16 00:02 UTC by Nicolas Koch
Modified: 2016-01-18 00:55 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
fragment shader to test segfault (396 bytes, text/plain)
2016-01-16 00:02 UTC, Nicolas Koch
Details
vertex shader which can be used with the fragment shader (93 bytes, text/plain)
2016-01-16 00:02 UTC, Nicolas Koch
Details

Description Nicolas Koch 2016-01-16 00:02:00 UTC
Created attachment 121069 [details]
fragment shader to test segfault

In GLSL, one can specify the location of a subroutine uniform by using something like:
#extension GL_ARB_shader_subroutine : require
#extension GL_ARB_explicit_uniform_location : require
layout(location = 5) subroutine uniform color_t Color;

Assuming this is the only subroutine uniform, you should be able to set it's value by calling:

UniformSubroutinesuiv(GL_FRAGMENT_SHADER, 6, &[0, 0, 0, 0, 0 , subroutin_index]);

According to the spec, the values [0]-[4] should be ignored, and the subroutine uniform at location 5 should be set to `subroutin_index`.
Mesa will segfault when calling this function like that.

Unfortunately, I do not have a complete minimum example program right now (I'm not good with raw opengl), but attached is a fragment shader which can be used to reproduce the problem.
Comment 1 Nicolas Koch 2016-01-16 00:02:56 UTC
Created attachment 121070 [details]
vertex shader which can be used with the fragment shader
Comment 2 Timothy Arceri 2016-01-17 05:21:03 UTC
Thanks for the bug report.

Mesa fix:
http://patchwork.freedesktop.org/patch/70667/

Piglit test:
http://patchwork.freedesktop.org/patch/70666/
Comment 3 Timothy Arceri 2016-01-18 00:55:23 UTC
Should be fixed by:

commit	86677f101641c75d52577e3cd9e76441b1228b21

mesa: fix segfault in glUniformSubroutinesuiv()
From Section 7.9 (SUBROUTINE UNIFORM VARIABLES) of the OpenGL
4.5 Core spec:

   "The command

       void UniformSubroutinesuiv(enum shadertype, sizei count,
                                  const uint *indices);

   will load all active subroutine uniforms for shader stage
   shadertype with subroutine indices from indices, storing
   indices[i] into the uniform at location i. The indices for
   any locations between zero and the value of
   ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS minus one which are not
   used will be ignored."

V2: simplify NULL check suggested by Jason.

Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Cc: "11.0 11.1" mesa-stable@lists.freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=93731


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.