[Mesa-dev] [PATCH 2/3] i965: Share code between intel_quantize_num_samples and clamp_max_samples

Chad Versace chad.versace at linux.intel.com
Wed Nov 20 14:10:47 PST 2013


clamp_max_samples() and intel_quantize_num_samples() each maintained
their own list of which MSAA modes the hardware supports. This patch
removes the duplication by making intel_quantize_num_samples() use the
same list as clamp_max_samples(), the list maintained in
brw_supported_msaa_modes().

By removing the duplication, we prevent the scenario where someone
updates one list but forgets to update the other.

Move function `brw_context.c:static brw_supported_msaa_modes()` to
`intel_screen.c:(non-static) intel_supported_msaa_modes()` and patch
intel_quantize_num_samples() to use the list returned by that function.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.c  | 26 ++++----------------------
 src/mesa/drivers/dri/i965/intel_fbo.c    | 28 ++++++++++------------------
 src/mesa/drivers/dri/i965/intel_screen.c | 20 ++++++++++++++++++++
 src/mesa/drivers/dri/i965/intel_screen.h |  3 +++
 4 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index b8b924d..ae50830 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -278,26 +278,6 @@ brw_init_driver_functions(struct brw_context *brw,
 }
 
 /**
- * Return array of MSAA modes supported by the hardware. The array is
- * terminated by -1 and sorted in decreasing order.
- */
-static const int*
-brw_supported_msaa_modes(const struct brw_context *brw)
-{
-   static const int gen7_samples[] = {8, 4, 0, -1};
-   static const int gen6_samples[] = {4, 0, -1};
-   static const int gen4_samples[] = {0, -1};
-
-   if (brw->gen >= 7) {
-      return gen7_samples;
-   } else if (brw->gen == 6) {
-      return gen6_samples;
-   } else {
-      return gen4_samples;
-   }
-}
-
-/**
  * Override GL_MAX_SAMPLES and related constants according to value of driconf
  * option 'clamp_max_samples'.
  */
@@ -309,7 +289,8 @@ brw_override_max_samples(struct brw_context *brw)
    if (clamp_max_samples < 0)
       return;
 
-   const int *supported_msaa_modes = brw_supported_msaa_modes(brw);
+   const int *supported_msaa_modes =
+      intel_supported_msaa_modes(brw->intelScreen);
    int max_samples = 0;
 
    /* Select the largest supported MSAA mode that does not exceed
@@ -393,7 +374,8 @@ brw_initialize_context_constants(struct brw_context *brw)
 
    ctx->Const.AlwaysUseGetTransformFeedbackVertexCount = true;
 
-   const int max_samples = brw_supported_msaa_modes(brw)[0];
+   const int max_samples =
+      intel_supported_msaa_modes(brw->intelScreen)[0];
    ctx->Const.MaxSamples = max_samples;
    ctx->Const.MaxColorTextureSamples = max_samples;
    ctx->Const.MaxDepthTextureSamples = max_samples;
diff --git a/src/mesa/drivers/dri/i965/intel_fbo.c b/src/mesa/drivers/dri/i965/intel_fbo.c
index ddecb2b..472d2ca 100644
--- a/src/mesa/drivers/dri/i965/intel_fbo.c
+++ b/src/mesa/drivers/dri/i965/intel_fbo.c
@@ -46,6 +46,7 @@
 #include "intel_fbo.h"
 #include "intel_mipmap_tree.h"
 #include "intel_regions.h"
+#include "intel_screen.h"
 #include "intel_tex.h"
 #include "brw_context.h"
 
@@ -159,26 +160,17 @@ intel_unmap_renderbuffer(struct gl_context *ctx,
 unsigned
 intel_quantize_num_samples(struct intel_screen *intel, unsigned num_samples)
 {
-   switch (intel->devinfo->gen) {
-   case 6:
-      /* Gen6 supports only 4x multisampling. */
-      if (num_samples > 0)
-         return 4;
-      else
-         return 0;
-   case 7:
-      /* Gen7 supports 4x and 8x multisampling. */
-      if (num_samples > 4)
-         return 8;
-      else if (num_samples > 0)
-         return 4;
+   const int *msaa_modes = intel_supported_msaa_modes(intel);
+   int quantized_samples = 0;
+
+   for (int i = 0; msaa_modes[i] != -1; ++i) {
+      if (msaa_modes[i] >= num_samples)
+         quantized_samples = msaa_modes[i];
       else
-         return 0;
-      return 0;
-   default:
-      /* MSAA unsupported. */
-      return 0;
+         break;
    }
+
+   return quantized_samples;
 }
 
 
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index e44d0f6..0fdc27d 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -1092,6 +1092,26 @@ intel_detect_swizzling(struct intel_screen *screen)
       return true;
 }
 
+/**
+ * Return array of MSAA modes supported by the hardware. The array is
+ * zero-terminated and sorted in decreasing order.
+ */
+const int*
+intel_supported_msaa_modes(const struct intel_screen  *screen)
+{
+   static const int gen7_modes[] = {8, 4, 0, -1};
+   static const int gen6_modes[] = {4, 0, -1};
+   static const int gen4_modes[] = {0, -1};
+
+   if (screen->devinfo->gen >= 7) {
+      return gen7_modes;
+   } else if (screen->devinfo->gen == 6) {
+      return gen6_modes;
+   } else {
+      return gen4_modes;
+   }
+}
+
 static __DRIconfig**
 intel_screen_make_configs(__DRIscreen *dri_screen)
 {
diff --git a/src/mesa/drivers/dri/i965/intel_screen.h b/src/mesa/drivers/dri/i965/intel_screen.h
index eb9bfca..2e3043e 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.h
+++ b/src/mesa/drivers/dri/i965/intel_screen.h
@@ -77,4 +77,7 @@ intelMakeCurrent(__DRIcontext * driContextPriv,
 double get_time(void);
 void aub_dump_bmp(struct gl_context *ctx);
 
+const int*
+intel_supported_msaa_modes(const struct intel_screen  *screen);
+
 #endif
-- 
1.8.4



More information about the mesa-dev mailing list