freedreno/ir3: handle color clamp variant ourselves
authorRob Clark <robclark@freedesktop.org>
Mon, 25 Apr 2016 13:07:04 +0000 (09:07 -0400)
committerRob Clark <robclark@freedesktop.org>
Sat, 30 Apr 2016 18:56:19 +0000 (14:56 -0400)
Now that there is a pass to do this in NIR, lets just use that and
manage the variants ourself, rather than letting state-tracker do it.
This way, mesa/st will precompile shaders without requiring
ST_DEBUG=precompile (which requires a debug build).

Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/gallium/drivers/freedreno/a3xx/fd3_draw.c
src/gallium/drivers/freedreno/a4xx/fd4_draw.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/freedreno/ir3/ir3_nir.c
src/gallium/drivers/freedreno/ir3/ir3_shader.h

index f48d464c2947c4cd3d50527e337550d380ed2874..ae36d137828498c28366c07e3b54aac48d15d208 100644 (file)
@@ -118,6 +118,12 @@ fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
                                ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
                }
 
+               if (last_key->vclamp_color != key->vclamp_color)
+                       ctx->prog.dirty |= FD_SHADER_DIRTY_VP;
+
+               if (last_key->fclamp_color != key->fclamp_color)
+                       ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
+
                if (last_key->color_two_side != key->color_two_side)
                        ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
 
@@ -140,6 +146,8 @@ fd3_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info)
                        /* do binning pass first: */
                        .binning_pass = true,
                        .color_two_side = ctx->rasterizer->light_twoside,
+                       .vclamp_color = ctx->rasterizer->clamp_vertex_color,
+                       .fclamp_color = ctx->rasterizer->clamp_fragment_color,
                        // TODO set .half_precision based on render target format,
                        // ie. float16 and smaller use half, float32 use full..
                        .half_precision = !!(fd_mesa_debug & FD_DBG_FRAGHALF),
index 68e1f53e2dde9e7d9dbdf9c1e4f725ce8c8c14b1..5b0b972022aad9adff4726eda82fcb3ff7dfe89e 100644 (file)
@@ -104,6 +104,12 @@ fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
                                ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
                }
 
+               if (last_key->vclamp_color != key->vclamp_color)
+                       ctx->prog.dirty |= FD_SHADER_DIRTY_VP;
+
+               if (last_key->fclamp_color != key->fclamp_color)
+                       ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
+
                if (last_key->color_two_side != key->color_two_side)
                        ctx->prog.dirty |= FD_SHADER_DIRTY_FP;
 
@@ -129,6 +135,8 @@ fd4_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info)
                        /* do binning pass first: */
                        .binning_pass = true,
                        .color_two_side = ctx->rasterizer->light_twoside,
+                       .vclamp_color = ctx->rasterizer->clamp_vertex_color,
+                       .fclamp_color = ctx->rasterizer->clamp_fragment_color,
                        .rasterflat = ctx->rasterizer->flatshade,
                        // TODO set .half_precision based on render target format,
                        // ie. float16 and smaller use half, float32 use full..
index 4ae1389ec9e1b2216655bb1166be7859dd5b0740..fee44fa584c16ff0a9d7fb2976a33bb3690f548a 100644 (file)
@@ -222,8 +222,6 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
        case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
        case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
        case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
-       case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
-       case PIPE_CAP_VERTEX_COLOR_CLAMPED:
        case PIPE_CAP_USER_VERTEX_BUFFERS:
        case PIPE_CAP_USER_INDEX_BUFFERS:
        case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
@@ -245,6 +243,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
        case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
        case PIPE_CAP_DEPTH_BOUNDS_TEST:
        case PIPE_CAP_TGSI_TXQS:
+       /* TODO if we need this, do it in nir/ir3 backend to avoid breaking precompile: */
        case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
        case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
        case PIPE_CAP_CLEAR_TEXTURE:
@@ -264,6 +263,9 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
                return 1;
 
        case PIPE_CAP_SHAREABLE_SHADERS:
+       /* manage the variants for these ourself, to avoid breaking precompile: */
+       case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
+       case PIPE_CAP_VERTEX_COLOR_CLAMPED:
                if (is_ir3(screen))
                        return 1;
                return 0;
index 364e92beb538e898fa01fb837ba144cc65d4aac2..99c2ecba480ff2cf1a097b6dbf8927990261d17d 100644 (file)
@@ -58,7 +58,8 @@ ir3_key_lowers_nir(const struct ir3_shader_key *key)
 {
        return key->fsaturate_s | key->fsaturate_t | key->fsaturate_r |
                        key->vsaturate_s | key->vsaturate_t | key->vsaturate_r |
-                       key->ucp_enables | key->color_two_side;
+                       key->ucp_enables | key->color_two_side |
+                       key->fclamp_color | key->vclamp_color;
 }
 
 #define OPT(nir, pass, ...) ({                             \
@@ -114,8 +115,12 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
        if (key) {
                if (s->stage == MESA_SHADER_VERTEX) {
                        OPT_V(s, nir_lower_clip_vs, key->ucp_enables);
+                       if (key->vclamp_color)
+                               OPT_V(s, nir_lower_clamp_color_outputs);
                } else if (s->stage == MESA_SHADER_FRAGMENT) {
                        OPT_V(s, nir_lower_clip_fs, key->ucp_enables);
+                       if (key->fclamp_color)
+                               OPT_V(s, nir_lower_clamp_color_outputs);
                }
                if (key->color_two_side) {
                        OPT_V(s, nir_lower_two_sided_color);
index e81e80d328f261fba66a0b1460104b63b33a5fbe..ff6bf1d67b80cd00226a309a6c78414572789fad 100644 (file)
@@ -81,6 +81,7 @@ struct ir3_shader_key {
                         * Vertex shader variant parameters:
                         */
                        unsigned binning_pass : 1;
+                       unsigned vclamp_color : 1;
 
                        /*
                         * Fragment shader variant parameters:
@@ -91,6 +92,7 @@ struct ir3_shader_key {
                         * for front/back color inputs to frag shader:
                         */
                        unsigned rasterflat : 1;
+                       unsigned fclamp_color : 1;
                };
                uint32_t global;
        };