[Mesa-dev] [PATCH 02/17] mesa/st: Set _NumSamples in update_framebuffer_state()

Edward O'Callaghan eocallaghan at alterapraxis.com
Sat Mar 19 06:41:15 UTC 2016


Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
 src/mesa/main/mtypes.h                       |  8 +++++++
 src/mesa/state_tracker/st_atom_framebuffer.c | 35 ++++++++++++++++++++++++++++
 src/mesa/state_tracker/st_extensions.c       |  4 ++++
 3 files changed, 47 insertions(+)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5d8bfe4..d0eae36 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3481,6 +3481,14 @@ struct gl_constants
    GLuint MaxFramebufferLayers;
    GLuint MaxFramebufferSamples;
 
+   /**
+    * In the case that the framebuffer has no attachment (i.e.
+    * GL_ARB_framebuffer_no_attachments) the driver must choose
+    * a valid value for hw for the NumSamples depending on the
+    * supported MSAA modes the hw supports.
+    */
+   GLuint MSAAModes;
+
    /** Number of varying vectors between any two shader stages. */
    GLuint MaxVarying;
 
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index ae883a2..111f64e 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -64,6 +64,29 @@ update_framebuffer_size(struct pipe_framebuffer_state *framebuffer,
    framebuffer->height = MIN2(framebuffer->height, surface->height);
 }
 
+/**
+ * Round up the requested multisample count to the next supported sample size.
+ */
+static unsigned
+framebuffer_quantize_num_samples(const int supported_msaa_modes, unsigned num_samples)
+{
+   int quantized_samples = 0;
+
+   if (!num_samples)
+      return 0;
+
+   for (int i = 31; i >= 0; i--) {
+      unsigned msaa_mode = (1U << i);
+      if ((supported_msaa_modes & msaa_mode) == msaa_mode) {
+         if (msaa_mode >= num_samples)
+            quantized_samples = msaa_mode;
+         else
+            break;
+      }
+   }
+
+   return quantized_samples;
+}
 
 /**
  * Update framebuffer state (color, depth, stencil, etc. buffers)
@@ -74,6 +97,7 @@ update_framebuffer_state( struct st_context *st )
    struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer;
    struct gl_framebuffer *fb = st->ctx->DrawBuffer;
    struct st_renderbuffer *strb;
+   const int supported_msaa_modes = st->ctx->Const.MSAAModes;
    GLuint i;
 
    st_flush_bitmap_cache(st);
@@ -82,6 +106,17 @@ update_framebuffer_state( struct st_context *st )
    framebuffer->width  = UINT_MAX;
    framebuffer->height = UINT_MAX;
 
+   /**
+    * Quantize the derived default number of samples:
+    *
+    * A query to the driver of supported MSAA values the
+    * hardware supports is done as to legalize the number
+    * of application requested samples, NumSamples.
+    * See commit eb9cf3c for more information.
+    */
+   fb->DefaultGeometry._NumSamples =
+      framebuffer_quantize_num_samples(supported_msaa_modes, fb->DefaultGeometry.NumSamples);
+
    /*printf("------ fb size %d x %d\n", fb->Width, fb->Height);*/
 
    /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 275fe55..840ad40 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -1042,6 +1042,10 @@ void st_init_extensions(struct pipe_screen *screen,
          extensions->AMD_vertex_shader_viewport_index = GL_TRUE;
    }
 
+   /* Bitmask of MSAA modes supported by the hardware. */
+   consts->MSAAModes
+      = screen->get_param(screen, PIPE_CAP_MSAA_MODES);
+
    /* GL_ARB_ES3_compatibility.
     *
     * Assume that ES3 is supported if GLSL 3.30 is supported.
-- 
2.5.0



More information about the mesa-dev mailing list