gallium: add support for programmable sample locations
authorRhys Perry <pendingchaos02@gmail.com>
Fri, 15 Jun 2018 01:56:28 +0000 (19:56 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 15 Jun 2018 02:09:45 +0000 (20:09 -0600)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com> (v2)
Reviewed-by: Marek Olšák <marek.olsak@amd.com> (v2)
24 files changed:
src/gallium/auxiliary/util/u_framebuffer.c
src/gallium/auxiliary/util/u_framebuffer.h
src/gallium/docs/source/context.rst
src/gallium/docs/source/screen.rst
src/gallium/drivers/etnaviv/etnaviv_screen.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/i915/i915_screen.c
src/gallium/drivers/llvmpipe/lp_screen.c
src/gallium/drivers/nouveau/nv30/nv30_screen.c
src/gallium/drivers/nouveau/nv50/nv50_screen.c
src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/radeonsi/si_get.c
src/gallium/drivers/softpipe/sp_screen.c
src/gallium/drivers/svga/svga_screen.c
src/gallium/drivers/swr/swr_screen.cpp
src/gallium/drivers/v3d/v3d_screen.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/virgl/virgl_screen.c
src/gallium/include/pipe/p_context.h
src/gallium/include/pipe/p_defines.h
src/gallium/include/pipe/p_screen.h
src/gallium/include/pipe/p_state.h

index c2948a5cfb30b9dd57f1c830fae0308dc6d16cfe..5bafddc726fb73d86bb68467dda9f28a2545ea80 100644 (file)
@@ -240,3 +240,33 @@ util_framebuffer_get_num_samples(const struct pipe_framebuffer_state *fb)
 
    return 1;
 }
+
+
+/**
+ * Flip the sample location state along the Y axis.
+ */
+void
+util_sample_locations_flip_y(struct pipe_screen *screen, unsigned fb_height,
+                             unsigned samples, uint8_t *locations)
+{
+   unsigned row, i, shift, grid_width, grid_height;
+   uint8_t new_locations[
+      PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE *
+      PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE * 32];
+
+   screen->get_sample_pixel_grid(screen, samples, &grid_width, &grid_height);
+
+   shift = fb_height % grid_height;
+
+   for (row = 0; row < grid_height; row++) {
+      unsigned row_size = grid_width * samples;
+      for (i = 0; i < row_size; i++) {
+         unsigned dest_row = grid_height - row - 1;
+         /* this relies on unsigned integer wraparound behaviour */
+         dest_row = (dest_row - shift) % grid_height;
+         new_locations[dest_row * row_size + i] = locations[row * row_size + i];
+      }
+   }
+
+   memcpy(locations, new_locations, grid_width * grid_height * samples);
+}
index c73942c9c142b8c14656512f8fa8186b8202c080..877e6e393f79243fe9ba3f00066613f734442f4f 100644 (file)
@@ -64,6 +64,11 @@ extern unsigned
 util_framebuffer_get_num_samples(const struct pipe_framebuffer_state *fb);
 
 
+extern void
+util_sample_locations_flip_y(struct pipe_screen *screen, unsigned fb_height,
+                             unsigned samples, uint8_t *locations);
+
+
 #ifdef __cplusplus
 }
 #endif
index e8e80dcbc391b53b4d6c646ba00ce869b64cb9d0..20d0df793127e5a9a9c586ce62434fa0b74a910a 100644 (file)
@@ -68,6 +68,9 @@ objects. They all follow simple, one-method binding calls, e.g.
   that this takes effect even if multisampling is not explicitly enabled if
   the frambuffer surface(s) are multisampled.  Also, this mask is AND-ed
   with the optional fragment shader sample mask output (when emitted).
+* ``set_sample_locations`` sets the sample locations used for rasterization.
+  ```get_sample_position``` still returns the default locations. When NULL,
+  the default locations are used.
 * ``set_min_samples`` sets the minimum number of samples that must be run.
 * ``set_clip_state``
 * ``set_polygon_stipple``
@@ -270,6 +273,17 @@ format.
 multi-byte element value starting at offset bytes from resource start, going
 for size bytes. It is guaranteed that size % clear_value_size == 0.
 
+Evaluating Depth Buffers
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+``evaluate_depth_buffer`` is a hint to decompress the current depth buffer
+assuming the current sample locations to avoid problems that could arise when
+using programmable sample locations.
+
+If a depth buffer is rendered with different sample location state than
+what is current at the time of reading the depth buffer, the values may differ
+because depth buffer compression can depend the sample locations.
+
 
 Uploading
 ^^^^^^^^^
index 0f18b7a94b91634c88865ef1026364d3ed49779f..a41c421ec47fec3d8afe424f3725ef1d4fd72a2c 100644 (file)
@@ -438,6 +438,9 @@ PIPE_CONSERVATIVE_RASTER_PRE_SNAP mode is supported for points and lines.
 works with conservative rasterization.
 * ``PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS``: The maximum
 subpixel precision bias in bits during conservative rasterization.
+* ``PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS``: True is the driver supports
+  programmable sample location through ```get_sample_pixel_grid``` and
+  ```set_sample_locations```.
 
 
 .. _pipe_capf:
index e031807117c0afd4dbad988fb44af7652fc6b0ef..36b86e5f36d28cbe117412a757e717c408587674 100644 (file)
@@ -281,6 +281,7 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
    case PIPE_CAP_PACKED_UNIFORMS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
 
    /* Stream output. */
index a414cb6d60ef9f659dea6ed348682b99245cdc78..93f3214c3c2f64c7e219694510f6ce7a7ae7de8f 100644 (file)
@@ -347,6 +347,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
        case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
        case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
        case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+       case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
                return 0;
 
        case PIPE_CAP_CONTEXT_PRIORITY_MASK:
index b08d2283e7ebb707d4aec5a50cc32f4d6187c5ac..d917048e2b9b74b7f59b5afac99062c8a405ea80 100644 (file)
@@ -333,6 +333,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
    case PIPE_CAP_FENCE_SIGNAL:
    case PIPE_CAP_CONSTBUF0_FLAGS:
    case PIPE_CAP_PACKED_UNIFORMS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
 
    case PIPE_CAP_MAX_VIEWPORTS:
index f12ad09298daeb1d16516007d07df07d65976627..28dbd9908f9e765995d3586d8c9a603ca9aaa328 100644 (file)
@@ -370,6 +370,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
    }
    /* should only get here on unhandled cases */
index a77f70e6bb4d2e437efddd3a44bb6edac6b2ad16..470625ba54239e125f94b468a69803f850a65910 100644 (file)
@@ -236,6 +236,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 2495a545fde81287becf40ef135724ceb2a00aec..bdb2a8e31c7d96361f4c1c45494057af655eb850 100644 (file)
@@ -289,6 +289,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index f679cbdba3e3a29508d7b629ec7bb6ddefeb373c..8e9ede0736ac841eb20d7b5e43995e0d3e903a33 100644 (file)
@@ -319,6 +319,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_CONSTBUF0_FLAGS:
    case PIPE_CAP_PACKED_UNIFORMS:
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 459349e821cd372cf3a6712ac842a9fb3de7b16f..793b0ba8d89105ef5fe6972c96db95dacfcf3683 100644 (file)
@@ -258,6 +258,7 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
         case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
         case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
         case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+        case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
             return 0;
 
         /* SWTCL-only features. */
index ff7306998bbd2aa33660abba4a558d9d1a0e822d..12960ed5373bd0ecc0ae40f05efe6528fc0d4c90 100644 (file)
@@ -428,6 +428,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
        case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
        case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
        case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+       case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
                return 0;
 
        case PIPE_CAP_DOUBLES:
index 154fabebdcce872f64f49e7e384d57ea06e28370..de05e8e7e6f436c1e6f7fda3bcfa103ad050d707 100644 (file)
@@ -257,6 +257,7 @@ static int si_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
        case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
        case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
        case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+       case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
                return 0;
 
        case PIPE_CAP_FENCE_SIGNAL:
index f9c916d9382ca070e37c893bf1d68088f1744fd9..8fbcbc8bac2d4d863f0abf92a6bb7d844483380c 100644 (file)
@@ -322,6 +322,7 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
    case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
       return 4;
index 2744f3100ebca8a9c8515a63038b0574b2dcc470..9e3e3e26a3c10bf0ad335e7b927e2314fadfc46f 100644 (file)
@@ -468,6 +468,7 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_FENCE_SIGNAL:
    case PIPE_CAP_CONSTBUF0_FLAGS:
    case PIPE_CAP_PACKED_UNIFORMS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
    }
 
index 091d322d38cd775360b74c49e184cc8ce380e397..65fa1bc50e62de690067cbcdb89d6b565f25f935 100644 (file)
@@ -355,6 +355,7 @@ swr_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 80b8156a73e8aef436463222fa016af7d44d2daf..cd84e61f2770c097eae94a66d52dab3a646bc209 100644 (file)
@@ -269,6 +269,7 @@ v3d_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
         case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
         case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
         case PIPE_CAP_PACKED_UNIFORMS:
+        case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
                 return 0;
 
                 /* Geometry shader output, unsupported. */
index 6415d95746b6901c00c02cbb822e8d3114bb7415..286263bf001f6d0abd123c4c8b9c18ede123f067 100644 (file)
@@ -298,6 +298,7 @@ vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
         case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
         case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
         case PIPE_CAP_PACKED_UNIFORMS:
+        case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
                 return 0;
 
                 /* Stream output. */
index f21526a60bd2cc77555eada3bad7f15e135c9d02..fa02907392c16b0304711dffb553371a03785cc2 100644 (file)
@@ -293,6 +293,7 @@ virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
    case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
    case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
       return 0;
    case PIPE_CAP_VENDOR_ID:
       return 0x1af4;
index c3dc5edf57d15e5d5ad2eddeea31835fa776bd43..7cf037f1abdc2f74c1a3af2666fd6053994cd4f3 100644 (file)
@@ -279,8 +279,35 @@ struct pipe_context {
    void (*set_framebuffer_state)( struct pipe_context *,
                                   const struct pipe_framebuffer_state * );
 
+   /**
+    * Set the sample locations used during rasterization. When NULL or sized
+    * zero, the default locations are used.
+    *
+    * Note that get_sample_position() still returns the default locations.
+    *
+    * The samples are accessed with
+    * locations[(pixel_y*grid_w+pixel_x)*ms+i],
+    * where:
+    * ms      = the sample count
+    * grid_w  = the pixel grid width for the sample count
+    * grid_w  = the pixel grid height for the sample count
+    * pixel_x = the window x coordinate modulo grid_w
+    * pixel_y = the window y coordinate modulo grid_w
+    * i       = the sample index
+    * This gives a result with the x coordinate as the low 4 bits and the y
+    * coordinate as the high 4 bits. For each coordinate 0 is the left or top
+    * edge of the pixel's rectangle and 16 (not 15) is the right or bottom edge.
+    *
+    * Out of bounds accesses are return undefined values.
+    *
+    * The pixel grid is used to vary sample locations across pixels and its
+    * size can be queried with get_sample_pixel_grid().
+    */
+   void (*set_sample_locations)( struct pipe_context *,
+                                 size_t size, const uint8_t *locations );
+
    void (*set_polygon_stipple)( struct pipe_context *,
-                               const struct pipe_poly_stipple * );
+                                const struct pipe_poly_stipple * );
 
    void (*set_scissor_states)( struct pipe_context *,
                                unsigned start_slot,
@@ -484,6 +511,16 @@ struct pipe_context {
                         const void *clear_value,
                         int clear_value_size);
 
+   /**
+    * If a depth buffer is rendered with different sample location state than
+    * what is current at the time of reading, the values may differ because
+    * depth buffer compression can depend the sample locations.
+    *
+    * This function is a hint to decompress the current depth buffer to avoid
+    * such problems.
+    */
+   void (*evaluate_depth_buffer)(struct pipe_context *pipe);
+
    /**
     * Flush draw commands.
     *
@@ -720,7 +757,7 @@ struct pipe_context {
    /*@}*/
 
    /**
-    * Get sample position for an individual sample point.
+    * Get the default sample position for an individual sample point.
     *
     * \param sample_count - total number of samples
     * \param sample_index - sample to get the position values for
index 6cc73a31bfc4fb04dcd18a100271382c5c2883e6..43db9f8fbaaa4efeb6df30a0914a1435f1f6ae53 100644 (file)
@@ -813,6 +813,7 @@ enum pipe_cap
    PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES,
    PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS,
    PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE,
+   PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS,
 };
 
 /**
index 8fd81a4e9a9695f481b6788c975a870dd0713a4e..0439060b60623a2bb957bad0b5f631060492905a 100644 (file)
@@ -131,6 +131,17 @@ struct pipe_screen {
                            enum pipe_compute_cap param,
                            void *ret);
 
+   /**
+    * Get the sample pixel grid's size. This function requires
+    * PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS to be callable.
+    *
+    * \param sample_count - total number of samples
+    * \param out_width - the width of the pixel grid
+    * \param out_height - the height of the pixel grid
+    */
+   void (*get_sample_pixel_grid)(struct pipe_screen *, unsigned sample_count,
+                                 unsigned *out_width, unsigned *out_height);
+
    /**
     * Query a timestamp in nanoseconds. The returned value should match
     * PIPE_QUERY_TIMESTAMP. This function returns immediately and doesn't
index db9fa1a8e9f6954bcb9ea6ee1cb82e3bea053831..809aa087ce0087fe0d38d24c3840862ce3c77fac 100644 (file)
@@ -74,6 +74,7 @@ extern "C" {
 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
 #define PIPE_MAX_WINDOW_RECTANGLES 8
+#define PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE 4
 
 #define PIPE_MAX_HW_ATOMIC_BUFFERS 32