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@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15327>
This commit is contained in:
Mike Blumenkrantz 2022-03-08 15:42:09 -05:00 committed by Marge Bot
parent eb9b092001
commit 68267aeab8
1 changed files with 25 additions and 1 deletions

View File

@ -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 */