ac: import linear/perspective PS input parameters from radv/radeonsi
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 31 Jul 2019 07:54:48 +0000 (09:54 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 30 Aug 2019 06:23:54 +0000 (08:23 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_shader_abi.h
src/amd/vulkan/radv_nir_to_llvm.c
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_nir.c

index ef628c1ff10045d77667f2ab30c75e678f803aa2..935355fbffa2cbbf15b2fcf3246f56ee7549f222 100644 (file)
@@ -58,6 +58,8 @@ struct ac_shader_abi {
        LLVMValueRef tes_patch_id;
        LLVMValueRef gs_prim_id;
        LLVMValueRef gs_invocation_id;
+
+       /* PS */
        LLVMValueRef frag_pos[4];
        LLVMValueRef front_face;
        LLVMValueRef ancillary;
@@ -66,6 +68,13 @@ struct ac_shader_abi {
        LLVMValueRef color0;
        LLVMValueRef color1;
        LLVMValueRef user_data;
+       LLVMValueRef persp_sample;
+       LLVMValueRef persp_center;
+       LLVMValueRef persp_centroid;
+       LLVMValueRef linear_sample;
+       LLVMValueRef linear_center;
+       LLVMValueRef linear_centroid;
+
        /* CS */
        LLVMValueRef local_invocation_ids;
        LLVMValueRef num_work_groups;
index fbfe12da562826fbcd8c48b6cd07198c308a5302..94d51b31b81ff31e325e06ae9c2fc75e6c698f6c 100644 (file)
@@ -86,9 +86,6 @@ struct radv_shader_context {
        LLVMValueRef hs_ring_tess_offchip;
        LLVMValueRef hs_ring_tess_factor;
 
-       LLVMValueRef persp_sample, persp_center, persp_centroid;
-       LLVMValueRef linear_sample, linear_center, linear_centroid;
-
        /* Streamout */
        LLVMValueRef streamout_buffers;
        LLVMValueRef streamout_write_idx;
@@ -1232,13 +1229,13 @@ static void create_function(struct radv_shader_context *ctx,
                                           &desc_sets);
 
                add_arg(&args, ARG_SGPR, ctx->ac.i32, &ctx->abi.prim_mask);
-               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->persp_sample);
-               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->persp_center);
-               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->persp_centroid);
+               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->abi.persp_sample);
+               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->abi.persp_center);
+               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->abi.persp_centroid);
                add_arg(&args, ARG_VGPR, ctx->ac.v3i32, NULL); /* persp pull model */
-               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->linear_sample);
-               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->linear_center);
-               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->linear_centroid);
+               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->abi.linear_sample);
+               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->abi.linear_center);
+               add_arg(&args, ARG_VGPR, ctx->ac.v2i32, &ctx->abi.linear_centroid);
                add_arg(&args, ARG_VGPR, ctx->ac.f32, NULL);  /* line stipple tex */
                add_arg(&args, ARG_VGPR, ctx->ac.f32, &ctx->abi.frag_pos[0]);
                add_arg(&args, ARG_VGPR, ctx->ac.f32, &ctx->abi.frag_pos[1]);
@@ -1774,19 +1771,19 @@ static LLVMValueRef lookup_interp_param(struct ac_shader_abi *abi,
        case INTERP_MODE_SMOOTH:
        case INTERP_MODE_NONE:
                if (location == INTERP_CENTER)
-                       return ctx->persp_center;
+                       return ctx->abi.persp_center;
                else if (location == INTERP_CENTROID)
-                       return ctx->persp_centroid;
+                       return ctx->abi.persp_centroid;
                else if (location == INTERP_SAMPLE)
-                       return ctx->persp_sample;
+                       return ctx->abi.persp_sample;
                break;
        case INTERP_MODE_NOPERSPECTIVE:
                if (location == INTERP_CENTER)
-                       return ctx->linear_center;
+                       return ctx->abi.linear_center;
                else if (location == INTERP_CENTROID)
-                       return ctx->linear_centroid;
+                       return ctx->abi.linear_centroid;
                else if (location == INTERP_SAMPLE)
-                       return ctx->linear_sample;
+                       return ctx->abi.linear_sample;
                break;
        }
        return NULL;
@@ -2382,8 +2379,8 @@ prepare_interp_optimize(struct radv_shader_context *ctx,
 
        if (uses_center && uses_centroid) {
                LLVMValueRef sel = LLVMBuildICmp(ctx->ac.builder, LLVMIntSLT, ctx->abi.prim_mask, ctx->ac.i32_0, "");
-               ctx->persp_centroid = LLVMBuildSelect(ctx->ac.builder, sel, ctx->persp_center, ctx->persp_centroid, "");
-               ctx->linear_centroid = LLVMBuildSelect(ctx->ac.builder, sel, ctx->linear_center, ctx->linear_centroid, "");
+               ctx->abi.persp_centroid = LLVMBuildSelect(ctx->ac.builder, sel, ctx->abi.persp_center, ctx->abi.persp_centroid, "");
+               ctx->abi.linear_centroid = LLVMBuildSelect(ctx->ac.builder, sel, ctx->abi.linear_center, ctx->abi.linear_centroid, "");
        }
 }
 
index c0c45b0bae6e2c994074330fa567243f7d3c6f39..171c1393aefd1ee6e908cf87380b115928613e7a 100644 (file)
@@ -4904,13 +4904,19 @@ static void create_function(struct si_shader_context *ctx)
                add_arg_assign_checked(&fninfo, ARG_SGPR, ctx->i32,
                                       &ctx->abi.prim_mask, SI_PARAM_PRIM_MASK);
 
-               add_arg_checked(&fninfo, ARG_VGPR, ctx->v2i32, SI_PARAM_PERSP_SAMPLE);
-               add_arg_checked(&fninfo, ARG_VGPR, ctx->v2i32, SI_PARAM_PERSP_CENTER);
-               add_arg_checked(&fninfo, ARG_VGPR, ctx->v2i32, SI_PARAM_PERSP_CENTROID);
+               add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->v2i32,
+                                      &ctx->abi.persp_sample, SI_PARAM_PERSP_SAMPLE);
+               add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->v2i32,
+                                      &ctx->abi.persp_center, SI_PARAM_PERSP_CENTER);
+               add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->v2i32,
+                                      &ctx->abi.persp_centroid, SI_PARAM_PERSP_CENTROID);
                add_arg_checked(&fninfo, ARG_VGPR, v3i32, SI_PARAM_PERSP_PULL_MODEL);
-               add_arg_checked(&fninfo, ARG_VGPR, ctx->v2i32, SI_PARAM_LINEAR_SAMPLE);
-               add_arg_checked(&fninfo, ARG_VGPR, ctx->v2i32, SI_PARAM_LINEAR_CENTER);
-               add_arg_checked(&fninfo, ARG_VGPR, ctx->v2i32, SI_PARAM_LINEAR_CENTROID);
+               add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->v2i32,
+                                      &ctx->abi.linear_sample, SI_PARAM_LINEAR_SAMPLE);
+               add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->v2i32,
+                                      &ctx->abi.linear_center, SI_PARAM_LINEAR_CENTER);
+               add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->v2i32,
+                                      &ctx->abi.linear_centroid, SI_PARAM_LINEAR_CENTROID);
                add_arg_checked(&fninfo, ARG_VGPR, ctx->f32, SI_PARAM_LINE_STIPPLE_TEX);
                add_arg_assign_checked(&fninfo, ARG_VGPR, ctx->f32,
                                       &ctx->abi.frag_pos[0], SI_PARAM_POS_X_FLOAT);
index 21de12a043f5662dbc4a51a6e26acf8d70221a9e..eeb27b66873d61ddc8179bd16e007e2298df02de 100644 (file)
@@ -1088,7 +1088,6 @@ si_nir_lookup_interp_param(struct ac_shader_abi *abi,
                           enum glsl_interp_mode interp, unsigned location)
 {
        struct si_shader_context *ctx = si_shader_context_from_abi(abi);
-       int interp_param_idx = -1;
 
        switch (interp) {
        case INTERP_MODE_FLAT:
@@ -1096,27 +1095,24 @@ si_nir_lookup_interp_param(struct ac_shader_abi *abi,
        case INTERP_MODE_SMOOTH:
        case INTERP_MODE_NONE:
                if (location == INTERP_CENTER)
-                       interp_param_idx = SI_PARAM_PERSP_CENTER;
+                       return ctx->abi.persp_center;
                else if (location == INTERP_CENTROID)
-                       interp_param_idx = SI_PARAM_PERSP_CENTROID;
+                       return ctx->abi.persp_centroid;
                else if (location == INTERP_SAMPLE)
-                       interp_param_idx = SI_PARAM_PERSP_SAMPLE;
+                       return ctx->abi.persp_sample;
                break;
        case INTERP_MODE_NOPERSPECTIVE:
                if (location == INTERP_CENTER)
-                       interp_param_idx = SI_PARAM_LINEAR_CENTER;
+                       return ctx->abi.linear_center;
                else if (location == INTERP_CENTROID)
-                       interp_param_idx = SI_PARAM_LINEAR_CENTROID;
+                       return ctx->abi.linear_centroid;
                else if (location == INTERP_SAMPLE)
-                       interp_param_idx = SI_PARAM_LINEAR_SAMPLE;
+                       return ctx->abi.linear_sample;
                break;
        default:
                assert(!"Unhandled interpolation mode.");
-               return NULL;
        }
-
-       return interp_param_idx != -1 ?
-               LLVMGetParam(ctx->main_fn, interp_param_idx) : NULL;
+       return NULL;
 }
 
 static LLVMValueRef