Reviewed-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>

On 06/05/2017 06:50 PM, Marek Olšák wrote:
From: Marek Olšák <marek.ol...@amd.com>

We can use a union in si_shader_key::mono.
---
  src/gallium/drivers/radeonsi/si_shader.c        | 14 +++++++-------
  src/gallium/drivers/radeonsi/si_shader.h        |  9 ++++++---
  src/gallium/drivers/radeonsi/si_state_shaders.c |  8 ++++----
  3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index 5c7deeb..2c92269 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -2485,21 +2485,21 @@ static void si_copy_tcs_inputs(struct 
lp_build_tgsi_context *bld_base)
        invocation_id = unpack_param(ctx, ctx->param_tcs_rel_ids, 8, 5);
        buffer = desc_from_addr_base64k(ctx, 
ctx->param_tcs_offchip_addr_base64k);
        buffer_offset = LLVMGetParam(ctx->main_fn, 
ctx->param_tcs_offchip_offset);
lds_vertex_stride = unpack_param(ctx, ctx->param_vs_state_bits, 24, 8);
        lds_vertex_offset = LLVMBuildMul(gallivm->builder, invocation_id,
                                         lds_vertex_stride, "");
        lds_base = get_tcs_in_current_patch_offset(ctx);
        lds_base = LLVMBuildAdd(gallivm->builder, lds_base, lds_vertex_offset, 
"");
- inputs = ctx->shader->key.mono.ff_tcs_inputs_to_copy;
+       inputs = ctx->shader->key.mono.u.ff_tcs_inputs_to_copy;
        while (inputs) {
                unsigned i = u_bit_scan64(&inputs);
LLVMValueRef lds_ptr = LLVMBuildAdd(gallivm->builder, lds_base,
                                            LLVMConstInt(ctx->i32, 4 * i, 0),
                                             "");
LLVMValueRef buffer_addr = get_tcs_tes_buffer_address(ctx,
                                              get_rel_patch_id(ctx),
                                              invocation_id,
@@ -3012,21 +3012,21 @@ static void si_llvm_emit_vs_epilogue(struct 
lp_build_tgsi_context *bld_base)
                                              "");
                        outputs[i].vertex_stream[j] =
                                (info->output_streams[i] >> (2 * j)) & 3;
                }
        }
if (ctx->shader->selector->so.num_outputs)
                si_llvm_emit_streamout(ctx, outputs, i, 0);
/* Export PrimitiveID. */
-       if (ctx->shader->key.mono.vs_export_prim_id) {
+       if (ctx->shader->key.mono.u.vs_export_prim_id) {
                outputs[i].semantic_name = TGSI_SEMANTIC_PRIMID;
                outputs[i].semantic_index = 0;
                outputs[i].values[0] = bitcast(bld_base, TGSI_TYPE_FLOAT,
                                               get_primitive_id(bld_base, 0));
                for (j = 1; j < 4; j++)
                        outputs[i].values[j] = LLVMConstReal(ctx->f32, 0);
memset(outputs[i].vertex_stream, 0,
                       sizeof(outputs[i].vertex_stream));
                i++;
@@ -5266,37 +5266,37 @@ static void si_dump_shader_key(unsigned processor, 
const struct si_shader *shade
        const struct si_shader_key *key = &shader->key;
fprintf(f, "SHADER KEY\n"); switch (processor) {
        case PIPE_SHADER_VERTEX:
                si_dump_shader_key_vs(key, &key->part.vs.prolog,
                                      "part.vs.prolog", f);
                fprintf(f, "  as_es = %u\n", key->as_es);
                fprintf(f, "  as_ls = %u\n", key->as_ls);
-               fprintf(f, "  mono.vs_export_prim_id = %u\n",
-                       key->mono.vs_export_prim_id);
+               fprintf(f, "  mono.u.vs_export_prim_id = %u\n",
+                       key->mono.u.vs_export_prim_id);
                break;
case PIPE_SHADER_TESS_CTRL:
                if (shader->selector->screen->b.chip_class >= GFX9) {
                        si_dump_shader_key_vs(key, &key->part.tcs.ls_prolog,
                                              "part.tcs.ls_prolog", f);
                }
                fprintf(f, "  part.tcs.epilog.prim_mode = %u\n", 
key->part.tcs.epilog.prim_mode);
-               fprintf(f, "  mono.ff_tcs_inputs_to_copy = 0x%"PRIx64"\n", 
key->mono.ff_tcs_inputs_to_copy);
+               fprintf(f, "  mono.u.ff_tcs_inputs_to_copy = 0x%"PRIx64"\n", 
key->mono.u.ff_tcs_inputs_to_copy);
                break;
case PIPE_SHADER_TESS_EVAL:
                fprintf(f, "  as_es = %u\n", key->as_es);
-               fprintf(f, "  mono.vs_export_prim_id = %u\n",
-                       key->mono.vs_export_prim_id);
+               fprintf(f, "  mono.u.vs_export_prim_id = %u\n",
+                       key->mono.u.vs_export_prim_id);
                break;
case PIPE_SHADER_GEOMETRY:
                if (shader->is_gs_copy_shader)
                        break;
if (shader->selector->screen->b.chip_class >= GFX9 &&
                    key->part.gs.es->type == PIPE_SHADER_VERTEX) {
                        si_dump_shader_key_vs(key, &key->part.gs.vs_prolog,
                                              "part.gs.vs_prolog", f);
diff --git a/src/gallium/drivers/radeonsi/si_shader.h 
b/src/gallium/drivers/radeonsi/si_shader.h
index 7112621..f739769 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -480,23 +480,26 @@ struct si_shader_key {
        /* These two are initially set according to the NEXT_SHADER property,
         * or guessed if the property doesn't seem correct.
         */
        unsigned as_es:1; /* export shader, which precedes GS */
        unsigned as_ls:1; /* local shader, which precedes TCS */
/* Flags for monolithic compilation only. */
        struct {
                /* One byte for every input: SI_FIX_FETCH_* enums. */
                uint8_t         vs_fix_fetch[SI_MAX_ATTRIBS];
-               uint64_t        ff_tcs_inputs_to_copy; /* for fixed-func TCS */
-               /* When PS needs PrimID and GS is disabled. */
-               unsigned        vs_export_prim_id:1;
+
+               union {
+                       uint64_t        ff_tcs_inputs_to_copy; /* for 
fixed-func TCS */
+                       /* When PS needs PrimID and GS is disabled. */
+                       unsigned        vs_export_prim_id:1;
+               } u;
        } mono;
/* Optimization flags for asynchronous compilation only. */
        struct {
                struct {
                        uint64_t        kill_outputs; /* "get_unique_index" 
bits */
                        unsigned        clip_disable:1;
                } hw_vs; /* HW VS (it can be VS, TES, GS) */
/* For shaders where monolithic variants have better code.
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c 
b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 41f8bdf..7ed6722 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -836,21 +836,21 @@ static void si_shader_gs(struct si_screen *sscreen, 
struct si_shader *shader)
  static void si_shader_vs(struct si_screen *sscreen, struct si_shader *shader,
                           struct si_shader_selector *gs)
  {
        struct si_pm4_state *pm4;
        unsigned num_user_sgprs;
        unsigned nparams, vgpr_comp_cnt;
        uint64_t va;
        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 || 
shader->selector->info.uses_primid;
+       bool enable_prim_id = shader->key.mono.u.vs_export_prim_id || 
shader->selector->info.uses_primid;
pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
/* We always write VGT_GS_MODE in the VS state, because every switch
         * between different shader pipelines involving a different GS or no
         * GS at all involves a switch of the VS (different GS use different
         * copy shaders). On the other hand, when the API switches from a GS to
         * no GS and then back to the same GS used originally, the GS state is
@@ -1260,46 +1260,46 @@ static inline void si_shader_selector_key(struct 
pipe_context *ctx,
                si_shader_selector_key_vs(sctx, sel, key, &key->part.vs.prolog);
if (sctx->tes_shader.cso)
                        key->as_ls = 1;
                else if (sctx->gs_shader.cso)
                        key->as_es = 1;
                else {
                        si_shader_selector_key_hw_vs(sctx, sel, key);
if (sctx->ps_shader.cso && sctx->ps_shader.cso->info.uses_primid)
-                               key->mono.vs_export_prim_id = 1;
+                               key->mono.u.vs_export_prim_id = 1;
                }
                break;
        case PIPE_SHADER_TESS_CTRL:
                if (sctx->b.chip_class >= GFX9) {
                        si_shader_selector_key_vs(sctx, sctx->vs_shader.cso,
                                                  key, 
&key->part.tcs.ls_prolog);
                        key->part.tcs.ls = sctx->vs_shader.cso;
                }
key->part.tcs.epilog.prim_mode =
                        
sctx->tes_shader.cso->info.properties[TGSI_PROPERTY_TES_PRIM_MODE];
                key->part.tcs.epilog.tes_reads_tess_factors =
                        sctx->tes_shader.cso->info.reads_tess_factors;
if (sel == sctx->fixed_func_tcs_shader.cso)
-                       key->mono.ff_tcs_inputs_to_copy = 
sctx->vs_shader.cso->outputs_written;
+                       key->mono.u.ff_tcs_inputs_to_copy = 
sctx->vs_shader.cso->outputs_written;
                break;
        case PIPE_SHADER_TESS_EVAL:
                if (sctx->gs_shader.cso)
                        key->as_es = 1;
                else {
                        si_shader_selector_key_hw_vs(sctx, sel, key);
if (sctx->ps_shader.cso && sctx->ps_shader.cso->info.uses_primid)
-                               key->mono.vs_export_prim_id = 1;
+                               key->mono.u.vs_export_prim_id = 1;
                }
                break;
        case PIPE_SHADER_GEOMETRY:
                if (sctx->b.chip_class >= GFX9) {
                        if (sctx->tes_shader.cso) {
                                key->part.gs.es = sctx->tes_shader.cso;
                        } else {
                                si_shader_selector_key_vs(sctx, 
sctx->vs_shader.cso,
                                                          key, 
&key->part.gs.vs_prolog);
                                key->part.gs.es = sctx->vs_shader.cso;

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to