gallium: add st_api feature mask to prevent advertising MS visuals
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Mon, 21 May 2012 21:46:11 +0000 (23:46 +0200)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Tue, 29 May 2012 13:01:41 +0000 (15:01 +0200)
v2: use a define for the maximum sample count
v3: also test odd sample counts (r300 supports MS3)

While multisample renderbuffers are supported by mesa, MS visuals
are not, so we need a way to tell dri/st not to advertise them even
if the gallium driver does support multisampled surfaces.

Otherwise applications selecting these non-functional visuals would
run into trouble ...

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/dri/common/dri_screen.c
src/gallium/state_trackers/vega/vg_manager.c
src/mesa/state_tracker/st_manager.c

index 3af1dfc6d4d189841d3759a16b7b5d30b4a1e9ce..86ab02d2883dbf0d1c138815d88705567c66c529 100644 (file)
@@ -69,6 +69,17 @@ enum st_profile_type
 #define ST_PROFILE_OPENGL_ES1_MASK   (1 << ST_PROFILE_OPENGL_ES1)
 #define ST_PROFILE_OPENGL_ES2_MASK   (1 << ST_PROFILE_OPENGL_ES2)
 
+/**
+ * Optional API/state tracker features.
+ */
+enum st_api_feature
+{
+   ST_API_FEATURE_MS_VISUALS  /**< support for multisample visuals */
+};
+
+/* for feature_mask in st_api */
+#define ST_API_FEATURE_MS_VISUALS_MASK (1 << ST_API_FEATURE_MS_VISUALS)
+
 /**
  * New context flags for GL 3.0 and beyond.
  *
@@ -429,6 +440,11 @@ struct st_api
     */
    unsigned profile_mask;
 
+   /**
+    * The supported optional features.  Tested with ST_FEATURE_*_MASK.
+    */
+   unsigned feature_mask;
+
    /**
     * Destroy the API.
     */
index 24efbde2017b50dcb6b7f6e32e6a654b90798dc8..406e550e58e8a2945de26cf7c90dd16dc297e0b1 100644 (file)
@@ -41,6 +41,8 @@
 
 #include "util/u_debug.h"
 
+#define MSAA_VISUAL_MAX_SAMPLES 8
+
 PUBLIC const char __driConfigOptions[] =
    DRI_CONF_BEGIN
       DRI_CONF_SECTION_PERFORMANCE
@@ -72,10 +74,10 @@ dri_fill_in_modes(struct dri_screen *screen,
    __DRIconfig **configs_x8r8g8b8 = NULL;
    uint8_t depth_bits_array[5];
    uint8_t stencil_bits_array[5];
-   uint8_t msaa_samples_array[5];
+   uint8_t msaa_samples_array[MSAA_VISUAL_MAX_SAMPLES];
    unsigned depth_buffer_factor;
    unsigned back_buffer_factor;
-   unsigned msaa_samples_factor;
+   unsigned msaa_samples_factor, msaa_samples_max;
    unsigned i;
    struct pipe_screen *p_screen = screen->base.screen;
    boolean pf_r5g6b5, pf_a8r8g8b8, pf_x8r8g8b8;
@@ -89,6 +91,9 @@ dri_fill_in_modes(struct dri_screen *screen,
    stencil_bits_array[0] = 0;
    depth_buffer_factor = 1;
 
+   msaa_samples_max = (screen->st_api->feature_mask & ST_API_FEATURE_MS_VISUALS)
+      ? MSAA_VISUAL_MAX_SAMPLES : 1;
+
    pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM,
                                            PIPE_TEXTURE_2D, 0,
                                             PIPE_BIND_DEPTH_STENCIL);
@@ -146,14 +151,16 @@ dri_fill_in_modes(struct dri_screen *screen,
    msaa_samples_array[0] = 0;
    back_buffer_factor = 3;
 
-   /* also test color for msaa 2/4/6/8 - just assume it'll work for all depth buffers */
+   /* Also test for color multisample support - just assume it'll work
+    * for all depth buffers.
+    */
    if (pf_r5g6b5) {
       msaa_samples_factor = 1;
-      for (i = 1; i < 5; i++) {
+      for (i = 2; i <= msaa_samples_max; i++) {
          if (p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM,
-                                                  PIPE_TEXTURE_2D, i*2,
+                                                  PIPE_TEXTURE_2D, i,
                                                    PIPE_BIND_RENDER_TARGET)) {
-            msaa_samples_array[msaa_samples_factor] = i * 2;
+            msaa_samples_array[msaa_samples_factor] = i;
             msaa_samples_factor++;
          }
       }
@@ -168,11 +175,11 @@ dri_fill_in_modes(struct dri_screen *screen,
 
    if (pf_a8r8g8b8) {
       msaa_samples_factor = 1;
-      for (i = 1; i < 5; i++) {
+      for (i = 2; i <= msaa_samples_max; i++) {
          if (p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM,
-                                                  PIPE_TEXTURE_2D, i*2,
+                                                  PIPE_TEXTURE_2D, i,
                                                    PIPE_BIND_RENDER_TARGET)) {
-            msaa_samples_array[msaa_samples_factor] = i * 2;
+            msaa_samples_array[msaa_samples_factor] = i;
             msaa_samples_factor++;
          }
       }
@@ -190,11 +197,11 @@ dri_fill_in_modes(struct dri_screen *screen,
 
    if (pf_x8r8g8b8) {
       msaa_samples_factor = 1;
-      for (i = 1; i < 5; i++) {
+      for (i = 2; i <= msaa_samples_max; i++) {
          if (p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM,
-                                                  PIPE_TEXTURE_2D, i*2,
+                                                  PIPE_TEXTURE_2D, i,
                                                    PIPE_BIND_RENDER_TARGET)) {
-            msaa_samples_array[msaa_samples_factor] = i * 2;
+            msaa_samples_array[msaa_samples_factor] = i;
             msaa_samples_factor++;
          }
       }
index e88f5f17fe5695fa4c64420d2915de28a7ed27c7..660a7af884f8a30ae2efcb6b28cca2655fdc0f98 100644 (file)
@@ -369,6 +369,7 @@ static const struct st_api vg_api = {
    "Vega " VEGA_VERSION_STRING,
    ST_API_OPENVG,
    ST_PROFILE_DEFAULT_MASK,
+   0,
    vg_api_destroy,
    vg_api_get_proc_address,
    vg_api_create_context,
index d54b7ed62bda991dea68c44beed57062036de6af..748624f3d9471dcb1e65906f0e030f71445c8399 100644 (file)
@@ -890,6 +890,7 @@ static const struct st_api st_gl_api = {
 #if FEATURE_ES2
    ST_PROFILE_OPENGL_ES2_MASK |
 #endif
+   0,
    0,
    st_api_destroy,
    st_api_get_proc_address,