Eagle-eyed observers will note that all of the device-independent code for SGI_make_current_read (and glXMakeCurrentContext from GLX 1.3) was comitted to CVS earlier today. After installing the new code, doing 'LIBGL_ALWAYS_INDIRECT=y glxinfo' on any DRI system should show GLX_SGI_make_current_read listed in the GLX extensions section.

As I mentioned in a couple earlier threads, there are some problems with enabling this extension in a couple different drivers. Because of that I have not committed any device-dependent code. Attached to this message are the patches to the Radeon and MGA drivers to enable SGI_make_current_read. I expect similar patches will be needed for the other drivers. The MGA patch seems okay, but I have not had a chance to test it much. The Radeon patch has several problems with both xdemos/wincopy from Mesa and my patched glxgears (see the previous thread for that patch).

I fully expect that the Rage128 and R200 drivers will exhibit the same problems (when patched) as the Radeon driver. I'd really appreciate it if someone could patch up the i810 and i830 drivers to support the extension. I'm not terribly worried about the sis, gamma, or tdfx drivers. :)

I'm going to be travelling on business all next week, so I won't be able to work on this until 7/16 at the soonest. I will be checking my e-mail and I plan to attend the Monday meeting.
Index: lib/GL/mesa/src/drv/radeon/radeon_context.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/radeon/radeon_context.c,v
retrieving revision 1.39
diff -u -d -r1.39 radeon_context.c
--- lib/GL/mesa/src/drv/radeon/radeon_context.c 10 Jun 2003 18:50:43 -0000      1.39
+++ lib/GL/mesa/src/drv/radeon/radeon_context.c 3 Jul 2003 15:53:13 -0000
@@ -254,7 +254,8 @@
    /* Init radeon context data */
    rmesa->dri.context = driContextPriv;
    rmesa->dri.screen = sPriv;
-   rmesa->dri.drawable = NULL; /* Set by XMesaMakeCurrent */
+   rmesa->dri.drawable = NULL; /* Set by radeonMakeCurrent */
+   rmesa->dri.readable = NULL; /* Set by radeonMakeCurrent */
    rmesa->dri.hwContext = driContextPriv->hHWContext;
    rmesa->dri.hwLock = &sPriv->pSAREA->lock;
    rmesa->dri.fd = sPriv->fd;
@@ -514,6 +515,7 @@
    if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
       radeonContextPtr rmesa;
       GLcontext *ctx;
+
       rmesa = (radeonContextPtr) dPriv->driContextPriv->driverPrivate;
       ctx = rmesa->glCtx;
       if (ctx->Visual.doubleBufferMode) {
@@ -549,8 +551,10 @@
       if (RADEON_DEBUG & DEBUG_DRI)
         fprintf(stderr, "%s ctx %p\n", __FUNCTION__, newCtx->glCtx);
 
-      if ( newCtx->dri.drawable != driDrawPriv ) {
+      if ( (newCtx->dri.drawable != driDrawPriv)
+          || (newCtx->dri.readable != driReadPriv) ) {
         newCtx->dri.drawable = driDrawPriv;
+        newCtx->dri.readable = driReadPriv;
         radeonUpdateWindow( newCtx->glCtx );
         radeonUpdateViewportOffset( newCtx->glCtx );
       }
Index: lib/GL/mesa/src/drv/radeon/radeon_context.h
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/radeon/radeon_context.h,v
retrieving revision 1.30
diff -u -d -r1.30 radeon_context.h
--- lib/GL/mesa/src/drv/radeon/radeon_context.h 20 Jun 2003 17:50:21 -0000      1.30
+++ lib/GL/mesa/src/drv/radeon/radeon_context.h 3 Jul 2003 15:53:14 -0000
@@ -483,6 +483,7 @@
    __DRIcontextPrivate *context;       /* DRI context */
    __DRIscreenPrivate  *screen;        /* DRI screen */
    __DRIdrawablePrivate        *drawable;      /* DRI drawable bound to this ctx */
+   __DRIdrawablePrivate        *readable;      /* DRI read-drawable bound to this ctx 
*/
 
    drmContext hwContext;
    drmLock *hwLock;
Index: lib/GL/mesa/src/drv/radeon/radeon_screen.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/radeon/radeon_screen.c,v
retrieving revision 1.20
diff -u -d -r1.20 radeon_screen.c
--- lib/GL/mesa/src/drv/radeon/radeon_screen.c  21 May 2003 17:32:09 -0000      1.20
+++ lib/GL/mesa/src/drv/radeon/radeon_screen.c  3 Jul 2003 15:53:14 -0000
@@ -371,10 +371,17 @@
          glXGetProcAddress( "__glXEnableExtension" );
 
       if ( glx_enable_extension != NULL ) {
-        glx_enable_extension( "GLX_SGI_swap_control", GL_FALSE );
-        glx_enable_extension( "GLX_SGI_video_sync", GL_FALSE );
-        glx_enable_extension( "GLX_MESA_swap_control", GL_FALSE );
-        glx_enable_extension( "GLX_MESA_swap_frame_usage", GL_FALSE );
+        /* Technically speaking, SGI_make_current_read wasn't added to libGL
+         * until version 20030606.  Enabling it here (regardless of the
+         * libGL API version) is safe.
+         */
+
+        (*glx_enable_extension)( "GLX_SGI_make_current_read", GL_FALSE );
+
+        (*glx_enable_extension)( "GLX_SGI_swap_control", GL_FALSE );
+        (*glx_enable_extension)( "GLX_SGI_video_sync", GL_FALSE );
+        (*glx_enable_extension)( "GLX_MESA_swap_control", GL_FALSE );
+        (*glx_enable_extension)( "GLX_MESA_swap_frame_usage", GL_FALSE );
       }
    }
 }
Index: lib/GL/mesa/src/drv/radeon/radeon_span.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/radeon/radeon_span.c,v
retrieving revision 1.17
diff -u -d -r1.17 radeon_span.c
--- lib/GL/mesa/src/drv/radeon/radeon_span.c    30 Apr 2003 01:50:52 -0000      1.17
+++ lib/GL/mesa/src/drv/radeon/radeon_span.c    3 Jul 2003 15:53:14 -0000
@@ -52,6 +52,7 @@
    radeonScreenPtr radeonScreen = rmesa->radeonScreen;                 \
    __DRIscreenPrivate *sPriv = rmesa->dri.screen;                      \
    __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;                  \
+   __DRIdrawablePrivate *rPriv = rmesa->dri.readable;                  \
    GLuint pitch = radeonScreen->frontPitch * radeonScreen->cpp;                \
    GLuint height = dPriv->h;                                           \
    char *buf = (char *)(sPriv->pFB +                                   \
@@ -60,8 +61,8 @@
                        (dPriv->y * pitch));                            \
    char *read_buf = (char *)(sPriv->pFB +                              \
                             rmesa->state.pixel.readOffset +            \
-                            (dPriv->x * radeonScreen->cpp) +           \
-                            (dPriv->y * pitch));                       \
+                            (rPriv->x * radeonScreen->cpp) +           \
+                            (rPriv->y * pitch));                       \
    GLuint p;                                                           \
    (void) read_buf; (void) buf; (void) p
 
@@ -70,11 +71,14 @@
    radeonScreenPtr radeonScreen = rmesa->radeonScreen;                 \
    __DRIscreenPrivate *sPriv = rmesa->dri.screen;                      \
    __DRIdrawablePrivate *dPriv = rmesa->dri.drawable;                  \
+   __DRIdrawablePrivate *rPriv = rmesa->dri.readable;                  \
    GLuint height = dPriv->h;                                           \
    GLuint xo = dPriv->x;                                               \
    GLuint yo = dPriv->y;                                               \
+   GLuint read_xo = rPriv->x;                                          \
+   GLuint read_yo = rPriv->y;                                          \
    char *buf = (char *)(sPriv->pFB + radeonScreen->depthOffset);       \
-   (void) buf
+   (void) buf; (void) read_xo; (void) read_yo; (void) xo; (void) yo
 
 #define LOCAL_STENCIL_VARS     LOCAL_DEPTH_VARS
 
@@ -238,7 +242,7 @@
    *(GLushort *)(buf + radeon_mba_z16( rmesa, _x + xo, _y + yo )) = d;
 
 #define READ_DEPTH( d, _x, _y )                                                \
-   d = *(GLushort *)(buf + radeon_mba_z16( rmesa, _x + xo, _y + yo ));
+   d = *(GLushort *)(buf + radeon_mba_z16( rmesa, _x + read_xo, _y + read_yo ));
 
 #define TAG(x) radeon##x##_16
 #include "depthtmp.h"
@@ -255,8 +259,8 @@
 } while (0)
 
 #define READ_DEPTH( d, _x, _y )                                                \
-   d = *(GLuint *)(buf + radeon_mba_z32( rmesa, _x + xo,               \
-                                        _y + yo )) & 0x00ffffff;
+   d = *(GLuint *)(buf + radeon_mba_z32( rmesa, _x + read_xo,          \
+                                        _y + read_yo )) & 0x00ffffff;
 
 #define TAG(x) radeon##x##_24_8
 #include "depthtmp.h"
Index: lib/GL/mesa/src/drv/mga/mga_xmesa.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c,v
retrieving revision 1.54
diff -u -d -r1.54 mga_xmesa.c
--- lib/GL/mesa/src/drv/mga/mga_xmesa.c 25 Jun 2003 17:13:46 -0000      1.54
+++ lib/GL/mesa/src/drv/mga/mga_xmesa.c 3 Jul 2003 15:53:13 -0000
@@ -607,6 +607,8 @@
    if (driContextPriv) {
       mgaContextPtr mmesa = (mgaContextPtr) driContextPriv->driverPrivate;
 
+      mmesa->driReadable = driReadPriv;
+
       if (mmesa->driDrawable != driDrawPriv) {
         mmesa->driDrawable = driDrawPriv;
         mmesa->dirty = ~0; 
@@ -712,6 +714,13 @@
          glXGetProcAddress( "__glXEnableExtension" );
 
       if ( glx_enable_extension != NULL ) {
+        /* Technically speaking, SGI_make_current_read wasn't added to libGL
+         * until version 20030606.  Enabling it here (regardless of the
+         * libGL API version) is safe.
+         */
+
+        (*glx_enable_extension)( "GLX_SGI_make_current_read", GL_FALSE );
+
         (*glx_enable_extension)( "GLX_SGI_swap_control", GL_FALSE );
         (*glx_enable_extension)( "GLX_SGI_video_sync", GL_FALSE );
         (*glx_enable_extension)( "GLX_MESA_swap_control", GL_FALSE );
Index: lib/GL/mesa/src/drv/mga/mgacontext.h
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/mga/mgacontext.h,v
retrieving revision 1.25
diff -u -d -r1.25 mgacontext.h
--- lib/GL/mesa/src/drv/mga/mgacontext.h        20 Jun 2003 17:50:21 -0000      1.25
+++ lib/GL/mesa/src/drv/mga/mgacontext.h        3 Jul 2003 15:53:13 -0000
@@ -297,6 +297,7 @@
    drmLock *driHwLock;
    int driFd;
    __DRIdrawablePrivate *driDrawable;
+   __DRIdrawablePrivate *driReadable;
    __DRIscreenPrivate *driScreen;
    struct mga_screen_private_s *mgaScreen;
    MGASAREAPrivPtr sarea;
Index: lib/GL/mesa/src/drv/mga/mgaspan.c
===================================================================
RCS file: /cvsroot/dri/xc/xc/lib/GL/mesa/src/drv/mga/mgaspan.c,v
retrieving revision 1.31
diff -u -d -r1.31 mgaspan.c
--- lib/GL/mesa/src/drv/mga/mgaspan.c   30 Apr 2003 01:50:42 -0000      1.31
+++ lib/GL/mesa/src/drv/mga/mgaspan.c   3 Jul 2003 15:53:13 -0000
@@ -38,14 +38,15 @@
 
 #define LOCAL_VARS                                     \
    __DRIdrawablePrivate *dPriv = mmesa->driDrawable;   \
+   __DRIdrawablePrivate *rPriv = mmesa->driReadable;   \
    mgaScreenPrivate *mgaScreen = mmesa->mgaScreen;     \
    __DRIscreenPrivate *sPriv = mmesa->driScreen;       \
    GLuint pitch = mgaScreen->frontPitch;               \
    GLuint height = dPriv->h;                           \
    char *read_buf = (char *)(sPriv->pFB +              \
                        mmesa->readOffset +             \
-                       dPriv->x * mgaScreen->cpp +     \
-                       dPriv->y * pitch);              \
+                       rPriv->x * mgaScreen->cpp +     \
+                       rPriv->y * pitch);              \
    char *buf = (char *)(sPriv->pFB +                   \
                        mmesa->drawOffset +             \
                        dPriv->x * mgaScreen->cpp +     \
@@ -57,6 +58,7 @@
 
 #define LOCAL_DEPTH_VARS                                               \
    __DRIdrawablePrivate *dPriv = mmesa->driDrawable;                   \
+   __DRIdrawablePrivate *rPriv = mmesa->driReadable;                   \
    mgaScreenPrivate *mgaScreen = mmesa->mgaScreen;                     \
    __DRIscreenPrivate *sPriv = mmesa->driScreen;                       \
    GLuint pitch = mgaScreen->frontPitch;                               \
@@ -64,7 +66,12 @@
    char *buf = (char *)(sPriv->pFB +                                   \
                        mgaScreen->depthOffset +                        \
                        dPriv->x * mgaScreen->cpp +                     \
-                       dPriv->y * pitch)
+                       dPriv->y * pitch);                              \
+   char *read_buf = (char *)(sPriv->pFB +                              \
+                       mgaScreen->depthOffset +                        \
+                       rPriv->x * mgaScreen->cpp +                     \
+                       rPriv->y * pitch);                              \
+   (void) read_buf; (void) buf
 
 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS 
 
@@ -181,7 +188,7 @@
    *(GLushort *)(buf + _x*2 + _y*pitch) = d;
 
 #define READ_DEPTH( d, _x, _y )                \
-   d = *(GLushort *)(buf + _x*2 + _y*pitch);
+   d = *(GLushort *)(read_buf + _x*2 + _y*pitch);
 
 #define TAG(x) mga##x##_16
 #include "depthtmp.h"
@@ -195,7 +202,7 @@
    *(GLuint *)(buf + _x*4 + _y*pitch) = d;
 
 #define READ_DEPTH( d, _x, _y )                \
-   d = *(GLuint *)(buf + _x*4 + _y*pitch);
+   d = *(GLuint *)(read_buf + _x*4 + _y*pitch);
 
 #define TAG(x) mga##x##_32
 #include "depthtmp.h"
@@ -212,7 +219,7 @@
 }
 
 #define READ_DEPTH( d, _x, _y )        {                               \
-   d = (*(GLuint *)(buf + _x*4 + _y*pitch) & ~0xff) >> 8;      \
+   d = (*(GLuint *)(read_buf + _x*4 + _y*pitch) & ~0xff) >> 8; \
 }
 
 #define TAG(x) mga##x##_24_8
@@ -226,7 +233,7 @@
 }
 
 #define READ_STENCIL( d, _x, _y )              \
-   d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
+   d = *(GLuint *)(read_buf + _x*4 + _y*pitch) & 0xff;
 
 #define TAG(x) mga##x##_24_8
 #include "stenciltmp.h"

Reply via email to