clover: Insert dummy uniform variables for images
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 27 Sep 2021 23:42:20 +0000 (18:42 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 15 Oct 2021 14:58:56 +0000 (14:58 +0000)
Instead of making images have a well-defined size, insert a dummy
variable of the appropriate type which we can use for the parameter
block layout.  This will work much better when we switch over to
nir_var_mem_image.

Acked-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4743>

src/gallium/frontends/clover/nir/invocation.cpp

index e30709c..f0022d3 100644 (file)
@@ -72,17 +72,33 @@ static void debug_function(void *private_data,
 static void
 clover_arg_size_align(const glsl_type *type, unsigned *size, unsigned *align)
 {
-   if (type == glsl_type::sampler_type) {
+   if (type == glsl_type::sampler_type || type->is_image()) {
       *size = 0;
       *align = 1;
-   } else if (type->is_image()) {
-      *size = *align = sizeof(cl_mem);
    } else {
       *size = type->cl_size();
       *align = type->cl_alignment();
    }
 }
 
+static void
+clover_nir_add_image_uniforms(nir_shader *shader)
+{
+   /* Clover expects each image variable to take up a cl_mem worth of space in
+    * the arguments data.  Add uniforms as needed to match this expectation.
+    */
+   nir_foreach_image_variable_safe(var, shader) {
+      nir_variable *uniform = rzalloc(shader, nir_variable);
+      uniform->name = ralloc_strdup(uniform, var->name);
+      uniform->type = glsl_uintN_t_type(sizeof(cl_mem) * 8);
+      uniform->data.mode = nir_var_uniform;
+      uniform->data.read_only = true;
+      uniform->data.location = var->data.location;
+
+      exec_node_insert_node_before(&var->node, &uniform->node);
+   }
+}
+
 static bool
 clover_nir_lower_images(nir_shader *shader)
 {
@@ -502,6 +518,7 @@ binary clover::nir::spirv_to_nir(const binary &mod, const device &dev,
       NIR_PASS_V(nir, clover_lower_nir, args, dev.max_block_size().size(),
                  dev.address_bits());
 
+      NIR_PASS_V(nir, clover_nir_add_image_uniforms);
       NIR_PASS_V(nir, nir_lower_vars_to_explicit_types,
                  nir_var_uniform, clover_arg_size_align);
       NIR_PASS_V(nir, nir_lower_vars_to_explicit_types,