mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-14 18:20:17 +01:00
zink/spirv: prepare for control-flow
Acked-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
parent
32aea77cfe
commit
8bbf86e7bc
2 changed files with 35 additions and 2 deletions
|
|
@ -50,6 +50,10 @@ struct ntv_context {
|
|||
size_t num_defs;
|
||||
|
||||
struct hash_table *vars;
|
||||
|
||||
const SpvId *block_ids;
|
||||
size_t num_blocks;
|
||||
bool block_started;
|
||||
};
|
||||
|
||||
static SpvId
|
||||
|
|
@ -83,6 +87,13 @@ get_bvec_type(struct ntv_context *ctx, int num_components)
|
|||
return bool_type;
|
||||
}
|
||||
|
||||
static SpvId
|
||||
block_label(struct ntv_context *ctx, nir_block *block)
|
||||
{
|
||||
assert(block->index < ctx->num_blocks);
|
||||
return ctx->block_ids[block->index];
|
||||
}
|
||||
|
||||
static SpvId
|
||||
get_fvec_type(struct ntv_context *ctx, unsigned bit_size, unsigned num_components)
|
||||
{
|
||||
|
|
@ -1128,9 +1139,20 @@ emit_tex(struct ntv_context *ctx, nir_tex_instr *tex)
|
|||
store_dest(ctx, &tex->dest, result, tex->dest_type);
|
||||
}
|
||||
|
||||
static void
|
||||
start_block(struct ntv_context *ctx, SpvId label)
|
||||
{
|
||||
assert(!ctx->block_started);
|
||||
|
||||
/* start new block */
|
||||
spirv_builder_label(&ctx->builder, label);
|
||||
ctx->block_started = true;
|
||||
}
|
||||
|
||||
static void
|
||||
emit_block(struct ntv_context *ctx, struct nir_block *block)
|
||||
{
|
||||
start_block(ctx, block_label(ctx, block));
|
||||
nir_foreach_instr(instr, block) {
|
||||
switch (instr->type) {
|
||||
case nir_instr_type_alu:
|
||||
|
|
@ -1253,7 +1275,6 @@ nir_to_spirv(struct nir_shader *s)
|
|||
SpvId type_main = spirv_builder_type_function(&ctx.builder, type_void,
|
||||
NULL, 0);
|
||||
SpvId entry_point = spirv_builder_new_id(&ctx.builder);
|
||||
SpvId label = spirv_builder_new_id(&ctx.builder);
|
||||
spirv_builder_emit_name(&ctx.builder, entry_point, "main");
|
||||
|
||||
nir_foreach_variable(var, &s->inputs)
|
||||
|
|
@ -1276,9 +1297,9 @@ nir_to_spirv(struct nir_shader *s)
|
|||
spirv_builder_function(&ctx.builder, entry_point, type_void,
|
||||
SpvFunctionControlMaskNone,
|
||||
type_main);
|
||||
spirv_builder_label(&ctx.builder, label);
|
||||
|
||||
nir_function_impl *entry = nir_shader_get_entrypoint(s);
|
||||
nir_metadata_require(entry, nir_metadata_block_index);
|
||||
|
||||
ctx.defs = (SpvId *)malloc(sizeof(SpvId) * entry->ssa_alloc);
|
||||
if (!ctx.defs)
|
||||
|
|
@ -1290,7 +1311,18 @@ nir_to_spirv(struct nir_shader *s)
|
|||
if (!ctx.vars)
|
||||
goto fail;
|
||||
|
||||
SpvId *block_ids = (SpvId *)malloc(sizeof(SpvId) * entry->num_blocks);
|
||||
if (!block_ids)
|
||||
goto fail;
|
||||
|
||||
for (int i = 0; i < entry->num_blocks; ++i)
|
||||
block_ids[i] = spirv_builder_new_id(&ctx.builder);
|
||||
|
||||
ctx.block_ids = block_ids;
|
||||
ctx.num_blocks = entry->num_blocks;
|
||||
|
||||
emit_cf_list(&ctx, &entry->body);
|
||||
|
||||
free(ctx.defs);
|
||||
|
||||
spirv_builder_return(&ctx.builder); // doesn't belong here, but whatevz
|
||||
|
|
|
|||
|
|
@ -303,6 +303,7 @@ zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir)
|
|||
optimize_nir(nir);
|
||||
NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp);
|
||||
NIR_PASS_V(nir, lower_discard_if);
|
||||
NIR_PASS_V(nir, nir_convert_from_ssa, true);
|
||||
|
||||
if (zink_debug & ZINK_DEBUG_NIR) {
|
||||
fprintf(stderr, "NIR shader:\n---8<---\n");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue