radeonsi: silence a Coverity warning
[mesa.git] / src / gallium / drivers / radeonsi / si_state_shaders.c
index 7da52f634565dcc0e524a9f83f7aa01a138de993..313af85a1cb8bd81933695b5992f732d662daad9 100644 (file)
@@ -498,11 +498,6 @@ static void si_shader_hs(struct si_screen *sscreen, struct si_shader *shader)
                 */
                ls_vgpr_comp_cnt = shader->info.uses_instanceid ? 2 : 1;
 
-               if (shader->config.scratch_bytes_per_wave) {
-                       fprintf(stderr, "HS: scratch buffer unsupported");
-                       abort();
-               }
-
                shader->config.rsrc2 =
                        S_00B42C_USER_SGPR(GFX9_TCS_NUM_USER_SGPR) |
                        S_00B42C_USER_SGPR_MSB(GFX9_TCS_NUM_USER_SGPR >> 5) |
@@ -816,11 +811,6 @@ static void si_shader_gs(struct si_screen *sscreen, struct si_shader *shader)
 
                polaris_set_vgt_vertex_reuse(sscreen, shader->key.part.gs.es,
                                             NULL, pm4);
-
-               if (shader->config.scratch_bytes_per_wave) {
-                       fprintf(stderr, "GS: scratch buffer unsupported");
-                       abort();
-               }
        } else {
                si_pm4_set_reg(pm4, R_00B220_SPI_SHADER_PGM_LO_GS, va >> 8);
                si_pm4_set_reg(pm4, R_00B224_SPI_SHADER_PGM_HI_GS, va >> 40);
@@ -853,7 +843,7 @@ static void si_shader_vs(struct si_screen *sscreen, struct si_shader *shader,
        unsigned oc_lds_en;
        unsigned window_space =
           shader->selector->info.properties[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION];
-       bool enable_prim_id = shader->key.mono.vs_export_prim_id;
+       bool enable_prim_id = shader->key.mono.vs_export_prim_id || shader->selector->info.uses_primid;
 
        pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
@@ -898,7 +888,7 @@ static void si_shader_vs(struct si_screen *sscreen, struct si_shader *shader,
                vgpr_comp_cnt = enable_prim_id ? 2 : (shader->info.uses_instanceid ? 1 : 0);
                num_user_sgprs = SI_VS_NUM_USER_SGPR;
        } else if (shader->selector->type == PIPE_SHADER_TESS_EVAL) {
-               vgpr_comp_cnt = shader->selector->info.uses_primid ? 3 : 2;
+               vgpr_comp_cnt = enable_prim_id ? 3 : 2;
                num_user_sgprs = SI_TES_NUM_USER_SGPR;
        } else
                unreachable("invalid shader selector type");
@@ -1241,22 +1231,17 @@ static void si_shader_selector_key_hw_vs(struct si_context *sctx,
 
        /* Find out which VS outputs aren't used by the PS. */
        uint64_t outputs_written = vs->outputs_written;
-       uint32_t outputs_written2 = vs->outputs_written2;
        uint64_t inputs_read = 0;
-       uint32_t inputs_read2 = 0;
 
        outputs_written &= ~0x3; /* ignore POSITION, PSIZE */
 
        if (!ps_disabled) {
                inputs_read = ps->inputs_read;
-               inputs_read2 = ps->inputs_read2;
        }
 
        uint64_t linked = outputs_written & inputs_read;
-       uint32_t linked2 = outputs_written2 & inputs_read2;
 
        key->opt.hw_vs.kill_outputs = ~linked & outputs_written;
-       key->opt.hw_vs.kill_outputs2 = ~linked2 & outputs_written2;
 }
 
 /* Compute the key for the hw shader variant */
@@ -1853,10 +1838,10 @@ void si_init_shader_selector_async(void *job, int thread_index)
                                switch (name) {
                                case TGSI_SEMANTIC_GENERIC:
                                        /* don't process indices the function can't handle */
-                                       if (index >= 60)
+                                       if (index >= SI_MAX_IO_GENERIC)
                                                break;
                                        /* fall through */
-                               case TGSI_SEMANTIC_CLIPDIST:
+                               default:
                                        id = si_shader_io_get_unique_index(name, index);
                                        sel->outputs_written &= ~(1ull << id);
                                        break;
@@ -1865,9 +1850,6 @@ void si_init_shader_selector_async(void *job, int thread_index)
                                case TGSI_SEMANTIC_CLIPVERTEX:
                                case TGSI_SEMANTIC_EDGEFLAG:
                                        break;
-                               default:
-                                       id = si_shader_io_get_unique_index2(name, index);
-                                       sel->outputs_written2 &= ~(1u << id);
                                }
                        }
                }
@@ -1991,8 +1973,8 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
        case PIPE_SHADER_TESS_CTRL:
                /* Always reserve space for these. */
                sel->patch_outputs_written |=
-                       (1llu << si_shader_io_get_unique_index(TGSI_SEMANTIC_TESSINNER, 0)) |
-                       (1llu << si_shader_io_get_unique_index(TGSI_SEMANTIC_TESSOUTER, 0));
+                       (1llu << si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSINNER, 0)) |
+                       (1llu << si_shader_io_get_unique_index_patch(TGSI_SEMANTIC_TESSOUTER, 0));
                /* fall through */
        case PIPE_SHADER_VERTEX:
        case PIPE_SHADER_TESS_EVAL:
@@ -2005,26 +1987,21 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
                        case TGSI_SEMANTIC_TESSOUTER:
                        case TGSI_SEMANTIC_PATCH:
                                sel->patch_outputs_written |=
-                                       1llu << si_shader_io_get_unique_index(name, index);
+                                       1llu << si_shader_io_get_unique_index_patch(name, index);
                                break;
 
                        case TGSI_SEMANTIC_GENERIC:
                                /* don't process indices the function can't handle */
-                               if (index >= 60)
+                               if (index >= SI_MAX_IO_GENERIC)
                                        break;
                                /* fall through */
-                       case TGSI_SEMANTIC_POSITION:
-                       case TGSI_SEMANTIC_PSIZE:
-                       case TGSI_SEMANTIC_CLIPDIST:
+                       default:
                                sel->outputs_written |=
                                        1llu << si_shader_io_get_unique_index(name, index);
                                break;
                        case TGSI_SEMANTIC_CLIPVERTEX: /* ignore these */
                        case TGSI_SEMANTIC_EDGEFLAG:
                                break;
-                       default:
-                               sel->outputs_written2 |=
-                                       1u << si_shader_io_get_unique_index2(name, index);
                        }
                }
                sel->esgs_itemsize = util_last_bit64(sel->outputs_written) * 16;
@@ -2042,16 +2019,17 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
                        unsigned index = sel->info.input_semantic_index[i];
 
                        switch (name) {
-                       case TGSI_SEMANTIC_CLIPDIST:
                        case TGSI_SEMANTIC_GENERIC:
+                               /* don't process indices the function can't handle */
+                               if (index >= SI_MAX_IO_GENERIC)
+                                       break;
+                               /* fall through */
+                       default:
                                sel->inputs_read |=
                                        1llu << si_shader_io_get_unique_index(name, index);
                                break;
                        case TGSI_SEMANTIC_PCOORD: /* ignore this */
                                break;
-                       default:
-                               sel->inputs_read2 |=
-                                       1u << si_shader_io_get_unique_index2(name, index);
                        }
                }
 
@@ -2148,6 +2126,19 @@ static void si_bind_vs_shader(struct pipe_context *ctx, void *state)
        r600_update_vs_writes_viewport_index(&sctx->b, si_get_vs_info(sctx));
 }
 
+static void si_update_tess_uses_prim_id(struct si_context *sctx)
+{
+       sctx->ia_multi_vgt_param_key.u.tess_uses_prim_id =
+               (sctx->tes_shader.cso &&
+                sctx->tes_shader.cso->info.uses_primid) ||
+               (sctx->tcs_shader.cso &&
+                sctx->tcs_shader.cso->info.uses_primid) ||
+               (sctx->gs_shader.cso &&
+                sctx->gs_shader.cso->info.uses_primid) ||
+               (sctx->ps_shader.cso && !sctx->gs_shader.cso &&
+                sctx->ps_shader.cso->info.uses_primid);
+}
+
 static void si_bind_gs_shader(struct pipe_context *ctx, void *state)
 {
        struct si_context *sctx = (struct si_context *)ctx;
@@ -2164,20 +2155,14 @@ static void si_bind_gs_shader(struct pipe_context *ctx, void *state)
        si_mark_atom_dirty(sctx, &sctx->clip_regs);
        sctx->last_rast_prim = -1; /* reset this so that it gets updated */
 
-       if (enable_changed)
+       if (enable_changed) {
                si_shader_change_notify(sctx);
+               if (sctx->ia_multi_vgt_param_key.u.uses_tess)
+                       si_update_tess_uses_prim_id(sctx);
+       }
        r600_update_vs_writes_viewport_index(&sctx->b, si_get_vs_info(sctx));
 }
 
-static void si_update_tcs_tes_uses_prim_id(struct si_context *sctx)
-{
-       sctx->ia_multi_vgt_param_key.u.tcs_tes_uses_prim_id =
-               (sctx->tes_shader.cso &&
-                sctx->tes_shader.cso->info.uses_primid) ||
-               (sctx->tcs_shader.cso &&
-                sctx->tcs_shader.cso->info.uses_primid);
-}
-
 static void si_bind_tcs_shader(struct pipe_context *ctx, void *state)
 {
        struct si_context *sctx = (struct si_context *)ctx;
@@ -2189,7 +2174,7 @@ static void si_bind_tcs_shader(struct pipe_context *ctx, void *state)
 
        sctx->tcs_shader.cso = sel;
        sctx->tcs_shader.current = sel ? sel->first_variant : NULL;
-       si_update_tcs_tes_uses_prim_id(sctx);
+       si_update_tess_uses_prim_id(sctx);
        sctx->do_update_shaders = true;
 
        if (enable_changed)
@@ -2208,7 +2193,7 @@ static void si_bind_tes_shader(struct pipe_context *ctx, void *state)
        sctx->tes_shader.cso = sel;
        sctx->tes_shader.current = sel ? sel->first_variant : NULL;
        sctx->ia_multi_vgt_param_key.u.uses_tess = sel != NULL;
-       si_update_tcs_tes_uses_prim_id(sctx);
+       si_update_tess_uses_prim_id(sctx);
        sctx->do_update_shaders = true;
        si_mark_atom_dirty(sctx, &sctx->clip_regs);
        sctx->last_rast_prim = -1; /* reset this so that it gets updated */
@@ -2232,6 +2217,8 @@ static void si_bind_ps_shader(struct pipe_context *ctx, void *state)
        sctx->ps_shader.cso = sel;
        sctx->ps_shader.current = sel ? sel->first_variant : NULL;
        sctx->do_update_shaders = true;
+       if (sel && sctx->ia_multi_vgt_param_key.u.uses_tess)
+               si_update_tess_uses_prim_id(sctx);
        si_mark_atom_dirty(sctx, &sctx->cb_render_state);
 }