[Mesa-dev] [PATCH 11/12] meta: Support 16x MSAA in the multisample scaled blit shader

Ian Romanick idr at freedesktop.org
Tue Sep 22 15:07:05 PDT 2015


On 09/17/2015 09:00 AM, Neil Roberts wrote:
> I'm not too sure about the expression used to index into sample_map in
> the shader. It looks like if fract(coord.x) and fract(coord.y) are
> close to 1.0 then it would index outside of the array. However the
> code for 4 and 8 has the same problem and the results seems to look
> reasonable. It might make more sense to change it to something like
> this:
> 
>  sample_map[int(4 * fract(coord.x)) + 4 * int(fract(coord.y) * 4)]

Yeah... Jason also noticed some strange things in this area.  I've got a
patch out
(http://lists.freedesktop.org/archives/mesa-dev/2015-September/095026.html)
that also fixes a bug here.  I'm going to dig a bit deeper if you want
to leave it as-is for now.

This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>  src/mesa/drivers/common/meta.h                     |  2 ++
>  src/mesa/drivers/common/meta_blit.c                |  8 ++++++--
>  src/mesa/drivers/dri/i965/gen6_multisample_state.c | 14 ++++++++++++++
>  src/mesa/main/mtypes.h                             | 15 ++++++++++++++-
>  4 files changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
> index fe43915..e42ddc8 100644
> --- a/src/mesa/drivers/common/meta.h
> +++ b/src/mesa/drivers/common/meta.h
> @@ -285,9 +285,11 @@ enum blit_msaa_shader {
>     BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE,
>     BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE,
>     BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE,
> +   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE,
>     BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE,
>     BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE,
>     BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE,
> +   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE,
>     BLIT_MSAA_SHADER_COUNT,
>  };
>  
> diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c
> index a41fe42..b545c37 100644
> --- a/src/mesa/drivers/common/meta_blit.c
> +++ b/src/mesa/drivers/common/meta_blit.c
> @@ -86,8 +86,8 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx,
>     while (samples >> (shader_offset + 1)) {
>        shader_offset++;
>     }
> -   /* Update the assert if we plan to support more than 8X MSAA. */
> -   assert(shader_offset > 0 && shader_offset < 4);
> +   /* Update the assert if we plan to support more than 16X MSAA. */
> +   assert(shader_offset > 0 && shader_offset <= 4);
>  
>     assert(target == GL_TEXTURE_2D_MULTISAMPLE ||
>            target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY);
> @@ -132,6 +132,10 @@ setup_glsl_msaa_blit_scaled_shader(struct gl_context *ctx,
>        sample_number =  "sample_map[int(2 * fract(coord.x) + 8 * fract(coord.y))]";
>        sample_map = ctx->Const.SampleMap8x;
>        break;
> +   case 16:
> +      sample_number =  "sample_map[int(4 * fract(coord.x) + 16 * fract(coord.y))]";
> +      sample_map = ctx->Const.SampleMap16x;
> +      break;
>     default:
>        sample_number = NULL;
>        sample_map = NULL;
> diff --git a/src/mesa/drivers/dri/i965/gen6_multisample_state.c b/src/mesa/drivers/dri/i965/gen6_multisample_state.c
> index 49c6eba..8eb620d 100644
> --- a/src/mesa/drivers/dri/i965/gen6_multisample_state.c
> +++ b/src/mesa/drivers/dri/i965/gen6_multisample_state.c
> @@ -91,6 +91,17 @@ gen6_get_sample_position(struct gl_context *ctx,
>   *           | 6 | 7 |                      | 7 | 1 |
>   *           ---------                      ---------
>   *
> + * 16X MSAA sample index layout  16x MSAA sample number layout
> + *         -----------------            -----------------
> + *         | 0 | 1 | 2 | 3 |            |15 |10 | 9 | 7 |
> + *         -----------------            -----------------
> + *         | 4 | 5 | 6 | 7 |            | 4 | 1 | 3 |13 |
> + *         -----------------            -----------------
> + *         | 8 | 9 |10 |11 |            |12 | 2 | 0 | 6 |
> + *         -----------------            -----------------
> + *         |12 |13 |14 |15 |            |11 | 8 | 5 |14 |
> + *         -----------------            -----------------
> + *
>   * A sample map is used to map sample indices to sample numbers.
>   */
>  void
> @@ -99,10 +110,13 @@ gen6_set_sample_maps(struct gl_context *ctx)
>     uint8_t map_2x[2] = {0, 1};
>     uint8_t map_4x[4] = {0, 1, 2, 3};
>     uint8_t map_8x[8] = {5, 2, 4, 6, 0, 3, 7, 1};
> +   uint8_t map_16x[16] = { 15, 10, 9, 7, 4, 1, 3, 13,
> +                           12, 2, 0, 6, 11, 8, 5, 14 };
>  
>     memcpy(ctx->Const.SampleMap2x, map_2x, sizeof(map_2x));
>     memcpy(ctx->Const.SampleMap4x, map_4x, sizeof(map_4x));
>     memcpy(ctx->Const.SampleMap8x, map_8x, sizeof(map_8x));
> +   memcpy(ctx->Const.SampleMap16x, map_16x, sizeof(map_16x));
>  }
>  
>  /**
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index fac45aa..e0a06f4 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -3550,11 +3550,24 @@ struct gl_constants
>      * below:
>      *    SampleMap8x = {a, b, c, d, e, f, g, h};
>      *
> -    * Follow the logic for other sample counts.
> +    * Follow the logic for sample counts 2-8.
> +    *
> +    * For 16x the sample indices layout as a 4x4 grid as follows:
> +    *
> +    *            -----------------
> +    *            | 0 | 1 | 2 | 3 |
> +    *            -----------------
> +    *            | 4 | 5 | 6 | 7 |
> +    *            -----------------
> +    *            | 8 | 9 |10 |11 |
> +    *            -----------------
> +    *            |12 |13 |14 |15 |
> +    *            -----------------
>      */
>     uint8_t SampleMap2x[2];
>     uint8_t SampleMap4x[4];
>     uint8_t SampleMap8x[8];
> +   uint8_t SampleMap16x[16];
>  
>     /** GL_ARB_shader_atomic_counters */
>     GLuint MaxAtomicBufferBindings;
> 



More information about the mesa-dev mailing list