meta: Store precompiled msaa shaders for all supported sample counts
authorAnuj Phogat <anuj.phogat@gmail.com>
Sat, 23 Aug 2014 00:12:28 +0000 (17:12 -0700)
committerAnuj Phogat <anuj.phogat@gmail.com>
Fri, 5 Sep 2014 22:40:37 +0000 (15:40 -0700)
Currently, BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE* and
BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE* shaders
in setup_glsl_msaa_blit_shader() are not recompiled
when the source buffer sample count changes. For example,
implementation continued using a 4X msaa shader, even if
source buffer changes from 4X msaa to 8x msaa. It causes
incorrect rendering.

This patch adds new enums in blit_msaa_shader, one for
each supported sample count, and uses them to store
msaa shaders.

Fixes following piglit tests on Broadwell:
ext_framebuffer_multisample-accuracy all_samples color
ext_framebuffer_multisample-accuracy all_samples depth_draw
ext_framebuffer_multisample-accuracy all_samples depth_resolve
ext_framebuffer_multisample-accuracy all_samples stencil_draw
ext_framebuffer_multisample-accuracy all_samples stencil_resolve
ext_framebuffer_multisample-formats all_samples

Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstarnd <jason@jlekstrand.net>
src/mesa/drivers/common/meta.h
src/mesa/drivers/common/meta_blit.c

index 56ba9bc659893625a9d5a6fafd9a63b81bed611d..edc3e8c2090c685a9aefa79e4563ef19dec823ba 100644 (file)
@@ -235,21 +235,45 @@ struct blit_shader_table {
 /**
  * Indices in the blit_state->msaa_shaders[] array
  *
- * Note that setup_glsl_msaa_blit_shader() assumes that the _INT enums are one
- * more than the non-_INT version and _UINT is one beyond that.
+ * Note that setup_glsl_msaa_blit_shader() assumes that the _INT enums are five
+ * more than the corresponding non-_INT versions and _UINT are five beyond that.
  */
 enum blit_msaa_shader {
-   BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
-   BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
-   BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
+   BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
+   BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
+   BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
+   BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
+   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE,
+   BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
+   BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
+   BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
+   BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
+   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT,
+   BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
+   BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
+   BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
+   BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
+   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_INT,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_UINT,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_RESOLVE,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_COPY,
-   BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
-   BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
-   BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
+   BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
+   BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
+   BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
+   BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
+   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE,
+   BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
+   BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
+   BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
+   BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
+   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT,
+   BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
+   BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
+   BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
+   BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
+   BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_INT,
    BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_UINT,
index 955e73f57ca001df354ce887ec267c306a6bf252..fc9848a7acd4398491e8da2cdd943aff8c61fdaa 100644 (file)
@@ -70,6 +70,16 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
    const char *sampler_array_suffix = "";
    char *name;
    const char *texcoord_type = "vec2";
+   const int samples = MAX2(src_rb->NumSamples, 1);
+   int shader_offset = 0;
+
+   /* We expect only power of 2 samples in source multisample buffer. */
+   assert((samples & (samples - 1)) == 0);
+   while (samples >> (shader_offset + 1)) {
+      shader_offset++;
+   }
+   /* Update the assert if we plan to support more than 16X MSAA. */
+   assert(shader_offset >= 0 && shader_offset <= 4);
 
    if (src_rb) {
       src_datatype = _mesa_get_format_datatype(src_rb->Format);
@@ -107,13 +117,15 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
       } else {
          if (dst_is_msaa)
             shader_index = BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY;
-         else
-            shader_index = BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE;
+         else {
+            shader_index = BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE +
+                           shader_offset;
+         }
       }
 
       if (target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
-         shader_index += (BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE -
-                          BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE);
+         shader_index += (BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE -
+                          BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE);
          sampler_array_suffix = "Array";
          texcoord_type = "vec3";
       }
@@ -121,19 +133,19 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
    default:
       _mesa_problem(ctx, "Unkown texture target %s\n",
                     _mesa_lookup_enum_by_nr(target));
-      shader_index = BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE;
+      shader_index = BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE;
    }
 
    /* We rely on the enum being sorted this way. */
-   STATIC_ASSERT(BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT ==
-                 BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE + 1);
-   STATIC_ASSERT(BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT ==
-                 BLIT_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE + 2);
+   STATIC_ASSERT(BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT ==
+                 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE + 5);
+   STATIC_ASSERT(BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT ==
+                 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE + 10);
    if (src_datatype == GL_INT) {
-      shader_index++;
+      shader_index += 5;
       vec4_prefix = "i";
    } else if (src_datatype == GL_UNSIGNED_INT) {
-      shader_index += 2;
+      shader_index += 10;
       vec4_prefix = "u";
    } else {
       vec4_prefix = "";
@@ -209,7 +221,6 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
       /* You can create 2D_MULTISAMPLE textures with 0 sample count (meaning 1
        * sample).  Yes, this is ridiculous.
        */
-      int samples;
       char *sample_resolve;
       const char *arb_sample_shading_extension_string;
       const char *merge_function;
@@ -217,8 +228,6 @@ setup_glsl_msaa_blit_shader(struct gl_context *ctx,
                              vec4_prefix,
                              dst_is_msaa ? "copy" : "resolve");
 
-      samples = MAX2(src_rb->NumSamples, 1);
-
       if (dst_is_msaa) {
          arb_sample_shading_extension_string = "#extension GL_ARB_sample_shading : enable";
          sample_resolve = ralloc_asprintf(mem_ctx, "   out_color = texelFetch(texSampler, i%s(texCoords), gl_SampleID);", texcoord_type);