From e04db879f8933915501bfb9cce0d1359d62766bd Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 25 Apr 2016 09:07:04 -0400 Subject: [PATCH] freedreno/ir3: handle color clamp variant ourselves 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 --- src/gallium/drivers/freedreno/a3xx/fd3_draw.c | 8 ++++++++ src/gallium/drivers/freedreno/a4xx/fd4_draw.c | 8 ++++++++ src/gallium/drivers/freedreno/freedreno_screen.c | 6 ++++-- src/gallium/drivers/freedreno/ir3/ir3_nir.c | 7 ++++++- src/gallium/drivers/freedreno/ir3/ir3_shader.h | 2 ++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_draw.c b/src/gallium/drivers/freedreno/a3xx/fd3_draw.c index f48d464c294..ae36d137828 100644 --- a/src/gallium/drivers/freedreno/a3xx/fd3_draw.c +++ b/src/gallium/drivers/freedreno/a3xx/fd3_draw.c @@ -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), diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_draw.c b/src/gallium/drivers/freedreno/a4xx/fd4_draw.c index 68e1f53e2dd..5b0b972022a 100644 --- a/src/gallium/drivers/freedreno/a4xx/fd4_draw.c +++ b/src/gallium/drivers/freedreno/a4xx/fd4_draw.c @@ -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.. diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c index 4ae1389ec9e..fee44fa584c 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.c +++ b/src/gallium/drivers/freedreno/freedreno_screen.c @@ -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; diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir.c b/src/gallium/drivers/freedreno/ir3/ir3_nir.c index 364e92beb53..99c2ecba480 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_nir.c +++ b/src/gallium/drivers/freedreno/ir3/ir3_nir.c @@ -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); diff --git a/src/gallium/drivers/freedreno/ir3/ir3_shader.h b/src/gallium/drivers/freedreno/ir3/ir3_shader.h index e81e80d328f..ff6bf1d67b8 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_shader.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_shader.h @@ -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; }; -- 2.30.2