st/mesa: expose & set limits for AMD_framebuffer_multisample_advanced
authorMarek Olšák <marek.olsak@amd.com>
Mon, 11 Jun 2018 22:54:26 +0000 (18:54 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 4 Aug 2018 06:47:58 +0000 (02:47 -0400)
Reviewed-by: Brian Paul <brianp@vmware.com>
docs/relnotes/18.3.0.html
src/mesa/state_tracker/st_extensions.c

index ea60d62b5cb2545e4be17c61c71a518059f161eb..786145ad8da1fbaa2808c5987be0bca46e9add95 100644 (file)
@@ -51,7 +51,7 @@ Note: some of the new features are only available with certain drivers.
 </p>
 
 <ul>
-<li>TBD</li>
+<li>GL_AMD_framebuffer_multisample_advanced on radeonsi.</li>
 </ul>
 
 <h2>Bug fixes</h2>
index dbaf7f6f8fe5bf7bccd114d8d9b595cf04fd756c..1c01495e9370453bbda8d598c0890277edd95d50 100644 (file)
@@ -600,6 +600,26 @@ get_max_samples_for_formats(struct pipe_screen *screen,
    return 0;
 }
 
+static unsigned
+get_max_samples_for_formats_advanced(struct pipe_screen *screen,
+                                     unsigned num_formats,
+                                     const enum pipe_format *formats,
+                                     unsigned max_samples,
+                                     unsigned num_storage_samples,
+                                     unsigned bind)
+{
+   unsigned i, f;
+
+   for (i = max_samples; i > 0; --i) {
+      for (f = 0; f < num_formats; f++) {
+         if (screen->is_format_supported(screen, formats[f], PIPE_TEXTURE_2D,
+                                         i, num_storage_samples, bind)) {
+            return i;
+         }
+      }
+   }
+   return 0;
+}
 
 /**
  * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
@@ -685,6 +705,7 @@ void st_init_extensions(struct pipe_screen *screen,
       { o(EXT_transform_feedback),           PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS        },
       { o(EXT_window_rectangles),            PIPE_CAP_MAX_WINDOW_RECTANGLES            },
 
+      { o(AMD_framebuffer_multisample_advanced), PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS },
       { o(AMD_pinned_memory),                PIPE_CAP_RESOURCE_FROM_USER_MEMORY        },
       { o(ATI_meminfo),                      PIPE_CAP_QUERY_MEMORY_INFO                },
       { o(AMD_seamless_cubemap_per_texture), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE    },
@@ -1102,6 +1123,74 @@ void st_init_extensions(struct pipe_screen *screen,
          get_max_samples_for_formats(screen, ARRAY_SIZE(void_formats),
                                      void_formats, 32,
                                      PIPE_BIND_RENDER_TARGET);
+
+      if (extensions->AMD_framebuffer_multisample_advanced) {
+         /* AMD_framebuffer_multisample_advanced */
+         /* This can be greater than storage samples. */
+         consts->MaxColorFramebufferSamples =
+            get_max_samples_for_formats_advanced(screen,
+                                                ARRAY_SIZE(color_formats),
+                                                color_formats, 16,
+                                                consts->MaxSamples,
+                                                PIPE_BIND_RENDER_TARGET);
+
+         /* If the driver supports N color samples, it means it supports
+          * N samples and N storage samples. N samples >= N storage
+          * samples.
+          */
+         consts->MaxColorFramebufferStorageSamples = consts->MaxSamples;
+         consts->MaxDepthStencilFramebufferSamples =
+            consts->MaxDepthTextureSamples;
+
+         assert(consts->MaxColorFramebufferSamples >=
+                consts->MaxDepthStencilFramebufferSamples);
+         assert(consts->MaxDepthStencilFramebufferSamples >=
+                consts->MaxColorFramebufferStorageSamples);
+
+         consts->NumSupportedMultisampleModes = 0;
+
+         unsigned depth_samples_supported = 0;
+
+         for (unsigned samples = 2;
+              samples <= consts->MaxDepthStencilFramebufferSamples;
+              samples++) {
+            if (screen->is_format_supported(screen, PIPE_FORMAT_Z32_FLOAT,
+                                            PIPE_TEXTURE_2D, samples, samples,
+                                            PIPE_BIND_DEPTH_STENCIL))
+               depth_samples_supported |= 1 << samples;
+         }
+
+         for (unsigned samples = 2;
+              samples <= consts->MaxColorFramebufferSamples;
+              samples++) {
+            for (unsigned depth_samples = 2;
+                 depth_samples <= samples; depth_samples++) {
+               if (!(depth_samples_supported & (1 << depth_samples)))
+                  continue;
+
+               for (unsigned storage_samples = 2;
+                    storage_samples <= depth_samples; storage_samples++) {
+                  if (screen->is_format_supported(screen,
+                                                  PIPE_FORMAT_R8G8B8A8_UNORM,
+                                                  PIPE_TEXTURE_2D,
+                                                  samples,
+                                                  storage_samples,
+                                                  PIPE_BIND_RENDER_TARGET)) {
+                     unsigned i = consts->NumSupportedMultisampleModes;
+
+                     assert(i < ARRAY_SIZE(consts->SupportedMultisampleModes));
+                     consts->SupportedMultisampleModes[i].NumColorSamples =
+                        samples;
+                     consts->SupportedMultisampleModes[i].NumColorStorageSamples =
+                        storage_samples;
+                     consts->SupportedMultisampleModes[i].NumDepthStencilSamples =
+                        depth_samples;
+                     consts->NumSupportedMultisampleModes++;
+                  }
+               }
+            }
+         }
+      }
    }
 
    if (consts->MaxSamples >= 2) {