[Mesa-dev] [PATCH 19/22] nir/spirv: handle kernel function parameters

Karol Herbst kherbst at redhat.com
Tue Nov 13 15:48:23 UTC 2018


the idea here is to generate an entry point stub function wrapping around the
actual kernel function and turn all parameters into shader inputs with byte
addressing instead of vec4.

This gives us several advantages:
1. calling kernel functions doesn't differ from calling any other function
2. CL inputs match uniforms in most ways and we can just take advantage of most
   of nir_lower_io

Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 src/compiler/spirv/spirv_to_nir.c | 32 +++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index a350a95e27e..dbac3b2e052 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -4335,6 +4335,38 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
    nir_function *entry_point = b->entry_point->func->impl->function;
    vtn_assert(entry_point);
 
+   /* post process entry_points with input params */
+   if (entry_point->num_params) {
+      /* we shouldn't have any inputs yet */
+      vtn_assert(!entry_point->shader->num_inputs);
+
+      nir_function *main_entry_point = nir_function_create(b->shader, ralloc_strdup(b->shader, "main"));
+      main_entry_point->impl = nir_function_impl_create(main_entry_point);
+      nir_builder_init(&b->nb, main_entry_point->impl);
+      b->nb.cursor = nir_after_cf_list(&main_entry_point->impl->body);
+      b->func_param_idx = 0;
+
+      nir_call_instr *call = nir_call_instr_create(b->nb.shader, entry_point);
+
+      for (unsigned i = 0; i < entry_point->num_params; ++i) {
+         /* input variable */
+         nir_variable *in_var = rzalloc(b->nb.shader, nir_variable);
+         in_var->data.mode = nir_var_shader_in;
+         in_var->data.read_only = true;
+         in_var->data.location = i;
+         in_var->type = b->entry_point->func->type->params[i]->type;
+
+         nir_shader_add_variable(b->nb.shader, in_var);
+         b->nb.shader->num_inputs++;
+
+         call->params[i] = nir_src_for_ssa(nir_load_var(&b->nb, in_var));
+      }
+
+      nir_builder_instr_insert(&b->nb, &call->instr);
+
+      entry_point = main_entry_point;
+   }
+
    /* Unparent the shader from the vtn_builder before we delete the builder */
    ralloc_steal(NULL, b->shader);
 
-- 
2.19.1



More information about the mesa-dev mailing list