aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/shader_query.cpp
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2014-05-08 00:18:25 +0200
committermarha <marha@users.sourceforge.net>2014-05-08 00:18:25 +0200
commit683155917770af9e63a938bc450df25d1904d567 (patch)
tree5eb9d2d0bba27ed4e8afe58c195d1918282c343b /mesalib/src/mesa/main/shader_query.cpp
parentea0cd87ecbe9fc3c5503ccad7f87a895a458d6d4 (diff)
downloadvcxsrv-683155917770af9e63a938bc450df25d1904d567.tar.gz
vcxsrv-683155917770af9e63a938bc450df25d1904d567.tar.bz2
vcxsrv-683155917770af9e63a938bc450df25d1904d567.zip
xserver xcb-proto mesa pixman xkeyboard-config git update 7 May 2014
xserver commit a5b9757142a2ab471ca26651dce9cc5f5e351f3d libxcb commit d978a4f69b30b630f28d07f1003cf290284d24d8 libxcb/xcb-proto commit 389889e2f95af19e7fc7ac89e7faeb2f28652415 xkeyboard-config commit 3e54f31b1f118f00c240f59d72d7ddb685c6db79 libX11 commit 8be4610939b833587954957f5963eb4191b43d19 libXdmcp commit 089081dca4ba3598c6f9bf401c029378943b5854 libXext commit 11aad96bd689d54156064d2e81213dc827a689d1 libfontenc commit 0037a42107b952c9d903719615747e760e4e7247 libXinerama commit edd95182b26eb5d576d4878c559e0f17dddaa909 libXau commit 1e4635be11154dd8262f37b379511bd627defa2a xkbcomp commit d4e02a09258063c6d024c3ccd42d6b22212e6e18 pixman commit 91f32ce961bc85f98b3372b95681ad8918d24b18 xextproto commit 66afec3f49e8eb0d4c2e9af7088fc3116d4bafd7 randrproto commit a4a6694c059d74247c16527eef4a0ec9f56bbef6 glproto commit f84853d97d5749308992412a215fa518b6536eb3 mkfontscale commit 399db42a151687f1181ae23d28a76d31125a2853 xwininfo commit ba0d1b0da21d2dbdd81098ed5778f3792b472e13 libXft commit 4acfdaf95adb0a05c2a25550bdde036c865902f4 libXmu commit 22d9c590901e121936f50dee97dc60c4f7defb63 libxtrans commit a57a7f62242e1ea972b81414741729bf3dbae0a4 fontconfig commit 81664fe54f117e4781fda5a30429b51858302e91 mesa commit 9ced3fc649ec04710a5f5c855bfb582b898cff83
Diffstat (limited to 'mesalib/src/mesa/main/shader_query.cpp')
-rw-r--r--mesalib/src/mesa/main/shader_query.cpp71
1 files changed, 66 insertions, 5 deletions
diff --git a/mesalib/src/mesa/main/shader_query.cpp b/mesalib/src/mesa/main/shader_query.cpp
index f66c11733..36d1d9cc0 100644
--- a/mesalib/src/mesa/main/shader_query.cpp
+++ b/mesalib/src/mesa/main/shader_query.cpp
@@ -153,6 +153,63 @@ _mesa_GetActiveAttrib(GLhandleARB program, GLuint desired_index,
_mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveAttrib(index)");
}
+/* Locations associated with shader variables (array or non-array) can be
+ * queried using its base name or using the base name appended with the
+ * valid array index. For example, in case of below vertex shader, valid
+ * queries can be made to know the location of "xyz", "array", "array[0]",
+ * "array[1]", "array[2]" and "array[3]". In this example index reurned
+ * will be 0, 0, 0, 1, 2, 3 respectively.
+ *
+ * [Vertex Shader]
+ * layout(location=0) in vec4 xyz;
+ * layout(location=1) in vec4[4] array;
+ * void main()
+ * { }
+ *
+ * This requirement came up with the addition of ARB_program_interface_query
+ * to OpenGL 4.3 specification. See page 101 (page 122 of the PDF) for details.
+ *
+ * This utility function is used by:
+ * _mesa_GetAttribLocation
+ * _mesa_GetFragDataLocation
+ * _mesa_GetFragDataIndex
+ *
+ * Returns 0:
+ * if the 'name' string matches var->name.
+ * Returns 'matched index':
+ * if the 'name' string matches var->name appended with valid array index.
+ */
+int static inline
+get_matching_index(const ir_variable *const var, const char *name) {
+ unsigned idx = 0;
+ const char *const paren = strchr(name, '[');
+ const unsigned len = (paren != NULL) ? paren - name : strlen(name);
+
+ if (paren != NULL) {
+ if (!var->type->is_array())
+ return -1;
+
+ char *endptr;
+ idx = (unsigned) strtol(paren + 1, &endptr, 10);
+ const unsigned idx_len = endptr != (paren + 1) ? endptr - paren - 1 : 0;
+
+ /* Validate the sub string representing index in 'name' string */
+ if ((idx > 0 && paren[1] == '0') /* leading zeroes */
+ || (idx == 0 && idx_len > 1) /* all zeroes */
+ || paren[1] == ' ' /* whitespace */
+ || endptr[0] != ']' /* closing brace */
+ || endptr[1] != '\0' /* null char */
+ || idx_len == 0 /* missing index */
+ || idx >= var->type->length) /* exceeding array bound */
+ return -1;
+ }
+
+ if (strncmp(var->name, name, len) == 0 && var->name[len] == '\0')
+ return idx;
+
+ return -1;
+}
+
GLint GLAPIENTRY
_mesa_GetAttribLocation(GLhandleARB program, const GLcharARB * name)
{
@@ -196,8 +253,10 @@ _mesa_GetAttribLocation(GLhandleARB program, const GLcharARB * name)
|| var->data.location < VERT_ATTRIB_GENERIC0)
continue;
- if (strcmp(var->name, name) == 0)
- return var->data.location - VERT_ATTRIB_GENERIC0;
+ int index = get_matching_index(var, (const char *) name);
+
+ if (index >= 0)
+ return var->data.location + index - VERT_ATTRIB_GENERIC0;
}
return -1;
@@ -358,7 +417,7 @@ _mesa_GetFragDataIndex(GLuint program, const GLchar *name)
|| var->data.location < FRAG_RESULT_DATA0)
continue;
- if (strcmp(var->name, name) == 0)
+ if (get_matching_index(var, (const char *) name) >= 0)
return var->data.index;
}
@@ -414,8 +473,10 @@ _mesa_GetFragDataLocation(GLuint program, const GLchar *name)
|| var->data.location < FRAG_RESULT_DATA0)
continue;
- if (strcmp(var->name, name) == 0)
- return var->data.location - FRAG_RESULT_DATA0;
+ int index = get_matching_index(var, (const char *) name);
+
+ if (index >= 0)
+ return var->data.location + index - FRAG_RESULT_DATA0;
}
return -1;