radeonsi: simplify gl_FragCoord behavior
authorMarek Olšák <marek.olsak@amd.com>
Thu, 7 Jan 2016 19:00:34 +0000 (20:00 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 13 Jan 2016 11:27:28 +0000 (12:27 +0100)
It will become a system value, not an input.

Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
src/gallium/drivers/radeonsi/si_state_shaders.c

index 64adf699604353e53fc280f9837107c03db9e82e..460dda51b97a2c15548ab036dccf4296f88bd81e 100644 (file)
@@ -399,30 +399,29 @@ static void si_shader_ps(struct si_shader *shader)
        if (!pm4)
                return;
 
-       for (i = 0; i < info->num_inputs; i++) {
-               switch (info->input_semantic_name[i]) {
-               case TGSI_SEMANTIC_POSITION:
-                       /* SPI_BARYC_CNTL.POS_FLOAT_LOCATION
-                        * Possible vaules:
-                        * 0 -> Position = pixel center (default)
-                        * 1 -> Position = pixel centroid
-                        * 2 -> Position = at sample position
-                        */
-                       switch (info->input_interpolate_loc[i]) {
-                       case TGSI_INTERPOLATE_LOC_CENTROID:
-                               spi_baryc_cntl |= S_0286E0_POS_FLOAT_LOCATION(1);
-                               break;
-                       case TGSI_INTERPOLATE_LOC_SAMPLE:
-                               spi_baryc_cntl |= S_0286E0_POS_FLOAT_LOCATION(2);
-                               break;
-                       }
+       /* SPI_BARYC_CNTL.POS_FLOAT_LOCATION
+        * Possible vaules:
+        * 0 -> Position = pixel center
+        * 1 -> Position = pixel centroid
+        * 2 -> Position = at sample position
+        *
+        * From GLSL 4.5 specification, section 7.1:
+        *   "The variable gl_FragCoord is available as an input variable from
+        *    within fragment shaders and it holds the window relative coordinates
+        *    (x, y, z, 1/w) values for the fragment. If multi-sampling, this
+        *    value can be for any location within the pixel, or one of the
+        *    fragment samples. The use of centroid does not further restrict
+        *    this value to be inside the current primitive."
+        *
+        * Meaning that centroid has no effect and we can return anything within
+        * the pixel. Thus, return the value at sample position, because that's
+        * the most accurate one shaders can get.
+        */
+       spi_baryc_cntl |= S_0286E0_POS_FLOAT_LOCATION(2);
 
-                       if (info->properties[TGSI_PROPERTY_FS_COORD_PIXEL_CENTER] ==
-                           TGSI_FS_COORD_PIXEL_CENTER_INTEGER)
-                               spi_baryc_cntl |= S_0286E0_POS_FLOAT_ULC(1);
-                       break;
-               }
-       }
+       if (info->properties[TGSI_PROPERTY_FS_COORD_PIXEL_CENTER] ==
+           TGSI_FS_COORD_PIXEL_CENTER_INTEGER)
+               spi_baryc_cntl |= S_0286E0_POS_FLOAT_ULC(1);
 
        /* Find out what SPI_SHADER_COL_FORMAT and CB_SHADER_MASK should be. */
        colors_written = info->colors_written;