radeonsi: Handle position input parameter for pixel shaders v2
authorTom Stellard <thomas.stellard@amd.com>
Thu, 6 Sep 2012 20:18:11 +0000 (16:18 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Tue, 11 Sep 2012 18:53:47 +0000 (14:53 -0400)
v2:
  - Don't increment ninterp or set any of the have_* flags for
    TGSI_SEMANTIC_POSITION

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeon/SIInstructions.td
src/gallium/drivers/radeon/SIIntrinsics.td
src/gallium/drivers/radeonsi/radeonsi_shader.c
src/gallium/drivers/radeonsi/si_state_draw.c

index 8f9de5253405f6b7ac106112356af7dfeae48683..ffc9537ea709b1f08605baf2341a1f236cf6a901 100644 (file)
@@ -1102,6 +1102,26 @@ def : Pat <
              imm:$attr, SReg_32:$params)
 >;
 
+def : Pat <
+  (int_SI_fs_read_pos 0),
+  (f32 POS_X_FLOAT)
+>;
+
+def : Pat <
+  (int_SI_fs_read_pos 1),
+  (f32 POS_Y_FLOAT)
+>;
+
+def : Pat <
+  (int_SI_fs_read_pos 2),
+  (f32 POS_Z_FLOAT)
+>;
+
+def : Pat <
+  (int_SI_fs_read_pos 3),
+  (f32 POS_W_FLOAT)
+>;
+
 /********** ================== **********/
 /********** Intrinsic Patterns **********/
 /********** ================== **********/
index fbb8dc90fbe0690070a4b5b155d46025ae8cf71a..f5c3f76fe279d4cae83a6f0f95a4513467593ee0 100644 (file)
@@ -34,4 +34,6 @@ let TargetPrefix = "SI", isTarget = 1 in {
   def int_SI_fs_interp_persp_center : Interp;
   def int_SI_fs_interp_persp_centroid : Interp;
   def int_SI_fs_interp_constant : Interp;
+
+  def int_SI_fs_read_pos : Intrinsic <[llvm_float_ty], [llvm_i32_ty], [IntrNoMem]>;
 }
index 0994fac6f219336a01e2b34599b20b08e42f53a9..466d5658d5ace3e22835b5cff4773161d319c408 100644 (file)
@@ -261,6 +261,7 @@ static void declare_input_fs(
        struct lp_build_context * base =
                                &si_shader_ctx->radeon_bld.soa.bld_base.base;
        struct gallivm_state * gallivm = base->gallivm;
+       LLVMTypeRef input_type = LLVMFloatTypeInContext(gallivm->context);
 
        /* This value is:
         * [15:0] NewPrimMask (Bit mask for each quad.  It is set it the
@@ -278,6 +279,20 @@ static void declare_input_fs(
        /* XXX: Is this the input_index? */
        LLVMValueRef attr_number = lp_build_const_int32(gallivm, input_index);
 
+       if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) {
+               for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) {
+                       LLVMValueRef args[1];
+                       unsigned soa_index =
+                               radeon_llvm_reg_index_soa(input_index, chan);
+                       args[0] = lp_build_const_int32(gallivm, chan);
+                       si_shader_ctx->radeon_bld.inputs[soa_index] =
+                               build_intrinsic(base->gallivm->builder,
+                                       "llvm.SI.fs.read.pos", input_type,
+                                       args, 1, LLVMReadNoneAttribute);
+               }
+               return;
+       }
+
        /* XXX: Handle all possible interpolation modes */
        switch (decl->Interp.Interpolate) {
        case TGSI_INTERPOLATE_COLOR:
@@ -332,7 +347,6 @@ static void declare_input_fs(
                LLVMValueRef args[3];
                LLVMValueRef llvm_chan = lp_build_const_int32(gallivm, chan);
                unsigned soa_index = radeon_llvm_reg_index_soa(input_index, chan);
-               LLVMTypeRef input_type = LLVMFloatTypeInContext(gallivm->context);
                args[0] = llvm_chan;
                args[1] = attr_number;
                args[2] = params;
index 8b43f5a8f7d47a2b32fe52e147b7f6755761d197..c71ad43db24849bcf1ce1b545efa3f4f8e91a5fb 100644 (file)
@@ -103,6 +103,7 @@ static void si_pipe_shader_ps(struct pipe_context *ctx, struct si_pipe_shader *s
        unsigned num_sgprs, num_user_sgprs;
        int ninterp = 0;
        boolean have_linear = FALSE, have_centroid = FALSE, have_perspective = FALSE;
+       unsigned fragcoord_interp_mode = 0;
        unsigned spi_baryc_cntl, spi_ps_input_ena;
        uint64_t va;
 
@@ -116,6 +117,20 @@ static void si_pipe_shader_ps(struct pipe_context *ctx, struct si_pipe_shader *s
 
        db_shader_control = S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z);
        for (i = 0; i < shader->shader.ninput; i++) {
+               if (shader->shader.input[i].name == TGSI_SEMANTIC_POSITION) {
+                       if (shader->shader.input[i].centroid) {
+                               /* fragcoord_interp_mode will be written to
+                                * SPI_BARYC_CNTL.POS_FLOAT_LOCATION
+                                * Possible vaules:
+                                * 0 -> Position = pixel center (default)
+                                * 1 -> Position = pixel centroid
+                                * 2 -> Position = iterated sample number XXX:
+                                *                        What does this mean?
+                                */
+                               fragcoord_interp_mode = 1;
+                       }
+                       continue;
+               }
                ninterp++;
                /* XXX: Flat shading hangs the GPU */
                if (shader->shader.input[i].interpolate == TGSI_INTERPOLATE_CONSTANT ||
@@ -166,6 +181,7 @@ static void si_pipe_shader_ps(struct pipe_context *ctx, struct si_pipe_shader *s
        if (have_linear)
                spi_baryc_cntl |= have_centroid ?
                        S_0286E0_LINEAR_CENTROID_CNTL(1) : S_0286E0_LINEAR_CENTER_CNTL(1);
+       spi_baryc_cntl |= S_0286E0_POS_FLOAT_LOCATION(fragcoord_interp_mode);
 
        si_pm4_set_reg(pm4, R_0286E0_SPI_BARYC_CNTL, spi_baryc_cntl);
        spi_ps_input_ena = shader->spi_ps_input_ena;