<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi all,</div><div><br></div><div>I have tested it on Intel CI and it just fixes test without any regression:</div><div><a href="https://mesa-ci.01.org/global_logic/builds/27/group/63a9f0ea7bb98050796b649e85481845">https://mesa-ci.01.org/global_logic/builds/27/group/63a9f0ea7bb98050796b649e85481845</a></div><br><div>This patch fixes piglit test:</div><div> <a href="https://bugs.freedesktop.org/show_bug.cgi?id=92822">https://bugs.freedesktop.org/show_bug.cgi?id=92822</a></div><div dir="ltr"><br>At the moment it is marked as expected failure.</div><div><div dir="ltr">So it fails with message: "ERROR: This test passed when it expected failure"</div></div><div><br></div><div>It would be grate if somebody reviews this patch) <br></div><div><br></div><div>Thanks,</div><div>Andrii.</div><div><div class="gmail_quote"><div dir="ltr">On Thu, Sep 20, 2018 at 5:03 PM <<a href="mailto:asimiklit.work@gmail.com">asimiklit.work@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Andrii Simiklit <<a href="mailto:andrii.simiklit@globallogic.com" target="_blank">andrii.simiklit@globallogic.com</a>><br>
<br>
It fixes a bit incorrectly implemented ARB_program_interface_query.<br>
If input aoa element is unused in shader program<br>
the 'glGetProgramResourceIndex' function shouldn't<br>
return a valid resource index for it according to:<br>
ARB_program_interface_query spec:<br>
" For an active variable declared as an array of an aggregate data type<br>
(structures or arrays), a separate entry will be generated for each<br>
active array element"<br>
<br>
v2: - Fixed case where the non-AoA elements were removed form<br>
the program resource list.<br>
The KHR-GL46.enhanced_layouts.varying_structure_locations<br>
test is passed now<br>
- Fixed case where a dereference index is not constant:<br>
The proper array length stored in 'deref->array->type->length'<br>
not in 'deref->type->length'<br>
- Fixed the output AoA elements handling:<br>
The list of active input AoA elements should not be used for<br>
output AoA elements<br>
- Fixed the function name from 'enumiramte_active_elements' to<br>
'enumerate_active_elements'<br>
- Fixed errors handling during active AoA elements enumeration<br>
<br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=92822" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=92822</a><br>
Signed-off-by: Andrii Simiklit <<a href="mailto:andrii.simiklit@globallogic.com" target="_blank">andrii.simiklit@globallogic.com</a>><br>
---<br>
src/compiler/Makefile.sources | 4 +-<br>
.../glsl/ir_collect_active_aoa_elements.cpp | 155 ++++++++++++++++++<br>
.../glsl/ir_collect_active_aoa_elements.h | 52 ++++++<br>
src/compiler/glsl/linker.cpp | 91 ++++++++--<br>
src/compiler/glsl/meson.build | 2 +<br>
5 files changed, 289 insertions(+), 15 deletions(-)<br>
create mode 100644 src/compiler/glsl/ir_collect_active_aoa_elements.cpp<br>
create mode 100644 src/compiler/glsl/ir_collect_active_aoa_elements.h<br>
<br>
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources<br>
index d3b0656483..a2ba3e37f1 100644<br>
--- a/src/compiler/Makefile.sources<br>
+++ b/src/compiler/Makefile.sources<br>
@@ -154,7 +154,9 @@ LIBGLSL_FILES = \<br>
glsl/serialize.cpp \<br>
glsl/serialize.h \<br>
glsl/string_to_uint_map.cpp \<br>
- glsl/string_to_uint_map.h<br>
+ glsl/string_to_uint_map.h \<br>
+ glsl/ir_collect_active_aoa_elements.cpp \<br>
+ glsl/ir_collect_active_aoa_elements.h<br>
<br>
LIBGLSL_SHADER_CACHE_FILES = \<br>
glsl/shader_cache.cpp \<br>
diff --git a/src/compiler/glsl/ir_collect_active_aoa_elements.cpp b/src/compiler/glsl/ir_collect_active_aoa_elements.cpp<br>
new file mode 100644<br>
index 0000000000..df0a41ad3e<br>
--- /dev/null<br>
+++ b/src/compiler/glsl/ir_collect_active_aoa_elements.cpp<br>
@@ -0,0 +1,155 @@<br>
+/*<br>
+ * Copyright © 2018 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "ir_collect_active_aoa_elements.h"<br>
+#include "program.h"<br>
+#include "linker_util.h"<br>
+#include "util/set.h"<br>
+#include "util/u_dynarray.h"<br>
+<br>
+namespace<br>
+{<br>
+ /***<br>
+ * Helps to collect the names of used aoa elements<br>
+ * to the accessed_elements set<br>
+ ***/<br>
+ struct elem_inserter<br>
+ {<br>
+ elem_inserter(struct set *accessed_elements_)<br>
+ : accessed_elements(accessed_elements_)<br>
+ {}<br>
+ bool operator ()(const char *name)<br>
+ {<br>
+ bool oval = true;<br>
+ if (NULL == _mesa_set_search(accessed_elements, name)) {<br>
+ oval = (_mesa_set_add(accessed_elements, name) != NULL);<br>
+ }<br>
+ return oval;<br>
+ }<br>
+ struct set *accessed_elements;<br>
+ };<br>
+<br>
+ bool<br>
+ ir_is_array_deref(ir_rvalue *const ir)<br>
+ {<br>
+ return (ir_type_dereference_array == ir->ir_type);<br>
+ }<br>
+<br>
+ ir_variable *<br>
+ base_ir_dereference_var(ir_dereference_array *const ir)<br>
+ {<br>
+ ir_dereference_array const *base_ir = ir;<br>
+ while (ir_type_dereference_array == base_ir->array->ir_type) {<br>
+ base_ir = base_ir->array->as_dereference_array();<br>
+ assert(NULL != base_ir);<br>
+ }<br>
+<br>
+ ir_dereference_variable *const d =<br>
+ base_ir->array->as_dereference_variable();<br>
+ return (NULL == d) ? NULL : d->var;<br>
+ }<br>
+}<br>
+/**<br>
+ * Helps to produce all combinations of used aoa elements<br>
+ * for cases with constant and variable index.<br>
+ **/<br>
+template <typename FunctorType><br>
+inline bool enumerate_active_elements(void *memctx,<br>
+ ir_dereference_array **first,<br>
+ ir_dereference_array **item,<br>
+ const char *accessed_elem_name,<br>
+ FunctorType functor)<br>
+{<br>
+ if (NULL == accessed_elem_name) {<br>
+ return false;<br>
+ }<br>
+ if(item == (first - 1))<br>
+ return functor(accessed_elem_name);<br>
+<br>
+ ir_dereference_array *const deref = (*item);<br>
+ ir_constant const *const idx = deref->array_index->as_constant();<br>
+ if (NULL != idx) {<br>
+ const unsigned uidx = idx->get_uint_component(0U);<br>
+ char *elem = ralloc_asprintf(memctx, "%s[%u]",<br>
+ accessed_elem_name, uidx);<br>
+<br>
+ if(!enumerate_active_elements(memctx, first, item - 1, elem, functor))<br>
+ return false;<br>
+ }<br>
+ else {<br>
+ for (unsigned i = 0U; i < deref->array->type->length; ++i) {<br>
+ char *elem = ralloc_asprintf(memctx, "%s[%u]",<br>
+ accessed_elem_name, i);<br>
+ if(!enumerate_active_elements(memctx, first, item - 1, elem, functor))<br>
+ return false;<br>
+ }<br>
+ }<br>
+ return true;<br>
+}<br>
+<br>
+ir_visitor_status<br>
+ir_collect_active_aoa_elements::visit_enter(ir_dereference_array *ir)<br>
+{<br>
+ if (!ir_is_array_deref(ir->array))<br>
+ return visit_continue;<br>
+<br>
+ last_array_deref = ir;<br>
+ if (last_array_deref && last_array_deref->array == ir)<br>
+ return visit_continue;<br>
+<br>
+ ir_variable *const var = base_ir_dereference_var(ir);<br>
+ if (!var)<br>
+ return visit_continue;<br>
+<br>
+ struct util_dynarray indexes;<br>
+ util_dynarray_init(&indexes, NULL);<br>
+ /* The first element it is dereference<br>
+ * of regular array not aoa so skip it.<br>
+ * All the dereference which are stored in<br>
+ * the IR tree are storead as in the following instance:<br>
+ *<br>
+ * gl_Position = myarr[5][3][1];<br>
+ *<br>
+ * The first dereference will have an array_index = [1]<br>
+ * The second dereference will have an array_index = [3]<br>
+ * The third dereference will have an array_index = [5]<br>
+ * So we need to traverse over the elements in the reverse direction<br>
+ * to enumerate all combinations of used aoa elements.<br>
+ */<br>
+ ir_rvalue *it = ir->array;<br>
+ while (ir_is_array_deref(it)) {<br>
+ ir_dereference_array *deref = it->as_dereference_array();<br>
+ assert(NULL != deref);<br>
+ assert(deref->array->type->is_array());<br>
+ util_dynarray_append(&indexes, ir_dereference_array*, deref);<br>
+ it = deref->array;<br>
+ }<br>
+ ir_dereference_array **last = util_dynarray_top_ptr(&indexes,<br>
+ ir_dereference_array*);<br>
+ ir_dereference_array **first = util_dynarray_element(&indexes,<br>
+ ir_dereference_array*, 0);<br>
+ error = !enumerate_active_elements(memctx, first, last, var->name,<br>
+ elem_inserter(accessed_elements));<br>
+ util_dynarray_fini(&indexes);<br>
+ return error ? visit_stop : visit_continue_with_parent;<br>
+}<br>
\ No newline at end of file<br>
diff --git a/src/compiler/glsl/ir_collect_active_aoa_elements.h b/src/compiler/glsl/ir_collect_active_aoa_elements.h<br>
new file mode 100644<br>
index 0000000000..5ca1dca7ac<br>
--- /dev/null<br>
+++ b/src/compiler/glsl/ir_collect_active_aoa_elements.h<br>
@@ -0,0 +1,52 @@<br>
+/*<br>
+ * Copyright © 2018 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#ifndef IR_COLLECT_ACTIVE_AOA_ELEMENTS_H<br>
+#define IR_COLLECT_ACTIVE_AOA_ELEMENTS_H<br>
+<br>
+#include "ir.h"<br>
+#include "util/hash_table.h"<br>
+<br>
+class ir_collect_active_aoa_elements : public ir_hierarchical_visitor {<br>
+public:<br>
+ ir_collect_active_aoa_elements(void *memctx_,<br>
+ struct set *accessed_elements_)<br>
+ : memctx(memctx_),<br>
+ accessed_elements(accessed_elements_),<br>
+ last_array_deref(0),<br>
+ error(false)<br>
+ {<br>
+ }<br>
+ virtual ir_visitor_status visit_enter(ir_dereference_array *);<br>
+ bool has_error() const { return this->error; }<br>
+private:<br>
+ void *memctx;<br>
+ struct set *accessed_elements;<br>
+ /**<br>
+ * Used to prevent some redundant calculations.<br>
+ */<br>
+ ir_dereference_array *last_array_deref;<br>
+ bool error;<br>
+};<br>
+<br>
+#endif /* IR_COLLECT_ACTIVE_AOA_ELEMENTS_H */<br>
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp<br>
index 3fde7e78d3..b41cd735ae 100644<br>
--- a/src/compiler/glsl/linker.cpp<br>
+++ b/src/compiler/glsl/linker.cpp<br>
@@ -83,6 +83,7 @@<br>
#include "ir_uniform.h"<br>
#include "builtin_functions.h"<br>
#include "shader_cache.h"<br>
+#include "ir_collect_active_aoa_elements.h"<br>
#include "util/u_string.h"<br>
#include "util/u_math.h"<br>
<br>
@@ -94,6 +95,32 @@<br>
<br>
namespace {<br>
<br>
+struct set * find_active_aoa_elements(void *mem_ctx,<br>
+ gl_linked_shader * linked_shader,<br>
+ struct gl_shader_program *shProg)<br>
+{<br>
+ struct set *active_aoa_elems =<br>
+ _mesa_set_create(mem_ctx, _mesa_key_hash_string,<br>
+ _mesa_key_string_equal);<br>
+ ir_collect_active_aoa_elements v(mem_ctx, active_aoa_elems);<br>
+ visit_list_elements(&v, linked_shader->ir);<br>
+#if 0<br>
+ if(!v.has_error()) {<br>
+ set_entry *entry;<br>
+ /* Print the active array of arrays "aoa" elements */<br>
+ set_foreach(active_aoa_elems, entry)<br>
+ {<br>
+ fprintf(stderr, "used aoa element : %s\n", (const char *)entry->key);<br>
+ }<br>
+ } else {<br>
+ fprintf(stderr, "error: ir_collect_active_aoa_elements completed with an error!\n");<br>
+ }<br>
+#endif<br>
+ if(v.has_error()) {<br>
+ linker_error(shProg, "error during active AoA elements enumeration!\n");<br>
+ }<br>
+ return v.has_error() ? NULL : active_aoa_elems;<br>
+}<br>
struct find_variable {<br>
const char *name;<br>
bool found;<br>
@@ -3880,7 +3907,9 @@ add_shader_variable(const struct gl_context *ctx,<br>
const char *name, const glsl_type *type,<br>
bool use_implicit_location, int location,<br>
bool inouts_share_location,<br>
- const glsl_type *outermost_struct_type = NULL)<br>
+ const glsl_type *outermost_struct_type = NULL,<br>
+ struct set *active_aoa_elems = NULL,<br>
+ uint32_t array_dimension = 0)<br>
{<br>
const glsl_type *interface_type = var->get_interface_type();<br>
<br>
@@ -3942,7 +3971,8 @@ add_shader_variable(const struct gl_context *ctx,<br>
stage_mask, programInterface,<br>
var, field_name, field->type,<br>
use_implicit_location, field_location,<br>
- false, outermost_struct_type))<br>
+ false, outermost_struct_type,<br>
+ NULL, 0U))<br>
return false;<br>
<br>
field_location += field->type->count_attribute_slots(false);<br>
@@ -3967,19 +3997,40 @@ add_shader_variable(const struct gl_context *ctx,<br>
* separate active variable."<br>
*/<br>
const struct glsl_type *array_type = type->fields.array;<br>
- if (array_type->base_type == GLSL_TYPE_STRUCT ||<br>
- array_type->base_type == GLSL_TYPE_ARRAY) {<br>
+ if (array_type->is_record() || array_type->is_array()) {<br>
+ const bool is_aoa = array_type->is_array_of_arrays();<br>
unsigned elem_location = location;<br>
unsigned stride = inouts_share_location ? 0 :<br>
array_type->count_attribute_slots(false);<br>
for (unsigned i = 0; i < type->length; i++) {<br>
char *elem = ralloc_asprintf(shProg, "%s[%d]", name, i);<br>
- if (!add_shader_variable(ctx, shProg, resource_set,<br>
- stage_mask, programInterface,<br>
- var, elem, array_type,<br>
- use_implicit_location, elem_location,<br>
- false, outermost_struct_type))<br>
- return false;<br>
+ /* Single dimensional array of structs is accepted by default*/<br>
+ const bool acceptable_elem = (array_dimension < 1u &&<br>
+ array_type->is_record()) ||<br>
+ /*if next type has an aoa type<br>
+ * the aoa elem name is not completed yet<br>
+ * and we will just come here again<br>
+ **/<br>
+ is_aoa ||<br>
+ /* if active_aoa_elems is NULL we will add all elements<br>
+ */<br>
+ (NULL == active_aoa_elems) ||<br>
+ /* if this aoa element is used<br>
+ * it can be added as resource<br>
+ * otherwise shouldn't be added<br>
+ **/<br>
+ (NULL != _mesa_set_search(active_aoa_elems, elem));<br>
+ if(acceptable_elem) {<br>
+ if (!add_shader_variable(ctx, shProg, resource_set,<br>
+ stage_mask, programInterface,<br>
+ var, elem, array_type,<br>
+ use_implicit_location, elem_location,<br>
+ false, outermost_struct_type,<br>
+ /*Pass the NULL to accept all elements*/<br>
+ is_aoa ? active_aoa_elems : NULL,<br>
+ array_dimension + 1U))<br>
+ return false;<br>
+ }<br>
elem_location += stride;<br>
}<br>
return true;<br>
@@ -4025,7 +4076,8 @@ static bool<br>
add_interface_variables(const struct gl_context *ctx,<br>
struct gl_shader_program *shProg,<br>
struct set *resource_set,<br>
- unsigned stage, GLenum programInterface)<br>
+ unsigned stage, GLenum programInterface,<br>
+ struct set *active_aoa_elems)<br>
{<br>
exec_list *ir = shProg->_LinkedShaders[stage]->ir;<br>
<br>
@@ -4078,7 +4130,8 @@ add_interface_variables(const struct gl_context *ctx,<br>
1 << stage, programInterface,<br>
var, var->name, var->type, vs_input_or_fs_output,<br>
var->data.location - loc_bias,<br>
- inout_has_same_location(var, stage)))<br>
+ inout_has_same_location(var, stage),<br>
+ NULL, active_aoa_elems))<br>
return false;<br>
}<br>
return true;<br>
@@ -4415,13 +4468,22 @@ build_program_resource_list(struct gl_context *ctx,<br>
if (!add_fragdata_arrays(ctx, shProg, resource_set))<br>
return;<br>
<br>
+ // temporary mem context for program res building<br>
+ void *res_build_mem_ctx = ralloc_context(NULL);<br>
+ struct set *in_active_aoa_elems = find_active_aoa_elements(res_build_mem_ctx,<br>
+ shProg->_LinkedShaders[input_stage], shProg);<br>
/* Add inputs and outputs to the resource list. */<br>
if (!add_interface_variables(ctx, shProg, resource_set,<br>
- input_stage, GL_PROGRAM_INPUT))<br>
+ input_stage, GL_PROGRAM_INPUT,<br>
+ in_active_aoa_elems))<br>
return;<br>
<br>
+ struct set *out_active_aoa_elems = find_active_aoa_elements(res_build_mem_ctx,<br>
+ shProg->_LinkedShaders[output_stage], shProg);<br>
+<br>
if (!add_interface_variables(ctx, shProg, resource_set,<br>
- output_stage, GL_PROGRAM_OUTPUT))<br>
+ output_stage, GL_PROGRAM_OUTPUT,<br>
+ out_active_aoa_elems))<br>
return;<br>
<br>
if (shProg->last_vert_prog) {<br>
@@ -4538,6 +4600,7 @@ build_program_resource_list(struct gl_context *ctx,<br>
}<br>
<br>
_mesa_set_destroy(resource_set, NULL);<br>
+ ralloc_free(res_build_mem_ctx);<br>
}<br>
<br>
/**<br>
diff --git a/src/compiler/glsl/meson.build b/src/compiler/glsl/meson.build<br>
index 7e4dd2929a..fffae246af 100644<br>
--- a/src/compiler/glsl/meson.build<br>
+++ b/src/compiler/glsl/meson.build<br>
@@ -198,6 +198,8 @@ files_libglsl = files(<br>
'serialize.h',<br>
'shader_cache.cpp',<br>
'shader_cache.h',<br>
+ 'ir_collect_active_aoa_elements.cpp',<br>
+ 'ir_collect_active_aoa_elements.h',<br>
)<br>
<br>
files_libglsl_standalone = files(<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div></div></div></div></div>