radeonsi/nir: always lower ballot masks as 64-bit, codegen handles it
[mesa.git] / src / gallium / drivers / radeonsi / si_shader.c
index 650195b01bfd1b9dfda1dcfeea70a10c84df8153..64d7ec08348f9f7454b12e2ece0351ff13c628c2 100644 (file)
@@ -50,7 +50,8 @@ static const char scratch_rsrc_dword1_symbol[] =
 static void si_init_shader_ctx(struct si_shader_context *ctx,
                               struct si_screen *sscreen,
                               struct ac_llvm_compiler *compiler,
-                              unsigned wave_size);
+                              unsigned wave_size,
+                              bool nir);
 
 static void si_llvm_emit_barrier(const struct lp_build_tgsi_action *action,
                                 struct lp_build_tgsi_context *bld_base,
@@ -134,7 +135,7 @@ static void add_arg_assign_checked(struct si_function_info *fninfo,
                                   enum si_arg_regfile regfile, LLVMTypeRef type,
                                   LLVMValueRef *assign, unsigned idx)
 {
-       MAYBE_UNUSED unsigned actual = add_arg_assign(fninfo, regfile, type, assign);
+       ASSERTED unsigned actual = add_arg_assign(fninfo, regfile, type, assign);
        assert(actual == idx);
 }
 
@@ -442,7 +443,7 @@ void si_llvm_load_input_vs(
        LLVMValueRef out[4])
 {
        const struct tgsi_shader_info *info = &ctx->shader->selector->info;
-       unsigned vs_blit_property = info->properties[TGSI_PROPERTY_VS_BLIT_SGPRS];
+       unsigned vs_blit_property = info->properties[TGSI_PROPERTY_VS_BLIT_SGPRS_AMD];
 
        if (vs_blit_property) {
                LLVMValueRef vertex_id = ctx->abi.vertex_id;
@@ -1977,12 +1978,44 @@ static LLVMValueRef load_tess_level(struct si_shader_context *ctx,
 
 }
 
+static LLVMValueRef load_tess_level_default(struct si_shader_context *ctx,
+                                           unsigned semantic_name)
+{
+       LLVMValueRef buf, slot, val[4];
+       int i, offset;
+
+       slot = LLVMConstInt(ctx->i32, SI_HS_CONST_DEFAULT_TESS_LEVELS, 0);
+       buf = LLVMGetParam(ctx->main_fn, ctx->param_rw_buffers);
+       buf = ac_build_load_to_sgpr(&ctx->ac, buf, slot);
+       offset = semantic_name == TGSI_SEMANTIC_TESS_DEFAULT_INNER_LEVEL ? 4 : 0;
+
+       for (i = 0; i < 4; i++)
+               val[i] = buffer_load_const(ctx, buf,
+                                          LLVMConstInt(ctx->i32, (offset + i) * 4, 0));
+       return ac_build_gather_values(&ctx->ac, val, 4);
+}
+
 static LLVMValueRef si_load_tess_level(struct ac_shader_abi *abi,
-                                      unsigned varying_id)
+                                      unsigned varying_id,
+                                      bool load_default_state)
 {
        struct si_shader_context *ctx = si_shader_context_from_abi(abi);
        unsigned semantic_name;
 
+       if (load_default_state) {
+               switch (varying_id) {
+               case VARYING_SLOT_TESS_LEVEL_INNER:
+                       semantic_name = TGSI_SEMANTIC_TESS_DEFAULT_INNER_LEVEL;
+                       break;
+               case VARYING_SLOT_TESS_LEVEL_OUTER:
+                       semantic_name = TGSI_SEMANTIC_TESS_DEFAULT_OUTER_LEVEL;
+                       break;
+               default:
+                       unreachable("unknown tess level");
+               }
+               return load_tess_level_default(ctx, semantic_name);
+       }
+
        switch (varying_id) {
        case VARYING_SLOT_TESS_LEVEL_INNER:
                semantic_name = TGSI_SEMANTIC_TESSINNER;
@@ -2116,23 +2149,10 @@ void si_load_system_value(struct si_shader_context *ctx,
                value = load_tess_level(ctx, decl->Semantic.Name);
                break;
 
-       case TGSI_SEMANTIC_DEFAULT_TESSOUTER_SI:
-       case TGSI_SEMANTIC_DEFAULT_TESSINNER_SI:
-       {
-               LLVMValueRef buf, slot, val[4];
-               int i, offset;
-
-               slot = LLVMConstInt(ctx->i32, SI_HS_CONST_DEFAULT_TESS_LEVELS, 0);
-               buf = LLVMGetParam(ctx->main_fn, ctx->param_rw_buffers);
-               buf = ac_build_load_to_sgpr(&ctx->ac, buf, slot);
-               offset = decl->Semantic.Name == TGSI_SEMANTIC_DEFAULT_TESSINNER_SI ? 4 : 0;
-
-               for (i = 0; i < 4; i++)
-                       val[i] = buffer_load_const(ctx, buf,
-                                                  LLVMConstInt(ctx->i32, (offset + i) * 4, 0));
-               value = ac_build_gather_values(&ctx->ac, val, 4);
+       case TGSI_SEMANTIC_TESS_DEFAULT_OUTER_LEVEL:
+       case TGSI_SEMANTIC_TESS_DEFAULT_INNER_LEVEL:
+               value = load_tess_level_default(ctx, decl->Semantic.Name);
                break;
-       }
 
        case TGSI_SEMANTIC_PRIMID:
                value = si_get_primitive_id(ctx, 0);
@@ -2215,7 +2235,7 @@ void si_load_system_value(struct si_shader_context *ctx,
                break;
        }
 
-       case TGSI_SEMANTIC_CS_USER_DATA:
+       case TGSI_SEMANTIC_CS_USER_DATA_AMD:
                value = LLVMGetParam(ctx->main_fn, ctx->param_cs_user_data);
                break;
 
@@ -2712,7 +2732,6 @@ static void si_llvm_emit_streamout(struct si_shader_context *ctx,
        struct pipe_stream_output_info *so = &sel->so;
        LLVMBuilderRef builder = ctx->ac.builder;
        int i;
-       struct lp_build_if_state if_ctx;
 
        /* Get bits [22:16], i.e. (so_param >> 16) & 127; */
        LLVMValueRef so_vtx_count =
@@ -2727,7 +2746,7 @@ static void si_llvm_emit_streamout(struct si_shader_context *ctx,
        /* Emit the streamout code conditionally. This actually avoids
         * out-of-bounds buffer access. The hw tells us via the SGPR
         * (so_vtx_count) which threads are allowed to emit streamout data. */
-       lp_build_if(&if_ctx, &ctx->gallivm, can_emit);
+       ac_build_ifcc(&ctx->ac, can_emit, 6501);
        {
                /* The buffer offset is computed as follows:
                 *   ByteOffset = streamout_offset[buffer_id]*4 +
@@ -2781,7 +2800,7 @@ static void si_llvm_emit_streamout(struct si_shader_context *ctx,
                                                 &so->output[i], &outputs[reg]);
                }
        }
-       lp_build_endif(&if_ctx);
+       ac_build_endif(&ctx->ac, 6501);
 }
 
 static void si_export_param(struct si_shader_context *ctx, unsigned index,
@@ -2876,8 +2895,7 @@ static void si_vertex_color_clamping(struct si_shader_context *ctx,
        LLVMValueRef cond = LLVMGetParam(ctx->main_fn, ctx->param_vs_state_bits);
        cond = LLVMBuildTrunc(ctx->ac.builder, cond, ctx->i1, "");
 
-       struct lp_build_if_state if_ctx;
-       lp_build_if(&if_ctx, &ctx->gallivm, cond);
+       ac_build_ifcc(&ctx->ac, cond, 6502);
 
        /* Store clamped colors to alloca variables within the conditional block. */
        for (unsigned i = 0; i < noutput; i++) {
@@ -2891,7 +2909,7 @@ static void si_vertex_color_clamping(struct si_shader_context *ctx,
                                       addr[i][j]);
                }
        }
-       lp_build_endif(&if_ctx);
+       ac_build_endif(&ctx->ac, 6502);
 
        /* Load clamped colors */
        for (unsigned i = 0; i < noutput; i++) {
@@ -3118,7 +3136,6 @@ static void si_write_tess_factors(struct lp_build_tgsi_context *bld_base,
        LLVMValueRef lds_base, lds_inner, lds_outer, byteoffset, buffer;
        LLVMValueRef out[6], vec0, vec1, tf_base, inner[4], outer[4];
        unsigned stride, outer_comps, inner_comps, i, offset;
-       struct lp_build_if_state if_ctx, inner_if_ctx;
 
        /* Add a barrier before loading tess factors from LDS. */
        if (!shader->key.part.tcs.epilog.invoc0_tess_factors_are_def)
@@ -3130,9 +3147,9 @@ static void si_write_tess_factors(struct lp_build_tgsi_context *bld_base,
         * This can't jump, because invocation 0 executes this. It should
         * at least mask out the loads and stores for other invocations.
         */
-       lp_build_if(&if_ctx, &ctx->gallivm,
-                   LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ,
-                                 invocation_id, ctx->i32_0, ""));
+       ac_build_ifcc(&ctx->ac,
+                     LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ,
+                                   invocation_id, ctx->i32_0, ""), 6503);
 
        /* Determine the layout of one tess factor element in the buffer. */
        switch (shader->key.part.tcs.epilog.prim_mode) {
@@ -3217,9 +3234,9 @@ static void si_write_tess_factors(struct lp_build_tgsi_context *bld_base,
        byteoffset = LLVMBuildMul(ctx->ac.builder, rel_patch_id,
                                  LLVMConstInt(ctx->i32, 4 * stride, 0), "");
 
-       lp_build_if(&inner_if_ctx, &ctx->gallivm,
-                   LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ,
-                                 rel_patch_id, ctx->i32_0, ""));
+       ac_build_ifcc(&ctx->ac,
+                     LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ,
+                                   rel_patch_id, ctx->i32_0, ""), 6504);
 
        /* Store the dynamic HS control word. */
        offset = 0;
@@ -3231,7 +3248,7 @@ static void si_write_tess_factors(struct lp_build_tgsi_context *bld_base,
                offset += 4;
        }
 
-       lp_build_endif(&inner_if_ctx);
+       ac_build_endif(&ctx->ac, 6504);
 
        /* Store the tessellation factors. */
        ac_build_buffer_store_dword(&ctx->ac, buffer, vec0,
@@ -3279,7 +3296,7 @@ static void si_write_tess_factors(struct lp_build_tgsi_context *bld_base,
                }
        }
 
-       lp_build_endif(&if_ctx);
+       ac_build_endif(&ctx->ac, 6503);
 }
 
 static LLVMValueRef
@@ -3332,11 +3349,11 @@ static void si_llvm_emit_tcs_epilogue(struct ac_shader_abi *abi,
        if (ctx->screen->info.chip_class >= GFX9) {
                LLVMBasicBlockRef blocks[2] = {
                        LLVMGetInsertBlock(builder),
-                       ctx->merged_wrap_if_state.entry_block
+                       ctx->merged_wrap_if_entry_block
                };
                LLVMValueRef values[2];
 
-               lp_build_endif(&ctx->merged_wrap_if_state);
+               ac_build_endif(&ctx->ac, ctx->merged_wrap_if_label);
 
                values[0] = rel_patch_id;
                values[1] = LLVMGetUndef(ctx->i32);
@@ -3463,7 +3480,7 @@ static void si_set_es_return_value_for_gs(struct si_shader_context *ctx)
        ret = si_insert_input_ptr(ctx, ret,
                                  ctx->param_bindless_samplers_and_images,
                                  8 + SI_SGPR_BINDLESS_SAMPLERS_AND_IMAGES);
-       if (ctx->screen->info.chip_class >= GFX10) {
+       if (ctx->screen->use_ngg) {
                ret = si_insert_input_ptr(ctx, ret, ctx->param_vs_state_bits,
                                          8 + SI_SGPR_VS_STATE_BITS);
        }
@@ -3620,7 +3637,7 @@ static void emit_gs_epilogue(struct si_shader_context *ctx)
                         si_get_gs_wave_id(ctx));
 
        if (ctx->screen->info.chip_class >= GFX9)
-               lp_build_endif(&ctx->merged_wrap_if_state);
+               ac_build_endif(&ctx->ac, ctx->merged_wrap_if_label);
 }
 
 static void si_llvm_emit_gs_epilogue(struct ac_shader_abi *abi,
@@ -3669,7 +3686,7 @@ static void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi,
                }
        }
 
-       if (ctx->ac.chip_class <= GFX9 &&
+       if (!ctx->screen->use_ngg_streamout &&
            ctx->shader->selector->so.num_outputs)
                si_llvm_emit_streamout(ctx, outputs, i, 0);
 
@@ -4266,7 +4283,6 @@ static void si_llvm_emit_vertex(struct ac_shader_abi *abi,
 
        struct tgsi_shader_info *info = &ctx->shader->selector->info;
        struct si_shader *shader = ctx->shader;
-       struct lp_build_if_state if_state;
        LLVMValueRef soffset = LLVMGetParam(ctx->main_fn,
                                            ctx->param_gs2vs_offset);
        LLVMValueRef gs_next_vertex;
@@ -4295,7 +4311,7 @@ static void si_llvm_emit_vertex(struct ac_shader_abi *abi,
        if (use_kill) {
                ac_build_kill_if_false(&ctx->ac, can_emit);
        } else {
-               lp_build_if(&if_state, &ctx->gallivm, can_emit);
+               ac_build_ifcc(&ctx->ac, can_emit, 6505);
        }
 
        offset = 0;
@@ -4335,7 +4351,7 @@ static void si_llvm_emit_vertex(struct ac_shader_abi *abi,
        }
 
        if (!use_kill)
-               lp_build_endif(&if_state);
+               ac_build_endif(&ctx->ac, 6505);
 }
 
 /* Emit one vertex from the geometry shader */
@@ -4444,29 +4460,13 @@ void si_create_function(struct si_shader_context *ctx,
        LLVMAddTargetDependentFunctionAttr(ctx->main_fn,
                                           "no-signed-zeros-fp-math",
                                           "true");
-
-       if (ctx->screen->debug_flags & DBG(UNSAFE_MATH)) {
-               /* These were copied from some LLVM test. */
-               LLVMAddTargetDependentFunctionAttr(ctx->main_fn,
-                                                  "less-precise-fpmad",
-                                                  "true");
-               LLVMAddTargetDependentFunctionAttr(ctx->main_fn,
-                                                  "no-infs-fp-math",
-                                                  "true");
-               LLVMAddTargetDependentFunctionAttr(ctx->main_fn,
-                                                  "no-nans-fp-math",
-                                                  "true");
-               LLVMAddTargetDependentFunctionAttr(ctx->main_fn,
-                                                  "unsafe-fp-math",
-                                                  "true");
-       }
 }
 
 static void declare_streamout_params(struct si_shader_context *ctx,
                                     struct pipe_stream_output_info *so,
                                     struct si_function_info *fninfo)
 {
-       if (ctx->ac.chip_class >= GFX10)
+       if (ctx->screen->use_ngg_streamout)
                return;
 
        /* Streamout SGPRs. */
@@ -4598,10 +4598,9 @@ static void declare_vs_input_vgprs(struct si_shader_context *ctx,
                        add_arg_assign(fninfo, ARG_VGPR, ctx->i32, &ctx->abi.instance_id);
                        add_arg(fninfo, ARG_VGPR, ctx->i32); /* unused */
                }
-       } else if (ctx->screen->info.chip_class == GFX10 &&
-                  !shader->is_gs_copy_shader) {
-               add_arg(fninfo, ARG_VGPR, ctx->i32); /* user vgpr */
+       } else if (ctx->screen->info.chip_class >= GFX10) {
                add_arg(fninfo, ARG_VGPR, ctx->i32); /* user vgpr */
+               ctx->param_vs_prim_id = add_arg(fninfo, ARG_VGPR, ctx->i32); /* user vgpr or PrimID (legacy) */
                add_arg_assign(fninfo, ARG_VGPR, ctx->i32, &ctx->abi.instance_id);
        } else {
                add_arg_assign(fninfo, ARG_VGPR, ctx->i32, &ctx->abi.instance_id);
@@ -4667,7 +4666,7 @@ static void create_function(struct si_shader_context *ctx)
        unsigned num_prolog_vgprs = 0;
        unsigned type = ctx->type;
        unsigned vs_blit_property =
-               shader->selector->info.properties[TGSI_PROPERTY_VS_BLIT_SGPRS];
+               shader->selector->info.properties[TGSI_PROPERTY_VS_BLIT_SGPRS_AMD];
 
        si_init_function_info(&fninfo);
 
@@ -4983,7 +4982,7 @@ static void create_function(struct si_shader_context *ctx)
                        ctx->param_block_size = add_arg(&fninfo, ARG_SGPR, v3i32);
 
                unsigned cs_user_data_dwords =
-                       shader->selector->info.properties[TGSI_PROPERTY_CS_USER_DATA_DWORDS];
+                       shader->selector->info.properties[TGSI_PROPERTY_CS_USER_DATA_COMPONENTS_AMD];
                if (cs_user_data_dwords) {
                        ctx->param_cs_user_data = add_arg(&fninfo, ARG_SGPR,
                                                          LLVMVectorType(ctx->i32, cs_user_data_dwords));
@@ -5727,7 +5726,8 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
        shader->is_gs_copy_shader = true;
 
        si_init_shader_ctx(&ctx, sscreen, compiler,
-                          si_get_wave_size(sscreen, PIPE_SHADER_VERTEX, false, false));
+                          si_get_wave_size(sscreen, PIPE_SHADER_VERTEX, false, false),
+                          false);
        ctx.shader = shader;
        ctx.type = PIPE_SHADER_VERTEX;
 
@@ -5743,7 +5743,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
        /* Fetch the vertex stream ID.*/
        LLVMValueRef stream_id;
 
-       if (ctx.ac.chip_class <= GFX9 && gs_selector->so.num_outputs)
+       if (!sscreen->use_ngg_streamout && gs_selector->so.num_outputs)
                stream_id = si_unpack_param(&ctx, ctx.param_streamout_config, 24, 2);
        else
                stream_id = ctx.i32_0;
@@ -5803,7 +5803,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
                }
 
                /* Streamout and exports. */
-               if (ctx.ac.chip_class <= GFX9 && gs_selector->so.num_outputs) {
+               if (!sscreen->use_ngg_streamout && gs_selector->so.num_outputs) {
                        si_llvm_emit_streamout(&ctx, outputs,
                                               gsinfo->num_outputs,
                                               stream);
@@ -5890,6 +5890,7 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
                                      "part.vs.prolog", f);
                fprintf(f, "  as_es = %u\n", key->as_es);
                fprintf(f, "  as_ls = %u\n", key->as_ls);
+               fprintf(f, "  as_ngg = %u\n", key->as_ngg);
                fprintf(f, "  mono.u.vs_export_prim_id = %u\n",
                        key->mono.u.vs_export_prim_id);
                fprintf(f, "  opt.vs_as_prim_discard_cs = %u\n",
@@ -5927,6 +5928,7 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
 
        case PIPE_SHADER_TESS_EVAL:
                fprintf(f, "  as_es = %u\n", key->as_es);
+               fprintf(f, "  as_ngg = %u\n", key->as_ngg);
                fprintf(f, "  mono.u.vs_export_prim_id = %u\n",
                        key->mono.u.vs_export_prim_id);
                break;
@@ -5941,6 +5943,8 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
                                              "part.gs.vs_prolog", f);
                }
                fprintf(f, "  part.gs.prolog.tri_strip_adj_fix = %u\n", key->part.gs.prolog.tri_strip_adj_fix);
+               fprintf(f, "  part.gs.prolog.gfx9_prev_is_vs = %u\n", key->part.gs.prolog.gfx9_prev_is_vs);
+               fprintf(f, "  as_ngg = %u\n", key->as_ngg);
                break;
 
        case PIPE_SHADER_COMPUTE:
@@ -5956,6 +5960,7 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
                fprintf(f, "  part.ps.prolog.force_linear_center_interp = %u\n", key->part.ps.prolog.force_linear_center_interp);
                fprintf(f, "  part.ps.prolog.bc_optimize_for_persp = %u\n", key->part.ps.prolog.bc_optimize_for_persp);
                fprintf(f, "  part.ps.prolog.bc_optimize_for_linear = %u\n", key->part.ps.prolog.bc_optimize_for_linear);
+               fprintf(f, "  part.ps.prolog.samplemask_log_ps_iter = %u\n", key->part.ps.prolog.samplemask_log_ps_iter);
                fprintf(f, "  part.ps.epilog.spi_shader_col_format = 0x%x\n", key->part.ps.epilog.spi_shader_col_format);
                fprintf(f, "  part.ps.epilog.color_is_int8 = 0x%X\n", key->part.ps.epilog.color_is_int8);
                fprintf(f, "  part.ps.epilog.color_is_int10 = 0x%X\n", key->part.ps.epilog.color_is_int10);
@@ -5964,6 +5969,10 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
                fprintf(f, "  part.ps.epilog.alpha_to_one = %u\n", key->part.ps.epilog.alpha_to_one);
                fprintf(f, "  part.ps.epilog.poly_line_smoothing = %u\n", key->part.ps.epilog.poly_line_smoothing);
                fprintf(f, "  part.ps.epilog.clamp_color = %u\n", key->part.ps.epilog.clamp_color);
+               fprintf(f, "  mono.u.ps.interpolate_at_sample_force_center = %u\n", key->mono.u.ps.interpolate_at_sample_force_center);
+               fprintf(f, "  mono.u.ps.fbfetch_msaa = %u\n", key->mono.u.ps.fbfetch_msaa);
+               fprintf(f, "  mono.u.ps.fbfetch_is_1D = %u\n", key->mono.u.ps.fbfetch_is_1D);
+               fprintf(f, "  mono.u.ps.fbfetch_layered = %u\n", key->mono.u.ps.fbfetch_layered);
                break;
 
        default:
@@ -5982,11 +5991,13 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f)
 static void si_init_shader_ctx(struct si_shader_context *ctx,
                               struct si_screen *sscreen,
                               struct ac_llvm_compiler *compiler,
-                              unsigned wave_size)
+                              unsigned wave_size,
+                              bool nir)
 {
        struct lp_build_tgsi_context *bld_base;
 
-       si_llvm_context_init(ctx, sscreen, compiler, wave_size);
+       si_llvm_context_init(ctx, sscreen, compiler, wave_size,
+                            nir ? 64 : wave_size);
 
        bld_base = &ctx->bld_base;
        bld_base->emit_fetch_funcs[TGSI_FILE_CONSTANT] = fetch_constant;
@@ -6082,6 +6093,7 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx)
        case PIPE_SHADER_TESS_CTRL:
                bld_base->emit_fetch_funcs[TGSI_FILE_INPUT] = fetch_input_tcs;
                ctx->abi.load_tess_varyings = si_nir_load_tcs_varyings;
+               ctx->abi.load_tess_level = si_load_tess_level;
                bld_base->emit_fetch_funcs[TGSI_FILE_OUTPUT] = fetch_output_tcs;
                bld_base->emit_store = store_output_tcs;
                ctx->abi.store_tcs_outputs = si_nir_store_output_tcs;
@@ -6151,9 +6163,9 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx)
                if (shader->key.as_ngg) {
                        for (unsigned i = 0; i < 4; ++i) {
                                ctx->gs_curprim_verts[i] =
-                                       lp_build_alloca(&ctx->gallivm, ctx->ac.i32, "");
+                                       ac_build_alloca(&ctx->ac, ctx->ac.i32, "");
                                ctx->gs_generated_prims[i] =
-                                       lp_build_alloca(&ctx->gallivm, ctx->ac.i32, "");
+                                       ac_build_alloca(&ctx->ac, ctx->ac.i32, "");
                        }
 
                        unsigned scratch_size = 8;
@@ -6250,7 +6262,10 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx)
                        LLVMValueRef ena =
                                LLVMBuildICmp(ctx->ac.builder, LLVMIntULT,
                                            ac_get_thread_id(&ctx->ac), num_threads, "");
-                       lp_build_if(&ctx->merged_wrap_if_state, &ctx->gallivm, ena);
+
+                       ctx->merged_wrap_if_entry_block = LLVMGetInsertBlock(ctx->ac.builder);
+                       ctx->merged_wrap_if_label = 11500;
+                       ac_build_ifcc(&ctx->ac, ena, ctx->merged_wrap_if_label);
 
                        if (nested_barrier) {
                                /* Execute a barrier before the second shader in
@@ -6650,11 +6665,10 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
        LLVMTypeRef function_type;
        unsigned num_first_params;
        unsigned num_out, initial_num_out;
-       MAYBE_UNUSED unsigned num_out_sgpr; /* used in debug checks */
-       MAYBE_UNUSED unsigned initial_num_out_sgpr; /* used in debug checks */
+       ASSERTED unsigned num_out_sgpr; /* used in debug checks */
+       ASSERTED unsigned initial_num_out_sgpr; /* used in debug checks */
        unsigned num_sgprs, num_vgprs;
        unsigned gprs;
-       struct lp_build_if_state if_state;
 
        si_init_function_info(&fninfo);
 
@@ -6788,7 +6802,7 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
                                             LLVMConstInt(ctx->i32, 0x7f, 0), "");
                        ena = LLVMBuildICmp(builder, LLVMIntULT,
                                            ac_get_thread_id(&ctx->ac), count, "");
-                       lp_build_if(&if_state, &ctx->gallivm, ena);
+                       ac_build_ifcc(&ctx->ac, ena, 6506);
                }
 
                /* Derive arguments for the next part from outputs of the
@@ -6845,7 +6859,7 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
 
                if (is_multi_part_shader(ctx) &&
                    part + 1 == next_shader_first_part) {
-                       lp_build_endif(&if_state);
+                       ac_build_endif(&ctx->ac, 6506);
 
                        /* The second half of the merged shader should use
                         * the inputs from the toplevel (wrapper) function,
@@ -6929,8 +6943,9 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
                si_dump_streamout(&sel->so);
        }
 
-       si_init_shader_ctx(&ctx, sscreen, compiler, si_get_shader_wave_size(shader));
-       si_llvm_context_set_tgsi(&ctx, shader);
+       si_init_shader_ctx(&ctx, sscreen, compiler, si_get_shader_wave_size(shader),
+                          sel->nir != NULL);
+       si_llvm_context_set_ir(&ctx, shader);
 
        memset(shader->info.vs_output_param_offset, AC_EXP_PARAM_UNDEFINED,
               sizeof(shader->info.vs_output_param_offset));
@@ -6987,7 +7002,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
                        shader_ls.key.mono = shader->key.mono;
                        shader_ls.key.opt = shader->key.opt;
                        shader_ls.is_monolithic = true;
-                       si_llvm_context_set_tgsi(&ctx, &shader_ls);
+                       si_llvm_context_set_ir(&ctx, &shader_ls);
 
                        if (!si_compile_tgsi_main(&ctx)) {
                                si_llvm_dispose(&ctx);
@@ -7054,7 +7069,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
                        shader_es.key.mono = shader->key.mono;
                        shader_es.key.opt = shader->key.opt;
                        shader_es.is_monolithic = true;
-                       si_llvm_context_set_tgsi(&ctx, &shader_es);
+                       si_llvm_context_set_ir(&ctx, &shader_es);
 
                        if (!si_compile_tgsi_main(&ctx)) {
                                si_llvm_dispose(&ctx);
@@ -7309,7 +7324,8 @@ si_get_shader_part(struct si_screen *sscreen,
        struct si_shader_context ctx;
        si_init_shader_ctx(&ctx, sscreen, compiler,
                           si_get_wave_size(sscreen, type, shader.key.as_ngg,
-                                           shader.key.as_es));
+                                           shader.key.as_es),
+                          false);
        ctx.shader = &shader;
        ctx.type = type;
 
@@ -7467,9 +7483,9 @@ static void si_build_vs_prolog_function(struct si_shader_context *ctx,
                                           key->vs_prolog.num_input_sgprs + i, "");
        }
 
-       struct lp_build_if_state wrap_if_state;
        LLVMValueRef original_ret = ret;
        bool wrapped = false;
+       LLVMBasicBlockRef if_entry_block = NULL;
 
        if (key->vs_prolog.is_monolithic && key->vs_prolog.as_ngg) {
                LLVMValueRef num_threads;
@@ -7478,7 +7494,8 @@ static void si_build_vs_prolog_function(struct si_shader_context *ctx,
                num_threads = si_unpack_param(ctx, 3, 0, 8);
                ena = LLVMBuildICmp(ctx->ac.builder, LLVMIntULT,
                                        ac_get_thread_id(&ctx->ac), num_threads, "");
-               lp_build_if(&wrap_if_state, &ctx->gallivm, ena);
+               if_entry_block = LLVMGetInsertBlock(ctx->ac.builder);
+               ac_build_ifcc(&ctx->ac, ena, 11501);
                wrapped = true;
        }
 
@@ -7538,16 +7555,16 @@ static void si_build_vs_prolog_function(struct si_shader_context *ctx,
        }
 
        if (wrapped) {
-               lp_build_endif(&wrap_if_state);
+               LLVMBasicBlockRef bbs[2] = {
+                       LLVMGetInsertBlock(ctx->ac.builder),
+                       if_entry_block,
+               };
+               ac_build_endif(&ctx->ac, 11501);
 
                LLVMValueRef values[2] = {
                        ret,
                        original_ret
                };
-               LLVMBasicBlockRef bbs[2] = {
-                       wrap_if_state.true_block,
-                       wrap_if_state.entry_block
-               };
                ret = ac_build_phi(&ctx->ac, LLVMTypeOf(ret), 2, values, bbs);
        }