radeonsi: Generalize counting of shader parameters
authorMichel Dänzer <michel.daenzer@amd.com>
Thu, 9 Jan 2014 06:33:34 +0000 (15:33 +0900)
committerMichel Dänzer <michel@daenzer.net>
Wed, 29 Jan 2014 02:06:58 +0000 (11:06 +0900)
Now it covers ES->GS as well as VS->PS.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_state_draw.c

index 8696d03ca922b68d22dc1c1cae4d691581e01ec3..42a3fc6a73b778509ae105c7215e564c2f3dcff0 100644 (file)
@@ -158,6 +158,34 @@ static LLVMValueRef get_instance_index_for_fetch(
        return result;
 }
 
+static int si_store_shader_io_attribs(struct si_shader *shader,
+                                     const struct tgsi_full_declaration *d)
+{
+       int i = -1;
+
+       switch (d->Declaration.File) {
+       case TGSI_FILE_INPUT:
+               i = shader->ninput++;
+               assert(i < Elements(shader->input));
+               shader->input[i].name = d->Semantic.Name;
+               shader->input[i].sid = d->Semantic.Index;
+               shader->input[i].interpolate = d->Interp.Interpolate;
+               shader->input[i].centroid = d->Interp.Centroid;
+               return -1;
+
+       case TGSI_FILE_OUTPUT:
+               i = shader->noutput++;
+               assert(i < Elements(shader->output));
+               shader->output[i].name = d->Semantic.Name;
+               shader->output[i].sid = d->Semantic.Index;
+               shader->output[i].index = d->Range.First;
+               shader->output[i].usage = d->Declaration.UsageMask;
+               break;
+       }
+
+       return i;
+}
+
 static void declare_input_vs(
        struct radeon_llvm_context *radeon_bld,
        unsigned input_index,
@@ -225,7 +253,12 @@ static void declare_input_gs(
        unsigned input_index,
        const struct tgsi_full_declaration *decl)
 {
-       /* Nothing to do, inputs are handled in fetch_input_gs() below */
+       struct si_shader_context *si_shader_ctx =
+               si_shader_context(&radeon_bld->soa.bld_base);
+       struct si_shader *shader = &si_shader_ctx->shader->shader;
+
+       si_store_shader_io_attribs(shader, decl);
+       shader->input[input_index].param_offset = shader->nparam++;
 }
 
 static LLVMValueRef fetch_input_gs(
@@ -236,6 +269,7 @@ static LLVMValueRef fetch_input_gs(
 {
        struct lp_build_context *base = &bld_base->base;
        struct si_shader_context *si_shader_ctx = si_shader_context(bld_base);
+       struct si_shader *shader = &si_shader_ctx->shader->shader;
        struct lp_build_context *uint = &si_shader_ctx->radeon_bld.soa.bld_base.uint_bld;
        struct gallivm_state *gallivm = base->gallivm;
        LLVMTypeRef i32 = LLVMInt32TypeInContext(gallivm->context);
@@ -280,7 +314,8 @@ static LLVMValueRef fetch_input_gs(
        args[0] = t_list;
        args[1] = vtx_offset;
        args[2] = lp_build_const_int32(gallivm,
-                                      ((reg->Register.Index * 4) + swizzle) * 256);
+                                      ((shader->input[reg->Register.Index].param_offset * 4) +
+                                       swizzle) * 256);
        args[3] = uint->zero;
        args[4] = uint->one;  /* OFFEN */
        args[5] = uint->zero; /* IDXEN */
@@ -368,7 +403,7 @@ static void declare_input_fs(
                return;
        }
 
-       shader->input[input_index].param_offset = shader->ninterp++;
+       shader->input[input_index].param_offset = shader->nparam++;
        attr_number = lp_build_const_int32(gallivm,
                                           shader->input[input_index].param_offset);
 
@@ -447,7 +482,7 @@ static void declare_input_fs(
                                                "");
                }
 
-               shader->ninterp++;
+               shader->nparam++;
        } else if (decl->Semantic.Name == TGSI_SEMANTIC_FOG) {
                LLVMValueRef args[4];
 
@@ -939,34 +974,6 @@ static void si_llvm_emit_streamout(struct si_shader_context *shader)
 }
 
 
-static int si_store_shader_io_attribs(struct si_shader *shader,
-                                     struct tgsi_full_declaration *d)
-{
-       int i = -1;
-
-       switch (d->Declaration.File) {
-       case TGSI_FILE_INPUT:
-               i = shader->ninput++;
-               assert(i < Elements(shader->input));
-               shader->input[i].name = d->Semantic.Name;
-               shader->input[i].sid = d->Semantic.Index;
-               shader->input[i].interpolate = d->Interp.Interpolate;
-               shader->input[i].centroid = d->Interp.Centroid;
-               return -1;
-
-       case TGSI_FILE_OUTPUT:
-               i = shader->noutput++;
-               assert(i < Elements(shader->output));
-               shader->output[i].name = d->Semantic.Name;
-               shader->output[i].sid = d->Semantic.Index;
-               shader->output[i].index = d->Range.First;
-               shader->output[i].usage = d->Declaration.UsageMask;
-               break;
-       }
-
-       return i;
-}
-
 /* Generate export instructions for hardware VS shader stage */
 static void si_llvm_export_vs(struct lp_build_tgsi_context *bld_base,
                              struct si_shader_output_values *outputs,
@@ -1877,9 +1884,12 @@ static void si_llvm_emit_vertex(
                while (!tgsi_parse_end_of_tokens(parse)) {
                        tgsi_parse_token(parse);
 
-                       if (parse->FullToken.Token.Type == TGSI_TOKEN_TYPE_DECLARATION)
-                               si_store_shader_io_attribs(shader,
-                                                          &parse->FullToken.FullDeclaration);
+                       if (parse->FullToken.Token.Type == TGSI_TOKEN_TYPE_DECLARATION) {
+                               struct tgsi_full_declaration *d = &parse->FullToken.FullDeclaration;
+
+                               if (d->Declaration.File == TGSI_FILE_OUTPUT)
+                                       si_store_shader_io_attribs(shader, d);
+                       }
                }
        }
 
@@ -2397,7 +2407,7 @@ int si_pipe_shader_create(
        bool dump = r600_can_dump_shader(&sctx->screen->b, shader->selector->tokens);
 
        assert(shader->shader.noutput == 0);
-       assert(shader->shader.ninterp == 0);
+       assert(shader->shader.nparam == 0);
        assert(shader->shader.ninput == 0);
 
        memset(&si_shader_ctx, 0, sizeof(si_shader_ctx));
index 19bad44c9e1a53b1a288193e68d339189b709367..32999066cc5ebe58470dfa79b3a3156ecf1d66b2 100644 (file)
@@ -136,7 +136,7 @@ struct si_shader {
        unsigned                gs_output_prim;
        unsigned                gs_max_out_vertices;
 
-       unsigned                ninterp;
+       unsigned                nparam;
        bool                    uses_kill;
        bool                    uses_instanceid;
        bool                    fs_write_all;
index c5a59750390e0b0588313cf2c2a74a61f14913d8..66b7ef3e04638b02a14cf8ada29ddd888f662241 100644 (file)
@@ -287,7 +287,7 @@ static void si_pipe_shader_ps(struct pipe_context *ctx, struct si_pipe_shader *s
                exports_ps = 2;
        }
 
-       spi_ps_in_control = S_0286D8_NUM_INTERP(shader->shader.ninterp) |
+       spi_ps_in_control = S_0286D8_NUM_INTERP(shader->shader.nparam) |
                S_0286D8_BC_OPTIMIZE_DISABLE(1);
 
        si_pm4_set_reg(pm4, R_0286E0_SPI_BARYC_CNTL, spi_baryc_cntl);