From aefa22ddb52bce625d562ce5528cd1e21ac347e4 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 27 Sep 2021 18:42:20 -0500 Subject: [PATCH] clover: Insert dummy uniform variables for images 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 Part-of: --- src/gallium/frontends/clover/nir/invocation.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gallium/frontends/clover/nir/invocation.cpp b/src/gallium/frontends/clover/nir/invocation.cpp index e30709c..f0022d3 100644 --- a/src/gallium/frontends/clover/nir/invocation.cpp +++ b/src/gallium/frontends/clover/nir/invocation.cpp @@ -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, -- 2.7.4