OSDN Git Service

r600: Turn 'r600_shader_key' struct into union
authorEdward O'Callaghan <eocallaghan@alterapraxis.com>
Wed, 19 Aug 2015 08:58:47 +0000 (18:58 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 20 Aug 2015 23:46:13 +0000 (09:46 +1000)
This struct was getting a bit crowded, following the lead of
radeonsi, mirror the idea of having sub-structures for each
shader type. Turning 'r600_shader_key' into an union saves
some trivial memory and CPU cycles for the shader keys.

[airlied: drop as_ls, and reorder so larger fields at start.]
Signed-off-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_shader.c
src/gallium/drivers/r600/r600_shader.h
src/gallium/drivers/r600/r600_state_common.c

index 9b66105..384ba80 100644 (file)
@@ -90,7 +90,7 @@
 
 struct r600_context;
 struct r600_bytecode;
-struct r600_shader_key;
+union  r600_shader_key;
 
 /* This is an atom containing GPU commands that never change.
  * This is supposed to be copied directly into the CS. */
@@ -643,7 +643,7 @@ void r600_resource_copy_region(struct pipe_context *ctx,
 /* r600_shader.c */
 int r600_pipe_shader_create(struct pipe_context *ctx,
                            struct r600_pipe_shader *shader,
-                           struct r600_shader_key key);
+                           union r600_shader_key key);
 
 void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
 
index 8d1f95a..6cbfd1b 100644 (file)
@@ -62,7 +62,7 @@ The compiler must issue the source argument to slots z, y, and x
 
 static int r600_shader_from_tgsi(struct r600_context *rctx,
                                 struct r600_pipe_shader *pipeshader,
-                                struct r600_shader_key key);
+                                union r600_shader_key key);
 
 
 static void r600_add_gpr_array(struct r600_shader *ps, int start_gpr,
@@ -133,7 +133,7 @@ static int store_shader(struct pipe_context *ctx,
 
 int r600_pipe_shader_create(struct pipe_context *ctx,
                            struct r600_pipe_shader *shader,
-                           struct r600_shader_key key)
+                           union r600_shader_key key)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
        struct r600_pipe_shader_selector *sel = shader->selector;
@@ -141,7 +141,7 @@ int r600_pipe_shader_create(struct pipe_context *ctx,
        bool dump = r600_can_dump_shader(&rctx->screen->b, sel->tokens);
        unsigned use_sb = !(rctx->screen->b.debug_flags & DBG_NO_SB);
        unsigned sb_disasm = use_sb || (rctx->screen->b.debug_flags & DBG_SB_DISASM);
-       unsigned export_shader = key.vs_as_es;
+       unsigned export_shader = key.vs.as_es;
 
        shader->shader.bc.isa = rctx->isa;
 
@@ -1802,7 +1802,7 @@ static int emit_gs_ring_writes(struct r600_shader_ctx *ctx, bool ind)
 
 static int r600_shader_from_tgsi(struct r600_context *rctx,
                                 struct r600_pipe_shader *pipeshader,
-                                struct r600_shader_key key)
+                                union r600_shader_key key)
 {
        struct r600_screen *rscreen = rctx->screen;
        struct r600_shader *shader = &pipeshader->shader;
@@ -1816,7 +1816,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
        unsigned opcode;
        int i, j, k, r = 0;
        int next_param_base = 0, next_clip_base;
-       int max_color_exports = MAX2(key.nr_cbufs, 1);
+       int max_color_exports = MAX2(key.ps.nr_cbufs, 1);
        /* Declarations used by llvm code */
        bool use_llvm = false;
        bool indirect_gprs;
@@ -1830,8 +1830,8 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
        ctx.shader = shader;
        ctx.native_integers = true;
 
-       shader->vs_as_gs_a = key.vs_as_gs_a;
-       shader->vs_as_es = key.vs_as_es;
+       shader->vs_as_gs_a = key.vs.as_gs_a;
+       shader->vs_as_es = key.vs.as_es;
 
        r600_bytecode_init(ctx.bc, rscreen->b.chip_class, rscreen->b.family,
                           rscreen->has_compressed_msaa_texturing);
@@ -1844,9 +1844,9 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
        shader->processor_type = ctx.type;
        ctx.bc->type = shader->processor_type;
 
-       ring_outputs = key.vs_as_es || (ctx.type == TGSI_PROCESSOR_GEOMETRY);
+       ring_outputs = key.vs.as_es || (ctx.type == TGSI_PROCESSOR_GEOMETRY);
 
-       if (key.vs_as_es) {
+       if (key.vs.as_es) {
                ctx.gs_for_vs = &rctx->gs_shader->current->shader;
        } else {
                ctx.gs_for_vs = NULL;
@@ -1866,7 +1866,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
        shader->nr_ps_color_exports = 0;
        shader->nr_ps_max_color_exports = 0;
 
-       shader->two_side = key.color_two_side;
+       shader->two_side = key.ps.color_two_side;
 
        /* register allocations */
        /* Values [0,127] correspond to GPR[0..127].
@@ -1970,7 +1970,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
        shader->fs_write_all = FALSE;
 
        if (shader->vs_as_gs_a)
-               vs_add_primid_output(&ctx, key.vs_prim_id_out);
+               vs_add_primid_output(&ctx, key.vs.prim_id_out);
 
        while (!tgsi_parse_end_of_tokens(&ctx.parse)) {
                tgsi_parse_token(&ctx.parse);
@@ -2091,7 +2091,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
                radeon_llvm_ctx.chip_class = ctx.bc->chip_class;
                radeon_llvm_ctx.fs_color_all = shader->fs_write_all && (rscreen->b.chip_class >= EVERGREEN);
                radeon_llvm_ctx.stream_outputs = &so;
-               radeon_llvm_ctx.alpha_to_one = key.alpha_to_one;
+               radeon_llvm_ctx.alpha_to_one = key.ps.alpha_to_one;
                radeon_llvm_ctx.has_compressed_msaa_texturing =
                        ctx.bc->has_compressed_msaa_texturing;
                mod = r600_tgsi_llvm(&radeon_llvm_ctx, tokens);
@@ -2270,7 +2270,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
        convert_edgeflag_to_int(&ctx);
 
        if (ring_outputs) {
-               if (key.vs_as_es)
+               if (key.vs.as_es)
                        emit_gs_ring_writes(&ctx, FALSE);
        } else {
                /* Export output */
@@ -2386,7 +2386,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
                                                j--;
                                                continue;
                                        }
-                                       output[j].swizzle_w = key.alpha_to_one ? 5 : 3;
+                                       output[j].swizzle_w = key.ps.alpha_to_one ? 5 : 3;
                                        output[j].array_base = shader->output[i].sid;
                                        output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
                                        shader->nr_ps_color_exports++;
@@ -2399,7 +2399,7 @@ static int r600_shader_from_tgsi(struct r600_context *rctx,
                                                        output[j].swizzle_x = 0;
                                                        output[j].swizzle_y = 1;
                                                        output[j].swizzle_z = 2;
-                                                       output[j].swizzle_w = key.alpha_to_one ? 5 : 3;
+                                                       output[j].swizzle_w = key.ps.alpha_to_one ? 5 : 3;
                                                        output[j].burst_count = 1;
                                                        output[j].array_base = k;
                                                        output[j].op = CF_OP_EXPORT;
index 5d05c81..927bac5 100644 (file)
@@ -95,13 +95,17 @@ struct r600_shader {
        struct r600_shader_array * arrays;
 };
 
-struct r600_shader_key {
-       unsigned color_two_side:1;
-       unsigned alpha_to_one:1;
-       unsigned nr_cbufs:4;
-       unsigned vs_as_es:1;
-       unsigned vs_as_gs_a:1;
-       unsigned vs_prim_id_out:8;
+union r600_shader_key {
+       struct {
+               unsigned        nr_cbufs:4;
+               unsigned        color_two_side:1;
+               unsigned        alpha_to_one:1;
+       } ps;
+       struct {
+               unsigned        prim_id_out:8;
+               unsigned        as_es:1; /* export shader */
+               unsigned        as_gs_a:1;
+       } vs;
 };
 
 struct r600_shader_array {
@@ -122,7 +126,7 @@ struct r600_pipe_shader {
        unsigned                flatshade;
        unsigned                pa_cl_vs_out_cntl;
        unsigned                nr_ps_color_outputs;
-       struct r600_shader_key  key;
+       union r600_shader_key   key;
        unsigned                db_shader_control;
        unsigned                ps_depth_export;
        unsigned                enabled_stream_buffers_mask;
index c7445b8..a05dd83 100644 (file)
@@ -702,33 +702,33 @@ void r600_emit_viewport_state(struct r600_context *rctx, struct r600_atom *atom)
 }
 
 /* Compute the key for the hw shader variant */
-static inline struct r600_shader_key r600_shader_selector_key(struct pipe_context * ctx,
+static inline union r600_shader_key r600_shader_selector_key(struct pipe_context * ctx,
                struct r600_pipe_shader_selector * sel)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
-       struct r600_shader_key key;
+       union r600_shader_key key;
        memset(&key, 0, sizeof(key));
 
        switch (sel->type) {
        case PIPE_SHADER_VERTEX: {
-               key.vs_as_es = (rctx->gs_shader != NULL);
+               key.vs.as_es = (rctx->gs_shader != NULL);
                if (rctx->ps_shader->current->shader.gs_prim_id_input && !rctx->gs_shader) {
-                       key.vs_as_gs_a = true;
-                       key.vs_prim_id_out = rctx->ps_shader->current->shader.input[rctx->ps_shader->current->shader.ps_prim_id_input].spi_sid;
+                       key.vs.as_gs_a = true;
+                       key.vs.prim_id_out = rctx->ps_shader->current->shader.input[rctx->ps_shader->current->shader.ps_prim_id_input].spi_sid;
                }
                break;
        }
        case PIPE_SHADER_GEOMETRY:
                break;
        case PIPE_SHADER_FRAGMENT: {
-               key.color_two_side = rctx->rasterizer && rctx->rasterizer->two_side;
-               key.alpha_to_one = rctx->alpha_to_one &&
-                                  rctx->rasterizer && rctx->rasterizer->multisample_enable &&
-                                  !rctx->framebuffer.cb0_is_integer;
-               key.nr_cbufs = rctx->framebuffer.state.nr_cbufs;
+               key.ps.color_two_side = rctx->rasterizer && rctx->rasterizer->two_side;
+               key.ps.alpha_to_one = rctx->alpha_to_one &&
+                                     rctx->rasterizer && rctx->rasterizer->multisample_enable &&
+                                     !rctx->framebuffer.cb0_is_integer;
+               key.ps.nr_cbufs = rctx->framebuffer.state.nr_cbufs;
                /* Dual-source blending only makes sense with nr_cbufs == 1. */
-               if (key.nr_cbufs == 1 && rctx->dual_src_blend)
-                       key.nr_cbufs = 2;
+               if (key.ps.nr_cbufs == 1 && rctx->dual_src_blend)
+                       key.ps.nr_cbufs = 2;
                break;
        }
        default:
@@ -744,7 +744,7 @@ static int r600_shader_select(struct pipe_context *ctx,
         struct r600_pipe_shader_selector* sel,
         bool *dirty)
 {
-       struct r600_shader_key key;
+       union r600_shader_key key;
        struct r600_pipe_shader * shader = NULL;
        int r;