st/glx: Add awareness for multisample pixel formats to st/glx-xlib.
authorBruce Cherniak <bruce.cherniak@intel.com>
Fri, 7 Apr 2017 16:27:39 +0000 (11:27 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Fri, 7 Apr 2017 21:50:58 +0000 (16:50 -0500)
In preparation for enabling MSAA in OpenSWR, the state trackers need to
be aware of multisample pixel formats for software renderers.  This patch
allows glx-xlib to query the renderer for support of pixel
formats with multisample, and create multisample resources.

This change is benign to softpipe and llvmpipe, as is_format_supported
returns FALSE for any sample_count > 1.  OpenSWR does the same at the
moment, but that will change soon.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/state_trackers/glx/xlib/glx_api.c
src/gallium/state_trackers/glx/xlib/xm_api.c
src/gallium/state_trackers/glx/xlib/xm_st.c

index 642ece7b0f89305eef2196916098010b36ce8e07..c473a0fe541b4ce055ae6fd309cccfe6f022a877 100644 (file)
@@ -181,7 +181,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
                  GLint depth_size, GLint stencil_size,
                  GLint accumRedSize, GLint accumGreenSize,
                  GLint accumBlueSize, GLint accumAlphaSize,
-                 GLint level, GLint numAuxBuffers )
+                 GLint level, GLint numAuxBuffers, GLint num_samples )
 {
    GLboolean ximageFlag = GL_TRUE;
    XMesaVisual xmvis;
@@ -229,6 +229,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
       if (v->display == dpy
           && v->mesa_visual.level == level
           && v->mesa_visual.numAuxBuffers == numAuxBuffers
+          && v->mesa_visual.samples == num_samples
           && v->ximage_flag == ximageFlag
           && v->mesa_visual.rgbMode == rgbFlag
           && v->mesa_visual.doubleBufferMode == dbFlag
@@ -254,7 +255,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
                               stereoFlag, ximageFlag,
                               depth_size, stencil_size,
                               accumRedSize, accumBlueSize,
-                              accumBlueSize, accumAlphaSize, 0, level,
+                              accumBlueSize, accumAlphaSize, num_samples, level,
                               GLX_NONE_EXT );
    if (xmvis) {
       /* Save a copy of the pointer now so we can find this visual again
@@ -344,7 +345,8 @@ create_glx_visual( Display *dpy, XVisualInfo *visinfo )
                               accBits, /* b */
                               accBits, /* a */
                               0,         /* level */
-                              0          /* numAux */
+                              0,         /* numAux */
+                              0          /* numSamples */
          );
    }
    else {
@@ -739,6 +741,7 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
    XMesaVisual xmvis = NULL;
    int desiredVisualID = -1;
    int numAux = 0;
+   GLint num_samples = 0;
 
    xmesa_init( dpy );
 
@@ -905,12 +908,13 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
           * GLX_ARB_multisample
           */
          case GLX_SAMPLE_BUFFERS_ARB:
+            /* ignore */
+            parselist++;
+            parselist++;
+            break;
          case GLX_SAMPLES_ARB:
             parselist++;
-            if (*parselist++ != 0) {
-               /* ms not supported */
-               return NULL;
-            }
+            num_samples = *parselist++;
             break;
 
          /*
@@ -1067,7 +1071,8 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
       xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
                                stereo_flag, depth_size, stencil_size,
                                accumRedSize, accumGreenSize,
-                               accumBlueSize, accumAlphaSize, level, numAux );
+                               accumBlueSize, accumAlphaSize, level, numAux,
+                               num_samples );
    }
 
    return xmvis;
@@ -1602,10 +1607,10 @@ get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
        * GLX_ARB_multisample
        */
       case GLX_SAMPLE_BUFFERS_ARB:
-         *value = 0;
+         *value = xmvis->mesa_visual.sampleBuffers;
          return 0;
       case GLX_SAMPLES_ARB:
-         *value = 0;
+         *value = xmvis->mesa_visual.samples;
          return 0;
 
       /*
index 398152e09b375fc61aed14f933fc58ccbc34aaef..881dd44323245d95a4f634410154e7d8c3344c58 100644 (file)
@@ -453,11 +453,11 @@ choose_pixel_format(XMesaVisual v)
  * stencil sizes.
  */
 static enum pipe_format
-choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil)
+choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil,
+                            int sample_count)
 {
    const enum pipe_texture_target target = PIPE_TEXTURE_2D;
    const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL;
-   const unsigned sample_count = 0;
    enum pipe_format formats[8], fmt;
    int count, i;
 
@@ -861,8 +861,8 @@ XMesaVisual XMesaCreateVisual( Display *display,
 
       vis->numAuxBuffers = 0;
       vis->level = 0;
-      vis->sampleBuffers = 0;
-      vis->samples = 0;
+      vis->sampleBuffers = num_samples > 1;
+      vis->samples = num_samples;
    }
 
    v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK;
@@ -875,6 +875,14 @@ XMesaVisual XMesaCreateVisual( Display *display,
    }
 
    v->stvis.color_format = choose_pixel_format(v);
+
+   /* Check format support at requested num_samples (for multisample) */
+   if (!xmdpy->screen->is_format_supported(xmdpy->screen,
+                                           v->stvis.color_format,
+                                           PIPE_TEXTURE_2D, num_samples,
+                                           PIPE_BIND_RENDER_TARGET))
+      v->stvis.color_format = PIPE_FORMAT_NONE;
+
    if (v->stvis.color_format == PIPE_FORMAT_NONE) {
       free(v->visinfo);
       free(v);
@@ -882,7 +890,8 @@ XMesaVisual XMesaCreateVisual( Display *display,
    }
 
    v->stvis.depth_stencil_format =
-      choose_depth_stencil_format(xmdpy, depth_size, stencil_size);
+      choose_depth_stencil_format(xmdpy, depth_size, stencil_size,
+                                  num_samples);
 
    v->stvis.accum_format = (accum_red_size +
          accum_green_size + accum_blue_size + accum_alpha_size) ?
index f598430dc263d6ff1a66f5e0457f8eb6a3390587..9e30efad60dc7125fa789bcd5b9224fbbf5ad4ff 100644 (file)
@@ -134,6 +134,7 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi,
    templ.depth0 = 1;
    templ.array_size = 1;
    templ.last_level = 0;
+   templ.nr_samples = xstfb->stvis.samples;
 
    for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
       enum pipe_format format;