[Mesa-dev] [PATCH 7/8] st/mesa: add renderbuffer support for AMD_framebuffer_multisample_advanced

Marek Olšák maraeo at gmail.com
Wed Aug 1 23:26:03 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_cb_fbo.c | 61 ++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 8 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 811451656ca..0e535257cb4 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -152,36 +152,80 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
     *   different sample counts for multisampled rendering, the actual
     *   number of samples allocated for the renderbuffer image is
     *   implementation dependent.  However, the resulting value for
     *   RENDERBUFFER_SAMPLES is guaranteed to be greater than or equal
     *   to <samples> and no more than the next larger sample count supported
     *   by the implementation.
     *
     * Find the supported number of samples >= rb->NumSamples
     */
    if (rb->NumSamples > 0) {
-      unsigned start, i;
+      unsigned start, start_storage;
 
       if (ctx->Const.MaxSamples > 1 &&  rb->NumSamples == 1) {
          /* don't try num_samples = 1 with drivers that support real msaa */
          start = 2;
+         start_storage = 2;
       } else {
          start = rb->NumSamples;
+         start_storage = rb->NumStorageSamples;
       }
 
-      for (i = start; i <= ctx->Const.MaxSamples; i++) {
-         format = st_choose_renderbuffer_format(st, internalFormat, i, i);
-
-         if (format != PIPE_FORMAT_NONE) {
-            rb->NumSamples = i;
-            rb->NumStorageSamples = i;
-            break;
+      if (ctx->Extensions.AMD_framebuffer_multisample_advanced) {
+         if (rb->_BaseFormat == GL_DEPTH_COMPONENT ||
+             rb->_BaseFormat == GL_DEPTH_STENCIL ||
+             rb->_BaseFormat == GL_STENCIL_INDEX) {
+            /* Find a supported depth-stencil format. */
+            for (unsigned samples = start;
+                 samples <= ctx->Const.MaxDepthStencilFramebufferSamples;
+                 samples++) {
+               format = st_choose_renderbuffer_format(st, internalFormat,
+                                                      samples, samples);
+
+               if (format != PIPE_FORMAT_NONE) {
+                  rb->NumSamples = samples;
+                  rb->NumStorageSamples = samples;
+                  break;
+               }
+            }
+         } else {
+            /* Find a supported color format, samples >= storage_samples. */
+            for (unsigned storage_samples = start_storage;
+                 storage_samples <= ctx->Const.MaxColorFramebufferStorageSamples;
+                 storage_samples++) {
+               for (unsigned samples = MAX2(start, storage_samples);
+                    samples <= ctx->Const.MaxColorFramebufferSamples;
+                    samples++) {
+                  format = st_choose_renderbuffer_format(st, internalFormat,
+                                                         samples,
+                                                         storage_samples);
+
+                  if (format != PIPE_FORMAT_NONE) {
+                     rb->NumSamples = samples;
+                     rb->NumStorageSamples = storage_samples;
+                     goto found;
+                  }
+               }
+            }
+            found:;
+         }
+      } else {
+         for (unsigned samples = start; samples <= ctx->Const.MaxSamples;
+              samples++) {
+            format = st_choose_renderbuffer_format(st, internalFormat,
+                                                   samples, samples);
+
+            if (format != PIPE_FORMAT_NONE) {
+               rb->NumSamples = samples;
+               rb->NumStorageSamples = samples;
+               break;
+            }
          }
       }
    } else {
       format = st_choose_renderbuffer_format(st, internalFormat, 0, 0);
    }
 
    /* Not setting gl_renderbuffer::Format here will cause
     * FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
     */
    if (format == PIPE_FORMAT_NONE) {
@@ -460,20 +504,21 @@ st_update_renderbuffer_surface(struct st_context *st,
       else
          last_layer = MIN2(first_layer + tex->NumLayers - 1, last_layer);
    }
 
    struct pipe_surface **psurf =
       enable_srgb ? &strb->surface_srgb : &strb->surface_linear;
    struct pipe_surface *surf = *psurf;
 
    if (!surf ||
        surf->texture->nr_samples != strb->Base.NumSamples ||
+       surf->texture->nr_storage_samples != strb->Base.NumStorageSamples ||
        surf->format != format ||
        surf->texture != resource ||
        surf->width != rtt_width ||
        surf->height != rtt_height ||
        surf->u.tex.level != level ||
        surf->u.tex.first_layer != first_layer ||
        surf->u.tex.last_layer != last_layer) {
       /* create a new pipe_surface */
       struct pipe_surface surf_tmpl;
       memset(&surf_tmpl, 0, sizeof(surf_tmpl));
-- 
2.17.1



More information about the mesa-dev mailing list