From: Tapani Date: Fri, 5 Jun 2015 05:22:07 +0000 (+0300) Subject: mesa: fix program resource queries for builtin variables X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78395dbf9ff429d98523f8b4a340f7188d8b4db0;p=mesa.git mesa: fix program resource queries for builtin variables Patch fixes special cases with gl_VertexID and sets all builtin variables locations as '-1' as specified by the extension spec. Fixes ES 3.1 conformance test failure: ES31-CTS.program_interface_query.input-built-in v2: comments + use is_gl_identifier() (Martin) Signed-off-by: Tapani Pälli Reviewed-by: Martin Peres --- diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp index 3445f89a356..a6246a39aad 100644 --- a/src/mesa/main/shader_query.cpp +++ b/src/mesa/main/shader_query.cpp @@ -479,12 +479,20 @@ _mesa_GetFragDataLocation(GLuint program, const GLchar *name) const char* _mesa_program_resource_name(struct gl_program_resource *res) { + const ir_variable *var; switch (res->Type) { case GL_UNIFORM_BLOCK: return RESOURCE_UBO(res)->Name; case GL_TRANSFORM_FEEDBACK_VARYING: return RESOURCE_XFB(res)->Name; case GL_PROGRAM_INPUT: + var = RESOURCE_VAR(res); + /* Special case gl_VertexIDMESA -> gl_VertexID. */ + if (var->data.mode == ir_var_system_value && + var->data.location == SYSTEM_VALUE_VERTEX_ID_ZERO_BASE) { + return "gl_VertexID"; + } + /* fallthrough */ case GL_PROGRAM_OUTPUT: return RESOURCE_VAR(res)->name; case GL_UNIFORM: @@ -539,6 +547,17 @@ struct gl_program_resource * _mesa_program_resource_find_name(struct gl_shader_program *shProg, GLenum programInterface, const char *name) { + GET_CURRENT_CONTEXT(ctx); + const char *full_name = name; + + /* When context has 'VertexID_is_zero_based' set, gl_VertexID has been + * lowered to gl_VertexIDMESA. + */ + if (name && ctx->Const.VertexID_is_zero_based) { + if (strcmp(name, "gl_VertexID") == 0) + full_name = "gl_VertexIDMESA"; + } + struct gl_program_resource *res = shProg->ProgramResourceList; for (unsigned i = 0; i < shProg->NumProgramResourceList; i++, res++) { if (res->Type != programInterface) @@ -563,7 +582,7 @@ _mesa_program_resource_find_name(struct gl_shader_program *shProg, break; case GL_PROGRAM_INPUT: case GL_PROGRAM_OUTPUT: - if (array_index_of_resource(res, name) >= 0) + if (array_index_of_resource(res, full_name) >= 0) return res; break; default: @@ -728,6 +747,10 @@ program_resource_location(struct gl_shader_program *shProg, return -1; } + /* Built-in locations should report GL_INVALID_INDEX. */ + if (is_gl_identifier(name)) + return GL_INVALID_INDEX; + /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these * offsets are used internally to differentiate between built-in attributes * and user-defined attributes.