gallium: handle msaa
authorRoland Scheidegger <sroland@tungstengraphics.com>
Fri, 27 Jun 2008 14:02:43 +0000 (16:02 +0200)
committerRoland Scheidegger <sroland@tungstengraphics.com>
Fri, 27 Jun 2008 14:10:16 +0000 (16:10 +0200)
src/gallium/include/pipe/p_state.h
src/gallium/winsys/dri/intel/intel_screen.c
src/mesa/drivers/dri/common/utils.c
src/mesa/drivers/dri/common/utils.h
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_fbo.h
src/mesa/state_tracker/st_framebuffer.c

index 2992e2f3b3049990a61bd443404be124274e6ada..5546796936163bcb5e9c58a5f3218ff440e3886b 100644 (file)
@@ -276,7 +276,7 @@ struct pipe_surface
    unsigned layout;              /**< PIPE_SURFACE_LAYOUT_x */
    unsigned offset;              /**< offset from start of buffer, in bytes */
    unsigned refcount;
-   unsigned usage;              /**< PIPE_BUFFER_USAGE_*  */
+   unsigned usage;               /**< PIPE_BUFFER_USAGE_*  */
 
    struct pipe_winsys *winsys;   /**< winsys which owns/created the surface */
 
@@ -311,7 +311,9 @@ struct pipe_texture
 
    unsigned last_level:8;    /**< Index of last mipmap level present/defined */
    unsigned compressed:1;
-   
+
+   unsigned nr_samples:8;          /**< for multisampled surfaces, nr of samples */
+
    unsigned tex_usage;          /* PIPE_TEXTURE_USAGE_* */
 
    /* These are also refcounted:
index 89de188ada84333ccad8fafc1a351a7d6fa46de2..cfecebdb8c7eac3d97d109eeb6cd31ffb0d03c63 100644 (file)
@@ -483,11 +483,13 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
 
    uint8_t depth_bits_array[3];
    uint8_t stencil_bits_array[3];
+   uint8_t msaa_samples_array[1];
 
 
    depth_bits_array[0] = 0;
    depth_bits_array[1] = depth_bits;
    depth_bits_array[2] = depth_bits;
+   msaa_samples_array[0] = 0;
 
    /* Just like with the accumulation buffer, always provide some modes
     * with a stencil buffer.  It will be a sw fallback, but some apps won't
@@ -521,7 +523,7 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
    if (!driFillInModes(&m, fb_format, fb_type,
                        depth_bits_array, stencil_bits_array,
                        depth_buffer_factor, back_buffer_modes,
-                       back_buffer_factor, GLX_TRUE_COLOR)) {
+                       back_buffer_factor, msaa_samples_array, 1, GLX_TRUE_COLOR)) {
       fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
               __LINE__);
       return NULL;
@@ -529,7 +531,7 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits,
    if (!driFillInModes(&m, fb_format, fb_type,
                        depth_bits_array, stencil_bits_array,
                        depth_buffer_factor, back_buffer_modes,
-                       back_buffer_factor, GLX_DIRECT_COLOR)) {
+                       back_buffer_factor, msaa_samples_array, 1, GLX_DIRECT_COLOR)) {
       fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
               __LINE__);
       return NULL;
index 94db3199287f892def988caf7396065b3bf1fbdd..3cf2146dceb1a00120d6f51df44a5cee5f630194 100644 (file)
@@ -521,6 +521,9 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
  *                      \c GLX_SWAP_UNDEFINED_OML.  See the
  *                      GLX_OML_swap_method extension spec for more details.
  * \param num_db_modes  Number of entries in \c db_modes.
+ * \param msaa_samples  Array of msaa sample count. 0 represents a visual
+ *                      without a multisample buffer.
+ * \param num_msaa_modes Number of entries in \c msaa_samples.
  * \param visType       GLX visual type.  Usually either \c GLX_TRUE_COLOR or
  *                      \c GLX_DIRECT_COLOR.
  * 
@@ -542,6 +545,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
                const uint8_t * depth_bits, const uint8_t * stencil_bits,
                unsigned num_depth_stencil_bits,
                const GLenum * db_modes, unsigned num_db_modes,
+               const u_int8_t * msaa_samples, unsigned num_msaa_modes,
                int visType )
 {
    static const uint8_t bits_table[3][4] = {
@@ -607,9 +611,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
    const uint32_t * masks;
    const int index = fb_type & 0x07;
    __GLcontextModes * modes = *ptr_to_modes;
-   unsigned i;
-   unsigned j;
-   unsigned k;
+   unsigned i, j, k, h;
 
 
    if ( bytes_per_pixel[ index ] == 0 ) {
@@ -659,49 +661,54 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
 
     for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
        for ( i = 0 ; i < num_db_modes ; i++ ) {
-           for ( j = 0 ; j < 2 ; j++ ) {
-
-               modes->redBits   = bits[0];
-               modes->greenBits = bits[1];
-               modes->blueBits  = bits[2];
-               modes->alphaBits = bits[3];
-               modes->redMask   = masks[0];
-               modes->greenMask = masks[1];
-               modes->blueMask  = masks[2];
-               modes->alphaMask = masks[3];
-               modes->rgbBits   = modes->redBits + modes->greenBits
-                   + modes->blueBits + modes->alphaBits;
-
-               modes->accumRedBits   = 16 * j;
-               modes->accumGreenBits = 16 * j;
-               modes->accumBlueBits  = 16 * j;
-               modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
-               modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
-
-               modes->stencilBits = stencil_bits[k];
-               modes->depthBits = depth_bits[k];
-
-               modes->visualType = visType;
-               modes->renderType = GLX_RGBA_BIT;
-               modes->drawableType = GLX_WINDOW_BIT;
-               modes->rgbMode = GL_TRUE;
-
-               if ( db_modes[i] == GLX_NONE ) {
-                   modes->doubleBufferMode = GL_FALSE;
+           for ( h = 0 ; h < num_msaa_modes; h++ ) {
+               for ( j = 0 ; j < 2 ; j++ ) {
+
+                   modes->redBits   = bits[0];
+                   modes->greenBits = bits[1];
+                   modes->blueBits  = bits[2];
+                   modes->alphaBits = bits[3];
+                   modes->redMask   = masks[0];
+                   modes->greenMask = masks[1];
+                   modes->blueMask  = masks[2];
+                   modes->alphaMask = masks[3];
+                   modes->rgbBits   = modes->redBits + modes->greenBits
+                       + modes->blueBits + modes->alphaBits;
+
+                   modes->accumRedBits   = 16 * j;
+                   modes->accumGreenBits = 16 * j;
+                   modes->accumBlueBits  = 16 * j;
+                   modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
+                   modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
+
+                   modes->stencilBits = stencil_bits[k];
+                   modes->depthBits = depth_bits[k];
+
+                   modes->visualType = visType;
+                   modes->renderType = GLX_RGBA_BIT;
+                   modes->drawableType = GLX_WINDOW_BIT;
+                   modes->rgbMode = GL_TRUE;
+
+                   if ( db_modes[i] == GLX_NONE ) {
+                       modes->doubleBufferMode = GL_FALSE;
+                   }
+                   else {
+                       modes->doubleBufferMode = GL_TRUE;
+                       modes->swapMethod = db_modes[i];
+                   }
+
+                   modes->samples = msaa_samples[h];
+                   modes->sampleBuffers = modes->samples ? 1 : 0;
+
+                   modes->haveAccumBuffer = ((modes->accumRedBits +
+                                              modes->accumGreenBits +
+                                              modes->accumBlueBits +
+                                              modes->accumAlphaBits) > 0);
+                   modes->haveDepthBuffer = (modes->depthBits > 0);
+                   modes->haveStencilBuffer = (modes->stencilBits > 0);
+
+                   modes = modes->next;
                }
-               else {
-                   modes->doubleBufferMode = GL_TRUE;
-                   modes->swapMethod = db_modes[i];
-               }
-
-               modes->haveAccumBuffer = ((modes->accumRedBits +
-                                          modes->accumGreenBits +
-                                          modes->accumBlueBits +
-                                          modes->accumAlphaBits) > 0);
-               modes->haveDepthBuffer = (modes->depthBits > 0);
-               modes->haveStencilBuffer = (modes->stencilBits > 0);
-
-               modes = modes->next;
            }
        }
     }
index 1067d0a8bfdf2d3c3817ef1b0a3f64cf8912b5a7..20940c21b4ece4b85a59c8c9f174b5e336163fb2 100644 (file)
@@ -115,6 +115,7 @@ extern GLboolean driFillInModes( __GLcontextModes ** modes,
     GLenum fb_format, GLenum fb_type,
     const uint8_t * depth_bits, const uint8_t * stencil_bits,
     unsigned num_depth_stencil_bits,
-    const GLenum * db_modes, unsigned num_db_modes, int visType );
+    const GLenum * db_modes, unsigned num_db_modes,
+    const u_int8_t * msaa_samples, unsigned num_msaa_modes, int visType );
 
 #endif /* DRI_DEBUG_H */
index dceb7611f252a4f8f2d53b4e388f3d392f32e5e9..0a065541e1f7e995b61edac9ffa2b6a7becd4dd3 100644 (file)
@@ -2269,6 +2269,7 @@ struct gl_renderbuffer
    GLubyte IndexBits;
    GLubyte DepthBits;
    GLubyte StencilBits;
+   GLubyte Samples;     /**< Number of samples - 0 if not multisampled */
    GLvoid *Data;        /**< This may not be used by some kinds of RBs */
 
    /* Used to wrap one renderbuffer around another: */
index 1067caf9b378594a548d656b236f0b439c69d03b..7245798d0da511b7108fe2a9d9408017660977a3 100644 (file)
@@ -118,6 +118,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
    template.height[0] = height;
    template.depth[0] = 1;
    template.last_level = 0;
+   template.nr_samples = rb->Samples;
 
    if (pf_is_depth_stencil(template.format)) {
       template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
@@ -249,7 +250,7 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name)
  * renderbuffer).  The window system code determines the format.
  */
 struct gl_renderbuffer *
-st_new_renderbuffer_fb(enum pipe_format format)
+st_new_renderbuffer_fb(enum pipe_format format, int samples)
 {
    struct st_renderbuffer *strb;
 
@@ -261,6 +262,7 @@ st_new_renderbuffer_fb(enum pipe_format format)
 
    _mesa_init_renderbuffer(&strb->Base, 0);
    strb->Base.ClassID = 0x4242; /* just a unique value */
+   strb->Base.Samples = samples;
    strb->format = format;
 
    switch (format) {
index 87b0734a0c8595dcbe1c8b13e4ec6bab0a8c850e..ff56001a4e14fa1f5fb4cf018fa654d479009c3b 100644 (file)
@@ -58,7 +58,7 @@ st_renderbuffer(struct gl_renderbuffer *rb)
 
 
 extern struct gl_renderbuffer *
-st_new_renderbuffer_fb(enum pipe_format format);
+st_new_renderbuffer_fb(enum pipe_format format, int samples);
 
 extern void
 st_init_fbo_functions(struct dd_function_table *functions);
index 1b6e68c2a116b7954cd719b433efc1b52dfb09af..1994a1c8260c57bb6eb83c058bca5e67db2e0114 100644 (file)
@@ -51,27 +51,29 @@ st_create_framebuffer( const __GLcontextModes *visual,
 {
    struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer);
    if (stfb) {
+      int samples = 0;
       _mesa_initialize_framebuffer(&stfb->Base, visual);
+      if (visual->sampleBuffers) samples = visual->samples;
 
       {
          /* fake frontbuffer */
          /* XXX allocation should only happen in the unusual case
             it's actually needed */
          struct gl_renderbuffer *rb
-            = st_new_renderbuffer_fb(colorFormat);
+            = st_new_renderbuffer_fb(colorFormat, samples);
          _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb);
       }
 
       if (visual->doubleBufferMode) {
          struct gl_renderbuffer *rb
-            = st_new_renderbuffer_fb(colorFormat);
+            = st_new_renderbuffer_fb(colorFormat, samples);
          _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb);
       }
 
       if (visual->depthBits == 24 && visual->stencilBits == 8) {
          /* combined depth/stencil buffer */
          struct gl_renderbuffer *depthStencilRb
-            = st_new_renderbuffer_fb(depthFormat);
+            = st_new_renderbuffer_fb(depthFormat, samples);
          /* note: bind RB to two attachment points */
          _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb);
          _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb);
@@ -82,26 +84,26 @@ st_create_framebuffer( const __GLcontextModes *visual,
          if (visual->depthBits == 32) {
             /* 32-bit depth buffer */
             struct gl_renderbuffer *depthRb
-               = st_new_renderbuffer_fb(depthFormat);
+               = st_new_renderbuffer_fb(depthFormat, samples);
             _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
          }
          else if (visual->depthBits == 24) {
             /* 24-bit depth buffer, ignore stencil bits */
             struct gl_renderbuffer *depthRb
-               = st_new_renderbuffer_fb(depthFormat);
+               = st_new_renderbuffer_fb(depthFormat, samples);
             _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
          }
          else if (visual->depthBits > 0) {
             /* 16-bit depth buffer */
             struct gl_renderbuffer *depthRb
-               = st_new_renderbuffer_fb(depthFormat);
+               = st_new_renderbuffer_fb(depthFormat, samples);
             _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb);
          }
 
          if (visual->stencilBits > 0) {
             /* 8-bit stencil */
             struct gl_renderbuffer *stencilRb
-               = st_new_renderbuffer_fb(stencilFormat);
+               = st_new_renderbuffer_fb(stencilFormat, samples);
             _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb);
          }
       }
@@ -109,7 +111,7 @@ st_create_framebuffer( const __GLcontextModes *visual,
       if (visual->accumRedBits > 0) {
          /* 16-bit/channel accum */
          struct gl_renderbuffer *accumRb
-            = st_new_renderbuffer_fb(DEFAULT_ACCUM_PIPE_FORMAT);
+            = st_new_renderbuffer_fb(DEFAULT_ACCUM_PIPE_FORMAT, 0); /* XXX accum isn't multisampled right? */
          _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb);
       }