From: Antia Puentes Date: Mon, 13 Aug 2018 16:48:37 +0000 (+0200) Subject: mesa/shader_query: Fix NAME_LENGTH queries (ARB_gl_spirv) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=96d6156678929d3d480fca3b4458767df31f4ee7;p=mesa.git mesa/shader_query: Fix NAME_LENGTH queries (ARB_gl_spirv) For shaders constructed from SPIR-V binaries, it is possible that no name reflection information is available. In that case, - glGetProgramInterfaceiv(.., pname=MAX_NAME_LENGTH, ..) - gletProgramResourceiv(.., props=NAME_LENGTH, ..) should return 1. Signed-off-by: Antia Puentes Signed-off-by: Andres Gomez Reviewed-by: Caio Marcelo de Oliveira Filho --- diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp index 3fcd4fcedc5..a3365107648 100644 --- a/src/mesa/main/shader_query.cpp +++ b/src/mesa/main/shader_query.cpp @@ -778,7 +778,15 @@ add_index_to_name(struct gl_program_resource *res) extern unsigned _mesa_program_resource_name_len(struct gl_program_resource *res) { - unsigned length = strlen(_mesa_program_resource_name(res)); + const char* name = _mesa_program_resource_name(res); + + /* For shaders constructed from SPIR-V binaries, variables may not + * have names associated with them. + */ + if (!name) + return 0; + + unsigned length = strlen(name); if (_mesa_program_resource_array_size(res) && add_index_to_name(res)) length += 3; return length; @@ -819,7 +827,11 @@ _mesa_get_program_resource_name(struct gl_shader_program *shProg, _mesa_copy_string(name, bufSize, length, _mesa_program_resource_name(res)); - if (_mesa_program_resource_array_size(res) && add_index_to_name(res)) { + /* The resource name can be NULL for shaders constructed from SPIR-V + * binaries. In that case, we do not add the '[0]'. + */ + if (name && name[0] != '\0' && + _mesa_program_resource_array_size(res) && add_index_to_name(res)) { int i; /* The comparison is strange because *length does *NOT* include the