[Xquartz-changes] mesa: Branch 'master' - 309 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Sun Apr 29 00:50:07 PDT 2012


Rebased ref, commits from common ancestor:
commit 727c38dab7654b5474abc6d7bc0c274a6fdb190f
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 27 18:36:33 2012 -0700

    darwin: Eliminate a possible race condition while destroying a surface
    
    Introduced by: c60ffd2840036af1ea6f2b6c6e1e9014bb8e2c34
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/src/glx/apple/apple_glx_surface.c b/src/glx/apple/apple_glx_surface.c
index d42fa3b..9155202 100644
--- a/src/glx/apple/apple_glx_surface.c
+++ b/src/glx/apple/apple_glx_surface.c
@@ -207,9 +207,6 @@ apple_glx_surface_destroy(unsigned int uid)
       d->types.surface.pending_destroy = true;
       d->release(d);
 
-      /* apple_glx_drawable_find_by_uid returns a locked drawable */
-      d->unlock(d);
-
       /* 
        * We release 2 references to the surface.  One was acquired by
        * the find, and the other was leftover from a context, or 
@@ -220,6 +217,9 @@ apple_glx_surface_destroy(unsigned int uid)
        * to actually destroy it when the pending_destroy is processed
        * by a glViewport callback (see apple_glx_context_update()).
        */
-      d->destroy(d);
+      if (!d->destroy(d)) {
+          /* apple_glx_drawable_find_by_uid returns a locked drawable */
+          d->unlock(d);
+      }
    }
 }
commit 940c5e4d52056df0c0039a6ea320fc4162bdd023
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 28 23:19:42 2012 -0700

    darwin: Use ASL for logging
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/src/glx/apple/Makefile b/src/glx/apple/Makefile
index dc64295..68fe6ad 100644
--- a/src/glx/apple/Makefile
+++ b/src/glx/apple/Makefile
@@ -26,6 +26,7 @@ SOURCES = \
 	apple_glx.c \
 	apple_glx_context.c \
 	apple_glx_drawable.c \
+	apple_glx_log.c \
 	apple_glx_pbuffer.c \
 	apple_glx_pixmap.c \
 	apple_glx_surface.c \
diff --git a/src/glx/apple/apple_glx.c b/src/glx/apple/apple_glx.c
index d94c1e0..56cff64 100644
--- a/src/glx/apple/apple_glx.c
+++ b/src/glx/apple/apple_glx.c
@@ -33,6 +33,8 @@
 #include <assert.h>
 #include <stdarg.h>
 #include <dlfcn.h>
+#include <pthread.h>
+#include <inttypes.h>
 #include "appledri.h"
 #include "apple_glx.h"
 #include "apple_glx_context.h"
@@ -43,22 +45,6 @@ static int dri_event_base = 0;
 
 const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
 
-static bool diagnostic = false;
-
-void
-apple_glx_diagnostic(const char *fmt, ...)
-{
-   va_list vl;
-
-   if (diagnostic) {
-      fprintf(stderr, "DIAG: ");
-
-      va_start(vl, fmt);
-      vfprintf(stderr, fmt, vl);
-      va_end(vl);
-   }
-}
-
 int
 apple_get_dri_event_base(void)
 {
@@ -125,10 +111,9 @@ apple_init_glx(Display * dpy)
    if (initialized)
       return false;
 
-   if (getenv("LIBGL_DIAGNOSTIC")) {
-      printf("initializing libGL in %s\n", __func__);
-      diagnostic = true;
-   }
+   apple_glx_log_init();
+
+   apple_glx_log(ASL_LEVEL_INFO, "Initializing libGL.");
 
    apple_cgl_init();
    (void) apple_glx_get_client_id();
diff --git a/src/glx/apple/apple_glx.h b/src/glx/apple/apple_glx.h
index ce8c488..0967f18 100644
--- a/src/glx/apple/apple_glx.h
+++ b/src/glx/apple/apple_glx.h
@@ -38,7 +38,8 @@
 #define XP_NO_X_HEADERS
 #include <Xplugin.h>
 
-void apple_glx_diagnostic(const char *fmt, ...);
+#include "apple_glx_log.h"
+
 xp_client_id apple_glx_get_client_id(void);
 bool apple_init_glx(Display * dpy);
 void apple_glx_swap_buffers(void *ptr);
diff --git a/src/glx/apple/apple_glx_log.c b/src/glx/apple/apple_glx_log.c
new file mode 100644
index 0000000..9ebf666
--- /dev/null
+++ b/src/glx/apple/apple_glx_log.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2012 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#include <sys/cdefs.h>
+#include <asl.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include "apple_glx_log.h"
+
+static bool diagnostic = false;
+static aslclient aslc;
+
+void apple_glx_log_init(void) {
+    if (getenv("LIBGL_DIAGNOSTIC")) {
+        diagnostic = true;
+    }
+
+    aslc = asl_open(NULL, NULL, 0);
+}
+
+void _apple_glx_log(int level, const char *file, const char *function,
+                    int line, const char *fmt, ...) {
+    va_list v;
+    va_start(v, fmt);
+    _apple_glx_vlog(level, file, function, line, fmt, v);
+    va_end(v);
+}
+
+static const char *
+_asl_level_string(int level)
+{
+        if (level == ASL_LEVEL_EMERG) return ASL_STRING_EMERG;
+        if (level == ASL_LEVEL_ALERT) return ASL_STRING_ALERT;
+        if (level == ASL_LEVEL_CRIT) return ASL_STRING_CRIT;
+        if (level == ASL_LEVEL_ERR) return ASL_STRING_ERR;
+        if (level == ASL_LEVEL_WARNING) return ASL_STRING_WARNING;
+        if (level == ASL_LEVEL_NOTICE) return ASL_STRING_NOTICE;
+        if (level == ASL_LEVEL_INFO) return ASL_STRING_INFO;
+        if (level == ASL_LEVEL_DEBUG) return ASL_STRING_DEBUG;
+        return "unknown";
+}
+
+void _apple_glx_vlog(int level, const char *file, const char *function,
+                     int line, const char *fmt, va_list args) {
+    aslmsg msg;
+    uint64_t thread = 0;
+
+    if (pthread_is_threaded_np()) {
+        pthread_threadid_np(NULL, &thread);
+    }
+
+    if (diagnostic) {
+        va_list args2;
+        va_copy(args2, args);
+
+        fprintf(stderr, "%-9s %24s:%-4d %s(%"PRIu64"): ",
+                _asl_level_string(level), file, line, function, thread);
+        vfprintf(stderr, fmt, args2);
+    }
+
+    msg = asl_new(ASL_TYPE_MSG);
+    if (msg) {
+        if (file)
+            asl_set(msg, "File", file);
+        if (function)
+            asl_set(msg, "Function", function);
+        if (line) {
+            char *_line;
+            asprintf(&_line, "%d", line);
+            if (_line) {
+                asl_set(msg, "Line", _line);
+                free(_line);
+            }
+        }
+        if (pthread_is_threaded_np()) {
+            char *_thread;
+            asprintf(&_thread, "%"PRIu64, thread);
+            if (_thread) {
+                asl_set(msg, "Thread", _thread);
+                free(_thread);
+            }
+        }
+    }
+
+    asl_vlog(aslc, msg, level, fmt, args);
+    if (msg)
+        asl_free(msg);
+}
diff --git a/src/glx/apple/apple_glx_log.h b/src/glx/apple/apple_glx_log.h
new file mode 100644
index 0000000..4b1c531
--- /dev/null
+++ b/src/glx/apple/apple_glx_log.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 Apple Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
+
+#ifndef APPLE_GLX_LOG_H
+#define APPLE_GLX_LOG_H
+
+#include <sys/cdefs.h>
+#include <asl.h>
+
+void apple_glx_log_init(void);
+
+__printflike(5, 6)
+void _apple_glx_log(int level, const char *file, const char *function,
+                    int line, const char *fmt, ...);
+#define apple_glx_log(l, f, args ...) \
+    _apple_glx_log(l, __FILE__, __FUNCTION__, __LINE__, f, ## args)
+
+
+__printflike(5, 0)
+void _apple_glx_vlog(int level, const char *file, const char *function,
+                     int line, const char *fmt, va_list v);
+#define apple_glx_vlog(l, f, v) \
+    _apple_glx_vlog(l, __FILE__, __FUNCTION__, __LINE__, f, v)
+
+/* This is just here to help the transition.
+ * TODO: Replace calls to apple_glx_diagnostic
+ */
+#define apple_glx_diagnostic(f, args ...) \
+    apple_glx_log(ASL_LEVEL_DEBUG, f, ## args)
+
+#endif
commit 4c071e0463a9dc3cce959ad07c9f33ad48f546a1
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 28 16:50:00 2012 -0700

    darwin: Make reported errors more user-friendly
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/src/glx/apple/apple_glx_drawable.c b/src/glx/apple/apple_glx_drawable.c
index db28302..3f84d56 100644
--- a/src/glx/apple/apple_glx_drawable.c
+++ b/src/glx/apple/apple_glx_drawable.c
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <pthread.h>
+#include <string.h>
 #include "apple_glx.h"
 #include "apple_glx_context.h"
 #include "apple_glx_drawable.h"
@@ -48,8 +49,8 @@ lock_drawables_list(void)
    err = pthread_mutex_lock(&drawables_lock);
 
    if (err) {
-      fprintf(stderr, "pthread_mutex_lock failure in %s: %d\n",
-              __func__, err);
+      fprintf(stderr, "pthread_mutex_lock failure in %s: %s\n",
+              __func__, strerror(err));
       abort();
    }
 }
@@ -62,8 +63,8 @@ unlock_drawables_list(void)
    err = pthread_mutex_unlock(&drawables_lock);
 
    if (err) {
-      fprintf(stderr, "pthread_mutex_unlock failure in %s: %d\n",
-              __func__, err);
+      fprintf(stderr, "pthread_mutex_unlock failure in %s: %s\n",
+              __func__, strerror(err));
       abort();
    }
 }
@@ -95,7 +96,7 @@ drawable_lock(struct apple_glx_drawable *agd)
    err = pthread_mutex_lock(&agd->mutex);
 
    if (err) {
-      fprintf(stderr, "pthread_mutex_lock error: %d\n", err);
+      fprintf(stderr, "pthread_mutex_lock error: %s\n", strerror(err));
       abort();
    }
 }
@@ -108,7 +109,7 @@ drawable_unlock(struct apple_glx_drawable *d)
    err = pthread_mutex_unlock(&d->mutex);
 
    if (err) {
-      fprintf(stderr, "pthread_mutex_unlock error: %d\n", err);
+      fprintf(stderr, "pthread_mutex_unlock error: %s\n", strerror(err));
       abort();
    }
 }
@@ -245,7 +246,7 @@ common_init(Display * dpy, GLXDrawable drawable, struct apple_glx_drawable *d)
    err = pthread_mutexattr_init(&attr);
 
    if (err) {
-      fprintf(stderr, "pthread_mutexattr_init error: %d\n", err);
+      fprintf(stderr, "pthread_mutexattr_init error: %s\n", strerror(err));
       abort();
    }
 
@@ -257,14 +258,14 @@ common_init(Display * dpy, GLXDrawable drawable, struct apple_glx_drawable *d)
    err = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
 
    if (err) {
-      fprintf(stderr, "error: setting pthread mutex type: %d\n", err);
+      fprintf(stderr, "error: setting pthread mutex type: %s\n", strerror(err));
       abort();
    }
 
    err = pthread_mutex_init(&d->mutex, &attr);
 
    if (err) {
-      fprintf(stderr, "pthread_mutex_init error: %d\n", err);
+      fprintf(stderr, "pthread_mutex_init error: %s\n", strerror(err));
       abort();
    }
 
commit a027324dca80721efb89e167d413e100317089a1
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sun Apr 29 00:27:03 2012 -0700

    darwin: Fix an error message
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/src/glx/apple/apple_glx_context.c b/src/glx/apple/apple_glx_context.c
index c58d05a..0bb25b4 100644
--- a/src/glx/apple/apple_glx_context.c
+++ b/src/glx/apple/apple_glx_context.c
@@ -421,7 +421,7 @@ apple_glx_make_current_context(Display * dpy, void *oldptr, void *ptr,
     */
 
    if (same_drawable && ac->is_current) {
-      apple_glx_diagnostic("%s: same_drawable and ac->is_current\n");
+      apple_glx_diagnostic("same_drawable and ac->is_current\n");
       return false;
    }
 
commit bcc5caf642a9beec324657becac501944ce4dc23
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Apr 24 14:09:13 2012 -0700

    i965/fs: Fix FB writes that tried to use the non-existent m16 register.
    
    A little analysis shows that the worst-case value for "nr" is 17:
    - base_mrf = 2                       ... 2
    - header present (say gen == 5)      ... 4
    - aa_dest_stencil_reg (stencil test) ... 5
    - SIMD16 mode: += 4 * reg_width      ... 13
    - source_depth_to_render_target      ... 15
    - dest_depth_reg                     ... 17
    
    This resulted in us setting base_mrf to 2 and mlen to 15.  In other
    words, we'd try to use m2..m16.  But m16 doesn't exist pre-Gen6.  Also,
    the instruction scheduler data structures use arrays of size 16, so this
    would cause us to access them out of bounds.
    
    While the debugger system routine may need m0 and m1, we don't use it
    today, so the simplest solution is just to move base_mrf back to 1.
    That way, our worst case message fits in m1..m15, which is legal.
    
    An alternative would be to fail on SIMD16 in this case, but that seems
    a bit unfortunate if there's no real need to reserve m0 and m1.
    
    Fixes new piglit test shaders/depth-test-and-write on Ironlake,
    as well as gzdoom.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48218
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit aa429ea73c0931d5cfa2c263fe005ead8dc32ddf)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 0632052..cec1e95 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1921,7 +1921,10 @@ fs_visitor::emit_fb_writes()
 {
    this->current_annotation = "FB write header";
    bool header_present = true;
-   int base_mrf = 2;
+   /* We can potentially have a message length of up to 15, so we have to set
+    * base_mrf to either 0 or 1 in order to fit in m0..m15.
+    */
+   int base_mrf = 1;
    int nr = base_mrf;
    int reg_width = c->dispatch_width / 8;
 
commit 69d8a25d429bccf960e98e5c126e1ef2ae4ffe9d
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Mon Apr 23 16:43:22 2012 -0700

    darwin: Eliminate a pthread mutex leak
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Tested-by: Charles Davis <cdavis at mines.edu>
    (cherry picked from commit 1a33c1b2b895566299ec76643659adacc239a3dc)

diff --git a/src/glx/apple/apple_glx_drawable.c b/src/glx/apple/apple_glx_drawable.c
index 5530224..db28302 100644
--- a/src/glx/apple/apple_glx_drawable.c
+++ b/src/glx/apple/apple_glx_drawable.c
@@ -135,6 +135,7 @@ release_drawable(struct apple_glx_drawable *d)
 static bool
 destroy_drawable(struct apple_glx_drawable *d)
 {
+   int err;
 
    d->lock(d);
 
@@ -172,6 +173,12 @@ destroy_drawable(struct apple_glx_drawable *d)
 
    apple_glx_diagnostic("%s: freeing %p\n", __func__, (void *) d);
 
+   err = pthread_mutex_destroy(&d->mutex);
+   if (err) {
+      fprintf(stderr, "pthread_mutex_destroy error: %s\n", strerror(err));
+      abort();
+   }
+   
    free(d);
 
    /* So that the locks are balanced and the caller correctly unlocks. */
commit 6095a17534c2694760300701fee59a320950f271
Author: Jonas Maebe <jonas.maebe at elis.ugent.be>
Date:   Mon Apr 23 16:02:16 2012 -0700

    apple: Fix a use after free
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit c60ffd2840036af1ea6f2b6c6e1e9014bb8e2c34)

diff --git a/src/glx/apple/apple_glx_surface.c b/src/glx/apple/apple_glx_surface.c
index 39f5130..d42fa3b 100644
--- a/src/glx/apple/apple_glx_surface.c
+++ b/src/glx/apple/apple_glx_surface.c
@@ -206,6 +206,10 @@ apple_glx_surface_destroy(unsigned int uid)
    if (d) {
       d->types.surface.pending_destroy = true;
       d->release(d);
+
+      /* apple_glx_drawable_find_by_uid returns a locked drawable */
+      d->unlock(d);
+
       /* 
        * We release 2 references to the surface.  One was acquired by
        * the find, and the other was leftover from a context, or 
@@ -217,7 +221,5 @@ apple_glx_surface_destroy(unsigned int uid)
        * by a glViewport callback (see apple_glx_context_update()).
        */
       d->destroy(d);
-
-      d->unlock(d);
    }
 }
commit bb30e76328e9dd80b0c7a7688828e3cf8e662b1b
Author: Jonas Maebe <jonas.maebe at elis.ugent.be>
Date:   Sun Apr 22 20:39:32 2012 -0700

    glapi: Correct size of allocated _glapi_table struct
    
    The __glapi_gentable_set_remaining_noop() routine treats the _glapi_struct
    as an array of _glapi_get_dispatch_table_size() pointers, so we have to
    allocate _glapi_get_dispatch_table_size()*sizeof(void*) bytes rather
    than sizeof(struct _glapi_struct) bytes.
    
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit 8d09f4d0cc8d2ac5398c8b26638d5659429a4280)

diff --git a/src/mapi/glapi/glapi_gentable.c b/src/mapi/glapi/glapi_gentable.c
index 5c04801..640c495 100644
--- a/src/mapi/glapi/glapi_gentable.c
+++ b/src/mapi/glapi/glapi_gentable.c
@@ -105,7 +105,7 @@ __glapi_gentable_set_remaining_noop(struct _glapi_table *disp) {
 
 struct _glapi_table *
 _glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
-    struct _glapi_table *disp = calloc(1, sizeof(struct _glapi_table));
+    struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(void *));
     char symboln[512];
 
     if(!disp)
commit 49ed43b6de98482c898334a9abfc574720391c9f
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Apr 17 17:41:09 2012 -0600

    mesa: add a couple fast-paths to fast_read_rgba_pixels_memcpy()
    
    Accelerates a few glReadPixels cases for WebGL.
    See https://bugs.freedesktop.org/show_bug.cgi?id=48545
    
    v2: Per Jose, use bit twiddling for the swizzle case instead of ubyte
    arrays (it's about 44% faster).
    
    Note: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    
    (cherry picked from commit a5e95a419e4f6ad93e35a960113d97ae2de27476)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 5b3c246..f3a0d10 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -196,6 +196,11 @@ read_stencil_pixels( struct gl_context *ctx,
    ctx->Driver.UnmapRenderbuffer(ctx, rb);
 }
 
+
+/**
+ * Try to do glReadPixels of RGBA data using a simple memcpy or swizzle.
+ * \return GL_TRUE if successful, GL_FALSE otherwise (use the slow path)
+ */
 static GLboolean
 fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
 			      GLint x, GLint y,
@@ -208,8 +213,20 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
    struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
    GLubyte *dst, *map;
    int dstStride, stride, j, texelBytes;
+   GLboolean swizzle_rb = GL_FALSE, copy_xrgb = GL_FALSE;
 
-   if (!_mesa_format_matches_format_and_type(rb->Format, format, type))
+   /* XXX we could check for other swizzle/special cases here as needed */
+   if (rb->Format == MESA_FORMAT_RGBA8888_REV &&
+       format == GL_BGRA &&
+       type == GL_UNSIGNED_INT_8_8_8_8_REV) {
+      swizzle_rb = GL_TRUE;
+   }
+   else if (rb->Format == MESA_FORMAT_XRGB8888 &&
+            format == GL_BGRA &&
+            type == GL_UNSIGNED_INT_8_8_8_8_REV) {
+      copy_xrgb = GL_TRUE;
+   }
+   else if (!_mesa_format_matches_format_and_type(rb->Format, format, type))
       return GL_FALSE;
 
    /* check for things we can't handle here */
@@ -240,10 +257,39 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
    }
 
    texelBytes = _mesa_get_format_bytes(rb->Format);
-   for (j = 0; j < height; j++) {
-      memcpy(dst, map, width * texelBytes);
-      dst += dstStride;
-      map += stride;
+
+   if (swizzle_rb) {
+      /* swap R/B */
+      for (j = 0; j < height; j++) {
+         int i;
+         for (i = 0; i < width; i++) {
+            GLuint *dst4 = (GLuint *) dst, *map4 = (GLuint *) map;
+            GLuint pixel = map4[i];
+            dst4[i] = (pixel & 0xff00ff00)
+                   | ((pixel & 0x00ff0000) >> 16)
+                   | ((pixel & 0x000000ff) << 16);
+         }
+         dst += dstStride;
+         map += stride;
+      }
+   } else if (copy_xrgb) {
+      /* convert xrgb -> argb */
+      for (j = 0; j < height; j++) {
+         GLuint *dst4 = (GLuint *) dst, *map4 = (GLuint *) map;
+         int i;
+         for (i = 0; i < width; i++) {
+            dst4[i] = map4[i] | 0xff000000;  /* set A=0xff */
+         }
+         dst += dstStride;
+         map += stride;
+      }
+   } else {
+      /* just memcpy */
+      for (j = 0; j < height; j++) {
+         memcpy(dst, map, width * texelBytes);
+         dst += dstStride;
+         map += stride;
+      }
    }
 
    ctx->Driver.UnmapRenderbuffer(ctx, rb);
commit 9f150ffe8ee5f184861a377637091e4f06210927
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Sat Mar 17 10:48:23 2012 +0800

    i915: set SPRITE_POINT_ENABLE bit correctly
    
    When SPRITE_POINT_ENABLE bit is set, the texture coord would be
    replaced, and this is only needed when we called something like
    glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE).
    
    And more,  we currently handle varying inputs as texture coord,
    we would be careful when setting this bit and set it just when
    needed, or you will find the value of varying input is not right
    and changed.
    
    Thus we do set SPRITE_POINT_ENABLE bit only when all enabled tex
    coord units need do CoordReplace. Or fallback is needed to make
    sure the rendering is right.
    
    With handling the bit setup at i915_update_sprite_point_enable(),
    we don't need the relative code at i915Enable then.
    
    This patch would _really_ fix the webglc point-size.html test case and
    of course, not regress piglit point-sprite and glean-pointSprite
    testcase.
    
    NOTE: This is a candidate for stable release branches.
    
    v2: fallback just when all enabled tex coord units need do
        CoordReplace (Eric)
    v3: move the sprite point validate code at I915InvalidateState (Eric)
    v4: sprite point enable bit update based on _NEW_PROGRAM, too
        add relative _NEW-state comments to show what state is being used(Eric)
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    (cherry picked from commit c6532875493ffe7de9c37924c70ebf6d0472e23d)

diff --git a/src/mesa/drivers/dri/i915/i915_context.c b/src/mesa/drivers/dri/i915/i915_context.c
index 36563ef..dc32292 100644
--- a/src/mesa/drivers/dri/i915/i915_context.c
+++ b/src/mesa/drivers/dri/i915/i915_context.c
@@ -76,6 +76,8 @@ i915InvalidateState(struct gl_context * ctx, GLuint new_state)
        i915_update_provoking_vertex(ctx);
    if (new_state & (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS))
        i915_update_program(ctx);
+   if (new_state & (_NEW_PROGRAM | _NEW_POINT))
+       i915_update_sprite_point_enable(ctx);
 }
 
 
diff --git a/src/mesa/drivers/dri/i915/i915_context.h b/src/mesa/drivers/dri/i915/i915_context.h
index 8167137..7037465 100644
--- a/src/mesa/drivers/dri/i915/i915_context.h
+++ b/src/mesa/drivers/dri/i915/i915_context.h
@@ -40,6 +40,7 @@
 #define I915_FALLBACK_POINT_SMOOTH	 0x80000
 #define I915_FALLBACK_POINT_SPRITE_COORD_ORIGIN	 0x100000
 #define I915_FALLBACK_DRAW_OFFSET	 0x200000
+#define I915_FALLBACK_COORD_REPLACE	 0x400000
 
 #define I915_UPLOAD_CTX              0x1
 #define I915_UPLOAD_BUFFERS          0x2
@@ -338,6 +339,7 @@ extern void i915InitStateFunctions(struct dd_function_table *functions);
 extern void i915InitState(struct i915_context *i915);
 extern void i915_update_stencil(struct gl_context * ctx);
 extern void i915_update_provoking_vertex(struct gl_context *ctx);
+extern void i915_update_sprite_point_enable(struct gl_context *ctx);
 
 
 /*======================================================================
diff --git a/src/mesa/drivers/dri/i915/i915_state.c b/src/mesa/drivers/dri/i915/i915_state.c
index 756001f..94c7327 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -652,6 +652,48 @@ i915PointParameterfv(struct gl_context * ctx, GLenum pname, const GLfloat *param
    }
 }
 
+void
+i915_update_sprite_point_enable(struct gl_context *ctx)
+{
+   struct intel_context *intel = intel_context(ctx);
+   /* _NEW_PROGRAM */
+   struct i915_fragment_program *p =
+      (struct i915_fragment_program *) ctx->FragmentProgram._Current;
+   const GLbitfield64 inputsRead = p->FragProg.Base.InputsRead;
+   struct i915_context *i915 = i915_context(ctx);
+   GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK;
+   int i;
+   GLuint coord_replace_bits = 0x0;
+   GLuint tex_coord_unit_bits = 0x0;
+
+   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
+      /* _NEW_POINT */
+      if (ctx->Point.CoordReplace[i] && ctx->Point.PointSprite)
+         coord_replace_bits |= (1 << i);
+      if (inputsRead & FRAG_BIT_TEX(i))
+         tex_coord_unit_bits |= (1 << i);
+   }
+
+   /*
+    * Here we can't enable the SPRITE_POINT_ENABLE bit when the mis-match
+    * of tex_coord_unit_bits and coord_replace_bits, or this will make all
+    * the other non-point-sprite coords(like varying inputs, as we now use
+    * tex coord to implement varying inputs) be replaced to value (0, 0)-(1, 1).
+    *
+    * Thus, do fallback when needed.
+    */
+   FALLBACK(intel, I915_FALLBACK_COORD_REPLACE,
+            coord_replace_bits && coord_replace_bits != tex_coord_unit_bits);
+
+   s4 &= ~S4_SPRITE_POINT_ENABLE;
+   s4 |= (coord_replace_bits && coord_replace_bits == tex_coord_unit_bits) ?
+         S4_SPRITE_POINT_ENABLE : 0;
+   if (s4 != i915->state.Ctx[I915_CTXREG_LIS4]) {
+      i915->state.Ctx[I915_CTXREG_LIS4] = s4;
+      I915_STATECHANGE(i915, I915_UPLOAD_CTX);
+   }
+}
+
 
 /* =============================================================
  * Color masks
@@ -869,18 +911,7 @@ i915Enable(struct gl_context * ctx, GLenum cap, GLboolean state)
       break;
 
    case GL_POINT_SPRITE:
-      /* This state change is handled in i915_reduced_primitive_state because
-       * the hardware bit should only be set when rendering points.
-       */
-	 dw = i915->state.Ctx[I915_CTXREG_LIS4];
-      if (state)
-	 dw |= S4_SPRITE_POINT_ENABLE;
-      else
-	 dw &= ~S4_SPRITE_POINT_ENABLE;
-      if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) {
-	 i915->state.Ctx[I915_CTXREG_LIS4] = dw;
-	 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
-      }
+      /* Handle it at i915_update_sprite_point_enable () */
       break;
 
    case GL_POINT_SMOOTH:
diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c
index a36011a..68f0e05 100644
--- a/src/mesa/drivers/dri/i915/intel_tris.c
+++ b/src/mesa/drivers/dri/i915/intel_tris.c
@@ -1198,6 +1198,7 @@ static char *fallbackStrings[] = {
    [19] = "Smooth point",
    [20] = "point sprite coord origin",
    [21] = "depth/color drawing offset",
+   [22] = "coord replace(SPRITE POINT ENABLE)",
 };
 
 
commit edeb3976d427bf4f9c471bc5171ee507533b7e89
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Apr 4 16:48:21 2012 -0700

    i965: Actually upload sampler state pointers for the VS unit on Gen6.
    
    We already program all the sampler state correctly, we just didn't give
    the GPU a pointer to it for the VS stage.  Thus, any texturing other
    than texelFetch() wouldn't work.
    
    Fixes piglit test vs-textureLod-miplevels and 99 of oglconform's
    glsl-bif-tex subtests.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 2a80a1e2a702228501fd298b9b176efa8c2c6258)

diff --git a/src/mesa/drivers/dri/i965/gen6_sampler_state.c b/src/mesa/drivers/dri/i965/gen6_sampler_state.c
index 15cae0a..a9a9df5 100644
--- a/src/mesa/drivers/dri/i965/gen6_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sampler_state.c
@@ -41,7 +41,7 @@ upload_sampler_state_pointers(struct brw_context *brw)
 	     GS_SAMPLER_STATE_CHANGE |
 	     PS_SAMPLER_STATE_CHANGE |
 	     (4 - 2));
-   OUT_BATCH(0); /* VS */
+   OUT_BATCH(brw->sampler.offset); /* VS */
    OUT_BATCH(0); /* GS */
    OUT_BATCH(brw->sampler.offset);
    ADVANCE_BATCH();
commit a30790a9a38dd392204c7d79ea448d5cd6001e43
Author: Marek Olšák <maraeo at gmail.com>
Date:   Wed Apr 4 03:55:42 2012 +0200

    r300g/swtcl: fix crash when back color is present in vertex shader
    
    The shader transformation code sometimes produced invalid TGSI.
    (cherry picked from commit 75f8990547903f7dde5d98319cc813f94a15aa78)

diff --git a/src/gallium/drivers/r300/r300_vs_draw.c b/src/gallium/drivers/r300/r300_vs_draw.c
index ce85a0c..69d6758 100644
--- a/src/gallium/drivers/r300/r300_vs_draw.c
+++ b/src/gallium/drivers/r300/r300_vs_draw.c
@@ -29,7 +29,7 @@
  *
  * Transformations:
  * 1) If the secondary color output is present, the primary color must be
- *    inserted before it.
+ *    present too.
  * 2) If any back-face color output is present, there must be all 4 color
  *    outputs and missing ones must be inserted.
  * 3) Insert a trailing texcoord output containing a copy of POS, for WPOS.
@@ -52,7 +52,6 @@ struct vs_transform_context {
 
     boolean color_used[2];
     boolean bcolor_used[2];
-    boolean temp_used[128];
 
     /* Index of the pos output, typically 0. */
     unsigned pos_output;
@@ -72,6 +71,8 @@ struct vs_transform_context {
     boolean first_instruction;
     /* End instruction processed? */
     boolean end_instruction;
+
+    boolean temp_used[1024];
 };
 
 static void emit_temp(struct tgsi_transform_context *ctx, unsigned reg)
@@ -102,9 +103,9 @@ static void emit_output(struct tgsi_transform_context *ctx,
     ++vsctx->num_outputs;
 }
 
-static void insert_output(struct tgsi_transform_context *ctx,
-                          struct tgsi_full_declaration *before,
-                          unsigned name, unsigned index, unsigned interp)
+static void insert_output_before(struct tgsi_transform_context *ctx,
+                                 struct tgsi_full_declaration *before,
+                                 unsigned name, unsigned index, unsigned interp)
 {
     struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx;
     unsigned i;
@@ -115,28 +116,29 @@ static void insert_output(struct tgsi_transform_context *ctx,
     }
 
     /* Insert the new output. */
-    emit_output(ctx, name, index, interp, before->Range.First);
+    emit_output(ctx, name, index, interp,
+                before->Range.First + vsctx->decl_shift);
 
     ++vsctx->decl_shift;
 }
 
-static void insert_trailing_bcolor(struct tgsi_transform_context *ctx,
-                                   struct tgsi_full_declaration *before)
+static void insert_output_after(struct tgsi_transform_context *ctx,
+                                struct tgsi_full_declaration *after,
+                                unsigned name, unsigned index, unsigned interp)
 {
     struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx;
+    unsigned i;
 
-    /* If BCOLOR0 is used, make sure BCOLOR1 is present too. Otherwise
-     * the rasterizer doesn't do the color selection correctly. */
-    if (vsctx->bcolor_used[0] && !vsctx->bcolor_used[1]) {
-        if (before) {
-            insert_output(ctx, before, TGSI_SEMANTIC_BCOLOR, 1,
-                          TGSI_INTERPOLATE_LINEAR);
-        } else {
-            emit_output(ctx, TGSI_SEMANTIC_BCOLOR, 1,
-                        TGSI_INTERPOLATE_LINEAR, vsctx->num_outputs);
-        }
-        vsctx->bcolor_used[1] = TRUE;
+    /* Make a place for the new output. */
+    for (i = after->Range.First+1; i < Elements(vsctx->out_remap); i++) {
+        ++vsctx->out_remap[i];
     }
+
+    /* Insert the new output. */
+    emit_output(ctx, name, index, interp,
+                after->Range.First + 1);
+
+    ++vsctx->decl_shift;
 }
 
 static void transform_decl(struct tgsi_transform_context *ctx,
@@ -153,41 +155,38 @@ static void transform_decl(struct tgsi_transform_context *ctx,
 
             case TGSI_SEMANTIC_COLOR:
                 assert(decl->Semantic.Index < 2);
-                vsctx->color_used[decl->Semantic.Index] = TRUE;
 
                 /* We must rasterize the first color if the second one is
                  * used, otherwise the rasterizer doesn't do the color
                  * selection correctly. Declare it, but don't write to it. */
                 if (decl->Semantic.Index == 1 && !vsctx->color_used[0]) {
-                    insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
-                                  TGSI_INTERPOLATE_LINEAR);
+                    insert_output_before(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
+                                         TGSI_INTERPOLATE_LINEAR);
                     vsctx->color_used[0] = TRUE;
                 }
                 break;
 
             case TGSI_SEMANTIC_BCOLOR:
                 assert(decl->Semantic.Index < 2);
-                vsctx->bcolor_used[decl->Semantic.Index] = TRUE;
 
                 /* We must rasterize all 4 colors if back-face colors are
                  * used, otherwise the rasterizer doesn't do the color
                  * selection correctly. Declare it, but don't write to it. */
                 if (!vsctx->color_used[0]) {
-                    insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
-                                  TGSI_INTERPOLATE_LINEAR);
+                    insert_output_before(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
+                                         TGSI_INTERPOLATE_LINEAR);
                     vsctx->color_used[0] = TRUE;
                 }
                 if (!vsctx->color_used[1]) {
-                    insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 1,
-                                  TGSI_INTERPOLATE_LINEAR);
+                    insert_output_before(ctx, decl, TGSI_SEMANTIC_COLOR, 1,
+                                         TGSI_INTERPOLATE_LINEAR);
                     vsctx->color_used[1] = TRUE;
                 }
                 if (decl->Semantic.Index == 1 && !vsctx->bcolor_used[0]) {
-                    insert_output(ctx, decl, TGSI_SEMANTIC_BCOLOR, 0,
-                                  TGSI_INTERPOLATE_LINEAR);
+                    insert_output_before(ctx, decl, TGSI_SEMANTIC_BCOLOR, 0,
+                                         TGSI_INTERPOLATE_LINEAR);
                     vsctx->bcolor_used[0] = TRUE;
                 }
-                /* One more case is handled in insert_trailing_bcolor. */
                 break;
 
             case TGSI_SEMANTIC_GENERIC:
@@ -195,11 +194,6 @@ static void transform_decl(struct tgsi_transform_context *ctx,
                 break;
         }
 
-        if (decl->Semantic.Name != TGSI_SEMANTIC_BCOLOR) {
-            /* Insert it as soon as possible. */
-            insert_trailing_bcolor(ctx, decl);
-        }
-
         /* Since we're inserting new outputs in between, the following outputs
          * should be moved to the right so that they don't overlap with
          * the newly added ones. */
@@ -214,6 +208,14 @@ static void transform_decl(struct tgsi_transform_context *ctx,
     }
 
     ctx->emit_declaration(ctx, decl);
+
+    /* Insert BCOLOR1 if needed. */
+    if (decl->Declaration.File == TGSI_FILE_OUTPUT &&
+        decl->Semantic.Name == TGSI_SEMANTIC_BCOLOR &&
+        !vsctx->bcolor_used[1]) {
+        insert_output_after(ctx, decl, TGSI_SEMANTIC_BCOLOR, 1,
+                            TGSI_INTERPOLATE_LINEAR);
+    }
 }
 
 static void transform_inst(struct tgsi_transform_context *ctx,
@@ -226,10 +228,6 @@ static void transform_inst(struct tgsi_transform_context *ctx,
     if (!vsctx->first_instruction) {
         vsctx->first_instruction = TRUE;
 
-        /* The trailing BCOLOR should be inserted before the code
-         * if it hasn't already been done so. */
-        insert_trailing_bcolor(ctx, NULL);
-
         /* Insert the generic output for WPOS. */
         emit_output(ctx, TGSI_SEMANTIC_GENERIC, vsctx->last_generic + 1,
                     TGSI_INTERPOLATE_PERSPECTIVE, vsctx->num_outputs);
@@ -314,10 +312,13 @@ void r300_draw_init_vertex_shader(struct r300_context *r300,
 {
     struct draw_context *draw = r300->draw;
     struct pipe_shader_state new_vs;
+    struct tgsi_shader_info info;
     struct vs_transform_context transform;
     const uint newLen = tgsi_num_tokens(vs->state.tokens) + 100 /* XXX */;
     unsigned i;
 
+    tgsi_scan_shader(vs->state.tokens, &info);
+
     new_vs.tokens = tgsi_alloc_tokens(newLen);
     if (new_vs.tokens == NULL)
         return;
@@ -330,6 +331,22 @@ void r300_draw_init_vertex_shader(struct r300_context *r300,
     transform.base.transform_instruction = transform_inst;
     transform.base.transform_declaration = transform_decl;
 
+    for (i = 0; i < info.num_outputs; i++) {
+        unsigned index = info.output_semantic_index[i];
+
+        switch (info.output_semantic_name[i]) {
+            case TGSI_SEMANTIC_COLOR:
+                assert(index < 2);
+                transform.color_used[index] = TRUE;
+                break;
+
+            case TGSI_SEMANTIC_BCOLOR:
+                assert(index < 2);
+                transform.bcolor_used[index] = TRUE;
+                break;
+        }
+    }
+
     tgsi_transform_shader(vs->state.tokens,
                           (struct tgsi_token*)new_vs.tokens,
                           newLen, &transform.base);
commit 3d436f6c376e0a564f7c6877fdfcae50662ce640
Author: Marek Olšák <maraeo at gmail.com>
Date:   Wed Apr 4 01:46:31 2012 +0200

    r300g/swtcl: fix polygon offset
    (cherry picked from commit c3481f341021c87c86a69bcf892447e55b0687e9)

diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 8dc7ae9..c43352a 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -1048,6 +1048,10 @@ static void* r300_create_rs_state(struct pipe_context* pipe,
 
     /* Override some states for Draw. */
     rs->rs_draw.sprite_coord_enable = 0; /* We can do this in HW. */
+    rs->rs_draw.offset_point = 0;
+    rs->rs_draw.offset_line = 0;
+    rs->rs_draw.offset_tri = 0;
+    rs->rs_draw.offset_clamp = 0;
 
 #ifdef PIPE_ARCH_LITTLE_ENDIAN
     vap_control_status = R300_VC_NO_SWAP;
commit 8d40c2f5e21a25a85708a40284350c43727fd0d8
Author: Marek Olšák <maraeo at gmail.com>
Date:   Tue Apr 3 23:00:18 2012 +0200

    r300g/swtcl: don't expose shader subroutine support
    
    RET in the main function doesn't work. This should be fixed in Draw, but meh.
    (cherry picked from commit 3b8fe06eb629f887071d5fbe2bc50b7a0c516a25)

diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
index 763321b..f28b0be 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -212,6 +212,7 @@ static int r300_get_shader_param(struct pipe_screen *pscreen, unsigned shader, e
         switch (param)
         {
         case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
+        case PIPE_SHADER_CAP_SUBROUTINES:
             return 0;
         default:;
         }
commit d146c503581f76c5296b82ebc0dc276b01e0e344
Author: Marek Olšák <maraeo at gmail.com>
Date:   Sat Mar 31 22:17:19 2012 +0200

    r300g/swtcl: don't enter u_vbuf_mgr
    (cherry picked from commit da2123051c3923a2953cdd96f05ad684e7d3c8c3)

diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c
index d132638..920612b 100644
--- a/src/gallium/drivers/r300/r300_blit.c
+++ b/src/gallium/drivers/r300/r300_blit.c
@@ -63,8 +63,13 @@ static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op o
     util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state);
     util_blitter_save_viewport(r300->blitter, &r300->viewport);
     util_blitter_save_vertex_elements(r300->blitter, r300->velems);
-    util_blitter_save_vertex_buffers(r300->blitter, r300->vbuf_mgr->nr_vertex_buffers,
-                                     r300->vbuf_mgr->vertex_buffer);
+    if (r300->vbuf_mgr) {
+        util_blitter_save_vertex_buffers(r300->blitter, r300->vbuf_mgr->nr_vertex_buffers,
+                                         r300->vbuf_mgr->vertex_buffer);
+    } else {
+        util_blitter_save_vertex_buffers(r300->blitter, r300->swtcl_nr_vertex_buffers,
+                                         r300->swtcl_vertex_buffer);
+    }
 
     if (op & R300_SAVE_FRAMEBUFFER) {
         util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state);
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index 7d289ca..1626768 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -419,17 +419,19 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     r300_init_query_functions(r300);
     r300_init_state_functions(r300);
     r300_init_resource_functions(r300);
-    
+
     r300->context.create_video_decoder = vl_create_decoder;
     r300->context.create_video_buffer = vl_video_buffer_create;
 
-    r300->vbuf_mgr = u_vbuf_create(&r300->context, 1024 * 1024, 16,
+    if (r300->screen->caps.has_tcl) {
+        r300->vbuf_mgr = u_vbuf_create(&r300->context, 1024 * 1024, 16,
                                        PIPE_BIND_VERTEX_BUFFER |
                                        PIPE_BIND_INDEX_BUFFER,
                                        U_VERTEX_FETCH_DWORD_ALIGNED);
-    if (!r300->vbuf_mgr)
-        goto fail;
-    r300->vbuf_mgr->caps.format_fixed32 = 0;
+        if (!r300->vbuf_mgr)
+            goto fail;
+        r300->vbuf_mgr->caps.format_fixed32 = 0;
+    }
 
     r300->blitter = util_blitter_create(&r300->context);
     if (r300->blitter == NULL)
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index e40b7af..8264b28 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -581,6 +581,9 @@ struct r300_context {
     void *dsa_decompress_zmask;
 
     struct u_vbuf *vbuf_mgr;
+    struct pipe_index_buffer swtcl_index_buffer;
+    struct pipe_vertex_buffer swtcl_vertex_buffer[PIPE_MAX_ATTRIBS];
+    unsigned swtcl_nr_vertex_buffers;
 
     struct util_slab_mempool pool_transfers;
 
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 83cad42..1542648 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -818,7 +818,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
     struct pipe_transfer *ib_transfer = NULL;
     int i;
     void *indices = NULL;
-    boolean indexed = info->indexed && r300->vbuf_mgr->index_buffer.buffer;
+    boolean indexed = info->indexed && r300->swtcl_index_buffer.buffer;
 
     if (r300->skip_rendering) {
         return;
@@ -831,10 +831,10 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
             (indexed ? PREP_INDEXED : 0),
             indexed ? 256 : 6);
 
-    for (i = 0; i < r300->vbuf_mgr->nr_vertex_buffers; i++) {
-        if (r300->vbuf_mgr->vertex_buffer[i].buffer) {
+    for (i = 0; i < r300->swtcl_nr_vertex_buffers; i++) {
+        if (r300->swtcl_vertex_buffer[i].buffer) {
             void *buf = pipe_buffer_map(pipe,
-                                  r300->vbuf_mgr->vertex_buffer[i].buffer,
+                                  r300->swtcl_vertex_buffer[i].buffer,
                                   PIPE_TRANSFER_READ |
                                   PIPE_TRANSFER_UNSYNCHRONIZED,
                                   &vb_transfer[i]);
@@ -843,7 +843,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
     }
 
     if (indexed) {
-        indices = pipe_buffer_map(pipe, r300->vbuf_mgr->index_buffer.buffer,
+        indices = pipe_buffer_map(pipe, r300->swtcl_index_buffer.buffer,
                                   PIPE_TRANSFER_READ |
                                   PIPE_TRANSFER_UNSYNCHRONIZED, &ib_transfer);
     }
@@ -856,8 +856,8 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
     draw_flush(r300->draw);
     r300->draw_vbo_locked = FALSE;
 
-    for (i = 0; i < r300->vbuf_mgr->nr_vertex_buffers; i++) {
-        if (r300->vbuf_mgr->vertex_buffer[i].buffer) {
+    for (i = 0; i < r300->swtcl_nr_vertex_buffers; i++) {
+        if (r300->swtcl_vertex_buffer[i].buffer) {
             pipe_buffer_unmap(pipe, vb_transfer[i]);
             draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
         }
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index c8e01c3..8dc7ae9 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -1595,7 +1595,6 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
                                     const struct pipe_vertex_buffer* buffers)
 {
     struct r300_context* r300 = r300_context(pipe);
-    unsigned i;
     struct pipe_vertex_buffer dummy_vb = {0};
 
     /* There must be at least one vertex buffer set, otherwise it locks up. */
@@ -1605,18 +1604,13 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
         count = 1;
     }
 
-    u_vbuf_set_vertex_buffers(r300->vbuf_mgr, count, buffers);
-
     if (r300->screen->caps.has_tcl) {
-        /* HW TCL. */
-        for (i = 0; i < count; i++) {
-            if (buffers[i].buffer &&
-		!r300_resource(buffers[i].buffer)->b.user_ptr) {
-            }
-        }
+        u_vbuf_set_vertex_buffers(r300->vbuf_mgr, count, buffers);
         r300->vertex_arrays_dirty = TRUE;
     } else {
-        /* SW TCL. */
+        util_copy_vertex_buffers(r300->swtcl_vertex_buffer,
+                                 &r300->swtcl_nr_vertex_buffers,
+                                 buffers, count);
         draw_set_vertex_buffers(r300->draw, count, buffers);
     }
 }
@@ -1626,9 +1620,15 @@ static void r300_set_index_buffer(struct pipe_context* pipe,
 {
     struct r300_context* r300 = r300_context(pipe);
 
-    u_vbuf_set_index_buffer(r300->vbuf_mgr, ib);
-
-    if (!r300->screen->caps.has_tcl) {
+    if (r300->screen->caps.has_tcl) {
+        u_vbuf_set_index_buffer(r300->vbuf_mgr, ib);
+    } else {
+        if (ib) {
+            pipe_resource_reference(&r300->swtcl_index_buffer.buffer, ib->buffer);
+            memcpy(&r300->swtcl_index_buffer, ib, sizeof(*ib));
+        } else {
+            pipe_resource_reference(&r300->swtcl_index_buffer.buffer, NULL);
+        }
         draw_set_index_buffer(r300->draw, ib);
     }
 }
@@ -1702,11 +1702,11 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe,
         return NULL;
 
     velems->count = count;
-    velems->vmgr_elements =
-        u_vbuf_create_vertex_elements(r300->vbuf_mgr, count, attribs,
-                                          velems->velem);
 
     if (r300_screen(pipe->screen)->caps.has_tcl) {
+        velems->vmgr_elements =
+            u_vbuf_create_vertex_elements(r300->vbuf_mgr, count, attribs,
+                                          velems->velem);
         /* Setup PSC.
          * The unused components will be replaced by (..., 0, 1). */
         r300_vertex_psc(velems);
@@ -1716,6 +1716,8 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe,
                 align(util_format_get_blocksize(velems->velem[i].src_format), 4);
             velems->vertex_size_dwords += velems->format_size[i] / 4;
         }
+    } else {
+        memcpy(velems->velem, attribs, count * sizeof(struct pipe_vertex_element));
     }
 
     return velems;
@@ -1733,9 +1735,9 @@ static void r300_bind_vertex_elements_state(struct pipe_context *pipe,
 
     r300->velems = velems;
 
-    u_vbuf_bind_vertex_elements(r300->vbuf_mgr, state, velems->vmgr_elements);
-
-    if (r300->draw) {
+    if (r300->screen->caps.has_tcl) {
+        u_vbuf_bind_vertex_elements(r300->vbuf_mgr, state, velems->vmgr_elements);
+    } else {
         draw_set_vertex_elements(r300->draw, velems->count, velems->velem);
         return;
     }
@@ -1750,7 +1752,9 @@ static void r300_delete_vertex_elements_state(struct pipe_context *pipe, void *s
     struct r300_context *r300 = r300_context(pipe);
     struct r300_vertex_element_state *velems = state;
 
-    u_vbuf_destroy_vertex_elements(r300->vbuf_mgr, velems->vmgr_elements);
+    if (r300->screen->caps.has_tcl) {
+        u_vbuf_destroy_vertex_elements(r300->vbuf_mgr, velems->vmgr_elements);
+    }
     FREE(state);
 }
 
commit 1709144338be4faf8497bc50cb8b1adebe8ce22f
Author: Marek Olšák <maraeo at gmail.com>
Date:   Tue Apr 3 22:37:30 2012 +0200

    r300g/swtcl: don't print an error when getting ClipVertex
    
    Draw can do it just fine.
    (cherry picked from commit 5ce0598a034179eaacff96f39eaebf0ba0f30d4c)

diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 2bc7036..c8e01c3 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -1765,10 +1765,10 @@ static void* r300_create_vs_state(struct pipe_context* pipe,
     vs->state.tokens = tgsi_dup_tokens(shader->tokens);
 
     if (r300->screen->caps.has_tcl) {
-        r300_init_vs_outputs(vs);
+        r300_init_vs_outputs(r300, vs);
         r300_translate_vertex_shader(r300, vs);
     } else {
-        r300_draw_init_vertex_shader(r300->draw, vs);
+        r300_draw_init_vertex_shader(r300, vs);
     }
 
     return vs;
diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c
index 1eef071..4faf2b5 100644
--- a/src/gallium/drivers/r300/r300_vs.c
+++ b/src/gallium/drivers/r300/r300_vs.c
@@ -36,6 +36,7 @@
 
 /* Convert info about VS output semantics into r300_shader_semantics. */
 static void r300_shader_read_vs_outputs(
+    struct r300_context *r300,
     struct tgsi_shader_info* info,
     struct r300_shader_semantics* vs_outputs)
 {
@@ -83,6 +84,14 @@ static void r300_shader_read_vs_outputs(
                 fprintf(stderr, "r300 VP: cannot handle edgeflag output.\n");
                 break;
 
+            case TGSI_SEMANTIC_CLIPVERTEX:
+                assert(index == 0);
+                /* Draw does clip vertex for us. */
+                if (r300->screen->caps.has_tcl) {
+                    fprintf(stderr, "r300 VP: cannot handle clip vertex output.\n");
+                }
+                break;
+
             default:
                 fprintf(stderr, "r300 VP: unknown vertex output semantic: %i.\n",
                         info->output_semantic_name[i]);
@@ -160,10 +169,11 @@ static void set_vertex_inputs_outputs(struct r300_vertex_program_compiler * c)
     c->code->outputs[outputs->wpos] = reg++;
 }
 
-void r300_init_vs_outputs(struct r300_vertex_shader *vs)
+void r300_init_vs_outputs(struct r300_context *r300,
+                          struct r300_vertex_shader *vs)
 {
     tgsi_scan_shader(vs->state.tokens, &vs->info);
-    r300_shader_read_vs_outputs(&vs->info, &vs->outputs);
+    r300_shader_read_vs_outputs(r300, &vs->info, &vs->outputs);
 }
 
 static void r300_dummy_vertex_shader(
@@ -187,7 +197,7 @@ static void r300_dummy_vertex_shader(
     ureg_destroy(ureg);
 
     shader->dummy = TRUE;
-    r300_init_vs_outputs(shader);
+    r300_init_vs_outputs(r300, shader);
     r300_translate_vertex_shader(r300, shader);
 }
 
diff --git a/src/gallium/drivers/r300/r300_vs.h b/src/gallium/drivers/r300/r300_vs.h
index a482ddc..b02d5d7 100644
--- a/src/gallium/drivers/r300/r300_vs.h
+++ b/src/gallium/drivers/r300/r300_vs.h
@@ -56,12 +56,13 @@ struct r300_vertex_shader {
     void *draw_vs;
 };
 
-void r300_init_vs_outputs(struct r300_vertex_shader *vs);
+void r300_init_vs_outputs(struct r300_context *r300,
+                          struct r300_vertex_shader *vs);
 
 void r300_translate_vertex_shader(struct r300_context *r300,
                                   struct r300_vertex_shader *vs);
 
-void r300_draw_init_vertex_shader(struct draw_context *draw,
+void r300_draw_init_vertex_shader(struct r300_context *r300,
                                   struct r300_vertex_shader *vs);
 
 #endif /* R300_VS_H */
diff --git a/src/gallium/drivers/r300/r300_vs_draw.c b/src/gallium/drivers/r300/r300_vs_draw.c
index 2939963..ce85a0c 100644
--- a/src/gallium/drivers/r300/r300_vs_draw.c
+++ b/src/gallium/drivers/r300/r300_vs_draw.c
@@ -309,9 +309,10 @@ static void transform_inst(struct tgsi_transform_context *ctx,
     ctx->emit_instruction(ctx, inst);
 }
 
-void r300_draw_init_vertex_shader(struct draw_context *draw,
+void r300_draw_init_vertex_shader(struct r300_context *r300,
                                   struct r300_vertex_shader *vs)
 {
+    struct draw_context *draw = r300->draw;
     struct pipe_shader_state new_vs;
     struct vs_transform_context transform;
     const uint newLen = tgsi_num_tokens(vs->state.tokens) + 100 /* XXX */;
@@ -350,7 +351,7 @@ void r300_draw_init_vertex_shader(struct draw_context *draw,
     vs->state.tokens = new_vs.tokens;
 
     /* Init the VS output table for the rasterizer. */
-    r300_init_vs_outputs(vs);
+    r300_init_vs_outputs(r300, vs);
 
     /* Make the last generic be WPOS. */
     vs->outputs.wpos = vs->outputs.generic[transform.last_generic + 1];
commit 54f7391664d2cffe1f719d11fec1f18db672be5d
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Wed Feb 8 15:07:33 2012 -0800

    glsl: Fix Android build
    
    The build was broken by the line below, added in commit 4f82fed4.
      s_expression.cpp:26: #include <limits>
    
    Mesa's half of the fix is to add 'external/astl/include' to the include
    path. The other half of the fix requires implementing
    numeric_limits<float>::infinity() in astl, for which I have patches
    submitted upstream for review.
    
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 5497cc428fa7c6670d252d34f4a67c9498ae3895)

diff --git a/src/glsl/Android.mk b/src/glsl/Android.mk
index d7d17dd..84a8655 100644
--- a/src/glsl/Android.mk
+++ b/src/glsl/Android.mk
@@ -39,6 +39,7 @@ LOCAL_SRC_FILES := \
 	$(LIBGLSL_CXX_SOURCES)
 
 LOCAL_C_INCLUDES := \
+	external/astl/include \
 	$(MESA_TOP)/src/mapi \
 	$(MESA_TOP)/src/mesa
 
commit 89e796aef5ca1b35ca4ff6fce9231b4125e07037
Author: Dylan Noblesmith <nobled at dreamwidth.org>
Date:   Fri Mar 16 18:38:49 2012 +0000

    intel: fix null dereference processing HiZ buffer
    
    Or technically, a near-null dereference.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=46303
    https://bugs.freedesktop.org/show_bug.cgi?id=46739
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 8d9decb75f0df564abaf9888d9fc5c77de8059cd)

diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index d3c0d70..9cdd804 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -1225,6 +1225,10 @@ intel_process_dri2_buffer_with_separate_stencil(struct intel_context *intel,
    if (!rb)
       return;
 
+   /* Check if we failed to allocate the depth miptree earlier. */
+   if (buffer->attachment == __DRI_BUFFER_HIZ && rb->mt == NULL)
+     return;
+
    /* If the renderbuffer's and DRIbuffer's regions match, then continue. */
    if ((buffer->attachment != __DRI_BUFFER_HIZ &&
 	rb->mt &&
@@ -1266,6 +1270,7 @@ intel_process_dri2_buffer_with_separate_stencil(struct intel_context *intel,
     * due to failure to allocate new storage.
     */
    if (buffer->attachment == __DRI_BUFFER_HIZ) {
+      assert(rb->mt);
       intel_miptree_release(&rb->mt->hiz_mt);
    } else {
       intel_miptree_release(&rb->mt);
@@ -1291,6 +1296,7 @@ intel_process_dri2_buffer_with_separate_stencil(struct intel_context *intel,
 
    /* Associate buffer with new storage. */
    if (buffer->attachment == __DRI_BUFFER_HIZ) {
+      assert(rb->mt);
       rb->mt->hiz_mt = mt;
    } else {
       rb->mt = mt;
commit 0bf0ba44de0cde5e041c188b409513866b7f5ab2
Author: Jakob Bornecrantz <jakob at vmware.com>
Date:   Wed Mar 21 19:19:45 2012 +0000

    docs: Add 8.0.2 md5sums
    
    Signed-off-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/docs/relnotes-8.0.2.html b/docs/relnotes-8.0.2.html
index ad1818c..d73ba9f 100644
--- a/docs/relnotes-8.0.2.html
+++ b/docs/relnotes-8.0.2.html
@@ -28,7 +28,9 @@ for DRI hardware acceleration.
 
 <h2>MD5 checksums</h2>
 <pre>
-tdb
+70eb3dc74fbfcd72f6776268ee1db52e  MesaLib-8.0.2.tar.gz
+a368104e5700707048dc3e8691a9a7a1  MesaLib-8.0.2.tar.bz2
+d5e5cdb85d2afdbcd1c0623d3ed1c54d  MesaLib-8.0.2.zip
 </pre>
 
 <h2>New features</h2>
commit 5f7204c3bbc070fce2f3351419a64362fe15a8c6
Author: Jakob Bornecrantz <jakob at vmware.com>
Date:   Wed Mar 21 16:51:06 2012 +0000

    docs: Add 8.0.2 release notes
    
    Signed-off-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/docs/news.html b/docs/news.html
index 346065c..e2fcca1 100644
--- a/docs/news.html
+++ b/docs/news.html
@@ -11,6 +11,14 @@
 <H1>News</H1>
 
 
+<h2>March 21, 2012</h2>
+
+<p>
+<a href="relnotes-8.0.2.html">Mesa 8.0.2</a> is released.
+This is a bug fix release.
+</p>
+
+
 <h2>February 16, 2012</h2>
 
 <p>
diff --git a/docs/relnotes-8.0.2.html b/docs/relnotes-8.0.2.html
new file mode 100644
index 0000000..ad1818c
--- /dev/null
+++ b/docs/relnotes-8.0.2.html
@@ -0,0 +1,158 @@
+<HTML>
+
+<head>
+<TITLE>Mesa Release Notes</TITLE>
+<link rel="stylesheet" type="text/css" href="mesa.css">
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
+</head>
+
+<BODY>
+
+<body bgcolor="#eeeeee">
+
+<H1>Mesa 8.0.2 Release Notes / March 21, 2012</H1>
+
+<p>
+Mesa 8.0.2 is a bug fix release which fixes bugs found since the 8.0.1 release.
+</p>
+<p>
+Mesa 8.0.2 implements the OpenGL 3.0 API, but the version reported by
+glGetString(GL_VERSION) depends on the particular driver being used.
+Some drivers don't support all the features required in OpenGL 3.0.
+</p>
+<p>
+See the <a href="install.html">Compiling/Installing page</a> for prerequisites
+for DRI hardware acceleration.
+</p>
+
+
+<h2>MD5 checksums</h2>
+<pre>
+tdb
+</pre>
+
+<h2>New features</h2>
+<p>None.</p>
+
+<h2>Bug fixes</h2>
+
+<p>This list is likely incomplete.</p>
+
+<ul>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=38720">Bug 38720</a> - [SNB] Trine triggers a GPU hang</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=40059">Bug 40059</a> - [SNB] hang in "Amnesia: The Dark Descent" demo</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45216">Bug 45216</a> - [SNB] GPU hang in OilRush</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=46631">Bug 46631</a> - It's really hard to hit the fast path for the fallback glReadPixels code</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=46679">Bug 46679</a> - glReadPixels on a luminance texture returns the wrong values</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=46311">Bug 46311</a> - Missing support of point size in Mesa core</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=46665">Bug 46665</a> - [PNV] webgl conformance case max texture fails</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45975">Bug 45975</a> - [Gen4 + ILK] render with pointcoord will fail to render</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=46666">Bug 46666</a> - [PNV] webgl conformance case NPOT case fails with TEXTURE_MIN_FILTER set to LINEAR</li>
+
+<!-- <li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=">Bug </a> - </li> -->
+
+</ul>
+
+
+<h2>Changes</h2>
+<p>The full set of changes can be viewed by using the following GIT command:</p>
+
+<pre>
+  git log mesa-8.0.1..mesa-8.0.2
+</pre>
+
+<p>Brian Paul (7):
+<ul>
+      <li>svga: add null vs pointer check in update_need_pipeline()</li>
+      <li>util: add mutex lock in u_debug_memory.c code</li>
+      <li>mesa: add _mesa_rebase_rgba_float/uint() functions</li>
+      <li>mesa: use _mesa_rebase_rgba_float/uint() in glReadPixels code</li>
+      <li>mesa: use _mesa_rebase_rgba_float/uint() in glGetTexImage code</li>
+      <li>mesa: fix GL_LUMINANCE handling in glGetTexImage</li>
+      <li>docs: add links to 8.0.1 release notes</li>
+</ul></p>
+
+<p>Daniel Vetter (1):
+<ul>
+      <li>i965: fixup W-tile offset computation to take swizzling into account</li>
+<ul></p>
+
+<p>Dylan Noblesmith (1):
+<ul>
+      <li>mesa: add back glGetnUniform*v() overflow error reporting</li>
+</ul></p>
+
+<p>Ian Romanick (1):
+<ul>
+      <li>docs: Add 8.0.1 release md5sums</li>
+</ul></p>
+
+<p>Jakob Bornecrantz (3):
+<ul>
+      <li>mesa: Include mesa ES mapi generated files</li>
+      <li>mesa: Bump version number to 8.0.2</li>
+      <li>docs: Add 8.0.2 release notes</li>
+</ul></p>
+
+<p>Jeremy Huddleston (3):
+<ul>
+      <li>darwin: config file cleanups</li>
+      <li>darwin: Build create_context.c</li>
+      <li>darwin: Link against libxcb</li>
+</ul></p>
+
+<p>José Fonseca (1):
+<ul>
+      <li>svga: Clamp advertised PIPE_SHADER_CAP_MAX_TEMPS to SVGA3D_TEMPREG_MAX.</li>
+</ul></p>
+
+<p>Kenneth Graunke (2):
+<ul>
+      <li>i965: Only set Last Render Target Select on the last FB write.</li>
+      <li>i965: Fix Gen6+ dynamic state upper bound on older kernels.</li>
+</ul></p>
+
+<p>Marek Olšák (1):
+<ul>
+      <li>gallium/rtasm: properly detect SSE and SSE2</li>
+</ul></p>
+
+<p>Neil Roberts (1):
+<ul>
+      <li>mesa: Don't disable fast path for normalized types</li>
+</ul></p>
+
+<p>Tom Stellard (1):
+<ul>
+      <li>r300/compiler: Fix bug when lowering KILP on r300 cards</li>
+</ul></p>
+
+<p>Yuanhan Liu (6):
+<ul>
+      <li>mesa: let GL3 buf obj queries not depend on opengl major version</li>
+      <li>tnl: let _TNL_ATTRIB_POINTSIZE do not depend on ctx->VertexProgram._Enabled</li>
+      <li>i915: fix wrong rendering of gl_PointSize on Pineview</li>
+      <li>i915: move the FALLBACK_DRAW_OFFSET check outside the drawing rect check</li>
+      <li>i965: handle gl_PointCoord for Gen4 and Gen5 platforms</li>
+      <li>i915: fallback for NPOT cubemap texture</li>
+</ul></p>
+
+<p>Zack Rusin (3):
+<ul>
+      <li>svga: fix a crash happening before setting fragment shaders.</li>
+      <li>svga: Fix stencil op mapping</li>
+      <li>svga: fix the rasterizer state resets</li>
+</ul></p>
+
+
+</body>
+</html>
diff --git a/docs/relnotes.html b/docs/relnotes.html
index d5c944a..23337cf 100644
--- a/docs/relnotes.html
+++ b/docs/relnotes.html
@@ -13,6 +13,7 @@ The release notes summarize what's new or changed in each Mesa release.
 </p>
 
 <UL>
+<LI><A HREF="relnotes-8.0.2.html">8.0.2 release notes</A>
 <LI><A HREF="relnotes-8.0.1.html">8.0.1 release notes</A>
 <LI><A HREF="relnotes-8.0.html">8.0 release notes</A>
 <LI><A HREF="relnotes-7.11.html">7.11 release notes</A>
commit dc20396a1416014c6762a3204bee7cd96cafa6f3
Author: Jakob Bornecrantz <jakob at vmware.com>
Date:   Tue Mar 20 13:51:39 2012 +0000

    mesa: Bump version number to 8.0.2
    
    Signed-off-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/Makefile b/Makefile
index 279dd07..6084e73 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ ultrix-gcc:
 
 # Rules for making release tarballs
 
-PACKAGE_VERSION=8.0.1
+PACKAGE_VERSION=8.0.2
 PACKAGE_DIR = Mesa-$(PACKAGE_VERSION)
 PACKAGE_NAME = MesaLib-$(PACKAGE_VERSION)
 
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 50f6adb..bc0494c 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -34,8 +34,8 @@ struct gl_context;
 /* Mesa version */
 #define MESA_MAJOR 8
 #define MESA_MINOR 0
-#define MESA_PATCH 1
-#define MESA_VERSION_STRING "8.0.1"
+#define MESA_PATCH 2
+#define MESA_VERSION_STRING "8.0.2"
 
 /* To make version comparison easy */
 #define MESA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
commit 770f785a6f30e5295ababe44a8e9449ee0be640a
Author: Jakob Bornecrantz <jakob at vmware.com>
Date:   Tue Mar 20 13:24:50 2012 +0000

    mesa: Include mesa ES mapi generated files
    
    Signed-off-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/Makefile b/Makefile
index 81ae944..279dd07 100644
--- a/Makefile
+++ b/Makefile
@@ -199,6 +199,12 @@ EXTRA_FILES = \
 	src/glsl/glcpp/glcpp-lex.c			\
 	src/glsl/glcpp/glcpp-parse.c			\
 	src/glsl/glcpp/glcpp-parse.h			\
+	src/mesa/main/api_exec_es1.c			\
+	src/mesa/main/api_exec_es1_dispatch.h		\
+	src/mesa/main/api_exec_es1_remap_helper.h	\
+	src/mesa/main/api_exec_es2.c			\
+	src/mesa/main/api_exec_es2_dispatch.h		\
+	src/mesa/main/api_exec_es2_remap_helper.h	\
 	src/mesa/program/lex.yy.c			\
 	src/mesa/program/program_parse.tab.c		\
 	src/mesa/program/program_parse.tab.h
commit 4b52be53a42f841c400879df98eb0210508ba573
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Mar 21 11:42:33 2012 -0600

    docs: add links to 8.0.1 release notes

diff --git a/docs/news.html b/docs/news.html
index 472f98b..346065c 100644
--- a/docs/news.html
+++ b/docs/news.html
@@ -11,6 +11,14 @@
 <H1>News</H1>
 
 
+<h2>February 16, 2012</h2>
+
+<p>
+<a href="relnotes-8.0.1.html">Mesa 8.0.1</a> is released.
+This is a bug fix release.
+</p>
+
+
 <h2>February 9, 2012</h2>
 
 <p>
diff --git a/docs/relnotes.html b/docs/relnotes.html
index 1dd5442..d5c944a 100644
--- a/docs/relnotes.html
+++ b/docs/relnotes.html
@@ -13,6 +13,7 @@ The release notes summarize what's new or changed in each Mesa release.
 </p>
 
 <UL>
+<LI><A HREF="relnotes-8.0.1.html">8.0.1 release notes</A>
 <LI><A HREF="relnotes-8.0.html">8.0 release notes</A>
 <LI><A HREF="relnotes-7.11.html">7.11 release notes</A>
 <LI><A HREF="relnotes-7.10.3.html">7.10.3 release notes</A>
commit e26aa8c660a025d448a6d297846940a225ed46ac
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Fri Mar 2 21:38:44 2012 +0100

    i965: fixup W-tile offset computation to take swizzling into account
    
    There's even a comment in the code containing the right swizzling
    computations!
    
    Previously this has not been noticed because we need to manually
    enabled swizzling on snb/ivb (kernel 3.4 will do that) and we
    don't use the separate stencil on ilk (where the bios enables
    swizzling). This fixes
    
    piglit ./bin/fbo-stencil  readpixels GL_DEPTH32F_STENCIL8 -auto
    
    on recent drm-intel-next kernels.
    
    Also remove the comment about ivb, it's stale now.
    
    Swizzling detection is done by allocating a temporary x-tiled
    buffer object. Unfortunately kernels before v3.2 lie on snb/ivb
    because they claim that swizzling is enable, but it isn't. The
    kernel commit that fixes this for backport to pre-v3.2 is
    
    commit acc83eb5a1e0ae7dbbf89ca2a1a943ade224bb84
    Author: Daniel Vetter <daniel.vetter at ffwll.ch>
    Date:   Mon Sep 12 20:49:16 2011 +0200
    
        drm/i915: fix swizzling on gen6+
    
    But if the kernel doesn't lie, this now works on swizzling and
    not swizzling machines.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit f172eae8b23d0612865895c52af745021ae20a4c)

diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index d4bb8c7..d3c0d70 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -629,6 +629,7 @@ intelInitContext(struct intel_context *intel,
    intel->must_use_separate_stencil = intel->intelScreen->hw_must_use_separate_stencil;
    intel->has_hiz = intel->intelScreen->hw_has_hiz;
    intel->has_llc = intel->intelScreen->hw_has_llc;
+   intel->has_swizzling = intel->intelScreen->hw_has_swizzling;
 
    memset(&ctx->TextureFormatSupported,
 	  0, sizeof(ctx->TextureFormatSupported));
diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index 150e55f..ef024b1 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -214,6 +214,7 @@ struct intel_context
    bool must_use_separate_stencil;
    bool has_hiz;
    bool has_llc;
+   bool has_swizzling;
 
    int urb_size;
 
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index 5290da4..3601f5e 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -830,7 +830,8 @@ intel_miptree_map_s8(struct intel_context *intel,
 	 for (uint32_t x = 0; x < map->w; x++) {
 	    ptrdiff_t offset = intel_offset_S8(mt->region->pitch,
 	                                       x + image_x + map->x,
-	                                       y + image_y + map->y);
+	                                       y + image_y + map->y,
+					       intel->has_swizzling);
 	    untiled_s8_map[y * map->w + x] = tiled_s8_map[offset];
 	 }
       }
@@ -865,7 +866,8 @@ intel_miptree_unmap_s8(struct intel_context *intel,
 	 for (uint32_t x = 0; x < map->w; x++) {
 	    ptrdiff_t offset = intel_offset_S8(mt->region->pitch,
 	                                       x + map->x,
-	                                       y + map->y);
+	                                       y + map->y,
+					       intel->has_swizzling);
 	    tiled_s8_map[offset] = untiled_s8_map[y * map->w + x];
 	 }
       }
@@ -925,7 +927,8 @@ intel_miptree_map_depthstencil(struct intel_context *intel,
 	    int map_x = map->x + x, map_y = map->y + y;
 	    ptrdiff_t s_offset = intel_offset_S8(s_mt->region->pitch,
 						 map_x + s_image_x,
-						 map_y + s_image_y);
+						 map_y + s_image_y,
+						 intel->has_swizzling);
 	    ptrdiff_t z_offset = ((map_y + z_image_y) * z_mt->region->pitch +
 				  (map_x + z_image_x));
 	    uint8_t s = s_map[s_offset];
@@ -983,7 +986,8 @@ intel_miptree_unmap_depthstencil(struct intel_context *intel,
 	 for (uint32_t x = 0; x < map->w; x++) {
 	    ptrdiff_t s_offset = intel_offset_S8(s_mt->region->pitch,
 						 x + s_image_x + map->x,
-						 y + s_image_y + map->y);
+						 y + s_image_y + map->y,
+						 intel->has_swizzling);
 	    ptrdiff_t z_offset = ((y + z_image_y) * z_mt->region->pitch +
 				  (x + z_image_x));
 
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index e6b749a..e6e79ef 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -650,6 +650,30 @@ intel_override_separate_stencil(struct intel_screen *screen)
    }
 }
 
+static bool
+intel_detect_swizzling(struct intel_screen *screen)
+{
+   drm_intel_bo *buffer;
+   unsigned long flags = 0;
+   unsigned long aligned_pitch;
+   uint32_t tiling = I915_TILING_X;
+   uint32_t swizzle_mode = 0;
+
+   buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test",
+				     64, 64, 4,
+				     &tiling, &aligned_pitch, flags);
+   if (buffer == NULL)
+      return false;
+
+   drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode);
+   drm_intel_bo_unreference(buffer);
+
+   if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE)
+      return false;
+   else
+      return true;
+}
+
 /**
  * This is the driver specific part of the createNewScreen entry point.
  * Called when using DRI2.
@@ -748,6 +772,8 @@ __DRIconfig **intelInitScreen2(__DRIscreen *psp)
    if (!intel_init_bufmgr(intelScreen))
        return false;
 
+   intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen);
+
    psp->extensions = intelScreenExtensions;
 
    msaa_samples_array[0] = 0;
diff --git a/src/mesa/drivers/dri/intel/intel_screen.h b/src/mesa/drivers/dri/intel/intel_screen.h
index a6baf16..1998f7e 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.h
+++ b/src/mesa/drivers/dri/intel/intel_screen.h
@@ -117,6 +117,7 @@ struct intel_screen
    bool kernel_has_gen7_sol_reset;
 
    bool hw_has_llc;
+   bool hw_has_swizzling;
 
    bool no_vbo;
    dri_bufmgr *bufmgr;
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 3645720..b0dc720 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -65,7 +65,7 @@
  *    mesa: Fix return type of  _mesa_get_format_bytes() (#37351)
  */
 intptr_t
-intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y)
+intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y, bool swizzled)
 {
    uint32_t tile_size = 4096;
    uint32_t tile_width = 64;
@@ -90,22 +90,16 @@ intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y)
                +   2 * (byte_y % 2)
                +   1 * (byte_x % 2);
 
-   /*
-    * Errata for Gen5:
-    *
-    * An additional offset is needed which is not documented in the PRM.
-    *
-    * if ((byte_x / 8) % 2 == 1) {
-    *    if ((byte_y / 8) % 2) == 0) {
-    *       u += 64;
-    *    } else {
-    *       u -= 64;
-    *    }
-    * }
-    *
-    * The offset is expressed more tersely as
-    * u += ((int) x & 0x8) * (8 - (((int) y & 0x8) << 1));
-    */
+   if (swizzled) {
+      /* adjust for bit6 swizzling */
+      if (((byte_x / 8) % 2) == 1) {
+	 if (((byte_y / 8) % 2) == 0) {
+	    u += 64;
+	 } else {
+	    u -= 64;
+	 }
+      }
+   }
 
    return u;
 }
diff --git a/src/mesa/drivers/dri/intel/intel_span.h b/src/mesa/drivers/dri/intel/intel_span.h
index b2bd416..e521869 100644
--- a/src/mesa/drivers/dri/intel/intel_span.h
+++ b/src/mesa/drivers/dri/intel/intel_span.h
@@ -38,6 +38,6 @@ extern void intelSpanRenderStart(struct gl_context * ctx);
 
 void intel_map_vertex_shader_textures(struct gl_context *ctx);
 void intel_unmap_vertex_shader_textures(struct gl_context *ctx);
-intptr_t intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y);
+intptr_t intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y, bool swizzled);
 
 #endif
commit 2f5182cfcf2eaf214f2c2a14406d7849668809b8
Author: Eugeni Dodonov <eugeni.dodonov at intel.com>
Date:   Wed Feb 1 18:24:23 2012 -0200

    intel: check for LLC support when reading maps
    
    This checks for advertised LLC support by the GPU instead of relying on
    the GPU generation for detection.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Signed-off-by: Eugeni Dodonov <eugeni.dodonov at intel.com>
    (cherry picked from commit 84e5f1c635899c657da58ca51d5e841354e9de9c)

diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index eae79c1..5290da4 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -1052,7 +1052,7 @@ intel_miptree_map(struct intel_context *intel,
       intel_miptree_map_s8(intel, mt, map, level, slice);
    } else if (mt->stencil_mt) {
       intel_miptree_map_depthstencil(intel, mt, map, level, slice);
-   } else if (intel->gen >= 6 &&
+   } else if (intel->has_llc &&
 	      !(mode & GL_MAP_WRITE_BIT) &&
 	      !mt->compressed &&
 	      mt->region->tiling == I915_TILING_X) {
commit 7fe667a18dc864f4aa90417f16d791a898937c48
Author: Eugeni Dodonov <eugeni.dodonov at intel.com>
Date:   Wed Feb 1 18:06:53 2012 -0200

    intel: verify if hardware has LLC support
    
    Rely on libdrm HAS_LLC parameter to verify if hardware supports it. In
    case the libdrm version does not supports this check, fallback to older
    way of detecting it which assumed that GPUs newer than GEN6 have it.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Signed-off-by: Eugeni Dodonov <eugeni.dodonov at intel.com>
    (cherry picked from commit 7def293204977c41ea35198af147f743a31b1889)

diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index ffd9536..d4bb8c7 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -628,6 +628,7 @@ intelInitContext(struct intel_context *intel,
    intel->has_separate_stencil = intel->intelScreen->hw_has_separate_stencil;
    intel->must_use_separate_stencil = intel->intelScreen->hw_must_use_separate_stencil;
    intel->has_hiz = intel->intelScreen->hw_has_hiz;
+   intel->has_llc = intel->intelScreen->hw_has_llc;
 
    memset(&ctx->TextureFormatSupported,
 	  0, sizeof(ctx->TextureFormatSupported));
diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index 4d4e030..150e55f 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -213,6 +213,7 @@ struct intel_context
    bool has_separate_stencil;
    bool must_use_separate_stencil;
    bool has_hiz;
+   bool has_llc;
 
    int urb_size;
 
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 6990265..e6b749a 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -723,6 +723,14 @@ __DRIconfig **intelInitScreen2(__DRIscreen *psp)
    intelScreen->hw_has_hiz = intelScreen->gen >= 6;
    intelScreen->dri2_has_hiz = INTEL_DRI2_HAS_HIZ_UNKNOWN;
 
+#if defined(I915_PARAM_HAS_LLC)
+   intelScreen->hw_has_llc =
+      intel_get_boolean(intelScreen->driScrnPriv,
+              I915_PARAM_HAS_LLC);
+#else
+   intelScreen->hw_has_llc = intelScreen->gen >= 6;
+#endif
+
    intel_override_hiz(intelScreen);
    intel_override_separate_stencil(intelScreen);
 
diff --git a/src/mesa/drivers/dri/intel/intel_screen.h b/src/mesa/drivers/dri/intel/intel_screen.h
index 6c6b516..a6baf16 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.h
+++ b/src/mesa/drivers/dri/intel/intel_screen.h
@@ -116,6 +116,8 @@ struct intel_screen
 
    bool kernel_has_gen7_sol_reset;
 
+   bool hw_has_llc;
+
    bool no_vbo;
    dri_bufmgr *bufmgr;
    struct _mesa_HashTable *named_regions;
commit 3d036f3f0aa7360c58d76b3f5114e1cf8c32260c
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Feb 29 12:32:41 2012 -0800

    i965: Fix Gen6+ dynamic state upper bound on older kernels.
    
    Kernels prior to 271d81b84171d84723357ae6d172ec16b0d8139c (March 2011)
    don't support relocations outside of the target buffer object.  Rather
    than guarding this with a I915_PARAM_HAS_RELAXED_DELTA check, just
    smash the bound to 0xfffff001 like we do on Ironlake.
    
    This effectively gives us no upper bound check, just like we did prior
    to commit 271d81b84171d84723357ae6d172ec16b0d8139c.
    
    Daniel Vetter would also like to mention that this relies on the guard
    page at the end of the GTT.
    
    Fixes a regression since 271d81b84171d84723357ae6d172ec16b0d8139c.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46766
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    (cherry picked from commit b2ace06cbbbb1021e2d7ace12a985c6406821939)

diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index 0343ae1..07462d3 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -774,8 +774,7 @@ static void upload_state_base_address( struct brw_context *brw )
 	* If this isn't programmed to a real bound, the sampler border color
 	* pointer is rejected, causing border color to mysteriously fail.
 	*/
-       OUT_RELOC(intel->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
-		 intel->batch.bo->size | 1);
+       OUT_BATCH(0xfffff001);
        OUT_BATCH(1); /* Indirect object upper bound */
        OUT_BATCH(1); /* Instruction access upper bound */
        ADVANCE_BATCH();
commit b056fc0741b6341494ad837affc597d46eea9e9a
Author: Dylan Noblesmith <nobled at dreamwidth.org>
Date:   Thu Dec 22 21:05:38 2011 +0000

    mesa: add back glGetnUniform*v() overflow error reporting
    
    The error was removed in:
    
    commit 719909698c67c287a393d2380278e7b7495ae018
    Author: Ian Romanick <ian.d.romanick at intel.com>
    Date:   Tue Oct 18 16:01:49 2011 -0700
    
        mesa: Rewrite the way uniforms are tracked and handled
    
    The GL_ARB_robustness spec doesn't say the implementation
    should truncate the output, so just return after setting
    the required error like it did before the above commit.
    
    Also fixup an old comment and add an assert.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit b536ac6b2bc54ad9bb6e58fbd307055e419a288f)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 869f7d3..991df78 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -203,10 +203,18 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
       const union gl_constant_value *const src =
 	 &uni->storage[offset * elements];
 
-      unsigned bytes = sizeof(uni->storage[0]) * elements;
-      if (bytes > (unsigned) bufSize) {
-	 elements = bufSize / sizeof(uni->storage[0]);
-	 bytes = bufSize;
+      assert(returnType == GLSL_TYPE_FLOAT || returnType == GLSL_TYPE_INT ||
+             returnType == GLSL_TYPE_UINT);
+      /* The three (currently) supported types all have the same size,
+       * which is of course the same as their union. That'll change
+       * with glGetUniformdv()...
+       */
+      unsigned bytes = sizeof(src[0]) * elements;
+      if (bufSize < 0 || bytes > (unsigned) bufSize) {
+	 _mesa_error( ctx, GL_INVALID_OPERATION,
+	             "glGetnUniform*vARB(out of bounds: bufSize is %d,"
+	             " but %u bytes are required)", bufSize, bytes );
+	 return;
       }
 
       /* If the return type and the uniform's native type are "compatible,"
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index e0214a8..be1e172 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -479,7 +479,7 @@ _mesa_GetnUniformdvARB(GLhandleARB program, GLint location,
    (void) params;
 
    /*
-   _mesa_get_uniform(ctx, program, location, bufSize, GL_DOUBLE, params);
+   _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_DOUBLE, params);
    */
    _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformdvARB"
                "(GL_ARB_gpu_shader_fp64 not implemented)");
commit adcb1806717f90f6acff2169a4a434997f433597
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Wed Feb 29 15:04:45 2012 +0800

    i915: fallback for NPOT cubemap texture
    
    Although some hardware support NPOT cubemap, but it seems we don't know
    the right layout for NPOT cubemap. Thus seems we need do fallback for
    other platforms as well.
    
    See comments inline the code for more detailed info.
    
    v2: give a more detailed info about why we need fallback for other
        platfroms as well.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46666
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    (cherry picked from commit 40c995c1fd7865f1b25765aa783fdadbf948b3dd)

diff --git a/src/mesa/drivers/dri/i915/i915_texstate.c b/src/mesa/drivers/dri/i915/i915_texstate.c
index 9022548..fd63a69 100644
--- a/src/mesa/drivers/dri/i915/i915_texstate.c
+++ b/src/mesa/drivers/dri/i915/i915_texstate.c
@@ -319,6 +319,28 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
            ((wt != GL_CLAMP) && (wt != GL_CLAMP_TO_EDGE))))
           return false;
 
+      /*
+       * According to 3DSTATE_MAP_STATE at page of 104 in Bspec
+       * Vol3d 3D Instructions:
+       *   [DevGDG and DevAlv]: Must be a power of 2 for cube maps.
+       *   [DevLPT, DevCST and DevBLB]: If not a power of 2, cube maps
+       *      must have all faces enabled.
+       *
+       * But, as I tested on pineview(DevBLB derived), the rendering is
+       * bad(you will find the color isn't samplered right in some
+       * fragments). After checking, it seems that the texture layout is
+       * wrong: making the width and height align of 4(although this
+       * doesn't make much sense) will fix this issue and also broke some
+       * others. Well, Bspec mentioned nothing about the layout alignment
+       * and layout for NPOT cube map.  I guess the Bspec just assume it's
+       * a POT cube map.
+       *
+       * Thus, I guess we need do this for other platforms as well.
+       */
+      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
+          !is_power_of_two(firstImage->Height))
+         return false;
+
       state[I915_TEXREG_SS3] = ss3;     /* SS3_NORMALIZED_COORDS */
 
       state[I915_TEXREG_SS3] |=
commit d982036c3ae1350c60874f5c4ea13c1867ed1c2c
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Mar 16 17:07:06 2012 -0700

    darwin: Link against libxcb
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit 90a51753c40465c1253c612e0fef2aef96441668)

diff --git a/configs/darwin b/configs/darwin
index fe721d7..721fbc7 100644
--- a/configs/darwin
+++ b/configs/darwin
@@ -47,7 +47,7 @@ GLW_LIB_GLOB = lib$(GLW_LIB).*dylib
 OSMESA_LIB_GLOB = lib$(OSMESA_LIB).*dylib
 VG_LIB_GLOB = lib$(VG_LIB).*dylib
 
-GL_LIB_DEPS = -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXext -lm -lpthread $(EXTRA_LDFLAGS)
+GL_LIB_DEPS = -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11-xcb -lxcb -lX11 -lXext $(EXTRA_LDFLAGS)
 OSMESA_LIB_DEPS = $(EXTRA_LDFLAGS)
 GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(EXTRA_LDFLAGS)
 GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXt $(EXTRA_LDFLAGS)
commit 63c8f7142c49007e9cb49ffcd73d85f8f4d71497
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Mar 16 17:03:54 2012 -0700

    darwin: Build create_context.c
    
    Fixes a build regression from: 588042a8ec4ea91a952c07a0768516fd590758f4
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit f9e1295cffc3cf096611e193cca016326715e6ca)

diff --git a/src/glx/apple/Makefile b/src/glx/apple/Makefile
index 66e6658..dc64295 100644
--- a/src/glx/apple/Makefile
+++ b/src/glx/apple/Makefile
@@ -35,6 +35,7 @@ SOURCES = \
 	apple_xgl_api_stereo.c \
 	apple_xgl_api_viewport.c \
 	appledri.c \
+	../create_context.c \
 	../clientattrib.c \
 	../compsize.c \
 	../glxconfig.c \
diff --git a/src/glx/create_context.c b/src/glx/create_context.c
index 714f0e5..a1a55b3 100644
--- a/src/glx/create_context.c
+++ b/src/glx/create_context.c
@@ -80,8 +80,13 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
 					       &dummy_err);
    }
 
-   if (gc == NULL)
+   if (gc == NULL) {
+#ifdef GLX_USE_APPLEGL
+      gc = applegl_create_context(psc, cfg, share, 0);
+#else
       gc = indirect_create_context(psc, cfg, share, 0);
+#endif
+   }
 
    gc->xid = xcb_generate_id(c);
    gc->share_xid = (share != NULL) ? share->xid : 0;
commit 485d1c491aabb30f29f52ec72842af2e6a649c6b
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Mar 16 17:01:01 2012 -0700

    darwin: config file cleanups
    
    Set our default compiler based on what our installed XCode prefers
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit 61f6aff5d9136c91ca4a16de04c7ae673e9433df)

diff --git a/configs/darwin b/configs/darwin
index e2ca70a..fe721d7 100644
--- a/configs/darwin
+++ b/configs/darwin
@@ -9,8 +9,8 @@ INSTALL_DIR = /usr/X11
 X11_DIR = $(INSTALL_DIR)
 
 # Compiler and flags
-CC = gcc
-CXX = g++
+CC = $(shell xcrun -find cc)
+CXX = $(shell xcrun -find c++)
 PIC_FLAGS = -fPIC
 DEFINES =  -D_DARWIN_C_SOURCE -DPTHREADS -D_GNU_SOURCE \
 	   -DGLX_ALIAS_UNSUPPORTED \
@@ -24,11 +24,14 @@ DEFINES =  -D_DARWIN_C_SOURCE -DPTHREADS -D_GNU_SOURCE \
 # -DIN_DRI_DRIVER
 
 ARCH_FLAGS += $(RC_CFLAGS)
+INCLUDE_FLAGS = -I$(INSTALL_DIR)/include -I$(X11_DIR)/include
+OPT_FLAGS = -g3 -gdwarf-2 -Os -ffast-math -fno-strict-aliasing
+WARN_FLAGS = -Wall -Wmissing-prototypes
 
-CFLAGS =  -ggdb3 -Os -Wall -Wmissing-prototypes -std=c99 -ffast-math -fno-strict-aliasing -fvisibility=hidden \
-	-I$(INSTALL_DIR)/include -I$(X11_DIR)/include $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES)
-CXXFLAGS =  -ggdb3 -Os -Wall -fno-strict-aliasing -fvisibility=hidden \
-	-I$(INSTALL_DIR)/include -I$(X11_DIR)/include $(OPT_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES)
+CFLAGS = -std=c99 -fvisibility=hidden \
+	$(OPT_FLAGS) $(WARN_FLAGS) $(INCLUDE_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES) $(EXTRA_CFLAGS)
+CXXFLAGS = -fvisibility=hidden \
+	$(OPT_FLAGS) $(WARN_FLAGS) $(INCLUDE_FLAGS) $(PIC_FLAGS) $(ARCH_FLAGS) $(ASM_FLAGS) $(DEFINES) $(EXTRA_CFLAGS)
 
 # Library names (actual file names)
 GL_LIB_NAME = lib$(GL_LIB).dylib
@@ -44,10 +47,10 @@ GLW_LIB_GLOB = lib$(GLW_LIB).*dylib
 OSMESA_LIB_GLOB = lib$(OSMESA_LIB).*dylib
 VG_LIB_GLOB = lib$(VG_LIB).*dylib
 
-GL_LIB_DEPS = -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXext -lm -lpthread
-OSMESA_LIB_DEPS =
-GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB)
-GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXt
+GL_LIB_DEPS = -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXext -lm -lpthread $(EXTRA_LDFLAGS)
+OSMESA_LIB_DEPS = $(EXTRA_LDFLAGS)
+GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(EXTRA_LDFLAGS)
+GLW_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) -L$(INSTALL_DIR)/$(LIB_DIR) -L$(X11_DIR)/$(LIB_DIR) -lX11 -lXt $(EXTRA_LDFLAGS)
 
 SRC_DIRS = glsl mapi/glapi mapi/vgapi glx/apple mesa gallium glu
 GLU_DIRS = sgi
diff --git a/configs/darwin-fat-intel b/configs/darwin-fat-intel
new file mode 100644
index 0000000..273ae3d
--- /dev/null
+++ b/configs/darwin-fat-intel
@@ -0,0 +1,7 @@
+# Configuration for Darwin / MacOS X, making 32bit and 64bit fat dynamic libs for intel
+
+RC_CFLAGS=-arch i386 -arch x86_64
+
+include $(TOP)/configs/darwin
+
+CONFIG_NAME = darwin-fat-intel
commit 7b1fbc688999fd568e65211d79d7678562061594
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Mon Feb 27 15:46:32 2012 +0800

    i965: handle gl_PointCoord for Gen4 and Gen5 platforms
    
    This patch add the support of gl_PointCoord gl builtin variable for
    platform gen4 and gen5(ILK).
    
    Unlike gen6+, we don't have a hardware support of gl_PointCoord, means
    hardware will not calculate the interpolation coefficient for you.
    Instead, you should handle it yourself in sf shader stage.
    
    But badly, gl_PointCoord is a FS instead of VS builtin variable, thus
    it's not included in c.vue_map generated in VS stage. Thus the current
    code doesn't aware of this attribute. And to handle it correctly, we
    need add it to c.vue_map manually to let SF shader generate the needed
    interpolation coefficient for FS shader. SF stage has it's own copy of
    vue_map, thus I think it's safe to do it manually.
    
    Since handling gl_PointCoord for gen4 and gen5 platforms is somehow a
    little special, I added a lot of comments and hope I didn't overdo it ;)
    
    v2: add a /* _NEW_BUFFERS */ comment to note the state flag dependency
        and also add the _NEW_BUFFERS dirty mask (Eric).
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45975
    Piglit: glsl-fs-pointcoord and fbo-gl_pointcoord
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 43af02ac731dac7d80f7e47feb0c80e4da156769)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 72e5059..3cfc54b 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -290,6 +290,12 @@ typedef enum
    BRW_VERT_RESULT_NDC = VERT_RESULT_MAX,
    BRW_VERT_RESULT_HPOS_DUPLICATE,
    BRW_VERT_RESULT_PAD,
+   /*
+    * It's actually not a vert_result but just a _mark_ to let sf aware that
+    * he need do something special to handle gl_PointCoord builtin variable
+    * correctly. see compile_sf_prog() for more info.
+    */
+   BRW_VERT_RESULT_PNTC,
    BRW_VERT_RESULT_MAX
 } brw_vert_result;
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 0de1eef..20b57bd 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -710,6 +710,15 @@ fs_visitor::calculate_urb_setup()
 	       urb_setup[fp_index] = urb_next++;
 	 }
       }
+
+      /*
+       * It's a FS only attribute, and we did interpolation for this attribute
+       * in SF thread. So, count it here, too.
+       *
+       * See compile_sf_prog() for more info.
+       */
+      if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(FRAG_ATTRIB_PNTC))
+         urb_setup[FRAG_ATTRIB_PNTC] = urb_next++;
    }
 
    /* Each attribute is 4 setup channels, each of which is half a reg. */
diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c
index 54c27f9..ccef3e83 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.c
+++ b/src/mesa/drivers/dri/i965/brw_sf.c
@@ -64,6 +64,16 @@ static void compile_sf_prog( struct brw_context *brw,
 
    c.key = *key;
    brw_compute_vue_map(&c.vue_map, intel, c.key.userclip_active, c.key.attrs);
+   if (c.key.do_point_coord) {
+      /*
+       * gl_PointCoord is a FS instead of VS builtin variable, thus it's
+       * not included in c.vue_map generated in VS stage. Here we add
+       * it manually to let SF shader generate the needed interpolation
+       * coefficient for FS shader.
+       */
+      c.vue_map.vert_result_to_slot[BRW_VERT_RESULT_PNTC] = c.vue_map.num_slots;
+      c.vue_map.slot_to_vert_result[c.vue_map.num_slots++] = BRW_VERT_RESULT_PNTC;
+   }
    c.urb_entry_read_offset = brw_sf_compute_urb_entry_read_offset(intel);
    c.nr_attr_regs = (c.vue_map.num_slots + 1)/2 - c.urb_entry_read_offset;
    c.nr_setup_regs = c.nr_attr_regs;
@@ -125,6 +135,8 @@ brw_upload_sf_prog(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
    struct brw_sf_prog_key key;
+   /* _NEW_BUFFERS */
+   bool render_to_fbo = ctx->DrawBuffer->Name != 0;
 
    memset(&key, 0, sizeof(key));
 
@@ -167,7 +179,15 @@ brw_upload_sf_prog(struct brw_context *brw)
 	    key.point_sprite_coord_replace |= (1 << i);
       }
    }
-   key.sprite_origin_lower_left = (ctx->Point.SpriteOrigin == GL_LOWER_LEFT);
+   if (brw->fragment_program->Base.InputsRead & BITFIELD64_BIT(FRAG_ATTRIB_PNTC))
+      key.do_point_coord = 1;
+   /*
+    * Window coordinates in a FBO are inverted, which means point
+    * sprite origin must be inverted, too.
+    */
+   if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo)
+      key.sprite_origin_lower_left = true;
+
    /* _NEW_LIGHT */
    key.do_flat_shading = (ctx->Light.ShadeModel == GL_FLAT);
    key.do_twoside_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
@@ -176,10 +196,9 @@ brw_upload_sf_prog(struct brw_context *brw)
    if (key.do_twoside_color) {
       /* If we're rendering to a FBO, we have to invert the polygon
        * face orientation, just as we invert the viewport in
-       * sf_unit_create_from_key().  ctx->DrawBuffer->Name will be
-       * nonzero if we're rendering to such an FBO.
+       * sf_unit_create_from_key().
        */
-      key.frontface_ccw = (ctx->Polygon.FrontFace == GL_CCW) ^ (ctx->DrawBuffer->Name != 0);
+      key.frontface_ccw = (ctx->Polygon.FrontFace == GL_CCW) != render_to_fbo;
    }
 
    if (!brw_search_cache(&brw->cache, BRW_SF_PROG,
@@ -192,7 +211,8 @@ brw_upload_sf_prog(struct brw_context *brw)
 
 const struct brw_tracked_state brw_sf_prog = {
    .dirty = {
-      .mesa  = (_NEW_HINT | _NEW_LIGHT | _NEW_POLYGON | _NEW_POINT | _NEW_TRANSFORM),
+      .mesa  = (_NEW_HINT | _NEW_LIGHT | _NEW_POLYGON | _NEW_POINT |
+                _NEW_TRANSFORM | _NEW_BUFFERS),
       .brw   = (BRW_NEW_REDUCED_PRIMITIVE),
       .cache = CACHE_NEW_VS_PROG
    },
diff --git a/src/mesa/drivers/dri/i965/brw_sf.h b/src/mesa/drivers/dri/i965/brw_sf.h
index 4ef0240..f908fc0 100644
--- a/src/mesa/drivers/dri/i965/brw_sf.h
+++ b/src/mesa/drivers/dri/i965/brw_sf.h
@@ -52,6 +52,7 @@ struct brw_sf_prog_key {
    GLuint do_flat_shading:1;
    GLuint frontface_ccw:1;
    GLuint do_point_sprite:1;
+   GLuint do_point_coord:1;
    GLuint sprite_origin_lower_left:1;
    GLuint userclip_active:1;
 };
diff --git a/src/mesa/drivers/dri/i965/brw_sf_emit.c b/src/mesa/drivers/dri/i965/brw_sf_emit.c
index 1ee0098..ff6383b 100644
--- a/src/mesa/drivers/dri/i965/brw_sf_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_sf_emit.c
@@ -386,6 +386,8 @@ calculate_point_sprite_mask(struct brw_sf_compile *c, GLuint reg)
       if (c->key.point_sprite_coord_replace & (1 << (vert_result1 - VERT_RESULT_TEX0)))
 	 pc |= 0x0f;
    }
+   if (vert_result1 == BRW_VERT_RESULT_PNTC)
+      pc |= 0x0f;
 
    vert_result2 = vert_reg_to_vert_result(c, reg, 1);
    if (vert_result2 >= VERT_RESULT_TEX0 && vert_result2 <= VERT_RESULT_TEX7) {
@@ -393,6 +395,8 @@ calculate_point_sprite_mask(struct brw_sf_compile *c, GLuint reg)
                                                      VERT_RESULT_TEX0)))
          pc |= 0xf0;
    }
+   if (vert_result2 == BRW_VERT_RESULT_PNTC)
+      pc |= 0xf0;
 
    return pc;
 }
commit 7f8ac0e70f265e1d4ec411e7165255c7270af8c2
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Tue Mar 6 14:40:32 2012 +0800

    i915: move the FALLBACK_DRAW_OFFSET check outside the drawing rect check
    
    We have to do fallback when the 'Clipped Drawing Rectangle X/Y Max'
    exceed the hardware's limit no matter the drawing rectangle offset
    changed or not.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46665
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit cf2f9ef015c312ecaa6656519602ae535f7ce9d7)

diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c
index 11e8a35..e78dbc8 100644
--- a/src/mesa/drivers/dri/i915/i915_vtbl.c
+++ b/src/mesa/drivers/dri/i915/i915_vtbl.c
@@ -665,12 +665,11 @@ i915_set_draw_region(struct intel_context *intel,
 
    draw_offset = (draw_y << 16) | draw_x;
 
+   FALLBACK(intel, I915_FALLBACK_DRAW_OFFSET,
+            (ctx->DrawBuffer->Width + draw_x > 2048) ||
+            (ctx->DrawBuffer->Height + draw_y > 2048));
    /* When changing drawing rectangle offset, an MI_FLUSH is first required. */
    if (draw_offset != i915->last_draw_offset) {
-      FALLBACK(intel, I915_FALLBACK_DRAW_OFFSET,
-               (ctx->DrawBuffer->Width + draw_x > 2048) ||
-               (ctx->DrawBuffer->Height + draw_y > 2048));
-
       state->Buffer[I915_DESTREG_DRAWRECT0] = MI_FLUSH | INHIBIT_FLUSH_RENDER_CACHE;
       i915->last_draw_offset = draw_offset;
    } else
commit 5cfc7d1167edc97b81118652cd1cefaf94b997e5
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Thu Feb 23 14:19:19 2012 +0800

    i915: fix wrong rendering of gl_PointSize on Pineview
    
    The current code would ignore the point size specified by gl_PointSize
    builtin variable in vertex shader on Pineview. This patch servers as
    fixing that.
    
    This patch fixes the following issues on Pineview:
    webglc: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/tests/conformance/rendering/point-size.html
    piglit: glsl-vs-point-size
    
    NOTE: This is a candidate for stable release branches.
    
    v2: pick Eric's nice tip for fixing this issue in hardware rendering.
    v3: the last arg of EMIT_ATTR specify the size in _byte_. (Eric)
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 058fc6521e3bc483bc948cc90dc5ee3b08d6ec64)

diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c
index 4f016a3..5b7e93e 100644
--- a/src/mesa/drivers/dri/i915/i915_fragprog.c
+++ b/src/mesa/drivers/dri/i915/i915_fragprog.c
@@ -1361,6 +1361,10 @@ i915ValidateFragmentProgram(struct i915_context *i915)
       EMIT_ATTR(_TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, S4_VFMT_XYZ, 12);
    }
 
+   /* Handle gl_PointSize builtin var here */
+   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled)
+      EMIT_ATTR(_TNL_ATTRIB_POINTSIZE, EMIT_1F, S4_VFMT_POINT_WIDTH, 4);
+
    if (inputsRead & FRAG_BIT_COL0) {
       intel->coloroffset = offset / 4;
       EMIT_ATTR(_TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, S4_VFMT_COLOR, 4);
commit fae3a31bbbefb2ac795ba0d5df613343a5a9e119
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Thu Feb 23 14:19:18 2012 +0800

    tnl: let _TNL_ATTRIB_POINTSIZE do not depend on ctx->VertexProgram._Enabled
    
    We may specify the point size in a glsl vertex shader.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46311
    piglit: glsl-vs-point-size
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 9962280c332aba4b945b73ae19862041a7053a71)

diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
index 1ded44c..e38c0a3 100644
--- a/src/mesa/tnl/t_context.c
+++ b/src/mesa/tnl/t_context.c
@@ -151,8 +151,7 @@ _tnl_InvalidateState( struct gl_context *ctx, GLuint new_state )
    if (ctx->RenderMode == GL_FEEDBACK)
       tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_TEX0);
 
-   if (ctx->Point._Attenuated ||
-       (ctx->VertexProgram._Enabled && ctx->VertexProgram.PointSizeEnabled))
+   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled)
       tnl->render_inputs_bitset |= BITFIELD64_BIT(_TNL_ATTRIB_POINTSIZE);
 
    /* check for varying vars which are written by the vertex program */
commit b9f8cb9e0b1bd640b9b362c9ad56791e4c8cabcd
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Mar 8 20:16:00 2012 -0700

    mesa: fix GL_LUMINANCE handling in glGetTexImage
    
    There are several cases in which we need to explicity "rebase" colors
    (ex: set G=B=0) when getting GL_LUMINANCE textures:
    1. If the luminance texture is actually stored as rgba
    2. If getting a luminance texture, but returning rgba
    3. If getting an rgba texture, but returning luminance
    
    Fixes https://bugs.freedesktop.org/show_bug.cgi?id=46679
    
    Also fixes the new piglit getteximage-luminance test.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit f5d0ced242abc9e4e777bbe374585f44399b75af)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index cb8cf3c..76ac5a2 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -307,6 +307,8 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
    const gl_format texFormat =
       _mesa_get_srgb_format_linear(texImage->TexFormat);
    const GLuint width = texImage->Width;
+   const GLenum destBaseFormat = _mesa_base_tex_format(ctx, format);
+   GLenum rebaseFormat = GL_NONE;
    GLuint height = texImage->Height;
    GLuint depth = texImage->Depth;
    GLuint img, row;
@@ -327,6 +329,28 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
       height = 1;
    }
 
+   if (texImage->_BaseFormat == GL_LUMINANCE ||
+       texImage->_BaseFormat == GL_INTENSITY ||
+       texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
+      /* If a luminance (or intensity) texture is read back as RGB(A), the
+       * returned value should be (L,0,0,1), not (L,L,L,1).  Set rebaseFormat
+       * here to get G=B=0.
+       */
+      rebaseFormat = texImage->_BaseFormat;
+   }
+   else if ((texImage->_BaseFormat == GL_RGBA ||
+             texImage->_BaseFormat == GL_RGB) &&
+            (destBaseFormat == GL_LUMINANCE ||
+             destBaseFormat == GL_LUMINANCE_ALPHA ||
+             destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
+             destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
+      /* If we're reading back an RGB(A) texture as luminance then we need
+       * to return L=tex(R).  Note, that's different from glReadPixels which
+       * returns L=R+G+B.
+       */
+      rebaseFormat = GL_LUMINANCE_ALPHA; /* this covers GL_LUMINANCE too */
+   }
+
    for (img = 0; img < depth; img++) {
       GLubyte *srcMap;
       GLint rowstride;
@@ -344,12 +368,14 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
 
 	    if (is_integer) {
 	       _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
-               _mesa_rebase_rgba_uint(width, rgba_uint, texImage->_BaseFormat);
+               if (rebaseFormat)
+                  _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
 	       _mesa_pack_rgba_span_int(ctx, width, rgba_uint,
 					format, type, dest);
 	    } else {
 	       _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-               _mesa_rebase_rgba_float(width, rgba, texImage->_BaseFormat);
+               if (rebaseFormat)
+                  _mesa_rebase_rgba_float(width, rgba, rebaseFormat);
 	       _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
 					  format, type, dest,
 					  &ctx->Pack, transferOps);
commit aabbf5adacdb1dbd342439374ed8fee303ac61a3
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Feb 29 20:55:50 2012 -0700

    mesa: use _mesa_rebase_rgba_float/uint() in glGetTexImage code
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 8362199..cb8cf3c 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -275,13 +275,8 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions,
 
    if (baseFormat == GL_LUMINANCE ||
        baseFormat == GL_LUMINANCE_ALPHA) {
-      /* Set green and blue to zero since the pack function here will
-       * compute L=R+G+B.
-       */
-      GLuint i;
-      for (i = 0; i < width * height; i++) {
-         tempImage[i * 4 + GCOMP] = tempImage[i * 4 + BCOMP] = 0.0f;
-      }
+      _mesa_rebase_rgba_float(width * height, (GLfloat (*)[4]) tempImage,
+                              baseFormat);
    }
 
    srcRow = tempImage;
@@ -349,76 +344,12 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
 
 	    if (is_integer) {
 	       _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
-
-	       if (texImage->_BaseFormat == GL_ALPHA) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba_uint[col][RCOMP] = 0;
-		     rgba_uint[col][GCOMP] = 0;
-		     rgba_uint[col][BCOMP] = 0;
-		  }
-	       }
-	       else if (texImage->_BaseFormat == GL_LUMINANCE) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba_uint[col][GCOMP] = 0;
-		     rgba_uint[col][BCOMP] = 0;
-		     rgba_uint[col][ACOMP] = 1;
-		  }
-	       }
-	       else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba_uint[col][GCOMP] = 0;
-		     rgba_uint[col][BCOMP] = 0;
-		  }
-	       }
-	       else if (texImage->_BaseFormat == GL_INTENSITY) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba_uint[col][GCOMP] = 0;
-		     rgba_uint[col][BCOMP] = 0;
-		     rgba_uint[col][ACOMP] = 1;
-		  }
-	       }
-
+               _mesa_rebase_rgba_uint(width, rgba_uint, texImage->_BaseFormat);
 	       _mesa_pack_rgba_span_int(ctx, width, rgba_uint,
 					format, type, dest);
 	    } else {
 	       _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-
-	       if (texImage->_BaseFormat == GL_ALPHA) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba[col][RCOMP] = 0.0F;
-		     rgba[col][GCOMP] = 0.0F;
-		     rgba[col][BCOMP] = 0.0F;
-		  }
-	       }
-	       else if (texImage->_BaseFormat == GL_LUMINANCE) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba[col][GCOMP] = 0.0F;
-		     rgba[col][BCOMP] = 0.0F;
-		     rgba[col][ACOMP] = 1.0F;
-		  }
-	       }
-	       else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba[col][GCOMP] = 0.0F;
-		     rgba[col][BCOMP] = 0.0F;
-		  }
-	       }
-	       else if (texImage->_BaseFormat == GL_INTENSITY) {
-		  GLint col;
-		  for (col = 0; col < width; col++) {
-		     rgba[col][GCOMP] = 0.0F;
-		     rgba[col][BCOMP] = 0.0F;
-		     rgba[col][ACOMP] = 1.0F;
-		  }
-	       }
-
+               _mesa_rebase_rgba_float(width, rgba, texImage->_BaseFormat);
 	       _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
 					  format, type, dest,
 					  &ctx->Pack, transferOps);
commit 83728cf4ce40488760f5487df64f4ddf5ecdfdb1
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Feb 29 20:55:50 2012 -0700

    mesa: use _mesa_rebase_rgba_float/uint() in glReadPixels code
    
    See the comments for _mesa_rebase_rgba_float() for details.
    Fixes https://bugs.freedesktop.org/show_bug.cgi?id=46679
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit ad897fff7730298c21289768d9b1b55f3d166ac5)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 6f401f1..5b3c246 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -284,10 +284,14 @@ slow_read_rgba_pixels( struct gl_context *ctx,
    for (j = 0; j < height; j++) {
       if (_mesa_is_integer_format(format)) {
 	 _mesa_unpack_uint_rgba_row(rbFormat, width, map, (GLuint (*)[4]) rgba);
+         _mesa_rebase_rgba_uint(width, (GLuint (*)[4]) rgba,
+                                rb->_BaseFormat);
 	 _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4]) rgba, format,
                                   type, dst);
       } else {
 	 _mesa_unpack_rgba_row(rbFormat, width, map, (GLfloat (*)[4]) rgba);
+         _mesa_rebase_rgba_float(width, (GLfloat (*)[4]) rgba,
+                                 rb->_BaseFormat);
 	 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
                                     type, dst, packing, transferOps);
       }
commit 8836517250fbe8f98c0082e289178fe4d4e2306b
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Feb 29 20:55:49 2012 -0700

    mesa: add _mesa_rebase_rgba_float/uint() functions
    
    These will be used by glReadPixels() and glGetTexImage() to fix issues
    with reading GL_LUMINANCE and other formats.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 774c4027651436451b3486f62b9a8903f29a715b)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index ee983f9..4b0ee79 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -5254,3 +5254,94 @@ _mesa_unpack_image( GLuint dimensions,
    }
 }
 
+
+
+/**
+ * If we unpack colors from a luminance surface, we'll get pixel colors
+ * such as (l, l, l, a).
+ * When we call _mesa_pack_rgba_span_float(format=GL_LUMINANCE), that
+ * function will compute L=R+G+B before packing.  The net effect is we'll
+ * accidentally store luminance values = 3*l.
+ * This function compensates for that by converting (aka rebasing) (l,l,l,a)
+ * to be (l,0,0,a).
+ * It's a similar story for other formats such as LUMINANCE_ALPHA, ALPHA
+ * and INTENSITY.
+ *
+ * Finally, we also need to do this when the actual surface format does
+ * not match the logical surface format.  For example, suppose the user
+ * requests a GL_LUMINANCE texture but the driver stores it as RGBA.
+ * Again, we'll get pixel values like (l,l,l,a).
+ */
+void
+_mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], GLenum baseFormat)
+{
+   GLuint i;
+
+   switch (baseFormat) {
+   case GL_ALPHA:
+      for (i = 0; i < n; i++) {
+         rgba[i][RCOMP] = 0.0F;
+         rgba[i][GCOMP] = 0.0F;
+         rgba[i][BCOMP] = 0.0F;
+      }
+      break;
+   case GL_INTENSITY:
+      /* fall-through */
+   case GL_LUMINANCE:
+      for (i = 0; i < n; i++) {
+         rgba[i][GCOMP] = 0.0F;
+         rgba[i][BCOMP] = 0.0F;
+         rgba[i][ACOMP] = 1.0F;
+      }
+      break;
+   case GL_LUMINANCE_ALPHA:
+      for (i = 0; i < n; i++) {
+         rgba[i][GCOMP] = 0.0F;
+         rgba[i][BCOMP] = 0.0F;
+      }
+      break;
+   default:
+      /* no-op */
+      ;
+   }
+}
+
+
+/**
+ * As above, but GLuint components.
+ */
+void
+_mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat)
+{
+   GLuint i;
+
+   switch (baseFormat) {
+   case GL_ALPHA:
+      for (i = 0; i < n; i++) {
+         rgba[i][RCOMP] = 0;
+         rgba[i][GCOMP] = 0;
+         rgba[i][BCOMP] = 0;
+      }
+      break;
+   case GL_INTENSITY:
+      /* fall-through */
+   case GL_LUMINANCE:
+      for (i = 0; i < n; i++) {
+         rgba[i][GCOMP] = 0;
+         rgba[i][BCOMP] = 0;
+         rgba[i][ACOMP] = 1;
+      }
+      break;
+   case GL_LUMINANCE_ALPHA:
+      for (i = 0; i < n; i++) {
+         rgba[i][GCOMP] = 0;
+         rgba[i][BCOMP] = 0;
+      }
+      break;
+   default:
+      /* no-op */
+      ;
+   }
+}
+
+
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index b1853cd..cd49c74 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -149,4 +149,11 @@ _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
                          GLenum dstFormat, GLenum dstType,
                          GLvoid *dstAddr);
 
+
+extern void
+_mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], GLenum baseFormat);
+
+extern void
+_mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat);
+
 #endif
commit bc9d4ae6c743d592e89972bea8b039ab20949038
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 16 12:25:22 2012 -0700

    util: add mutex lock in u_debug_memory.c code
    
    The linked list of memory allocations was not protected by a mutex.
    This lead to sporadic failures with multi-threaded apps.
    
    Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

diff --git a/src/gallium/auxiliary/util/u_debug_memory.c b/src/gallium/auxiliary/util/u_debug_memory.c
index f1baa62..e24a8bc 100644
--- a/src/gallium/auxiliary/util/u_debug_memory.c
+++ b/src/gallium/auxiliary/util/u_debug_memory.c
@@ -38,6 +38,7 @@
 
 #include "os/os_memory.h"
 #include "os/os_memory_debug.h"
+#include "os/os_thread.h"
 
 #include "util/u_debug.h" 
 #include "util/u_debug_stack.h" 
@@ -72,6 +73,8 @@ struct debug_memory_footer
 
 static struct list_head list = { &list, &list };
 
+pipe_static_mutex(list_mutex);
+
 static unsigned long last_no = 0;
 
 
@@ -132,7 +135,9 @@ debug_malloc(const char *file, unsigned line, const char *function,
    ftr = footer_from_header(hdr);
    ftr->magic = DEBUG_MEMORY_MAGIC;
    
+   pipe_mutex_lock(list_mutex);
    LIST_ADDTAIL(&hdr->head, &list);
+   pipe_mutex_unlock(list_mutex);
    
    return data_from_header(hdr);
 }
@@ -164,7 +169,9 @@ debug_free(const char *file, unsigned line, const char *function,
       debug_assert(0);
    }
 
+   pipe_mutex_lock(list_mutex);
    LIST_DEL(&hdr->head);
+   pipe_mutex_unlock(list_mutex);
    hdr->magic = 0;
    ftr->magic = 0;
    
@@ -232,7 +239,9 @@ debug_realloc(const char *file, unsigned line, const char *function,
    new_ftr = footer_from_header(new_hdr);
    new_ftr->magic = DEBUG_MEMORY_MAGIC;
    
+   pipe_mutex_lock(list_mutex);
    LIST_REPLACE(&old_hdr->head, &new_hdr->head);
+   pipe_mutex_unlock(list_mutex);
 
    /* copy data */
    new_ptr = data_from_header(new_hdr);
commit 437ed1faaf6804b4d1c8396b8559c051f1e73aec
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Mar 9 08:16:26 2012 -0700

    svga: add null vs pointer check in update_need_pipeline()
    
    Based on a patch submitted by Vic Lee.  The other part of his patch
    which checked the fs pointer wasn't needed.
    
    This fixes a crash when clear() is called before any VS or FS is set.
    But this can only happen when the driver is used without the Mesa
    state tracker.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 991798822346dbb2d741b1f6d62f4bcb2c889dc8)

diff --git a/src/gallium/drivers/svga/svga_state_need_swtnl.c b/src/gallium/drivers/svga/svga_state_need_swtnl.c
index 32355d1..ce4db8d 100644
--- a/src/gallium/drivers/svga/svga_state_need_swtnl.c
+++ b/src/gallium/drivers/svga/svga_state_need_swtnl.c
@@ -136,7 +136,7 @@ update_need_pipeline( struct svga_context *svga,
 
    /* EDGEFLAGS
     */
-    if (vs->base.info.writes_edgeflag) {
+    if (vs && vs->base.info.writes_edgeflag) {
       SVGA_DBG(DEBUG_SWTNL, "%s: edgeflags\n", __FUNCTION__);
       need_pipeline = TRUE;
    }
commit fa9efdbab8d605d986748260e1f5ef8066ced327
Author: Zack Rusin <zackr at vmware.com>
Date:   Fri Mar 2 20:13:38 2012 -0500

    svga: fix the rasterizer state resets
    
    draw module calls back into the driver and sets certain parts
    of the state to whatever it needs, unfortunately unless you
    get the ordering of calls to draw just right you'll end up
    reseting your own driver state. That's what was happening to us
    draw module would under certain conditions reset our own driver
    state.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 831de96db87ee1f16b60d3aff308a423fece3407)

diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h
index 02c176e..f3a3f23 100644
--- a/src/gallium/auxiliary/draw/draw_context.h
+++ b/src/gallium/auxiliary/draw/draw_context.h
@@ -80,6 +80,21 @@ void draw_set_viewport_state( struct draw_context *draw,
 void draw_set_clip_state( struct draw_context *pipe,
                           const struct pipe_clip_state *clip );
 
+/**
+ * Sets the rasterization state used by the draw module.
+ * The rast_handle is used to pass the driver specific representation
+ * of the rasterization state. It's going to be used when the
+ * draw module sets the state back on the driver itself using the
+ * pipe::bind_rasterizer_state method.
+ *
+ * NOTE: if you're calling this function from within the pipe's
+ * bind_rasterizer_state you should always call it before binding
+ * the actual state - that's because the draw module can try to
+ * bind its own rasterizer state which would reset your newly
+ * set state. i.e. always do
+ * draw_set_rasterizer_state(driver->draw, state->pipe_state, state);
+ * driver->state.raster = state;
+ */
 void draw_set_rasterizer_state( struct draw_context *draw,
                                 const struct pipe_rasterizer_state *raster,
                                 void *rast_handle );
diff --git a/src/gallium/drivers/svga/svga_pipe_rasterizer.c b/src/gallium/drivers/svga/svga_pipe_rasterizer.c
index a18845e..3342800 100644
--- a/src/gallium/drivers/svga/svga_pipe_rasterizer.c
+++ b/src/gallium/drivers/svga/svga_pipe_rasterizer.c
@@ -237,11 +237,11 @@ static void svga_bind_rasterizer_state( struct pipe_context *pipe,
    struct svga_context *svga = svga_context(pipe);
    struct svga_rasterizer_state *raster = (struct svga_rasterizer_state *)state;
 
-   svga->curr.rast = raster;
 
    draw_set_rasterizer_state(svga->swtnl.draw, raster ? &raster->templ : NULL,
                              state);
-   
+   svga->curr.rast = raster;
+
    svga->dirty |= SVGA_NEW_RAST;
 }
 
commit 151d32dd4595f21be2d2126aa8c0d0c9434af416
Author: Zack Rusin <zackr at vmware.com>
Date:   Fri Feb 24 14:26:41 2012 -0500

    svga: Fix stencil op mapping
    
    We were inverting the meaning of the stencil op flags: in svga/d3d
    the normal incr/decr wraps and the SAT ops clamp.
    This fixes piglit failures (at least stencil-twoside and stencil-wrap).
    We should backport this everywhere we can.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 5d9bfc4d3f117fd6d95e1818c60f4f7ea47e6929)

diff --git a/src/gallium/drivers/svga/svga_pipe_depthstencil.c b/src/gallium/drivers/svga/svga_pipe_depthstencil.c
index c84615a..cb07dbe 100644
--- a/src/gallium/drivers/svga/svga_pipe_depthstencil.c
+++ b/src/gallium/drivers/svga/svga_pipe_depthstencil.c
@@ -57,10 +57,10 @@ svga_translate_stencil_op(unsigned op)
    case PIPE_STENCIL_OP_KEEP:      return SVGA3D_STENCILOP_KEEP;
    case PIPE_STENCIL_OP_ZERO:      return SVGA3D_STENCILOP_ZERO;
    case PIPE_STENCIL_OP_REPLACE:   return SVGA3D_STENCILOP_REPLACE;
-   case PIPE_STENCIL_OP_INCR:      return SVGA3D_STENCILOP_INCR;
-   case PIPE_STENCIL_OP_DECR:      return SVGA3D_STENCILOP_DECR;
-   case PIPE_STENCIL_OP_INCR_WRAP: return SVGA3D_STENCILOP_INCRSAT; /* incorrect? */
-   case PIPE_STENCIL_OP_DECR_WRAP: return SVGA3D_STENCILOP_DECRSAT; /* incorrect? */
+   case PIPE_STENCIL_OP_INCR:      return SVGA3D_STENCILOP_INCRSAT;
+   case PIPE_STENCIL_OP_DECR:      return SVGA3D_STENCILOP_DECRSAT;
+   case PIPE_STENCIL_OP_INCR_WRAP: return SVGA3D_STENCILOP_INCR;
+   case PIPE_STENCIL_OP_DECR_WRAP: return SVGA3D_STENCILOP_DECR;
    case PIPE_STENCIL_OP_INVERT:    return SVGA3D_STENCILOP_INVERT;
    default:
       assert(0);
commit 1fae49b0f5e3a2124ce578df48c800313778a74e
Author: Zack Rusin <zackr at vmware.com>
Date:   Tue Jan 31 23:12:22 2012 -0500

    svga: fix a crash happening before setting fragment shaders.
    
    In certain situations API's will call pipe->clear which doesn't
    require fragment shader, but then we'd try to verify the pipeline
    and assume fragment shader was always set. This was leading to
    crash when API would just call simple clear's before anything else.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit cff0eac702e0070d4d7f0e2ae5f785ec10597d4d)

diff --git a/src/gallium/drivers/svga/svga_state_need_swtnl.c b/src/gallium/drivers/svga/svga_state_need_swtnl.c
index 8c39a4b..32355d1 100644
--- a/src/gallium/drivers/svga/svga_state_need_swtnl.c
+++ b/src/gallium/drivers/svga/svga_state_need_swtnl.c
@@ -145,7 +145,8 @@ update_need_pipeline( struct svga_context *svga,
     */
    if (svga->curr.reduced_prim == PIPE_PRIM_POINTS) {
       unsigned sprite_coord_gen = svga->curr.rast->templ.sprite_coord_enable;
-      unsigned generic_inputs = svga->curr.fs->generic_inputs;
+      unsigned generic_inputs =
+         svga->curr.fs ? svga->curr.fs->generic_inputs : 0;
 
       if (sprite_coord_gen &&
           (generic_inputs & ~sprite_coord_gen)) {
commit 9664fb70dcda922295e5a2be8571c22bb3f879c3
Author: Neil Roberts <neil at linux.intel.com>
Date:   Sun Feb 26 01:33:40 2012 +0000

    mesa: Don't disable fast path for normalized types
    
    Mesa has a fast path for the generic fallback when using glReadPixels
    for RGBA data which uses memcpy.  However it was really difficult to
    hit this case because it would not be used if any transferOps are
    enabled.  Any type apart from floating point or non-normalized integer
    types (so any of the common types) would force enabling clamping so
    the fast path could not be used.  This patch makes it ignore clamping
    when determining whether to use the fast path if the data type of the
    buffer is an unsigned normalized type because in that case clamping
    will not have any effect anyway.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=46631
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit d9c42097770f173804c7c7c40bf8bc6c4400673b)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index c1489d2..6f401f1 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -218,6 +218,16 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
       return GL_FALSE;
    }
 
+   /* If the format is unsigned normalized then we can ignore clamping
+    * because the values are already in the range [0,1] so it won't
+    * have any effect anyway.
+    */
+   if (_mesa_get_format_datatype(rb->Format) == GL_UNSIGNED_NORMALIZED)
+      transferOps &= ~IMAGE_CLAMP_BIT;
+
+   if (transferOps)
+      return GL_FALSE;
+
    dstStride = _mesa_image_row_stride(packing, width, format, type);
    dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
 					   format, type, 0, 0);
@@ -313,13 +323,11 @@ read_rgba_pixels( struct gl_context *ctx,
       transferOps |= IMAGE_CLAMP_BIT;
    }
 
-   if (!transferOps) {
-      /* Try the optimized paths first. */
-      if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height,
-				       format, type, pixels, packing,
-				       transferOps)) {
-	 return;
-      }
+   /* Try the optimized paths first. */
+   if (fast_read_rgba_pixels_memcpy(ctx, x, y, width, height,
+                                    format, type, pixels, packing,
+                                    transferOps)) {
+      return;
    }
 
    slow_read_rgba_pixels(ctx, x, y, width, height,
commit a30809878f17c183a8c321fb7de6b42861725dbe
Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Feb 27 11:21:32 2012 +0000

    svga: Clamp advertised PIPE_SHADER_CAP_MAX_TEMPS to SVGA3D_TEMPREG_MAX.
    
    Some backends may advertise more temps than SVGA3D_TEMPREG_MAX, but the
    driver is hardwired to only support up to the value defined by
    SVGA3D_TEMPREG_MAX, so clamp to it.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>

diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 82a3ff2..e22deb4 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -235,7 +235,7 @@ static int svga_get_shader_param(struct pipe_screen *screen, unsigned shader, en
       case PIPE_SHADER_CAP_MAX_TEMPS:
          if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS, &result))
             return 32;
-         return result.u;
+         return MIN2(result.u, SVGA3D_TEMPREG_MAX);
       case PIPE_SHADER_CAP_MAX_ADDRS:
       case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
 	 /* 
@@ -286,7 +286,7 @@ static int svga_get_shader_param(struct pipe_screen *screen, unsigned shader, en
       case PIPE_SHADER_CAP_MAX_TEMPS:
          if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS, &result))
             return 32;
-         return result.u;
+         return MIN2(result.u, SVGA3D_TEMPREG_MAX);
       case PIPE_SHADER_CAP_MAX_ADDRS:
          return 1;
       case PIPE_SHADER_CAP_MAX_PREDS:
commit 9f44387e4868e90044750c7183fcd4cfb107621f
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Mon Sep 19 18:25:54 2011 +0800

    mesa: let GL3 buf obj queries not depend on opengl major version
    
    While the ARB_map_buffer_range extension spec says nothing about these
    queries -- they were added in GL 3.0 --, it seems like this could be an
    error in the extension spec.  This is one of the extensions, like
    ARB_framebuffer_object, that "back ports" OpenGL 3.0 functionality to
    previous versions.  These extensions are supposed to provide identical
    functionality to OpenGL 3.0.  The other cases of mismatches have been
    determined to be bugs in the extension specs.
    
    And tools like apitrace rely on such queries to function properly.
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Signed-off-by: José Fonseca <jfonseca at vmware.com>
    Acked-by: Brian Paul <brianp at vmware.com>
    Acked-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index a2959a8..4b27e06 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1159,17 +1159,17 @@ _mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
       *params = _mesa_bufferobj_mapped(bufObj);
       return;
    case GL_BUFFER_ACCESS_FLAGS:
-      if (ctx->VersionMajor < 3)
+      if (!ctx->Extensions.ARB_map_buffer_range)
          goto invalid_pname;
       *params = bufObj->AccessFlags;
       return;
    case GL_BUFFER_MAP_OFFSET:
-      if (ctx->VersionMajor < 3)
+      if (!ctx->Extensions.ARB_map_buffer_range)
          goto invalid_pname;
       *params = (GLint) bufObj->Offset;
       return;
    case GL_BUFFER_MAP_LENGTH:
-      if (ctx->VersionMajor < 3)
+      if (!ctx->Extensions.ARB_map_buffer_range)
          goto invalid_pname;
       *params = (GLint) bufObj->Length;
       return;
@@ -1210,7 +1210,7 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
       *params = simplified_access_mode(bufObj->AccessFlags);
       return;
    case GL_BUFFER_ACCESS_FLAGS:
-      if (ctx->VersionMajor < 3)
+      if (!ctx->Extensions.ARB_map_buffer_range)
          goto invalid_pname;
       *params = bufObj->AccessFlags;
       return;
@@ -1218,12 +1218,12 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
       *params = _mesa_bufferobj_mapped(bufObj);
       return;
    case GL_BUFFER_MAP_OFFSET:
-      if (ctx->VersionMajor < 3)
+      if (!ctx->Extensions.ARB_map_buffer_range)
          goto invalid_pname;
       *params = bufObj->Offset;
       return;
    case GL_BUFFER_MAP_LENGTH:
-      if (ctx->VersionMajor < 3)
+      if (!ctx->Extensions.ARB_map_buffer_range)
          goto invalid_pname;
       *params = bufObj->Length;
       return;
commit 16cc79f975816c0741711560be48fc498d4b4794
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Sat Feb 18 21:29:29 2012 -0800

    i965: Only set Last Render Target Select on the last FB write.
    
    Fixes GPU hangs in OilRush, Trine, and Amnesia: The Dark Descent,
    which all use MRT (multiple render targets).
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38720
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40059
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45216
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 172bb92db1a3c317867d9cfec6f15c09c37a0f6c)

diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c
index 3347157..b2581da 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c
@@ -2188,7 +2188,7 @@ void brw_fb_WRITE(struct brw_compile *p,
 			    msg_type,
 			    msg_length,
 			    header_present,
-			    1, /* last render target write */
+			    eot, /* last render target write */
 			    response_length,
 			    eot,
 			    0 /* send_commit_msg */);
commit 82043eb72dec18375d5ab0e49a6cc432b7413afc
Author: Tom Stellard <tstellar at gmail.com>
Date:   Mon Feb 13 21:27:28 2012 -0500

    r300/compiler: Fix bug when lowering KILP on r300 cards
    
    KILP instruction inside IF blocks were being lowered to an unconditional
    KIL.  Since r300 doesn't support branching, when the IF's were lowered
    to conditional moves, the KIL would always be executed.  This is not a
    problem with the mesa state tracker, because the GLSL compiler handles
    lowering IF's, but this bug was appearing in the VDPAU state tracker,
    which does not use the GLSL compiler.
    
    (cherry picked from commit 342cac71669662abad3435fd13ecf28d073874c3)

diff --git a/src/gallium/drivers/r300/compiler/radeon_program_alu.c b/src/gallium/drivers/r300/compiler/radeon_program_alu.c
index dd1dfb3..c48f936 100644
--- a/src/gallium/drivers/r300/compiler/radeon_program_alu.c
+++ b/src/gallium/drivers/r300/compiler/radeon_program_alu.c
@@ -1165,35 +1165,79 @@ int radeonTransformDeriv(struct radeon_compiler* c,
 }
 
 /**
+ * IF Temp[0].x -> IF Temp[0].x
+ * ...          -> ...
+ * KILP         -> KIL -abs(Temp[0].x)
+ * ...          -> ...
+ * ENDIF        -> ENDIF
+ *
+ * === OR ===
+ *
  * IF Temp[0].x -\
  * KILP         - > KIL -abs(Temp[0].x)
  * ENDIF        -/
  *
- * This needs to be done in its own pass, because it modifies the instructions
- * before and after KILP.
+ * === OR ===
+ *
+ * IF Temp[0].x -> IF Temp[0].x
+ * ...          -> ...
+ * ELSE         -> ELSE
+ * ...	        -> ...
+ * KILP	        -> KIL -abs(Temp[0].x)
+ * ...          -> ...
+ * ENDIF        -> ENDIF
+ *
+ * === OR ===
+ *
+ * KILP         -> KIL -none.1111
+ *
+ * This needs to be done in its own pass, because it might modify the
+ * instructions before and after KILP.
  */
 void rc_transform_KILP(struct radeon_compiler * c, void *user)
 {
 	struct rc_instruction * inst;
 	for (inst = c->Program.Instructions.Next;
 			inst != &c->Program.Instructions; inst = inst->Next) {
+		struct rc_instruction * if_inst;
+		unsigned in_if = 0;
 
 		if (inst->U.I.Opcode != RC_OPCODE_KILP)
 			continue;
 
+		for (if_inst = inst->Prev; if_inst != &c->Program.Instructions;
+						if_inst = if_inst->Prev) {
+
+			if (if_inst->U.I.Opcode == RC_OPCODE_IF) {
+				in_if = 1;
+				break;
+			}
+		}
+
 		inst->U.I.Opcode = RC_OPCODE_KIL;
 
-		if (inst->Prev->U.I.Opcode != RC_OPCODE_IF
-				|| inst->Next->U.I.Opcode != RC_OPCODE_ENDIF) {
+		if (!in_if) {
 			inst->U.I.SrcReg[0] = negate(builtin_one);
 		} else {
-
+			/* This should work even if the KILP is inside the ELSE
+			 * block, because -0.0 is considered negative. */
 			inst->U.I.SrcReg[0] =
-				negate(absolute(inst->Prev->U.I.SrcReg[0]));
-			/* Remove IF */
-			rc_remove_instruction(inst->Prev);
-			/* Remove ENDIF */
-			rc_remove_instruction(inst->Next);
+				negate(absolute(if_inst->U.I.SrcReg[0]));
+
+			if (inst->Prev->U.I.Opcode != RC_OPCODE_IF
+				&& inst->Next->U.I.Opcode != RC_OPCODE_ENDIF) {
+
+				/* Optimize the special case:
+				 * IF Temp[0].x
+				 * KILP
+				 * ENDIF
+				 */
+
+				/* Remove IF */
+				rc_remove_instruction(inst->Prev);
+				/* Remove ENDIF */
+				rc_remove_instruction(inst->Next);
+			}
 		}
 	}
 }
commit 2845a0be81853f3da59cf1180fd189a2236efa2b
Author: Marek Olšák <maraeo at gmail.com>
Date:   Fri Feb 24 19:29:48 2012 +0100

    gallium/rtasm: properly detect SSE and SSE2
    
    This should fix crashes on ancient processors.
    (cherry picked from commit 74d303521e6ba41d1cbeb75edb2f834ebbe8c550)

diff --git a/src/gallium/auxiliary/rtasm/rtasm_cpu.c b/src/gallium/auxiliary/rtasm/rtasm_cpu.c
index 0461c81..7afcf14 100644
--- a/src/gallium/auxiliary/rtasm/rtasm_cpu.c
+++ b/src/gallium/auxiliary/rtasm/rtasm_cpu.c
@@ -25,43 +25,43 @@
  *
  **************************************************************************/
 
+#include "pipe/p_config.h"
+#include "rtasm_cpu.h"
+
+#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
 
 #include "util/u_debug.h"
-#include "rtasm_cpu.h"
+#include "util/u_cpu_detect.h"
 
+DEBUG_GET_ONCE_BOOL_OPTION(nosse, "GALLIUM_NOSSE", FALSE);
 
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-static boolean rtasm_sse_enabled(void)
+static struct util_cpu_caps *get_cpu_caps(void)
 {
-   static boolean firsttime = 1;
-   static boolean enabled;
-   
-   /* This gets called quite often at the moment:
-    */
-   if (firsttime) {
-      enabled =  !debug_get_bool_option("GALLIUM_NOSSE", FALSE);
-      firsttime = FALSE;
-   }
-   return enabled;
+   util_cpu_detect();
+   return &util_cpu_caps;
 }
-#endif
 
 int rtasm_cpu_has_sse(void)
 {
-   /* FIXME: actually detect this at run-time */
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-   return rtasm_sse_enabled();
-#else
-   return 0;
-#endif
+   return !debug_get_option_nosse() && get_cpu_caps()->has_sse;
 }
 
 int rtasm_cpu_has_sse2(void) 
 {
-   /* FIXME: actually detect this at run-time */
-#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-   return rtasm_sse_enabled();
+   return !debug_get_option_nosse() && get_cpu_caps()->has_sse2;
+}
+
+
 #else
+
+int rtasm_cpu_has_sse(void)
+{
    return 0;
-#endif
 }
+
+int rtasm_cpu_has_sse2(void)
+{
+   return 0;
+}
+
+#endif
commit d38a2952895d6e859e04bc5dc6d7cfa9f8c36f17
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Feb 16 23:25:14 2012 -0800

    docs: Add 8.0.1 release md5sums
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/docs/relnotes-8.0.1.html b/docs/relnotes-8.0.1.html
index 8c8cd3f..29a314c 100644
--- a/docs/relnotes-8.0.1.html
+++ b/docs/relnotes-8.0.1.html
@@ -28,7 +28,9 @@ for DRI hardware acceleration.
 
 <h2>MD5 checksums</h2>
 <pre>
-tdb
+4855c2d93bd2ebd43f384bdcc92c9a27  MesaLib-8.0.1.tar.gz
+24eeebf66971809d8f40775a379b36c9  MesaLib-8.0.1.tar.bz2
+54e745d14dac5717f7f65b4e2d5c1df2  MesaLib-8.0.1.zip
 </pre>
 
 <h2>New features</h2>
commit fe77fd3983ba3da16ec53c58a790c381b07387ce
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Feb 16 18:55:18 2012 -0800

    docs: Add 8.0.1 release notes
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/docs/relnotes-8.0.1.html b/docs/relnotes-8.0.1.html
new file mode 100644
index 0000000..8c8cd3f
--- /dev/null
+++ b/docs/relnotes-8.0.1.html
@@ -0,0 +1,151 @@
+<HTML>
+
+<head>
+<TITLE>Mesa Release Notes</TITLE>
+<link rel="stylesheet" type="text/css" href="mesa.css">
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
+</head>
+
+<BODY>
+
+<body bgcolor="#eeeeee">
+
+<H1>Mesa 8.0.1 Release Notes / February 16, 2012</H1>
+
+<p>
+Mesa 8.0.1 is a bug fix release which fixes bugs found since the 8.0 release.
+</p>
+<p>
+Mesa 8.0 implements the OpenGL 3.0 API, but the version reported by
+glGetString(GL_VERSION) depends on the particular driver being used.
+Some drivers don't support all the features required in OpenGL 3.0.
+</p>
+<p>
+See the <a href="install.html">Compiling/Installing page</a> for prerequisites
+for DRI hardware acceleration.
+</p>
+
+
+<h2>MD5 checksums</h2>
+<pre>
+tdb
+</pre>
+
+<h2>New features</h2>
+<p>None.</p>
+
+<h2>Bug fixes</h2>
+
+<p>This list is likely incomplete.</p>
+
+<ul>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=28924">Bug 28924</a> - [ILK] piglit tex-border-1 fail</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=40864">Bug 40864</a> - [bisected pineview] oglc pxconv-gettex(basic.allCases) fails on pineview</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=43327">Bug 43327</a> - [bisected SNB] HiZ make many oglc cases regressed</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=44333">Bug 44333</a> - [bisected] Color distortion with xbmc mediaplayer</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=44927">Bug 44927</a> - [SNB IVB regression] gl-117 abort when click</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45221">Bug 45221</a> - [bisected IVB] glean/fbo regression in stencil-only case</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45877">Bug 45877</a> - main/image.c:1597: _mesa_convert_colors: Assertion `dstType == 0x1406' failed.</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45578">Bug 45578</a> - main/image.c:1659: _mesa_convert_colors: Assertion `dstType == 0x1403' failed.</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45872">Bug 45872</a> - [bisected PNV] oglc mustpass(basic.stipple) regressed on pineview</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45876">Bug 45876</a> - [PNV]oglc texenv(basic.allCases) regressed on pineview</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45917">Bug 45917</a> - [PNV] Regression in Piglit test general/two-sided-lighting-separate-specular</li>
+
+<li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=45943">Bug 45943</a> - [r300g] r300_emit.c:365:r300_emit_aa_state: Assertion `(aa-d>dest)->cs_buf' failed.</li>
+
+<!-- <li><a href="https://bugs.freedesktop.org/show_bug.cgi?id=">Bug </a> - </li> -->
+
+</ul>
+
+
+<h2>Changes</h2>
+<p>The full set of changes can be viewed by using the following GIT command:</p>
+
+<pre>
+  git log mesa-8.0..mesa-8.0.1
+</pre>
+
+<p>Alex Deucher (2):
+<ul>
+  <li>r600g: fix tex tile_type offset for cayman</li>
+  <li>r600g: 128 bit formats require tile_type = 1 on cayman</li>
+</ul></p>
+
+<p>Anuj Phogat (2):
+<ul>
+  <li>meta: Add pixel store/pack operations in decompress_texture_image</li>
+  <li>meta: Avoid FBO resizing/reallocating in decompress_texture_image</li>
+</ul></p>
+
+<p>Brian Paul (6):
+<ul>
+  <li>docs: add news item for 8.0 release</li>
+  <li>docs: update info about supported systems, GPUs, APIs</li>
+  <li>docs: add VMware link</li>
+  <li>docs: remove link to the GLSL compiler page</li>
+  <li>mesa: fix proxy texture target initialization</li>
+  <li>swrast: fix span color type selection</li>
+</ul></p>
+
+<p>Chad Versace (2):
+<ul>
+  <li>i965: Rewrite the HiZ op</li>
+  <li>i965: Remove file i965/junk, accidentally added in 7b36c68</li>
+</ul></p>
+
+<p>Dave Airlie (1):
+<ul>
+  <li>st/mesa: only resolve if number of samples is > 1</li>
+</ul></p>
+
+<p>Eric Anholt (3):
+<ul>
+  <li>i965: Fix HiZ change compiler warning.</li>
+  <li>i965: Report the failure message when failing to compile the fragment shader.</li>
+  <li>i965/fs: Enable register spilling on gen7 too.</li>
+</ul></p>
+
+<p>Ian Romanick (4):
+<ul>
+  <li>docs: Add 8.0 MD5 checksums</li>
+  <li>glapi: Include GLES2 headers for ES2 extension functions</li>
+  <li>swrast: Only avoid empty _TexEnvPrograms</li>
+  <li>mesa: Bump version number to 8.0.1</li>
+</ul></p>
+
+<p>Kenneth Graunke (4):
+<ul>
+  <li>i965: Fix border color on Ironlake.</li>
+  <li>i965/fs: Add a new fs_inst::regs_written function.</li>
+  <li>i965/fs: Take # of components into account in try_rewrite_rhs_to_dst.</li>
+  <li>i965: Emit Ivybridge VS workaround flushes.</li>
+</ul></p>
+
+<p>Mathias Fröhlich (1):
+<ul>
+  <li>state_stracker: Fix access to uninitialized memory.</li>
+</ul></p>
+
+<p>Paul Berry (1):
+<ul>
+  <li>i915: Fix type of "specoffset" variable.</li>
+</ul></p>
+
+<p>Simon Farnsworth (1):
+<ul>
+  <li>r600g: Use a fake reloc to sleep for fences</li>
+</ul></p>
+
+</body>
+</html>
commit b6950789377b2b31d93beca9d61d1f38c9ba5d4b
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Feb 16 18:54:28 2012 -0800

    mesa: Bump version number to 8.0.1
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/Makefile b/Makefile
index e0dd6ef..81ae944 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ ultrix-gcc:
 
 # Rules for making release tarballs
 
-PACKAGE_VERSION=8.0
+PACKAGE_VERSION=8.0.1
 PACKAGE_DIR = Mesa-$(PACKAGE_VERSION)
 PACKAGE_NAME = MesaLib-$(PACKAGE_VERSION)
 
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 11fe922..50f6adb 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -34,8 +34,8 @@ struct gl_context;
 /* Mesa version */
 #define MESA_MAJOR 8
 #define MESA_MINOR 0
-#define MESA_PATCH 0
-#define MESA_VERSION_STRING "8.0"
+#define MESA_PATCH 1
+#define MESA_VERSION_STRING "8.0.1"
 
 /* To make version comparison easy */
 #define MESA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
commit 106ea10d1b246aba1a0f4e171fd7d21268f3960f
Author: Simon Farnsworth <simon.farnsworth at onelan.co.uk>
Date:   Tue Feb 14 12:06:20 2012 +0000

    r600g: Use a fake reloc to sleep for fences
    
    r300g is able to sleep until a fence completes rather than busywait because
    it creates a special buffer object and relocation that stays busy until the
    CS containing the fence is finished.
    
    Copy the idea into r600g, and use it to sleep if the user asked for an
    infinite wait, falling back to busywaiting if the user provided a timeout.
    
    Signed-off-by: Simon Farnsworth <simon.farnsworth at onelan.co.uk>
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
    (cherry picked from commit 8cd03b933cf868ff867e2db4a0937005a02fd0e4)
    
    Conflicts:
    
    	src/gallium/drivers/r600/r600_pipe.c

diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index 43d6fea..008a0b9 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -47,6 +47,7 @@
 #include "r600_resource.h"
 #include "r600_shader.h"
 #include "r600_pipe.h"
+#include "r600_hw_context_priv.h"
 
 /*
  * pipe_context
@@ -116,6 +117,14 @@ static struct r600_fence *r600_create_fence(struct r600_pipe_context *ctx)
 
 	rscreen->fences.data[fence->index] = 0;
 	r600_context_emit_fence(&ctx->ctx, rscreen->fences.bo, fence->index, 1);
+
+	/* Create a dummy BO so that fence_finish without a timeout can sleep waiting for completion */
+	fence->sleep_bo = (struct r600_resource*)
+			pipe_buffer_create(&ctx->ctx.screen->screen, PIPE_BIND_CUSTOM,
+					   PIPE_USAGE_STAGING, 1);
+	/* Add the fence as a dummy relocation. */
+	r600_context_bo_reloc(&ctx->ctx, fence->sleep_bo, RADEON_USAGE_READWRITE);
+
 out:
 	pipe_mutex_unlock(rscreen->fences.mutex);
 	return fence;
@@ -568,6 +577,7 @@ static void r600_fence_reference(struct pipe_screen *pscreen,
 	if (pipe_reference(&(*oldf)->reference, &newf->reference)) {
 		struct r600_screen *rscreen = (struct r600_screen *)pscreen;
 		pipe_mutex_lock(rscreen->fences.mutex);
+		pipe_resource_reference((struct pipe_resource**)&(*oldf)->sleep_bo, NULL);
 		LIST_ADDTAIL(&(*oldf)->head, &rscreen->fences.pool);
 		pipe_mutex_unlock(rscreen->fences.mutex);
 	}
@@ -601,6 +611,17 @@ static boolean r600_fence_finish(struct pipe_screen *pscreen,
 	}
 
 	while (rscreen->fences.data[rfence->index] == 0) {
+		/* Special-case infinite timeout - wait for the dummy BO to become idle */
+		if (timeout == PIPE_TIMEOUT_INFINITE) {
+			rscreen->ws->buffer_wait(rfence->sleep_bo->buf, RADEON_USAGE_READWRITE);
+			break;
+		}
+
+		/* The dummy BO will be busy until the CS including the fence has completed, or
+		 * the GPU is reset. Don't bother continuing to spin when the BO is idle. */
+		if (!rscreen->ws->buffer_is_busy(rfence->sleep_bo->buf, RADEON_USAGE_READWRITE))
+			break;
+
 		if (++spins % 256)
 			continue;
 #ifdef PIPE_OS_UNIX
@@ -610,11 +631,11 @@ static boolean r600_fence_finish(struct pipe_screen *pscreen,
 #endif
 		if (timeout != PIPE_TIMEOUT_INFINITE &&
 		    os_time_get() - start_time >= timeout) {
-			return FALSE;
+			break;
 		}
 	}
 
-	return TRUE;
+	return rscreen->fences.data[rfence->index] != 0;
 }
 
 static int r600_interpret_tiling(struct r600_screen *rscreen, uint32_t tiling_config)
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index 015d5e0..5e62210 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -172,6 +172,7 @@ struct r600_textures_info {
 struct r600_fence {
 	struct pipe_reference		reference;
 	unsigned			index; /* in the shared bo */
+	struct r600_resource            *sleep_bo;
 	struct list_head		head;
 };
 
commit fca1a33c96f2063bbaa4a6898fef1e41a197073d
Author: Alex Deucher <alexander.deucher at amd.com>
Date:   Fri Feb 10 11:02:03 2012 -0500

    r600g: 128 bit formats require tile_type = 1 on cayman
    
    Noticed by taiu on IRC.
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
    
    (cherry picked from commit 5e1495b2d9311fa2b320766a1d299053904bd9c3)
    
    Conflicts:
    
    	src/gallium/drivers/r600/evergreen_state.c

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 9fd5855..83699e3 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -1093,6 +1093,11 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte
 		      util_format_get_blockwidth(state->format), 8);
 	array_mode = tmp->array_mode[0];
 	tile_type = tmp->tile_type;
+	/* 128 bit formats require tile type = 1 */
+	if (rctx->chip_class == CAYMAN) {
+		if (util_format_get_blocksize(state->format) >= 16)
+			tile_type = 1;
+	}
 
 	if (texture->target == PIPE_TEXTURE_1D_ARRAY) {
 	        height = 1;
@@ -1461,6 +1466,11 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state
 		tile_type = rtex->tile_type;
 	} else /* workaround for linear buffers */
 		tile_type = 1;
+	/* 128 bit formats require tile type = 1 */
+	if (rctx->chip_class == CAYMAN) {
+		if (util_format_get_blocksize(surf->base.format) >= 16)
+			tile_type = 1;
+	}
 
 	/* FIXME handle enabling of CB beyond BASE8 which has different offset */
 	r600_pipe_state_add_reg(rstate,
commit 036d9992659bdd03c44800835f48b99f26ca24d7
Author: Alex Deucher <alexander.deucher at amd.com>
Date:   Fri Feb 10 10:49:13 2012 -0500

    r600g: fix tex tile_type offset for cayman
    
    Noticed by taiu on IRC.
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
    
    (cherry picked from commit acca690c259824636ef1ff684a10bd1caca4751f)
    
    Conflicts:
    
    	src/gallium/drivers/r600/evergreen_state.c

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 60b1909..9fd5855 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -1046,6 +1046,7 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte
 							struct pipe_resource *texture,
 							const struct pipe_sampler_view *state)
 {
+	struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
 	struct r600_pipe_sampler_view *view = CALLOC_STRUCT(r600_pipe_sampler_view);
 	struct r600_pipe_resource_state *rstate;
 	struct r600_resource_texture *tmp = (struct r600_resource_texture*)texture;
@@ -1107,8 +1108,11 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte
 
 	rstate->val[0] = (S_030000_DIM(r600_tex_dim(texture->target)) |
 			  S_030000_PITCH((pitch / 8) - 1) |
-			  S_030000_NON_DISP_TILING_ORDER(tile_type) |
 			  S_030000_TEX_WIDTH(texture->width0 - 1));
+	if (rctx->chip_class == CAYMAN)
+		rstate->val[0] |= CM_S_030000_NON_DISP_TILING_ORDER(tile_type);
+	else
+		rstate->val[0] |= S_030000_NON_DISP_TILING_ORDER(tile_type);
 	rstate->val[1] = (S_030004_TEX_HEIGHT(height - 1) |
 			  S_030004_TEX_DEPTH(depth - 1) |
 			  S_030004_ARRAY_MODE(array_mode));
diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
index fa3fece..310eb10 100644
--- a/src/gallium/drivers/r600/evergreend.h
+++ b/src/gallium/drivers/r600/evergreend.h
@@ -970,6 +970,9 @@
 #define   S_030000_NON_DISP_TILING_ORDER(x)            (((x) & 0x1) << 5)
 #define   G_030000_NON_DISP_TILING_ORDER(x)            (((x) >> 5) & 0x1)
 #define   C_030000_NON_DISP_TILING_ORDER               0xFFFFFFDF
+#define   CM_S_030000_NON_DISP_TILING_ORDER(x)         (((x) & 0x3) << 4)
+#define   CM_G_030000_NON_DISP_TILING_ORDER(x)         (((x) >> 4) & 0x3)
+#define   CM_C_030000_NON_DISP_TILING_ORDER            0xFFFFFFCF
 #define   S_030000_PITCH(x)                            (((x) & 0xFFF) << 6)
 #define   G_030000_PITCH(x)                            (((x) >> 6) & 0xFFF)
 #define   C_030000_PITCH                               0xFFFC003F
commit e3943cf1ccf5a08c8f1b98ebdd30980a7efc6f02
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Jan 19 09:55:34 2012 -0800

    i965: Emit Ivybridge VS workaround flushes.
    
    I recently discovered this text in the BSpec.  It seems wise to comply,
    though I haven't observed it to fix anything yet.
    
    Fixes a regression in glean/fbo since 28cfa1fa213fe.
    
    NOTE: This is a candidate for stable release branches.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45221
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 709f50928e1d4df755ffb90ec9f33ba6c9605a32)

diff --git a/src/mesa/drivers/dri/i965/gen7_urb.c b/src/mesa/drivers/dri/i965/gen7_urb.c
index e6cf1eb..920c9fc 100644
--- a/src/mesa/drivers/dri/i965/gen7_urb.c
+++ b/src/mesa/drivers/dri/i965/gen7_urb.c
@@ -99,6 +99,8 @@ gen7_upload_urb(struct brw_context *brw)
    /* GS requirement */
    assert(!brw->gs.prog_active);
 
+   gen7_emit_vs_workaround_flush(intel);
+
    BEGIN_BATCH(2);
    OUT_BATCH(_3DSTATE_URB_VS << 16 | (2 - 2));
    OUT_BATCH(brw->urb.nr_vs_entries |
diff --git a/src/mesa/drivers/dri/i965/gen7_vs_state.c b/src/mesa/drivers/dri/i965/gen7_vs_state.c
index 0746e6c..a3d652c 100644
--- a/src/mesa/drivers/dri/i965/gen7_vs_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_vs_state.c
@@ -35,6 +35,8 @@ upload_vs_state(struct brw_context *brw)
    struct intel_context *intel = &brw->intel;
    uint32_t floating_point_mode = 0;
 
+   gen7_emit_vs_workaround_flush(intel);
+
    BEGIN_BATCH(2);
    OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS_VS << 16 | (2 - 2));
    OUT_BATCH(brw->bind.bo_offset);
diff --git a/src/mesa/drivers/dri/intel/intel_batchbuffer.c b/src/mesa/drivers/dri/intel/intel_batchbuffer.c
index ab4cb7e..d8b1eca 100644
--- a/src/mesa/drivers/dri/intel/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/intel/intel_batchbuffer.c
@@ -57,13 +57,13 @@ intel_batchbuffer_init(struct intel_context *intel)
 {
    intel_batchbuffer_reset(intel);
 
-   if (intel->gen == 6) {
+   if (intel->gen >= 6) {
       /* We can't just use brw_state_batch to get a chunk of space for
        * the gen6 workaround because it involves actually writing to
        * the buffer, and the kernel doesn't let us write to the batch.
        */
       intel->batch.workaround_bo = drm_intel_bo_alloc(intel->bufmgr,
-						      "gen6 workaround",
+						      "pipe_control workaround",
 						      4096, 4096);
    }
 }
@@ -364,6 +364,28 @@ intel_emit_depth_stall_flushes(struct intel_context *intel)
 }
 
 /**
+ * From the BSpec, volume 2a.03: VS Stage Input / State:
+ * "[DevIVB] A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
+ *  stall needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
+ *  3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
+ *  3DSTATE_SAMPLER_STATE_POINTER_VS command.  Only one PIPE_CONTROL needs
+ *  to be sent before any combination of VS associated 3DSTATE."
+ */
+void
+gen7_emit_vs_workaround_flush(struct intel_context *intel)
+{
+   assert(intel->gen == 7);
+
+   BEGIN_BATCH(4);
+   OUT_BATCH(_3DSTATE_PIPE_CONTROL);
+   OUT_BATCH(PIPE_CONTROL_DEPTH_STALL | PIPE_CONTROL_WRITE_IMMEDIATE);
+   OUT_RELOC(intel->batch.workaround_bo,
+	     I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION, 0);
+   OUT_BATCH(0); /* write data */
+   ADVANCE_BATCH();
+}
+
+/**
  * Emits a PIPE_CONTROL with a non-zero post-sync operation, for
  * implementing two workarounds on gen6.  From section 1.4.7.1
  * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1:
diff --git a/src/mesa/drivers/dri/intel/intel_batchbuffer.h b/src/mesa/drivers/dri/intel/intel_batchbuffer.h
index e5e5bd4..751ec99 100644
--- a/src/mesa/drivers/dri/intel/intel_batchbuffer.h
+++ b/src/mesa/drivers/dri/intel/intel_batchbuffer.h
@@ -43,6 +43,7 @@ bool intel_batchbuffer_emit_reloc_fenced(struct intel_context *intel,
 void intel_batchbuffer_emit_mi_flush(struct intel_context *intel);
 void intel_emit_post_sync_nonzero_flush(struct intel_context *intel);
 void intel_emit_depth_stall_flushes(struct intel_context *intel);
+void gen7_emit_vs_workaround_flush(struct intel_context *intel);
 
 static INLINE uint32_t float_as_int(float f)
 {
commit 0aadb240e191538b07c45733dc2597235a52d274
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Feb 14 12:43:22 2012 -0800

    i965/fs: Take # of components into account in try_rewrite_rhs_to_dst.
    
    Commit dc7f449d1ac53a66e6efb56ccf2a5953418a26ca introduced a new method
    for avoiding MOVs: try to rewrite the destination of the instruction
    that produced the RHS so it writes into the LHS.
    
    Unfortunately, this is not safe for swizzled texturing operations, as
    they return a set of four contiguous registers.  Consider the following:
    
    (assign (x)
            (var_ref vec_ctor_x)
            (swiz x (tex vec4 (var_ref m_sampY) (var_ref m_cordY) 0 1 ())))
    
    In this case, the source and destination registers are equal, since
    reg_offset is 0 for both.  Yet, this is only a partial move: the texture
    operation generates four registers, and the LHS only covers one.
    
    Fixes color distortion in XBMC when using GLSL shaders.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44333
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 4b274068204c7f0bacaa4639f24feb433353b861)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 44c9ee8..0632052 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -564,6 +564,12 @@ fs_visitor::try_rewrite_rhs_to_dst(ir_assignment *ir,
        !src.equals(&last_rhs_inst->dst))
       return false;
 
+   /* If last_rhs_inst wrote a different number of components than our LHS,
+    * we can't safely rewrite it.
+    */
+   if (ir->lhs->type->vector_elements != last_rhs_inst->regs_written())
+      return false;
+
    /* Success!  Rewrite the instruction. */
    last_rhs_inst->dst = dst;
 
commit 740123fff754fac9da3e9807e2fcd05d66690866
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Feb 14 12:43:21 2012 -0800

    i965/fs: Add a new fs_inst::regs_written function.
    
    Certain instructions write more than one register.  Texturing, for
    example, returns 4 registers.  (We set rlen to 4 even for TXS and float
    shadow sampling.)  Some math functions return 2.  Most return 1.
    
    The next commit introduces a use of this function.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 8ab02b511882857a09fceed0e93bf4a0b25c17b2)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 5fdc055..9a2cc08 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -286,6 +286,18 @@ public:
 	      offset == inst->offset);
    }
 
+   int regs_written()
+   {
+      if (is_tex())
+	 return 4;
+
+      /* The SINCOS and INT_DIV_QUOTIENT_AND_REMAINDER math functions return 2,
+       * but we don't currently use them...nor do we have an opcode for them.
+       */
+
+      return 1;
+   }
+
    bool is_tex()
    {
       return (opcode == SHADER_OPCODE_TEX ||
commit ff1d9450321d5fe164611f819ee299706d9cbe02
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Feb 10 16:00:27 2012 -0800

    swrast: Only avoid empty _TexEnvPrograms
    
    If the generated shader for _TexEnvProgram is empty, force the use of
    the fixed-function code.  Otherwise, go ahead and use the shader.
    This works around a mysterious issue on i915 where fixed-function
    software fallbacks are not working correctly.
    
    This isn't really the fix we want, but it works around the issue.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45872
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45876
    (cherry picked from commit 3e22d4e5fc32dafcb9669a9d6376323aa88e300c)

diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index cd20d8e..8d59371 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -40,7 +40,8 @@ GLboolean
 _swrast_use_fragment_program(struct gl_context *ctx)
 {
    struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
-   return fp && fp != ctx->FragmentProgram._TexEnvProgram;
+   return fp && !(fp == ctx->FragmentProgram._TexEnvProgram
+                  && fp->Base.NumInstructions == 0);
 }
 
 /**
commit efca49fd513dd7504a07368c61e7198cfebe24a9
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Feb 8 13:04:38 2012 -0800

    glapi: Include GLES2 headers for ES2 extension functions
    
    This fixes build errors like
    
    In file included from glapi_dispatch.c:91:
    ../../../src/mapi/glapi/glapitemp.h:4641: error: no previous prototype for
    'glDrawBuffersNV'
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Tested-by: Lucas Stach <dev at lynxeye.de>
    (cherry picked from commit 8f3be339850ead96f9c6200db4e0db1f74e39d13)

diff --git a/src/mapi/glapi/glapi_priv.h b/src/mapi/glapi/glapi_priv.h
index 3ab553a..b6600c5 100644
--- a/src/mapi/glapi/glapi_priv.h
+++ b/src/mapi/glapi/glapi_priv.h
@@ -38,6 +38,16 @@
 #include "GL/gl.h"
 #include "GL/glext.h"
 
+/* The define of GL_COVERAGE_SAMPLES_NV in gl2ext.h is guarded by a different
+ * extension (GL_NV_coverage_sample) than in glext.h
+ * (GL_NV_multisample_coverage).  Just undefine it to avoid spurious compiler
+ * warnings.
+ */
+#undef GL_COVERAGE_SAMPLES_NV
+
+#include "GLES2/gl2platform.h"
+#include "GLES2/gl2ext.h"
+
 #ifndef GL_OES_fixed_point
 typedef int GLfixed;
 typedef int GLclampx;
commit d45a5fde45e30c4475a92217b582c73d8ef5f52b
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Mon Feb 13 10:48:45 2012 -0800

    meta: Avoid FBO resizing/reallocating in decompress_texture_image
    
    Reallocate/resize decompress FBO only if texture image width/height is
    greater than existing decompress FBO width/height.
    
    This is a candidate for stable branches.
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 66bf25f1a2cc8343640cdfc4242d882bc00b9e3b)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 2b994de..4dd9b29 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -3291,7 +3291,7 @@ decompress_texture_image(struct gl_context *ctx,
    }
 
    /* alloc dest surface */
-   if (width != decompress->Width || height != decompress->Height) {
+   if (width > decompress->Width || height > decompress->Height) {
       _mesa_RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA,
                                    width, height);
       decompress->Width = width;
commit e55f2d97f61420f6004c60be4238799f7a35b440
Author: Paul Berry <stereotype441 at gmail.com>
Date:   Fri Feb 10 19:51:55 2012 -0800

    i915: Fix type of "specoffset" variable.
    
    Commit 2e5a1a2 (intel: Convert from GLboolean to 'bool' from
    stdbool.h.) converted the "specoffset" local variable (in
    intel_tris.c) from a GLboolean to a bool.  However, GLboolean was the
    wrong type for specoffset--it should have been a GLuint (to match the
    declaration of specoffset in struct intel_context).
    
    This patch changes specoffset to the proper type.
    
    Fixes piglit test general/two-sided-lighting-separate-specular.
    
    This is a candidate for stable branches.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45917
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 6b0a07f9ce844a8a96e2583bd37ed8453bf151c6)

diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c
index 23de6ea..a36011a 100644
--- a/src/mesa/drivers/dri/i915/intel_tris.c
+++ b/src/mesa/drivers/dri/i915/intel_tris.c
@@ -663,7 +663,7 @@ do {							\
    struct intel_context *intel = intel_context(ctx);			\
    GLuint color[n] = { 0, }, spec[n] = { 0, };				\
    GLuint coloroffset = intel->coloroffset;				\
-   bool specoffset = intel->specoffset;				\
+   GLuint specoffset = intel->specoffset;				\
    (void) color; (void) spec; (void) coloroffset; (void) specoffset;
 
 
commit 6e09d3cff2e850b8fef44c4f7bd7397c78376f1d
Author: Mathias Fröhlich <Mathias.Froehlich at gmx.net>
Date:   Sat Jan 28 18:55:08 2012 +0100

    state_stracker: Fix access to uninitialized memory.
    
    Fix an access to uninitialized memory pointed out by valgrind in
    glsl_to_tgsi_visitor::simplify_cmp(void).
    
    Note: This is a candidate for the 8.0 branch.
    Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
    (cherry picked from commit 1d01429c6a1ae679d0cc0cb61db1948fca5ced4c)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 26047cf..ec8b1d1 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2978,7 +2978,7 @@ glsl_to_tgsi_visitor::simplify_cmp(void)
    if (!tempWrites) {
       return;
    }
-   memset(tempWrites, 0, sizeof(tempWrites));
+   memset(tempWrites, 0, sizeof(unsigned) * MAX_TEMPS);
    memset(outputWrites, 0, sizeof(outputWrites));
 
    foreach_iter(exec_list_iterator, iter, this->instructions) {
commit 99f9c9789a2d316d97ca6791343fb697f220929e
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 9 16:35:49 2012 -0800

    i965/fs: Enable register spilling on gen7 too.
    
    It turns out the same messages work on gen7, we were just being paranoid.
    
    Fixes the penumbra shadows mode of Lightsmark since the register
    allocation fix.
    
    NOTE: This is a candidate for release branches.
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 93831a54c7d4e74f353e0029164b1b3262e98806)

diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
index 0d1712e..7da1418 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
@@ -236,8 +236,6 @@ fs_visitor::assign_regs()
 
       if (reg == -1) {
 	 fail("no register to spill\n");
-      } else if (intel->gen >= 7) {
-	 fail("no spilling support on gen7 yet\n");
       } else if (c->dispatch_width == 16) {
 	 fail("no spilling support on 16-wide yet\n");
       } else {
commit a63d79dd4075fdc4dba4b9b6c9801fca93a8a725
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 9 10:23:45 2012 -0800

    i965: Report the failure message when failing to compile the fragment shader.
    
    We just abort later, but at least this should result in more
    informative bug reports.
    
    NOTE: This is a candidate for release branches.
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit a7f46eadea4555ed377928d4e3f89db4a445312e)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 40327ac..0de1eef 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -1844,6 +1844,9 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c,
       prog->LinkStatus = false;
       ralloc_strcat(&prog->InfoLog, v.fail_msg);
 
+      _mesa_problem(NULL, "Failed to compile fragment shader: %s\n",
+		    v.fail_msg);
+
       return false;
    }
 
commit ff7ccb1cf147b4c55492bc6ec6319dcbd6f31048
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Fri Feb 10 16:27:19 2012 -0800

    meta: Add pixel store/pack operations in decompress_texture_image
    
    This patch adds the pixel store operations in decompress_texture_image().
    decompress_texture_image() is used in glGetTexImage() for compressed
    textures with unsigned, normalized values.
    
    It also fixes the failures in intel oglconform pxstore-gettex due to
    following sub test cases:
    
     - Test all mipmaps with byte swapping enabled
     - Test all small mipmaps with all allowable alignment values
     - Test subimage packing for all mipmap levels
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40864
    
    Note: This is a candidate for stable branches
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 40427025916e003cfd380c2e30df78ad2bc8fe10)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index aa5fef8..2b994de 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -3243,7 +3243,7 @@ decompress_texture_image(struct gl_context *ctx,
                          struct gl_texture_image *texImage,
                          GLuint slice,
                          GLenum destFormat, GLenum destType,
-                         GLvoid *dest, GLint destRowLength)
+                         GLvoid *dest)
 {
    struct decompress_state *decompress = &ctx->Meta->Decompress;
    struct gl_texture_object *texObj = texImage->TexObject;
@@ -3273,7 +3273,7 @@ decompress_texture_image(struct gl_context *ctx,
    fboDrawSave = ctx->DrawBuffer->Name;
    fboReadSave = ctx->ReadBuffer->Name;
 
-   _mesa_meta_begin(ctx, MESA_META_ALL);
+   _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_PIXEL_STORE);
 
    /* Create/bind FBO/renderbuffer */
    if (decompress->FBO == 0) {
@@ -3408,7 +3408,6 @@ decompress_texture_image(struct gl_context *ctx,
          _mesa_PixelTransferf(GL_BLUE_SCALE, 0.0f);
       }
 
-      ctx->Pack.RowLength = destRowLength;
       _mesa_ReadPixels(0, 0, width, height, destFormat, destType, dest);
    }
 
@@ -3449,8 +3448,7 @@ _mesa_meta_GetTexImage(struct gl_context *ctx,
       const GLuint slice = 0; /* only 2D compressed textures for now */
       /* Need to unlock the texture here to prevent deadlock... */
       _mesa_unlock_texture(ctx, texObj);
-      decompress_texture_image(ctx, texImage, slice, format, type, pixels,
-                               ctx->Pack.RowLength);
+      decompress_texture_image(ctx, texImage, slice, format, type, pixels);
       /* ... and relock it */
       _mesa_lock_texture(ctx, texObj);
    }
commit 9e98d38e58e271f5fe383f3831c1919527bd8546
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Nov 30 20:10:19 2011 +0000

    st/mesa: only resolve if number of samples is > 1
    
    Marek: this fixes a firefox crash and maybe even:
    https://bugs.freedesktop.org/show_bug.cgi?id=45943
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Marek Olšák <maraeo at gmail.com>
    (cherry picked from commit 094eeff19946138d6306d74e9e62af5e9d192abd)

diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c
index 750f541..27da2c6 100644
--- a/src/mesa/state_tracker/st_cb_blit.c
+++ b/src/mesa/state_tracker/st_cb_blit.c
@@ -178,7 +178,8 @@ st_BlitFramebuffer(struct gl_context *ctx,
       st->pipe->render_condition(st->pipe, NULL, 0);
    }
 
-   if (readFB->Visual.sampleBuffers > drawFB->Visual.sampleBuffers) {
+   if (readFB->Visual.sampleBuffers > drawFB->Visual.sampleBuffers &&
+       readFB->Visual.samples > 1) {
       struct pipe_resolve_info info;
 
       if (dstX0 < dstX1) {
commit a2186a2ea6b998bd14e3cf7a63eb061b7719d11e
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Feb 3 08:17:24 2012 -0700

    swrast: fix span color type selection
    
    Fixes a regression from commit 660ed923ded3552e023ef8c3dd9f92e6792f1bd2.
    The basic idea is to look at the format of the dest renderbuffer and
    choose either GLubyte or GLfloat for colors.  The previous code used
    _mesa_format_to_type_and_comps() which could return a bunch types other
    than ubyte/float.
    
    Determine the datatype at renderbuffer mapping time to avoid frequent
    calls to the format query functions.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45578
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45577
    (cherry picked from commit bd1ae51b13535bc4438c663ffe91ded49db4890a)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index ae239a9..bf1316a 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -175,6 +175,9 @@ struct swrast_renderbuffer
    /** These fields are only valid while buffer is mapped for rendering */
    GLubyte *Map;
    GLint RowStride;    /**< in bytes */
+
+   /** For span rendering */
+   GLenum ColorType;
 };
 
 
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 637a7b6..d8a7467 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -615,8 +615,31 @@ unmap_attachment(struct gl_context *ctx,
 
    srb->Map = NULL;
 }
- 
- 
+
+
+/**
+ * Determine what type to use (ubyte vs. float) for span colors for the
+ * given renderbuffer.
+ * See also _swrast_write_rgba_span().
+ */
+static void
+find_renderbuffer_colortype(struct gl_renderbuffer *rb)
+{
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+   GLuint rbMaxBits = _mesa_get_format_max_bits(rb->Format);
+   GLenum rbDatatype = _mesa_get_format_datatype(rb->Format);
+
+   if (rbDatatype == GL_UNSIGNED_NORMALIZED && rbMaxBits <= 8) {
+      /* the buffer's values fit in GLubyte values */
+      srb->ColorType = GL_UNSIGNED_BYTE;
+   }
+   else {
+      /* use floats otherwise */
+      srb->ColorType = GL_FLOAT;
+   }
+}
+
+
 /**
  * Map the renderbuffers we'll use for tri/line/point rendering.
  */
@@ -641,6 +664,7 @@ _swrast_map_renderbuffers(struct gl_context *ctx)
 
    for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
       map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
+      find_renderbuffer_colortype(fb->_ColorDrawBuffers[buf]);
    }
 }
  
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 6d6538c..f62ee94 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1320,15 +1320,15 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
 
          if (rb) {
             GLchan rgbaSave[MAX_WIDTH][4];
+            struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+            GLenum colorType = srb->ColorType;
 
-	    GLenum datatype;
-	    GLuint comps;
+            assert(colorType == GL_UNSIGNED_BYTE ||
+                   colorType == GL_FLOAT);
 
-	    _mesa_format_to_type_and_comps(rb->Format, &datatype, &comps);
-
-            /* set span->array->rgba to colors for render buffer's datatype */
-            if (datatype != span->array->ChanType) {
-               convert_color_type(span, datatype, 0);
+            /* set span->array->rgba to colors for renderbuffer's datatype */
+            if (span->array->ChanType != colorType) {
+               convert_color_type(span, colorType, 0);
             }
             else {
                if (span->array->ChanType == GL_UNSIGNED_BYTE) {
commit be1377c33c320d70565192912fc53d72a86eebff
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Feb 8 17:14:15 2012 -0800

    i965: Fix border color on Ironlake.
    
    Ironlake appears to check our pointer against the General State Base
    Address upper bound, rather than ignoring the zero bound as it ought.
    
    Unfortunately, since we leave GSBA set to zero, there is no logical
    upper bound.  Set it to the maximum possible value, which should work
    since our virtual addresses only go up to 2GB.
    
    +94 piglits.
    
    NOTE: This is a candidate for stable release branches.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=28924
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 3340b47c2280346ba2f44dde44466f09d898b9d8)

diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index c364f40..0343ae1 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -788,7 +788,7 @@ static void upload_state_base_address( struct brw_context *brw )
        OUT_BATCH(1); /* Indirect object base address */
        OUT_RELOC(brw->cache.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
 		 1); /* Instruction base address */
-       OUT_BATCH(1); /* General state upper bound */
+       OUT_BATCH(0xfffff001); /* General state upper bound */
        OUT_BATCH(1); /* Indirect object upper bound */
        OUT_BATCH(1); /* Instruction access upper bound */
        ADVANCE_BATCH();
commit 9489ce6e060adace62be33e26d0c47fbee428387
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 9 09:20:08 2012 -0700

    mesa: fix proxy texture target initialization
    
    The mapping from TEXTURE_x_INDEX to GL_TEXTURE_x was broken in
    alloc_proxy_textures() because the elements in the targets[] array
    were in the wrong order.
    
    This didn't actually cause any failures since we never really use the
    proxy texture's Target field.  But let's get it right.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit d925b0d4a72147d3bc34e7ba068d48179be93021)

diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 8e9537f..cc49916 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -682,20 +682,25 @@ _mesa_update_texture( struct gl_context *ctx, GLuint new_state )
 static GLboolean
 alloc_proxy_textures( struct gl_context *ctx )
 {
+   /* NOTE: these values must be in the same order as the TEXTURE_x_INDEX
+    * values!
+    */
    static const GLenum targets[] = {
-      GL_TEXTURE_1D,
-      GL_TEXTURE_2D,
-      GL_TEXTURE_3D,
+      GL_TEXTURE_BUFFER,
+      GL_TEXTURE_2D_ARRAY_EXT,
+      GL_TEXTURE_1D_ARRAY_EXT,
+      GL_TEXTURE_EXTERNAL_OES,
       GL_TEXTURE_CUBE_MAP_ARB,
+      GL_TEXTURE_3D,
       GL_TEXTURE_RECTANGLE_NV,
-      GL_TEXTURE_1D_ARRAY_EXT,
-      GL_TEXTURE_2D_ARRAY_EXT,
-      GL_TEXTURE_BUFFER,
-      GL_TEXTURE_EXTERNAL_OES
+      GL_TEXTURE_2D,
+      GL_TEXTURE_1D,
    };
    GLint tgt;
 
    STATIC_ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
+   assert(targets[TEXTURE_2D_INDEX] == GL_TEXTURE_2D);
+   assert(targets[TEXTURE_CUBE_INDEX] == GL_TEXTURE_CUBE_MAP);
 
    for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
       if (!(ctx->Texture.ProxyTex[tgt]
commit c1dd6ddfd09c10080168cc888a25057144bb9458
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Wed Feb 8 09:18:46 2012 -0800

    i965: Remove file i965/junk, accidentally added in 7b36c68
    
    (cherry picked from commit b44c459cc32d0a4e70e86deae245b3097ac360a1)

diff --git a/src/mesa/drivers/dri/i965/junk b/src/mesa/drivers/dri/i965/junk
deleted file mode 100644
index e69de29..0000000
commit 3d3bd0e917c07910dcfd1a1246ef61c02bb23683
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Feb 7 16:03:17 2012 -0800

    i965: Fix HiZ change compiler warning.
    
    (cherry picked from commit 94866ffbb8c2bb6957a763975da859b123d74b16)

diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.c b/src/mesa/drivers/dri/i965/gen6_hiz.c
index 6d46b28..a86c147 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.c
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.c
@@ -72,7 +72,6 @@ gen6_hiz_emit_batch_head(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
    struct intel_context *intel = &brw->intel;
-   struct brw_hiz_state *hiz = &brw->hiz;
 
    /* To ensure that the batch contains only the resolve, flush the batch
     * before beginning and after finishing emitting the resolve packets.
commit e1f9820b47e3f124c49cd2ab4e09328e0cc3e638
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Thu Jan 26 11:01:36 2012 -0800

    i965: Rewrite the HiZ op
    
    This is a combination of 4 commits. The first commit rewrites the HiZ op,
    and remaining three fix bugs introduced by the rewrite.
    
    ======== commit 1 ========
    
    i965: Rewrite the HiZ op
    
    The HiZ op was implemented as a meta-op. This patch reimplements it by
    emitting a special HiZ batch. This fixes several known bugs, and likely
    a lot of undiscovered ones too.
    
    ==== Why the HiZ meta-op needed to die ====
    
    The HiZ op was implemented as a meta-op, which caused lots of trouble. All
    other meta-ops occur as a result of some GL call (for example, glClear and
    glGenerateMipmap), but the HiZ meta-op was special. It was called in
    places that Mesa (in particular, the vbo and swrast modules) did not
    expect---and were not prepared for---state changes to occur (for example:
    glDraw; glCallList; within glBegin/End blocks; and within
    swrast_prepare_render as a result of intel_miptree_map).
    
    In an attempt to work around these unexpected state changes, I added two
    hooks in i965:
      - A hook for glDraw, located in brw_predraw_resolve_buffers (which is
        called in the glDraw path). This hook detected if a predraw resolve
        meta-op had occurred, and would hackishly repropagate some GL state
        if necessary. This ensured that the meta-op state changes would not
        intefere with the vbo module's subsequent execution of glDraw.
      - A hook for glBegin, implemented by brwPrepareExecBegin. This hook
        resolved all buffers before entering
        a glBegin/End block, thus preventing an infinitely recurring call to
        vbo_exec_FlushVertices. The vbo module calls vbo_exec_FlushVertices to
        flush its vertex queue in response to GL state changes.
    
    Unfortunately, these hooks were not sufficient. The meta-op state changes
    still interacted badly with glPopAttrib (as discovered in bug 44927) and
    with swrast rendering (as discovered by debugging gen6's swrast fallback
    for glBitmap). I expect there are more undiscovered bugs. Rather than play
    whack-a-mole in a minefield, the sane approach is to replace the HiZ
    meta-op with something safer.
    
    ==== How it was killed ====
    
    This patch consists of several logical components:
      1. Rewrite the HiZ op by replacing function gen6_resolve_slice with
         gen6_hiz_exec and gen7_hiz_exec. The new functions do not call
         a meta-op, but instead manually construct and emit a batch to "draw"
         the HiZ op's rectangle primitive. The new functions alter no GL
         state.
      2. Add fields to brw_context::hiz for the new HiZ op.
      3. Emit a workaround flush when toggling 3DSTATE_VS.VsFunctionEnable.
      4. Kill all dead HiZ code:
         - the function gen6_resolve_slice
         - the dirty flag BRW_NEW_HIZ
         - the dead fields in brw_context::hiz
         - the state packet manipulation triggered by the now removed
           brw_context::hiz::op
         - the meta-op workaround in brw_predraw_resolve_buffers (discussed
           above)
         - the meta-op workaround brwPrepareExecBegin (discussed above)
    
    Note: This is a candidate for the 8.0 branch.
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Acked-by: Paul Berry <stereotype441 at gmail.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43327
    Reported-by: xunx.fang at intel.com
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44927
    Reported-by: chao.a.chen at intel.com
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 7b36c68ba6899c7f30fd56b7ef07a78b027771ac)
    
    ======== commit 2 ========
    
    i965/gen7: Fix GPU hangs from the HiZ op.
    
    The wm max threads is in the same dword as the dispatch enable.  The
    hardware gets super angry if you set max threads to 0, even if you
    aren't dispatching threads.
    (cherry picked from commit e5b225afbd581ccf5d61e9d6c566e26e74abe91e)
    
    ======== commit 3 ========
    
    i965/gen7: Fix the length of the DS state packet in the HiZ op.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit cdcfaa64e3a237517a1e1c913e8ea18d8bc5fa63)
    
    ======== commit 4 ========
    
    i965/gen7: Fix the length of the MULTISAMPLE state packet in the HiZ op.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit a7750c9fb5db9d76318c35a901f5359bf586cddf)

diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources
index 3eeac6f..dad6076 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -101,6 +101,7 @@ i965_C_SOURCES := \
 	gen7_cc_state.c \
 	gen7_clip_state.c \
 	gen7_disable.c \
+	gen7_hiz.c \
 	gen7_misc_state.c \
 	gen7_sampler_state.c \
 	gen7_sf_state.c \
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index f7bda1d..a66ccc7 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -41,8 +41,6 @@
 #include "brw_draw.h"
 #include "brw_state.h"
 
-#include "gen6_hiz.h"
-
 #include "intel_fbo.h"
 #include "intel_mipmap_tree.h"
 #include "intel_regions.h"
@@ -57,58 +55,6 @@
  * Mesa's Driver Functions
  ***************************************/
 
-/**
- * \brief Prepare for entry into glBegin/glEnd block.
- *
- * Resolve buffers before entering a glBegin/glEnd block. This is
- * necessary to prevent recursive calls to FLUSH_VERTICES.
- *
- * This resolves the depth buffer of each enabled depth texture and the HiZ
- * buffer of the attached depth renderbuffer.
- *
- * Details
- * -------
- * When vertices are queued during a glBegin/glEnd block, those vertices must
- * be drawn before any rendering state changes. To ensure this, Mesa calls
- * FLUSH_VERTICES as a prehook to such state changes. Therefore,
- * FLUSH_VERTICES itself cannot change rendering state without falling into a
- * recursive trap.
- *
- * This precludes meta-ops, namely buffer resolves, from occurring while any
- * vertices are queued. To prevent that situation, we resolve some buffers on
- * entering a glBegin/glEnd
- *
- * \see brwCleanupExecEnd()
- */
-static void brwPrepareExecBegin(struct gl_context *ctx)
-{
-   struct brw_context *brw = brw_context(ctx);
-   struct intel_context *intel = &brw->intel;
-   struct intel_renderbuffer *draw_irb;
-   struct intel_texture_object *tex_obj;
-
-   if (!intel->has_hiz) {
-      /* The context uses no feature that requires buffer resolves. */
-      return;
-   }
-
-   /* Resolve each enabled texture. */
-   for (int i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
-      if (!ctx->Texture.Unit[i]._ReallyEnabled)
-	 continue;
-      tex_obj = intel_texture_object(ctx->Texture.Unit[i]._Current);
-      if (!tex_obj || !tex_obj->mt)
-	 continue;
-      intel_miptree_all_slices_resolve_depth(intel, tex_obj->mt);
-   }
-
-   /* Resolve the attached depth buffer. */
-   draw_irb = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_DEPTH);
-   if (draw_irb) {
-      intel_renderbuffer_resolve_hiz(intel, draw_irb);
-   }
-}
-
 static void brwInitDriverFunctions(struct intel_screen *screen,
 				   struct dd_function_table *functions)
 {
@@ -117,7 +63,6 @@ static void brwInitDriverFunctions(struct intel_screen *screen,
    brwInitFragProgFuncs( functions );
    brw_init_queryobj_functions(functions);
 
-   functions->PrepareExecBegin = brwPrepareExecBegin;
    functions->BeginTransformFeedback = brw_begin_transform_feedback;
 
    if (screen->gen >= 7)
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index c027bef..72e5059 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -119,6 +119,10 @@
 #define BRW_MAX_CURBE                    (32*16)
 
 struct brw_context;
+struct brw_instruction;
+struct brw_vs_prog_key;
+struct brw_wm_prog_key;
+struct brw_wm_prog_data;
 
 enum brw_state_id {
    BRW_STATE_URB_FENCE,
@@ -144,7 +148,6 @@ enum brw_state_id {
    BRW_STATE_VS_CONSTBUF,
    BRW_STATE_PROGRAM_CACHE,
    BRW_STATE_STATE_BASE_ADDRESS,
-   BRW_STATE_HIZ,
    BRW_STATE_SOL_INDICES,
 };
 
@@ -174,7 +177,6 @@ enum brw_state_id {
 #define BRW_NEW_VS_CONSTBUF            (1 << BRW_STATE_VS_CONSTBUF)
 #define BRW_NEW_PROGRAM_CACHE		(1 << BRW_STATE_PROGRAM_CACHE)
 #define BRW_NEW_STATE_BASE_ADDRESS	(1 << BRW_STATE_STATE_BASE_ADDRESS)
-#define BRW_NEW_HIZ			(1 << BRW_STATE_HIZ)
 #define BRW_NEW_SOL_INDICES		(1 << BRW_STATE_SOL_INDICES)
 
 struct brw_state_flags {
@@ -950,38 +952,18 @@ struct brw_context
    int state_batch_count;
 
    /**
-    * \brief State needed to execute HiZ meta-ops
+    * \brief State needed to execute HiZ ops.
     *
-    * All fields except \c op are initialized by gen6_hiz_init().
+    * \see gen6_hiz_init()
+    * \see gen6_hiz_exec()
     */
    struct brw_hiz_state {
-      /**
-       * \brief Indicates which HiZ operation is in progress.
+      /** \brief VBO for rectangle primitive.
        *
-       * See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
-       *   - 7.5.3.1 Depth Buffer Clear
-       *   - 7.5.3.2 Depth Buffer Resolve
-       *   - 7.5.3.3 Hierarchical Depth Buffer Resolve
+       * Rather than using glGenBuffers(), we allocate the VBO directly
+       * through drm.
        */
-      enum brw_hiz_op {
-	 BRW_HIZ_OP_NONE = 0,
-	 BRW_HIZ_OP_DEPTH_CLEAR,
-	 BRW_HIZ_OP_DEPTH_RESOLVE,
-	 BRW_HIZ_OP_HIZ_RESOLVE,
-      } op;
-
-      /** \brief Shader state */
-      struct {
-	 GLuint program;
-	 GLuint position_vbo;
-	 GLint position_location;
-      } shader;
-
-      /** \brief VAO for the rectangle primitive's vertices. */
-      GLuint vao;
-
-      GLuint fbo;
-      struct gl_renderbuffer *depth_rb;
+      drm_intel_bo *vertex_bo;
    } hiz;
 
    struct brw_sol_state {
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 621195d..d6f4653 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -126,12 +126,7 @@ static void gen6_set_prim(struct brw_context *brw,
 
    DBG("PRIM: %s\n", _mesa_lookup_enum_by_nr(prim->mode));
 
-   if (brw->hiz.op) {
-      assert(prim->mode == GL_TRIANGLES);
-      hw_prim = _3DPRIM_RECTLIST;
-   } else {
-      hw_prim = prim_to_hw_prim[prim->mode];
-   }
+   hw_prim = prim_to_hw_prim[prim->mode];
 
    if (hw_prim != brw->primitive) {
       brw->primitive = hw_prim;
@@ -307,17 +302,11 @@ brw_predraw_resolve_buffers(struct brw_context *brw)
    struct intel_context *intel = &brw->intel;
    struct intel_renderbuffer *depth_irb;
    struct intel_texture_object *tex_obj;
-   bool did_resolve = false;
-
-   /* Avoid recursive HiZ op. */
-   if (brw->hiz.op) {
-      return;
-   }
 
    /* Resolve the depth buffer's HiZ buffer. */
    depth_irb = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_DEPTH);
    if (depth_irb && depth_irb->mt) {
-      did_resolve |= intel_renderbuffer_resolve_hiz(intel, depth_irb);
+      intel_renderbuffer_resolve_hiz(intel, depth_irb);
    }
 
    /* Resolve depth buffer of each enabled depth texture. */
@@ -327,33 +316,7 @@ brw_predraw_resolve_buffers(struct brw_context *brw)
       tex_obj = intel_texture_object(ctx->Texture.Unit[i]._Current);
       if (!tex_obj || !tex_obj->mt)
 	 continue;
-      did_resolve |= intel_miptree_all_slices_resolve_depth(intel, tex_obj->mt);
-   }
-
-   if (did_resolve) {
-      /* Call vbo_bind_array() to synchronize the vbo module's vertex
-       * attributes to the gl_context's.
-       *
-       * Details
-       * -------
-       * The vbo module tracks vertex attributes separately from the
-       * gl_context.  Specifically, the vbo module maintins vertex attributes
-       * in vbo_exec_context::array::inputs, which is synchronized with
-       * gl_context::Array::ArrayObj::VertexAttrib by vbo_bind_array().
-       * vbo_draw_arrays() calls vbo_bind_array() to perform the
-       * synchronization before calling the real draw call,
-       * vbo_context::draw_arrays.
-       *
-       * At this point (after performing a resolve meta-op but before calling
-       * vbo_bind_array), the gl_context's vertex attributes have been
-       * restored to their original state (that is, their state before the
-       * meta-op began), but the vbo module's vertex attribute are those used
-       * in the last meta-op. Therefore we must manually synchronize the two with
-       * vbo_bind_array() before continuing with the original draw command.
-       */
-      _mesa_update_state(ctx);
-      vbo_bind_arrays(ctx);
-      _mesa_update_state(ctx);
+      intel_miptree_all_slices_resolve_depth(intel, tex_obj->mt);
    }
 }
 
@@ -372,9 +335,7 @@ static void brw_postdraw_set_buffers_need_resolve(struct brw_context *brw)
    struct intel_renderbuffer *depth_irb =
 	 intel_get_renderbuffer(fb, BUFFER_DEPTH);
 
-   if (depth_irb &&
-       ctx->Depth.Mask &&
-       !brw->hiz.op) {
+   if (depth_irb && ctx->Depth.Mask) {
       intel_renderbuffer_set_needs_depth_resolve(depth_irb);
    }
 }
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
index d071f87..f5e6fdc 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -372,7 +372,6 @@ static struct dirty_bit_map brw_bits[] = {
    DEFINE_BIT(BRW_NEW_GS_BINDING_TABLE),
    DEFINE_BIT(BRW_NEW_PS_BINDING_TABLE),
    DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS),
-   DEFINE_BIT(BRW_NEW_HIZ),
    {0, 0, 0}
 };
 
diff --git a/src/mesa/drivers/dri/i965/brw_vtbl.c b/src/mesa/drivers/dri/i965/brw_vtbl.c
index be975d1..724111c 100644
--- a/src/mesa/drivers/dri/i965/brw_vtbl.c
+++ b/src/mesa/drivers/dri/i965/brw_vtbl.c
@@ -50,6 +50,7 @@
 #include "brw_wm.h"
 
 #include "gen6_hiz.h"
+#include "gen7_hiz.h"
 
 #include "glsl/ralloc.h"
 
@@ -70,9 +71,11 @@ static void brw_destroy_context( struct intel_context *intel )
 
    brw_destroy_state(brw);
    brw_draw_destroy( brw );
+
    ralloc_free(brw->wm.compile_data);
 
    dri_bo_release(&brw->curbe.curbe_bo);
+   dri_bo_release(&brw->hiz.vertex_bo);
    dri_bo_release(&brw->vs.const_bo);
    dri_bo_release(&brw->wm.const_bo);
 
@@ -236,8 +239,15 @@ void brwInitVtbl( struct brw_context *brw )
    brw->intel.vtbl.is_hiz_depth_format = brw_is_hiz_depth_format;
 
    if (brw->intel.has_hiz) {
-      brw->intel.vtbl.resolve_depth_slice = gen6_resolve_depth_slice;
-      brw->intel.vtbl.resolve_hiz_slice = gen6_resolve_hiz_slice;
+      if (brw->intel.gen == 7) {
+         brw->intel.vtbl.resolve_depth_slice = gen7_resolve_depth_slice;
+         brw->intel.vtbl.resolve_hiz_slice = gen7_resolve_hiz_slice;
+      } else if (brw->intel.gen == 6) {
+         brw->intel.vtbl.resolve_depth_slice = gen6_resolve_depth_slice;
+         brw->intel.vtbl.resolve_hiz_slice = gen6_resolve_hiz_slice;
+      } else {
+         assert(0);
+      }
    }
 
    if (brw->intel.gen >= 7) {
diff --git a/src/mesa/drivers/dri/i965/gen6_clip_state.c b/src/mesa/drivers/dri/i965/gen6_clip_state.c
index d2a5f75..b3bb8ae 100644
--- a/src/mesa/drivers/dri/i965/gen6_clip_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_clip_state.c
@@ -67,23 +67,6 @@ upload_clip_state(struct brw_context *brw)
          GEN6_CLIP_NON_PERSPECTIVE_BARYCENTRIC_ENABLE;
    }
 
-   if (brw->hiz.op) {
-      /* HiZ operations emit a rectangle primitive, which requires clipping to
-       * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
-       * Section 1.3 3D Primitives Overview:
-       *    RECTLIST:
-       *    Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
-       *    Mode should be set to a value other than CLIPMODE_NORMAL.
-       */
-      BEGIN_BATCH(4);
-      OUT_BATCH(_3DSTATE_CLIP << 16 | (4 - 2));
-      OUT_BATCH(0);
-      OUT_BATCH(0);
-      OUT_BATCH(0);
-      ADVANCE_BATCH();
-      return;
-   }
-
    if (!ctx->Transform.DepthClamp)
       depth_clamp = GEN6_CLIP_Z_TEST;
 
@@ -124,8 +107,7 @@ const struct brw_tracked_state gen6_clip_state = {
    .dirty = {
       .mesa  = _NEW_TRANSFORM | _NEW_LIGHT,
       .brw   = (BRW_NEW_CONTEXT |
-                BRW_NEW_FRAGMENT_PROGRAM |
-                BRW_NEW_HIZ),
+                BRW_NEW_FRAGMENT_PROGRAM),
       .cache = 0
    },
    .emit = upload_clip_state,
diff --git a/src/mesa/drivers/dri/i965/gen6_depthstencil.c b/src/mesa/drivers/dri/i965/gen6_depthstencil.c
index d9f686a..4ea517f 100644
--- a/src/mesa/drivers/dri/i965/gen6_depthstencil.c
+++ b/src/mesa/drivers/dri/i965/gen6_depthstencil.c
@@ -82,11 +82,7 @@ gen6_upload_depth_stencil_state(struct brw_context *brw)
    }
 
    /* _NEW_DEPTH */
-   if ((ctx->Depth.Test || brw->hiz.op) && depth_irb) {
-      assert(brw->hiz.op != BRW_HIZ_OP_DEPTH_RESOLVE || ctx->Depth.Test);
-      assert(brw->hiz.op != BRW_HIZ_OP_HIZ_RESOLVE   || !ctx->Depth.Test);
-      assert(brw->hiz.op != BRW_HIZ_OP_DEPTH_CLEAR   || !ctx->Depth.Test);
-
+   if (ctx->Depth.Test && depth_irb) {
       ds->ds2.depth_test_enable = ctx->Depth.Test;
       ds->ds2.depth_test_func = intel_translate_compare_func(ctx->Depth.Func);
       ds->ds2.depth_write_enable = ctx->Depth.Mask;
@@ -98,8 +94,7 @@ gen6_upload_depth_stencil_state(struct brw_context *brw)
 const struct brw_tracked_state gen6_depth_stencil_state = {
    .dirty = {
       .mesa = _NEW_DEPTH | _NEW_STENCIL | _NEW_BUFFERS,
-      .brw  = (BRW_NEW_BATCH |
-	       BRW_NEW_HIZ),
+      .brw  = BRW_NEW_BATCH,
       .cache = 0,
    },
    .emit = gen6_upload_depth_stencil_state,
diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.c b/src/mesa/drivers/dri/i965/gen6_hiz.c
index d7698ed..6d46b28 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.c
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.c
@@ -21,345 +21,621 @@
  * IN THE SOFTWARE.
  */
 
-#include "gen6_hiz.h"
-
 #include <assert.h>
 
-#include "mesa/drivers/common/meta.h"
-
-#include "mesa/main/arrayobj.h"
-#include "mesa/main/bufferobj.h"
-#include "mesa/main/depth.h"
-#include "mesa/main/enable.h"
-#include "mesa/main/fbobject.h"
-#include "mesa/main/framebuffer.h"
-#include "mesa/main/get.h"
-#include "mesa/main/renderbuffer.h"
-#include "mesa/main/shaderapi.h"
-#include "mesa/main/varray.h"
-
+#include "intel_batchbuffer.h"
 #include "intel_fbo.h"
 #include "intel_mipmap_tree.h"
-#include "intel_regions.h"
-#include "intel_tex.h"
 
 #include "brw_context.h"
 #include "brw_defines.h"
+#include "brw_state.h"
 
-static const uint32_t gen6_hiz_meta_save =
-
-      /* Disable alpha, depth, and stencil test.
-       *
-       * See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
-       *   - 7.5.3.1 Depth Buffer Clear
-       *   - 7.5.3.2 Depth Buffer Resolve
-       *   - 7.5.3.3 Hierarchical Depth Buffer Resolve
-       */
-      MESA_META_ALPHA_TEST |
-      MESA_META_DEPTH_TEST |
-      MESA_META_STENCIL_TEST |
-
-      /* Disable viewport mapping.
-       *
-       * From page 11 of the Sandy Bridge PRM, Volume 2, Part 1, Section 1.3
-       * 3D Primitives Overview:
-       *    RECTLIST:
-       *    Viewport Mapping must be DISABLED (as is typical with the use of
-       *    screen- space coordinates).
-       *
-       * We must also manually disable 3DSTATE_SF.Viewport_Transform_Enable.
-       */
-      MESA_META_VIEWPORT |
-
-      /* Disable clipping.
-       *
-       * From page 11 of the Sandy Bridge PRM, Volume 2, Part 1, Section 1.3
-       * 3D Primitives Overview:
-       *     Either the CLIP unit should be DISABLED, or the CLIP unit’s Clip
-       *     Mode should be set to a value other than CLIPMODE_NORMAL.
-       */
-      MESA_META_CLIP |
-
-      /* Render a solid rectangle (set 3DSTATE_SF.FrontFace_Fill_Mode).
-       *
-       * From page 249 of the Sandy Bridge PRM, Volume 2, Part 1, Section
-       * 6.4.1.1 3DSTATE_SF, FrontFace_Fill_Mode:
-       *     SOLID: Any triangle or rectangle object found to be front-facing
-       *     is rendered as a solid object. This setting is required when
-       *     (rendering rectangle (RECTLIST) objects.
-       * Also see field BackFace_Fill_Mode.
-       *
-       * Note: MESA_META_RASTERIZAION also disables culling, but that is
-       * irrelevant. See 3DSTATE_SF.Cull_Mode.
-       */
-      MESA_META_RASTERIZATION |
-
-      /* Each HiZ operation uses a vertex shader and VAO. */
-      MESA_META_SHADER |
-      MESA_META_VERTEX |
-
-      /* Disable scissoring.
-       *
-       * Scissoring is disabled for resolves because a resolve operation
-       * should resolve the entire buffer. Scissoring is disabled for depth
-       * clears because, if we are performing a partial depth clear, then we
-       * specify the clear region with the RECTLIST vertices.
-       */
-      MESA_META_SCISSOR |
-
-      MESA_META_SELECT_FEEDBACK;
+#include "gen6_hiz.h"
 
-static void
-gen6_hiz_get_framebuffer_enum(struct gl_context *ctx,
-                              GLenum *bind_enum,
-                              GLenum *get_enum)
-{
-   if (ctx->Extensions.EXT_framebuffer_blit && ctx->API == API_OPENGL) {
-      /* Different buffers may be bound to GL_DRAW_FRAMEBUFFER and
-       * GL_READ_FRAMEBUFFER. Take care to not disrupt the read buffer.
-       */
-      *bind_enum = GL_DRAW_FRAMEBUFFER;
-      *get_enum = GL_DRAW_FRAMEBUFFER_BINDING;
-   } else {
-      /* The enums GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER do not exist.
-       * The bound framebuffer is both the read and draw buffer.
-       */
-      *bind_enum = GL_FRAMEBUFFER;
-      *get_enum = GL_FRAMEBUFFER_BINDING;
-   }
-}
+/**
+ * \name Constants for HiZ VBO
+ * \{
+ *
+ * \see brw_context::hiz::vertex_bo
+ */
+#define GEN6_HIZ_NUM_VERTICES 3
+#define GEN6_HIZ_NUM_VUE_ELEMS 8
+#define GEN6_HIZ_VBO_SIZE (GEN6_HIZ_NUM_VERTICES \
+                           * GEN6_HIZ_NUM_VUE_ELEMS \
+                           * sizeof(float))
+/** \} */
 
 /**
- * Initialize static data needed for HiZ operations.
+ * \brief Initialize data needed for the HiZ op.
+ *
+ * This called when executing the first HiZ op.
+ * \see brw_context::hiz
  */
-static void
+void
 gen6_hiz_init(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
+   struct intel_context *intel = &brw->intel;
    struct brw_hiz_state *hiz = &brw->hiz;
-   GLenum fb_bind_enum, fb_get_enum;
 
-   if (hiz->fbo != 0)
-      return;
+   hiz->vertex_bo = drm_intel_bo_alloc(intel->bufmgr, "bufferobj",
+                                       GEN6_HIZ_VBO_SIZE, /* size */
+                                       64); /* alignment */
 
-   gen6_hiz_get_framebuffer_enum(ctx, &fb_bind_enum, &fb_get_enum);
+   if (!hiz->vertex_bo)
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "failed to allocate internal VBO");
+}
 
-   /* Create depthbuffer.
+void
+gen6_hiz_emit_batch_head(struct brw_context *brw)
+{
+   struct gl_context *ctx = &brw->intel.ctx;
+   struct intel_context *intel = &brw->intel;
+   struct brw_hiz_state *hiz = &brw->hiz;
+
+   /* To ensure that the batch contains only the resolve, flush the batch
+    * before beginning and after finishing emitting the resolve packets.
     *
-    * Until glRenderbufferStorage is called, the renderbuffer hash table
-    * maps the renderbuffer name to a dummy renderbuffer. We need the
-    * renderbuffer to be registered in the hash table so that framebuffer
-    * validation succeeds, so we hackishly allocate storage then immediately
-    * discard it.
+    * Ideally, we would not need to flush for the resolve op. But, I suspect
+    * that it's unsafe for CMD_PIPELINE_SELECT to occur multiple times in
+    * a single batch, and there is no safe way to ensure that other than by
+    * fencing the resolve with flushes. Ideally, we would just detect if
+    * a batch is in progress and do the right thing, but that would require
+    * the ability to *safely* access brw_context::state::dirty::brw
+    * outside of the brw_upload_state() codepath.
     */
-   GLuint depth_rb_name;
-   _mesa_GenRenderbuffersEXT(1, &depth_rb_name);
-   _mesa_BindRenderbufferEXT(GL_RENDERBUFFER, depth_rb_name);
-   _mesa_RenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 32, 32);
-   _mesa_reference_renderbuffer(&hiz->depth_rb,
-                                _mesa_lookup_renderbuffer(ctx, depth_rb_name));
-   intel_miptree_release(&((struct intel_renderbuffer*) hiz->depth_rb)->mt);
-
-   /* Setup FBO. */
-   _mesa_GenFramebuffersEXT(1, &hiz->fbo);
-   _mesa_BindFramebufferEXT(fb_bind_enum, hiz->fbo);
-   _mesa_FramebufferRenderbufferEXT(fb_bind_enum,
-                                    GL_DEPTH_ATTACHMENT,
-                                    GL_RENDERBUFFER,
-                                    hiz->depth_rb->Name);
-
-   /* Compile vertex shader. */
-   const char *vs_source =
-      "attribute vec4 position;\n"
-      "void main()\n"
-      "{\n"
-      "   gl_Position = position;\n"
-      "}\n";
-   GLuint vs = _mesa_CreateShaderObjectARB(GL_VERTEX_SHADER);
-   _mesa_ShaderSourceARB(vs, 1, &vs_source, NULL);
-   _mesa_CompileShaderARB(vs);
-
-   /* Compile fragment shader. */
-   const char *fs_source = "void main() {}";
-   GLuint fs = _mesa_CreateShaderObjectARB(GL_FRAGMENT_SHADER);
-   _mesa_ShaderSourceARB(fs, 1, &fs_source, NULL);
-   _mesa_CompileShaderARB(fs);
-
-   /* Link and use program. */
-   hiz->shader.program = _mesa_CreateProgramObjectARB();
-   _mesa_AttachShader(hiz->shader.program, vs);
-   _mesa_AttachShader(hiz->shader.program, fs);
-   _mesa_LinkProgramARB(hiz->shader.program);
-   _mesa_UseProgramObjectARB(hiz->shader.program);
-
-   /* Create and bind VAO. */
-   _mesa_GenVertexArrays(1, &hiz->vao);
-   _mesa_BindVertexArray(hiz->vao);
-
-   /* Setup VBO for 'position'. */
-   hiz->shader.position_location =
-      _mesa_GetAttribLocationARB(hiz->shader.program, "position");
-   _mesa_GenBuffersARB(1, &hiz->shader.position_vbo);
-   _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, hiz->shader.position_vbo);
-   _mesa_VertexAttribPointerARB(hiz->shader.position_location,
-				2, /*components*/
-				GL_FLOAT,
-				GL_FALSE, /*normalized?*/
-				0, /*stride*/
-				NULL);
-   _mesa_EnableVertexAttribArrayARB(hiz->shader.position_location);
-
-   /* Cleanup. */
-   _mesa_DeleteShader(vs);
-   _mesa_DeleteShader(fs);
+   intel_flush(ctx);
+
+   /* CMD_PIPELINE_SELECT
+    *
+    * Select the 3D pipeline, as opposed to the media pipeline.
+    */
+   {
+      BEGIN_BATCH(1);
+      OUT_BATCH(brw->CMD_PIPELINE_SELECT << 16);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_MULTISAMPLE */
+   {
+      int length = intel->gen == 7 ? 4 : 3;
+
+      BEGIN_BATCH(length);
+      OUT_BATCH(_3DSTATE_MULTISAMPLE << 16 | (length - 2));
+      OUT_BATCH(MS_PIXEL_LOCATION_CENTER |
+                MS_NUMSAMPLES_1);
+      OUT_BATCH(0);
+      if (length >= 4)
+         OUT_BATCH(0);
+      ADVANCE_BATCH();
+
+   }
+
+   /* 3DSTATE_SAMPLE_MASK */
+   {
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_SAMPLE_MASK << 16 | (2 - 2));
+      OUT_BATCH(1);
+      ADVANCE_BATCH();
+   }
+
+   /* CMD_STATE_BASE_ADDRESS
+    *
+    * From the Sandy Bridge PRM, Volume 1, Part 1, Table STATE_BASE_ADDRESS:
+    *     The following commands must be reissued following any change to the
+    *     base addresses:
+    *         3DSTATE_CC_POINTERS
+    *         3DSTATE_BINDING_TABLE_POINTERS
+    *         3DSTATE_SAMPLER_STATE_POINTERS
+    *         3DSTATE_VIEWPORT_STATE_POINTERS
+    *         MEDIA_STATE_POINTERS
+    */
+   {
+      BEGIN_BATCH(10);
+      OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (10 - 2));
+      OUT_BATCH(1); /* GeneralStateBaseAddressModifyEnable */
+      /* SurfaceStateBaseAddress */
+      OUT_RELOC(intel->batch.bo, I915_GEM_DOMAIN_SAMPLER, 0, 1);
+      /* DynamicStateBaseAddress */
+      OUT_RELOC(intel->batch.bo, (I915_GEM_DOMAIN_RENDER |
+                                  I915_GEM_DOMAIN_INSTRUCTION), 0, 1);
+      OUT_BATCH(1); /* IndirectObjectBaseAddress */
+      OUT_BATCH(1); /* InstructionBaseAddress */
+      OUT_BATCH(1); /* GeneralStateUpperBound */
+      OUT_BATCH(1); /* DynamicStateUpperBound */
+      OUT_BATCH(1); /* IndirectObjectUpperBound*/
+      OUT_BATCH(1); /* InstructionAccessUpperBound */
+      ADVANCE_BATCH();
+   }
 }
 
-/**
- * Wrap \c brw->hiz.depth_rb around a miptree.
- *
- * \see gen6_hiz_teardown_depth_buffer()
- */
-static void
-gen6_hiz_setup_depth_buffer(struct brw_context *brw,
-			    struct intel_mipmap_tree *mt,
-			    unsigned int level,
-			    unsigned int layer)
+void
+gen6_hiz_emit_vertices(struct brw_context *brw,
+                       struct intel_mipmap_tree *mt,
+                       unsigned int level,
+                       unsigned int layer)
 {
-   struct gl_renderbuffer *rb = brw->hiz.depth_rb;
-   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+   struct intel_context *intel = &brw->intel;
+   struct brw_hiz_state *hiz = &brw->hiz;
 
-   rb->Format = mt->format;
-   rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
-   rb->InternalFormat = rb->_BaseFormat;
-   rb->Width = mt->level[level].width;
-   rb->Height = mt->level[level].height;
+   /* Setup VBO for the rectangle primitive..
+    *
+    * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
+    * vertices. The vertices reside in screen space with DirectX coordinates
+    * (that is, (0, 0) is the upper left corner).
+    *
+    *   v2 ------ implied
+    *    |        |
+    *    |        |
+    *   v0 ----- v1
+    *
+    * Since the VS is disabled, the clipper loads each VUE directly from
+    * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
+    * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
+    *   dw0: Reserved, MBZ.
+    *   dw1: Render Target Array Index. The HiZ op does not use indexed
+    *        vertices, so set the dword to 0.
+    *   dw2: Viewport Index. The HiZ op disables viewport mapping and
+    *        scissoring, so set the dword to 0.
+    *   dw3: Point Width: The HiZ op does not emit the POINTLIST primitive, so
+    *        set the dword to 0.
+    *   dw4: Vertex Position X.
+    *   dw5: Vertex Position Y.
+    *   dw6: Vertex Position Z.
+    *   dw7: Vertex Position W.
+    *
+    * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
+    * "Vertex URB Entry (VUE) Formats".
+    */
+   {
+      const int width = mt->level[level].width;
+      const int height = mt->level[level].height;
 
-   irb->mt_level = level;
-   irb->mt_layer = layer;
+      const float vertices[GEN6_HIZ_VBO_SIZE] = {
+         /* v0 */ 0, 0, 0, 0,         0, height, 0, 1,
+         /* v1 */ 0, 0, 0, 0,     width, height, 0, 1,
+         /* v2 */ 0, 0, 0, 0,         0,      0, 0, 1,
+      };
 
-   intel_miptree_reference(&irb->mt, mt);
-   intel_renderbuffer_set_draw_offset(irb);
+      drm_intel_bo_subdata(hiz->vertex_bo, 0, GEN6_HIZ_VBO_SIZE, vertices);
+   }
+
+   /* 3DSTATE_VERTEX_BUFFERS */
+   {
+      const int num_buffers = 1;
+      const int batch_length = 1 + 4 * num_buffers;
+
+      uint32_t dw0 = GEN6_VB0_ACCESS_VERTEXDATA |
+                     (GEN6_HIZ_NUM_VUE_ELEMS * sizeof(float)) << BRW_VB0_PITCH_SHIFT;
+
+      if (intel->gen >= 7)
+         dw0 |= GEN7_VB0_ADDRESS_MODIFYENABLE;
+
+      BEGIN_BATCH(batch_length);
+      OUT_BATCH((_3DSTATE_VERTEX_BUFFERS << 16) | (batch_length - 2));
+      OUT_BATCH(dw0);
+      /* start address */
+      OUT_RELOC(hiz->vertex_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
+      /* end address */
+      OUT_RELOC(hiz->vertex_bo, I915_GEM_DOMAIN_VERTEX,
+                0, hiz->vertex_bo->size - 1);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_VERTEX_ELEMENTS
+    *
+    * Fetch dwords 0 - 7 from each VUE. See the comments above where
+    * hiz->vertex_bo is filled with data.
+    */
+   {
+      const int num_elements = 2;
+      const int batch_length = 1 + 2 * num_elements;
+
+      BEGIN_BATCH(batch_length);
+      OUT_BATCH((_3DSTATE_VERTEX_ELEMENTS << 16) | (batch_length - 2));
+      /* Element 0 */
+      OUT_BATCH(GEN6_VE0_VALID |
+                BRW_SURFACEFORMAT_R32G32B32A32_FLOAT << BRW_VE0_FORMAT_SHIFT |
+                0 << BRW_VE0_SRC_OFFSET_SHIFT);
+      OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_0_SHIFT |
+                BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_1_SHIFT |
+                BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_2_SHIFT |
+                BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_3_SHIFT);
+      /* Element 1 */
+      OUT_BATCH(GEN6_VE0_VALID |
+                BRW_SURFACEFORMAT_R32G32B32A32_FLOAT << BRW_VE0_FORMAT_SHIFT |
+                16 << BRW_VE0_SRC_OFFSET_SHIFT);
+      OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_0_SHIFT |
+                BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_1_SHIFT |
+                BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_2_SHIFT |
+                BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_3_SHIFT);
+      ADVANCE_BATCH();
+   }
 }
 
 /**
- * Release the region from \c brw->hiz.depth_rb.
+ * \brief Execute a HiZ op on a miptree slice.
+ *
+ * To execute the HiZ op, this function manually constructs and emits a batch
+ * to "draw" the HiZ op's rectangle primitive. The batchbuffer is flushed
+ * before constructing and after emitting the batch.
  *
- * \see gen6_hiz_setup_depth_buffer()
+ * This function alters no GL state.
+ *
+ * For an overview of HiZ ops, see the following sections of the Sandy Bridge
+ * PRM, Volume 1, Part 2:
+ *   - 7.5.3.1 Depth Buffer Clear
+ *   - 7.5.3.2 Depth Buffer Resolve
+ *   - 7.5.3.3 Hierarchical Depth Buffer Resolve
  */
 static void
-gen6_hiz_teardown_depth_buffer(struct gl_renderbuffer *rb)
-{
-   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
-   intel_miptree_release(&irb->mt);
-}
-
-static void
-gen6_resolve_slice(struct intel_context *intel,
-	         struct intel_mipmap_tree *mt,
-		 unsigned int level,
-		 unsigned int layer,
-                 enum brw_hiz_op op)
+gen6_hiz_exec(struct intel_context *intel,
+              struct intel_mipmap_tree *mt,
+              unsigned int level,
+              unsigned int layer,
+              enum gen6_hiz_op op)
 {
    struct gl_context *ctx = &intel->ctx;
    struct brw_context *brw = brw_context(ctx);
    struct brw_hiz_state *hiz = &brw->hiz;
-   GLenum fb_bind_enum, fb_get_enum;
-
-   /* Do not recurse. */
-   assert(!brw->hiz.op);
 
+   assert(op != GEN6_HIZ_OP_DEPTH_CLEAR); /* Not implemented yet. */
    assert(mt->hiz_mt != NULL);
-   assert(level >= mt->first_level);
-   assert(level <= mt->last_level);
-   assert(layer < mt->level[level].depth);
-
-   gen6_hiz_get_framebuffer_enum(ctx, &fb_bind_enum, &fb_get_enum);
-
-   /* Save state. */
-   GLint save_drawbuffer;
-   GLint save_renderbuffer;
-   _mesa_meta_begin(ctx, gen6_hiz_meta_save);
-   _mesa_GetIntegerv(fb_get_enum, &save_drawbuffer);
-   _mesa_GetIntegerv(GL_RENDERBUFFER_BINDING, &save_renderbuffer);
-
-   /* Initialize context data for HiZ operations. */
-   gen6_hiz_init(brw);
-
-   /* Set depth state. */
-   if (!ctx->Depth.Mask) {
-      /* This sets 3DSTATE_WM.Depth_Buffer_Write_Enable. */
-      _mesa_DepthMask(GL_TRUE);
+   intel_miptree_check_level_layer(mt, level, layer);
+
+   if (hiz->vertex_bo == NULL)
+      gen6_hiz_init(brw);
+
+   if (hiz->vertex_bo == NULL) {
+      /* Ouch. Give up. */
+      return;
    }
-   if (op == BRW_HIZ_OP_DEPTH_RESOLVE) {
-      _mesa_set_enable(ctx, GL_DEPTH_TEST, GL_TRUE);
-      _mesa_DepthFunc(GL_NEVER);
+
+   gen6_hiz_emit_batch_head(brw);
+   gen6_hiz_emit_vertices(brw, mt, level, layer);
+
+   /* 3DSTATE_URB
+    *
+    * Assign the entire URB to the VS. Even though the VS disabled, URB space
+    * is still needed because the clipper loads the VUE's from the URB. From
+    * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
+    * Dword 1.15:0 "VS Number of URB Entries":
+    *     This field is always used (even if VS Function Enable is DISABLED).
+    *
+    * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
+    * safely ignore it because this batch contains only one draw call.
+    *     Because of URB corruption caused by allocating a previous GS unit
+    *     URB entry to the VS unit, software is required to send a “GS NULL
+    *     Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
+    *     plus a dummy DRAW call before any case where VS will be taking over
+    *     GS URB space.
+    */
+   {
+      BEGIN_BATCH(3);
+      OUT_BATCH(_3DSTATE_URB << 16 | (3 - 2));
+      OUT_BATCH(brw->urb.max_vs_entries << GEN6_URB_VS_ENTRIES_SHIFT);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
    }
 
-   /* Setup FBO. */
-   gen6_hiz_setup_depth_buffer(brw, mt, level, layer);
-   _mesa_BindFramebufferEXT(fb_bind_enum, hiz->fbo);
+   /* 3DSTATE_CC_STATE_POINTERS
+    *
+    * The pointer offsets are relative to
+    * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
+    *
+    * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
+    */
+   {
+      uint32_t depthstencil_offset;
+      gen6_hiz_emit_depth_stencil_state(brw, op, &depthstencil_offset);
+
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_CC_STATE_POINTERS << 16 | (4 - 2));
+      OUT_BATCH(1); /* BLEND_STATE offset */
+      OUT_BATCH(depthstencil_offset | 1); /* DEPTH_STENCIL_STATE offset */
+      OUT_BATCH(1); /* COLOR_CALC_STATE offset */
+      ADVANCE_BATCH();
+   }
 
+   /* 3DSTATE_VS
+    *
+    * Disable vertex shader.
+    */
+   {
+      /* From the BSpec, Volume 2a, Part 3 "Vertex Shader", Section
+       * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
+       *   [DevSNB] A pipeline flush must be programmed prior to a 3DSTATE_VS
+       *   command that causes the VS Function Enable to toggle. Pipeline
+       *   flush can be executed by sending a PIPE_CONTROL command with CS
+       *   stall bit set and a post sync operation.
+       */
+      intel_emit_post_sync_nonzero_flush(intel);
+
+      BEGIN_BATCH(6);
+      OUT_BATCH(_3DSTATE_VS << 16 | (6 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
 
-   /* A rectangle primitive (3DPRIM_RECTLIST) consists of only three vertices.
-    * The vertices reside in screen space with DirectX coordinates (this is,
-    * (0, 0) is the upper left corner).
+   /* 3DSTATE_GS
     *
-    *   v2 ------ implied
-    *    |        |
-    *    |        |
-    *   v0 ----- v1
+    * Disable the geometry shader.
     */
-   const int width = hiz->depth_rb->Width;
-   const int height = hiz->depth_rb->Height;
-   const GLfloat positions[] = {
-          0, height,
-      width, height,
-          0,      0,
-   };
-
-   /* Setup program and vertex attributes. */
-   _mesa_UseProgramObjectARB(hiz->shader.program);
-   _mesa_BindVertexArray(hiz->vao);
-   _mesa_BindBufferARB(GL_ARRAY_BUFFER, hiz->shader.position_vbo);
-   _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(positions), positions,
-		       GL_DYNAMIC_DRAW_ARB);
-
-   /* Execute the HiZ operation. */
-   brw->hiz.op = op;
-   brw->state.dirty.brw |= BRW_NEW_HIZ;
-   _mesa_DrawArrays(GL_TRIANGLES, 0, 3);
-   brw->state.dirty.brw |= BRW_NEW_HIZ;
-   brw->hiz.op = BRW_HIZ_OP_NONE;
-
-   /* Restore state.
+   {
+      BEGIN_BATCH(7);
+      OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_CLIP
+    *
+    * Disable the clipper.
     *
-    * The order in which state is restored is significant. The draw buffer
-    * used for the HiZ op has no stencil buffer, and glStencilFunc() clamps
-    * the stencil reference value to the range allowed by the draw buffer's
-    * number of stencil bits. So, the draw buffer binding must be restored
-    * before the stencil state, or else the stencil ref will be clamped to 0.
+    * The HiZ op emits a rectangle primitive, which requires clipping to
+    * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
+    * Section 1.3 "3D Primitives Overview":
+    *    RECTLIST:
+    *    Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
+    *    Mode should be set to a value other than CLIPMODE_NORMAL.
+    *
+    * Also disable perspective divide. This doesn't change the clipper's
+    * output, but does spare a few electrons.
     */
-   gen6_hiz_teardown_depth_buffer(hiz->depth_rb);
-   _mesa_BindRenderbufferEXT(GL_RENDERBUFFER, save_renderbuffer);
-   _mesa_BindFramebufferEXT(fb_bind_enum, save_drawbuffer);
-   _mesa_meta_end(ctx);
+   {
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_CLIP << 16 | (4 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(GEN6_CLIP_PERSPECTIVE_DIVIDE_DISABLE);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_SF
+    *
+    * Disable ViewportTransformEnable (dw2.1)
+    *
+    * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
+    * Primitives Overview":
+    *     RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
+    *     use of screen- space coordinates).
+    *
+    * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
+    * and BackFaceFillMode (dw2.5:6) to SOLID(0).
+    *
+    * From the Sandy Bridge PRM, Volume 2, Part 1, Section
+    * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
+    *     SOLID: Any triangle or rectangle object found to be front-facing
+    *     is rendered as a solid object. This setting is required when
+    *     (rendering rectangle (RECTLIST) objects.
+    */
+   {
+      BEGIN_BATCH(20);
+      OUT_BATCH(_3DSTATE_SF << 16 | (20 - 2));
+      OUT_BATCH((1 - 1) << GEN6_SF_NUM_OUTPUTS_SHIFT | /* only position */
+                1 << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT |
+                0 << GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT);
+      for (int i = 0; i < 18; ++i)
+         OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_WM
+    *
+    * Disable thread dispatch (dw5.19) and enable the HiZ op.
+    *
+    * Even though thread dispatch is disabled, max threads (dw5.25:31) must be
+    * nonzero to prevent the GPU from hanging. See the valid ranges in the
+    * BSpec, Volume 2a.11 Windower, Section 3DSTATE_WM, Dword 5.25:31
+    * "Maximum Number Of Threads".
+    */
+   {
+      uint32_t dw4 = 0;
+
+      switch (op) {
+      case GEN6_HIZ_OP_DEPTH_CLEAR:
+         assert(!"not implemented");
+         dw4 |= GEN6_WM_DEPTH_CLEAR;
+         break;
+      case GEN6_HIZ_OP_DEPTH_RESOLVE:
+         dw4 |= GEN6_WM_DEPTH_RESOLVE;
+         break;
+      case GEN6_HIZ_OP_HIZ_RESOLVE:
+         dw4 |= GEN6_WM_HIERARCHICAL_DEPTH_RESOLVE;
+         break;
+      default:
+         assert(0);
+         break;
+      }
+
+      BEGIN_BATCH(9);
+      OUT_BATCH(_3DSTATE_WM << 16 | (9 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(dw4);
+      OUT_BATCH((brw->max_wm_threads - 1) << GEN6_WM_MAX_THREADS_SHIFT);
+      OUT_BATCH((1 - 1) << GEN6_WM_NUM_SF_OUTPUTS_SHIFT); /* only position */
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_DEPTH_BUFFER */
+   {
+      uint32_t width = mt->level[level].width;
+      uint32_t height = mt->level[level].height;
+
+      uint32_t tile_x;
+      uint32_t tile_y;
+      uint32_t offset;
+      {
+         /* Construct a dummy renderbuffer just to extract tile offsets. */
+         struct intel_renderbuffer rb;
+         rb.mt = mt;
+         rb.mt_level = level;
+         rb.mt_layer = layer;
+         intel_renderbuffer_set_draw_offset(&rb);
+         offset = intel_renderbuffer_tile_offsets(&rb, &tile_x, &tile_y);
+      }
+
+      uint32_t format;
+      switch (mt->format) {
+      case MESA_FORMAT_Z16:       format = BRW_DEPTHFORMAT_D16_UNORM; break;
+      case MESA_FORMAT_Z32_FLOAT: format = BRW_DEPTHFORMAT_D32_FLOAT; break;
+      case MESA_FORMAT_X8_Z24:    format = BRW_DEPTHFORMAT_D24_UNORM_X8_UINT; break;
+      default:                    assert(0); break;
+      }
+
+      intel_emit_post_sync_nonzero_flush(intel);
+      intel_emit_depth_stall_flushes(intel);
+
+      BEGIN_BATCH(7);
+      OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
+      OUT_BATCH(((mt->region->pitch * mt->region->cpp) - 1) |
+                format << 18 |
+                1 << 21 | /* separate stencil enable */
+                1 << 22 | /* hiz enable */
+                BRW_TILEWALK_YMAJOR << 26 |
+                1 << 27 | /* y-tiled */
+                BRW_SURFACE_2D << 29);
+      OUT_RELOC(mt->region->bo,
+                I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                offset);
+      OUT_BATCH(BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1 |
+                (width + tile_x - 1) << 6 |
+                (height + tile_y - 1) << 19);
+      OUT_BATCH(0);
+      OUT_BATCH(tile_x |
+                tile_y << 16);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_HIER_DEPTH_BUFFER */
+   {
+      struct intel_region *hiz_region = mt->hiz_mt->region;
+
+      BEGIN_BATCH(3);
+      OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
+      OUT_BATCH(hiz_region->pitch * hiz_region->cpp - 1);
+      OUT_RELOC(hiz_region->bo,
+                I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_STENCIL_BUFFER */
+   {
+      BEGIN_BATCH(3);
+      OUT_BATCH((_3DSTATE_STENCIL_BUFFER << 16) | (3 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_CLEAR_PARAMS
+    *
+    * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
+    *   [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
+    *   packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
+    */
+   {
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_CLEAR_PARAMS << 16 | (2 - 2));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_DRAWING_RECTANGLE */
+   {
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_DRAWING_RECTANGLE << 16 | (4 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(((mt->level[level].width - 1) & 0xffff) |
+                ((mt->level[level].height - 1) << 16));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DPRIMITIVE */
+   {
+     BEGIN_BATCH(6);
+     OUT_BATCH(CMD_3D_PRIM << 16 | (6 - 2) |
+               _3DPRIM_RECTLIST << GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT |
+               GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL);
+     OUT_BATCH(3); /* vertex count per instance */
+     OUT_BATCH(0);
+     OUT_BATCH(1); /* instance count */
+     OUT_BATCH(0);
+     OUT_BATCH(0);
+     ADVANCE_BATCH();
+   }
+
+   /* See comments above at first invocation of intel_flush() in
+    * gen6_hiz_emit_batch_head().
+    */
+   intel_flush(ctx);
+
+   /* Be safe. */
+   brw->state.dirty.brw = ~0;
+   brw->state.dirty.cache = ~0;
 }
 
+/**
+ * \param out_offset is relative to
+ *        CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
+ */
+void
+gen6_hiz_emit_depth_stencil_state(struct brw_context *brw,
+                                  enum gen6_hiz_op op,
+                                  uint32_t *out_offset)
+{
+   struct gen6_depth_stencil_state *state;
+   state = brw_state_batch(brw, AUB_TRACE_DEPTH_STENCIL_STATE,
+                              sizeof(*state), 64,
+                              out_offset);
+   memset(state, 0, sizeof(*state));
+
+   /* See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
+    *   - 7.5.3.1 Depth Buffer Clear
+    *   - 7.5.3.2 Depth Buffer Resolve
+    *   - 7.5.3.3 Hierarchical Depth Buffer Resolve
+    */
+   state->ds2.depth_write_enable = 1;
+   if (op == GEN6_HIZ_OP_DEPTH_RESOLVE) {
+      state->ds2.depth_test_enable = 1;
+      state->ds2.depth_test_func = COMPAREFUNC_NEVER;
+   }
+}
+
+/** \see intel_context::vtbl::resolve_hiz_slice */
 void
 gen6_resolve_hiz_slice(struct intel_context *intel,
                        struct intel_mipmap_tree *mt,
                        uint32_t level,
                        uint32_t layer)
 {
-   gen6_resolve_slice(intel, mt, level, layer, BRW_HIZ_OP_HIZ_RESOLVE);
+   gen6_hiz_exec(intel, mt, level, layer, GEN6_HIZ_OP_HIZ_RESOLVE);
 }
 
-
+/** \see intel_context::vtbl::resolve_depth_slice */
 void
 gen6_resolve_depth_slice(struct intel_context *intel,
                          struct intel_mipmap_tree *mt,
                          uint32_t level,
                          uint32_t layer)
 {
-   gen6_resolve_slice(intel, mt, level, layer, BRW_HIZ_OP_DEPTH_RESOLVE);
+   gen6_hiz_exec(intel, mt, level, layer, GEN6_HIZ_OP_DEPTH_RESOLVE);
 }
diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.h b/src/mesa/drivers/dri/i965/gen6_hiz.h
index 4929012..0a13ba0 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.h
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.h
@@ -28,6 +28,44 @@
 struct intel_context;
 struct intel_mipmap_tree;
 
+/**
+ * For an overview of the HiZ operations, see the following sections of the
+ * Sandy Bridge PRM, Volume 1, Part2:
+ *   - 7.5.3.1 Depth Buffer Clear
+ *   - 7.5.3.2 Depth Buffer Resolve
+ *   - 7.5.3.3 Hierarchical Depth Buffer Resolve
+ */
+enum gen6_hiz_op {
+   GEN6_HIZ_OP_DEPTH_CLEAR,
+   GEN6_HIZ_OP_DEPTH_RESOLVE,
+   GEN6_HIZ_OP_HIZ_RESOLVE,
+};
+
+/**
+ * \name HiZ internals
+ * \{
+ *
+ * Used internally by gen6_hiz_exec() and gen7_hiz_exec().
+ */
+
+void
+gen6_hiz_init(struct brw_context *brw);
+
+void
+gen6_hiz_emit_batch_head(struct brw_context *brw);
+
+void
+gen6_hiz_emit_vertices(struct brw_context *brw,
+                       struct intel_mipmap_tree *mt,
+                       unsigned int level,
+                       unsigned int layer);
+
+void
+gen6_hiz_emit_depth_stencil_state(struct brw_context *brw,
+                                  enum gen6_hiz_op op,
+                                  uint32_t *out_offset);
+/** \} */
+
 void
 gen6_resolve_hiz_slice(struct intel_context *intel,
                        struct intel_mipmap_tree *mt,
diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c b/src/mesa/drivers/dri/i965/gen6_sf_state.c
index 163b54c..07b8e6d 100644
--- a/src/mesa/drivers/dri/i965/gen6_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c
@@ -149,17 +149,8 @@ upload_sf_state(struct brw_context *brw)
       urb_entry_read_length << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT |
       urb_entry_read_offset << GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT;
 
-   dw2 = GEN6_SF_STATISTICS_ENABLE;
-
-   /* Enable viewport transform only if no HiZ operation is progress
-    *
-    * From page 11 of the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
-    * Primitives Overview":
-    *     RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
-    *     use of screen- space coordinates).
-    */
-   if (!brw->hiz.op)
-      dw2 |= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE;
+   dw2 = GEN6_SF_STATISTICS_ENABLE |
+         GEN6_SF_VIEWPORT_TRANSFORM_ENABLE;
 
    dw3 = 0;
    dw4 = 0;
@@ -354,8 +345,7 @@ const struct brw_tracked_state gen6_sf_state = {
 		_NEW_POINT |
 		_NEW_TRANSFORM),
       .brw   = (BRW_NEW_CONTEXT |
-		BRW_NEW_FRAGMENT_PROGRAM |
-		BRW_NEW_HIZ),
+		BRW_NEW_FRAGMENT_PROGRAM),
       .cache = CACHE_NEW_VS_PROG
    },
    .emit = upload_sf_state,
diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c b/src/mesa/drivers/dri/i965/gen6_vs_state.c
index 63efaa4..3392a9f 100644
--- a/src/mesa/drivers/dri/i965/gen6_vs_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c
@@ -133,6 +133,15 @@ upload_vs_state(struct brw_context *brw)
    struct intel_context *intel = &brw->intel;
    uint32_t floating_point_mode = 0;
 
+   /* From the BSpec, Volume 2a, Part 3 "Vertex Shader", Section
+    * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
+    *   [DevSNB] A pipeline flush must be programmed prior to a 3DSTATE_VS
+    *   command that causes the VS Function Enable to toggle. Pipeline
+    *   flush can be executed by sending a PIPE_CONTROL command with CS
+    *   stall bit set and a post sync operation.
+    */
+   intel_emit_post_sync_nonzero_flush(intel);
+
    if (brw->vs.push_const_size == 0) {
       /* Disable the push constant buffers. */
       BEGIN_BATCH(5);
diff --git a/src/mesa/drivers/dri/i965/gen6_wm_state.c b/src/mesa/drivers/dri/i965/gen6_wm_state.c
index 3669811..205e648 100644
--- a/src/mesa/drivers/dri/i965/gen6_wm_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_wm_state.c
@@ -149,23 +149,6 @@ upload_wm_state(struct brw_context *brw)
    dw4 |= (brw->wm.prog_data->first_curbe_grf_16 <<
 	   GEN6_WM_DISPATCH_START_GRF_SHIFT_2);
 
-   switch (brw->hiz.op) {
-   case BRW_HIZ_OP_NONE:
-      break;
-   case BRW_HIZ_OP_DEPTH_CLEAR:
-      dw4 |= GEN6_WM_DEPTH_CLEAR;
-      break;
-   case BRW_HIZ_OP_DEPTH_RESOLVE:
-      dw4 |= GEN6_WM_DEPTH_RESOLVE;
-      break;
-   case BRW_HIZ_OP_HIZ_RESOLVE:
-      dw4 |= GEN6_WM_HIERARCHICAL_DEPTH_RESOLVE;
-      break;
-   default:
-      assert(0);
-      break;
-   }
-
    dw5 |= (brw->max_wm_threads - 1) << GEN6_WM_MAX_THREADS_SHIFT;
 
    /* CACHE_NEW_WM_PROG */
@@ -233,8 +216,7 @@ const struct brw_tracked_state gen6_wm_state = {
 		_NEW_PROGRAM_CONSTANTS |
 		_NEW_POLYGON),
       .brw   = (BRW_NEW_FRAGMENT_PROGRAM |
-		BRW_NEW_BATCH |
-		BRW_NEW_HIZ),
+		BRW_NEW_BATCH),
       .cache = (CACHE_NEW_SAMPLER |
 		CACHE_NEW_WM_PROG)
    },
diff --git a/src/mesa/drivers/dri/i965/gen7_clip_state.c b/src/mesa/drivers/dri/i965/gen7_clip_state.c
index 9be3ce9..c32cd98 100644
--- a/src/mesa/drivers/dri/i965/gen7_clip_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_clip_state.c
@@ -39,23 +39,6 @@ upload_clip_state(struct brw_context *brw)
    /* BRW_NEW_FRAGMENT_PROGRAM */
    const struct gl_fragment_program *fprog = brw->fragment_program;
 
-   if (brw->hiz.op) {
-      /* HiZ operations emit a rectangle primitive, which requires clipping to
-       * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
-       * Section 1.3 3D Primitives Overview:
-       *    RECTLIST:
-       *    Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
-       *    Mode should be set to a value other than CLIPMODE_NORMAL.
-       */
-      BEGIN_BATCH(4);
-      OUT_BATCH(_3DSTATE_CLIP << 16 | (4 - 2));
-      OUT_BATCH(0);
-      OUT_BATCH(0);
-      OUT_BATCH(0);
-      ADVANCE_BATCH();
-      return;
-   }
-
    /* _NEW_BUFFERS */
    bool render_to_fbo = brw->intel.ctx.DrawBuffer->Name != 0;
 
@@ -133,8 +116,7 @@ const struct brw_tracked_state gen7_clip_state = {
                 _NEW_LIGHT |
                 _NEW_TRANSFORM),
       .brw   = (BRW_NEW_CONTEXT |
-                BRW_NEW_FRAGMENT_PROGRAM |
-                BRW_NEW_HIZ),
+                BRW_NEW_FRAGMENT_PROGRAM),
       .cache = 0
    },
    .emit = upload_clip_state,
diff --git a/src/mesa/drivers/dri/i965/gen7_hiz.c b/src/mesa/drivers/dri/i965/gen7_hiz.c
new file mode 100644
index 0000000..34e51ab
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/gen7_hiz.c
@@ -0,0 +1,464 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <assert.h>
+
+#include "intel_batchbuffer.h"
+#include "intel_fbo.h"
+#include "intel_mipmap_tree.h"
+
+#include "brw_context.h"
+#include "brw_defines.h"
+#include "brw_state.h"
+
+#include "gen6_hiz.h"
+#include "gen7_hiz.h"
+
+/**
+ * \copydoc gen6_hiz_exec()
+ */
+static void
+gen7_hiz_exec(struct intel_context *intel,
+              struct intel_mipmap_tree *mt,
+              unsigned int level,
+              unsigned int layer,
+              enum gen6_hiz_op op)
+{
+   struct gl_context *ctx = &intel->ctx;
+   struct brw_context *brw = brw_context(ctx);
+   struct brw_hiz_state *hiz = &brw->hiz;
+
+   assert(op != GEN6_HIZ_OP_DEPTH_CLEAR); /* Not implemented yet. */
+   assert(mt->hiz_mt != NULL);
+   intel_miptree_check_level_layer(mt, level, layer);
+
+   if (hiz->vertex_bo == NULL)
+      gen6_hiz_init(brw);
+
+   if (hiz->vertex_bo == NULL) {
+      /* Ouch. Give up. */
+      return;
+   }
+
+   uint32_t depth_format;
+   switch (mt->format) {
+   case MESA_FORMAT_Z16:       depth_format = BRW_DEPTHFORMAT_D16_UNORM; break;
+   case MESA_FORMAT_Z32_FLOAT: depth_format = BRW_DEPTHFORMAT_D32_FLOAT; break;
+   case MESA_FORMAT_X8_Z24:    depth_format = BRW_DEPTHFORMAT_D24_UNORM_X8_UINT; break;
+   default:                    assert(0); break;
+   }
+
+   gen6_hiz_emit_batch_head(brw);
+   gen6_hiz_emit_vertices(brw, mt, level, layer);
+
+   /* 3DSTATE_URB_VS
+    * 3DSTATE_URB_HS
+    * 3DSTATE_URB_DS
+    * 3DSTATE_URB_GS
+    *
+    * If the 3DSTATE_URB_VS is emitted, than the others must be also. From the
+    * BSpec, Volume 2a "3D Pipeline Overview", Section 1.7.1 3DSTATE_URB_VS:
+    *     3DSTATE_URB_HS, 3DSTATE_URB_DS, and 3DSTATE_URB_GS must also be
+    *     programmed in order for the programming of this state to be
+    *     valid.
+    */
+   {
+      /* The minimum valid value is 32. See 3DSTATE_URB_VS,
+       * Dword 1.15:0 "VS Number of URB Entries".
+       */
+      int num_vs_entries = 32;
+
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_URB_VS << 16 | (2 - 2));
+      OUT_BATCH(1 << GEN7_URB_ENTRY_SIZE_SHIFT |
+                0 << GEN7_URB_STARTING_ADDRESS_SHIFT |
+                num_vs_entries);
+      ADVANCE_BATCH();
+
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_URB_GS << 16 | (2 - 2));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_URB_HS << 16 | (2 - 2));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_URB_DS << 16 | (2 - 2));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_DEPTH_STENCIL_STATE_POINTERS
+    *
+    * The offset is relative to CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
+    */
+   {
+      uint32_t depthstencil_offset;
+      gen6_hiz_emit_depth_stencil_state(brw, op, &depthstencil_offset);
+
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_DEPTH_STENCIL_STATE_POINTERS << 16 | (2 - 2));
+      OUT_BATCH(depthstencil_offset | 1);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_VS
+    *
+    * Disable vertex shader.
+    */
+   {
+      BEGIN_BATCH(6);
+      OUT_BATCH(_3DSTATE_VS << 16 | (6 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_HS
+    *
+    * Disable the hull shader.
+    */
+   {
+      BEGIN_BATCH(7);
+      OUT_BATCH(_3DSTATE_HS << 16 | (7 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_TE
+    *
+    * Disable the tesselation engine.
+    */
+   {
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_TE << 16 | (4 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_DS
+    *
+    * Disable the domain shader.
+    */
+   {
+      BEGIN_BATCH(6);
+      OUT_BATCH(_3DSTATE_DS << 16 | (6 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_GS
+    *
+    * Disable the geometry shader.
+    */
+   {
+      BEGIN_BATCH(7);
+      OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_STREAMOUT
+    *
+    * Disable streamout.
+    */
+   {
+      BEGIN_BATCH(3);
+      OUT_BATCH(_3DSTATE_STREAMOUT << 16 | (3 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_CLIP
+    *
+    * Disable the clipper.
+    *
+    * The HiZ op emits a rectangle primitive, which requires clipping to
+    * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
+    * Section 1.3 "3D Primitives Overview":
+    *    RECTLIST:
+    *    Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
+    *    Mode should be set to a value other than CLIPMODE_NORMAL.
+    *
+    * Also disable perspective divide. This doesn't change the clipper's
+    * output, but does spare a few electrons.
+    */
+   {
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_CLIP << 16 | (4 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(GEN6_CLIP_PERSPECTIVE_DIVIDE_DISABLE);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_SF
+    *
+    * Disable ViewportTransformEnable (dw1.1)
+    *
+    * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
+    * Primitives Overview":
+    *     RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
+    *     use of screen- space coordinates).
+    *
+    * A solid rectangle must be rendered, so set FrontFaceFillMode (dw1.6:5)
+    * and BackFaceFillMode (dw1.4:3) to SOLID(0).
+    *
+    * From the Sandy Bridge PRM, Volume 2, Part 1, Section
+    * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
+    *     SOLID: Any triangle or rectangle object found to be front-facing
+    *     is rendered as a solid object. This setting is required when
+    *     (rendering rectangle (RECTLIST) objects.
+    */
+   {
+      BEGIN_BATCH(7);
+      OUT_BATCH(_3DSTATE_SF << 16 | (7 - 2));
+      OUT_BATCH(depth_format << GEN7_SF_DEPTH_BUFFER_SURFACE_FORMAT_SHIFT);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_SBE */
+   {
+      BEGIN_BATCH(14);
+      OUT_BATCH(_3DSTATE_SBE << 16 | (14 - 2));
+      OUT_BATCH((1 - 1) << GEN7_SBE_NUM_OUTPUTS_SHIFT | /* only position */
+                1 << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT |
+                0 << GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT);
+      for (int i = 0; i < 12; ++i)
+         OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_WM
+    *
+    * Disable PS thread dispatch (dw1.29) and enable the HiZ op.
+    */
+   {
+      uint32_t dw1 = 0;
+
+      switch (op) {
+      case GEN6_HIZ_OP_DEPTH_CLEAR:
+         assert(!"not implemented");
+         dw1 |= GEN7_WM_DEPTH_CLEAR;
+         break;
+      case GEN6_HIZ_OP_DEPTH_RESOLVE:
+         dw1 |= GEN7_WM_DEPTH_RESOLVE;
+         break;
+      case GEN6_HIZ_OP_HIZ_RESOLVE:
+         dw1 |= GEN7_WM_HIERARCHICAL_DEPTH_RESOLVE;
+         break;
+      default:
+         assert(0);
+         break;
+      }
+
+      BEGIN_BATCH(3);
+      OUT_BATCH(_3DSTATE_WM << 16 | (3 - 2));
+      OUT_BATCH(dw1);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_PS
+    *
+    * Pixel shader dispatch is disabled above in 3DSTATE_WM, dw1.29. Despite
+    * that, thread dispatch info must still be specified.
+    *     - Maximum Number of Threads (dw4.24:31) must be nonzero, as the BSpec
+    *       states that the valid range for this field is [0x3, 0x2f].
+    *     - A dispatch mode must be given; that is, at least one of the
+    *       "N Pixel Dispatch Enable" (N=8,16,32) fields must be set. This was
+    *       discovered through simulator error messages.
+    */
+   {
+      BEGIN_BATCH(8);
+      OUT_BATCH(_3DSTATE_PS << 16 | (8 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(((brw->max_wm_threads - 1) << GEN7_PS_MAX_THREADS_SHIFT) |
+		GEN7_PS_32_DISPATCH_ENABLE);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_DEPTH_BUFFER */
+   {
+      uint32_t width = mt->level[level].width;
+      uint32_t height = mt->level[level].height;
+
+      uint32_t tile_x;
+      uint32_t tile_y;
+      uint32_t offset;
+      {
+         /* Construct a dummy renderbuffer just to extract tile offsets. */
+         struct intel_renderbuffer rb;
+         rb.mt = mt;
+         rb.mt_level = level;
+         rb.mt_layer = layer;
+         intel_renderbuffer_set_draw_offset(&rb);
+         offset = intel_renderbuffer_tile_offsets(&rb, &tile_x, &tile_y);
+      }
+
+      intel_emit_depth_stall_flushes(intel);
+
+      BEGIN_BATCH(7);
+      OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
+      OUT_BATCH(((mt->region->pitch * mt->region->cpp) - 1) |
+                depth_format << 18 |
+                1 << 22 | /* hiz enable */
+                1 << 28 | /* depth write */
+                BRW_SURFACE_2D << 29);
+      OUT_RELOC(mt->region->bo,
+                I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                offset);
+      OUT_BATCH((width + tile_x - 1) << 4 |
+                (height + tile_y - 1) << 18);
+      OUT_BATCH(0);
+      OUT_BATCH(tile_x |
+                tile_y << 16);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_HIER_DEPTH_BUFFER */
+   {
+      struct intel_region *hiz_region = mt->hiz_mt->region;
+
+      BEGIN_BATCH(3);
+      OUT_BATCH((GEN7_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
+      OUT_BATCH(hiz_region->pitch * hiz_region->cpp - 1);
+      OUT_RELOC(hiz_region->bo,
+                I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_STENCIL_BUFFER */
+   {
+      BEGIN_BATCH(3);
+      OUT_BATCH((GEN7_3DSTATE_STENCIL_BUFFER << 16) | (3 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_CLEAR_PARAMS
+    *
+    * From the BSpec, Volume 2a.11 Windower, Section 1.5.6.3.2
+    * 3DSTATE_CLEAR_PARAMS:
+    *    [DevIVB] 3DSTATE_CLEAR_PARAMS must always be programmed in the along
+    *    with the other Depth/Stencil state commands(i.e.  3DSTATE_DEPTH_BUFFER,
+    *    3DSTATE_STENCIL_BUFFER, or 3DSTATE_HIER_DEPTH_BUFFER).
+    */
+   {
+      BEGIN_BATCH(3);
+      OUT_BATCH(GEN7_3DSTATE_CLEAR_PARAMS << 16 | (3 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DSTATE_DRAWING_RECTANGLE */
+   {
+      BEGIN_BATCH(4);
+      OUT_BATCH(_3DSTATE_DRAWING_RECTANGLE << 16 | (4 - 2));
+      OUT_BATCH(0);
+      OUT_BATCH(((mt->level[level].width - 1) & 0xffff) |
+                ((mt->level[level].height - 1) << 16));
+      OUT_BATCH(0);
+      ADVANCE_BATCH();
+   }
+
+   /* 3DPRIMITIVE */
+   {
+     BEGIN_BATCH(7);
+     OUT_BATCH(CMD_3D_PRIM << 16 | (7 - 2));
+     OUT_BATCH(GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL |
+               _3DPRIM_RECTLIST);
+     OUT_BATCH(3); /* vertex count per instance */
+     OUT_BATCH(0);
+     OUT_BATCH(1); /* instance count */
+     OUT_BATCH(0);
+     OUT_BATCH(0);
+     ADVANCE_BATCH();
+   }
+
+   /* See comments above at first invocation of intel_flush() in
+    * gen6_hiz_emit_batch_head().
+    */
+   intel_flush(ctx);
+
+   /* Be safe. */
+   brw->state.dirty.brw = ~0;
+   brw->state.dirty.cache = ~0;
+}
+
+/** \copydoc gen6_resolve_hiz_slice() */
+void
+gen7_resolve_hiz_slice(struct intel_context *intel,
+                       struct intel_mipmap_tree *mt,
+                       uint32_t level,
+                       uint32_t layer)
+{
+   gen7_hiz_exec(intel, mt, level, layer, GEN6_HIZ_OP_HIZ_RESOLVE);
+}
+
+/** \copydoc gen6_resolve_depth_slice() */
+void
+gen7_resolve_depth_slice(struct intel_context *intel,
+                         struct intel_mipmap_tree *mt,
+                         uint32_t level,
+                         uint32_t layer)
+{
+   gen7_hiz_exec(intel, mt, level, layer, GEN6_HIZ_OP_DEPTH_RESOLVE);
+}
diff --git a/src/mesa/drivers/dri/i965/gen7_hiz.h b/src/mesa/drivers/dri/i965/gen7_hiz.h
new file mode 100644
index 0000000..b89ffb0
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/gen7_hiz.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+struct intel_context;
+struct intel_mipmap_tree;
+
+/** \copydoc gen6_resolve_hiz_slice() */
+void
+gen7_resolve_hiz_slice(struct intel_context *intel,
+                       struct intel_mipmap_tree *mt,
+                       uint32_t level,
+                       uint32_t layer);
+
+/** \copydoc gen6_resolve_depth_slice() */
+void
+gen7_resolve_depth_slice(struct intel_context *intel,
+                         struct intel_mipmap_tree *mt,
+                         uint32_t level,
+                         uint32_t layer);
diff --git a/src/mesa/drivers/dri/i965/gen7_sf_state.c b/src/mesa/drivers/dri/i965/gen7_sf_state.c
index da7ef81..b215af2 100644
--- a/src/mesa/drivers/dri/i965/gen7_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_sf_state.c
@@ -149,8 +149,7 @@ const struct brw_tracked_state gen7_sbe_state = {
 		_NEW_PROGRAM |
 		_NEW_TRANSFORM),
       .brw   = (BRW_NEW_CONTEXT |
-		BRW_NEW_FRAGMENT_PROGRAM |
-		BRW_NEW_HIZ),
+		BRW_NEW_FRAGMENT_PROGRAM),
       .cache = CACHE_NEW_VS_PROG
    },
    .emit = upload_sbe_state,
@@ -166,17 +165,8 @@ upload_sf_state(struct brw_context *brw)
    /* _NEW_BUFFERS */
    bool render_to_fbo = brw->intel.ctx.DrawBuffer->Name != 0;
 
-   dw1 = GEN6_SF_STATISTICS_ENABLE;
-
-   /* Enable viewport transform only if no HiZ operation is progress
-    *
-    * From page 11 of the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
-    * Primitives Overview":
-    *     RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
-    *     use of screen- space coordinates).
-    */
-   if (!brw->hiz.op)
-      dw1 |= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE;
+   dw1 = GEN6_SF_STATISTICS_ENABLE |
+         GEN6_SF_VIEWPORT_TRANSFORM_ENABLE;
 
    /* _NEW_BUFFERS */
    dw1 |= (brw_depthbuffer_format(brw) << GEN7_SF_DEPTH_BUFFER_SURFACE_FORMAT_SHIFT);
@@ -310,8 +300,7 @@ const struct brw_tracked_state gen7_sf_state = {
 		_NEW_SCISSOR |
 		_NEW_BUFFERS |
 		_NEW_POINT),
-      .brw   = (BRW_NEW_CONTEXT |
-		BRW_NEW_HIZ),
+      .brw   = BRW_NEW_CONTEXT,
       .cache = CACHE_NEW_VS_PROG
    },
    .emit = upload_sf_state,
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_state.c b/src/mesa/drivers/dri/i965/gen7_wm_state.c
index 32222f9..870590f 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_state.c
@@ -49,23 +49,6 @@ upload_wm_state(struct brw_context *brw)
    dw1 |= GEN7_WM_LINE_AA_WIDTH_1_0;
    dw1 |= GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5;
 
-   switch (brw->hiz.op) {
-   case BRW_HIZ_OP_NONE:
-      break;
-   case BRW_HIZ_OP_DEPTH_CLEAR:
-      dw1 |= GEN7_WM_DEPTH_CLEAR;
-      break;
-   case BRW_HIZ_OP_DEPTH_RESOLVE:
-      dw1 |= GEN7_WM_DEPTH_RESOLVE;
-      break;
-   case BRW_HIZ_OP_HIZ_RESOLVE:
-      dw1 |= GEN7_WM_HIERARCHICAL_DEPTH_RESOLVE;
-      break;
-   default:
-      assert(0);
-      break;
-   }
-
    /* _NEW_LINE */
    if (ctx->Line.StippleFlag)
       dw1 |= GEN7_WM_LINE_STIPPLE_ENABLE;
@@ -106,7 +89,6 @@ const struct brw_tracked_state gen7_wm_state = {
       .mesa  = (_NEW_LINE | _NEW_LIGHT | _NEW_POLYGON |
 	        _NEW_COLOR | _NEW_BUFFERS),
       .brw   = (BRW_NEW_FRAGMENT_PROGRAM |
-                BRW_NEW_HIZ |
 		BRW_NEW_BATCH),
       .cache = 0,
    },
diff --git a/src/mesa/drivers/dri/i965/junk b/src/mesa/drivers/dri/i965/junk
new file mode 100644
index 0000000..e69de29
commit 65526d54aa2599b069bd443d3e6e9762e613042d
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 9 18:06:47 2012 -0700

    docs: remove link to the GLSL compiler page
    
    The page is terribly out of date.

diff --git a/docs/contents.html b/docs/contents.html
index 33c2191..6f556ee 100644
--- a/docs/contents.html
+++ b/docs/contents.html
@@ -52,7 +52,6 @@ a:visited {
 
 <b>User Topics</b>
 <ul>
-<li><a href="shading.html" target="MainFrame">Shading Language</a>
 <li><a href="egl.html" target="MainFrame">EGL</a>
 <li><a href="opengles.html" target="MainFrame">OpenGL ES</a>
 <li><a href="openvg.html" target="MainFrame">OpenVG / Vega</a>
commit 6aa9ce2687637ee678fa4258eb9efa695fca8690
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 9 18:06:06 2012 -0700

    docs: add VMware link

diff --git a/docs/vmware-guest.html b/docs/vmware-guest.html
index 727f99b..2a8bd6c 100644
--- a/docs/vmware-guest.html
+++ b/docs/vmware-guest.html
@@ -10,7 +10,8 @@
 <h1>VMware guest GL driver</h1>
 
 <p>
-This page describes how to build, install and use the VMware guest GL driver
+This page describes how to build, install and use the
+<a href="http://www.vmware.com/" target="_parent">VMware</a> guest GL driver
 (aka the SVGA or SVGA3D driver) for Linux using the latest source code.
 This driver gives a Linux virtual machine access to the host's GPU for
 hardware-accelerated 3D.
commit 14cf3dd826938f0a8a6f32a81c634ecc835f7319
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 9 18:05:52 2012 -0700

    docs: update info about supported systems, GPUs, APIs
    
    Add link to Intel's Linux graphics page, etc.

diff --git a/docs/systems.html b/docs/systems.html
index 035a489..62a6e0b 100644
--- a/docs/systems.html
+++ b/docs/systems.html
@@ -9,34 +9,78 @@
 <H1>Supported Systems and Drivers</H1>
 
 <p>
-Mesa was originally designed for Unix/X11 systems and is still best
-supported on those systems. All you need is an ANSI C compiler and the
-X development environment to use Mesa.
+Mesa is primarily developed and used on Linux systems.
+But there's also support for Windows, other flavors of Unix and other
+systems such as Haiku.
+We're actively developing and maintaining several hardware and
+software drivers.
 </p>
 
 <p>
-The DRI hardware drivers for the X.org server and XFree86 provide
-hardware accelerated rendering for chips from ATI, Intel, and NVIDIA
-on Linux and FreeBSD.
+The primary API is OpenGL but there's also support for OpenGL ES 1
+and ES 2, OpenVG and the EGL interface.
 </p>
 
 <p>
-Drivers for other assorted platforms include:
-the Apple Macintosh and Windows.
+Hardware drivers include:
 </p>
+<ul>
+<li>Intel i965, i945, i915.
+    See <a href="http://intellinuxgraphics.org/index.html" target="_parent">
+    Intel's website</a>
+<li>AMD Radeon series
+<li>Some NVIDIA GPus.
+<li>VMware virtual GPU
+</ul>
 
 <p>
-Details about particular drivers follows:
+Software drivers include:
+</p>
+<ul>
+<li><a href="llvmpipe.html">llvmpipe</a> - uses LLVM for x86 JIT code
+    generation and is multi-threaded
+<li>softpipe - a reference Gallium driver
+<li>swrast - the legacy/original Mesa software rasterizer
+</ul>
+
+<p>
+Additional driver information:
 </p>
 
 <UL>
 <li><a href="http://dri.freedesktop.org/" target="_parent"> DRI hardware
 drivers</a> for the X Window System
-<LI><a href="xlibdriver.html">Xlib software driver</a> for the X Window System
+<li><a href="xlibdriver.html">Xlib / swrast driver</a> for the X Window System
 and Unix-like operating systems
-<LI>Microsoft Windows <A HREF="README.WIN32">(README.WIN32)</A>
-<LI>DEC VMS <A HREF="README.VMS">(README.VMS)</A>
+<li><a href="README.WIN32">Microsoft Windows</a>
+<li><a href="vmware-guest.html">VMware</a> guest OS driver
 </UL>
 
+
+<h1>
+Deprecated Systems and Drivers
+</h1>
+
+<p>
+In the past there were other drivers for older GPUs and operating
+systems.
+These have been removed from the Mesa source tree and distribution.
+If anyone's interested though, the code can be found in the git repo.
+The list includes:
+</p>
+
+<ul>
+<li>3dfx/glide
+<li>Matrox
+<li>ATI R128
+<li>Savage
+<li>VIA Unichrome
+<li>SIS
+<li>3Dlabs gamma
+<li>DOS
+<li>fbdev
+<li>DEC/VMS
+<ul>
+
 </body>
 </html>
commit 7aef839760d5216ec2a413092cae35fd223678a4
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 9 15:52:13 2012 -0700

    docs: add news item for 8.0 release

diff --git a/docs/news.html b/docs/news.html
index d6a2aa8..472f98b 100644
--- a/docs/news.html
+++ b/docs/news.html
@@ -11,6 +11,16 @@
 <H1>News</H1>
 
 
+<h2>February 9, 2012</h2>
+
+<p>
+<a href="relnotes-8.0.html">Mesa 8.0</a> is released.
+This is the first version of Mesa to support OpenGL 3.0 and GLSL 1.30
+(with the i965 driver).
+See the release notes for more information about the release.
+</p>
+
+
 <h2>November 27, 2011</h2>
 
 <p>
commit fb56b0972dad8921bc43e1eeb4eebf5e3550e213
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Feb 9 14:28:58 2012 -0800

    docs: Add 8.0 MD5 checksums
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/docs/relnotes-8.0.html b/docs/relnotes-8.0.html
index 6df8fc8..afec121 100644
--- a/docs/relnotes-8.0.html
+++ b/docs/relnotes-8.0.html
@@ -30,7 +30,9 @@ for DRI hardware acceleration.
 
 <h2>MD5 checksums</h2>
 <pre>
-tbd
+3516fea6c28ce4a0fa9759e4894729a1  MesaLib-8.0.tar.gz
+1a5668fe72651a670611164cefc703b2  MesaLib-8.0.tar.bz2
+66f5a01a85530a91472a3acceb556db8  MesaLib-8.0.zip
 </pre>
 
 
commit f9c9933f9c7f72f12be27ccda98c965c75f08a12
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Feb 9 14:26:15 2012 -0800

    mesa: Bump version number to 8.0 (final)
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/Makefile b/Makefile
index c1f7158..e0dd6ef 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ ultrix-gcc:
 
 # Rules for making release tarballs
 
-PACKAGE_VERSION=8.0-rc2
+PACKAGE_VERSION=8.0
 PACKAGE_DIR = Mesa-$(PACKAGE_VERSION)
 PACKAGE_NAME = MesaLib-$(PACKAGE_VERSION)
 
diff --git a/docs/relnotes-8.0.html b/docs/relnotes-8.0.html
index 4aa1753..6df8fc8 100644
--- a/docs/relnotes-8.0.html
+++ b/docs/relnotes-8.0.html
@@ -10,7 +10,7 @@
 
 <body bgcolor="#eeeeee">
 
-<H1>Mesa 8.0 Release Notes / (release date TBD)</H1>
+<H1>Mesa 8.0 Release Notes / February 9, 2012</H1>
 
 <p>
 Mesa 8.0 is a new development release.
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 12844b1..11fe922 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -35,7 +35,7 @@ struct gl_context;
 #define MESA_MAJOR 8
 #define MESA_MINOR 0
 #define MESA_PATCH 0
-#define MESA_VERSION_STRING "8.0-rc2"
+#define MESA_VERSION_STRING "8.0"
 
 /* To make version comparison easy */
 #define MESA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
commit b2b5d6b8fb839cb93173f2d59475ff1d4ba60494
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Wed Jan 25 19:05:45 2012 -0800

    mesa: fix maximum allowed proxy texture size condition
    
    width, height parameter in glTexImage2D() includes: texture image
    width + 2 * border (if any). So when doing the texture size check
    in _mesa_test_proxy_teximage() width and height should not exceed
    maximum supported size for target texture type + 2 * border.
    i.e. 1 << (ctx->Const.MaxTextureLevels - 1) + 2 * border
    
    Texture border is anyway stripped out before it is given to intel
    or gallium drivers.
    
    This patch fixes Intel oglconform test case:
    max_values negative.textureSize.textureCube
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44970
    
    Note: This is a candidate for mesa 8.0 branch.
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Ian Romanick <idr at freedesktop.org>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit ea228d97f811092b9ffcb90565184a7a8f089477)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 111e4bf..e4f678d 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1173,7 +1173,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
    switch (target) {
    case GL_PROXY_TEXTURE_1D:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > maxSize)
+      if (width < 2 * border || width > 2 * border + maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.MaxTextureLevels)
          return GL_FALSE;
@@ -1185,9 +1185,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_2D:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > maxSize)
+      if (width < 2 * border || width > 2 * border + maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > maxSize)
+      if (height < 2 * border || height > 2 * border + maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.MaxTextureLevels)
          return GL_FALSE;
@@ -1201,11 +1201,11 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_3D:
       maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
-      if (width < 2 * border || width > maxSize)
+      if (width < 2 * border || width > 2 * border + maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > maxSize)
+      if (height < 2 * border || height > 2 * border + maxSize)
          return GL_FALSE;
-      if (depth < 2 * border || depth > maxSize)
+      if (depth < 2 * border || depth > 2 * border + maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.Max3DTextureLevels)
          return GL_FALSE;
@@ -1231,9 +1231,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
       maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
-      if (width < 2 * border || width > maxSize)
+      if (width < 2 * border || width > 2 * border + maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > maxSize)
+      if (height < 2 * border || height > 2 * border + maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.MaxCubeTextureLevels)
          return GL_FALSE;
@@ -1247,7 +1247,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > maxSize)
+      if (width < 2 * border || width > 2 * border + maxSize)
          return GL_FALSE;
       if (height < 1 || height > ctx->Const.MaxArrayTextureLayers)
          return GL_FALSE;
@@ -1261,9 +1261,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > maxSize)
+      if (width < 2 * border || width > 2 * border + maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > maxSize)
+      if (height < 2 * border || height > 2 * border + maxSize)
          return GL_FALSE;
       if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers)
          return GL_FALSE;
commit e86d90eb208292916c8a04c5d75499492003dd16
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 13:30:53 2012 -0800

    dri: Add Unigine Tropics as an app that requires the GLSL warn workaround.
    
    I wasn't seeing it be needed because of the previous bug.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eugeni Dodonov <eugeni.dodonov at intel.com>
    (cherry picked from commit b8c9252570d126e06607cd28b14f0fe3a2ffe4cf)

diff --git a/src/mesa/drivers/dri/common/drirc b/src/mesa/drivers/dri/common/drirc
index ac83a2d..59c00d7 100644
--- a/src/mesa/drivers/dri/common/drirc
+++ b/src/mesa/drivers/dri/common/drirc
@@ -3,5 +3,8 @@
         <application executable="Sanctuary">
             <option name="force_glsl_extensions_warn" value="true" />
 	</application>
+        <application executable="Tropics">
+            <option name="force_glsl_extensions_warn" value="true" />
+	</application>
     </device>
 </driconf>
commit 1531b94471fa283690fabb19e9a157247ba5fb8b
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 13:29:07 2012 -0800

    dri: Fix typo in xml file that made all applications use the workaround.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eugeni Dodonov <eugeni.dodonov at intel.com>
    (cherry picked from commit 4dd2743d4542bedd935134d351e528ad574f7ee5)

diff --git a/src/mesa/drivers/dri/common/drirc b/src/mesa/drivers/dri/common/drirc
index 7abc646..ac83a2d 100644
--- a/src/mesa/drivers/dri/common/drirc
+++ b/src/mesa/drivers/dri/common/drirc
@@ -1,6 +1,6 @@
 <driconf>
     <device screen="0" driver="i965">
-        <application name="Sanctuary">
+        <application executable="Sanctuary">
             <option name="force_glsl_extensions_warn" value="true" />
 	</application>
     </device>
commit b5efe0881ed385de36fa2f4889e1dd962990420a
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 25 14:22:03 2012 -0800

    dri: Add a default drirc to be installed to provide application workarounds.
    
    Specifially, this being present works around a bug in Unigine
    Sanctuary on i965 which previously resulted in bad rendering.
    
    NOTE: This is a candidate for the 8.0 branch.
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit ff2497dca39d688bbceba9f524a61e99d93a9607)
    
    NOTE: Compared to ff2497d this does not install the default drirc.
    The pre-automake build system is sufficiently braindamaged to make
    this exceptionally difficult.

diff --git a/src/mesa/drivers/dri/common/drirc b/src/mesa/drivers/dri/common/drirc
new file mode 100644
index 0000000..7abc646
--- /dev/null
+++ b/src/mesa/drivers/dri/common/drirc
@@ -0,0 +1,7 @@
+<driconf>
+    <device screen="0" driver="i965">
+        <application name="Sanctuary">
+            <option name="force_glsl_extensions_warn" value="true" />
+	</application>
+    </device>
+</driconf>
commit 73e15679cede19a780481bb60fa2ca582c6abf0e
Author: Chih-Wei Huang <cwhuang at linux.org.tw>
Date:   Thu Feb 2 20:23:57 2012 +0800

    vbo: fix a building error
    
    Signed-off-by: Marek Olšák <maraeo at gmail.com>
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit f8be4f33d31d004bfcf090fa7d4aa37b750e43af)

diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index fec49d3..e31e93f 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -1302,7 +1302,9 @@ vbo_exec_array_init( struct vbo_exec_context *exec )
    exec->vtxfmt.DrawArraysInstanced = vbo_exec_DrawArraysInstanced;
    exec->vtxfmt.DrawElementsInstanced = vbo_exec_DrawElementsInstanced;
    exec->vtxfmt.DrawElementsInstancedBaseVertex = vbo_exec_DrawElementsInstancedBaseVertex;
+#if FEATURE_EXT_transform_feedback
    exec->vtxfmt.DrawTransformFeedback = vbo_exec_DrawTransformFeedback;
+#endif
 }
 
 
commit 974a67b41e879b91765e3ef647ae22fe99a47079
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 09:50:35 2012 -0800

    glsl: Add error case for switch() with two default cases.
    
    Fixes piglit switch-case-duplicated.vert.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 57e44371a5b6aa8122b6a482ed6bd33e797ea1d2)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 4f328ad..c580359 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3537,6 +3537,7 @@ ast_switch_statement::hir(exec_list *instructions,
    state->switch_state.switch_nesting_ast = this;
    state->switch_state.labels_ht = hash_table_ctor(0, hash_table_pointer_hash,
 						   hash_table_pointer_compare);
+   state->switch_state.previous_default = NULL;
 
    /* Initalize is_fallthru state to false.
     */
@@ -3749,6 +3750,20 @@ ast_switch_statement::hir(exec_list *instructions,
 
 	instructions->push_tail(set_fallthru_on_test);
      } else { /* default case */
+	if (state->switch_state.previous_default) {
+	   printf("a\n");
+	   YYLTYPE loc = this->get_location();
+	   _mesa_glsl_error(& loc, state,
+			       "multiple default labels in one switch");
+
+	   printf("b\n");
+
+	   loc = state->switch_state.previous_default->get_location();
+	   _mesa_glsl_error(& loc, state,
+			    "this is the first default label");
+	}
+	state->switch_state.previous_default = this;
+
 	/* Set falltrhu state.
 	 */
 	ir_assignment *set_fallthru =
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index d5d5101..ee8f71b 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -51,6 +51,7 @@ struct glsl_switch_state {
 
    /** Table of constant values already used in case labels */
    struct hash_table *labels_ht;
+   class ast_case_label *previous_default;
 
    bool is_switch_innermost; // if switch stmt is closest to break, ...
 };
commit 83075bd0fe1fa4519f40edde1f9bc70967ee03a9
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 08:50:14 2012 -0800

    glsl: Throw an error when faced with a duplicated switch() case label.
    
    The error message I chose matches gcc's error.  Fixes piglit
    switch-case-duplicated.vert.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 140632190cf41e6a035ca199b181091d4ed46986)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 28aff39..4f328ad 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -54,6 +54,7 @@
 #include "glsl_parser_extras.h"
 #include "ast.h"
 #include "glsl_types.h"
+#include "program/hash_table.h"
 #include "ir.h"
 
 void
@@ -3534,6 +3535,8 @@ ast_switch_statement::hir(exec_list *instructions,
 
    state->switch_state.is_switch_innermost = true;
    state->switch_state.switch_nesting_ast = this;
+   state->switch_state.labels_ht = hash_table_ctor(0, hash_table_pointer_hash,
+						   hash_table_pointer_compare);
 
    /* Initalize is_fallthru state to false.
     */
@@ -3572,6 +3575,8 @@ ast_switch_statement::hir(exec_list *instructions,
     */
    body->hir(instructions, state);
 
+   hash_table_dtor(state->switch_state.labels_ht);
+
    state->switch_state = saved;
 
      /* Switch statements do not have r-values.
@@ -3709,6 +3714,24 @@ ast_switch_statement::hir(exec_list *instructions,
 
 	   /* Stuff a dummy value in to allow processing to continue. */
 	   label_const = new(ctx) ir_constant(0);
+	} else {
+	   ast_expression *previous_label = (ast_expression *)
+	      hash_table_find(state->switch_state.labels_ht,
+			      (void *)(uintptr_t)label_const->value.u[0]);
+
+	   if (previous_label) {
+	      YYLTYPE loc = this->test_value->get_location();
+	      _mesa_glsl_error(& loc, state,
+			       "duplicate case value");
+
+	      loc = previous_label->get_location();
+	      _mesa_glsl_error(& loc, state,
+			       "this is the previous case label");
+	   } else {
+	      hash_table_insert(state->switch_state.labels_ht,
+				this->test_value,
+				(void *)(uintptr_t)label_const->value.u[0]);
+	   }
 	}
 
 	ir_dereference_variable *deref_test_var =
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 35d1e3a..d5d5101 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -48,6 +48,10 @@ struct glsl_switch_state {
    ir_variable *is_fallthru_var;
    ir_variable *is_break_var;
    class ast_switch_statement *switch_nesting_ast;
+
+   /** Table of constant values already used in case labels */
+   struct hash_table *labels_ht;
+
    bool is_switch_innermost; // if switch stmt is closest to break, ...
 };
 
commit d799a7b585225441b5a424fbd3de8b719d0ada6e
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 09:46:09 2012 -0800

    glsl: Add other missing error location information for switch statements.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 01a5a2c9d761d4c9d72c236084efee700dcb28b8)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 8368d06..d5e85ab 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -1671,6 +1671,7 @@ switch_statement:
 	SWITCH '(' expression ')' switch_body
 	{
 	   $$ = new(state) ast_switch_statement($3, $5);
+	   $$->set_location(yylloc);
 	}
 	;
 
@@ -1707,6 +1708,7 @@ case_label_list:
 
 	   labels->labels.push_tail(& $1->link);
 	   $$ = labels;
+	   $$->set_location(yylloc);
 	}
 	| case_label_list case_label
 	{
@@ -1719,6 +1721,7 @@ case_statement:
 	case_label_list statement
 	{
 	   ast_case_statement *stmts = new(state) ast_case_statement($1);
+	   stmts->set_location(yylloc);
 
 	   stmts->stmts.push_tail(& $2->link);
 	   $$ = stmts;
@@ -1734,6 +1737,7 @@ case_statement_list:
 	case_statement
 	{
 	   ast_case_statement_list *cases= new(state) ast_case_statement_list();
+	   cases->set_location(yylloc);
 
 	   cases->cases.push_tail(& $1->link);
 	   $$ = cases;
commit 2b4df494b1f5f020444b14fcaeea6e02adb7d7ac
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 09:41:55 2012 -0800

    glsl: Add missing location info to case labels.
    
    Otherwise, the upcoming error messages said the location was 0:0(0).
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 663dcbbffeaedf0643e7e9d930ccfbcd698d1d9c)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index e774b46..8368d06 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -1691,10 +1691,12 @@ case_label:
 	CASE expression ':'
 	{
 	   $$ = new(state) ast_case_label($2);
+	   $$->set_location(yylloc);
 	}
 	| DEFAULT ':'
 	{
 	   $$ = new(state) ast_case_label(NULL);
+	   $$->set_location(yylloc);
 	}
 	;
 
commit 728bda08d85813eeda12ae52e0893a37533ba02c
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Jan 28 11:43:22 2012 -0800

    glsl: Throw the required error when a case label is a non-constant.
    
    It's not quite spelled out in the spec text, but the grammar indicates
    that only constant values are allowed as switch() case labels (and
    only constant values make sense, anyway).
    
    Fixes piglit glsl-1.30/compiler/switch-statement/switch-case-uniform-int.vert.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 2c3e10e71935506798c413363df27afc4348fb53)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 25ccdab..28aff39 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3697,14 +3697,26 @@ ast_switch_statement::hir(exec_list *instructions,
 	/* Conditionally set fallthru state based on
 	 * comparison of cached test expression value to case label.
 	 */
-	ir_rvalue *const test_val = this->test_value->hir(instructions, state);
+	ir_rvalue *const label_rval = this->test_value->hir(instructions, state);
+	ir_constant *label_const = label_rval->constant_expression_value();
+
+	if (!label_const) {
+	   YYLTYPE loc = this->test_value->get_location();
+
+	   _mesa_glsl_error(& loc, state,
+			    "switch statement case label must be a "
+			    "constant expression");
+
+	   /* Stuff a dummy value in to allow processing to continue. */
+	   label_const = new(ctx) ir_constant(0);
+	}
 
 	ir_dereference_variable *deref_test_var =
 	   new(ctx) ir_dereference_variable(state->switch_state.test_var);
 
 	ir_rvalue *const test_cond = new(ctx) ir_expression(ir_binop_all_equal,
 							    glsl_type::bool_type,
-							    test_val,
+							    label_const,
 							    deref_test_var);
 
 	ir_assignment *set_fallthru_on_test =
commit f775d9aa848c61dcf7eb2ca6d599b40366034848
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Jan 28 11:26:02 2012 -0800

    glsl: Save and restore the whole switch state for nesting.
    
    This stuffs them all in a struct for sanity.  Fixes piglit
    glsl-1.30/execution/switch/fs-uniform-nested.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 22d81f154fed9e004cca91807808ae3b81b01ced)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index cde7052..25ccdab 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3405,7 +3405,7 @@ ast_jump_statement::hir(exec_list *instructions,
 			  "continue may only appear in a loop");
       } else if (mode == ast_break &&
 		 state->loop_nesting_ast == NULL &&
-		 state->switch_nesting_ast == NULL) {
+		 state->switch_state.switch_nesting_ast == NULL) {
 	 YYLTYPE loc = this->get_location();
 
 	 _mesa_glsl_error(& loc, state,
@@ -3423,11 +3423,11 @@ ast_jump_statement::hir(exec_list *instructions,
 							  state);
 	 }
 
-	 if (state->is_switch_innermost &&
+	 if (state->switch_state.is_switch_innermost &&
 	     mode == ast_break) {
 	    /* Force break out of switch by setting is_break switch state.
 	     */
-	    ir_variable *const is_break_var = state->is_break_var;
+	    ir_variable *const is_break_var = state->switch_state.is_break_var;
 	    ir_dereference_variable *const deref_is_break_var =
 	       new(ctx) ir_dereference_variable(is_break_var);
 	    ir_constant *const true_val = new(ctx) ir_constant(true);
@@ -3530,25 +3530,22 @@ ast_switch_statement::hir(exec_list *instructions,
 
    /* Track the switch-statement nesting in a stack-like manner.
     */
-   ir_variable *saved_test_var = state->test_var;
-   ir_variable *saved_is_fallthru_var = state->is_fallthru_var;
-   
-   bool save_is_switch_innermost = state->is_switch_innermost;
-   ast_switch_statement *saved_nesting_ast = state->switch_nesting_ast;
+   struct glsl_switch_state saved = state->switch_state;
 
-   state->is_switch_innermost = true;
-   state->switch_nesting_ast = this;
+   state->switch_state.is_switch_innermost = true;
+   state->switch_state.switch_nesting_ast = this;
 
    /* Initalize is_fallthru state to false.
     */
    ir_rvalue *const is_fallthru_val = new (ctx) ir_constant(false);
-   state->is_fallthru_var = new(ctx) ir_variable(glsl_type::bool_type,
-					        "switch_is_fallthru_tmp",
-					        ir_var_temporary);
-   instructions->push_tail(state->is_fallthru_var);
+   state->switch_state.is_fallthru_var =
+      new(ctx) ir_variable(glsl_type::bool_type,
+			   "switch_is_fallthru_tmp",
+			   ir_var_temporary);
+   instructions->push_tail(state->switch_state.is_fallthru_var);
 
    ir_dereference_variable *deref_is_fallthru_var =
-      new(ctx) ir_dereference_variable(state->is_fallthru_var);
+      new(ctx) ir_dereference_variable(state->switch_state.is_fallthru_var);
    instructions->push_tail(new(ctx) ir_assignment(deref_is_fallthru_var,
 						  is_fallthru_val,
 						  NULL));
@@ -3556,13 +3553,13 @@ ast_switch_statement::hir(exec_list *instructions,
    /* Initalize is_break state to false.
     */
    ir_rvalue *const is_break_val = new (ctx) ir_constant(false);
-   state->is_break_var = new(ctx) ir_variable(glsl_type::bool_type,
-					      "switch_is_break_tmp",
-					      ir_var_temporary);
-   instructions->push_tail(state->is_break_var);
+   state->switch_state.is_break_var = new(ctx) ir_variable(glsl_type::bool_type,
+							   "switch_is_break_tmp",
+							   ir_var_temporary);
+   instructions->push_tail(state->switch_state.is_break_var);
 
    ir_dereference_variable *deref_is_break_var =
-      new(ctx) ir_dereference_variable(state->is_break_var);
+      new(ctx) ir_dereference_variable(state->switch_state.is_break_var);
    instructions->push_tail(new(ctx) ir_assignment(deref_is_break_var,
 						  is_break_val,
 						  NULL));
@@ -3575,254 +3572,248 @@ ast_switch_statement::hir(exec_list *instructions,
     */
    body->hir(instructions, state);
 
-   /* Restore previous nesting before returning.
-    */
-   state->switch_nesting_ast = saved_nesting_ast;
-   state->is_switch_innermost = save_is_switch_innermost;
-
-   state->test_var = saved_test_var;
-   state->is_fallthru_var = saved_is_fallthru_var;
-
-   /* Switch statements do not have r-values.
-    */
-   return NULL;
-}
-
-
-void
-ast_switch_statement::test_to_hir(exec_list *instructions,
-				  struct _mesa_glsl_parse_state *state)
-{
-   void *ctx = state;
-
-   /* Cache value of test expression.
-    */
-   ir_rvalue *const test_val =
-      test_expression->hir(instructions,
-			   state);
-
-   state->test_var = new(ctx) ir_variable(glsl_type::int_type,
-					  "switch_test_tmp",
-					  ir_var_temporary);
-   ir_dereference_variable *deref_test_var =
-      new(ctx) ir_dereference_variable(state->test_var);
-
-   instructions->push_tail(state->test_var);
-   instructions->push_tail(new(ctx) ir_assignment(deref_test_var,
-						  test_val,
-						  NULL));
-}
-
-
-ir_rvalue *
-ast_switch_body::hir(exec_list *instructions,
-		     struct _mesa_glsl_parse_state *state)
-{
-   if (stmts != NULL)
-      stmts->hir(instructions, state);
-      
-   /* Switch bodies do not have r-values.
-    */
-   return NULL;
-}
-
-
-ir_rvalue *
-ast_case_statement_list::hir(exec_list *instructions,
-			     struct _mesa_glsl_parse_state *state)
-{
-   foreach_list_typed (ast_case_statement, case_stmt, link, & this->cases)
-      case_stmt->hir(instructions, state);
-         
-   /* Case statements do not have r-values.
-    */
-   return NULL;
-}
-
-
-ir_rvalue *
-ast_case_statement::hir(exec_list *instructions,
-			struct _mesa_glsl_parse_state *state)
-{
-   labels->hir(instructions, state);
-   
-   /* Conditionally set fallthru state based on break state.
-    */
-   ir_constant *const false_val = new(state) ir_constant(false);
-   ir_dereference_variable *const deref_is_fallthru_var =
-      new(state) ir_dereference_variable(state->is_fallthru_var);
-   ir_dereference_variable *const deref_is_break_var =
-      new(state) ir_dereference_variable(state->is_break_var);
-   ir_assignment *const reset_fallthru_on_break =
-      new(state) ir_assignment(deref_is_fallthru_var,
-			       false_val,
-			       deref_is_break_var);
-   instructions->push_tail(reset_fallthru_on_break);
-
-   /* Guard case statements depending on fallthru state.
-    */
-   ir_dereference_variable *const deref_fallthru_guard =
-      new(state) ir_dereference_variable(state->is_fallthru_var);
-   ir_if *const test_fallthru = new(state) ir_if(deref_fallthru_guard);
-   
-   foreach_list_typed (ast_node, stmt, link, & this->stmts)
-      stmt->hir(& test_fallthru->then_instructions, state);
-
-   instructions->push_tail(test_fallthru);
-         
-   /* Case statements do not have r-values.
-    */
-   return NULL;
-}
-
-
-ir_rvalue *
-ast_case_label_list::hir(exec_list *instructions,
-			 struct _mesa_glsl_parse_state *state)
-{
-   foreach_list_typed (ast_case_label, label, link, & this->labels)
-      label->hir(instructions, state);
-         
-   /* Case labels do not have r-values.
-    */
-   return NULL;
-}
-
+   state->switch_state = saved;
 
-ir_rvalue *
-ast_case_label::hir(exec_list *instructions,
-		    struct _mesa_glsl_parse_state *state)
-{
-   void *ctx = state;
+     /* Switch statements do not have r-values.
+      */
+     return NULL;
+  }
 
-   ir_dereference_variable *deref_fallthru_var =
-      new(ctx) ir_dereference_variable(state->is_fallthru_var);
-   
-   ir_rvalue *const true_val = new(ctx) ir_constant(true);
 
-   /* If not default case, ...
-    */
-   if (this->test_value != NULL) {
-      /* Conditionally set fallthru state based on
-       * comparison of cached test expression value to case label.
-       */
-      ir_rvalue *const test_val = this->test_value->hir(instructions, state);
+  void
+  ast_switch_statement::test_to_hir(exec_list *instructions,
+				    struct _mesa_glsl_parse_state *state)
+  {
+     void *ctx = state;
 
-      ir_dereference_variable *deref_test_var =
-	 new(ctx) ir_dereference_variable(state->test_var);
+     /* Cache value of test expression.
+      */
+     ir_rvalue *const test_val =
+	test_expression->hir(instructions,
+			     state);
 
-      ir_rvalue *const test_cond = new(ctx) ir_expression(ir_binop_all_equal,
-							  glsl_type::bool_type,
-							  test_val,
-							  deref_test_var);
+     state->switch_state.test_var = new(ctx) ir_variable(glsl_type::int_type,
+							 "switch_test_tmp",
+							 ir_var_temporary);
+     ir_dereference_variable *deref_test_var =
+	new(ctx) ir_dereference_variable(state->switch_state.test_var);
 
-      ir_assignment *set_fallthru_on_test =
-	 new(ctx) ir_assignment(deref_fallthru_var,
-				true_val,
-				test_cond);
-   
-      instructions->push_tail(set_fallthru_on_test);
-   } else { /* default case */
-      /* Set falltrhu state.
-       */
-      ir_assignment *set_fallthru =
-	 new(ctx) ir_assignment(deref_fallthru_var,
-				true_val,
-				NULL);
-   
-      instructions->push_tail(set_fallthru);
-   }
-   
-   /* Case statements do not have r-values.
-    */
-   return NULL;
-}
+     instructions->push_tail(state->switch_state.test_var);
+     instructions->push_tail(new(ctx) ir_assignment(deref_test_var,
+						    test_val,
+						    NULL));
+  }
 
 
-void
-ast_iteration_statement::condition_to_hir(ir_loop *stmt,
-					  struct _mesa_glsl_parse_state *state)
-{
-   void *ctx = state;
+  ir_rvalue *
+  ast_switch_body::hir(exec_list *instructions,
+		       struct _mesa_glsl_parse_state *state)
+  {
+     if (stmts != NULL)
+	stmts->hir(instructions, state);
 
-   if (condition != NULL) {
-      ir_rvalue *const cond =
-	 condition->hir(& stmt->body_instructions, state);
+     /* Switch bodies do not have r-values.
+      */
+     return NULL;
+  }
 
-      if ((cond == NULL)
-	  || !cond->type->is_boolean() || !cond->type->is_scalar()) {
-	 YYLTYPE loc = condition->get_location();
 
-	 _mesa_glsl_error(& loc, state,
-			  "loop condition must be scalar boolean");
-      } else {
-	 /* As the first code in the loop body, generate a block that looks
-	  * like 'if (!condition) break;' as the loop termination condition.
-	  */
-	 ir_rvalue *const not_cond =
-	    new(ctx) ir_expression(ir_unop_logic_not, glsl_type::bool_type, cond,
-				   NULL);
+  ir_rvalue *
+  ast_case_statement_list::hir(exec_list *instructions,
+			       struct _mesa_glsl_parse_state *state)
+  {
+     foreach_list_typed (ast_case_statement, case_stmt, link, & this->cases)
+	case_stmt->hir(instructions, state);
 
-	 ir_if *const if_stmt = new(ctx) ir_if(not_cond);
+     /* Case statements do not have r-values.
+      */
+     return NULL;
+  }
 
-	 ir_jump *const break_stmt =
-	    new(ctx) ir_loop_jump(ir_loop_jump::jump_break);
 
-	 if_stmt->then_instructions.push_tail(break_stmt);
-	 stmt->body_instructions.push_tail(if_stmt);
-      }
-   }
-}
-
-
-ir_rvalue *
-ast_iteration_statement::hir(exec_list *instructions,
-			     struct _mesa_glsl_parse_state *state)
-{
-   void *ctx = state;
-
-   /* For-loops and while-loops start a new scope, but do-while loops do not.
-    */
-   if (mode != ast_do_while)
-      state->symbols->push_scope();
-
-   if (init_statement != NULL)
-      init_statement->hir(instructions, state);
-
-   ir_loop *const stmt = new(ctx) ir_loop();
-   instructions->push_tail(stmt);
-
-   /* Track the current loop nesting.
-    */
-   ast_iteration_statement *nesting_ast = state->loop_nesting_ast;
-
-   state->loop_nesting_ast = this;
-
-   /* Likewise, indicate that following code is closest to a loop,
-    * NOT closest to a switch.
-    */
-   bool saved_is_switch_innermost = state->is_switch_innermost;
-   state->is_switch_innermost = false;
-
-   if (mode != ast_do_while)
-      condition_to_hir(stmt, state);
-
-   if (body != NULL)
-      body->hir(& stmt->body_instructions, state);
-
-   if (rest_expression != NULL)
-      rest_expression->hir(& stmt->body_instructions, state);
-
-   if (mode == ast_do_while)
-      condition_to_hir(stmt, state);
-
-   if (mode != ast_do_while)
-      state->symbols->pop_scope();
+  ir_rvalue *
+  ast_case_statement::hir(exec_list *instructions,
+			  struct _mesa_glsl_parse_state *state)
+  {
+     labels->hir(instructions, state);
+
+     /* Conditionally set fallthru state based on break state.
+      */
+     ir_constant *const false_val = new(state) ir_constant(false);
+     ir_dereference_variable *const deref_is_fallthru_var =
+	new(state) ir_dereference_variable(state->switch_state.is_fallthru_var);
+     ir_dereference_variable *const deref_is_break_var =
+	new(state) ir_dereference_variable(state->switch_state.is_break_var);
+     ir_assignment *const reset_fallthru_on_break =
+	new(state) ir_assignment(deref_is_fallthru_var,
+				 false_val,
+				 deref_is_break_var);
+     instructions->push_tail(reset_fallthru_on_break);
+
+     /* Guard case statements depending on fallthru state.
+      */
+     ir_dereference_variable *const deref_fallthru_guard =
+	new(state) ir_dereference_variable(state->switch_state.is_fallthru_var);
+     ir_if *const test_fallthru = new(state) ir_if(deref_fallthru_guard);
+
+     foreach_list_typed (ast_node, stmt, link, & this->stmts)
+	stmt->hir(& test_fallthru->then_instructions, state);
+
+     instructions->push_tail(test_fallthru);
+
+     /* Case statements do not have r-values.
+      */
+     return NULL;
+  }
+
+
+  ir_rvalue *
+  ast_case_label_list::hir(exec_list *instructions,
+			   struct _mesa_glsl_parse_state *state)
+  {
+     foreach_list_typed (ast_case_label, label, link, & this->labels)
+	label->hir(instructions, state);
+
+     /* Case labels do not have r-values.
+      */
+     return NULL;
+  }
+
+
+  ir_rvalue *
+  ast_case_label::hir(exec_list *instructions,
+		      struct _mesa_glsl_parse_state *state)
+  {
+     void *ctx = state;
+
+     ir_dereference_variable *deref_fallthru_var =
+	new(ctx) ir_dereference_variable(state->switch_state.is_fallthru_var);
+
+     ir_rvalue *const true_val = new(ctx) ir_constant(true);
+
+     /* If not default case, ...
+      */
+     if (this->test_value != NULL) {
+	/* Conditionally set fallthru state based on
+	 * comparison of cached test expression value to case label.
+	 */
+	ir_rvalue *const test_val = this->test_value->hir(instructions, state);
+
+	ir_dereference_variable *deref_test_var =
+	   new(ctx) ir_dereference_variable(state->switch_state.test_var);
+
+	ir_rvalue *const test_cond = new(ctx) ir_expression(ir_binop_all_equal,
+							    glsl_type::bool_type,
+							    test_val,
+							    deref_test_var);
+
+	ir_assignment *set_fallthru_on_test =
+	   new(ctx) ir_assignment(deref_fallthru_var,
+				  true_val,
+				  test_cond);
+
+	instructions->push_tail(set_fallthru_on_test);
+     } else { /* default case */
+	/* Set falltrhu state.
+	 */
+	ir_assignment *set_fallthru =
+	   new(ctx) ir_assignment(deref_fallthru_var,
+				  true_val,
+				  NULL);
+
+	instructions->push_tail(set_fallthru);
+     }
+
+     /* Case statements do not have r-values.
+      */
+     return NULL;
+  }
+
+
+  void
+  ast_iteration_statement::condition_to_hir(ir_loop *stmt,
+					    struct _mesa_glsl_parse_state *state)
+  {
+     void *ctx = state;
+
+     if (condition != NULL) {
+	ir_rvalue *const cond =
+	   condition->hir(& stmt->body_instructions, state);
+
+	if ((cond == NULL)
+	    || !cond->type->is_boolean() || !cond->type->is_scalar()) {
+	   YYLTYPE loc = condition->get_location();
+
+	   _mesa_glsl_error(& loc, state,
+			    "loop condition must be scalar boolean");
+	} else {
+	   /* As the first code in the loop body, generate a block that looks
+	    * like 'if (!condition) break;' as the loop termination condition.
+	    */
+	   ir_rvalue *const not_cond =
+	      new(ctx) ir_expression(ir_unop_logic_not, glsl_type::bool_type, cond,
+				     NULL);
+
+	   ir_if *const if_stmt = new(ctx) ir_if(not_cond);
 
-   /* Restore previous nesting before returning.
-    */
-   state->loop_nesting_ast = nesting_ast;
-   state->is_switch_innermost = saved_is_switch_innermost;
+	   ir_jump *const break_stmt =
+	      new(ctx) ir_loop_jump(ir_loop_jump::jump_break);
+
+	   if_stmt->then_instructions.push_tail(break_stmt);
+	   stmt->body_instructions.push_tail(if_stmt);
+	}
+     }
+  }
+
+
+  ir_rvalue *
+  ast_iteration_statement::hir(exec_list *instructions,
+			       struct _mesa_glsl_parse_state *state)
+  {
+     void *ctx = state;
+
+     /* For-loops and while-loops start a new scope, but do-while loops do not.
+      */
+     if (mode != ast_do_while)
+	state->symbols->push_scope();
+
+     if (init_statement != NULL)
+	init_statement->hir(instructions, state);
+
+     ir_loop *const stmt = new(ctx) ir_loop();
+     instructions->push_tail(stmt);
+
+     /* Track the current loop nesting.
+      */
+     ast_iteration_statement *nesting_ast = state->loop_nesting_ast;
+
+     state->loop_nesting_ast = this;
+
+     /* Likewise, indicate that following code is closest to a loop,
+      * NOT closest to a switch.
+      */
+     bool saved_is_switch_innermost = state->switch_state.is_switch_innermost;
+     state->switch_state.is_switch_innermost = false;
+
+     if (mode != ast_do_while)
+	condition_to_hir(stmt, state);
+
+     if (body != NULL)
+	body->hir(& stmt->body_instructions, state);
+
+     if (rest_expression != NULL)
+	rest_expression->hir(& stmt->body_instructions, state);
+
+     if (mode == ast_do_while)
+	condition_to_hir(stmt, state);
+
+     if (mode != ast_do_while)
+	state->symbols->pop_scope();
+
+     /* Restore previous nesting before returning.
+      */
+     state->loop_nesting_ast = nesting_ast;
+     state->switch_state.is_switch_innermost = saved_is_switch_innermost;
 
    /* Loops do not have r-values.
     */
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 7f8d47c..2a72ba1 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -51,7 +51,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx,
    this->info_log = ralloc_strdup(mem_ctx, "");
    this->error = false;
    this->loop_nesting_ast = NULL;
-   this->switch_nesting_ast = NULL;
+   this->switch_state.switch_nesting_ast = NULL;
 
    this->num_builtins_to_link = 0;
 
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index dd93295..35d1e3a 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -42,6 +42,15 @@ enum _mesa_glsl_parser_targets {
 
 struct gl_context;
 
+struct glsl_switch_state {
+   /** Temporary variables needed for switch statement. */
+   ir_variable *test_var;
+   ir_variable *is_fallthru_var;
+   ir_variable *is_break_var;
+   class ast_switch_statement *switch_nesting_ast;
+   bool is_switch_innermost; // if switch stmt is closest to break, ...
+};
+
 struct _mesa_glsl_parse_state {
    _mesa_glsl_parse_state(struct gl_context *ctx, GLenum target,
 			  void *mem_ctx);
@@ -150,13 +159,8 @@ struct _mesa_glsl_parse_state {
 
    /** Loop or switch statement containing the current instructions. */
    class ast_iteration_statement *loop_nesting_ast;
-   class ast_switch_statement *switch_nesting_ast;
-   bool is_switch_innermost; // if switch stmt is closest to break, ...
 
-   /** Temporary variables needed for switch statement. */
-   ir_variable *test_var;
-   ir_variable *is_fallthru_var;
-   ir_variable *is_break_var;
+   struct glsl_switch_state switch_state;
 
    /** List of structures defined in user code. */
    const glsl_type **user_structures;
commit 6887ec766b33ed7a9d44376050d5876f2b6c88ec
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 30 13:20:27 2012 -0800

    mesa: Fix the error message function names for glFlushMappedBufferRange().
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 27af00eac8c574c2fc145e333d1c0ade1fd91cda)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index e355995..a2959a8 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1459,42 +1459,42 @@ _mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
 
    if (!ctx->Extensions.ARB_map_buffer_range) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glMapBufferRange(extension not supported)");
+                  "glFlushMappedBufferRange(extension not supported)");
       return;
    }
 
    if (offset < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glMapBufferRange(offset = %ld)", (long)offset);
+                  "glFlushMappedBufferRange(offset = %ld)", (long)offset);
       return;
    }
 
    if (length < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glMapBufferRange(length = %ld)", (long)length);
+                  "glFlushMappedBufferRange(length = %ld)", (long)length);
       return;
    }
 
-   bufObj = get_buffer(ctx, "glMapBufferRange", target);
+   bufObj = get_buffer(ctx, "glFlushMappedBufferRange", target);
    if (!bufObj)
       return;
 
    if (!_mesa_bufferobj_mapped(bufObj)) {
       /* buffer is not mapped */
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glMapBufferRange(buffer is not mapped)");
+                  "glFlushMappedBufferRange(buffer is not mapped)");
       return;
    }
 
    if ((bufObj->AccessFlags & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glMapBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
+                  "glFlushMappedBufferRange(GL_MAP_FLUSH_EXPLICIT_BIT not set)");
       return;
    }
 
    if (offset + length > bufObj->Length) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-		  "glMapBufferRange(offset %ld + length %ld > mapped length %ld)",
+		  "glFlushMappedBufferRange(offset %ld + length %ld > mapped length %ld)",
 		  (long)offset, (long)length, (long)bufObj->Length);
       return;
    }
commit 6d82dc18f11e21eb57e229ac9b95a2850f2e7971
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 25 16:30:26 2012 -0800

    mesa: Fix bad-enum/no-buffer error handling for buffer object functions.
    
    For all the extension entrypoints using the get_buffer() helper, they
    wanted the same error handling.  In some cases, the error was doing
    the same error return whether target was a bad enum, or a user buffer
    wasn't bound.
    
    (Actually, GL_ARB_map_buffer_range doesn't specify the error for a zero
    buffer being bound for MapBufferRange, though it does for
    FlushMappedBufferRange.  This appears to be an oversight).
    
    Fixes piglit GL_ARB_copy_buffer/negative-bound-zero.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit f20fb80a916d9f88dbc7efc43d4c31e038cb70c6)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 5b6db78..e355995 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -106,12 +106,21 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
  *           specified context or \c NULL if \c target is invalid.
  */
 static inline struct gl_buffer_object *
-get_buffer(struct gl_context *ctx, GLenum target)
+get_buffer(struct gl_context *ctx, const char *func, GLenum target)
 {
    struct gl_buffer_object **bufObj = get_buffer_target(ctx, target);
-   if (bufObj)
-      return *bufObj;
-   return NULL;
+
+   if (!bufObj) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
+      return NULL;
+   }
+
+   if (!_mesa_is_bufferobj(*bufObj)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(buffer 0)", func);
+      return NULL;
+   }
+
+   return *bufObj;
 }
 
 
@@ -190,15 +199,10 @@ buffer_object_subdata_range_good( struct gl_context * ctx, GLenum target,
       return NULL;
    }
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", caller);
-      return NULL;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
+   bufObj = get_buffer(ctx, caller, target);
+   if (!bufObj)
       return NULL;
-   }
+
    if (offset + size > bufObj->Size) {
       _mesa_error(ctx, GL_INVALID_VALUE,
 		  "%s(offset %lu + size %lu > buffer size %lu)", caller,
@@ -905,16 +909,10 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size,
       return;
    }
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBufferDataARB(target)" );
+   bufObj = get_buffer(ctx, "glBufferDataARB", target);
+   if (!bufObj)
       return;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glBufferDataARB(buffer 0)" );
-      return;
-   }
-   
+
    if (_mesa_bufferobj_mapped(bufObj)) {
       /* Unmap the existing buffer.  We'll replace it now.  Not an error. */
       ctx->Driver.UnmapBuffer(ctx, bufObj);
@@ -1012,15 +1010,10 @@ _mesa_MapBufferARB(GLenum target, GLenum access)
       return NULL;
    }
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glMapBufferARB(target)" );
-      return NULL;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(buffer 0)" );
+   bufObj = get_buffer(ctx, "glMapBufferARB", target);
+   if (!bufObj)
       return NULL;
-   }
+
    if (_mesa_bufferobj_mapped(bufObj)) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glMapBufferARB(already mapped)");
       return NULL;
@@ -1086,15 +1079,10 @@ _mesa_UnmapBufferARB(GLenum target)
    GLboolean status = GL_TRUE;
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glUnmapBufferARB(target)" );
-      return GL_FALSE;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB" );
+   bufObj = get_buffer(ctx, "glUnmapBufferARB", target);
+   if (!bufObj)
       return GL_FALSE;
-   }
+
    if (!_mesa_bufferobj_mapped(bufObj)) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glUnmapBufferARB");
       return GL_FALSE;
@@ -1153,15 +1141,9 @@ _mesa_GetBufferParameterivARB(GLenum target, GLenum pname, GLint *params)
    struct gl_buffer_object *bufObj;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameterivARB(target)" );
-      return;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferParameterivARB" );
+   bufObj = get_buffer(ctx, "glGetBufferParameterivARB", target);
+   if (!bufObj)
       return;
-   }
 
    switch (pname) {
    case GL_BUFFER_SIZE_ARB:
@@ -1213,15 +1195,9 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
    struct gl_buffer_object *bufObj;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferParameteri64v(target)" );
+   bufObj = get_buffer(ctx, "glGetBufferParameteri64v", target);
+   if (!bufObj)
       return;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferParameteri64v" );
-      return;
-   }
 
    switch (pname) {
    case GL_BUFFER_SIZE_ARB:
@@ -1273,15 +1249,9 @@ _mesa_GetBufferPointervARB(GLenum target, GLenum pname, GLvoid **params)
       return;
    }
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(target)" );
-      return;
-   }
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetBufferPointervARB" );
+   bufObj = get_buffer(ctx, "glGetBufferPointervARB", target);
+   if (!bufObj)
       return;
-   }
 
    *params = bufObj->Pointer;
 }
@@ -1296,19 +1266,13 @@ _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
    struct gl_buffer_object *src, *dst;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   src = get_buffer(ctx, readTarget);
-   if (!_mesa_is_bufferobj(src)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glCopyBuffserSubData(readTarget = 0x%x)", readTarget);
+   src = get_buffer(ctx, "glCopyBuffserSubData", readTarget);
+   if (!src)
       return;
-   }
 
-   dst = get_buffer(ctx, writeTarget);
-   if (!_mesa_is_bufferobj(dst)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glCopyBuffserSubData(writeTarget = 0x%x)", writeTarget);
+   dst = get_buffer(ctx, "glCopyBuffserSubData", writeTarget);
+   if (!dst)
       return;
-   }
 
    if (_mesa_bufferobj_mapped(src)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -1431,12 +1395,9 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
       return NULL;
    }
 
-   bufObj = get_buffer(ctx, target);
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glMapBufferRange(target = 0x%x)", target);
+   bufObj = get_buffer(ctx, "glMapBufferRange", target);
+   if (!bufObj)
       return NULL;
-   }
 
    if (offset + length > bufObj->Size) {
       _mesa_error(ctx, GL_INVALID_VALUE,
@@ -1514,18 +1475,9 @@ _mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
       return;
    }
 
-   bufObj = get_buffer(ctx, target);
-   if (!bufObj) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glMapBufferRange(target = 0x%x)", target);
-      return;
-   }
-
-   if (!_mesa_is_bufferobj(bufObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glMapBufferRange(current buffer is 0)");
+   bufObj = get_buffer(ctx, "glMapBufferRange", target);
+   if (!bufObj)
       return;
-   }
 
    if (!_mesa_bufferobj_mapped(bufObj)) {
       /* buffer is not mapped */
commit 02962ea086abac01fdb9e4539db30e7c3bc0a4a4
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Feb 2 11:29:51 2012 -0800

    glsl: Avoid ralloc_stealing a long-lived object to a short-lived parent
    
    In commit 6ecee54a9aecc120cb68b02f7e14dcac86b9eca2 a call to
    talloc_reference was replaced with a call to talloc_steal. This was in
    preparation for moving to ralloc which doesn't support reference
    counting.
    
    The justification for talloc_steal within token_list_append in that
    commit is that the tokens are being copied already. But the copies are
    shallow, so this does not work.
    
    Fortunately, the lifetime of these tokens is easy to understand. A
    token list for "replacements" is created and stored in a hash table
    when a function-like macro is defined. This list will live until the
    macro is #undefed (if ever).
    
    Meanwhile, a shallow copy of the list is created when the macro is
    used and the list expanded. This copy is short-lived, so is unsuitable
    as a new parent.
    
    So we can just let the original, longer-lived owner continue to own
    the underlying objects and things will work.
    
    This fixes bug #45082:
    
    	"ralloc.c:78: get_header: Assertion `info->canary == 0x5A1106'
    	failed." when using a macro in GLSL
    	https://bugs.freedesktop.org/show_bug.cgi?id=45082
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    
    NOTE: This is a candidate for stable release branches.
    (cherry picked from commit cd2e2187cb45accb13bf89ef297324332c46f379)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 2b7e65c..efcc205 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -85,7 +85,6 @@ _token_create_ival (void *ctx, int type, int ival);
 static token_list_t *
 _token_list_create (void *ctx);
 
-/* Note: This function calls ralloc_steal on token. */
 static void
 _token_list_append (token_list_t *list, token_t *token);
 
@@ -763,8 +762,6 @@ _token_list_append (token_list_t *list, token_t *token)
 	node->token = token;
 	node->next = NULL;
 
-	ralloc_steal (list, token);
-
 	if (list->head == NULL) {
 		list->head = node;
 	} else {
commit 358389fe5954c69eb5d75e8c0d0caa9c12cd492b
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 31 18:24:07 2012 -0700

    mesa: reference shared state in glPushAttrib(GL_TEXTURE_BIT)
    
    This fixes a dangling texture object pointer bug hit via wglShareLists().
    When we push the GL_TEXTURE_BIT state we may push references to the default
    texture objects which are owned by the gl_shared_state object.  We don't
    want to accidentally delete that shared state while the attribute stack
    references shared objects.  So keep a reference to it.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit a1471e4877515e2ce4fcc129c4ce26f5c306b193)

diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 01e7945..1068dd8 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -47,6 +47,7 @@
 #include "multisample.h"
 #include "points.h"
 #include "polygon.h"
+#include "shared.h"
 #include "scissor.h"
 #include "stencil.h"
 #include "texenv.h"
@@ -165,6 +166,13 @@ struct texture_state
     * deleted while saved in the attribute stack).
     */
    struct gl_texture_object *SavedTexRef[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS];
+
+   /* We need to keep a reference to the shared state.  That's where the
+    * default texture objects are kept.  We don't want that state to be
+    * freed while the attribute stack contains pointers to any default
+    * texture objects.
+    */
+   struct gl_shared_state *SharedRef;
 };
 
 
@@ -437,6 +445,8 @@ _mesa_PushAttrib(GLbitfield mask)
          }
       }
 
+      _mesa_reference_shared_state(ctx, &texstate->SharedRef, ctx->Shared);
+
       _mesa_unlock_context_textures(ctx);
 
       save_attrib_data(&head, GL_TEXTURE_BIT, texstate);
@@ -806,6 +816,8 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate)
 
    _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit);
 
+   _mesa_reference_shared_state(ctx, &texstate->SharedRef, NULL);
+
    _mesa_unlock_context_textures(ctx);
 }
 
@@ -1605,6 +1617,7 @@ _mesa_free_attrib_data(struct gl_context *ctx)
                   _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL);
                }
             }
+            _mesa_reference_shared_state(ctx, &texstate->SharedRef, NULL);
          }
          else {
             /* any other chunks of state that requires special handling? */
commit 2ed8367d72e25069172a8b57c19ed35ed3ff8990
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 31 18:23:03 2012 -0700

    mesa: use new _mesa_reference_shared_state() function
    
    This cleans up the reference counting of shared context state.
    The next patch will use this to fix an actual bug.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 361cd53a77dd48fbf2a0321446c0b7c07365bff9)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index f39cab5..43e7438 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -939,13 +939,10 @@ _mesa_initialize_context(struct gl_context *ctx,
          return GL_FALSE;
    }
 
-   _glthread_LOCK_MUTEX(shared->Mutex);
-   ctx->Shared = shared;
-   shared->RefCount++;
-   _glthread_UNLOCK_MUTEX(shared->Mutex);
+   _mesa_reference_shared_state(ctx, &ctx->Shared, shared);
 
    if (!init_attrib_groups( ctx )) {
-      _mesa_release_shared_state(ctx, ctx->Shared);
+      _mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
       return GL_FALSE;
    }
 
@@ -973,7 +970,7 @@ _mesa_initialize_context(struct gl_context *ctx,
    }
 
    if (!ctx->Exec) {
-      _mesa_release_shared_state(ctx, ctx->Shared);
+      _mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
       return GL_FALSE;
    }
 #endif
@@ -1002,7 +999,7 @@ _mesa_initialize_context(struct gl_context *ctx,
 #if FEATURE_dlist
       ctx->Save = _mesa_create_save_table();
       if (!ctx->Save) {
-	 _mesa_release_shared_state(ctx, ctx->Shared);
+         _mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
 	 free(ctx->Exec);
 	 return GL_FALSE;
       }
@@ -1140,7 +1137,7 @@ _mesa_free_context_data( struct gl_context *ctx )
    free(ctx->Save);
 
    /* Shared context state (display lists, textures, etc) */
-   _mesa_release_shared_state( ctx, ctx->Shared );
+   _mesa_reference_shared_state(ctx, &ctx->Shared, NULL);
 
    /* needs to be after freeing shared state */
    _mesa_free_display_list_data(ctx);
@@ -1540,17 +1537,18 @@ GLboolean
 _mesa_share_state(struct gl_context *ctx, struct gl_context *ctxToShare)
 {
    if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
-      struct gl_shared_state *oldSharedState = ctx->Shared;
+      struct gl_shared_state *oldShared = NULL;
 
-      ctx->Shared = ctxToShare->Shared;
-      
-      _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
-      ctx->Shared->RefCount++;
-      _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+      /* save ref to old state to prevent it from being deleted immediately */
+      _mesa_reference_shared_state(ctx, &oldShared, ctx->Shared);
+
+      /* update ctx's Shared pointer */
+      _mesa_reference_shared_state(ctx, &ctx->Shared, ctxToShare->Shared);
 
       update_default_objects(ctx);
 
-      _mesa_release_shared_state(ctx, oldSharedState);
+      /* release the old shared state */
+      _mesa_reference_shared_state(ctx, &oldShared, NULL);
 
       return GL_TRUE;
    }
diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c
index c3e93b5..c07ce82 100644
--- a/src/mesa/main/shared.c
+++ b/src/mesa/main/shared.c
@@ -388,28 +388,40 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
 
 
 /**
- * Decrement shared state object reference count and potentially free it
- * and all children structures.
- *
- * \param ctx GL context.
- * \param shared shared state pointer.
- *
- * \sa free_shared_state().
+ * gl_shared_state objects are ref counted.
+ * If ptr's refcount goes to zero, free the shared state.
  */
 void
-_mesa_release_shared_state(struct gl_context *ctx,
-                           struct gl_shared_state *shared)
+_mesa_reference_shared_state(struct gl_context *ctx,
+                             struct gl_shared_state **ptr,
+                             struct gl_shared_state *state)
 {
-   GLint RefCount;
-
-   _glthread_LOCK_MUTEX(shared->Mutex);
-   RefCount = --shared->RefCount;
-   _glthread_UNLOCK_MUTEX(shared->Mutex);
+   if (*ptr == state)
+      return;
+
+   if (*ptr) {
+      /* unref old state */
+      struct gl_shared_state *old = *ptr;
+      GLboolean delete;
+
+      _glthread_LOCK_MUTEX(old->Mutex);
+      assert(old->RefCount >= 1);
+      old->RefCount--;
+      delete = (old->RefCount == 0);
+      _glthread_UNLOCK_MUTEX(old->Mutex);
+
+      if (delete) {
+         free_shared_state(ctx, old);
+      }
 
-   assert(RefCount >= 0);
+      *ptr = NULL;
+   }
 
-   if (RefCount == 0) {
-      /* free shared state */
-      free_shared_state( ctx, shared );
+   if (state) {
+      /* reference new state */
+      _glthread_LOCK_MUTEX(state->Mutex);
+      state->RefCount++;
+      *ptr = state;
+      _glthread_UNLOCK_MUTEX(state->Mutex);
    }
 }
diff --git a/src/mesa/main/shared.h b/src/mesa/main/shared.h
index 55516a8..3fe4578 100644
--- a/src/mesa/main/shared.h
+++ b/src/mesa/main/shared.h
@@ -27,13 +27,14 @@
 
 struct gl_context;
 
-struct gl_shared_state *
-_mesa_alloc_shared_state(struct gl_context *ctx);
+void
+_mesa_reference_shared_state(struct gl_context *ctx,
+                             struct gl_shared_state **ptr,
+                             struct gl_shared_state *state);
 
 
-void
-_mesa_release_shared_state(struct gl_context *ctx,
-                           struct gl_shared_state *shared);
+struct gl_shared_state *
+_mesa_alloc_shared_state(struct gl_context *ctx);
 
 
 #endif
commit f723df005c2e66925dcb5aff4ab609d784d953d5
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 25 14:13:13 2012 -0800

    i965: Add a driconf option to force GLSL extension behavior to "warn".
    
    This can be used to work around broken application behavior, like in
    Unigine where it attempts to use texture arrays without declaring
    either "#extension GL_EXT_texture_array : enable" or "#version 130".
    
    NOTE: This is a candidate for the 8.0 branch.
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 642247883fb9e6dce9bad724f7f6503321e0ef6f)

diff --git a/src/mesa/drivers/dri/common/xmlpool/options.h b/src/mesa/drivers/dri/common/xmlpool/options.h
index 1e584ba..75c887e 100644
--- a/src/mesa/drivers/dri/common/xmlpool/options.h
+++ b/src/mesa/drivers/dri/common/xmlpool/options.h
@@ -626,3 +626,13 @@ DRI_CONF_OPT_BEGIN(always_flush_cache,bool,def) \
         DRI_CONF_DESC(fr,"Enable flushing GPU caches with each draw call") \
         DRI_CONF_DESC(sv,"Enable flushing GPU caches with each draw call") \
 DRI_CONF_OPT_END
+
+#define DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN(def) \
+DRI_CONF_OPT_BEGIN(force_glsl_extensions_warn,bool,def) \
+        DRI_CONF_DESC(en,"Force GLSL extension default behavior to 'warn'") \
+        DRI_CONF_DESC(de,"Force GLSL extension default behavior to 'warn'") \
+        DRI_CONF_DESC(es,"Force GLSL extension default behavior to 'warn'") \
+        DRI_CONF_DESC(nl,"Force GLSL extension default behavior to 'warn'") \
+        DRI_CONF_DESC(fr,"Force GLSL extension default behavior to 'warn'") \
+        DRI_CONF_DESC(sv,"Force GLSL extension default behavior to 'warn'") \
+DRI_CONF_OPT_END
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index eb152f9..f7bda1d 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -372,6 +372,8 @@ brwCreateContext(int api,
    ctx->Const.NativeIntegers = true;
    ctx->Const.UniformBooleanTrue = 1;
 
+   ctx->Const.ForceGLSLExtensionsWarn = driQueryOptionb(&intel->optionCache, "force_glsl_extensions_warn");
+
    return true;
 }
 
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index a998a37..6990265 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -74,6 +74,7 @@ PUBLIC const char __driConfigOptions[] =
      DRI_CONF_NO_RAST(false)
      DRI_CONF_ALWAYS_FLUSH_BATCH(false)
      DRI_CONF_ALWAYS_FLUSH_CACHE(false)
+     DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN(false)
 
       DRI_CONF_OPT_BEGIN(stub_occlusion_query, bool, false)
 	 DRI_CONF_DESC(en, "Enable stub ARB_occlusion_query support on 915/945.")
@@ -85,7 +86,7 @@ PUBLIC const char __driConfigOptions[] =
    DRI_CONF_SECTION_END
 DRI_CONF_END;
 
-const GLuint __driNConfigOptions = 12;
+const GLuint __driNConfigOptions = 13;
 
 #include "intel_batchbuffer.h"
 #include "intel_buffers.h"
commit 92d842c073e7f2afbe3ee2fbfb930bb6233a497b
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 18 12:14:09 2012 -0800

    mesa: Add a flag for forcing all GLSL extensions to "warn".
    
    NOTE: This is a candidate for the 8.0 branch.
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit b9e27cc1426e3242a003fa5ae91fab330694009a)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 0b53232..7f8d47c 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -114,6 +114,9 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx,
    }
 
    this->supported_version_string = supported;
+
+   if (ctx->Const.ForceGLSLExtensionsWarn)
+      _mesa_glsl_process_extension("all", NULL, "warn", NULL, this);
 }
 
 const char *
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index bce5de2..b86aeb6 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2773,6 +2773,12 @@ struct gl_constants
    GLuint GLSLVersion;  /**< GLSL version supported (ex: 120 = 1.20) */
 
    /**
+    * Changes default GLSL extension behavior from "error" to "warn".  It's out
+    * of spec, but it can make some apps work that otherwise wouldn't.
+    */
+   GLboolean ForceGLSLExtensionsWarn;
+
+   /**
     * Does the driver support real 32-bit integers?  (Otherwise, integers are
     * simulated via floats.)
     */
commit 1b5e151ffae3ff50e9012243b7fcbbb60c3a0042
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 27 12:59:24 2012 -0800

    i965/vs: Avoid allocating registers in to the gen7 MRF hack region.
    
    This is the corresponding fix to the previous one for the FS, but I
    don't have a particular test for it.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 9195191e50429d9cf25e6498f9fb108758ac2be6)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 2555fa7..bc8b392 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -334,6 +334,7 @@ public:
    int virtual_grf_count;
    int virtual_grf_array_size;
    int first_non_payload_grf;
+   unsigned int max_grf;
    int *virtual_grf_def;
    int *virtual_grf_use;
    dst_reg userplane[MAX_CLIP_PLANES];
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
index 2efe235..57b0519 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
@@ -87,9 +87,9 @@ vec4_visitor::reg_allocate_trivial()
       assign(hw_reg_mapping, &inst->src[2]);
    }
 
-   if (prog_data->total_grf > BRW_MAX_GRF) {
+   if (prog_data->total_grf > max_grf) {
       fail("Ran out of regs on trivial allocator (%d/%d)\n",
-	   prog_data->total_grf, BRW_MAX_GRF);
+	   prog_data->total_grf, max_grf);
    }
 }
 
@@ -144,7 +144,7 @@ vec4_visitor::reg_allocate()
 {
    int hw_reg_mapping[virtual_grf_count];
    int first_assigned_grf = this->first_non_payload_grf;
-   int base_reg_count = BRW_MAX_GRF - first_assigned_grf;
+   int base_reg_count = max_grf - first_assigned_grf;
    int class_sizes[base_reg_count];
    int class_count = 0;
 
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index d3c9397..3f6939b 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -2601,6 +2601,8 @@ vec4_visitor::vec4_visitor(struct brw_vs_compile *c,
    this->virtual_grf_array_size = 0;
    this->live_intervals_valid = false;
 
+   this->max_grf = intel->gen >= 7 ? GEN7_MRF_HACK_START : BRW_MAX_GRF;
+
    this->uniforms = 0;
 }
 
commit 20da01fecdd2379bd6df1407d1c344aa8ddd5c45
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Wed Jan 25 19:38:10 2012 -0800

    swrast: Fix fixed-function fragment processing
    
    On i965, _mesa_ir_link_shader is never called. As a consequence, the
    current fragment program (ctx->FragmentProgram->_Current) exists but is
    invalid because it has no instructions. Yet swrast continued to attempt to
    use the empty program.
    
    To avoid using the empty program, this patch 1) defines a new function,
    _swrast_use_fragment_program, which checks if the current fragment program
    exists and differs from the fixed function fragment program, and, when
    appropriate, 2) replaces checks of the form
        if (ctx->FragmentProgram->_Current == NULL)
    with
        if (_swrast_use_fragment_program(ctx))
    
    Fixes the following oglconform regressions on i965/gen6:
        api-fogcoord(basic.allCases.log)
        api-mtexcoord(basic.allCases.log)
        api-seccolor(basic.allCases.log)
        api-texcoord(basic.allCases.log)
        blend-separate(basic.allCases)
        colorsum(basic.allCases.log)
    
    The tests were ran with the GLXFBConfig:
        visual  x   bf lv rg d st  colorbuffer  sr ax dp st accumbuffer ms  cav
      id dep cl sp  sz l  ci b ro  r  g  b  a F gb bf th cl  r  g  b  a ns b eat
    ----------------------------------------------------------------------------
    0x021 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24 8  0  0  0  0  0 0 None
    
    (Note: I originally believed that the hunk in
    _swrast_update_fragment_program was unnecessary. But it is required to fix
    blend-separate.)
    
    Note: This is a candidate for the 8.0 branch.
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43327
    Reveiwed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Ian Romanick <idr at freedesktop.org>
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 1c0f1dd42a50464eeb81de4aad8eecf24b3d6c89)

diff --git a/src/mesa/swrast/s_aaline.c b/src/mesa/swrast/s_aaline.c
index d4b1805..d36d876 100644
--- a/src/mesa/swrast/s_aaline.c
+++ b/src/mesa/swrast/s_aaline.c
@@ -479,7 +479,7 @@ _swrast_choose_aa_line_function(struct gl_context *ctx)
    ASSERT(ctx->Line.SmoothFlag);
 
    if (ctx->Texture._EnabledCoordUnits != 0
-       || ctx->FragmentProgram._Current
+       || _swrast_use_fragment_program(ctx)
        || (ctx->Light.Enabled &&
            ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
        || ctx->Fog.ColorSumEnabled
diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h
index 376ef32..ba9f8ab 100644
--- a/src/mesa/swrast/s_aalinetemp.h
+++ b/src/mesa/swrast/s_aalinetemp.h
@@ -67,7 +67,7 @@ NAME(plot)(struct gl_context *ctx, struct LineInfo *line, int ix, int iy)
    ATTRIB_LOOP_BEGIN
       GLfloat (*attribArray)[4] = line->span.array->attribs[attr];
       if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0
-          && !ctx->FragmentProgram._Current) {
+          && !_swrast_use_fragment_program(ctx)) {
          /* texcoord w/ divide by Q */
          const GLuint unit = attr - FRAG_ATTRIB_TEX0;
          const GLfloat invQ = solve_plane_recip(fx, fy, line->attrPlane[attr][3]);
diff --git a/src/mesa/swrast/s_aatriangle.c b/src/mesa/swrast/s_aatriangle.c
index c68fdf6..b59177f 100644
--- a/src/mesa/swrast/s_aatriangle.c
+++ b/src/mesa/swrast/s_aatriangle.c
@@ -299,7 +299,7 @@ _swrast_set_aa_triangle_function(struct gl_context *ctx)
    ASSERT(ctx->Polygon.SmoothFlag);
 
    if (ctx->Texture._EnabledCoordUnits != 0
-       || ctx->FragmentProgram._Current
+       || _swrast_use_fragment_program(ctx)
        || swrast->_FogEnabled
        || _mesa_need_secondary_color(ctx)) {
       SWRAST_CONTEXT(ctx)->Triangle = general_aa_tri;
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 14cb9b1..cc304d7 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -105,7 +105,7 @@ _swrast_update_rasterflags( struct gl_context *ctx )
    }
 
 
-   if (ctx->FragmentProgram._Current) {
+   if (_swrast_use_fragment_program(ctx)) {
       rasterMask |= FRAGPROG_BIT;
    }
 
@@ -170,7 +170,7 @@ _swrast_update_fog_hint( struct gl_context *ctx )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    swrast->_PreferPixelFog = (!swrast->AllowVertexFog ||
-                              ctx->FragmentProgram._Current ||
+			      _swrast_use_fragment_program(ctx) ||
 			      (ctx->Hint.Fog == GL_NICEST &&
 			       swrast->AllowPixelFog));
 }
@@ -220,13 +220,14 @@ _swrast_update_deferred_texture(struct gl_context *ctx)
       swrast->_DeferredTexture = GL_FALSE;
    }
    else {
+      GLboolean use_fprog = _swrast_use_fragment_program(ctx);
       const struct gl_fragment_program *fprog
          = ctx->FragmentProgram._Current;
-      if (fprog && (fprog->Base.OutputsWritten & (1 << FRAG_RESULT_DEPTH))) {
+      if (use_fprog && (fprog->Base.OutputsWritten & (1 << FRAG_RESULT_DEPTH))) {
          /* Z comes from fragment program/shader */
          swrast->_DeferredTexture = GL_FALSE;
       }
-      else if (fprog && fprog->UsesKill) {
+      else if (use_fprog && fprog->UsesKill) {
          swrast->_DeferredTexture = GL_FALSE;
       }
       else if (ctx->Query.CurrentOcclusionObject) {
@@ -254,7 +255,8 @@ _swrast_update_fog_state( struct gl_context *ctx )
           (fp->Base.Target == GL_FRAGMENT_PROGRAM_NV));
 
    /* determine if fog is needed, and if so, which fog mode */
-   swrast->_FogEnabled = (fp == NULL && ctx->Fog.Enabled);
+   swrast->_FogEnabled = (!_swrast_use_fragment_program(ctx) &&
+			  ctx->Fog.Enabled);
 }
 
 
@@ -265,10 +267,11 @@ _swrast_update_fog_state( struct gl_context *ctx )
 static void
 _swrast_update_fragment_program(struct gl_context *ctx, GLbitfield newState)
 {
-   const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
-   if (fp) {
-      _mesa_load_state_parameters(ctx, fp->Base.Parameters);
-   }
+   if (!_swrast_use_fragment_program(ctx))
+      return;
+
+   _mesa_load_state_parameters(ctx,
+                               ctx->FragmentProgram._Current->Base.Parameters);
 }
 
 
@@ -286,7 +289,7 @@ _swrast_update_specular_vertex_add(struct gl_context *ctx)
 
    swrast->SpecularVertexAdd = (separateSpecular
                                 && ctx->Texture._EnabledUnits == 0x0
-                                && !ctx->FragmentProgram._Current
+                                && !_swrast_use_fragment_program(ctx)
                                 && !ctx->ATIFragmentShader._Enabled);
 }
 
@@ -497,7 +500,7 @@ _swrast_update_active_attribs(struct gl_context *ctx)
    /*
     * Compute _ActiveAttribsMask = which fragment attributes are needed.
     */
-   if (ctx->FragmentProgram._Current) {
+   if (_swrast_use_fragment_program(ctx)) {
       /* fragment program/shader */
       attribsMask = ctx->FragmentProgram._Current->Base.InputsRead;
       attribsMask &= ~FRAG_BIT_WPOS; /* WPOS is always handled specially */
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 1caa0eb..cd20d8e 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -30,6 +30,18 @@
 #include "s_fragprog.h"
 #include "s_span.h"
 
+/**
+ * \brief Should swrast use a fragment program?
+ *
+ * \return true if the current fragment program exists and is not the fixed
+ *         function fragment program
+ */
+GLboolean
+_swrast_use_fragment_program(struct gl_context *ctx)
+{
+   struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
+   return fp && fp != ctx->FragmentProgram._TexEnvProgram;
+}
 
 /**
  * Apply texture object's swizzle (X/Y/Z/W/0/1) to incoming 'texel'
diff --git a/src/mesa/swrast/s_fragprog.h b/src/mesa/swrast/s_fragprog.h
index 62a6836..ac1f5ff 100644
--- a/src/mesa/swrast/s_fragprog.h
+++ b/src/mesa/swrast/s_fragprog.h
@@ -31,6 +31,8 @@
 
 struct gl_context;
 
+GLboolean
+_swrast_use_fragment_program(struct gl_context *ctx);
 
 extern void
 _swrast_exec_fragment_program(struct gl_context *ctx, SWspan *span);
diff --git a/src/mesa/swrast/s_lines.c b/src/mesa/swrast/s_lines.c
index 95a2a5d..ee997b0 100644
--- a/src/mesa/swrast/s_lines.c
+++ b/src/mesa/swrast/s_lines.c
@@ -236,7 +236,7 @@ _swrast_choose_line( struct gl_context *ctx )
          ASSERT(swrast->Line);
       }
       else if (ctx->Texture._EnabledCoordUnits
-               || ctx->FragmentProgram._Current
+               || _swrast_use_fragment_program(ctx)
                || swrast->_FogEnabled
                || specular) {
          USE(general_line);
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 51666ba..6d6538c 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -139,7 +139,8 @@ _swrast_span_default_attribs(struct gl_context *ctx, SWspan *span)
       for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
          const GLuint attr = FRAG_ATTRIB_TEX0 + i;
          const GLfloat *tc = ctx->Current.RasterTexCoords[i];
-         if (ctx->FragmentProgram._Current || ctx->ATIFragmentShader._Enabled) {
+         if (_swrast_use_fragment_program(ctx) ||
+             ctx->ATIFragmentShader._Enabled) {
             COPY_4V(span->attrStart[attr], tc);
          }
          else if (tc[3] > 0.0F) {
@@ -498,7 +499,7 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span)
                swrast_texture_image_const(img);
 
             needLambda = (obj->Sampler.MinFilter != obj->Sampler.MagFilter)
-               || ctx->FragmentProgram._Current;
+               || _swrast_use_fragment_program(ctx);
             /* LOD is calculated directly in the ansiotropic filter, we can
              * skip the normal lambda function as the result is ignored.
              */
@@ -518,7 +519,7 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span)
 
          if (needLambda) {
             GLuint i;
-            if (ctx->FragmentProgram._Current
+            if (_swrast_use_fragment_program(ctx)
                 || ctx->ATIFragmentShader._Enabled) {
                /* do perspective correction but don't divide s, t, r by q */
                const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3];
@@ -559,7 +560,7 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span)
          }
          else {
             GLuint i;
-            if (ctx->FragmentProgram._Current ||
+            if (_swrast_use_fragment_program(ctx) ||
                 ctx->ATIFragmentShader._Enabled) {
                /* do perspective correction but don't divide s, t, r by q */
                const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3];
@@ -833,7 +834,7 @@ add_specular(struct gl_context *ctx, SWspan *span)
    GLfloat (*col1)[4] = span->array->attribs[FRAG_ATTRIB_COL1];
    GLuint i;
 
-   ASSERT(!ctx->FragmentProgram._Current);
+   ASSERT(!_swrast_use_fragment_program(ctx));
    ASSERT(span->arrayMask & SPAN_RGBA);
    ASSERT(swrast->_ActiveAttribMask & FRAG_BIT_COL1);
    (void) swrast; /* silence warning */
@@ -971,25 +972,7 @@ convert_color_type(SWspan *span, GLenum newType, GLuint output)
 static inline void
 shade_texture_span(struct gl_context *ctx, SWspan *span)
 {
-   /* This is a hack to work around drivers such as i965 that:
-    *
-    *     - Set _MaintainTexEnvProgram to generate GLSL IR for
-    *       fixed-function fragment processing.
-    *     - Don't call _mesa_ir_link_shader to generate Mesa IR from
-    *       the GLSL IR.
-    *     - May use swrast to handle glDrawPixels.
-    *
-    * Since _mesa_ir_link_shader is never called, there is no Mesa IR
-    * to execute.  Instead do regular fixed-function processing.
-    *
-    * It is also worth noting that the software fixed-function path is
-    * much faster than the software shader path.
-    */
-   const bool use_fragment_program =
-      ctx->FragmentProgram._Current
-      && ctx->FragmentProgram._Current != ctx->FragmentProgram._TexEnvProgram;
-
-   if (use_fragment_program ||
+   if (_swrast_use_fragment_program(ctx) ||
        ctx->ATIFragmentShader._Enabled) {
       /* programmable shading */
       if (span->primitive == GL_BITMAP && span->array->ChanType != GL_FLOAT) {
@@ -1018,7 +1001,7 @@ shade_texture_span(struct gl_context *ctx, SWspan *span)
          interpolate_wpos(ctx, span);
 
       /* Run fragment program/shader now */
-      if (use_fragment_program) {
+      if (_swrast_use_fragment_program(ctx)) {
          _swrast_exec_fragment_program(ctx, span);
       }
       else {
@@ -1151,7 +1134,7 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
    const GLbitfield64 origArrayAttribs = span->arrayAttribs;
    const GLenum origChanType = span->array->ChanType;
    void * const origRgba = span->array->rgba;
-   const GLboolean shader = (ctx->FragmentProgram._Current
+   const GLboolean shader = (_swrast_use_fragment_program(ctx)
                              || ctx->ATIFragmentShader._Enabled);
    const GLboolean shaderOrTexture = shader || ctx->Texture._EnabledCoordUnits;
    struct gl_framebuffer *fb = ctx->DrawBuffer;
@@ -1326,7 +1309,8 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
       const GLuint numBuffers = fb->_NumColorDrawBuffers;
       const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
       const GLboolean multiFragOutputs = 
-         (fp && fp->Base.OutputsWritten >= (1 << FRAG_RESULT_DATA0));
+         _swrast_use_fragment_program(ctx)
+         && fp->Base.OutputsWritten >= (1 << FRAG_RESULT_DATA0);
       GLuint buf;
 
       for (buf = 0; buf < numBuffers; buf++) {
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 124aa5f..ddb4792 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -1038,7 +1038,7 @@ _swrast_choose_triangle( struct gl_context *ctx )
        * needs to be interpolated.
        */
       if (ctx->Texture._EnabledCoordUnits ||
-          ctx->FragmentProgram._Current ||
+	  _swrast_use_fragment_program(ctx) ||
           ctx->ATIFragmentShader._Enabled ||
           _mesa_need_secondary_color(ctx) ||
           swrast->_FogEnabled) {
@@ -1060,7 +1060,7 @@ _swrast_choose_triangle( struct gl_context *ctx )
 
          /* First see if we can use an optimized 2-D texture function */
          if (ctx->Texture._EnabledCoordUnits == 0x1
-             && !ctx->FragmentProgram._Current
+             && !_swrast_use_fragment_program(ctx)
              && !ctx->ATIFragmentShader._Enabled
              && ctx->Texture._EnabledUnits == 0x1
              && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
commit 203ef2a12b8e8fa520decf9e9024329f4dc96996
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 14:52:04 2012 -0800

    mesa: Don't round-trip integer texture data through a floating point temp.
    
    This was losing bits of precision.  Fixes (with the previous commits):
    piglit EXT_texture_integer/getteximage-clamping
    piglit EXT_texture_integer/getteximage-clamping GL_ARB_texture_rg
    oglc advanced.mipmap.upload
    
    Regresses oglc negative.typeFormatMismatch.teximage from fail to
    abort, because it's been hitting texstore for a format/type combo that
    shouldn't happen.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 5f65598cc79eccd38bf7f95ab167ed62e575daf2)

diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 600dab3..f5cd100 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -3465,13 +3465,14 @@ _mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
    }
    else {
       /* general path */
-      const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
-                                                 baseInternalFormat,
-                                                 baseFormat,
-                                                 srcWidth, srcHeight, srcDepth,
-                                                 srcFormat, srcType, srcAddr,
-                                                 srcPacking, 0x0);
-      const GLfloat *src = tempImage;
+      const GLuint *tempImage = make_temp_uint_image(ctx, dims,
+						     baseInternalFormat,
+						     baseFormat,
+						     srcWidth, srcHeight, srcDepth,
+						     srcFormat, srcType,
+						     srcAddr,
+						     srcPacking);
+      const GLuint *src = tempImage;
       GLint img, row;
       if (!tempImage)
          return GL_FALSE;
@@ -3534,13 +3535,14 @@ _mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
    }
    else {
       /* general path */
-      const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
-                                                 baseInternalFormat,
-                                                 baseFormat,
-                                                 srcWidth, srcHeight, srcDepth,
-                                                 srcFormat, srcType, srcAddr,
-                                                 srcPacking, 0x0);
-      const GLfloat *src = tempImage;
+      const GLuint *tempImage = make_temp_uint_image(ctx, dims,
+						     baseInternalFormat,
+						     baseFormat,
+						     srcWidth, srcHeight, srcDepth,
+						     srcFormat, srcType,
+						     srcAddr,
+						     srcPacking);
+      const GLuint *src = tempImage;
       GLint img, row;
       if (!tempImage)
          return GL_FALSE;
@@ -3603,13 +3605,14 @@ _mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
    }
    else {
       /* general path */
-      const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
-                                                 baseInternalFormat,
-                                                 baseFormat,
-                                                 srcWidth, srcHeight, srcDepth,
-                                                 srcFormat, srcType, srcAddr,
-                                                 srcPacking, 0x0);
-      const GLfloat *src = tempImage;
+      const GLuint *tempImage = make_temp_uint_image(ctx, dims,
+						     baseInternalFormat,
+						     baseFormat,
+						     srcWidth, srcHeight, srcDepth,
+						     srcFormat, srcType,
+						     srcAddr,
+						     srcPacking);
+      const GLuint *src = tempImage;
       GLint img, row;
       if (!tempImage)
          return GL_FALSE;
commit 05ff4d209d67962c6f367a94dcf0045ea242d5c3
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 14:48:56 2012 -0800

    mesa: When unpacking signed integer pixel data, don't clamp to 0.
    
    In the core, we always treat spans of int/uint data as uint, so this
    extract function was truncating storage of integer pixel data to a n
    int texture to (0, max_int) instead of (min_int, max_int).  There is
    probably missing code for handling truncation on conversion between
    pixel formats, still, but this does improve things.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit dadbec1e90415f0744eb91e684bf9d7496f474c0)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 23e9d1d..ee983f9 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -3007,27 +3007,6 @@ extract_float_rgba(GLuint n, GLfloat rgba[][4],
 
 
 static inline GLuint
-clamp_byte_to_uint(GLbyte b)
-{
-   return b < 0 ? 0 : b;
-}
-
-
-static inline GLuint
-clamp_short_to_uint(GLshort s)
-{
-   return s < 0 ? 0 : s;
-}
-
-
-static inline GLuint
-clamp_int_to_uint(GLint i)
-{
-   return i < 0 ? 0 : i;
-}
-
-
-static inline GLuint
 clamp_float_to_uint(GLfloat f)
 {
    return f < 0.0F ? 0 : IROUND(f);
@@ -3149,10 +3128,10 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
          PROCESS(aSrc, ACOMP, 1, GLubyte, (GLuint));
          break;
       case GL_BYTE:
-         PROCESS(rSrc, RCOMP, 0, GLbyte, clamp_byte_to_uint);
-         PROCESS(gSrc, GCOMP, 0, GLbyte, clamp_byte_to_uint);
-         PROCESS(bSrc, BCOMP, 0, GLbyte, clamp_byte_to_uint);
-         PROCESS(aSrc, ACOMP, 1, GLbyte, clamp_byte_to_uint);
+         PROCESS(rSrc, RCOMP, 0, GLbyte, (GLuint));
+         PROCESS(gSrc, GCOMP, 0, GLbyte, (GLuint));
+         PROCESS(bSrc, BCOMP, 0, GLbyte, (GLuint));
+         PROCESS(aSrc, ACOMP, 1, GLbyte, (GLuint));
          break;
       case GL_UNSIGNED_SHORT:
          PROCESS(rSrc, RCOMP, 0, GLushort, (GLuint));
@@ -3161,10 +3140,10 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
          PROCESS(aSrc, ACOMP, 1, GLushort, (GLuint));
          break;
       case GL_SHORT:
-         PROCESS(rSrc, RCOMP, 0, GLshort, clamp_short_to_uint);
-         PROCESS(gSrc, GCOMP, 0, GLshort, clamp_short_to_uint);
-         PROCESS(bSrc, BCOMP, 0, GLshort, clamp_short_to_uint);
-         PROCESS(aSrc, ACOMP, 1, GLshort, clamp_short_to_uint);
+         PROCESS(rSrc, RCOMP, 0, GLshort, (GLuint));
+         PROCESS(gSrc, GCOMP, 0, GLshort, (GLuint));
+         PROCESS(bSrc, BCOMP, 0, GLshort, (GLuint));
+         PROCESS(aSrc, ACOMP, 1, GLshort, (GLuint));
          break;
       case GL_UNSIGNED_INT:
          PROCESS(rSrc, RCOMP, 0, GLuint, (GLuint));
@@ -3173,10 +3152,10 @@ extract_uint_rgba(GLuint n, GLuint rgba[][4],
          PROCESS(aSrc, ACOMP, 1, GLuint, (GLuint));
          break;
       case GL_INT:
-         PROCESS(rSrc, RCOMP, 0, GLint, clamp_int_to_uint);
-         PROCESS(gSrc, GCOMP, 0, GLint, clamp_int_to_uint);
-         PROCESS(bSrc, BCOMP, 0, GLint, clamp_int_to_uint);
-         PROCESS(aSrc, ACOMP, 1, GLint, clamp_int_to_uint);
+         PROCESS(rSrc, RCOMP, 0, GLint, (GLuint));
+         PROCESS(gSrc, GCOMP, 0, GLint, (GLuint));
+         PROCESS(bSrc, BCOMP, 0, GLint, (GLuint));
+         PROCESS(aSrc, ACOMP, 1, GLint, (GLuint));
          break;
       case GL_FLOAT:
          PROCESS(rSrc, RCOMP, 0, GLfloat, clamp_float_to_uint);
commit c1ccb52c72e73ad657bc5b5d2cb04759953fd3ab
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 14:16:59 2012 -0800

    mesa: Add clamping for packing of integer data.
    
    Mostly fixes piglit EXT_texture_integer/getteximage-clamping.  The
    remaining failure involves precision loss on storing of int32 texture
    data (something I knew was an issue, but wasn't trying to test).
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 8b97bb02fb1a55a6b0fe558ea1eb97bb4dae0347)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index ad76c98..23e9d1d 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -462,7 +462,7 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
 #undef FN_NAME
 
 #define DST_TYPE GLushort
-#define SRC_CONVERT(x) (x)
+#define SRC_CONVERT(x) MIN2(x, 0xffff)
 #define FN_NAME pack_ushort_from_uint_rgba
 #include "pack_tmp.h"
 #undef DST_TYPE
@@ -470,7 +470,7 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
 #undef FN_NAME
 
 #define DST_TYPE GLshort
-#define SRC_CONVERT(x) (x)
+#define SRC_CONVERT(x) CLAMP((int)x, -32768, 32767)
 #define FN_NAME pack_short_from_uint_rgba
 #include "pack_tmp.h"
 #undef DST_TYPE
@@ -478,7 +478,7 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
 #undef FN_NAME
 
 #define DST_TYPE GLubyte
-#define SRC_CONVERT(x) (x)
+#define SRC_CONVERT(x) MIN2(x, 0xff)
 #define FN_NAME pack_ubyte_from_uint_rgba
 #include "pack_tmp.h"
 #undef DST_TYPE
@@ -486,7 +486,7 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
 #undef FN_NAME
 
 #define DST_TYPE GLbyte
-#define SRC_CONVERT(x) (x)
+#define SRC_CONVERT(x) CLAMP((int)x, -128, 127)
 #define FN_NAME pack_byte_from_uint_rgba
 #include "pack_tmp.h"
 #undef DST_TYPE
commit 35af0909077b13ec198ca6b46101260a4c47a960
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 16:34:24 2012 -0800

    mesa: Add missing format unpack for some integer texture formats.
    
    This cut and paste is pretty awful.  I'm tempted to do a lot of this
    using preprocessor tricks for customizing the parameter type from a
    template function, but that's just a different sort of hideous.
    
    Fixes 8 Intel oglconform int-textures cases.
    
    NOTE: This is a candidate for the 8.0 branch.
    v2: Add alpha formats, too.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit de24ccabd6494125e10017e0914b3298ea3791ea)

diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index be39873..5846c54 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -2210,6 +2210,58 @@ unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 }
 
 static void
+unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i * 2 + 0];
+      dst[i][1] = src[i * 2 + 1];
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i * 2 + 0];
+      dst[i][1] = src[i * 2 + 1];
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i * 2 + 0];
+      dst[i][1] = src[i * 2 + 1];
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i * 2 + 0];
+      dst[i][1] = src[i * 2 + 1];
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 {
    unsigned int i;
@@ -2223,6 +2275,113 @@ unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 }
 
 static void
+unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i];
+      dst[i][1] = 0;
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i];
+      dst[i][1] = 0;
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i];
+      dst[i][1] = 0;
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = src[i];
+      dst[i][1] = 0;
+      dst[i][2] = 0;
+      dst[i][3] = 1;
+   }
+}
+
+static void
+unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = 0;
+      dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = 0;
+      dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = 0;
+      dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = 0;
+      dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = 0;
+      dst[i][3] = src[i];
+   }
+}
+
+static void
 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 {
    unsigned int i;
@@ -2245,6 +2404,50 @@ unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuin
 }
 
 static void
+unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
+      dst[i][3] = src[i * 2 + 1];
+   }
+}
+
+static void
+unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
+      dst[i][3] = src[i * 2 + 1];
+   }
+}
+
+static void
+unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
+      dst[i][3] = src[i * 2 + 1];
+   }
+}
+
+static void
+unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
+      dst[i][3] = src[i * 2 + 1];
+   }
+}
+
+static void
 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 {
    unsigned int i;
@@ -2255,6 +2458,46 @@ unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
 }
 
 static void
+unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
+   }
+}
+
+static void
+unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
+   }
+}
+
+static void
 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
 {
    unsigned int i;
@@ -2318,24 +2561,102 @@ _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
    case MESA_FORMAT_RG_INT32:
       unpack_int_rgba_RG_UINT32(src, dst, n);
       break;
+
+   case MESA_FORMAT_RG_UINT16:
+      unpack_int_rgba_RG_UINT16(src, dst, n);
+      break;
+   case MESA_FORMAT_RG_INT16:
+      unpack_int_rgba_RG_INT16(src, dst, n);
+      break;
+
+   case MESA_FORMAT_RG_UINT8:
+      unpack_int_rgba_RG_UINT8(src, dst, n);
+      break;
+   case MESA_FORMAT_RG_INT8:
+      unpack_int_rgba_RG_INT8(src, dst, n);
+      break;
+
    case MESA_FORMAT_R_UINT32:
    case MESA_FORMAT_R_INT32:
       unpack_int_rgba_R_UINT32(src, dst, n);
       break;
 
+   case MESA_FORMAT_R_UINT16:
+      unpack_int_rgba_R_UINT16(src, dst, n);
+      break;
+   case MESA_FORMAT_R_INT16:
+      unpack_int_rgba_R_INT16(src, dst, n);
+      break;
+
+   case MESA_FORMAT_R_UINT8:
+      unpack_int_rgba_R_UINT8(src, dst, n);
+      break;
+   case MESA_FORMAT_R_INT8:
+      unpack_int_rgba_R_INT8(src, dst, n);
+      break;
+
+   case MESA_FORMAT_ALPHA_UINT32:
+   case MESA_FORMAT_ALPHA_INT32:
+      unpack_int_rgba_ALPHA_UINT32(src, dst, n);
+      break;
+
+   case MESA_FORMAT_ALPHA_UINT16:
+      unpack_int_rgba_ALPHA_UINT16(src, dst, n);
+      break;
+   case MESA_FORMAT_ALPHA_INT16:
+      unpack_int_rgba_ALPHA_INT16(src, dst, n);
+      break;
+
+   case MESA_FORMAT_ALPHA_UINT8:
+      unpack_int_rgba_ALPHA_UINT8(src, dst, n);
+      break;
+   case MESA_FORMAT_ALPHA_INT8:
+      unpack_int_rgba_ALPHA_INT8(src, dst, n);
+      break;
+
    case MESA_FORMAT_LUMINANCE_UINT32:
    case MESA_FORMAT_LUMINANCE_INT32:
       unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
       break;
+
    case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
    case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
       unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
       break;
+
+   case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
+      unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
+      break;
+   case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
+      unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
+      break;
+
+   case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
+      unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
+      break;
+   case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
+      unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
+      break;
+
    case MESA_FORMAT_INTENSITY_UINT32:
    case MESA_FORMAT_INTENSITY_INT32:
       unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
       break;
 
+   case MESA_FORMAT_INTENSITY_UINT16:
+      unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
+      break;
+   case MESA_FORMAT_INTENSITY_INT16:
+      unpack_int_rgba_INTENSITY_INT16(src, dst, n);
+      break;
+
+   case MESA_FORMAT_INTENSITY_UINT8:
+      unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
+      break;
+   case MESA_FORMAT_INTENSITY_INT8:
+      unpack_int_rgba_INTENSITY_INT8(src, dst, n);
+      break;
+
    case MESA_FORMAT_ARGB2101010_UINT:
       unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
       break;
commit 80cd02f5176da3597e706941b74f0de1f69ea70c
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 16:32:36 2012 -0800

    i965: Don't allow rendering to non-GL_RED/RG/RGBA integer textures.
    
    Fixes piglit EXT_texture_integer/fbo-blending.
    (cherry picked from commit 3a8cf3357abb50d4ee11cfb801f965e3df7592fb)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index bdce057..51d3a46 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -563,6 +563,17 @@ brw_render_target_supported(struct intel_context *intel,
    struct brw_context *brw = brw_context(&intel->ctx);
    gl_format format = rb->Format;
 
+   /* Many integer formats are promoted to RGBA (like XRGB8888 is), which means
+    * we would consider them renderable even though we don't have surface
+    * support for their alpha behavior and don't have the blending unit
+    * available to fake it like we do for XRGB8888.  Force them to being
+    * unsupported.
+    */
+   if ((rb->_BaseFormat != GL_RGBA &&
+	rb->_BaseFormat != GL_RG &&
+	rb->_BaseFormat != GL_RED) && _mesa_is_format_integer_color(format))
+      return false;
+
    return brw->format_supported_as_render_target[format];
 }
 
commit 0749290d69f4f79cf6af7ac6af56c6d71c1c4c46
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 17:23:25 2012 -0800

    intel: Pass the gl_renderbuffer to render_target_supported() vtable method.
    
    I'm going to want to go looking at it for an integer texture fix.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 796f44d77906342e5912e7da6bdba1ba86bab9f0)

diff --git a/src/mesa/drivers/dri/i915/i830_vtbl.c b/src/mesa/drivers/dri/i915/i830_vtbl.c
index 082372e..8b25596 100644
--- a/src/mesa/drivers/dri/i915/i830_vtbl.c
+++ b/src/mesa/drivers/dri/i915/i830_vtbl.c
@@ -592,8 +592,11 @@ static uint32_t i830_render_target_format_for_mesa_format[MESA_FORMAT_COUNT] =
 };
 
 static bool
-i830_render_target_supported(struct intel_context *intel, gl_format format)
+i830_render_target_supported(struct intel_context *intel,
+			     struct gl_renderbuffer *rb)
 {
+   gl_format format = rb->Format;
+
    if (format == MESA_FORMAT_S8_Z24 ||
        format == MESA_FORMAT_X8_Z24 ||
        format == MESA_FORMAT_Z16) {
diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c
index 62bfa0a..11e8a35 100644
--- a/src/mesa/drivers/dri/i915/i915_vtbl.c
+++ b/src/mesa/drivers/dri/i915/i915_vtbl.c
@@ -557,8 +557,11 @@ static uint32_t i915_render_target_format_for_mesa_format[MESA_FORMAT_COUNT] =
 };
 
 static bool
-i915_render_target_supported(struct intel_context *intel, gl_format format)
+i915_render_target_supported(struct intel_context *intel,
+			     struct gl_renderbuffer *rb)
 {
+   gl_format format = rb->Format;
+
    if (format == MESA_FORMAT_S8_Z24 ||
        format == MESA_FORMAT_X8_Z24 ||
        format == MESA_FORMAT_Z16) {
diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h
index 3bce1f3..8f1cb8c 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.h
+++ b/src/mesa/drivers/dri/i965/brw_wm.h
@@ -472,7 +472,8 @@ struct gl_shader *brw_new_shader(struct gl_context *ctx, GLuint name, GLuint typ
 struct gl_shader_program *brw_new_shader_program(struct gl_context *ctx, GLuint name);
 
 bool brw_color_buffer_write_enabled(struct brw_context *brw);
-bool brw_render_target_supported(struct intel_context *intel, gl_format format);
+bool brw_render_target_supported(struct intel_context *intel,
+				 struct gl_renderbuffer *rb);
 void brw_wm_payload_setup(struct brw_context *brw,
 			  struct brw_wm_compile *c);
 bool do_wm_prog(struct brw_context *brw,
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index c77d83a..bdce057 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -557,12 +557,12 @@ brw_init_surface_formats(struct brw_context *brw)
 }
 
 bool
-brw_render_target_supported(struct intel_context *intel, gl_format format)
+brw_render_target_supported(struct intel_context *intel,
+			    struct gl_renderbuffer *rb)
 {
    struct brw_context *brw = brw_context(&intel->ctx);
-   /* Not exactly true, as some of those formats are not renderable.
-    * But at least we know how to translate them.
-    */
+   gl_format format = rb->Format;
+
    return brw->format_supported_as_render_target[format];
 }
 
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index d429adc..1efb82f 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -221,7 +221,7 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
 	 surf->ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
       break;
    default:
-      assert(brw_render_target_supported(intel, rb_format));
+      assert(brw_render_target_supported(intel, rb));
       surf->ss0.surface_format = brw->render_target_format[rb_format];
       if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
 	 _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index e673a4e..4d4e030 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -153,7 +153,7 @@ struct intel_context
 
       void (*debug_batch)(struct intel_context *intel);
       bool (*render_target_supported)(struct intel_context *intel,
-				      gl_format format);
+				      struct gl_renderbuffer *rb);
 
       /** Can HiZ be enabled on a depthbuffer of the given format? */
       bool (*is_hiz_depth_format)(struct intel_context *intel,
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 07256b2..185602a 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -780,7 +780,7 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 	 continue;
       }
 
-      if (!intel->vtbl.render_target_supported(intel, intel_rb_format(irb))) {
+      if (!intel->vtbl.render_target_supported(intel, rb)) {
 	 DBG("Unsupported HW texture/renderbuffer format attached: %s\n",
 	     _mesa_get_format_name(intel_rb_format(irb)));
 	 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
commit f62c8648d35a51f17bef08dab841a1d223f8f2c6
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 17:41:39 2012 -0800

    intel: Make a renderbuffer wrapping a texture have the same _BaseFormat.
    
    Otherwise, when you asked for the _BaseFormat of an rb wrapping a
    GL_RGB texture, you got GL_RGBA because that's what we were storing
    the texture data as.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 7cac88679bb600f35694e91859c4682c04c32f7a)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 514ac92..07256b2 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -475,7 +475,7 @@ intel_renderbuffer_update_wrapper(struct intel_context *intel,
 
    rb->Format = image->TexFormat;
    rb->InternalFormat = image->InternalFormat;
-   rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
+   rb->_BaseFormat = image->_BaseFormat;
    rb->Width = mt->level[level].width;
    rb->Height = mt->level[level].height;
 
commit 869728bd99ebc14e3b58f11e16e5c1b73916df6c
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 17:40:41 2012 -0800

    intel: Simplify intel_renderbuffer_update_wrapper() by passing in the image.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit b73f5df6483b2e37235b258f705944321ee617f5)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 8a93146..514ac92 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -59,15 +59,6 @@
 static struct gl_renderbuffer *
 intel_new_renderbuffer(struct gl_context * ctx, GLuint name);
 
-static bool
-intel_renderbuffer_update_wrapper(struct intel_context *intel,
-                                  struct intel_renderbuffer *irb,
-                                  struct intel_mipmap_tree *mt,
-                                  uint32_t level,
-                                  uint32_t layer,
-                                  gl_format format,
-                                  GLenum internal_format);
-
 bool
 intel_framebuffer_has_hiz(struct gl_framebuffer *fb)
 {
@@ -470,19 +461,20 @@ intel_framebuffer_renderbuffer(struct gl_context * ctx,
  *
  * @return true on success
  */
+
 static bool
 intel_renderbuffer_update_wrapper(struct intel_context *intel,
                                   struct intel_renderbuffer *irb,
-                                  struct intel_mipmap_tree *mt,
-                                  uint32_t level,
-                                  uint32_t layer,
-                                  gl_format format,
-                                  GLenum internal_format)
+				  struct gl_texture_image *image,
+                                  uint32_t layer)
 {
    struct gl_renderbuffer *rb = &irb->Base.Base;
+   struct intel_texture_image *intel_image = intel_texture_image(image);
+   struct intel_mipmap_tree *mt = intel_image->mt;
+   int level = image->Level;
 
-   rb->Format = format;
-   rb->InternalFormat = internal_format;
+   rb->Format = image->TexFormat;
+   rb->InternalFormat = image->InternalFormat;
    rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
    rb->Width = mt->level[level].width;
    rb->Height = mt->level[level].height;
@@ -628,10 +620,7 @@ intel_render_texture(struct gl_context * ctx,
       }
    }
 
-   if (!intel_renderbuffer_update_wrapper(intel, irb,
-                                          mt, att->TextureLevel, layer,
-                                          image->TexFormat,
-                                          image->InternalFormat)) {
+   if (!intel_renderbuffer_update_wrapper(intel, irb, image, layer)) {
        _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
        _swrast_render_texture(ctx, fb, att);
        return;
commit 1100a19da8bd37aa9eb31aeb2dddeb1081c5da7f
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 17:32:55 2012 -0800

    intel: Drop intel_wrap_miptree().
    
    Most of this function was just calling
    intel_renderbuffer_update_wrapper(), which was called immediately
    afterwards in the only caller.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 74484c5d411788c855cf91a2017d763d6a8fb4f2)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 3f6f086..8a93146 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -457,14 +457,6 @@ intel_framebuffer_renderbuffer(struct gl_context * ctx,
    intel_draw_buffer(ctx);
 }
 
-static struct intel_renderbuffer*
-intel_renderbuffer_wrap_miptree(struct intel_context *intel,
-                                struct intel_mipmap_tree *mt,
-                                uint32_t level,
-                                uint32_t layer,
-                                gl_format format,
-                                GLenum internal_format);
-
 /**
  * \par Special case for separate stencil
  *
@@ -516,45 +508,6 @@ intel_renderbuffer_update_wrapper(struct intel_context *intel,
    return true;
 }
 
-/**
- * \brief Wrap a renderbuffer around a single slice of a miptree.
- *
- * Called by glFramebufferTexture*(). This just allocates a
- * ``struct intel_renderbuffer`` then calls
- * intel_renderbuffer_update_wrapper() to do the real work.
- *
- * \see intel_renderbuffer_update_wrapper()
- */
-static struct intel_renderbuffer*
-intel_renderbuffer_wrap_miptree(struct intel_context *intel,
-                                struct intel_mipmap_tree *mt,
-                                uint32_t level,
-                                uint32_t layer,
-                                gl_format format,
-                                GLenum internal_format)
-
-{
-   struct gl_context *ctx = &intel->ctx;
-   struct gl_renderbuffer *rb;
-   struct intel_renderbuffer *irb;
-
-   intel_miptree_check_level_layer(mt, level, layer);
-
-   rb = intel_new_renderbuffer(ctx, ~0);
-   irb = intel_renderbuffer(rb);
-   if (!irb)
-      return NULL;
-
-   if (!intel_renderbuffer_update_wrapper(intel, irb,
-                                          mt, level, layer,
-                                          format, internal_format)) {
-      free(irb);
-      return NULL;
-   }
-
-   return irb;
-}
-
 void
 intel_renderbuffer_set_draw_offset(struct intel_renderbuffer *irb)
 {
@@ -660,12 +613,9 @@ intel_render_texture(struct gl_context * ctx,
       return;
    }
    else if (!irb) {
-      irb = intel_renderbuffer_wrap_miptree(intel,
-                                            mt,
-                                            att->TextureLevel,
-                                            layer,
-                                            image->TexFormat,
-                                            image->InternalFormat);
+      intel_miptree_check_level_layer(mt, att->TextureLevel, layer);
+
+      irb = (struct intel_renderbuffer *)intel_new_renderbuffer(ctx, ~0);
 
       if (irb) {
          /* bind the wrapper to the attachment point */
commit f811d501b6c254f7577fbca0cdafff8cb8ca4c2f
Author: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Date:   Fri Jan 20 07:48:52 2012 +0800

    i965: fix inverted point sprite origin when rendering to FBO
    
    When rendering to FBO, rendering is inverted. At the same time, we would
    also make sure the point sprite origin is inverted. Or, we will get an
    inverted result correspoinding to rendering to the default winsys FBO.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44613
    
    NOTE: This is a candidate for stable release branches.
    
    v2: add the simliar logic to ivb, too (comments from Ian)
        simplify the logic operation (comments from Brian)
    
    v3: pick a better comment from Eric
        use != for the logic instead of ^ (comments from Ian)
    
    Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit eaf360e5bffc5630789367020252cd12fe586177)

diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h
index 4d90a99..029be87 100644
--- a/src/mesa/drivers/dri/i965/brw_defines.h
+++ b/src/mesa/drivers/dri/i965/brw_defines.h
@@ -1128,6 +1128,7 @@ enum brw_message_target {
 /* DW1 (for gen6) */
 # define GEN6_SF_NUM_OUTPUTS_SHIFT			22
 # define GEN6_SF_SWIZZLE_ENABLE				(1 << 21)
+# define GEN6_SF_POINT_SPRITE_UPPERLEFT			(0 << 20)
 # define GEN6_SF_POINT_SPRITE_LOWERLEFT			(1 << 20)
 # define GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT		11
 # define GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT		4
diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c b/src/mesa/drivers/dri/i965/gen6_sf_state.c
index 548c5a3..163b54c 100644
--- a/src/mesa/drivers/dri/i965/gen6_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c
@@ -129,6 +129,7 @@ upload_sf_state(struct brw_context *brw)
    float point_size;
    uint16_t attr_overrides[FRAG_ATTRIB_MAX];
    bool userclip_active;
+   uint32_t point_sprite_origin;
 
    /* _NEW_TRANSFORM */
    userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
@@ -258,8 +259,16 @@ upload_sf_state(struct brw_context *brw)
    /* Clamp to the hardware limits and convert to fixed point */
    dw4 |= U_FIXED(CLAMP(point_size, 0.125, 255.875), 3);
 
-   if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT)
-      dw1 |= GEN6_SF_POINT_SPRITE_LOWERLEFT;
+   /*
+    * Window coordinates in an FBO are inverted, which means point
+    * sprite origin must be inverted, too.
+    */
+   if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo) {
+      point_sprite_origin = GEN6_SF_POINT_SPRITE_LOWERLEFT;
+   } else {
+      point_sprite_origin = GEN6_SF_POINT_SPRITE_UPPERLEFT;
+   }
+   dw1 |= point_sprite_origin;
 
    /* _NEW_LIGHT */
    if (ctx->Light.ProvokingVertex != GL_FIRST_VERTEX_CONVENTION) {
diff --git a/src/mesa/drivers/dri/i965/gen7_sf_state.c b/src/mesa/drivers/dri/i965/gen7_sf_state.c
index 7691cb2..da7ef81 100644
--- a/src/mesa/drivers/dri/i965/gen7_sf_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_sf_state.c
@@ -48,6 +48,9 @@ upload_sbe_state(struct brw_context *brw)
    int urb_entry_read_offset = 1;
    bool userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
    uint16_t attr_overrides[FRAG_ATTRIB_MAX];
+   /* _NEW_BUFFERS */
+   bool render_to_fbo = ctx->DrawBuffer->Name != 0;
+   uint32_t point_sprite_origin;
 
    brw_compute_vue_map(&vue_map, intel, userclip_active, vs_outputs_written);
    urb_entry_read_length = (vue_map.num_slots + 1)/2 - urb_entry_read_offset;
@@ -65,9 +68,18 @@ upload_sbe_state(struct brw_context *brw)
       urb_entry_read_length << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT |
       urb_entry_read_offset << GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT;
 
-   /* _NEW_POINT */
-   if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT)
-      dw1 |= GEN6_SF_POINT_SPRITE_LOWERLEFT;
+   /* _NEW_POINT
+    *
+    * Window coordinates in an FBO are inverted, which means point
+    * sprite origin must be inverted.
+    */
+   if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo) {
+      point_sprite_origin = GEN6_SF_POINT_SPRITE_LOWERLEFT;
+   } else {
+      point_sprite_origin = GEN6_SF_POINT_SPRITE_UPPERLEFT;
+   }
+   dw1 |= point_sprite_origin;
+
 
    dw10 = 0;
    dw11 = 0;
commit ecd0d460707336abfc593f9113a45e9914587a3e
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 27 12:54:11 2012 -0800

    i965/fs: Fix rendering corruption in unigine tropics.
    
    We were allocating registers into the MRF hack region, resulting in
    sparkly renering in a few of the scenes.  We could do better
    allocation by making an MRF class, having MRFs conflict with the
    corresponding GRFs, and tracking the live intervals of the "MRF"s and
    setting up the conflicts.  But this is way easier for the moment.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit e910241e9754b6e673ed0fc3133c8b1de56e76c7)

diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c
index 9929739..3347157 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c
@@ -95,7 +95,7 @@ gen7_convert_mrf_to_grf(struct brw_compile *p, struct brw_reg *reg)
    struct intel_context *intel = &p->brw->intel;
    if (intel->gen == 7 && reg->file == BRW_MESSAGE_REGISTER_FILE) {
       reg->file = BRW_GENERAL_REGISTER_FILE;
-      reg->nr += 112;
+      reg->nr += GEN7_MRF_HACK_START;
    }
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index d623316..5fdc055 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -379,6 +379,7 @@ public:
       this->frag_depth = NULL;
       memset(this->outputs, 0, sizeof(this->outputs));
       this->first_non_payload_grf = 0;
+      this->max_grf = intel->gen >= 7 ? GEN7_MRF_HACK_START : BRW_MAX_GRF;
 
       this->current_annotation = NULL;
       this->base_ir = NULL;
@@ -583,6 +584,7 @@ public:
    ir_variable *frag_depth;
    fs_reg outputs[BRW_MAX_DRAW_BUFFERS];
    int first_non_payload_grf;
+   int max_grf;
    int urb_setup[FRAG_ATTRIB_MAX];
    bool kill_emitted;
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
index d4dd124..0d1712e 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
@@ -63,9 +63,9 @@ fs_visitor::assign_regs_trivial()
       assign_reg(hw_reg_mapping, &inst->src[1], reg_width);
    }
 
-   if (this->grf_used >= BRW_MAX_GRF) {
+   if (this->grf_used >= max_grf) {
       fail("Ran out of regs on trivial allocator (%d/%d)\n",
-	   this->grf_used, BRW_MAX_GRF);
+	   this->grf_used, max_grf);
    }
 
 }
@@ -156,7 +156,7 @@ fs_visitor::assign_regs()
    int reg_width = c->dispatch_width / 8;
    int hw_reg_mapping[this->virtual_grf_next];
    int first_assigned_grf = ALIGN(this->first_non_payload_grf, reg_width);
-   int base_reg_count = (BRW_MAX_GRF - first_assigned_grf) / reg_width;
+   int base_reg_count = (max_grf - first_assigned_grf) / reg_width;
    int class_sizes[base_reg_count];
    int class_count = 0;
 
diff --git a/src/mesa/drivers/dri/i965/brw_structs.h b/src/mesa/drivers/dri/i965/brw_structs.h
index aef5695..d23ad0d 100644
--- a/src/mesa/drivers/dri/i965/brw_structs.h
+++ b/src/mesa/drivers/dri/i965/brw_structs.h
@@ -37,6 +37,17 @@
 /** Number of general purpose registers (VS, WM, etc) */
 #define BRW_MAX_GRF 128
 
+/**
+ * First GRF used for the MRF hack.
+ *
+ * On gen7, MRFs are no longer used, and contiguous GRFs are used instead.  We
+ * haven't converted our compiler to be aware of this, so it asks for MRFs and
+ * brw_eu_emit.c quietly converts them to be accesses of the top GRFs.  The
+ * register allocators have to be careful of this to avoid corrupting the "MRF"s
+ * with actual GRF allocations.
+ */
+#define GEN7_MRF_HACK_START 112.
+
 /** Number of message register file registers */
 #define BRW_MAX_MRF 16
 
commit cf4a7c41f6f2594ce4e8841ae1b268568f4ad1a7
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Feb 2 16:32:45 2012 -0700

    intel: Avoid divide by zero for very small linear blits
    
    If size is small (such as 1),
    
       pitch = ROUND_DOWN_TO(MIN2(size, (1 << 15) - 1), 4);
    
    makes pitch = 0.  Then
    
       height = size / pitch;
    
    causes a division-by-zero exception.  If pitch is zero, set height to
    1 and avoid the division.
    
    This fixes piglit's bin/getteximage-formats test and glean's
    bufferObject test.
    
    NOTE: This is a candidate for the 8.0 release branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44971
    (cherry picked from commit d59466279e45a1e9c3f9081f72fedbdf961afbe1)

diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c
index bafee4f..894e74e 100644
--- a/src/mesa/drivers/dri/intel/intel_blit.c
+++ b/src/mesa/drivers/dri/intel/intel_blit.c
@@ -492,7 +492,7 @@ intel_emit_linear_blit(struct intel_context *intel,
     * rounding that down to the nearest DWORD is 1 << 15 - 4
     */
    pitch = ROUND_DOWN_TO(MIN2(size, (1 << 15) - 1), 4);
-   height = size / pitch;
+   height = (pitch == 0) ? 1 : size / pitch;
    ok = intelEmitCopyBlit(intel, 1,
 			  pitch, src_bo, src_offset, I915_TILING_NONE,
 			  pitch, dst_bo, dst_offset, I915_TILING_NONE,
commit 74a5f030664a9509664c91346f2cde7ed06cd3c9
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Feb 1 11:37:54 2012 -0700

    intel: Remove num_mapped_regions assertion from _intel_batchbuffer_flush
    
    There are cases where a buffer can be mapped while another buffer is
    flushed.  This can happen in the CopyPixels meta-op path for piglit's
    fbo-mipmap-copypix.  After some discussion with Eric, it seems this
    assertion is no longer necessary, and it has always been too strict.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43328
    Cc: Eric Anholt <eric at anholt.net>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 65b096aeddd9b45ca038f44cc9adfff86c8c48b2)

diff --git a/src/mesa/drivers/dri/intel/intel_batchbuffer.c b/src/mesa/drivers/dri/intel/intel_batchbuffer.c
index 90effd2..ab4cb7e 100644
--- a/src/mesa/drivers/dri/intel/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/intel/intel_batchbuffer.c
@@ -178,13 +178,6 @@ _intel_batchbuffer_flush(struct intel_context *intel,
 {
    int ret;
 
-   /* No batch should be emitted that uses a mapped region, because that would
-    * cause the map to be incoherent with GPU rendering done by the
-    * batchbuffer. To ensure that condition, we assert a condition that is
-    * stronger but easier to implement: that *no* region is mapped.
-    */
-   assert(intel->num_mapped_regions == 0);
-
    if (intel->batch.used == 0)
       return 0;
 
commit 65b500857ef9ab8b6bd16bc80e7c9cc869f35750
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Feb 1 10:18:13 2012 -0700

    intel: FBOs with texture border are unsupported
    
    FBOs differ from textures in a significant way.  With textures, we can
    strip the border and get correct rendering except when the application
    fetches texels outside [0,1].
    
    With an FBO, the pixel at (0,0) is in the border.  The
    ARB_framebuffer_object spec says:
    
        "If the attached image is a texture image, then the window
        coordinates (x[w], y[w]) correspond to the texel (i, j, k), from
        figure 3.10 as follows:
    
                               i = (x[w] - b)
    
                               j = (y[w] - b)
    
                               k = (layer - b)
    
        where <b> is the texture image's border width..."
    
    Since the border doesn't exist, we can never render any pixels in the
    correct location.  Just mark these FBOs FRAMEBUFFER_UNSUPPORTED.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42336
    (cherry picked from commit 87b4c9b322dabeba7c9a9d02e9efefd2c89e6625)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 27b0bfc..3f6f086 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -823,6 +823,17 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 	 continue;
       }
 
+      if (fb->Attachment[i].Type == GL_TEXTURE) {
+	 const struct gl_texture_image *img =
+	    _mesa_get_attachment_teximage_const(&fb->Attachment[i]);
+
+	 if (img->Border) {
+	    DBG("texture with border\n");
+	    fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
+	    continue;
+	 }
+      }
+
       irb = intel_renderbuffer(rb);
       if (irb == NULL) {
 	 DBG("software rendering renderbuffer\n");
commit c231482725c84a59d5d06fb776230e3543990620
Author: Carl Worth <cworth at cworth.org>
Date:   Sat Jan 21 09:24:11 2012 -0800

    glcpp: Fix so that trailing punctuation does not prevent macro expansion
    
    The trick here is that flex always chooses the rule that matches the most
    text. So with a input text of "two:" which we want to be lexed as an
    IDENTIFIER token "two" followed by an OTHER token ":" the previous OTHER
    rule would match longer as a single token of "two:" which we don't want.
    
    We prevent this by forcing the OTHER pattern to never match any
    characters that appear in other constructs, (no letters, numbers, #,
    _, whitespace, nor any punctuation that appear in CPP operators).
    
    Fixes bug #44764:
    
    	GLSL preprocessor doesn't replace defines ending with ":"
    	https://bugs.freedesktop.org/show_bug.cgi?id=44764
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    
    NOTE: This is a candidate for stable release branches.
    (cherry picked from commit 7ab1c7f7926c75a07f33eb149d0fc17dcfaffd5e)

diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index 8661887..b34f2c0 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -70,7 +70,15 @@ HSPACE		[ \t]
 HASH		^{HSPACE}*#{HSPACE}*
 IDENTIFIER	[_a-zA-Z][_a-zA-Z0-9]*
 PUNCTUATION	[][(){}.&*~!/%<>^|;,=+-]
-OTHER		[^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
+
+/* The OTHER class is simply a catch-all for things that the CPP
+parser just doesn't care about. Since flex regular expressions that
+match longer strings take priority over those matching shorter
+strings, we have to be careful to avoid OTHER matching and hiding
+something that CPP does care about. So we simply exclude all
+characters that appear in any other expressions. */
+
+OTHER		[^][_#[:space:]#a-zA-Z0-9(){}.&*~!/%<>^|;,=+-]
 
 DIGITS			[0-9][0-9]*
 DECIMAL_INTEGER		[1-9][0-9]*[uU]?
commit 50a8b9971e2aebee5d89c22df8404a2ef6ade111
Author: Ville Syrjala <syrjala at sci.fi>
Date:   Wed Feb 1 05:10:04 2012 +0200

    gallium/dri: Handle xserver that doesn't send needless DRI2 invalidate events
    
    Ever since xserver commit 531869448d07e00ae241120b59f3aaaa5709d59c,
    the server no longer sends invalidate events to clients, unless they
    have performed a GetBuffers request since the drawable was last
    invalidated.
    
    If the drawable gets invalidated immediately after the GetBuffers
    request was processed by the X server, it's possible that Xlib
    will process the invalidate event while waiting for the GetBuffers
    reply. So the server, thinking the client knows that the buffers
    are invalid, is waiting for another GetBuffers request before
    sending any more invalidate events. The client, on the other hand,
    believes the buffers to be valid, and thus is expecting to receive
    another invalidate event before it has to send another GetBuffers
    request. The end result is that the client never again sends
    a GetBuffers request.
    
    To avoid this problem, take a snapshot of the lastStamp before
    doing GetBuffers, and retry if the snapshot and the current
    lastStamp no longer match after the GetBuffers reply has been
    processed.
    
    Signed-off-by: Ville Syrjälä <syrjala at sci.fi>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 0fcc518964223d9baaa2b45e80afeb800beb872f)

diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c b/src/gallium/state_trackers/dri/common/dri_drawable.c
index 65b3d04..5a261dd 100644
--- a/src/gallium/state_trackers/dri/common/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/common/dri_drawable.c
@@ -53,6 +53,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
    unsigned statt_mask, new_mask;
    boolean new_stamp;
    int i;
+   unsigned int lastStamp;
 
    statt_mask = 0x0;
    for (i = 0; i < count; i++)
@@ -66,23 +67,26 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
     * client stamp.  It has the value of the server stamp when last
     * checked.
     */
-   new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp);
+   do {
+      lastStamp = drawable->dPriv->lastStamp;
+      new_stamp = (drawable->texture_stamp != lastStamp);
 
-   if (new_stamp || new_mask || screen->broken_invalidate) {
-      if (new_stamp && drawable->update_drawable_info)
-         drawable->update_drawable_info(drawable);
+      if (new_stamp || new_mask || screen->broken_invalidate) {
+         if (new_stamp && drawable->update_drawable_info)
+            drawable->update_drawable_info(drawable);
 
-      drawable->allocate_textures(drawable, statts, count);
+         drawable->allocate_textures(drawable, statts, count);
 
-      /* add existing textures */
-      for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
-         if (drawable->textures[i])
-            statt_mask |= (1 << i);
-      }
+         /* add existing textures */
+         for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
+            if (drawable->textures[i])
+               statt_mask |= (1 << i);
+         }
 
-      drawable->texture_stamp = drawable->dPriv->lastStamp;
-      drawable->texture_mask = statt_mask;
-   }
+         drawable->texture_stamp = lastStamp;
+         drawable->texture_mask = statt_mask;
+      }
+   } while (lastStamp != drawable->dPriv->lastStamp);
 
    if (!out)
       return TRUE;
commit a4cb2fdb644297484a80f173d3e96e140a64ef85
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Feb 2 15:14:04 2012 -0700

    gallium/postprocess: move declarations before code
    
    To fix MSVC build.
    (cherry picked from commit 8cbe699c0dd9b8d4accf1eaa570689f813aa3c2f)

diff --git a/src/gallium/auxiliary/postprocess/pp_run.c b/src/gallium/auxiliary/postprocess/pp_run.c
index aa1badc..89b88a5 100644
--- a/src/gallium/auxiliary/postprocess/pp_run.c
+++ b/src/gallium/auxiliary/postprocess/pp_run.c
@@ -42,7 +42,7 @@ void
 pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
        struct pipe_resource *out, struct pipe_resource *indepth)
 {
-
+   struct pipe_resource *refin = NULL, *refout = NULL;
    unsigned int i;
 
    if (in->width0 != ppq->p->framebuffer.width ||
@@ -65,7 +65,6 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    }
 
    // Kept only for this frame.
-   struct pipe_resource *refin = NULL, *refout = NULL;
    pipe_resource_reference(&ppq->depth, indepth);
    pipe_resource_reference(&refin, in);
    pipe_resource_reference(&refout, out);
commit 1c403f4999a12e696b420213be7283e6e6b27ffd
Author: Lauri Kasanen <cand at gmx.com>
Date:   Tue Jan 24 21:37:56 2012 +0200

    gallium/postprocess: Just to be safe, reference all buffers from outside
    
    Even though it should be safe to use them for one frame, better be sure.
    Suggested by Michael Dänzer.
    
    NOTE: This is a candidate for the 8.0 stable branch.
    
    Signed-off-by: Lauri Kasanen <cand at gmx.com>
    (cherry picked from commit 81938d2137a7a65521ca5a3cd7180902d063c5c0)

diff --git a/src/gallium/auxiliary/postprocess/pp_run.c b/src/gallium/auxiliary/postprocess/pp_run.c
index be52051..aa1badc 100644
--- a/src/gallium/auxiliary/postprocess/pp_run.c
+++ b/src/gallium/auxiliary/postprocess/pp_run.c
@@ -64,6 +64,12 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
       in = ppq->tmp[0];
    }
 
+   // Kept only for this frame.
+   struct pipe_resource *refin = NULL, *refout = NULL;
+   pipe_resource_reference(&ppq->depth, indepth);
+   pipe_resource_reference(&refin, in);
+   pipe_resource_reference(&refout, out);
+
    switch (ppq->n_filters) {
    case 1:                     /* No temp buf */
       ppq->pp_queue[0] (ppq, in, out, 0);
@@ -93,6 +99,10 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
 
       break;
    }
+
+   pipe_resource_reference(&ppq->depth, NULL);
+   pipe_resource_reference(&refin, NULL);
+   pipe_resource_reference(&refout, NULL);
 }
 
 
commit ad83ddc868aafdcf263360e075ae7c399bcd71d4
Author: Lauri Kasanen <cand at gmx.com>
Date:   Tue Jan 24 21:37:07 2012 +0200

    gallium/postprocess: Fix depth logic
    
    This prevents a possible lapse of the depth buffer - the situation where
    the app and pp have different depth buffers.
    
    NOTE: This is a candidate for the 8.0 stable branch.
    
    Signed-off-by: Lauri Kasanen <cand at gmx.com>
    (cherry picked from commit c5976017e31828dd67fb54e8c11b863fffcac70b)

diff --git a/src/gallium/auxiliary/postprocess/postprocess.h b/src/gallium/auxiliary/postprocess/postprocess.h
index ef94f79..dfa15f7 100644
--- a/src/gallium/auxiliary/postprocess/postprocess.h
+++ b/src/gallium/auxiliary/postprocess/postprocess.h
@@ -72,8 +72,7 @@ void pp_free(struct pp_queue_t *);
 void pp_free_fbos(struct pp_queue_t *);
 void pp_debug(const char *, ...);
 struct program *pp_init_prog(struct pp_queue_t *, struct pipe_screen *);
-void pp_init_fbos(struct pp_queue_t *, unsigned int, unsigned int,
-                  struct pipe_resource *);
+void pp_init_fbos(struct pp_queue_t *, unsigned int, unsigned int);
 
 /* The filters */
 
diff --git a/src/gallium/auxiliary/postprocess/pp_init.c b/src/gallium/auxiliary/postprocess/pp_init.c
index 740d230..e2068c2 100644
--- a/src/gallium/auxiliary/postprocess/pp_init.c
+++ b/src/gallium/auxiliary/postprocess/pp_init.c
@@ -135,7 +135,6 @@ pp_free_fbos(struct pp_queue_t *ppq)
       pipe_surface_reference(&ppq->inner_tmps[i], NULL);
       pipe_resource_reference(&ppq->inner_tmp[i], NULL);
    }
-   pipe_resource_reference(&ppq->depth, NULL);
    pipe_surface_reference(&ppq->stencils, NULL);
    pipe_resource_reference(&ppq->stencil, NULL);
 
@@ -196,7 +195,7 @@ pp_debug(const char *fmt, ...)
 /** Allocate the temp FBOs. Called on makecurrent and resize. */
 void
 pp_init_fbos(struct pp_queue_t *ppq, unsigned int w,
-             unsigned int h, struct pipe_resource *indepth)
+             unsigned int h)
 {
 
    struct program *p = ppq->p;  /* The lazy will inherit the earth */
@@ -243,11 +242,7 @@ pp_init_fbos(struct pp_queue_t *ppq, unsigned int w,
          goto error;
    }
 
-   tmp_res.format = p->surf.format = indepth->format;
    tmp_res.bind = p->surf.usage = PIPE_BIND_DEPTH_STENCIL;
-   pipe_resource_reference(&ppq->depth, indepth);
-   if (!ppq->depth)
-      goto error;
 
    tmp_res.format = p->surf.format = PIPE_FORMAT_S8_UINT_Z24_UNORM;
 
diff --git a/src/gallium/auxiliary/postprocess/pp_run.c b/src/gallium/auxiliary/postprocess/pp_run.c
index ab09a56..be52051 100644
--- a/src/gallium/auxiliary/postprocess/pp_run.c
+++ b/src/gallium/auxiliary/postprocess/pp_run.c
@@ -49,7 +49,7 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
        in->height0 != ppq->p->framebuffer.height) {
       pp_debug("Resizing the temp pp buffers\n");
       pp_free_fbos(ppq);
-      pp_init_fbos(ppq, in->width0, in->height0, indepth);
+      pp_init_fbos(ppq, in->width0, in->height0);
    }
 
    if (in == out && ppq->n_filters == 1) {
diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c
index b47d8d9..28380180 100644
--- a/src/gallium/state_trackers/dri/common/dri_context.c
+++ b/src/gallium/state_trackers/dri/common/dri_context.c
@@ -232,8 +232,7 @@ dri_make_current(__DRIcontext * cPriv,
    if (draw->textures[ST_ATTACHMENT_BACK_LEFT] && draw->textures[ST_ATTACHMENT_DEPTH_STENCIL]
       && ctx->pp)
          pp_init_fbos(ctx->pp, draw->textures[ST_ATTACHMENT_BACK_LEFT]->width0,
-            draw->textures[ST_ATTACHMENT_BACK_LEFT]->height0,
-            draw->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
+            draw->textures[ST_ATTACHMENT_BACK_LEFT]->height0);
 
    return GL_TRUE;
 }
commit ac089040d729ac746fadd70b4d3a3061279be6d1
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Tue Jan 24 17:57:56 2012 +0100

    gallium/postprocess: Proper reference counting of pp_jimenezmlaa depth buffer.
    
    Fixes https://bugs.freedesktop.org/show_bug.cgi?id=40776
    
    NOTE: This is a candidate for the stable branches.
    (cherry picked from commit 7219af5ec184d4f92682e75f3d992ae048005d6a)

diff --git a/src/gallium/auxiliary/postprocess/pp_init.c b/src/gallium/auxiliary/postprocess/pp_init.c
index ef127f8..740d230 100644
--- a/src/gallium/auxiliary/postprocess/pp_init.c
+++ b/src/gallium/auxiliary/postprocess/pp_init.c
@@ -135,6 +135,7 @@ pp_free_fbos(struct pp_queue_t *ppq)
       pipe_surface_reference(&ppq->inner_tmps[i], NULL);
       pipe_resource_reference(&ppq->inner_tmp[i], NULL);
    }
+   pipe_resource_reference(&ppq->depth, NULL);
    pipe_surface_reference(&ppq->stencils, NULL);
    pipe_resource_reference(&ppq->stencil, NULL);
 
@@ -244,7 +245,7 @@ pp_init_fbos(struct pp_queue_t *ppq, unsigned int w,
 
    tmp_res.format = p->surf.format = indepth->format;
    tmp_res.bind = p->surf.usage = PIPE_BIND_DEPTH_STENCIL;
-   ppq->depth = indepth;
+   pipe_resource_reference(&ppq->depth, indepth);
    if (!ppq->depth)
       goto error;
 
commit 0e08205421c88d19a8a8955bc27602444df6a0ab
Author: Paul Berry <stereotype441 at gmail.com>
Date:   Mon Jan 23 16:11:05 2012 -0800

    i965/gen6: Fix segfault in transform feedback to DYNAMIC_DRAW buffers.
    
    When storing data in a buffer of type DYNAMIC_DRAW, we don't create a
    drm_intel_bo for it; instead we store the data in system memory and
    defer allocation of the GPU buffer until it is needed.  Therefore, in
    brw_update_sol_surface(), we can't just consult the "buffer" field of
    the intel_buffer_object structure; we need to call
    intel_bufferobj_buffer() to ensure that the deferred allocation
    occurs.
    
    This parallels a similar fix for gen7 (see commit ba6f4c9).
    
    Fixes piglit test EXT_transform_feedback/buffer-usage on gen6.
    
    This is a candidate for the 8.0 release branch.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 6bc08ee56991ac3ca0fa0728c3907835282332b8)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index 7fd83ea..c77d83a 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -730,7 +730,10 @@ brw_update_sol_surface(struct brw_context *brw,
                        uint32_t *out_offset, unsigned num_vector_components,
                        unsigned stride_dwords, unsigned offset_dwords)
 {
-   drm_intel_bo *bo = intel_buffer_object(buffer_obj)->buffer;
+   struct intel_context *intel = &brw->intel;
+   struct intel_buffer_object *intel_bo = intel_buffer_object(buffer_obj);
+   drm_intel_bo *bo =
+      intel_bufferobj_buffer(intel, intel_bo, INTEL_WRITE_PART);
    uint32_t *surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 6 * 4, 32,
                                     out_offset);
    uint32_t pitch_minus_1 = 4*stride_dwords - 1;
commit cc27a42b6f268cfa8fb6021ed0e12789cc51ac92
Author: Paul Berry <stereotype441 at gmail.com>
Date:   Thu Jan 19 15:49:43 2012 -0800

    i965/vs: Fix bogus assertion in emit_block_move()
    
    i965 processes assignments of whole structures using
    vec4_visitor::emit_block_move, a recursive function which visits each
    element of a structure or array (to arbitrary nesting depth) and
    copies it from the source to the destination.  Then it increments the
    source and destination register numbers so that further recursive
    invocations will copy the rest of the structure.  In addition, it sets
    the swizzle field for the source register to an appropriate value of
    swizzle_for_size(...) for the size of each element being copied, so
    that later optimization passes won't be fooled into thinking that
    unused vector elements are live.
    
    This all works fine.  However, emit_block_move also contains an
    assertion to verify, before setting the swizzle field for the source
    register, that the source register doesn't already contain a
    nontrivial swizzle.  The intention is to make sure that the caller of
    emit_block_move hasn't already done some swizzling of the data before
    the call, which emit_block_move would then counteract when it
    overwrites the swizzle field.  But the assertion is at the lowest
    level of nesting of emit_block_move, which means that after the first
    element is copied, instead of checking the swizzle field set by the
    caller, it checks the swizzle field used when moving the previous
    element.  That means that if the structure contains elements of
    different vector sizes (which therefore require different swizzles),
    the assertion will erroneously fire.
    
    This patch moves the assertion from emit_block_move to the calling
    function, vec4_visitor::visit(ir_assignment *).  Since the caller is
    non-recursive, the assertion will only happen once, and won't be
    fooled by emit_block_move's modification of the swizzle field.
    
    This patch also reverts commit fe006a7 (i965/vs: Fix swizzle related
    assertion), which attempted to fix the bug by making the assertion
    more lenient, but only worked properly for structures, arrays, and
    matrices in which each constituent vector is the same size.
    
    This fixes the problem described in comment 9 of
    https://bugs.freedesktop.org/show_bug.cgi?id=40865.  Unfortunately, it
    doesn't fix the whole bug, since the test in question is also failing
    due to lack of register spilling support in the VS.
    
    Fixes piglit test vs-assign-varied-struct.  No piglit regressions on
    Sandy Bridge.
    
    This is a candidate for the 8.0 release branch.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40865#c9
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit e2274aa7398d6d710683c1a2518353750700bcc0)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 06bde92..d3c9397 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -1532,9 +1532,6 @@ vec4_visitor::emit_block_move(dst_reg *dst, src_reg *src,
 
    dst->writemask = (1 << type->vector_elements) - 1;
 
-   /* Do we need to worry about swizzling a swizzle? */
-   assert(src->swizzle == BRW_SWIZZLE_NOOP
-	  || src->swizzle == swizzle_for_size(type->vector_elements));
    src->swizzle = swizzle_for_size(type->vector_elements);
 
    vec4_instruction *inst = emit(MOV(*dst, *src));
@@ -1617,6 +1614,15 @@ vec4_visitor::visit(ir_assignment *ir)
 	 emit_bool_to_cond_code(ir->condition, &predicate);
       }
 
+      /* emit_block_move doesn't account for swizzles in the source register.
+       * This should be ok, since the source register is a structure or an
+       * array, and those can't be swizzled.  But double-check to be sure.
+       */
+      assert(src.swizzle ==
+             (ir->rhs->type->is_matrix()
+              ? swizzle_for_size(ir->rhs->type->vector_elements)
+              : BRW_SWIZZLE_NOOP));
+
       emit_block_move(&dst, &src, ir->rhs->type, predicate);
       return;
    }
commit 67937502f557bee2000b2abc172e0e0f4458ec6c
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 15:27:29 2012 -0800

    mesa: Fix display list handling for GL_EXT_framebuffer_multisample.
    
    From the extension spec:
    
        Added to section 5.4, as part of the discussion of which commands
        are not compiled into display lists:
    
        "Certain commands, when called while compiling a display list, are
        not compiled into the display list but are executed immediately.
        These are: ..., RenderbufferStorageMultisampleEXT..."
    
    Fixes piglit EXT_framebuffer_multisample/dlist.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 3d8c27f882b852ada86aac99a54fdb57d98a79ac)

diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index fed487b..677debf 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -10130,6 +10130,9 @@ _mesa_create_save_table(void)
    SET_FramebufferRenderbufferEXT(table, _mesa_FramebufferRenderbufferEXT);
    SET_GenerateMipmapEXT(table, _mesa_GenerateMipmapEXT);
 
+   /* 317. GL_EXT_framebuffer_multisample */
+   SET_RenderbufferStorageMultisample(table, _mesa_RenderbufferStorageMultisample);
+
    /* GL_ARB_vertex_array_object */
    SET_BindVertexArray(table, _mesa_BindVertexArray);
    SET_GenVertexArrays(table, _mesa_GenVertexArrays);
commit 1a77654e6abcb143ed66e5eb0564d5f0392018df
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 15:19:50 2012 -0800

    mesa: Fix display list handling for EXT_framebuffer_object.
    
    Noticed when handling a similar problem in EXT_framebuffer_multisample.
    
    From the EXT_framebuffer_object spec:
    
        Added to section 5.4, as part of the discussion of which commands
        are not compiled into display lists:
    
        "Certain commands, when called while compiling a display list, are
        not compiled into the display list but are executed immediately.
        These are: ..., GenFramebuffersEXT, BindFramebufferEXT,
        DeleteFramebuffersEXT, CheckFramebufferStatusEXT,
        GenRenderbuffersEXT, BindRenderbufferEXT, DeleteRenderbuffersEXT,
        RenderbufferStorageEXT, FramebufferTexture1DEXT,
        FramebufferTexture2DEXT, FramebufferTexture3DEXT,
        FramebufferRenderbufferEXT, GenerateMipmapEXT..."
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 25dd80555d895fbe98e8f8099283992d350f22a2)

diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 95b8211..fed487b 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -46,6 +46,9 @@
 #include "dlist.h"
 #include "enums.h"
 #include "eval.h"
+#if FEATURE_EXT_framebuffer_object
+#include "fbobject.h"
+#endif
 #include "framebuffer.h"
 #include "glapi/glapi.h"
 #include "hash.h"
@@ -10112,6 +10115,21 @@ _mesa_create_save_table(void)
    SET_GenVertexArraysAPPLE(table, _mesa_GenVertexArraysAPPLE);
    SET_IsVertexArrayAPPLE(table, _mesa_IsVertexArrayAPPLE);
 
+   /* 310. GL_EXT_framebuffer_object */
+   SET_GenFramebuffersEXT(table, _mesa_GenFramebuffersEXT);
+   SET_BindFramebufferEXT(table, _mesa_BindFramebufferEXT);
+   SET_DeleteFramebuffersEXT(table, _mesa_DeleteFramebuffersEXT);
+   SET_CheckFramebufferStatusEXT(table, _mesa_CheckFramebufferStatusEXT);
+   SET_GenRenderbuffersEXT(table, _mesa_GenRenderbuffersEXT);
+   SET_BindRenderbufferEXT(table, _mesa_BindRenderbufferEXT);
+   SET_DeleteRenderbuffersEXT(table, _mesa_DeleteRenderbuffersEXT);
+   SET_RenderbufferStorageEXT(table, _mesa_RenderbufferStorageEXT);
+   SET_FramebufferTexture1DEXT(table, _mesa_FramebufferTexture1DEXT);
+   SET_FramebufferTexture2DEXT(table, _mesa_FramebufferTexture2DEXT);
+   SET_FramebufferTexture3DEXT(table, _mesa_FramebufferTexture3DEXT);
+   SET_FramebufferRenderbufferEXT(table, _mesa_FramebufferRenderbufferEXT);
+   SET_GenerateMipmapEXT(table, _mesa_GenerateMipmapEXT);
+
    /* GL_ARB_vertex_array_object */
    SET_BindVertexArray(table, _mesa_BindVertexArray);
    SET_GenVertexArrays(table, _mesa_GenVertexArrays);
commit b38640082cdf0d271c7d3da83d45dfa5f3a7b8d3
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Wed Jan 25 19:05:45 2012 -0800

    mesa: fix maximum allowed proxy texture size condition
    
    width, height parameter in glTexImage2D() includes: texture image
    width + 2 * border (if any). So when doing the texture size check
    in _mesa_test_proxy_teximage() width and height should not exceed
    maximum supported size for target texture type.
    i.e. 1 << (ctx->Const.MaxTextureLevels - 1)
    
    Texture border is anyway stripped out before it is given to intel
    or gallium drivers.
    
    This patch fixes Intel oglconform test case: max_values
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44970
    
    Note: This is a candidate for mesa 8.0 branch.
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Ian Romanick <idr at freedesktop.org>
    Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 15986d21ebaaeedb234b066edba5cf7f6ea87a3c)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 53fd241..111e4bf 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1173,7 +1173,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
    switch (target) {
    case GL_PROXY_TEXTURE_1D:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > 2 + maxSize)
+      if (width < 2 * border || width > maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.MaxTextureLevels)
          return GL_FALSE;
@@ -1185,9 +1185,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_2D:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > 2 + maxSize)
+      if (width < 2 * border || width > maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > 2 + maxSize)
+      if (height < 2 * border || height > maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.MaxTextureLevels)
          return GL_FALSE;
@@ -1201,11 +1201,11 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_3D:
       maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
-      if (width < 2 * border || width > 2 + maxSize)
+      if (width < 2 * border || width > maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > 2 + maxSize)
+      if (height < 2 * border || height > maxSize)
          return GL_FALSE;
-      if (depth < 2 * border || depth > 2 + maxSize)
+      if (depth < 2 * border || depth > maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.Max3DTextureLevels)
          return GL_FALSE;
@@ -1231,9 +1231,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
       maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
-      if (width < 2 * border || width > 2 + maxSize)
+      if (width < 2 * border || width > maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > 2 + maxSize)
+      if (height < 2 * border || height > maxSize)
          return GL_FALSE;
       if (level >= ctx->Const.MaxCubeTextureLevels)
          return GL_FALSE;
@@ -1247,7 +1247,7 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > 2 + maxSize)
+      if (width < 2 * border || width > maxSize)
          return GL_FALSE;
       if (height < 1 || height > ctx->Const.MaxArrayTextureLayers)
          return GL_FALSE;
@@ -1261,9 +1261,9 @@ _mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
 
    case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
       maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
-      if (width < 2 * border || width > 2 + maxSize)
+      if (width < 2 * border || width > maxSize)
          return GL_FALSE;
-      if (height < 2 * border || height > 2 + maxSize)
+      if (height < 2 * border || height > maxSize)
          return GL_FALSE;
       if (depth < 1 || depth > ctx->Const.MaxArrayTextureLayers)
          return GL_FALSE;
commit 736f1e53e4f08e9c56ce6480695f5de0f2caa982
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Tue Jan 24 20:06:27 2012 -0800

    mesa: set clamp bit in glGetTexImage for GL_UNSIGNED_NORMALIZED
    
    Color clamping should be enabled in glGetTexImage if texture dataType is
    GL_UNSIGNED_NORMALIZED and format is GL_LUMINANCE or GL_LUMINANCE_ALPHA
    
    Fixes 2 Intel oglconform test cases: pxconv-gettex and pxtrans-gettex
    https://bugs.freedesktop.org/show_bug.cgi?id=40864
    
    NOTE: This is a candidate for the 8.0 branch
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 5665b5cc31da70e833f80e7a17bfa034d2f7ba44)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 4eaa035..8362199 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -462,6 +462,15 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
          transferOps |= IMAGE_CLAMP_BIT;
       }
    }
+   /* This applies to RGB, RGBA textures. if the format is either LUMINANCE
+    * or LUMINANCE ALPHA, luminance (L) is computed as L=R+G+B .we need to
+    * clamp the sum to [0,1].
+    */
+   else if ((format == GL_LUMINANCE ||
+            format == GL_LUMINANCE_ALPHA) &&
+            dataType == GL_UNSIGNED_NORMALIZED) {
+      transferOps |= IMAGE_CLAMP_BIT;
+   }
 
    if (_mesa_is_format_compressed(texImage->TexFormat)) {
       get_tex_rgba_compressed(ctx, dimensions, format, type,
commit d45d250ad102f22b7e1b51bd6d68366b8f5ca7ff
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Feb 1 22:46:31 2012 -0700

    mesa: Fix copy-and-paste error in _mesa_pack_rgba_span_float
    
    GL_RG_INTEGER only has two components, not three.  I'll be surprised
    if anyone ever tries to glReadPixels(..., GL_SHORT, GL_RG_INTEGER,
    ...).  This was found by inspection.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 2e8f8cb383320b83ba5d85c27808ac2d841834e6)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index f874ab2..ad76c98 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -1175,9 +1175,8 @@ _mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
                   break;
                case GL_RG_INTEGER:
                   for (i=0;i<n;i++) {
-                     dst[i*3+0] = (GLshort) rgba[i][RCOMP];
-                     dst[i*3+1] = (GLshort) rgba[i][GCOMP];
-                     dst[i*3+2] = (GLshort) rgba[i][BCOMP];
+                     dst[i*2+0] = (GLshort) rgba[i][RCOMP];
+                     dst[i*2+1] = (GLshort) rgba[i][GCOMP];
                   }
                   break;
                case GL_RGB_INTEGER_EXT:
commit 4635e26db23dae60b7586995eb3cf27cb9841443
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Feb 1 14:19:35 2012 -0700

    mesa: Fix copy-and-paste bug in do_row_3D
    
    Several of the half-float cases used 4 as the texel size when it
    should have been some smaller value.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43324
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43325
    (cherry picked from commit 5c341b7df3c1058d586629394e53e9e26ae2cc01)

diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index 03ce536..756316a 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -991,7 +991,7 @@ do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
       }
    }
    else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 3)) {
-      DECLARE_ROW_POINTERS(GLhalfARB, 4);
+      DECLARE_ROW_POINTERS(GLhalfARB, 3);
 
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
@@ -1001,7 +1001,7 @@ do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
       }
    }
    else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 2)) {
-      DECLARE_ROW_POINTERS(GLhalfARB, 4);
+      DECLARE_ROW_POINTERS(GLhalfARB, 2);
 
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
@@ -1010,7 +1010,7 @@ do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
       }
    }
    else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 1)) {
-      DECLARE_ROW_POINTERS(GLhalfARB, 4);
+      DECLARE_ROW_POINTERS(GLhalfARB, 1);
 
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
commit 65b9c1dee6edbafb46f782ecc525c1dbdbf76e0d
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Jan 31 11:29:06 2012 -0700

    mesa: Convert colors if span ChanType and renderbuffer data type don't match
    
    This is a partial revert of f9874fe.  It turns out that the types
    don't always match.  Specifically, this can happen when doing
    glCopyPixels from a float FBO to a RGBA8 FBO.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45429
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 660ed923ded3552e023ef8c3dd9f92e6792f1bd2)

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 7ab60b1..51666ba 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1337,12 +1337,23 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
          if (rb) {
             GLchan rgbaSave[MAX_WIDTH][4];
 
-            if (span->array->ChanType == GL_UNSIGNED_BYTE) {
-               span->array->rgba = span->array->rgba8;
+	    GLenum datatype;
+	    GLuint comps;
+
+	    _mesa_format_to_type_and_comps(rb->Format, &datatype, &comps);
+
+            /* set span->array->rgba to colors for render buffer's datatype */
+            if (datatype != span->array->ChanType) {
+               convert_color_type(span, datatype, 0);
             }
             else {
-               span->array->rgba = (void *)
-                  span->array->attribs[FRAG_ATTRIB_COL0];
+               if (span->array->ChanType == GL_UNSIGNED_BYTE) {
+                  span->array->rgba = span->array->rgba8;
+               }
+               else {
+                  span->array->rgba = (void *)
+                     span->array->attribs[FRAG_ATTRIB_COL0];
+               }
             }
 
             if (!multiFragOutputs && numBuffers > 1) {
commit c34947dbb10f7211c351d02a3f64df284a40ee49
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Jan 31 09:00:48 2012 -0700

    mesa: Set the gl_array_object::ARBsemantics flag at the right time
    
    With 0963990 the flag was only set when Bind created the object.  In
    all cases where ::ARBsemantics could be true, this path never
    happened.  Instead, add a _Used flag to track whether a VAO has ever
    been bound.  On the first Bind, set the _Used flag, and set the
    ARBsemantics flag to the correct value.
    
    NOTE: This is a candidate for release branches.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45423
    (cherry picked from commit e06b1c65bc576a9b239841cbe3a8a8c2d6a8d09f)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index de1391f..04c403c 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -360,6 +360,10 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
             return;
          }
 
+         save_array_object(ctx, newObj);
+      }
+
+      if (!newObj->_Used) {
          /* The "Interactions with APPLE_vertex_array_object" section of the
           * GL_ARB_vertex_array_object spec says:
           *
@@ -367,7 +371,7 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
           *     BindVertexArrayAPPLE, determines the semantic of the object."
           */
          newObj->ARBsemantics = genRequired;
-         save_array_object(ctx, newObj);
+         newObj->_Used = GL_TRUE;
       }
    }
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 1d37008..bce5de2 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1627,6 +1627,11 @@ struct gl_array_object
     */
    GLboolean ARBsemantics;
 
+   /**
+    * Has this array object been bound?
+    */
+   GLboolean _Used;
+
    /** Vertex attribute arrays */
    struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX];
 
commit 9da7b58b39658f9d42777a4cb387bb668b28d491
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jan 18 11:56:12 2012 -0800

    mesa: Add unpack_uint_z_row support for floating-point depth buffers
    
    This is a hack, and it will result in incorrect rendering.  However,
    it does eliminate spurious warnings in several piglit CopyPixels tests
    that involve floating-point depth buffers.
    
    The real solution is to add a zf field to SWspan to store float Z
    values.  When a float depth buffer is involved, swrast should also
    populate the zf field.  I'll consider this post-8.0 work.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit af1477b088448aeca762f515410c80054cb225b9)

diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index ff98c69..be39873 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -2537,6 +2537,32 @@ unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
    memcpy(dst, src, n * sizeof(GLuint));
 }
 
+static void
+unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
+{
+   const float *s = (const float *)src;
+   GLuint i;
+   for (i = 0; i < n; i++) {
+      dst[i] = FLOAT_TO_UINT(IROUND(CLAMP((s[i]), 0.0F, 1.0F)));
+   }
+}
+
+static void
+unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
+{
+   struct z32f_x24s8 {
+      float z;
+      uint32_t x24s8;
+   };
+
+   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
+   GLuint i;
+
+   for (i = 0; i < n; i++) {
+      dst[i] = FLOAT_TO_UINT(IROUND(CLAMP((s[i].z), 0.0F, 1.0F)));
+   }
+}
+
 
 /**
  * Unpack Z values.
@@ -2564,6 +2590,12 @@ _mesa_unpack_uint_z_row(gl_format format, GLuint n,
    case MESA_FORMAT_Z32:
       unpack = unpack_uint_z_Z32;
       break;
+   case MESA_FORMAT_Z32_FLOAT:
+      unpack = unpack_uint_z_Z32_FLOAT;
+      break;
+   case MESA_FORMAT_Z32_FLOAT_X24S8:
+      unpack = unpack_uint_z_Z32_FLOAT_X24S8;
+      break;
    default:
       _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
                     _mesa_get_format_name(format));
commit 5ac4c8cf53de2f0ed228949a724f40eb108cfd00
Author: José Fonseca <jfonseca at vmware.com>
Date:   Thu Feb 2 10:44:10 2012 +0000

    mapi/glapi: Never use a generic no-op entry-point on Windows.
    
    When GLAPIENTRY is __stdcall (ie Windows), the stack is popped by the
    callee making the number/type of arguments significant, therefore
    using a generic no-op causes stack corruption for many entry-points.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>

diff --git a/src/mapi/glapi/glapi_nop.c b/src/mapi/glapi/glapi_nop.c
index 9b09297..69b1ae6 100644
--- a/src/mapi/glapi/glapi_nop.c
+++ b/src/mapi/glapi/glapi_nop.c
@@ -51,7 +51,11 @@ _glapi_set_warning_func(_glapi_proc func)
 {
 }
 
-#ifdef DEBUG
+/*
+ * When GLAPIENTRY is __stdcall (i.e. Windows), the stack is popped by the
+ * callee making the number/type of arguments significant.
+ */
+#if defined(_WIN32) || defined(DEBUG)
 
 /**
  * Called by each of the no-op GL entrypoints.
@@ -59,7 +63,7 @@ _glapi_set_warning_func(_glapi_proc func)
 static int
 Warn(const char *func)
 {
-#if !defined(_WIN32_WCE)
+#if defined(DEBUG) && !defined(_WIN32_WCE)
    if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) {
       fprintf(stderr, "GL User Error: gl%s called without a rendering context\n",
               func);
commit 7f5d3f7ed2ac42f00e4f848dd79b6223d95d7877
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Jan 20 16:08:01 2012 -0800

    meta: Fallback for glBlitFramebuffer from a multisample surface
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44818
    (cherry picked from commit b48d4b64e97f48dcf0aef1b6f7bc333c309cc183)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index 8cc7cf2..aa5fef8 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1451,7 +1451,12 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx,
    struct vertex verts[4];
    GLboolean newTex;
 
-   if (srcW > maxTexSize || srcH > maxTexSize) {
+   /* In addition to falling back if the blit size is larger than the maximum
+    * texture size, fallback if the source is multisampled.  This fallback can
+    * be removed once Mesa gets support ARB_texture_multisample.
+    */
+   if (srcW > maxTexSize || srcH > maxTexSize
+       || ctx->ReadBuffer->Visual.samples > 0) {
       /* XXX avoid this fallback */
       _swrast_BlitFramebuffer(ctx, srcX0, srcY0, srcX1, srcY1,
                               dstX0, dstY0, dstX1, dstY1, mask, filter);
commit 442dc31fa71ec433b2c100ec983a6061e83f7dbd
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 24 15:52:52 2012 -0800

    intel: Fix accum buffer mapping since the swrast rework.
    
    A pure swrast-allocated buffer gets an irb of NULL, so we segfaulted
    in the clear-accum test.  Just look at the swrast renderbuffer pointer
    for handling swrast rbs.
    (cherry picked from commit 42e9936ce6bcac9f863b2f85978489e4f804e927)
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45428

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 3a35a01..27b0bfc 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -128,15 +128,16 @@ intel_map_renderbuffer(struct gl_context *ctx,
 		       GLint *out_stride)
 {
    struct intel_context *intel = intel_context(ctx);
+   struct swrast_renderbuffer *srb = (struct swrast_renderbuffer *)rb;
    struct intel_renderbuffer *irb = intel_renderbuffer(rb);
    void *map;
    int stride;
 
-   if (!irb && irb->Base.Buffer) {
-      /* this is a malloc'd renderbuffer (accum buffer) */
+   if (srb->Buffer) {
+      /* this is a malloc'd renderbuffer (accum buffer), not an irb */
       GLint bpp = _mesa_get_format_bytes(rb->Format);
-      GLint rowStride = irb->Base.RowStride;
-      *out_map = (GLubyte *) irb->Base.Buffer + y * rowStride + x * bpp;
+      GLint rowStride = srb->RowStride;
+      *out_map = (GLubyte *) srb->Buffer + y * rowStride + x * bpp;
       *out_stride = rowStride;
       return;
    }
@@ -180,12 +181,13 @@ intel_unmap_renderbuffer(struct gl_context *ctx,
 			 struct gl_renderbuffer *rb)
 {
    struct intel_context *intel = intel_context(ctx);
+   struct swrast_renderbuffer *srb = (struct swrast_renderbuffer *)rb;
    struct intel_renderbuffer *irb = intel_renderbuffer(rb);
 
    DBG("%s: rb %d (%s)\n", __FUNCTION__,
        rb->Name, _mesa_get_format_name(rb->Format));
 
-   if (!irb && irb->Base.Buffer) {
+   if (srb->Buffer) {
       /* this is a malloc'd renderbuffer (accum buffer) */
       /* nothing to do */
       return;
commit 3ad7f44926483ffc99cc3b682415a55961d6abe3
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 31 07:44:53 2012 -0700

    osmesa: set RefCount = 1 in new_osmesa_renderbuffer()
    
    This was lost during the renderbuffer overhaul work.  Fixes a failed
    refcount assertion.
    (cherry picked from commit 3fc6e4e0254c0bfb643439952f2ceb55193010e7)

diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 0ec2d37..b767240 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -515,6 +515,7 @@ new_osmesa_renderbuffer(struct gl_context *ctx, GLenum format, GLenum type)
       _mesa_init_renderbuffer(&srb->Base, name);
 
       srb->Base.ClassID = OSMESA_RENDERBUFFER_CLASS;
+      srb->Base.RefCount = 1;
       srb->Base.Delete = osmesa_delete_renderbuffer;
       srb->Base.AllocStorage = osmesa_renderbuffer_storage;
 
commit 9f0088e906a5893f864724281919aeea71e5947f
Author: Vinson Lee <vlee at freedesktop.org>
Date:   Sat Jan 28 07:36:04 2012 +0100

    osmesa: Fix osmesa_context.DataType type.
    
    Fixes these GCC warnings.
    osmesa.c: In function ‘osmesa_renderbuffer_storage’:
    osmesa.c:417: warning: comparison is always false due to limited range of data type
    osmesa.c:423: warning: comparison is always false due to limited range of data type
    osmesa.c:431: warning: comparison is always false due to limited range of data type
    osmesa.c:437: warning: comparison is always false due to limited range of data type
    osmesa.c:447: warning: comparison is always false due to limited range of data type
    osmesa.c:453: warning: comparison is always false due to limited range of data type
    osmesa.c:463: warning: comparison is always false due to limited range of data type
    osmesa.c:466: warning: comparison is always false due to limited range of data type
    osmesa.c:476: warning: comparison is always false due to limited range of data type
    osmesa.c:479: warning: comparison is always false due to limited range of data type
    
    Signed-off-by: Vinson Lee <vlee at freedesktop.org>
    Signed-off-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 136791ebc1fb91ef20dc65722a34f093d2947849)

diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 0a42741..0ec2d37 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -75,7 +75,7 @@ struct osmesa_context
    GLvoid *rowaddr[MAX_HEIGHT];	/*< address of first pixel in each image row */
    GLboolean yup;		/*< TRUE  -> Y increases upward */
 				/*< FALSE -> Y increases downward */
-   GLboolean DataType;
+   GLenum DataType;
 };
 
 
commit f893fde63bb4d3f3802c950d2c8e0b4fc8129190
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 31 07:01:29 2012 -0700

    vega: memset data array to zero to silence uninitialized var warnings
    (cherry picked from commit 6386f80dbd6f1230abf16fa5ac65dc0dca70033a)

diff --git a/src/gallium/state_trackers/vega/path.c b/src/gallium/state_trackers/vega/path.c
index e62d1e3..43755f4 100644
--- a/src/gallium/state_trackers/vega/path.c
+++ b/src/gallium/state_trackers/vega/path.c
@@ -367,6 +367,8 @@ static struct polygon_array * path_get_fill_polygons(struct path *p, struct matr
    void *coords = (VGfloat *)p->control_points->data;
    struct array *array;
 
+   memset(data, 0, sizeof(data));
+
    if (p->fill_polys.polygon_array.array)
    {
       if (memcmp( &p->fill_polys.matrix,
commit 6bb4823f7de47d061467c3390119fe72d7a2e288
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 24 11:15:43 2012 -0700

    softpipe: move var initialization to silence warning
    (cherry picked from commit 3e01c3f3baee82524e23107aecb2de4c7ee8b978)

diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c b/src/gallium/drivers/softpipe/sp_state_derived.c
index 7b2b04e..b9b0f94 100644
--- a/src/gallium/drivers/softpipe/sp_state_derived.c
+++ b/src/gallium/drivers/softpipe/sp_state_derived.c
@@ -88,7 +88,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
       vinfo->num_attribs = 0;
       for (i = 0; i < fsInfo->num_inputs; i++) {
          int src;
-         enum interp_mode interp;
+         enum interp_mode interp = INTERP_LINEAR;
 
          switch (fsInfo->input_interpolate[i]) {
          case TGSI_INTERPOLATE_CONSTANT:
@@ -105,7 +105,6 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
             break;
          default:
             assert(0);
-            interp = INTERP_LINEAR;
          }
 
          switch (fsInfo->input_semantic_name[i]) {
commit ddd2503750c52c4725e1d083288287b9d8a78322
Author: Vinson Lee <vlee at freedesktop.org>
Date:   Mon Jan 16 13:02:03 2012 -0800

    softpipe: Silence unused variable warning on non-LLVM builds.
    
    Fix this GCC warning with non-LLVM builds.
    sp_screen.c: In function ‘softpipe_get_shader_param’:
    sp_screen.c:141:28: warning: unused variable ‘sp_screen’ [-Wunused-variable]
    
    Signed-off-by: Vinson Lee <vlee at freedesktop.org>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 8e543cc09862abb57e9d4dafe12e20a49972987b)

diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index f5ff68c..a044c2f 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -138,7 +138,9 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
 static int
 softpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param)
 {
+#ifdef HAVE_LLVM
    struct softpipe_screen *sp_screen = softpipe_screen(screen);
+#endif
    switch(shader)
    {
    case PIPE_SHADER_FRAGMENT:
commit 5f60d134e68775d00afca062eec42838e7888358
Author: Benjamin Franzke <benjaminfranzke at googlemail.com>
Date:   Sun Jan 29 17:28:50 2012 +0100

    st/dri: Support 24bit formats in dri2_allocate_buffer
    
    Prior commit 576161289df68eedade591fbca4013329c9e5ded,
    the parameter format was bpp, thus both 24bit and 32bit formats were
    requested with format set to 32. Handle 24bit seperately now.
    
    Fixes RGBX formats in wayland platform for egl_dri2 (EGL_ALPHA_SIZE=0).
    
    Note: This is a candidate for the 8.0 branch.
    (cherry picked from commit c72d7df16879e3210946ba92a7edc823815b6f16)

diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 2f7f1cb..b9930d3 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -316,6 +316,9 @@ dri2_allocate_buffer(__DRIscreen *sPriv,
 
    switch (format) {
       case 32:
+         pf = PIPE_FORMAT_B8G8R8A8_UNORM;
+         break;
+      case 24:
          pf = PIPE_FORMAT_B8G8R8X8_UNORM;
          break;
       case 16:
commit caebd7929dca802ece8ef36b0f85094d66133b57
Author: Christian König <deathsimple at vodafone.de>
Date:   Tue Jan 24 12:19:59 2012 +0100

    st/xvmc: remove xorg-server dependency
    
    Fixing a circular build dependency.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Christian König <deathsimple at vodafone.de>
    (cherry picked from commit c2e2b58a58880c9b9f189fc154205e99144e9502)

diff --git a/configure.ac b/configure.ac
index 1fcfdbc..ac6007a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1566,7 +1566,7 @@ if test "x$enable_gallium_g3dvl" = xyes; then
 fi
 
 if test "x$enable_xvmc" = xyes; then
-    PKG_CHECK_MODULES([XVMC], [xvmc >= 1.0.6 xorg-server])
+    PKG_CHECK_MODULES([XVMC], [xvmc >= 1.0.6])
     GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg/xvmc"
     HAVE_ST_XVMC="yes"
 fi
diff --git a/src/gallium/state_trackers/xorg/xvmc/subpicture.c b/src/gallium/state_trackers/xorg/xvmc/subpicture.c
index 1904429..c5aa0c3 100644
--- a/src/gallium/state_trackers/xorg/xvmc/subpicture.c
+++ b/src/gallium/state_trackers/xorg/xvmc/subpicture.c
@@ -29,7 +29,6 @@
 
 #include <X11/Xlibint.h>
 #include <X11/extensions/XvMClib.h>
-#include <xorg/fourcc.h>
 
 #include "pipe/p_screen.h"
 #include "pipe/p_video_decoder.h"
@@ -46,6 +45,8 @@
 #include "xvmc_private.h"
 
 #define FOURCC_RGB 0x0000003
+#define FOURCC_AI44 0x34344941
+#define FOURCC_IA44 0x34344149
 
 static enum pipe_format XvIDToPipe(int xvimage_id)
 {
commit 0dddf4c575c7d8398727b80b6475b01e9f2e0b22
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Jan 27 17:45:49 2012 -0800

    mesa: Bump version number to 8.0-rc2
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/Makefile b/Makefile
index 64e3a7cd..c1f7158 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ ultrix-gcc:
 
 # Rules for making release tarballs
 
-PACKAGE_VERSION=8.0-rc1
+PACKAGE_VERSION=8.0-rc2
 PACKAGE_DIR = Mesa-$(PACKAGE_VERSION)
 PACKAGE_NAME = MesaLib-$(PACKAGE_VERSION)
 
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index c1f4e8e..12844b1 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -35,7 +35,7 @@ struct gl_context;
 #define MESA_MAJOR 8
 #define MESA_MINOR 0
 #define MESA_PATCH 0
-#define MESA_VERSION_STRING "8.0-rc1"
+#define MESA_VERSION_STRING "8.0-rc2"
 
 /* To make version comparison easy */
 #define MESA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
commit 4aa158d09aab294845d33027dc1ef42056dec90a
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Jan 26 05:38:28 2012 -0800

    i965/vs: Use the sampler for VS pull constant loading on Ivybridge.
    
    Substantially increases performance in GLBenchmark PRO:
    - 320x240   => 3.28x
    - 1920x1080 => 1.47x
    - 2560x1440 => 1.27x
    
    The LD message ignores the sampler unit index and SAMPLER_STATE pointer,
    instead relying on hard-wired default state.  Thus, there's no need to
    worry about running out of sampler units or providing SAMPLER_STATE;
    this small patch should be all that's required.
    
    NOTE: This is a candidate for release branches.
          (It requires the preceding commit to compile.)
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 259b65e2e7938de4aab323033cfe2b33369ddb07)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
index dbe4dd0..917c927 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
@@ -647,6 +647,23 @@ vec4_visitor::generate_pull_constant_load(vec4_instruction *inst,
 					  struct brw_reg dst,
 					  struct brw_reg index)
 {
+   if (intel->gen == 7) {
+      gen6_resolve_implied_move(p, &index, inst->base_mrf);
+      brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
+      brw_set_dest(p, insn, dst);
+      brw_set_src0(p, insn, index);
+      brw_set_sampler_message(p, insn,
+                              SURF_INDEX_VERT_CONST_BUFFER,
+                              0, /* LD message ignores sampler unit */
+                              GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
+                              1, /* rlen */
+                              1, /* mlen */
+                              false, /* no header */
+                              BRW_SAMPLER_SIMD_MODE_SIMD4X2,
+                              0);
+      return;
+   }
+
    struct brw_reg header = brw_vec8_grf(0, 0);
 
    gen6_resolve_implied_move(p, &header, inst->base_mrf);
commit 38b76cf8319168c3628cc18c6231e9a081a2481b
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Jan 26 05:33:19 2012 -0800

    i965: Expose brw_set_sampler_message for use outside brw_eu_emit.c.
    
    brw_SAMPLE is full of complex workarounds for original Broadwater
    hardware, and I'd rather avoid all that for my next Ivybridge patch.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 5f4575d42fdaaf671d4b3cdcf2c733ad9d35d339)

diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h
index d967d93..f660222 100644
--- a/src/mesa/drivers/dri/i965/brw_eu.h
+++ b/src/mesa/drivers/dri/i965/brw_eu.h
@@ -887,6 +887,17 @@ ROUND(RNDE)
 
 /* Helpers for SEND instruction:
  */
+void brw_set_sampler_message(struct brw_compile *p,
+                             struct brw_instruction *insn,
+                             GLuint binding_table_index,
+                             GLuint sampler,
+                             GLuint msg_type,
+                             GLuint response_length,
+                             GLuint msg_length,
+                             GLuint header_present,
+                             GLuint simd_mode,
+                             GLuint return_format);
+
 void brw_set_dp_read_message(struct brw_compile *p,
 			     struct brw_instruction *insn,
 			     GLuint binding_table_index,
diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c
index d8ea06f..9929739 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c
@@ -653,16 +653,17 @@ brw_set_dp_read_message(struct brw_compile *p,
    }
 }
 
-static void brw_set_sampler_message(struct brw_compile *p,
-                                    struct brw_instruction *insn,
-                                    GLuint binding_table_index,
-                                    GLuint sampler,
-                                    GLuint msg_type,
-                                    GLuint response_length,
-                                    GLuint msg_length,
-                                    GLuint header_present,
-                                    GLuint simd_mode,
-				    GLuint return_format)
+void
+brw_set_sampler_message(struct brw_compile *p,
+                        struct brw_instruction *insn,
+                        GLuint binding_table_index,
+                        GLuint sampler,
+                        GLuint msg_type,
+                        GLuint response_length,
+                        GLuint msg_length,
+                        GLuint header_present,
+                        GLuint simd_mode,
+                        GLuint return_format)
 {
    struct brw_context *brw = p->brw;
    struct intel_context *intel = &brw->intel;
commit 73ff415b596ea0449bd79b2a076987678fcefebd
Author: Paul Berry <stereotype441 at gmail.com>
Date:   Mon Jan 9 15:36:27 2012 -0800

    i965: Set pitch of pull constant buffers to 16.
    
    We always access pull constant buffers using the message types "OWord
    Block Read" or "OWord Dual Block Read".  According to the Sandy Bridge
    PRM, Vol 4 Part 1, pages 214 and 218, when using these messages:
    
        "the surface pitch is ignored, the surface is treated as a
        1-dimensional surface.  An element size (pitch) of 16 bytes is
        used to determine the size of the buffer for out-of-bounds
        checking if using the surface state model."
    
    Previously we were setting the pitch for pull constant buffers to the
    size of the whole constant buffer--this made no sense and would have
    led to incorrect behavior if it were not for the fact that the pitch
    is ignored.
    
    For clarity, this patch sets the pitch for pull constant buffers to 16
    bytes, consistent with the hardware's behavior.
    
    v2: Clarify the meaning of the ignored values by writing them as (16 - 1).
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit fcd5af4a916b4ba7860ba27eb47404934bde0d08)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index 62214d1..7fd83ea 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -703,7 +703,7 @@ brw_create_constant_surface(struct brw_context *brw,
 	      ((w >> 7) & 0x1fff) << BRW_SURFACE_HEIGHT_SHIFT);
 
    surf[3] = (((w >> 20) & 0x7f) << BRW_SURFACE_DEPTH_SHIFT |
-	      (width * 16 - 1) << BRW_SURFACE_PITCH_SHIFT);
+	      (16 - 1) << BRW_SURFACE_PITCH_SHIFT); /* ignored */
 
    surf[4] = 0;
    surf[5] = 0;
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index adc3a45..d429adc 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -157,7 +157,7 @@ gen7_create_constant_surface(struct brw_context *brw,
    surf->ss2.width = w & 0x7f;            /* bits 6:0 of size or width */
    surf->ss2.height = (w >> 7) & 0x1fff;  /* bits 19:7 of size or width */
    surf->ss3.depth = (w >> 20) & 0x7f;    /* bits 26:20 of size or width */
-   surf->ss3.pitch = (width * 16) - 1; /* ignored?? */
+   surf->ss3.pitch = (16 - 1); /* ignored */
    gen7_set_surface_tiling(surf, I915_TILING_NONE); /* tiling now allowed */
 
    /* Emit relocation to surface contents.  Section 5.1.1 of the gen4
commit 58e0c4f87272bfae09f522c8a1cfce112a04a3b2
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Jan 20 17:23:02 2012 -0800

    mesa: Don't resurrect deleted ARB VAOs in glPopClientAttrib
    
    When ARB VAOs are used, glPopClientAttrib does not resurrect a deleted
    VAO or VBO.  This difference between the two spec is, unfortunately,
    not very well spelled out in the specs.
    
    Fixes oglc vao(advanced.pushPop.deleteVAO) and
    vao(advanced.pushPop.deleteVBO) tests.
    
    NOTE: This is a candidate for release branches.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 34c353ce463960afdf64fa2be1f155b8b7f6c70c)

diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 1cd1fc4..01e7945 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -58,6 +58,8 @@
 #include "viewport.h"
 #include "mtypes.h"
 #include "main/dispatch.h"
+#include "hash.h"
+#include <stdbool.h>
 
 
 /**
@@ -1337,7 +1339,8 @@ copy_array_object(struct gl_context *ctx,
 static void
 copy_array_attrib(struct gl_context *ctx,
                   struct gl_array_attrib *dest,
-                  struct gl_array_attrib *src)
+                  struct gl_array_attrib *src,
+                  bool vbo_deleted)
 {
    /* skip ArrayObj */
    /* skip DefaultArrayObj, Objects */
@@ -1349,7 +1352,8 @@ copy_array_attrib(struct gl_context *ctx,
    /* skip NewState */
    /* skip RebindArrays */
 
-   copy_array_object(ctx, dest->ArrayObj, src->ArrayObj);
+   if (!vbo_deleted)
+      copy_array_object(ctx, dest->ArrayObj, src->ArrayObj);
 
    /* skip ArrayBufferObj */
    /* skip ElementArrayBufferObj */
@@ -1367,7 +1371,7 @@ save_array_attrib(struct gl_context *ctx,
     * Needs to match value in the object hash. */
    dest->ArrayObj->Name = src->ArrayObj->Name;
    /* And copy all of the rest. */
-   copy_array_attrib(ctx, dest, src);
+   copy_array_attrib(ctx, dest, src, false);
 
    /* Just reference them here */
    _mesa_reference_buffer_object(ctx, &dest->ArrayBufferObj,
@@ -1384,17 +1388,44 @@ restore_array_attrib(struct gl_context *ctx,
                      struct gl_array_attrib *dest,
                      struct gl_array_attrib *src)
 {
-   /* Restore or recreate the array object by its name ... */
-   _mesa_BindVertexArrayAPPLE(src->ArrayObj->Name);
+   /* The ARB_vertex_array_object spec says:
+    *
+    *     "BindVertexArray fails and an INVALID_OPERATION error is generated
+    *     if array is not a name returned from a previous call to
+    *     GenVertexArrays, or if such a name has since been deleted with
+    *     DeleteVertexArrays."
+    *
+    * Therefore popping a deleted VAO cannot magically recreate it.
+    *
+    * The semantics of objects created using APPLE_vertex_array_objects behave
+    * differently.  These objects expect to be recreated by pop.  Alas.
+    */
+   const bool arb_vao = (src->ArrayObj->Name != 0
+			 && src->ArrayObj->ARBsemantics);
+
+   if (arb_vao && !_mesa_IsVertexArrayAPPLE(src->ArrayObj->Name))
+      return;
 
-   /* ... and restore its content */
-   copy_array_attrib(ctx, dest, src);
+   _mesa_BindVertexArrayAPPLE(src->ArrayObj->Name);
 
    /* Restore or recreate the buffer objects by the names ... */
-   _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB,
-                       src->ArrayBufferObj->Name);
-   _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
-                       src->ArrayObj->ElementArrayBufferObj->Name);
+   if (!arb_vao
+       || src->ArrayBufferObj->Name == 0
+       || _mesa_IsBufferARB(src->ArrayBufferObj->Name)) {
+      /* ... and restore its content */
+      copy_array_attrib(ctx, dest, src, false);
+
+      _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB,
+			  src->ArrayBufferObj->Name);
+   } else {
+      copy_array_attrib(ctx, dest, src, true);
+   }
+
+   if (!arb_vao
+       || src->ArrayObj->ElementArrayBufferObj->Name == 0
+       || _mesa_IsBufferARB(src->ArrayObj->ElementArrayBufferObj->Name))
+      _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
+			  src->ArrayObj->ElementArrayBufferObj->Name);
 
    /* Better safe than sorry?! */
    dest->RebindArrays = GL_TRUE;
commit eea63b7621740ad020b9a2448f9c2f809f4827f3
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Jan 23 14:22:38 2012 -0800

    mesa: Rename gl_array_object::VBOonly to ::ARBsemantics
    
    There are more differences between Apple and ARB than just requiring
    that all arrays be stored in VBOs.  Additional uses will be added in
    following commits.
    
    Also, set the flag at Bind time instead of Gen time.  The ARB_vao spec
    specifies that behavior.
    
    NOTE: This is a candidate for release branches.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 09639901530da7df7347428512c2bee86af1ef8e)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index 4b3e07b..de1391f 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -359,6 +359,14 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindVertexArrayAPPLE");
             return;
          }
+
+         /* The "Interactions with APPLE_vertex_array_object" section of the
+          * GL_ARB_vertex_array_object spec says:
+          *
+          *     "The first bind call, either BindVertexArray or
+          *     BindVertexArrayAPPLE, determines the semantic of the object."
+          */
+         newObj->ARBsemantics = genRequired;
          save_array_object(ctx, newObj);
       }
    }
@@ -455,8 +463,7 @@ _mesa_DeleteVertexArraysAPPLE(GLsizei n, const GLuint *ids)
  * \param vboOnly Will arrays have to reside in VBOs?
  */
 static void 
-gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
-                  GLboolean vboOnly)
+gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays)
 {
    GLuint first;
    GLint i;
@@ -483,7 +490,6 @@ gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenVertexArraysAPPLE");
          return;
       }
-      obj->VBOonly = vboOnly;
       save_array_object(ctx, obj);
       arrays[i] = first + i;
    }
@@ -498,7 +504,7 @@ void GLAPIENTRY
 _mesa_GenVertexArrays(GLsizei n, GLuint *arrays)
 {
    GET_CURRENT_CONTEXT(ctx);
-   gen_vertex_arrays(ctx, n, arrays, GL_TRUE);
+   gen_vertex_arrays(ctx, n, arrays);
 }
 
 
@@ -510,7 +516,7 @@ void GLAPIENTRY
 _mesa_GenVertexArraysAPPLE(GLsizei n, GLuint *arrays)
 {
    GET_CURRENT_CONTEXT(ctx);
-   gen_vertex_arrays(ctx, n, arrays, GL_FALSE);
+   gen_vertex_arrays(ctx, n, arrays);
 }
 
 
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 1c1ee5d..1cd1fc4 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -1320,7 +1320,7 @@ copy_array_object(struct gl_context *ctx,
    /* skip RefCount */
 
    /* In theory must be the same anyway, but on recreate make sure it matches */
-   dest->VBOonly = src->VBOonly;
+   dest->ARBsemantics = src->ARBsemantics;
 
    for (i = 0; i < Elements(src->VertexAttrib); i++)
       _mesa_copy_client_array(ctx, &dest->VertexAttrib[i], &src->VertexAttrib[i]);
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 30c5475..1d37008 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1610,7 +1610,22 @@ struct gl_array_object
 
    GLint RefCount;
    _glthread_Mutex Mutex;
-   GLboolean VBOonly;  /**< require all arrays to live in VBOs? */
+
+   /**
+    * Does the VAO use ARB semantics or Apple semantics?
+    *
+    * There are several ways in which ARB_vertex_array_object and
+    * APPLE_vertex_array_object VAOs have differing semantics.  At the very
+    * least,
+    *
+    *     - ARB VAOs require that all array data be sourced from vertex buffer
+    *       objects, but Apple VAOs do not.
+    *
+    *     - ARB VAOs require that names come from GenVertexArrays.
+    *
+    * This flag notes which behavior governs this VAO.
+    */
+   GLboolean ARBsemantics;
 
    /** Vertex attribute arrays */
    struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX];
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 9078d11..77c1d7d 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -194,7 +194,7 @@ update_array(struct gl_context *ctx,
       return;
    }
 
-   if (ctx->Array.ArrayObj->VBOonly &&
+   if (ctx->Array.ArrayObj->ARBsemantics &&
        !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
       /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
        * Generate GL_INVALID_OPERATION if that's not true.
commit 85a52bf7b5f5f0317d15a51f94f294fc5e72d936
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Jan 19 17:29:37 2012 -0800

    swrast: Use fixed-function processing instead _TexEnvProgram for DrawPixels
    
    This is a hack to work around drivers such as i965 that:
    
        - Set _MaintainTexEnvProgram to generate GLSL IR for
          fixed-function fragment processing.
        - Don't call _mesa_ir_link_shader to generate Mesa IR from the
          GLSL IR.
        - May use swrast to handle glDrawPixels.
    
    Since _mesa_ir_link_shader is never called, there is no Mesa IR to
    execute.  Instead do regular fixed-function processing.
    
    Even on platforms that don't need this, the software fixed-function
    code is much faster than the software shader code.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44749
    (cherry picked from commit 9be3be3c6654da18466626c2d45ff4d06b5fb953)

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 8ecc3f9..7ab60b1 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -52,6 +52,7 @@
 #include "s_stencil.h"
 #include "s_texcombine.h"
 
+#include <stdbool.h>
 
 /**
  * Set default fragment attributes for the span using the
@@ -970,7 +971,25 @@ convert_color_type(SWspan *span, GLenum newType, GLuint output)
 static inline void
 shade_texture_span(struct gl_context *ctx, SWspan *span)
 {
-   if (ctx->FragmentProgram._Current ||
+   /* This is a hack to work around drivers such as i965 that:
+    *
+    *     - Set _MaintainTexEnvProgram to generate GLSL IR for
+    *       fixed-function fragment processing.
+    *     - Don't call _mesa_ir_link_shader to generate Mesa IR from
+    *       the GLSL IR.
+    *     - May use swrast to handle glDrawPixels.
+    *
+    * Since _mesa_ir_link_shader is never called, there is no Mesa IR
+    * to execute.  Instead do regular fixed-function processing.
+    *
+    * It is also worth noting that the software fixed-function path is
+    * much faster than the software shader path.
+    */
+   const bool use_fragment_program =
+      ctx->FragmentProgram._Current
+      && ctx->FragmentProgram._Current != ctx->FragmentProgram._TexEnvProgram;
+
+   if (use_fragment_program ||
        ctx->ATIFragmentShader._Enabled) {
       /* programmable shading */
       if (span->primitive == GL_BITMAP && span->array->ChanType != GL_FLOAT) {
@@ -999,7 +1018,7 @@ shade_texture_span(struct gl_context *ctx, SWspan *span)
          interpolate_wpos(ctx, span);
 
       /* Run fragment program/shader now */
-      if (ctx->FragmentProgram._Current) {
+      if (use_fragment_program) {
          _swrast_exec_fragment_program(ctx, span);
       }
       else {
commit 05b7f13af191e6fdf640e97017b073684550159b
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Jan 19 17:23:51 2012 -0800

    mesa: Make sure _TexEnvProgram points at the current ff fragment program
    
    At least one place, the _mesa_need_secondary_color function in
    state.h, uses this to make decisions.  The next patch in this series
    will add another dependency.  Ideally, this field would go away and be
    replace by a flag or something.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 34db7a8c1e775aaefad7952133e087f1c1a569f6)

diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index b910543..c59eff7 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -259,6 +259,8 @@ update_program(struct gl_context *ctx)
       _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
 			       (struct gl_fragment_program *)
 			       fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
+      _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
+			       NULL);
    }
    else if (ctx->FragmentProgram._Enabled) {
       /* Use user-defined fragment program */
@@ -267,6 +269,8 @@ update_program(struct gl_context *ctx)
 				     NULL);
       _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
                                ctx->FragmentProgram.Current);
+      _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
+			       NULL);
    }
    else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
       /* Use fragment program generated from fixed-function state */
@@ -278,10 +282,15 @@ update_program(struct gl_context *ctx)
       _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
 			       (struct gl_fragment_program *)
                                f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
+      _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
+			       (struct gl_fragment_program *)
+                               f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
    }
    else {
       /* No fragment program */
       _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
+      _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
+			       NULL);
    }
 
    if (gsProg && gsProg->LinkStatus
commit 93d5799e8bf8bb67d985d59cccf1063dedd3cedd
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 24 13:32:13 2012 -0700

    swrast: fix uninitialized variable warning
    (cherry picked from commit ba151a333be7a23266b23ee6f65669bb19221546)

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 819fe4b..8ecc3f9 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1084,7 +1084,7 @@ _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
       /* We can't pass a 'mask' array to the _mesa_pack_rgba_row() functions
        * so look for runs where mask=1...
        */
-      runLen = 0;
+      runLen = runStart = 0;
       for (i = 0; i < count; i++) {
          if (mask[i]) {
             if (runLen == 0)
commit 4f8b00d8effc9b1494e644cb3e15d8519083a8cf
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 24 13:29:05 2012 -0700

    swrast: make rowStride variable signed in put_z32_values()
    
    As with commit aed5c8299fe47b8e1728f8140d069bc89d3fa947
    (cherry picked from commit cf386f0a2ba3efcfd6ddbfcbebaf98a9bfa7a29f)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 1336407..c903882 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -253,7 +253,7 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
-      const GLuint rowStride = srb->RowStride;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             GLuint *dst = (GLuint *) (map + y[i] * rowStride + x[i] * 4);
commit b5a5a1c6153d9a6ef16f60b391fe0181305d9c96
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 18 17:47:32 2012 -0700

    intel: use swrast code to map/unmap renderbuffers for swrast rendering
    (cherry picked from commit 89bb19adb08caaefc01e613e9bbfbdd1f366ddab)

diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 2090e51..3645720 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -110,77 +110,6 @@ intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y)
    return u;
 }
 
-static void
-intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
-{
-   struct gl_context *ctx = &intel->ctx;
-   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
-   GLubyte *map;
-   int stride;
-
-   if (!irb)
-      return;
-
-   if (irb->Base.Map) {
-      /* Renderbuffer is already mapped. This usually happens when a single
-       * buffer is attached to the framebuffer's depth and stencil attachment
-       * points.
-       */
-      return;
-   }
-
-   ctx->Driver.MapRenderbuffer(ctx, rb, 0, 0, rb->Width, rb->Height,
-			       GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
-			       &map, &stride);
-   irb->Base.Map = map;
-   irb->Base.RowStride = stride;
-}
-
-static void
-intel_renderbuffer_unmap(struct intel_context *intel,
-			 struct gl_renderbuffer *rb)
-{
-   struct gl_context *ctx = &intel->ctx;
-   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
-
-   if (!irb)
-      return;
-
-   if (!irb->Base.Map) {
-      /* Renderbuffer is already unmapped. This usually happens when a single
-       * buffer is attached to the framebuffer's depth and stencil attachment
-       * points.
-       */
-      return;
-   }
-
-   ctx->Driver.UnmapRenderbuffer(ctx, rb);
-
-   irb->Base.Map = NULL;
-   irb->Base.RowStride = 0;
-}
-
-static void
-intel_framebuffer_map(struct intel_context *intel, struct gl_framebuffer *fb)
-{
-   int i;
-
-   for (i = 0; i < BUFFER_COUNT; i++) {
-      intel_renderbuffer_map(intel, fb->Attachment[i].Renderbuffer);
-   }
-
-   intel_check_front_buffer_rendering(intel);
-}
-
-static void
-intel_framebuffer_unmap(struct intel_context *intel, struct gl_framebuffer *fb)
-{
-   int i;
-
-   for (i = 0; i < BUFFER_COUNT; i++) {
-      intel_renderbuffer_unmap(intel, fb->Attachment[i].Renderbuffer);
-   }
-}
 
 /**
  * Resolve all buffers that will be mapped by intelSpanRenderStart().
@@ -236,10 +165,7 @@ intel_span_map_buffers(struct intel_context *intel)
 			   GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
    }
 
-   intel_framebuffer_map(intel, ctx->DrawBuffer);
-   if (ctx->ReadBuffer != ctx->DrawBuffer) {
-      intel_framebuffer_map(intel, ctx->ReadBuffer);
-   }
+   _swrast_map_renderbuffers(ctx);
 }
 
 /**
@@ -279,10 +205,7 @@ intelSpanRenderFinish(struct gl_context * ctx)
       }
    }
 
-   intel_framebuffer_unmap(intel, ctx->DrawBuffer);
-   if (ctx->ReadBuffer != ctx->DrawBuffer) {
-      intel_framebuffer_unmap(intel, ctx->ReadBuffer);
-   }
+   _swrast_unmap_renderbuffers(ctx);
 }
 
 
commit 4d72e190c0c6b6d5988ca523018e31075e2fd832
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 18 17:39:33 2012 -0700

    mesa: update comments, fix whitespace in dd.h
    (cherry picked from commit 4baf90353dee771e553c552674616b93aedeaecf)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 0641e3b..9631113 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -398,18 +398,16 @@ struct dd_function_table {
                                    GLenum format,
                                    GLsizei imageSize, const GLvoid *data);
 
-
    /**
     * Called by glGetCompressedTexImage.
     */
    void (*GetCompressedTexImage)(struct gl_context *ctx,
                                  struct gl_texture_image *texImage,
                                  GLvoid *data);
-
    /*@}*/
 
    /**
-    * \name Texture object functions
+    * \name Texture object / image functions
     */
    /*@{*/
 
@@ -420,24 +418,20 @@ struct dd_function_table {
                         struct gl_texture_object *tObj );
 
    /**
-    * Called to allocate a new texture object.
-    * A new gl_texture_object should be returned.  The driver should
-    * attach to it any device-specific info it needs.
+    * Called to allocate a new texture object.  Drivers will usually
+    * allocate/return a subclass of gl_texture_object.
     */
-   struct gl_texture_object * (*NewTextureObject)( struct gl_context *ctx, GLuint name,
-                                                   GLenum target );
+   struct gl_texture_object * (*NewTextureObject)(struct gl_context *ctx,
+                                                  GLuint name, GLenum target);
    /**
-    * Called when a texture object is about to be deallocated.  
-    *
-    * Driver should delete the gl_texture_object object and anything
-    * hanging off of it.
+    * Called to delete/free a texture object.  Drivers should free the
+    * object and any image data it contains.
     */
-   void (*DeleteTexture)( struct gl_context *ctx, struct gl_texture_object *tObj );
+   void (*DeleteTexture)(struct gl_context *ctx,
+                         struct gl_texture_object *texObj);
 
-   /**
-    * Called to allocate a new texture image object.
-    */
-   struct gl_texture_image * (*NewTextureImage)( struct gl_context *ctx );
+   /** Called to allocate a new texture image object. */
+   struct gl_texture_image * (*NewTextureImage)(struct gl_context *ctx);
 
    /** Called to free a texture image object returned by NewTextureImage() */
    void (*DeleteTextureImage)(struct gl_context *ctx,
@@ -449,10 +443,9 @@ struct dd_function_table {
                                         gl_format format, GLsizei width,
                                         GLsizei height, GLsizei depth);
 
-   /** 
-    * Called to free tImage->Data.
-    */
-   void (*FreeTextureImageBuffer)( struct gl_context *ctx, struct gl_texture_image *tImage );
+   /** Free the memory for a single texture image */
+   void (*FreeTextureImageBuffer)(struct gl_context *ctx,
+                                  struct gl_texture_image *texImage);
 
    /** Map a slice of a texture image into user space.
     * Note: for GL_TEXTURE_1D_ARRAY, height must be 1, y must be 0 and slice
commit e442906c87ff7e42f1c2a2ea3d408929bd2552e1
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 18 17:39:33 2012 -0700

    swrast: remove unused StoreTexel code
    
    No longer needed since we do all rendering to texture with the buffer
    mapping and pixel packing functions.
    (cherry picked from commit 9403cc3aba0769dc6925cea3ec20aa95d491f516)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 2fb61ea..ae239a9 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -120,14 +120,10 @@ typedef void (*FetchTexelFunc)(const struct swrast_texture_image *texImage,
                                GLfloat *texelOut);
 
 
-typedef void (*StoreTexelFunc)(struct swrast_texture_image *texImage,
-                               GLint col, GLint row, GLint img,
-                               const void *texel);
-
 /**
  * Subclass of gl_texture_image.
  * We need extra fields/info to keep tracking of mapped texture buffers,
- * strides and Fetch/Store functions.
+ * strides and Fetch functions.
  */
 struct swrast_texture_image
 {
@@ -148,7 +144,6 @@ struct swrast_texture_image
    GLubyte *Buffer;
 
    FetchTexelFunc FetchTexel;
-   StoreTexelFunc Store;
 };
 
 
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index 7cb6e68..8529ff0 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -103,18 +103,6 @@ static void fetch_null_texelf( const struct swrast_texture_image *texImage,
    _mesa_warning(NULL, "fetch_null_texelf() called!");
 }
 
-static void store_null_texel(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   (void) texImage;
-   (void) i;
-   (void) j;
-   (void) k;
-   (void) texel;
-   /* no-op */
-}
-
-
 
 /**
  * Table to map MESA_FORMAT_ to texel fetch/store funcs.
@@ -125,7 +113,6 @@ static struct {
    FetchTexelFunc Fetch1D;
    FetchTexelFunc Fetch2D;
    FetchTexelFunc Fetch3D;
-   StoreTexelFunc StoreTexel;
 }
 texfetch_funcs[MESA_FORMAT_COUNT] =
 {
@@ -133,386 +120,331 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_NONE,
       fetch_null_texelf,
       fetch_null_texelf,
-      fetch_null_texelf,
-      store_null_texel
+      fetch_null_texelf
    },
 
    {
       MESA_FORMAT_RGBA8888,
       fetch_texel_1d_f_rgba8888,
       fetch_texel_2d_f_rgba8888,
-      fetch_texel_3d_f_rgba8888,
-      store_texel_rgba8888
+      fetch_texel_3d_f_rgba8888
    },
    {
       MESA_FORMAT_RGBA8888_REV,
       fetch_texel_1d_f_rgba8888_rev,
       fetch_texel_2d_f_rgba8888_rev,
-      fetch_texel_3d_f_rgba8888_rev,
-      store_texel_rgba8888_rev
+      fetch_texel_3d_f_rgba8888_rev
    },
    {
       MESA_FORMAT_ARGB8888,
       fetch_texel_1d_f_argb8888,
       fetch_texel_2d_f_argb8888,
-      fetch_texel_3d_f_argb8888,
-      store_texel_argb8888
+      fetch_texel_3d_f_argb8888
    },
    {
       MESA_FORMAT_ARGB8888_REV,
       fetch_texel_1d_f_argb8888_rev,
       fetch_texel_2d_f_argb8888_rev,
-      fetch_texel_3d_f_argb8888_rev,
-      store_texel_argb8888_rev
+      fetch_texel_3d_f_argb8888_rev
    },
    {
       MESA_FORMAT_RGBX8888,
       fetch_texel_1d_f_rgbx8888,
       fetch_texel_2d_f_rgbx8888,
-      fetch_texel_3d_f_rgbx8888,
-      store_texel_rgbx8888
+      fetch_texel_3d_f_rgbx8888
    },
    {
       MESA_FORMAT_RGBX8888_REV,
       fetch_texel_1d_f_rgbx8888_rev,
       fetch_texel_2d_f_rgbx8888_rev,
-      fetch_texel_3d_f_rgbx8888_rev,
-      store_texel_rgbx8888_rev,
+      fetch_texel_3d_f_rgbx8888_rev
    },
    {
       MESA_FORMAT_XRGB8888,
       fetch_texel_1d_f_xrgb8888,
       fetch_texel_2d_f_xrgb8888,
-      fetch_texel_3d_f_xrgb8888,
-      store_texel_xrgb8888
+      fetch_texel_3d_f_xrgb8888
    },
    {
       MESA_FORMAT_XRGB8888_REV,
       fetch_texel_1d_f_xrgb8888_rev,
       fetch_texel_2d_f_xrgb8888_rev,
-      fetch_texel_3d_f_xrgb8888_rev,
-      store_texel_xrgb8888_rev,
+      fetch_texel_3d_f_xrgb8888_rev
    },
    {
       MESA_FORMAT_RGB888,
       fetch_texel_1d_f_rgb888,
       fetch_texel_2d_f_rgb888,
-      fetch_texel_3d_f_rgb888,
-      store_texel_rgb888
+      fetch_texel_3d_f_rgb888
    },
    {
       MESA_FORMAT_BGR888,
       fetch_texel_1d_f_bgr888,
       fetch_texel_2d_f_bgr888,
-      fetch_texel_3d_f_bgr888,
-      store_texel_bgr888
+      fetch_texel_3d_f_bgr888
    },
    {
       MESA_FORMAT_RGB565,
       fetch_texel_1d_f_rgb565,
       fetch_texel_2d_f_rgb565,
-      fetch_texel_3d_f_rgb565,
-      store_texel_rgb565
+      fetch_texel_3d_f_rgb565
    },
    {
       MESA_FORMAT_RGB565_REV,
       fetch_texel_1d_f_rgb565_rev,
       fetch_texel_2d_f_rgb565_rev,
-      fetch_texel_3d_f_rgb565_rev,
-      store_texel_rgb565_rev
+      fetch_texel_3d_f_rgb565_rev
    },
    {
       MESA_FORMAT_ARGB4444,
       fetch_texel_1d_f_argb4444,
       fetch_texel_2d_f_argb4444,
-      fetch_texel_3d_f_argb4444,
-      store_texel_argb4444
+      fetch_texel_3d_f_argb4444
    },
    {
       MESA_FORMAT_ARGB4444_REV,
       fetch_texel_1d_f_argb4444_rev,
       fetch_texel_2d_f_argb4444_rev,
-      fetch_texel_3d_f_argb4444_rev,
-      store_texel_argb4444_rev
+      fetch_texel_3d_f_argb4444_rev
    },
    {
       MESA_FORMAT_RGBA5551,
       fetch_texel_1d_f_rgba5551,
       fetch_texel_2d_f_rgba5551,
-      fetch_texel_3d_f_rgba5551,
-      store_texel_rgba5551
+      fetch_texel_3d_f_rgba5551
    },
    {
       MESA_FORMAT_ARGB1555,
       fetch_texel_1d_f_argb1555,
       fetch_texel_2d_f_argb1555,
-      fetch_texel_3d_f_argb1555,
-      store_texel_argb1555
+      fetch_texel_3d_f_argb1555
    },
    {
       MESA_FORMAT_ARGB1555_REV,
       fetch_texel_1d_f_argb1555_rev,
       fetch_texel_2d_f_argb1555_rev,
-      fetch_texel_3d_f_argb1555_rev,
-      store_texel_argb1555_rev
+      fetch_texel_3d_f_argb1555_rev
    },
    {
       MESA_FORMAT_AL44,
       fetch_texel_1d_f_al44,
       fetch_texel_2d_f_al44,
-      fetch_texel_3d_f_al44,
-      store_texel_al44
+      fetch_texel_3d_f_al44
    },
    {
       MESA_FORMAT_AL88,
       fetch_texel_1d_f_al88,
       fetch_texel_2d_f_al88,
-      fetch_texel_3d_f_al88,
-      store_texel_al88
+      fetch_texel_3d_f_al88
    },
    {
       MESA_FORMAT_AL88_REV,
       fetch_texel_1d_f_al88_rev,
       fetch_texel_2d_f_al88_rev,
-      fetch_texel_3d_f_al88_rev,
-      store_texel_al88_rev
+      fetch_texel_3d_f_al88_rev
    },
    {
       MESA_FORMAT_AL1616,
       fetch_texel_1d_f_al1616,
       fetch_texel_2d_f_al1616,
-      fetch_texel_3d_f_al1616,
-      store_texel_al1616
+      fetch_texel_3d_f_al1616
    },
    {
       MESA_FORMAT_AL1616_REV,
       fetch_texel_1d_f_al1616_rev,
       fetch_texel_2d_f_al1616_rev,
-      fetch_texel_3d_f_al1616_rev,
-      store_texel_al1616_rev
+      fetch_texel_3d_f_al1616_rev
    },
    {
       MESA_FORMAT_RGB332,
       fetch_texel_1d_f_rgb332,
       fetch_texel_2d_f_rgb332,
-      fetch_texel_3d_f_rgb332,
-      store_texel_rgb332
+      fetch_texel_3d_f_rgb332
    },
    {
       MESA_FORMAT_A8,
       fetch_texel_1d_f_a8,
       fetch_texel_2d_f_a8,
-      fetch_texel_3d_f_a8,
-      store_texel_a8
+      fetch_texel_3d_f_a8
    },
    {
       MESA_FORMAT_A16,
       fetch_texel_1d_f_a16,
       fetch_texel_2d_f_a16,
-      fetch_texel_3d_f_a16,
-      store_texel_a16
+      fetch_texel_3d_f_a16
    },
    {
       MESA_FORMAT_L8,
       fetch_texel_1d_f_l8,
       fetch_texel_2d_f_l8,
-      fetch_texel_3d_f_l8,
-      store_texel_l8
+      fetch_texel_3d_f_l8
    },
    {
       MESA_FORMAT_L16,
       fetch_texel_1d_f_l16,
       fetch_texel_2d_f_l16,
-      fetch_texel_3d_f_l16,
-      store_texel_l16
+      fetch_texel_3d_f_l16
    },
    {
       MESA_FORMAT_I8,
       fetch_texel_1d_f_i8,
       fetch_texel_2d_f_i8,
-      fetch_texel_3d_f_i8,
-      store_texel_i8
+      fetch_texel_3d_f_i8
    },
    {
       MESA_FORMAT_I16,
       fetch_texel_1d_f_i16,
       fetch_texel_2d_f_i16,
-      fetch_texel_3d_f_i16,
-      store_texel_i16
+      fetch_texel_3d_f_i16
    },
    {
       MESA_FORMAT_YCBCR,
       fetch_texel_1d_f_ycbcr,
       fetch_texel_2d_f_ycbcr,
-      fetch_texel_3d_f_ycbcr,
-      store_texel_ycbcr
+      fetch_texel_3d_f_ycbcr
    },
    {
       MESA_FORMAT_YCBCR_REV,
       fetch_texel_1d_f_ycbcr_rev,
       fetch_texel_2d_f_ycbcr_rev,
-      fetch_texel_3d_f_ycbcr_rev,
-      store_texel_ycbcr_rev
+      fetch_texel_3d_f_ycbcr_rev
    },
    {
       MESA_FORMAT_R8,
       fetch_texel_1d_f_r8,
       fetch_texel_2d_f_r8,
-      fetch_texel_3d_f_r8,
-      store_texel_r8,
+      fetch_texel_3d_f_r8
    },
    {
       MESA_FORMAT_GR88,
       fetch_texel_1d_f_gr88,
       fetch_texel_2d_f_gr88,
-      fetch_texel_3d_f_gr88,
-      store_texel_gr88,
+      fetch_texel_3d_f_gr88
    },
    {
       MESA_FORMAT_RG88,
       fetch_texel_1d_f_rg88,
       fetch_texel_2d_f_rg88,
-      fetch_texel_3d_f_rg88,
-      store_texel_rg88,
+      fetch_texel_3d_f_rg88
    },
    {
       MESA_FORMAT_R16,
       fetch_texel_1d_f_r16,
       fetch_texel_2d_f_r16,
-      fetch_texel_3d_f_r16,
-      store_texel_r16,
+      fetch_texel_3d_f_r16
    },
    {
       MESA_FORMAT_RG1616,
       fetch_texel_1d_f_rg1616,
       fetch_texel_2d_f_rg1616,
-      fetch_texel_3d_f_rg1616,
-      store_texel_rg1616,
+      fetch_texel_3d_f_rg1616
    },
    {
       MESA_FORMAT_RG1616_REV,
       fetch_texel_1d_f_rg1616_rev,
       fetch_texel_2d_f_rg1616_rev,
-      fetch_texel_3d_f_rg1616_rev,
-      store_texel_rg1616_rev,
+      fetch_texel_3d_f_rg1616_rev
    },
    {
       MESA_FORMAT_ARGB2101010,
       fetch_texel_1d_f_argb2101010,
       fetch_texel_2d_f_argb2101010,
-      fetch_texel_3d_f_argb2101010,
-      store_texel_argb2101010
+      fetch_texel_3d_f_argb2101010
    },
    {
       MESA_FORMAT_Z24_S8,
       fetch_texel_1d_f_z24_s8,
       fetch_texel_2d_f_z24_s8,
-      fetch_texel_3d_f_z24_s8,
-      store_texel_z24_s8
+      fetch_texel_3d_f_z24_s8
    },
    {
       MESA_FORMAT_S8_Z24,
       fetch_texel_1d_f_s8_z24,
       fetch_texel_2d_f_s8_z24,
-      fetch_texel_3d_f_s8_z24,
-      store_texel_s8_z24
+      fetch_texel_3d_f_s8_z24
    },
    {
       MESA_FORMAT_Z16,
       fetch_texel_1d_f_z16,
       fetch_texel_2d_f_z16,
-      fetch_texel_3d_f_z16,
-      store_texel_z16
+      fetch_texel_3d_f_z16
    },
    {
       MESA_FORMAT_X8_Z24,
       fetch_texel_1d_f_s8_z24,
       fetch_texel_2d_f_s8_z24,
-      fetch_texel_3d_f_s8_z24,
-      store_texel_s8_z24
+      fetch_texel_3d_f_s8_z24
    },
    {
       MESA_FORMAT_Z24_X8,
       fetch_texel_1d_f_z24_s8,
       fetch_texel_2d_f_z24_s8,
-      fetch_texel_3d_f_z24_s8,
-      store_texel_z24_s8
+      fetch_texel_3d_f_z24_s8
    },
    {
       MESA_FORMAT_Z32,
       fetch_texel_1d_f_z32,
       fetch_texel_2d_f_z32,
-      fetch_texel_3d_f_z32,
-      store_texel_z32
+      fetch_texel_3d_f_z32
    },
    {
       MESA_FORMAT_S8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SRGB8,
       fetch_texel_1d_srgb8,
       fetch_texel_2d_srgb8,
-      fetch_texel_3d_srgb8,
-      store_texel_srgb8
+      fetch_texel_3d_srgb8
    },
    {
       MESA_FORMAT_SRGBA8,
       fetch_texel_1d_srgba8,
       fetch_texel_2d_srgba8,
-      fetch_texel_3d_srgba8,
-      store_texel_srgba8
+      fetch_texel_3d_srgba8
    },
    {
       MESA_FORMAT_SARGB8,
       fetch_texel_1d_sargb8,
       fetch_texel_2d_sargb8,
-      fetch_texel_3d_sargb8,
-      store_texel_sargb8
+      fetch_texel_3d_sargb8
    },
    {
       MESA_FORMAT_SL8,
       fetch_texel_1d_sl8,
       fetch_texel_2d_sl8,
-      fetch_texel_3d_sl8,
-      store_texel_sl8
+      fetch_texel_3d_sl8
    },
    {
       MESA_FORMAT_SLA8,
       fetch_texel_1d_sla8,
       fetch_texel_2d_sla8,
-      fetch_texel_3d_sla8,
-      store_texel_sla8
+      fetch_texel_3d_sla8
    },
    {
       MESA_FORMAT_SRGB_DXT1,
       NULL,
       _mesa_fetch_texel_2d_f_srgb_dxt1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SRGBA_DXT1,
       NULL,
       _mesa_fetch_texel_2d_f_srgba_dxt1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SRGBA_DXT3,
       NULL,
       _mesa_fetch_texel_2d_f_srgba_dxt3,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SRGBA_DXT5,
       NULL,
       _mesa_fetch_texel_2d_f_srgba_dxt5,
-      NULL,
       NULL
    },
 
@@ -520,162 +452,139 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_RGB_FXT1,
       NULL,
       _mesa_fetch_texel_2d_f_rgb_fxt1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_FXT1,
       NULL,
       _mesa_fetch_texel_2d_f_rgba_fxt1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGB_DXT1,
       NULL,
       _mesa_fetch_texel_2d_f_rgb_dxt1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_DXT1,
       NULL,
       _mesa_fetch_texel_2d_f_rgba_dxt1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_DXT3,
       NULL,
       _mesa_fetch_texel_2d_f_rgba_dxt3,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_DXT5,
       NULL,
       _mesa_fetch_texel_2d_f_rgba_dxt5,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_FLOAT32,
       fetch_texel_1d_f_rgba_f32,
       fetch_texel_2d_f_rgba_f32,
-      fetch_texel_3d_f_rgba_f32,
-      store_texel_rgba_f32
+      fetch_texel_3d_f_rgba_f32
    },
    {
       MESA_FORMAT_RGBA_FLOAT16,
       fetch_texel_1d_f_rgba_f16,
       fetch_texel_2d_f_rgba_f16,
-      fetch_texel_3d_f_rgba_f16,
-      store_texel_rgba_f16
+      fetch_texel_3d_f_rgba_f16
    },
    {
       MESA_FORMAT_RGB_FLOAT32,
       fetch_texel_1d_f_rgb_f32,
       fetch_texel_2d_f_rgb_f32,
-      fetch_texel_3d_f_rgb_f32,
-      store_texel_rgb_f32
+      fetch_texel_3d_f_rgb_f32
    },
    {
       MESA_FORMAT_RGB_FLOAT16,
       fetch_texel_1d_f_rgb_f16,
       fetch_texel_2d_f_rgb_f16,
-      fetch_texel_3d_f_rgb_f16,
-      store_texel_rgb_f16
+      fetch_texel_3d_f_rgb_f16
    },
    {
       MESA_FORMAT_ALPHA_FLOAT32,
       fetch_texel_1d_f_alpha_f32,
       fetch_texel_2d_f_alpha_f32,
-      fetch_texel_3d_f_alpha_f32,
-      store_texel_alpha_f32
+      fetch_texel_3d_f_alpha_f32
    },
    {
       MESA_FORMAT_ALPHA_FLOAT16,
       fetch_texel_1d_f_alpha_f16,
       fetch_texel_2d_f_alpha_f16,
-      fetch_texel_3d_f_alpha_f16,
-      store_texel_alpha_f16
+      fetch_texel_3d_f_alpha_f16
    },
    {
       MESA_FORMAT_LUMINANCE_FLOAT32,
       fetch_texel_1d_f_luminance_f32,
       fetch_texel_2d_f_luminance_f32,
-      fetch_texel_3d_f_luminance_f32,
-      store_texel_luminance_f32
+      fetch_texel_3d_f_luminance_f32
    },
    {
       MESA_FORMAT_LUMINANCE_FLOAT16,
       fetch_texel_1d_f_luminance_f16,
       fetch_texel_2d_f_luminance_f16,
-      fetch_texel_3d_f_luminance_f16,
-      store_texel_luminance_f16
+      fetch_texel_3d_f_luminance_f16
    },
    {
       MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
       fetch_texel_1d_f_luminance_alpha_f32,
       fetch_texel_2d_f_luminance_alpha_f32,
-      fetch_texel_3d_f_luminance_alpha_f32,
-      store_texel_luminance_alpha_f32
+      fetch_texel_3d_f_luminance_alpha_f32
    },
    {
       MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
       fetch_texel_1d_f_luminance_alpha_f16,
       fetch_texel_2d_f_luminance_alpha_f16,
-      fetch_texel_3d_f_luminance_alpha_f16,
-      store_texel_luminance_alpha_f16
+      fetch_texel_3d_f_luminance_alpha_f16
    },
    {
       MESA_FORMAT_INTENSITY_FLOAT32,
       fetch_texel_1d_f_intensity_f32,
       fetch_texel_2d_f_intensity_f32,
-      fetch_texel_3d_f_intensity_f32,
-      store_texel_intensity_f32
+      fetch_texel_3d_f_intensity_f32
    },
    {
       MESA_FORMAT_INTENSITY_FLOAT16,
       fetch_texel_1d_f_intensity_f16,
       fetch_texel_2d_f_intensity_f16,
-      fetch_texel_3d_f_intensity_f16,
-      store_texel_intensity_f16
+      fetch_texel_3d_f_intensity_f16
    },
    {
       MESA_FORMAT_R_FLOAT32,
       fetch_texel_1d_f_r_f32,
       fetch_texel_2d_f_r_f32,
-      fetch_texel_3d_f_r_f32,
-      store_texel_r_f32
+      fetch_texel_3d_f_r_f32
    },
    {
       MESA_FORMAT_R_FLOAT16,
       fetch_texel_1d_f_r_f16,
       fetch_texel_2d_f_r_f16,
-      fetch_texel_3d_f_r_f16,
-      store_texel_r_f16
+      fetch_texel_3d_f_r_f16
    },
    {
       MESA_FORMAT_RG_FLOAT32,
       fetch_texel_1d_f_rg_f32,
       fetch_texel_2d_f_rg_f32,
-      fetch_texel_3d_f_rg_f32,
-      store_texel_rg_f32
+      fetch_texel_3d_f_rg_f32
    },
    {
       MESA_FORMAT_RG_FLOAT16,
       fetch_texel_1d_f_rg_f16,
       fetch_texel_2d_f_rg_f16,
-      fetch_texel_3d_f_rg_f16,
-      store_texel_rg_f16
+      fetch_texel_3d_f_rg_f16
    },
 
    {
       MESA_FORMAT_ALPHA_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -683,7 +592,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_ALPHA_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -691,7 +599,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_ALPHA_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -699,7 +606,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_ALPHA_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -707,7 +613,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_ALPHA_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -715,7 +620,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_ALPHA_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -724,7 +628,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_INTENSITY_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -732,7 +635,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_INTENSITY_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -740,7 +642,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_INTENSITY_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -748,7 +649,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_INTENSITY_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -756,7 +656,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_INTENSITY_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -764,7 +663,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_INTENSITY_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -773,7 +671,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -781,7 +678,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -789,7 +685,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -797,7 +692,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -805,7 +699,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -813,7 +706,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -822,7 +714,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_ALPHA_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -830,7 +721,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_ALPHA_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -838,7 +728,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_ALPHA_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -846,7 +735,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_ALPHA_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -854,7 +742,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_ALPHA_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -862,7 +749,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_LUMINANCE_ALPHA_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -871,7 +757,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_R_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -879,7 +764,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_RG_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -887,7 +771,6 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_RGB_INT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
 
@@ -896,64 +779,55 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_RGBA_INT8,
       fetch_texel_1d_rgba_int8,
       fetch_texel_2d_rgba_int8,
-      fetch_texel_3d_rgba_int8,
-      store_texel_rgba_int8
+      fetch_texel_3d_rgba_int8
    },
    {
       MESA_FORMAT_R_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RG_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGB_INT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_INT16,
       fetch_texel_1d_rgba_int16,
       fetch_texel_2d_rgba_int16,
-      fetch_texel_3d_rgba_int16,
-      store_texel_rgba_int16
+      fetch_texel_3d_rgba_int16
    },
    {
       MESA_FORMAT_R_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RG_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGB_INT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_INT32,
       fetch_texel_1d_rgba_int32,
       fetch_texel_2d_rgba_int32,
-      fetch_texel_3d_rgba_int32,
-      store_texel_rgba_int32
+      fetch_texel_3d_rgba_int32
    },
 
    /* non-normalized, unsigned int */
@@ -961,85 +835,73 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_R_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RG_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGB_UINT8,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_UINT8,
       fetch_texel_1d_rgba_uint8,
       fetch_texel_2d_rgba_uint8,
-      fetch_texel_3d_rgba_uint8,
-      store_texel_rgba_uint8
+      fetch_texel_3d_rgba_uint8
    },
    {
       MESA_FORMAT_R_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RG_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGB_UINT16,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_UINT16,
       fetch_texel_1d_rgba_uint16,
       fetch_texel_2d_rgba_uint16,
-      fetch_texel_3d_rgba_uint16,
-      store_texel_rgba_uint16
+      fetch_texel_3d_rgba_uint16
    },
    {
       MESA_FORMAT_R_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RG_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGB_UINT32,
       NULL,
       NULL,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RGBA_UINT32,
       fetch_texel_1d_rgba_uint32,
       fetch_texel_2d_rgba_uint32,
-      fetch_texel_3d_rgba_uint32,
-      store_texel_rgba_uint32
+      fetch_texel_3d_rgba_uint32
    },
 
    /* dudv */
@@ -1047,8 +909,7 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_DUDV8,
       fetch_texel_1d_dudv8,
       fetch_texel_2d_dudv8,
-      fetch_texel_3d_dudv8,
-      NULL
+      fetch_texel_3d_dudv8
    },
 
    /* signed, normalized */
@@ -1056,224 +917,192 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       MESA_FORMAT_SIGNED_R8,
       fetch_texel_1d_signed_r8,
       fetch_texel_2d_signed_r8,
-      fetch_texel_3d_signed_r8,
-      store_texel_signed_r8
+      fetch_texel_3d_signed_r8
    },
    {
       MESA_FORMAT_SIGNED_RG88_REV,
       fetch_texel_1d_signed_rg88_rev,
       fetch_texel_2d_signed_rg88_rev,
-      fetch_texel_3d_signed_rg88_rev,
-      store_texel_signed_rg88_rev
+      fetch_texel_3d_signed_rg88_rev
    },
    {
       MESA_FORMAT_SIGNED_RGBX8888,
       fetch_texel_1d_signed_rgbx8888,
       fetch_texel_2d_signed_rgbx8888,
-      fetch_texel_3d_signed_rgbx8888,
-      store_texel_signed_rgbx8888
+      fetch_texel_3d_signed_rgbx8888
    },
    {
       MESA_FORMAT_SIGNED_RGBA8888,
       fetch_texel_1d_signed_rgba8888,
       fetch_texel_2d_signed_rgba8888,
-      fetch_texel_3d_signed_rgba8888,
-      store_texel_signed_rgba8888
+      fetch_texel_3d_signed_rgba8888
    },
    {
       MESA_FORMAT_SIGNED_RGBA8888_REV,
       fetch_texel_1d_signed_rgba8888_rev,
       fetch_texel_2d_signed_rgba8888_rev,
-      fetch_texel_3d_signed_rgba8888_rev,
-      store_texel_signed_rgba8888_rev
+      fetch_texel_3d_signed_rgba8888_rev
    },
    {
       MESA_FORMAT_SIGNED_R16,
       fetch_texel_1d_signed_r16,
       fetch_texel_2d_signed_r16,
-      fetch_texel_3d_signed_r16,
-      store_texel_signed_r16
+      fetch_texel_3d_signed_r16
    },
    {
       MESA_FORMAT_SIGNED_GR1616,
       fetch_texel_1d_signed_rg1616,
       fetch_texel_2d_signed_rg1616,
-      fetch_texel_3d_signed_rg1616,
-      store_texel_signed_rg1616
+      fetch_texel_3d_signed_rg1616
    },
    {
       MESA_FORMAT_SIGNED_RGB_16,
       fetch_texel_1d_signed_rgb_16,
       fetch_texel_2d_signed_rgb_16,
-      fetch_texel_3d_signed_rgb_16,
-      store_texel_signed_rgb_16
+      fetch_texel_3d_signed_rgb_16
    },
    {
       MESA_FORMAT_SIGNED_RGBA_16,
       fetch_texel_1d_signed_rgba_16,
       fetch_texel_2d_signed_rgba_16,
-      fetch_texel_3d_signed_rgba_16,
-      store_texel_signed_rgba_16
+      fetch_texel_3d_signed_rgba_16
    },
    {
       MESA_FORMAT_RGBA_16,
       fetch_texel_1d_rgba_16,
       fetch_texel_2d_rgba_16,
-      fetch_texel_3d_rgba_16,
-      store_texel_rgba_16
+      fetch_texel_3d_rgba_16
    },
    {
       MESA_FORMAT_RED_RGTC1,
       NULL,
       _mesa_fetch_texel_2d_f_red_rgtc1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SIGNED_RED_RGTC1,
       NULL,
       _mesa_fetch_texel_2d_f_signed_red_rgtc1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_RG_RGTC2,
       NULL,
       _mesa_fetch_texel_2d_f_rg_rgtc2,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SIGNED_RG_RGTC2,
       NULL,
       _mesa_fetch_texel_2d_f_signed_rg_rgtc2,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_L_LATC1,
       NULL,
       _mesa_fetch_texel_2d_f_l_latc1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SIGNED_L_LATC1,
       NULL,
       _mesa_fetch_texel_2d_f_signed_l_latc1,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_LA_LATC2,
       NULL,
       _mesa_fetch_texel_2d_f_la_latc2,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SIGNED_LA_LATC2,
       NULL,
       _mesa_fetch_texel_2d_f_signed_la_latc2,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_ETC1_RGB8,
       NULL,
       _mesa_fetch_texel_2d_f_etc1_rgb8,
-      NULL,
       NULL
    },
    {
       MESA_FORMAT_SIGNED_A8,
       fetch_texel_1d_signed_a8,
       fetch_texel_2d_signed_a8,
-      fetch_texel_3d_signed_a8,
-      store_texel_signed_a8
+      fetch_texel_3d_signed_a8
    },
    {
       MESA_FORMAT_SIGNED_L8,
       fetch_texel_1d_signed_l8,
       fetch_texel_2d_signed_l8,
-      fetch_texel_3d_signed_l8,
-      store_texel_signed_l8
+      fetch_texel_3d_signed_l8
    },
    {
       MESA_FORMAT_SIGNED_AL88,
       fetch_texel_1d_signed_al88,
       fetch_texel_2d_signed_al88,
-      fetch_texel_3d_signed_al88,
-      store_texel_signed_al88
+      fetch_texel_3d_signed_al88
    },
    {
       MESA_FORMAT_SIGNED_I8,
       fetch_texel_1d_signed_i8,
       fetch_texel_2d_signed_i8,
-      fetch_texel_3d_signed_i8,
-      store_texel_signed_i8
+      fetch_texel_3d_signed_i8
    },
    {
       MESA_FORMAT_SIGNED_A16,
       fetch_texel_1d_signed_a16,
       fetch_texel_2d_signed_a16,
-      fetch_texel_3d_signed_a16,
-      store_texel_signed_a16
+      fetch_texel_3d_signed_a16
    },
    {
       MESA_FORMAT_SIGNED_L16,
       fetch_texel_1d_signed_l16,
       fetch_texel_2d_signed_l16,
-      fetch_texel_3d_signed_l16,
-      store_texel_signed_l16
+      fetch_texel_3d_signed_l16
    },
    {
       MESA_FORMAT_SIGNED_AL1616,
       fetch_texel_1d_signed_al1616,
       fetch_texel_2d_signed_al1616,
-      fetch_texel_3d_signed_al1616,
-      store_texel_signed_al1616
+      fetch_texel_3d_signed_al1616
    },
    {
       MESA_FORMAT_SIGNED_I16,
       fetch_texel_1d_signed_i16,
       fetch_texel_2d_signed_i16,
-      fetch_texel_3d_signed_i16,
-      store_texel_signed_i16
+      fetch_texel_3d_signed_i16
    },
    {
       MESA_FORMAT_RGB9_E5_FLOAT,
       fetch_texel_1d_rgb9_e5,
       fetch_texel_2d_rgb9_e5,
-      fetch_texel_3d_rgb9_e5,
-      store_texel_rgb9_e5
+      fetch_texel_3d_rgb9_e5
    },
    {
       MESA_FORMAT_R11_G11_B10_FLOAT,
       fetch_texel_1d_r11_g11_b10f,
       fetch_texel_2d_r11_g11_b10f,
-      fetch_texel_3d_r11_g11_b10f,
-      store_texel_r11_g11_b10f
+      fetch_texel_3d_r11_g11_b10f
    },
    {
       MESA_FORMAT_Z32_FLOAT,
       fetch_texel_1d_f_r_f32, /* Reuse the R32F functions. */
       fetch_texel_2d_f_r_f32,
-      fetch_texel_3d_f_r_f32,
-      store_texel_r_f32
+      fetch_texel_3d_f_r_f32
    },
    {
       MESA_FORMAT_Z32_FLOAT_X24S8,
       fetch_texel_1d_z32f_x24s8,
       fetch_texel_2d_z32f_x24s8,
-      fetch_texel_3d_z32f_x24s8,
-      store_texel_z32f_x24s8
+      fetch_texel_3d_z32f_x24s8
    },
    {
       MESA_FORMAT_ARGB2101010_UINT,
       NULL,
       NULL,
-      NULL,
       NULL
    }
 };
@@ -1308,14 +1137,6 @@ _mesa_get_texel_fetch_func(gl_format format, GLuint dims)
 }
 
 
-StoreTexelFunc
-_mesa_get_texel_store_func(gl_format format)
-{
-   assert(format < MESA_FORMAT_COUNT);
-   return texfetch_funcs[format].StoreTexel;
-}
-
-
 /**
  * Initialize the texture image's FetchTexel methods.
  */
diff --git a/src/mesa/swrast/s_texfetch.h b/src/mesa/swrast/s_texfetch.h
index c98aa5c..1aa7ce5 100644
--- a/src/mesa/swrast/s_texfetch.h
+++ b/src/mesa/swrast/s_texfetch.h
@@ -29,9 +29,6 @@
 
 #include "swrast/s_context.h"
 
-extern StoreTexelFunc
-_mesa_get_texel_store_func(gl_format format);
-
 extern FetchTexelFunc
 _mesa_get_texel_fetch_func(gl_format format, GLuint dims);
 
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index f1a2ed6..b65d33f 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -81,16 +81,6 @@ static void FETCH(f_z32)( const struct swrast_texture_image *texImage,
    texel[0] = src[0] * (1.0F / 0xffffffff);
 }
 
-#if DIM == 3
-static void store_texel_z32(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLuint *depth = (const GLuint *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   dst[0] = *depth;
-}
-#endif
-
 
 /* MESA_FORMAT_Z16 ***********************************************************/
 
@@ -105,15 +95,6 @@ static void FETCH(f_z16)(const struct swrast_texture_image *texImage,
    texel[0] = src[0] * (1.0F / 65535.0F);
 }
 
-#if DIM == 3
-static void store_texel_z16(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLushort *depth = (const GLushort *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   dst[0] = *depth;
-}
-#endif
 
 
 /* MESA_FORMAT_RGBA_F32 ******************************************************/
@@ -130,18 +111,7 @@ static void FETCH(f_rgba_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = src[3];
 }
 
-#if DIM == 3
-static void store_texel_rgba_f32(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *depth = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
-   dst[0] = depth[RCOMP];
-   dst[1] = depth[GCOMP];
-   dst[2] = depth[BCOMP];
-   dst[3] = depth[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_F16 ******************************************************/
@@ -159,18 +129,7 @@ static void FETCH(f_rgba_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = _mesa_half_to_float(src[3]);
 }
 
-#if DIM == 3
-static void store_texel_rgba_f16(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *src = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
-   dst[0] = _mesa_float_to_half(src[RCOMP]);
-   dst[1] = _mesa_float_to_half(src[GCOMP]);
-   dst[2] = _mesa_float_to_half(src[BCOMP]);
-   dst[3] = _mesa_float_to_half(src[ACOMP]);
-}
-#endif
+
 
 /* MESA_FORMAT_RGB_F32 *******************************************************/
 
@@ -187,17 +146,7 @@ static void FETCH(f_rgb_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb_f32(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *src = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
-   dst[0] = src[RCOMP];
-   dst[1] = src[GCOMP];
-   dst[2] = src[BCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGB_F16 *******************************************************/
@@ -215,17 +164,7 @@ static void FETCH(f_rgb_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb_f16(struct swrast_texture_image *texImage,
-                                GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *src = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
-   dst[0] = _mesa_float_to_half(src[RCOMP]);
-   dst[1] = _mesa_float_to_half(src[GCOMP]);
-   dst[2] = _mesa_float_to_half(src[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
@@ -243,15 +182,7 @@ static void FETCH(f_alpha_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = src[0];
 }
 
-#if DIM == 3
-static void store_texel_alpha_f32(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   dst[0] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
@@ -269,15 +200,7 @@ static void FETCH(f_alpha_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = _mesa_half_to_float(src[0]);
 }
 
-#if DIM == 3
-static void store_texel_alpha_f16(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
-   dst[0] = _mesa_float_to_half(rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
@@ -295,15 +218,7 @@ static void FETCH(f_luminance_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_luminance_f32(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   dst[0] = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
@@ -321,15 +236,7 @@ static void FETCH(f_luminance_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_luminance_f16(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
-   dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
@@ -347,16 +254,7 @@ static void FETCH(f_luminance_alpha_f32)( const struct swrast_texture_image *tex
    texel[ACOMP] = src[1];
 }
 
-#if DIM == 3
-static void store_texel_luminance_alpha_f32(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
@@ -374,16 +272,7 @@ static void FETCH(f_luminance_alpha_f16)( const struct swrast_texture_image *tex
    texel[ACOMP] = _mesa_half_to_float(src[1]);
 }
 
-#if DIM == 3
-static void store_texel_luminance_alpha_f16(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
-   dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-   dst[1] = _mesa_float_to_half(rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
@@ -401,15 +290,7 @@ static void FETCH(f_intensity_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = src[0];
 }
 
-#if DIM == 3
-static void store_texel_intensity_f32(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   dst[0] = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
@@ -427,15 +308,7 @@ static void FETCH(f_intensity_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = _mesa_half_to_float(src[0]);
 }
 
-#if DIM == 3
-static void store_texel_intensity_f16(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
-   dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
@@ -453,15 +326,7 @@ static void FETCH(f_r_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_r_f32(struct swrast_texture_image *texImage,
-                              GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
-   dst[0] = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
@@ -479,15 +344,7 @@ static void FETCH(f_r_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_r_f16(struct swrast_texture_image *texImage,
-                              GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
-   dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
@@ -505,16 +362,7 @@ static void FETCH(f_rg_f32)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rg_f32(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
@@ -532,16 +380,7 @@ static void FETCH(f_rg_f16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rg_f16(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *rgba = (const GLfloat *) texel;
-   GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
-   dst[0] = _mesa_float_to_half(rgba[RCOMP]);
-   dst[1] = _mesa_float_to_half(rgba[GCOMP]);
-}
-#endif
+
 
 
 /*
@@ -563,15 +402,7 @@ static void FETCH(f_rgba8888)( const struct swrast_texture_image *texImage,
 
 
 
-#if DIM == 3
-static void store_texel_rgba8888(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA888_REV ***************************************************/
@@ -587,15 +418,7 @@ static void FETCH(f_rgba8888_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
 }
 
-#if DIM == 3
-static void store_texel_rgba8888_rev(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_ARGB8888 ******************************************************/
@@ -611,15 +434,7 @@ static void FETCH(f_argb8888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
 }
 
-#if DIM == 3
-static void store_texel_argb8888(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_ARGB8888_REV **************************************************/
@@ -635,15 +450,7 @@ static void FETCH(f_argb8888_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
 }
 
-#if DIM == 3
-static void store_texel_argb8888_rev(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBX8888 ******************************************************/
@@ -659,15 +466,7 @@ static void FETCH(f_rgbx8888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0f;
 }
 
-#if DIM == 3
-static void store_texel_rgbx8888(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 0xff);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBX888_REV ***************************************************/
@@ -683,15 +482,7 @@ static void FETCH(f_rgbx8888_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0f;
 }
 
-#if DIM == 3
-static void store_texel_rgbx8888_rev(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 0xff);
-}
-#endif
+
 
 
 /* MESA_FORMAT_XRGB8888 ******************************************************/
@@ -707,15 +498,7 @@ static void FETCH(f_xrgb8888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0f;
 }
 
-#if DIM == 3
-static void store_texel_xrgb8888(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_XRGB8888_REV **************************************************/
@@ -731,15 +514,7 @@ static void FETCH(f_xrgb8888_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0f;
 }
 
-#if DIM == 3
-static void store_texel_xrgb8888_rev(struct swrast_texture_image *texImage,
-                                     GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGB888 ********************************************************/
@@ -755,17 +530,7 @@ static void FETCH(f_rgb888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb888(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
-   dst[0] = rgba[BCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_BGR888 ********************************************************/
@@ -781,17 +546,7 @@ static void FETCH(f_bgr888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_bgr888(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-}
-#endif
+
 
 
 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
@@ -811,15 +566,7 @@ static void FETCH(f_rgb565)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb565(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGB565_REV ****************************************************/
@@ -836,18 +583,7 @@ static void FETCH(f_rgb565_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb565_rev(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   GLushort p = PACK_COLOR_565(CHAN_TO_UBYTE(rgba[RCOMP]),
-                               CHAN_TO_UBYTE(rgba[GCOMP]),
-                               CHAN_TO_UBYTE(rgba[BCOMP]));
-   *dst = (p >> 8) | (p << 8); /* byte swap */
-}
-#endif
+
 
 
 /* MESA_FORMAT_ARGB4444 ******************************************************/
@@ -864,18 +600,7 @@ static void FETCH(f_argb4444)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
 }
 
-#if DIM == 3
-static void store_texel_argb4444(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[ACOMP]),
-                          CHAN_TO_UBYTE(rgba[RCOMP]),
-                          CHAN_TO_UBYTE(rgba[GCOMP]),
-                          CHAN_TO_UBYTE(rgba[BCOMP]));
-}
-#endif
+
 
 
 /* MESA_FORMAT_ARGB4444_REV **************************************************/
@@ -891,18 +616,7 @@ static void FETCH(f_argb4444_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
 }
 
-#if DIM == 3
-static void store_texel_argb4444_rev(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[GCOMP]),
-                          CHAN_TO_UBYTE(rgba[BCOMP]),
-                          CHAN_TO_UBYTE(rgba[ACOMP]),
-                          CHAN_TO_UBYTE(rgba[RCOMP]));
-}
-#endif
+
 
 /* MESA_FORMAT_RGBA5551 ******************************************************/
 
@@ -918,15 +632,7 @@ static void FETCH(f_rgba5551)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = ((s      ) & 0x01) * 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgba5551(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 /* MESA_FORMAT_ARGB1555 ******************************************************/
 
@@ -942,15 +648,7 @@ static void FETCH(f_argb1555)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_argb1555(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_ARGB1555_REV **************************************************/
@@ -967,15 +665,7 @@ static void FETCH(f_argb1555_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
 }
 
-#if DIM == 3
-static void store_texel_argb1555_rev(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_ARGB2101010 ***************************************************/
@@ -992,19 +682,7 @@ static void FETCH(f_argb2101010)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
 }
 
-#if DIM == 3
-static void store_texel_argb2101010(struct swrast_texture_image *texImage,
-                                    GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
-   GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
-   GLushort b = CHAN_TO_USHORT(rgba[BCOMP]);
-   GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
-   *dst = PACK_COLOR_2101010_US(a, r, g, b);
-}
-#endif
+
 
 
 /* MESA_FORMAT_GR88 **********************************************************/
@@ -1020,17 +698,7 @@ static void FETCH(f_gr88)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0;
 }
 
-#if DIM == 3
-static void store_texel_gr88(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   GLubyte r = CHAN_TO_UBYTE(rgba[RCOMP]);
-   GLubyte g = CHAN_TO_UBYTE(rgba[GCOMP]);
-   *dst = PACK_COLOR_88(g, r);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RG88 ******************************************************/
@@ -1046,15 +714,7 @@ static void FETCH(f_rg88)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0;
 }
 
-#if DIM == 3
-static void store_texel_rg88(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_AL44 **********************************************************/
@@ -1070,15 +730,7 @@ static void FETCH(f_al44)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
 }
 
-#if DIM == 3
-static void store_texel_al44(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_AL88 **********************************************************/
@@ -1094,15 +746,7 @@ static void FETCH(f_al88)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
 }
 
-#if DIM == 3
-static void store_texel_al88(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_R8 ************************************************************/
@@ -1118,15 +762,7 @@ static void FETCH(f_r8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0;
 }
 
-#if DIM == 3
-static void store_texel_r8(struct swrast_texture_image *texImage,
-			   GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_R16 ***********************************************************/
@@ -1142,15 +778,7 @@ static void FETCH(f_r16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0;
 }
 
-#if DIM == 3
-static void store_texel_r16(struct swrast_texture_image *texImage,
-			    GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = CHAN_TO_USHORT(rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_AL88_REV ******************************************************/
@@ -1166,15 +794,7 @@ static void FETCH(f_al88_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
 }
 
-#if DIM == 3
-static void store_texel_al88_rev(struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RG1616 ********************************************************/
@@ -1190,17 +810,7 @@ static void FETCH(f_rg1616)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0;
 }
 
-#if DIM == 3
-static void store_texel_rg1616(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
-   GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
-   *dst = PACK_COLOR_1616(g, r);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RG1616_REV ****************************************************/
@@ -1216,15 +826,7 @@ static void FETCH(f_rg1616_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0;
 }
 
-#if DIM == 3
-static void store_texel_rg1616_rev(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_AL1616 ********************************************************/
@@ -1240,17 +842,7 @@ static void FETCH(f_al1616)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
 }
 
-#if DIM == 3
-static void store_texel_al1616(struct swrast_texture_image *texImage,
-                             GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   GLushort l = CHAN_TO_USHORT(rgba[RCOMP]);
-   GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
-   *dst = PACK_COLOR_1616(a, l);
-}
-#endif
+
 
 
 /* MESA_FORMAT_AL1616_REV ****************************************************/
@@ -1266,15 +858,7 @@ static void FETCH(f_al1616_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
 }
 
-#if DIM == 3
-static void store_texel_al1616_rev(struct swrast_texture_image *texImage,
-				   GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLushort *rgba = (const GLushort *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGB332 ********************************************************/
@@ -1291,15 +875,7 @@ static void FETCH(f_rgb332)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb332(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_A8 ************************************************************/
@@ -1315,15 +891,7 @@ static void FETCH(f_a8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
 }
 
-#if DIM == 3
-static void store_texel_a8(struct swrast_texture_image *texImage,
-                           GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   *dst = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_A16 ************************************************************/
@@ -1339,15 +907,7 @@ static void FETCH(f_a16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
 }
 
-#if DIM == 3
-static void store_texel_a16(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = CHAN_TO_USHORT(rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_L8 ************************************************************/
@@ -1363,15 +923,7 @@ static void FETCH(f_l8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_l8(struct swrast_texture_image *texImage,
-                           GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_L16 ***********************************************************/
@@ -1387,15 +939,7 @@ static void FETCH(f_l16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_l16(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = CHAN_TO_USHORT(rgba[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_I8 ************************************************************/
@@ -1411,15 +955,7 @@ static void FETCH(f_i8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
 }
 
-#if DIM == 3
-static void store_texel_i8(struct swrast_texture_image *texImage,
-                           GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_I16 ***********************************************************/
@@ -1435,15 +971,7 @@ static void FETCH(f_i16)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
 }
 
-#if DIM == 3
-static void store_texel_i16(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   *dst = CHAN_TO_USHORT(rgba[RCOMP]);
-}
-#endif
+
 
 
 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
@@ -1458,17 +986,7 @@ static void FETCH(srgb8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_srgb8(struct swrast_texture_image *texImage,
-                              GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
-   dst[0] = rgba[BCOMP]; /* no conversion */
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[RCOMP];
-}
-#endif
+
 
 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
 static void FETCH(srgba8)(const struct swrast_texture_image *texImage,
@@ -1481,15 +999,7 @@ static void FETCH(srgba8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff ); /* linear! */
 }
 
-#if DIM == 3
-static void store_texel_srgba8(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
 static void FETCH(sargb8)(const struct swrast_texture_image *texImage,
@@ -1502,15 +1012,7 @@ static void FETCH(sargb8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
 }
 
-#if DIM == 3
-static void store_texel_sargb8(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
-}
-#endif
+
 
 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
 static void FETCH(sl8)(const struct swrast_texture_image *texImage,
@@ -1523,15 +1025,7 @@ static void FETCH(sl8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_sl8(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
-   dst[0] = rgba[RCOMP];
-}
-#endif
+
 
 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
 static void FETCH(sla8)(const struct swrast_texture_image *texImage,
@@ -1544,16 +1038,7 @@ static void FETCH(sla8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
 }
 
-#if DIM == 3
-static void store_texel_sla8(struct swrast_texture_image *texImage,
-                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_INT8 **************************************************/
@@ -1569,19 +1054,7 @@ FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = (GLfloat) src[3];
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_int8(struct swrast_texture_image *texImage,
-                      GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-   dst[3] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_INT16 **************************************************/
@@ -1597,19 +1070,7 @@ FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = (GLfloat) src[3];
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_int16(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLshort *rgba = (const GLshort *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-   dst[3] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_INT32 **************************************************/
@@ -1625,19 +1086,7 @@ FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = (GLfloat) src[3];
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_int32(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLint *rgba = (const GLint *) texel;
-   GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-   dst[3] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
@@ -1653,19 +1102,7 @@ FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = (GLfloat) src[3];
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_uint8(struct swrast_texture_image *texImage,
-                      GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-   dst[3] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
@@ -1681,19 +1118,7 @@ FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = (GLfloat) src[3];
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_uint16(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLushort *rgba = (const GLushort *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-   dst[3] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
@@ -1709,19 +1134,7 @@ FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = (GLfloat) src[3];
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_uint32(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLuint *rgba = (const GLuint *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
-   dst[0] = rgba[RCOMP];
-   dst[1] = rgba[GCOMP];
-   dst[2] = rgba[BCOMP];
-   dst[3] = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_DUDV8 ********************************************************/
@@ -1751,15 +1164,7 @@ static void FETCH(signed_r8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_signed_r8(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
@@ -1774,15 +1179,7 @@ static void FETCH(signed_a8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
 }
 
-#if DIM == 3
-static void store_texel_signed_a8(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
-   *dst = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
@@ -1797,15 +1194,7 @@ static void FETCH(signed_l8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_signed_l8(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
@@ -1820,15 +1209,7 @@ static void FETCH(signed_i8)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
 }
 
-#if DIM == 3
-static void store_texel_signed_i8(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
@@ -1843,15 +1224,7 @@ static void FETCH(signed_rg88_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_signed_rg88_rev(struct swrast_texture_image *texImage,
-                                        GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rg = (const GLbyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
@@ -1866,15 +1239,7 @@ static void FETCH(signed_al88)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
 }
 
-#if DIM == 3
-static void store_texel_signed_al88(struct swrast_texture_image *texImage,
-                                    GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rg = (const GLbyte *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
-   dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
@@ -1889,15 +1254,7 @@ static void FETCH(signed_rgbx8888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0f;
 }
 
-#if DIM == 3
-static void store_texel_signed_rgbx8888(struct swrast_texture_image *texImage,
-                                        GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
@@ -1912,15 +1269,7 @@ static void FETCH(signed_rgba8888)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
 }
 
-#if DIM == 3
-static void store_texel_signed_rgba8888(struct swrast_texture_image *texImage,
-                                        GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLbyte *rgba = (const GLbyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 static void FETCH(signed_rgba8888_rev)( const struct swrast_texture_image *texImage,
                                         GLint i, GLint j, GLint k, GLfloat *texel )
@@ -1932,15 +1281,7 @@ static void FETCH(signed_rgba8888_rev)( const struct swrast_texture_image *texIm
    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
 }
 
-#if DIM == 3
-static void store_texel_signed_rgba8888_rev(struct swrast_texture_image *texImage,
-                                            GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLubyte *rgba = (const GLubyte *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
-}
-#endif
+
 
 
 
@@ -1957,16 +1298,7 @@ FETCH(signed_r16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void
-store_texel_signed_r16(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLshort *rgba = (const GLshort *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
-   *dst = rgba[0];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
@@ -1982,16 +1314,7 @@ FETCH(signed_a16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
 }
 
-#if DIM == 3
-static void
-store_texel_signed_a16(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLshort *rgba = (const GLshort *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
-   *dst = rgba[ACOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
@@ -2007,16 +1330,7 @@ FETCH(signed_l16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void
-store_texel_signed_l16(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLshort *rgba = (const GLshort *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
@@ -2032,16 +1346,7 @@ FETCH(signed_i16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
 }
 
-#if DIM == 3
-static void
-store_texel_signed_i16(struct swrast_texture_image *texImage,
-                       GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLshort *rgba = (const GLshort *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
-   *dst = rgba[RCOMP];
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
@@ -2057,17 +1362,7 @@ FETCH(signed_rg1616)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void
-store_texel_signed_rg1616(struct swrast_texture_image *texImage,
-                         GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
-   dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
-   dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
@@ -2083,17 +1378,7 @@ FETCH(signed_al1616)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
 }
 
-#if DIM == 3
-static void
-store_texel_signed_al1616(struct swrast_texture_image *texImage,
-                         GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
-   dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
-   dst[1] = CHAN_TO_SHORT(rgba[ACOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
@@ -2109,18 +1394,7 @@ FETCH(signed_rgb_16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void
-store_texel_signed_rgb_16(struct swrast_texture_image *texImage,
-                          GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
-   dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
-   dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
-   dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
-}
-#endif
+
 
 
 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
@@ -2136,19 +1410,7 @@ FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
 }
 
-#if DIM == 3
-static void
-store_texel_signed_rgba_16(struct swrast_texture_image *texImage,
-                           GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
-   dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
-   dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
-   dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
-   dst[3] = CHAN_TO_SHORT(rgba[ACOMP]);
-}
-#endif
+
 
 
 
@@ -2165,19 +1427,7 @@ FETCH(rgba_16)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
 }
 
-#if DIM == 3
-static void
-store_texel_rgba_16(struct swrast_texture_image *texImage,
-                    GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLchan *rgba = (const GLchan *) texel;
-   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
-   dst[0] = CHAN_TO_USHORT(rgba[RCOMP]);
-   dst[1] = CHAN_TO_USHORT(rgba[GCOMP]);
-   dst[2] = CHAN_TO_USHORT(rgba[BCOMP]);
-   dst[3] = CHAN_TO_USHORT(rgba[ACOMP]);
-}
-#endif
+
 
 
 
@@ -2208,18 +1458,7 @@ static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_ycbcr(struct swrast_texture_image *texImage,
-                              GLint i, GLint j, GLint k, const void *texel)
-{
-   (void) texImage;
-   (void) i;
-   (void) j;
-   (void) k;
-   (void) texel;
-   /* XXX to do */
-}
-#endif
+
 
 
 /* MESA_FORMAT_YCBCR_REV *****************************************************/
@@ -2249,18 +1488,7 @@ static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_ycbcr_rev(struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, const void *texel)
-{
-   (void) texImage;
-   (void) i;
-   (void) j;
-   (void) k;
-   (void) texel;
-   /* XXX to do */
-}
-#endif
+
 
 
 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
@@ -2278,17 +1506,7 @@ static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
    ASSERT(texel[0] <= 1.0F);
 }
 
-#if DIM == 3
-static void store_texel_z24_s8(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   /* only store Z, not stencil */
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   GLfloat depth = *((GLfloat *) texel);
-   GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
-   *dst = zi | (*dst & 0xff);
-}
-#endif
+
 
 
 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
@@ -2306,17 +1524,7 @@ static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
    ASSERT(texel[0] <= 1.0F);
 }
 
-#if DIM == 3
-static void store_texel_s8_z24(struct swrast_texture_image *texImage,
-                               GLint i, GLint j, GLint k, const void *texel)
-{
-   /* only store Z, not stencil */
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   GLfloat depth = *((GLfloat *) texel);
-   GLuint zi = (GLuint) (depth * 0xffffff);
-   *dst = zi | (*dst & 0xff000000);
-}
-#endif
+
 
 
 /* MESA_FORMAT_RGB9_E5 ******************************************************/
@@ -2329,15 +1537,7 @@ static void FETCH(rgb9_e5)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_rgb9_e5(struct swrast_texture_image *texImage,
-                                GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *src = (const GLfloat *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = float3_to_rgb9e5(src);
-}
-#endif
+
 
 
 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
@@ -2350,15 +1550,7 @@ static void FETCH(r11_g11_b10f)( const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_r11_g11_b10f(struct swrast_texture_image *texImage,
-                                     GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *src = (const GLfloat *) texel;
-   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
-   *dst = float3_to_r11g11b10f(src);
-}
-#endif
+
 
 
 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
@@ -2373,15 +1565,6 @@ static void FETCH(z32f_x24s8)(const struct swrast_texture_image *texImage,
    texel[ACOMP] = 1.0F;
 }
 
-#if DIM == 3
-static void store_texel_z32f_x24s8(struct swrast_texture_image *texImage,
-                                   GLint i, GLint j, GLint k, const void *texel)
-{
-   const GLfloat *src = (const GLfloat *) texel;
-   GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
-   dst[0] = src[0];
-}
-#endif
 
 
 #undef TEXEL_ADDR
commit 12370e050a62769052c967462fb30c6d4c6a95fb
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 18 17:39:33 2012 -0700

    swrast: use Map/UnmapTextureImage() in framebuffer map/unmap code
    
    When we're actually rendering into a texture, map the texture image
    instead of the corresponding renderbuffer.  Before, we just copied
    a pointer from the texture image to the renderbuffer.  This change
    will make the code usable by hardware drivers.
    (cherry picked from commit 1caf698191fb871850311353862eb7fc927f9f9c)

diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 501b469..637a7b6 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -565,20 +565,16 @@ map_attachment(struct gl_context *ctx,
    struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
 
    if (texObj) {
+      /* map texture image (render to texture) */
       const GLuint level = fb->Attachment[buffer].TextureLevel;
       const GLuint face = fb->Attachment[buffer].CubeMapFace;
+      const GLuint slice = fb->Attachment[buffer].Zoffset;
       struct gl_texture_image *texImage = texObj->Image[face][level];
       if (texImage) {
-         struct swrast_texture_image *swImage
-            = swrast_texture_image(texImage);
-
-         /* XXX we'll eventually call _swrast_map_teximage() here */
-         swImage->Map = swImage->Buffer;
-         if (srb) {
-            srb->Map = swImage->Buffer;
-            srb->RowStride = swImage->RowStride *
-               _mesa_get_format_bytes(swImage->Base.TexFormat);
-         }
+         ctx->Driver.MapTextureImage(ctx, texImage, slice,
+                                     0, 0, texImage->Width, texImage->Height,
+                                     GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+                                     &srb->Map, &srb->RowStride);
       }
    }
    else if (rb) {
@@ -587,8 +583,9 @@ map_attachment(struct gl_context *ctx,
                                   0, 0, rb->Width, rb->Height,
                                   GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
                                   &srb->Map, &srb->RowStride);
-      assert(srb->Map);
    }
+
+   assert(srb->Map);
 }
  
 
@@ -602,14 +599,15 @@ unmap_attachment(struct gl_context *ctx,
    struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
 
    if (texObj) {
+      /* unmap texture image (render to texture) */
       const GLuint level = fb->Attachment[buffer].TextureLevel;
       const GLuint face = fb->Attachment[buffer].CubeMapFace;
+      const GLuint slice = fb->Attachment[buffer].Zoffset;
       struct gl_texture_image *texImage = texObj->Image[face][level];
       if (texImage) {
-
-         /* XXX we'll eventually call _swrast_unmap_teximage() here */
-       }
-    }
+         ctx->Driver.UnmapTextureImage(ctx, texImage, slice);
+      }
+   }
    else if (rb) {
       /* unmap ordinary renderbuffer */
       ctx->Driver.UnmapRenderbuffer(ctx, rb);
commit 5163fed9194e4dfcd9a1935cffcdaff93f4ea846
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:06:03 2012 -0700

    mesa: remove ctx->Driver.Map/UnmapTexture() hooks
    
    No longer used anywhere.
    (cherry picked from commit 56d83ac4bf0267982554f25c6fdb3c1dd6e14a9c)

diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
index c6b42a2..1df8381 100644
--- a/src/mesa/drivers/common/driverfuncs.c
+++ b/src/mesa/drivers/common/driverfuncs.c
@@ -119,8 +119,6 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->FreeTextureImageBuffer = _swrast_free_texture_image_buffer;
    driver->MapTextureImage = _swrast_map_teximage;
    driver->UnmapTextureImage = _swrast_unmap_teximage;
-   driver->MapTexture = NULL;
-   driver->UnmapTexture = NULL;
    driver->DrawTex = _mesa_meta_DrawTex;
 
    /* Vertex/fragment programs */
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 8393f32..0641e3b 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -476,11 +476,6 @@ struct dd_function_table {
 			     struct gl_texture_image *texImage,
 			     GLuint slice);
 
-   /** Map texture image data into user space */
-   void (*MapTexture)( struct gl_context *ctx, struct gl_texture_object *tObj );
-   /** Unmap texture images from user space */
-   void (*UnmapTexture)( struct gl_context *ctx, struct gl_texture_object *tObj );
-
    /** For GL_ARB_texture_storage.  Allocate memory for whole mipmap stack.
     * All the gl_texture_images in the texture object will have their
     * dimensions, format, etc. initialized already.
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 817f137..14cb9b1 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -752,9 +752,6 @@ _swrast_CreateContext( struct gl_context *ctx )
    swrast->Driver.SpanRenderStart = _swrast_span_render_start;
    swrast->Driver.SpanRenderFinish = _swrast_span_render_finish;
 
-   ctx->Driver.MapTexture = _swrast_map_texture;
-   ctx->Driver.UnmapTexture = _swrast_unmap_texture;
-
    for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
       swrast->TextureSample[i] = NULL;
 
commit acfbf24335118ef70f09d6107ce9af3320834731
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:59 2012 -0700

    nouveau: stop calling ctx->Driver.Map/UnmapTexture()
    
    And remove unused nouveau_texture_map/unmap()
    (cherry picked from commit 8b8a54afd9b748b7250993393864544ad6961edb)

diff --git a/src/mesa/drivers/dri/nouveau/nouveau_span.c b/src/mesa/drivers/dri/nouveau/nouveau_span.c
index 91a9311..f82a2e1 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_span.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_span.c
@@ -46,18 +46,6 @@ renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
 }
 
 static void
-texture_unit_map_unmap(struct gl_context *ctx, struct gl_texture_unit *u, GLboolean map)
-{
-	if (!u->_ReallyEnabled)
-		return;
-
-	if (map)
-		ctx->Driver.MapTexture(ctx, u->_Current);
-	else
-		ctx->Driver.UnmapTexture(ctx, u->_Current);
-}
-
-static void
 framebuffer_map_unmap(struct gl_framebuffer *fb, GLboolean map)
 {
 	int i;
@@ -82,7 +70,10 @@ span_map_unmap(struct gl_context *ctx, GLboolean map)
 		framebuffer_map_unmap(ctx->ReadBuffer, map);
 
 	for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
-		texture_unit_map_unmap(ctx, &ctx->Texture.Unit[i], map);
+		if (map)
+			_swrast_map_texture(ctx, ctx->Texture.Unit[i]._Current);
+		else
+			_swrast_unmap_texture(ctx, ctx->Texture.Unit[i]._Current);
 }
 
 static void
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index b364f78..66c3cb2 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -680,31 +680,6 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
 	_mesa_unlock_texture(ctx, t);
 }
 
-static void
-nouveau_texture_map(struct gl_context *ctx, struct gl_texture_object *t)
-{
-	int i;
-
-	for (i = t->BaseLevel; i < t->_MaxLevel; i++) {
-		struct gl_texture_image *ti = t->Image[0][i];
-
-		if (ti)
-			nouveau_teximage_map(ctx, ti, GL_MAP_READ_BIT,
-					     0, 0, ti->Width, ti->Height);
-	}
-}
-
-static void
-nouveau_texture_unmap(struct gl_context *ctx, struct gl_texture_object *t)
-{
-	int i;
-
-	for (i = t->BaseLevel; i < t->_MaxLevel; i++) {
-		if (t->Image[0][i])
-			nouveau_teximage_unmap(ctx, t->Image[0][i]);
-	}
-}
-
 void
 nouveau_texture_functions_init(struct dd_function_table *functions)
 {
@@ -720,8 +695,6 @@ nouveau_texture_functions_init(struct dd_function_table *functions)
 	functions->TexSubImage2D = nouveau_texsubimage_2d;
 	functions->TexSubImage3D = nouveau_texsubimage_3d;
 	functions->BindTexture = nouveau_bind_texture;
-	functions->MapTexture = nouveau_texture_map;
-	functions->UnmapTexture = nouveau_texture_unmap;
 	functions->MapTextureImage = nouveau_map_texture_image;
 	functions->UnmapTextureImage = nouveau_unmap_texture_image;
 }
commit 765892865f77fb11815bc1f8a4536f0b2436c20d
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:55 2012 -0700

    tnl: remove ctx->Driver.Map/UnmapTexture() calls
    
    ctx->Driver.MapTexture() always points to _swrast_map_texture().
    We're already reaching into swrast from t_vb_program.c anyway.
    This will let us remove the ctx->Driver.Map/UnmapTexture() functions.
    (cherry picked from commit 4bbab2275f792553f8ed6bcebfe6acc4cb4179c2)

diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c
index 8b060ff..7687ae0 100644
--- a/src/mesa/tnl/t_vb_program.c
+++ b/src/mesa/tnl/t_vb_program.c
@@ -272,15 +272,12 @@ map_textures(struct gl_context *ctx, const struct gl_vertex_program *vp)
 {
    GLuint u;
 
-   if (!ctx->Driver.MapTexture)
-      return;
-
    for (u = 0; u < ctx->Const.MaxVertexTextureImageUnits; u++) {
       if (vp->Base.TexturesUsed[u]) {
          /* Note: _Current *should* correspond to the target indicated
           * in TexturesUsed[u].
           */
-         ctx->Driver.MapTexture(ctx, ctx->Texture.Unit[u]._Current);
+         _swrast_map_texture(ctx, ctx->Texture.Unit[u]._Current);
       }
    }
 }
@@ -294,15 +291,12 @@ unmap_textures(struct gl_context *ctx, const struct gl_vertex_program *vp)
 {
    GLuint u;
 
-   if (!ctx->Driver.MapTexture)
-      return;
-
    for (u = 0; u < ctx->Const.MaxVertexTextureImageUnits; u++) {
       if (vp->Base.TexturesUsed[u]) {
          /* Note: _Current *should* correspond to the target indicated
           * in TexturesUsed[u].
           */
-         ctx->Driver.UnmapTexture(ctx, ctx->Texture.Unit[u]._Current);
+         _swrast_unmap_texture(ctx, ctx->Texture.Unit[u]._Current);
       }
    }
 }
commit 9daa974d4d792b1cea84ef7676bec556e248c4b9
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:49 2012 -0700

    swrast: move some renderbuffer functions to s_renderbuffer.c
    (cherry picked from commit bde356a1580f52cae0aaca020a33a6437083a450)

diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 378e3a7..501b469 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -552,3 +552,124 @@ _swrast_add_soft_renderbuffers(struct gl_framebuffer *fb,
    }
 #endif
 }
+
+
+
+static void
+map_attachment(struct gl_context *ctx,
+                 struct gl_framebuffer *fb,
+                 gl_buffer_index buffer)
+{
+   struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
+   struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+
+   if (texObj) {
+      const GLuint level = fb->Attachment[buffer].TextureLevel;
+      const GLuint face = fb->Attachment[buffer].CubeMapFace;
+      struct gl_texture_image *texImage = texObj->Image[face][level];
+      if (texImage) {
+         struct swrast_texture_image *swImage
+            = swrast_texture_image(texImage);
+
+         /* XXX we'll eventually call _swrast_map_teximage() here */
+         swImage->Map = swImage->Buffer;
+         if (srb) {
+            srb->Map = swImage->Buffer;
+            srb->RowStride = swImage->RowStride *
+               _mesa_get_format_bytes(swImage->Base.TexFormat);
+         }
+      }
+   }
+   else if (rb) {
+      /* Map ordinary renderbuffer */
+      ctx->Driver.MapRenderbuffer(ctx, rb,
+                                  0, 0, rb->Width, rb->Height,
+                                  GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+                                  &srb->Map, &srb->RowStride);
+      assert(srb->Map);
+   }
+}
+ 
+
+static void
+unmap_attachment(struct gl_context *ctx,
+                   struct gl_framebuffer *fb,
+                   gl_buffer_index buffer)
+{
+   struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
+   struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+
+   if (texObj) {
+      const GLuint level = fb->Attachment[buffer].TextureLevel;
+      const GLuint face = fb->Attachment[buffer].CubeMapFace;
+      struct gl_texture_image *texImage = texObj->Image[face][level];
+      if (texImage) {
+
+         /* XXX we'll eventually call _swrast_unmap_teximage() here */
+       }
+    }
+   else if (rb) {
+      /* unmap ordinary renderbuffer */
+      ctx->Driver.UnmapRenderbuffer(ctx, rb);
+   }
+
+   srb->Map = NULL;
+}
+ 
+ 
+/**
+ * Map the renderbuffers we'll use for tri/line/point rendering.
+ */
+void
+_swrast_map_renderbuffers(struct gl_context *ctx)
+{
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+   struct gl_renderbuffer *depthRb, *stencilRb;
+   GLuint buf;
+
+   depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+   if (depthRb) {
+      /* map depth buffer */
+      map_attachment(ctx, fb, BUFFER_DEPTH);
+   }
+
+   stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+   if (stencilRb && stencilRb != depthRb) {
+      /* map stencil buffer */
+      map_attachment(ctx, fb, BUFFER_STENCIL);
+   }
+
+   for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
+      map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
+   }
+}
+ 
+ 
+/**
+ * Unmap renderbuffers after rendering.
+ */
+void
+_swrast_unmap_renderbuffers(struct gl_context *ctx)
+{
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+   struct gl_renderbuffer *depthRb, *stencilRb;
+   GLuint buf;
+
+   depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+   if (depthRb) {
+      /* map depth buffer */
+      unmap_attachment(ctx, fb, BUFFER_DEPTH);
+   }
+
+   stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+   if (stencilRb && stencilRb != depthRb) {
+      /* map stencil buffer */
+      unmap_attachment(ctx, fb, BUFFER_STENCIL);
+   }
+
+   for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
+      unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
+   }
+}
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 971b9fe..2c74261 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -315,127 +315,6 @@ _swrast_unmap_textures(struct gl_context *ctx)
 }
 
 
-static void
-map_attachment(struct gl_context *ctx,
-                 struct gl_framebuffer *fb,
-                 gl_buffer_index buffer)
-{
-   struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
-   struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
-   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
-
-   if (texObj) {
-      const GLuint level = fb->Attachment[buffer].TextureLevel;
-      const GLuint face = fb->Attachment[buffer].CubeMapFace;
-      struct gl_texture_image *texImage = texObj->Image[face][level];
-      if (texImage) {
-         struct swrast_texture_image *swImage
-            = swrast_texture_image(texImage);
-
-         /* XXX we'll eventually call _swrast_map_teximage() here */
-         swImage->Map = swImage->Buffer;
-         if (srb) {
-            srb->Map = swImage->Buffer;
-            srb->RowStride = swImage->RowStride *
-               _mesa_get_format_bytes(swImage->Base.TexFormat);
-         }
-      }
-   }
-   else if (rb) {
-      /* Map ordinary renderbuffer */
-      ctx->Driver.MapRenderbuffer(ctx, rb,
-                                  0, 0, rb->Width, rb->Height,
-                                  GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
-                                  &srb->Map, &srb->RowStride);
-      assert(srb->Map);
-   }
-}
- 
-
-static void
-unmap_attachment(struct gl_context *ctx,
-                   struct gl_framebuffer *fb,
-                   gl_buffer_index buffer)
-{
-   struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
-   struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
-   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
-
-   if (texObj) {
-      const GLuint level = fb->Attachment[buffer].TextureLevel;
-      const GLuint face = fb->Attachment[buffer].CubeMapFace;
-      struct gl_texture_image *texImage = texObj->Image[face][level];
-      if (texImage) {
-
-         /* XXX we'll eventually call _swrast_unmap_teximage() here */
-       }
-    }
-   else if (rb) {
-      /* unmap ordinary renderbuffer */
-      ctx->Driver.UnmapRenderbuffer(ctx, rb);
-   }
-
-   srb->Map = NULL;
-}
- 
- 
-/**
- * Map the renderbuffers we'll use for tri/line/point rendering.
- */
-void
-_swrast_map_renderbuffers(struct gl_context *ctx)
-{
-   struct gl_framebuffer *fb = ctx->DrawBuffer;
-   struct gl_renderbuffer *depthRb, *stencilRb;
-   GLuint buf;
-
-   depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
-   if (depthRb) {
-      /* map depth buffer */
-      map_attachment(ctx, fb, BUFFER_DEPTH);
-   }
-
-   stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
-   if (stencilRb && stencilRb != depthRb) {
-      /* map stencil buffer */
-      map_attachment(ctx, fb, BUFFER_STENCIL);
-   }
-
-   for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
-      map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
-   }
-}
- 
- 
-/**
- * Unmap renderbuffers after rendering.
- */
-void
-_swrast_unmap_renderbuffers(struct gl_context *ctx)
-{
-   struct gl_framebuffer *fb = ctx->DrawBuffer;
-   struct gl_renderbuffer *depthRb, *stencilRb;
-   GLuint buf;
-
-   depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
-   if (depthRb) {
-      /* map depth buffer */
-      unmap_attachment(ctx, fb, BUFFER_DEPTH);
-   }
-
-   stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
-   if (stencilRb && stencilRb != depthRb) {
-      /* map stencil buffer */
-      unmap_attachment(ctx, fb, BUFFER_STENCIL);
-   }
-
-   for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
-      unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
-   }
-}
- 
-
-
 /**
  * Called via ctx->Driver.AllocTextureStorage()
  * Just have to allocate memory for the texture images.
commit 05adf4d6e44419eb650dc767929df9bf42d923a5
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:44 2012 -0700

    intel: remove intel_span_supports_format()
    
    It always returned True.
    (cherry picked from commit 1839a7fc9faae81d32ffc0cdc908b933f4524e28)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 0bb61b5..3a35a01 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -833,14 +833,6 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 	     _mesa_get_format_name(intel_rb_format(irb)));
 	 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
       }
-
-#ifdef I915
-      if (!intel_span_supports_format(intel_rb_format(irb))) {
-	 DBG("Unsupported swrast texture/renderbuffer format attached: %s\n",
-	     _mesa_get_format_name(intel_rb_format(irb)));
-	 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
-      }
-#endif
    }
 }
 
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 9b6540d..2090e51 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -332,15 +332,3 @@ intel_unmap_vertex_shader_textures(struct gl_context *ctx)
       }
    }
 }
-
-
-bool
-intel_span_supports_format(gl_format format)
-{
-   /* Rendering to/from integer textures will be done using MapRenderbuffer,
-    * rather than coding up new paths through GetRow/PutRow(), so claim support
-    * for those formats in here for now.
-    */
-   return true;
-}
-
diff --git a/src/mesa/drivers/dri/intel/intel_span.h b/src/mesa/drivers/dri/intel/intel_span.h
index 6640e15..b2bd416 100644
--- a/src/mesa/drivers/dri/intel/intel_span.h
+++ b/src/mesa/drivers/dri/intel/intel_span.h
@@ -38,7 +38,6 @@ extern void intelSpanRenderStart(struct gl_context * ctx);
 
 void intel_map_vertex_shader_textures(struct gl_context *ctx);
 void intel_unmap_vertex_shader_textures(struct gl_context *ctx);
-bool intel_span_supports_format(gl_format format);
 intptr_t intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y);
 
 #endif
commit eca54b1eb442abec1d42a81171dc7da15f691627
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:41 2012 -0700

    swrast: remove a few extra _mesa_get_format_bytes() calls
    (cherry picked from commit 6c1e27ba219e41ae2641cca0d3c67462bdba8631)

diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index f0dbb01..378e3a7 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -58,6 +58,7 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
                           GLuint width, GLuint height)
 {
    struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+   GLuint bpp;
 
    switch (internalFormat) {
    case GL_RGB:
@@ -115,25 +116,26 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       return GL_FALSE;
    }
 
+   bpp = _mesa_get_format_bytes(rb->Format);
+
    /* free old buffer storage */
    if (srb->Buffer) {
       free(srb->Buffer);
       srb->Buffer = NULL;
    }
 
-   srb->RowStride = width * _mesa_get_format_bytes(rb->Format);
+   srb->RowStride = width * bpp;
 
    if (width > 0 && height > 0) {
       /* allocate new buffer storage */
-      srb->Buffer = malloc(width * height
-                           * _mesa_get_format_bytes(rb->Format));
+      srb->Buffer = malloc(srb->RowStride * height);
 
       if (srb->Buffer == NULL) {
          rb->Width = 0;
          rb->Height = 0;
          _mesa_error(ctx, GL_OUT_OF_MEMORY,
                      "software renderbuffer allocation (%d x %d x %d)",
-                     width, height, _mesa_get_format_bytes(rb->Format));
+                     width, height, bpp);
          return GL_FALSE;
       }
    }
commit 8e5cf4cb45b2a2cc989530d17933228ec86cfe1a
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:36 2012 -0700

    mesa: update comments for gl_renderbuffer
    (cherry picked from commit 1da7d6c919e9a6d756b208caa6685bfa1146b543)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index fb69e40..30c5475 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2511,39 +2511,32 @@ struct gl_shared_state
 
 
 
-
 /**
- * A renderbuffer stores colors or depth values or stencil values.
- * A framebuffer object will have a collection of these.
- * Data are read/written to the buffer with a handful of Get/Put functions.
- *
- * Instances of this object are allocated with the Driver's NewRenderbuffer
- * hook.  Drivers will likely wrap this class inside a driver-specific
- * class to simulate inheritance.
+ * Renderbuffers represent drawing surfaces such as color, depth and/or
+ * stencil.  A framebuffer object has a set of renderbuffers.
+ * Drivers will typically derive subclasses of this type.
  */
 struct gl_renderbuffer
 {
-   _glthread_Mutex Mutex;		   /**< for thread safety */
+   _glthread_Mutex Mutex; /**< for thread safety */
    GLuint ClassID;        /**< Useful for drivers */
    GLuint Name;
    GLint RefCount;
    GLuint Width, Height;
-   GLboolean Purgeable;   /**< Is the buffer purgeable under memory pressure? */
-
+   GLboolean Purgeable;  /**< Is the buffer purgeable under memory pressure? */
    GLboolean AttachedAnytime; /**< TRUE if it was attached to a framebuffer */
-
    GLubyte NumSamples;
-
    GLenum InternalFormat; /**< The user-specified format */
    GLenum _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
                                GL_STENCIL_INDEX. */
    gl_format Format;      /**< The actual renderbuffer memory format */
 
-   /* Delete this renderbuffer */
+   /** Delete this renderbuffer */
    void (*Delete)(struct gl_renderbuffer *rb);
 
-   /* Allocate new storage for this renderbuffer */
-   GLboolean (*AllocStorage)(struct gl_context *ctx, struct gl_renderbuffer *rb,
+   /** Allocate new storage for this renderbuffer */
+   GLboolean (*AllocStorage)(struct gl_context *ctx,
+                             struct gl_renderbuffer *rb,
                              GLenum internalFormat,
                              GLuint width, GLuint height);
 };
commit 1fd179b9840e47f0e904183398116f451220b8cb
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:05:07 2012 -0700

    mesa/swrast/drivers: remove obsolete gl_renderbuffer fields
    
    This removes the last of the legacy fields from gl_renderbuffer.
    (cherry picked from commit 1888dd52a32e114e7b3796db5a6b44921a2e04d4)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index fc66791..fb69e40 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2539,13 +2539,6 @@ struct gl_renderbuffer
                                GL_STENCIL_INDEX. */
    gl_format Format;      /**< The actual renderbuffer memory format */
 
-   /* XXX the following fields are obsolete and wil go away */
-   GLvoid *Buffer;        /**< Malloc'd memory for software buffers */
-
-   /** The following fields are only valid while the buffer is mapped */
-   GLubyte *Map;
-   GLint RowStrideBytes;
-
    /* Delete this renderbuffer */
    void (*Delete)(struct gl_renderbuffer *rb);
 
commit 843194d89fe3686ff3de85eb5aff3893917864b7
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:03:28 2012 -0700

    dri/swrast: use swrast_renderbuffer type
    (cherry picked from commit becbb643135ddccac5054bf138ca0cc7cc3fff15)

diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 5f25d33..d18dd09 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -263,10 +263,12 @@ choose_pixel_format(const struct gl_config *v)
 static void
 swrast_delete_renderbuffer(struct gl_renderbuffer *rb)
 {
+    struct dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
+
     TRACE;
 
-    free(rb->Buffer);
-    free(rb);
+    free(xrb->Base.Buffer);
+    free(xrb);
 }
 
 /* see bytes_per_line in libGL */
@@ -289,7 +291,7 @@ swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
     (void) ctx;
     (void) internalFormat;
 
-    rb->Buffer = NULL;
+    xrb->Base.Buffer = NULL;
     rb->Width = width;
     rb->Height = height;
     xrb->pitch = bytes_per_line(width * xrb->bpp, 32);
@@ -305,11 +307,11 @@ swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
     TRACE;
 
-    free(rb->Buffer);
+    free(xrb->Base.Buffer);
 
     swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
 
-    rb->Buffer = malloc(height * xrb->pitch);
+    xrb->Base.Buffer = malloc(height * xrb->pitch);
 
     return GL_TRUE;
 }
@@ -319,6 +321,7 @@ swrast_new_renderbuffer(const struct gl_config *visual, __DRIdrawable *dPriv,
 			GLboolean front)
 {
     struct dri_swrast_renderbuffer *xrb = calloc(1, sizeof *xrb);
+    struct gl_renderbuffer *rb;
     GLuint pixel_format;
 
     TRACE;
@@ -326,42 +329,44 @@ swrast_new_renderbuffer(const struct gl_config *visual, __DRIdrawable *dPriv,
     if (!xrb)
 	return NULL;
 
-    _mesa_init_renderbuffer(&xrb->Base, 0);
+    rb = &xrb->Base.Base;
+
+    _mesa_init_renderbuffer(rb, 0);
 
     pixel_format = choose_pixel_format(visual);
 
     xrb->dPriv = dPriv;
-    xrb->Base.Delete = swrast_delete_renderbuffer;
+    xrb->Base.Base.Delete = swrast_delete_renderbuffer;
     if (front) {
-	xrb->Base.AllocStorage = swrast_alloc_front_storage;
+        rb->AllocStorage = swrast_alloc_front_storage;
     }
     else {
-	xrb->Base.AllocStorage = swrast_alloc_back_storage;
+	rb->AllocStorage = swrast_alloc_back_storage;
     }
 
     switch (pixel_format) {
     case PF_A8R8G8B8:
-	xrb->Base.Format = MESA_FORMAT_ARGB8888;
-	xrb->Base.InternalFormat = GL_RGBA;
-	xrb->Base._BaseFormat = GL_RGBA;
+	rb->Format = MESA_FORMAT_ARGB8888;
+	rb->InternalFormat = GL_RGBA;
+	rb->_BaseFormat = GL_RGBA;
 	xrb->bpp = 32;
 	break;
     case PF_X8R8G8B8:
-	xrb->Base.Format = MESA_FORMAT_ARGB8888; /* XXX */
-	xrb->Base.InternalFormat = GL_RGB;
-	xrb->Base._BaseFormat = GL_RGB;
+	rb->Format = MESA_FORMAT_ARGB8888; /* XXX */
+	rb->InternalFormat = GL_RGB;
+	rb->_BaseFormat = GL_RGB;
 	xrb->bpp = 32;
 	break;
     case PF_R5G6B5:
-	xrb->Base.Format = MESA_FORMAT_RGB565;
-	xrb->Base.InternalFormat = GL_RGB;
-	xrb->Base._BaseFormat = GL_RGB;
+	rb->Format = MESA_FORMAT_RGB565;
+	rb->InternalFormat = GL_RGB;
+	rb->_BaseFormat = GL_RGB;
 	xrb->bpp = 16;
 	break;
     case PF_R3G3B2:
-	xrb->Base.Format = MESA_FORMAT_RGB332;
-	xrb->Base.InternalFormat = GL_RGB;
-	xrb->Base._BaseFormat = GL_RGB;
+	rb->Format = MESA_FORMAT_RGB332;
+	rb->InternalFormat = GL_RGB;
+	rb->_BaseFormat = GL_RGB;
 	xrb->bpp = 8;
 	break;
     default:
@@ -380,7 +385,7 @@ swrast_map_renderbuffer(struct gl_context *ctx,
 			GLint *out_stride)
 {
    struct dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
-   GLubyte *map = rb->Buffer;
+   GLubyte *map = xrb->Base.Buffer;
    int cpp = _mesa_get_format_bytes(rb->Format);
    int stride = rb->Width * cpp;
 
@@ -395,18 +400,18 @@ swrast_map_renderbuffer(struct gl_context *ctx,
       xrb->map_h = h;
 
       stride = w * cpp;
-      rb->Buffer = malloc(h * stride);
+      xrb->Base.Buffer = malloc(h * stride);
 
       sPriv->swrast_loader->getImage(dPriv, x, y, w, h,
-				     (char *)rb->Buffer,
+				     (char *) xrb->Base.Buffer,
 				     dPriv->loaderPrivate);
 
-      *out_map = rb->Buffer;
+      *out_map = xrb->Base.Buffer;
       *out_stride = stride;
       return;
    }
 
-   ASSERT(rb->Buffer);
+   ASSERT(xrb->Base.Buffer);
 
    if (rb->AllocStorage == swrast_alloc_back_storage) {
       map += (rb->Height - 1) * stride;
@@ -434,12 +439,12 @@ swrast_unmap_renderbuffer(struct gl_context *ctx,
 	 sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_DRAW,
 					xrb->map_x, xrb->map_y,
 					xrb->map_w, xrb->map_h,
-					rb->Buffer,
+					(char *) xrb->Base.Buffer,
 					dPriv->loaderPrivate);
       }
 
-      free(rb->Buffer);
-      rb->Buffer = NULL;
+      free(xrb->Base.Buffer);
+      xrb->Base.Buffer = NULL;
    }
 }
 
@@ -475,12 +480,12 @@ dri_create_buffer(__DRIscreen * sPriv,
 
     /* add front renderbuffer */
     frontrb = swrast_new_renderbuffer(visual, dPriv, GL_TRUE);
-    _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base);
+    _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base.Base);
 
     /* add back renderbuffer */
     if (visual->doubleBufferMode) {
 	backrb = swrast_new_renderbuffer(visual, dPriv, GL_FALSE);
-	_mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base);
+	_mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base.Base);
     }
 
     /* add software renderbuffers */
@@ -554,9 +559,9 @@ dri_swap_buffers(__DRIdrawable * dPriv)
 
     sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
 				   0, 0,
-				   frontrb->Base.Width,
-				   frontrb->Base.Height,
-				   backrb->Base.Buffer,
+				   frontrb->Base.Base.Width,
+				   frontrb->Base.Base.Height,
+				   (char *) backrb->Base.Buffer,
 				   dPriv->loaderPrivate);
 }
 
diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h
index aa1979c..b25de93 100644
--- a/src/mesa/drivers/dri/swrast/swrast_priv.h
+++ b/src/mesa/drivers/dri/swrast/swrast_priv.h
@@ -31,6 +31,7 @@
 #include <GL/internal/dri_interface.h>
 #include "main/mtypes.h"
 #include "dri_util.h"
+#include "swrast/s_context.h"
 
 
 /**
@@ -101,7 +102,7 @@ swrast_drawable(struct gl_framebuffer *fb)
 }
 
 struct dri_swrast_renderbuffer {
-    struct gl_renderbuffer Base;
+    struct swrast_renderbuffer Base;
     __DRIdrawable *dPriv;
 
     /* GL_MAP_*_BIT, used for mapping of front buffer. */
commit 7c95a4ec2266e1c2e35a39df30b9c7066fd05c70
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:02:19 2012 -0700

    swrast: use swrast_renderbuffer instead of gl_renderbuffer
    (cherry picked from commit 0c1862851f27c428a18ba5509636efcc2f0084f8)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index f03f048..2fb61ea 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -453,8 +453,9 @@ _swrast_unmap_renderbuffers(struct gl_context *ctx);
 static inline GLubyte *
 _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStrideBytes;
+   const GLint rowStride = srb->RowStride;
    assert(x >= 0);
    assert(y >= 0);
    /* NOTE: using <= only because of s_tritemp.h which gets a pixel
@@ -462,8 +463,8 @@ _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
     */
    assert(x <= (GLint) rb->Width);
    assert(y <= (GLint) rb->Height);
-   assert(rb->Map);
-   return (GLubyte *) rb->Map + y * rowStride + x * bpp;
+   assert(srb->Map);
+   return (GLubyte *) srb->Map + y * rowStride + x * bpp;
 }
 
 
diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 91541d2..592d35a 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -567,6 +567,7 @@ map_readbuffer(struct gl_context *ctx, GLenum type)
 {
    struct gl_framebuffer *fb = ctx->ReadBuffer;
    struct gl_renderbuffer *rb;
+   struct swrast_renderbuffer *srb;
 
    switch (type) {
    case GL_COLOR:
@@ -583,7 +584,9 @@ map_readbuffer(struct gl_context *ctx, GLenum type)
       return NULL;
    }
 
-   if (!rb || rb->Map) {
+   srb = swrast_renderbuffer(rb);
+
+   if (!srb || srb->Map) {
       /* no buffer, or buffer is mapped already, we're done */
       return NULL;
    }
@@ -591,7 +594,7 @@ map_readbuffer(struct gl_context *ctx, GLenum type)
    ctx->Driver.MapRenderbuffer(ctx, rb,
                                0, 0, rb->Width, rb->Height,
                                GL_MAP_READ_BIT,
-                               &rb->Map, &rb->RowStrideBytes);
+                               &srb->Map, &srb->RowStride);
 
    return rb;
 }
@@ -650,7 +653,8 @@ _swrast_CopyPixels( struct gl_context *ctx,
    swrast_render_finish(ctx);
 
    if (rb) {
+      struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
       ctx->Driver.UnmapRenderbuffer(ctx, rb);
-      rb->Map = NULL;
+      srb->Map = NULL;
    }
 }
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 0788644..1336407 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -212,12 +212,13 @@ get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
                GLuint count, const GLint x[], const GLint y[],
                GLuint zbuffer[])
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    const GLint w = rb->Width, h = rb->Height;
    const GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
-      const GLint rowStride = rb->RowStrideBytes;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             zbuffer[i] = *((GLuint *) (map + y[i] * rowStride + x[i] * 4));
@@ -226,7 +227,7 @@ get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else {
       const GLint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLint rowStride = rb->RowStrideBytes;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             const GLubyte *src = map + y[i] * rowStride+ x[i] * bpp;
@@ -246,12 +247,13 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
                GLuint count, const GLint x[], const GLint y[],
                const GLuint zvalues[], const GLubyte mask[])
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    const GLint w = rb->Width, h = rb->Height;
    GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
-      const GLuint rowStride = rb->RowStrideBytes;
+      const GLuint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             GLuint *dst = (GLuint *) (map + y[i] * rowStride + x[i] * 4);
@@ -262,7 +264,7 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    else {
       gl_pack_uint_z_func packZ = _mesa_get_pack_uint_z_func(rb->Format);
       const GLint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLint rowStride = rb->RowStrideBytes;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             void *dst = map + y[i] * rowStride + x[i] * bpp;
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 5050ad9..c5466dd 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -513,6 +513,7 @@ fast_draw_depth_stencil(struct gl_context *ctx, GLint x, GLint y,
    const GLenum type = GL_UNSIGNED_INT_24_8;
    struct gl_renderbuffer *rb =
       ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    GLubyte *src, *dst;
    GLint srcRowStride, dstRowStride;
    GLint i;
@@ -522,7 +523,7 @@ fast_draw_depth_stencil(struct gl_context *ctx, GLint x, GLint y,
    srcRowStride = _mesa_image_row_stride(unpack, width, format, type);
 
    dst = _swrast_pixel_address(rb, x, y);
-   dstRowStride = rb->RowStrideBytes;
+   dstRowStride = srb->RowStride;
 
    for (i = 0; i < height; i++) {
       _mesa_pack_uint_24_8_depth_stencil_row(rb->Format, width,
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index af02b02..f0dbb01 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -37,6 +37,7 @@
 #include "main/formats.h"
 #include "main/mtypes.h"
 #include "main/renderbuffer.h"
+#include "swrast/s_context.h"
 #include "swrast/s_renderbuffer.h"
 
 
@@ -56,6 +57,8 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
                           GLenum internalFormat,
                           GLuint width, GLuint height)
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+
    switch (internalFormat) {
    case GL_RGB:
    case GL_R3_G3_B2:
@@ -113,18 +116,19 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
 
    /* free old buffer storage */
-   if (rb->Buffer) {
-      free(rb->Buffer);
-      rb->Buffer = NULL;
+   if (srb->Buffer) {
+      free(srb->Buffer);
+      srb->Buffer = NULL;
    }
 
-   rb->RowStrideBytes = width * _mesa_get_format_bytes(rb->Format);
+   srb->RowStride = width * _mesa_get_format_bytes(rb->Format);
 
    if (width > 0 && height > 0) {
       /* allocate new buffer storage */
-      rb->Buffer = malloc(width * height * _mesa_get_format_bytes(rb->Format));
+      srb->Buffer = malloc(width * height
+                           * _mesa_get_format_bytes(rb->Format));
 
-      if (rb->Buffer == NULL) {
+      if (srb->Buffer == NULL) {
          rb->Width = 0;
          rb->Height = 0;
          _mesa_error(ctx, GL_OUT_OF_MEMORY,
@@ -162,11 +166,13 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 static void
 soft_renderbuffer_delete(struct gl_renderbuffer *rb)
 {
-   if (rb->Buffer) {
-      free(rb->Buffer);
-      rb->Buffer = NULL;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+
+   if (srb->Buffer) {
+      free(srb->Buffer);
+      srb->Buffer = NULL;
    }
-   free(rb);
+   free(srb);
 }
 
 
@@ -178,7 +184,8 @@ _swrast_map_soft_renderbuffer(struct gl_context *ctx,
                               GLubyte **out_map,
                               GLint *out_stride)
 {
-   GLubyte *map = rb->Buffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+   GLubyte *map = srb->Buffer;
    int cpp = _mesa_get_format_bytes(rb->Format);
    int stride = rb->Width * cpp;
 
@@ -212,12 +219,13 @@ _swrast_unmap_soft_renderbuffer(struct gl_context *ctx,
 struct gl_renderbuffer *
 _swrast_new_soft_renderbuffer(struct gl_context *ctx, GLuint name)
 {
-   struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, name);
-   if (rb) {
-      rb->AllocStorage = soft_renderbuffer_storage;
-      rb->Delete = soft_renderbuffer_delete;
+   struct swrast_renderbuffer *srb = CALLOC_STRUCT(swrast_renderbuffer);
+   if (srb) {
+      _mesa_init_renderbuffer(&srb->Base, name);
+      srb->Base.AllocStorage = soft_renderbuffer_storage;
+      srb->Base.Delete = soft_renderbuffer_delete;
    }
-   return rb;
+   return &srb->Base;
 }
 
 
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index dd70412..819fe4b 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1395,6 +1395,7 @@ _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
                         GLuint n, GLint x, GLint y,
                         GLvoid *rgba)
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    GLenum dstType = GL_FLOAT;
    const GLint bufWidth = (GLint) rb->Width;
    const GLint bufHeight = (GLint) rb->Height;
@@ -1445,7 +1446,7 @@ _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
 	     rb->_BaseFormat == GL_LUMINANCE_ALPHA ||
 	     rb->_BaseFormat == GL_ALPHA);
 
-      assert(rb->Map);
+      assert(srb->Map);
 
       src = _swrast_pixel_address(rb, x + skip, y);
 
diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 9aa7ffc..bbfbf44 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -292,12 +292,13 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
               GLuint count, const GLint x[], const GLint y[],
               GLubyte stencil[])
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    const GLint w = rb->Width, h = rb->Height;
    const GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_S8) {
-      const GLint rowStride = rb->RowStrideBytes;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             stencil[i] = *(map + y[i] * rowStride + x[i]);
@@ -306,7 +307,7 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else {
       const GLint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLint rowStride = rb->RowStrideBytes;
+      const GLint rowStride = srb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 23a7388..140e4b5 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -62,6 +62,7 @@ static void
 update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 {
    struct gl_renderbuffer *rb = att->Renderbuffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    struct swrast_texture_image *swImage;
    gl_format format;
    GLuint zOffset;
@@ -93,11 +94,11 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
      */
    if (att->Texture->Target == GL_TEXTURE_3D ||
        att->Texture->Target == GL_TEXTURE_2D_ARRAY_EXT) {
-      rb->Buffer = swImage->Buffer +
+      srb->Buffer = swImage->Buffer +
          swImage->ImageOffsets[zOffset] * _mesa_get_format_bytes(format);
    }
    else {
-      rb->Buffer = swImage->Buffer;
+      srb->Buffer = swImage->Buffer;
    }
 }
 
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 7c45126..971b9fe 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -322,6 +322,7 @@ map_attachment(struct gl_context *ctx,
 {
    struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
    struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
 
    if (texObj) {
       const GLuint level = fb->Attachment[buffer].TextureLevel;
@@ -333,20 +334,20 @@ map_attachment(struct gl_context *ctx,
 
          /* XXX we'll eventually call _swrast_map_teximage() here */
          swImage->Map = swImage->Buffer;
-         if (rb) {
-            rb->Map = swImage->Buffer;
-            rb->RowStrideBytes = swImage->RowStride *
+         if (srb) {
+            srb->Map = swImage->Buffer;
+            srb->RowStride = swImage->RowStride *
                _mesa_get_format_bytes(swImage->Base.TexFormat);
          }
       }
    }
    else if (rb) {
       /* Map ordinary renderbuffer */
-         ctx->Driver.MapRenderbuffer(ctx, rb,
-                                     0, 0, rb->Width, rb->Height,
-                                     GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
-                                     &rb->Map, &rb->RowStrideBytes);
-         assert(rb->Map);
+      ctx->Driver.MapRenderbuffer(ctx, rb,
+                                  0, 0, rb->Width, rb->Height,
+                                  GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+                                  &srb->Map, &srb->RowStride);
+      assert(srb->Map);
    }
 }
  
@@ -358,6 +359,7 @@ unmap_attachment(struct gl_context *ctx,
 {
    struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
    struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
 
    if (texObj) {
       const GLuint level = fb->Attachment[buffer].TextureLevel;
@@ -373,7 +375,7 @@ unmap_attachment(struct gl_context *ctx,
       ctx->Driver.UnmapRenderbuffer(ctx, rb);
    }
 
-   rb->Map = NULL;
+   srb->Map = NULL;
 }
  
  
commit 9567178ca2be19ff2b03dae382439073e729daea
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 13:01:35 2012 -0700

    osmesa: use swrast_renderbuffer
    (cherry picked from commit 797c18be1f907337ebd85b18ce43dfa0b056f492)

diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 1c4f52b..0a42741 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -67,7 +67,7 @@ struct osmesa_context
 {
    struct gl_context mesa;		/*< Base class - this must be first */
    struct gl_config *gl_visual;		/*< Describes the buffers */
-   struct gl_renderbuffer *rb;  /*< The user's colorbuffer */
+   struct swrast_renderbuffer *srb;     /*< The user's colorbuffer */
    struct gl_framebuffer *gl_buffer;	/*< The framebuffer, containing user's rb */
    GLenum format;		/*< User-specified context format */
    GLint userRowLength;		/*< user-specified number of pixels per row */
@@ -354,16 +354,16 @@ static void
 compute_row_addresses( OSMesaContext osmesa )
 {
    GLint bytesPerRow, i;
-   GLubyte *origin = (GLubyte *) osmesa->rb->Buffer;
+   GLubyte *origin = (GLubyte *) osmesa->srb->Buffer;
    GLint rowlength; /* in pixels */
-   GLint height = osmesa->rb->Height;
+   GLint height = osmesa->srb->Base.Height;
 
    if (osmesa->userRowLength)
       rowlength = osmesa->userRowLength;
    else
-      rowlength = osmesa->rb->Width;
+      rowlength = osmesa->srb->Base.Width;
 
-   bytesPerRow = rowlength * _mesa_get_format_bytes(osmesa->rb->Format);
+   bytesPerRow = rowlength * _mesa_get_format_bytes(osmesa->srb->Base.Format);
 
    if (osmesa->yup) {
       /* Y=0 is bottom line of window */
@@ -505,21 +505,25 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 /**
  * Allocate a new renderbuffer to describe the user-provided color buffer.
  */
-static struct gl_renderbuffer *
+static struct swrast_renderbuffer *
 new_osmesa_renderbuffer(struct gl_context *ctx, GLenum format, GLenum type)
 {
    const GLuint name = 0;
-   struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, name);
-   if (rb) {
-      rb->RefCount = 1;
-      rb->Delete = osmesa_delete_renderbuffer;
-      rb->AllocStorage = osmesa_renderbuffer_storage;
-      rb->ClassID = OSMESA_RENDERBUFFER_CLASS;
-
-      rb->InternalFormat = GL_RGBA;
-      rb->_BaseFormat = GL_RGBA;
+   struct swrast_renderbuffer *srb = CALLOC_STRUCT(swrast_renderbuffer);
+
+   if (srb) {
+      _mesa_init_renderbuffer(&srb->Base, name);
+
+      srb->Base.ClassID = OSMESA_RENDERBUFFER_CLASS;
+      srb->Base.Delete = osmesa_delete_renderbuffer;
+      srb->Base.AllocStorage = osmesa_renderbuffer_storage;
+
+      srb->Base.InternalFormat = GL_RGBA;
+      srb->Base._BaseFormat = GL_RGBA;
+
+      return srb;
    }
-   return rb;
+   return NULL;
 }
 
 
@@ -535,6 +539,7 @@ osmesa_MapRenderbuffer(struct gl_context *ctx,
 
    if (rb->ClassID == OSMESA_RENDERBUFFER_CLASS) {
       /* this is an OSMesa renderbuffer which wraps user memory */
+      struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
       const GLuint bpp = _mesa_get_format_bytes(rb->Format);
       GLint rowStride; /* in bytes */
 
@@ -552,7 +557,7 @@ osmesa_MapRenderbuffer(struct gl_context *ctx,
          *rowStrideOut = rowStride;
       }
 
-      *mapOut = (GLubyte *) rb->Data + y * rowStride + x * bpp;
+      *mapOut = (GLubyte *) srb->Buffer + y * rowStride + x * bpp;
    }
    else {
       _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
@@ -795,8 +800,8 @@ GLAPI void GLAPIENTRY
 OSMesaDestroyContext( OSMesaContext osmesa )
 {
    if (osmesa) {
-      if (osmesa->rb)
-         _mesa_reference_renderbuffer(&osmesa->rb, NULL);
+      if (osmesa->srb)
+         _mesa_reference_renderbuffer((struct gl_renderbuffer **) &osmesa->srb, NULL);
 
       _mesa_meta_free( &osmesa->mesa );
 
@@ -879,11 +884,12 @@ OSMesaMakeCurrent( OSMesaContext osmesa, void *buffer, GLenum type,
     * that converts rendering from CHAN_BITS to the user-requested channel
     * size.
     */
-   if (!osmesa->rb) {
-      osmesa->rb = new_osmesa_renderbuffer(&osmesa->mesa, osmesa->format, type);
+   if (!osmesa->srb) {
+      osmesa->srb = new_osmesa_renderbuffer(&osmesa->mesa, osmesa->format, type);
       _mesa_remove_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT);
-      _mesa_add_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT, osmesa->rb);
-      assert(osmesa->rb->RefCount == 2);
+      _mesa_add_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT,
+                             &osmesa->srb->Base);
+      assert(osmesa->srb->Base.RefCount == 2);
    }
 
    osmesa->DataType = type;
@@ -891,8 +897,8 @@ OSMesaMakeCurrent( OSMesaContext osmesa, void *buffer, GLenum type,
    /* Set renderbuffer fields.  Set width/height = 0 to force 
     * osmesa_renderbuffer_storage() being called by _mesa_resize_framebuffer()
     */
-   osmesa->rb->Buffer = buffer;
-   osmesa->rb->Width = osmesa->rb->Height = 0;
+   osmesa->srb->Buffer = buffer;
+   osmesa->srb->Base.Width = osmesa->srb->Base.Height = 0;
 
    /* Set the framebuffer's size.  This causes the
     * osmesa_renderbuffer_storage() function to get called.
@@ -906,7 +912,8 @@ OSMesaMakeCurrent( OSMesaContext osmesa, void *buffer, GLenum type,
     * renderbuffer adaptor/wrapper if needed (for bpp conversion).
     */
    _mesa_remove_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT);
-   _mesa_add_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT, osmesa->rb);
+   _mesa_add_renderbuffer(osmesa->gl_buffer, BUFFER_FRONT_LEFT,
+                          &osmesa->srb->Base);
 
 
    /* this updates the visual's red/green/blue/alphaBits fields */
@@ -981,12 +988,7 @@ OSMesaGetIntegerv( GLint pname, GLint *value )
          return;
       case OSMESA_TYPE:
          /* current color buffer's data type */
-         if (osmesa->rb) {
-            *value = osmesa->DataType;
-         }
-         else {
-            *value = 0;
-         }
+         *value = osmesa->DataType;
          return;
       case OSMESA_ROW_LENGTH:
          *value = osmesa->userRowLength;
@@ -1019,12 +1021,13 @@ GLAPI GLboolean GLAPIENTRY
 OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
                       GLint *bytesPerValue, void **buffer )
 {
-   struct gl_renderbuffer *rb = NULL;
+   struct swrast_renderbuffer *srb = NULL;
 
    if (c->gl_buffer)
-      rb = c->gl_buffer->Attachment[BUFFER_DEPTH].Renderbuffer;
+      srb = swrast_renderbuffer(c->gl_buffer->
+                                Attachment[BUFFER_DEPTH].Renderbuffer);
 
-   if (!rb || !rb->Buffer) {
+   if (!srb || !srb->Buffer) {
       *width = 0;
       *height = 0;
       *bytesPerValue = 0;
@@ -1032,13 +1035,13 @@ OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
       return GL_FALSE;
    }
    else {
-      *width = rb->Width;
-      *height = rb->Height;
+      *width = srb->Base.Width;
+      *height = srb->Base.Height;
       if (c->gl_visual->depthBits <= 16)
          *bytesPerValue = sizeof(GLushort);
       else
          *bytesPerValue = sizeof(GLuint);
-      *buffer = (void *) rb->Buffer;
+      *buffer = (void *) srb->Buffer;
       return GL_TRUE;
    }
 }
@@ -1056,11 +1059,11 @@ GLAPI GLboolean GLAPIENTRY
 OSMesaGetColorBuffer( OSMesaContext osmesa, GLint *width,
                       GLint *height, GLint *format, void **buffer )
 {
-   if (osmesa->rb && osmesa->rb->Buffer) {
-      *width = osmesa->rb->Width;
-      *height = osmesa->rb->Height;
+   if (osmesa->srb && osmesa->srb->Buffer) {
+      *width = osmesa->srb->Base.Width;
+      *height = osmesa->srb->Base.Height;
       *format = osmesa->format;
-      *buffer = (void *) osmesa->rb->Buffer;
+      *buffer = (void *) osmesa->srb->Buffer;
       return GL_TRUE;
    }
    else {
commit 83602e83424926677af462c87d0b6c273ad82492
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:52:21 2012 -0700

    radeon: derive radeon_renderbuffer from swrast_renderbuffer
    (cherry picked from commit c080202db5363a18a759a9a7c82b40ac558c8abe)

diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c
index 49f66fb..5677a9e 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -1619,8 +1619,8 @@ void r200_vtbl_update_scissor( struct gl_context *ctx )
       rrb = radeon_get_colorbuffer(&r200->radeon);
       x1 = 0;
       y1 = 0;
-      x2 = rrb->base.Width - 1;
-      y2 = rrb->base.Height - 1;
+      x2 = rrb->base.Base.Width - 1;
+      y2 = rrb->base.Base.Height - 1;
    }
 
    R200_SET_STATE(r200, sci, SCI_XY_1, x1 | (y1 << 16));
diff --git a/src/mesa/drivers/dri/r200/r200_state_init.c b/src/mesa/drivers/dri/r200/r200_state_init.c
index ab4a188..bddecaf 100644
--- a/src/mesa/drivers/dri/r200/r200_state_init.c
+++ b/src/mesa/drivers/dri/r200/r200_state_init.c
@@ -451,7 +451,7 @@ static void ctx_emit_cs(struct gl_context *ctx, struct radeon_state_atom *atom)
    atom->cmd[CTX_RB3D_CNTL] &= ~(0xf << 10);
    if (rrb->cpp == 4)
 	atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_ARGB8888;
-   else switch (rrb->base.Format) {
+   else switch (rrb->base.Base.Format) {
    case MESA_FORMAT_RGB565:
 	atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_RGB565;
 	break;
diff --git a/src/mesa/drivers/dri/r200/r200_texstate.c b/src/mesa/drivers/dri/r200/r200_texstate.c
index 4624b08..19e77c5 100644
--- a/src/mesa/drivers/dri/r200/r200_texstate.c
+++ b/src/mesa/drivers/dri/r200/r200_texstate.c
@@ -807,13 +807,14 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
 	}
 
 	_mesa_init_teximage_fields(radeon->glCtx, texImage,
-				   rb->base.Width, rb->base.Height, 1, 0,
+				   rb->base.Base.Width, rb->base.Base.Height,
+				   1, 0,
 				   rb->cpp, texFormat);
 	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 
-        t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
-		   | ((rb->base.Height - 1) << RADEON_TEX_VSIZE_SHIFT);
+        t->pp_txsize = ((rb->base.Base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
+		   | ((rb->base.Base.Height - 1) << RADEON_TEX_VSIZE_SHIFT);
 
 	if (target == GL_TEXTURE_RECTANGLE_NV) {
 		t->pp_txformat |= R200_TXFORMAT_NON_POWER2;
diff --git a/src/mesa/drivers/dri/radeon/radeon_common.c b/src/mesa/drivers/dri/radeon/radeon_common.c
index bb9cb2a..b64ff81 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common.c
+++ b/src/mesa/drivers/dri/radeon/radeon_common.c
@@ -364,8 +364,8 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 		ctx->NewState |= (_NEW_DEPTH | _NEW_STENCIL);
 	}
 
-	_mesa_reference_renderbuffer(&radeon->state.depth.rb, &rrbDepth->base);
-	_mesa_reference_renderbuffer(&radeon->state.color.rb, &rrbColor->base);
+	_mesa_reference_renderbuffer(&radeon->state.depth.rb, &rrbDepth->base.Base);
+	_mesa_reference_renderbuffer(&radeon->state.color.rb, &rrbColor->base.Base);
 	radeon->state.color.draw_offset = offset;
 
 #if 0
diff --git a/src/mesa/drivers/dri/radeon/radeon_common.h b/src/mesa/drivers/dri/radeon/radeon_common.h
index 24cba34..6f9b5b9 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common.h
+++ b/src/mesa/drivers/dri/radeon/radeon_common.h
@@ -45,7 +45,7 @@ static inline struct radeon_renderbuffer *radeon_renderbuffer(struct gl_renderbu
 	radeon_print(RADEON_MEMORY, RADEON_TRACE,
 		"%s(rb %p)\n",
 		__func__, (void *) rb);
-	if (rrb && rrb->base.ClassID == RADEON_RB_CLASS)
+	if (rrb && rrb->base.Base.ClassID == RADEON_RB_CLASS)
 		return rrb;
 	else
 		return NULL;
diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.c b/src/mesa/drivers/dri/radeon/radeon_common_context.c
index ceaefda..b5fe7cd 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_common_context.c
@@ -294,7 +294,7 @@ GLboolean radeonUnbindContext(__DRIcontext * driContextPriv)
 static unsigned
 radeon_bits_per_pixel(const struct radeon_renderbuffer *rb)
 {
-   return _mesa_get_format_bytes(rb->base.Format) * 8; 
+   return _mesa_get_format_bytes(rb->base.Base.Format) * 8; 
 }
 
 /*
@@ -484,8 +484,8 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
 
 		rb->cpp = buffers[i].cpp;
 		rb->pitch = buffers[i].pitch;
-		rb->base.Width = drawable->w;
-		rb->base.Height = drawable->h;
+		rb->base.Base.Width = drawable->w;
+		rb->base.Base.Height = drawable->h;
 		rb->has_surface = 0;
 
 		if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_bo) {
@@ -602,9 +602,9 @@ GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
 	if (driDrawPriv != driReadPriv)
 	   radeon_update_renderbuffers(driContextPriv, driReadPriv, GL_FALSE);
 	_mesa_reference_renderbuffer(&radeon->state.color.rb,
-		&(radeon_get_renderbuffer(drfb, BUFFER_BACK_LEFT)->base));
+		&(radeon_get_renderbuffer(drfb, BUFFER_BACK_LEFT)->base.Base));
 	_mesa_reference_renderbuffer(&radeon->state.depth.rb,
-		&(radeon_get_renderbuffer(drfb, BUFFER_DEPTH)->base));
+		&(radeon_get_renderbuffer(drfb, BUFFER_DEPTH)->base.Base));
 
 	if (RADEON_DEBUG & RADEON_DRI)
 	     fprintf(stderr, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__, radeon->glCtx, drfb, readfb);
diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.h b/src/mesa/drivers/dri/radeon/radeon_common_context.h
index 1fa7547..80ae2d1 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common_context.h
+++ b/src/mesa/drivers/dri/radeon/radeon_common_context.h
@@ -80,7 +80,8 @@ typedef struct radeon_context *radeonContextPtr;
 
 struct radeon_renderbuffer
 {
-	struct gl_renderbuffer base;
+	struct swrast_renderbuffer base;
+
 	struct radeon_bo *bo;
 	unsigned int cpp;
 	/* unsigned int offset; */
diff --git a/src/mesa/drivers/dri/radeon/radeon_fbo.c b/src/mesa/drivers/dri/radeon/radeon_fbo.c
index 026587c..9032a32 100644
--- a/src/mesa/drivers/dri/radeon/radeon_fbo.c
+++ b/src/mesa/drivers/dri/radeon/radeon_fbo.c
@@ -263,7 +263,7 @@ radeon_map_renderbuffer(struct gl_context *ctx,
 	   src_y = y;
        } else {
 	   src_x = x;
-	   src_y = rrb->base.Height - y - h;
+	   src_y = rrb->base.Base.Height - y - h;
        }
 
        /* Make a temporary buffer and blit the current contents of the renderbuffer
@@ -645,7 +645,7 @@ radeon_resize_buffers(struct gl_context *ctx, struct gl_framebuffer *fb,
 
    /* Make sure all window system renderbuffers are up to date */
    for (i = 0; i < 2; i++) {
-      struct gl_renderbuffer *rb = &radeon_fb->color_rb[i]->base;
+      struct gl_renderbuffer *rb = &radeon_fb->color_rb[i]->base.Base;
 
       /* only resize if size is changing */
       if (rb && (rb->Width != width || rb->Height != height)) {
@@ -673,6 +673,7 @@ struct radeon_renderbuffer *
 radeon_create_renderbuffer(gl_format format, __DRIdrawable *driDrawPriv)
 {
     struct radeon_renderbuffer *rrb;
+    struct gl_renderbuffer *rb;
 
     rrb = CALLOC_STRUCT(radeon_renderbuffer);
 
@@ -683,18 +684,18 @@ radeon_create_renderbuffer(gl_format format, __DRIdrawable *driDrawPriv)
     if (!rrb)
 	return NULL;
 
-    _mesa_init_renderbuffer(&rrb->base, 0);
-    rrb->base.ClassID = RADEON_RB_CLASS;
+    rb = &rrb->base.Base;
 
-    rrb->base.Format = format;
-
-    rrb->base._BaseFormat = _mesa_get_format_base_format(format);
+    _mesa_init_renderbuffer(rb, 0);
+    rb->ClassID = RADEON_RB_CLASS;
+    rb->Format = format;
+    rb->_BaseFormat = _mesa_get_format_base_format(format);
+    rb->InternalFormat = _mesa_get_format_base_format(format);
 
     rrb->dPriv = driDrawPriv;
-    rrb->base.InternalFormat = _mesa_get_format_base_format(format);
 
-    rrb->base.Delete = radeon_delete_renderbuffer;
-    rrb->base.AllocStorage = radeon_alloc_window_storage;
+    rb->Delete = radeon_delete_renderbuffer;
+    rb->AllocStorage = radeon_alloc_window_storage;
 
     rrb->bo = NULL;
     return rrb;
@@ -704,6 +705,8 @@ static struct gl_renderbuffer *
 radeon_new_renderbuffer(struct gl_context * ctx, GLuint name)
 {
   struct radeon_renderbuffer *rrb;
+  struct gl_renderbuffer *rb;
+
 
   rrb = CALLOC_STRUCT(radeon_renderbuffer);
 
@@ -714,13 +717,14 @@ radeon_new_renderbuffer(struct gl_context * ctx, GLuint name)
   if (!rrb)
     return NULL;
 
-  _mesa_init_renderbuffer(&rrb->base, name);
-  rrb->base.ClassID = RADEON_RB_CLASS;
+  rb = &rrb->base.Base;
 
-  rrb->base.Delete = radeon_delete_renderbuffer;
-  rrb->base.AllocStorage = radeon_alloc_renderbuffer_storage;
+  _mesa_init_renderbuffer(rb, name);
+  rb->ClassID = RADEON_RB_CLASS;
+  rb->Delete = radeon_delete_renderbuffer;
+  rb->AllocStorage = radeon_alloc_renderbuffer_storage;
 
-  return &rrb->base;
+  return rb;
 }
 
 static void
@@ -761,19 +765,21 @@ static GLboolean
 radeon_update_wrapper(struct gl_context *ctx, struct radeon_renderbuffer *rrb, 
 		     struct gl_texture_image *texImage)
 {
+	struct gl_renderbuffer *rb = &rrb->base.Base;
+
 	radeon_print(RADEON_TEXTURE, RADEON_TRACE,
 		"%s(%p, rrb %p, texImage %p, texFormat %s) \n",
 		__func__, ctx, rrb, texImage, _mesa_get_format_name(texImage->TexFormat));
 
 	rrb->cpp = _mesa_get_format_bytes(texImage->TexFormat);
 	rrb->pitch = texImage->Width * rrb->cpp;
-	rrb->base.Format = texImage->TexFormat;
-	rrb->base.InternalFormat = texImage->InternalFormat;
-	rrb->base._BaseFormat = _mesa_base_fbo_format(ctx, rrb->base.InternalFormat);
-	rrb->base.Width = texImage->Width;
-	rrb->base.Height = texImage->Height;
-	rrb->base.Delete = radeon_delete_renderbuffer;
-	rrb->base.AllocStorage = radeon_nop_alloc_storage;
+	rb->Format = texImage->TexFormat;
+	rb->InternalFormat = texImage->InternalFormat;
+	rb->_BaseFormat = _mesa_base_fbo_format(ctx, rb->InternalFormat);
+	rb->Width = texImage->Width;
+	rb->Height = texImage->Height;
+	rb->Delete = radeon_delete_renderbuffer;
+	rb->AllocStorage = radeon_nop_alloc_storage;
 
 	return GL_TRUE;
 }
@@ -797,8 +803,8 @@ radeon_wrap_texture(struct gl_context * ctx, struct gl_texture_image *texImage)
       return NULL;
    }
 
-   _mesa_init_renderbuffer(&rrb->base, name);
-   rrb->base.ClassID = RADEON_RB_CLASS;
+   _mesa_init_renderbuffer(&rrb->base.Base, name);
+   rrb->base.Base.ClassID = RADEON_RB_CLASS;
 
    if (!radeon_update_wrapper(ctx, rrb, texImage)) {
       free(rrb);
@@ -840,7 +846,7 @@ radeon_render_texture(struct gl_context * ctx,
       rrb = radeon_wrap_texture(ctx, newImage);
       if (rrb) {
          /* bind the wrapper to the attachment point */
-         _mesa_reference_renderbuffer(&att->Renderbuffer, &rrb->base);
+         _mesa_reference_renderbuffer(&att->Renderbuffer, &rrb->base.Base);
       }
       else {
          /* fallback to software rendering */
@@ -858,7 +864,7 @@ radeon_render_texture(struct gl_context * ctx,
    DBG("Begin render texture tid %lx tex=%u w=%d h=%d refcount=%d\n",
        _glthread_GetID(),
        att->Texture->Name, newImage->Width, newImage->Height,
-       rrb->base.RefCount);
+       rrb->base.Base.RefCount);
 
    /* point the renderbufer's region to the texture image region */
    if (rrb->bo != radeon_image->mt->bo) {
diff --git a/src/mesa/drivers/dri/radeon/radeon_pixel_read.c b/src/mesa/drivers/dri/radeon/radeon_pixel_read.c
index 68e3114..3a14cc6 100644
--- a/src/mesa/drivers/dri/radeon/radeon_pixel_read.c
+++ b/src/mesa/drivers/dri/radeon/radeon_pixel_read.c
@@ -150,17 +150,17 @@ do_blit_readpixels(struct gl_context * ctx,
     /* Disable source Y flipping for FBOs */
     flip_y = (ctx->ReadBuffer->Name == 0);
     if (pack->Invert) {
-        y = rrb->base.Height - height - y;
+        y = rrb->base.Base.Height - height - y;
         flip_y = !flip_y;
     }
 
     if (radeon->vtbl.blit(ctx,
                           rrb->bo,
                           rrb->draw_offset,
-                          rrb->base.Format,
+                          rrb->base.Base.Format,
                           rrb->pitch / rrb->cpp,
-                          rrb->base.Width,
-                          rrb->base.Height,
+                          rrb->base.Base.Width,
+                          rrb->base.Base.Height,
                           x,
                           y,
                           dst_buffer,
diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c
index 51a1ef5..76c23eb 100644
--- a/src/mesa/drivers/dri/radeon/radeon_screen.c
+++ b/src/mesa/drivers/dri/radeon/radeon_screen.c
@@ -620,13 +620,13 @@ radeonCreateBuffer( __DRIscreen *driScrnPriv,
 
     /* front color renderbuffer */
     rfb->color_rb[0] = radeon_create_renderbuffer(rgbFormat, driDrawPriv);
-    _mesa_add_renderbuffer(&rfb->base, BUFFER_FRONT_LEFT, &rfb->color_rb[0]->base);
+    _mesa_add_renderbuffer(&rfb->base, BUFFER_FRONT_LEFT, &rfb->color_rb[0]->base.Base);
     rfb->color_rb[0]->has_surface = 1;
 
     /* back color renderbuffer */
     if (mesaVis->doubleBufferMode) {
       rfb->color_rb[1] = radeon_create_renderbuffer(rgbFormat, driDrawPriv);
-	_mesa_add_renderbuffer(&rfb->base, BUFFER_BACK_LEFT, &rfb->color_rb[1]->base);
+	_mesa_add_renderbuffer(&rfb->base, BUFFER_BACK_LEFT, &rfb->color_rb[1]->base.Base);
 	rfb->color_rb[1]->has_surface = 1;
     }
 
@@ -634,21 +634,21 @@ radeonCreateBuffer( __DRIscreen *driScrnPriv,
       if (mesaVis->stencilBits == 8) {
 	struct radeon_renderbuffer *depthStencilRb =
            radeon_create_renderbuffer(MESA_FORMAT_S8_Z24, driDrawPriv);
-	_mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depthStencilRb->base);
-	_mesa_add_renderbuffer(&rfb->base, BUFFER_STENCIL, &depthStencilRb->base);
+	_mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depthStencilRb->base.Base);
+	_mesa_add_renderbuffer(&rfb->base, BUFFER_STENCIL, &depthStencilRb->base.Base);
 	depthStencilRb->has_surface = screen->depthHasSurface;
       } else {
 	/* depth renderbuffer */
 	struct radeon_renderbuffer *depth =
            radeon_create_renderbuffer(MESA_FORMAT_X8_Z24, driDrawPriv);
-	_mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base);
+	_mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base.Base);
 	depth->has_surface = screen->depthHasSurface;
       }
     } else if (mesaVis->depthBits == 16) {
         /* just 16-bit depth buffer, no hw stencil */
 	struct radeon_renderbuffer *depth =
            radeon_create_renderbuffer(MESA_FORMAT_Z16, driDrawPriv);
-	_mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base);
+	_mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base.Base);
 	depth->has_surface = screen->depthHasSurface;
     }
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c
index 6588ae8..1f2ba49 100644
--- a/src/mesa/drivers/dri/radeon/radeon_span.c
+++ b/src/mesa/drivers/dri/radeon/radeon_span.c
@@ -64,8 +64,8 @@ radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb)
 				    GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
 				    &map, &stride);
 
-	rb->Map = map;
-	rb->RowStrideBytes = stride;
+	rrb->base.Map = map;
+	rrb->base.RowStride = stride;
 }
 
 static void
@@ -77,8 +77,8 @@ radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb)
 
 	ctx->Driver.UnmapRenderbuffer(ctx, rb);
 
-	rb->Map = NULL;
-	rb->RowStrideBytes = 0;
+	rrb->base.Map = NULL;
+	rrb->base.RowStride = 0;
 }
 
 static void
diff --git a/src/mesa/drivers/dri/radeon/radeon_state_init.c b/src/mesa/drivers/dri/radeon/radeon_state_init.c
index 8edba6e..151f4f5 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state_init.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state_init.c
@@ -334,7 +334,7 @@ static void ctx_emit_cs(struct gl_context *ctx, struct radeon_state_atom *atom)
    atom->cmd[CTX_RB3D_CNTL] &= ~(0xf << 10);
    if (rrb->cpp == 4)
 	atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_ARGB8888;
-   else switch (rrb->base.Format) {
+   else switch (rrb->base.Base.Format) {
    case MESA_FORMAT_RGB565:
 	atom->cmd[CTX_RB3D_CNTL] |= RADEON_COLOR_FORMAT_RGB565;
 	break;
@@ -404,8 +404,8 @@ static void ctx_emit_cs(struct gl_context *ctx, struct radeon_state_atom *atom)
    OUT_BATCH(0);
    OUT_BATCH(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT, 0));
    if (rrb) {
-       OUT_BATCH(((rrb->base.Width - 1) << RADEON_RE_WIDTH_SHIFT) |
-                 ((rrb->base.Height - 1) << RADEON_RE_HEIGHT_SHIFT));
+       OUT_BATCH(((rrb->base.Base.Width - 1) << RADEON_RE_WIDTH_SHIFT) |
+                 ((rrb->base.Base.Height - 1) << RADEON_RE_HEIGHT_SHIFT));
    } else {
        OUT_BATCH(0);
    }
diff --git a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c
index 726692e..a26acbf 100644
--- a/src/mesa/drivers/dri/radeon/radeon_tex_copy.c
+++ b/src/mesa/drivers/dri/radeon/radeon_tex_copy.c
@@ -89,12 +89,12 @@ do_copy_texsubimage(struct gl_context *ctx,
                 __FUNCTION__, face, level);
         fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset);
         fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d\n",
-                x, y, rrb->base.Width, rrb->base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp);
+                x, y, rrb->base.Base.Width, rrb->base.Base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp);
         fprintf(stderr, "src size %d, dst size %d\n", rrb->bo->size, timg->mt->bo->size);
 
     }
 
-    src_mesaformat = rrb->base.Format;
+    src_mesaformat = rrb->base.Base.Format;
     dst_mesaformat = timg->base.Base.TexFormat;
     src_bpp = _mesa_get_format_bytes(src_mesaformat);
     dst_bpp = _mesa_get_format_bytes(dst_mesaformat);
@@ -126,7 +126,7 @@ do_copy_texsubimage(struct gl_context *ctx,
 
     /* blit from src buffer to texture */
     return radeon->vtbl.blit(ctx, rrb->bo, src_offset, src_mesaformat, rrb->pitch/rrb->cpp,
-                             rrb->base.Width, rrb->base.Height, x, y,
+                             rrb->base.Base.Width, rrb->base.Base.Height, x, y,
                              timg->mt->bo, dst_offset, dst_mesaformat,
                              timg->mt->levels[level].rowstride / dst_bpp,
                              timg->base.Base.Width, timg->base.Base.Height,
diff --git a/src/mesa/drivers/dri/radeon/radeon_texstate.c b/src/mesa/drivers/dri/radeon/radeon_texstate.c
index 67acb73..87f12d5 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texstate.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texstate.c
@@ -681,15 +681,16 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
 	}
 
 	_mesa_init_teximage_fields(radeon->glCtx, texImage,
-				   rb->base.Width, rb->base.Height, 1, 0,
+				   rb->base.Base.Width, rb->base.Base.Height,
+				   1, 0,
 				   rb->cpp, texFormat);
 	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 	t->pp_txpitch &= (1 << 13) -1;
 	pitch_val = rb->pitch;
 
-        t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
-		| ((rb->base.Height - 1) << RADEON_TEX_VSIZE_SHIFT);
+        t->pp_txsize = ((rb->base.Base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
+		| ((rb->base.Base.Height - 1) << RADEON_TEX_VSIZE_SHIFT);
 	if (target == GL_TEXTURE_RECTANGLE_NV) {
 		t->pp_txformat |= RADEON_TXFORMAT_NON_POWER2;
 		t->pp_txpitch = pitch_val;
commit b31bfae0db24f2c7c5592fc423bdb221219d0faf
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:40:01 2012 -0700

    intel: derive intel_renderbuffer from swrast_renderbuffer
    
    Drivers that rely on swrast need to do this, as with swrast_texture_image.
    (cherry picked from commit 9f8ed9d66298e2dc5dff508e3ea723469fe06d93)

diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index 68e1e80..c364f40 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -354,8 +354,8 @@ static void emit_depthbuffer(struct brw_context *brw)
 	        (1 << 27) | /* tiled surface */
 	        (BRW_SURFACE_2D << 29));
       OUT_BATCH(0);
-      OUT_BATCH(((stencil_irb->Base.Width - 1) << 6) |
-	         (stencil_irb->Base.Height - 1) << 19);
+      OUT_BATCH(((stencil_irb->Base.Base.Width - 1) << 6) |
+	         (stencil_irb->Base.Base.Height - 1) << 19);
       OUT_BATCH(0);
       OUT_BATCH(0);
 
@@ -389,8 +389,8 @@ static void emit_depthbuffer(struct brw_context *brw)
 		I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
 		offset);
       OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) |
-		(((depth_irb->Base.Width + tile_x)- 1) << 6) |
-		(((depth_irb->Base.Height + tile_y) - 1) << 19));
+		(((depth_irb->Base.Base.Width + tile_x) - 1) << 6) |
+		(((depth_irb->Base.Base.Height + tile_y) - 1) << 19));
       OUT_BATCH(0);
 
       if (intel->is_g4x || intel->gen >= 5)
diff --git a/src/mesa/drivers/dri/i965/gen7_misc_state.c b/src/mesa/drivers/dri/i965/gen7_misc_state.c
index c2f58d5..d0ce542 100644
--- a/src/mesa/drivers/dri/i965/gen7_misc_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_misc_state.c
@@ -74,8 +74,8 @@ static void emit_depthbuffer(struct brw_context *brw)
 
 	 /* 3DSTATE_STENCIL_BUFFER inherits surface type and dimensions. */
 	 dw1 |= (BRW_SURFACE_2D << 29);
-	 dw3 = ((srb->Base.Width - 1) << 4) |
-	       ((srb->Base.Height - 1) << 18);
+	 dw3 = ((srb->Base.Base.Width - 1) << 4) |
+	       ((srb->Base.Base.Height - 1) << 18);
       }
 
       BEGIN_BATCH(7);
@@ -107,8 +107,8 @@ static void emit_depthbuffer(struct brw_context *brw)
       OUT_RELOC(region->bo,
 	        I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
 		offset);
-      OUT_BATCH((((drb->Base.Width + tile_x) - 1) << 4) |
-                (((drb->Base.Height + tile_y) - 1) << 18));
+      OUT_BATCH((((drb->Base.Base.Width + tile_x) - 1) << 4) |
+                (((drb->Base.Base.Height + tile_y) - 1) << 18));
       OUT_BATCH(0);
       OUT_BATCH(tile_x | (tile_y << 16));
       OUT_BATCH(0);
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 30a01bb..ffd9536 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -1401,8 +1401,8 @@ intel_verify_dri2_has_hiz(struct intel_context *intel,
 	 /* 2. Create new depth/stencil renderbuffer. */
 	 struct intel_renderbuffer *depth_stencil_rb =
 	    intel_create_renderbuffer(MESA_FORMAT_S8_Z24);
-	 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depth_stencil_rb->Base);
-	 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depth_stencil_rb->Base);
+	 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depth_stencil_rb->Base.Base);
+	 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &depth_stencil_rb->Base.Base);
 
 	 /* 3. Append DRI2BufferDepthStencil to attachment list. */
 	 int old_count = *count;
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 2e400e7..0bb61b5 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -132,11 +132,11 @@ intel_map_renderbuffer(struct gl_context *ctx,
    void *map;
    int stride;
 
-   if (!irb && rb->Buffer) {
+   if (!irb && irb->Base.Buffer) {
       /* this is a malloc'd renderbuffer (accum buffer) */
       GLint bpp = _mesa_get_format_bytes(rb->Format);
-      GLint rowStride = rb->RowStrideBytes;
-      *out_map = (GLubyte *) rb->Buffer + y * rowStride + x * bpp;
+      GLint rowStride = irb->Base.RowStride;
+      *out_map = (GLubyte *) irb->Base.Buffer + y * rowStride + x * bpp;
       *out_stride = rowStride;
       return;
    }
@@ -185,7 +185,7 @@ intel_unmap_renderbuffer(struct gl_context *ctx,
    DBG("%s: rb %d (%s)\n", __FUNCTION__,
        rb->Name, _mesa_get_format_name(rb->Format));
 
-   if (!irb && rb->Buffer) {
+   if (!irb && irb->Base.Buffer) {
       /* this is a malloc'd renderbuffer (accum buffer) */
       /* nothing to do */
       return;
@@ -368,9 +368,10 @@ intel_nop_alloc_storage(struct gl_context * ctx, struct gl_renderbuffer *rb,
 struct intel_renderbuffer *
 intel_create_renderbuffer(gl_format format)
 {
-   GET_CURRENT_CONTEXT(ctx);
-
    struct intel_renderbuffer *irb;
+   struct gl_renderbuffer *rb;
+
+   GET_CURRENT_CONTEXT(ctx);
 
    irb = CALLOC_STRUCT(intel_renderbuffer);
    if (!irb) {
@@ -378,15 +379,17 @@ intel_create_renderbuffer(gl_format format)
       return NULL;
    }
 
-   _mesa_init_renderbuffer(&irb->Base, 0);
-   irb->Base.ClassID = INTEL_RB_CLASS;
-   irb->Base._BaseFormat = _mesa_get_format_base_format(format);
-   irb->Base.Format = format;
-   irb->Base.InternalFormat = irb->Base._BaseFormat;
+   rb = &irb->Base.Base;
+
+   _mesa_init_renderbuffer(rb, 0);
+   rb->ClassID = INTEL_RB_CLASS;
+   rb->_BaseFormat = _mesa_get_format_base_format(format);
+   rb->Format = format;
+   rb->InternalFormat = rb->_BaseFormat;
 
    /* intel-specific methods */
-   irb->Base.Delete = intel_delete_renderbuffer;
-   irb->Base.AllocStorage = intel_alloc_window_storage;
+   rb->Delete = intel_delete_renderbuffer;
+   rb->AllocStorage = intel_alloc_window_storage;
 
    return irb;
 }
@@ -400,6 +403,7 @@ intel_new_renderbuffer(struct gl_context * ctx, GLuint name)
 {
    /*struct intel_context *intel = intel_context(ctx); */
    struct intel_renderbuffer *irb;
+   struct gl_renderbuffer *rb;
 
    irb = CALLOC_STRUCT(intel_renderbuffer);
    if (!irb) {
@@ -407,15 +411,17 @@ intel_new_renderbuffer(struct gl_context * ctx, GLuint name)
       return NULL;
    }
 
-   _mesa_init_renderbuffer(&irb->Base, name);
-   irb->Base.ClassID = INTEL_RB_CLASS;
+   rb = &irb->Base.Base;
+
+   _mesa_init_renderbuffer(rb, name);
+   rb->ClassID = INTEL_RB_CLASS;
 
    /* intel-specific methods */
-   irb->Base.Delete = intel_delete_renderbuffer;
-   irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
+   rb->Delete = intel_delete_renderbuffer;
+   rb->AllocStorage = intel_alloc_renderbuffer_storage;
    /* span routines set in alloc_storage function */
 
-   return &irb->Base;
+   return rb;
 }
 
 
@@ -479,7 +485,7 @@ intel_renderbuffer_update_wrapper(struct intel_context *intel,
                                   gl_format format,
                                   GLenum internal_format)
 {
-   struct gl_renderbuffer *rb = &irb->Base;
+   struct gl_renderbuffer *rb = &irb->Base.Base;
 
    rb->Format = format;
    rb->InternalFormat = internal_format;
@@ -487,8 +493,8 @@ intel_renderbuffer_update_wrapper(struct intel_context *intel,
    rb->Width = mt->level[level].width;
    rb->Height = mt->level[level].height;
 
-   irb->Base.Delete = intel_delete_renderbuffer;
-   irb->Base.AllocStorage = intel_nop_alloc_storage;
+   rb->Delete = intel_delete_renderbuffer;
+   rb->AllocStorage = intel_nop_alloc_storage;
 
    intel_miptree_check_level_layer(mt, level, layer);
    irb->mt_level = level;
@@ -661,7 +667,7 @@ intel_render_texture(struct gl_context * ctx,
 
       if (irb) {
          /* bind the wrapper to the attachment point */
-         _mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base);
+         _mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base.Base);
       }
       else {
          /* fallback to software rendering */
@@ -682,7 +688,7 @@ intel_render_texture(struct gl_context * ctx,
    DBG("Begin render %s texture tex=%u w=%d h=%d refcount=%d\n",
        _mesa_get_format_name(image->TexFormat),
        att->Texture->Name, image->Width, image->Height,
-       irb->Base.RefCount);
+       irb->Base.Base.RefCount);
 
    intel_image->used_as_render_target = true;
 
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.h b/src/mesa/drivers/dri/intel/intel_fbo.h
index 5a0d865..a2c1b1a 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.h
+++ b/src/mesa/drivers/dri/intel/intel_fbo.h
@@ -43,7 +43,7 @@ struct intel_texture_image;
  */
 struct intel_renderbuffer
 {
-   struct gl_renderbuffer Base;
+   struct swrast_renderbuffer Base;
    struct intel_mipmap_tree *mt; /**< The renderbuffer storage. */
    drm_intel_bo *map_bo;
 
@@ -84,7 +84,7 @@ static INLINE struct intel_renderbuffer *
 intel_renderbuffer(struct gl_renderbuffer *rb)
 {
    struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
-   if (irb && irb->Base.ClassID == INTEL_RB_CLASS) {
+   if (irb && irb->Base.Base.ClassID == INTEL_RB_CLASS) {
       /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
       return irb;
    }
@@ -119,7 +119,7 @@ intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
 static INLINE gl_format
 intel_rb_format(const struct intel_renderbuffer *rb)
 {
-   return rb->Base.Format;
+   return rb->Base.Base.Format;
 }
 
 
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index cf046a2..a998a37 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -425,11 +425,11 @@ intelCreateBuffer(__DRIscreen * driScrnPriv,
 
       /* setup the hardware-based renderbuffers */
       rb = intel_create_renderbuffer(rgbFormat);
-      _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base);
+      _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
 
       if (mesaVis->doubleBufferMode) {
 	 rb = intel_create_renderbuffer(rgbFormat);
-         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base);
+         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base);
       }
 
       /*
@@ -448,17 +448,17 @@ intelCreateBuffer(__DRIscreen * driScrnPriv,
 	     * enum intel_dri2_has_hiz).
 	     */
 	    rb = intel_create_renderbuffer(MESA_FORMAT_X8_Z24);
-	    _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base);
+	    _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
 	    rb = intel_create_renderbuffer(MESA_FORMAT_S8);
-	    _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base);
+	    _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
 	 } else {
 	    /*
 	     * Use combined depth/stencil. Note that the renderbuffer is
 	     * attached to two attachment points.
 	     */
 	    rb = intel_create_renderbuffer(MESA_FORMAT_S8_Z24);
-	    _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base);
-	    _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base);
+	    _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
+	    _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
 	 }
       }
       else if (mesaVis->depthBits == 16) {
@@ -466,7 +466,7 @@ intelCreateBuffer(__DRIscreen * driScrnPriv,
          /* just 16-bit depth buffer, no hw stencil */
          struct intel_renderbuffer *depthRb
 	    = intel_create_renderbuffer(MESA_FORMAT_Z16);
-         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base.Base);
       }
       else {
 	 assert(mesaVis->depthBits == 0);
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 34bcd28..9b6540d 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -121,7 +121,7 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
    if (!irb)
       return;
 
-   if (rb->Map) {
+   if (irb->Base.Map) {
       /* Renderbuffer is already mapped. This usually happens when a single
        * buffer is attached to the framebuffer's depth and stencil attachment
        * points.
@@ -132,8 +132,8 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
    ctx->Driver.MapRenderbuffer(ctx, rb, 0, 0, rb->Width, rb->Height,
 			       GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
 			       &map, &stride);
-   rb->Map = map;
-   rb->RowStrideBytes = stride;
+   irb->Base.Map = map;
+   irb->Base.RowStride = stride;
 }
 
 static void
@@ -146,7 +146,7 @@ intel_renderbuffer_unmap(struct intel_context *intel,
    if (!irb)
       return;
 
-   if (!rb->Map) {
+   if (!irb->Base.Map) {
       /* Renderbuffer is already unmapped. This usually happens when a single
        * buffer is attached to the framebuffer's depth and stencil attachment
        * points.
@@ -156,8 +156,8 @@ intel_renderbuffer_unmap(struct intel_context *intel,
 
    ctx->Driver.UnmapRenderbuffer(ctx, rb);
 
-   rb->Map = NULL;
-   rb->RowStrideBytes = 0;
+   irb->Base.Map = NULL;
+   irb->Base.RowStride = 0;
 }
 
 static void
commit 49ab5ad14299ca9e68437586ce9298edff74e31c
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:35:49 2012 -0700

    xlib: derive xmesa_renderbuffer from swrast_renderbuffer
    (cherry picked from commit d16e71eeb47d1e67930f6e86a80dc926468224d9)

diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index 0f41218..fb82889 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -309,7 +309,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
    b->frontxrb->drawable = d;
    b->frontxrb->pixmap = (XMesaPixmap) d;
    _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_FRONT_LEFT,
-                          &b->frontxrb->Base);
+                          &b->frontxrb->Base.Base);
 
    /*
     * Back renderbuffer
@@ -326,7 +326,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type,
       b->db_mode = vis->ximage_flag ? BACK_XIMAGE : BACK_PIXMAP;
       
       _mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_BACK_LEFT,
-                             &b->backxrb->Base);
+                             &b->backxrb->Base.Base);
    }
 
    /*
@@ -1469,7 +1469,9 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height,
 {
    struct gl_renderbuffer *rb
       = b->mesa_buffer.Attachment[BUFFER_DEPTH].Renderbuffer;
-   if (!rb || !rb->Buffer) {
+   struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
+
+   if (!xrb || !xrb->Base.Buffer) {
       *width = 0;
       *height = 0;
       *bytesPerValue = 0;
@@ -1481,7 +1483,7 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height,
       *height = b->mesa_buffer.Height;
       *bytesPerValue = b->mesa_buffer.Visual.depthBits <= 16
          ? sizeof(GLushort) : sizeof(GLuint);
-      *buffer = (void *) rb->Buffer;
+      *buffer = (void *) xrb->Base.Buffer;
       return GL_TRUE;
    }
 }
diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c
index 64a8f43..a7395a3 100644
--- a/src/mesa/drivers/x11/xm_buffer.c
+++ b/src/mesa/drivers/x11/xm_buffer.c
@@ -326,37 +326,37 @@ xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name,
    struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer);
    if (xrb) {
       GLuint name = 0;
-      _mesa_init_renderbuffer(&xrb->Base, name);
+      _mesa_init_renderbuffer(&xrb->Base.Base, name);
 
-      xrb->Base.Delete = xmesa_delete_renderbuffer;
+      xrb->Base.Base.Delete = xmesa_delete_renderbuffer;
       if (backBuffer)
-         xrb->Base.AllocStorage = xmesa_alloc_back_storage;
+         xrb->Base.Base.AllocStorage = xmesa_alloc_back_storage;
       else
-         xrb->Base.AllocStorage = xmesa_alloc_front_storage;
+         xrb->Base.Base.AllocStorage = xmesa_alloc_front_storage;
 
-      xrb->Base.InternalFormat = GL_RGBA;
-      xrb->Base._BaseFormat = GL_RGBA;
-      xrb->Base.ClassID = XMESA_RENDERBUFFER;
+      xrb->Base.Base.InternalFormat = GL_RGBA;
+      xrb->Base.Base._BaseFormat = GL_RGBA;
+      xrb->Base.Base.ClassID = XMESA_RENDERBUFFER;
 
       switch (xmvis->undithered_pf) {
       case PF_8R8G8B:
          /* This will really only happen for pixmaps.  We'll access the
           * pixmap via a temporary XImage which will be 32bpp.
           */
-         xrb->Base.Format = MESA_FORMAT_XRGB8888;
+         xrb->Base.Base.Format = MESA_FORMAT_XRGB8888;
          break;
       case PF_8A8R8G8B:
-         xrb->Base.Format = MESA_FORMAT_ARGB8888;
+         xrb->Base.Base.Format = MESA_FORMAT_ARGB8888;
          break;
       case PF_8A8B8G8R:
-         xrb->Base.Format = MESA_FORMAT_RGBA8888_REV;
+         xrb->Base.Base.Format = MESA_FORMAT_RGBA8888_REV;
          break;
       case PF_5R6G5B:
-         xrb->Base.Format = MESA_FORMAT_RGB565;
+         xrb->Base.Base.Format = MESA_FORMAT_RGB565;
          break;
       default:
          _mesa_warning(ctx, "Bad pixel format in xmesa_new_renderbuffer");
-         xrb->Base.Format = MESA_FORMAT_ARGB8888;
+         xrb->Base.Base.Format = MESA_FORMAT_ARGB8888;
          break;
       }
 
@@ -426,7 +426,7 @@ xmesa_MapRenderbuffer(struct gl_context *ctx,
 {
    struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
 
-   if (xrb->Base.ClassID == XMESA_RENDERBUFFER) {
+   if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
       XImage *ximage = xrb->ximage;
 
       assert(!xrb->map_mode); /* only a single mapping allowed */
@@ -488,7 +488,7 @@ xmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
 
-   if (xrb->Base.ClassID == XMESA_RENDERBUFFER) {
+   if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
       XImage *ximage = xrb->ximage;
 
       if (!ximage) {
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c
index 342d2d9..d0bf2f0 100644
--- a/src/mesa/drivers/x11/xm_dd.c
+++ b/src/mesa/drivers/x11/xm_dd.c
@@ -138,7 +138,7 @@ clear_pixmap(struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
    assert(xmbuf->cleargc);
 
    XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc,
-                       x, xrb->Base.Height - y - height,
+                       x, xrb->Base.Base.Height - y - height,
                        width, height );
 }
 
@@ -215,9 +215,9 @@ clear_32bit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
             | ((pixel << 24) & 0xff000000);
    }
 
-   if (width == xrb->Base.Width && height == xrb->Base.Height) {
+   if (width == xrb->Base.Base.Width && height == xrb->Base.Base.Height) {
       /* clearing whole buffer */
-      const GLuint n = xrb->Base.Width * xrb->Base.Height;
+      const GLuint n = xrb->Base.Base.Width * xrb->Base.Base.Height;
       GLuint *ptr4 = (GLuint *) xrb->ximage->data;
       if (pixel == 0) {
          /* common case */
@@ -332,7 +332,7 @@ can_do_DrawPixels_8R8G8B(struct gl_context *ctx, GLenum format, GLenum type)
             struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
             if (xrb &&
                 xrb->pixmap && /* drawing to pixmap or window */
-                _mesa_get_format_bits(xrb->Base.Format, GL_ALPHA_BITS) == 0) {
+                _mesa_get_format_bits(xrb->Base.Base.Format, GL_ALPHA_BITS) == 0) {
                return GL_TRUE;
             }
          }
@@ -465,7 +465,7 @@ can_do_DrawPixels_5R6G5B(struct gl_context *ctx, GLenum format, GLenum type)
             struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
             if (xrb &&
                 xrb->pixmap && /* drawing to pixmap or window */
-                _mesa_get_format_bits(xrb->Base.Format, GL_ALPHA_BITS) == 0) {
+                _mesa_get_format_bits(xrb->Base.Base.Format, GL_ALPHA_BITS) == 0) {
                return GL_TRUE;
             }
          }
diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h
index 7caa356..7e7b1f8 100644
--- a/src/mesa/drivers/x11/xmesaP.h
+++ b/src/mesa/drivers/x11/xmesaP.h
@@ -29,6 +29,7 @@
 
 #include "xmesa.h"
 #include "main/mtypes.h"
+#include "swrast/s_context.h"
 
 
 extern _glthread_Mutex _xmesa_lock;
@@ -151,7 +152,7 @@ typedef enum {
  */
 struct xmesa_renderbuffer
 {
-   struct gl_renderbuffer Base;  /* Base class */
+   struct swrast_renderbuffer Base;  /* Base class */
 
    XMesaBuffer Parent;  /**< The XMesaBuffer this renderbuffer belongs to */
    XMesaDrawable drawable;	/* Usually the X window ID */
commit 5916b152479be63d77ae5f4da9b30bf3261d828f
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:35:45 2012 -0700

    swrast: allocate swrast_renderbuffers instead of gl_renderbuffers
    (cherry picked from commit f2479530b8be3866c234ac759a7fa84e634dd1aa)

diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 52697f2..af02b02 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -259,7 +259,7 @@ add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
 
       assert(fb->Attachment[b].Renderbuffer == NULL);
 
-      rb = _mesa_new_renderbuffer(ctx, 0);
+      rb = ctx->Driver.NewRenderbuffer(ctx, 0);
       if (!rb) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating color buffer");
          return GL_FALSE;
@@ -297,7 +297,7 @@ add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
 
    assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL);
 
-   rb = _mesa_new_renderbuffer(ctx, 0);
+   rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth buffer");
       return GL_FALSE;
@@ -342,7 +342,7 @@ add_stencil_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
 
    assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL);
 
-   rb = _mesa_new_renderbuffer(ctx, 0);
+   rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating stencil buffer");
       return GL_FALSE;
@@ -367,7 +367,7 @@ add_depth_stencil_renderbuffer(struct gl_context *ctx,
    assert(fb->Attachment[BUFFER_DEPTH].Renderbuffer == NULL);
    assert(fb->Attachment[BUFFER_STENCIL].Renderbuffer == NULL);
 
-   rb = _mesa_new_renderbuffer(ctx, 0);
+   rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth+stencil buffer");
       return GL_FALSE;
@@ -406,7 +406,7 @@ add_accum_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
 
    assert(fb->Attachment[BUFFER_ACCUM].Renderbuffer == NULL);
 
-   rb = _mesa_new_renderbuffer(ctx, 0);
+   rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer");
       return GL_FALSE;
@@ -446,7 +446,7 @@ add_aux_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
    assert(numBuffers <= MAX_AUX_BUFFERS);
 
    for (i = 0; i < numBuffers; i++) {
-      struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, 0);
+      struct gl_renderbuffer *rb = _swrast_new_soft_renderbuffer(ctx, 0);
 
       assert(fb->Attachment[BUFFER_AUX0 + i].Renderbuffer == NULL);
 
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index ebfba6d..23a7388 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -37,7 +37,7 @@ wrap_texture(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
    ASSERT(att->Type == GL_TEXTURE);
    ASSERT(att->Renderbuffer == NULL);
 
-   rb = CALLOC_STRUCT(gl_renderbuffer);
+   rb = ctx->Driver.NewRenderbuffer(ctx, name);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "wrap_texture");
       return;
commit a36cc604cfd44883c45b0936d62eb81a9c222552
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:29:15 2012 -0700

    swrast: new swrast_renderbuffer type
    
    This will let us move the swrast-specific fields out of gl_renderbuffer.
    (cherry picked from commit 34988272d9c7a889a26bb8bdcb841d44797a5dd6)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 7f1e4c7..f03f048 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -168,6 +168,31 @@ swrast_texture_image_const(const struct gl_texture_image *img)
 
 
 /**
+ * Subclass of gl_renderbuffer with extra fields needed for software
+ * rendering.
+ */
+struct swrast_renderbuffer
+{
+   struct gl_renderbuffer Base;
+
+   GLubyte *Buffer;     /**< The malloc'd memory for buffer */
+
+   /** These fields are only valid while buffer is mapped for rendering */
+   GLubyte *Map;
+   GLint RowStride;    /**< in bytes */
+};
+
+
+/** cast wrapper */
+static inline struct swrast_renderbuffer *
+swrast_renderbuffer(struct gl_renderbuffer *img)
+{
+   return (struct swrast_renderbuffer *) img;
+}
+
+
+
+/**
  * \struct SWcontext
  * \brief  Per-context state that's private to the software rasterizer module.
  */
commit 73ed8cec4a959124fd4081c99e87594a1e480e12
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:29:11 2012 -0700

    intel: use intel_rb_format() to get renderbuffer format
    
    This will make future changes cleaner and less invasive.
    (cherry picked from commit 924de7dc96f4607cb3d833637b5f69f4b9e2a6d0)

diff --git a/src/mesa/drivers/dri/i915/i830_vtbl.c b/src/mesa/drivers/dri/i915/i830_vtbl.c
index 513acb9..082372e 100644
--- a/src/mesa/drivers/dri/i915/i830_vtbl.c
+++ b/src/mesa/drivers/dri/i915/i830_vtbl.c
@@ -642,7 +642,7 @@ i830_set_draw_region(struct intel_context *intel,
             DSTORG_VERT_BIAS(0x8) | DEPTH_IS_Z);    /* .5 */
 
    if (irb != NULL) {
-      value |= i830_render_target_format_for_mesa_format[irb->Base.Format];
+      value |= i830_render_target_format_for_mesa_format[intel_rb_format(irb)];
    }
 
    if (depth_region && depth_region->cpp == 4) {
@@ -803,7 +803,7 @@ i830_update_draw_buffer(struct intel_context *intel)
 
    /* Check for stencil fallback. */
    if (irbStencil && irbStencil->mt) {
-      assert(irbStencil->Base.Format == MESA_FORMAT_S8_Z24);
+      assert(intel_rb_format(irbStencil) == MESA_FORMAT_S8_Z24);
       FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false);
    } else if (irbStencil && !irbStencil->mt) {
       FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, true);
@@ -816,7 +816,7 @@ i830_update_draw_buffer(struct intel_context *intel)
     * we still need to set up the shared depth/stencil state so we can use it.
     */
    if (depthRegion == NULL && irbStencil && irbStencil->mt
-       && irbStencil->Base.Format == MESA_FORMAT_S8_Z24) {
+       && intel_rb_format(irbStencil) == MESA_FORMAT_S8_Z24) {
       depthRegion = irbStencil->mt->region;
    }
 
diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c
index e938af8..62bfa0a 100644
--- a/src/mesa/drivers/dri/i915/i915_vtbl.c
+++ b/src/mesa/drivers/dri/i915/i915_vtbl.c
@@ -607,7 +607,7 @@ i915_set_draw_region(struct intel_context *intel,
             DSTORG_VERT_BIAS(0x8) |     /* .5 */
             LOD_PRECLAMP_OGL | TEX_DEFAULT_COLOR_OGL);
    if (irb != NULL) {
-      value |= i915_render_target_format_for_mesa_format[irb->Base.Format];
+      value |= i915_render_target_format_for_mesa_format[intel_rb_format(irb)];
    } else {
       value |= DV_PF_8888;
    }
@@ -775,7 +775,7 @@ i915_update_draw_buffer(struct intel_context *intel)
 
    /* Check for stencil fallback. */
    if (irbStencil && irbStencil->mt) {
-      assert(irbStencil->Base.Format == MESA_FORMAT_S8_Z24);
+      assert(intel_rb_format(irbStencil) == MESA_FORMAT_S8_Z24);
       FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, false);
    } else if (irbStencil && !irbStencil->mt) {
       FALLBACK(intel, INTEL_FALLBACK_STENCIL_BUFFER, true);
@@ -788,7 +788,7 @@ i915_update_draw_buffer(struct intel_context *intel)
     * we still need to set up the shared depth/stencil state so we can use it.
     */
    if (depthRegion == NULL && irbStencil && irbStencil->mt
-       && irbStencil->Base.Format == MESA_FORMAT_S8_Z24) {
+       && intel_rb_format(irbStencil) == MESA_FORMAT_S8_Z24) {
       depthRegion = irbStencil->mt->region;
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index 1a7d328..68e1e80 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -209,8 +209,8 @@ brw_depthbuffer_format(struct brw_context *brw)
    if (!drb &&
        (srb = intel_get_renderbuffer(fb, BUFFER_STENCIL)) &&
        !srb->mt->stencil_mt &&
-       (srb->Base.Format == MESA_FORMAT_S8_Z24 ||
-	srb->Base.Format == MESA_FORMAT_Z32_FLOAT_X24S8)) {
+       (intel_rb_format(srb) == MESA_FORMAT_S8_Z24 ||
+	intel_rb_format(srb) == MESA_FORMAT_Z32_FLOAT_X24S8)) {
       drb = srb;
    }
 
@@ -246,7 +246,7 @@ brw_depthbuffer_format(struct brw_context *brw)
       return BRW_DEPTHFORMAT_D32_FLOAT_S8X24_UINT;
    default:
       _mesa_problem(ctx, "Unexpected depth format %s\n",
-		    _mesa_get_format_name(drb->Base.Format));
+		    _mesa_get_format_name(intel_rb_format(drb)));
       return BRW_DEPTHFORMAT_D16_UNORM;
    }
 }
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index b7454b0..62214d1 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -906,24 +906,25 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
    uint32_t *surf;
    uint32_t tile_x, tile_y;
    uint32_t format = 0;
+   gl_format rb_format = intel_rb_format(irb);
 
    surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,
 			  6 * 4, 32, &brw->bind.surf_offset[unit]);
 
-   switch (irb->Base.Format) {
+   switch (rb_format) {
    case MESA_FORMAT_SARGB8:
       /* without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB
 	 surfaces to the blend/update as sRGB */
       if (ctx->Color.sRGBEnabled)
-	 format = brw_format_for_mesa_format(irb->Base.Format);
+	 format = brw_format_for_mesa_format(rb_format);
       else
 	 format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
       break;
    default:
-      format = brw->render_target_format[irb->Base.Format];
-      if (unlikely(!brw->format_supported_as_render_target[irb->Base.Format])) {
+      format = brw->render_target_format[rb_format];
+      if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
 	 _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
-		       __FUNCTION__, _mesa_get_format_name(irb->Base.Format));
+		       __FUNCTION__, _mesa_get_format_name(rb_format));
       }
       break;
    }
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index 940b294..adc3a45 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -200,6 +200,7 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
    struct intel_region *region = irb->mt->region;
    struct gen7_surface_state *surf;
    uint32_t tile_x, tile_y;
+   gl_format rb_format = intel_rb_format(irb);
 
    surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,
 			  sizeof(*surf), 32, &brw->bind.surf_offset[unit]);
@@ -210,21 +211,21 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
    if (irb->mt->align_w == 8)
       surf->ss0.horizontal_alignment = 1;
 
-   switch (irb->Base.Format) {
+   switch (rb_format) {
    case MESA_FORMAT_SARGB8:
       /* without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB
 	 surfaces to the blend/update as sRGB */
       if (ctx->Color.sRGBEnabled)
-	 surf->ss0.surface_format = brw_format_for_mesa_format(irb->Base.Format);
+	 surf->ss0.surface_format = brw_format_for_mesa_format(rb_format);
       else
 	 surf->ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
       break;
    default:
-      assert(brw_render_target_supported(intel, irb->Base.Format));
-      surf->ss0.surface_format = brw->render_target_format[irb->Base.Format];
-      if (unlikely(!brw->format_supported_as_render_target[irb->Base.Format])) {
+      assert(brw_render_target_supported(intel, rb_format));
+      surf->ss0.surface_format = brw->render_target_format[rb_format];
+      if (unlikely(!brw->format_supported_as_render_target[rb_format])) {
 	 _mesa_problem(ctx, "%s: renderbuffer format %s unsupported\n",
-		       __FUNCTION__, _mesa_get_format_name(irb->Base.Format));
+		       __FUNCTION__, _mesa_get_format_name(rb_format));
       }
        break;
    }
diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c
index 1369e63..bafee4f 100644
--- a/src/mesa/drivers/dri/intel/intel_blit.c
+++ b/src/mesa/drivers/dri/intel/intel_blit.c
@@ -328,7 +328,7 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask)
 
 	 _mesa_unclamped_float_rgba_to_ubyte(clear, color);
 
-	 switch (irb->Base.Format) {
+	 switch (intel_rb_format(irb)) {
 	 case MESA_FORMAT_ARGB8888:
 	 case MESA_FORMAT_XRGB8888:
 	    clear_val = PACK_COLOR_8888(clear[3], clear[0],
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index ecc03a2..30a01bb 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -225,7 +225,7 @@ intel_flush_front(struct gl_context *ctx)
 static unsigned
 intel_bits_per_pixel(const struct intel_renderbuffer *rb)
 {
-   return _mesa_get_format_bytes(rb->Base.Format) * 8;
+   return _mesa_get_format_bytes(intel_rb_format(rb)) * 8;
 }
 
 static void
@@ -1066,7 +1066,7 @@ intel_process_dri2_buffer_no_separate_stencil(struct intel_context *intel,
 
       rb->mt = intel_miptree_create_for_region(intel,
                                                GL_TEXTURE_2D,
-                                               rb->Base.Format,
+                                               intel_rb_format(rb),
                                                region);
       intel_region_release(&region);
       if (!rb->mt)
@@ -1163,7 +1163,7 @@ intel_query_dri2_buffers_with_separate_stencil(struct intel_context *intel,
       (*attachments)[i++] = __DRI_BUFFER_DEPTH;
       (*attachments)[i++] = intel_bits_per_pixel(depth_rb);
 
-      if (intel->vtbl.is_hiz_depth_format(intel, depth_rb->Base.Format)) {
+      if (intel->vtbl.is_hiz_depth_format(intel, intel_rb_format(depth_rb))) {
 	 /* Depth and hiz buffer have same bpp. */
 	 (*attachments)[i++] = __DRI_BUFFER_HIZ;
 	 (*attachments)[i++] = intel_bits_per_pixel(depth_rb);
@@ -1171,7 +1171,7 @@ intel_query_dri2_buffers_with_separate_stencil(struct intel_context *intel,
    }
 
    if (stencil_rb) {
-      assert(stencil_rb->Base.Format == MESA_FORMAT_S8);
+      assert(intel_rb_format(stencil_rb) == MESA_FORMAT_S8);
       (*attachments)[i++] = __DRI_BUFFER_STENCIL;
       (*attachments)[i++] = intel_bits_per_pixel(stencil_rb);
    }
@@ -1283,7 +1283,7 @@ intel_process_dri2_buffer_with_separate_stencil(struct intel_context *intel,
    struct intel_mipmap_tree *mt =
       intel_miptree_create_for_region(intel,
 				      GL_TEXTURE_2D,
-				      rb->Base.Format,
+				      intel_rb_format(rb),
 				      region);
    intel_region_release(&region);
 
@@ -1366,8 +1366,8 @@ intel_verify_dri2_has_hiz(struct intel_context *intel,
        */
       struct intel_renderbuffer *depth_rb =
 	 intel_get_renderbuffer(fb, BUFFER_DEPTH);
-      assert(stencil_rb->Base.Format == MESA_FORMAT_S8);
-      assert(depth_rb && depth_rb->Base.Format == MESA_FORMAT_X8_Z24);
+      assert(intel_rb_format(stencil_rb) == MESA_FORMAT_S8);
+      assert(depth_rb && intel_rb_format(depth_rb) == MESA_FORMAT_X8_Z24);
 
       if (stencil_rb->mt->region->tiling == I915_TILING_NONE) {
 	 /*
@@ -1456,7 +1456,7 @@ intel_verify_dri2_has_hiz(struct intel_context *intel,
 	 struct intel_mipmap_tree *mt =
 	       intel_miptree_create_for_region(intel,
 	                                       GL_TEXTURE_2D,
-	                                       depth_stencil_rb->Base.Format,
+	                                       intel_rb_format(depth_stencil_rb),
 	                                       region);
 	 intel_region_release(&region);
 	 if (!mt)
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 5463776..2e400e7 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -822,16 +822,16 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 	 continue;
       }
 
-      if (!intel->vtbl.render_target_supported(intel, irb->Base.Format)) {
+      if (!intel->vtbl.render_target_supported(intel, intel_rb_format(irb))) {
 	 DBG("Unsupported HW texture/renderbuffer format attached: %s\n",
-	     _mesa_get_format_name(irb->Base.Format));
+	     _mesa_get_format_name(intel_rb_format(irb)));
 	 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
       }
 
 #ifdef I915
-      if (!intel_span_supports_format(irb->Base.Format)) {
+      if (!intel_span_supports_format(intel_rb_format(irb))) {
 	 DBG("Unsupported swrast texture/renderbuffer format attached: %s\n",
-	     _mesa_get_format_name(irb->Base.Format));
+	     _mesa_get_format_name(intel_rb_format(irb)));
 	 fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
       }
 #endif
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.h b/src/mesa/drivers/dri/intel/intel_fbo.h
index edba8e6..5a0d865 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.h
+++ b/src/mesa/drivers/dri/intel/intel_fbo.h
@@ -115,6 +115,14 @@ intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex)
    return intel_renderbuffer(rb);
 }
 
+
+static INLINE gl_format
+intel_rb_format(const struct intel_renderbuffer *rb)
+{
+   return rb->Base.Format;
+}
+
+
 bool
 intel_framebuffer_has_hiz(struct gl_framebuffer *fb);
 
diff --git a/src/mesa/drivers/dri/intel/intel_pixel_copy.c b/src/mesa/drivers/dri/intel/intel_pixel_copy.c
index 2682e15..18a8075 100644
--- a/src/mesa/drivers/dri/intel/intel_pixel_copy.c
+++ b/src/mesa/drivers/dri/intel/intel_pixel_copy.c
@@ -88,6 +88,7 @@ do_blit_copypixels(struct gl_context * ctx,
    bool flip = false;
    struct intel_renderbuffer *draw_irb = NULL;
    struct intel_renderbuffer *read_irb = NULL;
+   gl_format read_format, draw_format;
 
    /* Update draw buffer bounds */
    _mesa_update_state(ctx);
@@ -128,12 +129,15 @@ do_blit_copypixels(struct gl_context * ctx,
       return false;
    }
 
-   if (draw_irb->Base.Format != read_irb->Base.Format &&
-       !(draw_irb->Base.Format == MESA_FORMAT_XRGB8888 &&
-	 read_irb->Base.Format == MESA_FORMAT_ARGB8888)) {
+   read_format = intel_rb_format(read_irb);
+   draw_format = intel_rb_format(draw_irb);
+
+   if (draw_format != read_format &&
+       !(draw_format == MESA_FORMAT_XRGB8888 &&
+	 read_format == MESA_FORMAT_ARGB8888)) {
       fallback_debug("glCopyPixels() fallback: mismatched formats (%s -> %s\n",
-		     _mesa_get_format_name(read_irb->Base.Format),
-		     _mesa_get_format_name(draw_irb->Base.Format));
+		     _mesa_get_format_name(read_format),
+                     _mesa_get_format_name(draw_format));
       return false;
    }
 
diff --git a/src/mesa/drivers/dri/intel/intel_tex_copy.c b/src/mesa/drivers/dri/intel/intel_tex_copy.c
index b6e29f7..8617302 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_copy.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_copy.c
@@ -69,16 +69,16 @@ intel_copy_texsubimage(struct intel_context *intel,
       assert(region);
    }
 
-   copy_supported = intelImage->base.Base.TexFormat == irb->Base.Format;
+   copy_supported = intelImage->base.Base.TexFormat == intel_rb_format(irb);
 
    /* Converting ARGB8888 to XRGB8888 is trivial: ignore the alpha bits */
-   if (irb->Base.Format == MESA_FORMAT_ARGB8888 &&
+   if (intel_rb_format(irb) == MESA_FORMAT_ARGB8888 &&
        intelImage->base.Base.TexFormat == MESA_FORMAT_XRGB8888) {
       copy_supported = true;
    }
 
    /* Converting XRGB8888 to ARGB8888 requires setting the alpha bits to 1.0 */
-   if (irb->Base.Format == MESA_FORMAT_XRGB8888 &&
+   if (intel_rb_format(irb) == MESA_FORMAT_XRGB8888 &&
        intelImage->base.Base.TexFormat == MESA_FORMAT_ARGB8888) {
       copy_supported_with_alpha_override = true;
    }
@@ -88,7 +88,7 @@ intel_copy_texsubimage(struct intel_context *intel,
 	 fprintf(stderr, "%s mismatched formats %s, %s\n",
 		 __FUNCTION__,
 		 _mesa_get_format_name(intelImage->base.Base.TexFormat),
-		 _mesa_get_format_name(irb->Base.Format));
+		 _mesa_get_format_name(intel_rb_format(irb)));
       return false;
    }
 
commit c6e56a69d83f26ffe443abb6e7fe6ce4a2f90041
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:29:04 2012 -0700

    dri/swrast: rename swrast_renderbuffer to dri_swrast_renderbuffer
    
    To prevent name collision with future swrast_renderbuffer in the swrast
    module.
    (cherry picked from commit 1048d55d5fa60d17dd99ac7394ff0572500625f9)

diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index f7cb3c2..5f25d33 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -282,7 +282,7 @@ static GLboolean
 swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 			   GLenum internalFormat, GLuint width, GLuint height)
 {
-    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+    struct dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
 
     TRACE;
 
@@ -301,7 +301,7 @@ static GLboolean
 swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 			  GLenum internalFormat, GLuint width, GLuint height)
 {
-    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+    struct dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
 
     TRACE;
 
@@ -314,11 +314,11 @@ swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
     return GL_TRUE;
 }
 
-static struct swrast_renderbuffer *
+static struct dri_swrast_renderbuffer *
 swrast_new_renderbuffer(const struct gl_config *visual, __DRIdrawable *dPriv,
 			GLboolean front)
 {
-    struct swrast_renderbuffer *xrb = calloc(1, sizeof *xrb);
+    struct dri_swrast_renderbuffer *xrb = calloc(1, sizeof *xrb);
     GLuint pixel_format;
 
     TRACE;
@@ -379,7 +379,7 @@ swrast_map_renderbuffer(struct gl_context *ctx,
 			GLubyte **out_map,
 			GLint *out_stride)
 {
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+   struct dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
    GLubyte *map = rb->Buffer;
    int cpp = _mesa_get_format_bytes(rb->Format);
    int stride = rb->Width * cpp;
@@ -424,7 +424,7 @@ static void
 swrast_unmap_renderbuffer(struct gl_context *ctx,
 			  struct gl_renderbuffer *rb)
 {
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+   struct dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
 
    if (rb->AllocStorage == swrast_alloc_front_storage) {
       __DRIdrawable *dPriv = xrb->dPriv;
@@ -450,7 +450,7 @@ dri_create_buffer(__DRIscreen * sPriv,
 {
     struct dri_drawable *drawable = NULL;
     struct gl_framebuffer *fb;
-    struct swrast_renderbuffer *frontrb, *backrb;
+    struct dri_swrast_renderbuffer *frontrb, *backrb;
 
     TRACE;
 
@@ -531,16 +531,16 @@ dri_swap_buffers(__DRIdrawable * dPriv)
 
     struct dri_drawable *drawable = dri_drawable(dPriv);
     struct gl_framebuffer *fb;
-    struct swrast_renderbuffer *frontrb, *backrb;
+    struct dri_swrast_renderbuffer *frontrb, *backrb;
 
     TRACE;
 
     fb = &drawable->Base;
 
     frontrb =
-	swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
+	dri_swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
     backrb =
-	swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
+	dri_swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
 
     /* check for signle-buffered */
     if (backrb == NULL)
diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h
index 8695d4b..aa1979c 100644
--- a/src/mesa/drivers/dri/swrast/swrast_priv.h
+++ b/src/mesa/drivers/dri/swrast/swrast_priv.h
@@ -100,7 +100,7 @@ swrast_drawable(struct gl_framebuffer *fb)
     return (struct dri_drawable *) fb;
 }
 
-struct swrast_renderbuffer {
+struct dri_swrast_renderbuffer {
     struct gl_renderbuffer Base;
     __DRIdrawable *dPriv;
 
@@ -114,10 +114,10 @@ struct swrast_renderbuffer {
     GLuint bpp;
 };
 
-static INLINE struct swrast_renderbuffer *
-swrast_renderbuffer(struct gl_renderbuffer *rb)
+static INLINE struct dri_swrast_renderbuffer *
+dri_swrast_renderbuffer(struct gl_renderbuffer *rb)
 {
-    return (struct swrast_renderbuffer *) rb;
+    return (struct dri_swrast_renderbuffer *) rb;
 }
 
 
commit d980b8350f75ab2cec7363815951e83bb2ef7dfa
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:28:59 2012 -0700

    swrast: use stencil packing function in s_stencil.c
    (cherry picked from commit c45771905f237d9285465dfce955440582ee51e5)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 005423e..9aa7ffc 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -326,12 +326,14 @@ put_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
               const GLubyte stencil[])
 {
    const GLint w = rb->Width, h = rb->Height;
+   gl_pack_ubyte_stencil_func pack_stencil =
+      _mesa_get_pack_ubyte_stencil_func(rb->Format);
    GLuint i;
 
    for (i = 0; i < count; i++) {
       if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
          GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
-         _mesa_pack_ubyte_stencil_row(rb->Format, 1, &stencil[i], dst);
+         pack_stencil(&stencil[i], dst);
       }
    }
 }
commit 143999bdd830178957c5b3498f90a1c3495cc260
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:28:56 2012 -0700

    swrast: use color packing functions in s_span.c
    (cherry picked from commit 881ef2a9db22cff4c7d07b873d23b0c324da555a)

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 49529a8..dd70412 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1033,20 +1033,25 @@ put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
            GLuint count, const GLint x[], const GLint y[],
            const void *values, const GLubyte *mask)
 {
+   gl_pack_ubyte_rgba_func pack_ubyte;
+   gl_pack_float_rgba_func pack_float;
    GLuint i;
 
+   if (datatype == GL_UNSIGNED_BYTE)
+      pack_ubyte = _mesa_get_pack_ubyte_rgba_function(rb->Format);
+   else
+      pack_float = _mesa_get_pack_float_rgba_function(rb->Format);
+
    for (i = 0; i < count; i++) {
       if (mask[i]) {
          GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
 
          if (datatype == GL_UNSIGNED_BYTE) {
-            _mesa_pack_ubyte_rgba_row(rb->Format, 1,
-                                      (const GLubyte (*)[4]) values + i, dst);
+            pack_ubyte((const GLubyte *) values + 4 * i, dst);
          }
          else {
             assert(datatype == GL_FLOAT);
-            _mesa_pack_float_rgba_row(rb->Format, count,
-                                      (const GLfloat (*)[4]) values + i, dst);
+            pack_float((const GLfloat *) values + 4 * i, dst);
          }
       }
    }
commit ae3bd76e31d85f9d5c628c2d609967378293aad3
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:28:51 2012 -0700

    swrast: remove s_spantemp.h
    (cherry picked from commit 8696a5210289166ce39d765d771258258400e876)

diff --git a/src/mesa/swrast/s_spantemp.h b/src/mesa/swrast/s_spantemp.h
deleted file mode 100644
index 2d2561b..0000000
--- a/src/mesa/swrast/s_spantemp.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  6.5.1
- *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/*
- * Templates for the span/pixel-array write/read functions called via
- * the gl_renderbuffer's GetRow, GetValues, PutRow, and PutValues.
- *
- * Define the following macros before including this file:
- *   NAME(BASE)  to generate the function name (i.e. add prefix or suffix)
- *   RB_TYPE  the renderbuffer DataType
- *   SPAN_VARS  to declare any local variables
- *   INIT_PIXEL_PTR(P, X, Y)  to initialize a pointer to a pixel
- *   INC_PIXEL_PTR(P)  to increment a pixel pointer by one pixel
- *   STORE_PIXEL(DST, X, Y, VALUE)  to store pixel values in buffer
- *   FETCH_PIXEL(DST, SRC)  to fetch pixel values from buffer
- *
- * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
- * for the pixels to be stored.  This is useful when dithering and probably
- * ignored otherwise.
- */
-
-#include "main/macros.h"
-
-
-#if !defined(RB_COMPONENTS)
-#define RB_COMPONENTS 4
-#endif
-
-
-static void
-NAME(get_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-               GLuint count, GLint x, GLint y, void *values )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   INIT_PIXEL_PTR(pixel, x, y);
-   for (i = 0; i < count; i++) {
-      FETCH_PIXEL(dest[i], pixel);
-      INC_PIXEL_PTR(pixel);
-   }
-   (void) rb;
-   (void) ctx;
-}
-
-
-static void
-NAME(get_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-                  GLuint count, const GLint x[], const GLint y[], void *values )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   for (i = 0; i < count; i++) {
-      INIT_PIXEL_PTR(pixel, x[i], y[i]);
-      FETCH_PIXEL(dest[i], pixel);
-   }
-   (void) rb;
-   (void) ctx;
-}
-
-
-static void
-NAME(put_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-               GLuint count, GLint x, GLint y,
-               const void *values, const GLubyte mask[] )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   INIT_PIXEL_PTR(pixel, x, y);
-   if (mask) {
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            STORE_PIXEL(pixel, x + i, y, src[i]);
-         }
-         INC_PIXEL_PTR(pixel);
-      }
-   }
-   else {
-      for (i = 0; i < count; i++) {
-         STORE_PIXEL(pixel, x + i, y, src[i]);
-         INC_PIXEL_PTR(pixel);
-      }
-   }
-   (void) rb;
-   (void) ctx;
-}
-
-
-static void
-NAME(put_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-                  GLuint count, const GLint x[], const GLint y[],
-                  const void *values, const GLubyte mask[] )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   ASSERT(mask);
-   for (i = 0; i < count; i++) {
-      if (mask[i]) {
-         INIT_PIXEL_PTR(pixel, x[i], y[i]);
-         STORE_PIXEL(pixel, x[i], y[i], src[i]);
-      }
-   }
-   (void) rb;
-   (void) ctx;
-}
-
-
-#undef NAME
-#undef RB_TYPE
-#undef RB_COMPONENTS
-#undef SPAN_VARS
-#undef INIT_PIXEL_PTR
-#undef INC_PIXEL_PTR
-#undef STORE_PIXEL
-#undef STORE_PIXEL_RGB
-#undef FETCH_PIXEL
commit 86fc256131b44206604e225bee71385e7b5f5f49
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:28:47 2012 -0700

    xlib: remove xm_span.c and related code
    (cherry picked from commit b0f0d7a8118401b209c674804255b5fd9e8c94c0)

diff --git a/src/mesa/drivers/x11/Makefile b/src/mesa/drivers/x11/Makefile
index 412fbfe..437c4f3 100644
--- a/src/mesa/drivers/x11/Makefile
+++ b/src/mesa/drivers/x11/Makefile
@@ -30,7 +30,6 @@ SOURCES = \
 	xm_buffer.c \
 	xm_dd.c \
 	xm_line.c \
-	xm_span.c \
 	xm_tri.c
 
 OBJECTS = $(SOURCES:.c=.o)
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index d0374ec..0f41218 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -600,8 +600,6 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b,
    }
 
    if (b && window) {
-      char *data;
-
       /* Do window-specific initializations */
 
       /* these should have been set in create_xmesa_buffer */
@@ -633,19 +631,6 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b,
                                GCGraphicsExposures, &gcvalues);
       }
       XMesaSetFunction( v->display, b->swapgc, GXcopy );
-
-      /* Initialize the row buffer XImage for use in write_color_span() */
-      data = (char*) MALLOC(MAX_WIDTH*4);
-      b->rowimage = XCreateImage( v->display,
-                                  v->visinfo->visual,
-                                  v->visinfo->depth,
-                                  ZPixmap, 0,           /*format, offset*/
-                                  data,                 /*data*/
-                                  MAX_WIDTH, 1,         /*width, height*/
-                                  32,                   /*bitmap_pad*/
-                                  0                     /*bytes_per_line*/ );
-      if (!b->rowimage)
-         return GL_FALSE;
    }
 
    return GL_TRUE;
diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c
index 0f1d960..64a8f43 100644
--- a/src/mesa/drivers/x11/xm_buffer.c
+++ b/src/mesa/drivers/x11/xm_buffer.c
@@ -409,12 +409,6 @@ xmesa_delete_framebuffer(struct gl_framebuffer *fb)
       }
    }
 
-   if (b->rowimage) {
-      free( b->rowimage->data );
-      b->rowimage->data = NULL;
-      XMesaDestroyImage( b->rowimage );
-   }
-
    _mesa_free_framebuffer_data(fb);
    free(fb);
 }
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c
index b1439d8..342d2d9 100644
--- a/src/mesa/drivers/x11/xm_dd.c
+++ b/src/mesa/drivers/x11/xm_dd.c
@@ -720,15 +720,11 @@ xmesa_update_state( struct gl_context *ctx, GLbitfield new_state )
 
       front_xrb = xmbuf->frontxrb;
       if (front_xrb) {
-         xmesa_set_renderbuffer_funcs(front_xrb, xmesa->pixelformat,
-                                      xmesa->xm_visual->BitsPerPixel);
          front_xrb->clearFunc = clear_pixmap;
       }
 
       back_xrb = xmbuf->backxrb;
       if (back_xrb) {
-         xmesa_set_renderbuffer_funcs(back_xrb, xmesa->pixelformat,
-                                      xmesa->xm_visual->BitsPerPixel);
          if (xmbuf->backxrb->pixmap) {
             back_xrb->clearFunc = clear_pixmap;
          }
diff --git a/src/mesa/drivers/x11/xm_span.c b/src/mesa/drivers/x11/xm_span.c
deleted file mode 100644
index be4e545..0000000
--- a/src/mesa/drivers/x11/xm_span.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  6.3
- *
- * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "glxheader.h"
-#include "main/context.h"
-#include "main/macros.h"
-#include "main/imports.h"
-#include "main/mtypes.h"
-#include "xmesaP.h"
-
-#include "swrast/swrast.h"
-
-
-/*
- * The following functions are used to trap XGetImage() calls which
- * generate BadMatch errors if the drawable isn't mapped.
- */
-
-static int caught_xgetimage_error = 0;
-static int (*old_xerror_handler)( XMesaDisplay *dpy, XErrorEvent *ev );
-static unsigned long xgetimage_serial;
-
-/*
- * This is the error handler which will be called if XGetImage fails.
- */
-static int xgetimage_error_handler( XMesaDisplay *dpy, XErrorEvent *ev )
-{
-   if (ev->serial==xgetimage_serial && ev->error_code==BadMatch) {
-      /* caught the expected error */
-      caught_xgetimage_error = 0;
-   }
-   else {
-      /* call the original X error handler, if any.  otherwise ignore */
-      if (old_xerror_handler) {
-         (*old_xerror_handler)( dpy, ev );
-      }
-   }
-   return 0;
-}
-
-
-/*
- * Call this right before XGetImage to setup error trap.
- */
-static void catch_xgetimage_errors( XMesaDisplay *dpy )
-{
-   xgetimage_serial = NextRequest( dpy );
-   old_xerror_handler = XSetErrorHandler( xgetimage_error_handler );
-   caught_xgetimage_error = 0;
-}
-
-
-/*
- * Call this right after XGetImage to check if an error occured.
- */
-static int check_xgetimage_errors( void )
-{
-   /* restore old handler */
-   (void) XSetErrorHandler( old_xerror_handler );
-   /* return 0=no error, 1=error caught */
-   return caught_xgetimage_error;
-}
-
-
-/*
- * Read a pixel from an X drawable.
- */
-static unsigned long read_pixel( XMesaDisplay *dpy,
-                                 XMesaDrawable d, int x, int y )
-{
-   unsigned long p;
-   XMesaImage *pixel = NULL;
-   int error;
-
-   catch_xgetimage_errors( dpy );
-   pixel = XGetImage( dpy, d, x, y, 1, 1, AllPlanes, ZPixmap );
-   error = check_xgetimage_errors();
-   if (pixel && !error) {
-      p = XMesaGetPixel( pixel, 0, 0 );
-   }
-   else {
-      p = 0;
-   }
-   if (pixel) {
-      XMesaDestroyImage( pixel );
-   }
-   return p;
-}
-
-
-
-/*
- * The Mesa library needs to be able to draw pixels in a number of ways:
- *   1. RGB vs Color Index
- *   2. as horizontal spans (polygons, images) vs random locations (points,
- *      lines)
- *   3. different color per-pixel or same color for all pixels
- *
- * Furthermore, the X driver needs to support rendering to 3 possible
- * "buffers", usually one, but sometimes two at a time:
- *   1. The front buffer as an X window
- *   2. The back buffer as a Pixmap
- *   3. The back buffer as an XImage
- *
- * Finally, if the back buffer is an XImage, we can avoid using XPutPixel and
- * optimize common cases such as 24-bit and 8-bit modes.
- *
- * By multiplication, there's at least 48 possible combinations of the above.
- *
- * Below are implementations of the most commonly used combinations.  They are
- * accessed through function pointers which get initialized here and are used
- * directly from the Mesa library.  The 8 function pointers directly correspond
- * to the first 3 cases listed above.
- *
- *
- * The function naming convention is:
- *
- *   [put|get]_[row|values]_[format]_[pixmap|ximage]
- *
- * New functions optimized for specific cases can be added without too much
- * trouble.  An example might be the 24-bit TrueColor mode 8A8R8G8B which is
- * found on IBM RS/6000 X servers.
- */
-
-
-
-
-
-
-
-/**********************************************************************/
-/*****                      Pixel reading                         *****/
-/**********************************************************************/
-
-/**
- * Do clip testing prior to calling XGetImage.  If any of the region lies
- * outside the screen's bounds, XGetImage will return NULL.
- * We use XTranslateCoordinates() to check if that's the case and
- * adjust the x, y and length parameters accordingly.
- * \return  -1 if span is totally clipped away,
- *          else return number of pixels to skip in the destination array.
- */
-static int
-clip_for_xgetimage(struct gl_context *ctx, XMesaPixmap pixmap, GLuint *n, GLint *x, GLint *y)
-{
-   XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
-   Window rootWin = RootWindow(xmesa->display, 0);
-   Window child;
-   GLint screenWidth = WidthOfScreen(DefaultScreenOfDisplay(xmesa->display));
-   GLint dx, dy;
-   if (source->type == PBUFFER || source->type == PIXMAP)
-      return 0;
-   XTranslateCoordinates(xmesa->display, pixmap, rootWin,
-                         *x, *y, &dx, &dy, &child);
-   if (dx >= screenWidth) {
-      /* totally clipped on right */
-      return -1;
-   }
-   if (dx < 0) {
-      /* clipped on left */
-      GLint clip = -dx;
-      if (clip >= (GLint) *n)
-         return -1;  /* totally clipped on left */
-      *x += clip;
-      *n -= clip;
-      dx = 0;
-      return clip;
-   }
-   if ((GLint) (dx + *n) > screenWidth) {
-      /* clipped on right */
-      GLint clip = dx + *n - screenWidth;
-      *n -= clip;
-   }
-   return 0;
-}
-
-
-#define GET_XRB(XRB) \
-   struct xmesa_renderbuffer *XRB = xmesa_renderbuffer(rb)
-
-
-
-
-
-/**
- * Initialize the renderbuffer's PutRow, GetRow, etc. functions.
- * This would generally only need to be called once when the renderbuffer
- * is created.  However, we can change pixel formats on the fly if dithering
- * is enabled/disabled.  Therefore, we may call this more often than that.
- */
-void
-xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
-                             enum pixel_format pixelformat, GLint depth)
-{
-   /* XXX remove this */
-}
-
diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h
index 7e1cb8a..7caa356 100644
--- a/src/mesa/drivers/x11/xmesaP.h
+++ b/src/mesa/drivers/x11/xmesaP.h
@@ -209,7 +209,7 @@ struct xmesa_buffer {
    XShmSegmentInfo shminfo;
 #endif
 
-   XMesaImage *rowimage;	/* Used for optimized span writing */
+   //   XMesaImage *rowimage;	/* Used for optimized span writing */
    XMesaPixmap stipple_pixmap;	/* For polygon stippling */
    XMesaGC stipple_gc;		/* For polygon stippling */
 
@@ -355,9 +355,6 @@ xmesa_init_driver_functions( XMesaVisual xmvisual,
 extern void
 xmesa_update_state( struct gl_context *ctx, GLbitfield new_state );
 
-extern void
-xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
-                             enum pixel_format pixelformat, GLint depth);
 
 extern void
 xmesa_MapRenderbuffer(struct gl_context *ctx,
commit 5cb5aa4a846861fa46369ac4b144160d8519b708
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:28:42 2012 -0700

    mesa: remove gl_renderbuffer::Wrapped
    
    There's no such thing as renderbuffer wrappers anymore.
    (cherry picked from commit 59a5b5a193d5d9c5776aa586b34657b6e315479d)

diff --git a/src/mesa/drivers/dri/nouveau/nouveau_driver.c b/src/mesa/drivers/dri/nouveau/nouveau_driver.c
index d1e269af..ba818f0 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_driver.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_driver.c
@@ -96,7 +96,7 @@ nouveau_clear(struct gl_context *ctx, GLbitfield buffers)
 			continue;
 
 		s = &to_nouveau_renderbuffer(
-			fb->Attachment[i].Renderbuffer->Wrapped)->surface;
+			fb->Attachment[i].Renderbuffer)->surface;
 
 		if (buf & BUFFER_BITS_COLOR) {
 			mask = pack_rgba_i(s->format, ctx->Color.ColorMask[0]);
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c
index 9ab77e2..b1439d8 100644
--- a/src/mesa/drivers/x11/xm_dd.c
+++ b/src/mesa/drivers/x11/xm_dd.c
@@ -329,7 +329,7 @@ can_do_DrawPixels_8R8G8B(struct gl_context *ctx, GLenum format, GLenum type)
       if ((swrast->_RasterMask & ~CLIP_BIT) == 0) /* no blend, z-test, etc */ {
          struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
          if (rb) {
-            struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb->Wrapped);
+            struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
             if (xrb &&
                 xrb->pixmap && /* drawing to pixmap or window */
                 _mesa_get_format_bits(xrb->Base.Format, GL_ALPHA_BITS) == 0) {
@@ -393,7 +393,7 @@ xmesa_DrawPixels_8R8G8B( struct gl_context *ctx,
          XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
          const XMesaGC gc = xmbuf->cleargc;  /* effected by glColorMask */
          struct xmesa_renderbuffer *xrb
-            = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+            = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
          const int srcX = clippedUnpack.SkipPixels;
          const int srcY = clippedUnpack.SkipRows;
          const int rowLength = clippedUnpack.RowLength;
@@ -462,7 +462,7 @@ can_do_DrawPixels_5R6G5B(struct gl_context *ctx, GLenum format, GLenum type)
       if ((swrast->_RasterMask & ~CLIP_BIT) == 0) /* no blend, z-test, etc */ {
          struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
          if (rb) {
-            struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb->Wrapped);
+            struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
             if (xrb &&
                 xrb->pixmap && /* drawing to pixmap or window */
                 _mesa_get_format_bits(xrb->Base.Format, GL_ALPHA_BITS) == 0) {
@@ -527,7 +527,7 @@ xmesa_DrawPixels_5R6G5B( struct gl_context *ctx,
          XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
          const XMesaGC gc = xmbuf->cleargc;  /* effected by glColorMask */
          struct xmesa_renderbuffer *xrb
-            = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+            = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
          const int srcX = clippedUnpack.SkipPixels;
          const int srcY = clippedUnpack.SkipRows;
          const int rowLength = clippedUnpack.RowLength;
@@ -597,9 +597,9 @@ can_do_CopyPixels(struct gl_context *ctx, GLenum type)
           ctx->DrawBuffer &&
           ctx->DrawBuffer->_ColorDrawBuffers[0]) {
          struct xmesa_renderbuffer *srcXrb
-            = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer->Wrapped);
+            = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
          struct xmesa_renderbuffer *dstXrb
-            = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+            = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
          if (srcXrb->pixmap && dstXrb->pixmap) {
             return GL_TRUE;
          }
@@ -625,9 +625,9 @@ xmesa_CopyPixels( struct gl_context *ctx,
       XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);
       const XMesaGC gc = xmbuf->cleargc;  /* effected by glColorMask */
       struct xmesa_renderbuffer *srcXrb
-         = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer->Wrapped);
+         = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
       struct xmesa_renderbuffer *dstXrb
-         = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+         = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
 
       ASSERT(dpy);
       ASSERT(gc);
diff --git a/src/mesa/drivers/x11/xm_line.c b/src/mesa/drivers/x11/xm_line.c
index ad0336f..dc2687d 100644
--- a/src/mesa/drivers/x11/xm_line.c
+++ b/src/mesa/drivers/x11/xm_line.c
@@ -120,7 +120,7 @@ void xmesa_choose_point( struct gl_context *ctx )
 
 
 #define GET_XRB(XRB)  struct xmesa_renderbuffer *XRB = \
-   xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped)
+   xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0])
 
 
 /*
@@ -461,7 +461,7 @@ get_line_func(struct gl_context *ctx)
    if (ctx->Line.StippleFlag)             return (swrast_line_func) NULL;
    if (swrast->_RasterMask & MULTI_DRAW_BIT) return (swrast_line_func) NULL;
 
-   xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+   xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
 
    if (xrb->ximage
        && swrast->_RasterMask==DEPTH_BIT
diff --git a/src/mesa/drivers/x11/xm_tri.c b/src/mesa/drivers/x11/xm_tri.c
index a2dbf57..12a2049 100644
--- a/src/mesa/drivers/x11/xm_tri.c
+++ b/src/mesa/drivers/x11/xm_tri.c
@@ -43,7 +43,7 @@
 
 
 #define GET_XRB(XRB)  struct xmesa_renderbuffer *XRB = \
-   xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped)
+   xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0])
 
 
 /**********************************************************************/
@@ -1023,7 +1023,7 @@ get_triangle_func(struct gl_context *ctx)
        ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
       return (swrast_tri_func) NULL;
 
-   xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]->Wrapped);
+   xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]);
 
    if (xrb->ximage) {
       if (   ctx->Light.ShadeModel==GL_SMOOTH
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 996f68a..fc66791 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2546,9 +2546,6 @@ struct gl_renderbuffer
    GLubyte *Map;
    GLint RowStrideBytes;
 
-   /* Used to wrap one renderbuffer around another: */
-   struct gl_renderbuffer *Wrapped;
-
    /* Delete this renderbuffer */
    void (*Delete)(struct gl_renderbuffer *rb);
 
diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index cb19f53..d139386 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -54,11 +54,6 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
    rb->Height = 0;
    rb->InternalFormat = GL_RGBA;
    rb->Format = MESA_FORMAT_NONE;
-
-   /* Point back to ourself so that we don't have to check for Wrapped==NULL
-    * all over the drivers.
-    */
-   rb->Wrapped = rb;
 }
 
 
diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c
index 76386fe..a8907c1 100644
--- a/src/mesa/state_tracker/st_atom_framebuffer.c
+++ b/src/mesa/state_tracker/st_atom_framebuffer.c
@@ -139,7 +139,6 @@ update_framebuffer_state( struct st_context *st )
     */
    strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
    if (strb) {
-      strb = st_renderbuffer(strb->Base.Wrapped);
       if (strb->rtt) {
          /* rendering to a GL texture, may have to update surface */
          update_renderbuffer_surface(st, strb);
@@ -149,7 +148,6 @@ update_framebuffer_state( struct st_context *st )
    else {
       strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
       if (strb) {
-         strb = st_renderbuffer(strb->Base.Wrapped);
          assert(strb->surface);
          pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
       }
commit f0ad188c9fac676cf0f2a752707ce1edd2e7f708
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:27:50 2012 -0700

    swrast: rewrite, simplify the the render-to-texture code
    (cherry picked from commit ab331140c68d1c157e69ea8e53b44729355fa43c)

diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index af4be7b..ebfba6d 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -15,40 +15,6 @@
  */
 
 
-/**
- * Derived from gl_renderbuffer class
- */
-struct texture_renderbuffer
-{
-   struct gl_renderbuffer Base;   /**< Base class object */
-   struct swrast_texture_image *TexImage;
-   StoreTexelFunc Store;
-   FetchTexelFunc Fetch;
-   GLint Yoffset;                 /**< Layer for 1D array textures. */
-   GLint Zoffset;                 /**< Layer for 2D array textures, or slice
-				   * for 3D textures
-				   */
-};
-
-
-/** cast wrapper */
-static inline struct texture_renderbuffer *
-texture_renderbuffer(struct gl_renderbuffer *rb)
-{
-   return (struct texture_renderbuffer *) rb;
-}
-
-
-
-
-static void
-store_nop(struct swrast_texture_image *texImage,
-          GLint col, GLint row, GLint img,
-          const void *texel)
-{
-}
-
-
 static void
 delete_texture_wrapper(struct gl_renderbuffer *rb)
 {
@@ -65,26 +31,26 @@ delete_texture_wrapper(struct gl_renderbuffer *rb)
 static void
 wrap_texture(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 {
-   struct texture_renderbuffer *trb;
+   struct gl_renderbuffer *rb;
    const GLuint name = 0;
 
    ASSERT(att->Type == GL_TEXTURE);
    ASSERT(att->Renderbuffer == NULL);
 
-   trb = CALLOC_STRUCT(texture_renderbuffer);
-   if (!trb) {
+   rb = CALLOC_STRUCT(gl_renderbuffer);
+   if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "wrap_texture");
       return;
    }
 
    /* init base gl_renderbuffer fields */
-   _mesa_init_renderbuffer(&trb->Base, name);
+   _mesa_init_renderbuffer(rb, name);
    /* plug in our texture_renderbuffer-specific functions */
-   trb->Base.Delete = delete_texture_wrapper;
-   trb->Base.AllocStorage = NULL; /* illegal! */
+   rb->Delete = delete_texture_wrapper;
+   rb->AllocStorage = NULL; /* illegal! */
 
    /* update attachment point */
-   _mesa_reference_renderbuffer(&att->Renderbuffer, &(trb->Base));
+   _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
 }
 
 /**
@@ -95,89 +61,43 @@ wrap_texture(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 static void
 update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 {
-   struct texture_renderbuffer *trb
-      = (struct texture_renderbuffer *) att->Renderbuffer;
+   struct gl_renderbuffer *rb = att->Renderbuffer;
+   struct swrast_texture_image *swImage;
+   gl_format format;
+   GLuint zOffset;
 
    (void) ctx;
-   ASSERT(trb);
 
-   trb->TexImage = swrast_texture_image(_mesa_get_attachment_teximage(att));
-   ASSERT(trb->TexImage);
-
-   trb->Store = _mesa_get_texel_store_func(trb->TexImage->Base.TexFormat);
-   if (!trb->Store) {
-      /* we'll never draw into some textures (compressed formats) */
-      trb->Store = store_nop;
-   }
+   swImage = swrast_texture_image(_mesa_get_attachment_teximage(att));
+   assert(swImage);
 
-   if (!trb->TexImage->FetchTexel) {
-      _mesa_update_fetch_functions(trb->TexImage->Base.TexObject);
-   }
-   trb->Fetch = trb->TexImage->FetchTexel;
-   assert(trb->Fetch);
+   format = swImage->Base.TexFormat;
 
    if (att->Texture->Target == GL_TEXTURE_1D_ARRAY_EXT) {
-      trb->Yoffset = att->Zoffset;
-      trb->Zoffset = 0;
+      zOffset = 0;
    }
    else {
-      trb->Yoffset = 0;
-      trb->Zoffset = att->Zoffset;
+      zOffset = att->Zoffset;
    }
 
-   trb->Base.Width = trb->TexImage->Base.Width;
-   trb->Base.Height = trb->TexImage->Base.Height;
-   trb->Base.InternalFormat = trb->TexImage->Base.InternalFormat;
-   trb->Base.Format = trb->TexImage->Base.TexFormat;
-
-   /* Set the gl_renderbuffer::Data field so that mapping the buffer
-    * in renderbuffer.c succeeds.
-    */
+   rb->Width = swImage->Base.Width;
+   rb->Height = swImage->Base.Height;
+   rb->InternalFormat = swImage->Base.InternalFormat;
+   rb->_BaseFormat = _mesa_get_format_base_format(format);
+
+   /* Want to store linear values, not sRGB */
+   rb->Format = _mesa_get_srgb_format_linear(format);
+ 
+   /* Set the gl_renderbuffer::Buffer field so that mapping the buffer
+    * succeeds.
+     */
    if (att->Texture->Target == GL_TEXTURE_3D ||
        att->Texture->Target == GL_TEXTURE_2D_ARRAY_EXT) {
-      trb->Base.Buffer = trb->TexImage->Buffer +
-         trb->TexImage->ImageOffsets[trb->Zoffset] *
-         _mesa_get_format_bytes(trb->TexImage->Base.TexFormat);
+      rb->Buffer = swImage->Buffer +
+         swImage->ImageOffsets[zOffset] * _mesa_get_format_bytes(format);
    }
    else {
-      trb->Base.Buffer = trb->TexImage->Buffer;
-   }
-
-   /* XXX may need more special cases here */
-   switch (trb->TexImage->Base.TexFormat) {
-   case MESA_FORMAT_Z24_S8:
-      trb->Base._BaseFormat = GL_DEPTH_STENCIL;
-      break;
-   case MESA_FORMAT_S8_Z24:
-      trb->Base._BaseFormat = GL_DEPTH_STENCIL;
-      break;
-   case MESA_FORMAT_Z24_X8:
-      trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
-      break;
-   case MESA_FORMAT_X8_Z24:
-      trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
-      break;
-   case MESA_FORMAT_Z16:
-      trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
-      break;
-   case MESA_FORMAT_Z32:
-      trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
-      break;
-   /* SRGB formats pre EXT_framebuffer_sRGB don't do sRGB translations on FBO readback */
-   case MESA_FORMAT_SRGB8:
-      trb->Fetch = _mesa_get_texel_fetch_func(MESA_FORMAT_RGB888, _mesa_get_texture_dimensions(att->Texture->Target));
-      trb->Base._BaseFormat = GL_RGBA;
-      break;
-   case MESA_FORMAT_SRGBA8:
-      trb->Fetch = _mesa_get_texel_fetch_func(MESA_FORMAT_RGBA8888, _mesa_get_texture_dimensions(att->Texture->Target));
-      trb->Base._BaseFormat = GL_RGBA;
-      break;
-   case MESA_FORMAT_SARGB8:
-      trb->Fetch = _mesa_get_texel_fetch_func(MESA_FORMAT_ARGB8888, _mesa_get_texture_dimensions(att->Texture->Target));
-      trb->Base._BaseFormat = GL_RGBA;
-      break;
-   default:
-      trb->Base._BaseFormat = GL_RGBA;
+      rb->Buffer = swImage->Buffer;
    }
 }
 
commit 8786555199e0916be516492e512afcdb01dc7eb5
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:10:46 2012 -0700

    mesa: rename gl_renderbuffer::Data to Buffer
    
    To better indicate that this pointer to the malloc'd memory.
    (cherry picked from commit 7a36345f70a0b8ac2d480bb52eb2c74c2be5a978)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index e13d62c..5463776 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -132,11 +132,11 @@ intel_map_renderbuffer(struct gl_context *ctx,
    void *map;
    int stride;
 
-   if (!irb && rb->Data) {
+   if (!irb && rb->Buffer) {
       /* this is a malloc'd renderbuffer (accum buffer) */
       GLint bpp = _mesa_get_format_bytes(rb->Format);
       GLint rowStride = rb->RowStrideBytes;
-      *out_map = (GLubyte *) rb->Data + y * rowStride + x * bpp;
+      *out_map = (GLubyte *) rb->Buffer + y * rowStride + x * bpp;
       *out_stride = rowStride;
       return;
    }
@@ -185,7 +185,7 @@ intel_unmap_renderbuffer(struct gl_context *ctx,
    DBG("%s: rb %d (%s)\n", __FUNCTION__,
        rb->Name, _mesa_get_format_name(rb->Format));
 
-   if (!irb && rb->Data) {
+   if (!irb && rb->Buffer) {
       /* this is a malloc'd renderbuffer (accum buffer) */
       /* nothing to do */
       return;
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 19da702..f7cb3c2 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -265,7 +265,7 @@ swrast_delete_renderbuffer(struct gl_renderbuffer *rb)
 {
     TRACE;
 
-    free(rb->Data);
+    free(rb->Buffer);
     free(rb);
 }
 
@@ -289,7 +289,7 @@ swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
     (void) ctx;
     (void) internalFormat;
 
-    rb->Data = NULL;
+    rb->Buffer = NULL;
     rb->Width = width;
     rb->Height = height;
     xrb->pitch = bytes_per_line(width * xrb->bpp, 32);
@@ -305,11 +305,11 @@ swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
     TRACE;
 
-    free(rb->Data);
+    free(rb->Buffer);
 
     swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
 
-    rb->Data = malloc(height * xrb->pitch);
+    rb->Buffer = malloc(height * xrb->pitch);
 
     return GL_TRUE;
 }
@@ -380,7 +380,7 @@ swrast_map_renderbuffer(struct gl_context *ctx,
 			GLint *out_stride)
 {
    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-   GLubyte *map = rb->Data;
+   GLubyte *map = rb->Buffer;
    int cpp = _mesa_get_format_bytes(rb->Format);
    int stride = rb->Width * cpp;
 
@@ -395,18 +395,18 @@ swrast_map_renderbuffer(struct gl_context *ctx,
       xrb->map_h = h;
 
       stride = w * cpp;
-      rb->Data = malloc(h * stride);
+      rb->Buffer = malloc(h * stride);
 
       sPriv->swrast_loader->getImage(dPriv, x, y, w, h,
-				     (char *)rb->Data,
+				     (char *)rb->Buffer,
 				     dPriv->loaderPrivate);
 
-      *out_map = rb->Data;
+      *out_map = rb->Buffer;
       *out_stride = stride;
       return;
    }
 
-   ASSERT(rb->Data);
+   ASSERT(rb->Buffer);
 
    if (rb->AllocStorage == swrast_alloc_back_storage) {
       map += (rb->Height - 1) * stride;
@@ -434,12 +434,12 @@ swrast_unmap_renderbuffer(struct gl_context *ctx,
 	 sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_DRAW,
 					xrb->map_x, xrb->map_y,
 					xrb->map_w, xrb->map_h,
-					rb->Data,
+					rb->Buffer,
 					dPriv->loaderPrivate);
       }
 
-      free(rb->Data);
-      rb->Data = NULL;
+      free(rb->Buffer);
+      rb->Buffer = NULL;
    }
 }
 
@@ -556,7 +556,7 @@ dri_swap_buffers(__DRIdrawable * dPriv)
 				   0, 0,
 				   frontrb->Base.Width,
 				   frontrb->Base.Height,
-				   backrb->Base.Data,
+				   backrb->Base.Buffer,
 				   dPriv->loaderPrivate);
 }
 
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 5c1a3f3..1c4f52b 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -354,7 +354,7 @@ static void
 compute_row_addresses( OSMesaContext osmesa )
 {
    GLint bytesPerRow, i;
-   GLubyte *origin = (GLubyte *) osmesa->rb->Data;
+   GLubyte *origin = (GLubyte *) osmesa->rb->Buffer;
    GLint rowlength; /* in pixels */
    GLint height = osmesa->rb->Height;
 
@@ -383,7 +383,7 @@ compute_row_addresses( OSMesaContext osmesa )
 
 
 /**
- * Don't use _mesa_delete_renderbuffer since we can't free rb->Data.
+ * Don't use _mesa_delete_renderbuffer since we can't free rb->Buffer.
  */
 static void
 osmesa_delete_renderbuffer(struct gl_renderbuffer *rb)
@@ -891,7 +891,7 @@ OSMesaMakeCurrent( OSMesaContext osmesa, void *buffer, GLenum type,
    /* Set renderbuffer fields.  Set width/height = 0 to force 
     * osmesa_renderbuffer_storage() being called by _mesa_resize_framebuffer()
     */
-   osmesa->rb->Data = buffer;
+   osmesa->rb->Buffer = buffer;
    osmesa->rb->Width = osmesa->rb->Height = 0;
 
    /* Set the framebuffer's size.  This causes the
@@ -1024,7 +1024,7 @@ OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
    if (c->gl_buffer)
       rb = c->gl_buffer->Attachment[BUFFER_DEPTH].Renderbuffer;
 
-   if (!rb || !rb->Data) {
+   if (!rb || !rb->Buffer) {
       *width = 0;
       *height = 0;
       *bytesPerValue = 0;
@@ -1038,7 +1038,7 @@ OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
          *bytesPerValue = sizeof(GLushort);
       else
          *bytesPerValue = sizeof(GLuint);
-      *buffer = rb->Data;
+      *buffer = (void *) rb->Buffer;
       return GL_TRUE;
    }
 }
@@ -1056,11 +1056,11 @@ GLAPI GLboolean GLAPIENTRY
 OSMesaGetColorBuffer( OSMesaContext osmesa, GLint *width,
                       GLint *height, GLint *format, void **buffer )
 {
-   if (osmesa->rb && osmesa->rb->Data) {
+   if (osmesa->rb && osmesa->rb->Buffer) {
       *width = osmesa->rb->Width;
       *height = osmesa->rb->Height;
       *format = osmesa->format;
-      *buffer = osmesa->rb->Data;
+      *buffer = (void *) osmesa->rb->Buffer;
       return GL_TRUE;
    }
    else {
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index bdee2a2..d0374ec 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -1484,7 +1484,7 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height,
 {
    struct gl_renderbuffer *rb
       = b->mesa_buffer.Attachment[BUFFER_DEPTH].Renderbuffer;
-   if (!rb || !rb->Data) {
+   if (!rb || !rb->Buffer) {
       *width = 0;
       *height = 0;
       *bytesPerValue = 0;
@@ -1496,7 +1496,7 @@ GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height,
       *height = b->mesa_buffer.Height;
       *bytesPerValue = b->mesa_buffer.Visual.depthBits <= 16
          ? sizeof(GLushort) : sizeof(GLuint);
-      *buffer = rb->Data;
+      *buffer = (void *) rb->Buffer;
       return GL_TRUE;
    }
 }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 3e8d171..996f68a 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2540,7 +2540,7 @@ struct gl_renderbuffer
    gl_format Format;      /**< The actual renderbuffer memory format */
 
    /* XXX the following fields are obsolete and wil go away */
-   GLvoid *Data;        /**< This may not be used by some kinds of RBs */
+   GLvoid *Buffer;        /**< Malloc'd memory for software buffers */
 
    /** The following fields are only valid while the buffer is mapped */
    GLubyte *Map;
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 825214c..52697f2 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -113,18 +113,18 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
 
    /* free old buffer storage */
-   if (rb->Data) {
-      free(rb->Data);
-      rb->Data = NULL;
+   if (rb->Buffer) {
+      free(rb->Buffer);
+      rb->Buffer = NULL;
    }
 
    rb->RowStrideBytes = width * _mesa_get_format_bytes(rb->Format);
 
    if (width > 0 && height > 0) {
       /* allocate new buffer storage */
-      rb->Data = malloc(width * height * _mesa_get_format_bytes(rb->Format));
+      rb->Buffer = malloc(width * height * _mesa_get_format_bytes(rb->Format));
 
-      if (rb->Data == NULL) {
+      if (rb->Buffer == NULL) {
          rb->Width = 0;
          rb->Height = 0;
          _mesa_error(ctx, GL_OUT_OF_MEMORY,
@@ -162,9 +162,9 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 static void
 soft_renderbuffer_delete(struct gl_renderbuffer *rb)
 {
-   if (rb->Data) {
-      free(rb->Data);
-      rb->Data = NULL;
+   if (rb->Buffer) {
+      free(rb->Buffer);
+      rb->Buffer = NULL;
    }
    free(rb);
 }
@@ -178,11 +178,14 @@ _swrast_map_soft_renderbuffer(struct gl_context *ctx,
                               GLubyte **out_map,
                               GLint *out_stride)
 {
-   GLubyte *map = rb->Data;
+   GLubyte *map = rb->Buffer;
    int cpp = _mesa_get_format_bytes(rb->Format);
    int stride = rb->Width * cpp;
 
-   ASSERT(rb->Data);
+   if (!map) {
+      *out_map = NULL;
+      *out_stride = 0;
+   }
 
    map += y * stride;
    map += x * cpp;
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 368fa98..af4be7b 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -135,12 +135,12 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
     */
    if (att->Texture->Target == GL_TEXTURE_3D ||
        att->Texture->Target == GL_TEXTURE_2D_ARRAY_EXT) {
-      trb->Base.Data = trb->TexImage->Buffer +
+      trb->Base.Buffer = trb->TexImage->Buffer +
          trb->TexImage->ImageOffsets[trb->Zoffset] *
          _mesa_get_format_bytes(trb->TexImage->Base.TexFormat);
    }
    else {
-      trb->Base.Data = trb->TexImage->Buffer;
+      trb->Base.Buffer = trb->TexImage->Buffer;
    }
 
    /* XXX may need more special cases here */
commit f29212ecba70cc9d7f764084f2a56bde67c548bc
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:15:40 2012 -0700

    mesa: move freeing of software renderbuffers into swrast
    (cherry picked from commit f6a3979a0444a14c198c10501e9ff13f24625443)

diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 9cdc499..cb19f53 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -55,8 +55,6 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
    rb->InternalFormat = GL_RGBA;
    rb->Format = MESA_FORMAT_NONE;
 
-   rb->Data = NULL;
-
    /* Point back to ourself so that we don't have to check for Wrapped==NULL
     * all over the drivers.
     */
@@ -86,10 +84,7 @@ _mesa_new_renderbuffer(struct gl_context *ctx, GLuint name)
 void
 _mesa_delete_renderbuffer(struct gl_renderbuffer *rb)
 {
-   if (rb->Data) {
-      free(rb->Data);
-   }
-   free(rb);
+   /* no-op */
 }
 
 
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index a78c6a1..825214c 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -156,6 +156,20 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
 }
 
 
+/**
+ * Called via gl_renderbuffer::Delete()
+ */
+static void
+soft_renderbuffer_delete(struct gl_renderbuffer *rb)
+{
+   if (rb->Data) {
+      free(rb->Data);
+      rb->Data = NULL;
+   }
+   free(rb);
+}
+
+
 void
 _swrast_map_soft_renderbuffer(struct gl_context *ctx,
                               struct gl_renderbuffer *rb,
@@ -198,6 +212,7 @@ _swrast_new_soft_renderbuffer(struct gl_context *ctx, GLuint name)
    struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, name);
    if (rb) {
       rb->AllocStorage = soft_renderbuffer_storage;
+      rb->Delete = soft_renderbuffer_delete;
    }
    return rb;
 }
commit 8e5e73542459dabd241c35d0aa3ea7c0e30bf2ed
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 12:03:09 2012 -0700

    mesa: remove gl_renderbuffer::DataType
    (cherry picked from commit f9874feef4d8952df5054bd8e8f4e0deda4ef44f)

diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.c b/src/mesa/drivers/dri/i965/gen6_hiz.c
index 4d36729..d7698ed 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.c
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.c
@@ -230,7 +230,6 @@ gen6_hiz_setup_depth_buffer(struct brw_context *brw,
 
    rb->Format = mt->format;
    rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
-   rb->DataType = intel_mesa_format_to_rb_datatype(rb->Format);
    rb->InternalFormat = rb->_BaseFormat;
    rb->Width = mt->level[level].width;
    rb->Height = mt->level[level].height;
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index bd4fc7f..e13d62c 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -237,7 +237,6 @@ intel_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffer
    rb->Width = width;
    rb->Height = height;
    rb->_BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
-   rb->DataType = intel_mesa_format_to_rb_datatype(rb->Format);
 
    intel_miptree_release(&irb->mt);
 
@@ -303,7 +302,6 @@ intel_image_target_renderbuffer_storage(struct gl_context *ctx,
    rb->Width = image->region->width;
    rb->Height = image->region->height;
    rb->Format = image->format;
-   rb->DataType = image->data_type;
    rb->_BaseFormat = _mesa_base_fbo_format(&intel->ctx,
 					   image->internal_format);
 }
@@ -385,7 +383,6 @@ intel_create_renderbuffer(gl_format format)
    irb->Base._BaseFormat = _mesa_get_format_base_format(format);
    irb->Base.Format = format;
    irb->Base.InternalFormat = irb->Base._BaseFormat;
-   irb->Base.DataType = intel_mesa_format_to_rb_datatype(format);
 
    /* intel-specific methods */
    irb->Base.Delete = intel_delete_renderbuffer;
@@ -486,7 +483,6 @@ intel_renderbuffer_update_wrapper(struct intel_context *intel,
 
    rb->Format = format;
    rb->InternalFormat = internal_format;
-   rb->DataType = intel_mesa_format_to_rb_datatype(rb->Format);
    rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
    rb->Width = mt->level[level].width;
    rb->Height = mt->level[level].height;
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 0566907..cf046a2 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -208,7 +208,7 @@ intel_create_image_from_renderbuffer(__DRIcontext *context,
 
    image->internal_format = rb->InternalFormat;
    image->format = rb->Format;
-   image->data_type = rb->DataType;
+   image->data_type = GL_UNSIGNED_BYTE;
    image->data = loaderPrivate;
    intel_region_reference(&image->region, irb->mt->region);
 
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_fbo.c b/src/mesa/drivers/dri/nouveau/nouveau_fbo.c
index d56e954..6f4956e 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_fbo.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_fbo.c
@@ -46,26 +46,22 @@ set_renderbuffer_format(struct gl_renderbuffer *rb, GLenum internalFormat)
 	case GL_RGB8:
 		rb->_BaseFormat  = GL_RGB;
 		rb->Format = MESA_FORMAT_XRGB8888;
-		rb->DataType = GL_UNSIGNED_BYTE;
 		s->cpp = 4;
 		break;
 	case GL_RGBA:
 	case GL_RGBA8:
 		rb->_BaseFormat  = GL_RGBA;
 		rb->Format = MESA_FORMAT_ARGB8888;
-		rb->DataType = GL_UNSIGNED_BYTE;
 		s->cpp = 4;
 		break;
 	case GL_RGB5:
 		rb->_BaseFormat  = GL_RGB;
 		rb->Format = MESA_FORMAT_RGB565;
-		rb->DataType = GL_UNSIGNED_BYTE;
 		s->cpp = 2;
 		break;
 	case GL_DEPTH_COMPONENT16:
 		rb->_BaseFormat  = GL_DEPTH_COMPONENT;
 		rb->Format = MESA_FORMAT_Z16;
-		rb->DataType = GL_UNSIGNED_SHORT;
 		s->cpp = 2;
 		break;
 	case GL_DEPTH_COMPONENT:
@@ -74,7 +70,6 @@ set_renderbuffer_format(struct gl_renderbuffer *rb, GLenum internalFormat)
 	case GL_DEPTH24_STENCIL8_EXT:
 		rb->_BaseFormat  = GL_DEPTH_STENCIL;
 		rb->Format = MESA_FORMAT_Z24_S8;
-		rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
 		s->cpp = 4;
 		break;
 	default:
diff --git a/src/mesa/drivers/dri/radeon/radeon_fbo.c b/src/mesa/drivers/dri/radeon/radeon_fbo.c
index a0d7956..026587c 100644
--- a/src/mesa/drivers/dri/radeon/radeon_fbo.c
+++ b/src/mesa/drivers/dri/radeon/radeon_fbo.c
@@ -481,7 +481,6 @@ radeon_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffe
    case GL_RGB4:
    case GL_RGB5:
       rb->Format = _radeon_texformat_rgb565;
-      rb->DataType = GL_UNSIGNED_BYTE;
       cpp = 2;
       break;
    case GL_RGB:
@@ -490,7 +489,6 @@ radeon_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffe
    case GL_RGB12:
    case GL_RGB16:
       rb->Format = _radeon_texformat_argb8888;
-      rb->DataType = GL_UNSIGNED_BYTE;
       cpp = 4;
       break;
    case GL_RGBA:
@@ -502,7 +500,6 @@ radeon_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffe
    case GL_RGBA12:
    case GL_RGBA16:
       rb->Format = _radeon_texformat_argb8888;
-      rb->DataType = GL_UNSIGNED_BYTE;
       cpp = 4;
       break;
    case GL_STENCIL_INDEX:
@@ -512,25 +509,21 @@ radeon_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffe
    case GL_STENCIL_INDEX16_EXT:
       /* alloc a depth+stencil buffer */
       rb->Format = MESA_FORMAT_S8_Z24;
-      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
       cpp = 4;
       break;
    case GL_DEPTH_COMPONENT16:
       rb->Format = MESA_FORMAT_Z16;
-      rb->DataType = GL_UNSIGNED_SHORT;
       cpp = 2;
       break;
    case GL_DEPTH_COMPONENT:
    case GL_DEPTH_COMPONENT24:
    case GL_DEPTH_COMPONENT32:
       rb->Format = MESA_FORMAT_X8_Z24;
-      rb->DataType = GL_UNSIGNED_INT;
       cpp = 4;
       break;
    case GL_DEPTH_STENCIL_EXT:
    case GL_DEPTH24_STENCIL8_EXT:
       rb->Format = MESA_FORMAT_S8_Z24;
-      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
       cpp = 4;
       break;
    default:
@@ -604,7 +597,6 @@ radeon_image_target_renderbuffer_storage(struct gl_context *ctx,
    rb->Width = image->width;
    rb->Height = image->height;
    rb->Format = image->format;
-   rb->DataType = image->data_type;
    rb->_BaseFormat = _mesa_base_fbo_format(radeon->glCtx,
                                            image->internal_format);
 }
@@ -696,49 +688,6 @@ radeon_create_renderbuffer(gl_format format, __DRIdrawable *driDrawPriv)
 
     rrb->base.Format = format;
 
-    switch (format) {
-        case MESA_FORMAT_RGB565:
-	    assert(_mesa_little_endian());
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-        case MESA_FORMAT_RGB565_REV:
-	    assert(!_mesa_little_endian());
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-        case MESA_FORMAT_XRGB8888:
-	    assert(_mesa_little_endian());
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-        case MESA_FORMAT_XRGB8888_REV:
-	    assert(!_mesa_little_endian());
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-	case MESA_FORMAT_ARGB8888:
-	    assert(_mesa_little_endian());
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-	case MESA_FORMAT_ARGB8888_REV:
-	    assert(!_mesa_little_endian());
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-	case MESA_FORMAT_S8:
-	    rrb->base.DataType = GL_UNSIGNED_BYTE;
-	    break;
-	case MESA_FORMAT_Z16:
-	    rrb->base.DataType = GL_UNSIGNED_SHORT;
-	    break;
-	case MESA_FORMAT_X8_Z24:
-	    rrb->base.DataType = GL_UNSIGNED_INT;
-	    break;
-	case MESA_FORMAT_S8_Z24:
-	    rrb->base.DataType = GL_UNSIGNED_INT_24_8_EXT;
-	    break;
-	default:
-	    fprintf(stderr, "%s: Unknown format %s\n",
-                    __FUNCTION__, _mesa_get_format_name(format));
-	    _mesa_delete_renderbuffer(&rrb->base);
-	    return NULL;
-    }
     rrb->base._BaseFormat = _mesa_get_format_base_format(format);
 
     rrb->dPriv = driDrawPriv;
@@ -816,35 +765,6 @@ radeon_update_wrapper(struct gl_context *ctx, struct radeon_renderbuffer *rrb,
 		"%s(%p, rrb %p, texImage %p, texFormat %s) \n",
 		__func__, ctx, rrb, texImage, _mesa_get_format_name(texImage->TexFormat));
 
-	switch (texImage->TexFormat) {
-		case MESA_FORMAT_RGBA8888:
-		case MESA_FORMAT_RGBA8888_REV:
-		case MESA_FORMAT_ARGB8888:
-		case MESA_FORMAT_ARGB8888_REV:
-		case MESA_FORMAT_XRGB8888:
-		case MESA_FORMAT_XRGB8888_REV:
-		case MESA_FORMAT_RGB565:
-		case MESA_FORMAT_RGB565_REV:
-		case MESA_FORMAT_RGBA5551:
-		case MESA_FORMAT_ARGB1555:
-		case MESA_FORMAT_ARGB1555_REV:
-		case MESA_FORMAT_ARGB4444:
-		case MESA_FORMAT_ARGB4444_REV:
-			rrb->base.DataType = GL_UNSIGNED_BYTE;
-			break;
-		case MESA_FORMAT_Z16:
-			rrb->base.DataType = GL_UNSIGNED_SHORT;
-			break;
-		case MESA_FORMAT_X8_Z24:
-			rrb->base.DataType = GL_UNSIGNED_INT;
-			break;
-		case MESA_FORMAT_S8_Z24:
-			rrb->base.DataType = GL_UNSIGNED_INT_24_8_EXT;
-			break;
-		default:
-			_mesa_problem(ctx, "Unexpected texture format in radeon_update_wrapper()");
-	}
-		
 	rrb->cpp = _mesa_get_format_bytes(texImage->TexFormat);
 	rrb->pitch = texImage->Width * rrb->cpp;
 	rrb->base.Format = texImage->TexFormat;
diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c
index 2e364d0..51a1ef5 100644
--- a/src/mesa/drivers/dri/radeon/radeon_screen.c
+++ b/src/mesa/drivers/dri/radeon/radeon_screen.c
@@ -282,7 +282,7 @@ radeon_create_image_from_renderbuffer(__DRIcontext *context,
    image->internal_format = rb->InternalFormat;
    image->format = rb->Format;
    image->cpp = rrb->cpp;
-   image->data_type = rb->DataType;
+   image->data_type = GL_UNSIGNED_BYTE;
    image->data = loaderPrivate;
    radeon_bo_ref(rrb->bo);
    image->bo = rrb->bo;
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index efc5527..19da702 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -344,28 +344,24 @@ swrast_new_renderbuffer(const struct gl_config *visual, __DRIdrawable *dPriv,
 	xrb->Base.Format = MESA_FORMAT_ARGB8888;
 	xrb->Base.InternalFormat = GL_RGBA;
 	xrb->Base._BaseFormat = GL_RGBA;
-	xrb->Base.DataType = GL_UNSIGNED_BYTE;
 	xrb->bpp = 32;
 	break;
     case PF_X8R8G8B8:
 	xrb->Base.Format = MESA_FORMAT_ARGB8888; /* XXX */
 	xrb->Base.InternalFormat = GL_RGB;
 	xrb->Base._BaseFormat = GL_RGB;
-	xrb->Base.DataType = GL_UNSIGNED_BYTE;
 	xrb->bpp = 32;
 	break;
     case PF_R5G6B5:
 	xrb->Base.Format = MESA_FORMAT_RGB565;
 	xrb->Base.InternalFormat = GL_RGB;
 	xrb->Base._BaseFormat = GL_RGB;
-	xrb->Base.DataType = GL_UNSIGNED_BYTE;
 	xrb->bpp = 16;
 	break;
     case PF_R3G3B2:
 	xrb->Base.Format = MESA_FORMAT_RGB332;
 	xrb->Base.InternalFormat = GL_RGB;
 	xrb->Base._BaseFormat = GL_RGB;
-	xrb->Base.DataType = GL_UNSIGNED_BYTE;
 	xrb->bpp = 8;
 	break;
     default:
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 543bcbf..5c1a3f3 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -75,6 +75,7 @@ struct osmesa_context
    GLvoid *rowaddr[MAX_HEIGHT];	/*< address of first pixel in each image row */
    GLboolean yup;		/*< TRUE  -> Y increases upward */
 				/*< FALSE -> Y increases downward */
+   GLboolean DataType;
 };
 
 
@@ -192,9 +193,6 @@ osmesa_choose_line_function( struct gl_context *ctx )
    const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
    const SWcontext *swrast = SWRAST_CONTEXT(ctx);
 
-   if (osmesa->rb->DataType != GL_UNSIGNED_BYTE)
-      return NULL;
-
    if (ctx->RenderMode != GL_RENDER)      return NULL;
    if (ctx->Line.SmoothFlag)              return NULL;
    if (ctx->Texture._EnabledUnits)        return NULL;
@@ -296,9 +294,6 @@ osmesa_choose_triangle_function( struct gl_context *ctx )
    const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
    const SWcontext *swrast = SWRAST_CONTEXT(ctx);
 
-   if (osmesa->rb->DataType != GL_UNSIGNED_BYTE)
-      return (swrast_tri_func) NULL;
-
    if (ctx->RenderMode != GL_RENDER)    return (swrast_tri_func) NULL;
    if (ctx->Polygon.SmoothFlag)         return (swrast_tri_func) NULL;
    if (ctx->Polygon.StippleFlag)        return (swrast_tri_func) NULL;
@@ -419,13 +414,13 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
     * XXX The 8-bit/channel formats should all be OK.
     */
    if (osmesa->format == OSMESA_RGBA) {
-      if (rb->DataType == GL_UNSIGNED_BYTE) {
+      if (osmesa->DataType == GL_UNSIGNED_BYTE) {
          if (_mesa_little_endian())
             rb->Format = MESA_FORMAT_RGBA8888_REV;
          else
             rb->Format = MESA_FORMAT_RGBA8888;
       }
-      else if (rb->DataType == GL_UNSIGNED_SHORT) {
+      else if (osmesa->DataType == GL_UNSIGNED_SHORT) {
          rb->Format = MESA_FORMAT_RGBA_16;
       }
       else {
@@ -433,13 +428,13 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else if (osmesa->format == OSMESA_BGRA) {
-      if (rb->DataType == GL_UNSIGNED_BYTE) {
+      if (osmesa->DataType == GL_UNSIGNED_BYTE) {
          if (_mesa_little_endian())
             rb->Format = MESA_FORMAT_ARGB8888;
          else
             rb->Format = MESA_FORMAT_ARGB8888_REV;
       }
-      else if (rb->DataType == GL_UNSIGNED_SHORT) {
+      else if (osmesa->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format BGRA/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
       }
@@ -449,13 +444,13 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else if (osmesa->format == OSMESA_ARGB) {
-      if (rb->DataType == GL_UNSIGNED_BYTE) {
+      if (osmesa->DataType == GL_UNSIGNED_BYTE) {
          if (_mesa_little_endian())
             rb->Format = MESA_FORMAT_ARGB8888_REV;
          else
             rb->Format = MESA_FORMAT_ARGB8888;
       }
-      else if (rb->DataType == GL_UNSIGNED_SHORT) {
+      else if (osmesa->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format ARGB/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
       }
@@ -465,10 +460,10 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else if (osmesa->format == OSMESA_RGB) {
-      if (rb->DataType == GL_UNSIGNED_BYTE) {
+      if (osmesa->DataType == GL_UNSIGNED_BYTE) {
          rb->Format = MESA_FORMAT_RGB888;
       }
-      else if (rb->DataType == GL_UNSIGNED_SHORT) {
+      else if (osmesa->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format RGB/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
       }
@@ -478,10 +473,10 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else if (osmesa->format == OSMESA_BGR) {
-      if (rb->DataType == GL_UNSIGNED_BYTE) {
+      if (osmesa->DataType == GL_UNSIGNED_BYTE) {
          rb->Format = MESA_FORMAT_BGR888;
       }
-      else if (rb->DataType == GL_UNSIGNED_SHORT) {
+      else if (osmesa->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format BGR/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
       }
@@ -491,7 +486,7 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else if (osmesa->format == OSMESA_RGB_565) {
-      ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+      ASSERT(osmesa->DataType == GL_UNSIGNED_BYTE);
       rb->Format = MESA_FORMAT_RGB565;
    }
    else {
@@ -523,7 +518,6 @@ new_osmesa_renderbuffer(struct gl_context *ctx, GLenum format, GLenum type)
 
       rb->InternalFormat = GL_RGBA;
       rb->_BaseFormat = GL_RGBA;
-      rb->DataType = type;
    }
    return rb;
 }
@@ -892,6 +886,8 @@ OSMesaMakeCurrent( OSMesaContext osmesa, void *buffer, GLenum type,
       assert(osmesa->rb->RefCount == 2);
    }
 
+   osmesa->DataType = type;
+
    /* Set renderbuffer fields.  Set width/height = 0 to force 
     * osmesa_renderbuffer_storage() being called by _mesa_resize_framebuffer()
     */
@@ -986,7 +982,7 @@ OSMesaGetIntegerv( GLint pname, GLint *value )
       case OSMESA_TYPE:
          /* current color buffer's data type */
          if (osmesa->rb) {
-            *value = osmesa->rb->DataType;
+            *value = osmesa->DataType;
          }
          else {
             *value = 0;
diff --git a/src/mesa/drivers/windows/gdi/wmesa.c b/src/mesa/drivers/windows/gdi/wmesa.c
index 255d811..40aa56e 100644
--- a/src/mesa/drivers/windows/gdi/wmesa.c
+++ b/src/mesa/drivers/windows/gdi/wmesa.c
@@ -1233,7 +1233,6 @@ wmesa_new_renderbuffer(void)
     
     rb->_BaseFormat = GL_RGBA;
     rb->InternalFormat = GL_RGBA;
-    rb->DataType = CHAN_TYPE;
     rb->Delete = wmesa_delete_renderbuffer;
     rb->AllocStorage = wmesa_renderbuffer_storage;
     return rb;
diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c
index 84e6fcd..0f1d960 100644
--- a/src/mesa/drivers/x11/xm_buffer.c
+++ b/src/mesa/drivers/x11/xm_buffer.c
@@ -336,7 +336,6 @@ xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name,
 
       xrb->Base.InternalFormat = GL_RGBA;
       xrb->Base._BaseFormat = GL_RGBA;
-      xrb->Base.DataType = GL_UNSIGNED_BYTE;
       xrb->Base.ClassID = XMESA_RENDERBUFFER;
 
       switch (xmvis->undithered_pf) {
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 37df03e..3e8d171 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2541,7 +2541,6 @@ struct gl_renderbuffer
 
    /* XXX the following fields are obsolete and wil go away */
    GLvoid *Data;        /**< This may not be used by some kinds of RBs */
-   GLenum DataType;      /**< Type of values passed to the Get/Put functions */
 
    /** The following fields are only valid while the buffer is mapped */
    GLubyte *Map;
diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 39c25b0..9cdc499 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -55,7 +55,6 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
    rb->InternalFormat = GL_RGBA;
    rb->Format = MESA_FORMAT_NONE;
 
-   rb->DataType = GL_NONE;
    rb->Data = NULL;
 
    /* Point back to ourself so that we don't have to check for Wrapped==NULL
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 2ef3e03..a78c6a1 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -40,98 +40,6 @@
 #include "swrast/s_renderbuffer.h"
 
 
-
-/**
- * This is the default software fallback for gl_renderbuffer's span
- * access functions.
- *
- * The assumptions are that rb->Data will be a pointer to (0,0), that pixels
- * are packed in the type of rb->Format, and that subsequent rows appear
- * rb->RowStride pixels later.
- */
-void
-_swrast_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
-{
-   switch (rb->Format) {
-   case MESA_FORMAT_RGB888:
-      rb->DataType = GL_UNSIGNED_BYTE;
-      break;
-
-   case MESA_FORMAT_RGBA8888:
-   case MESA_FORMAT_RGBA8888_REV:
-      rb->DataType = GL_UNSIGNED_BYTE;
-      break;
-
-   case MESA_FORMAT_R8:
-      rb->DataType = GL_UNSIGNED_BYTE;
-
-      break;
-
-   case MESA_FORMAT_GR88:
-      rb->DataType = GL_UNSIGNED_BYTE;
-      break;
-
-   case MESA_FORMAT_R16:
-      rb->DataType = GL_UNSIGNED_SHORT;
-
-      break;
-
-   case MESA_FORMAT_RG1616:
-      rb->DataType = GL_UNSIGNED_SHORT;
-      break;
-
-   case MESA_FORMAT_SIGNED_RGBA_16:
-      rb->DataType = GL_SHORT;
-      break;
-
-   case MESA_FORMAT_S8:
-      rb->DataType = GL_UNSIGNED_BYTE;
-      break;
-
-   case MESA_FORMAT_Z16:
-      rb->DataType = GL_UNSIGNED_SHORT;
-      break;
-
-   case MESA_FORMAT_Z32:
-   case MESA_FORMAT_X8_Z24:
-   case MESA_FORMAT_Z24_X8:
-      rb->DataType = GL_UNSIGNED_INT;
-      break;
-
-   case MESA_FORMAT_Z24_S8:
-   case MESA_FORMAT_S8_Z24:
-      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
-      break;
-
-   case MESA_FORMAT_RGBA_FLOAT32:
-      rb->DataType = GL_FLOAT;
-      break;
-
-   case MESA_FORMAT_INTENSITY_FLOAT32:
-      rb->DataType = GL_FLOAT;
-      break;
-
-   case MESA_FORMAT_LUMINANCE_FLOAT32:
-      rb->DataType = GL_FLOAT;
-      break;
-
-   case MESA_FORMAT_ALPHA_FLOAT32:
-      rb->DataType = GL_FLOAT;
-      break;
-
-   case MESA_FORMAT_RG_FLOAT32:
-      rb->DataType = GL_FLOAT;
-      break;
-
-   case MESA_FORMAT_R_FLOAT32:
-      rb->DataType = GL_FLOAT;
-      break;
-
-   default:
-      break;
-   }
-}
-
 /**
  * This is a software fallback for the gl_renderbuffer->AllocStorage
  * function.
@@ -204,10 +112,6 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       return GL_FALSE;
    }
 
-   _swrast_set_renderbuffer_accessors(rb);
-
-   ASSERT(rb->DataType);
-
    /* free old buffer storage */
    if (rb->Data) {
       free(rb->Data);
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 2b67d55..49529a8 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1029,6 +1029,7 @@ shade_texture_span(struct gl_context *ctx, SWspan *span)
 /** Put colors at x/y locations into a renderbuffer */
 static void
 put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+           GLenum datatype,
            GLuint count, const GLint x[], const GLint y[],
            const void *values, const GLubyte *mask)
 {
@@ -1038,12 +1039,12 @@ put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
       if (mask[i]) {
          GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
 
-         if (rb->DataType == GL_UNSIGNED_BYTE) {
+         if (datatype == GL_UNSIGNED_BYTE) {
             _mesa_pack_ubyte_rgba_row(rb->Format, 1,
                                       (const GLubyte (*)[4]) values + i, dst);
          }
          else {
-            assert(rb->DataType == GL_FLOAT);
+            assert(datatype == GL_FLOAT);
             _mesa_pack_float_rgba_row(rb->Format, count,
                                       (const GLfloat (*)[4]) values + i, dst);
          }
@@ -1055,18 +1056,19 @@ put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
 /** Put row of colors into renderbuffer */
 void
 _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
+                GLenum datatype,
                 GLuint count, GLint x, GLint y,
                 const void *values, const GLubyte *mask)
 {
    GLubyte *dst = _swrast_pixel_address(rb, x, y);
 
    if (!mask) {
-      if (rb->DataType == GL_UNSIGNED_BYTE) {
+      if (datatype == GL_UNSIGNED_BYTE) {
          _mesa_pack_ubyte_rgba_row(rb->Format, count,
                                    (const GLubyte (*)[4]) values, dst);
       }
       else {
-         assert(rb->DataType == GL_FLOAT);
+         assert(datatype == GL_FLOAT);
          _mesa_pack_float_rgba_row(rb->Format, count,
                                    (const GLfloat (*)[4]) values, dst);
       }
@@ -1088,13 +1090,13 @@ _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
          if (!mask[i] || i == count - 1) {
             /* might be the end of a run of pixels */
             if (runLen > 0) {
-               if (rb->DataType == GL_UNSIGNED_BYTE) {
+               if (datatype == GL_UNSIGNED_BYTE) {
                   _mesa_pack_ubyte_rgba_row(rb->Format, runLen,
                                      (const GLubyte (*)[4]) values + runStart,
                                      dst + runStart * bpp);
                }
                else {
-                  assert(rb->DataType == GL_FLOAT);
+                  assert(datatype == GL_FLOAT);
                   _mesa_pack_float_rgba_row(rb->Format, runLen,
                                    (const GLfloat (*)[4]) values + runStart,
                                    dst + runStart * bpp);
@@ -1310,23 +1312,13 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
 
          if (rb) {
             GLchan rgbaSave[MAX_WIDTH][4];
-            const GLuint fragOutput = multiFragOutputs ? buf : 0;
 
-            /* set span->array->rgba to colors for render buffer's datatype */
-            if (rb->DataType != span->array->ChanType || fragOutput > 0) {
-               convert_color_type(span, rb->DataType, fragOutput);
+            if (span->array->ChanType == GL_UNSIGNED_BYTE) {
+               span->array->rgba = span->array->rgba8;
             }
             else {
-               if (rb->DataType == GL_UNSIGNED_BYTE) {
-                  span->array->rgba = span->array->rgba8;
-               }
-               else if (rb->DataType == GL_UNSIGNED_SHORT) {
-                  span->array->rgba = (void *) span->array->rgba16;
-               }
-               else {
-                  span->array->rgba = (void *)
-                     span->array->attribs[FRAG_ATTRIB_COL0];
-               }
+               span->array->rgba = (void *)
+                  span->array->attribs[FRAG_ATTRIB_COL0];
             }
 
             if (!multiFragOutputs && numBuffers > 1) {
@@ -1354,13 +1346,16 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
 
             if (span->arrayMask & SPAN_XY) {
                /* array of pixel coords */
-               put_values(ctx, rb, span->end,
+               put_values(ctx, rb,
+                          span->array->ChanType, span->end,
                           span->array->x, span->array->y,
                           span->array->rgba, span->array->mask);
             }
             else {
                /* horizontal run of pixels */
-               _swrast_put_row(ctx, rb, span->end, span->x, span->y,
+               _swrast_put_row(ctx, rb,
+                               span->array->ChanType,
+                               span->end, span->x, span->y,
                                span->array->rgba,
                                span->writeAll ? NULL: span->array->mask);
             }
diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index 4d6eb7e..ff0fe6c 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -205,6 +205,7 @@ _swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
 extern void
 _swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
+                GLenum datatype,
                 GLuint count, GLint x, GLint y,
                 const void *values, const GLubyte *mask);
 
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 4a94431..368fa98 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -146,47 +146,37 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
    /* XXX may need more special cases here */
    switch (trb->TexImage->Base.TexFormat) {
    case MESA_FORMAT_Z24_S8:
-      trb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
       trb->Base._BaseFormat = GL_DEPTH_STENCIL;
       break;
    case MESA_FORMAT_S8_Z24:
-      trb->Base.DataType = GL_UNSIGNED_INT_8_24_REV_MESA;
       trb->Base._BaseFormat = GL_DEPTH_STENCIL;
       break;
    case MESA_FORMAT_Z24_X8:
-      trb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
       trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
       break;
    case MESA_FORMAT_X8_Z24:
-      trb->Base.DataType = GL_UNSIGNED_INT_8_24_REV_MESA;
       trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
       break;
    case MESA_FORMAT_Z16:
-      trb->Base.DataType = GL_UNSIGNED_SHORT;
       trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
       break;
    case MESA_FORMAT_Z32:
-      trb->Base.DataType = GL_UNSIGNED_INT;
       trb->Base._BaseFormat = GL_DEPTH_COMPONENT;
       break;
    /* SRGB formats pre EXT_framebuffer_sRGB don't do sRGB translations on FBO readback */
    case MESA_FORMAT_SRGB8:
       trb->Fetch = _mesa_get_texel_fetch_func(MESA_FORMAT_RGB888, _mesa_get_texture_dimensions(att->Texture->Target));
-      trb->Base.DataType = CHAN_TYPE;
       trb->Base._BaseFormat = GL_RGBA;
       break;
    case MESA_FORMAT_SRGBA8:
       trb->Fetch = _mesa_get_texel_fetch_func(MESA_FORMAT_RGBA8888, _mesa_get_texture_dimensions(att->Texture->Target));
-      trb->Base.DataType = CHAN_TYPE;
       trb->Base._BaseFormat = GL_RGBA;
       break;
    case MESA_FORMAT_SARGB8:
       trb->Fetch = _mesa_get_texel_fetch_func(MESA_FORMAT_ARGB8888, _mesa_get_texture_dimensions(att->Texture->Target));
-      trb->Base.DataType = CHAN_TYPE;
       trb->Base._BaseFormat = GL_RGBA;
       break;
    default:
-      trb->Base.DataType = CHAN_TYPE;
       trb->Base._BaseFormat = GL_RGBA;
    }
 }
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 2b54cd1..124aa5f 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -157,7 +157,8 @@ _swrast_culltriangle( struct gl_context *ctx,
       span.intTex[0] += span.intTexStep[0];				\
       span.intTex[1] += span.intTexStep[1];				\
    }									\
-   _swrast_put_row(ctx, rb, span.end, span.x, span.y, rgba, NULL);
+   _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE, span.end,                 \
+                   span.x, span.y, rgba, NULL);
 
 #include "s_tritemp.h"
 
@@ -223,7 +224,8 @@ _swrast_culltriangle( struct gl_context *ctx,
       span.intTex[1] += span.intTexStep[1];				\
       span.z += span.zStep;						\
    }									\
-   _swrast_put_row(ctx, rb, span.end, span.x, span.y, rgba, span.array->mask);
+   _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE,                           \
+                   span.end, span.x, span.y, rgba, span.array->mask);
 
 #include "s_tritemp.h"
 
commit f5367c45031cac167f3ef8ee273880318156e787
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:48:18 2012 -0700

    mesa: remove gl_renderbuffer:RowStride field
    (cherry picked from commit 1e1b5cb01a10e39d01923e3c7e989c44210950cd)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index d3c2924..bd4fc7f 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -135,7 +135,7 @@ intel_map_renderbuffer(struct gl_context *ctx,
    if (!irb && rb->Data) {
       /* this is a malloc'd renderbuffer (accum buffer) */
       GLint bpp = _mesa_get_format_bytes(rb->Format);
-      GLint rowStride = rb->RowStride * bpp;
+      GLint rowStride = rb->RowStrideBytes;
       *out_map = (GLubyte *) rb->Data + y * rowStride + x * bpp;
       *out_stride = rowStride;
       return;
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index d6b4d0f..34bcd28 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -133,7 +133,6 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
 			       GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
 			       &map, &stride);
    rb->Map = map;
-   rb->RowStride = stride / _mesa_get_format_bytes(rb->Format);
    rb->RowStrideBytes = stride;
 }
 
@@ -158,7 +157,6 @@ intel_renderbuffer_unmap(struct intel_context *intel,
    ctx->Driver.UnmapRenderbuffer(ctx, rb);
 
    rb->Map = NULL;
-   rb->RowStride = 0;
    rb->RowStrideBytes = 0;
 }
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c
index be5a913..6588ae8 100644
--- a/src/mesa/drivers/dri/radeon/radeon_span.c
+++ b/src/mesa/drivers/dri/radeon/radeon_span.c
@@ -65,7 +65,6 @@ radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb)
 				    &map, &stride);
 
 	rb->Map = map;
-	rb->RowStride = stride / _mesa_get_format_bytes(rb->Format);
 	rb->RowStrideBytes = stride;
 }
 
@@ -79,7 +78,6 @@ radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb)
 	ctx->Driver.UnmapRenderbuffer(ctx, rb);
 
 	rb->Map = NULL;
-	rb->RowStride = 0;
 	rb->RowStrideBytes = 0;
 }
 
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index e7f121e..efc5527 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -292,7 +292,6 @@ swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
     rb->Data = NULL;
     rb->Width = width;
     rb->Height = height;
-    rb->RowStride = width;
     xrb->pitch = bytes_per_line(width * xrb->bpp, 32);
 
     return GL_TRUE;
@@ -387,7 +386,7 @@ swrast_map_renderbuffer(struct gl_context *ctx,
    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
    GLubyte *map = rb->Data;
    int cpp = _mesa_get_format_bytes(rb->Format);
-   int stride = rb->RowStride * cpp;
+   int stride = rb->Width * cpp;
 
    if (rb->AllocStorage == swrast_alloc_front_storage) {
       __DRIdrawable *dPriv = xrb->dPriv;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 70667dc..37df03e 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2539,10 +2539,9 @@ struct gl_renderbuffer
                                GL_STENCIL_INDEX. */
    gl_format Format;      /**< The actual renderbuffer memory format */
 
-   /* XXX the following 3 fields are obsolete and wil go away */
-   GLint RowStride;       /**< Padded width in units of pixels */
-   GLenum DataType;      /**< Type of values passed to the Get/Put functions */
+   /* XXX the following fields are obsolete and wil go away */
    GLvoid *Data;        /**< This may not be used by some kinds of RBs */
+   GLenum DataType;      /**< Type of values passed to the Get/Put functions */
 
    /** The following fields are only valid while the buffer is mapped */
    GLubyte *Map;
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 5828a78..5050ad9 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -522,7 +522,7 @@ fast_draw_depth_stencil(struct gl_context *ctx, GLint x, GLint y,
    srcRowStride = _mesa_image_row_stride(unpack, width, format, type);
 
    dst = _swrast_pixel_address(rb, x, y);
-   dstRowStride = rb->RowStride * 4;
+   dstRowStride = rb->RowStrideBytes;
 
    for (i = 0; i < height; i++) {
       _mesa_pack_uint_24_8_depth_stencil_row(rb->Format, width,
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 267ec3b..2ef3e03 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -214,7 +214,7 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       rb->Data = NULL;
    }
 
-   rb->RowStride = width;
+   rb->RowStrideBytes = width * _mesa_get_format_bytes(rb->Format);
 
    if (width > 0 && height > 0) {
       /* allocate new buffer storage */
@@ -223,7 +223,6 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
       if (rb->Data == NULL) {
          rb->Width = 0;
          rb->Height = 0;
-	 rb->RowStride = 0;
          _mesa_error(ctx, GL_OUT_OF_MEMORY,
                      "software renderbuffer allocation (%d x %d x %d)",
                      width, height, _mesa_get_format_bytes(rb->Format));
@@ -263,7 +262,7 @@ _swrast_map_soft_renderbuffer(struct gl_context *ctx,
 {
    GLubyte *map = rb->Data;
    int cpp = _mesa_get_format_bytes(rb->Format);
-   int stride = rb->RowStride * cpp;
+   int stride = rb->Width * cpp;
 
    ASSERT(rb->Data);
 
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 1adf281..4a94431 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -127,7 +127,6 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
 
    trb->Base.Width = trb->TexImage->Base.Width;
    trb->Base.Height = trb->TexImage->Base.Height;
-   trb->Base.RowStride = trb->TexImage->RowStride;
    trb->Base.InternalFormat = trb->TexImage->Base.InternalFormat;
    trb->Base.Format = trb->TexImage->Base.TexFormat;
 
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index fe44663..7c45126 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -374,7 +374,6 @@ unmap_attachment(struct gl_context *ctx,
    }
 
    rb->Map = NULL;
-   rb->RowStrideBytes = 0;
 }
  
  
commit d60bcbe31da5869f018ca73f43f93cc391e79f9a
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:32:12 2012 -0700

    mesa: finally, remove the GetRow/PutRow/etc functions
    (cherry picked from commit 82846fea4d042466ccfd5b3c86d98e856086cc05)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 99b6a6f..70667dc 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2558,43 +2558,6 @@ struct gl_renderbuffer
    GLboolean (*AllocStorage)(struct gl_context *ctx, struct gl_renderbuffer *rb,
                              GLenum internalFormat,
                              GLuint width, GLuint height);
-
-   /* Lock/Unlock are called before/after calling the Get/Put functions.
-    * Not sure this is the right place for these yet.
-   void (*Lock)(struct gl_context *ctx, struct gl_renderbuffer *rb);
-   void (*Unlock)(struct gl_context *ctx, struct gl_renderbuffer *rb);
-    */
-
-   /* Return a pointer to the element/pixel at (x,y).
-    * Should return NULL if the buffer memory can't be directly addressed.
-    */
-   void *(*GetPointer)(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                       GLint x, GLint y);
-
-   /* Get/Read a row of values.
-    * The values will be of format _BaseFormat and type DataType.
-    */
-   void (*GetRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  GLint x, GLint y, void *values);
-
-   /* Get/Read values at arbitrary locations.
-    * The values will be of format _BaseFormat and type DataType.
-    */
-   void (*GetValues)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                     const GLint x[], const GLint y[], void *values);
-
-   /* Put/Write a row of values.
-    * The values will be of format _BaseFormat and type DataType.
-    */
-   void (*PutRow)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  GLint x, GLint y, const void *values, const GLubyte *mask);
-
-   /* Put/Write values at arbitrary locations.
-    * The values will be of format _BaseFormat and type DataType.
-    */
-   void (*PutValues)(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                     const GLint x[], const GLint y[], const void *values,
-                     const GLubyte *mask);
 };
 
 
commit 64deeddce8eafa3d220c2db12a33848c2e12ed19
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:30:03 2012 -0700

    dri: remove all the obsolete spantmp files
    (cherry picked from commit 304f7a132741a528ca6e861a918ef59991874e5f)

diff --git a/src/mesa/drivers/dri/common/depthtmp.h b/src/mesa/drivers/dri/common/depthtmp.h
deleted file mode 100644
index d8f259f..0000000
--- a/src/mesa/drivers/dri/common/depthtmp.h
+++ /dev/null
@@ -1,218 +0,0 @@
-
-/*
- * Notes:
- * 1. These functions plug into the gl_renderbuffer structure.
- * 2. The 'values' parameter always points to GLuint values, regardless of
- *    the actual Z buffer depth.
- */
-
-
-#include "spantmp_common.h"
-
-#ifndef DBG
-#define DBG 0
-#endif
-
-#ifndef HAVE_HW_DEPTH_SPANS
-#define HAVE_HW_DEPTH_SPANS 0
-#endif
-
-#ifndef HAVE_HW_DEPTH_PIXELS
-#define HAVE_HW_DEPTH_PIXELS 0
-#endif
-
-static void TAG(WriteDepthSpan)( struct gl_context *ctx,
-                                 struct gl_renderbuffer *rb,
-                                 GLuint n, GLint x, GLint y,
-				 const void *values,
-				 const GLubyte mask[] )
-{
-   HW_WRITE_LOCK()
-      {
-         const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
-	 GLint x1;
-	 GLint n1;
-	 LOCAL_DEPTH_VARS;
-
-	 y = Y_FLIP( y );
-
-#if HAVE_HW_DEPTH_SPANS
-	 (void) x1; (void) n1;
-
-	 if ( DBG ) fprintf( stderr, "WriteDepthSpan 0..%d (x1 %d)\n",
-			     (int)n, (int)x );
-
-	 WRITE_DEPTH_SPAN();
-#else
-	 HW_CLIPLOOP()
-	    {
-	       GLint i = 0;
-	       CLIPSPAN( x, y, n, x1, n1, i );
-
-	       if ( DBG ) fprintf( stderr, "WriteDepthSpan %d..%d (x1 %d) (mask %p)\n",
-				   (int)i, (int)n1, (int)x1, mask );
-
-	       if ( mask ) {
-		  for ( ; n1>0 ; i++, x1++, n1-- ) {
-		     if ( mask[i] ) WRITE_DEPTH( x1, y, depth[i] );
-		  }
-	       } else {
-		  for ( ; n1>0 ; i++, x1++, n1-- ) {
-		     WRITE_DEPTH( x1, y, depth[i] );
-		  }
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif
-      }
-   HW_WRITE_UNLOCK();
-
-   (void) ctx;
-}
-
-
-static void TAG(WriteDepthPixels)( struct gl_context *ctx,
-                                   struct gl_renderbuffer *rb,
-				   GLuint n,
-				   const GLint x[],
-				   const GLint y[],
-				   const void *values,
-				   const GLubyte mask[] )
-{
-   HW_WRITE_LOCK()
-      {
-         const VALUE_TYPE *depth = (const VALUE_TYPE *) values;
-	 GLuint i;
-	 LOCAL_DEPTH_VARS;
-
-	 if ( DBG ) fprintf( stderr, "WriteDepthPixels\n" );
-
-#if HAVE_HW_DEPTH_PIXELS
-	 (void) i;
-
-	 WRITE_DEPTH_PIXELS();
-#else
-	 HW_CLIPLOOP()
-	    {
-	       if ( mask ) {
-		  for ( i = 0 ; i < n ; i++ ) {
-		     if ( mask[i] ) {
-			const int fy = Y_FLIP( y[i] );
-			if ( CLIPPIXEL( x[i], fy ) )
-			   WRITE_DEPTH( x[i], fy, depth[i] );
-		     }
-		  }
-	       }
-	       else {
-		  for ( i = 0 ; i < n ; i++ ) {
-		     const int fy = Y_FLIP( y[i] );
-		     if ( CLIPPIXEL( x[i], fy ) )
-			WRITE_DEPTH( x[i], fy, depth[i] );
-		  }
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif
-      }
-   HW_WRITE_UNLOCK();
-
-   (void) ctx;
-}
-
-
-/* Read depth spans and pixels
- */
-static void TAG(ReadDepthSpan)( struct gl_context *ctx,
-                                struct gl_renderbuffer *rb,
-				GLuint n, GLint x, GLint y,
-				void *values )
-{
-   HW_READ_LOCK()
-      {
-         VALUE_TYPE *depth = (VALUE_TYPE *) values;
-	 GLint x1, n1;
-	 LOCAL_DEPTH_VARS;
-
-	 y = Y_FLIP( y );
-
-	 if ( DBG ) fprintf( stderr, "ReadDepthSpan\n" );
-
-#if HAVE_HW_DEPTH_SPANS
-	 (void) x1; (void) n1;
-
-	 READ_DEPTH_SPAN();
-#else
-	 HW_CLIPLOOP()
-	    {
-	       GLint i = 0;
-	       CLIPSPAN( x, y, n, x1, n1, i );
-	       for ( ; n1>0 ; i++, n1-- ) {
-		  READ_DEPTH( depth[i], x+i, y );
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif
-      }
-   HW_READ_UNLOCK();
-}
-
-static void TAG(ReadDepthPixels)( struct gl_context *ctx,
-                                  struct gl_renderbuffer *rb,
-                                  GLuint n,
-				  const GLint x[], const GLint y[],
-				  void *values )
-{
-   HW_READ_LOCK()
-      {
-         VALUE_TYPE *depth = (VALUE_TYPE *) values;
-	 GLuint i;
-	 LOCAL_DEPTH_VARS;
-
-	 if ( DBG ) fprintf( stderr, "ReadDepthPixels\n" );
-
-#if HAVE_HW_DEPTH_PIXELS
-	 (void) i;
-
-	 READ_DEPTH_PIXELS();
-#else
-	 HW_CLIPLOOP()
-	    {
-	       for ( i = 0 ; i < n ;i++ ) {
-		  int fy = Y_FLIP( y[i] );
-		  if ( CLIPPIXEL( x[i], fy ) )
-		     READ_DEPTH( depth[i], x[i], fy );
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif
-      }
-   HW_READ_UNLOCK();
-
-   (void) ctx;
-}
-
-
-/**
- * Initialize the given renderbuffer's span routines to point to
- * the depth/z functions we generated above.
- */
-static void TAG(InitDepthPointers)(struct gl_renderbuffer *rb)
-{
-   rb->GetRow = TAG(ReadDepthSpan);
-   rb->GetValues = TAG(ReadDepthPixels);
-   rb->PutRow = TAG(WriteDepthSpan);
-   rb->PutValues = TAG(WriteDepthPixels);
-}
-
-
-#if HAVE_HW_DEPTH_SPANS
-#undef WRITE_DEPTH_SPAN
-#undef WRITE_DEPTH_PIXELS
-#undef READ_DEPTH_SPAN
-#undef READ_DEPTH_PIXELS
-#else
-#undef WRITE_DEPTH
-#undef READ_DEPTH
-#endif
-#undef TAG
-#undef VALUE_TYPE
diff --git a/src/mesa/drivers/dri/common/spantmp2.h b/src/mesa/drivers/dri/common/spantmp2.h
deleted file mode 100644
index 744dfcd..0000000
--- a/src/mesa/drivers/dri/common/spantmp2.h
+++ /dev/null
@@ -1,777 +0,0 @@
-/*
- * Copyright 2000-2001 VA Linux Systems, Inc.
- * (C) Copyright IBM Corporation 2004
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file spantmp2.h
- *
- * Template file of span read / write functions.
- *
- * \author Keith Whitwell <keithw at tungstengraphics.com>
- * \author Gareth Hughes <gareth at nvidia.com>
- * \author Ian Romanick <idr at us.ibm.com>
- */
-
-#include "main/colormac.h"
-#include "spantmp_common.h"
-
-#ifndef DBG
-#define DBG 0
-#endif
-
-#ifndef HW_READ_CLIPLOOP
-#define HW_READ_CLIPLOOP()	HW_CLIPLOOP()
-#endif
-
-#ifndef HW_WRITE_CLIPLOOP
-#define HW_WRITE_CLIPLOOP()	HW_CLIPLOOP()
-#endif
-
-#if (SPANTMP_PIXEL_FMT == GL_RGB)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
-
-/**
- ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )				\
-   PUT_VALUE(_x, _y, ((((int)r & 0xf8) << 8) |				\
-		      (((int)g & 0xfc) << 3) |				\
-		      (((int)b & 0xf8) >> 3)))				\
-
-#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )					\
-   do {									\
-      GLushort p = GET_VALUE(_x, _y);					\
-      rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8;				\
-      rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc;				\
-      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;				\
-      rgba[3] = 0xff;							\
-   } while (0)
-
-#elif (SPANTMP_PIXEL_FMT == GL_RGB)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5_REV)
-
-/**
- ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )				\
-   PUT_VALUE(_x, _y, PACK_COLOR_565_REV( r, g, b ))
-
-#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )					\
-   do {									\
-      GLushort p = GET_VALUE(_x, _y);					\
-      p = p << 8 | p >> 8;						\
-      rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8;				\
-      rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc;				\
-      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;				\
-      rgba[3] = 0xff;							\
-   } while (0)
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4)
-
-/**
- ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )				\
-   PUT_VALUE(_x, _y, PACK_COLOR_4444_REV(a, r, g, b))			\
-
-#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )					\
-   do {									\
-      GLushort p = GET_VALUE(_x, _y);					\
-      rgba[0] = ((p >> 0) & 0xf) * 0x11;				\
-      rgba[1] = ((p >> 12) & 0xf) * 0x11;				\
-      rgba[2] = ((p >> 4) & 0xf) * 0x11;				\
-      rgba[3] = ((p >> 8) & 0xf) * 0x11;				\
-   } while (0)
-
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4_REV)
-
-/**
- ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )				\
-   PUT_VALUE(_x, _y, PACK_COLOR_4444(a, r, g, b))			\
-
-#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )					\
-   do {									\
-      GLushort p = GET_VALUE(_x, _y);					\
-      rgba[0] = ((p >> 8) & 0xf) * 0x11;				\
-      rgba[1] = ((p >> 4) & 0xf) * 0x11;				\
-      rgba[2] = ((p >> 0) & 0xf) * 0x11;				\
-      rgba[3] = ((p >> 12) & 0xf) * 0x11;				\
-   } while (0)
-
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5_REV)
-
-/**
- ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )				\
-   PUT_VALUE(_x, _y, PACK_COLOR_1555(a, r, g, b))			\
-
-#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )					\
-   do {									\
-      GLushort p = GET_VALUE(_x, _y);					\
-      rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8;				\
-      rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8;				\
-      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;				\
-      rgba[3] = ((p >> 15) & 0x1) * 0xff;				\
-   } while (0)
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGRA)  && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5)
-
-/**
- ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-#define WRITE_RGBA( _x, _y, r, g, b, a )				\
-   PUT_VALUE(_x, _y, PACK_COLOR_1555_REV(a, r, g, b))			\
-
-#define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )					\
-   do {									\
-      GLushort p = GET_VALUE(_x, _y);					\
-      p = p << 8 | p >> 8;						\
-      rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8;				\
-      rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8;				\
-      rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8;				\
-      rgba[3] = ((p >> 15) & 0x1) * 0xff;				\
-   } while (0)
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-
-/**
- ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (     buf + (_x) * 4 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-# define WRITE_RGBA(_x, _y, r, g, b, a)                                 \
-   PUT_VALUE(_x, _y, ((r << 16) |					\
-		      (g << 8) |					\
-		      (b << 0) |					\
-		      (a << 24)))
-
-#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
-
-# if defined( USE_X86_ASM )
-#  define READ_RGBA(rgba, _x, _y)                                       \
-    do {                                                                \
-       GLuint p = GET_VALUE(_x, _y);					\
-       __asm__ __volatile__( "bswap	%0; rorl $8, %0"                \
-				: "=r" (p) : "0" (p) );                 \
-       ((GLuint *)rgba)[0] = p;                                         \
-    } while (0)
-# elif defined( MESA_BIG_ENDIAN )
-    /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
-     * rotlwi instruction.  It also produces good code on SPARC.
-     */
-#  define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLuint p = GET_VALUE(_x, _y);					\
-        GLuint t = p;                                                   \
-        *((uint32_t *) rgba) = (t >> 24) | (p << 8);                    \
-     } while (0)
-# else
-#  define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLuint p = GET_VALUE(_x, _y);					\
-	rgba[0] = (p >> 16) & 0xff;					\
-	rgba[1] = (p >>  8) & 0xff;					\
-	rgba[2] = (p >>  0) & 0xff;					\
-	rgba[3] = (p >> 24) & 0xff;					\
-     } while (0)
-# endif
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8)
-
-/**
- ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (     buf + (_x) * 4 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-# define WRITE_RGBA(_x, _y, r, g, b, a)                                 \
-   PUT_VALUE(_x, _y, ((r << 8) |					\
-		      (g << 16) |					\
-		      (b << 24) |					\
-		      (a << 0)))
-
-#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
-
-# if defined( USE_X86_ASM )
-#  define READ_RGBA(rgba, _x, _y)                                       \
-    do {                                                                \
-       GLuint p = GET_VALUE(_x, _y);					\
-       __asm__ __volatile__( "rorl $8, %0"				\
-				: "=r" (p) : "0" (p) );                 \
-       ((GLuint *)rgba)[0] = p;                                         \
-    } while (0)
-# elif defined( MESA_BIG_ENDIAN )
-    /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
-     * rotlwi instruction.  It also produces good code on SPARC.
-     */
-#  define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLuint p = CPU_TO_LE32(GET_VALUE(_x, _y));                      \
-        GLuint t = p;                                                   \
-        *((uint32_t *) rgba) = (t >> 24) | (p << 8);                    \
-     } while (0)
-# else
-#  define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLuint p = GET_VALUE(_x, _y);					\
-	rgba[0] = (p >>  8) & 0xff;					\
-	rgba[1] = (p >> 16) & 0xff;					\
-	rgba[2] = (p >> 24) & 0xff;					\
-	rgba[3] = (p >>  0) & 0xff;					\
-     } while (0)
-# endif
-
-#elif (SPANTMP_PIXEL_FMT == GL_BGR) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-
-/**
- ** GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV
- **
- ** This is really for MESA_FORMAT_XRGB8888.  The spantmp code needs to be
- ** kicked to the curb, and we need to just code-gen this.
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (     buf + (_x) * 4 + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-# define WRITE_RGBA(_x, _y, r, g, b, a)					\
-   PUT_VALUE(_x, _y, ((r << 16) |					\
-		      (g << 8) |					\
-		      (b << 0) |					\
-		      (0xff << 24)))
-
-#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
-
-# if defined( USE_X86_ASM )
-#  define READ_RGBA(rgba, _x, _y)                                       \
-    do {                                                                \
-       GLuint p = GET_VALUE(_x, _y);					\
-       __asm__ __volatile__( "bswap	%0; rorl $8, %0"                \
-				: "=r" (p) : "0" (p) );                 \
-       ((GLuint *)rgba)[0] = p | 0xff000000;				\
-    } while (0)
-# elif defined( MESA_BIG_ENDIAN )
-    /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
-     * rotlwi instruction.  It also produces good code on SPARC.
-     */
-#  define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLuint p = GET_VALUE(_x, _y);					\
-        *((uint32_t *) rgba) = (p << 8) | 0xff;				\
-     } while (0)
-# else
-#  define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLuint p = GET_VALUE(_x, _y);					\
-	rgba[0] = (p >> 16) & 0xff;					\
-	rgba[1] = (p >>  8) & 0xff;					\
-	rgba[2] = (p >>  0) & 0xff;					\
-	rgba[3] = 0xff;							\
-     } while (0)
-# endif
-
-#elif (SPANTMP_PIXEL_FMT == GL_ALPHA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_BYTE)
-
-/**
- ** GL_ALPHA, GL_UNSIGNED_BYTE
- **/
-
-#ifndef GET_VALUE
-#ifndef GET_PTR
-#define GET_PTR(_x, _y) (     buf + (_x) + (_y) * pitch)
-#endif
-
-#define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y))
-#define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v)
-#endif /* GET_VALUE */
-
-# define WRITE_RGBA(_x, _y, r, g, b, a)                                 \
-   PUT_VALUE(_x, _y, a | (r & 0 /* quiet warnings */))
-
-#define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
-
-#define READ_RGBA( rgba, _x, _y )				        \
-     do {								\
-        GLubyte p = GET_VALUE(_x, _y);					\
-	rgba[0] = 0;							\
-	rgba[1] = 0;							\
-	rgba[2] = 0;							\
-	rgba[3] = p;							\
-     } while (0)
-
-#else
-#error SPANTMP_PIXEL_FMT must be set to a valid value!
-#endif
-
-
-
-/**
- ** Assembly routines.
- **/
-
-#if defined( USE_MMX_ASM ) || defined( USE_SSE_ASM )
-#include "x86/read_rgba_span_x86.h"
-#include "x86/common_x86_asm.h"
-#endif
-
-static void TAG(WriteRGBASpan)( struct gl_context *ctx,
-                                struct gl_renderbuffer *rb,
-				GLuint n, GLint x, GLint y,
-				const void *values, const GLubyte mask[] )
-{
-   (void) ctx;
-
-   HW_WRITE_LOCK()
-      {
-         const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-	 GLint x1;
-	 GLint n1;
-	 LOCAL_VARS;
-
-	 y = Y_FLIP(y);
-
-	 HW_WRITE_CLIPLOOP()
-	    {
-	       GLint i = 0;
-	       CLIPSPAN(x,y,n,x1,n1,i);
-
-	       if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
-				(int)i, (int)n1, (int)x1);
-
-	       if (mask)
-	       {
-		  for (;n1>0;i++,x1++,n1--)
-		     if (mask[i])
-			WRITE_RGBA( x1, y,
-				    rgba[i][0], rgba[i][1],
-				    rgba[i][2], rgba[i][3] );
-	       }
-	       else
-	       {
-		  for (;n1>0;i++,x1++,n1--)
-		     WRITE_RGBA( x1, y,
-				 rgba[i][0], rgba[i][1],
-				 rgba[i][2], rgba[i][3] );
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-      }
-   HW_WRITE_UNLOCK();
-}
-
-
-static void TAG(WriteRGBAPixels)( struct gl_context *ctx,
-                                  struct gl_renderbuffer *rb,
-                                  GLuint n, const GLint x[], const GLint y[],
-                                  const void *values, const GLubyte mask[] )
-{
-   (void) ctx;
-
-   HW_WRITE_LOCK()
-      {
-         const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-	 GLint i;
-	 LOCAL_VARS;
-
-	 if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
-
-	 HW_WRITE_CLIPLOOP()
-	    {
-	       if (mask)
-	       {
-	          for (i=0;i<n;i++)
-	          {
-		     if (mask[i]) {
-		        const int fy = Y_FLIP(y[i]);
-		        if (CLIPPIXEL(x[i],fy))
-			   WRITE_RGBA( x[i], fy,
-				       rgba[i][0], rgba[i][1],
-				       rgba[i][2], rgba[i][3] );
-		     }
-	          }
-	       }
-	       else
-	       {
-	          for (i=0;i<n;i++)
-	          {
-		     const int fy = Y_FLIP(y[i]);
-		     if (CLIPPIXEL(x[i],fy))
-			WRITE_RGBA( x[i], fy,
-				    rgba[i][0], rgba[i][1],
-				    rgba[i][2], rgba[i][3] );
-	          }
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-      }
-   HW_WRITE_UNLOCK();
-}
-
-
-static void TAG(ReadRGBASpan)( struct gl_context *ctx,
-                               struct gl_renderbuffer *rb,
-			       GLuint n, GLint x, GLint y, void *values)
-{
-   (void) ctx;
-
-   HW_READ_LOCK()
-      {
-         GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-	 GLint x1,n1;
-	 LOCAL_VARS;
-
-	 y = Y_FLIP(y);
-
-	 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
-
-	 HW_READ_CLIPLOOP()
-	    {
-	       GLint i = 0;
-	       CLIPSPAN(x,y,n,x1,n1,i);
-	       for (;n1>0;i++,x1++,n1--)
-		  READ_RGBA( rgba[i], x1, y );
-	    }
-         HW_ENDCLIPLOOP();
-      }
-   HW_READ_UNLOCK();
-}
-
-
-#if defined(GET_PTR) && \
-   defined(USE_MMX_ASM) && \
-   (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
-	(SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
-    ((SPANTMP_PIXEL_FMT == GL_RGB) && \
-	(SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
-static void TAG2(ReadRGBASpan,_MMX)( struct gl_context *ctx,
-                                     struct gl_renderbuffer *rb,
-                                     GLuint n, GLint x, GLint y, void *values)
-{
-#ifndef USE_INNER_EMMS
-   /* The EMMS instruction is directly in-lined here because using GCC's
-    * built-in _mm_empty function was found to utterly destroy performance.
-    */
-   __asm__ __volatile__( "emms" );
-#endif
-
-   (void) ctx;
-
-   HW_READ_LOCK()
-     {
-        GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-	GLint x1,n1;
-	LOCAL_VARS;
-
-	y = Y_FLIP(y);
-
-	if (DBG) fprintf(stderr, "ReadRGBASpan\n");
-
-	HW_READ_CLIPLOOP()
-	  {
-	     GLint i = 0;
-	     CLIPSPAN(x,y,n,x1,n1,i);
-
-	       {
-		  const void * src = GET_PTR( x1, y );
-#if (SPANTMP_PIXEL_FMT == GL_RGB) && \
-		  (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
-		  _generic_read_RGBA_span_RGB565_MMX( src, rgba[i], n1 );
-#else
-		  _generic_read_RGBA_span_BGRA8888_REV_MMX( src, rgba[i], n1 );
-#endif
-	       }
-	  }
-	HW_ENDCLIPLOOP();
-     }
-   HW_READ_UNLOCK();
-#ifndef USE_INNER_EMMS
-   __asm__ __volatile__( "emms" );
-#endif
-}
-#endif
-
-
-#if defined(GET_PTR) &&	\
-   defined(USE_SSE_ASM) && \
-   (SPANTMP_PIXEL_FMT == GL_BGRA) && \
-     (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-static void TAG2(ReadRGBASpan,_SSE2)( struct gl_context *ctx,
-                                      struct gl_renderbuffer *rb,
-                                      GLuint n, GLint x, GLint y,
-                                      void *values)
-{
-   (void) ctx;
-
-   HW_READ_LOCK()
-     {
-        GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-	GLint x1,n1;
-	LOCAL_VARS;
-
-	y = Y_FLIP(y);
-
-	if (DBG) fprintf(stderr, "ReadRGBASpan\n");
-
-	HW_READ_CLIPLOOP()
-	  {
-	     GLint i = 0;
-	     CLIPSPAN(x,y,n,x1,n1,i);
-
-	       {
-		  const void * src = GET_PTR( x1, y );
-		  _generic_read_RGBA_span_BGRA8888_REV_SSE2( src, rgba[i], n1 );
-	       }
-	  }
-	HW_ENDCLIPLOOP();
-     }
-   HW_READ_UNLOCK();
-}
-#endif
-
-#if defined(GET_PTR) &&	\
-   defined(USE_SSE_ASM) && \
-   (SPANTMP_PIXEL_FMT == GL_BGRA) && \
-     (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-static void TAG2(ReadRGBASpan,_SSE)( struct gl_context *ctx,
-                                     struct gl_renderbuffer *rb,
-                                     GLuint n, GLint x, GLint y,
-                                     void *values)
-{
-#ifndef USE_INNER_EMMS
-   /* The EMMS instruction is directly in-lined here because using GCC's
-    * built-in _mm_empty function was found to utterly destroy performance.
-    */
-   __asm__ __volatile__( "emms" );
-#endif
-
-   (void) ctx;
-
-   HW_READ_LOCK()
-     {
-        GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-	GLint x1,n1;
-	LOCAL_VARS;
-
-	y = Y_FLIP(y);
-
-	if (DBG) fprintf(stderr, "ReadRGBASpan\n");
-
-	HW_READ_CLIPLOOP()
-	  {
-	     GLint i = 0;
-	     CLIPSPAN(x,y,n,x1,n1,i);
-
-	       {
-		  const void * src = GET_PTR( x1, y );
-		  _generic_read_RGBA_span_BGRA8888_REV_SSE( src, rgba[i], n1 );
-	       }
-	  }
-	HW_ENDCLIPLOOP();
-     }
-   HW_READ_UNLOCK();
-#ifndef USE_INNER_EMMS
-   __asm__ __volatile__( "emms" );
-#endif
-}
-#endif
-
-
-static void TAG(ReadRGBAPixels)( struct gl_context *ctx,
-                                 struct gl_renderbuffer *rb,
-				 GLuint n, const GLint x[], const GLint y[],
-				 void *values )
-{
-   (void) ctx;
-
-   HW_READ_LOCK()
-      {
-         GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-	 GLint i;
-	 LOCAL_VARS;
-
-	 if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
-
-	 HW_READ_CLIPLOOP()
-	    {
-               for (i=0;i<n;i++) {
-                  int fy = Y_FLIP( y[i] );
-                     if (CLIPPIXEL( x[i], fy ))
-                        READ_RGBA( rgba[i], x[i], fy );
-               }
-	    }
-	 HW_ENDCLIPLOOP();
-      }
-   HW_READ_UNLOCK();
-}
-
-static void TAG(InitPointers)(struct gl_renderbuffer *rb)
-{
-   rb->PutRow = TAG(WriteRGBASpan);
-   rb->PutValues = TAG(WriteRGBAPixels);
-   rb->GetValues = TAG(ReadRGBAPixels);
-
-#if defined(GET_PTR)
-#if defined(USE_SSE_ASM) && \
-   (SPANTMP_PIXEL_FMT == GL_BGRA) && \
-     (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-   if ( cpu_has_xmm2 ) {
-      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE2" );
-      rb->GetRow = TAG2(ReadRGBASpan, _SSE2);
-   }
-   else
-#endif
-#if defined(USE_SSE_ASM) && \
-   (SPANTMP_PIXEL_FMT == GL_BGRA) && \
-     (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
-   if ( cpu_has_xmm ) {
-      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE" );
-      rb->GetRow = TAG2(ReadRGBASpan, _SSE);
-   }
-   else
-#endif
-#if defined(USE_MMX_ASM) && \
-   (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
-	(SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
-    ((SPANTMP_PIXEL_FMT == GL_RGB) && \
-	(SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
-   if ( cpu_has_mmx ) {
-      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "MMX" );
-      rb->GetRow = TAG2(ReadRGBASpan, _MMX);
-   }
-   else
-#endif
-#endif /* GET_PTR */
-   {
-      if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "C" );
-      rb->GetRow = TAG(ReadRGBASpan);
-   }
-
-}
-
-
-#undef WRITE_PIXEL
-#undef WRITE_RGBA
-#undef READ_RGBA
-#undef TAG
-#undef TAG2
-#undef GET_VALUE
-#undef PUT_VALUE
-#undef GET_PTR
-#undef SPANTMP_PIXEL_FMT
-#undef SPANTMP_PIXEL_TYPE
diff --git a/src/mesa/drivers/dri/common/spantmp_common.h b/src/mesa/drivers/dri/common/spantmp_common.h
deleted file mode 100644
index 8916e7b..0000000
--- a/src/mesa/drivers/dri/common/spantmp_common.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2000-2001 VA Linux Systems, Inc.
- * (C) Copyright IBM Corporation 2004
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file spantmp_common.h
- *
- * common macros for span read / write functions to be used in the depth,
- * stencil and pixel span templates.
- */
-
-#ifndef HW_WRITE_LOCK
-#define HW_WRITE_LOCK()		HW_LOCK()
-#endif
-
-#ifndef HW_WRITE_UNLOCK
-#define HW_WRITE_UNLOCK()	HW_UNLOCK()
-#endif
-
-#ifndef HW_READ_LOCK
-#define HW_READ_LOCK()		HW_LOCK()
-#endif
-
-#ifndef HW_READ_UNLOCK
-#define HW_READ_UNLOCK()	HW_UNLOCK()
-#endif
-
-#ifndef HW_CLIPLOOP
-#define HW_CLIPLOOP()							\
-   do {									\
-      int minx = 0;							\
-      int miny = 0;							\
-      int maxx = dPriv->w;						\
-      int maxy = dPriv->h;
-#endif
-
-#ifndef HW_ENDCLIPLOOP
-#define HW_ENDCLIPLOOP()						\
-   } while (0)
-#endif
-
-#ifndef CLIPPIXEL
-#define CLIPPIXEL( _x, _y )						\
-   ((_x >= minx) && (_x < maxx) && (_y >= miny) && (_y < maxy))
-#endif
-
-#ifndef CLIPSPAN
-#define CLIPSPAN( _x, _y, _n, _x1, _n1, _i )				\
-   if ( _y < miny || _y >= maxy /*|| _x + n < minx || _x >=maxx*/ ) {	\
-      _n1 = 0, _x1 = x;							\
-   } else {								\
-      _n1 = _n;								\
-      _x1 = _x;								\
-      if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
-      if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx);		        \
-   }
-#endif
diff --git a/src/mesa/drivers/dri/common/stenciltmp.h b/src/mesa/drivers/dri/common/stenciltmp.h
deleted file mode 100644
index 950d3c4..0000000
--- a/src/mesa/drivers/dri/common/stenciltmp.h
+++ /dev/null
@@ -1,186 +0,0 @@
-
-#include "spantmp_common.h"
-
-#ifndef DBG
-#define DBG 0
-#endif
-
-#ifndef HAVE_HW_STENCIL_SPANS
-#define HAVE_HW_STENCIL_SPANS 0
-#endif
-
-#ifndef HAVE_HW_STENCIL_PIXELS
-#define HAVE_HW_STENCIL_PIXELS 0
-#endif
-
-static void TAG(WriteStencilSpan)( struct gl_context *ctx,
-                                   struct gl_renderbuffer *rb,
-				   GLuint n, GLint x, GLint y,
-				   const void *values, const GLubyte mask[] )
-{
-   HW_WRITE_LOCK()
-      {
-         const GLubyte *stencil = (const GLubyte *) values;
-	 GLint x1;
-	 GLint n1;
-	 LOCAL_STENCIL_VARS;
-
-	 y = Y_FLIP(y);
-
-#if HAVE_HW_STENCIL_SPANS
-	 (void) x1; (void) n1;
-
-	 if (DBG) fprintf(stderr, "WriteStencilSpan 0..%d (x1 %d)\n",
-			  (int)n1, (int)x1);
-
-	 WRITE_STENCIL_SPAN();
-#else /* HAVE_HW_STENCIL_SPANS */
-	 HW_CLIPLOOP() 
-	    {
-	       GLint i = 0;
-	       CLIPSPAN(x,y,n,x1,n1,i);
-
-	       if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n",
-				(int)i, (int)n1, (int)x1);
-
-	       if (mask)
-	       {
-		  for (;n1>0;i++,x1++,n1--)
-		     if (mask[i])
-			WRITE_STENCIL( x1, y, stencil[i] );
-	       }
-	       else
-	       {
-		  for (;n1>0;i++,x1++,n1--)
-		     WRITE_STENCIL( x1, y, stencil[i] );
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif /* !HAVE_HW_STENCIL_SPANS */
-      }
-   HW_WRITE_UNLOCK();
-}
-
-
-static void TAG(WriteStencilPixels)( struct gl_context *ctx,
-                                     struct gl_renderbuffer *rb,
-				     GLuint n,
-				     const GLint x[], const GLint y[],
-				     const void *values, const GLubyte mask[] )
-{
-   HW_WRITE_LOCK()
-      {
-         const GLubyte *stencil = (const GLubyte *) values;
-	 GLuint i;
-	 LOCAL_STENCIL_VARS;
-
-	 if (DBG) fprintf(stderr, "WriteStencilPixels\n");
-
-#if HAVE_HW_STENCIL_PIXELS
-	 (void) i;
-
-	 WRITE_STENCIL_PIXELS();
-#else /* HAVE_HW_STENCIL_PIXELS */
-	 HW_CLIPLOOP()
-	    {
-	       for (i=0;i<n;i++)
-	       {
-		  if (mask[i]) {
-		     const int fy = Y_FLIP(y[i]);
-		     if (CLIPPIXEL(x[i],fy))
-			WRITE_STENCIL( x[i], fy, stencil[i] );
-		  }
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif /* !HAVE_HW_STENCIL_PIXELS */
-      }
-   HW_WRITE_UNLOCK();
-}
-
-
-/* Read stencil spans and pixels
- */
-static void TAG(ReadStencilSpan)( struct gl_context *ctx,
-                                  struct gl_renderbuffer *rb,
-				  GLuint n, GLint x, GLint y,
-				  void *values)
-{
-   HW_READ_LOCK()
-      {
-         GLubyte *stencil = (GLubyte *) values;
-	 GLint x1,n1;
-	 LOCAL_STENCIL_VARS;
-
-	 y = Y_FLIP(y);
-
-	 if (DBG) fprintf(stderr, "ReadStencilSpan\n");
-
-#if HAVE_HW_STENCIL_SPANS
-	 (void) x1; (void) n1;
-
-	 READ_STENCIL_SPAN();
-#else /* HAVE_HW_STENCIL_SPANS */
-	 HW_CLIPLOOP() 
-	    {
-	       GLint i = 0;
-	       CLIPSPAN(x,y,n,x1,n1,i);
-	       for (;n1>0;i++,n1--)
-		  READ_STENCIL( stencil[i], (x+i), y );
-	    }
-	 HW_ENDCLIPLOOP();
-#endif /* !HAVE_HW_STENCIL_SPANS */
-      }
-   HW_READ_UNLOCK();
-}
-
-static void TAG(ReadStencilPixels)( struct gl_context *ctx,
-                                    struct gl_renderbuffer *rb,
-                                    GLuint n, const GLint x[], const GLint y[],
-				    void *values )
-{
-   HW_READ_LOCK()
-      {
-         GLubyte *stencil = (GLubyte *) values;
-	 GLuint i;
-	 LOCAL_STENCIL_VARS;
-
-	 if (DBG) fprintf(stderr, "ReadStencilPixels\n");
- 
-#if HAVE_HW_STENCIL_PIXELS
-	 (void) i;
-
-	 READ_STENCIL_PIXELS();
-#else /* HAVE_HW_STENCIL_PIXELS */
-	 HW_CLIPLOOP()
-	    {
-	       for (i=0;i<n;i++) {
-		  int fy = Y_FLIP( y[i] );
-		  if (CLIPPIXEL( x[i], fy ))
-		     READ_STENCIL( stencil[i], x[i], fy );
-	       }
-	    }
-	 HW_ENDCLIPLOOP();
-#endif /* !HAVE_HW_STENCIL_PIXELS */
-      }
-   HW_READ_UNLOCK();
-}
-
-
-
-/**
- * Initialize the given renderbuffer's span routines to point to
- * the stencil functions we generated above.
- */
-static void TAG(InitStencilPointers)(struct gl_renderbuffer *rb)
-{
-   rb->GetRow = TAG(ReadStencilSpan);
-   rb->GetValues = TAG(ReadStencilPixels);
-   rb->PutRow = TAG(WriteStencilSpan);
-   rb->PutValues = TAG(WriteStencilPixels);
-}
-
-
-#undef WRITE_STENCIL
-#undef READ_STENCIL
-#undef TAG
commit 514fcec7daaf807bf228102e14618ea2494f450a
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:29:58 2012 -0700

    radeon: remove obsolete GetRow/PutRow code
    (cherry picked from commit a4c6dedb27897ae1340983b5d12927e0a9fb2212)

diff --git a/src/mesa/drivers/dri/radeon/radeon_fbo.c b/src/mesa/drivers/dri/radeon/radeon_fbo.c
index 3140657..a0d7956 100644
--- a/src/mesa/drivers/dri/radeon/radeon_fbo.c
+++ b/src/mesa/drivers/dri/radeon/radeon_fbo.c
@@ -456,16 +456,6 @@ radeon_unmap_renderbuffer(struct gl_context *ctx,
    rrb->map_bo = NULL;
 }
 
-static void *
-radeon_get_pointer(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		   GLint x, GLint y)
-{
-  radeon_print(RADEON_TEXTURE, RADEON_TRACE,
-		"%s(%p, rb %p) \n",
-		__func__, ctx, rb);
-
-  return NULL;
-}
 
 /**
  * Called via glRenderbufferStorageEXT() to set the format and allocate
@@ -756,7 +746,6 @@ radeon_create_renderbuffer(gl_format format, __DRIdrawable *driDrawPriv)
 
     rrb->base.Delete = radeon_delete_renderbuffer;
     rrb->base.AllocStorage = radeon_alloc_window_storage;
-    rrb->base.GetPointer = radeon_get_pointer;
 
     rrb->bo = NULL;
     return rrb;
@@ -781,7 +770,6 @@ radeon_new_renderbuffer(struct gl_context * ctx, GLuint name)
 
   rrb->base.Delete = radeon_delete_renderbuffer;
   rrb->base.AllocStorage = radeon_alloc_renderbuffer_storage;
-  rrb->base.GetPointer = radeon_get_pointer;
 
   return &rrb->base;
 }
diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c
index 569aca9..be5a913 100644
--- a/src/mesa/drivers/dri/radeon/radeon_span.c
+++ b/src/mesa/drivers/dri/radeon/radeon_span.c
@@ -49,120 +49,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "radeon_common.h"
 #include "radeon_span.h"
 
-#define DBG 0
-
-#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
-#if defined(__linux__)
-#include <byteswap.h>
-#define CPU_TO_LE16( x )	bswap_16( x )
-#define LE16_TO_CPU( x )	bswap_16( x )
-#endif /* __linux__ */
-#else
-#define CPU_TO_LE16( x )	( x )
-#define LE16_TO_CPU( x )	( x )
-#endif
-
-static void radeonSetSpanFunctions(struct radeon_renderbuffer *rrb);
-
-/*
- * Note that all information needed to access pixels in a renderbuffer
- * should be obtained through the gl_renderbuffer parameter, not per-context
- * information.
- */
-#define LOCAL_VARS						\
-   struct radeon_renderbuffer *rrb = (void *) rb;		\
-   int minx = 0, miny = 0;						\
-   int maxx = rb->Width;						\
-   int maxy = rb->Height;						\
-   void *buf = rb->Map;						\
-   int pitch = rb->RowStrideBytes;				\
-   GLuint p;						\
-   (void)p;
-
-#define Y_FLIP(_y) (_y)
-
-#define HW_LOCK()
-#define HW_UNLOCK()
-#define HW_CLIPLOOP()
-#define HW_ENDCLIPLOOP()
-
-/* ================================================================
- * Color buffer
- */
-
-/* 16 bit, RGB565 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_RGB
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
-#define TAG(x)    radeon##x##_RGB565
-#define TAG2(x,y) radeon##x##_RGB565##y
-#include "spantmp2.h"
-
-#define SPANTMP_PIXEL_FMT GL_RGB
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5_REV
-#define TAG(x)    radeon##x##_RGB565_REV
-#define TAG2(x,y) radeon##x##_RGB565_REV##y
-#include "spantmp2.h"
-
-/* 16 bit, ARGB1555 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5_REV
-#define TAG(x)    radeon##x##_ARGB1555
-#define TAG2(x,y) radeon##x##_ARGB1555##y
-#include "spantmp2.h"
-
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5
-#define TAG(x)    radeon##x##_ARGB1555_REV
-#define TAG2(x,y) radeon##x##_ARGB1555_REV##y
-#include "spantmp2.h"
-
-/* 16 bit, RGBA4 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4_REV
-#define TAG(x)    radeon##x##_ARGB4444
-#define TAG2(x,y) radeon##x##_ARGB4444##y
-#include "spantmp2.h"
-
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4
-#define TAG(x)    radeon##x##_ARGB4444_REV
-#define TAG2(x,y) radeon##x##_ARGB4444_REV##y
-#include "spantmp2.h"
-
-/* 32 bit, xRGB8888 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-#define TAG(x)    radeon##x##_xRGB8888
-#define TAG2(x,y) radeon##x##_xRGB8888##y
-#include "spantmp2.h"
-
-/* 32 bit, ARGB8888 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-#define TAG(x)    radeon##x##_ARGB8888
-#define TAG2(x,y) radeon##x##_ARGB8888##y
-#include "spantmp2.h"
-
-/* 32 bit, BGRx8888 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8
-#define TAG(x)    radeon##x##_BGRx8888
-#define TAG2(x,y) radeon##x##_BGRx8888##y
-#include "spantmp2.h"
-
-/* 32 bit, BGRA8888 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8
-#define TAG(x)    radeon##x##_BGRA8888
-#define TAG2(x,y) radeon##x##_BGRA8888##y
-#include "spantmp2.h"
 
 static void
 radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb)
@@ -181,8 +67,6 @@ radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb)
 	rb->Map = map;
 	rb->RowStride = stride / _mesa_get_format_bytes(rb->Format);
 	rb->RowStrideBytes = stride;
-
-	radeonSetSpanFunctions(rrb);
 }
 
 static void
@@ -194,8 +78,6 @@ radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb)
 
 	ctx->Driver.UnmapRenderbuffer(ctx, rb);
 
-	rb->GetRow = NULL;
-	rb->PutRow = NULL;
 	rb->Map = NULL;
 	rb->RowStride = 0;
 	rb->RowStrideBytes = 0;
@@ -275,40 +157,3 @@ void radeonInitSpanFuncs(struct gl_context * ctx)
 	swdd->SpanRenderFinish = radeonSpanRenderFinish;
 }
 
-/**
- * Plug in the Get/Put routines for the given driRenderbuffer.
- */
-static void radeonSetSpanFunctions(struct radeon_renderbuffer *rrb)
-{
-	if (rrb->base.Format == MESA_FORMAT_RGB565) {
-		radeonInitPointers_RGB565(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_RGB565_REV) {
-		radeonInitPointers_RGB565_REV(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_XRGB8888) {
-		radeonInitPointers_xRGB8888(&rrb->base);
-        } else if (rrb->base.Format == MESA_FORMAT_XRGB8888_REV) {
-		radeonInitPointers_BGRx8888(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_ARGB8888) {
-		radeonInitPointers_ARGB8888(&rrb->base);
-        } else if (rrb->base.Format == MESA_FORMAT_ARGB8888_REV) {
-		radeonInitPointers_BGRA8888(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_ARGB4444) {
-		radeonInitPointers_ARGB4444(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_ARGB4444_REV) {
-		radeonInitPointers_ARGB4444_REV(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_ARGB1555) {
-		radeonInitPointers_ARGB1555(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_ARGB1555_REV) {
-		radeonInitPointers_ARGB1555_REV(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_Z16) {
-		_swrast_set_renderbuffer_accessors(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_X8_Z24) {
-		_swrast_set_renderbuffer_accessors(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_S8_Z24) {
-		_swrast_set_renderbuffer_accessors(&rrb->base);
-	} else if (rrb->base.Format == MESA_FORMAT_S8) {
-		_swrast_set_renderbuffer_accessors(&rrb->base);
-	} else {
-		fprintf(stderr, "radeonSetSpanFunctions: bad format: 0x%04X\n", rrb->base.Format);
-	}
-}
commit 9b5e40283794c033522bbe92e1236ca0b5006c91
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:29:53 2012 -0700

    nouveau: remove obsolete GetRow/PutRow code
    (cherry picked from commit f892debdc21d12c40d2b69b4e9efdf527672d3ec)

diff --git a/src/mesa/drivers/dri/nouveau/nouveau_span.c b/src/mesa/drivers/dri/nouveau/nouveau_span.c
index c02682b..91a9311 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_span.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_span.c
@@ -31,72 +31,7 @@
 
 #include "swrast/swrast.h"
 
-#define LOCAL_VARS							\
-	struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface; \
-	GLuint p;							\
-	(void)p;
 
-#define LOCAL_DEPTH_VARS LOCAL_VARS
-
-#define HW_LOCK()
-#define HW_UNLOCK()
-
-#define HW_CLIPLOOP() {							\
-	int minx = 0;							\
-	int miny = 0;							\
-	int maxx = rb->Width;						\
-	int maxy = rb->Height;
-
-#define HW_ENDCLIPLOOP() }
-
-#define Y_FLIP(y) (rb->Name ? (y) : rb->Height - 1 - (y))
-
-/* RGB565 span functions */
-#define SPANTMP_PIXEL_FMT GL_RGB
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
-#define TAG(x) nouveau_##x##_rgb565
-#define TAG2(x, y) nouveau_##x##_rgb565##y
-#define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
-
-#include "spantmp2.h"
-
-/* RGB888 span functions */
-#define SPANTMP_PIXEL_FMT GL_BGR
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-#define TAG(x) nouveau_##x##_rgb888
-#define TAG2(x, y) nouveau_##x##_rgb888##y
-#define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
-
-#include "spantmp2.h"
-
-/* ARGB8888 span functions */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-#define TAG(x) nouveau_##x##_argb8888
-#define TAG2(x, y) nouveau_##x##_argb8888##y
-#define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
-
-#include "spantmp2.h"
-
-/* Z16 span functions */
-#define VALUE_TYPE uint16_t
-#define READ_DEPTH(v, x, y)						\
-	v = *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
-#define WRITE_DEPTH(x, y, v)						\
-	*(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
-#define TAG(x) nouveau_##x##_z16
-
-#include "depthtmp.h"
-
-/* Z24S8 span functions */
-#define VALUE_TYPE uint32_t
-#define READ_DEPTH(v, x, y)						\
-	v = *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
-#define WRITE_DEPTH(x, y, v)						\
-	*(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
-#define TAG(x) nouveau_##x##_z24s8
-
-#include "depthtmp.h"
 
 static void
 renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
@@ -104,26 +39,6 @@ renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
 	struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
 
 	if (map) {
-		switch (rb->Format) {
-		case MESA_FORMAT_RGB565:
-			nouveau_InitPointers_rgb565(rb);
-			break;
-		case MESA_FORMAT_XRGB8888:
-			nouveau_InitPointers_rgb888(rb);
-			break;
-		case MESA_FORMAT_ARGB8888:
-			nouveau_InitPointers_argb8888(rb);
-			break;
-		case MESA_FORMAT_Z16:
-			nouveau_InitDepthPointers_z16(rb);
-			break;
-		case MESA_FORMAT_Z24_S8:
-			nouveau_InitDepthPointers_z24s8(rb);
-			break;
-		default:
-			assert(0);
-		}
-
 		nouveau_bo_map(s->bo, NOUVEAU_BO_RDWR);
 	} else {
 		nouveau_bo_unmap(s->bo);
commit 57df49908ec4d5724d824a4b5482b7b7db02c06a
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:29:35 2012 -0700

    intel: remove most of the span Get/PutRow code
    (cherry picked from commit 41869c49421141807ab71cabca4c8a07611f6a64)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 45a6827..d3c2924 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -194,19 +194,6 @@ intel_unmap_renderbuffer(struct gl_context *ctx,
    intel_miptree_unmap(intel, irb->mt, irb->mt_level, irb->mt_layer);
 }
 
-/**
- * Return a pointer to a specific pixel in a renderbuffer.
- */
-static void *
-intel_get_pointer(struct gl_context * ctx, struct gl_renderbuffer *rb,
-                  GLint x, GLint y)
-{
-   /* By returning NULL we force all software rendering to go through
-    * the span routines.
-    */
-   return NULL;
-}
-
 
 /**
  * Called via glRenderbufferStorageEXT() to set the format and allocate
@@ -403,7 +390,6 @@ intel_create_renderbuffer(gl_format format)
    /* intel-specific methods */
    irb->Base.Delete = intel_delete_renderbuffer;
    irb->Base.AllocStorage = intel_alloc_window_storage;
-   irb->Base.GetPointer = intel_get_pointer;
 
    return irb;
 }
@@ -430,7 +416,6 @@ intel_new_renderbuffer(struct gl_context * ctx, GLuint name)
    /* intel-specific methods */
    irb->Base.Delete = intel_delete_renderbuffer;
    irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
-   irb->Base.GetPointer = intel_get_pointer;
    /* span routines set in alloc_storage function */
 
    return &irb->Base;
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 506c295..d6b4d0f 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -48,74 +48,6 @@
 #include "swrast/swrast.h"
 #include "swrast/s_renderbuffer.h"
 
-static void
-intel_set_span_functions(struct intel_context *intel,
-			 struct gl_renderbuffer *rb);
-
-#undef DBG
-#define DBG 0
-
-#define LOCAL_VARS							\
-   struct intel_renderbuffer *irb = intel_renderbuffer(rb);		\
-   int minx = 0, miny = 0;						\
-   int maxx = rb->Width;						\
-   int maxy = rb->Height;						\
-   int pitch = rb->RowStrideBytes;                                      \
-   void *buf = rb->Map;                                                 \
-   GLuint p;								\
-   (void) p;
-
-#define HW_CLIPLOOP()
-#define HW_ENDCLIPLOOP()
-
-#define Y_FLIP(_y) (_y)
-
-#define HW_LOCK()
-
-#define HW_UNLOCK()
-
-/* r5g6b5 color span and pixel functions */
-#define SPANTMP_PIXEL_FMT GL_RGB
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
-#define TAG(x) intel_##x##_RGB565
-#define TAG2(x,y) intel_##x##y_RGB565
-#include "spantmp2.h"
-
-/* a4r4g4b4 color span and pixel functions */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4_REV
-#define TAG(x) intel_##x##_ARGB4444
-#define TAG2(x,y) intel_##x##y_ARGB4444
-#include "spantmp2.h"
-
-/* a1r5g5b5 color span and pixel functions */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5_REV
-#define TAG(x) intel_##x##_ARGB1555
-#define TAG2(x,y) intel_##x##y##_ARGB1555
-#include "spantmp2.h"
-
-/* a8r8g8b8 color span and pixel functions */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-#define TAG(x) intel_##x##_ARGB8888
-#define TAG2(x,y) intel_##x##y##_ARGB8888
-#include "spantmp2.h"
-
-/* x8r8g8b8 color span and pixel functions */
-#define SPANTMP_PIXEL_FMT GL_BGR
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-#define TAG(x) intel_##x##_xRGB8888
-#define TAG2(x,y) intel_##x##y##_xRGB8888
-#include "spantmp2.h"
-
-/* a8 color span and pixel functions */
-#define SPANTMP_PIXEL_FMT GL_ALPHA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_BYTE
-#define TAG(x) intel_##x##_A8
-#define TAG2(x,y) intel_##x##y##_A8
-#include "spantmp2.h"
-
 /**
  * \brief Get pointer offset into stencil buffer.
  *
@@ -203,8 +135,6 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
    rb->Map = map;
    rb->RowStride = stride / _mesa_get_format_bytes(rb->Format);
    rb->RowStrideBytes = stride;
-
-   intel_set_span_functions(intel, rb);
 }
 
 static void
@@ -227,8 +157,6 @@ intel_renderbuffer_unmap(struct intel_context *intel,
 
    ctx->Driver.UnmapRenderbuffer(ctx, rb);
 
-   rb->GetRow = NULL;
-   rb->PutRow = NULL;
    rb->Map = NULL;
    rb->RowStride = 0;
    rb->RowStrideBytes = 0;
@@ -407,31 +335,6 @@ intel_unmap_vertex_shader_textures(struct gl_context *ctx)
    }
 }
 
-typedef void (*span_init_func)(struct gl_renderbuffer *rb);
-
-static span_init_func intel_span_init_funcs[MESA_FORMAT_COUNT] =
-{
-   [MESA_FORMAT_A8] = intel_InitPointers_A8,
-   [MESA_FORMAT_RGB565] = intel_InitPointers_RGB565,
-   [MESA_FORMAT_ARGB4444] = intel_InitPointers_ARGB4444,
-   [MESA_FORMAT_ARGB1555] = intel_InitPointers_ARGB1555,
-   [MESA_FORMAT_XRGB8888] = intel_InitPointers_xRGB8888,
-   [MESA_FORMAT_ARGB8888] = intel_InitPointers_ARGB8888,
-   [MESA_FORMAT_SARGB8] = intel_InitPointers_ARGB8888,
-   [MESA_FORMAT_Z16] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_X8_Z24] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_S8_Z24] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_S8] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_R8] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_GR88] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_R16] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_RG1616] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_RGBA_FLOAT32] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_RG_FLOAT32] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_R_FLOAT32] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_INTENSITY_FLOAT32] = _swrast_set_renderbuffer_accessors,
-   [MESA_FORMAT_LUMINANCE_FLOAT32] = _swrast_set_renderbuffer_accessors,
-};
 
 bool
 intel_span_supports_format(gl_format format)
@@ -440,27 +343,6 @@ intel_span_supports_format(gl_format format)
     * rather than coding up new paths through GetRow/PutRow(), so claim support
     * for those formats in here for now.
     */
-   return (intel_span_init_funcs[format] != NULL ||
-	   _mesa_is_format_integer_color(format));
+   return true;
 }
 
-/**
- * Plug in appropriate span read/write functions for the given renderbuffer.
- * These are used for the software fallbacks.
- */
-static void
-intel_set_span_functions(struct intel_context *intel,
-			 struct gl_renderbuffer *rb)
-{
-   struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
-
-   assert(intel_span_init_funcs[irb->Base.Format]);
-   intel_span_init_funcs[irb->Base.Format](rb);
-
-   if (rb->DataType == GL_NONE) {
-      _mesa_problem(NULL,
-		    "renderbuffer format %s is missing "
-		    "intel_mesa_format_to_rb_datatype() support.",
-		    _mesa_get_format_name(rb->Format));
-   }
-}
commit 38e4496ac3154642e0c69a5e0a7ff400e3b7186c
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:28:15 2012 -0700

    dri/swrast: remove obsolete GetRow/PutRow code
    
    This is a squash of:
    
        dri/swrast: remove obsolete GetRow/PutRow code
        (cherry picked from commit cb5fa9ea624574909bf57f9e1ad190a440d59dc2)
    
    and
    
        dri/swrast: remove obsolete swrast_span.c file from source list
        (cherry picked from commit a9bf149e7f699d05bcf31dff54c4b4cf78018dd0)
    
        Conflicts:
    
    	src/mesa/drivers/dri/swrast/Makefile.sources

diff --git a/src/mesa/drivers/dri/swrast/Makefile b/src/mesa/drivers/dri/swrast/Makefile
index 509fa28..fd4c44c 100644
--- a/src/mesa/drivers/dri/swrast/Makefile
+++ b/src/mesa/drivers/dri/swrast/Makefile
@@ -10,8 +10,7 @@ include ../Makefile.defines
 DRIVER_DEFINES = -D__NOT_HAVE_DRM_H
 
 DRIVER_SOURCES = \
-	swrast.c \
-	swrast_span.c
+	swrast.c
 
 C_SOURCES = \
 	$(SWRAST_COMMON_SOURCES) \
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 90a9638..e7f121e 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -335,11 +335,9 @@ swrast_new_renderbuffer(const struct gl_config *visual, __DRIdrawable *dPriv,
     xrb->Base.Delete = swrast_delete_renderbuffer;
     if (front) {
 	xrb->Base.AllocStorage = swrast_alloc_front_storage;
-	swrast_set_span_funcs_front(xrb, pixel_format);
     }
     else {
 	xrb->Base.AllocStorage = swrast_alloc_back_storage;
-	swrast_set_span_funcs_back(xrb, pixel_format);
     }
 
     switch (pixel_format) {
diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h
index b57012a..8695d4b 100644
--- a/src/mesa/drivers/dri/swrast/swrast_priv.h
+++ b/src/mesa/drivers/dri/swrast/swrast_priv.h
@@ -130,14 +130,4 @@ swrast_renderbuffer(struct gl_renderbuffer *rb)
 #define PF_X8R8G8B8   4		/**< 32bpp TrueColor:  8-R, 8-G, 8-B bits */
 
 
-/* swrast_span.c */
-
-extern void
-swrast_set_span_funcs_back(struct swrast_renderbuffer *xrb,
-			   GLuint pixel_format);
-
-extern void
-swrast_set_span_funcs_front(struct swrast_renderbuffer *xrb,
-			    GLuint pixel_format);
-
 #endif /* _SWRAST_PRIV_H_ */
diff --git a/src/mesa/drivers/dri/swrast/swrast_span.c b/src/mesa/drivers/dri/swrast/swrast_span.c
deleted file mode 100644
index ba6174f..0000000
--- a/src/mesa/drivers/dri/swrast/swrast_span.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  7.1
- *
- * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
- * Copyright 2008, 2010 George Sapountzis <gsapountzis at gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "swrast_priv.h"
-
-#define YFLIP(_xrb, Y) ((_xrb)->Base.Height - (Y) - 1)
-
-/*
- * Dithering support takes the "computation" extreme in the "computation vs.
- * storage" trade-off. This approach is very simple to implement and any
- * computational overhead should be acceptable. XMesa uses table lookups for
- * around 8KB of storage overhead per visual.
- */
-#define DITHER 1
-
-static const GLubyte kernel[16] = {
-    0*16,  8*16,  2*16, 10*16,
-   12*16,  4*16, 14*16,  6*16,
-    3*16, 11*16,  1*16,  9*16,
-   15*16,  7*16, 13*16,  5*16,
-};
-
-#if DITHER
-#define DITHER_COMP(X, Y) kernel[((X) & 0x3) | (((Y) & 0x3) << 2)]
-
-#define DITHER_CLAMP(X) (((X) < 255) ? (X) : 255)
-#else
-#define DITHER_COMP(X, Y) 0
-
-#define DITHER_CLAMP(X) (X)
-#endif
-
-
-/*
- * Pixel macros shared across front/back buffer span functions.
- */
-
-/* 32-bit BGRA */
-#define STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE) \
-   *DST = VALUE[ACOMP] << 24 | VALUE[RCOMP] << 16 | VALUE[GCOMP] << 8 | VALUE[BCOMP]
-#define STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE) \
-   *DST = 0xff << 24 | VALUE[RCOMP] << 16 | VALUE[GCOMP] << 8 | VALUE[BCOMP]
-#define FETCH_PIXEL_A8R8G8B8(DST, SRC) \
-   DST[ACOMP] = *SRC >> 24;            \
-   DST[RCOMP] = (*SRC >> 16) & 0xff;   \
-   DST[GCOMP] = (*SRC >> 8) & 0xff;    \
-   DST[BCOMP] = *SRC & 0xff
-
-
-/* 32-bit BGRX */
-#define STORE_PIXEL_X8R8G8B8(DST, X, Y, VALUE) \
-   *DST = 0xff << 24 | VALUE[RCOMP] << 16 | VALUE[GCOMP] << 8 | VALUE[BCOMP]
-#define STORE_PIXEL_RGB_X8R8G8B8(DST, X, Y, VALUE) \
-   *DST = 0xff << 24 | VALUE[RCOMP] << 16 | VALUE[GCOMP] << 8 | VALUE[BCOMP]
-#define FETCH_PIXEL_X8R8G8B8(DST, SRC) \
-   DST[ACOMP] = 0xff;                  \
-   DST[RCOMP] = (*SRC >> 16) & 0xff;   \
-   DST[GCOMP] = (*SRC >> 8) & 0xff;    \
-   DST[BCOMP] = *SRC & 0xff
-
-
-/* 16-bit BGR */
-#define STORE_PIXEL_R5G6B5(DST, X, Y, VALUE) \
-   do { \
-   int d = DITHER_COMP(X, Y) >> 6; \
-   *DST = ( ((DITHER_CLAMP((VALUE[RCOMP]) + d) & 0xf8) << 8) | \
-            ((DITHER_CLAMP((VALUE[GCOMP]) + d) & 0xfc) << 3) | \
-            ((DITHER_CLAMP((VALUE[BCOMP]) + d) & 0xf8) >> 3) ); \
-   } while(0)
-#define FETCH_PIXEL_R5G6B5(DST, SRC) \
-   do { \
-   DST[ACOMP] = 0xff; \
-   DST[RCOMP] = ((*SRC >> 8) & 0xf8) * 255 / 0xf8; \
-   DST[GCOMP] = ((*SRC >> 3) & 0xfc) * 255 / 0xfc; \
-   DST[BCOMP] = ((*SRC << 3) & 0xf8) * 255 / 0xf8; \
-   } while(0)
-
-
-/* 8-bit BGR */
-#define STORE_PIXEL_R3G3B2(DST, X, Y, VALUE) \
-   do { \
-   int d = DITHER_COMP(X, Y) >> 3; \
-   GLubyte *p = (GLubyte *)DST; \
-   *p = ( ((DITHER_CLAMP((VALUE[RCOMP]) + d) & 0xe0) >> 5) | \
-	  ((DITHER_CLAMP((VALUE[GCOMP]) + d) & 0xe0) >> 2) | \
-	  ((DITHER_CLAMP((VALUE[BCOMP]) + d) & 0xc0) >> 0) ); \
-   } while(0)
-#define FETCH_PIXEL_R3G3B2(DST, SRC) \
-   do { \
-   GLubyte p = *(GLubyte *)SRC; \
-   DST[ACOMP] = 0xff; \
-   DST[RCOMP] = ((p << 5) & 0xe0) * 255 / 0xe0; \
-   DST[GCOMP] = ((p << 2) & 0xe0) * 255 / 0xe0; \
-   DST[BCOMP] = ((p << 0) & 0xc0) * 255 / 0xc0; \
-   } while(0)
-
-
-/*
- * Generate code for back-buffer span functions.
- */
-
-/* 32-bit BGRA */
-#define NAME(FUNC) FUNC##_A8R8G8B8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLuint *P = (GLuint *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch / 4 + (X)
-#define INC_PIXEL_PTR(P) P++
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE)
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_A8R8G8B8(DST, SRC)
-
-#include "swrast/s_spantemp.h"
-
-
-/* 32-bit BGRX */
-#define NAME(FUNC) FUNC##_X8R8G8B8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLuint *P = (GLuint *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch / 4 + (X);
-#define INC_PIXEL_PTR(P) P++
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_X8R8G8B8(DST, X, Y, VALUE)
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   STORE_PIXEL_RGB_X8R8G8B8(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_X8R8G8B8(DST, SRC)
-
-#include "swrast/s_spantemp.h"
-
-
-/* 16-bit BGR */
-#define NAME(FUNC) FUNC##_R5G6B5
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch / 2 + (X);
-#define INC_PIXEL_PTR(P) P++
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_R5G6B5(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_R5G6B5(DST, SRC)
-
-#include "swrast/s_spantemp.h"
-
-
-/* 8-bit BGR */
-#define NAME(FUNC) FUNC##_R3G3B2
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X) * 1;
-#define INC_PIXEL_PTR(P) P += 1
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_R3G3B2(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_R3G3B2(DST, SRC)
-
-#include "swrast/s_spantemp.h"
-
-
-/*
- * Generate code for front-buffer span functions.
- */
-
-/* 32-bit BGRA */
-#define NAME(FUNC) FUNC##_A8R8G8B8_front
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLuint *P = (GLuint *)row;
-#define INC_PIXEL_PTR(P) P++
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE)
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_A8R8G8B8(DST, SRC)
-
-#include "swrast_spantemp.h"
-
-
-/* 32-bit BGRX */
-#define NAME(FUNC) FUNC##_X8R8G8B8_front
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLuint *P = (GLuint *)row;
-#define INC_PIXEL_PTR(P) P++
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_X8R8G8B8(DST, X, Y, VALUE)
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   STORE_PIXEL_RGB_X8R8G8B8(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_X8R8G8B8(DST, SRC)
-
-#include "swrast_spantemp.h"
-
-
-/* 16-bit BGR */
-#define NAME(FUNC) FUNC##_R5G6B5_front
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *)row;
-#define INC_PIXEL_PTR(P) P++
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_R5G6B5(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_R5G6B5(DST, SRC)
-
-#include "swrast_spantemp.h"
-
-
-/* 8-bit BGR */
-#define NAME(FUNC) FUNC##_R3G3B2_front
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *)row;
-#define INC_PIXEL_PTR(P) P += 1
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   STORE_PIXEL_R3G3B2(DST, X, Y, VALUE)
-#define FETCH_PIXEL(DST, SRC) \
-   FETCH_PIXEL_R3G3B2(DST, SRC)
-
-#include "swrast_spantemp.h"
-
-
-/*
- * Back-buffers are malloced memory and always private.
- *
- * BACK_PIXMAP (not supported)
- * BACK_XIMAGE
- */
-void
-swrast_set_span_funcs_back(struct swrast_renderbuffer *xrb,
-			   GLuint pixel_format)
-{
-    switch (pixel_format) {
-    case PF_A8R8G8B8:
-	xrb->Base.GetRow = get_row_A8R8G8B8;
-	xrb->Base.GetValues = get_values_A8R8G8B8;
-	xrb->Base.PutRow = put_row_A8R8G8B8;
-	xrb->Base.PutValues = put_values_A8R8G8B8;
-	break;
-    case PF_X8R8G8B8:
-	xrb->Base.GetRow = get_row_X8R8G8B8;
-	xrb->Base.GetValues = get_values_X8R8G8B8;
-	xrb->Base.PutRow = put_row_X8R8G8B8;
-	xrb->Base.PutValues = put_values_X8R8G8B8;
-	break;
-    case PF_R5G6B5:
-	xrb->Base.GetRow = get_row_R5G6B5;
-	xrb->Base.GetValues = get_values_R5G6B5;
-	xrb->Base.PutRow = put_row_R5G6B5;
-	xrb->Base.PutValues = put_values_R5G6B5;
-	break;
-    case PF_R3G3B2:
-	xrb->Base.GetRow = get_row_R3G3B2;
-	xrb->Base.GetValues = get_values_R3G3B2;
-	xrb->Base.PutRow = put_row_R3G3B2;
-	xrb->Base.PutValues = put_values_R3G3B2;
-	break;
-    default:
-	assert(0);
-	return;
-    }
-}
-
-
-/*
- * Front-buffers are provided by the loader, the xorg loader uses pixmaps.
- *
- * WINDOW,          An X window
- * GLXWINDOW,       GLX window
- * PIXMAP,          GLX pixmap
- * PBUFFER          GLX Pbuffer
- */
-void
-swrast_set_span_funcs_front(struct swrast_renderbuffer *xrb,
-			    GLuint pixel_format)
-{
-    switch (pixel_format) {
-    case PF_A8R8G8B8:
-	xrb->Base.GetRow = get_row_A8R8G8B8_front;
-	xrb->Base.GetValues = get_values_A8R8G8B8_front;
-	xrb->Base.PutRow = put_row_A8R8G8B8_front;
-	xrb->Base.PutValues = put_values_A8R8G8B8_front;
-	break;
-    case PF_X8R8G8B8:
-	xrb->Base.GetRow = get_row_X8R8G8B8_front;
-	xrb->Base.GetValues = get_values_X8R8G8B8_front;
-	xrb->Base.PutRow = put_row_X8R8G8B8_front;
-	xrb->Base.PutValues = put_values_X8R8G8B8_front;
-	break;
-    case PF_R5G6B5:
-	xrb->Base.GetRow = get_row_R5G6B5_front;
-	xrb->Base.GetValues = get_values_R5G6B5_front;
-	xrb->Base.PutRow = put_row_R5G6B5_front;
-	xrb->Base.PutValues = put_values_R5G6B5_front;
-	break;
-    case PF_R3G3B2:
-	xrb->Base.GetRow = get_row_R3G3B2_front;
-	xrb->Base.GetValues = get_values_R3G3B2_front;
-	xrb->Base.PutRow = put_row_R3G3B2_front;
-	xrb->Base.PutValues = put_values_R3G3B2_front;
-	break;
-    default:
-	assert(0);
-	return;
-    }
-}
diff --git a/src/mesa/drivers/dri/swrast/swrast_spantemp.h b/src/mesa/drivers/dri/swrast/swrast_spantemp.h
deleted file mode 100644
index 5067119..0000000
--- a/src/mesa/drivers/dri/swrast/swrast_spantemp.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Mesa 3-D graphics library
- * Version:  6.5.1
- *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/*
- * Modified version of swrast/s_spantemp.h for front-buffer rendering. The
- * no-mask paths use a scratch row to avoid repeated calls to the loader.
- *
- * For the mask paths we always use an array of 4 elements of RB_TYPE. This is
- * to satisfy the xorg loader requirement of an image pitch of 32 bits and
- * should be ok for other loaders also.
- */
-
-
-#ifndef _SWRAST_SPANTEMP_ONCE
-#define _SWRAST_SPANTEMP_ONCE
-
-static INLINE void
-PUT_PIXEL( struct gl_context *glCtx, GLint x, GLint y, GLvoid *p )
-{
-    __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
-    __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer)->dPriv;
-
-    __DRIscreen *screen = ctx->driScreenPriv;
-
-    screen->swrast_loader->putImage(draw, __DRI_SWRAST_IMAGE_OP_DRAW,
-				    x, y, 1, 1, (char *)p,
-				    draw->loaderPrivate);
-}
-
-
-static INLINE void
-GET_PIXEL( struct gl_context *glCtx, GLint x, GLint y, GLubyte *p )
-{
-    __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
-    __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer)->dPriv;
-
-    __DRIscreen *screen = ctx->driScreenPriv;
-
-    screen->swrast_loader->getImage(read, x, y, 1, 1, (char *)p,
-				    read->loaderPrivate);
-}
-
-static INLINE void
-PUT_ROW( struct gl_context *glCtx, GLint x, GLint y, GLuint n, char *row )
-{
-    __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
-    __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer)->dPriv;
-
-    __DRIscreen *screen = ctx->driScreenPriv;
-
-    screen->swrast_loader->putImage(draw, __DRI_SWRAST_IMAGE_OP_DRAW,
-				    x, y, n, 1, row,
-				    draw->loaderPrivate);
-}
-
-static INLINE void
-GET_ROW( struct gl_context *glCtx, GLint x, GLint y, GLuint n, char *row )
-{
-    __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
-    __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer)->dPriv;
-
-    __DRIscreen *screen = ctx->driScreenPriv;
-
-    screen->swrast_loader->getImage(read, x, y, n, 1, row,
-				    read->loaderPrivate);
-}
-
-#endif /* _SWRAST_SPANTEMP_ONCE */
-
-
-/*
- * Templates for the span/pixel-array write/read functions called via
- * the gl_renderbuffer's GetRow, GetValues, PutRow and PutValues.
- *
- * Define the following macros before including this file:
- *   NAME(BASE)  to generate the function name (i.e. add prefix or suffix)
- *   RB_TYPE  the renderbuffer DataType
- *   SPAN_VARS  to declare any local variables
- *   INIT_PIXEL_PTR(P, X, Y)  to initialize a pointer to a pixel
- *   INC_PIXEL_PTR(P)  to increment a pixel pointer by one pixel
- *   STORE_PIXEL(DST, X, Y, VALUE)  to store pixel values in buffer
- *   FETCH_PIXEL(DST, SRC)  to fetch pixel values from buffer
- *
- * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
- * for the pixels to be stored.  This is useful when dithering and probably
- * ignored otherwise.
- */
-
-#include "main/macros.h"
-
-
-#if !defined(RB_COMPONENTS)
-#define RB_COMPONENTS 4
-#endif
-
-
-static void
-NAME(get_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-               GLuint count, GLint x, GLint y, void *values )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   char *row = swrast_drawable(ctx->ReadBuffer)->row;
-   INIT_PIXEL_PTR(pixel, x, y);
-   GET_ROW( ctx, x, YFLIP(xrb, y), count, row );
-   for (i = 0; i < count; i++) {
-      FETCH_PIXEL(dest[i], pixel);
-      INC_PIXEL_PTR(pixel);
-   }
-   (void) rb;
-}
-
-
-static void
-NAME(get_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-                  GLuint count, const GLint x[], const GLint y[], void *values )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   for (i = 0; i < count; i++) {
-      RB_TYPE pixel[4];
-      GET_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
-      FETCH_PIXEL(dest[i], pixel);
-   }
-   (void) rb;
-}
-
-
-static void
-NAME(put_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-               GLuint count, GLint x, GLint y,
-               const void *values, const GLubyte mask[] )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   if (mask) {
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            RB_TYPE row[4];
-            INIT_PIXEL_PTR(pixel, x, y);
-            STORE_PIXEL(pixel, x + i, y, src[i]);
-            PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
-         }
-      }
-   }
-   else {
-      char *row = swrast_drawable(ctx->DrawBuffer)->row;
-      INIT_PIXEL_PTR(pixel, x, y);
-      for (i = 0; i < count; i++) {
-         STORE_PIXEL(pixel, x + i, y, src[i]);
-         INC_PIXEL_PTR(pixel);
-      }
-      PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
-   }
-   (void) rb;
-}
-
-
-static void
-NAME(put_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
-                  GLuint count, const GLint x[], const GLint y[],
-                  const void *values, const GLubyte mask[] )
-{
-#ifdef SPAN_VARS
-   SPAN_VARS
-#endif
-   const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
-   GLuint i;
-   ASSERT(mask);
-   for (i = 0; i < count; i++) {
-      if (mask[i]) {
-         RB_TYPE row[4];
-         INIT_PIXEL_PTR(pixel, x, y);
-         STORE_PIXEL(pixel, x[i], y[i], src[i]);
-         PUT_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
-      }
-   }
-   (void) rb;
-}
-
-
-
-
-#undef NAME
-#undef RB_TYPE
-#undef RB_COMPONENTS
-#undef SPAN_VARS
-#undef INIT_PIXEL_PTR
-#undef INC_PIXEL_PTR
-#undef STORE_PIXEL
-#undef STORE_PIXEL_RGB
-#undef FETCH_PIXEL
commit 39d978a60c193b6be20bc42714d883d725b8fa4d
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:28:02 2012 -0700

    osmesa: remove obsolete GetRow/PutRow code
    (cherry picked from commit 2873555a76a7358db053c3a7b121b489f8df9bb1)

diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 3d5ff8a..543bcbf 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -40,6 +40,7 @@
 #include "main/formats.h"
 #include "main/framebuffer.h"
 #include "main/imports.h"
+#include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/renderbuffer.h"
 #include "swrast/swrast.h"
@@ -121,372 +122,6 @@ osmesa_update_state( struct gl_context *ctx, GLuint new_state )
 
 
 
-/**********************************************************************/
-/*****        Read/write spans/arrays of pixels                   *****/
-/**********************************************************************/
-
-/* 8-bit RGBA */
-#define NAME(PREFIX) PREFIX##_RGBA8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP];  \
-   DST[3] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP];  \
-   DST[3] = 255
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[0];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[2];  \
-   DST[ACOMP] = SRC[3]
-#include "swrast/s_spantemp.h"
-
-/* 16-bit RGBA */
-#define NAME(PREFIX) PREFIX##_RGBA16
-#define RB_TYPE GLushort
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP];  \
-   DST[3] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP];  \
-   DST[3] = 65535
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[0];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[2];  \
-   DST[ACOMP] = SRC[3]
-#include "swrast/s_spantemp.h"
-
-/* 32-bit RGBA */
-#define NAME(PREFIX) PREFIX##_RGBA32
-#define RB_TYPE GLfloat
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[0] = MAX2((VALUE[RCOMP]), 0.0F); \
-   DST[1] = MAX2((VALUE[GCOMP]), 0.0F); \
-   DST[2] = MAX2((VALUE[BCOMP]), 0.0F); \
-   DST[3] = CLAMP((VALUE[ACOMP]), 0.0F, 1.0F)
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[0] = MAX2((VALUE[RCOMP]), 0.0F); \
-   DST[1] = MAX2((VALUE[GCOMP]), 0.0F); \
-   DST[2] = MAX2((VALUE[BCOMP]), 0.0F); \
-   DST[3] = 1.0F
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[0];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[2];  \
-   DST[ACOMP] = SRC[3]
-#include "swrast/s_spantemp.h"
-
-
-/* 8-bit BGRA */
-#define NAME(PREFIX) PREFIX##_BGRA8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP];  \
-   DST[3] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP];  \
-   DST[3] = 255
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[2];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[0];  \
-   DST[ACOMP] = SRC[3]
-#include "swrast/s_spantemp.h"
-
-/* 16-bit BGRA */
-#define NAME(PREFIX) PREFIX##_BGRA16
-#define RB_TYPE GLushort
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP];  \
-   DST[3] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP];  \
-   DST[3] = 65535
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[2];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[0];  \
-   DST[ACOMP] = SRC[3]
-#include "swrast/s_spantemp.h"
-
-/* 32-bit BGRA */
-#define NAME(PREFIX) PREFIX##_BGRA32
-#define RB_TYPE GLfloat
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP];  \
-   DST[3] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP];  \
-   DST[3] = 1.0F
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[2];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[0];  \
-   DST[ACOMP] = SRC[3]
-#include "swrast/s_spantemp.h"
-
-
-/* 8-bit ARGB */
-#define NAME(PREFIX) PREFIX##_ARGB8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[1] = VALUE[RCOMP];  \
-   DST[2] = VALUE[GCOMP];  \
-   DST[3] = VALUE[BCOMP];  \
-   DST[0] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[1] = VALUE[RCOMP];  \
-   DST[2] = VALUE[GCOMP];  \
-   DST[3] = VALUE[BCOMP];  \
-   DST[0] = 255
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[1];  \
-   DST[GCOMP] = SRC[2];  \
-   DST[BCOMP] = SRC[3];  \
-   DST[ACOMP] = SRC[0]
-#include "swrast/s_spantemp.h"
-
-/* 16-bit ARGB */
-#define NAME(PREFIX) PREFIX##_ARGB16
-#define RB_TYPE GLushort
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[1] = VALUE[RCOMP];  \
-   DST[2] = VALUE[GCOMP];  \
-   DST[3] = VALUE[BCOMP];  \
-   DST[0] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[1] = VALUE[RCOMP];  \
-   DST[2] = VALUE[GCOMP];  \
-   DST[3] = VALUE[BCOMP];  \
-   DST[0] = 65535
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[1];  \
-   DST[GCOMP] = SRC[2];  \
-   DST[BCOMP] = SRC[3];  \
-   DST[ACOMP] = SRC[0]
-#include "swrast/s_spantemp.h"
-
-/* 32-bit ARGB */
-#define NAME(PREFIX) PREFIX##_ARGB32
-#define RB_TYPE GLfloat
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 4 * (X)
-#define INC_PIXEL_PTR(P) P += 4
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[1] = VALUE[RCOMP];  \
-   DST[2] = VALUE[GCOMP];  \
-   DST[3] = VALUE[BCOMP];  \
-   DST[0] = VALUE[ACOMP]
-#define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
-   DST[1] = VALUE[RCOMP];  \
-   DST[2] = VALUE[GCOMP];  \
-   DST[3] = VALUE[BCOMP];  \
-   DST[0] = 1.0F
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[1];  \
-   DST[GCOMP] = SRC[2];  \
-   DST[BCOMP] = SRC[3];  \
-   DST[ACOMP] = SRC[0]
-#include "swrast/s_spantemp.h"
-
-
-/* 8-bit RGB */
-#define NAME(PREFIX) PREFIX##_RGB8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 3 * (X)
-#define INC_PIXEL_PTR(P) P += 3
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP]
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[0];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[2];  \
-   DST[ACOMP] = 255
-#include "swrast/s_spantemp.h"
-
-/* 16-bit RGB */
-#define NAME(PREFIX) PREFIX##_RGB16
-#define RB_TYPE GLushort
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 3 * (X)
-#define INC_PIXEL_PTR(P) P += 3
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP]
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[0];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[2];  \
-   DST[ACOMP] = 65535U
-#include "swrast/s_spantemp.h"
-
-/* 32-bit RGB */
-#define NAME(PREFIX) PREFIX##_RGB32
-#define RB_TYPE GLfloat
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 3 * (X)
-#define INC_PIXEL_PTR(P) P += 3
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[0] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[2] = VALUE[BCOMP]
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[0];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[2];  \
-   DST[ACOMP] = 1.0F
-#include "swrast/s_spantemp.h"
-
-
-/* 8-bit BGR */
-#define NAME(PREFIX) PREFIX##_BGR8
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (GLubyte *) osmesa->rowaddr[Y] + 3 * (X)
-#define INC_PIXEL_PTR(P) P += 3
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP]
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[2];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[0];  \
-   DST[ACOMP] = 255
-#include "swrast/s_spantemp.h"
-
-/* 16-bit BGR */
-#define NAME(PREFIX) PREFIX##_BGR16
-#define RB_TYPE GLushort
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + 3 * (X)
-#define INC_PIXEL_PTR(P) P += 3
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP]
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[2];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[0];  \
-   DST[ACOMP] = 65535
-#include "swrast/s_spantemp.h"
-
-/* 32-bit BGR */
-#define NAME(PREFIX) PREFIX##_BGR32
-#define RB_TYPE GLfloat
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLfloat *P = (GLfloat *) osmesa->rowaddr[Y] + 3 * (X)
-#define INC_PIXEL_PTR(P) P += 3
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   DST[2] = VALUE[RCOMP];  \
-   DST[1] = VALUE[GCOMP];  \
-   DST[0] = VALUE[BCOMP]
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = SRC[2];  \
-   DST[GCOMP] = SRC[1];  \
-   DST[BCOMP] = SRC[0];  \
-   DST[ACOMP] = 1.0F
-#include "swrast/s_spantemp.h"
-
-
-/* 16-bit 5/6/5 RGB */
-#define NAME(PREFIX) PREFIX##_RGB_565
-#define RB_TYPE GLubyte
-#define SPAN_VARS \
-   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-#define INIT_PIXEL_PTR(P, X, Y) \
-   GLushort *P = (GLushort *) osmesa->rowaddr[Y] + (X)
-#define INC_PIXEL_PTR(P) P += 1
-#define STORE_PIXEL(DST, X, Y, VALUE) \
-   *DST = ( (((VALUE[RCOMP]) & 0xf8) << 8) | (((VALUE[GCOMP]) & 0xfc) << 3) | ((VALUE[BCOMP]) >> 3) )
-#define FETCH_PIXEL(DST, SRC) \
-   DST[RCOMP] = ( (((*SRC) >> 8) & 0xf8) | (((*SRC) >> 11) & 0x7) ); \
-   DST[GCOMP] = ( (((*SRC) >> 3) & 0xfc) | (((*SRC) >>  5) & 0x3) ); \
-   DST[BCOMP] = ( (((*SRC) << 3) & 0xf8) | (((*SRC)      ) & 0x7) ); \
-   DST[ACOMP] = CHAN_MAX
-#include "swrast/s_spantemp.h"
-
-
 /**
  * Macros for optimized line/triangle rendering.
  * Only for 8-bit channel, RGBA, BGRA, ARGB formats.
@@ -789,24 +424,12 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
             rb->Format = MESA_FORMAT_RGBA8888_REV;
          else
             rb->Format = MESA_FORMAT_RGBA8888;
-         rb->GetRow = get_row_RGBA8;
-         rb->GetValues = get_values_RGBA8;
-         rb->PutRow = put_row_RGBA8;
-         rb->PutValues = put_values_RGBA8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
          rb->Format = MESA_FORMAT_RGBA_16;
-         rb->GetRow = get_row_RGBA16;
-         rb->GetValues = get_values_RGBA16;
-         rb->PutRow = put_row_RGBA16;
-         rb->PutValues = put_values_RGBA16;
       }
       else {
          rb->Format = MESA_FORMAT_RGBA_FLOAT32;
-         rb->GetRow = get_row_RGBA32;
-         rb->GetValues = get_values_RGBA32;
-         rb->PutRow = put_row_RGBA32;
-         rb->PutValues = put_values_RGBA32;
       }
    }
    else if (osmesa->format == OSMESA_BGRA) {
@@ -815,26 +438,14 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
             rb->Format = MESA_FORMAT_ARGB8888;
          else
             rb->Format = MESA_FORMAT_ARGB8888_REV;
-         rb->GetRow = get_row_BGRA8;
-         rb->GetValues = get_values_BGRA8;
-         rb->PutRow = put_row_BGRA8;
-         rb->PutValues = put_values_BGRA8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format BGRA/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
-         rb->GetRow = get_row_BGRA16;
-         rb->GetValues = get_values_BGRA16;
-         rb->PutRow = put_row_BGRA16;
-         rb->PutValues = put_values_BGRA16;
       }
       else {
          _mesa_warning(ctx, "Unsupported OSMesa format BGRA/GLfloat");
          rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
-         rb->GetRow = get_row_BGRA32;
-         rb->GetValues = get_values_BGRA32;
-         rb->PutRow = put_row_BGRA32;
-         rb->PutValues = put_values_BGRA32;
       }
    }
    else if (osmesa->format == OSMESA_ARGB) {
@@ -843,85 +454,45 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
             rb->Format = MESA_FORMAT_ARGB8888_REV;
          else
             rb->Format = MESA_FORMAT_ARGB8888;
-         rb->GetRow = get_row_ARGB8;
-         rb->GetValues = get_values_ARGB8;
-         rb->PutRow = put_row_ARGB8;
-         rb->PutValues = put_values_ARGB8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format ARGB/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
-         rb->GetRow = get_row_ARGB16;
-         rb->GetValues = get_values_ARGB16;
-         rb->PutRow = put_row_ARGB16;
-         rb->PutValues = put_values_ARGB16;
       }
       else {
          _mesa_warning(ctx, "Unsupported OSMesa format ARGB/GLfloat");
          rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
-         rb->GetRow = get_row_ARGB32;
-         rb->GetValues = get_values_ARGB32;
-         rb->PutRow = put_row_ARGB32;
-         rb->PutValues = put_values_ARGB32;
       }
    }
    else if (osmesa->format == OSMESA_RGB) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
          rb->Format = MESA_FORMAT_RGB888;
-         rb->GetRow = get_row_RGB8;
-         rb->GetValues = get_values_RGB8;
-         rb->PutRow = put_row_RGB8;
-         rb->PutValues = put_values_RGB8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format RGB/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
-         rb->GetRow = get_row_RGB16;
-         rb->GetValues = get_values_RGB16;
-         rb->PutRow = put_row_RGB16;
-         rb->PutValues = put_values_RGB16;
       }
       else {
          _mesa_warning(ctx, "Unsupported OSMesa format RGB/GLfloat");
          rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
-         rb->GetRow = get_row_RGB32;
-         rb->GetValues = get_values_RGB32;
-         rb->PutRow = put_row_RGB32;
-         rb->PutValues = put_values_RGB32;
       }
    }
    else if (osmesa->format == OSMESA_BGR) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
          rb->Format = MESA_FORMAT_BGR888;
-         rb->GetRow = get_row_BGR8;
-         rb->GetValues = get_values_BGR8;
-         rb->PutRow = put_row_BGR8;
-         rb->PutValues = put_values_BGR8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
          _mesa_warning(ctx, "Unsupported OSMesa format BGR/GLushort");
          rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
-         rb->GetRow = get_row_BGR16;
-         rb->GetValues = get_values_BGR16;
-         rb->PutRow = put_row_BGR16;
-         rb->PutValues = put_values_BGR16;
       }
       else {
          _mesa_warning(ctx, "Unsupported OSMesa format BGR/GLfloat");
          rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
-         rb->GetRow = get_row_BGR32;
-         rb->GetValues = get_values_BGR32;
-         rb->PutRow = put_row_BGR32;
-         rb->PutValues = put_values_BGR32;
       }
    }
    else if (osmesa->format == OSMESA_RGB_565) {
       ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
       rb->Format = MESA_FORMAT_RGB565;
-      rb->GetRow = get_row_RGB_565;
-      rb->GetValues = get_values_RGB_565;
-      rb->PutRow = put_row_RGB_565;
-      rb->PutValues = put_values_RGB_565;
    }
    else {
       _mesa_problem(ctx, "bad pixel format in osmesa renderbuffer_storage");
commit e4b42d618c0fe501ac3438063e1eb8d21cd59c35
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:24:18 2012 -0700

    xlib: remove obsolete GetRow/PutRow code
    (cherry picked from commit 2e80c7e5bf822e3b9efd145d33badcf4f14504ff)

diff --git a/src/mesa/drivers/x11/xm_span.c b/src/mesa/drivers/x11/xm_span.c
index 37e8815..be4e545 100644
--- a/src/mesa/drivers/x11/xm_span.c
+++ b/src/mesa/drivers/x11/xm_span.c
@@ -146,1082 +146,6 @@ static unsigned long read_pixel( XMesaDisplay *dpy,
 
 
 
-/**********************************************************************/
-/*** Write COLOR SPAN functions                                     ***/
-/**********************************************************************/
-
-
-#define PUT_ROW_ARGS \
-	struct gl_context *ctx,					\
-	struct gl_renderbuffer *rb,			\
-	GLuint n, GLint x, GLint y,			\
-	const void *values, const GLubyte mask[]
-
-#define RGB_SPAN_ARGS \
-	struct gl_context *ctx,					\
-	struct gl_renderbuffer *rb,			\
-	GLuint n, GLint x, GLint y,			\
-	const void *values, const GLubyte mask[]
-
-
-#define GET_XRB(XRB) \
-   struct xmesa_renderbuffer *XRB = xmesa_renderbuffer(rb)
-
-
-/*
- * Write a span of PF_TRUECOLOR pixels to a pixmap.
- */
-static void put_row_TRUECOLOR_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = XMESA_BUFFER(ctx->DrawBuffer)->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            unsigned long p;
-            PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-            XMesaSetForeground( dpy, gc, p );
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      for (i=0;i<n;i++) {
-         unsigned long p;
-         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-         XMesaPutPixel( rowimg, i, 0, p );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-/*
- * Write a span of PF_TRUEDITHER pixels to a pixmap.
- */
-static void put_row_TRUEDITHER_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            unsigned long p;
-            PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-            XMesaSetForeground( dpy, gc, p );
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      for (i=0;i<n;i++) {
-         unsigned long p;
-         PACK_TRUEDITHER(p, x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-         XMesaPutPixel( rowimg, i, 0, p );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-/*
- * Write a span of PF_8A8B8G8R pixels to a pixmap.
- */
-static void put_row_8A8B8G8R_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            XMesaSetForeground( dpy, gc,
-                         PACK_8A8B8G8R(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      register GLuint *ptr4 = (GLuint *) rowimg->data;
-      for (i=0;i<n;i++) {
-         *ptr4++ = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-/*
- * Write a span of PF_8A8R8G8B pixels to a pixmap.
- */
-static void put_row_8A8R8G8B_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            XMesaSetForeground( dpy, gc,
-                         PACK_8A8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      register GLuint *ptr4 = (GLuint *) rowimg->data;
-      for (i=0;i<n;i++) {
-         *ptr4++ = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-
-/*
- * Write a span of PF_8R8G8B pixels to a pixmap.
- */
-static void put_row_8R8G8B_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-#if 1
-            /*
-             * XXX Something funny is going on here.
-             * If we're drawing into a window that uses a depth 32 TrueColor
-             * visual, we see the right pixels on screen, but when we read
-             * them back with XGetImage() we get random colors.
-             * The alternative code below which uses XPutImage() instead
-             * seems to mostly fix the problem, but not always.
-             * We don't normally create windows with this visual, but glean
-             * does and we're seeing some failures there.
-             */
-            XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-#else
-            /* This code works more often, but not always */
-            XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-            GLuint *ptr4 = (GLuint *) rowimg->data;
-            *ptr4 = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-            XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, 1, 1 );
-#endif
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      register GLuint *ptr4 = (GLuint *) rowimg->data;
-      for (i=0;i<n;i++) {
-         *ptr4++ = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-/*
- * Write a span of PF_8R8G8B24 pixels to a pixmap.
- */
-static void put_row_8R8G8B24_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      register GLuint i;
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            XMesaSetForeground( dpy, gc,
-               PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      register GLuint *ptr4 = (GLuint *) rowimg->data;
-      register GLuint pixel;
-      static const GLuint shift[4] = {0, 8, 16, 24};
-      register GLuint i = 0;
-      int w = n;
-      while (w > 3) {
-         pixel  = rgba[i][BCOMP] /* << shift[0]*/;
-         pixel |= rgba[i][GCOMP]    << shift[1];
-         pixel |= rgba[i++][RCOMP]  << shift[2];
-         pixel |= rgba[i][BCOMP]    << shift[3];
-         *ptr4++ = pixel;
-
-         pixel  = rgba[i][GCOMP] /* << shift[0]*/;
-         pixel |= rgba[i++][RCOMP]  << shift[1];
-         pixel |= rgba[i][BCOMP]    << shift[2];
-         pixel |= rgba[i][GCOMP]    << shift[3];
-         *ptr4++ = pixel;
-
-         pixel  = rgba[i++][RCOMP]/* << shift[0]*/;
-         pixel |= rgba[i][BCOMP]     << shift[1];
-         pixel |= rgba[i][GCOMP]     << shift[2];
-         pixel |= rgba[i++][RCOMP]   << shift[3];
-         *ptr4++ = pixel;
-
-         w -= 4;
-      }
-      switch (w) {
-         case 3:
-            pixel = 0;
-            pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
-            pixel |= rgba[i][GCOMP]   << shift[1];
-            pixel |= rgba[i++][RCOMP] << shift[2];
-            pixel |= rgba[i][BCOMP]   << shift[3];
-            *ptr4++ = pixel;
-            pixel = 0;
-            pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
-            pixel |= rgba[i++][RCOMP] << shift[1];
-            pixel |= rgba[i][BCOMP]   << shift[2];
-            pixel |= rgba[i][GCOMP]   << shift[3];
-            *ptr4++ = pixel;
-            pixel = 0xffffff00 & *ptr4;
-            pixel |= rgba[i][RCOMP] /*<< shift[0]*/;
-            *ptr4 = pixel;
-            break;
-         case 2:
-            pixel = 0;
-            pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
-            pixel |= rgba[i][GCOMP]   << shift[1];
-            pixel |= rgba[i++][RCOMP] << shift[2];
-            pixel |= rgba[i][BCOMP]   << shift[3];
-            *ptr4++ = pixel;
-            pixel = 0xffff0000 & *ptr4;
-            pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
-            pixel |= rgba[i][RCOMP]   << shift[1];
-            *ptr4 = pixel;
-            break;
-         case 1:
-            pixel = 0xff000000 & *ptr4;
-            pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
-            pixel |= rgba[i][GCOMP] << shift[1];
-            pixel |= rgba[i][RCOMP] << shift[2];
-            *ptr4 = pixel;
-            break;
-         case 0:
-            break;
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-
-/*
- * Write a span of PF_5R6G5B pixels to a pixmap.
- */
-static void put_row_5R6G5B_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      register GLushort *ptr2 = (GLushort *) rowimg->data;
-      for (i=0;i<n;i++) {
-         ptr2[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-/*
- * Write a span of PF_DITHER_5R6G5B pixels to a pixmap.
- */
-static void put_row_DITHER_5R6G5B_pixmap( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            unsigned long p;
-            PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-            XMesaSetForeground( dpy, gc, p );
-            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
-      register GLushort *ptr2 = (GLushort *) rowimg->data;
-      for (i=0;i<n;i++) {
-         PACK_TRUEDITHER( ptr2[i], x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-      }
-      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
-   }
-}
-
-
-/*
- * Write a span of PF_TRUECOLOR pixels to an XImage.
- */
-static void put_row_TRUECOLOR_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaImage *img = xrb->ximage;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            unsigned long p;
-            PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-            XMesaPutPixel( img, x, y, p );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      for (i=0;i<n;i++,x++) {
-         unsigned long p;
-         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-         XMesaPutPixel( img, x, y, p );
-      }
-   }
-}
-
-
-/*
- * Write a span of PF_TRUEDITHER pixels to an XImage.
- */
-static void put_row_TRUEDITHER_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaImage *img = xrb->ximage;
-   register GLuint i;
-   y = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            unsigned long p;
-            PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-            XMesaPutPixel( img, x, y, p );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      for (i=0;i<n;i++,x++) {
-         unsigned long p;
-         PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-         XMesaPutPixel( img, x, y, p );
-      }
-   }
-}
-
-
-/*
- * Write a span of PF_8A8B8G8R-format pixels to an ximage.
- */
-static void put_row_8A8B8G8R_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
-   (void) ctx;
-   if (mask) {
-      for (i=0;i<n;i++) {
-         if (mask[i]) {
-            ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      for (i=0;i<n;i++) {
-         ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-      }
-   }
-}
-
-
-/*
- * Write a span of PF_8A8R8G8B-format pixels to an ximage.
- */
-static void put_row_8A8R8G8B_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
-   if (mask) {
-      for (i=0;i<n;i++) {
-         if (mask[i]) {
-            ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-      for (i=0;i<n;i++) {
-         ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-      }
-   }
-}
-
-
-/*
- * Write a span of PF_8R8G8B-format pixels to an ximage.
- */
-static void put_row_8R8G8B_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
-   if (mask) {
-      for (i=0;i<n;i++) {
-         if (mask[i]) {
-            ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-         }
-      }
-   }
-   else {
-      for (i=0;i<n;i++) {
-         ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-      }
-   }
-}
-
-
-/*
- * Write a span of PF_8R8G8B24-format pixels to an ximage.
- */
-static void put_row_8R8G8B24_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y );
-   if (mask) {
-      for (i=0;i<n;i++) {
-         if (mask[i]) {
-            GLuint *ptr4 = (GLuint *) ptr;
-            register GLuint pixel = *ptr4;
-            switch (3 & (int)(ptr - (GLubyte*)ptr4)) {
-               case 0:
-                  pixel &= 0xff000000;
-                  pixel |= rgba[i][BCOMP];
-                  pixel |= rgba[i][GCOMP] << 8;
-                  pixel |= rgba[i][RCOMP] << 16;
-                  *ptr4 = pixel;
-                  break;
-               case 3:
-                  pixel &= 0x00ffffff;
-                  pixel |= rgba[i][BCOMP] << 24;
-                  *ptr4++ = pixel;
-                  pixel = *ptr4 & 0xffff0000;
-                  pixel |= rgba[i][GCOMP];
-                  pixel |= rgba[i][RCOMP] << 8;
-                  *ptr4 = pixel;
-                  break;
-               case 2:
-                  pixel &= 0x0000ffff;
-                  pixel |= rgba[i][BCOMP] << 16;
-                  pixel |= rgba[i][GCOMP] << 24;
-                  *ptr4++ = pixel;
-                  pixel = *ptr4 & 0xffffff00;
-                  pixel |= rgba[i][RCOMP];
-                  *ptr4 = pixel;
-                  break;
-               case 1:
-                  pixel &= 0x000000ff;
-                  pixel |= rgba[i][BCOMP] << 8;
-                  pixel |= rgba[i][GCOMP] << 16;
-                  pixel |= rgba[i][RCOMP] << 24;
-                  *ptr4 = pixel;
-                  break;
-            }
-         }
-	 ptr += 3;
-      }
-   }
-   else {
-      /* write all pixels */
-      int w = n;
-      GLuint *ptr4 = (GLuint *) ptr;
-      register GLuint pixel = *ptr4;
-      int index = (int)(ptr - (GLubyte *)ptr4);
-      register GLuint i = 0;
-      switch (index) {
-         case 0:
-            break;
-         case 1:
-            pixel &= 0x00ffffff;
-            pixel |= rgba[i][BCOMP] << 24;
-            *ptr4++ = pixel;
-            pixel = *ptr4 & 0xffff0000;
-            pixel |= rgba[i][GCOMP];
-            pixel |= rgba[i++][RCOMP] << 8;
-            *ptr4 = pixel;
-            if (0 == --w)
-               break;
-         case 2:
-            pixel &= 0x0000ffff;
-            pixel |= rgba[i][BCOMP] << 16;
-            pixel |= rgba[i][GCOMP] << 24;
-            *ptr4++ = pixel;
-            pixel = *ptr4 & 0xffffff00;
-            pixel |= rgba[i++][RCOMP];
-            *ptr4 = pixel;
-            if (0 == --w)
-               break;
-         case 3:
-            pixel &= 0x000000ff;
-            pixel |= rgba[i][BCOMP] << 8;
-            pixel |= rgba[i][GCOMP] << 16;
-            pixel |= rgba[i++][RCOMP] << 24;
-            *ptr4++ = pixel;
-            if (0 == --w)
-               break;
-            break;
-      }
-      while (w > 3) {
-         pixel = rgba[i][BCOMP];
-         pixel |= rgba[i][GCOMP] << 8;
-         pixel |= rgba[i++][RCOMP] << 16;
-         pixel |= rgba[i][BCOMP] << 24;
-         *ptr4++ = pixel;
-         pixel = rgba[i][GCOMP];
-         pixel |= rgba[i++][RCOMP] << 8;
-         pixel |= rgba[i][BCOMP] << 16;
-         pixel |= rgba[i][GCOMP] << 24;
-         *ptr4++ = pixel;
-         pixel = rgba[i++][RCOMP];
-         pixel |= rgba[i][BCOMP] << 8;
-         pixel |= rgba[i][GCOMP] << 16;
-         pixel |= rgba[i++][RCOMP] << 24;
-         *ptr4++ = pixel;
-         w -= 4;
-      }
-      switch (w) {
-         case 0:
-            break;
-         case 1:
-            pixel = *ptr4 & 0xff000000;
-            pixel |= rgba[i][BCOMP];
-            pixel |= rgba[i][GCOMP] << 8;
-            pixel |= rgba[i][RCOMP] << 16;
-            *ptr4 = pixel;
-            break;
-         case 2:
-            pixel = rgba[i][BCOMP];
-            pixel |= rgba[i][GCOMP] << 8;
-            pixel |= rgba[i++][RCOMP] << 16;
-            pixel |= rgba[i][BCOMP] << 24;
-            *ptr4++ = pixel;
-            pixel = *ptr4 & 0xffff0000;
-            pixel |= rgba[i][GCOMP];
-            pixel |= rgba[i][RCOMP] << 8;
-            *ptr4 = pixel;
-            break;
-         case 3:
-            pixel = rgba[i][BCOMP];
-            pixel |= rgba[i][GCOMP] << 8;
-            pixel |= rgba[i++][RCOMP] << 16;
-            pixel |= rgba[i][BCOMP] << 24;
-            *ptr4++ = pixel;
-            pixel = rgba[i][GCOMP];
-            pixel |= rgba[i++][RCOMP] << 8;
-            pixel |= rgba[i][BCOMP] << 16;
-            pixel |= rgba[i][GCOMP] << 24;
-            *ptr4++ = pixel;
-            pixel = *ptr4 & 0xffffff00;
-            pixel |= rgba[i][RCOMP];
-            *ptr4 = pixel;
-            break;
-      }
-   }
-}
-
-
-/*
- * Write a span of PF_5R6G5B-format pixels to an ximage.
- */
-static void put_row_5R6G5B_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
-   if (mask) {
-      for (i=0;i<n;i++) {
-         if (mask[i]) {
-            ptr[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
-      GLuint *ptr32 = (GLuint *) ptr;
-      GLuint extraPixel = (n & 1);
-      n -= extraPixel;
-      for (i = 0; i < n; i += 2) {
-         GLuint p0, p1;
-         p0 = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-         p1 = PACK_5R6G5B(rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP]);
-         *ptr32++ = (p1 << 16) | p0;
-      }
-      if (extraPixel) {
-         ptr[n] = PACK_5R6G5B(rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
-      }
-#else
-      for (i = 0; i < n; i++) {
-         ptr[i] = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-      }
-#endif
-   }
-}
-
-
-/*
- * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage.
- */
-static void put_row_DITHER_5R6G5B_ximage( PUT_ROW_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   register GLuint i;
-   register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
-   const GLint y2 = YFLIP(xrb, y);
-   if (mask) {
-      for (i=0;i<n;i++,x++) {
-         if (mask[i]) {
-            PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-         }
-      }
-   }
-   else {
-      /* draw all pixels */
-#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
-      GLuint *ptr32 = (GLuint *) ptr;
-      GLuint extraPixel = (n & 1);
-      n -= extraPixel;
-      for (i = 0; i < n; i += 2, x += 2) {
-         GLuint p0, p1;
-         PACK_TRUEDITHER( p0, x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-         PACK_TRUEDITHER( p1, x+1, y2, rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP] );
-         *ptr32++ = (p1 << 16) | p0;
-      }
-      if (extraPixel) {
-         PACK_TRUEDITHER( ptr[n], x+n, y2, rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
-      }
-#else
-      for (i = 0; i < n; i++, x++) {
-         PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-      }
-#endif
-   }
-}
-
-
-/**********************************************************************/
-/*** Write COLOR PIXEL functions                                    ***/
-/**********************************************************************/
-
-
-#define PUT_VALUES_ARGS \
-	struct gl_context *ctx, struct gl_renderbuffer *rb,	\
-	GLuint n, const GLint x[], const GLint y[],	\
-	const void *values, const GLubyte mask[]
-
-
-/*
- * Write an array of PF_TRUECOLOR pixels to a pixmap.
- */
-static void put_values_TRUECOLOR_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-         unsigned long p;
-         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-	 XMesaSetForeground( dpy, gc, p );
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_TRUEDITHER pixels to a pixmap.
- */
-static void put_values_TRUEDITHER_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-         unsigned long p;
-         PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-         XMesaSetForeground( dpy, gc, p );
-         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_8A8B8G8R pixels to a pixmap.
- */
-static void put_values_8A8B8G8R_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 XMesaSetForeground( dpy, gc,
-                         PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-/*
- * Write an array of PF_8A8R8G8B pixels to a pixmap.
- */
-static void put_values_8A8R8G8B_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 XMesaSetForeground( dpy, gc,
-                         PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-/*
- * Write an array of PF_8R8G8B pixels to a pixmap.
- */
-static void put_values_8R8G8B_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_8R8G8B24 pixels to a pixmap.
- */
-static void put_values_8R8G8B24_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_5R6G5B pixels to a pixmap.
- */
-static void put_values_5R6G5B_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
- */
-static void put_values_DITHER_5R6G5B_pixmap( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   XMesaDrawable buffer = xrb->drawable;
-   XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-         unsigned long p;
-         PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-	 XMesaSetForeground( dpy, gc, p );
-	 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_TRUECOLOR pixels to an ximage.
- */
-static void put_values_TRUECOLOR_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaImage *img = xrb->ximage;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-         unsigned long p;
-         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-	 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_TRUEDITHER pixels to an XImage.
- */
-static void put_values_TRUEDITHER_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-   XMesaImage *img = xrb->ximage;
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-         unsigned long p;
-         PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
-	 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_8A8B8G8R pixels to an ximage.
- */
-static void put_values_8A8B8G8R_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
-         *ptr = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-      }
-   }
-}
-
-/*
- * Write an array of PF_8A8R8G8B pixels to an ximage.
- */
-static void put_values_8A8R8G8B_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
-         *ptr = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_8R8G8B pixels to an ximage.
- */
-static void put_values_8R8G8B_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
-         *ptr = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_8R8G8B24 pixels to an ximage.
- */
-static void put_values_8R8G8B24_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
-         ptr->r = rgba[i][RCOMP];
-         ptr->g = rgba[i][GCOMP];
-         ptr->b = rgba[i][BCOMP];
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_5R6G5B pixels to an ximage.
- */
-static void put_values_5R6G5B_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
-         *ptr = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-      }
-   }
-}
-
-
-/*
- * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
- */
-static void put_values_DITHER_5R6G5B_ximage( PUT_VALUES_ARGS )
-{
-   const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   register GLuint i;
-   for (i=0;i<n;i++) {
-      if (mask[i]) {
-	 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
-         PACK_TRUEDITHER( *ptr, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
-      }
-   }
-}
 
 
 
@@ -1273,435 +197,11 @@ clip_for_xgetimage(struct gl_context *ctx, XMesaPixmap pixmap, GLuint *n, GLint
 }
 
 
-/*
- * Read a horizontal span of color pixels.
- */
-static void
-get_row_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
-             GLuint n, GLint x, GLint y, void *values)
-{
-   GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   GET_XRB(xrb);
-
-   if (xrb->pixmap) {
-      /* Read from Pixmap or Window */
-      XMesaImage *span = NULL;
-      int error;
-      int k;
-      y = YFLIP(xrb, y);
-      k = clip_for_xgetimage(ctx, xrb->pixmap, &n, &x, &y);
-      if (k < 0)
-         return;
-      rgba += k;
-      catch_xgetimage_errors( xmesa->display );
-      span = XGetImage( xmesa->display, xrb->pixmap,
-		        x, y, n, 1, AllPlanes, ZPixmap );
-      error = check_xgetimage_errors();
-      if (span && !error) {
-	 switch (xmesa->pixelformat) {
-	    case PF_Truecolor:
-	    case PF_Dither_True:
-               {
-                  const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
-                  const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
-                  const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
-                  unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
-                  unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
-                  unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
-                  GLint rShift = xmesa->xm_visual->rshift;
-                  GLint gShift = xmesa->xm_visual->gshift;
-                  GLint bShift = xmesa->xm_visual->bshift;
-                  GLuint i;
-                  for (i=0;i<n;i++) {
-                     unsigned long p;
-                     p = XMesaGetPixel( span, i, 0 );
-                     rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
-                     rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
-                     rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
-                     rgba[i][ACOMP] = 255;
-                  }
-               }
-	       break;
-            case PF_5R6G5B:
-            case PF_Dither_5R6G5B:
-               {
-                  const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
-                  const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
-                  const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
-                  GLuint i;
-                  for (i=0;i<n;i++) {
-                     unsigned long p = XMesaGetPixel( span, i, 0 );
-                     /* fast, but not quite accurate
-                     rgba[i][RCOMP] = ((p >> 8) & 0xf8);
-                     rgba[i][GCOMP] = ((p >> 3) & 0xfc);
-                     rgba[i][BCOMP] = ((p << 3) & 0xff);
-                     */
-                     rgba[i][RCOMP] = pixelToR[p >> 11];
-                     rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
-                     rgba[i][BCOMP] = pixelToB[p & 0x1f];
-                     rgba[i][ACOMP] = 255;
-                  }
-               }
-	       break;
-	    case PF_8A8B8G8R:
-               {
-                  const GLuint *ptr4 = (GLuint *) span->data;
-                  GLuint i;
-                  for (i=0;i<n;i++) {
-                     GLuint p4 = *ptr4++;
-                     rgba[i][RCOMP] = (GLubyte) ( p4        & 0xff);
-                     rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-                     rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-                     rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
-                  }
-	       }
-	       break;
-            case PF_8A8R8G8B:
-               {
-                  const GLuint *ptr4 = (GLuint *) span->data;
-                  GLuint i;
-                  for (i=0;i<n;i++) {
-                     GLuint p4 = *ptr4++;
-                     rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-                     rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-                     rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
-                     rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
-                  }
-	       }
-	       break;
-            case PF_8R8G8B:
-               {
-                  const GLuint *ptr4 = (GLuint *) span->data;
-                  GLuint i;
-                  for (i=0;i<n;i++) {
-                     GLuint p4 = *ptr4++;
-                     rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-                     rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-                     rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
-                     rgba[i][ACOMP] = 255;
-                  }
-	       }
-	       break;
-            case PF_8R8G8B24:
-               {
-                  const bgr_t *ptr3 = (bgr_t *) span->data;
-                  GLuint i;
-                  for (i=0;i<n;i++) {
-                     rgba[i][RCOMP] = ptr3[i].r;
-                     rgba[i][GCOMP] = ptr3[i].g;
-                     rgba[i][BCOMP] = ptr3[i].b;
-                     rgba[i][ACOMP] = 255;
-                  }
-	       }
-	       break;
-	    default:
-	       _mesa_problem(NULL,"Problem in DD.read_color_span (1)");
-               return;
-	 }
-      }
-      else {
-	 /* return black pixels */
-         GLuint i;
-	 for (i=0;i<n;i++) {
-	    rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = 0;
-	 }
-      }
-      if (span) {
-	 XMesaDestroyImage( span );
-      }
-   }
-   else if (xrb->ximage) {
-      /* Read from XImage back buffer */
-      switch (xmesa->pixelformat) {
-         case PF_Truecolor:
-         case PF_Dither_True:
-            {
-               const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
-               const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
-               const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
-               unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
-               unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
-               unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
-               GLint rShift = xmesa->xm_visual->rshift;
-               GLint gShift = xmesa->xm_visual->gshift;
-               GLint bShift = xmesa->xm_visual->bshift;
-               XMesaImage *img = xrb->ximage;
-               GLuint i;
-               y = YFLIP(xrb, y);
-               for (i=0;i<n;i++) {
-                  unsigned long p;
-		  p = XMesaGetPixel( img, x+i, y );
-                  rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
-                  rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
-                  rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
-                  rgba[i][ACOMP] = 255;
-               }
-            }
-            break;
-         case PF_5R6G5B:
-         case PF_Dither_5R6G5B:
-            {
-               const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
-               const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
-               const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
-               const GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y);
-               GLuint i;
-#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
-               const GLuint *ptr4 = (const GLuint *) ptr2;
-               GLuint extraPixel = (n & 1);
-               n -= extraPixel;
-               for (i = 0; i < n; i += 2) {
-                  const GLuint p = *ptr4++;
-                  const GLuint p0 = p & 0xffff;
-                  const GLuint p1 = p >> 16;
-                  /* fast, but not quite accurate
-                  rgba[i][RCOMP] = ((p >> 8) & 0xf8);
-                  rgba[i][GCOMP] = ((p >> 3) & 0xfc);
-                  rgba[i][BCOMP] = ((p << 3) & 0xff);
-                  */
-                  rgba[i][RCOMP] = pixelToR[p0 >> 11];
-                  rgba[i][GCOMP] = pixelToG[(p0 >> 5) & 0x3f];
-                  rgba[i][BCOMP] = pixelToB[p0 & 0x1f];
-                  rgba[i][ACOMP] = 255;
-                  rgba[i+1][RCOMP] = pixelToR[p1 >> 11];
-                  rgba[i+1][GCOMP] = pixelToG[(p1 >> 5) & 0x3f];
-                  rgba[i+1][BCOMP] = pixelToB[p1 & 0x1f];
-                  rgba[i+1][ACOMP] = 255;
-               }
-               if (extraPixel) {
-                  GLushort p = ptr2[n];
-                  rgba[n][RCOMP] = pixelToR[p >> 11];
-                  rgba[n][GCOMP] = pixelToG[(p >> 5) & 0x3f];
-                  rgba[n][BCOMP] = pixelToB[p & 0x1f];
-                  rgba[n][ACOMP] = 255;
-               }
-#else
-               for (i = 0; i < n; i++) {
-                  const GLushort p = ptr2[i];
-                  rgba[i][RCOMP] = pixelToR[p >> 11];
-                  rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
-                  rgba[i][BCOMP] = pixelToB[p & 0x1f];
-                  rgba[i][ACOMP] = 255;
-               }
-#endif
-            }
-            break;
-	 case PF_8A8B8G8R:
-            {
-               const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
-               GLuint i;
-               for (i=0;i<n;i++) {
-                  GLuint p4 = *ptr4++;
-                  rgba[i][RCOMP] = (GLubyte) ( p4        & 0xff);
-                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-                  rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-                  rgba[i][ACOMP] = (GLint)   ((p4 >> 24) & 0xff);
-               }
-            }
-	    break;
-	 case PF_8A8R8G8B:
-            {
-               const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
-               GLuint i;
-               for (i=0;i<n;i++) {
-                  GLuint p4 = *ptr4++;
-                  rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-                  rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
-                  rgba[i][ACOMP] = (GLint)   ((p4 >> 24) & 0xff);
-               }
-            }
-	    break;
-	 case PF_8R8G8B:
-            {
-               const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
-               GLuint i;
-               for (i=0;i<n;i++) {
-                  GLuint p4 = *ptr4++;
-                  rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-                  rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
-                  rgba[i][ACOMP] = 255;
-               }
-            }
-	    break;
-	 case PF_8R8G8B24:
-            {
-               const bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y);
-               GLuint i;
-               for (i=0;i<n;i++) {
-                  rgba[i][RCOMP] = ptr3[i].r;
-                  rgba[i][GCOMP] = ptr3[i].g;
-                  rgba[i][BCOMP] = ptr3[i].b;
-                  rgba[i][ACOMP] = 255;
-               }
-            }
-	    break;
-	 default:
-	    _mesa_problem(NULL,"Problem in DD.read_color_span (2)");
-            return;
-      }
-   }
-}
-
+#define GET_XRB(XRB) \
+   struct xmesa_renderbuffer *XRB = xmesa_renderbuffer(rb)
 
 
-static void
-get_values_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                GLuint n, const GLint x[], const GLint y[], void *values)
-{
-   GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
-   GET_XRB(xrb);
-   const XMesaContext xmesa = XMESA_CONTEXT(ctx);
-   XMesaDisplay *dpy = xmesa->xm_visual->display;
-   register GLuint i;
 
-   if (xrb->pixmap) {
-      XMesaDrawable buffer = xrb->drawable;
-      switch (xmesa->pixelformat) {
-	 case PF_Truecolor:
-         case PF_Dither_True:
-         case PF_5R6G5B:
-         case PF_Dither_5R6G5B:
-            {
-               unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
-               unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
-               unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
-               GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
-               GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
-               GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
-               GLint rShift = xmesa->xm_visual->rshift;
-               GLint gShift = xmesa->xm_visual->gshift;
-               GLint bShift = xmesa->xm_visual->bshift;
-               for (i=0;i<n;i++) {
-                  unsigned long p = read_pixel( dpy, buffer,
-                                                x[i], YFLIP(xrb, y[i]) );
-                  rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
-                  rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
-                  rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
-                  rgba[i][ACOMP] = 255;
-               }
-            }
-            break;
-	 case PF_8A8B8G8R:
-	    for (i=0;i<n;i++) {
-               unsigned long p = read_pixel( dpy, buffer,
-                                             x[i], YFLIP(xrb, y[i]) );
-               rgba[i][RCOMP] = (GLubyte) ( p        & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ((p >> 16) & 0xff);
-               rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
-	    }
-	    break;
-	 case PF_8A8R8G8B:
-	    for (i=0;i<n;i++) {
-               unsigned long p = read_pixel( dpy, buffer,
-                                             x[i], YFLIP(xrb, y[i]) );
-               rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ( p        & 0xff);
-               rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
-	    }
-	    break;
-	 case PF_8R8G8B:
-	    for (i=0;i<n;i++) {
-               unsigned long p = read_pixel( dpy, buffer,
-                                             x[i], YFLIP(xrb, y[i]) );
-               rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ( p        & 0xff);
-               rgba[i][ACOMP] = 255;
-	    }
-	    break;
-	 case PF_8R8G8B24:
-	    for (i=0;i<n;i++) {
-               unsigned long p = read_pixel( dpy, buffer,
-                                             x[i], YFLIP(xrb, y[i]) );
-               rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ( p        & 0xff);
-               rgba[i][ACOMP] = 255;
-	    }
-	    break;
-	 default:
-	    _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
-            return;
-      }
-   }
-   else if (xrb->ximage) {
-      /* Read from XImage back buffer */
-      switch (xmesa->pixelformat) {
-	 case PF_Truecolor:
-         case PF_Dither_True:
-         case PF_5R6G5B:
-         case PF_Dither_5R6G5B:
-            {
-               unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
-               unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
-               unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
-               GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
-               GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
-               GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
-               GLint rShift = xmesa->xm_visual->rshift;
-               GLint gShift = xmesa->xm_visual->gshift;
-               GLint bShift = xmesa->xm_visual->bshift;
-               XMesaImage *img = xrb->ximage;
-               for (i=0;i<n;i++) {
-                  unsigned long p;
-                  p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
-                  rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
-                  rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
-                  rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
-                  rgba[i][ACOMP] = 255;
-               }
-            }
-            break;
-	 case PF_8A8B8G8R:
-	    for (i=0;i<n;i++) {
-               GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
-               GLuint p4 = *ptr4;
-               rgba[i][RCOMP] = (GLubyte) ( p4        & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-               rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
-	    }
-	    break;
-	 case PF_8A8R8G8B:
-	    for (i=0;i<n;i++) {
-               GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
-               GLuint p4 = *ptr4;
-               rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
-               rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
-	    }
-	    break;
-	 case PF_8R8G8B:
-	    for (i=0;i<n;i++) {
-               GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
-               GLuint p4 = *ptr4;
-               rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
-               rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
-               rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
-               rgba[i][ACOMP] = 255;
-	    }
-	    break;
-	 case PF_8R8G8B24:
-	    for (i=0;i<n;i++) {
-               bgr_t *ptr3 = PIXEL_ADDR3(xrb, x[i], y[i]);
-               rgba[i][RCOMP] = ptr3->r;
-               rgba[i][GCOMP] = ptr3->g;
-               rgba[i][BCOMP] = ptr3->b;
-               rgba[i][ACOMP] = 255;
-	    }
-	    break;
-	 default:
-	    _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
-            return;
-      }
-   }
-}
 
 
 /**
@@ -1714,97 +214,6 @@ void
 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
                              enum pixel_format pixelformat, GLint depth)
 {
-   const GLboolean pixmap = xrb->pixmap ? GL_TRUE : GL_FALSE;
-
-   switch (pixelformat) {
-   case PF_Truecolor:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_TRUECOLOR_pixmap;
-         xrb->Base.PutValues     = put_values_TRUECOLOR_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_TRUECOLOR_ximage;
-         xrb->Base.PutValues     = put_values_TRUECOLOR_ximage;
-      }
-      break;
-   case PF_Dither_True:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_TRUEDITHER_pixmap;
-         xrb->Base.PutValues     = put_values_TRUEDITHER_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_TRUEDITHER_ximage;
-         xrb->Base.PutValues     = put_values_TRUEDITHER_ximage;
-      }
-      break;
-   case PF_8A8B8G8R:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_8A8B8G8R_pixmap;
-         xrb->Base.PutValues     = put_values_8A8B8G8R_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_8A8B8G8R_ximage;
-         xrb->Base.PutValues     = put_values_8A8B8G8R_ximage;
-      }
-      break;
-   case PF_8A8R8G8B:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_8A8R8G8B_pixmap;
-         xrb->Base.PutValues     = put_values_8A8R8G8B_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_8A8R8G8B_ximage;
-         xrb->Base.PutValues     = put_values_8A8R8G8B_ximage;
-      }
-      break;
-   case PF_8R8G8B:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_8R8G8B_pixmap;
-         xrb->Base.PutValues     = put_values_8R8G8B_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_8R8G8B_ximage;
-         xrb->Base.PutValues     = put_values_8R8G8B_ximage;
-      }
-      break;
-   case PF_8R8G8B24:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_8R8G8B24_pixmap;
-         xrb->Base.PutValues     = put_values_8R8G8B24_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_8R8G8B24_ximage;
-         xrb->Base.PutValues     = put_values_8R8G8B24_ximage;
-      }
-      break;
-   case PF_5R6G5B:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_5R6G5B_pixmap;
-         xrb->Base.PutValues     = put_values_5R6G5B_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_5R6G5B_ximage;
-         xrb->Base.PutValues     = put_values_5R6G5B_ximage;
-      }
-      break;
-   case PF_Dither_5R6G5B:
-      if (pixmap) {
-         xrb->Base.PutRow        = put_row_DITHER_5R6G5B_pixmap;
-         xrb->Base.PutValues     = put_values_DITHER_5R6G5B_pixmap;
-      }
-      else {
-         xrb->Base.PutRow        = put_row_DITHER_5R6G5B_ximage;
-         xrb->Base.PutValues     = put_values_DITHER_5R6G5B_ximage;
-      }
-      break;
-   default:
-      _mesa_problem(NULL, "Bad pixel format in xmesa_update_state (1)");
-      return;
-   }
-
-
-   /* Get functions */
-   xrb->Base.GetRow = get_row_rgba;
-   xrb->Base.GetValues = get_values_rgba;
+   /* XXX remove this */
 }
 
commit d85b4bae0ea615c54a342e10351c82901b3eb7db
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:24:09 2012 -0700

    mesa: remove obsolete PutRow, etc assignments
    (cherry picked from commit 0d2f0c8bb86b8dfcb6f0be7bf027fe725007bc5f)

diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index bb8f46d..39c25b0 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -33,17 +33,6 @@
 
 
 /**
- * Default GetPointer routine.  Always return NULL to indicate that
- * direct buffer access is not supported.
- */
-static void *
-nop_get_pointer(struct gl_context *ctx, struct gl_renderbuffer *rb, GLint x, GLint y)
-{
-   return NULL;
-}
-
-
-/**
  * Initialize the fields of a gl_renderbuffer to default values.
  */
 void
@@ -73,12 +62,6 @@ _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name)
     * all over the drivers.
     */
    rb->Wrapped = rb;
-
-   rb->GetPointer = nop_get_pointer;
-   rb->GetRow = NULL;
-   rb->GetValues = NULL;
-   rb->PutRow = NULL;
-   rb->PutValues = NULL;
 }
 
 
commit 3dd893749295a785688150452eddf829c7b605c3
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 18:33:09 2012 -0700

    swrast: remove Get/PutRow()-related code
    (cherry picked from commit d65bbfa947b9e2c5353bda857470a01d5398b3fa)

diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 1a7cb36..267ec3b 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -40,895 +40,6 @@
 #include "swrast/s_renderbuffer.h"
 
 
-/*
- * Routines for get/put values in common buffer formats follow.
- */
-
-/* Returns a bytes per pixel of the DataType in the get/put span
- * functions for at least a subset of the available combinations a
- * renderbuffer can have.
- *
- * It would be nice to see gl_renderbuffer start talking about a
- * gl_format instead of a GLenum DataType.
- */
-static int
-get_datatype_bytes(struct gl_renderbuffer *rb)
-{
-   int component_size;
-
-   switch (rb->DataType) {
-   case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
-      component_size = 8;
-      break;
-   case GL_FLOAT:
-   case GL_UNSIGNED_INT:
-   case GL_UNSIGNED_INT_24_8_EXT:
-      component_size = 4;
-      break;
-   case GL_UNSIGNED_SHORT:
-      component_size = 2;
-      break;
-   case GL_UNSIGNED_BYTE:
-      component_size = 1;
-      break;
-   default:
-      component_size = 1;
-      assert(0);
-   }
-
-   switch (rb->_BaseFormat) {
-   case GL_DEPTH_COMPONENT:
-   case GL_DEPTH_STENCIL:
-      return component_size;
-   default:
-      return 4 * component_size;
-   }
-}
-
-/* This is commonly used by most of the accessors. */
-static void *
-get_pointer_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		    GLint x, GLint y)
-{
-   if (!rb->Data)
-      return NULL;
-
-   return ((char *) rb->Data +
-	   (y * rb->RowStride + x) * _mesa_get_format_bytes(rb->Format));
-}
-
-/* GetRow() implementation for formats where DataType matches the rb->Format.
- */
-static void
-get_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		GLuint count, GLint x, GLint y, void *values)
-{
-   void *src = rb->GetPointer(ctx, rb, x, y);
-   memcpy(values, src, count * _mesa_get_format_bytes(rb->Format));
-}
-
-/* Only used for float textures currently, but might also be used for
- * RGBA8888, RGBA16, etc.
- */
-static void
-get_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		   GLuint count, const GLint x[], const GLint y[], void *values)
-{
-   int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const void *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      char *dst = (char *) values + i * format_bytes;
-      memcpy(dst, src, format_bytes);
-   }
-}
-
-/* For the GL_RED/GL_RG/GL_RGB format/DataType combinations (and
- * GL_LUMINANCE/GL_INTENSITY?), the Put functions are a matter of
- * storing those initial components of the value per pixel into the
- * destination.
- */
-static void
-put_row_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		GLuint count, GLint x, GLint y,
-		const void *values, const GLubyte *mask)
-{
-   void *row = rb->GetPointer(ctx, rb, x, y);
-   int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
-   int datatype_bytes = get_datatype_bytes(rb);
-   unsigned int i;
-
-   if (mask) {
-      for (i = 0; i < count; i++) {
-	 char *dst = (char *) row + i * format_bytes;
-	 const char *src = (const char *) values + i * datatype_bytes;
-
-         if (mask[i]) {
-	    memcpy(dst, src, format_bytes);
-         }
-      }
-   }
-   else {
-      for (i = 0; i < count; i++) {
-	 char *dst = (char *) row + i * format_bytes;
-	 const char *src = (const char *) values + i * datatype_bytes;
-	 memcpy(dst, src, format_bytes);
-      }
-   }
-}
-
-
-static void
-put_values_generic(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		   GLuint count, const GLint x[], const GLint y[],
-		   const void *values, const GLubyte *mask)
-{
-   int format_bytes = _mesa_get_format_bytes(rb->Format) / sizeof(GLfloat);
-   int datatype_bytes = get_datatype_bytes(rb);
-   unsigned int i;
-
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-	 void *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
-	 const char *src = (const char *) values + i * datatype_bytes;
-	 memcpy(dst, src, format_bytes);
-      }
-   }
-}
-
-
-
-/**********************************************************************
- * Functions for buffers of 1 X GLubyte values.
- * Typically stencil.
- */
-
-static void
-get_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                 const GLint x[], const GLint y[], void *values)
-{
-   GLubyte *dst = (GLubyte *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   for (i = 0; i < count; i++) {
-      const GLubyte *src = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
-      dst[i] = *src;
-   }
-}
-
-
-static void
-put_row_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-              GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   const GLubyte *src = (const GLubyte *) values;
-   GLubyte *dst = (GLubyte *) rb->Data + y * rb->RowStride + x;
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   if (mask) {
-      GLuint i;
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            dst[i] = src[i];
-         }
-      }
-   }
-   else {
-      memcpy(dst, values, count * sizeof(GLubyte));
-   }
-}
-
-
-static void
-put_values_ubyte(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                 const GLint x[], const GLint y[],
-                 const void *values, const GLubyte *mask)
-{
-   const GLubyte *src = (const GLubyte *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         GLubyte *dst = (GLubyte *) rb->Data + y[i] * rb->RowStride + x[i];
-         *dst = src[i];
-      }
-   }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 1 X GLushort values.
- * Typically depth/Z.
- */
-
-static void
-get_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  const GLint x[], const GLint y[], void *values)
-{
-   GLushort *dst = (GLushort *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
-   for (i = 0; i < count; i++) {
-      const GLushort *src = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
-      dst[i] = *src;
-   }
-}
-
-
-static void
-put_row_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-               GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   const GLushort *src = (const GLushort *) values;
-   GLushort *dst = (GLushort *) rb->Data + y * rb->RowStride + x;
-   ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
-   if (mask) {
-      GLuint i;
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            dst[i] = src[i];
-         }
-      }
-   }
-   else {
-      memcpy(dst, src, count * sizeof(GLushort));
-   }
-}
-
-
-static void
-put_values_ushort(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  const GLint x[], const GLint y[], const void *values,
-                  const GLubyte *mask)
-{
-   const GLushort *src = (const GLushort *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         GLushort *dst = (GLushort *) rb->Data + y[i] * rb->RowStride + x[i];
-         *dst = src[i];
-      }
-   }
-}
- 
-
-/**********************************************************************
- * Functions for buffers of 1 X GLuint values.
- * Typically depth/Z or color index.
- */
-
-static void
-get_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                const GLint x[], const GLint y[], void *values)
-{
-   GLuint *dst = (GLuint *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
-          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
-   for (i = 0; i < count; i++) {
-      const GLuint *src = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
-      dst[i] = *src;
-   }
-}
-
-
-static void
-put_row_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-             GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   const GLuint *src = (const GLuint *) values;
-   GLuint *dst = (GLuint *) rb->Data + y * rb->RowStride + x;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
-          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
-   if (mask) {
-      GLuint i;
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            dst[i] = src[i];
-         }
-      }
-   }
-   else {
-      memcpy(dst, src, count * sizeof(GLuint));
-   }
-}
-
-
-static void
-put_values_uint(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                const GLint x[], const GLint y[], const void *values,
-                const GLubyte *mask)
-{
-   const GLuint *src = (const GLuint *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_INT ||
-          rb->DataType == GL_UNSIGNED_INT_24_8_EXT);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         GLuint *dst = (GLuint *) rb->Data + y[i] * rb->RowStride + x[i];
-         *dst = src[i];
-      }
-   }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 3 X GLubyte (or GLbyte) values.
- * Typically color buffers.
- * NOTE: the incoming and outgoing colors are RGBA!  We ignore incoming
- * alpha values and return 255 for outgoing alpha values.
- */
-
-static void *
-get_pointer_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                   GLint x, GLint y)
-{
-   ASSERT(rb->Format == MESA_FORMAT_RGB888);
-   /* No direct access since this buffer is RGB but caller will be
-    * treating it as if it were RGBA.
-    */
-   return NULL;
-}
-
-
-static void
-get_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-               GLint x, GLint y, void *values)
-{
-   const GLubyte *src = ((const GLubyte *) rb->Data) +
-					   3 * (y * rb->RowStride + x);
-   GLubyte *dst = (GLubyte *) values;
-   GLuint i;
-   ASSERT(rb->Format == MESA_FORMAT_RGB888);
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + 0] = src[i * 3 + 0];
-      dst[i * 4 + 1] = src[i * 3 + 1];
-      dst[i * 4 + 2] = src[i * 3 + 2];
-      dst[i * 4 + 3] = 255;
-   }
-}
-
-
-static void
-get_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  const GLint x[], const GLint y[], void *values)
-{
-   GLubyte *dst = (GLubyte *) values;
-   GLuint i;
-   ASSERT(rb->Format == MESA_FORMAT_RGB888);
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   for (i = 0; i < count; i++) {
-      const GLubyte *src
-         = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
-      dst[i * 4 + 0] = src[0];
-      dst[i * 4 + 1] = src[1];
-      dst[i * 4 + 2] = src[2];
-      dst[i * 4 + 3] = 255;
-   }
-}
-
-
-static void
-put_row_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-               GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   /* note: incoming values are RGB+A! */
-   const GLubyte *src = (const GLubyte *) values;
-   GLubyte *dst = (GLubyte *) rb->Data + 3 * (y * rb->RowStride + x);
-   GLuint i;
-   ASSERT(rb->Format == MESA_FORMAT_RGB888);
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         dst[i * 3 + 0] = src[i * 4 + 0];
-         dst[i * 3 + 1] = src[i * 4 + 1];
-         dst[i * 3 + 2] = src[i * 4 + 2];
-      }
-   }
-}
-
-
-static void
-put_values_ubyte3(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  const GLint x[], const GLint y[], const void *values,
-                  const GLubyte *mask)
-{
-   /* note: incoming values are RGB+A! */
-   const GLubyte *src = (const GLubyte *) values;
-   GLuint i;
-   ASSERT(rb->Format == MESA_FORMAT_RGB888);
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         GLubyte *dst = (GLubyte *) rb->Data + 3 * (y[i] * rb->RowStride + x[i]);
-         dst[0] = src[i * 4 + 0];
-         dst[1] = src[i * 4 + 1];
-         dst[2] = src[i * 4 + 2];
-      }
-   }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 4 X GLubyte (or GLbyte) values.
- * Typically color buffers.
- */
-
-static void
-get_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  const GLint x[], const GLint y[], void *values)
-{
-   /* treat 4*GLubyte as 1*GLuint */
-   GLuint *dst = (GLuint *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
-          rb->Format == MESA_FORMAT_RGBA8888_REV);
-   for (i = 0; i < count; i++) {
-      const GLuint *src = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
-      dst[i] = *src;
-   }
-}
-
-
-static void
-put_row_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-               GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   /* treat 4*GLubyte as 1*GLuint */
-   const GLuint *src = (const GLuint *) values;
-   GLuint *dst = (GLuint *) rb->Data + (y * rb->RowStride + x);
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
-          rb->Format == MESA_FORMAT_RGBA8888_REV);
-   if (mask) {
-      GLuint i;
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            dst[i] = src[i];
-         }
-      }
-   }
-   else {
-      memcpy(dst, src, 4 * count * sizeof(GLubyte));
-   }
-}
-
-
-static void
-put_values_ubyte4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                  const GLint x[], const GLint y[], const void *values,
-                  const GLubyte *mask)
-{
-   /* treat 4*GLubyte as 1*GLuint */
-   const GLuint *src = (const GLuint *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
-   ASSERT(rb->Format == MESA_FORMAT_RGBA8888 ||
-          rb->Format == MESA_FORMAT_RGBA8888_REV);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         GLuint *dst = (GLuint *) rb->Data + (y[i] * rb->RowStride + x[i]);
-         *dst = src[i];
-      }
-   }
-}
-
-
-/**********************************************************************
- * Functions for buffers of 4 X GLushort (or GLshort) values.
- * Typically accum buffer.
- */
-
-static void
-get_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                   const GLint x[], const GLint y[], void *values)
-{
-   GLushort *dst = (GLushort *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
-   for (i = 0; i < count; i++) {
-      const GLushort *src
-         = (GLushort *) rb->Data + 4 * (y[i] * rb->RowStride + x[i]);
-      dst[i] = *src;
-   }
-}
-
-
-static void
-put_row_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   const GLushort *src = (const GLushort *) values;
-   GLushort *dst = (GLushort *) rb->Data + 4 * (y * rb->RowStride + x);
-   ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
-   if (mask) {
-      GLuint i;
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-            dst[i * 4 + 0] = src[i * 4 + 0];
-            dst[i * 4 + 1] = src[i * 4 + 1];
-            dst[i * 4 + 2] = src[i * 4 + 2];
-            dst[i * 4 + 3] = src[i * 4 + 3];
-         }
-      }
-   }
-   else {
-      memcpy(dst, src, 4 * count * sizeof(GLushort));
-   }
-}
-
-
-static void
-put_values_ushort4(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                   const GLint x[], const GLint y[], const void *values,
-                   const GLubyte *mask)
-{
-   const GLushort *src = (const GLushort *) values;
-   GLuint i;
-   ASSERT(rb->DataType == GL_UNSIGNED_SHORT || rb->DataType == GL_SHORT);
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-         GLushort *dst =
-            ((GLushort *) rb->Data) + 4 * (y[i] * rb->RowStride + x[i]);
-         dst[0] = src[i * 4 + 0];
-         dst[1] = src[i * 4 + 1];
-         dst[2] = src[i * 4 + 2];
-         dst[3] = src[i * 4 + 3];
-      }
-   }
-}
-
-
-/**********************************************************************
- * Functions for MESA_FORMAT_R8.
- */
-static void
-get_row_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-	   GLint x, GLint y, void *values)
-{
-   const GLubyte *src = rb->GetPointer(ctx, rb, x, y);
-   GLuint *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i] = 0xff000000 | src[i];
-   }
-}
-
-static void
-get_values_r8(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-	      const GLint x[], const GLint y[], void *values)
-{
-   GLuint *dst = (GLuint *) values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLubyte *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i] = 0xff000000 | *src;
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_GR88.
- */
-static void
-get_row_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-	     GLint x, GLint y, void *values)
-{
-   const GLushort *src = rb->GetPointer(ctx, rb, x, y);
-   GLuint *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i] = 0xff000000 | src[i];
-   }
-}
-
-static void
-get_values_rg88(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		GLuint count, const GLint x[], const GLint y[], void *values)
-{
-   GLuint *dst = (GLuint *) values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i] = 0xff000000 | *src;
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_R16.
- */
-static void
-get_row_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-	    GLint x, GLint y, void *values)
-{
-   const GLushort *src = rb->GetPointer(ctx, rb, x, y);
-   GLushort *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] = src[i];
-      dst[i * 4 + GCOMP] = 0;
-      dst[i * 4 + BCOMP] = 0;
-      dst[i * 4 + ACOMP] = 0xffff;
-   }
-}
-
-static void
-get_values_r16(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-	       const GLint x[], const GLint y[], void *values)
-{
-   GLushort *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLushort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] = *src;
-      dst[i * 4 + GCOMP] = 0;
-      dst[i * 4 + BCOMP] = 0;
-      dst[i * 4 + ACOMP] = 0xffff;
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_RG1616.
- */
-static void
-get_row_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-	       GLint x, GLint y, void *values)
-{
-   const GLushort *src = rb->GetPointer(ctx, rb, x, y);
-   GLushort *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] = src[i * 2];
-      dst[i * 4 + GCOMP] = src[i * 2 + 1];
-      dst[i * 4 + BCOMP] = 0;
-      dst[i * 4 + ACOMP] = 0xffff;
-   }
-}
-
-static void
-get_values_rg1616(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		  GLuint count, const GLint x[], const GLint y[], void *values)
-{
-   GLushort *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLshort *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] = src[0];
-      dst[i * 4 + GCOMP] = src[1];
-      dst[i * 4 + BCOMP] = 0;
-      dst[i * 4 + ACOMP] = 0xffff;
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_INTENSITY_FLOAT32.
- */
-static void
-get_row_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		  GLuint count, GLint x, GLint y, void *values)
-{
-   const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] =
-      dst[i * 4 + GCOMP] =
-      dst[i * 4 + BCOMP] =
-      dst[i * 4 + ACOMP] = src[i];
-   }
-}
-
-static void
-get_values_i_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		     GLuint count, const GLint x[], const GLint y[],
-		     void *values)
-{
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] =
-      dst[i * 4 + GCOMP] =
-      dst[i * 4 + BCOMP] =
-      dst[i * 4 + ACOMP] = src[0];
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_LUMINANCE_FLOAT32.
- */
-static void
-get_row_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		  GLuint count, GLint x, GLint y, void *values)
-{
-   const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] =
-      dst[i * 4 + GCOMP] =
-      dst[i * 4 + BCOMP] = src[i];
-      dst[i * 4 + ACOMP] = 1.0;
-   }
-}
-
-static void
-get_values_l_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		     GLuint count, const GLint x[], const GLint y[],
-		     void *values)
-{
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] =
-      dst[i * 4 + GCOMP] =
-      dst[i * 4 + BCOMP] = src[0];
-      dst[i * 4 + ACOMP] = 1.0;
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_ALPHA_FLOAT32.
- */
-static void
-get_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		  GLuint count, GLint x, GLint y, void *values)
-{
-   const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] = 0.0;
-      dst[i * 4 + GCOMP] = 0.0;
-      dst[i * 4 + BCOMP] = 0.0;
-      dst[i * 4 + ACOMP] = src[i];
-   }
-}
-
-static void
-get_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		     GLuint count, const GLint x[], const GLint y[],
-		     void *values)
-{
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] = 0.0;
-      dst[i * 4 + GCOMP] = 0.0;
-      dst[i * 4 + BCOMP] = 0.0;
-      dst[i * 4 + ACOMP] = src[0];
-   }
-}
-
-static void
-put_row_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		  GLuint count, GLint x, GLint y,
-		  const void *values, const GLubyte *mask)
-{
-   float *dst = rb->GetPointer(ctx, rb, x, y);
-   const float *src = values;
-   unsigned int i;
-
-   if (mask) {
-      for (i = 0; i < count; i++) {
-         if (mask[i]) {
-	    dst[i] = src[i * 4 + ACOMP];
-         }
-      }
-   }
-   else {
-      for (i = 0; i < count; i++) {
-	 dst[i] = src[i * 4 + ACOMP];
-      }
-   }
-}
-
-static void
-put_values_a_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		     GLuint count, const GLint x[], const GLint y[],
-		     const void *values, const GLubyte *mask)
-{
-   const float *src = values;
-   unsigned int i;
-
-   for (i = 0; i < count; i++) {
-      if (!mask || mask[i]) {
-	 float *dst = rb->GetPointer(ctx, rb, x[i], y[i]);
-
-	 *dst = src[i * 4 + ACOMP];
-      }
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_R_FLOAT32.
- */
-static void
-get_row_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		  GLuint count, GLint x, GLint y, void *values)
-{
-   const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] = src[i];
-      dst[i * 4 + GCOMP] = 0.0;
-      dst[i * 4 + BCOMP] = 0.0;
-      dst[i * 4 + ACOMP] = 1.0;
-   }
-}
-
-static void
-get_values_r_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		     GLuint count, const GLint x[], const GLint y[],
-		     void *values)
-{
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] = src[0];
-      dst[i * 4 + GCOMP] = 0.0;
-      dst[i * 4 + BCOMP] = 0.0;
-      dst[i * 4 + ACOMP] = 1.0;
-   }
-}
-
-/**********************************************************************
- * Functions for MESA_FORMAT_RG_FLOAT32.
- */
-static void
-get_row_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		   GLuint count, GLint x, GLint y, void *values)
-{
-   const GLfloat *src = rb->GetPointer(ctx, rb, x, y);
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      dst[i * 4 + RCOMP] = src[i * 2 + 0];
-      dst[i * 4 + GCOMP] = src[i * 2 + 1];
-      dst[i * 4 + BCOMP] = 0.0;
-      dst[i * 4 + ACOMP] = 1.0;
-   }
-}
-
-static void
-get_values_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
-		      GLuint count, const GLint x[], const GLint y[],
-		      void *values)
-{
-   GLfloat *dst = values;
-   GLuint i;
-
-   for (i = 0; i < count; i++) {
-      const GLfloat *src = rb->GetPointer(ctx, rb, x[i], y[i]);
-      dst[i * 4 + RCOMP] = src[0];
-      dst[i * 4 + GCOMP] = src[1];
-      dst[i * 4 + BCOMP] = 0.0;
-      dst[i * 4 + ACOMP] = 1.0;
-   }
-}
 
 /**
  * This is the default software fallback for gl_renderbuffer's span
@@ -941,137 +52,79 @@ get_values_rg_float32(struct gl_context *ctx, struct gl_renderbuffer *rb,
 void
 _swrast_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
 {
-   rb->GetPointer = get_pointer_generic;
-   rb->GetRow = get_row_generic;
-
    switch (rb->Format) {
    case MESA_FORMAT_RGB888:
       rb->DataType = GL_UNSIGNED_BYTE;
-      rb->GetPointer = get_pointer_ubyte3;
-      rb->GetRow = get_row_ubyte3;
-      rb->GetValues = get_values_ubyte3;
-      rb->PutRow = put_row_ubyte3;
-      rb->PutValues = put_values_ubyte3;
       break;
 
    case MESA_FORMAT_RGBA8888:
    case MESA_FORMAT_RGBA8888_REV:
       rb->DataType = GL_UNSIGNED_BYTE;
-      rb->GetValues = get_values_ubyte4;
-      rb->PutRow = put_row_ubyte4;
-      rb->PutValues = put_values_ubyte4;
       break;
 
    case MESA_FORMAT_R8:
       rb->DataType = GL_UNSIGNED_BYTE;
-      rb->GetValues = get_values_r8;
-      rb->GetRow = get_row_r8;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+
       break;
 
    case MESA_FORMAT_GR88:
       rb->DataType = GL_UNSIGNED_BYTE;
-      rb->GetValues = get_values_rg88;
-      rb->GetRow = get_row_rg88;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
       break;
 
    case MESA_FORMAT_R16:
       rb->DataType = GL_UNSIGNED_SHORT;
-      rb->GetValues = get_values_r16;
-      rb->GetRow = get_row_r16;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+
       break;
 
    case MESA_FORMAT_RG1616:
       rb->DataType = GL_UNSIGNED_SHORT;
-      rb->GetValues = get_values_rg1616;
-      rb->GetRow = get_row_rg1616;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
       break;
 
    case MESA_FORMAT_SIGNED_RGBA_16:
       rb->DataType = GL_SHORT;
-      rb->GetValues = get_values_ushort4;
-      rb->PutRow = put_row_ushort4;
-      rb->PutValues = put_values_ushort4;
       break;
 
    case MESA_FORMAT_S8:
       rb->DataType = GL_UNSIGNED_BYTE;
-      rb->GetValues = get_values_ubyte;
-      rb->PutRow = put_row_ubyte;
-      rb->PutValues = put_values_ubyte;
       break;
 
    case MESA_FORMAT_Z16:
       rb->DataType = GL_UNSIGNED_SHORT;
-      rb->GetValues = get_values_ushort;
-      rb->PutRow = put_row_ushort;
-      rb->PutValues = put_values_ushort;
       break;
 
    case MESA_FORMAT_Z32:
    case MESA_FORMAT_X8_Z24:
    case MESA_FORMAT_Z24_X8:
       rb->DataType = GL_UNSIGNED_INT;
-      rb->GetValues = get_values_uint;
-      rb->PutRow = put_row_uint;
-      rb->PutValues = put_values_uint;
       break;
 
    case MESA_FORMAT_Z24_S8:
    case MESA_FORMAT_S8_Z24:
       rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
-      rb->GetValues = get_values_uint;
-      rb->PutRow = put_row_uint;
-      rb->PutValues = put_values_uint;
       break;
 
    case MESA_FORMAT_RGBA_FLOAT32:
-      rb->GetRow = get_row_generic;
-      rb->GetValues = get_values_generic;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+      rb->DataType = GL_FLOAT;
       break;
 
    case MESA_FORMAT_INTENSITY_FLOAT32:
-      rb->GetRow = get_row_i_float32;
-      rb->GetValues = get_values_i_float32;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+      rb->DataType = GL_FLOAT;
       break;
 
    case MESA_FORMAT_LUMINANCE_FLOAT32:
-      rb->GetRow = get_row_l_float32;
-      rb->GetValues = get_values_l_float32;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+      rb->DataType = GL_FLOAT;
       break;
 
    case MESA_FORMAT_ALPHA_FLOAT32:
-      rb->GetRow = get_row_a_float32;
-      rb->GetValues = get_values_a_float32;
-      rb->PutRow = put_row_a_float32;
-      rb->PutValues = put_values_a_float32;
+      rb->DataType = GL_FLOAT;
       break;
 
    case MESA_FORMAT_RG_FLOAT32:
-      rb->GetRow = get_row_rg_float32;
-      rb->GetValues = get_values_rg_float32;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+      rb->DataType = GL_FLOAT;
       break;
 
    case MESA_FORMAT_R_FLOAT32:
-      rb->GetRow = get_row_r_float32;
-      rb->GetValues = get_values_r_float32;
-      rb->PutRow = put_row_generic;
-      rb->PutValues = put_values_generic;
+      rb->DataType = GL_FLOAT;
       break;
 
    default:
@@ -1089,9 +142,6 @@ _swrast_set_renderbuffer_accessors(struct gl_renderbuffer *rb)
  *
  * This one multi-purpose function can allocate stencil, depth, accum, color
  * or color-index buffers!
- *
- * This function also plugs in the appropriate GetPointer, Get/PutRow and
- * Get/PutValues functions.
  */
 static GLboolean
 soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
@@ -1157,11 +207,6 @@ soft_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    _swrast_set_renderbuffer_accessors(rb);
 
    ASSERT(rb->DataType);
-   ASSERT(rb->GetPointer);
-   ASSERT(rb->GetRow);
-   ASSERT(rb->GetValues);
-   ASSERT(rb->PutRow);
-   ASSERT(rb->PutValues);
 
    /* free old buffer storage */
    if (rb->Data) {
@@ -1250,10 +295,6 @@ _swrast_new_soft_renderbuffer(struct gl_context *ctx, GLuint name)
    struct gl_renderbuffer *rb = _mesa_new_renderbuffer(ctx, name);
    if (rb) {
       rb->AllocStorage = soft_renderbuffer_storage;
-      /* Normally, one would setup the PutRow, GetRow, etc functions here.
-       * But we're doing that in the soft_renderbuffer_storage() function
-       * instead.
-       */
    }
    return rb;
 }
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 5234202..1adf281 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -40,259 +40,6 @@ texture_renderbuffer(struct gl_renderbuffer *rb)
 
 
 
-/**
- * Get row of values from the renderbuffer that wraps a texture image.
- */
-static void
-texture_get_row(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                GLint x, GLint y, void *values)
-{
-   struct texture_renderbuffer *trb = texture_renderbuffer(rb);
-   const GLint z = trb->Zoffset;
-   GLuint i;
-
-   ASSERT(trb->TexImage->Base.Width == rb->Width);
-   ASSERT(trb->TexImage->Base.Height == rb->Height);
-
-   y += trb->Yoffset;
-
-   if (rb->DataType == CHAN_TYPE) {
-      GLchan *rgbaOut = (GLchan *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat rgba[4];
-         trb->Fetch(trb->TexImage, x + i, y, z, rgba);
-         UNCLAMPED_FLOAT_TO_RGBA_CHAN(rgbaOut + 4 * i, rgba);
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_SHORT) {
-      GLushort *zValues = (GLushort *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x + i, y, z, &flt);
-         zValues[i] = (GLushort) (flt * 0xffff);
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT) {
-      GLuint *zValues = (GLuint *) values;
-      /*
-      const GLdouble scale = (GLdouble) 0xffffffff;
-      */
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x + i, y, z, &flt);
-#if 0
-         /* this should work, but doesn't (overflow due to low precision) */
-         zValues[i] = (GLuint) (flt * scale);
-#else
-         /* temporary hack */
-         zValues[i] = ((GLuint) (flt * 0xffffff)) << 8;
-#endif
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_24_8_EXT) {
-      GLuint *zValues = (GLuint *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x + i, y, z, &flt);
-         zValues[i] = ((GLuint) (flt * 0xffffff)) << 8;
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_8_24_REV_MESA) {
-      GLuint *zValues = (GLuint *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x + i, y, z, &flt);
-         zValues[i] = (GLuint) (flt * 0xffffff);
-      }
-   }
-   else {
-      _mesa_problem(ctx, "invalid rb->DataType in texture_get_row");
-   }
-}
-
-
-static void
-texture_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                   const GLint x[], const GLint y[], void *values)
-{
-   struct texture_renderbuffer *trb = texture_renderbuffer(rb);
-   const GLint z = trb->Zoffset;
-   GLuint i;
-
-   if (rb->DataType == CHAN_TYPE) {
-      GLchan *rgbaOut = (GLchan *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat rgba[4];
-         trb->Fetch(trb->TexImage, x[i], y[i] + trb->Yoffset,
-				    z, rgba);
-         UNCLAMPED_FLOAT_TO_RGBA_CHAN(rgbaOut + 4 * i, rgba);
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_SHORT) {
-      GLushort *zValues = (GLushort *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x[i], y[i] + trb->Yoffset,
-				    z, &flt);
-         zValues[i] = (GLushort) (flt * 0xffff);
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT) {
-      GLuint *zValues = (GLuint *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x[i], y[i] + trb->Yoffset,
-				    z, &flt);
-#if 0
-         zValues[i] = (GLuint) (flt * 0xffffffff);
-#else
-         zValues[i] = ((GLuint) (flt * 0xffffff)) << 8;
-#endif
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_24_8_EXT) {
-      GLuint *zValues = (GLuint *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x[i], y[i] + trb->Yoffset,
-				    z, &flt);
-         zValues[i] = ((GLuint) (flt * 0xffffff)) << 8;
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_8_24_REV_MESA) {
-      GLuint *zValues = (GLuint *) values;
-      for (i = 0; i < count; i++) {
-         GLfloat flt;
-         trb->Fetch(trb->TexImage, x[i], y[i] + trb->Yoffset,
-				    z, &flt);
-         zValues[i] = (GLuint) (flt * 0xffffff);
-      }
-   }
-   else {
-      _mesa_problem(ctx, "invalid rb->DataType in texture_get_values");
-   }
-}
-
-
-/**
- * Put row of values into a renderbuffer that wraps a texture image.
- */
-static void
-texture_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                GLint x, GLint y, const void *values, const GLubyte *mask)
-{
-   struct texture_renderbuffer *trb = texture_renderbuffer(rb);
-   const GLint z = trb->Zoffset;
-   GLuint i;
-
-   y += trb->Yoffset;
-
-   if (rb->DataType == CHAN_TYPE) {
-      const GLchan *rgba = (const GLchan *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            trb->Store(trb->TexImage, x + i, y, z, rgba);
-         }
-         rgba += 4;
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_SHORT) {
-      const GLushort *zValues = (const GLushort *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            trb->Store(trb->TexImage, x + i, y, z, zValues + i);
-         }
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT) {
-      const GLuint *zValues = (const GLuint *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            trb->Store(trb->TexImage, x + i, y, z, zValues + i);
-         }
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_24_8_EXT) {
-      const GLuint *zValues = (const GLuint *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            GLfloat flt = (GLfloat) ((zValues[i] >> 8) * (1.0 / 0xffffff));
-            trb->Store(trb->TexImage, x + i, y, z, &flt);
-         }
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_8_24_REV_MESA) {
-      const GLuint *zValues = (const GLuint *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            GLfloat flt = (GLfloat) ((zValues[i] & 0xffffff) * (1.0 / 0xffffff));
-            trb->Store(trb->TexImage, x + i, y, z, &flt);
-         }
-      }
-   }
-   else {
-      _mesa_problem(ctx, "invalid rb->DataType in texture_put_row");
-   }
-}
-
-
-static void
-texture_put_values(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
-                   const GLint x[], const GLint y[], const void *values,
-                   const GLubyte *mask)
-{
-   struct texture_renderbuffer *trb = texture_renderbuffer(rb);
-   const GLint z = trb->Zoffset;
-   GLuint i;
-
-   if (rb->DataType == CHAN_TYPE) {
-      const GLchan *rgba = (const GLchan *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            trb->Store(trb->TexImage, x[i], y[i] + trb->Yoffset, z, rgba);
-         }
-         rgba += 4;
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_SHORT) {
-      const GLushort *zValues = (const GLushort *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            trb->Store(trb->TexImage, x[i], y[i] + trb->Yoffset, z, zValues + i);
-         }
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT) {
-      const GLuint *zValues = (const GLuint *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            trb->Store(trb->TexImage, x[i], y[i] + trb->Yoffset, z, zValues + i);
-         }
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_24_8_EXT) {
-      const GLuint *zValues = (const GLuint *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            GLfloat flt = (GLfloat) ((zValues[i] >> 8) * (1.0 / 0xffffff));
-            trb->Store(trb->TexImage, x[i], y[i] + trb->Yoffset, z, &flt);
-         }
-      }
-   }
-   else if (rb->DataType == GL_UNSIGNED_INT_8_24_REV_MESA) {
-      const GLuint *zValues = (const GLuint *) values;
-      for (i = 0; i < count; i++) {
-         if (!mask || mask[i]) {
-            GLfloat flt = (GLfloat) ((zValues[i] & 0xffffff) * (1.0 / 0xffffff));
-            trb->Store(trb->TexImage, x[i], y[i] + trb->Yoffset, z, &flt);
-         }
-      }
-   }
-   else {
-      _mesa_problem(ctx, "invalid rb->DataType in texture_put_values");
-   }
-}
-
 
 static void
 store_nop(struct swrast_texture_image *texImage,
@@ -335,10 +82,6 @@ wrap_texture(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
    /* plug in our texture_renderbuffer-specific functions */
    trb->Base.Delete = delete_texture_wrapper;
    trb->Base.AllocStorage = NULL; /* illegal! */
-   trb->Base.GetRow = texture_get_row;
-   trb->Base.GetValues = texture_get_values;
-   trb->Base.PutRow = texture_put_row;
-   trb->Base.PutValues = texture_put_values;
 
    /* update attachment point */
    _mesa_reference_renderbuffer(&att->Renderbuffer, &(trb->Base));
commit 1f0cc3faf2b6b615f55f524d0a16a0da98b9549c
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 11:38:46 2012 -0700

    st/mesa: remove gl_renderbuffer::GetPointer stuff
    (cherry picked from commit a4a566a610778e6ab93424a38e372c3dcb7d92d3)

diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index be9c365..aeaf0c5 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -185,23 +185,6 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb)
 
 
 /**
- * gl_renderbuffer::GetPointer()
- */
-static void *
-null_get_pointer(struct gl_context * ctx, struct gl_renderbuffer *rb,
-                 GLint x, GLint y)
-{
-   /* By returning NULL we force all software rendering to go through
-    * the span routines.
-    */
-#if 0
-   assert(0);  /* Should never get called with softpipe */
-#endif
-   return NULL;
-}
-
-
-/**
  * Called via ctx->Driver.NewFramebuffer()
  */
 static struct gl_framebuffer *
@@ -223,7 +206,6 @@ st_new_renderbuffer(struct gl_context *ctx, GLuint name)
       _mesa_init_renderbuffer(&strb->Base, name);
       strb->Base.Delete = st_renderbuffer_delete;
       strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
-      strb->Base.GetPointer = null_get_pointer;
       strb->format = PIPE_FORMAT_NONE;
       return &strb->Base;
    }
@@ -307,7 +289,6 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
    /* st-specific methods */
    strb->Base.Delete = st_renderbuffer_delete;
    strb->Base.AllocStorage = st_renderbuffer_alloc_storage;
-   strb->Base.GetPointer = null_get_pointer;
 
    /* surface is allocated in st_renderbuffer_alloc_storage() */
    strb->surface = NULL;
commit f00ba2191567baed42018e2d62688233b46b8dba
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:55:39 2012 -0700

    swrast: stop using Put/GetRow/Values() in swrast code
    
    All color buffer rendering is now done by accessing mapped renderbuffer
    memory.  We're now able to get rid of all the GetRow/PutRow stuff.
    (cherry picked from commit 0ff817f200ef4cb4a5ab0d90eccfc83d0671fb65)

diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 13fc36c..91541d2 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -558,6 +558,46 @@ swrast_fast_copy_pixels(struct gl_context *ctx,
 
 
 /**
+ * Find/map the renderbuffer that we'll be reading from.
+ * The swrast_render_start() function only maps the drawing buffers,
+ * not the read buffer.
+ */
+static struct gl_renderbuffer *
+map_readbuffer(struct gl_context *ctx, GLenum type)
+{
+   struct gl_framebuffer *fb = ctx->ReadBuffer;
+   struct gl_renderbuffer *rb;
+
+   switch (type) {
+   case GL_COLOR:
+      rb = fb->Attachment[fb->_ColorReadBufferIndex].Renderbuffer;
+      break;
+   case GL_DEPTH:
+   case GL_DEPTH_STENCIL:
+      rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+      break;
+   case GL_STENCIL:
+      rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+      break;
+   default:
+      return NULL;
+   }
+
+   if (!rb || rb->Map) {
+      /* no buffer, or buffer is mapped already, we're done */
+      return NULL;
+   }
+
+   ctx->Driver.MapRenderbuffer(ctx, rb,
+                               0, 0, rb->Width, rb->Height,
+                               GL_MAP_READ_BIT,
+                               &rb->Map, &rb->RowStrideBytes);
+
+   return rb;
+}
+
+
+/**
  * Do software-based glCopyPixels.
  * By time we get here, all parameters will have been error-checked.
  */
@@ -567,6 +607,7 @@ _swrast_CopyPixels( struct gl_context *ctx,
 		    GLint destx, GLint desty, GLenum type )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   struct gl_renderbuffer *rb;
       
    if (!_mesa_check_conditional_render(ctx))
       return; /* don't copy */
@@ -585,6 +626,7 @@ _swrast_CopyPixels( struct gl_context *ctx,
    }
 
    swrast_render_start(ctx);
+   rb = map_readbuffer(ctx, type);
 
    switch (type) {
    case GL_COLOR:
@@ -606,4 +648,9 @@ _swrast_CopyPixels( struct gl_context *ctx,
    }
 
    swrast_render_finish(ctx);
+
+   if (rb) {
+      ctx->Driver.UnmapRenderbuffer(ctx, rb);
+      rb->Map = NULL;
+   }
 }
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index fe199cb..2b67d55 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -33,6 +33,8 @@
 
 #include "main/glheader.h"
 #include "main/colormac.h"
+#include "main/format_pack.h"
+#include "main/format_unpack.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/image.h"
@@ -1024,6 +1026,87 @@ shade_texture_span(struct gl_context *ctx, SWspan *span)
 }
 
 
+/** Put colors at x/y locations into a renderbuffer */
+static void
+put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+           GLuint count, const GLint x[], const GLint y[],
+           const void *values, const GLubyte *mask)
+{
+   GLuint i;
+
+   for (i = 0; i < count; i++) {
+      if (mask[i]) {
+         GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
+
+         if (rb->DataType == GL_UNSIGNED_BYTE) {
+            _mesa_pack_ubyte_rgba_row(rb->Format, 1,
+                                      (const GLubyte (*)[4]) values + i, dst);
+         }
+         else {
+            assert(rb->DataType == GL_FLOAT);
+            _mesa_pack_float_rgba_row(rb->Format, count,
+                                      (const GLfloat (*)[4]) values + i, dst);
+         }
+      }
+   }
+}
+
+
+/** Put row of colors into renderbuffer */
+void
+_swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
+                GLuint count, GLint x, GLint y,
+                const void *values, const GLubyte *mask)
+{
+   GLubyte *dst = _swrast_pixel_address(rb, x, y);
+
+   if (!mask) {
+      if (rb->DataType == GL_UNSIGNED_BYTE) {
+         _mesa_pack_ubyte_rgba_row(rb->Format, count,
+                                   (const GLubyte (*)[4]) values, dst);
+      }
+      else {
+         assert(rb->DataType == GL_FLOAT);
+         _mesa_pack_float_rgba_row(rb->Format, count,
+                                   (const GLfloat (*)[4]) values, dst);
+      }
+   }
+   else {
+      const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+      GLuint i, runLen, runStart;
+      /* We can't pass a 'mask' array to the _mesa_pack_rgba_row() functions
+       * so look for runs where mask=1...
+       */
+      runLen = 0;
+      for (i = 0; i < count; i++) {
+         if (mask[i]) {
+            if (runLen == 0)
+               runStart = i;
+            runLen++;
+         }
+
+         if (!mask[i] || i == count - 1) {
+            /* might be the end of a run of pixels */
+            if (runLen > 0) {
+               if (rb->DataType == GL_UNSIGNED_BYTE) {
+                  _mesa_pack_ubyte_rgba_row(rb->Format, runLen,
+                                     (const GLubyte (*)[4]) values + runStart,
+                                     dst + runStart * bpp);
+               }
+               else {
+                  assert(rb->DataType == GL_FLOAT);
+                  _mesa_pack_float_rgba_row(rb->Format, runLen,
+                                   (const GLfloat (*)[4]) values + runStart,
+                                   dst + runStart * bpp);
+               }
+               runLen = 0;
+            }
+         }
+      }
+   }
+}
+
+
 
 /**
  * Apply all the per-fragment operations to a span.
@@ -1271,17 +1354,15 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
 
             if (span->arrayMask & SPAN_XY) {
                /* array of pixel coords */
-               ASSERT(rb->PutValues);
-               rb->PutValues(ctx, rb, span->end,
-                             span->array->x, span->array->y,
-                             span->array->rgba, span->array->mask);
+               put_values(ctx, rb, span->end,
+                          span->array->x, span->array->y,
+                          span->array->rgba, span->array->mask);
             }
             else {
                /* horizontal run of pixels */
-               ASSERT(rb->PutRow);
-               rb->PutRow(ctx, rb, span->end, span->x, span->y,
-                          span->array->rgba,
-                          span->writeAll ? NULL: span->array->mask);
+               _swrast_put_row(ctx, rb, span->end, span->x, span->y,
+                               span->array->rgba,
+                               span->writeAll ? NULL: span->array->mask);
             }
 
             if (!multiFragOutputs && numBuffers > 1) {
@@ -1325,6 +1406,8 @@ _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else {
       GLint skip, length;
+      GLubyte *src;
+
       if (x < 0) {
          /* left edge clipping */
          skip = -x;
@@ -1353,7 +1436,6 @@ _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
 
       ASSERT(rb);
-      ASSERT(rb->GetRow);
       ASSERT(rb->_BaseFormat == GL_RGBA ||
 	     rb->_BaseFormat == GL_RGB ||
 	     rb->_BaseFormat == GL_RG ||
@@ -1363,70 +1445,69 @@ _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
 	     rb->_BaseFormat == GL_LUMINANCE_ALPHA ||
 	     rb->_BaseFormat == GL_ALPHA);
 
-      if (rb->DataType == dstType) {
-         rb->GetRow(ctx, rb, length, x + skip, y,
-                    (GLubyte *) rgba + skip * RGBA_PIXEL_SIZE(rb->DataType));
+      assert(rb->Map);
+
+      src = _swrast_pixel_address(rb, x + skip, y);
+
+      if (dstType == GL_UNSIGNED_BYTE) {
+         _mesa_unpack_ubyte_rgba_row(rb->Format, length, src,
+                                     (GLubyte (*)[4]) rgba + skip);
+      }
+      else if (dstType == GL_FLOAT) {
+         _mesa_unpack_rgba_row(rb->Format, length, src,
+                               (GLfloat (*)[4]) rgba + skip);
       }
       else {
-         GLuint temp[MAX_WIDTH * 4];
-         rb->GetRow(ctx, rb, length, x + skip, y, temp);
-         _mesa_convert_colors(rb->DataType, temp,
-                   dstType, (GLubyte *) rgba + skip * RGBA_PIXEL_SIZE(dstType),
-                   length, NULL);
+         _mesa_problem(ctx, "unexpected type in _swrast_read_rgba_span()");
       }
    }
 }
 
 
 /**
- * Wrapper for gl_renderbuffer::GetValues() which does clipping to avoid
- * reading values outside the buffer bounds.
- * We can use this for reading any format/type of renderbuffer.
- * \param valueSize is the size in bytes of each value (pixel) put into the
- *                  values array.
+ * Get colors at x/y positions with clipping.
+ * \param type  type of values to return
  */
 static void
 get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
            GLuint count, const GLint x[], const GLint y[],
-           void *values, GLuint valueSize)
+           void *values, GLenum type)
 {
-   GLuint i, inCount = 0, inStart = 0;
+   GLuint i;
 
    for (i = 0; i < count; i++) {
       if (x[i] >= 0 && y[i] >= 0 &&
 	  x[i] < (GLint) rb->Width && y[i] < (GLint) rb->Height) {
          /* inside */
-         if (inCount == 0)
-            inStart = i;
-         inCount++;
-      }
-      else {
-         if (inCount > 0) {
-            /* read [inStart, inStart + inCount) */
-            rb->GetValues(ctx, rb, inCount, x + inStart, y + inStart,
-                          (GLubyte *) values + inStart * valueSize);
-            inCount = 0;
+         const GLubyte *src = _swrast_pixel_address(rb, x[i], y[i]);
+
+         if (type == GL_UNSIGNED_BYTE) {
+            _mesa_unpack_ubyte_rgba_row(rb->Format, 1, src,
+                                        (GLubyte (*)[4]) values + i);
+         }
+         else if (type == GL_FLOAT) {
+            _mesa_unpack_rgba_row(rb->Format, 1, src,
+                                  (GLfloat (*)[4]) values + i);
+         }
+         else {
+            _mesa_problem(ctx, "unexpected type in get_values()");
          }
       }
    }
-   if (inCount > 0) {
-      /* read last values */
-      rb->GetValues(ctx, rb, inCount, x + inStart, y + inStart,
-                    (GLubyte *) values + inStart * valueSize);
-   }
 }
 
 
 /**
- * Wrapper for gl_renderbuffer::GetRow() which does clipping.
- * \param valueSize  size of each value (pixel) in bytes
+ * Get row of colors with clipping.
+ * \param type  type of values to return
  */
 static void
 get_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
         GLuint count, GLint x, GLint y,
-        GLvoid *values, GLuint valueSize)
+        GLvoid *values, GLenum type)
 {
    GLint skip = 0;
+   GLubyte *src;
 
    if (y < 0 || y >= (GLint) rb->Height)
       return; /* above or below */
@@ -1447,7 +1528,19 @@ get_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
       count -= skip;
    }
 
-   rb->GetRow(ctx, rb, count, x, y, (GLubyte *) values + skip * valueSize);
+   src = _swrast_pixel_address(rb, x, y);
+
+   if (type == GL_UNSIGNED_BYTE) {
+      _mesa_unpack_ubyte_rgba_row(rb->Format, count, src,
+                                  (GLubyte (*)[4]) values + skip);
+   }
+   else if (type == GL_FLOAT) {
+      _mesa_unpack_rgba_row(rb->Format, count, src,
+                            (GLfloat (*)[4]) values + skip);
+   }
+   else {
+      _mesa_problem(ctx, "unexpected type in get_row()");
+   }
 }
 
 
@@ -1460,7 +1553,6 @@ void *
 _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
                       SWspan *span)
 {
-   const GLuint pixelSize = RGBA_PIXEL_SIZE(span->array->ChanType);
    void *rbPixels;
 
    /* Point rbPixels to a temporary space */
@@ -1469,11 +1561,11 @@ _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
    /* Get destination values from renderbuffer */
    if (span->arrayMask & SPAN_XY) {
       get_values(ctx, rb, span->end, span->array->x, span->array->y,
-                 rbPixels, pixelSize);
+                 rbPixels, span->array->ChanType);
    }
    else {
       get_row(ctx, rb, span->end, span->x, span->y,
-              rbPixels, pixelSize);
+              rbPixels, span->array->ChanType);
    }
 
    return rbPixels;
diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index e39ae85..4d6eb7e 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -203,6 +203,11 @@ extern void
 _swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
                        GLuint n, GLint x, GLint y, GLvoid *rgba);
 
+extern void
+_swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
+                GLuint count, GLint x, GLint y,
+                const void *values, const GLubyte *mask);
+
 extern void *
 _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
                       SWspan *span);
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 51cd330..fe44663 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -342,14 +342,11 @@ map_attachment(struct gl_context *ctx,
    }
    else if (rb) {
       /* Map ordinary renderbuffer */
-      /* XXX don't map color buffers yet */
-      if (buffer == BUFFER_DEPTH || buffer == BUFFER_STENCIL) {
          ctx->Driver.MapRenderbuffer(ctx, rb,
                                      0, 0, rb->Width, rb->Height,
                                      GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
                                      &rb->Map, &rb->RowStrideBytes);
          assert(rb->Map);
-      }
    }
 }
  
@@ -373,10 +370,7 @@ unmap_attachment(struct gl_context *ctx,
     }
    else if (rb) {
       /* unmap ordinary renderbuffer */
-      /* XXX don't map color buffers yet */
-      if (buffer == BUFFER_DEPTH || buffer == BUFFER_STENCIL) {
-         ctx->Driver.UnmapRenderbuffer(ctx, rb);
-      }
+      ctx->Driver.UnmapRenderbuffer(ctx, rb);
    }
 
    rb->Map = NULL;
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 4d815c5..2b54cd1 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -157,7 +157,7 @@ _swrast_culltriangle( struct gl_context *ctx,
       span.intTex[0] += span.intTexStep[0];				\
       span.intTex[1] += span.intTexStep[1];				\
    }									\
-   rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, NULL);
+   _swrast_put_row(ctx, rb, span.end, span.x, span.y, rgba, NULL);
 
 #include "s_tritemp.h"
 
@@ -223,7 +223,7 @@ _swrast_culltriangle( struct gl_context *ctx,
       span.intTex[1] += span.intTexStep[1];				\
       span.z += span.zStep;						\
    }									\
-   rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, span.array->mask);
+   _swrast_put_row(ctx, rb, span.end, span.x, span.y, rgba, span.array->mask);
 
 #include "s_tritemp.h"
 
commit c8562a6ed39287582c4a484e19c4efd62dd5df2f
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:55:32 2012 -0700

    swrast: use gl_renderbuffer::StrideInBytes in depth/stencil code
    (cherry picked from commit b766d4bb43b2c8271413c1efafe3590fa75efc3c)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 440c43f..0788644 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -217,7 +217,7 @@ get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
-      const GLint rowStride = rb->RowStride * 4;
+      const GLint rowStride = rb->RowStrideBytes;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             zbuffer[i] = *((GLuint *) (map + y[i] * rowStride + x[i] * 4));
@@ -226,7 +226,7 @@ get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else {
       const GLint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLint rowStride = rb->RowStride * bpp;
+      const GLint rowStride = rb->RowStrideBytes;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             const GLubyte *src = map + y[i] * rowStride+ x[i] * bpp;
@@ -251,7 +251,7 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
-      const GLuint rowStride = rb->RowStride * 4;
+      const GLuint rowStride = rb->RowStrideBytes;
       for (i = 0; i < count; i++) {
          if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             GLuint *dst = (GLuint *) (map + y[i] * rowStride + x[i] * 4);
@@ -262,7 +262,7 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    else {
       gl_pack_uint_z_func packZ = _mesa_get_pack_uint_z_func(rb->Format);
       const GLint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLint rowStride = rb->RowStride * bpp;
+      const GLint rowStride = rb->RowStrideBytes;
       for (i = 0; i < count; i++) {
          if (mask[i] && x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             void *dst = map + y[i] * rowStride + x[i] * bpp;
diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 98af928..005423e 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -297,7 +297,7 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_S8) {
-      const GLint rowStride = rb->RowStride;
+      const GLint rowStride = rb->RowStrideBytes;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             stencil[i] = *(map + y[i] * rowStride + x[i]);
@@ -306,7 +306,7 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else {
       const GLint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLint rowStride = rb->RowStride * bpp;
+      const GLint rowStride = rb->RowStrideBytes;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
commit 48173180b55241d0536999a90a3c1a000ce35500
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:55:25 2012 -0700

    mesa: use gl_renderbuffer::Map for all depth/stencil accesses
    
    Instead of using the obsolete gl_renderbuffer::Data field.
    Color buffer are still accessed through GetRow/PutRow().
    (cherry picked from commit 7d1ddec92168e9b6ead0da80b18364a75f9a85e6)

diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index d4d3bf9..506c295 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -60,8 +60,8 @@ intel_set_span_functions(struct intel_context *intel,
    int minx = 0, miny = 0;						\
    int maxx = rb->Width;						\
    int maxy = rb->Height;						\
-   int pitch = rb->RowStride * irb->mt->region->cpp;			\
-   void *buf = rb->Data;						\
+   int pitch = rb->RowStrideBytes;                                      \
+   void *buf = rb->Map;                                                 \
    GLuint p;								\
    (void) p;
 
@@ -189,7 +189,7 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
    if (!irb)
       return;
 
-   if (rb->Data) {
+   if (rb->Map) {
       /* Renderbuffer is already mapped. This usually happens when a single
        * buffer is attached to the framebuffer's depth and stencil attachment
        * points.
@@ -200,8 +200,9 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
    ctx->Driver.MapRenderbuffer(ctx, rb, 0, 0, rb->Width, rb->Height,
 			       GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
 			       &map, &stride);
-   rb->Data = map;
+   rb->Map = map;
    rb->RowStride = stride / _mesa_get_format_bytes(rb->Format);
+   rb->RowStrideBytes = stride;
 
    intel_set_span_functions(intel, rb);
 }
@@ -216,7 +217,7 @@ intel_renderbuffer_unmap(struct intel_context *intel,
    if (!irb)
       return;
 
-   if (!rb->Data) {
+   if (!rb->Map) {
       /* Renderbuffer is already unmapped. This usually happens when a single
        * buffer is attached to the framebuffer's depth and stencil attachment
        * points.
@@ -228,8 +229,9 @@ intel_renderbuffer_unmap(struct intel_context *intel,
 
    rb->GetRow = NULL;
    rb->PutRow = NULL;
-   rb->Data = NULL;
+   rb->Map = NULL;
    rb->RowStride = 0;
+   rb->RowStrideBytes = 0;
 }
 
 static void
diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c
index e3bdc36..569aca9 100644
--- a/src/mesa/drivers/dri/radeon/radeon_span.c
+++ b/src/mesa/drivers/dri/radeon/radeon_span.c
@@ -74,8 +74,8 @@ static void radeonSetSpanFunctions(struct radeon_renderbuffer *rrb);
    int minx = 0, miny = 0;						\
    int maxx = rb->Width;						\
    int maxy = rb->Height;						\
-   void *buf = rb->Data;						\
-   int pitch = rb->RowStride * rrb->cpp;				\
+   void *buf = rb->Map;						\
+   int pitch = rb->RowStrideBytes;				\
    GLuint p;						\
    (void)p;
 
@@ -178,8 +178,9 @@ radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb)
 				    GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
 				    &map, &stride);
 
-	rb->Data = map;
+	rb->Map = map;
 	rb->RowStride = stride / _mesa_get_format_bytes(rb->Format);
+	rb->RowStrideBytes = stride;
 
 	radeonSetSpanFunctions(rrb);
 }
@@ -195,8 +196,9 @@ radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb)
 
 	rb->GetRow = NULL;
 	rb->PutRow = NULL;
-	rb->Data = NULL;
+	rb->Map = NULL;
 	rb->RowStride = 0;
+	rb->RowStrideBytes = 0;
 }
 
 static void
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 36ab86a..7f1e4c7 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -429,7 +429,7 @@ static inline GLubyte *
 _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
 {
    const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStride * bpp;
+   const GLint rowStride = rb->RowStrideBytes;
    assert(x >= 0);
    assert(y >= 0);
    /* NOTE: using <= only because of s_tritemp.h which gets a pixel
@@ -437,8 +437,8 @@ _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
     */
    assert(x <= (GLint) rb->Width);
    assert(y <= (GLint) rb->Height);
-   assert(rb->Data);
-   return (GLubyte *) rb->Data + y * rowStride + x * bpp;
+   assert(rb->Map);
+   return (GLubyte *) rb->Map + y * rowStride + x * bpp;
 }
 
 
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index b131d5a..51cd330 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -315,57 +315,130 @@ _swrast_unmap_textures(struct gl_context *ctx)
 }
 
 
-/**
- * Map or unmap any textures that we may be rendering to as renderbuffers.
- */
 static void
-map_unmap_renderbuffers(struct gl_context *ctx,
-                        struct gl_framebuffer *fb,
-                        GLboolean map)
+map_attachment(struct gl_context *ctx,
+                 struct gl_framebuffer *fb,
+                 gl_buffer_index buffer)
 {
-   GLuint i;
-
-   for (i = 0; i < Elements(fb->Attachment); i++) {
-      struct gl_texture_object *texObj = fb->Attachment[i].Texture;
-      if (texObj) {
-         const GLuint level = fb->Attachment[i].TextureLevel;
-         const GLuint face = fb->Attachment[i].CubeMapFace;
-         struct gl_texture_image *texImage = texObj->Image[face][level];
-         if (texImage) {
-            struct swrast_texture_image *swImage
-               = swrast_texture_image(texImage);
-
-            if (map) {
-               /* XXX we'll eventually call _swrast_map_teximage() here */
-               swImage->Map = swImage->Buffer;
-            }
-            else {
-               /* XXX we'll eventually call _swrast_unmap_teximage() here */
-               swImage->Map = NULL;
-            }
+   struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
+   struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
+
+   if (texObj) {
+      const GLuint level = fb->Attachment[buffer].TextureLevel;
+      const GLuint face = fb->Attachment[buffer].CubeMapFace;
+      struct gl_texture_image *texImage = texObj->Image[face][level];
+      if (texImage) {
+         struct swrast_texture_image *swImage
+            = swrast_texture_image(texImage);
+
+         /* XXX we'll eventually call _swrast_map_teximage() here */
+         swImage->Map = swImage->Buffer;
+         if (rb) {
+            rb->Map = swImage->Buffer;
+            rb->RowStrideBytes = swImage->RowStride *
+               _mesa_get_format_bytes(swImage->Base.TexFormat);
          }
       }
    }
+   else if (rb) {
+      /* Map ordinary renderbuffer */
+      /* XXX don't map color buffers yet */
+      if (buffer == BUFFER_DEPTH || buffer == BUFFER_STENCIL) {
+         ctx->Driver.MapRenderbuffer(ctx, rb,
+                                     0, 0, rb->Width, rb->Height,
+                                     GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+                                     &rb->Map, &rb->RowStrideBytes);
+         assert(rb->Map);
+      }
+   }
 }
+ 
 
+static void
+unmap_attachment(struct gl_context *ctx,
+                   struct gl_framebuffer *fb,
+                   gl_buffer_index buffer)
+{
+   struct gl_texture_object *texObj = fb->Attachment[buffer].Texture;
+   struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer;
+
+   if (texObj) {
+      const GLuint level = fb->Attachment[buffer].TextureLevel;
+      const GLuint face = fb->Attachment[buffer].CubeMapFace;
+      struct gl_texture_image *texImage = texObj->Image[face][level];
+      if (texImage) {
+
+         /* XXX we'll eventually call _swrast_unmap_teximage() here */
+       }
+    }
+   else if (rb) {
+      /* unmap ordinary renderbuffer */
+      /* XXX don't map color buffers yet */
+      if (buffer == BUFFER_DEPTH || buffer == BUFFER_STENCIL) {
+         ctx->Driver.UnmapRenderbuffer(ctx, rb);
+      }
+   }
 
+   rb->Map = NULL;
+   rb->RowStrideBytes = 0;
+}
+ 
+ 
+/**
+ * Map the renderbuffers we'll use for tri/line/point rendering.
+ */
 void
 _swrast_map_renderbuffers(struct gl_context *ctx)
 {
-   map_unmap_renderbuffers(ctx, ctx->DrawBuffer, GL_TRUE);
-   if (ctx->ReadBuffer != ctx->DrawBuffer)
-      map_unmap_renderbuffers(ctx, ctx->ReadBuffer, GL_TRUE);
-}
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+   struct gl_renderbuffer *depthRb, *stencilRb;
+   GLuint buf;
+
+   depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+   if (depthRb) {
+      /* map depth buffer */
+      map_attachment(ctx, fb, BUFFER_DEPTH);
+   }
 
+   stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+   if (stencilRb && stencilRb != depthRb) {
+      /* map stencil buffer */
+      map_attachment(ctx, fb, BUFFER_STENCIL);
+   }
 
+   for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
+      map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
+   }
+}
+ 
+ 
+/**
+ * Unmap renderbuffers after rendering.
+ */
 void
 _swrast_unmap_renderbuffers(struct gl_context *ctx)
 {
-   map_unmap_renderbuffers(ctx, ctx->DrawBuffer, GL_FALSE);
-   if (ctx->ReadBuffer != ctx->DrawBuffer)
-      map_unmap_renderbuffers(ctx, ctx->ReadBuffer, GL_FALSE);
-}
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+   struct gl_renderbuffer *depthRb, *stencilRb;
+   GLuint buf;
+
+   depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+   if (depthRb) {
+      /* map depth buffer */
+      unmap_attachment(ctx, fb, BUFFER_DEPTH);
+   }
 
+   stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer;
+   if (stencilRb && stencilRb != depthRb) {
+      /* map stencil buffer */
+      unmap_attachment(ctx, fb, BUFFER_STENCIL);
+   }
+
+   for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
+      unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
+   }
+}
+ 
 
 
 /**
commit 349d5a8a383f70464baf7a838c56accf0189527f
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:55:20 2012 -0700

    intel: make intel_renderbuffer_map/unmap() static
    (cherry picked from commit 14da67d9b9b9e30740ef1687c3952a0b5e8b0a54)

diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index 43b8151..d4d3bf9 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -178,7 +178,7 @@ intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y)
    return u;
 }
 
-void
+static void
 intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
 {
    struct gl_context *ctx = &intel->ctx;
@@ -206,7 +206,7 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
    intel_set_span_functions(intel, rb);
 }
 
-void
+static void
 intel_renderbuffer_unmap(struct intel_context *intel,
 			 struct gl_renderbuffer *rb)
 {
diff --git a/src/mesa/drivers/dri/intel/intel_span.h b/src/mesa/drivers/dri/intel/intel_span.h
index d546ecd..6640e15 100644
--- a/src/mesa/drivers/dri/intel/intel_span.h
+++ b/src/mesa/drivers/dri/intel/intel_span.h
@@ -35,10 +35,7 @@ extern void intelInitSpanFuncs(struct gl_context * ctx);
 
 extern void intelSpanRenderFinish(struct gl_context * ctx);
 extern void intelSpanRenderStart(struct gl_context * ctx);
-void intel_renderbuffer_map(struct intel_context *intel,
-			    struct gl_renderbuffer *rb);
-void intel_renderbuffer_unmap(struct intel_context *intel,
-			      struct gl_renderbuffer *rb);
+
 void intel_map_vertex_shader_textures(struct gl_context *ctx);
 void intel_unmap_vertex_shader_textures(struct gl_context *ctx);
 bool intel_span_supports_format(gl_format format);
commit fee5f10241e8efd3f875b8721aa9515a33dce299
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:55:15 2012 -0700

    mesa: add new gl_renderbuffer fields
    
    These are temporary, actually, but they'll make follow-on work easier to
    implement in a step-by-step manner.  Eventually the Map and RowStrideBytes
    fields will go into a new swrast_renderbuffer type, but adding that type
    now would involve touching a _lot_ of code that'll eventually be removed.
    
    The fields marked as obsolete will go away completely at some point.
    (cherry picked from commit 827c1d66f671e50d9d96277b1fd3a59309626f66)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 95450f9..99b6a6f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2528,7 +2528,6 @@ struct gl_renderbuffer
    GLuint Name;
    GLint RefCount;
    GLuint Width, Height;
-   GLint RowStride;       /**< Padded width in units of pixels */
    GLboolean Purgeable;   /**< Is the buffer purgeable under memory pressure? */
 
    GLboolean AttachedAnytime; /**< TRUE if it was attached to a framebuffer */
@@ -2540,9 +2539,15 @@ struct gl_renderbuffer
                                GL_STENCIL_INDEX. */
    gl_format Format;      /**< The actual renderbuffer memory format */
 
+   /* XXX the following 3 fields are obsolete and wil go away */
+   GLint RowStride;       /**< Padded width in units of pixels */
    GLenum DataType;      /**< Type of values passed to the Get/Put functions */
    GLvoid *Data;        /**< This may not be used by some kinds of RBs */
 
+   /** The following fields are only valid while the buffer is mapped */
+   GLubyte *Map;
+   GLint RowStrideBytes;
+
    /* Used to wrap one renderbuffer around another: */
    struct gl_renderbuffer *Wrapped;
 
commit 83eb5e43722cf0a6b3366ddf6a7ff3f8a44d4c23
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:55:10 2012 -0700

    swrast: flush pending rendering before unmapping buffers
    (cherry picked from commit fc9f74839d50ab5480ae657524cf2ddebf55d451)

diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 06824ea..817f137 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -872,10 +872,11 @@ void
 _swrast_render_finish( struct gl_context *ctx )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   if (swrast->Driver.SpanRenderFinish)
-      swrast->Driver.SpanRenderFinish( ctx );
 
    _swrast_flush(ctx);
+
+   if (swrast->Driver.SpanRenderFinish)
+      swrast->Driver.SpanRenderFinish( ctx );
 }
 
 
commit 5f6676b0ee6f847c1473670f665fcea03ff8f224
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:53 2012 -0700

    swrast: new assertions in _swrast_pixel_address()
    (cherry picked from commit 33257803d9083643ea9709c127933d5a2c4f1960)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 3391600..36ab86a 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -430,6 +430,14 @@ _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
 {
    const GLint bpp = _mesa_get_format_bytes(rb->Format);
    const GLint rowStride = rb->RowStride * bpp;
+   assert(x >= 0);
+   assert(y >= 0);
+   /* NOTE: using <= only because of s_tritemp.h which gets a pixel
+    * address but doesn't necessarily access it.
+    */
+   assert(x <= (GLint) rb->Width);
+   assert(y <= (GLint) rb->Height);
+   assert(rb->Data);
    return (GLubyte *) rb->Data + y * rowStride + x * bpp;
 }
 
commit 7c6f54811c7c1843f862ab4986431527f56a6db1
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:47 2012 -0700

    swrast: use _swrast_pixel_address() in more places
    (cherry picked from commit e34a54ff451a37a6e6eab529c44330dd6a8b218b)

diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 42724c7..440c43f 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -213,7 +213,7 @@ get_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
                GLuint zbuffer[])
 {
    const GLint w = rb->Width, h = rb->Height;
-   const GLubyte *map = (const GLubyte *) rb->Data;
+   const GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
@@ -247,7 +247,7 @@ put_z32_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
                const GLuint zvalues[], const GLubyte mask[])
 {
    const GLint w = rb->Width, h = rb->Height;
-   GLubyte *map = (GLubyte *) rb->Data;
+   GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_Z32) {
@@ -283,7 +283,7 @@ _swrast_depth_test_span(struct gl_context *ctx, SWspan *span)
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
    const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   void *zStart = _swrast_pixel_address(rb, span->x, span->y);
+   void *zStart;
    const GLuint count = span->end;
    const GLuint *fragZ = span->array->z;
    GLubyte *mask = span->array->mask;
@@ -293,6 +293,11 @@ _swrast_depth_test_span(struct gl_context *ctx, SWspan *span)
    GLuint zBits = _mesa_get_format_bits(rb->Format, GL_DEPTH_BITS);
    GLboolean ztest16 = GL_FALSE;
 
+   if (span->arrayMask & SPAN_XY)
+      zStart = NULL;
+   else
+      zStart = _swrast_pixel_address(rb, span->x, span->y);
+
    if (rb->Format == MESA_FORMAT_Z16 && !(span->arrayMask & SPAN_XY)) {
       /* directly read/write row of 16-bit Z values */
       zBufferVals = zStart;
@@ -405,9 +410,7 @@ _swrast_depth_bounds_test( struct gl_context *ctx, SWspan *span )
 {
    struct gl_framebuffer *fb = ctx->DrawBuffer;
    struct gl_renderbuffer *rb = fb->Attachment[BUFFER_DEPTH].Renderbuffer;
-   const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStride * bpp;
-   GLubyte *zStart = (GLubyte*) rb->Data + span->y * rowStride + span->x * bpp;
+   GLubyte *zStart;
    GLuint zMin = (GLuint) (ctx->Depth.BoundsMin * fb->_DepthMaxF + 0.5F);
    GLuint zMax = (GLuint) (ctx->Depth.BoundsMax * fb->_DepthMaxF + 0.5F);
    GLubyte *mask = span->array->mask;
@@ -417,6 +420,11 @@ _swrast_depth_bounds_test( struct gl_context *ctx, SWspan *span )
    GLuint zBufferTemp[MAX_WIDTH];
    const GLuint *zBufferVals;
 
+   if (span->arrayMask & SPAN_XY)
+      zStart = NULL;
+   else
+      zStart = _swrast_pixel_address(rb, span->x, span->y);
+
    if (rb->Format == MESA_FORMAT_Z32 && !(span->arrayMask & SPAN_XY)) {
       /* directly access 32-bit values in the depth buffer */
       zBufferVals = (const GLuint *) zStart;
diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index fb95ef1..98af928 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -293,7 +293,7 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
               GLubyte stencil[])
 {
    const GLint w = rb->Width, h = rb->Height;
-   const GLubyte *map = (const GLubyte *) rb->Data;
+   const GLubyte *map = _swrast_pixel_address(rb, 0, 0);
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_S8) {
commit a42dcf1614cae7a1f896eb934c99c78dfd36c1d8
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:41 2012 -0700

    swrast: s/Data/Map/ in swrast_texture_image
    
    To indicate that it points to mapped texture memory.
    (cherry picked from commit bd3c10c0f0c60ab3421c2da2eab814edc2296cb0)

diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
index 63938dd..b96f2a4 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
@@ -148,7 +148,7 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
 
       DBG("%s \n", __FUNCTION__);
 
-      intel_image->base.Data = intel_region_map(intel, mt->region, mode);
+      intel_image->base.Map = intel_region_map(intel, mt->region, mode);
    } else {
       assert(intel_image->base.Base.Depth == 1);
       intel_miptree_get_image_offset(mt, level, face, 0, &x, &y);
@@ -156,7 +156,7 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
       DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
 	  __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
 
-      intel_image->base.Data = intel_region_map(intel, mt->region, mode) +
+      intel_image->base.Map = intel_region_map(intel, mt->region, mode) +
 	 (x + y * mt->region->pitch) * mt->cpp;
    }
 
@@ -169,7 +169,7 @@ intel_tex_unmap_image_for_swrast(struct intel_context *intel,
 {
    if (intel_image && intel_image->mt) {
       intel_region_unmap(intel, intel_image->mt->region);
-      intel_image->base.Data = NULL;
+      intel_image->base.Map = NULL;
    }
 }
 
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index b90ab9a..b364f78 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -103,7 +103,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
 			nti->transfer.x = x;
 			nti->transfer.y = y;
 
-			nti->base.Data = nouveau_get_scratch(ctx, st->pitch * h,
+			nti->base.Map = nouveau_get_scratch(ctx, st->pitch * h,
 						       &st->bo, &st->offset);
 
 		} else {
@@ -119,7 +119,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
 				assert(!ret);
 			}
 
-			nti->base.Data = s->bo->map + y * s->pitch + x * s->cpp;
+			nti->base.Map = s->bo->map + y * s->pitch + x * s->cpp;
 		}
 	}
 }
@@ -141,7 +141,7 @@ nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
 		nouveau_bo_unmap(s->bo);
 	}
 
-	nti->base.Data = NULL;
+	nti->base.Map = NULL;
 }
 
 
@@ -197,7 +197,7 @@ nouveau_map_texture_image(struct gl_context *ctx,
 			*stride = s->pitch;
 		}
 	} else {
-		*map = nti->base.Data + y * s->pitch + x * s->cpp;
+		*map = nti->base.Map + y * s->pitch + x * s->cpp;
 		*stride = s->pitch;
 	}
 }
@@ -220,7 +220,7 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
 		nouveau_bo_unmap(s->bo);
 	}
 
-	nti->base.Data = NULL;
+	nti->base.Map = NULL;
 }
 
 static gl_format
@@ -481,7 +481,7 @@ nouveau_teximage(struct gl_context *ctx, GLint dims,
 		ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
 				     ti->TexFormat,
 				     s->pitch,
-                                     &nti->base.Data,
+                                     &nti->base.Map,
 				     width, height, depth,
 				     format, type, pixels, packing);
 		assert(ret);
@@ -565,7 +565,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims,
 
 		ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat,
                                      s->pitch,
-				     &nti->base.Data,
+				     &nti->base.Map,
                                      width, height, depth,
 				     format, type, pixels, packing);
 		assert(ret);
diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
index 23af9ac..ca5dadc 100644
--- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
+++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
@@ -440,7 +440,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
 		radeon_bo_unmap(image->mt->bo);
 
 		radeon_miptree_unreference(&image->mt);
-	} else if (image->base.Data) {
+	} else if (image->base.Map) {
 		/* This condition should be removed, it's here to workaround
 		 * a segfault when mapping textures during software fallbacks.
 		 */
@@ -456,11 +456,11 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
 			rows = (rows + blockHeight - 1) / blockHeight;
 		}
 
-		copy_rows(dest, dstlvl->rowstride, image->base.Data, srcrowstride,
+		copy_rows(dest, dstlvl->rowstride, image->base.Map, srcrowstride,
 				  rows, srcrowstride);
 
-		_mesa_align_free(image->base.Data);
-		image->base.Data = 0;
+		_mesa_align_free(image->base.Map);
+		image->base.Map = 0;
 	}
 
 	radeon_bo_unmap(mt->bo);
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index 78fb1b5..ccb9956 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -170,7 +170,7 @@ static void teximage_set_map_data(radeon_texture_image *image)
 
 	lvl = &image->mt->levels[image->base.Base.Level];
 
-	image->base.Data = image->mt->bo->ptr + lvl->faces[image->base.Base.Face].offset;
+	image->base.Map = image->mt->bo->ptr + lvl->faces[image->base.Base.Face].offset;
 	image->base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat);
 }
 
@@ -185,7 +185,7 @@ void radeon_teximage_map(radeon_texture_image *image, GLboolean write_enable)
 			__func__, image,
 			write_enable ? "true": "false");
 	if (image->mt) {
-		assert(!image->base.Data);
+		assert(!image->base.Map);
 
 		radeon_bo_map(image->mt->bo, write_enable);
 		teximage_set_map_data(image);
@@ -199,9 +199,9 @@ void radeon_teximage_unmap(radeon_texture_image *image)
 			"%s(img %p)\n",
 			__func__, image);
 	if (image->mt) {
-		assert(image->base.Data);
+		assert(image->base.Map);
 
-		image->base.Data = 0;
+		image->base.Map = 0;
 		radeon_bo_unmap(image->mt->bo);
 	}
 }
@@ -788,7 +788,7 @@ radeon_swrast_map_image(radeonContextPtr rmesa,
 
 	radeon_bo_map(mt->bo, 1);
 	
-	image->base.Data = mt->bo->ptr + lvl->faces[face].offset;
+	image->base.Map = mt->bo->ptr + lvl->faces[face].offset;
 	if (mt->target == GL_TEXTURE_3D) {
 		int i;
 
@@ -803,7 +803,7 @@ radeon_swrast_unmap_image(radeonContextPtr rmesa,
 			  radeon_texture_image *image)
 {
 	if (image && image->mt) {
-		image->base.Data = NULL;
+		image->base.Map = NULL;
 		radeon_bo_unmap(image->mt->bo);
 	}
 }
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 4f6d016..90a9638 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -94,7 +94,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     _mesa_init_teximage_fields(&dri_ctx->Base, texImage,
 			       w, h, 1, 0, internalFormat, texFormat);
 
-    sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)swImage->Data,
+    sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)swImage->Buffer,
 				   dPriv->loaderPrivate);
 
     _mesa_unlock_texture(&dri_ctx->Base, texObj);
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index 5045aef..44590ea 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -478,7 +478,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
 
    /* setup dummy texture image info */
    memset(&texImage, 0, sizeof(texImage));
-   texImage.Data = (void *) src;
+   texImage.Map = (void *) src;
    texImage.RowStride = srcRowStride;
 
    switch (format) {
diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
index 4d3b857..5b331a9 100644
--- a/src/mesa/main/texcompress_etc.c
+++ b/src/mesa/main/texcompress_etc.c
@@ -58,7 +58,7 @@ _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
    GLubyte dst[3];
    const GLubyte *src;
 
-   src = (const GLubyte *) texImage->Data +
+   src = (const GLubyte *) texImage->Map +
       (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
 
    etc1_parse_block(&block, src);
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index 2480ffb..eafa187 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -163,7 +163,7 @@ _mesa_fetch_texel_2d_f_rgba_fxt1( const struct swrast_texture_image *texImage,
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
    (void) k;
-   fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
+   fxt1_decode_1(texImage->Map, texImage->RowStride, i, j, rgba);
    texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
    texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
    texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
@@ -178,7 +178,7 @@ _mesa_fetch_texel_2d_f_rgb_fxt1( const struct swrast_texture_image *texImage,
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
    (void) k;
-   fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
+   fxt1_decode_1(texImage->Map, texImage->RowStride, i, j, rgba);
    texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
    texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
    texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c
index b8e334b..f707a09 100644
--- a/src/mesa/main/texcompress_rgtc.c
+++ b/src/mesa/main/texcompress_rgtc.c
@@ -296,7 +296,7 @@ _mesa_fetch_texel_2d_f_red_rgtc1(const struct swrast_texture_image *texImage,
 				 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red;
-   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Map,
 		       i, j, &red, 1);
    texel[RCOMP] = UBYTE_TO_FLOAT(red);
    texel[GCOMP] = 0.0;
@@ -309,7 +309,7 @@ _mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct swrast_texture_image *texIm
 					GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red;
-   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Map),
 		       i, j, &red, 1);
    texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
    texel[GCOMP] = 0.0;
@@ -322,9 +322,9 @@ _mesa_fetch_texel_2d_f_rg_rgtc2(const struct swrast_texture_image *texImage,
 				 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red, green;
-   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Map,
 		     i, j, &red, 2);
-   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Map + 8,
 		     i, j, &green, 2);
    texel[RCOMP] = UBYTE_TO_FLOAT(red);
    texel[GCOMP] = UBYTE_TO_FLOAT(green);
@@ -337,9 +337,9 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct swrast_texture_image *texIma
 				       GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red, green;
-   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Map),
 		     i, j, &red, 2);
-   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Map) + 8,
 		     i, j, &green, 2);
    texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
    texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
@@ -352,7 +352,7 @@ _mesa_fetch_texel_2d_f_l_latc1(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red;
-   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Map,
                        i, j, &red, 1);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -365,7 +365,7 @@ _mesa_fetch_texel_2d_f_signed_l_latc1(const struct swrast_texture_image *texImag
                                         GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red;
-   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Map),
                        i, j, &red, 1);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -378,9 +378,9 @@ _mesa_fetch_texel_2d_f_la_latc2(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red, green;
-   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Map,
                      i, j, &red, 2);
-   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Map + 8,
                      i, j, &green, 2);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -393,9 +393,9 @@ _mesa_fetch_texel_2d_f_signed_la_latc2(const struct swrast_texture_image *texIma
                                        GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red, green;
-   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Map),
                      i, j, &red, 2);
-   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Map) + 8,
                      i, j, &green, 2);
    texel[RCOMP] =
    texel[GCOMP] =
diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
index 995e079..e30890c 100644
--- a/src/mesa/main/texcompress_s3tc.c
+++ b/src/mesa/main/texcompress_s3tc.c
@@ -374,7 +374,7 @@ fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
    (void) k;
    if (fetch_ext_rgb_dxt1) {
       fetch_ext_rgb_dxt1(texImage->RowStride,
-                         texImage->Data, i, j, texel);
+                         texImage->Map, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
@@ -402,7 +402,7 @@ fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
    (void) k;
    if (fetch_ext_rgba_dxt1) {
       fetch_ext_rgba_dxt1(texImage->RowStride,
-                          texImage->Data, i, j, texel);
+                          texImage->Map, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
@@ -430,7 +430,7 @@ fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
    (void) k;
    if (fetch_ext_rgba_dxt3) {
       fetch_ext_rgba_dxt3(texImage->RowStride,
-                          texImage->Data, i, j, texel);
+                          texImage->Map, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
@@ -458,7 +458,7 @@ fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
    (void) k;
    if (fetch_ext_rgba_dxt5) {
       fetch_ext_rgba_dxt5(texImage->RowStride,
-                          texImage->Data, i, j, texel);
+                          texImage->Map, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 0a383aa..3391600 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -142,7 +142,7 @@ struct swrast_texture_image
    GLint RowStride;		/**< Padded width in units of texels */
    GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
                                      each 2D slice in 'Data', in texels */
-   GLubyte *Data;		/**< Image data, accessed via FetchTexel() */
+   GLubyte *Map;		/**< Pointer to mapped image memory */
 
    /** Malloc'd texture memory */
    GLubyte *Buffer;
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index 877c29c..f1a2ed6 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -43,7 +43,7 @@
 #if DIM == 1
 
 #define TEXEL_ADDR( type, image, i, j, k, size ) \
-	((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
+	((void) (j), (void) (k), ((type *)(image)->Map + (i) * (size)))
 
 #define FETCH(x) fetch_texel_1d_##x
 
@@ -51,14 +51,14 @@
 
 #define TEXEL_ADDR( type, image, i, j, k, size )			\
 	((void) (k),							\
-	 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
+	 ((type *)(image)->Map + ((image)->RowStride * (j) + (i)) * (size)))
 
 #define FETCH(x) fetch_texel_2d_##x
 
 #elif DIM == 3
 
 #define TEXEL_ADDR( type, image, i, j, k, size )			\
-	((type *)(image)->Data + ((image)->ImageOffsets[k]		\
+	((type *)(image)->Map + ((image)->ImageOffsets[k]		\
              + (image)->RowStride * (j) + (i)) * (size))
 
 #define FETCH(x) fetch_texel_3d_##x
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index 21b55a8..d142d3d 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -1380,7 +1380,7 @@ opt_sample_rgb_2d(struct gl_context *ctx,
       GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
       GLint j = IFLOOR(texcoords[k][1] * height) & rowMask;
       GLint pos = (j << shift) | i;
-      GLubyte *texel = swImg->Data + 3 * pos;
+      GLubyte *texel = swImg->Map + 3 * pos;
       rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]);
       rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]);
       rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]);
@@ -1424,7 +1424,7 @@ opt_sample_rgba_2d(struct gl_context *ctx,
       const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
       const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask;
       const GLint pos = (row << shift) | col;
-      const GLuint texel = *((GLuint *) swImg->Data + pos);
+      const GLuint texel = *((GLuint *) swImg->Map + pos);
       rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24)        );
       rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff );
       rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >>  8) & 0xff );
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index ffd78a2..b131d5a 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -247,7 +247,7 @@ _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
                swrast_texture_image(texImage);
 
             /* XXX we'll eventually call _swrast_map_teximage() here */
-            swImage->Data = swImage->Buffer;
+            swImage->Map = swImage->Buffer;
          }
       }
    }
@@ -268,7 +268,7 @@ _swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
                = swrast_texture_image(texImage);
 
             /* XXX we'll eventually call _swrast_unmap_teximage() here */
-            swImage->Data = NULL;
+            swImage->Map = NULL;
          }
       }
    }
@@ -337,11 +337,11 @@ map_unmap_renderbuffers(struct gl_context *ctx,
 
             if (map) {
                /* XXX we'll eventually call _swrast_map_teximage() here */
-               swImage->Data = swImage->Buffer;
+               swImage->Map = swImage->Buffer;
             }
             else {
                /* XXX we'll eventually call _swrast_unmap_teximage() here */
-               swImage->Data = NULL;
+               swImage->Map = NULL;
             }
          }
       }
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 43deaf4..4d815c5 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -132,7 +132,7 @@ _swrast_culltriangle( struct gl_context *ctx,
    const GLfloat twidth = (GLfloat) texImg->Width;			\
    const GLfloat theight = (GLfloat) texImg->Height;			\
    const GLint twidth_log2 = texImg->WidthLog2;				\
-   const GLubyte *texture = (const GLubyte *) swImg->Data;		\
+   const GLubyte *texture = (const GLubyte *) swImg->Map;		\
    const GLint smask = texImg->Width - 1;				\
    const GLint tmask = texImg->Height - 1;				\
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);			\
@@ -189,7 +189,7 @@ _swrast_culltriangle( struct gl_context *ctx,
    const GLfloat twidth = (GLfloat) texImg->Width;			\
    const GLfloat theight = (GLfloat) texImg->Height;			\
    const GLint twidth_log2 = texImg->WidthLog2;				\
-   const GLubyte *texture = (const GLubyte *) swImg->Data;		\
+   const GLubyte *texture = (const GLubyte *) swImg->Map;		\
    const GLint smask = texImg->Width - 1;				\
    const GLint tmask = texImg->Height - 1;				\
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);			\
@@ -543,7 +543,7 @@ affine_span(struct gl_context *ctx, SWspan *span,
       swrast_texture_image_const(texImg);				\
    const GLfloat twidth = (GLfloat) texImg->Width;			\
    const GLfloat theight = (GLfloat) texImg->Height;			\
-   info.texture = (const GLchan *) swImg->Data;				\
+   info.texture = (const GLchan *) swImg->Map;				\
    info.twidth_log2 = texImg->WidthLog2;				\
    info.smask = texImg->Width - 1;					\
    info.tmask = texImg->Height - 1;					\
@@ -810,7 +810,7 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
       obj->Image[0][obj->BaseLevel];			 		\
    const struct swrast_texture_image *swImg =				\
       swrast_texture_image_const(texImg);				\
-   info.texture = (const GLchan *) swImg->Data;				\
+   info.texture = (const GLchan *) swImg->Map;				\
    info.twidth_log2 = texImg->WidthLog2;				\
    info.smask = texImg->Width - 1;					\
    info.tmask = texImg->Height - 1;					\
commit 573e1478eb789230efcad952b5fdbe902375d867
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:36 2012 -0700

    swrast: remove gl_renderbuffer::DataType check in DrawPixels()
    
    The field will be going away so update this code.
    (cherry picked from commit ecb8594c184f5daa2f5a735e42ee24e7d110aa9f)

diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c
index 4231bb4..5828a78 100644
--- a/src/mesa/swrast/s_drawpix.c
+++ b/src/mesa/swrast/s_drawpix.c
@@ -429,11 +429,14 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
    span.arrayMask = SPAN_RGBA;
    span.arrayAttribs = FRAG_BIT_COL0; /* we're fill in COL0 attrib values */
 
-   if (ctx->DrawBuffer->_NumColorDrawBuffers > 0 &&
-       ctx->DrawBuffer->_ColorDrawBuffers[0]->DataType != GL_FLOAT &&
-       ctx->Color.ClampFragmentColor != GL_FALSE) {
-      /* need to clamp colors before applying fragment ops */
-      transferOps |= IMAGE_CLAMP_BIT;
+   if (ctx->DrawBuffer->_NumColorDrawBuffers > 0) {
+      GLenum datatype = _mesa_get_format_datatype(
+                 ctx->DrawBuffer->_ColorDrawBuffers[0]->Format);
+      if (datatype != GL_FLOAT &&
+          ctx->Color.ClampFragmentColor != GL_FALSE) {
+         /* need to clamp colors before applying fragment ops */
+         transferOps |= IMAGE_CLAMP_BIT;
+      }
    }
 
    /*
commit 490057ae81e87823cb85cbd663087b7b4d1b12c9
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:31 2012 -0700

    swrast: remove gl_renderbuffer::DataType assertions
    
    This field will go away, so remove some uses of it.
    (cherry picked from commit 7726be1c1b8ae321d01e781b5db4e2224e67d13d)

diff --git a/src/mesa/swrast/s_blend.c b/src/mesa/swrast/s_blend.c
index be5010b..cd6e6f0 100644
--- a/src/mesa/swrast/s_blend.c
+++ b/src/mesa/swrast/s_blend.c
@@ -1000,7 +1000,6 @@ _swrast_blend_span(struct gl_context *ctx, struct gl_renderbuffer *rb, SWspan *s
 
    ASSERT(span->end <= MAX_WIDTH);
    ASSERT(span->arrayMask & SPAN_RGBA);
-   ASSERT(rb->DataType == span->array->ChanType);
    ASSERT(!ctx->Color.ColorLogicOpEnabled);
 
    rbPixels = _swrast_get_dest_rgba(ctx, rb, span);
diff --git a/src/mesa/swrast/s_logic.c b/src/mesa/swrast/s_logic.c
index 80ee46c..e908a0e 100644
--- a/src/mesa/swrast/s_logic.c
+++ b/src/mesa/swrast/s_logic.c
@@ -195,7 +195,6 @@ _swrast_logicop_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
    ASSERT(span->end < MAX_WIDTH);
    ASSERT(span->arrayMask & SPAN_RGBA);
-   ASSERT(rb->DataType == span->array->ChanType);
 
    rbPixels = _swrast_get_dest_rgba(ctx, rb, span);
 
diff --git a/src/mesa/swrast/s_masking.c b/src/mesa/swrast/s_masking.c
index 2e68f8c..2d962eb 100644
--- a/src/mesa/swrast/s_masking.c
+++ b/src/mesa/swrast/s_masking.c
@@ -48,7 +48,6 @@ _swrast_mask_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
    ASSERT(n < MAX_WIDTH);
    ASSERT(span->arrayMask & SPAN_RGBA);
-   ASSERT(rb->DataType == span->array->ChanType);
 
    rbPixels = _swrast_get_dest_rgba(ctx, rb, span);
 
commit d2d1419ba076101ef55b9142d44855351dc6afc6
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:23 2012 -0700

    st/mesa: remove gl_renderbuffer:DataType assignments
    
    That field is only used by swrast code so there's no reason to mess
    with it in the gallium state tracker.
    
    This also lets us remove the unused st_format_data() type function and
    related code.
    (cherry picked from commit ca6d86d26b1726b13baa21b73fe9d426f28370e2)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c b/src/mesa/state_tracker/st_cb_eglimage.c
index 5209fc7..e91e914 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -86,7 +86,6 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
       strb->Base.Width = ps->width;
       strb->Base.Height = ps->height;
       strb->Base.Format = st_pipe_format_to_mesa_format(ps->format);
-      strb->Base.DataType = st_format_datatype(ps->format);
       strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format);
       strb->Base.InternalFormat = strb->Base._BaseFormat;
 
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index ec40a2b..be9c365 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -97,7 +97,6 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
    strb->Base.Height = height;
    strb->Base.Format = st_pipe_format_to_mesa_format(format);
    strb->Base._BaseFormat = _mesa_base_fbo_format(ctx, internalFormat);
-   strb->Base.DataType = st_format_datatype(format);
    strb->format = format;
 
    strb->defined = GL_FALSE;  /* undefined contents now */
@@ -252,7 +251,6 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw)
    strb->Base.NumSamples = samples;
    strb->Base.Format = st_pipe_format_to_mesa_format(format);
    strb->Base._BaseFormat = _mesa_get_format_base_format(strb->Base.Format);
-   strb->Base.DataType = st_format_datatype(format);
    strb->format = format;
    strb->software = sw;
    
@@ -425,7 +423,6 @@ st_render_texture(struct gl_context *ctx,
    strb->format = pt->format;
 
    strb->Base.Format = st_pipe_format_to_mesa_format(pt->format);
-   strb->Base.DataType = st_format_datatype(pt->format);
 
    /*
    printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p  %d x %d\n",
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 5f9ae91..c6e3175 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -47,106 +47,6 @@
 #include "st_format.h"
 
 
-static GLuint
-format_max_bits(enum pipe_format format)
-{
-   GLuint size = util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0);
-
-   size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 1));
-   size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 2));
-   size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3));
-   size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0));
-   size = MAX2(size, util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1));
-   return size;
-}
-
-
-/**
- * Return basic GL datatype for the given gallium format.
- */
-GLenum
-st_format_datatype(enum pipe_format format)
-{
-   const struct util_format_description *desc;
-   int i;
-
-   desc = util_format_description(format);
-   assert(desc);
-
-   /* Find the first non-VOID channel. */
-   for (i = 0; i < 4; i++) {
-       if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
-           break;
-       }
-   }
-
-   if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
-      if (format == PIPE_FORMAT_B5G5R5A1_UNORM ||
-          format == PIPE_FORMAT_B5G6R5_UNORM) {
-         return GL_UNSIGNED_SHORT;
-      }
-      else if (format == PIPE_FORMAT_R11G11B10_FLOAT ||
-               format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
-         return GL_FLOAT;
-      }
-      else if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
-               format == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
-               format == PIPE_FORMAT_Z24X8_UNORM ||
-               format == PIPE_FORMAT_X8Z24_UNORM) {
-         return GL_UNSIGNED_INT_24_8;
-      }
-      else if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
-         return GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
-      }
-      else {
-         const GLuint size = format_max_bits(format);
-
-         assert(i < 4);
-         if (i == 4)
-            return GL_NONE;
-
-         if (size == 8) {
-            if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
-               return GL_UNSIGNED_BYTE;
-            else
-               return GL_BYTE;
-         }
-         else if (size == 16) {
-            if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
-               return GL_HALF_FLOAT;
-            if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
-               return GL_UNSIGNED_SHORT;
-            else
-               return GL_SHORT;
-         }
-         else if (size <= 32) {
-            if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
-               return GL_FLOAT;
-            if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
-               return GL_UNSIGNED_INT;
-            else
-               return GL_INT;
-         }
-         else {
-            assert(size == 64);
-            assert(desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT);
-            return GL_DOUBLE;
-         }
-      }
-   }
-   else if (format == PIPE_FORMAT_UYVY) {
-      return GL_UNSIGNED_SHORT;
-   }
-   else if (format == PIPE_FORMAT_YUYV) {
-      return GL_UNSIGNED_SHORT;
-   }
-   else {
-      /* probably a compressed format, unsupported anyway */
-      return GL_NONE;
-   }
-}
-
-
 /**
  * Translate Mesa format to Gallium format.
  */
diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h
index 10ffeaa..1dea0d9 100644
--- a/src/mesa/state_tracker/st_format.h
+++ b/src/mesa/state_tracker/st_format.h
@@ -39,9 +39,6 @@
 struct gl_context;
 struct pipe_screen;
 
-extern GLenum
-st_format_datatype(enum pipe_format format);
-
 
 extern enum pipe_format
 st_mesa_format_to_pipe_format(gl_format mesaFormat);
commit 0941b808a62d9b8cd380830603d84008cceecec2
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:19 2012 -0700

    swrast: make _swrast_get_values(), _swrast_get_row() static
    
    They were only called from in s_span.c
    (cherry picked from commit ff57b0f037a45b0d5ced38234f0a8b29d32e7f9d)

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index c82b15a..fe199cb 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1385,10 +1385,10 @@ _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
  * \param valueSize is the size in bytes of each value (pixel) put into the
  *                  values array.
  */
-void
-_swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                   GLuint count, const GLint x[], const GLint y[],
-                   void *values, GLuint valueSize)
+static void
+get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
+           GLuint count, const GLint x[], const GLint y[],
+           void *values, GLuint valueSize)
 {
    GLuint i, inCount = 0, inStart = 0;
 
@@ -1421,10 +1421,10 @@ _swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
  * Wrapper for gl_renderbuffer::GetRow() which does clipping.
  * \param valueSize  size of each value (pixel) in bytes
  */
-void
-_swrast_get_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                GLuint count, GLint x, GLint y,
-                GLvoid *values, GLuint valueSize)
+static void
+get_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
+        GLuint count, GLint x, GLint y,
+        GLvoid *values, GLuint valueSize)
 {
    GLint skip = 0;
 
@@ -1468,12 +1468,12 @@ _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
    /* Get destination values from renderbuffer */
    if (span->arrayMask & SPAN_XY) {
-      _swrast_get_values(ctx, rb, span->end, span->array->x, span->array->y,
-                         rbPixels, pixelSize);
+      get_values(ctx, rb, span->end, span->array->x, span->array->y,
+                 rbPixels, pixelSize);
    }
    else {
-      _swrast_get_row(ctx, rb, span->end, span->x, span->y,
-                      rbPixels, pixelSize);
+      get_row(ctx, rb, span->end, span->x, span->y,
+              rbPixels, pixelSize);
    }
 
    return rbPixels;
diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index 1663831..e39ae85 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -203,17 +203,6 @@ extern void
 _swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
                        GLuint n, GLint x, GLint y, GLvoid *rgba);
 
-extern void
-_swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                   GLuint count, const GLint x[], const GLint y[],
-                   void *values, GLuint valueSize);
-
-extern void
-_swrast_get_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                GLuint count, GLint x, GLint y,
-                GLvoid *values, GLuint valueSize);
-
-
 extern void *
 _swrast_get_dest_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
                       SWspan *span);
commit ac6074de17aee7e3b93034897332c87271bfe9b8
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:13 2012 -0700

    swrast: remove dstType param from _swrast_read_rgba_span()
    
    It was always GL_FLOAT.
    (cherry picked from commit 267fb178844d3f17503dd0f921791f3ab059c4e7)

diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c
index 1e0f9fe..13fc36c 100644
--- a/src/mesa/swrast/s_copypix.c
+++ b/src/mesa/swrast/s_copypix.c
@@ -148,7 +148,7 @@ copy_rgba_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
       p = tmpImage;
       for (row = 0; row < height; row++) {
          _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
-                                 width, srcx, sy + row, GL_FLOAT, p );
+                                 width, srcx, sy + row, p );
          p += width * 4;
       }
       p = tmpImage;
@@ -172,7 +172,7 @@ copy_rgba_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
       else {
          /* get from framebuffer */
          _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
-                                 width, srcx, sy, GL_FLOAT, rgba );
+                                 width, srcx, sy, rgba );
       }
 
       if (transferOps) {
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 554f409..c82b15a 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1305,16 +1305,16 @@ end:
 
 
 /**
- * Read RGBA pixels from a renderbuffer.  Clipping will be done to prevent
- * reading ouside the buffer's boundaries.
- * \param dstType  datatype for returned colors
+ * Read float RGBA pixels from a renderbuffer.  Clipping will be done to
+ * prevent reading ouside the buffer's boundaries.
  * \param rgba  the returned colors
  */
 void
 _swrast_read_rgba_span( struct gl_context *ctx, struct gl_renderbuffer *rb,
-                        GLuint n, GLint x, GLint y, GLenum dstType,
+                        GLuint n, GLint x, GLint y,
                         GLvoid *rgba)
 {
+   GLenum dstType = GL_FLOAT;
    const GLint bufWidth = (GLint) rb->Width;
    const GLint bufHeight = (GLint) rb->Height;
 
diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index e8f7687..1663831 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -201,7 +201,7 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span);
 
 extern void
 _swrast_read_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                       GLuint n, GLint x, GLint y, GLenum type, GLvoid *rgba);
+                       GLuint n, GLint x, GLint y, GLvoid *rgba);
 
 extern void
 _swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
commit 289a7e74b32267b6b65a02f387f6701d70aa2eaf
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:54:01 2012 -0700

    swrast: remove unused _swrast_put_row()
    (cherry picked from commit 64be85540f30e904784c6a72f2ba2784d5ccb36d)

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index e899303..554f409 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1418,41 +1418,6 @@ _swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
 
 
 /**
- * Wrapper for gl_renderbuffer::PutRow() which does clipping.
- * \param valueSize  size of each value (pixel) in bytes
- */
-void
-_swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                GLuint count, GLint x, GLint y,
-                const GLvoid *values, GLuint valueSize)
-{
-   GLint skip = 0;
-
-   if (y < 0 || y >= (GLint) rb->Height)
-      return; /* above or below */
-
-   if (x + (GLint) count <= 0 || x >= (GLint) rb->Width)
-      return; /* entirely left or right */
-
-   if ((GLint) (x + count) > (GLint) rb->Width) {
-      /* right clip */
-      GLint clip = x + count - rb->Width;
-      count -= clip;
-   }
-
-   if (x < 0) {
-      /* left clip */
-      skip = -x;
-      x = 0;
-      count -= skip;
-   }
-
-   rb->PutRow(ctx, rb, count, x, y,
-              (const GLubyte *) values + skip * valueSize, NULL);
-}
-
-
-/**
  * Wrapper for gl_renderbuffer::GetRow() which does clipping.
  * \param valueSize  size of each value (pixel) in bytes
  */
diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index f4d32dd..e8f7687 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -209,11 +209,6 @@ _swrast_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
                    void *values, GLuint valueSize);
 
 extern void
-_swrast_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
-                GLuint count, GLint x, GLint y,
-                const GLvoid *values, GLuint valueSize);
-
-extern void
 _swrast_get_row(struct gl_context *ctx, struct gl_renderbuffer *rb,
                 GLuint count, GLint x, GLint y,
                 GLvoid *values, GLuint valueSize);
commit 889f756c2864df9428289f11a9ad837147e6d963
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Wed Jan 18 15:56:58 2012 -0800

    swrast: Fix unsigned promotion in pointer arithmetic
    
    When rowstride was negatie, unsigned promotion caused a segfault here:
    
    299│    if (rb->Format == MESA_FORMAT_S8) {
    300│       const GLuint rowStride = rb->RowStride;
    301│       for (i = 0; i < count; i++) {
    302│          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
    303├>            stencil[i] = *(map + y[i] * rowStride + x[i]);
    304│          }
    305│       }
    306│    }
    
    Fixes segfault in oglconform
    separatestencil-neu(NonPolygon.BothFacesBitmapCoreAPI),
    though test still fails.
    
    Note: This is a candidate for the stable branches.
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43327
    Reviewed-by: Brian Paul <brianp at vmware.com>
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit aed5c8299fe47b8e1728f8140d069bc89d3fa947)

diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index dbcbd2b..fb95ef1 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -297,7 +297,7 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
    GLuint i;
 
    if (rb->Format == MESA_FORMAT_S8) {
-      const GLuint rowStride = rb->RowStride;
+      const GLint rowStride = rb->RowStride;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             stencil[i] = *(map + y[i] * rowStride + x[i]);
@@ -305,8 +305,8 @@ get_s8_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
       }
    }
    else {
-      const GLuint bpp = _mesa_get_format_bytes(rb->Format);
-      const GLuint rowStride = rb->RowStride * bpp;
+      const GLint bpp = _mesa_get_format_bytes(rb->Format);
+      const GLint rowStride = rb->RowStride * bpp;
       for (i = 0; i < count; i++) {
          if (x[i] >= 0 && y[i] >= 0 && x[i] < w && y[i] < h) {
             const GLubyte *src = map + y[i] * rowStride + x[i] * bpp;
commit e10c47adffb0371cba3d6a2c80313489e6fa8767
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 20 13:43:11 2012 -0800

    mesa: Fix CopyTex{Sub,}Image error checks for integer vs non-integer.
    
    Fixes Intel oglconform negative.typeFormatMismatch.copyteximage.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 422b18794eacc8f0be5b4e9611e2726f4e0d86b6)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index d5e462b..53fd241 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1938,6 +1938,24 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
       return GL_TRUE;
    }
 
+   /* From the EXT_texture_integer spec:
+    *
+    *     "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
+    *      if the texture internalformat is an integer format and the read color
+    *      buffer is not an integer format, or if the internalformat is not an
+    *      integer format and the read color buffer is an integer format."
+    */
+   if (_mesa_is_color_format(internalFormat)) {
+      struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
+
+      if (_mesa_is_integer_format(rb->InternalFormat) !=
+	  _mesa_is_integer_format(internalFormat)) {
+	 _mesa_error(ctx, GL_INVALID_OPERATION,
+		     "glCopyTexImage%dD(integer vs non-integer)", dimensions);
+	 return GL_TRUE;
+      }
+   }
+
    /* Do size, level checking */
    sizeOK = (proxyTarget == GL_PROXY_TEXTURE_CUBE_MAP_ARB)
       ? (width == height) : 1;
@@ -2153,16 +2171,21 @@ copytexsubimage_error_check2( struct gl_context *ctx, GLuint dimensions,
       return GL_TRUE;
    }
 
-   /* If copying into an integer texture, the source buffer must also be
-    * integer-valued.
+   /* From the EXT_texture_integer spec:
+    *
+    *     "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
+    *      if the texture internalformat is an integer format and the read color
+    *      buffer is not an integer format, or if the internalformat is not an
+    *      integer format and the read color buffer is an integer format."
     */
-   if (_mesa_is_format_integer_color(teximage->TexFormat)) {
+   if (_mesa_is_color_format(teximage->InternalFormat)) {
       struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
-      if (!_mesa_is_format_integer_color(rb->Format)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glCopyTexSubImage%dD(source buffer is not integer format)",
-                  dimensions);
-         return GL_TRUE;
+
+      if (_mesa_is_format_integer_color(rb->Format) !=
+	  _mesa_is_format_integer_color(teximage->TexFormat)) {
+	 _mesa_error(ctx, GL_INVALID_OPERATION,
+		     "glCopyTexImage%dD(integer vs non-integer)", dimensions);
+	 return GL_TRUE;
       }
    }
 
commit dcaf26ac91943849ffd2ee4a23ac4b1e12ef639f
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 20 15:23:42 2012 -0800

    mesa: Add missing integer R/RG cases to _mesa_is_color_format().
    
    This is part of fixing Intel oglconform
    negative.typeFormatMismatch.copyteximage.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit ee9804af14caa18586dd711119bc8fc8c2de00a8)

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index b37cd7e..8b65cf0 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -759,36 +759,48 @@ _mesa_is_color_format(GLenum format)
       /* sized integer formats */
       case GL_RGBA32UI_EXT:
       case GL_RGB32UI_EXT:
+      case GL_RG32UI:
+      case GL_R32UI:
       case GL_ALPHA32UI_EXT:
       case GL_INTENSITY32UI_EXT:
       case GL_LUMINANCE32UI_EXT:
       case GL_LUMINANCE_ALPHA32UI_EXT:
       case GL_RGBA16UI_EXT:
       case GL_RGB16UI_EXT:
+      case GL_RG16UI:
+      case GL_R16UI:
       case GL_ALPHA16UI_EXT:
       case GL_INTENSITY16UI_EXT:
       case GL_LUMINANCE16UI_EXT:
       case GL_LUMINANCE_ALPHA16UI_EXT:
       case GL_RGBA8UI_EXT:
       case GL_RGB8UI_EXT:
+      case GL_RG8UI:
+      case GL_R8UI:
       case GL_ALPHA8UI_EXT:
       case GL_INTENSITY8UI_EXT:
       case GL_LUMINANCE8UI_EXT:
       case GL_LUMINANCE_ALPHA8UI_EXT:
       case GL_RGBA32I_EXT:
       case GL_RGB32I_EXT:
+      case GL_RG32I:
+      case GL_R32I:
       case GL_ALPHA32I_EXT:
       case GL_INTENSITY32I_EXT:
       case GL_LUMINANCE32I_EXT:
       case GL_LUMINANCE_ALPHA32I_EXT:
       case GL_RGBA16I_EXT:
       case GL_RGB16I_EXT:
+      case GL_RG16I:
+      case GL_R16I:
       case GL_ALPHA16I_EXT:
       case GL_INTENSITY16I_EXT:
       case GL_LUMINANCE16I_EXT:
       case GL_LUMINANCE_ALPHA16I_EXT:
       case GL_RGBA8I_EXT:
       case GL_RGB8I_EXT:
+      case GL_RG8I:
+      case GL_R8I:
       case GL_ALPHA8I_EXT:
       case GL_INTENSITY8I_EXT:
       case GL_LUMINANCE8I_EXT:
commit 9a33b5a269d8407872a9cc86cb0ce36a1c510e21
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 20 13:59:37 2012 -0800

    meta: Detect currently-unsupported integer CopyTexSubImage and complain.
    
    This code is unprepared for handling integer (particularly, the
    baseFormat of the TexFormat comes out as GL_RGBA, not GL_RGBA_INTEGER,
    so the direct call of Driver.ReadPixels crashes due to the int vs
    non-int error checking not having happened).  I'm frankly tempted to
    convert this code to MapRenderbuffer/MapTexImage rather than doing it
    as meta ops, now that we have that support.
    
    Improves the remaining crash in Intel oglconform for int-textures to
    just a rendering failure.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 6bf0f6ae86dae14ed0348e5fccf75c43302ad502)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index dca3613..8cc7cf2 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -3126,6 +3126,11 @@ copy_tex_sub_image(struct gl_context *ctx,
       format = GL_RGBA;
    }
 
+   if (_mesa_is_format_integer_color(texImage->TexFormat)) {
+      _mesa_problem(ctx, "unsupported integer color copyteximage");
+      return;
+   }
+
    type = get_temp_image_type(ctx, format);
    bpp = _mesa_bytes_per_pixel(format, type);
    if (bpp <= 0) {
commit 61be81ae5c47ea2d23f591acc7f3bbbfb6b6e841
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 20 12:50:34 2012 -0800

    mesa: Add the remaining from/to types for GL_EXT_texture_integer (and R/RG).
    
    This aborts and crashes in intel oglconform's int-textures into being
    just rendering failures.  Clamping isn't handled yet.
    
    v2: Add missing "break".
    v3: Drop the int/uint distinction, since they don't need different clamping.
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com> (v2)
    (cherry picked from commit d6c58545a1da8c83f0aad296a5e9e31a7c77cfe4)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 8f2c8fd..f874ab2 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -448,65 +448,75 @@ get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
    }
 }
 
-/*
- * integer packing , no transfer operations only packs
- * to dst of GL_UNSIGNED_INT or GL_INT
+/* Customization of integer packing.  We always treat src as uint, and can pack dst
+ * as any integer type/format combo.
  */
+#define SRC_TYPE GLuint
+
+#define DST_TYPE GLuint
+#define SRC_CONVERT(x) (x)
+#define FN_NAME pack_uint_from_uint_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLushort
+#define SRC_CONVERT(x) (x)
+#define FN_NAME pack_ushort_from_uint_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLshort
+#define SRC_CONVERT(x) (x)
+#define FN_NAME pack_short_from_uint_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLubyte
+#define SRC_CONVERT(x) (x)
+#define FN_NAME pack_ubyte_from_uint_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
+#define DST_TYPE GLbyte
+#define SRC_CONVERT(x) (x)
+#define FN_NAME pack_byte_from_uint_rgba
+#include "pack_tmp.h"
+#undef DST_TYPE
+#undef SRC_CONVERT
+#undef FN_NAME
+
 void
 _mesa_pack_rgba_span_int(struct gl_context *ctx, GLuint n, GLuint rgba[][4],
                          GLenum dstFormat, GLenum dstType,
                          GLvoid *dstAddr)
 {
-   int i;
-
    switch(dstType) {
-   case GL_UNSIGNED_INT: {
-      GLuint *dst = (GLuint *) dstAddr;
-      switch (dstFormat) {
-      case GL_RED_INTEGER_EXT:
-      case GL_GREEN_INTEGER_EXT:
-      case GL_BLUE_INTEGER_EXT:
-      case GL_ALPHA_INTEGER_EXT:
-      case GL_RG_INTEGER:
-      case GL_RGB_INTEGER_EXT:
-      case GL_RGBA_INTEGER_EXT:
-      case GL_BGR_INTEGER_EXT:
-      case GL_BGRA_INTEGER_EXT:
-      case GL_LUMINANCE_INTEGER_EXT:
-      case GL_LUMINANCE_ALPHA_INTEGER_EXT:
-         for (i=0;i<n;i++) {
-            dst[i*4+0] = (GLuint) rgba[i][RCOMP];
-            dst[i*4+1] = (GLuint) rgba[i][GCOMP];
-            dst[i*4+2] = (GLuint) rgba[i][BCOMP];
-            dst[i*4+3] = (GLuint) rgba[i][ACOMP];
-         }
-         break;
-      }
-   }
+   case GL_UNSIGNED_INT:
+      pack_uint_from_uint_rgba(dstAddr, dstFormat, rgba, n);
       break;
-   case GL_INT: {
-      GLint *dst = (GLint *) dstAddr;
-      switch (dstFormat) {
-      case GL_RED_INTEGER_EXT:
-      case GL_GREEN_INTEGER_EXT:
-      case GL_BLUE_INTEGER_EXT:
-      case GL_ALPHA_INTEGER_EXT:
-      case GL_RG_INTEGER:
-      case GL_RGB_INTEGER_EXT:
-      case GL_RGBA_INTEGER_EXT:
-      case GL_BGR_INTEGER_EXT:
-      case GL_BGRA_INTEGER_EXT:
-      case GL_LUMINANCE_INTEGER_EXT:
-      case GL_LUMINANCE_ALPHA_INTEGER_EXT:
-         for (i=0;i<n;i++) {
-            dst[i*4+0] = (GLint) rgba[i][RCOMP];
-            dst[i*4+1] = (GLint) rgba[i][GCOMP];
-            dst[i*4+2] = (GLint) rgba[i][BCOMP];
-            dst[i*4+3] = (GLint) rgba[i][ACOMP];
-         }
-         break;
-      }
-   }
+   case GL_INT:
+      /* No conversion necessary. */
+      pack_uint_from_uint_rgba(dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_UNSIGNED_SHORT:
+      pack_ushort_from_uint_rgba(dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_SHORT:
+      pack_short_from_uint_rgba(dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_UNSIGNED_BYTE:
+      pack_ubyte_from_uint_rgba(dstAddr, dstFormat, rgba, n);
+      break;
+   case GL_BYTE:
+      pack_byte_from_uint_rgba(dstAddr, dstFormat, rgba, n);
       break;
    default:
       assert(0);
diff --git a/src/mesa/main/pack_tmp.h b/src/mesa/main/pack_tmp.h
new file mode 100644
index 0000000..83b6557
--- /dev/null
+++ b/src/mesa/main/pack_tmp.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+static void
+FN_NAME(DST_TYPE *dst,
+	GLenum dstFormat,
+	SRC_TYPE rgba[][4],
+	int n)
+{
+   int i;
+
+   switch (dstFormat) {
+   case GL_RED_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i] = SRC_CONVERT(rgba[i][RCOMP]);
+      }
+      break;
+
+   case GL_GREEN_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i] = SRC_CONVERT(rgba[i][GCOMP]);
+      }
+      break;
+
+   case GL_BLUE_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i] = SRC_CONVERT(rgba[i][BCOMP]);
+      };
+      break;
+
+   case GL_ALPHA_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i] = SRC_CONVERT(rgba[i][ACOMP]);
+      }
+      break;
+
+   case GL_RG_INTEGER:
+      for (i=0;i<n;i++) {
+	 dst[i*2+0] = SRC_CONVERT(rgba[i][RCOMP]);
+	 dst[i*2+1] = SRC_CONVERT(rgba[i][GCOMP]);
+      }
+      break;
+
+   case GL_RGB_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i*3+0] = SRC_CONVERT(rgba[i][RCOMP]);
+	 dst[i*3+1] = SRC_CONVERT(rgba[i][GCOMP]);
+	 dst[i*3+2] = SRC_CONVERT(rgba[i][BCOMP]);
+      }
+      break;
+
+   case GL_RGBA_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i*4+0] = SRC_CONVERT(rgba[i][RCOMP]);
+	 dst[i*4+1] = SRC_CONVERT(rgba[i][GCOMP]);
+	 dst[i*4+2] = SRC_CONVERT(rgba[i][BCOMP]);
+	 dst[i*4+3] = SRC_CONVERT(rgba[i][ACOMP]);
+      }
+      break;
+
+   case GL_BGR_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i*3+0] = SRC_CONVERT(rgba[i][BCOMP]);
+	 dst[i*3+1] = SRC_CONVERT(rgba[i][GCOMP]);
+	 dst[i*3+2] = SRC_CONVERT(rgba[i][RCOMP]);
+      }
+      break;
+
+   case GL_BGRA_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i*4+0] = SRC_CONVERT(rgba[i][BCOMP]);
+	 dst[i*4+1] = SRC_CONVERT(rgba[i][GCOMP]);
+	 dst[i*4+2] = SRC_CONVERT(rgba[i][RCOMP]);
+	 dst[i*4+3] = SRC_CONVERT(rgba[i][ACOMP]);
+      }
+      break;
+
+   case GL_LUMINANCE_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i] = SRC_CONVERT(rgba[i][RCOMP] +
+			      rgba[i][GCOMP] +
+			      rgba[i][BCOMP]);
+      }
+      break;
+
+   case GL_LUMINANCE_ALPHA_INTEGER_EXT:
+      for (i=0;i<n;i++) {
+	 dst[i*2+0] = SRC_CONVERT(rgba[i][RCOMP] +
+				  rgba[i][GCOMP] +
+				  rgba[i][BCOMP]);
+	 dst[i*2+1] = SRC_CONVERT(rgba[i][ACOMP]);
+      }
+      break;
+   }
+}
commit 46c146116f43047572ca98c99a9ca0a119227801
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 20 15:03:12 2012 -0800

    mesa: Add support for glGetTexImage on GL_TEXTURE_1D_ARRAY
    
    Similarly to how we handle this in texstore, we have to remap height
    to depth so that we MapTextureImage each image layer individually.
    
    Fixes part of Intel oglconform's int-textures advanced.fbo.rtt
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 08acd4bd61430beb20a74af23de9f63c8f077467)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 95de24a..4eaa035 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -312,8 +312,8 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
    const gl_format texFormat =
       _mesa_get_srgb_format_linear(texImage->TexFormat);
    const GLuint width = texImage->Width;
-   const GLuint height = texImage->Height;
-   const GLuint depth = texImage->Depth;
+   GLuint height = texImage->Height;
+   GLuint depth = texImage->Depth;
    GLuint img, row;
    GLfloat (*rgba)[4];
    GLuint (*rgba_uint)[4];
@@ -327,6 +327,11 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
       return;
    }
 
+   if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
+      depth = height;
+      height = 1;
+   }
+
    for (img = 0; img < depth; img++) {
       GLubyte *srcMap;
       GLint rowstride;
commit e695c7e5b8eabf6178da381db57f849149de5bb9
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 09:46:24 2012 -0800

    mesa: Add support for glGetTexImage() from integer textures.
    
    This is a step toward fixing Intel oglconform's
    int-textures advanced.fbo.rtt.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 9f1e64d0856129374b00bd97685f22e092d6442d)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index 8c85c1e..95de24a 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -316,9 +316,12 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
    const GLuint depth = texImage->Depth;
    GLuint img, row;
    GLfloat (*rgba)[4];
+   GLuint (*rgba_uint)[4];
+   GLboolean is_integer = _mesa_is_format_integer_color(texImage->TexFormat);
 
    /* Allocate buffer for one row of texels */
    rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+   rgba_uint = (GLuint (*)[4]) rgba;
    if (!rgba) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
       return;
@@ -339,44 +342,83 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions,
                                              width, height, format, type,
                                              img, row, 0);
 
-            _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-
-            if (texImage->_BaseFormat == GL_ALPHA) {
-               GLint col;
-               for (col = 0; col < width; col++) {
-                  rgba[col][RCOMP] = 0.0F;
-                  rgba[col][GCOMP] = 0.0F;
-                  rgba[col][BCOMP] = 0.0F;
-               }
-            }
-            else if (texImage->_BaseFormat == GL_LUMINANCE) {
-               GLint col;
-               for (col = 0; col < width; col++) {
-                  rgba[col][GCOMP] = 0.0F;
-                  rgba[col][BCOMP] = 0.0F;
-                  rgba[col][ACOMP] = 1.0F;
-               }
-            }
-            else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
-               GLint col;
-               for (col = 0; col < width; col++) {
-                  rgba[col][GCOMP] = 0.0F;
-                  rgba[col][BCOMP] = 0.0F;
-               }
-            }
-            else if (texImage->_BaseFormat == GL_INTENSITY) {
-               GLint col;
-               for (col = 0; col < width; col++) {
-                  rgba[col][GCOMP] = 0.0F;
-                  rgba[col][BCOMP] = 0.0F;
-                  rgba[col][ACOMP] = 1.0F;
-               }
-            }
-
-            _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
-                                       format, type, dest,
-                                       &ctx->Pack, transferOps);
-         }
+	    if (is_integer) {
+	       _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
+
+	       if (texImage->_BaseFormat == GL_ALPHA) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba_uint[col][RCOMP] = 0;
+		     rgba_uint[col][GCOMP] = 0;
+		     rgba_uint[col][BCOMP] = 0;
+		  }
+	       }
+	       else if (texImage->_BaseFormat == GL_LUMINANCE) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba_uint[col][GCOMP] = 0;
+		     rgba_uint[col][BCOMP] = 0;
+		     rgba_uint[col][ACOMP] = 1;
+		  }
+	       }
+	       else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba_uint[col][GCOMP] = 0;
+		     rgba_uint[col][BCOMP] = 0;
+		  }
+	       }
+	       else if (texImage->_BaseFormat == GL_INTENSITY) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba_uint[col][GCOMP] = 0;
+		     rgba_uint[col][BCOMP] = 0;
+		     rgba_uint[col][ACOMP] = 1;
+		  }
+	       }
+
+	       _mesa_pack_rgba_span_int(ctx, width, rgba_uint,
+					format, type, dest);
+	    } else {
+	       _mesa_unpack_rgba_row(texFormat, width, src, rgba);
+
+	       if (texImage->_BaseFormat == GL_ALPHA) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba[col][RCOMP] = 0.0F;
+		     rgba[col][GCOMP] = 0.0F;
+		     rgba[col][BCOMP] = 0.0F;
+		  }
+	       }
+	       else if (texImage->_BaseFormat == GL_LUMINANCE) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba[col][GCOMP] = 0.0F;
+		     rgba[col][BCOMP] = 0.0F;
+		     rgba[col][ACOMP] = 1.0F;
+		  }
+	       }
+	       else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba[col][GCOMP] = 0.0F;
+		     rgba[col][BCOMP] = 0.0F;
+		  }
+	       }
+	       else if (texImage->_BaseFormat == GL_INTENSITY) {
+		  GLint col;
+		  for (col = 0; col < width; col++) {
+		     rgba[col][GCOMP] = 0.0F;
+		     rgba[col][BCOMP] = 0.0F;
+		     rgba[col][ACOMP] = 1.0F;
+		  }
+	       }
+
+	       _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
+					  format, type, dest,
+					  &ctx->Pack, transferOps);
+	    }
+	 }
 
          /* Unmap the src texture buffer */
          ctx->Driver.UnmapTextureImage(ctx, texImage, img);
commit bc973082fcae3816691e75d4024ecf55102e2b97
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jan 20 13:19:10 2012 -0800

    i965/gen6+: Work around GPU hangs with logic ops on integer textures.
    
    This doesn't result in correct rendering -- GL requires that logic ops
    work, while the hardware specs say it doesn't do them.  I'm not sure
    how we would want to handle this.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit f6e82cd2a18b0edebe3e4102fc93b552e708935a)

diff --git a/src/mesa/drivers/dri/i965/gen6_cc.c b/src/mesa/drivers/dri/i965/gen6_cc.c
index dada09c..8a805fa 100644
--- a/src/mesa/drivers/dri/i965/gen6_cc.c
+++ b/src/mesa/drivers/dri/i965/gen6_cc.c
@@ -79,9 +79,14 @@ gen6_upload_blend_state(struct brw_context *brw)
       /* _NEW_COLOR */
       if (ctx->Color.ColorLogicOpEnabled) {
 	 /* Floating point RTs should have no effect from LogicOp,
-	  * except for disabling of blending
+	  * except for disabling of blending.
+	  *
+	  * From the Sandy Bridge PRM, Vol 2 Par 1, Section 8.1.11, "Logic Ops",
+	  *
+	  *     "Logic Ops are only supported on *_UNORM surfaces (excluding
+	  *      _SRGB variants), otherwise Logic Ops must be DISABLED."
 	  */
-	 if (rb_type != GL_FLOAT) {
+	 if (rb_type == GL_UNSIGNED_NORMALIZED) {
 	    blend[b].blend1.logic_op_enable = 1;
 	    blend[b].blend1.logic_op_func =
 	       intel_translate_logic_op(ctx->Color.LogicOp);
commit f92503e171c327c1b78ef09129d4290210353244
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 19 15:41:12 2012 -0800

    i965/gen6+: Disable blending, alpha test, and dither on integer FBOs.
    
    Fixes GPU hangs and some rendering failures in piglit
    EXT_texture_integer/fbo-blending
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 04b4880d7c9a5882100ca6a19d42a8c012b174f6)

diff --git a/src/mesa/drivers/dri/i965/gen6_cc.c b/src/mesa/drivers/dri/i965/gen6_cc.c
index 916ec7d..dada09c 100644
--- a/src/mesa/drivers/dri/i965/gen6_cc.c
+++ b/src/mesa/drivers/dri/i965/gen6_cc.c
@@ -57,19 +57,36 @@ gen6_upload_blend_state(struct brw_context *brw)
    memset(blend, 0, size);
 
    for (b = 0; b < nr_draw_buffers; b++) {
+      /* _NEW_BUFFERS */
+      struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[b];
+      GLenum rb_type;
+      bool integer;
+
+      if (rb)
+	 rb_type = _mesa_get_format_datatype(rb->Format);
+      else
+	 rb_type = GL_UNSIGNED_NORMALIZED;
+
+      /* Used for implementing the following bit of GL_EXT_texture_integer:
+       *
+       *     "Per-fragment operations that require floating-point color
+       *      components, including multisample alpha operations, alpha test,
+       *      blending, and dithering, have no effect when the corresponding
+       *      colors are written to an integer color buffer."
+      */
+      integer = (rb_type == GL_INT || rb_type == GL_UNSIGNED_INT);
+
       /* _NEW_COLOR */
       if (ctx->Color.ColorLogicOpEnabled) {
-	 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[b];
-	 /* _NEW_BUFFERS */
 	 /* Floating point RTs should have no effect from LogicOp,
 	  * except for disabling of blending
 	  */
-	 if (rb && _mesa_get_format_datatype(rb->Format) != GL_FLOAT) {
+	 if (rb_type != GL_FLOAT) {
 	    blend[b].blend1.logic_op_enable = 1;
 	    blend[b].blend1.logic_op_func =
 	       intel_translate_logic_op(ctx->Color.LogicOp);
 	 }
-      } else if (ctx->Color.BlendEnabled & (1 << b)) {
+      } else if (ctx->Color.BlendEnabled & (1 << b) && !integer) {
 	 GLenum eqRGB = ctx->Color.Blend[0].EquationRGB;
 	 GLenum eqA = ctx->Color.Blend[0].EquationA;
 	 GLenum srcRGB = ctx->Color.Blend[0].SrcRGB;
@@ -121,7 +138,7 @@ gen6_upload_blend_state(struct brw_context *brw)
       blend[b].blend1.clamp_range = BRW_RENDERTARGET_CLAMPRANGE_FORMAT;
 
       /* _NEW_COLOR */
-      if (ctx->Color.AlphaEnabled) {
+      if (ctx->Color.AlphaEnabled && !integer) {
 	 blend[b].blend1.alpha_test_enable = 1;
 	 blend[b].blend1.alpha_test_func =
 	    intel_translate_compare_func(ctx->Color.AlphaFunc);
@@ -129,7 +146,7 @@ gen6_upload_blend_state(struct brw_context *brw)
       }
 
       /* _NEW_COLOR */
-      if (ctx->Color.DitherFlag) {
+      if (ctx->Color.DitherFlag && !integer) {
 	 blend[b].blend1.dither_enable = 1;
 	 blend[b].blend1.y_dither_offset = 0;
 	 blend[b].blend1.x_dither_offset = 0;
commit e406659b8bed4dd8450935e2f3ee697b99d278cf
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Thu May 5 14:08:57 2011 -0700

    configure.ac: Don't use $CLANG since it will collide with the static analyzer.
    
    We just prefix the $CLANG environment variable in configure.ac with acv_mesa_
    
    Found by: tinderbox
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit b728eefb06c26e4b5a25db31bbda9fcf4d015e17)

diff --git a/configure.ac b/configure.ac
index 7c50e3c..1fcfdbc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,13 +88,13 @@ AC_COMPILE_IFELSE(
        not clang
 #endif
 ]])],
-[CLANG=yes], [CLANG=no])
+[acv_mesa_CLANG=yes], [acv_mesa_CLANG=no])
 
-AC_MSG_RESULT([$CLANG])
+AC_MSG_RESULT([$acv_mesa_CLANG])
 
 dnl If we're using GCC, make sure that it is at least version 3.3.0.  Older
 dnl versions are explictly not supported.
-if test "x$GCC" = xyes -a "x$CLANG" = xno; then
+if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
     AC_MSG_CHECKING([whether gcc version is sufficient])
     major=0
     minor=0
commit 19f88670b528827f201bba2a996405d230cedc1b
Author: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
Date:   Wed Jan 25 16:24:13 2012 +0200

    gbm: fix copy & paste error in gbm_bo_get_handle documentation
    (cherry picked from commit 33f8a3cfbe85db6514231d8ebc622af1f2139a13)

diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 3e24c4a..03fc52b 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -211,7 +211,7 @@ gbm_bo_get_pitch(struct gbm_bo *bo)
  * the format of this handle is platform specific.
  *
  * \param bo The buffer object
- * \return Returns the stride of the allocated buffer object
+ * \return Returns the handle of the allocated buffer object
  */
 GBM_EXPORT union gbm_bo_handle
 gbm_bo_get_handle(struct gbm_bo *bo)
commit dcb1a3bc27e963d8db8f0f5976958c5fba1fa919
Author: Rob Bradford <rob at linux.intel.com>
Date:   Tue Dec 20 15:40:21 2011 +0000

    gbm: Add documentation for the public facing API
    (cherry picked from commit baab68e1a607b818c8988e70546fe3e6f97cf572)

diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 8440b2c..3e24c4a 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -48,6 +48,10 @@ struct gbm_device *devices[16];
 
 static int device_num = 0;
 
+/** Returns the file description for the gbm device
+ *
+ * \return The fd that the struct gbm_device was created with
+ */
 GBM_EXPORT int
 gbm_device_get_fd(struct gbm_device *gbm)
 {
@@ -55,12 +59,29 @@ gbm_device_get_fd(struct gbm_device *gbm)
 }
 
 /* FIXME: maybe superfluous, use udev subclass from the fd? */
+/** Get the backend name for the given gbm device
+ *
+ * \return The backend name string - this belongs to the device and must not
+ * be freed
+ */
 GBM_EXPORT const char *
 gbm_device_get_backend_name(struct gbm_device *gbm)
 {
    return gbm->name;
 }
 
+/** Test if a format is supported for a given set of usage flags.
+ *
+ * \param gbm The created buffer manager
+ * \param format The format to test
+ * \param usage A bitmask of the usages to test the format against
+ * \return 1 if the format is supported otherwise 0
+ *
+ * \sa enum gbm_bo_flags for the list of flags that the format can be
+ * tested against
+ *
+ * \sa enum gbm_bo_format for the list of formats
+ */
 int
 gbm_device_is_format_supported(struct gbm_device *gbm,
                                enum gbm_bo_format format,
@@ -69,6 +90,10 @@ gbm_device_is_format_supported(struct gbm_device *gbm,
    return gbm->is_format_supported(gbm, format, usage);
 }
 
+/** Destroy the gbm device and free all resources associated with it.
+ *
+ * \param gbm The device created using gbm_create_device()
+ */
 GBM_EXPORT void
 gbm_device_destroy(struct gbm_device *gbm)
 {
@@ -103,6 +128,18 @@ _gbm_mesa_get_device(int fd)
    return gbm;
 }
 
+/** Create a gbm device for allocating buffers
+ *
+ * The file descriptor passed in is used by the backend to communicate with
+ * platform for allocating the memory. For allocations using DRI this would be
+ * the file descriptor returned when opening a device such as \c
+ * /dev/dri/card0
+ *
+ * \param fd The file descriptor for an backend specific device
+ * \return The newly created struct gbm_device. The resources associated with
+ * the device should be freed with gbm_device_destroy() when it is no longer
+ * needed. If the creation of the device failed NULL will be returned.
+ */
 GBM_EXPORT struct gbm_device *
 gbm_create_device(int fd)
 {
@@ -131,36 +168,85 @@ gbm_create_device(int fd)
    return gbm;
 }
 
+/** Get the width of the buffer object
+ *
+ * \param bo The buffer object
+ * \return The width of the allocated buffer object
+ *
+ */
 GBM_EXPORT unsigned int
 gbm_bo_get_width(struct gbm_bo *bo)
 {
    return bo->width;
 }
 
+/** Get the height of the buffer object
+ *
+ * \param bo The buffer object
+ * \return The height of the allocated buffer object
+ */
 GBM_EXPORT unsigned int
 gbm_bo_get_height(struct gbm_bo *bo)
 {
    return bo->height;
 }
 
+/** Get the stride of the buffer object
+ *
+ * This is calculated by the backend when it does the allocation in
+ * gbm_bo_create()
+ *
+ * \param bo The buffer object
+ * \return The stride of the allocated buffer object
+ */
 GBM_EXPORT uint32_t
 gbm_bo_get_pitch(struct gbm_bo *bo)
 {
    return bo->pitch;
 }
 
+/** Get the handle of the buffer object
+ *
+ * This is stored in the platform generic union gbm_bo_handle type. However
+ * the format of this handle is platform specific.
+ *
+ * \param bo The buffer object
+ * \return Returns the stride of the allocated buffer object
+ */
 GBM_EXPORT union gbm_bo_handle
 gbm_bo_get_handle(struct gbm_bo *bo)
 {
    return bo->handle;
 }
 
+/**
+ * Destroys the given buffer object and frees all resources associated with
+ * it.
+ *
+ * \param bo The buffer object
+ */
 GBM_EXPORT void
 gbm_bo_destroy(struct gbm_bo *bo)
 {
    bo->gbm->bo_destroy(bo);
 }
 
+/**
+ * Allocate a buffer object for the given dimensions
+ *
+ * \param gbm The gbm device returned from gbm_create_device()
+ * \param width The width for the buffer
+ * \param height The height for the buffer
+ * \param format The format to use for the buffer
+ * \param usage The union of the usage flags for this buffer
+ *
+ * \return A newly allocated buffer that should be freed with gbm_bo_destroy()
+ * when no longer needed. If an error occurs during allocation %NULL will be
+ * returned.
+ *
+ * \sa enum gbm_bo_format for the list of formats
+ * \sa enum gbm_bo_flags for the list of usage flags
+ */
 GBM_EXPORT struct gbm_bo *
 gbm_bo_create(struct gbm_device *gbm,
               uint32_t width, uint32_t height,
@@ -176,6 +262,24 @@ gbm_bo_create(struct gbm_device *gbm,
    return gbm->bo_create(gbm, width, height, format, usage);
 }
 
+/**
+ * Create a buffer object representing the contents of an EGLImage
+ *
+ * \param gbm The gbm device returned from gbm_create_device()
+ * \param egl_dpy The EGLDisplay on which the EGLImage was created
+ * \param egl_image The EGLImage to create the buffer from
+ * \param width The width to use in the creation of the buffer object
+ * \param height The height to use in the creation of the buffer object
+ * \param usage The union of the usage flags for this buffer
+ *
+ * \return A newly allocated buffer object that should be freed with
+ * gbm_bo_destroy() when no longer needed.
+ *
+ * \sa enum gbm_bo_flags for the list of usage flags
+ *
+ * \note The expectation is that this function will use an efficient method
+ * for making the contents of the EGLImage available as a buffer object.
+ */
 GBM_EXPORT struct gbm_bo *
 gbm_bo_create_from_egl_image(struct gbm_device *gbm,
                              void *egl_dpy, void *egl_image,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 05d2292..c4ae51d 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -37,9 +37,28 @@ extern "C" {
 
 #include <stdint.h>
 
+/**
+ * \file gbm.h
+ * \brief Generic Buffer Manager
+ */
+
 struct gbm_device;
 struct gbm_bo;
 
+/**
+ * \mainpage The Generic Buffer Manager
+ *
+ * This module provides an abstraction that the caller can use to request a
+ * buffer from the underlying memory management system for the platform.
+ *
+ * This allows the creation of portable code whilst still allowing access to
+ * the underlying memory manager.
+ */
+
+/**
+ * Abstraction representing the handle to a buffer allocated by the
+ * manager
+ */
 union gbm_bo_handle {
    void *ptr;
    int32_t s32;
@@ -48,14 +67,36 @@ union gbm_bo_handle {
    uint64_t u64;
 };
 
+/** Format of the allocated buffer */
 enum gbm_bo_format {
-   GBM_BO_FORMAT_XRGB8888,
-   GBM_BO_FORMAT_ARGB8888,
+   /** RGB with 8 bits per channel in a 32 bit value */
+   GBM_BO_FORMAT_XRGB8888, 
+   /** ARGB with 8 bits per channel in a 32 bit value */
+   GBM_BO_FORMAT_ARGB8888
 };
 
+/**
+ * Flags to indicate the intended use for the buffer - these are passed into
+ * gbm_bo_create(). The caller must set the union of all the flags that are
+ * appropriate
+ *
+ * \sa Use gbm_device_is_format_supported() to check if the combination of format
+ * and use flags are supported
+ */
 enum gbm_bo_flags {
+   /**
+    * Buffer is going to be presented to the screen using an API such as KMS
+    */
    GBM_BO_USE_SCANOUT      = (1 << 0),
+   /**
+    * Buffer is going to be used as cursor - the dimensions for the buffer
+    * must be 64x64 if this flag is passed.
+    */
    GBM_BO_USE_CURSOR_64X64 = (1 << 1),
+   /**
+    * Buffer is to be used for rendering - for example it is going to be used
+    * as the storage for a color buffer
+    */
    GBM_BO_USE_RENDERING    = (1 << 2),
 };
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index fb8db80..9e4072e 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -38,6 +38,16 @@
 #define GBM_EXPORT
 #endif
 
+/**
+ * \file gbmint.h
+ * \brief Internal implementation details of gbm
+ */
+
+/**
+ * The device used for the memory allocation.
+ *
+ * The members of this structure should be not accessed directly
+ */
 struct gbm_device {
    /* Hack to make a gbm_device detectable by its first element. */
    struct gbm_device *(*dummy)(int);
@@ -63,6 +73,11 @@ struct gbm_device {
    void (*bo_destroy)(struct gbm_bo *bo);
 };
 
+/**
+ * The allocated buffer object.
+ *
+ * The members in this structure should not be accessed directly.
+ */
 struct gbm_bo {
    struct gbm_device *gbm;
    uint32_t width;
commit b0640785811f7f5d363e14e6be84717637a0b00d
Author: Scott Moreau <oreaus at gmail.com>
Date:   Tue Jan 17 10:36:12 2012 -0500

    Complete ARGB8888 naming convention format renames missed
    (cherry picked from commit e0897009f8fe8100204038e37f5555966300383a)

diff --git a/src/gallium/state_trackers/egl/wayland/native_shm.c b/src/gallium/state_trackers/egl/wayland/native_shm.c
index b76e5db..7d83e78 100644
--- a/src/gallium/state_trackers/egl/wayland/native_shm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_shm.c
@@ -94,11 +94,10 @@ wayland_create_shm_buffer(struct wayland_display *display,
 
    switch (surface->color_format) {
    case PIPE_FORMAT_B8G8R8A8_UNORM:
-      format = (surface->premultiplied_alpha) ?
-         WL_SHM_FORMAT_PREMULTIPLIED_ARGB32 : WL_SHM_FORMAT_ARGB32;
+      format = WL_SHM_FORMAT_ARGB8888;
       break;
    case PIPE_FORMAT_B8G8R8X8_UNORM:
-      format = WL_SHM_FORMAT_XRGB32;
+      format = WL_SHM_FORMAT_XRGB8888;
       break;
    default:
       return NULL;
@@ -116,7 +115,7 @@ shm_handle_format(void *data, struct wl_shm *shm, uint32_t format)
    struct wayland_shm_display *shmdpy = data;
 
    switch (format) {
-   case WL_SHM_FORMAT_ARGB32:
+   case WL_SHM_FORMAT_ARGB8888:
       shmdpy->base.formats |= HAS_ARGB8888;
       break;
    case WL_SHM_FORMAT_XRGB8888:
commit 252a1d863560fe47720910de9a852697ba1925f6
Author: Benjamin Franzke <benjaminfranzke at googlemail.com>
Date:   Tue Jan 24 14:35:34 2012 +0100

    st/mesa: Fix recurring surfaceless contexts
    
    A current incomplete framebuffer was incorrectly used as a
    st_framebuffer. When accessing st_framebuffer childs bad things happen:
    e.g. st_framebuffer::iface was used to check whether its an incomplete
    fb, instead we need to compare st_framebuffer::Base against
    mesa_get_incomplete_framebuffer.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44919
    Note: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit 36fb83e4a868e047521b3d5e0edc4d7a77a96aaf)

diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index b83cb23..4a30ef8 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -688,7 +688,9 @@ st_framebuffer_reuse_or_create(struct gl_framebuffer *fb,
 {
    struct st_framebuffer *cur = st_ws_framebuffer(fb), *stfb = NULL;
 
-   if (cur && cur->iface == stfbi) {
+   /* dummy framebuffers cant be used as st_framebuffer */
+   if (cur && &cur->Base != _mesa_get_incomplete_framebuffer() &&
+       cur->iface == stfbi) {
       /* reuse the current stfb */
       st_framebuffer_reference(&stfb, cur);
    }
@@ -779,7 +781,7 @@ st_manager_flush_frontbuffer(struct st_context *st)
       return;
 
    /* never a dummy fb */
-   assert(stfb->iface);
+   assert(&stfb->Base != _mesa_get_incomplete_framebuffer());
    stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT);
 }
 
commit 8e42dadf70ea2d359ef2c6d07a9a4da6d0b8e2da
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Jan 20 03:33:40 2012 -0800

    i965: Fix border color on Sandybridge and Ivybridge.
    
    While reading through the simulator, I found some interesting code that
    looks like it checks the sampler default color pointer against the bound
    set in STATE_BASE_ADDRESS.  On failure, it appears to program it to the
    base address itself.
    
    So I decided to try programming a legitimate bound, and lo and behold,
    border color worked.
    
    +92 piglits on Sandybridge.  Also fixes Lightsmark on Ivybridge.
    
    NOTE: This is a candidate for stable release branches.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=28924
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38868
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit c25e5300cba7628b58df93ead14ebc3cc32f338c)

diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index 8e59a47..1a7d328 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -769,7 +769,13 @@ static void upload_state_base_address( struct brw_context *brw )
 		 1); /* Instruction base address: shader kernels (incl. SIP) */
 
        OUT_BATCH(1); /* General state upper bound */
-       OUT_BATCH(1); /* Dynamic state upper bound */
+       /* Dynamic state upper bound.  Although the documentation says that
+	* programming it to zero will cause it to be ignored, that is a lie.
+	* If this isn't programmed to a real bound, the sampler border color
+	* pointer is rejected, causing border color to mysteriously fail.
+	*/
+       OUT_RELOC(intel->batch.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
+		 intel->batch.bo->size | 1);
        OUT_BATCH(1); /* Indirect object upper bound */
        OUT_BATCH(1); /* Instruction access upper bound */
        ADVANCE_BATCH();
commit 0b6003af71803db69a4911955026b93a552635e6
Author: Vinson Lee <vlee at freedesktop.org>
Date:   Mon Jan 16 18:01:22 2012 -0800

    glsl: Fix 'control reaches end of non-void function' warning.
    
    Fix this GCC warning on non-debug builds.
    glsl_types.cpp: In member function 'gl_texture_index
    glsl_type::sampler_index() const':
    glsl_types.cpp:157: warning: control reaches end of non-void function
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Vinson Lee <vlee at freedesktop.org>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit e9bcf4d56b8ae128204fb95693c6f81a6b724052)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index d4385a6..1489aae 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -147,12 +147,12 @@ glsl_type::sampler_index() const
       return TEXTURE_RECT_INDEX;
    case GLSL_SAMPLER_DIM_BUF:
       assert(!"FINISHME: Implement ARB_texture_buffer_object");
-      break;
+      return TEXTURE_BUFFER_INDEX;
    case GLSL_SAMPLER_DIM_EXTERNAL:
       return TEXTURE_EXTERNAL_INDEX;
    default:
       assert(!"Should not get here.");
-      break;
+      return TEXTURE_BUFFER_INDEX;
    }
 }
 
commit d8f66afa5d1cdb42677f5d170b99fa2ed9a1ef81
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Tue Jan 17 12:01:34 2012 -0800

    mesa: Loosen glBlitFramebuffer restrictions on depthstencil buffers (v2)
    
    This loosens the format validation in glBlitFramebuffer. When blitting
    depth bits, don't require an exact match between the depth formats; only
    require that the two formats have the same number of depth bits and the
    same depth datatype (float vs uint). Ditto for stencil.
    
    Between S8_Z24 buffers, the EXT_framebuffer_blit spec allows
    glBlitFramebuffer to blit the depth and stencil bits separately. So I see
    no reason to prevent blitting the depth bits between X8_Z24 and S8_Z24 or
    the stencil bits between S8 and S8_Z24. However, we of course don't want
    to allow blitting from Z32 to Z32_FLOAT.
    
    Fixes Piglit fbo/fbo-blit-d24s8 on Intel drivers with separate stencil
    enabled.
    
    The problem was that, on Intel drivers with separate stencil, the default
    framebuffer has separate depth and stencil buffers with formats X8_Z24 and
    S8. The test attempts to blit the depth bits from a S8_Z24 buffer into the
    default framebuffer.
    
    v2: Check that depth datatypes match.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44665
    Note: This is a candidate for the 8.0 branch.
    Reported-by: Xunx Fang <xunx.fang at intel.com>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit f74d8aacbf2f6d140381e272d17c31162a3481b3)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index e6bab4b..393b214 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -2728,9 +2728,13 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
       if ((readRb == NULL) || (drawRb == NULL)) {
 	 mask &= ~GL_STENCIL_BUFFER_BIT;
       }
-      else if (readRb->Format != drawRb->Format) {
+      else if (_mesa_get_format_bits(readRb->Format, GL_STENCIL_BITS) !=
+	       _mesa_get_format_bits(drawRb->Format, GL_STENCIL_BITS)) {
+	 /* There is no need to check the stencil datatype here, because
+	  * there is only one: GL_UNSIGNED_INT.
+	  */
          _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glBlitFramebufferEXT(stencil buffer format mismatch)");
+                     "glBlitFramebufferEXT(stencil buffer size mismatch)");
          return;
       }
    }
@@ -2750,7 +2754,10 @@ _mesa_BlitFramebufferEXT(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
       if ((readRb == NULL) || (drawRb == NULL)) {
 	 mask &= ~GL_DEPTH_BUFFER_BIT;
       }
-      else if (readRb->Format != drawRb->Format) {
+      else if ((_mesa_get_format_bits(readRb->Format, GL_DEPTH_BITS) !=
+	        _mesa_get_format_bits(drawRb->Format, GL_DEPTH_BITS)) ||
+	       (_mesa_get_format_datatype(readRb->Format) !=
+		_mesa_get_format_datatype(drawRb->Format))) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glBlitFramebufferEXT(depth buffer format mismatch)");
          return;
commit 09b6308a2deadd3b2ea7b11ec44cd0f437454d40
Author: Paul Berry <stereotype441 at gmail.com>
Date:   Tue Jan 17 10:28:10 2012 -0800

    glsl: Fix isinf() for non-C99-compliant compilers.
    
    Commit ede60bc4670a8d9c14921c77abee1ac57fc0e6bf (glsl: Add isinf() and
    isnan() builtins) uses "+INF" in the .ir file to represent infinity.
    This worked on C99-compliant compilers, since the s-expression reader
    uses strtod() to read numbers, and C99 requires strtod() to understand
    "+INF".  However, it didn't work on non-C99-compliant compilers such
    as MSVC.
    
    This patch modifies the s-expression reader to explicitly check for
    "+INF" rather than relying on strtod() to support it.
    
    This is a candidate for the 8.0 branch.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44767
    Tested-by: Morgan Armand <morgan.devel at gmail.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 4f82fed49359676fc19598f8c65ca51958dd2d79)

diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp
index e704a3b..57de9d3 100644
--- a/src/glsl/s_expression.cpp
+++ b/src/glsl/s_expression.cpp
@@ -23,6 +23,7 @@
  */
 
 #include <assert.h>
+#include <limits>
 #include "s_expression.h"
 
 s_symbol::s_symbol(const char *str, size_t n)
@@ -64,21 +65,28 @@ read_atom(void *ctx, const char *&src, char *&symbol_buffer)
    if (n == 0)
       return NULL; // no atom
 
-   // Check if the atom is a number.
-   char *float_end = NULL;
-   double f = glsl_strtod(src, &float_end);
-   if (float_end != src) {
-      char *int_end = NULL;
-      int i = strtol(src, &int_end, 10);
-      // If strtod matched more characters, it must have a decimal part
-      if (float_end > int_end)
-	 expr = new(ctx) s_float(f);
-      else
-	 expr = new(ctx) s_int(i);
+   // Check for the special symbol '+INF', which means +Infinity.  Note: C99
+   // requires strtod to parse '+INF' as +Infinity, but we still support some
+   // non-C99-compliant compilers (e.g. MSVC).
+   if (n == 4 && strncmp(src, "+INF", 4) == 0) {
+      expr = new(ctx) s_float(std::numeric_limits<float>::infinity());
    } else {
-      // Not a number; return a symbol.
-      symbol_buffer[n] = '\0';
-      expr = new(ctx) s_symbol(symbol_buffer, n);
+      // Check if the atom is a number.
+      char *float_end = NULL;
+      double f = glsl_strtod(src, &float_end);
+      if (float_end != src) {
+         char *int_end = NULL;
+         int i = strtol(src, &int_end, 10);
+         // If strtod matched more characters, it must have a decimal part
+         if (float_end > int_end)
+            expr = new(ctx) s_float(f);
+         else
+            expr = new(ctx) s_int(i);
+      } else {
+         // Not a number; return a symbol.
+         symbol_buffer[n] = '\0';
+         expr = new(ctx) s_symbol(symbol_buffer, n);
+      }
    }
 
    src += n;
commit 30e9bfd84ad64655a5ed0d1f84f5877cb3ae1b5a
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Jan 17 16:24:05 2012 -0800

    mesa: Set default access flags based on the run-time API
    
    The default access flags for OpenGL ES (via GL_OES_map_buffer) and
    desktop OpenGL are different.  The code previously tried to handle
    this, but the decision was made at compile time.  Since the same
    driver binary can be used for both OpenGL ES and desktop OpenGL, the
    decision must be made at run-time.
    
    This should fix bug #44433.  It appears that the test case does
    various map and unmap operations and inspects the state of the buffer
    object around each.  When it sees that GL_BUFFER_ACCESS does not match
    its expectations, it fails.
    
    NOTE: This is a candidate for release branches.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44433
    (cherry picked from commit f0ea46790f8f4df9a39b0cfab5c5f1bf02c136fc)

diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
index 03dd179..600f01c 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
@@ -72,7 +72,7 @@ intel_bufferobj_alloc(struct gl_context * ctx, GLuint name, GLenum target)
 {
    struct intel_buffer_object *obj = CALLOC_STRUCT(intel_buffer_object);
 
-   _mesa_initialize_buffer_object(&obj->Base, name, target);
+   _mesa_initialize_buffer_object(ctx, &obj->Base, name, target);
 
    obj->buffer = NULL;
 
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
index dc5b152..f7ad895 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
@@ -56,7 +56,7 @@ nouveau_bufferobj_new(struct gl_context *ctx, GLuint buffer, GLenum target)
 	if (!nbo)
 		return NULL;
 
-	_mesa_initialize_buffer_object(&nbo->base, buffer, target);
+	_mesa_initialize_buffer_object(ctx, &nbo->base, buffer, target);
 
 	return &nbo->base;
 }
diff --git a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
index 7b59c03..5abc52b 100644
--- a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
+++ b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
@@ -46,7 +46,7 @@ radeonNewBufferObject(struct gl_context * ctx,
 {
     struct radeon_buffer_object *obj = CALLOC_STRUCT(radeon_buffer_object);
 
-    _mesa_initialize_buffer_object(&obj->Base, name, target);
+    _mesa_initialize_buffer_object(ctx, &obj->Base, name, target);
 
     obj->bo = NULL;
 
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 5f8071f..5b6db78 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -49,13 +49,6 @@
 /*#define BOUNDS_CHECK*/
 
 
-#if FEATURE_OES_mapbuffer
-#define DEFAULT_ACCESS GL_MAP_WRITE_BIT
-#else
-#define DEFAULT_ACCESS (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)
-#endif
-
-
 /**
  * Used as a placeholder for buffer objects between glGenBuffers() and
  * glBindBuffer() so that glIsBuffer() can work correctly.
@@ -122,6 +115,30 @@ get_buffer(struct gl_context *ctx, GLenum target)
 }
 
 
+static inline GLenum
+default_access_mode(const struct gl_context *ctx)
+{
+   /* Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
+    *
+    * Name           Type  Initial Value  Legal Values
+    * ...            ...   ...            ...
+    * BUFFER_ACCESS  enum  READ_WRITE     READ_ONLY, WRITE_ONLY
+    *                                     READ_WRITE
+    *
+    * However, table 6.8 in the GL_OES_mapbuffer extension says:
+    *
+    * Get Value         Type Get Command          Value          Description
+    * ---------         ---- -----------          -----          -----------
+    * BUFFER_ACCESS_OES Z1   GetBufferParameteriv WRITE_ONLY_OES buffer map flag
+    *
+    * The difference is because GL_OES_mapbuffer only supports mapping buffers
+    * write-only.
+    */
+   return (ctx->API == API_OPENGLES)
+      ? GL_MAP_WRITE_BIT : (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
+}
+
+
 /**
  * Convert a GLbitfield describing the mapped buffer access flags
  * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
@@ -213,7 +230,7 @@ _mesa_new_buffer_object( struct gl_context *ctx, GLuint name, GLenum target )
    (void) ctx;
 
    obj = MALLOC_STRUCT(gl_buffer_object);
-   _mesa_initialize_buffer_object(obj, name, target);
+   _mesa_initialize_buffer_object(ctx, obj, name, target);
    return obj;
 }
 
@@ -311,7 +328,8 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
  * Initialize a buffer object to default values.
  */
 void
-_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
+_mesa_initialize_buffer_object( struct gl_context *ctx,
+				struct gl_buffer_object *obj,
 				GLuint name, GLenum target )
 {
    (void) target;
@@ -321,7 +339,7 @@ _mesa_initialize_buffer_object( struct gl_buffer_object *obj,
    obj->RefCount = 1;
    obj->Name = name;
    obj->Usage = GL_STATIC_DRAW_ARB;
-   obj->AccessFlags = DEFAULT_ACCESS;
+   obj->AccessFlags = default_access_mode(ctx);
 }
 
 
@@ -740,7 +758,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids)
          if (_mesa_bufferobj_mapped(bufObj)) {
             /* if mapped, unmap it now */
             ctx->Driver.UnmapBuffer(ctx, bufObj);
-            bufObj->AccessFlags = DEFAULT_ACCESS;
+            bufObj->AccessFlags = default_access_mode(ctx);
             bufObj->Pointer = NULL;
          }
 
@@ -900,7 +918,7 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size,
    if (_mesa_bufferobj_mapped(bufObj)) {
       /* Unmap the existing buffer.  We'll replace it now.  Not an error. */
       ctx->Driver.UnmapBuffer(ctx, bufObj);
-      bufObj->AccessFlags = DEFAULT_ACCESS;
+      bufObj->AccessFlags = default_access_mode(ctx);
       ASSERT(bufObj->Pointer == NULL);
    }  
 
@@ -1119,7 +1137,7 @@ _mesa_UnmapBufferARB(GLenum target)
 #endif
 
    status = ctx->Driver.UnmapBuffer( ctx, bufObj );
-   bufObj->AccessFlags = DEFAULT_ACCESS;
+   bufObj->AccessFlags = default_access_mode(ctx);
    ASSERT(bufObj->Pointer == NULL);
    ASSERT(bufObj->Offset == 0);
    ASSERT(bufObj->Length == 0);
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index c0d5a64..a7ce379 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -71,7 +71,8 @@ extern struct gl_buffer_object *
 _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer);
 
 extern void
-_mesa_initialize_buffer_object( struct gl_buffer_object *obj,
+_mesa_initialize_buffer_object( struct gl_context *ctx,
+				struct gl_buffer_object *obj,
 				GLuint name, GLenum target );
 
 extern void
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 6d95d57..6534a43 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -58,7 +58,7 @@ st_bufferobj_alloc(struct gl_context *ctx, GLuint name, GLenum target)
    if (!st_obj)
       return NULL;
 
-   _mesa_initialize_buffer_object(&st_obj->Base, name, target);
+   _mesa_initialize_buffer_object(ctx, &st_obj->Base, name, target);
 
    return &st_obj->Base;
 }
commit aa00ccdc0285a65c1162b0819cbabae1689827f1
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jan 18 00:55:12 2012 -0800

    i965: Fix disassembly of data port writes on Ivybridge.
    
    msg_type moved by a bit, so the message type was being disassembled
    incorrectly.  In particular, render target writes were showing up as
    "OWORD block write".
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit dcdfd1905c8012fe0a90e553f2a894c12cf144cf)

diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index 02fa14c..a86c8f2 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -1029,7 +1029,18 @@ int brw_disasm (FILE *file, struct brw_instruction *inst, int gen)
 	    break;
 
 	case BRW_SFID_DATAPORT_WRITE:
-	    if (gen >= 6) {
+	    if (gen >= 7) {
+		format (file, " (");
+
+		err |= control (file, "DP rc message type",
+				dp_rc_msg_type_gen6,
+				inst->bits3.gen7_dp.msg_type, &space);
+
+		format (file, ", %d, %d, %d)",
+			inst->bits3.gen7_dp.binding_table_index,
+			inst->bits3.gen7_dp.msg_control,
+			inst->bits3.gen7_dp.msg_type);
+	    } else if (gen == 6) {
 		format (file, " (");
 
 		err |= control (file, "DP rc message type",
commit a62a4f77e8bbe4a66670d65a8a3707f78272dfd1
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jan 18 00:50:31 2012 -0800

    i965: Fix disassembly of sampler messages on Ivybridge.
    
    Compared to sampler_gen5, simd_mode shifted by a bit and msg_type grew
    by a bit.  So we were printing slightly incorrect numbers.
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit a608be5d3333244f5357c459135b17b4c2298e18)

diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index cfea1a3..02fa14c 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -982,7 +982,13 @@ int brw_disasm (FILE *file, struct brw_instruction *inst, int gen)
 			    inst->bits3.math.precision, &space);
 	    break;
 	case BRW_SFID_SAMPLER:
-	    if (gen >= 5) {
+	    if (gen >= 7) {
+		format (file, " (%d, %d, %d, %d)",
+			inst->bits3.sampler_gen7.binding_table_index,
+			inst->bits3.sampler_gen7.sampler,
+			inst->bits3.sampler_gen7.msg_type,
+			inst->bits3.sampler_gen7.simd_mode);
+	    } else if (gen >= 5) {
 		format (file, " (%d, %d, %d, %d)",
 			inst->bits3.sampler_gen5.binding_table_index,
 			inst->bits3.sampler_gen5.sampler,
commit 2fae4d26f3b55c59ad7a2b7f1e958933b7f7c7e7
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Jan 18 04:53:40 2012 -0800

    i965/vs: Take attributes into account when deciding urb_entry_size.
    
    Both the VF and VS share space in the URB.  First, the VF stores
    attributes (shader inputs) there.  The VS then reads the attributes,
    executes, and reuses the space to store varyings (shader outputs).
    
    Thus, we need to calculate the amount of URB space necessary for inputs,
    outputs, and pick whichever is greater.
    
    The old VS backend correctly did this (brw_vs_emit.c:408), but the new
    VS backend only considered outputs.
    
    Fixes vertex scrambling in GLBenchmark PRO on Ivybridge.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41318
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 2e712e41db0c0676e9f30fc73172c0e8de8d84d4)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
index a618614..dbe4dd0 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
@@ -25,6 +25,7 @@
 
 extern "C" {
 #include "brw_eu.h"
+#include "main/macros.h"
 };
 
 using namespace brw;
@@ -95,6 +96,13 @@ vec4_visitor::setup_attributes(int payload_reg)
 
    prog_data->urb_read_length = (nr_attributes + 1) / 2;
 
+   unsigned vue_entries = MAX2(nr_attributes, c->vue_map.num_slots);
+
+   if (intel->gen == 6)
+      c->prog_data.urb_entry_size = ALIGN(vue_entries, 8) / 8;
+   else
+      c->prog_data.urb_entry_size = ALIGN(vue_entries, 4) / 4;
+
    return payload_reg + nr_attributes;
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index ecabcc8..06bde92 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -2286,11 +2286,6 @@ vec4_visitor::emit_urb_writes()
        */
       inst->offset = (max_usable_mrf - base_mrf) / 2;
    }
-
-   if (intel->gen == 6)
-      c->prog_data.urb_entry_size = ALIGN(c->vue_map.num_slots, 8) / 8;
-   else
-      c->prog_data.urb_entry_size = ALIGN(c->vue_map.num_slots, 4) / 4;
 }
 
 src_reg
commit 759da0cb564ba6f765fc86f6ab207f35a224ebc2
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Jan 17 12:41:15 2012 -0800

    intel: Set depth to 6 for cubemaps
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41216
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43212
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43250
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Cc: Jin Yang <jin.a.yang at intel.com>
    (cherry picked from commit 8a472427559ea33186c71dfbab8254651fec3077)

diff --git a/src/mesa/drivers/dri/i915/i915_tex_layout.c b/src/mesa/drivers/dri/i915/i915_tex_layout.c
index caa7127..1e3cfad 100644
--- a/src/mesa/drivers/dri/i915/i915_tex_layout.c
+++ b/src/mesa/drivers/dri/i915/i915_tex_layout.c
@@ -129,7 +129,7 @@ i915_miptree_layout_cube(struct intel_mipmap_tree * mt)
       intel_miptree_set_level_info(mt, level,
 				   0, 0,
 				   lvlWidth, lvlHeight,
-				   1);
+				   6);
       lvlWidth /= 2;
       lvlHeight /= 2;
    }
@@ -337,7 +337,7 @@ i945_miptree_layout_cube(struct intel_mipmap_tree * mt)
    for (level = mt->first_level; level <= mt->last_level; level++) {
       intel_miptree_set_level_info(mt, level,
 				   0, 0,
-				   lvlWidth, lvlHeight, 1);
+				   lvlWidth, lvlHeight, 6);
       lvlWidth /= 2;
       lvlHeight /= 2;
    }
diff --git a/src/mesa/drivers/dri/i965/brw_tex_layout.c b/src/mesa/drivers/dri/i965/brw_tex_layout.c
index 4c7e88c..7a1b91f 100644
--- a/src/mesa/drivers/dri/i965/brw_tex_layout.c
+++ b/src/mesa/drivers/dri/i965/brw_tex_layout.c
@@ -77,6 +77,7 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
 	 brw_miptree_layout_texture_array(intel, mt);
 	 break;
       }
+      assert(mt->depth0 == 6);
       /* FALLTHROUGH */
 
    case GL_TEXTURE_3D: {
@@ -101,7 +102,6 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
       pack_x_nr = 1;
 
       for (level = mt->first_level ; level <= mt->last_level ; level++) {
-	 GLuint nr_images = mt->target == GL_TEXTURE_3D ? depth : 6;
 	 GLint x = 0;
 	 GLint y = 0;
 	 GLint q, j;
@@ -110,8 +110,8 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
 				      0, mt->total_height,
 				      width, height, depth);
 
-	 for (q = 0; q < nr_images;) {
-	    for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
+	 for (q = 0; q < depth; /* empty */) {
+	    for (j = 0; j < pack_x_nr && q < depth; j++, q++) {
 	       intel_miptree_set_image_offset(mt, level, q, x, y);
 	       x += pack_x_pitch;
 	    }
commit 4dbc544bb1e3a15653c0e1fd67c4fd477314c251
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Nov 17 17:11:00 2011 -0800

    i965: Add support for Z16 depth formats.
    
    This is a squash of the following two commits.  The first caused a
    regression on SNB systems without a HiZ capable DDX, and the second
    fixes that regression.
    
        i965: Add support for Z16 depth formats.
    
        v2: Don't flag the format as being HiZ ready (there's DRI2 handshake
            pain to go through).
    
        Fixes piglit gl-3.0-required-sized-texture-formats
    
        NOTE: This is a candidate for the 8.0 branch.
    
        Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
        Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
        (cherry picked from commit 2f868f1ddd636bc8d4cbcd5beeef1246cec80c65)
    
        intel/gen6: Some framebuffers having separate depthstencil should be unsupported
    
        When the framebuffer has separate depth and stencil buffers, and HiZ is
        not enabled on the depth buffer, mark the framebuffer as unsupported. This
        happens when trying to create a framebuffer with Z16/S8 because we haven't
        enabled HiZ on Z16 yet.
    
        Fixes gles2conform test stencil8.
    
        Note: This is a candiate for the 8.0 branch.
        Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44948
        Reviewed-and-tested-by: Ian Romanick <ian.d.romanick at intel.com>
        Reviewed--by: Eric Anholt <eric at anholt.net>
        Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
        (cherry picked from commit ba5252e590782a77b8a46d9c0ec4691cf8da6298)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index b40f5e1..b7454b0 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -553,6 +553,7 @@ brw_init_surface_formats(struct brw_context *brw)
    ctx->TextureFormatSupported[MESA_FORMAT_X8_Z24] = true;
    ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT] = true;
    ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT_X24S8] = true;
+   ctx->TextureFormatSupported[MESA_FORMAT_Z16] = true;
 }
 
 bool
diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index c37075c..45a6827 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -804,6 +804,15 @@ intel_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 	    fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
 	 if (stencil_mt->format != MESA_FORMAT_S8)
 	    fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
+	 if (intel->gen < 7 && depth_mt->hiz_mt == NULL) {
+	    /* Before Gen7, separate depth and stencil buffers can be used
+	     * only if HiZ is enabled. From the Sandybridge PRM, Volume 2,
+	     * Part 1, Bit 3DSTATE_DEPTH_BUFFER.SeparateStencilBufferEnable:
+	     *     [DevSNB]: This field must be set to the same value (enabled
+	     *     or disabled) as Hierarchical Depth Buffer Enable.
+	     */
+	    fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
+	 }
       }
    }
 
commit c256fd094b433fdd955c35f66ad4794a4017b65f
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 17 11:28:56 2012 -0800

    i965/gen7: Set up surface horizontal alignment field.
    
    This is required for Z16 support for texturing, which is the first
    thing to have a horizontal alignment of 8.  Renderbuffers don't need
    it, since they're always set up as the only mip level, but do it for
    completeness anyway.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit f0d5c92a4c9d5057d727819e501d80c5dfcdf76e)

diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index 1c6f662..940b294 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -74,6 +74,8 @@ gen7_update_texture_surface(struct gl_context *ctx, GLuint unit)
 
    if (mt->align_h == 4)
       surf->ss0.vertical_alignment = 1;
+   if (mt->align_w == 8)
+      surf->ss0.horizontal_alignment = 1;
 
    surf->ss0.surface_type = translate_tex_target(tObj->Target);
    surf->ss0.surface_format = translate_tex_format(mt->format,
@@ -94,7 +96,6 @@ gen7_update_texture_surface(struct gl_context *ctx, GLuint unit)
    gen7_set_surface_tiling(surf, intelObj->mt->region->tiling);
 
    /* ss0 remaining fields:
-    * - horizontal_alignment
     * - vert_line_stride (exists on gen6 but we ignore it)
     * - vert_line_stride_ofs (exists on gen6 but we ignore it)
     * - surface_array_spacing
@@ -206,6 +207,8 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
 
    if (irb->mt->align_h == 4)
       surf->ss0.vertical_alignment = 1;
+   if (irb->mt->align_w == 8)
+      surf->ss0.horizontal_alignment = 1;
 
    switch (irb->Base.Format) {
    case MESA_FORMAT_SARGB8:
commit f0662ee6095b8c35e7788882c84f7c276c4bde3a
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jan 17 11:27:11 2012 -0800

    i965/gen7: Remove stale comment.
    
    This field is actually set up above.
    
    NOTE: This is a candidate for the 8.0 branch, to avoid conflicts.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit fc767ff59056a418a1c573261f0d04a329278ee8)

diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index 1c0183b..1c6f662 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -94,7 +94,6 @@ gen7_update_texture_surface(struct gl_context *ctx, GLuint unit)
    gen7_set_surface_tiling(surf, intelObj->mt->region->tiling);
 
    /* ss0 remaining fields:
-    * - vertical_alignment
     * - horizontal_alignment
     * - vert_line_stride (exists on gen6 but we ignore it)
     * - vert_line_stride_ofs (exists on gen6 but we ignore it)
commit 99c0aeb3db39f10d53fab6ee88d08ea91f8a6550
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 13:16:33 2012 -0800

    glsl: Fix leak of linked uniform names at relink/free of the shader_program.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit aad3a46ff453d33cb3df909903d261f67b452d31)

diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index 02f57d9..d51850c 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -287,7 +287,7 @@ private:
 	 this->uniforms[id].sampler = ~0;
       }
 
-      this->uniforms[id].name = strdup(name);
+      this->uniforms[id].name = ralloc_strdup(this->uniforms, name);
       this->uniforms[id].type = base_type;
       this->uniforms[id].initialized = 0;
       this->uniforms[id].num_driver_storage = 0;
commit 7861ccbe238033614d9c96caab24b5bbfce8fe06
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 13:10:26 2012 -0800

    glsl: Fix leak of LinkedTransformFeedback.Varyings.
    
    I copy-and-pasted the thing I was allocating for as the context, so
    the first time it would be NULL (root of a ralloc context) and they'd
    chain off each other from then on.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 5a0f395bcf70e524492e766a07cf0b816b42a20d)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 47fbb5a..5095751 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1989,7 +1989,7 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
       separate_attribs_mode ? num_tfeedback_decls : 1;
 
    prog->LinkedTransformFeedback.Varyings =
-      rzalloc_array(prog->LinkedTransformFeedback.Varyings,
+      rzalloc_array(prog,
 		    struct gl_transform_feedback_varying_info,
 		    num_tfeedback_decls);
 
commit bffefc3d27c74dc25987405c6f94d7bc7f67acf6
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 13:08:22 2012 -0800

    mesa: Fix leak of uniform storage records on shader program link/free.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 0f68d88034a9815445ae0a35aacc500f82f33a18)

diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index de66851..36f208d 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -35,6 +35,7 @@
 #include "main/mfeatures.h"
 #include "main/mtypes.h"
 #include "main/shaderobj.h"
+#include "main/uniforms.h"
 #include "program/program.h"
 #include "program/prog_parameter.h"
 #include "program/hash_table.h"
@@ -276,6 +277,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx,
                                 struct gl_shader_program *shProg)
 {
    if (shProg->UniformStorage) {
+      _mesa_uniform_detach_all_driver_storage(shProg->UniformStorage);
       ralloc_free(shProg->UniformStorage);
       shProg->NumUserUniformStorage = 0;
       shProg->UniformStorage = NULL;
commit 531948947e39225d42967521a4bb479f6be5ab72
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 13:01:21 2012 -0800

    i965: Fix leak of the program cache BO on context destroy.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit cbd464a117317f276b65cbca69d6339166581bf7)

diff --git a/src/mesa/drivers/dri/i965/brw_state_cache.c b/src/mesa/drivers/dri/i965/brw_state_cache.c
index 3988625..4ae8e12 100644
--- a/src/mesa/drivers/dri/i965/brw_state_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_state_cache.c
@@ -386,6 +386,8 @@ brw_destroy_cache(struct brw_context *brw, struct brw_cache *cache)
 
    DBG("%s\n", __FUNCTION__);
 
+   drm_intel_bo_unreference(cache->bo);
+   cache->bo = NULL;
    brw_clear_cache(brw, cache);
    free(cache->items);
    cache->items = NULL;
commit decf80c621af1e5ce8c923bf073802e0e23b0662
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 12:59:15 2012 -0800

    i965/vs: Fix leak of an empty hash_table structure per compile.
    
    This statement got duplicated above, probably in a rebase resolution,
    so we never freed the extra one.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 7f278e15ad271daaa08dd2fef84cca5e344d5771)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 5df2470..ecabcc8 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -2601,10 +2601,6 @@ vec4_visitor::vec4_visitor(struct brw_vs_compile *c,
    this->live_intervals_valid = false;
 
    this->uniforms = 0;
-
-   this->variable_ht = hash_table_ctor(0,
-				       hash_table_pointer_hash,
-				       hash_table_pointer_compare);
 }
 
 vec4_visitor::~vec4_visitor()
commit 812a8eade5f8e25bdbea95d7c1e6e8b42af07d79
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 12:55:06 2012 -0800

    i965: Fix refcount leak of the gl_program structure.
    
    Fixes a leak of almost 200kb on a minimal shader_runner program
    (algebraic-add-add-1).
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit b2be4869624443cd9769bd696b11dd587494b62a)

diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index ef0f09d..aa1bfdb 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -229,6 +229,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
        * program constant) has to happen before creating this linkage.
        */
       _mesa_associate_uniform_storage(ctx, shProg, prog->Parameters);
+
+      _mesa_reference_program(ctx, &prog, NULL);
    }
 
    if (!brw_shader_precompile(ctx, shProg))
commit 230f6e7ddc643e3c1aade95bf6e1934e3dff9061
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 12:51:34 2012 -0800

    mesa: Make the register allocator allocation take a ralloc context.
    
    This fixes a memory leak on i965 context destruction.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit b972744c78e45928876ea781b9eeef09b3baf083)

diff --git a/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c b/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c
index 30716a3..bb5b43f 100644
--- a/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c
+++ b/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c
@@ -547,7 +547,7 @@ static void do_advanced_regalloc(struct regalloc_state * s)
 	struct ra_graph * graph;
 
 	/* Allocate the main ra data structure */
-	regs = ra_alloc_reg_set(s->C->max_temp_regs * RC_MASK_XYZW);
+	regs = ra_alloc_reg_set(NULL, s->C->max_temp_regs * RC_MASK_XYZW);
 
 	/* Get list of program variables */
 	variables = rc_get_variables(s->C);
diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
index 3f875cc..d4dd124 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
@@ -88,7 +88,7 @@ brw_alloc_reg_set_for_classes(struct brw_context *brw,
    ralloc_free(brw->wm.ra_reg_to_grf);
    brw->wm.ra_reg_to_grf = ralloc_array(brw, uint8_t, ra_reg_count);
    ralloc_free(brw->wm.regs);
-   brw->wm.regs = ra_alloc_reg_set(ra_reg_count);
+   brw->wm.regs = ra_alloc_reg_set(brw, ra_reg_count);
    ralloc_free(brw->wm.classes);
    brw->wm.classes = ralloc_array(brw, int, class_count + 1);
 
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
index 1ace91f..2efe235 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
@@ -108,7 +108,7 @@ brw_alloc_reg_set_for_classes(struct brw_context *brw,
    ralloc_free(brw->vs.ra_reg_to_grf);
    brw->vs.ra_reg_to_grf = ralloc_array(brw, uint8_t, ra_reg_count);
    ralloc_free(brw->vs.regs);
-   brw->vs.regs = ra_alloc_reg_set(ra_reg_count);
+   brw->vs.regs = ra_alloc_reg_set(brw, ra_reg_count);
    ralloc_free(brw->vs.classes);
    brw->vs.classes = ralloc_array(brw, int, class_count + 1);
 
diff --git a/src/mesa/program/register_allocate.c b/src/mesa/program/register_allocate.c
index f5b5174..f08c9d2 100644
--- a/src/mesa/program/register_allocate.c
+++ b/src/mesa/program/register_allocate.c
@@ -154,13 +154,19 @@ struct ra_graph {
    unsigned int stack_count;
 };
 
+/**
+ * Creates a set of registers for the allocator.
+ *
+ * mem_ctx is a ralloc context for the allocator.  The reg set may be freed
+ * using ralloc_free().
+ */
 struct ra_regs *
-ra_alloc_reg_set(unsigned int count)
+ra_alloc_reg_set(void *mem_ctx, unsigned int count)
 {
    unsigned int i;
    struct ra_regs *regs;
 
-   regs = rzalloc(NULL, struct ra_regs);
+   regs = rzalloc(mem_ctx, struct ra_regs);
    regs->count = count;
    regs->regs = rzalloc_array(regs, struct ra_reg, count);
 
diff --git a/src/mesa/program/register_allocate.h b/src/mesa/program/register_allocate.h
index ee2e58a..00b851e 100644
--- a/src/mesa/program/register_allocate.h
+++ b/src/mesa/program/register_allocate.h
@@ -36,7 +36,7 @@ struct ra_regs;
  * registers, such as aligned register pairs that conflict with the
  * two real registers from which they are composed.
  */
-struct ra_regs *ra_alloc_reg_set(unsigned int count);
+struct ra_regs *ra_alloc_reg_set(void *mem_ctx, unsigned int count);
 unsigned int ra_alloc_reg_class(struct ra_regs *regs);
 void ra_add_reg_conflict(struct ra_regs *regs,
 			 unsigned int r1, unsigned int r2);
commit 655b36d1d563abc17a5339886c313f358fa70b00
Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 17 08:12:30 2012 -0700

    mesa: use GL_MAP_INVALIDATE_RANGE_BIT in glTexImage paths
    
    Update the dd.h docs to indicate that GL_MAP_INVALIDATE_RANGE_BIT
    can be used with GL_MAP_WRITE_BIT when mapping renderbuffers and
    texture images.
    
    Pass the flag when mapping texture images for glTexImage, glTexSubImage,
    etc.  It's up to drivers whether to actually make use of the flag.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 64fdfefb9d1136c5f98f3e3b2ba716c224a4d792)

diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 24f3d4c..8393f32 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -460,7 +460,8 @@ struct dd_function_table {
     * \param texImage  the texture image
     * \param slice  the 3D image slice or array texture slice
     * \param x, y, w, h  region of interest
-    * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
+    * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT and
+    *              GL_MAP_INVALIDATE_RANGE_BIT (if writing)
     * \param mapOut  returns start of mapping of region of interest
     * \param rowStrideOut  returns row stride (in bytes)
     */
@@ -489,6 +490,11 @@ struct dd_function_table {
                                     GLsizei levels, GLsizei width,
                                     GLsizei height, GLsizei depth);
 
+   /**
+    * Map a renderbuffer into user space.
+    * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT and
+    *              GL_MAP_INVALIDATE_RANGE_BIT (if writing)
+    */
    void (*MapRenderbuffer)(struct gl_context *ctx,
 			   struct gl_renderbuffer *rb,
 			   GLuint x, GLuint y, GLuint w, GLuint h,
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index a9c64ce..600dab3 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -4404,7 +4404,7 @@ get_read_write_mode(GLenum userFormat, gl_format texFormat)
        && _mesa_get_format_base_format(texFormat) == GL_DEPTH_STENCIL)
       return GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
    else
-      return GL_MAP_WRITE_BIT;
+      return GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT;
 }
 
 
@@ -4805,7 +4805,7 @@ _mesa_store_compressed_texsubimage2d(struct gl_context *ctx,
    /* Map dest texture buffer */
    ctx->Driver.MapTextureImage(ctx, texImage, 0,
                                xoffset, yoffset, width, height,
-                               GL_MAP_WRITE_BIT,
+                               GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT,
                                &dstMap, &dstRowStride);
 
    if (dstMap) {
commit 7a11d201e71cc519f5290bc5e399d65e4d5bb65d
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 10:08:08 2012 -0700

    mesa: try RGBA_FLOAT16 before RGBA_FLOAT32 when choosing A,L,LA,I formats
    
    To try to use less tex memory and maybe get better performance.
    Spotted by Roland Scheidegger.
    
    NOTE: This is a candidate for the 8.0 and 7.11 branches.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 1d7048f12e7e2e8f42d27aa665f7134f8f10cf4e)

diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index d393873..259eb90 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -323,6 +323,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
          case GL_ALPHA16F_ARB:
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
+	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
 	    break;
          case GL_ALPHA32F_ARB:
@@ -334,6 +335,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
          case GL_LUMINANCE16F_ARB:
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
+	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
 	    break;
          case GL_LUMINANCE32F_ARB:
@@ -345,6 +347,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
          case GL_LUMINANCE_ALPHA16F_ARB:
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
+	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
 	    break;
          case GL_LUMINANCE_ALPHA32F_ARB:
@@ -356,6 +359,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
          case GL_INTENSITY16F_ARB:
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
+	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
 	    break;
          case GL_INTENSITY32F_ARB:
commit dd73100c248341383c9e90c5bb273ac224fc10ac
Author: Brian Paul <brianp at vmware.com>
Date:   Mon Jan 16 09:05:05 2012 -0700

    mesa: fix tex format selection for GL_R32F and other R/G float formats
    
    The i965 driver advertises GL_ARB_texture_float and GL_ARB_texture_rg
    support but the ctx->TextureFormatSupported[] table entries for
    MESA_FORMAT_R_FLOAT32 and MESA_FORMAT_RGBA_FLOAT32 are false on gen 4
    hardware.  So the case for GL_R32F would fail and we'd print an
    implementation error.
    
    This patch adds more Mesa tex format options for GL_R32F and other R/G
    formats so we fall back to 16-bit formats when 32-bit formats aren't
    available.
    
    Eric made the same fix in commit 6216a5b4 for the non R/G formats.
    
    v2: try 16-bit formats before 32-bit formats and try RG formats before
    RGBA where possible.
    
    This should fix https://bugs.freedesktop.org/show_bug.cgi?id=44039
    
    NOTE: This is a candidate for the 8.0 and 7.11 branches.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    Reviewed-by: Roland Scheidegger <sroland at vmware.com>
    (cherry picked from commit 7628696004515074594d4fdac4e422c81c86b32c)

diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 7e60541..d393873 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -786,21 +786,31 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       switch (internalFormat) {
       case GL_R16F:
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
 	 break;
       case GL_R32F:
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	 break;
       case GL_RG16F:
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
 	 break;
       case GL_RG32F:
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
+	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
 	 break;
 
       default:
commit 5f25e0a39cb5111c1d36813a28ee283db683ae07
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Jan 17 08:08:25 2012 -0800

    i965: Bump Ivybridge's fake MRF range to g112-127 instead of g111-126.
    
    When I originally implemented the hack to use GRFs 111+ as fake MRFs, I
    did so purely to avoid rewriting all the code that dealt with MRFs.
    However, it turns out that a similar hack is actually required.
    
    Newly discovered language in the BSpec indicates that SEND instructions
    with EOT set "should" use g112-g127 as their source registers.  Based on
    assertions in the simulator, this is actually a requirement on certain
    platforms.
    
    Since we're faking MRFs already, we may as well use the officially
    sanctioned range.  My guess is that we avoided this issue because we
    seldom use m0: URB writes in the new VS backend start at m1, and RT
    writes in the new FS backend start at m2.
    
    NOTE: This is a candidate for stable release branches.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 5acc7f38d42859db459567d4442c18764a4072e7)

diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c
index 1f4afa0..d8ea06f 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c
@@ -84,10 +84,18 @@ gen6_resolve_implied_move(struct brw_compile *p,
 static void
 gen7_convert_mrf_to_grf(struct brw_compile *p, struct brw_reg *reg)
 {
+   /* From the BSpec / ISA Reference / send - [DevIVB+]:
+    * "The send with EOT should use register space R112-R127 for <src>. This is
+    *  to enable loading of a new thread into the same slot while the message
+    *  with EOT for current thread is pending dispatch."
+    *
+    * Since we're pretending to have 16 MRFs anyway, we may as well use the
+    * registers required for messages with EOT.
+    */
    struct intel_context *intel = &p->brw->intel;
    if (intel->gen == 7 && reg->file == BRW_MESSAGE_REGISTER_FILE) {
       reg->file = BRW_GENERAL_REGISTER_FILE;
-      reg->nr += 111;
+      reg->nr += 112;
    }
 }
 
commit f48e6748a719968dd0b959c00f3d89eb7d4c6e82
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Tue Jan 17 13:21:52 2012 -0800

    intel: Return if pointer to intel_context is null
    
    It is better to test if(intel == NULL) and simply return in that case.
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit ce1c949b162260cec84431913f7aac83cb1b938e)

diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index a08f3d1..0566907 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -114,16 +114,16 @@ intelDRI2Flush(__DRIdrawable *drawable)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct intel_context *intel = intel_context(ctx);
+   if (intel == NULL)
+      return;
 
-   if (intel != NULL) {
-      if (intel->gen < 4)
-	 INTEL_FIREVERTICES(intel);
+   if (intel->gen < 4)
+      INTEL_FIREVERTICES(intel);
 
-      intel->need_throttle = true;
+   intel->need_throttle = true;
 
-      if (intel->batch.used)
-	 intel_batchbuffer_flush(intel);
-   }
+   if (intel->batch.used)
+      intel_batchbuffer_flush(intel);
 }
 
 static const struct __DRI2flushExtensionRec intelFlushExtension = {
commit 68a9cd6fa1854709e17e171be14ad70de0c69e7b
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 14:32:50 2012 -0800

    intel: Fix warnings of undefined ffs().
    
    For some reason these started showing up with the automake conversion.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit ccf0d31a210baf062dcc0e0c19527cdbbade0ac9)

diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index 9fb2902..e673a4e 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -30,6 +30,7 @@
 
 
 #include <stdbool.h>
+#include <string.h>
 #include "main/mtypes.h"
 #include "main/mm.h"
 
commit 907495465a7cb32881967c8b87759c4e59dd0935
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Fri Jan 13 10:26:01 2012 -0800

    i965: Comment gen6_hiz_get_framebuffer_enum()
    
    Make the comments precise. Explain why each branch is needed and correct.
    Document the potential pitfall in the true-branch.
    
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit e13c99a0043854cb286c773faa891a3115cd0a68)

diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.c b/src/mesa/drivers/dri/i965/gen6_hiz.c
index 92b1d61..4d36729 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.c
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.c
@@ -114,14 +114,16 @@ gen6_hiz_get_framebuffer_enum(struct gl_context *ctx,
                               GLenum *bind_enum,
                               GLenum *get_enum)
 {
-   /* If the blit framebuffer extension isn't supported then Mesa will
-      report an error if we try to bind GL_DRAW_FRAMEBUFFER. However in
-      that case it should be safe to just save and restore
-      GL_FRAMEBUFFER instead. */
    if (ctx->Extensions.EXT_framebuffer_blit && ctx->API == API_OPENGL) {
+      /* Different buffers may be bound to GL_DRAW_FRAMEBUFFER and
+       * GL_READ_FRAMEBUFFER. Take care to not disrupt the read buffer.
+       */
       *bind_enum = GL_DRAW_FRAMEBUFFER;
       *get_enum = GL_DRAW_FRAMEBUFFER_BINDING;
    } else {
+      /* The enums GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER do not exist.
+       * The bound framebuffer is both the read and draw buffer.
+       */
       *bind_enum = GL_FRAMEBUFFER;
       *get_enum = GL_FRAMEBUFFER_BINDING;
    }
commit daf5ee5ef121c48fd8cddb75187211521c58032f
Author: Christoph Bumiller <e0425955 at student.tuwien.ac.at>
Date:   Fri Jan 20 13:43:32 2012 +0100

    nvc0: fix some limit cap values
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit ab69d584f923101fab05560b8e9ff97cf3cc2c5f)

diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c
index a991e67..f9ad39d 100644
--- a/src/gallium/drivers/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nvc0/nvc0_screen.c
@@ -69,15 +69,14 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
 {
    switch (param) {
    case PIPE_CAP_MAX_COMBINED_SAMPLERS:
-      return 64;
+      return 16 * PIPE_SHADER_TYPES; /* NOTE: should not count COMPUTE */
    case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
-      return 13;
-   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
-      return 10;
    case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
-      return 13;
+      return 15;
+   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
+      return 12;
    case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
-      return 8192;
+      return 2048;
    case PIPE_CAP_MIN_TEXEL_OFFSET:
       return -8;
    case PIPE_CAP_MAX_TEXEL_OFFSET:
@@ -167,7 +166,9 @@ nvc0_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
    case PIPE_SHADER_CAP_MAX_INPUTS:
       if (shader == PIPE_SHADER_VERTEX)
          return 32;
-      return 0x300 / 16;
+      if (shader == PIPE_SHADER_FRAGMENT)
+         return (0x200 + 0x20 + 0x80) / 16; /* generic + colors + TexCoords */
+      return (0x200 + 0x40 + 0x80) / 16; /* without 0x60 for per-patch inputs */
    case PIPE_SHADER_CAP_MAX_CONSTS:
       return 65536 / 16;
    case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
@@ -191,7 +192,11 @@ nvc0_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
    case PIPE_SHADER_CAP_INTEGERS:
       return 1;
    case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
+      return 16; /* would be 32 in linked (OpenGL-style) mode */
+      /*
+   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLER_VIEWS:
       return 32;
+      */
    case PIPE_SHADER_CAP_OUTPUT_READ:
       return 0; /* shader != PIPE_SHADER_TESSELLATION_CONTROL; */
    default:
@@ -208,12 +213,13 @@ nvc0_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
    case PIPE_CAPF_MAX_LINE_WIDTH_AA:
       return 10.0f;
    case PIPE_CAPF_MAX_POINT_WIDTH:
+      return 63.0f;
    case PIPE_CAPF_MAX_POINT_WIDTH_AA:
-      return 64.0f;
+      return 63.375f;
    case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
       return 16.0f;
    case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
-      return 4.0f;
+      return 15.0f;
    default:
       NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
       return 0.0f;
commit 1a499d761a904eed565b0cdc36cea02e043f5761
Author: Christoph Bumiller <e0425955 at student.tuwien.ac.at>
Date:   Fri Jan 20 13:24:46 2012 +0100

    mesa: allocate transform_feedback_info::Outputs array dynamically
    
    The nvc0 gallium driver is advertising 128 MAX_INTERLEAVED_COMPS
    which made it always assert in the linker when TFB was used since
    the Outputs array was smaller than that maximum.
    
    v2: added assertions
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Paul Berry <stereotype441 at gmail.com>
    (cherry picked from commit d540af554adfe302387014c0f46d6ac3aaa75121)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 0d85aee..47fbb5a 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1388,9 +1388,10 @@ public:
    static bool is_same(const tfeedback_decl &x, const tfeedback_decl &y);
    bool assign_location(struct gl_context *ctx, struct gl_shader_program *prog,
                         ir_variable *output_var);
+   bool accumulate_num_outputs(struct gl_shader_program *prog, unsigned *count);
    bool store(struct gl_context *ctx, struct gl_shader_program *prog,
               struct gl_transform_feedback_info *info, unsigned buffer,
-	      unsigned varying) const;
+              unsigned varying, const unsigned max_outputs) const;
 
 
    /**
@@ -1624,16 +1625,9 @@ tfeedback_decl::assign_location(struct gl_context *ctx,
 }
 
 
-/**
- * Update gl_transform_feedback_info to reflect this tfeedback_decl.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
 bool
-tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
-                      struct gl_transform_feedback_info *info,
-                      unsigned buffer, unsigned varying) const
+tfeedback_decl::accumulate_num_outputs(struct gl_shader_program *prog,
+                                       unsigned *count)
 {
    if (!this->is_assigned()) {
       /* From GL_EXT_transform_feedback:
@@ -1648,6 +1642,28 @@ tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
       return false;
    }
 
+   unsigned translated_size = this->size;
+   if (this->is_clip_distance_mesa)
+      translated_size = (translated_size + 3) / 4;
+
+   *count += translated_size * this->matrix_columns;
+
+   return true;
+}
+
+
+/**
+ * Update gl_transform_feedback_info to reflect this tfeedback_decl.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
+                      struct gl_transform_feedback_info *info,
+                      unsigned buffer,
+                      unsigned varying, const unsigned max_outputs) const
+{
    /* From GL_EXT_transform_feedback:
     *   A program will fail to link if:
     *
@@ -1663,19 +1679,6 @@ tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
       return false;
    }
 
-   /* Verify that the checks on MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS
-    * and MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS are sufficient to prevent
-    * overflow of info->Outputs[].  In worst case we generate one entry in
-    * Outputs[] per component so a conservative check is to verify that the
-    * size of the array is greater than or equal to both
-    * MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS and
-    * MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS.
-    */
-   assert(Elements(info->Outputs) >=
-          ctx->Const.MaxTransformFeedbackInterleavedComponents);
-   assert(Elements(info->Outputs) >=
-          ctx->Const.MaxTransformFeedbackSeparateComponents);
-
    unsigned translated_size = this->size;
    if (this->is_clip_distance_mesa)
       translated_size = (translated_size + 3) / 4;
@@ -1683,6 +1686,7 @@ tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
    for (unsigned index = 0; index < translated_size; ++index) {
       for (unsigned v = 0; v < this->matrix_columns; ++v) {
          unsigned num_components = this->vector_elements;
+         assert(info->NumOutputs < max_outputs);
          info->Outputs[info->NumOutputs].ComponentOffset = 0;
          if (this->is_clip_distance_mesa) {
             if (this->is_subscripted) {
@@ -1976,6 +1980,7 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
       prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS;
 
    ralloc_free(prog->LinkedTransformFeedback.Varyings);
+   ralloc_free(prog->LinkedTransformFeedback.Outputs);
 
    memset(&prog->LinkedTransformFeedback, 0,
           sizeof(prog->LinkedTransformFeedback));
@@ -1988,12 +1993,23 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
 		    struct gl_transform_feedback_varying_info,
 		    num_tfeedback_decls);
 
+   unsigned num_outputs = 0;
+   for (unsigned i = 0; i < num_tfeedback_decls; ++i)
+      if (!tfeedback_decls[i].accumulate_num_outputs(prog, &num_outputs))
+         return false;
+
+   prog->LinkedTransformFeedback.Outputs =
+      rzalloc_array(prog,
+                    struct gl_transform_feedback_output,
+                    num_outputs);
+
    for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
       unsigned buffer = separate_attribs_mode ? i : 0;
       if (!tfeedback_decls[i].store(ctx, prog, &prog->LinkedTransformFeedback,
-                                    buffer, i))
+                                    buffer, i, num_outputs))
          return false;
    }
+   assert(prog->LinkedTransformFeedback.NumOutputs == num_outputs);
 
    return true;
 }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 9fdabf9..95450f9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1823,6 +1823,22 @@ struct gl_transform_feedback_varying_info {
    GLint Size;
 };
 
+struct gl_transform_feedback_output {
+   unsigned OutputRegister;
+   unsigned OutputBuffer;
+   unsigned NumComponents;
+
+   /** offset (in DWORDs) of this output within the interleaved structure */
+   unsigned DstOffset;
+
+   /**
+    * Offset into the output register of the data to output.  For example,
+    * if NumComponents is 2 and ComponentOffset is 1, then the data to
+    * offset is in the y and z components of the output register.
+    */
+   unsigned ComponentOffset;
+};
+
 /** Post-link transform feedback info. */
 struct gl_transform_feedback_info {
    unsigned NumOutputs;
@@ -1832,21 +1848,7 @@ struct gl_transform_feedback_info {
     */
    unsigned NumBuffers;
 
-   struct {
-      unsigned OutputRegister;
-      unsigned OutputBuffer;
-      unsigned NumComponents;
-
-      /** offset (in DWORDs) of this output within the interleaved structure */
-      unsigned DstOffset;
-
-      /**
-       * Offset into the output register of the data to output.  For example,
-       * if NumComponents is 2 and ComponentOffset is 1, then the data to
-       * offset is in the y and z components of the output register.
-       */
-      unsigned ComponentOffset;
-   } Outputs[MAX_PROGRAM_OUTPUTS];
+   struct gl_transform_feedback_output *Outputs;
 
    /** Transform feedback varyings used for the linking of this shader program.
     *
commit f97ee6460670b8c69cd878eb67f4f0b0fbc92786
Author: Christoph Bumiller <e0425955 at student.tuwien.ac.at>
Date:   Thu Jan 12 19:28:03 2012 +0100

    nv50/ir: make use of TGSI_INTERPOLATE_COLOR
    
    Flat SHADE_MODEL still overrides any non-flat interpolation
    qualifier, but pulling that state out of the rasterizer cso
    isn't really worth the effort, is it ?
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit af0ce1dba8219ff8628f1fa61cf93c11a77dab94)

diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h b/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h
index a37a29a..84a5140 100644
--- a/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h
+++ b/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h
@@ -42,6 +42,7 @@ struct nv50_ir_varying
    unsigned mask     : 4; /* vec4 mask */
    unsigned linear   : 1; /* linearly interpolated if true (and not flat) */
    unsigned flat     : 1;
+   unsigned sc       : 1; /* special colour interpolation mode (SHADE_MODEL) */
    unsigned centroid : 1;
    unsigned patch    : 1; /* patch constant value */
    unsigned regular  : 1; /* driver-specific meaning (e.g. input in sreg) */
diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp b/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp
index c104dbe..3fb679b 100644
--- a/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp
+++ b/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp
@@ -817,9 +817,11 @@ bool Source::scanDeclaration(const struct tgsi_full_declaration *decl)
                case TGSI_INTERPOLATE_CONSTANT:
                   info->in[i].flat = 1;
                   break;
+               case TGSI_INTERPOLATE_COLOR:
+                  info->in[i].sc = 1;
+                  break;
                case TGSI_INTERPOLATE_LINEAR:
-                  if (sn != TGSI_SEMANTIC_COLOR) // GL_NICEST
-                     info->in[i].linear = 1;
+                  info->in[i].linear = 1;
                   break;
                default:
                   break;
@@ -1141,7 +1143,7 @@ Converter::makeSym(uint tgsiFile, int fileIdx, int idx, int c, uint32_t address)
 static inline uint8_t
 translateInterpMode(const struct nv50_ir_varying *var, operation& op)
 {
-   uint8_t mode;
+   uint8_t mode = NV50_IR_INTERP_PERSPECTIVE;
 
    if (var->flat)
       mode = NV50_IR_INTERP_FLAT;
@@ -1149,9 +1151,11 @@ translateInterpMode(const struct nv50_ir_varying *var, operation& op)
    if (var->linear)
       mode = NV50_IR_INTERP_LINEAR;
    else
-      mode = NV50_IR_INTERP_PERSPECTIVE;
+   if (var->sc)
+      mode = NV50_IR_INTERP_SC;
 
-   op = (mode == NV50_IR_INTERP_PERSPECTIVE) ? OP_PINTERP : OP_LINTERP;
+   op = (mode == NV50_IR_INTERP_PERSPECTIVE || mode == NV50_IR_INTERP_SC)
+      ? OP_PINTERP : OP_LINTERP;
 
    if (var->centroid)
       mode |= NV50_IR_INTERP_CENTROID;
diff --git a/src/gallium/drivers/nvc0/codegen/nv50_ir_lowering_nvc0.cpp b/src/gallium/drivers/nvc0/codegen/nv50_ir_lowering_nvc0.cpp
index 5f906e4..1c19651 100644
--- a/src/gallium/drivers/nvc0/codegen/nv50_ir_lowering_nvc0.cpp
+++ b/src/gallium/drivers/nvc0/codegen/nv50_ir_lowering_nvc0.cpp
@@ -703,11 +703,6 @@ NVC0LoweringPass::visit(Instruction *i)
          assert(prog->getType() != Program::TYPE_FRAGMENT);
       }
       break;
-   case OP_PINTERP:
-      if (i->getSrc(0)->reg.data.offset >= 0x280 &&
-          i->getSrc(0)->reg.data.offset <  0x2c0)
-         i->setInterpolate(i->getSampleMode() | NV50_IR_INTERP_SC);
-      break;
    default:
       break;
    }   
commit 4ac2e2f1592b7c91c57f5d72ba8601d1ee0c1234
Author: Christoph Bumiller <e0425955 at student.tuwien.ac.at>
Date:   Thu Jan 12 19:12:02 2012 +0100

    nvc0: fix submission of VertexID and EdgeFlag in push mode
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 7b6881932a71b36dd47f63200c9dbee8e2b9af4f)

diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir.cpp b/src/gallium/drivers/nv50/codegen/nv50_ir.cpp
index a8f0529..7d9b7e2 100644
--- a/src/gallium/drivers/nv50/codegen/nv50_ir.cpp
+++ b/src/gallium/drivers/nv50/codegen/nv50_ir.cpp
@@ -938,6 +938,7 @@ nv50_ir_init_prog_info(struct nv50_ir_prog_info *info)
    }
    info->io.clipDistance = 0xff;
    info->io.pointSize = 0xff;
+   info->io.vertexId = 0xff;
    info->io.edgeFlagIn = 0xff;
    info->io.edgeFlagOut = 0xff;
    info->io.fragDepth = 0xff;
diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h b/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h
index 73fb023..a37a29a 100644
--- a/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h
+++ b/src/gallium/drivers/nv50/codegen/nv50_ir_driver.h
@@ -155,6 +155,7 @@ struct nv50_ir_prog_info
       uint8_t cullDistanceMask;  /* clip distance mode (1 bit per output) */
       int8_t genUserClip;        /* request user clip planes for ClipVertex */
       uint8_t pointSize;         /* output index for PointSize */
+      uint8_t vertexId;          /* system value index of VertexID */
       uint8_t edgeFlagIn;
       uint8_t edgeFlagOut;
       uint8_t fragDepth;         /* output index of FragDepth */
diff --git a/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp b/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp
index a1c8f84..c104dbe 100644
--- a/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp
+++ b/src/gallium/drivers/nv50/codegen/nv50_ir_from_tgsi.cpp
@@ -864,6 +864,13 @@ bool Source::scanDeclaration(const struct tgsi_full_declaration *decl)
       }
       break;
    case TGSI_FILE_SYSTEM_VALUE:
+      switch (sn) {
+      case TGSI_SEMANTIC_VERTEXID:
+         info->io.vertexId = first;
+         break;
+      default:
+         break;
+      }
       for (i = first; i <= last; ++i, ++si) {
          info->sv[i].sn = sn;
          info->sv[i].si = si;
diff --git a/src/gallium/drivers/nvc0/nvc0_3d.xml.h b/src/gallium/drivers/nvc0/nvc0_3d.xml.h
index 8d6ea7e..6a1dff7 100644
--- a/src/gallium/drivers/nvc0/nvc0_3d.xml.h
+++ b/src/gallium/drivers/nvc0/nvc0_3d.xml.h
@@ -913,6 +913,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT			0x04000000
 #define NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_CONT			0x08000000
 
+#define NVC0_3D_VERTEX_ID_REPLACE				0x0000161c
+#define NVC0_3D_VERTEX_ID_REPLACE_ENABLE			0x00000001
+#define NVC0_3D_VERTEX_ID_REPLACE_SOURCE__MASK			0x00000ff0
+#define NVC0_3D_VERTEX_ID_REPLACE_SOURCE__SHIFT			4
+
 #define NVC0_3D_VERTEX_DATA					0x00001640
 
 #define NVC0_3D_PRIM_RESTART_ENABLE				0x00001644
diff --git a/src/gallium/drivers/nvc0/nvc0_context.h b/src/gallium/drivers/nvc0/nvc0_context.h
index af95d1a..b8f0d92 100644
--- a/src/gallium/drivers/nvc0/nvc0_context.h
+++ b/src/gallium/drivers/nvc0/nvc0_context.h
@@ -134,9 +134,6 @@ struct nvc0_context {
    struct draw_context *draw;
 };
 
-#define NVC0_USING_EDGEFLAG(ctx) \
-   ((ctx)->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)
-
 static INLINE struct nvc0_context *
 nvc0_context(struct pipe_context *pipe)
 {
diff --git a/src/gallium/drivers/nvc0/nvc0_program.c b/src/gallium/drivers/nvc0/nvc0_program.c
index 813008c..cff76fe 100644
--- a/src/gallium/drivers/nvc0/nvc0_program.c
+++ b/src/gallium/drivers/nvc0/nvc0_program.c
@@ -107,7 +107,7 @@ nvc0_vp_assign_input_slots(struct nv50_ir_prog_info *info)
 
    for (n = 0, i = 0; i < info->numInputs; ++i) {
       switch (info->in[i].sn) {
-      case TGSI_SEMANTIC_INSTANCEID:
+      case TGSI_SEMANTIC_INSTANCEID: /* for SM4 only, in TGSI they're SVs */
       case TGSI_SEMANTIC_VERTEXID:
          info->in[i].mask = 0x1;
          info->in[i].slot[0] =
@@ -580,7 +580,11 @@ nvc0_program_translate(struct nvc0_program *prog)
    prog->relocs = info->bin.relocData;
    prog->max_gpr = MAX2(4, (info->bin.maxGPR + 1));
 
-   prog->vp.edgeflag = PIPE_MAX_ATTRIBS;
+   prog->vp.need_vertex_id = info->io.vertexId < PIPE_MAX_SHADER_INPUTS;
+
+   if (info->io.edgeFlagOut < PIPE_MAX_ATTRIBS)
+      info->out[info->io.edgeFlagOut].mask = 0; /* for headergen */
+   prog->vp.edgeflag = info->io.edgeFlagIn;
 
    switch (prog->type) {
    case PIPE_SHADER_VERTEX:
diff --git a/src/gallium/drivers/nvc0/nvc0_program.h b/src/gallium/drivers/nvc0/nvc0_program.h
index c384ef5..6eb8c96 100644
--- a/src/gallium/drivers/nvc0/nvc0_program.h
+++ b/src/gallium/drivers/nvc0/nvc0_program.h
@@ -37,8 +37,9 @@ struct nvc0_program {
    struct {
       uint32_t clip_mode; /* clip/cull selection */
       uint8_t clip_enable; /* mask of defined clip planes */
-      uint8_t edgeflag;
       uint8_t num_ucps; /* also set to max if ClipDistance is used */
+      uint8_t edgeflag; /* attribute index of edgeflag input */
+      boolean need_vertex_id;
    } vp;
    struct {
       uint8_t early_z;
diff --git a/src/gallium/drivers/nvc0/nvc0_push.c b/src/gallium/drivers/nvc0/nvc0_push.c
index 238671d..412186c 100644
--- a/src/gallium/drivers/nvc0/nvc0_push.c
+++ b/src/gallium/drivers/nvc0/nvc0_push.c
@@ -21,6 +21,7 @@ struct push_context {
    struct translate *translate;
 
    boolean primitive_restart;
+   boolean need_vertex_id;
    uint32_t prim;
    uint32_t restart_index;
    uint32_t instance_id;
@@ -42,22 +43,23 @@ init_push_context(struct nvc0_context *nvc0, struct push_context *ctx)
    ctx->chan = nvc0->screen->base.channel;
    ctx->translate = nvc0->vertex->translate;
 
+   if (likely(nvc0->vertex->num_elements < 32))
+      ctx->need_vertex_id = nvc0->vertprog->vp.need_vertex_id;
+   else
+      ctx->need_vertex_id = FALSE;
+
+   ctx->edgeflag.buffer = -1;
    ctx->edgeflag.value = 0.5f;
 
-   if (NVC0_USING_EDGEFLAG(nvc0)) {
+   if (unlikely(nvc0->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)) {
       ve = &nvc0->vertex->element[nvc0->vertprog->vp.edgeflag].pipe;
-
       ctx->edgeflag.buffer = ve->vertex_buffer_index;
       ctx->edgeflag.offset = ve->src_offset;
-
       ctx->packet_vertex_limit = 1;
    } else {
-      ctx->edgeflag.buffer = -1;
-      ctx->edgeflag.offset = 0;
-      ctx->edgeflag.stride = 0;
-      ctx->edgeflag.data = NULL;
-
       ctx->packet_vertex_limit = nvc0->vertex->vtx_per_packet_max;
+      if (unlikely(ctx->need_vertex_id))
+         ctx->packet_vertex_limit = 1;
    }
 
    ctx->vertex_words = nvc0->vertex->vtx_size;
@@ -74,6 +76,17 @@ set_edgeflag(struct push_context *ctx, unsigned vtx_id)
    }
 }
 
+static INLINE void
+set_vertexid(struct push_context *ctx, uint32_t vtx_id)
+{
+#if 0
+   BEGIN_RING(ctx->chan, RING_3D(VERTEX_ID), 1); /* broken on nvc0 */
+#else
+   BEGIN_RING(ctx->chan, RING_3D(VERTEX_DATA), 1); /* as last attribute */
+#endif
+   OUT_RING  (ctx->chan, vtx_id);
+}
+
 static INLINE unsigned
 prim_restart_search_i08(uint8_t *elts, unsigned push, uint8_t index)
 {
@@ -117,7 +130,7 @@ emit_vertices_i08(struct push_context *ctx, unsigned start, unsigned count)
       if (ctx->primitive_restart)
          nr = prim_restart_search_i08(elts, push, ctx->restart_index);
 
-      if (unlikely(ctx->edgeflag.buffer >= 0) && nr)
+      if (unlikely(ctx->edgeflag.buffer >= 0) && likely(nr))
          set_edgeflag(ctx, elts[0]);
 
       size = ctx->vertex_words * nr;
@@ -126,8 +139,11 @@ emit_vertices_i08(struct push_context *ctx, unsigned start, unsigned count)
 
       ctx->translate->run_elts8(ctx->translate, elts, nr, ctx->instance_id,
                                 ctx->chan->cur);
-
       ctx->chan->cur += size;
+
+      if (unlikely(ctx->need_vertex_id) && likely(size))
+         set_vertexid(ctx, elts[0]);
+
       count -= nr;
       elts += nr;
 
@@ -155,7 +171,7 @@ emit_vertices_i16(struct push_context *ctx, unsigned start, unsigned count)
       if (ctx->primitive_restart)
          nr = prim_restart_search_i16(elts, push, ctx->restart_index);
 
-      if (unlikely(ctx->edgeflag.buffer >= 0) && nr)
+      if (unlikely(ctx->edgeflag.buffer >= 0) && likely(nr))
          set_edgeflag(ctx, elts[0]);
 
       size = ctx->vertex_words * nr;
@@ -164,8 +180,11 @@ emit_vertices_i16(struct push_context *ctx, unsigned start, unsigned count)
 
       ctx->translate->run_elts16(ctx->translate, elts, nr, ctx->instance_id,
                                  ctx->chan->cur);
-
       ctx->chan->cur += size;
+
+      if (unlikely(ctx->need_vertex_id))
+         set_vertexid(ctx, elts[0]);
+
       count -= nr;
       elts += nr;
 
@@ -193,7 +212,7 @@ emit_vertices_i32(struct push_context *ctx, unsigned start, unsigned count)
       if (ctx->primitive_restart)
          nr = prim_restart_search_i32(elts, push, ctx->restart_index);
 
-      if (unlikely(ctx->edgeflag.buffer >= 0) && nr)
+      if (unlikely(ctx->edgeflag.buffer >= 0) && likely(nr))
          set_edgeflag(ctx, elts[0]);
 
       size = ctx->vertex_words * nr;
@@ -202,8 +221,11 @@ emit_vertices_i32(struct push_context *ctx, unsigned start, unsigned count)
 
       ctx->translate->run_elts(ctx->translate, elts, nr, ctx->instance_id,
                                ctx->chan->cur);
-
       ctx->chan->cur += size;
+
+      if (unlikely(ctx->need_vertex_id))
+         set_vertexid(ctx, elts[0]);
+
       count -= nr;
       elts += nr;
 
@@ -233,6 +255,10 @@ emit_vertices_seq(struct push_context *ctx, unsigned start, unsigned count)
       ctx->translate->run(ctx->translate, start, push, ctx->instance_id,
                           ctx->chan->cur);
       ctx->chan->cur += size;
+
+      if (unlikely(ctx->need_vertex_id))
+         set_vertexid(ctx, start);
+
       count -= push;
       start += push;
    }
@@ -326,6 +352,16 @@ nvc0_push_vbo(struct nvc0_context *nvc0, const struct pipe_draw_info *info)
    ctx.instance_id = info->start_instance;
    ctx.prim = nvc0_prim_gl(info->mode);
 
+   if (unlikely(ctx.need_vertex_id)) {
+      const unsigned a = nvc0->vertex->num_elements;
+      BEGIN_RING(ctx.chan, RING_3D(VERTEX_ATTRIB_FORMAT(a)), 1);
+      OUT_RING  (ctx.chan, (a << NVC0_3D_VERTEX_ATTRIB_FORMAT_BUFFER__SHIFT) |
+                 NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT |
+                 NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32);
+      BEGIN_RING(ctx.chan, RING_3D(VERTEX_ID_REPLACE), 1);
+      OUT_RING  (ctx.chan, (((0x80 + a * 0x10) / 4) << 4) | 1);
+   }
+
    while (inst_count--) {
       BEGIN_RING(ctx.chan, RING_3D(VERTEX_BEGIN_GL), 1);
       OUT_RING  (ctx.chan, ctx.prim);
@@ -355,6 +391,16 @@ nvc0_push_vbo(struct nvc0_context *nvc0, const struct pipe_draw_info *info)
    if (unlikely(ctx.edgeflag.value == 0.0f))
       IMMED_RING(ctx.chan, RING_3D(EDGEFLAG_ENABLE), 1);
 
+   if (unlikely(ctx.need_vertex_id)) {
+      const unsigned a = nvc0->vertex->num_elements;
+      IMMED_RING(ctx.chan, RING_3D(VERTEX_ID_REPLACE), 0);
+      BEGIN_RING(ctx.chan, RING_3D(VERTEX_ATTRIB_FORMAT(a)), 1);
+      OUT_RING  (ctx.chan,
+                 NVC0_3D_VERTEX_ATTRIB_FORMAT_CONST |
+                 NVC0_3D_VERTEX_ATTRIB_FORMAT_TYPE_FLOAT |
+                 NVC0_3D_VERTEX_ATTRIB_FORMAT_SIZE_32);
+   }
+
    if (info->indexed)
       nouveau_resource_unmap(nv04_resource(nvc0->idxbuf.buffer));
 
diff --git a/src/gallium/drivers/nvc0/nvc0_vbo.c b/src/gallium/drivers/nvc0/nvc0_vbo.c
index 7cf6991..3e95d50 100644
--- a/src/gallium/drivers/nvc0/nvc0_vbo.c
+++ b/src/gallium/drivers/nvc0/nvc0_vbo.c
@@ -263,7 +263,8 @@ nvc0_vertex_arrays_validate(struct nvc0_context *nvc0)
    struct nvc0_vertex_element *ve;
    unsigned i;
 
-   if (unlikely(vertex->need_conversion || NVC0_USING_EDGEFLAG(nvc0))) {
+   if (unlikely(vertex->need_conversion) ||
+       unlikely(nvc0->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS)) {
       nvc0->vbo_fifo = ~0;
       nvc0->vbo_user = 0;
    } else {
commit f5b787b9e3aa0720c820e071d1f67b6879aaa71c
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Mon Jan 23 15:58:31 2012 +0400

    r600g: fix interpolation with clipvertex
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 5a84cc4ebcc99fb029d5f855e8afa11fab09266a)

diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index a32288c..45d491b 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -970,6 +970,9 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 		shader->output[noutput].gpr = ctx.temp_reg+1;
 		noutput++;
 
+		/* reset spi_sid for clipvertex output to avoid confusing spi */
+		shader->output[ctx.cv_output].spi_sid = 0;
+
 		shader->clip_dist_write = 0xFF;
 
 		for (i = 0; i < 8; i++) {
commit 84d2bb4dfc19a9a4771177aef2e667673ea4b6d2
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Mon Jan 23 13:47:51 2012 +0400

    r600g: fix VS fog export
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 13daa059c01d6dd05064e82cf67cba9cc5fe79db)

diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index e01871d..a32288c 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -1158,6 +1158,11 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 					output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
 				}
 				break;
+			case TGSI_SEMANTIC_FOG:
+				output[j].swizzle_y = 4; /* 0 */
+				output[j].swizzle_z = 4; /* 0 */
+				output[j].swizzle_w = 5; /* 1 */
+				break;
 			}
 			break;
 		case TGSI_PROCESSOR_FRAGMENT:
commit e1a02333a0d26ce3d8631e701fc3960b35e6aeb5
Author: Alex Deucher <alexander.deucher at amd.com>
Date:   Thu Jan 19 21:07:58 2012 -0500

    r600g: fix typo in evergreen register
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
    (cherry picked from commit 5e576efef2397e6748e0dc727d92d1064bf90efe)

diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
index 17dee1a..fa3fece 100644
--- a/src/gallium/drivers/r600/evergreend.h
+++ b/src/gallium/drivers/r600/evergreend.h
@@ -675,13 +675,6 @@
 #define   G_028814_MULTI_PRIM_IB_ENA(x)                (((x) >> 21) & 0x1)
 #define   C_028814_MULTI_PRIM_IB_ENA                   0xFFDFFFFF
 
-#define R_028004_DB_DEPTH_VIEW                       0x028004
-#define   S_028004_SLICE_START(x)                      (((x) & 0x7FF) << 0)
-#define   G_028004_SLICE_START(x)                      (((x) >> 0) & 0x7FF)
-#define   C_028004_SLICE_START                         0xFFFFF800
-#define   S_028004_SLICE_MAX(x)                        (((x) & 0x7FF) << 13)
-#define   G_028004_SLICE_MAX(x)                        (((x) >> 13) & 0x7FF)
-#define   C_028004_SLICE_MAX                           0xFF001FFF
 #define R_028D24_DB_HTILE_SURFACE                    0x028D24
 #define   S_028D24_HTILE_WIDTH(x)                      (((x) & 0x1) << 0)
 #define   G_028D24_HTILE_WIDTH(x)                      (((x) >> 0) & 0x1)
@@ -1469,6 +1462,12 @@
 #define   S_028004_ZPASS_INCREMENT_DISABLE        (((x) & 0x1) << 0)
 #define   S_028004_PERFECT_ZPASS_COUNTS(x)        (((x) & 0x1) << 1)
 #define R_028008_DB_DEPTH_VIEW                       0x00028008
+#define   S_028008_SLICE_START(x)                      (((x) & 0x7FF) << 0)
+#define   G_028008_SLICE_START(x)                      (((x) >> 0) & 0x7FF)
+#define   C_028008_SLICE_START                         0xFFFFF800
+#define   S_028008_SLICE_MAX(x)                        (((x) & 0x7FF) << 13)
+#define   G_028008_SLICE_MAX(x)                        (((x) >> 13) & 0x7FF)
+#define   C_028008_SLICE_MAX                           0xFF001FFF
 #define R_02800C_DB_RENDER_OVERRIDE                  0x0002800C
 #define   V_02800C_FORCE_OFF                         0
 #define   V_02800C_FORCE_ENABLE                      1
commit 20457cfcb81223802f71968e255f2b28942010a8
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Sun Jan 22 01:49:46 2012 +0400

    r600g: take into account kcache banks for bank swizzle check
    
    Due to the changes for multiple kcache banks support, now we are assigning
    final SRCx_SEL values for kcache access at the later stage, when building the
    bytecode. So we need to take into account kcache banks to distinguish
    the constants with the same address but different bank index.
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 840a342cd0ac4a9937798a2137122387c0d3d7f6)

diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c
index c9b4845..f4977fb 100644
--- a/src/gallium/drivers/r600/r600_asm.c
+++ b/src/gallium/drivers/r600/r600_asm.c
@@ -722,7 +722,7 @@ static int check_vector(struct r600_bytecode *bc, struct r600_bytecode_alu *alu,
 					return r;
 			}
 		} else if (is_cfile(sel)) {
-			r = reserve_cfile(bc, bs, sel, elem);
+			r = reserve_cfile(bc, bs, (alu->src[src].kc_bank<<16) + sel, elem);
 			if (r)
 				return r;
 		}
@@ -749,7 +749,7 @@ static int check_scalar(struct r600_bytecode *bc, struct r600_bytecode_alu *alu,
 				const_count++;
 		}
 		if (is_cfile(sel)) {
-			r = reserve_cfile(bc, bs, sel, elem);
+			r = reserve_cfile(bc, bs, (alu->src[src].kc_bank<<16) + sel, elem);
 			if (r)
 				return r;
 		}
commit fceca6191a8c017cf9f0ba689a407d25a294335c
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Sat Jan 21 01:37:48 2012 +0400

    r600g: implement clip vertex v2
    
    Clip planes are uploaded as a constant buffer and used by the vertex
    shader to produce corresponding clip distances for hw clipping.
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 54e8dcaad65cbe3603730414fd8d76ac53f89a86)
    
    Conflicts:
    
    	src/gallium/drivers/r600/r600_state_common.c

diff --git a/src/gallium/drivers/r600/evergreen_hw_context.c b/src/gallium/drivers/r600/evergreen_hw_context.c
index bd1d969..7e698f1 100644
--- a/src/gallium/drivers/r600/evergreen_hw_context.c
+++ b/src/gallium/drivers/r600/evergreen_hw_context.c
@@ -99,7 +99,9 @@ static const struct r600_reg evergreen_context_reg_list[] = {
 	{R_028058_DB_DEPTH_SIZE, 0, 0, 0},
 	{R_02805C_DB_DEPTH_SLICE, 0, 0, 0},
 	{R_028140_ALU_CONST_BUFFER_SIZE_PS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0},
+	{R_028144_ALU_CONST_BUFFER_SIZE_PS_1, REG_FLAG_DIRTY_ALWAYS, 0, 0},
 	{R_028180_ALU_CONST_BUFFER_SIZE_VS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0},
+	{R_028184_ALU_CONST_BUFFER_SIZE_VS_1, REG_FLAG_DIRTY_ALWAYS, 0, 0},
 	{R_028200_PA_SC_WINDOW_OFFSET, 0, 0, 0},
 	{R_028204_PA_SC_WINDOW_SCISSOR_TL, 0, 0, 0},
 	{R_028208_PA_SC_WINDOW_SCISSOR_BR, 0, 0, 0},
@@ -293,7 +295,9 @@ static const struct r600_reg evergreen_context_reg_list[] = {
 	{R_028924_SQ_GS_VERT_ITEMSIZE_2, 0, 0, 0},
 	{R_028928_SQ_GS_VERT_ITEMSIZE_3, 0, 0, 0},
 	{R_028940_ALU_CONST_CACHE_PS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
+	{R_028944_ALU_CONST_CACHE_PS_1, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
 	{R_028980_ALU_CONST_CACHE_VS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
+	{R_028984_ALU_CONST_CACHE_VS_1, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
 	{R_028A00_PA_SU_POINT_SIZE, 0, 0, 0},
 	{R_028A04_PA_SU_POINT_MINMAX, 0, 0, 0},
 	{R_028A08_PA_SU_LINE_CNTL, 0, 0, 0},
@@ -465,7 +469,9 @@ static const struct r600_reg cayman_context_reg_list[] = {
 	{R_028058_DB_DEPTH_SIZE, 0, 0, 0},
 	{R_02805C_DB_DEPTH_SLICE, 0, 0, 0},
 	{R_028140_ALU_CONST_BUFFER_SIZE_PS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0},
+	{R_028144_ALU_CONST_BUFFER_SIZE_PS_1, REG_FLAG_DIRTY_ALWAYS, 0, 0},
 	{R_028180_ALU_CONST_BUFFER_SIZE_VS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0},
+	{R_028184_ALU_CONST_BUFFER_SIZE_VS_1, REG_FLAG_DIRTY_ALWAYS, 0, 0},
 	{R_028200_PA_SC_WINDOW_OFFSET, 0, 0, 0},
 	{R_028204_PA_SC_WINDOW_SCISSOR_TL, 0, 0, 0},
 	{R_028208_PA_SC_WINDOW_SCISSOR_BR, 0, 0, 0},
@@ -658,7 +664,9 @@ static const struct r600_reg cayman_context_reg_list[] = {
 	{R_028924_SQ_GS_VERT_ITEMSIZE_2, 0, 0, 0},
 	{R_028928_SQ_GS_VERT_ITEMSIZE_3, 0, 0, 0},
 	{R_028940_ALU_CONST_CACHE_PS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
+	{R_028944_ALU_CONST_CACHE_PS_1, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
 	{R_028980_ALU_CONST_CACHE_VS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
+	{R_028984_ALU_CONST_CACHE_VS_1, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
 	{R_028A00_PA_SU_POINT_SIZE, 0, 0, 0},
 	{R_028A04_PA_SU_POINT_MINMAX, 0, 0, 0},
 	{R_028A08_PA_SU_LINE_CNTL, 0, 0, 0},
diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index d5e4aef..60b1909 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -1211,6 +1211,7 @@ static void evergreen_set_clip_state(struct pipe_context *ctx,
 {
 	struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
 	struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
+	struct pipe_resource *cbuf;
 
 	if (rstate == NULL)
 		return;
@@ -1235,6 +1236,13 @@ static void evergreen_set_clip_state(struct pipe_context *ctx,
 	free(rctx->states[R600_PIPE_STATE_CLIP]);
 	rctx->states[R600_PIPE_STATE_CLIP] = rstate;
 	r600_context_pipe_state_set(&rctx->ctx, rstate);
+
+	cbuf = pipe_user_buffer_create(ctx->screen,
+                                   state->ucp,
+                                   4*4*8, /* 8*4 floats */
+                                   PIPE_BIND_CONSTANT_BUFFER);
+	r600_set_constant_buffer(ctx, PIPE_SHADER_VERTEX, 1, cbuf);
+	pipe_resource_reference(&cbuf, NULL);
 }
 
 static void evergreen_set_polygon_stipple(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
index 68b77b4..17dee1a 100644
--- a/src/gallium/drivers/r600/evergreend.h
+++ b/src/gallium/drivers/r600/evergreend.h
@@ -1524,7 +1524,9 @@
 #define R_028050_DB_Z_WRITE_BASE                     0x00028050
 #define R_028054_DB_STENCIL_WRITE_BASE               0x00028054
 #define R_028140_ALU_CONST_BUFFER_SIZE_PS_0          0x00028140
+#define R_028144_ALU_CONST_BUFFER_SIZE_PS_1          0x00028144
 #define R_028180_ALU_CONST_BUFFER_SIZE_VS_0          0x00028180
+#define R_028184_ALU_CONST_BUFFER_SIZE_VS_1          0x00028184
 #define R_028200_PA_SC_WINDOW_OFFSET                 0x00028200
 #define R_02820C_PA_SC_CLIPRECT_RULE                 0x0002820C
 #define R_028210_PA_SC_CLIPRECT_0_TL                 0x00028210
@@ -1701,7 +1703,9 @@
 #define R_028924_SQ_GS_VERT_ITEMSIZE_2               0x00028924
 #define R_028928_SQ_GS_VERT_ITEMSIZE_3               0x00028928
 #define R_028940_ALU_CONST_CACHE_PS_0                0x00028940
+#define R_028944_ALU_CONST_CACHE_PS_1                0x00028944
 #define R_028980_ALU_CONST_CACHE_VS_0                0x00028980
+#define R_028984_ALU_CONST_CACHE_VS_1                0x00028984
 #define R_028A04_PA_SU_POINT_MINMAX                  0x00028A04
 #define R_028A08_PA_SU_LINE_CNTL                     0x00028A08
 #define   S_028A08_WIDTH(x)                            (((x) & 0xFFFF) << 0)
diff --git a/src/gallium/drivers/r600/r600_hw_context.c b/src/gallium/drivers/r600/r600_hw_context.c
index 1dba966..2319ba1 100644
--- a/src/gallium/drivers/r600/r600_hw_context.c
+++ b/src/gallium/drivers/r600/r600_hw_context.c
@@ -408,9 +408,13 @@ static const struct r600_reg r600_context_reg_list[] = {
 	{R_028128_CB_CLEAR_BLUE, 0, 0, 0},
 	{R_02812C_CB_CLEAR_ALPHA, 0, 0, 0},
 	{R_028140_ALU_CONST_BUFFER_SIZE_PS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0},
+	{R_028144_ALU_CONST_BUFFER_SIZE_PS_1, REG_FLAG_DIRTY_ALWAYS, 0, 0},
 	{R_028180_ALU_CONST_BUFFER_SIZE_VS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0},
+	{R_028184_ALU_CONST_BUFFER_SIZE_VS_1, REG_FLAG_DIRTY_ALWAYS, 0, 0},
 	{R_028940_ALU_CONST_CACHE_PS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
+	{R_028944_ALU_CONST_CACHE_PS_1, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
 	{R_028980_ALU_CONST_CACHE_VS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
+	{R_028984_ALU_CONST_CACHE_VS_1, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF},
 	{R_02823C_CB_SHADER_MASK, 0, 0, 0},
 	{R_028238_CB_TARGET_MASK, 0, 0, 0},
 	{R_028410_SX_ALPHA_TEST_CONTROL, 0, 0, 0},
@@ -1326,15 +1330,20 @@ void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *
 			if (block->pm4_bo_index[j]) {
 				/* find relocation */
 				struct r600_block_reloc *reloc = &block->reloc[block->pm4_bo_index[j]];
-				block->pm4[reloc->bo_pm4_index] =
-					r600_context_bo_reloc(ctx, reloc->bo, reloc->bo_usage);
-				r600_context_bo_flush(ctx,
-						      reloc->flush_flags,
-						      reloc->flush_mask,
-						      reloc->bo);
+				if (reloc->bo) {
+					block->pm4[reloc->bo_pm4_index] =
+							r600_context_bo_reloc(ctx, reloc->bo, reloc->bo_usage);
+					r600_context_bo_flush(ctx,
+							reloc->flush_flags,
+							reloc->flush_mask,
+							reloc->bo);
+				} else {
+					block->pm4[reloc->bo_pm4_index] = 0;
+				}
 				nbo--;
 				if (nbo == 0)
 					break;
+
 			}
 		}
 		ctx->flags &= ~R600_CONTEXT_CHECK_EVENT_FLUSH;
diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index 537024c..43d6fea 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -492,7 +492,7 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, unsigned shader, e
 	case PIPE_SHADER_CAP_MAX_CONSTS:
 		return R600_MAX_CONST_BUFFER_SIZE;
 	case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
-		return R600_MAX_CONST_BUFFERS;
+		return R600_MAX_CONST_BUFFERS-1;
 	case PIPE_SHADER_CAP_MAX_PREDS:
 		return 0; /* FIXME */
 	case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index ce808d7..015d5e0 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -39,7 +39,7 @@
 #include "r600_shader.h"
 #include "r600_resource.h"
 
-#define R600_MAX_CONST_BUFFERS 1
+#define R600_MAX_CONST_BUFFERS 2
 #define R600_MAX_CONST_BUFFER_SIZE 4096
 
 #ifdef PIPE_ARCH_BIG_ENDIAN
diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index 78ffefe..e01871d 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -193,6 +193,8 @@ struct r600_shader_ctx {
 	int					num_interp_gpr;
 	int					face_gpr;
 	int					colors_used;
+	boolean                 clip_vertex_write;
+	unsigned                cv_output;
 };
 
 struct r600_shader_tgsi_instruction {
@@ -477,6 +479,10 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
 			case TGSI_SEMANTIC_PSIZE:
 				ctx->shader->vs_out_misc_write = 1;
 				break;
+			case TGSI_SEMANTIC_CLIPVERTEX:
+				ctx->clip_vertex_write = TRUE;
+				ctx->cv_output = i;
+				break;
 			}
 		}
 		break;
@@ -794,7 +800,8 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 	struct r600_bytecode_output output[32];
 	unsigned output_done, noutput;
 	unsigned opcode;
-	int i, j, r = 0, pos0;
+	int i, j, k, r = 0;
+	int next_pixel_base = 0, next_pos_base = 60, next_param_base = 0;
 
 	ctx.bc = &shader->bc;
 	ctx.shader = shader;
@@ -808,6 +815,7 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 
 	ctx.face_gpr = -1;
 	ctx.colors_used = 0;
+	ctx.clip_vertex_write = 0;
 
 	shader->two_side = (ctx.type == TGSI_PROCESSOR_FRAGMENT) && rctx->two_side;
 
@@ -950,6 +958,47 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 
 	noutput = shader->noutput;
 
+	if (ctx.clip_vertex_write) {
+		/* need to convert a clipvertex write into clipdistance writes and not export
+		   the clip vertex anymore */
+
+		memset(&shader->output[noutput], 0, 2*sizeof(struct r600_shader_io));
+		shader->output[noutput].name = TGSI_SEMANTIC_CLIPDIST;
+		shader->output[noutput].gpr = ctx.temp_reg;
+		noutput++;
+		shader->output[noutput].name = TGSI_SEMANTIC_CLIPDIST;
+		shader->output[noutput].gpr = ctx.temp_reg+1;
+		noutput++;
+
+		shader->clip_dist_write = 0xFF;
+
+		for (i = 0; i < 8; i++) {
+			int oreg = i >> 2;
+			int ochan = i & 3;
+
+			for (j = 0; j < 4; j++) {
+				struct r600_bytecode_alu alu;
+				memset(&alu, 0, sizeof(struct r600_bytecode_alu));
+				alu.inst = BC_INST(ctx.bc, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4);
+				alu.src[0].sel = shader->output[ctx.cv_output].gpr;
+				alu.src[0].chan = j;
+
+				alu.src[1].sel = 512 + i;
+				alu.src[1].kc_bank = 1;
+				alu.src[1].chan = j;
+
+				alu.dst.sel = ctx.temp_reg + oreg;
+				alu.dst.chan = j;
+				alu.dst.write = (j == ochan);
+				if (j == 3)
+					alu.last = 1;
+				r = r600_bytecode_add_alu(ctx.bc, &alu);
+				if (r)
+					return r;
+			}
+		}
+	}
+
 	/* clamp color outputs */
 	if (shader->clamp_color) {
 		for (i = 0; i < noutput; i++) {
@@ -1069,89 +1118,81 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 	}
 
 	/* export output */
-	j = 0;
-
-	for (i = 0, pos0 = 0; i < noutput; i++) {
-		memset(&output[i+j], 0, sizeof(struct r600_bytecode_output));
-		output[i + j].gpr = shader->output[i].gpr;
-		output[i + j].elem_size = 3;
-		output[i + j].swizzle_x = 0;
-		output[i + j].swizzle_y = 1;
-		output[i + j].swizzle_z = 2;
-		output[i + j].swizzle_w = 3;
-		output[i + j].burst_count = 1;
-		output[i + j].barrier = 1;
-		output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
-		output[i + j].array_base = i+j - pos0;
-		output[i + j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
+	for (i = 0, j = 0; i < noutput; i++, j++) {
+		memset(&output[j], 0, sizeof(struct r600_bytecode_output));
+		output[j].gpr = shader->output[i].gpr;
+		output[j].elem_size = 3;
+		output[j].swizzle_x = 0;
+		output[j].swizzle_y = 1;
+		output[j].swizzle_z = 2;
+		output[j].swizzle_w = 3;
+		output[j].burst_count = 1;
+		output[j].barrier = 1;
+		output[j].type = -1;
+		output[j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
 		switch (ctx.type) {
 		case TGSI_PROCESSOR_VERTEX:
 			switch (shader->output[i].name) {
 			case TGSI_SEMANTIC_POSITION:
-				output[i + j].array_base = 60;
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
-				/* position doesn't count in array_base */
-				pos0++;
+				output[j].array_base = next_pos_base++;
+				output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
 				break;
 
 			case TGSI_SEMANTIC_PSIZE:
-				output[i + j].array_base = 61;
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
-				/* position doesn't count in array_base */
-				pos0++;
+				output[j].array_base = next_pos_base++;
+				output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
+				break;
+			case TGSI_SEMANTIC_CLIPVERTEX:
+				j--;
 				break;
-
 			case TGSI_SEMANTIC_CLIPDIST:
-				/* array base for enabled OUT_MISC_VEC & CCDIST[0|1]_VEC
-				 * vectors is allocated sequentially, starting from 61 */
-				output[i + j].array_base = 61 + shader->output[i].sid
-					/* +1 if OUT_MISC_VEC is enabled */
-					+ shader->vs_out_misc_write
-					/* -1 if OUT_CCDIST0_VEC is disabled */
-					- (((shader->clip_dist_write & 0xF) == 0)? 1 : 0);
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
-				j++;
-				pos0++;
-				/* duplicate it as PARAM to pass to the pixel shader */
-				memcpy(&output[i+j], &output[i+j-1], sizeof(struct r600_bytecode_output));
-				output[i + j].array_base = i+j-pos0;
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
+				output[j].array_base = next_pos_base++;
+				output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
+				/* spi_sid is 0 for clipdistance outputs that were generated
+				 * for clipvertex - we don't need to pass them to PS */
+				if (shader->output[i].spi_sid) {
+					j++;
+					/* duplicate it as PARAM to pass to the pixel shader */
+					memcpy(&output[j], &output[j-1], sizeof(struct r600_bytecode_output));
+					output[j].array_base = next_param_base++;
+					output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
+				}
 				break;
 			}
 			break;
 		case TGSI_PROCESSOR_FRAGMENT:
 			if (shader->output[i].name == TGSI_SEMANTIC_COLOR) {
-				output[i + j].array_base = shader->output[i].sid;
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+				output[j].array_base = next_pixel_base++;
+				output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
 				if (shader->fs_write_all && (rctx->chip_class >= EVERGREEN)) {
-					for (j = 1; j < shader->nr_cbufs; j++) {
-						memset(&output[i + j], 0, sizeof(struct r600_bytecode_output));
-						output[i + j].gpr = shader->output[i].gpr;
-						output[i + j].elem_size = 3;
-						output[i + j].swizzle_x = 0;
-						output[i + j].swizzle_y = 1;
-						output[i + j].swizzle_z = 2;
-						output[i + j].swizzle_w = 3;
-						output[i + j].burst_count = 1;
-						output[i + j].barrier = 1;
-						output[i + j].array_base = shader->output[i].sid + j;
-						output[i + j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
-						output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+					for (k = 1; k < shader->nr_cbufs; k++) {
+						j++;
+						memset(&output[j], 0, sizeof(struct r600_bytecode_output));
+						output[j].gpr = shader->output[i].gpr;
+						output[j].elem_size = 3;
+						output[j].swizzle_x = 0;
+						output[j].swizzle_y = 1;
+						output[j].swizzle_z = 2;
+						output[j].swizzle_w = 3;
+						output[j].burst_count = 1;
+						output[j].barrier = 1;
+						output[j].array_base = next_pixel_base++;
+						output[j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
+						output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
 					}
-					j = shader->nr_cbufs-1;
 				}
 			} else if (shader->output[i].name == TGSI_SEMANTIC_POSITION) {
-				output[i + j].array_base = 61;
-				output[i + j].swizzle_x = 2;
-				output[i + j].swizzle_y = 7;
-				output[i + j].swizzle_z = output[i + j].swizzle_w = 7;
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+				output[j].array_base = 61;
+				output[j].swizzle_x = 2;
+				output[j].swizzle_y = 7;
+				output[j].swizzle_z = output[j].swizzle_w = 7;
+				output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
 			} else if (shader->output[i].name == TGSI_SEMANTIC_STENCIL) {
-				output[i + j].array_base = 61;
-				output[i + j].swizzle_x = 7;
-				output[i + j].swizzle_y = 1;
-				output[i + j].swizzle_z = output[i + j].swizzle_w = 7;
-				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+				output[j].array_base = 61;
+				output[j].swizzle_x = 7;
+				output[j].swizzle_y = 1;
+				output[j].swizzle_z = output[j].swizzle_w = 7;
+				output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
 			} else {
 				R600_ERR("unsupported fragment output name %d\n", shader->output[i].name);
 				r = -EINVAL;
@@ -1163,48 +1204,49 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 			r = -EINVAL;
 			goto out_err;
 		}
+
+		if (output[j].type==-1) {
+			output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
+			output[j].array_base = next_param_base++;
+		}
 	}
-	noutput += j;
+
 	/* add fake param output for vertex shader if no param is exported */
-	if (ctx.type == TGSI_PROCESSOR_VERTEX) {
-		for (i = 0, pos0 = 0; i < noutput; i++) {
-			if (output[i].type == V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM) {
-				pos0 = 1;
-				break;
-			}
-		}
-		if (!pos0) {
-			memset(&output[i], 0, sizeof(struct r600_bytecode_output));
-			output[i].gpr = 0;
-			output[i].elem_size = 3;
-			output[i].swizzle_x = 7;
-			output[i].swizzle_y = 7;
-			output[i].swizzle_z = 7;
-			output[i].swizzle_w = 7;
-			output[i].burst_count = 1;
-			output[i].barrier = 1;
-			output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
-			output[i].array_base = 0;
-			output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
-			noutput++;
-		}
+	if (ctx.type == TGSI_PROCESSOR_VERTEX && next_param_base == 0) {
+			memset(&output[j], 0, sizeof(struct r600_bytecode_output));
+			output[j].gpr = 0;
+			output[j].elem_size = 3;
+			output[j].swizzle_x = 7;
+			output[j].swizzle_y = 7;
+			output[j].swizzle_z = 7;
+			output[j].swizzle_w = 7;
+			output[j].burst_count = 1;
+			output[j].barrier = 1;
+			output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
+			output[j].array_base = 0;
+			output[j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
+			j++;
 	}
+
 	/* add fake pixel export */
-	if (ctx.type == TGSI_PROCESSOR_FRAGMENT && !noutput) {
-		memset(&output[0], 0, sizeof(struct r600_bytecode_output));
-		output[0].gpr = 0;
-		output[0].elem_size = 3;
-		output[0].swizzle_x = 7;
-		output[0].swizzle_y = 7;
-		output[0].swizzle_z = 7;
-		output[0].swizzle_w = 7;
-		output[0].burst_count = 1;
-		output[0].barrier = 1;
-		output[0].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
-		output[0].array_base = 0;
-		output[0].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
-		noutput++;
+	if (ctx.type == TGSI_PROCESSOR_FRAGMENT && j == 0) {
+		memset(&output[j], 0, sizeof(struct r600_bytecode_output));
+		output[j].gpr = 0;
+		output[j].elem_size = 3;
+		output[j].swizzle_x = 7;
+		output[j].swizzle_y = 7;
+		output[j].swizzle_z = 7;
+		output[j].swizzle_w = 7;
+		output[j].burst_count = 1;
+		output[j].barrier = 1;
+		output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
+		output[j].array_base = 0;
+		output[j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
+		j++;
 	}
+
+	noutput = j;
+
 	/* set export done on last export of each type */
 	for (i = noutput - 1, output_done = 0; i >= 0; i--) {
 		if (ctx.bc->chip_class < CAYMAN) {
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index 513fd17..89ff389 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -1317,6 +1317,7 @@ static void r600_set_clip_state(struct pipe_context *ctx,
 {
 	struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
 	struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
+	struct pipe_resource * cbuf;
 
 	if (rstate == NULL)
 		return;
@@ -1341,6 +1342,13 @@ static void r600_set_clip_state(struct pipe_context *ctx,
 	free(rctx->states[R600_PIPE_STATE_CLIP]);
 	rctx->states[R600_PIPE_STATE_CLIP] = rstate;
 	r600_context_pipe_state_set(&rctx->ctx, rstate);
+
+	cbuf = pipe_user_buffer_create(ctx->screen,
+                                   state->ucp,
+                                   4*4*8, /* 8*4 floats */
+                                   PIPE_BIND_CONSTANT_BUFFER);
+	r600_set_constant_buffer(ctx, PIPE_SHADER_VERTEX, 1, cbuf);
+	pipe_resource_reference(&cbuf, NULL);
 }
 
 static void r600_set_polygon_stipple(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index ec454ac..53f8dd9 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -353,11 +353,11 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
 	case PIPE_SHADER_VERTEX:
 		rctx->vs_const_buffer.nregs = 0;
 		r600_pipe_state_add_reg(&rctx->vs_const_buffer,
-					R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
+					R_028180_ALU_CONST_BUFFER_SIZE_VS_0 + index * 4,
 					ALIGN_DIVUP(buffer->width0 >> 4, 16),
 					0xFFFFFFFF, NULL, 0);
 		r600_pipe_state_add_reg(&rctx->vs_const_buffer,
-					R_028980_ALU_CONST_CACHE_VS_0,
+					R_028980_ALU_CONST_CACHE_VS_0 + index * 4,
 					offset >> 8, 0xFFFFFFFF, rbuffer, RADEON_USAGE_READ);
 		r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_const_buffer);
 
@@ -559,7 +559,7 @@ static void r600_update_derived_state(struct r600_pipe_context *rctx)
 	else
 		user_clip_plane_enable = rctx->rasterizer->clip_plane_enable & 0x3F;
 
-	clip_dist_enable = rctx->rasterizer->clip_plane_enable & rctx->vs_shader->shader.clip_dist_write & 0xFF;
+	clip_dist_enable = rctx->rasterizer->clip_plane_enable & rctx->vs_shader->shader.clip_dist_write;
 	rstate.nregs = 0;
 
 	if (user_clip_plane_enable != rctx->user_clip_plane_enable) {
diff --git a/src/gallium/drivers/r600/r600d.h b/src/gallium/drivers/r600/r600d.h
index ccdf82e..16330d3 100644
--- a/src/gallium/drivers/r600/r600d.h
+++ b/src/gallium/drivers/r600/r600d.h
@@ -3538,9 +3538,13 @@
 #define R_038018_RESOURCE0_WORD6                     0x038018
 
 #define R_028140_ALU_CONST_BUFFER_SIZE_PS_0          0x00028140
+#define R_028144_ALU_CONST_BUFFER_SIZE_PS_1          0x00028144
 #define R_028180_ALU_CONST_BUFFER_SIZE_VS_0          0x00028180
+#define R_028184_ALU_CONST_BUFFER_SIZE_VS_1          0x00028184
 #define R_028940_ALU_CONST_CACHE_PS_0                0x00028940
+#define R_028944_ALU_CONST_CACHE_PS_1                0x00028944
 #define R_028980_ALU_CONST_CACHE_VS_0                0x00028980
+#define R_028984_ALU_CONST_CACHE_VS_1                0x00028984
 
 #define R_03CFF0_SQ_VTX_BASE_VTX_LOC                 0x03CFF0
 #define R_03CFF4_SQ_VTX_START_INST_LOC               0x03CFF4
commit a71013d120b2d0687420fcc8f0857f0116d3cded
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Fri Jan 20 23:24:32 2012 +0400

    r600g: improve kcache line sets handling v2
    
    Add support for multiple kcache banks (constant buffers).
    Lock the required lines only.
    Allow up to 4 kcache line sets in the alu clause by using ALU_EXTENDED on eg+.
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit d649bf51ec787021f7872e2a4c09fb2188c0891b)

diff --git a/src/gallium/drivers/r600/eg_asm.c b/src/gallium/drivers/r600/eg_asm.c
index 877e162..e867ea4 100644
--- a/src/gallium/drivers/r600/eg_asm.c
+++ b/src/gallium/drivers/r600/eg_asm.c
@@ -38,6 +38,23 @@ int eg_bytecode_cf_build(struct r600_bytecode *bc, struct r600_bytecode_cf *cf)
 	case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER:
 	case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER:
 	case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE:
+		/* prepend ALU_EXTENDED if we need more than 2 kcache sets */
+		if (cf->eg_alu_extended) {
+			bc->bytecode[id++] =
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE0(V_SQ_CF_INDEX_NONE) |
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE1(V_SQ_CF_INDEX_NONE) |
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE2(V_SQ_CF_INDEX_NONE) |
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE3(V_SQ_CF_INDEX_NONE) |
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK2(cf->kcache[2].bank) |
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK3(cf->kcache[3].bank) |
+				S_SQ_CF_ALU_WORD0_EXT_KCACHE_MODE2(cf->kcache[2].mode);
+			bc->bytecode[id++] = EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_EXTENDED |
+				S_SQ_CF_ALU_WORD1_EXT_KCACHE_MODE3(cf->kcache[3].mode) |
+				S_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR2(cf->kcache[2].addr) |
+				S_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR3(cf->kcache[3].addr) |
+				S_SQ_CF_ALU_WORD1_EXT_BARRIER(1);
+		}
+
 		bc->bytecode[id++] = S_SQ_CF_ALU_WORD0_ADDR(cf->addr >> 1) |
 			S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf->kcache[0].mode) |
 			S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf->kcache[0].bank) |
diff --git a/src/gallium/drivers/r600/eg_sq.h b/src/gallium/drivers/r600/eg_sq.h
index 854c1b8..eba42d0 100644
--- a/src/gallium/drivers/r600/eg_sq.h
+++ b/src/gallium/drivers/r600/eg_sq.h
@@ -78,6 +78,10 @@
 #define   S_SQ_CF_ALU_WORD0_KCACHE_MODE0(x)                          (((x) & 0x3) << 30)
 #define   G_SQ_CF_ALU_WORD0_KCACHE_MODE0(x)                          (((x) >> 30) & 0x3)
 #define   C_SQ_CF_ALU_WORD0_KCACHE_MODE0                             0x3FFFFFFF
+#define     V_SQ_CF_KCACHE_NOP                                       0x00000000
+#define     V_SQ_CF_KCACHE_LOCK_1                                    0x00000001
+#define     V_SQ_CF_KCACHE_LOCK_2                                    0x00000002
+#define     V_SQ_CF_KCACHE_LOCK_LOOP_INDEX                           0x00000003
 #define P_SQ_CF_ALU_WORD1
 #define   S_SQ_CF_ALU_WORD1_KCACHE_MODE1(x)                          (((x) & 0x3) << 0)
 #define   G_SQ_CF_ALU_WORD1_KCACHE_MODE1(x)                          (((x) >> 0) & 0x3)
@@ -103,7 +107,50 @@
 #define   S_SQ_CF_ALU_WORD1_BARRIER(x)                               (((x) & 0x1) << 31)
 #define   G_SQ_CF_ALU_WORD1_BARRIER(x)                               (((x) >> 31) & 0x1)
 #define   C_SQ_CF_ALU_WORD1_BARRIER                                  0x7FFFFFFF
-/* extended TODO */
+
+#define P_SQ_CF_ALU_WORD0_EXT
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE0(x)           (((x) & 0x3) << 4)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE0(x)           (((x) >> 4) & 0x3)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE0              0xFFFFFFCF
+#define	    V_SQ_CF_INDEX_NONE                                       0x00
+#define	    V_SQ_CF_INDEX_0                                          0x01
+#define	    V_SQ_CF_INDEX_1                                          0x02
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE1(x)           (((x) & 0x3) << 6)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE1(x)           (((x) >> 6) & 0x3)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE1              0xFFFFFF3F
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE2(x)           (((x) & 0x3) << 8)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE2(x)           (((x) >> 8) & 0x3)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE2              0xFFFFFCFF
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE3(x)           (((x) & 0x3) << 10)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE3(x)           (((x) >> 10) & 0x3)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK_INDEX_MODE3              0xFFFFF3FF
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK2(x)                      (((x) & 0xF) << 22)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK2(x)                      (((x) >> 22) & 0xF)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK2                         0xFC3FFFFF
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK3(x)                      (((x) & 0xF) << 26)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK3(x)                      (((x) >> 26) & 0xF)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_BANK3                         0xC3FFFFFF
+#define   S_SQ_CF_ALU_WORD0_EXT_KCACHE_MODE2(x)                      (((x) & 0x3) << 30)
+#define   G_SQ_CF_ALU_WORD0_EXT_KCACHE_MODE2(x)                      (((x) >> 30) & 0x3)
+#define   C_SQ_CF_ALU_WORD0_EXT_KCACHE_MODE2                         0x3FFFFFFF
+
+#define P_SQ_CF_ALU_WORD1_EXT
+#define   S_SQ_CF_ALU_WORD1_EXT_KCACHE_MODE3(x)                      (((x) & 0x3) << 0)
+#define   G_SQ_CF_ALU_WORD1_EXT_KCACHE_MODE3(x)                      (((x) >> 0) & 0x3)
+#define   C_SQ_CF_ALU_WORD1_EXT_KCACHE_MODE3                         0xFFFFFFFC
+#define   S_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR2(x)                      (((x) & 0xFF) << 2)
+#define   G_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR2(x)                      (((x) >> 2) & 0xFF)
+#define   C_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR2                         0xFFFFFC03
+#define   S_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR3(x)                      (((x) & 0xFF) << 10)
+#define   G_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR3(x)                      (((x) >> 10) & 0xFF)
+#define   C_SQ_CF_ALU_WORD1_EXT_KCACHE_ADDR3                         0xFFFC03FF
+#define   S_SQ_CF_ALU_WORD1_EXT_CF_INST(x)                           (((x) & 0xF) << 26)
+#define   G_SQ_CF_ALU_WORD1_EXT_CF_INST(x)                           (((x) >> 26) & 0xF)
+#define   C_SQ_CF_ALU_WORD1_EXT_CF_INST                              0xC3FFFFFF
+#define   S_SQ_CF_ALU_WORD1_EXT_BARRIER(x)                           (((x) & 0x1) << 31)
+#define   G_SQ_CF_ALU_WORD1_EXT_BARRIER(x)                           (((x) >> 31) & 0x1)
+#define   C_SQ_CF_ALU_WORD1_EXT_BARRIER                              0x7FFFFFFF
+
 /* done */
 #define P_SQ_CF_ALLOC_EXPORT_WORD0
 #define   S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(x)                   (((x) & 0x1FFF) << 0)
diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c
index ba473a5..c9b4845 100644
--- a/src/gallium/drivers/r600/r600_asm.c
+++ b/src/gallium/drivers/r600/r600_asm.c
@@ -260,8 +260,14 @@ static int r600_bytecode_add_cf(struct r600_bytecode *bc)
 	if (cf == NULL)
 		return -ENOMEM;
 	LIST_ADDTAIL(&cf->list, &bc->cf);
-	if (bc->cf_last)
+	if (bc->cf_last) {
 		cf->id = bc->cf_last->id + 2;
+		if (bc->cf_last->eg_alu_extended) {
+			/* take into account extended alu size */
+			cf->id += 2;
+			bc->ndw += 2;
+		}
+	}
 	bc->cf_last = cf;
 	bc->ncf++;
 	bc->ndw += 2;
@@ -1143,116 +1149,157 @@ static int merge_inst_groups(struct r600_bytecode *bc, struct r600_bytecode_alu
 	return 0;
 }
 
-/* This code handles kcache lines as single blocks of 32 constants. We could
- * probably do slightly better by recognizing that we actually have two
- * consecutive lines of 16 constants, but the resulting code would also be
- * somewhat more complicated. */
-static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode *bc, struct r600_bytecode_alu *alu, int type)
+/* we'll keep kcache sets sorted by bank & addr */
+static int r600_bytecode_alloc_kcache_line(struct r600_bytecode *bc,
+		struct r600_bytecode_kcache *kcache,
+		unsigned bank, unsigned line)
 {
-	struct r600_bytecode_kcache *kcache = bc->cf_last->kcache;
-	unsigned int required_lines;
-	unsigned int free_lines = 0;
-	unsigned int cache_line[3];
-	unsigned int count = 0;
-	unsigned int i, j;
-	int r;
+	int i, kcache_banks = bc->chip_class >= EVERGREEN ? 4 : 2;
 
-	/* Collect required cache lines. */
-	for (i = 0; i < 3; ++i) {
-		boolean found = false;
-		unsigned int line;
+	for (i = 0; i < kcache_banks; i++) {
+		if (kcache[i].mode) {
+			int d;
 
-		if (alu->src[i].sel < 512)
-			continue;
+			if (kcache[i].bank < bank)
+				continue;
 
-		line = ((alu->src[i].sel - 512) / 32) * 2;
+			if ((kcache[i].bank == bank && kcache[i].addr > line+1) ||
+					kcache[i].bank > bank) {
+				/* try to insert new line */
+				if (kcache[kcache_banks-1].mode) {
+					/* all sets are in use */
+					return -ENOMEM;
+				}
 
-		for (j = 0; j < count; ++j) {
-			if (cache_line[j] == line) {
-				found = true;
-				break;
+				memmove(&kcache[i+1],&kcache[i], (kcache_banks-i-1)*sizeof(struct r600_bytecode_kcache));
+				kcache[i].mode = V_SQ_CF_KCACHE_LOCK_1;
+				kcache[i].bank = bank;
+				kcache[i].addr = line;
+				return 0;
 			}
-		}
 
-		if (!found)
-			cache_line[count++] = line;
-	}
+			d = line - kcache[i].addr;
 
-	/* This should never actually happen. */
-	if (count >= 3) return -ENOMEM;
-
-	for (i = 0; i < 2; ++i) {
-		if (kcache[i].mode == V_SQ_CF_KCACHE_NOP) {
-			++free_lines;
-		}
-	}
-
-	/* Filter lines pulled in by previous intructions. Note that this is
-	 * only for the required_lines count, we can't remove these from the
-	 * cache_line array since we may have to start a new ALU clause. */
-	for (i = 0, required_lines = count; i < count; ++i) {
-		for (j = 0; j < 2; ++j) {
-			if (kcache[j].mode == V_SQ_CF_KCACHE_LOCK_2 &&
-			    kcache[j].addr == cache_line[i]) {
-				--required_lines;
-				break;
-			}
+			if (d == -1) {
+				kcache[i].addr--;
+				if (kcache[i].mode == V_SQ_CF_KCACHE_LOCK_2) {
+					/* we are prepending the line to the current set,
+					 * discarding the existing second line,
+					 * so we'll have to insert line+2 after it */
+					line += 2;
+					continue;
+				} else if (kcache[i].mode == V_SQ_CF_KCACHE_LOCK_1) {
+					kcache[i].mode = V_SQ_CF_KCACHE_LOCK_2;
+					return 0;
+				} else {
+					/* V_SQ_CF_KCACHE_LOCK_LOOP_INDEX is not supported */
+					return -ENOMEM;
+				}
+			} else if (d == 1) {
+				kcache[i].mode = V_SQ_CF_KCACHE_LOCK_2;
+				return 0;
+			} else if (d == 0)
+				return 0;
+		} else { /* free kcache set - use it */
+			kcache[i].mode = V_SQ_CF_KCACHE_LOCK_1;
+			kcache[i].bank = bank;
+			kcache[i].addr = line;
+			return 0;
 		}
 	}
+	return -ENOMEM;
+}
 
-	/* Start a new ALU clause if needed. */
-	if (required_lines > free_lines) {
-		if ((r = r600_bytecode_add_cf(bc))) {
-			return r;
-		}
-		bc->cf_last->inst = type;
-		kcache = bc->cf_last->kcache;
-	}
+static int r600_bytecode_alloc_inst_kcache_lines(struct r600_bytecode *bc,
+		struct r600_bytecode_kcache *kcache,
+		struct r600_bytecode_alu *alu)
+{
+	int i, r;
 
-	/* Setup the kcache lines. */
-	for (i = 0; i < count; ++i) {
-		boolean found = false;
+	for (i = 0; i < 3; i++) {
+		unsigned bank, line, sel = alu->src[i].sel;
 
-		for (j = 0; j < 2; ++j) {
-			if (kcache[j].mode == V_SQ_CF_KCACHE_LOCK_2 &&
-			    kcache[j].addr == cache_line[i]) {
-				found = true;
-				break;
-			}
-		}
+		if (sel < 512)
+			continue;
 
-		if (found) continue;
+		bank = alu->src[i].kc_bank;
+		line = (sel-512)>>4;
 
-		for (j = 0; j < 2; ++j) {
-			if (kcache[j].mode == V_SQ_CF_KCACHE_NOP) {
-				kcache[j].bank = 0;
-				kcache[j].addr = cache_line[i];
-				kcache[j].mode = V_SQ_CF_KCACHE_LOCK_2;
-				break;
-			}
-		}
+		if ((r = r600_bytecode_alloc_kcache_line(bc, kcache, bank, line)))
+			return r;
 	}
+	return 0;
+}
+
+static int r600_bytecode_assign_kcache_banks(struct r600_bytecode *bc,
+		struct r600_bytecode_alu *alu,
+		struct r600_bytecode_kcache * kcache)
+{
+	int i, j;
 
 	/* Alter the src operands to refer to the kcache. */
 	for (i = 0; i < 3; ++i) {
 		static const unsigned int base[] = {128, 160, 256, 288};
-		unsigned int line;
+		unsigned int line, sel = alu->src[i].sel, found = 0;
 
-		if (alu->src[i].sel < 512)
+		if (sel < 512)
 			continue;
 
-		alu->src[i].sel -= 512;
-		line = (alu->src[i].sel / 32) * 2;
+		sel -= 512;
+		line = sel>>4;
 
-		for (j = 0; j < 2; ++j) {
-			if (kcache[j].mode == V_SQ_CF_KCACHE_LOCK_2 &&
-			    kcache[j].addr == line) {
-				alu->src[i].sel &= 0x1f;
-				alu->src[i].sel += base[j];
-				break;
+		for (j = 0; j < 4 && !found; ++j) {
+			switch (kcache[j].mode) {
+			case V_SQ_CF_KCACHE_NOP:
+			case V_SQ_CF_KCACHE_LOCK_LOOP_INDEX:
+				R600_ERR("unexpected kcache line mode\n");
+				return -ENOMEM;
+			default:
+				if (kcache[j].bank == alu->src[i].kc_bank &&
+						kcache[j].addr <= line &&
+						line < kcache[j].addr + kcache[j].mode) {
+					alu->src[i].sel = sel - (kcache[j].addr<<4);
+					alu->src[i].sel += base[j];
+					found=1;
+			    }
 			}
 		}
 	}
+	return 0;
+}
+
+static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode *bc, struct r600_bytecode_alu *alu, int type)
+{
+	struct r600_bytecode_kcache kcache_sets[4];
+	struct r600_bytecode_kcache *kcache = kcache_sets;
+	int r;
+
+	memcpy(kcache, bc->cf_last->kcache, 4 * sizeof(struct r600_bytecode_kcache));
+
+	if ((r = r600_bytecode_alloc_inst_kcache_lines(bc, kcache, alu))) {
+		/* can't alloc, need to start new clause */
+		if ((r = r600_bytecode_add_cf(bc))) {
+			return r;
+		}
+		bc->cf_last->inst = type;
+
+		/* retry with the new clause */
+		kcache = bc->cf_last->kcache;
+		if ((r = r600_bytecode_alloc_inst_kcache_lines(bc, kcache, alu))) {
+			/* can't alloc again- should never happen */
+			return r;
+		}
+	} else {
+		/* update kcache sets */
+		memcpy(bc->cf_last->kcache, kcache, 4 * sizeof(struct r600_bytecode_kcache));
+	}
+
+	/* if we actually used more than 2 kcache sets - use ALU_EXTENDED on eg+ */
+	if (kcache[2].mode != V_SQ_CF_KCACHE_NOP) {
+		if (bc->chip_class < EVERGREEN)
+			return -ENOMEM;
+		bc->cf_last->eg_alu_extended = 1;
+	}
 
 	return 0;
 }
@@ -1922,6 +1969,8 @@ int r600_bytecode_build(struct r600_bytecode *bc)
 					if (r)
 						return r;
 					r600_bytecode_alu_adjust_literals(bc, alu, literal, nliteral);
+					r600_bytecode_assign_kcache_banks(bc, alu, cf->kcache);
+
 					switch(bc->chip_class) {
 					case EVERGREEN: /* eg alu is same encoding as r700 */
 					case CAYMAN:
@@ -2017,6 +2066,8 @@ int r600_bytecode_build(struct r600_bytecode *bc)
 					if (r)
 						return r;
 					r600_bytecode_alu_adjust_literals(bc, alu, literal, nliteral);
+					r600_bytecode_assign_kcache_banks(bc, alu, cf->kcache);
+
 					switch(bc->chip_class) {
 					case R600:
 						r = r600_bytecode_alu_build(bc, alu, addr);
@@ -2157,6 +2208,19 @@ void r600_bytecode_dump(struct r600_bytecode *bc)
 			case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER:
 			case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER:
 			case EG_V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE:
+				if (cf->eg_alu_extended) {
+					fprintf(stderr, "%04d %08X ALU_EXT0 ", id, bc->bytecode[id]);
+					fprintf(stderr, "KCACHE_BANK2:%X ", cf->kcache[2].bank);
+					fprintf(stderr, "KCACHE_BANK3:%X ", cf->kcache[3].bank);
+					fprintf(stderr, "KCACHE_MODE2:%X\n", cf->kcache[2].mode);
+					id++;
+					fprintf(stderr, "%04d %08X ALU_EXT1 ", id, bc->bytecode[id]);
+					fprintf(stderr, "KCACHE_MODE3:%X ", cf->kcache[3].mode);
+					fprintf(stderr, "KCACHE_ADDR2:%X ", cf->kcache[2].addr);
+					fprintf(stderr, "KCACHE_ADDR3:%X\n", cf->kcache[3].addr);
+					id++;
+				}
+
 				fprintf(stderr, "%04d %08X ALU ", id, bc->bytecode[id]);
 				fprintf(stderr, "ADDR:%d ", cf->addr);
 				fprintf(stderr, "KCACHE_MODE0:%X ", cf->kcache[0].mode);
diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h
index 00f7e59..a68b299 100644
--- a/src/gallium/drivers/r600/r600_asm.h
+++ b/src/gallium/drivers/r600/r600_asm.h
@@ -32,6 +32,7 @@ struct r600_bytecode_alu_src {
 	unsigned			neg;
 	unsigned			abs;
 	unsigned			rel;
+	unsigned			kc_bank;
 	uint32_t			value;
 };
 
@@ -144,8 +145,9 @@ struct r600_bytecode_cf {
 	unsigned			cond;
 	unsigned			pop_count;
 	unsigned			cf_addr; /* control flow addr */
-	struct r600_bytecode_kcache		kcache[2];
+	struct r600_bytecode_kcache		kcache[4];
 	unsigned			r6xx_uses_waterfall;
+	unsigned			eg_alu_extended;
 	struct list_head		alu;
 	struct list_head		tex;
 	struct list_head		vtx;
commit cbdf7de014090c28a0f5cd2f22a055dd043cdb7f
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Sun Jan 15 09:29:50 2012 -0500

    r600g: implement clip distances
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 91d47296967ebfaf685f3870998ea0a1450ecf55)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 352ea23..d5e4aef 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -907,6 +907,7 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 	rs->flatshade = state->flatshade;
 	rs->sprite_coord_enable = state->sprite_coord_enable;
 	rs->two_side = state->light_twoside;
+	rs->clip_plane_enable = state->clip_plane_enable;
 
 	clip_rule = state->scissor ? 0xAAAA : 0xFFFF;
 
@@ -944,8 +945,8 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 		S_028814_POLYMODE_FRONT_PTYPE(r600_translate_fill(state->fill_front)) |
 		S_028814_POLYMODE_BACK_PTYPE(r600_translate_fill(state->fill_back)), 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_02881C_PA_CL_VS_OUT_CNTL,
-			S_02881C_USE_VTX_POINT_SIZE(state->point_size_per_vertex) |
-			S_02881C_VS_OUT_MISC_VEC_ENA(state->point_size_per_vertex), 0xFFFFFFFF, NULL, 0);
+			S_02881C_USE_VTX_POINT_SIZE(state->point_size_per_vertex),
+			S_02881C_USE_VTX_POINT_SIZE(1), NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_028820_PA_CL_NANINF_CNTL, 0x00000000, 0xFFFFFFFF, NULL, 0);
 	/* point size 12.4 fixed point */
 	tmp = (unsigned)(state->point_size * 8.0);
@@ -992,9 +993,10 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 	r600_pipe_state_add_reg(rstate, R_028B7C_PA_SU_POLY_OFFSET_CLAMP, fui(state->offset_clamp), 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_02820C_PA_SC_CLIPRECT_RULE, clip_rule, 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL,
-			S_028810_PS_UCP_MODE(3) | (state->clip_plane_enable & 63) |
-			S_028810_ZCLIP_NEAR_DISABLE(!state->depth_clip) |
-			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip), 0xFFFFFFFF, NULL, 0);
+			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(!state->depth_clip) |
+			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip),
+			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(1) |
+			S_028810_ZCLIP_FAR_DISABLE(1), NULL, 0);
 	return rstate;
 }
 
@@ -2467,6 +2469,16 @@ void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader
 	r600_pipe_state_add_reg(rstate,
 				R_03A200_SQ_LOOP_CONST_0 + (32 * 4), 0x01000FFF,
 				0xFFFFFFFF, NULL, 0);
+
+	r600_pipe_state_add_reg(rstate,
+				R_02881C_PA_CL_VS_OUT_CNTL,
+				S_02881C_VS_OUT_CCDIST0_VEC_ENA((rshader->clip_dist_write & 0x0F) != 0) |
+				S_02881C_VS_OUT_CCDIST1_VEC_ENA((rshader->clip_dist_write & 0xF0) != 0) |
+				S_02881C_VS_OUT_MISC_VEC_ENA(rshader->vs_out_misc_write),
+				S_02881C_VS_OUT_CCDIST0_VEC_ENA(1) |
+				S_02881C_VS_OUT_CCDIST1_VEC_ENA(1) |
+				S_02881C_VS_OUT_MISC_VEC_ENA(1),
+				NULL, 0);
 }
 
 void evergreen_fetch_shader(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index bd0b8fe..ce808d7 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -110,6 +110,7 @@ struct r600_pipe_rasterizer {
 	boolean				flatshade;
 	boolean				two_side;
 	unsigned			sprite_coord_enable;
+	unsigned                        clip_plane_enable;
 	float				offset_units;
 	float				offset_scale;
 };
@@ -220,6 +221,8 @@ struct r600_pipe_context {
 	boolean				clamp_vertex_color;
 	boolean				clamp_fragment_color;
 	boolean				two_side;
+	unsigned			user_clip_plane_enable;
+	unsigned			clip_dist_enable;
 	unsigned			sprite_coord_enable;
 	boolean				export_16bpc;
 	unsigned			alpha_ref;
diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index 8a06e8f..78ffefe 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -468,6 +468,17 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
 		ctx->shader->output[i].spi_sid = r600_spi_sid(&ctx->shader->output[i]);
 		ctx->shader->output[i].gpr = ctx->file_offset[TGSI_FILE_OUTPUT] + d->Range.First;
 		ctx->shader->output[i].interpolate = d->Declaration.Interpolate;
+		ctx->shader->output[i].write_mask = d->Declaration.UsageMask;
+		if (ctx->type == TGSI_PROCESSOR_VERTEX) {
+			switch (d->Semantic.Name) {
+			case TGSI_SEMANTIC_CLIPDIST:
+				ctx->shader->clip_dist_write |= d->Declaration.UsageMask << (d->Semantic.Index << 2);
+				break;
+			case TGSI_SEMANTIC_PSIZE:
+				ctx->shader->vs_out_misc_write = 1;
+				break;
+			}
+		}
 		break;
 	case TGSI_FILE_CONSTANT:
 	case TGSI_FILE_TEMPORARY:
@@ -882,9 +893,15 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 			break;
 		case TGSI_TOKEN_TYPE_PROPERTY:
 			property = &ctx.parse.FullToken.FullProperty;
-			if (property->Property.PropertyName == TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS) {
+			switch (property->Property.PropertyName) {
+			case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS:
 				if (property->u[0].Data == 1)
 					shader->fs_write_all = TRUE;
+				break;
+			case TGSI_PROPERTY_VS_PROHIBIT_UCPS:
+				if (property->u[0].Data == 1)
+					shader->vs_prohibit_ucps = TRUE;
+				break;
 			}
 			break;
 		default:
@@ -1053,8 +1070,9 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 
 	/* export output */
 	j = 0;
+
 	for (i = 0, pos0 = 0; i < noutput; i++) {
-		memset(&output[i], 0, sizeof(struct r600_bytecode_output));
+		memset(&output[i+j], 0, sizeof(struct r600_bytecode_output));
 		output[i + j].gpr = shader->output[i].gpr;
 		output[i + j].elem_size = 3;
 		output[i + j].swizzle_x = 0;
@@ -1064,21 +1082,41 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 		output[i + j].burst_count = 1;
 		output[i + j].barrier = 1;
 		output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
-		output[i + j].array_base = i - pos0;
+		output[i + j].array_base = i+j - pos0;
 		output[i + j].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
 		switch (ctx.type) {
 		case TGSI_PROCESSOR_VERTEX:
-			if (shader->output[i].name == TGSI_SEMANTIC_POSITION) {
+			switch (shader->output[i].name) {
+			case TGSI_SEMANTIC_POSITION:
 				output[i + j].array_base = 60;
 				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
 				/* position doesn't count in array_base */
 				pos0++;
-			}
-			if (shader->output[i].name == TGSI_SEMANTIC_PSIZE) {
+				break;
+
+			case TGSI_SEMANTIC_PSIZE:
 				output[i + j].array_base = 61;
 				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
 				/* position doesn't count in array_base */
 				pos0++;
+				break;
+
+			case TGSI_SEMANTIC_CLIPDIST:
+				/* array base for enabled OUT_MISC_VEC & CCDIST[0|1]_VEC
+				 * vectors is allocated sequentially, starting from 61 */
+				output[i + j].array_base = 61 + shader->output[i].sid
+					/* +1 if OUT_MISC_VEC is enabled */
+					+ shader->vs_out_misc_write
+					/* -1 if OUT_CCDIST0_VEC is disabled */
+					- (((shader->clip_dist_write & 0xF) == 0)? 1 : 0);
+				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
+				j++;
+				pos0++;
+				/* duplicate it as PARAM to pass to the pixel shader */
+				memcpy(&output[i+j], &output[i+j-1], sizeof(struct r600_bytecode_output));
+				output[i + j].array_base = i+j-pos0;
+				output[i + j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
+				break;
 			}
 			break;
 		case TGSI_PROCESSOR_FRAGMENT:
diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h
index 530a776..323f948 100644
--- a/src/gallium/drivers/r600/r600_shader.h
+++ b/src/gallium/drivers/r600/r600_shader.h
@@ -34,6 +34,7 @@ struct r600_shader_io {
 	unsigned		interpolate;
 	boolean                 centroid;
 	unsigned		lds_pos; /* for evergreen */
+	unsigned		write_mask;
 };
 
 struct r600_shader {
@@ -46,9 +47,14 @@ struct r600_shader {
 	struct r600_shader_io	output[32];
 	boolean			uses_kill;
 	boolean			fs_write_all;
+	boolean			vs_prohibit_ucps;
 	boolean			clamp_color;
 	boolean			two_side;
 	unsigned		nr_cbufs;
+	/* bit n is set if the shader writes gl_ClipDistance[n] */
+	unsigned		clip_dist_write;
+	/* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
+	boolean			vs_out_misc_write;
 };
 
 #endif
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index fb95caa..513fd17 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -959,6 +959,7 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 	rs->flatshade = state->flatshade;
 	rs->sprite_coord_enable = state->sprite_coord_enable;
 	rs->two_side = state->light_twoside;
+	rs->clip_plane_enable = state->clip_plane_enable;
 
 	clip_rule = state->scissor ? 0xAAAA : 0xFFFF;
 	/* offset */
@@ -995,8 +996,8 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 		S_028814_POLYMODE_FRONT_PTYPE(r600_translate_fill(state->fill_front)) |
 		S_028814_POLYMODE_BACK_PTYPE(r600_translate_fill(state->fill_back)), 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_02881C_PA_CL_VS_OUT_CNTL,
-			S_02881C_USE_VTX_POINT_SIZE(state->point_size_per_vertex) |
-			S_02881C_VS_OUT_MISC_VEC_ENA(state->point_size_per_vertex), 0xFFFFFFFF, NULL, 0);
+			S_02881C_USE_VTX_POINT_SIZE(state->point_size_per_vertex),
+			S_02881C_USE_VTX_POINT_SIZE(1), NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_028820_PA_CL_NANINF_CNTL, 0x00000000, 0xFFFFFFFF, NULL, 0);
 	/* point size 12.4 fixed point */
 	tmp = (unsigned)(state->point_size * 8.0);
@@ -1035,10 +1036,10 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 	r600_pipe_state_add_reg(rstate, R_028DFC_PA_SU_POLY_OFFSET_CLAMP, fui(state->offset_clamp), 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_02820C_PA_SC_CLIPRECT_RULE, clip_rule, 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL,
-			S_028810_PS_UCP_MODE(3) | (state->clip_plane_enable & 63) |
-			S_028810_ZCLIP_NEAR_DISABLE(!state->depth_clip) |
-			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip), 0xFFFFFFFF, NULL, 0);
-
+			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(!state->depth_clip) |
+			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip),
+			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(1) |
+			S_028810_ZCLIP_FAR_DISABLE(1), NULL, 0);
 	return rstate;
 }
 
@@ -2244,6 +2245,16 @@ void r600_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shad
 	r600_pipe_state_add_reg(rstate,
 				R_03E200_SQ_LOOP_CONST_0 + (32 * 4), 0x01000FFF,
 				0xFFFFFFFF, NULL, 0);
+
+	r600_pipe_state_add_reg(rstate,
+				R_02881C_PA_CL_VS_OUT_CNTL,
+				S_02881C_VS_OUT_CCDIST0_VEC_ENA((rshader->clip_dist_write & 0x0F) != 0) |
+				S_02881C_VS_OUT_CCDIST1_VEC_ENA((rshader->clip_dist_write & 0xF0) != 0) |
+				S_02881C_VS_OUT_MISC_VEC_ENA(rshader->vs_out_misc_write),
+				S_02881C_VS_OUT_CCDIST0_VEC_ENA(1) |
+				S_02881C_VS_OUT_CCDIST1_VEC_ENA(1) |
+				S_02881C_VS_OUT_MISC_VEC_ENA(1),
+				NULL, 0);
 }
 
 void r600_fetch_shader(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 7f8aad6..ec454ac 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -550,6 +550,30 @@ static int r600_shader_rebuild(struct pipe_context * ctx, struct r600_pipe_shade
 static void r600_update_derived_state(struct r600_pipe_context *rctx)
 {
 	struct pipe_context * ctx = (struct pipe_context*)rctx;
+	struct r600_pipe_state rstate;
+	unsigned user_clip_plane_enable;
+	unsigned clip_dist_enable;
+
+	if (rctx->vs_shader->shader.clip_dist_write || rctx->vs_shader->shader.vs_prohibit_ucps)
+		user_clip_plane_enable = 0;
+	else
+		user_clip_plane_enable = rctx->rasterizer->clip_plane_enable & 0x3F;
+
+	clip_dist_enable = rctx->rasterizer->clip_plane_enable & rctx->vs_shader->shader.clip_dist_write & 0xFF;
+	rstate.nregs = 0;
+
+	if (user_clip_plane_enable != rctx->user_clip_plane_enable) {
+		r600_pipe_state_add_reg(&rstate, R_028810_PA_CL_CLIP_CNTL, user_clip_plane_enable , 0x3F, NULL, 0);
+		rctx->user_clip_plane_enable = user_clip_plane_enable;
+	}
+
+	if (clip_dist_enable != rctx->clip_dist_enable) {
+		r600_pipe_state_add_reg(&rstate, R_02881C_PA_CL_VS_OUT_CNTL, clip_dist_enable, 0xFF, NULL, 0);
+		rctx->clip_dist_enable = clip_dist_enable;
+	}
+
+	if (rstate.nregs)
+		r600_context_pipe_state_set(&rctx->ctx, &rstate);
 
 	if (!rctx->blitter->running) {
 		if (rctx->have_depth_fb || rctx->have_depth_texture)
commit daefd7f20bc8e79b871a46c50710266fd2006d8c
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Fri Jan 6 08:13:18 2012 +0400

    r600g: implement two-sided lighting (v3)
    
    v2: select the colors in the pixel shader
    
    v3: fix rs state creation for pre-evergreen
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 725a820b926575265e6790601a0defd9c30947dc)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 185ea77..352ea23 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -906,6 +906,7 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 	rs->clamp_fragment_color = state->clamp_fragment_color;
 	rs->flatshade = state->flatshade;
 	rs->sprite_coord_enable = state->sprite_coord_enable;
+	rs->two_side = state->light_twoside;
 
 	clip_rule = state->scissor ? 0xAAAA : 0xFFFF;
 
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index 447b9dc..bd0b8fe 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -108,6 +108,7 @@ struct r600_pipe_rasterizer {
 	boolean				clamp_vertex_color;
 	boolean				clamp_fragment_color;
 	boolean				flatshade;
+	boolean				two_side;
 	unsigned			sprite_coord_enable;
 	float				offset_units;
 	float				offset_scale;
@@ -218,6 +219,7 @@ struct r600_pipe_context {
 	/* shader information */
 	boolean				clamp_vertex_color;
 	boolean				clamp_fragment_color;
+	boolean				two_side;
 	unsigned			sprite_coord_enable;
 	boolean				export_16bpc;
 	unsigned			alpha_ref;
diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index 568ab71..8a06e8f 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -191,6 +191,8 @@ struct r600_shader_ctx {
 	boolean                                 input_linear;
 	boolean                                 input_perspective;
 	int					num_interp_gpr;
+	int					face_gpr;
+	int					colors_used;
 };
 
 struct r600_shader_tgsi_instruction {
@@ -374,12 +376,6 @@ static int r600_spi_sid(struct r600_shader_io * io)
 			/* For generic params simply use sid from tgsi */
 			index = io->sid;
 		} else {
-
-			/* FIXME: two-side rendering is broken in r600g, this will
-			 * keep old functionality */
-			if (name == TGSI_SEMANTIC_BCOLOR)
-				name = TGSI_SEMANTIC_COLOR;
-
 			/* For non-generic params - pack name and sid into 8 bits */
 			index = 0x80 | (name<<3) | (io->sid);
 		}
@@ -393,6 +389,51 @@ static int r600_spi_sid(struct r600_shader_io * io)
 	return index;
 };
 
+/* turn input into interpolate on EG */
+static int evergreen_interp_input(struct r600_shader_ctx *ctx, int index)
+{
+	int r = 0;
+
+	if (ctx->shader->input[index].spi_sid) {
+		ctx->shader->input[index].lds_pos = ctx->shader->nlds++;
+		if (ctx->shader->input[index].interpolate > 0) {
+			r = evergreen_interp_alu(ctx, index);
+		} else {
+			r = evergreen_interp_flat(ctx, index);
+		}
+	}
+	return r;
+}
+
+static int select_twoside_color(struct r600_shader_ctx *ctx, int front, int back)
+{
+	struct r600_bytecode_alu alu;
+	int i, r;
+	int gpr_front = ctx->shader->input[front].gpr;
+	int gpr_back = ctx->shader->input[back].gpr;
+
+	for (i = 0; i < 4; i++) {
+		memset(&alu, 0, sizeof(alu));
+		alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT);
+		alu.is_op3 = 1;
+		alu.dst.write = 1;
+		alu.dst.sel = gpr_front;
+		alu.src[0].sel = ctx->face_gpr;
+		alu.src[1].sel = gpr_front;
+		alu.src[2].sel = gpr_back;
+
+		alu.dst.chan = i;
+		alu.src[1].chan = i;
+		alu.src[2].chan = i;
+		alu.last = (i==3);
+
+		if ((r = r600_bytecode_add_alu(ctx->bc, &alu)))
+			return r;
+	}
+
+	return 0;
+}
+
 static int tgsi_declaration(struct r600_shader_ctx *ctx)
 {
 	struct tgsi_full_declaration *d = &ctx->parse.FullToken.FullDeclaration;
@@ -408,15 +449,15 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
 		ctx->shader->input[i].interpolate = d->Declaration.Interpolate;
 		ctx->shader->input[i].centroid = d->Declaration.Centroid;
 		ctx->shader->input[i].gpr = ctx->file_offset[TGSI_FILE_INPUT] + d->Range.First;
-		if (ctx->type == TGSI_PROCESSOR_FRAGMENT && ctx->bc->chip_class >= EVERGREEN) {
-			/* turn input into interpolate on EG */
-			if (ctx->shader->input[i].spi_sid) {
-				ctx->shader->input[i].lds_pos = ctx->shader->nlds++;
-				if (ctx->shader->input[i].interpolate > 0) {
-					evergreen_interp_alu(ctx, i);
-				} else {
-					evergreen_interp_flat(ctx, i);
-				}
+		if (ctx->type == TGSI_PROCESSOR_FRAGMENT) {
+			if (ctx->shader->input[i].name == TGSI_SEMANTIC_FACE)
+				ctx->face_gpr = ctx->shader->input[i].gpr;
+			else if (ctx->shader->input[i].name == TGSI_SEMANTIC_COLOR)
+				ctx->colors_used++;
+			if (ctx->bc->chip_class >= EVERGREEN) {
+				r = evergreen_interp_input(ctx, i);
+				if (r)
+					return r;
 			}
 		}
 		break;
@@ -690,6 +731,47 @@ static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx)
 	return 0;
 }
 
+static int process_twoside_color_inputs(struct r600_shader_ctx *ctx)
+{
+	int i, r, count = ctx->shader->ninput;
+
+	/* additional inputs will be allocated right after the existing inputs,
+	 * we won't need them after the color selection, so we don't need to
+	 * reserve these gprs for the rest of the shader code and to adjust
+	 * output offsets etc. */
+	int gpr = ctx->file_offset[TGSI_FILE_INPUT] +
+			ctx->info.file_max[TGSI_FILE_INPUT] + 1;
+
+	if (ctx->face_gpr == -1) {
+		i = ctx->shader->ninput++;
+		ctx->shader->input[i].name = TGSI_SEMANTIC_FACE;
+		ctx->shader->input[i].spi_sid = 0;
+		ctx->shader->input[i].gpr = gpr++;
+		ctx->face_gpr = ctx->shader->input[i].gpr;
+	}
+
+	for (i = 0; i < count; i++) {
+		if (ctx->shader->input[i].name == TGSI_SEMANTIC_COLOR) {
+			int ni = ctx->shader->ninput++;
+			memcpy(&ctx->shader->input[ni],&ctx->shader->input[i], sizeof(struct r600_shader_io));
+			ctx->shader->input[ni].name = TGSI_SEMANTIC_BCOLOR;
+			ctx->shader->input[ni].spi_sid = r600_spi_sid(&ctx->shader->input[ni]);
+			ctx->shader->input[ni].gpr = gpr++;
+
+			if (ctx->bc->chip_class >= EVERGREEN) {
+				r = evergreen_interp_input(ctx, ni);
+				if (r)
+					return r;
+			}
+
+			r = select_twoside_color(ctx, i, ni);
+			if (r)
+				return r;
+		}
+	}
+	return 0;
+}
+
 static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pipe_shader *pipeshader)
 {
 	struct r600_shader *shader = &pipeshader->shader;
@@ -713,6 +795,11 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 	shader->processor_type = ctx.type;
 	ctx.bc->type = shader->processor_type;
 
+	ctx.face_gpr = -1;
+	ctx.colors_used = 0;
+
+	shader->two_side = (ctx.type == TGSI_PROCESSOR_FRAGMENT) && rctx->two_side;
+
 	shader->clamp_color = (((ctx.type == TGSI_PROCESSOR_FRAGMENT) && rctx->clamp_fragment_color) ||
 		((ctx.type == TGSI_PROCESSOR_VERTEX) && rctx->clamp_vertex_color));
 
@@ -792,6 +879,31 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 				goto out_err;
 			break;
 		case TGSI_TOKEN_TYPE_INSTRUCTION:
+			break;
+		case TGSI_TOKEN_TYPE_PROPERTY:
+			property = &ctx.parse.FullToken.FullProperty;
+			if (property->Property.PropertyName == TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS) {
+				if (property->u[0].Data == 1)
+					shader->fs_write_all = TRUE;
+			}
+			break;
+		default:
+			R600_ERR("unsupported token type %d\n", ctx.parse.FullToken.Token.Type);
+			r = -EINVAL;
+			goto out_err;
+		}
+	}
+
+	if (shader->two_side && ctx.colors_used) {
+		if ((r = process_twoside_color_inputs(&ctx)))
+			return r;
+	}
+
+	tgsi_parse_init(&ctx.parse, tokens);
+	while (!tgsi_parse_end_of_tokens(&ctx.parse)) {
+		tgsi_parse_token(&ctx.parse);
+		switch (ctx.parse.FullToken.Token.Type) {
+		case TGSI_TOKEN_TYPE_INSTRUCTION:
 			r = tgsi_is_supported(&ctx);
 			if (r)
 				goto out_err;
@@ -814,17 +926,8 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 			if (r)
 				goto out_err;
 			break;
-		case TGSI_TOKEN_TYPE_PROPERTY:
-			property = &ctx.parse.FullToken.FullProperty;
-			if (property->Property.PropertyName == TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS) {
-				if (property->u[0].Data == 1)
-					shader->fs_write_all = TRUE;
-			}
-			break;
 		default:
-			R600_ERR("unsupported token type %d\n", ctx.parse.FullToken.Token.Type);
-			r = -EINVAL;
-			goto out_err;
+			break;
 		}
 	}
 
diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h
index 9990ba6..530a776 100644
--- a/src/gallium/drivers/r600/r600_shader.h
+++ b/src/gallium/drivers/r600/r600_shader.h
@@ -47,6 +47,7 @@ struct r600_shader {
 	boolean			uses_kill;
 	boolean			fs_write_all;
 	boolean			clamp_color;
+	boolean			two_side;
 	unsigned		nr_cbufs;
 };
 
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index 8fc5618..fb95caa 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -958,6 +958,7 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 	rs->clamp_fragment_color = state->clamp_fragment_color;
 	rs->flatshade = state->flatshade;
 	rs->sprite_coord_enable = state->sprite_coord_enable;
+	rs->two_side = state->light_twoside;
 
 	clip_rule = state->scissor ? 0xAAAA : 0xFFFF;
 	/* offset */
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 054ab90..7f8aad6 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -103,6 +103,7 @@ void r600_bind_rs_state(struct pipe_context *ctx, void *state)
 	rctx->clamp_fragment_color = rs->clamp_fragment_color;
 
 	rctx->sprite_coord_enable = rs->sprite_coord_enable;
+	rctx->two_side = rs->two_side;
 
 	rctx->rasterizer = rs;
 
@@ -564,6 +565,7 @@ static void r600_update_derived_state(struct r600_pipe_context *rctx)
 	}
 
 	if ((rctx->ps_shader->shader.clamp_color != rctx->clamp_fragment_color) ||
+	    (rctx->ps_shader->shader.two_side != rctx->two_side) ||
 	    ((rctx->chip_class >= EVERGREEN) && rctx->ps_shader->shader.fs_write_all &&
 	     (rctx->ps_shader->shader.nr_cbufs != rctx->nr_cbufs))) {
 		r600_shader_rebuild(&rctx->context, rctx->ps_shader);
commit 4b6dc4c1b3d8055e4504562ce3c0211086ced915
Author: Dave Airlie <airlied at redhat.com>
Date:   Sun Jan 22 16:52:19 2012 +0000

    r600g: srgb mode is only valid on certain format types.
    
    "If set, forces degamma on XYZ if format is
    FMT_8_8_8_8, FMT_BC1, FMT_BC2, or FMT_BC3"
    
    Don't claim support for sRGB on any other formts.
    
    This fixes glean texture_srgb.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit a9d8809f16feb7f6d5d723f2afa2cfbea60cae55)

diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c
index decd941..6692aa6 100644
--- a/src/gallium/drivers/r600/r600_texture.c
+++ b/src/gallium/drivers/r600/r600_texture.c
@@ -869,6 +869,7 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen,
 	const struct util_format_description *desc;
 	boolean uniform = TRUE;
 	static int r600_enable_s3tc = -1;
+	bool is_srgb_valid = FALSE;
 
 	int i;
 	const uint32_t sign_bit[4] = {
@@ -980,14 +981,17 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen,
 		case PIPE_FORMAT_DXT1_SRGB:
 		case PIPE_FORMAT_DXT1_SRGBA:
 			result = FMT_BC1;
+			is_srgb_valid = TRUE;
 			goto out_word4;
 		case PIPE_FORMAT_DXT3_RGBA:
 		case PIPE_FORMAT_DXT3_SRGBA:
 			result = FMT_BC2;
+			is_srgb_valid = TRUE;
 			goto out_word4;
 		case PIPE_FORMAT_DXT5_RGBA:
 		case PIPE_FORMAT_DXT5_SRGBA:
 			result = FMT_BC3;
+			is_srgb_valid = TRUE;
 			goto out_word4;
 		default:
 			goto out_unknown;
@@ -1095,6 +1099,7 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen,
 				goto out_word4;
 			case 4:
 				result = FMT_8_8_8_8;
+				is_srgb_valid = TRUE;
 				goto out_word4;
 			}
 			goto out_unknown;
@@ -1158,6 +1163,9 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen,
 	}
 
 out_word4:
+
+	if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB && !is_srgb_valid)
+		return ~0;
 	if (word4_p)
 		*word4_p = word4;
 	if (yuv_format_p)
commit 0d6f7b181fb617cec177a407735eab4371be6f9a
Author: Vadim Girlin <vadimgirlin at gmail.com>
Date:   Sat Jan 21 04:48:12 2012 +0400

    r600g: make INTERP_LOAD_P0 vector-only
    
    Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 8b1471f8ca2933a5a4f55be9d0a4db83bdee0435)

diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c
index 88df495..ba473a5 100644
--- a/src/gallium/drivers/r600/r600_asm.c
+++ b/src/gallium/drivers/r600/r600_asm.c
@@ -465,6 +465,7 @@ static int is_alu_vec_unit_inst(struct r600_bytecode *bc, struct r600_bytecode_a
 			is_alu_mova_inst(bc, alu) ||
 			(alu->inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT ||
 			 alu->inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR ||
+			 alu->inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_LOAD_P0 ||
 			 alu->inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY ||
 			 alu->inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW);
 	}
commit 6988699e445407318608021693089b9cc5b0442e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jan 18 15:16:55 2012 +0000

    r600g: fixup AR handling (v5)
    
    So it appears R600s (except rv670) do AR handling different using a different
    opcode. This patch fixes up r600g to work properly on r600.
    
    This fixes ~100 piglit tests here (in GLSL1.30 mode) on rv610.
    
    v3: add index_mode as per the docs.
    
    This still fails any dst relative tests for some reason I can't quite see yet,
    but it passes a lot more tests than without.
    
    v4: add a nop after dst.rel this could be improved using a second pass,
    where we only insert nops if two instructions are sure to collide.
    The docs say r600, rv610, rv630 needs this, and not rv670, rs780, rs880,
    need AMD to confirm rv620, rv635.
    
    v5: add is_nop_inst.
    
    NOTE: This is a candidate for stable branches.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit c96b9834032952492efbd2d1f5511fe225704918)

diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c
index e617b16..88df495 100644
--- a/src/gallium/drivers/r600/r600_asm.c
+++ b/src/gallium/drivers/r600/r600_asm.c
@@ -91,6 +91,7 @@ static inline unsigned int r600_bytecode_get_num_operands(struct r600_bytecode *
 		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV:
 		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA:
 		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR:
+		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT:
 		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT:
 		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT:
 		case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR:
@@ -236,8 +237,18 @@ static struct r600_bytecode_tex *r600_bytecode_tex(void)
 	return tex;
 }
 
-void r600_bytecode_init(struct r600_bytecode *bc, enum chip_class chip_class)
+void r600_bytecode_init(struct r600_bytecode *bc, enum chip_class chip_class, enum radeon_family family)
 {
+	if ((chip_class == R600) && (family != CHIP_RV670))
+		bc->ar_handling = AR_HANDLE_RV6XX;
+	else
+		bc->ar_handling = AR_HANDLE_NORMAL;
+
+	if ((chip_class == R600) && (family != CHIP_RV670 && family != CHIP_RS780 &&
+					   family != CHIP_RS880))
+		bc->r6xx_nop_after_rel_dst = 1;
+	else
+		bc->r6xx_nop_after_rel_dst = 0;
 	LIST_INITHEAD(&bc->cf);
 	bc->chip_class = chip_class;
 }
@@ -428,7 +439,8 @@ static int is_alu_mova_inst(struct r600_bytecode *bc, struct r600_bytecode_alu *
 		return !alu->is_op3 && (
 			alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA ||
 			alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR ||
-			alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT);
+			alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT ||
+			alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT);
 	case EVERGREEN:
 	case CAYMAN:
 	default:
@@ -444,7 +456,8 @@ static int is_alu_vec_unit_inst(struct r600_bytecode *bc, struct r600_bytecode_a
 	case R600:
 	case R700:
 		return is_alu_reduction_inst(bc, alu) ||
-			is_alu_mova_inst(bc, alu);
+			(is_alu_mova_inst(bc, alu) && 
+			 (alu->inst != V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT));
 	case EVERGREEN:
 	case CAYMAN:
 	default:
@@ -465,6 +478,7 @@ static int is_alu_trans_unit_inst(struct r600_bytecode *bc, struct r600_bytecode
 	case R700:
 		if (!alu->is_op3)
 			return alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ASHR_INT ||
+				alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT ||
 				alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_INT_TO_FLT ||
 			        alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT ||
 				alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT ||
@@ -536,6 +550,19 @@ static int is_alu_any_unit_inst(struct r600_bytecode *bc, struct r600_bytecode_a
 		!is_alu_trans_unit_inst(bc, alu);
 }
 
+static int is_nop_inst(struct r600_bytecode *bc, struct r600_bytecode_alu *alu)
+{
+	switch (bc->chip_class) {
+	case R600:
+	case R700:
+		return (!alu->is_op3 && alu->inst == V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP);
+	case EVERGREEN:
+	case CAYMAN:
+	default:
+		return (!alu->is_op3 && alu->inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP);
+	}
+}		
+
 static int assign_alu_units(struct r600_bytecode *bc, struct r600_bytecode_alu *alu_first,
 			    struct r600_bytecode_alu *assignment[5])
 {
@@ -1037,6 +1064,10 @@ static int merge_inst_groups(struct r600_bytecode *bc, struct r600_bytecode_alu
 		alu = slots[i];
 		num_once_inst += is_alu_once_inst(bc, alu);
 
+		/* don't reschedule NOPs */
+		if (is_nop_inst(bc, alu))
+			return 0;
+
 		/* Let's check dst gpr. */
 		if (alu->dst.rel) {
 			if (have_mova)
@@ -1225,12 +1256,60 @@ static int r600_bytecode_alloc_kcache_lines(struct r600_bytecode *bc, struct r60
 	return 0;
 }
 
+static int insert_nop_r6xx(struct r600_bytecode *bc)
+{
+	struct r600_bytecode_alu alu;
+	int r, i;
+
+	for (i = 0; i < 4; i++) {
+		memset(&alu, 0, sizeof(alu));
+		alu.inst = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP;
+		alu.src[0].chan = i;
+		alu.dst.chan = i;
+		alu.last = (i == 3);
+		r = r600_bytecode_add_alu(bc, &alu);
+		if (r)
+			return r;
+	}
+	return 0;
+}
+
+/* load AR register from gpr (bc->ar_reg) with MOVA_INT */
+static int load_ar_r6xx(struct r600_bytecode *bc)
+{
+	struct r600_bytecode_alu alu;
+	int r;
+
+	if (bc->ar_loaded)
+		return 0;
+
+	/* hack to avoid making MOVA the last instruction in the clause */
+	if ((bc->cf_last->ndw>>1) >= 110)
+		bc->force_add_cf = 1;
+
+	memset(&alu, 0, sizeof(alu));
+	alu.inst = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_GPR_INT;
+	alu.src[0].sel = bc->ar_reg;
+	alu.last = 1;
+	alu.index_mode = INDEX_MODE_LOOP;
+	r = r600_bytecode_add_alu(bc, &alu);
+	if (r)
+		return r;
+
+	/* no requirement to set uses waterfall on MOVA_GPR_INT */
+	bc->ar_loaded = 1;
+	return 0;
+}
+
 /* load AR register from gpr (bc->ar_reg) with MOVA_INT */
 static int load_ar(struct r600_bytecode *bc)
 {
 	struct r600_bytecode_alu alu;
 	int r;
 
+	if (bc->ar_handling)
+		return load_ar_r6xx(bc);
+
 	if (bc->ar_loaded)
 		return 0;
 
@@ -1365,6 +1444,10 @@ int r600_bytecode_add_alu_type(struct r600_bytecode *bc, const struct r600_bytec
 		bc->cf_last->prev_bs_head = bc->cf_last->curr_bs_head;
 		bc->cf_last->curr_bs_head = NULL;
 	}
+
+	if (nalu->dst.rel && bc->r6xx_nop_after_rel_dst)
+		insert_nop_r6xx(bc);
+
 	return 0;
 }
 
@@ -1588,6 +1671,7 @@ static int r600_bytecode_alu_build(struct r600_bytecode *bc, struct r600_bytecod
 				S_SQ_ALU_WORD0_SRC1_REL(alu->src[1].rel) |
 				S_SQ_ALU_WORD0_SRC1_CHAN(alu->src[1].chan) |
 				S_SQ_ALU_WORD0_SRC1_NEG(alu->src[1].neg) |
+				S_SQ_ALU_WORD0_INDEX_MODE(alu->index_mode) |
 				S_SQ_ALU_WORD0_LAST(alu->last);
 
 	if (alu->is_op3) {
@@ -2275,7 +2359,8 @@ void r600_bytecode_dump(struct r600_bytecode *bc)
 			fprintf(stderr, "SRC1(SEL:%d ", alu->src[1].sel);
 			fprintf(stderr, "REL:%d ", alu->src[1].rel);
 			fprintf(stderr, "CHAN:%d ", alu->src[1].chan);
-			fprintf(stderr, "NEG:%d) ", alu->src[1].neg);
+			fprintf(stderr, "NEG:%d ", alu->src[1].neg);
+			fprintf(stderr, "IM:%d) ", alu->index_mode);
 			fprintf(stderr, "LAST:%d)\n", alu->last);
 			id++;
 			fprintf(stderr, "%04d %08X %c ", id, bc->bytecode[id], alu->last ? '*' : ' ');
@@ -2554,7 +2639,7 @@ int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, stru
 	}
 
 	memset(&bc, 0, sizeof(bc));
-	r600_bytecode_init(&bc, rctx->chip_class);
+	r600_bytecode_init(&bc, rctx->chip_class, rctx->family);
 
 	for (i = 0; i < ve->count; i++) {
 		if (elements[i].instance_divisor > 1) {
diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h
index d0ff75d..00f7e59 100644
--- a/src/gallium/drivers/r600/r600_asm.h
+++ b/src/gallium/drivers/r600/r600_asm.h
@@ -54,6 +54,7 @@ struct r600_bytecode_alu {
 	unsigned			bank_swizzle;
 	unsigned			bank_swizzle_force;
 	unsigned			omod;
+	unsigned                        index_mode;
 };
 
 struct r600_bytecode_tex {
@@ -176,6 +177,10 @@ struct r600_cf_callstack {
 	int				max;
 };
 
+#define AR_HANDLE_NORMAL 0
+#define AR_HANDLE_RV6XX 1 /* except RV670 */
+
+
 struct r600_bytecode {
 	enum chip_class			chip_class;
 	int				type;
@@ -194,13 +199,15 @@ struct r600_bytecode {
 	struct r600_cf_callstack	callstack[SQ_MAX_CALL_DEPTH];
 	unsigned	ar_loaded;
 	unsigned	ar_reg;
+	unsigned        ar_handling;
+	unsigned        r6xx_nop_after_rel_dst;
 };
 
 /* eg_asm.c */
 int eg_bytecode_cf_build(struct r600_bytecode *bc, struct r600_bytecode_cf *cf);
 
 /* r600_asm.c */
-void r600_bytecode_init(struct r600_bytecode *bc, enum chip_class chip_class);
+void r600_bytecode_init(struct r600_bytecode *bc, enum chip_class chip_class, enum radeon_family family);
 void r600_bytecode_clear(struct r600_bytecode *bc);
 int r600_bytecode_add_alu(struct r600_bytecode *bc, const struct r600_bytecode_alu *alu);
 int r600_bytecode_add_vtx(struct r600_bytecode *bc, const struct r600_bytecode_vtx *vtx);
diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index ad4aded..568ab71 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -705,7 +705,7 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 
 	ctx.bc = &shader->bc;
 	ctx.shader = shader;
-	r600_bytecode_init(ctx.bc, rctx->chip_class);
+	r600_bytecode_init(ctx.bc, rctx->chip_class, rctx->family);
 	ctx.tokens = tokens;
 	tgsi_scan_shader(tokens, &ctx.info);
 	tgsi_parse_init(&ctx.parse, tokens);
diff --git a/src/gallium/drivers/r600/r600_sq.h b/src/gallium/drivers/r600/r600_sq.h
index b9c4126..4b2a19a 100644
--- a/src/gallium/drivers/r600/r600_sq.h
+++ b/src/gallium/drivers/r600/r600_sq.h
@@ -471,4 +471,11 @@
 #define SQ_ALU_SCL_122                           0x00000001
 #define SQ_ALU_SCL_212                           0x00000002
 #define SQ_ALU_SCL_221                           0x00000003
+
+#define   INDEX_MODE_AR_X 0
+#define   INDEX_MODE_AR_Y 1
+#define   INDEX_MODE_AR_Z 2
+#define   INDEX_MODE_AR_W 3
+#define   INDEX_MODE_LOOP 4
+
 #endif
commit 533651b679fdcfbc152e1e935aa5ae375df78c57
Author: Alex Deucher <alexander.deucher at amd.com>
Date:   Tue Jan 17 18:44:47 2012 -0500

    r600g: add workaround for original R600 PS setup
    
    The original R600 requires the UNCACHED_FIRST_INST bit
    to be set in the PS.
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
    
    Note: this is candidate for the stable branches.
    (cherry picked from commit 46ce25722b364ae7fa20b61e60eff4be5ad051d3)

diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index 39ab247..8fc5618 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -2073,7 +2073,7 @@ void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shad
 	struct r600_shader *rshader = &shader->shader;
 	unsigned i, exports_ps, num_cout, spi_ps_in_control_0, spi_input_z, spi_ps_in_control_1, db_shader_control;
 	int pos_index = -1, face_index = -1;
-	unsigned tmp, sid;
+	unsigned tmp, sid, ufi = 0;
 
 	rstate->nregs = 0;
 
@@ -2151,6 +2151,10 @@ void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shad
 			S_0286D0_FRONT_FACE_ADDR(rshader->input[face_index].gpr);
 	}
 
+	/* HW bug in original R600 */
+	if (rctx->family == CHIP_R600)
+		ufi = 1;
+
 	r600_pipe_state_add_reg(rstate, R_0286CC_SPI_PS_IN_CONTROL_0, spi_ps_in_control_0, 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_0286D0_SPI_PS_IN_CONTROL_1, spi_ps_in_control_1, 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_0286D8_SPI_INPUT_Z, spi_input_z, 0xFFFFFFFF, NULL, 0);
@@ -2160,7 +2164,8 @@ void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shad
 	r600_pipe_state_add_reg(rstate,
 				R_028850_SQ_PGM_RESOURCES_PS,
 				S_028850_NUM_GPRS(rshader->bc.ngpr) |
-				S_028850_STACK_SIZE(rshader->bc.nstack),
+				S_028850_STACK_SIZE(rshader->bc.nstack) |
+				S_028850_UNCACHED_FIRST_INST(ufi),
 				0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate,
 				R_028854_SQ_PGM_EXPORTS_PS,
commit ee6a817f8059cf8a31a0f91169fc144984804d40
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Jan 14 17:32:14 2012 +0000

    r600g: add missing r32 uint/sint fbo formats.
    
    Fixes the GL3 required formats test.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 5250bd00c00ac8470320f4fae1d74425132f2083)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index f3aab69..185ea77 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -508,6 +508,10 @@ static uint32_t r600_translate_colorformat(enum pipe_format format)
 	case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
 		return V_028C70_COLOR_X24_8_32_FLOAT;
 
+	case PIPE_FORMAT_R32_UINT:
+	case PIPE_FORMAT_R32_SINT:
+		return V_028C70_COLOR_32;
+
 	case PIPE_FORMAT_R32_FLOAT:
 	case PIPE_FORMAT_Z32_FLOAT:
 		return V_028C70_COLOR_32_FLOAT;
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index 5fe038e..39ab247 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -509,6 +509,10 @@ static uint32_t r600_translate_colorformat(enum pipe_format format)
 	case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
 		return V_0280A0_COLOR_X24_8_32_FLOAT;
 
+	case PIPE_FORMAT_R32_UINT:
+	case PIPE_FORMAT_R32_SINT:
+		return V_0280A0_COLOR_32;
+
 	case PIPE_FORMAT_R32_FLOAT:
 	case PIPE_FORMAT_Z32_FLOAT:
 		return V_0280A0_COLOR_32_FLOAT;
commit 1b33ae3a7da160033a2dc7abe6ef46dee3730c2e
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Jan 17 04:49:04 2012 -0800

    i965: Remove the INTEL_OLD_VS option.
    
    Now that we no longer generate Mesa IR from GLSL IR, it's impossible to
    use the old vertex shader backend for GLSL programs.  There's simply no
    Mesa IR to codegen from.
    
    Any attempt to do so would result in immediate GPU hangs, presumably due
    to the driver uploading an empty program with no EOT message.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Eugeni Dodonov <eugeni.dodonov at intel.com>
    (cherry picked from commit bdedd03b701781c8b71e162f7eb834e6a11105de)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 558e077..eb152f9 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -367,16 +367,10 @@ brwCreateContext(int api,
 
    brw_draw_init( brw );
 
-   brw->new_vs_backend = (getenv("INTEL_OLD_VS") == NULL);
    brw->precompile = driQueryOptionb(&intel->optionCache, "shader_precompile");
 
-   /* If we're using the new shader backend, we require integer uniforms
-    * stored as actual integers.
-    */
-   if (brw->new_vs_backend) {
-      ctx->Const.NativeIntegers = true;
-      ctx->Const.UniformBooleanTrue = 1;
-   }
+   ctx->Const.NativeIntegers = true;
+   ctx->Const.UniformBooleanTrue = 1;
 
    return true;
 }
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 9f9b113..c027bef 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -645,7 +645,6 @@ struct brw_context
    bool has_negative_rhw_bug;
    bool has_aa_line_parameters;
    bool has_pln;
-   bool new_vs_backend;
    bool precompile;
 
    struct {
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 7fc7dcc..a2bce27 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -231,7 +231,7 @@ do_vs_prog(struct brw_context *brw,
 
    /* Emit GEN4 code.
     */
-   if (brw->new_vs_backend && prog) {
+   if (prog) {
       if (!brw_vs_emit(prog, &c)) {
 	 ralloc_free(mem_ctx);
 	 return false;
commit 41c1a7311ecae6d8f4cfe8cd76e1d64d8466ca43
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Jan 16 10:34:56 2012 -0800

    mesa: Support GL_VERTEX_ATTRIB_ARRAY_INTEGER in GL 3.0 contexts.
    
    According to Table 6.8 (Page 348) in the OpenGL 3.0 specification,
    glGetVertexAttribiv supports GL_VERTEX_ATTRIB_ARRAY_INTEGER.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit d56ad273c0ff37d790c614b2d3f04c1249b47307)

diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index 540e896..9078d11 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -555,7 +555,7 @@ get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
    case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
       return array->BufferObj->Name;
    case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
-      if (ctx->Extensions.EXT_gpu_shader4) {
+      if (ctx->VersionMajor >= 3 || ctx->Extensions.EXT_gpu_shader4) {
          return array->Integer;
       }
       goto error;
commit d090099f7dd6769aa322aadf16f31f60f1639394
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Tue Jan 17 15:41:46 2012 -0800

    i965/gen5: Fix rendering of depth buffers without stencil [v2]
    
    Fixes the following OGLConform tests on gen5:
        depth-stencil(misc.state_on.depth_int)
        fbo_db_ARBfp(basic.OnlyDepthBuffDrawBufferRender)
    
    The problem was that, if the depth buffer's Mesa format was X8_Z24, then
    we emitted the hardware format D24_UNORM_X8. But, on gen5, D24_UNORM_S8
    must be emitted.
    
    This bug was introduced by:
        commit d84a180417d1eabd680554970f1eaaa93abcd41e
        Author: Eric Anholt <eric at anholt.net>
        i965: Base HW depth format setup based on MESA_FORMAT, not bpp.
    
    v2: Deref 'intel' directly. Move the branch for newer chipset to top.
        Quote the PRM. As requested by Ken.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43408
    Note: This is a candidate for the 8.0 branch.
    Reported-by: Xunx Fang <xunx.fang at intel.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit a6dd4bf5fcce2520ab199201fdd1ad155457d781)

diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index b6bca4b..8e59a47 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -223,10 +223,23 @@ brw_depthbuffer_format(struct brw_context *brw)
    case MESA_FORMAT_Z32_FLOAT:
       return BRW_DEPTHFORMAT_D32_FLOAT;
    case MESA_FORMAT_X8_Z24:
-      if (intel->gen >= 5)
+      if (intel->gen >= 6) {
 	 return BRW_DEPTHFORMAT_D24_UNORM_X8_UINT;
-      else /* Gen4 doesn't support X8; use S8 instead. */
+      } else {
+	 /* Use D24_UNORM_S8, not D24_UNORM_X8.
+	  *
+	  * D24_UNORM_X8 was not introduced until Gen5. (See the Ironlake PRM,
+	  * Volume 2, Part 1, Section 8.4.6 "Depth/Stencil Buffer State", Bits
+	  * 3DSTATE_DEPTH_BUFFER.Surface_Format).
+	  *
+	  * However, on Gen5, D24_UNORM_X8 may be used only if separate
+	  * stencil is enabled, and we never enable it. From the Ironlake PRM,
+	  * same section as above, Bit 3DSTATE_DEPTH_BUFFER.Separate_Stencil_Buffer_Enable:
+	  *     If this field is disabled, the Surface Format of the depth
+	  *     buffer cannot be D24_UNORM_X8_UINT.
+	  */
 	 return BRW_DEPTHFORMAT_D24_UNORM_S8_UINT;
+      }
    case MESA_FORMAT_S8_Z24:
       return BRW_DEPTHFORMAT_D24_UNORM_S8_UINT;
    case MESA_FORMAT_Z32_FLOAT_X24S8:
commit 8ac4470041ff63e01b4d4200ca298bd7244232f8
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Mon Jan 16 16:15:30 2012 -0800

    mesa: Add condition in glGetTexImage for zero size textures
    
    TestMipMaps() function in src/OGLconform/textureNPOT.c calls glTexImage2D()
    with width = 0. Texture with zero size skips miptree allocation due to a
    condition in function _mesa_store_teximage3d(). While calling glGetTexImage()
    it results in assertion failure in intel_map_texture_image() due to null mt
    pointer.
    
    This patch fixes the issue by detecting the zero size texture early in
    glGetTexImage and glGetCompressedTexImage functions. In such a case function
    simply returns doing nothing.
    Verified that below mentioned bug is fixed by this patch.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=42334
    
    NOTE: This is a candidate for stable branches
    
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Brian Paul <brianp at vmware.com>
    (cherry picked from commit f1a9a9bcd19dcbb8a0a4bd7299400cb418970f99)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index f848aa8..8c85c1e 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -837,6 +837,9 @@ _mesa_GetnTexImageARB( GLenum target, GLint level, GLenum format,
    texObj = _mesa_get_current_tex_object(ctx, target);
    texImage = _mesa_select_tex_image(ctx, texObj, target, level);
 
+   if (_mesa_is_zero_size_texture(texImage))
+      return;
+
    if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
       _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
                   " dstFmt=0x%x, dstType=0x%x\n",
@@ -970,6 +973,9 @@ _mesa_GetnCompressedTexImageARB(GLenum target, GLint level, GLsizei bufSize,
    texObj = _mesa_get_current_tex_object(ctx, target);
    texImage = _mesa_select_tex_image(ctx, texObj, target, level);
 
+   if (_mesa_is_zero_size_texture(texImage))
+      return;
+
    if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
       _mesa_debug(ctx,
                   "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index 12af0e6..e2bdaca 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -44,7 +44,14 @@ _mesa_is_cube_face(GLenum target)
            target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
 }
 
-
+/** Is any of the dimensions of given texture equal to zero? */
+static inline GLboolean
+_mesa_is_zero_size_texture(const struct gl_texture_image *texImage)
+{
+   return (texImage->Width == 0 ||
+           texImage->Height == 0 ||
+           texImage->Depth == 0);
+}
 
 /** \name Internal functions */
 /*@{*/
commit 6382f98b9a37616a0802cb8ef450ce16e5ef1921
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 12 14:53:10 2012 -0800

    intel: Drop the version override code now that we don't have any left.
    
    Fixes a compiler warning.
    
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit a14582d7e2ace05a3583cecff39f2bb4f41f7b79)

diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index 7aa040c..0ce452f 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -41,14 +41,6 @@ void
 intelInitExtensions(struct gl_context *ctx)
 {
    struct intel_context *intel = intel_context(ctx);
-   char *override = getenv("MESA_GL_VERSION_OVERRIDE");
-   int override_major, override_minor;
-   int override_version = 0;
-
-   if (override &&
-       sscanf(override, "%u.%u", &override_major, &override_minor) == 2) {
-      override_version = override_major * 10 + override_minor;
-   }
 
    ctx->Extensions.ARB_draw_elements_base_vertex = true;
    ctx->Extensions.ARB_explicit_attrib_location = true;
commit 274e8b92342baa313ab9ef8c57b6530aa6a1bc7b
Author: Chad Versace <chad.versace at linux.intel.com>
Date:   Tue Dec 27 10:52:44 2011 -0800

    i965: Fix gen6,gen7 when used with a non-HiZ capable DDX
    
    Nothing works if HiZ is enabled and the DDX is incapable of HiZ (that is,
    the DDX version is < 2.16).
    
    The problem is that the refactoring that eliminated
    intel_renderbuffer::stencil_rb broke the recovery path in
    intel_verify_dri2_has_hiz().  Specifically, it broke line
    intel_context.c:1445, which allocates the region for
    DRI_BUFFER_DEPTH_STENCIL. That allocation was creating a separate stencil
    miptree, despite the buffer being a packed depthstencil buffer. Havoc
    ensued.
    
    This patch introduces a bool flag that prevents allocation of that stencil
    miptree.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44103
    Tested-by: Ian Romanick <idr at freedesktop.org>
    Note: This is a candidate for the 8.0 branch.
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 7e08bf08d13228001f6306800b5bd69b89b1bb6f)

diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index 4e1a502..eae79c1 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -58,6 +58,11 @@ target_to_target(GLenum target)
    }
 }
 
+/**
+ * @param for_region Indicates that the caller is
+ *        intel_miptree_create_for_region(). If true, then do not create
+ *        \c stencil_mt.
+ */
 static struct intel_mipmap_tree *
 intel_miptree_create_internal(struct intel_context *intel,
 			      GLenum target,
@@ -66,7 +71,8 @@ intel_miptree_create_internal(struct intel_context *intel,
 			      GLuint last_level,
 			      GLuint width0,
 			      GLuint height0,
-			      GLuint depth0)
+			      GLuint depth0,
+			      bool for_region)
 {
    struct intel_mipmap_tree *mt = calloc(sizeof(*mt), 1);
    int compress_byte = 0;
@@ -106,7 +112,8 @@ intel_miptree_create_internal(struct intel_context *intel,
       mt->cpp = 2;
    }
 
-   if (_mesa_is_depthstencil_format(_mesa_get_format_base_format(format)) &&
+   if (!for_region &&
+       _mesa_is_depthstencil_format(_mesa_get_format_base_format(format)) &&
        (intel->must_use_separate_stencil ||
 	(intel->has_separate_stencil &&
 	 intel->vtbl.is_hiz_depth_format(intel, format)))) {
@@ -199,7 +206,8 @@ intel_miptree_create(struct intel_context *intel,
 
    mt = intel_miptree_create_internal(intel, target, format,
 				      first_level, last_level, width0,
-				      height0, depth0);
+				      height0, depth0,
+				      false);
    /*
     * pitch == 0 || height == 0  indicates the null texture
     */
@@ -234,7 +242,8 @@ intel_miptree_create_for_region(struct intel_context *intel,
 
    mt = intel_miptree_create_internal(intel, target, format,
 				      0, 0,
-				      region->width, region->height, 1);
+				      region->width, region->height, 1,
+				      true);
    if (!mt)
       return mt;
 
commit a12606cb544dfbd42a354779078a611f7808433c
Author: Anuj Phogat <anuj.phogat at gmail.com>
Date:   Wed Jan 11 15:26:10 2012 -0800

    intel: Fix segfault in glXSwapBuffers with no bound context
    
    Calling glXSwapBuffers with no bound context causes segmentation
    fault in function intelDRI2Flush. All the gl calls should be
    ignored after setting the current context to null. So the contents
    of framebuffer stay unchanged. But the driver should not seg fault.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44614
    
    Reported-by: Yi Sun <yi.sun at intel.com>
    Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    Tested-by: Yi Sun <yi.sun at intel.com>
    (cherry picked from commit dd7220652e65a8a23e7739eeee687f3d6a865b80)

diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index b0e800b..a08f3d1 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -115,13 +115,15 @@ intelDRI2Flush(__DRIdrawable *drawable)
    GET_CURRENT_CONTEXT(ctx);
    struct intel_context *intel = intel_context(ctx);
 
-   if (intel->gen < 4)
-      INTEL_FIREVERTICES(intel);
+   if (intel != NULL) {
+      if (intel->gen < 4)
+	 INTEL_FIREVERTICES(intel);
 
-   intel->need_throttle = true;
+      intel->need_throttle = true;
 
-   if (intel->batch.used)
-      intel_batchbuffer_flush(intel);
+      if (intel->batch.used)
+	 intel_batchbuffer_flush(intel);
+   }
 }
 
 static const struct __DRI2flushExtensionRec intelFlushExtension = {
commit 33f5c3946d5e66bb932e2a51eb27b427a3bd1644
Author: Marek Olšák <maraeo at gmail.com>
Date:   Thu Jan 12 03:54:09 2012 +0100

    mesa: update compute_version for GL3
    
    only check ARB_fbo, add shader_texture_lod as a requirement
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    (cherry picked from commit 5596db74117e56a58e16a61c34bc87d787bb24bb)

diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index 49cdc30..38ae1ce 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -130,16 +130,14 @@ compute_version(struct gl_context *ctx)
                               ctx->Extensions.ARB_half_float_pixel &&
                               ctx->Extensions.ARB_half_float_vertex &&
                               ctx->Extensions.ARB_map_buffer_range &&
+                              ctx->Extensions.ARB_shader_texture_lod &&
                               ctx->Extensions.ARB_texture_float &&
                               ctx->Extensions.ARB_texture_rg &&
                               ctx->Extensions.ARB_texture_compression_rgtc &&
                               ctx->Extensions.APPLE_vertex_array_object &&
                               ctx->Extensions.EXT_draw_buffers2 &&
-                              ctx->Extensions.EXT_framebuffer_blit &&
-                              ctx->Extensions.EXT_framebuffer_multisample &&
-                              ctx->Extensions.EXT_framebuffer_object &&
+                              ctx->Extensions.ARB_framebuffer_object &&
                               ctx->Extensions.EXT_framebuffer_sRGB &&
-                              ctx->Extensions.EXT_packed_depth_stencil &&
                               ctx->Extensions.EXT_packed_float &&
                               ctx->Extensions.EXT_texture_array &&
                               ctx->Extensions.EXT_texture_integer &&
commit a07afa11d2b78a3ec98a97e811cbb98ecf62584f
Author: Vinson Lee <vlee at vmware.com>
Date:   Thu Nov 3 00:36:27 2011 -0700

    i965: Fix Coverity wrong sizeof argument defect.
    
    NOTE: This is a candidate for stable release branches.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42542
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit 3e18ad7fd7026e31fd92fe5cf7097d08e5b9a15a)

diff --git a/src/mesa/drivers/dri/i965/gen7_viewport_state.c b/src/mesa/drivers/dri/i965/gen7_viewport_state.c
index 252a35b..d0b89d5 100644
--- a/src/mesa/drivers/dri/i965/gen7_viewport_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_viewport_state.c
@@ -38,7 +38,7 @@ gen7_upload_sf_clip_viewport(struct brw_context *brw)
    struct gen7_sf_clip_viewport *vp;
 
    vp = brw_state_batch(brw, AUB_TRACE_SF_VP_STATE,
-			sizeof(vp), 64, &brw->sf.vp_offset);
+			sizeof(*vp), 64, &brw->sf.vp_offset);
    /* Also assign to clip.vp_offset in case something uses it. */
    brw->clip.vp_offset = brw->sf.vp_offset;
 
commit 9e0cec45aef55ddd07189e834d7f0bf50b24dccd
Author: Paul Berry <stereotype441 at gmail.com>
Date:   Mon Jan 9 14:45:04 2012 -0800

    i965 gen4-6: Fix off-by-one errors brw_create_constant_surface()
    
    Commit 9bdc44a52804a64219a0ca1a061b18596863e524 (i965: Replace struct
    with bit shifting for WM pull constant surfaces) accidentally
    introduced off-by-one errors into the calculation of the surface
    width, height, and depth.  This patch restores the correct
    computation.
    
    The reason this wasn't noticed by Piglit tests is that the size of our
    constant surfaces is always less than 2^20, therefore the off-by-one
    error was causing the "depth" field of the surface to be set to all
    1's.  The hardware interpreted this as an extremely large surface, so
    overflow checking was effectively disabled.
    
    No Piglit regressions on Sandy Bridge.
    
    NOTE: This is a candidate for the 7.11 and 8.0 branches.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
    (cherry picked from commit f6f43bd5a276990c58c021bc047e60f9763df479)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index dedf594..b40f5e1 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -698,10 +698,10 @@ brw_create_constant_surface(struct brw_context *brw,
 
    surf[1] = bo->offset; /* reloc */
 
-   surf[2] = (((w & 0x7f) - 1) << BRW_SURFACE_WIDTH_SHIFT |
-	      (((w >> 7) & 0x1fff) - 1) << BRW_SURFACE_HEIGHT_SHIFT);
+   surf[2] = ((w & 0x7f) << BRW_SURFACE_WIDTH_SHIFT |
+	      ((w >> 7) & 0x1fff) << BRW_SURFACE_HEIGHT_SHIFT);
 
-   surf[3] = ((((w >> 20) & 0x7f) - 1) << BRW_SURFACE_DEPTH_SHIFT |
+   surf[3] = (((w >> 20) & 0x7f) << BRW_SURFACE_DEPTH_SHIFT |
 	      (width * 16 - 1) << BRW_SURFACE_PITCH_SHIFT);
 
    surf[4] = 0;
commit c85402aba91755808729fadf57a9f92285f4e61a
Author: Jakob Bornecrantz <jakob at vmware.com>
Date:   Wed Jan 11 23:33:07 2012 +0100

    mesa: Bump version number to 8.0-rc1
    
    Signed-off-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/Makefile b/Makefile
index 1fa369a..64e3a7cd 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ ultrix-gcc:
 
 # Rules for making release tarballs
 
-PACKAGE_VERSION=8.0-devel
+PACKAGE_VERSION=8.0-rc1
 PACKAGE_DIR = Mesa-$(PACKAGE_VERSION)
 PACKAGE_NAME = MesaLib-$(PACKAGE_VERSION)
 
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 8723c1f..c1f4e8e 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -35,7 +35,7 @@ struct gl_context;
 #define MESA_MAJOR 8
 #define MESA_MINOR 0
 #define MESA_PATCH 0
-#define MESA_VERSION_STRING "8.0-devel"
+#define MESA_VERSION_STRING "8.0-rc1"
 
 /* To make version comparison easy */
 #define MESA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
commit 9c81e4eed1bc691f6308a230fddc80d2d2936a50
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Jan 13 13:45:58 2012 -0700

    docs: add links to xf86-video-vmware wiki pages
    
    (cherry picked from commit 548526f2e967d29e0aa1d9a37e4364100e84dc3f)

diff --git a/docs/vmware-guest.html b/docs/vmware-guest.html
index 9295644..727f99b 100644
--- a/docs/vmware-guest.html
+++ b/docs/vmware-guest.html
@@ -23,6 +23,15 @@ End users shouldn't have to go through all these steps once the driver is
 included in newer Linux distributions.
 </p>
 
+<p>
+For more information about the X components see these wiki pages at x.org:
+</p>
+<ul>
+<li><a href="http://wiki.x.org/wiki/vmware" target="_parent">
+Driver Overview</a>
+<li><a href="http://wiki.x.org/wiki/vmware/vmware3D" target="_parent">
+xf86-video-vmware Details</a>
+</ul>
 
 
 <h2>Components</h2>
commit daa2545508202302208317ace78d328d60f4d35f
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 11 14:06:17 2012 -0800

    mesa: Throw the required error for glCopyPixels from multisample FBO.
    
    Fixes piglit EXT_framebuffer_multisample/negative-copypixels.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 9be6654c1f75bc402c807ec0caccebde032afa59)

diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c
index 9f5b0b3..01983d9 100644
--- a/src/mesa/main/drawpix.c
+++ b/src/mesa/main/drawpix.c
@@ -203,6 +203,12 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
       goto end;
    }
 
+   if (ctx->ReadBuffer->Name != 0 && ctx->ReadBuffer->Visual.samples > 0) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION,
+		  "glCopyPixels(multisample FBO)");
+      goto end;
+   }
+
    if (!_mesa_source_buffer_exists(ctx, type) ||
        !_mesa_dest_buffer_exists(ctx, type)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
commit baaa30ad52ac6eba0ee444c33678ffd357883a4d
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 11 14:02:41 2012 -0800

    mesa: Throw the required error for glCopyTex{Sub,}Image from multisample FBO.
    
    Fixes piglit EXT_framebuffer_multisample/negative-copyteximage.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 6950a4faf650fe119ee97aa18b006eed099038be)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 9475e84..d5e462b 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1909,6 +1909,13 @@ copytexture_error_check( struct gl_context *ctx, GLuint dimensions,
                      "glCopyTexImage%dD(invalid readbuffer)", dimensions);
          return GL_TRUE;
       }
+
+      if (ctx->ReadBuffer->Visual.samples > 0) {
+	 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION,
+		     "glCopyTexImage%dD(multisample FBO)",
+		     dimensions);
+	 return GL_TRUE;
+      }
    }
 
    /* Check border */
@@ -2008,6 +2015,13 @@ copytexsubimage_error_check1( struct gl_context *ctx, GLuint dimensions,
                      "glCopyTexImage%dD(invalid readbuffer)", dimensions);
          return GL_TRUE;
       }
+
+      if (ctx->ReadBuffer->Visual.samples > 0) {
+	 _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION,
+		     "glCopyTexSubImage%dD(multisample FBO)",
+		     dimensions);
+	 return GL_TRUE;
+      }
    }
 
    /* check target (proxies not allowed) */
commit b178514e24ee7f2f89448b384683fe42fd448c18
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 11 13:54:53 2012 -0800

    mesa: Throw the required error for glReadPixels() from a multisampled FBO.
    
    Fixes piglit EXT_framebuffer_multisample-negative-readpixels.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 86b7c6707f915b07347070901d602917bc25dd0f)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 0c0e539..c1489d2 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -782,6 +782,11 @@ _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
+   if (ctx->ReadBuffer->Name != 0 && ctx->ReadBuffer->Visual.samples > 0) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(multisample FBO)");
+      return;
+   }
+
    if (!_mesa_source_buffer_exists(ctx, format)) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
       return;
commit 48e72b660549577c25a444826073f77232072dd9
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 11 13:46:43 2012 -0800

    mesa: Avoid short-circuiting realloc of renderbuffers to new sample count.
    
    Fixes piglit EXT_framebuffer_multisample/renderbuffer-samples.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 0e8d156c3cd70a67c99a82e42e7875f69b6a5b94)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index aefcaf3..e6bab4b 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -1395,7 +1395,8 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
 
    if (rb->InternalFormat == internalFormat &&
        rb->Width == (GLuint) width &&
-       rb->Height == (GLuint) height) {
+       rb->Height == (GLuint) height &&
+       rb->NumSamples == samples) {
       /* no change in allocation needed */
       return;
    }
commit 89fdeab1a201ae41b13693261fdc1aca6dbf79f7
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jan 9 16:41:02 2012 -0800

    meta: Add GL_RED/GL_RG support to meta CopyTexImage.
    
    Fixes some _mesa_problem()s in oglconform.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit f83756f80f509fc51030853f8aa0fef3309fe886)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index abf2f1f..dca3613 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -3071,6 +3071,8 @@ get_temp_image_type(struct gl_context *ctx, GLenum baseFormat)
    switch (baseFormat) {
    case GL_RGBA:
    case GL_RGB:
+   case GL_RG:
+   case GL_RED:
    case GL_ALPHA:
    case GL_LUMINANCE:
    case GL_LUMINANCE_ALPHA:
@@ -3086,7 +3088,8 @@ get_temp_image_type(struct gl_context *ctx, GLenum baseFormat)
    case GL_DEPTH_STENCIL:
       return GL_UNSIGNED_INT_24_8;
    default:
-      _mesa_problem(ctx, "Unexpected format in get_temp_image_type()");
+      _mesa_problem(ctx, "Unexpected format %d in get_temp_image_type()",
+		    baseFormat);
       return 0;
    }
 }
commit 504eaa12120c319aa990c12773f9cfe28ace0d07
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jan 11 15:31:30 2012 -0800

    i965/gen7: Fix depth buffer rendering to tile offsets.
    
    Previously, we were saying that everything from the starting tile to
    region width+height was part of the limits of our depthbuffer, even if
    the tile was near the bottom of the depthbuffer.  This mean that our
    range was not clipping to buffer buonds if the start tile was anything
    but the start of the buffer.
    
    In bebc91f0f3a1f2d19d36a7f1a4f7c992ace064e9, this was changed to
    saying that we're just rendering to a region of the size of the
    renderbuffer.  This is great -- we get a range that should actually
    match what we want.  However, the hardware's range checking occurs
    after the X/Y offset addition, so we were clipping out rendering to
    small depth mip levels when an X/Y offset was present.  Just add
    tile_x/y to the width in that case -- the WM won't produce negative
    x/y values pre-offset, so we just need to get the left/bottom sides of
    the region to cover our buffer.
    
    Fixes the following Piglit regressions on gen7:
        spec/ARB_depth_buffer_float/fbo-clear-formats
        spec/ARB_depth_texture/fbo-clear-formats
        spec/EXT_packed_depth_stencil/fbo-clear-formats
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit e6d6a10c5a2962f93d4adcd251b9a47a4e438121)

diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c
index f9652df..b6bca4b 100644
--- a/src/mesa/drivers/dri/i965/brw_misc_state.c
+++ b/src/mesa/drivers/dri/i965/brw_misc_state.c
@@ -376,8 +376,8 @@ static void emit_depthbuffer(struct brw_context *brw)
 		I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
 		offset);
       OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) |
-		((depth_irb->Base.Width - 1) << 6) |
-		((depth_irb->Base.Height - 1) << 19));
+		(((depth_irb->Base.Width + tile_x)- 1) << 6) |
+		(((depth_irb->Base.Height + tile_y) - 1) << 19));
       OUT_BATCH(0);
 
       if (intel->is_g4x || intel->gen >= 5)
diff --git a/src/mesa/drivers/dri/i965/gen7_misc_state.c b/src/mesa/drivers/dri/i965/gen7_misc_state.c
index 8a383f5..c2f58d5 100644
--- a/src/mesa/drivers/dri/i965/gen7_misc_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_misc_state.c
@@ -107,8 +107,8 @@ static void emit_depthbuffer(struct brw_context *brw)
       OUT_RELOC(region->bo,
 	        I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
 		offset);
-      OUT_BATCH(((drb->Base.Width - 1) << 4) |
-                ((drb->Base.Height - 1) << 18));
+      OUT_BATCH((((drb->Base.Width + tile_x) - 1) << 4) |
+                (((drb->Base.Height + tile_y) - 1) << 18));
       OUT_BATCH(0);
       OUT_BATCH(tile_x | (tile_y << 16));
       OUT_BATCH(0);
commit 399b9799de9980b8ebc0ba46304be207b28b7825
Author: Neil Roberts <neil at linux.intel.com>
Date:   Wed Nov 30 22:29:21 2011 +0000

    gen6_hiz: Don't bind GL_DRAW_FRAMEBUFFER on GLES
    
    When using Mesa with a GLES API, calling _mesa_FramebufferRenderbuffer
    with GL_DRAW_FRAMEBUFFER will report a 'user error' because
    get_framebuffer_target validates that this enum from the framebuffer
    blit extension is only used on GL. To work around it this patch makes
    it use the GL_FRAMEBUFFER enum instead in that case.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43418
    Note: This is a candidate for the 8.0 branch.
    Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
    (cherry picked from commit 9462b8447864c754252cd2580c9e1e4d36d5cc63)

diff --git a/src/mesa/drivers/dri/i965/gen6_hiz.c b/src/mesa/drivers/dri/i965/gen6_hiz.c
index e282511..92b1d61 100644
--- a/src/mesa/drivers/dri/i965/gen6_hiz.c
+++ b/src/mesa/drivers/dri/i965/gen6_hiz.c
@@ -109,6 +109,24 @@ static const uint32_t gen6_hiz_meta_save =
 
       MESA_META_SELECT_FEEDBACK;
 
+static void
+gen6_hiz_get_framebuffer_enum(struct gl_context *ctx,
+                              GLenum *bind_enum,
+                              GLenum *get_enum)
+{
+   /* If the blit framebuffer extension isn't supported then Mesa will
+      report an error if we try to bind GL_DRAW_FRAMEBUFFER. However in
+      that case it should be safe to just save and restore
+      GL_FRAMEBUFFER instead. */
+   if (ctx->Extensions.EXT_framebuffer_blit && ctx->API == API_OPENGL) {
+      *bind_enum = GL_DRAW_FRAMEBUFFER;
+      *get_enum = GL_DRAW_FRAMEBUFFER_BINDING;
+   } else {
+      *bind_enum = GL_FRAMEBUFFER;
+      *get_enum = GL_FRAMEBUFFER_BINDING;
+   }
+}
+
 /**
  * Initialize static data needed for HiZ operations.
  */
@@ -117,10 +135,13 @@ gen6_hiz_init(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->intel.ctx;
    struct brw_hiz_state *hiz = &brw->hiz;
+   GLenum fb_bind_enum, fb_get_enum;
 
    if (hiz->fbo != 0)
       return;
 
+   gen6_hiz_get_framebuffer_enum(ctx, &fb_bind_enum, &fb_get_enum);
+
    /* Create depthbuffer.
     *
     * Until glRenderbufferStorage is called, the renderbuffer hash table
@@ -139,8 +160,8 @@ gen6_hiz_init(struct brw_context *brw)
 
    /* Setup FBO. */
    _mesa_GenFramebuffersEXT(1, &hiz->fbo);
-   _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, hiz->fbo);
-   _mesa_FramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER,
+   _mesa_BindFramebufferEXT(fb_bind_enum, hiz->fbo);
+   _mesa_FramebufferRenderbufferEXT(fb_bind_enum,
                                     GL_DEPTH_ATTACHMENT,
                                     GL_RENDERBUFFER,
                                     hiz->depth_rb->Name);
@@ -241,6 +262,7 @@ gen6_resolve_slice(struct intel_context *intel,
    struct gl_context *ctx = &intel->ctx;
    struct brw_context *brw = brw_context(ctx);
    struct brw_hiz_state *hiz = &brw->hiz;
+   GLenum fb_bind_enum, fb_get_enum;
 
    /* Do not recurse. */
    assert(!brw->hiz.op);
@@ -250,11 +272,13 @@ gen6_resolve_slice(struct intel_context *intel,
    assert(level <= mt->last_level);
    assert(layer < mt->level[level].depth);
 
+   gen6_hiz_get_framebuffer_enum(ctx, &fb_bind_enum, &fb_get_enum);
+
    /* Save state. */
    GLint save_drawbuffer;
    GLint save_renderbuffer;
    _mesa_meta_begin(ctx, gen6_hiz_meta_save);
-   _mesa_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &save_drawbuffer);
+   _mesa_GetIntegerv(fb_get_enum, &save_drawbuffer);
    _mesa_GetIntegerv(GL_RENDERBUFFER_BINDING, &save_renderbuffer);
 
    /* Initialize context data for HiZ operations. */
@@ -272,7 +296,7 @@ gen6_resolve_slice(struct intel_context *intel,
 
    /* Setup FBO. */
    gen6_hiz_setup_depth_buffer(brw, mt, level, layer);
-   _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, hiz->fbo);
+   _mesa_BindFramebufferEXT(fb_bind_enum, hiz->fbo);
 
 
    /* A rectangle primitive (3DPRIM_RECTLIST) consists of only three vertices.
@@ -316,7 +340,7 @@ gen6_resolve_slice(struct intel_context *intel,
     */
    gen6_hiz_teardown_depth_buffer(hiz->depth_rb);
    _mesa_BindRenderbufferEXT(GL_RENDERBUFFER, save_renderbuffer);
-   _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER, save_drawbuffer);
+   _mesa_BindFramebufferEXT(fb_bind_enum, save_drawbuffer);
    _mesa_meta_end(ctx);
 }
 
commit 2c1ee157c7e8526cd9e097ee25d63961d6aaf619
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Jan 13 10:54:22 2012 -0700

    docs: new page describing how to build, install VMware SVGA3D guest driver
    
    (cherry picked from commit 27915708ed4519cc5606e81fb789e8427501f355)

diff --git a/docs/contents.html b/docs/contents.html
index e3cea2a..33c2191 100644
--- a/docs/contents.html
+++ b/docs/contents.html
@@ -63,6 +63,7 @@ a:visited {
 <LI><A HREF="extensions.html" target="MainFrame">Mesa Extensions</A>
 <LI><A HREF="mangling.html" target="MainFrame">Function Name Mangling</A>
 <LI><A href="llvmpipe.html" target="MainFrame">Gallium llvmpipe driver</A>
+<LI><A href="vmware-guest.html" target="MainFrame">VMware SVGA3D guest driver</a>
 <LI><A href="postprocess.html" target="MainFrame">Gallium post-processing</A>
 <LI><A href="viewperf.html" target="MainFrame">Viewperf Issues</A>
 </ul>
diff --git a/docs/vmware-guest.html b/docs/vmware-guest.html
new file mode 100644
index 0000000..9295644
--- /dev/null
+++ b/docs/vmware-guest.html
@@ -0,0 +1,185 @@
+<html>
+
+<title>VMware guest GL driver</title>
+
+<link rel="stylesheet" type="text/css" href="mesa.css"></head>
+
+<body>
+
+
+<h1>VMware guest GL driver</h1>
+
+<p>
+This page describes how to build, install and use the VMware guest GL driver
+(aka the SVGA or SVGA3D driver) for Linux using the latest source code.
+This driver gives a Linux virtual machine access to the host's GPU for
+hardware-accelerated 3D.
+VMware Workstation running on Linux or Windows and VMware Fusion running on
+MacOS are all supported.
+</p>
+
+<p>
+End users shouldn't have to go through all these steps once the driver is
+included in newer Linux distributions.
+</p>
+
+
+
+<h2>Components</h2>
+
+The components involved in this include:
+<ul>
+<li>Linux kernel module: vmwgfx
+<li>X server 2D driver: xf86-video-vmware
+<li>User-space libdrm library
+<li>Mesa/gallium OpenGL driver: "svga"
+</ul>
+
+
+<h2>Prerequisites</h2>
+
+<ul>
+<li>Kernel version at least 2.6.25 
+<li>Xserver version at least 1.7 
+<li>Ubuntu: For ubuntu you need to install a number of build dependencies. 
+  <pre>
+  sudo apt-get install git-core
+  sudo apt-get install automake libtool libpthread-stubs0-dev
+  sudo apt-get install xserver-xorg-dev x11proto-xinerama-dev
+  sudo apt-get build-dep libgl1-mesa-dri libxcb-glx0-dev
+  </pre>
+<li>Fedora: For Fedora you also need to install a number of build dependencies. 
+  <pre>
+  sudo yum install mesa-libGL-devel xorg-x11-server-devel xorg-x11-util-macros
+  sudo yum install automake gcc libtool expat-devel kernel-devel git-core
+  </pre>
+</ul>
+
+<p>
+Depending on your Linux distro, other packages may be needed.
+The configure scripts should tell you what's missing.
+</p>
+
+
+
+<h2>Getting the Latest Source Code</h2>
+
+Begin by saving your current directory location:
+  <pre>
+  export TOP=$PWD
+  </pre>
+
+<ul>
+<li>Mesa/Gallium master branch. This code is used to build libGL, and the direct rendering svga driver for libGL, vmwgfx_dri.so, and the X acceleration library libxatracker.so.x.x.x. 
+  <pre>
+  git clone git://anongit.freedesktop.org/git/mesa/mesa
+  </pre>
+<li>VMware Linux guest kernel module. Note that this repo contains the complete DRM and TTM code. The vmware-specific driver is really only the files prefixed with vmwgfx. 
+  <pre>
+  git clone git://anongit.freedesktop.org/git/mesa/vmwgfx
+  </pre>
+
+<li>libdrm, A user-space library that interfaces with drm. Most distros ship with this driver. Safest bet is really to replace the system one. Optionally you can point LIBDRM_CFLAGS and LIBDRM_LIBS to the libdrm-2.4.22 package in toolchain. But here, we replace: 
+  <pre>
+  git clone git://anongit.freedesktop.org/git/mesa/drm
+  </pre>
+<li>xf86-video-vmware. The chainloading driver, vmware_drv.so, the legacy driver vmwlegacy_drv.so, and the vmwgfx driver vmwgfx_drv.so. 
+  <pre>
+  git clone git://anongit.freedesktop.org/git/xorg/driver/xf86-video-vmware
+  </pre>
+</ul>
+
+
+<h2>Building the Code</h2>
+
+<ul>
+<li>Build libdrm: If you're on a 32-bit system, you should skip the --libdir configure option. Note also the comment about toolchain libdrm above. 
+  <pre>
+  cd $TOP/drm
+  ./autogen.sh --prefix=/usr --enable-vmwgfx-experimental-api --libdir=/usr/lib64
+  make
+  sudo make install
+  </pre>
+<li>Build Mesa and the vmwgfx_dri.so driver, the vmwgfx_drv.so xorg driver, the X acceleration library libxatracker.
+The vmwgfx_dri.so is used by the OpenGL libraries during direct rendering,
+and by the Xorg server during accelerated indirect GL rendering.
+The libxatracker library is used exclusively by the X server to do render,
+copy and video acceleration:
+<br>
+The following configure options doesn't build the EGL system.
+<br>
+As before, if you're on a 32-bit system, you should skip the --libdir
+configure option.
+  <pre>
+  cd $TOP/mesa
+  ./autogen.sh --prefix=/usr --libdir=/usr/lib64 --with-gallium-drivers=svga --with-dri-drivers= --enable-xa
+  make
+  sudo make install
+  </pre>
+
+Note that you may have to install other packages that Mesa depends upon
+if they're not installed in your system.  You should be told what's missing.
+<br>
+<br>
+
+<li>xf86-video-vmware: Now, once libxatracker is installed, we proceed with building and replacing the current Xorg driver. First check if your system is 32- or 64-bit. If you're building for a 32-bit system, you will not be needing the --libdir=/usr/lib64 option to autogen. 
+  <pre>
+  cd $TOP/xf86-video-vmware
+  ./autogen.sh --prefix=/usr --libdir=/usr/lib64
+  make
+  sudo make install
+  </pre>
+<li>vmwgfx kernel module. First make sure that any old version of this kernel module is removed from the system by issuing
+  <pre>
+  sudo rm /lib/modules/`uname -r`/kernel/drivers/gpu/drm/vmwgfx.ko*
+  </pre>
+Then 
+  <pre>
+  cd $TOP/vmwgfx
+  make
+  sudo make install
+  sudo cp 00-vmwgfx.rules /etc/udev/rules.d
+  sudo depmod -ae
+  </pre>
+</ul>
+
+
+Now try to load the kernel module by issuing
+  <pre>
+  sudo modprobe vmwgfx</pre>
+Then type 
+  <pre>
+  dmesg</pre>
+to watch the debug output. It should contain a number of lines prefixed with "[vmwgfx]". 
+
+<p>
+Then restart the Xserver (or reboot).
+The lines starting with "vmwlegacy" or "VMWARE" in the file /var/log/Xorg.0.log
+should now have been replaced with lines starting with "vmwgfx", indicating that
+the new Xorg driver is in use. 
+</p>
+
+
+<h2>Running OpenGL Programs</h2>
+
+<p>
+In a shell, run 'glxinfo' and look for the following to verify that the
+driver is working:
+</p>
+
+<pre>
+OpenGL vendor string: VMware, Inc.
+OpenGL renderer string: Gallium 0.4 on SVGA3D; build: RELEASE;
+OpenGL version string: 2.1 Mesa 8.0
+</pre>
+
+If you don't see this, try setting this environment variable:
+  <pre>
+  export LIBGL_DEBUG=verbose</pre>
+then rerun glxinfo and examine the output for error messages.
+</p>
+
+
+
+</body>
+</html>
commit 8b7f6de8b9b8797d88449e5329c65b11f6249b12
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Jan 13 09:41:35 2012 -0700

    mesa: s/GLushort/GLubyte/ in pack_ubyte_AL44()
    
    The AL44 format occupies one byte, not two.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit b0af16abf1153da243b856e55f59ca1945860f47)

diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 0982c9a..85b2c69 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -636,7 +636,7 @@ pack_float_ARGB1555_REV(const GLfloat src[4], void *dst)
 static void
 pack_ubyte_AL44(const GLubyte src[4], void *dst)
 {
-   GLushort *d = ((GLushort *) dst);
+   GLubyte *d = ((GLubyte *) dst);
    *d = PACK_COLOR_44(src[ACOMP], src[RCOMP]);
 }
 
commit eb8063361ee74ca3d551950bfc5ffe6615ab06aa
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Jan 13 08:31:26 2012 -0700

    osmesa: fix renderbuffer format selection
    
    The gl_renderbuffer::Format field wasn't always set properly.  This
    didn't matter much in the past but with the recent swrast/renderbuffer
    mapping changes, core Mesa will be directly touching OSMesa colorbuffers
    so using the right MESA_FORMAT_x value is important.
    
    Unfortunately, there aren't MESA_FORMATs for all the possible OSmesa
    format/type combinations, such as GL_FLOAT / OSMESA_ARGB.  If anyone
    runs into these we can add new Mesa formats.
    
    v2: add warnings for unsupported formats, fix ARGB_REV mix-up.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 540a8b2cfdedbf5a635f33c720aa795fae74e08b)

diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 67d329f..3d5ff8a 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -723,9 +723,8 @@ osmesa_choose_line( struct gl_context *ctx )
 static void
 compute_row_addresses( OSMesaContext osmesa )
 {
-   GLint bytesPerPixel, bytesPerRow, i;
+   GLint bytesPerRow, i;
    GLubyte *origin = (GLubyte *) osmesa->rb->Data;
-   GLint bpc; /* bytes per channel */
    GLint rowlength; /* in pixels */
    GLint height = osmesa->rb->Height;
 
@@ -734,32 +733,7 @@ compute_row_addresses( OSMesaContext osmesa )
    else
       rowlength = osmesa->rb->Width;
 
-   if (osmesa->rb->DataType == GL_UNSIGNED_BYTE)
-      bpc = 1;
-   else if (osmesa->rb->DataType == GL_UNSIGNED_SHORT)
-      bpc = 2;
-   else if (osmesa->rb->DataType == GL_FLOAT)
-      bpc = 4;
-   else {
-      _mesa_problem(&osmesa->mesa,
-                    "Unexpected datatype in osmesa::compute_row_addresses");
-      return;
-   }
-
-   if ((osmesa->format == OSMESA_RGB) || (osmesa->format == OSMESA_BGR)) {
-      /* RGB mode */
-      bytesPerPixel = 3 * bpc;
-   }
-   else if (osmesa->format == OSMESA_RGB_565) {
-      /* 5/6/5 RGB pixel in 16 bits */
-      bytesPerPixel = 2;
-   }
-   else {
-      /* RGBA mode */
-      bytesPerPixel = 4 * bpc;
-   }
-
-   bytesPerRow = rowlength * bytesPerPixel;
+   bytesPerRow = rowlength * _mesa_get_format_bytes(osmesa->rb->Format);
 
    if (osmesa->yup) {
       /* Y=0 is bottom line of window */
@@ -802,20 +776,33 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    /* Note: we can ignoring internalFormat for "window-system" renderbuffers */
    (void) internalFormat;
 
+   /* Given the user-provided format and type, figure out which MESA_FORMAT_x
+    * to use.
+    * XXX There aren't Mesa formats for all the possible combinations here!
+    * XXX Specifically, there's only RGBA-order 16-bit/channel and float
+    * XXX formats.
+    * XXX The 8-bit/channel formats should all be OK.
+    */
    if (osmesa->format == OSMESA_RGBA) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
+         if (_mesa_little_endian())
+            rb->Format = MESA_FORMAT_RGBA8888_REV;
+         else
+            rb->Format = MESA_FORMAT_RGBA8888;
          rb->GetRow = get_row_RGBA8;
          rb->GetValues = get_values_RGBA8;
          rb->PutRow = put_row_RGBA8;
          rb->PutValues = put_values_RGBA8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
+         rb->Format = MESA_FORMAT_RGBA_16;
          rb->GetRow = get_row_RGBA16;
          rb->GetValues = get_values_RGBA16;
          rb->PutRow = put_row_RGBA16;
          rb->PutValues = put_values_RGBA16;
       }
       else {
+         rb->Format = MESA_FORMAT_RGBA_FLOAT32;
          rb->GetRow = get_row_RGBA32;
          rb->GetValues = get_values_RGBA32;
          rb->PutRow = put_row_RGBA32;
@@ -824,18 +811,26 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else if (osmesa->format == OSMESA_BGRA) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
+         if (_mesa_little_endian())
+            rb->Format = MESA_FORMAT_ARGB8888;
+         else
+            rb->Format = MESA_FORMAT_ARGB8888_REV;
          rb->GetRow = get_row_BGRA8;
          rb->GetValues = get_values_BGRA8;
          rb->PutRow = put_row_BGRA8;
          rb->PutValues = put_values_BGRA8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
+         _mesa_warning(ctx, "Unsupported OSMesa format BGRA/GLushort");
+         rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
          rb->GetRow = get_row_BGRA16;
          rb->GetValues = get_values_BGRA16;
          rb->PutRow = put_row_BGRA16;
          rb->PutValues = put_values_BGRA16;
       }
       else {
+         _mesa_warning(ctx, "Unsupported OSMesa format BGRA/GLfloat");
+         rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
          rb->GetRow = get_row_BGRA32;
          rb->GetValues = get_values_BGRA32;
          rb->PutRow = put_row_BGRA32;
@@ -844,18 +839,26 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else if (osmesa->format == OSMESA_ARGB) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
+         if (_mesa_little_endian())
+            rb->Format = MESA_FORMAT_ARGB8888_REV;
+         else
+            rb->Format = MESA_FORMAT_ARGB8888;
          rb->GetRow = get_row_ARGB8;
          rb->GetValues = get_values_ARGB8;
          rb->PutRow = put_row_ARGB8;
          rb->PutValues = put_values_ARGB8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
+         _mesa_warning(ctx, "Unsupported OSMesa format ARGB/GLushort");
+         rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
          rb->GetRow = get_row_ARGB16;
          rb->GetValues = get_values_ARGB16;
          rb->PutRow = put_row_ARGB16;
          rb->PutValues = put_values_ARGB16;
       }
       else {
+         _mesa_warning(ctx, "Unsupported OSMesa format ARGB/GLfloat");
+         rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
          rb->GetRow = get_row_ARGB32;
          rb->GetValues = get_values_ARGB32;
          rb->PutRow = put_row_ARGB32;
@@ -864,18 +867,23 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else if (osmesa->format == OSMESA_RGB) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
+         rb->Format = MESA_FORMAT_RGB888;
          rb->GetRow = get_row_RGB8;
          rb->GetValues = get_values_RGB8;
          rb->PutRow = put_row_RGB8;
          rb->PutValues = put_values_RGB8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
+         _mesa_warning(ctx, "Unsupported OSMesa format RGB/GLushort");
+         rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
          rb->GetRow = get_row_RGB16;
          rb->GetValues = get_values_RGB16;
          rb->PutRow = put_row_RGB16;
          rb->PutValues = put_values_RGB16;
       }
       else {
+         _mesa_warning(ctx, "Unsupported OSMesa format RGB/GLfloat");
+         rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
          rb->GetRow = get_row_RGB32;
          rb->GetValues = get_values_RGB32;
          rb->PutRow = put_row_RGB32;
@@ -884,18 +892,23 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else if (osmesa->format == OSMESA_BGR) {
       if (rb->DataType == GL_UNSIGNED_BYTE) {
+         rb->Format = MESA_FORMAT_BGR888;
          rb->GetRow = get_row_BGR8;
          rb->GetValues = get_values_BGR8;
          rb->PutRow = put_row_BGR8;
          rb->PutValues = put_values_BGR8;
       }
       else if (rb->DataType == GL_UNSIGNED_SHORT) {
+         _mesa_warning(ctx, "Unsupported OSMesa format BGR/GLushort");
+         rb->Format = MESA_FORMAT_RGBA_16; /* not exactly right */
          rb->GetRow = get_row_BGR16;
          rb->GetValues = get_values_BGR16;
          rb->PutRow = put_row_BGR16;
          rb->PutValues = put_values_BGR16;
       }
       else {
+         _mesa_warning(ctx, "Unsupported OSMesa format BGR/GLfloat");
+         rb->Format = MESA_FORMAT_RGBA_FLOAT32; /* not exactly right */
          rb->GetRow = get_row_BGR32;
          rb->GetValues = get_values_BGR32;
          rb->PutRow = put_row_BGR32;
@@ -904,6 +917,7 @@ osmesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
    }
    else if (osmesa->format == OSMESA_RGB_565) {
       ASSERT(rb->DataType == GL_UNSIGNED_BYTE);
+      rb->Format = MESA_FORMAT_RGB565;
       rb->GetRow = get_row_RGB_565;
       rb->GetValues = get_values_RGB_565;
       rb->PutRow = put_row_RGB_565;
@@ -937,24 +951,6 @@ new_osmesa_renderbuffer(struct gl_context *ctx, GLenum format, GLenum type)
       rb->ClassID = OSMESA_RENDERBUFFER_CLASS;
 
       rb->InternalFormat = GL_RGBA;
-      switch (type) {
-      case GL_UNSIGNED_BYTE:
-         rb->Format = MESA_FORMAT_RGBA8888_REV;
-         break;
-      case GL_UNSIGNED_SHORT:
-         rb->Format = MESA_FORMAT_RGBA_16;
-         break;
-      case GL_UNSIGNED_SHORT_5_6_5:
-         rb->Format = MESA_FORMAT_RGB565;
-         type = GL_UNSIGNED_BYTE;
-         break;
-      case GL_FLOAT:
-         rb->Format = MESA_FORMAT_RGBA_FLOAT32;
-         break;
-      default:
-         assert(0 && "Unexpected type in new_osmesa_renderbuffer()");
-         rb->Format = MESA_FORMAT_RGBA8888;
-      }
       rb->_BaseFormat = GL_RGBA;
       rb->DataType = type;
    }
commit b26682e12e38325b37ddfe7de8f705f29390c584
Author: Brian Paul <brianp at vmware.com>
Date:   Fri Jan 13 08:31:26 2012 -0700

    docs: freshen up the introduction page with Mesa 8.0 info, etc
    (cherry picked from commit 0c14bbbc8634f516d75a06e2a52d11d674e41170)

diff --git a/docs/intro.html b/docs/intro.html
index 0806caf..303f5eb 100644
--- a/docs/intro.html
+++ b/docs/intro.html
@@ -132,12 +132,26 @@ June 2007: Mesa 7.0 is released, implementing the OpenGL 2.1 specification
 and OpenGL Shading Language.
 </p>
 
+<p>
+2008: Keith Whitwell and other Tungsten Graphics employees develop
+<a href="http://en.wikipedia.org/wiki/Gallium3D"  target="_parent">Gallium</a>
+- a new GPU abstraction layer.  The latest Mesa drivers are based on
+Gallium and other APIs such as OpenVG are implemented on top of Gallium.
+</p>
+
+<p>
+February 2012: Mesa 8.0 is released, implementing the OpenGL 3.0 specification
+and version 1.30 of the OpenGL Shading Language.
+</p>
 
 <p>
-Ongoing: Mesa is used as the core of many hardware OpenGL drivers for
-the XFree86 and X.org X servers within the
-<A href="http://dri.freedesktop.org/" target="_parent">DRI project</A>.
-I continue to enhance Mesa with new extensions and features.
+Ongoing: Mesa is the OpenGL implementation for several types of hardware
+made by Intel, AMD and NVIDIA, plus the VMware virtual GPU.
+There's also several software-based renderers: swrast (the legacy
+Mesa rasterizer), softpipe (a gallium reference driver) and llvmpipe
+(LLVM/JIT-based high-speed rasterizer).
+Work continues on the drivers and core Mesa to implement newer versions
+of the OpenGL specification.
 </p>
 
 
@@ -151,6 +165,15 @@ of the OpenGL specification is implemented.
 </p>
 
 
+<H2>Version 8.x features</H2>
+<p>
+Version 8.x of Mesa implements the OpenGL 3.0 API.
+The developers at Intel deserve a lot of credit for implementing most
+of the OpenGL 3.0 features in core Mesa, the GLSL compiler as well as
+the i965 driver.
+</p>
+
+
 <H2>Version 7.x features</H2>
 <p>
 Version 7.x of Mesa implements the OpenGL 2.1 API.  The main feature
commit deff0244edd6b822aea30b37955723012d69ca16
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 11:52:22 2012 -0700

    osmesa: fix glReadPixels, etc
    
    Needed to implement the Map/UnmapRenderbuffer() driver hooks.
    This fixes glRead/Draw/CopyPixels, etc.
    
    See https://bugs.freedesktop.org/show_bug.cgi?id=44723
    
    Note: This is a candidate for the 8.0 branch.
    
    Tested-by: Kevin Hobbs <hobbsk at ohiou.edu>
    (cherry picked from commit cb254b75d7d971b3f1baab45a82cedf0bd6c36c4)

diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index acfe629..67d329f 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -56,6 +56,8 @@
 #include "vbo/vbo.h"
 
 
+#define OSMESA_RENDERBUFFER_CLASS 0x053
+
 
 /**
  * OSMesa rendering context, derived from core Mesa struct gl_context.
@@ -932,11 +934,12 @@ new_osmesa_renderbuffer(struct gl_context *ctx, GLenum format, GLenum type)
       rb->RefCount = 1;
       rb->Delete = osmesa_delete_renderbuffer;
       rb->AllocStorage = osmesa_renderbuffer_storage;
+      rb->ClassID = OSMESA_RENDERBUFFER_CLASS;
 
       rb->InternalFormat = GL_RGBA;
       switch (type) {
       case GL_UNSIGNED_BYTE:
-         rb->Format = MESA_FORMAT_RGBA8888;
+         rb->Format = MESA_FORMAT_RGBA8888_REV;
          break;
       case GL_UNSIGNED_SHORT:
          rb->Format = MESA_FORMAT_RGBA_16;
@@ -959,6 +962,56 @@ new_osmesa_renderbuffer(struct gl_context *ctx, GLenum format, GLenum type)
 }
 
 
+
+static void
+osmesa_MapRenderbuffer(struct gl_context *ctx,
+                       struct gl_renderbuffer *rb,
+                       GLuint x, GLuint y, GLuint w, GLuint h,
+                       GLbitfield mode,
+                       GLubyte **mapOut, GLint *rowStrideOut)
+{
+   const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
+
+   if (rb->ClassID == OSMESA_RENDERBUFFER_CLASS) {
+      /* this is an OSMesa renderbuffer which wraps user memory */
+      const GLuint bpp = _mesa_get_format_bytes(rb->Format);
+      GLint rowStride; /* in bytes */
+
+      if (osmesa->userRowLength)
+         rowStride = osmesa->userRowLength * bpp;
+      else
+         rowStride = rb->Width * bpp;
+
+      if (!osmesa->yup) {
+         /* Y=0 is top line of window */
+         y = rb->Height - y - 1;
+         *rowStrideOut = -rowStride;
+      }
+      else {
+         *rowStrideOut = rowStride;
+      }
+
+      *mapOut = (GLubyte *) rb->Data + y * rowStride + x * bpp;
+   }
+   else {
+      _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
+                                    mapOut, rowStrideOut);
+   }
+}
+
+
+static void
+osmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
+{
+   if (rb->ClassID == OSMESA_RENDERBUFFER_CLASS) {
+      /* no-op */
+   }
+   else {
+      _swrast_unmap_soft_renderbuffer(ctx, rb);
+   }
+}
+
+
 /**********************************************************************/
 /*****                    Public Functions                        *****/
 /**********************************************************************/
@@ -1157,6 +1210,9 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
          tnl = TNL_CONTEXT(ctx);
          tnl->Driver.RunPipeline = _tnl_run_pipeline;
 
+         ctx->Driver.MapRenderbuffer = osmesa_MapRenderbuffer;
+         ctx->Driver.UnmapRenderbuffer = osmesa_UnmapRenderbuffer;
+
          /* Extend the software rasterizer with our optimized line and triangle
           * drawing functions.
           */
commit 830688b36ace22ad1412b5c1caba0e0ccd474c3c
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 11:41:42 2012 -0700

    intel: move declaration before code
    (cherry picked from commit 062a4b601edaaea193397bd5d86fea11ceec04f4)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 1d8b10e..c37075c 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -651,10 +651,10 @@ intel_render_texture(struct gl_context * ctx,
    struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
    struct intel_texture_image *intel_image = intel_texture_image(image);
    struct intel_mipmap_tree *mt = intel_image->mt;
+   int layer;
 
    (void) fb;
 
-   int layer;
    if (att->CubeMapFace > 0) {
       assert(att->Zoffset == 0);
       layer = att->CubeMapFace;
commit cd56917a50ee8f2fe56ae0f12b1769351b21425c
Author: Brian Paul <brianp at vmware.com>
Date:   Sat Jan 7 15:05:35 2012 -0700

    intel: fix mapping of malloc'd renderbuffers
    
    This fixes accum buffer operations.  The accumulation buffer is the
    only malloc-based renderbuffer for the intel drivers.
    
    v2: apply x/y offset to returned pointer
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    (cherry picked from commit 6dbdc0395698de929e23b4ec1ab399e64ecfd264)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index b95193d..1d8b10e 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -132,6 +132,15 @@ intel_map_renderbuffer(struct gl_context *ctx,
    void *map;
    int stride;
 
+   if (!irb && rb->Data) {
+      /* this is a malloc'd renderbuffer (accum buffer) */
+      GLint bpp = _mesa_get_format_bytes(rb->Format);
+      GLint rowStride = rb->RowStride * bpp;
+      *out_map = (GLubyte *) rb->Data + y * rowStride + x * bpp;
+      *out_stride = rowStride;
+      return;
+   }
+
    /* We sometimes get called with this by our intel_span.c usage. */
    if (!irb->mt) {
       *out_map = NULL;
@@ -176,6 +185,12 @@ intel_unmap_renderbuffer(struct gl_context *ctx,
    DBG("%s: rb %d (%s)\n", __FUNCTION__,
        rb->Name, _mesa_get_format_name(rb->Format));
 
+   if (!irb && rb->Data) {
+      /* this is a malloc'd renderbuffer (accum buffer) */
+      /* nothing to do */
+      return;
+   }
+
    intel_miptree_unmap(intel, irb->mt, irb->mt_level, irb->mt_layer);
 }
 
commit 867fdbd36dd29032604a149367e69f109c2691e0
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 09:55:40 2012 -0700

    mesa: remove incorrect (float) cast in mipmap do_row()
    
    The array holds GLuint values so remove the float cast.
    Note, however, that to compute the average of four GLuints we really
    want to do (a+b+c+d)/4 but that could overflow.  This change doesn't
    address that for now.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 003dd8adf39c964d8c7beb86955a61ceb3706ebc)

diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index 867506c..03ce536 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -476,7 +476,7 @@ do_row(GLenum datatype, GLuint comps, GLint srcWidth,
       GLuint *dst = (GLuint *) dstRow;
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
-         dst[i] = (GLfloat)(rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4);
+         dst[i] = rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4;
       }
    }
 
commit d7a4eb331bb177ad9f81d14305b8107a3c9dccfb
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 09:54:04 2012 -0700

    swrast: use BITFIELD64_BIT() macro to fix MSVC warnings
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 706400f0a7a59bba89eca8e97a1ada45445ee6df)

diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h
index d99d9d3..376ef32 100644
--- a/src/mesa/swrast/s_aalinetemp.h
+++ b/src/mesa/swrast/s_aalinetemp.h
@@ -175,7 +175,7 @@ NAME(line)(struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1)
                              line.attrPlane[attr][c]);
             }
          }
-         line.span.arrayAttribs |= (1 << attr);
+         line.span.arrayAttribs |= BITFIELD64_BIT(attr);
          if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
             const GLuint u = attr - FRAG_ATTRIB_TEX0;
             const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 94b7fe3..06824ea 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -531,7 +531,7 @@ _swrast_update_active_attribs(struct gl_context *ctx)
    {
       GLuint i, num = 0;
       for (i = 0; i < FRAG_ATTRIB_MAX; i++) {
-         if (attribsMask & (1 << i)) {
+         if (attribsMask & BITFIELD64_BIT(i)) {
             swrast->_ActiveAttribs[num++] = i;
             /* how should this attribute be interpolated? */
             if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1)
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 689fe34..e899303 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -175,7 +175,7 @@ interpolate_active_attribs(struct gl_context *ctx, SWspan *span,
    attrMask &= ~span->arrayAttribs;
 
    ATTRIB_LOOP_BEGIN
-      if (attrMask & (1 << attr)) {
+      if (attrMask & BITFIELD64_BIT(attr)) {
          const GLfloat dwdx = span->attrStepX[FRAG_ATTRIB_WPOS][3];
          GLfloat w = span->attrStart[FRAG_ATTRIB_WPOS][3];
          const GLfloat dv0dx = span->attrStepX[attr][0];
@@ -199,8 +199,8 @@ interpolate_active_attribs(struct gl_context *ctx, SWspan *span,
             v3 += dv3dx;
             w += dwdx;
          }
-         ASSERT((span->arrayAttribs & (1 << attr)) == 0);
-         span->arrayAttribs |= (1 << attr);
+         ASSERT((span->arrayAttribs & BITFIELD64_BIT(attr)) == 0);
+         span->arrayAttribs |= BITFIELD64_BIT(attr);
       }
    ATTRIB_LOOP_END
 }
commit ee5b35c568acff1bf5bed537635ff51d725337a6
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 09:53:07 2012 -0700

    mesa: fix ir_variable declaration
    
    ir_variable is a class, not a struct.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit decd018b992eb0f7f85338ee39083daca04885b6)

diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp
index 3596a3d..b53b717 100644
--- a/src/mesa/main/ff_fragment_shader.cpp
+++ b/src/mesa/main/ff_fragment_shader.cpp
@@ -528,7 +528,7 @@ struct texenv_fragment_program {
     */
 
    /* Texcoord override from bumpmapping. */
-   struct ir_variable *texcoord_tex[MAX_TEXTURE_COORD_UNITS];
+   ir_variable *texcoord_tex[MAX_TEXTURE_COORD_UNITS];
 
    /* Reg containing texcoord for a texture unit,
     * needed for bump mapping, else undef.
commit a748a9f8eef6998133f8da1b18063a6c04fc4474
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 09:51:21 2012 -0700

    mesa: fix incorrect float vs. int values in a few places
    
    In the first case, the newImage[] array contains GLuint values.
    In the second case, the parameter type is GLuint, but the maxDepth
    value is never used in this case (GL_FLOAT_32_UNSIGNED_INT_24_8_REV).
    Pass ~OU just to be safe.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit a240c998ac649d79f423bb0c445993132cd56f97)

diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 512965f..a9c64ce 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -515,9 +515,9 @@ make_temp_uint_image(struct gl_context *ctx, GLuint dims,
          for (k = 0; k < texComponents; k++) {
             GLint j = map[k];
             if (j == ZERO)
-               newImage[i * texComponents + k] = 0.0F;
+               newImage[i * texComponents + k] = 0;
             else if (j == ONE)
-               newImage[i * texComponents + k] = 1.0F;
+               newImage[i * texComponents + k] = 1;
             else
                newImage[i * texComponents + k] = tempImage[i * logComponents + j];
          }
@@ -4094,7 +4094,7 @@ _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS)
                _mesa_unpack_depth_span(ctx, srcWidth,
                                        GL_FLOAT_32_UNSIGNED_INT_24_8_REV, /* dst type */
                                        dstRow, /* dst addr */
-                                       1.0f, srcType, src, srcPacking);
+                                       ~0U, srcType, src, srcPacking);
 
             if (srcFormat != GL_DEPTH_COMPONENT)
                _mesa_unpack_stencil_span(ctx, srcWidth,
commit f1ff449120a6770953776aa996297c3cd9fb4ef6
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 09:50:27 2012 -0700

    meta: fix incorrect argument order in setup_texture_coords() call
    
    And pass integer width, height values.
    
    NOTE: This is a candidate for the 8.0 branch.
    
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    (cherry picked from commit 2f0fa456e31a7030c911a563b62c84d448b09800)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index ad289aa..abf2f1f 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -2920,8 +2920,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
 
    /* setup texcoords (XXX what about border?) */
    setup_texture_coords(faceTarget,
-                        0.0f, 0.0f, /* width, height never used here */
                         slice,
+                        0, 0, /* width, height never used here */
                         verts[0].tex,
                         verts[1].tex,
                         verts[2].tex,
commit af33e16eab657f0b353c201b10992632d6556275
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 08:30:52 2012 -0700

    sofpipe: remove extraneous semicolon
    (cherry picked from commit 0c57323de8bcfb5932e14a88ef9554059fc3be72)

diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index 32408f3..f5ff68c 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -45,7 +45,7 @@
 #include "sp_fence.h"
 #include "sp_public.h"
 
-DEBUG_GET_ONCE_BOOL_OPTION(use_llvm, "SOFTPIPE_USE_LLVM", FALSE);
+DEBUG_GET_ONCE_BOOL_OPTION(use_llvm, "SOFTPIPE_USE_LLVM", FALSE)
 
 static const char *
 softpipe_get_vendor(struct pipe_screen *screen)
commit 89a1e7caf486b089b8c2790fc8e61debebbe7590
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 08:28:20 2012 -0700

    st/mesa: fix struct vs. class compilation warning
    
    glsl_to_tgsi_visitor is earlier defined as a class, not a struct.
    Fixes MSVC warning.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit 9f2963b631cb2a2899fcb0eb384895fd33f9821d)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index f5bee01..26047cf 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5093,7 +5093,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 }
 
 void
-st_translate_stream_output_info(struct glsl_to_tgsi_visitor *glsl_to_tgsi,
+st_translate_stream_output_info(glsl_to_tgsi_visitor *glsl_to_tgsi,
                                 const GLuint outputMapping[],
                                 struct pipe_stream_output_info *so)
 {
commit ad77e2fb78dfb6abf8966524346800b389052df4
Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 12 07:53:22 2012 -0700

    configs: fix, simplify RADEON_LIBS, RADEON_CFLAGS
    
    Fixes build problems with the r200, radeon drivers.
    
    NOTE: This is a candidate for the 8.0 branch.
    (cherry picked from commit c7188ece0ee33f13e6f6aa776a5639bcd4047e5b)

diff --git a/configs/linux-dri b/configs/linux-dri
index 6990c3a..e63790e 100644
--- a/configs/linux-dri
+++ b/configs/linux-dri
@@ -70,7 +70,6 @@ INTEL_CFLAGS = $(shell $(PKG_CONFIG) --cflags libdrm_intel)
 NOUVEAU_LIBS = $(shell $(PKG_CONFIG) --libs libdrm_nouveau)
 NOUVEAU_CFLAGS = $(shell $(PKG_CONFIG) --cflags libdrm_nouveau)
 
-LIBDRM_RADEON_LIBS = $(shell $(PKG_CONFIG) --libs libdrm_radeon)
-LIBDRM_RADEON_CFLAGS = $(shell $(PKG_CONFIG) --cflags libdrm_radeon)
-RADEON_CFLAGS = "-DHAVE_LIBDRM_RADEON=1 $(LIBDRM_RADEON_CFLAGS)"
+RADEON_LIBS = $(shell $(PKG_CONFIG) --libs libdrm_radeon)
+RADEON_CFLAGS = $(shell $(PKG_CONFIG) --cflags libdrm_radeon)
 RADEON_LDFLAGS = $(LIBDRM_RADEON_LIBS)
commit 1e51d4b4f6287da42759b8e52d1bf0f87acdc5e4
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jan 12 10:13:37 2012 +0000

    softpipe: bump max texture array layers to 256.
    
    This as per GL3 specification.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index 37aa585..32408f3 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -121,7 +121,7 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
       return 1;
    case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
-      return 64; /* matches core Mesa defaults */
+      return 256; /* for GL3 */
    case PIPE_CAP_MIN_TEXEL_OFFSET:
       return -8;
    case PIPE_CAP_MAX_TEXEL_OFFSET:
commit 0b9e6d2017f4123ba83a6522c8c4fd2111bb090d
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jan 12 15:05:15 2012 +0000

    r600g: don't advertise integers yet on r600.
    
    Still some work to be done before this is finished.
    
    This is a candidate for 8.0 branch.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 3e044bcc4b2fcf9418f5a8fb682c8fab3bc454e9)

diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index e50b5cc..537024c 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -505,8 +505,6 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, unsigned shader, e
 	case PIPE_SHADER_CAP_SUBROUTINES:
 		return 0;
 	case PIPE_SHADER_CAP_INTEGERS:
-		if (rscreen->chip_class == EVERGREEN)
-			return 1;
 		return 0;
 	case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
 		return 16;
commit 57665cb09e00761240afbb93adcd88f3ed139b15
Author: Thomas Hellstrom <thellstrom at vmware.com>
Date:   Thu Jan 12 12:10:53 2012 +0100

    configure: Add the svga gallium driver to the default gallium drivers
    
    Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
    Reviewed-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/configure.ac b/configure.ac
index e2302de..7c50e3c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -662,7 +662,7 @@ AC_ARG_ENABLE([gallium_gbm],
     [enable_gallium_gbm=auto])
 
 # Option for Gallium drivers
-GALLIUM_DRIVERS_DEFAULT="r300,r600,swrast"
+GALLIUM_DRIVERS_DEFAULT="r300,r600,svga,swrast"
 
 AC_ARG_WITH([gallium-drivers],
     [AS_HELP_STRING([--with-gallium-drivers@<:@=DIRS...@:>@],
commit 372b7f1d35c141994ce9fd212ad6e42f8c01a3a3
Author: Thomas Hellstrom <thellstrom at vmware.com>
Date:   Thu Jan 12 11:57:12 2012 +0100

    st/xa: Bump version to 1.0.0 according to the README
    
    Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
    Reviewed-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/src/gallium/state_trackers/xa/xa_tracker.h b/src/gallium/state_trackers/xa/xa_tracker.h
index d3adedb..ffe24f7 100644
--- a/src/gallium/state_trackers/xa/xa_tracker.h
+++ b/src/gallium/state_trackers/xa/xa_tracker.h
@@ -36,8 +36,8 @@
 
 #include <stdint.h>
 
-#define XA_TRACKER_VERSION_MAJOR 0
-#define XA_TRACKER_VERSION_MINOR 6
+#define XA_TRACKER_VERSION_MAJOR 1
+#define XA_TRACKER_VERSION_MINOR 0
 #define XA_TRACKER_VERSION_PATCH 0
 
 #define XA_FLAG_SHARED         (1 << 0)
diff --git a/src/gallium/targets/xa-vmwgfx/Makefile b/src/gallium/targets/xa-vmwgfx/Makefile
index 26d95cb..f185e1a 100644
--- a/src/gallium/targets/xa-vmwgfx/Makefile
+++ b/src/gallium/targets/xa-vmwgfx/Makefile
@@ -3,8 +3,8 @@ include $(TOP)/configs/current
 
 ##### MACROS #####
 
-XA_MAJOR = 0
-XA_MINOR = 6
+XA_MAJOR = 1
+XA_MINOR = 0
 XA_TINY = 0
 XA_CFLAGS = -Wall -pedantic
 
commit 4b86bd13474cfc6e0ffe5c7a1c2621c5a6171dac
Author: José Fonseca <jfonseca at vmware.com>
Date:   Wed Jan 11 20:54:13 2012 +0000

    svga: Fix user clip planes.
    
    Dirty flags also need to be updated in face of recent interface change.
    
    Fixes regression in compiz.
    
    Reviewed-by: Brian Paul <brianp at vmware.com>

diff --git a/src/gallium/drivers/svga/svga_state_framebuffer.c b/src/gallium/drivers/svga/svga_state_framebuffer.c
index f3625e0..3244023 100644
--- a/src/gallium/drivers/svga/svga_state_framebuffer.c
+++ b/src/gallium/drivers/svga/svga_state_framebuffer.c
@@ -477,7 +477,7 @@ emit_clip_planes( struct svga_context *svga,
 
    /* TODO: just emit directly from svga_set_clip_state()?
     */
-   for (i = 0; i < 6; i++) {
+   for (i = 0; i < SVGA3D_MAX_CLIP_PLANES; i++) {
       /* need to express the plane in D3D-style coordinate space.
        * GL coords get converted to D3D coords with the matrix:
        * [ 1  0  0  0 ]
diff --git a/src/gallium/drivers/svga/svga_state_rss.c b/src/gallium/drivers/svga/svga_state_rss.c
index d94ac35..af68d9c 100644
--- a/src/gallium/drivers/svga/svga_state_rss.c
+++ b/src/gallium/drivers/svga/svga_state_rss.c
@@ -244,8 +244,8 @@ static int emit_rss( struct svga_context *svga,
       EMIT_RS_FLOAT( svga, bias, DEPTHBIAS, fail );
    }
 
-   if (dirty & SVGA_NEW_CLIP) {
-      /* the number of clip planes is how many planes to enable */
+   if (dirty & SVGA_NEW_RAST) {
+      /* bitmask of the enabled clip planes */
       unsigned enabled = svga->curr.rast->templ.clip_plane_enable;
       EMIT_RS( svga, enabled, CLIPPLANEENABLE, fail );
    }
@@ -285,7 +285,6 @@ struct svga_tracked_state svga_hw_rss =
 
    (SVGA_NEW_BLEND |
     SVGA_NEW_BLEND_COLOR |
-    SVGA_NEW_CLIP |
     SVGA_NEW_DEPTH_STENCIL |
     SVGA_NEW_STENCIL_REF |
     SVGA_NEW_RAST |
commit 7465c5d9761762134db86505a637676cc79e622f
Author: Thomas Hellstrom <thellstrom at vmware.com>
Date:   Tue Jan 10 14:37:33 2012 +0100

    gallium/svga: Pass the SVGA3D_SURFACE_HINT_RENDERTARGET flag to the device
    
    Some hardware versions rely on it to render correctly.
    
    Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
    Reviewed-by: José Fonseca <jfonseca at vmware.com>
    Reviewed-by: Jakob Bornecrantz <jakob at vmware.com>

diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
index d374842..92286f9 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.c
+++ b/src/gallium/drivers/svga/svga_resource_texture.c
@@ -454,16 +454,19 @@ svga_texture_create(struct pipe_screen *screen,
    }
 
    /* 
-    * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
+    * Note: Previously we never passed the
+    * SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
     * know beforehand whether a texture will be used as a rendertarget or not
     * and it always requests PIPE_BIND_RENDER_TARGET, therefore
     * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose.
+    *
+    * However, this was changed since other state trackers
+    * (XA for example) uses it accurately and certain device versions
+    * relies on it in certain situations to render correctly.
     */
-#if 0
    if((template->bind & PIPE_BIND_RENDER_TARGET) &&
       !util_format_is_s3tc(template->format))
       tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
-#endif
    
    if(template->bind & PIPE_BIND_DEPTH_STENCIL)
       tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
commit 9489ae8938b74551913337876656bcb9178a8905
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 11 18:19:37 2012 -0700

    mesa: remove const qualifier from fProg to silence warning
    
    The args to _mesa_reference_shader_program() can't be const.
    (cherry picked from commit 459a44460e4d31d69d7ff04c1000917ca7870ff3)

diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 56bb797..b910543 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -228,7 +228,7 @@ update_program(struct gl_context *ctx)
 {
    const struct gl_shader_program *vsProg = ctx->Shader.CurrentVertexProgram;
    const struct gl_shader_program *gsProg = ctx->Shader.CurrentGeometryProgram;
-   const struct gl_shader_program *fsProg = ctx->Shader.CurrentFragmentProgram;
+   struct gl_shader_program *fsProg = ctx->Shader.CurrentFragmentProgram;
    const struct gl_vertex_program *prevVP = ctx->VertexProgram._Current;
    const struct gl_fragment_program *prevFP = ctx->FragmentProgram._Current;
    const struct gl_geometry_program *prevGP = ctx->GeometryProgram._Current;
commit b8af8b83cf3d42dd286c8de062ab9f5fee84d397
Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 11 18:19:09 2012 -0700

    mesa: include uniforms.h to silence warning, remove unused var
    
    (cherry picked from commit fe1b38960b44135f6557a1e7a9fb5adc66d0edbb)

diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 5bfe217..8b68ebf 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -45,6 +45,7 @@
 #include "main/mtypes.h"
 #include "main/shaderapi.h"
 #include "main/shaderobj.h"
+#include "main/uniforms.h"
 #include "program/program.h"
 #include "program/prog_parameter.h"
 #include "ralloc.h"
@@ -936,8 +937,6 @@ static GLboolean
 validate_shader_program(const struct gl_shader_program *shProg,
                         char *errMsg)
 {
-   unsigned i;
-
    if (!shProg->LinkStatus) {
       return GL_FALSE;
    }


More information about the Xquartz-changes mailing list