microsoft/clc: Move inline samplers to the end of the variable list
authorJesse Natalie <jenatali@microsoft.com>
Thu, 18 Feb 2021 19:05:43 +0000 (11:05 -0800)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Feb 2021 21:33:54 +0000 (21:33 +0000)
Since inline samplers are uniforms, just like kernel args, and
nir_lower_vars_to_explicit_types will assign driver_location based
on order in the variable list, move the inline samplers to the end
of the list to prevent them from creating gaps in the kernel arg
offsets.

Fixes: ff05da7f ("microsoft: Add CLC frontend and kernel/compute support to DXIL converter")
Reviewed-By: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9138>

src/microsoft/clc/clc_compiler.c

index 3b68fff..03e9ec3 100644 (file)
@@ -1209,8 +1209,11 @@ clc_to_dxil(struct clc_context *ctx,
 
    NIR_PASS_V(nir, scale_fdiv);
 
-   // Assign bindings for constant samplers
-   nir_foreach_variable_with_modes(var, nir, nir_var_uniform) {
+   struct exec_list tmp_list;
+   exec_list_make_empty(&tmp_list);
+
+   // Assign bindings for constant samplers, and move them to the end of the variable list
+   nir_foreach_variable_with_modes_safe(var, nir, nir_var_uniform) {
       if (glsl_type_is_sampler(var->type) && var->data.sampler.is_inline_sampler) {
          int_sampler_states[sampler_id].wrap[0] =
             int_sampler_states[sampler_id].wrap[1] =
@@ -1228,8 +1231,12 @@ clc_to_dxil(struct clc_context *ctx,
          metadata->const_samplers[metadata->num_const_samplers].normalized_coords = var->data.sampler.normalized_coordinates;
          metadata->const_samplers[metadata->num_const_samplers].filter_mode = var->data.sampler.filter_mode;
          metadata->num_const_samplers++;
+
+         exec_node_remove(&var->node);
+         exec_list_push_tail(&tmp_list, &var->node);
       }
    }
+   exec_node_insert_list_after(exec_list_get_tail(&nir->variables), &tmp_list);
 
    NIR_PASS_V(nir, nir_lower_variable_initializers, ~(nir_var_function_temp | nir_var_shader_temp));