radeonsi: pass alpha_ref value to PS in the user sgpr
authorVadim Girlin <vadimgirlin@gmail.com>
Sun, 13 Oct 2013 15:53:54 +0000 (19:53 +0400)
committerVadim Girlin <vadimgirlin@gmail.com>
Sun, 13 Oct 2013 16:03:35 +0000 (20:03 +0400)
Currently it's hardcoded in the shader, so every change requires
compilation of the shader variant, killing the performance
in Serious Sam 3 and probably other apps.

This patch passes alpha_ref in the user sgpr and removes it from
the shader key.

Signed-off-by: Vadim Girlin <vadimgirlin@gmail.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeonsi/radeonsi_shader.c
src/gallium/drivers/radeonsi/radeonsi_shader.h
src/gallium/drivers/radeonsi/si_state.c

index 88fc0400a8315ac3a4ea5b2325f17a7fa6d94433..3aa271ea832a850e40b6afece57cd2fb34e53a86 100644 (file)
@@ -570,11 +570,14 @@ static void si_alpha_test(struct lp_build_tgsi_context *bld_base,
 
        if (si_shader_ctx->shader->key.ps.alpha_func != PIPE_FUNC_NEVER) {
                LLVMValueRef out_ptr = si_shader_ctx->radeon_bld.soa.outputs[index][3];
+               LLVMValueRef alpha_ref = LLVMGetParam(si_shader_ctx->radeon_bld.main_fn,
+                               SI_PARAM_ALPHA_REF);
+
                LLVMValueRef alpha_pass =
                        lp_build_cmp(&bld_base->base,
                                     si_shader_ctx->shader->key.ps.alpha_func,
                                     LLVMBuildLoad(gallivm->builder, out_ptr, ""),
-                                    lp_build_const_float(gallivm, si_shader_ctx->shader->key.ps.alpha_ref));
+                                    alpha_ref);
                LLVMValueRef arg =
                        lp_build_select(&bld_base->base,
                                        alpha_pass,
@@ -1569,7 +1572,7 @@ static void create_function(struct si_shader_context *si_shader_ctx)
 {
        struct lp_build_tgsi_context *bld_base = &si_shader_ctx->radeon_bld.soa.bld_base;
        struct gallivm_state *gallivm = bld_base->base.gallivm;
-       LLVMTypeRef params[20], f32, i8, i32, v2i32, v3i32;
+       LLVMTypeRef params[21], f32, i8, i32, v2i32, v3i32;
        unsigned i, last_sgpr, num_params;
 
        i8 = LLVMInt8TypeInContext(gallivm->context);
@@ -1614,6 +1617,7 @@ static void create_function(struct si_shader_context *si_shader_ctx)
                break;
 
        case TGSI_PROCESSOR_FRAGMENT:
+               params[SI_PARAM_ALPHA_REF] = f32;
                params[SI_PARAM_PRIM_MASK] = i32;
                last_sgpr = SI_PARAM_PRIM_MASK;
                params[SI_PARAM_PERSP_SAMPLE] = v2i32;
index 1db8bb8d8eedf00f341d8678f184308d35aff95c..c9e851a899cd6fa10d24c68eebedef49d7e989ee 100644 (file)
 #define SI_SGPR_VERTEX_BUFFER  6  /* VS only */
 #define SI_SGPR_SO_BUFFER      8  /* VS only, stream-out */
 #define SI_SGPR_START_INSTANCE 10 /* VS only */
+#define SI_SGPR_ALPHA_REF      6  /* PS only */
 
 #define SI_VS_NUM_USER_SGPR    11
-#define SI_PS_NUM_USER_SGPR    6
+#define SI_PS_NUM_USER_SGPR    7
 
 /* LLVM function parameter indices */
 #define SI_PARAM_CONST         0
 /* the other VS parameters are assigned dynamically */
 
 /* PS only parameters */
-#define SI_PARAM_PRIM_MASK             3
-#define SI_PARAM_PERSP_SAMPLE          4
-#define SI_PARAM_PERSP_CENTER          5
-#define SI_PARAM_PERSP_CENTROID                6
-#define SI_PARAM_PERSP_PULL_MODEL      7
-#define SI_PARAM_LINEAR_SAMPLE         8
-#define SI_PARAM_LINEAR_CENTER         9
-#define SI_PARAM_LINEAR_CENTROID       10
-#define SI_PARAM_LINE_STIPPLE_TEX      11
-#define SI_PARAM_POS_X_FLOAT           12
-#define SI_PARAM_POS_Y_FLOAT           13
-#define SI_PARAM_POS_Z_FLOAT           14
-#define SI_PARAM_POS_W_FLOAT           15
-#define SI_PARAM_FRONT_FACE            16
-#define SI_PARAM_ANCILLARY             17
-#define SI_PARAM_SAMPLE_COVERAGE       18
-#define SI_PARAM_POS_FIXED_PT          19
+#define SI_PARAM_ALPHA_REF             3
+#define SI_PARAM_PRIM_MASK             4
+#define SI_PARAM_PERSP_SAMPLE          5
+#define SI_PARAM_PERSP_CENTER          6
+#define SI_PARAM_PERSP_CENTROID                7
+#define SI_PARAM_PERSP_PULL_MODEL      8
+#define SI_PARAM_LINEAR_SAMPLE         9
+#define SI_PARAM_LINEAR_CENTER         10
+#define SI_PARAM_LINEAR_CENTROID       11
+#define SI_PARAM_LINE_STIPPLE_TEX      12
+#define SI_PARAM_POS_X_FLOAT           13
+#define SI_PARAM_POS_Y_FLOAT           14
+#define SI_PARAM_POS_Z_FLOAT           15
+#define SI_PARAM_POS_W_FLOAT           16
+#define SI_PARAM_FRONT_FACE            17
+#define SI_PARAM_ANCILLARY             18
+#define SI_PARAM_SAMPLE_COVERAGE       19
+#define SI_PARAM_POS_FIXED_PT          20
 
 struct si_shader_io {
        unsigned                name;
@@ -124,7 +126,6 @@ union si_shader_key {
                unsigned        alpha_func:3;
                unsigned        flatshade:1;
                unsigned        alpha_to_one:1;
-               float           alpha_ref;
        } ps;
        struct {
                unsigned        instance_divisors[PIPE_MAX_ATTRIBS];
index 3e771b297be57fae3405f633f437dcceaba20a1a..da7c3d0ab0c4798b86509c07606f3613c6133871 100644 (file)
@@ -744,6 +744,9 @@ static void *si_create_dsa_state(struct pipe_context *ctx,
        if (state->alpha.enabled) {
                dsa->alpha_func = state->alpha.func;
                dsa->alpha_ref = state->alpha.ref_value;
+
+               si_pm4_set_reg(pm4, R_00B030_SPI_SHADER_USER_DATA_PS_0 +
+                              SI_SGPR_ALPHA_REF * 4, fui(dsa->alpha_ref));
        } else {
                dsa->alpha_func = PIPE_FUNC_ALWAYS;
        }
@@ -2116,10 +2119,6 @@ static INLINE void si_shader_selector_key(struct pipe_context *ctx,
                            rctx->framebuffer.cbufs[0] &&
                            util_format_is_pure_integer(rctx->framebuffer.cbufs[0]->texture->format))
                                key->ps.alpha_func = PIPE_FUNC_ALWAYS;
-
-                       if (key->ps.alpha_func != PIPE_FUNC_ALWAYS &&
-                           key->ps.alpha_func != PIPE_FUNC_NEVER)
-                               key->ps.alpha_ref = rctx->queued.named.dsa->alpha_ref;
                } else {
                        key->ps.alpha_func = PIPE_FUNC_ALWAYS;
                }