<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 30, 2018 at 4:18 AM, Timothy Arceri <span dir="ltr"><<a href="mailto:tarceri@itsqueeze.com" target="_blank">tarceri@itsqueeze.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">For now we skip SI && HAVE_LLVM < 0x0600 for simplicity. We also skip<br>
setting the more accurate masks for some builtin uniforms for now as<br>
it causes some piglit regressions.<br>
---<br>
</span> src/gallium/drivers/radeonsi/<wbr>si_shader.c     |  7 +++<br>
 src/gallium/drivers/radeonsi/<wbr>si_shader_nir.c | 90 ++++++++++++++++++++++++++--<br>
 2 files changed, 91 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/src/gallium/drivers/<wbr>radeonsi/si_shader.c b/src/gallium/drivers/<wbr>radeonsi/si_shader.c<br>
index 714415edba7..13b588eb68f 100644<br>
--- a/src/gallium/drivers/<wbr>radeonsi/si_shader.c<br>
+++ b/src/gallium/drivers/<wbr>radeonsi/si_shader.c<br>
@@ -2374,8 +2374,15 @@ static LLVMValueRef load_const_buffer_desc(struct si_shader_context *ctx, int i)<br>
<span class=""> static LLVMValueRef load_ubo(struct ac_shader_abi *abi, LLVMValueRef index)<br>
 {<br>
        struct si_shader_context *ctx = si_shader_context_from_abi(<wbr>abi);<br>
+       struct si_shader_selector *sel = ctx->shader->selector;<br>
+<br>
        LLVMValueRef ptr = LLVMGetParam(ctx->main_fn, ctx->param_const_and_shader_<wbr>buffers);<br>
<br>
+       if (sel->info.const_buffers_<wbr>declared == 1 &&<br>
</span>+           sel->info.shader_buffers_<wbr>declared == 0) {<br>
<span class="">+               return load_const_buffer_desc_fast_<wbr>path(ctx);<br>
+       }<br>
+<br>
        index = si_llvm_bound_index(ctx, index, ctx->num_const_buffers);<br>
        index = LLVMBuildAdd(ctx->ac.builder, index,<br>
                             LLVMConstInt(ctx->i32, SI_NUM_SHADER_BUFFERS, 0), "");<br>
diff --git a/src/gallium/drivers/<wbr>radeonsi/si_shader_nir.c b/src/gallium/drivers/<wbr>radeonsi/si_shader_nir.c<br>
</span>index 437eefc54d0..e116c23815b 100644<br>
--- a/src/gallium/drivers/<wbr>radeonsi/si_shader_nir.c<br>
+++ b/src/gallium/drivers/<wbr>radeonsi/si_shader_nir.c<br>
@@ -600,23 +600,98 @@ void si_nir_scan_shader(const struct nir_shader *nir,<br>
<span class=""><br>
        info->num_outputs = num_outputs;<br>
<br>
+       struct set *ubo_set = _mesa_set_create(NULL, _mesa_hash_pointer,<br>
+                                              _mesa_key_pointer_equal);<br>
+<br>
+       unsigned ubo_idx = 1;<br>
        nir_foreach_variable(variable, &nir->uniforms) {<br>
                const struct glsl_type *type = variable->type;<br>
                enum glsl_base_type base_type =<br>
                        glsl_get_base_type(glsl_<wbr>without_array(type));<br>
                unsigned aoa_size = MAX2(1, glsl_get_aoa_size(type));<br>
<br>
+               /* Gather buffers declared bitmasks. Note: radeonsi doesn't<br>
+                * really use the mask (other than ubo_idx == 1 for regular<br>
+                * uniforms) its really only used for getting the buffer count<br>
+                * so we don't need to worry about the ordering.<br>
+                */<br>
+               if (variable->interface_type != NULL) {<br>
+                       if (variable->data.mode == nir_var_uniform) {<br>
+<br>
</span>+                               unsigned block_count;<br>
<span class="">+                               if (base_type != GLSL_TYPE_INTERFACE) {<br>
+                                       struct set_entry *entry =<br>
+                                               _mesa_set_search(ubo_set, variable->interface_type);<br>
+<br>
+                                       /* Check if we have already processed<br>
+                                        * a member from this ubo.<br>
+                                        */<br>
+                                       if (entry)<br>
+                                               continue;<br>
+<br>
</span>+                                       block_count = 1;<br>
+                               } else {<br>
+                                       block_count = aoa_size;<br>
+                               }<br>
+<br>
+                               info->const_buffers_declared |= u_bit_consecutive(ubo_idx, block_count);<br>
+                               ubo_idx += block_count;<br>
<span class="">+<br>
+                               _mesa_set_add(ubo_set, variable->interface_type);<br>
+                       }<br>
+<br>
+                       if (variable->data.mode == nir_var_shader_storage) {<br>
+                               /* TODO: make this more accurate */<br>
+                               info->shader_buffers_declared =<br>
+                                       u_bit_consecutive(0, SI_NUM_SHADER_BUFFERS);<br>
+                       }<br>
+<br>
+                       continue;<br>
+               }<br>
+<br>
                /* We rely on the fact that nir_lower_samplers_as_deref has<br>
                 * eliminated struct dereferences.<br>
                 */<br>
-               if (base_type == GLSL_TYPE_SAMPLER)<br>
+               if (base_type == GLSL_TYPE_SAMPLER) {<br>
                        info->samplers_declared |=<br>
                                u_bit_consecutive(variable-><wbr>data.binding, aoa_size);<br>
-               else if (base_type == GLSL_TYPE_IMAGE)<br>
+<br>
+                       if (variable->data.bindless) {<br>
+                               info->const_buffers_declared |= 1;<br>
</span><span class="">+                               info->const_file_max[0] +=<br>
+                                       glsl_count_attribute_slots(<wbr>type, false);<br>
+                       }<br>
</span><span class="">+               } else if (base_type == GLSL_TYPE_IMAGE) {<br>
                        info->images_declared |=<br>
                                u_bit_consecutive(variable-><wbr>data.binding, aoa_size);<br>
+<br>
+                       if (variable->data.bindless) {<br>
+                               info->const_buffers_declared |= 1;<br>
</span><span class="">+                               info->const_file_max[0] +=<br>
+                                       glsl_count_attribute_slots(<wbr>type, false);<br>
+                       }<br>
</span><span class="">+               } else if (base_type != GLSL_TYPE_ATOMIC_UINT) {<br>
+                       if (strncmp(variable->name, "state.", 6) == 0 ||<br>
</span>+                           strncmp(variable->name, "gl_", 3) == 0) {<br>
<span class="">+                               /* FIXME: figure out why piglit tests with builtin<br>
+                                * uniforms are failing without this.<br>
+                                */<br>
+                               info->const_buffers_declared =<br>
+                                       u_bit_consecutive(0, SI_NUM_CONST_BUFFERS);<br>
+                       } else {<br>
+                               info->const_buffers_declared |= 1;<br>
+                               info->const_file_max[0] +=<br>
+                                       glsl_count_attribute_slots(<wbr>type, false);<br>
+                       }<br>
+               }<br>
        }<br>
<br>
+       _mesa_set_destroy(ubo_set, NULL);<br>
+<br>
+       /* This is the max index not max count so we adjust it here */<br>
+       if (info->const_file_max[0] != 0)<br>
+               info->const_file_max[0] -= 1;<br></span></blockquote><div><br></div><div>const_file_max should be -1 by default, so perhaps this can be done unconditionally.<br><br></div><div>Other than that:<br><br></div><div>Reviewed-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>><br><br></div><div>Marek<br></div></div><br></div></div>