Mesa (main): zink: add nir_var_function_temp support to ntv

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 15 21:35:18 UTC 2022


Module: Mesa
Branch: main
Commit: 68267aeab856961ece73c1fbd661d6ecbd6bf319
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=68267aeab856961ece73c1fbd661d6ecbd6bf319

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Tue Mar  8 15:42:09 2022 -0500

zink: add nir_var_function_temp support to ntv

I said I'd never do this, but here we are

Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15327>

---

 .../drivers/zink/nir_to_spirv/nir_to_spirv.c       | 26 +++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
index a7028c01dea..efbfa719887 100644
--- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
+++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
@@ -312,6 +312,8 @@ static SpvStorageClass
 get_storage_class(struct nir_variable *var)
 {
    switch (var->data.mode) {
+   case nir_var_function_temp:
+      return SpvStorageClassFunction;
    case nir_var_mem_push_const:
       return SpvStorageClassPushConstant;
    case nir_var_shader_in:
@@ -683,6 +685,24 @@ emit_output(struct ntv_context *ctx, struct nir_variable *var)
    ctx->entry_ifaces[ctx->num_entry_ifaces++] = var_id;
 }
 
+static void
+emit_temp(struct ntv_context *ctx, struct nir_variable *var)
+{
+   SpvId var_type = get_glsl_type(ctx, var->type);
+
+   SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder,
+                                                   SpvStorageClassFunction,
+                                                   var_type);
+   SpvId var_id = spirv_builder_emit_var(&ctx->builder, pointer_type,
+                                         SpvStorageClassFunction);
+   if (var->name)
+      spirv_builder_emit_name(&ctx->builder, var_id, var->name);
+
+   _mesa_hash_table_insert(ctx->vars, var, (void *)(intptr_t)var_id);
+   assert(ctx->num_entry_ifaces < ARRAY_SIZE(ctx->entry_ifaces));
+   ctx->entry_ifaces[ctx->num_entry_ifaces++] = var_id;
+}
+
 static SpvDim
 type_to_dim(enum glsl_sampler_dim gdim, bool *is_ms)
 {
@@ -3477,6 +3497,7 @@ emit_deref_array(struct ntv_context *ctx, nir_deref_instr *deref)
    SpvStorageClass storage_class = get_storage_class(var);
    SpvId base, type;
    switch (var->data.mode) {
+   case nir_var_function_temp:
    case nir_var_shader_in:
    case nir_var_shader_out:
    case nir_var_mem_ubo:
@@ -3999,7 +4020,6 @@ nir_to_spirv(struct nir_shader *s, const struct zink_shader_info *sinfo, uint32_
       emit_output(&ctx, var);
    }
 
-
    if (sinfo->last_vertex)
       emit_so_info(&ctx, sinfo, max_output + 1);
    uint32_t tcs_vertices_out_word = 0;
@@ -4164,6 +4184,10 @@ nir_to_spirv(struct nir_shader *s, const struct zink_shader_info *sinfo, uint32_
       ctx.regs[reg->index] = var;
    }
 
+   nir_foreach_function_temp_variable(var, entry)
+      emit_temp(&ctx, var);
+
+
    emit_cf_list(&ctx, &entry->body);
 
    /* vertex/tess shader emits copied xfb outputs at the end of the shader */



More information about the mesa-commit mailing list