[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

mesa: Changes to 'upstream-experimental'



Rebased ref, commits from common ancestor:
commit 2fe39b46e73aea37152777fe11d489e0b1bc3f92
Author: Vadim Girlin <vadimgirlin@gmail.com>
Date:   Fri Jun 17 23:02:01 2011 +0400

    r600g: fix LIT to handle src==dst properly
    
    Current LIT implementation uses dst components for storing temp
    results, possibly overwriting still needed values (depends on the
    swizzles).
    This patch uses temp reg for one of such cases (found in etqw) and
    fixes "LIT R.z, R.xyzz".
    
    Tested on evergreen. Fixes some etqw-demo rendering glitches when
    "Lighting" is set to "High" in the settings.
    
    Signed-off-by: Vadim Girlin <vadimgirlin@gmail.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index 0995dd5..0268108 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -1366,7 +1366,9 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
 			memset(&alu, 0, sizeof(struct r600_bc_alu));
 			alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED);
 			r600_bc_src(&alu.src[0], &ctx->src[0], 1);
-			tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst);
+			alu.dst.sel = ctx->temp_reg;
+			alu.dst.chan = 2;
+			alu.dst.write = 1;
 			alu.last = 1;
 			r = r600_bc_add_alu(ctx->bc, &alu);
 			if (r)

commit 8ab1c5328b12e8b075f62599a84672024aaf2982
Author: Vadim Girlin <vadimgirlin@gmail.com>
Date:   Fri Jun 17 23:02:00 2011 +0400

    r600g: fix RSQ to use abs value of operand on evergreen
    
    fixes https://bugs.freedesktop.org/show_bug.cgi?id=36917
    
    Signed-off-by: Vadim Girlin <vadimgirlin@gmail.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index b8a86b0..0995dd5 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -3266,7 +3266,7 @@ static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction[] = {
 	{TGSI_OPCODE_MOV,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2},
 	{TGSI_OPCODE_LIT,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lit},
 	{TGSI_OPCODE_RCP,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE, tgsi_trans_srcx_replicate},
-	{TGSI_OPCODE_RSQ,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE, tgsi_trans_srcx_replicate},
+	{TGSI_OPCODE_RSQ,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE, tgsi_rsq},
 	{TGSI_OPCODE_EXP,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_exp},
 	{TGSI_OPCODE_LOG,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_log},
 	{TGSI_OPCODE_MUL,	0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL, tgsi_op2},

commit a916d4279a2c8daac832f77b84aff66f33b590a3
Author: Vadim Girlin <vadimgirlin@gmail.com>
Date:   Fri Jun 17 23:01:59 2011 +0400

    r600g: fix source box in r600_resource_copy_region
    
    Source box needs to be adjusted for blitting from compressed formats.
    
    fixes https://bugs.freedesktop.org/show_bug.cgi?id=35434
    
    Signed-off-by: Vadim Girlin <vadimgirlin@gmail.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>

diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
index 043c875..e858ea2 100644
--- a/src/gallium/drivers/r600/r600_blit.c
+++ b/src/gallium/drivers/r600/r600_blit.c
@@ -294,6 +294,7 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
 {
 	struct r600_resource_texture *rsrc = (struct r600_resource_texture*)src;
 	struct texture_orig_info orig_info[2];
+	struct pipe_box sbox, *psbox;
 	boolean restore_orig[2];
 
 	/* Fallback for buffers. */
@@ -311,7 +312,15 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
 	if (util_format_is_compressed(src->format)) {
 		r600_compressed_to_blittable(src, src_level, &orig_info[0]);
 		restore_orig[0] = TRUE;
-	}
+		sbox.x = util_format_get_nblocksx(orig_info[0].format, src_box->x);
+		sbox.y = util_format_get_nblocksy(orig_info[0].format, src_box->y);
+		sbox.z = src_box->z;
+		sbox.width = util_format_get_nblocksx(orig_info[0].format, src_box->width);
+		sbox.height = util_format_get_nblocksy(orig_info[0].format, src_box->height);
+		sbox.depth = src_box->depth;
+		psbox=&sbox;
+	} else
+		psbox=src_box;
 
 	if (util_format_is_compressed(dst->format)) {
 		r600_compressed_to_blittable(dst, dst_level, &orig_info[1]);
@@ -322,7 +331,7 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
 	}
 
 	r600_hw_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
-			    src, src_level, src_box);
+			    src, src_level, psbox);
 
 	if (restore_orig[0])
 		r600_reset_blittable_to_compressed(src, src_level, &orig_info[0]);

commit 753660780a84187043d0dc4b0e0f449786862182
Author: Brian Paul <brianp@vmware.com>
Date:   Fri Jun 17 13:43:06 2011 -0600

    mesa: allow depth texture arrays
    
    The GL_EXT_texture_array spec allows this (Section 3.8.1).
    Fixes failing piglit fbo-depth-array test.
    
    NOTE: This is a candidate for the 7.10 branch.

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 0827cb8..40398a8 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1685,11 +1685,15 @@ texture_error_check( struct gl_context *ctx,
 
    /* additional checks for depth textures */
    if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT) {
-      /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
+      /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
       if (target != GL_TEXTURE_1D &&
           target != GL_PROXY_TEXTURE_1D &&
           target != GL_TEXTURE_2D &&
           target != GL_PROXY_TEXTURE_2D &&
+          target != GL_TEXTURE_1D_ARRAY &&
+          target != GL_PROXY_TEXTURE_1D_ARRAY &&
+          target != GL_TEXTURE_2D_ARRAY &&
+          target != GL_PROXY_TEXTURE_2D_ARRAY &&
           target != GL_TEXTURE_RECTANGLE_ARB &&
           target != GL_PROXY_TEXTURE_RECTANGLE_ARB) {
          if (!isProxy)

commit da5c852d636dfeffeb792c78b882c80c91ab6a89
Author: Brian Paul <brianp@vmware.com>
Date:   Fri Jun 17 13:28:38 2011 -0600

    st/mesa: remove unneeded test for GL_TRUE

diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 99f486b..45e4766 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1203,7 +1203,7 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
     * that in advance.  Specify potential render target flags now.
     */
    bindings = PIPE_BIND_SAMPLER_VIEW;
-   if (renderable == GL_TRUE) {
+   if (renderable) {
       if (_mesa_is_depth_or_stencil_format(internalFormat))
 	 bindings |= PIPE_BIND_DEPTH_STENCIL;
       else

commit 15750d89b9d3592032814faf7dd885c9dd6d686b
Author: Brian Paul <brianp@vmware.com>
Date:   Fri Jun 17 13:25:31 2011 -0600

    st/mesa: remove redundant _mesa_is_depth_format() call
    
    The _mesa_is_depth_or_stencil_format() call covers all depth
    format cases too.

diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index d11308d..99f486b 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1204,8 +1204,7 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
     */
    bindings = PIPE_BIND_SAMPLER_VIEW;
    if (renderable == GL_TRUE) {
-      if (_mesa_is_depth_format(internalFormat) ||
-	  _mesa_is_depth_or_stencil_format(internalFormat))
+      if (_mesa_is_depth_or_stencil_format(internalFormat))
 	 bindings |= PIPE_BIND_DEPTH_STENCIL;
       else
 	 bindings |= PIPE_BIND_RENDER_TARGET;

commit 3ea6fdfdf1a6aed5c924cfe52aa0d543c6d58aa3
Author: Brian Paul <brianp@vmware.com>
Date:   Fri Jun 17 13:23:16 2011 -0600

    st/mesa: remove trailing whitespace in st_format.c

diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index bd17448..d11308d 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1108,7 +1108,7 @@ static struct format_mapping format_map[] = {
  * Return first supported format from the given list.
  */
 static enum pipe_format
-find_supported_format(struct pipe_screen *screen, 
+find_supported_format(struct pipe_screen *screen,
                       const enum pipe_format formats[],
                       enum pipe_texture_target target,
                       unsigned sample_count,
@@ -1207,7 +1207,7 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
       if (_mesa_is_depth_format(internalFormat) ||
 	  _mesa_is_depth_or_stencil_format(internalFormat))
 	 bindings |= PIPE_BIND_DEPTH_STENCIL;
-      else 
+      else
 	 bindings |= PIPE_BIND_RENDER_TARGET;
    }
 

commit befaab8fa12eb4f628e21ffa75e523ac5eb7fbc2
Author: Brian Paul <brianp@vmware.com>
Date:   Fri Jun 17 13:22:43 2011 -0600

    st/mesa: move comment for ChooseTextureFormat() to right place

diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 3583571..bd17448 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1188,9 +1188,6 @@ st_choose_renderbuffer_format(struct pipe_screen *screen,
 }
 
 
-/**
- * Called via ctx->Driver.chooseTextureFormat().
- */
 gl_format
 st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
 				  GLenum format, GLenum type, GLboolean renderable)
@@ -1231,6 +1228,10 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
    return st_pipe_format_to_mesa_format(pFormat);
 }
 
+
+/**
+ * Called via ctx->Driver.ChooseTextureFormat().
+ */
 gl_format
 st_ChooseTextureFormat(struct gl_context *ctx, GLint internalFormat,
                        GLenum format, GLenum type)

commit cb5a5f055b6a9f05aed927d28a242bde81dd5bfc
Author: Jeremy Huddleston <jeremyhu@apple.com>
Date:   Wed Jun 15 00:22:00 2011 -0700

    apple: Use apple_cgl_get_dl_handle() rather than opening a new handle
    
    Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>

diff --git a/src/glx/apple/apple_glapi.c b/src/glx/apple/apple_glapi.c
index 0c89f46..34f726e 100644
--- a/src/glx/apple/apple_glapi.c
+++ b/src/glx/apple/apple_glapi.c
@@ -44,38 +44,18 @@
 
 #include "apple_glx.h"
 #include "apple_xgl_api.h"
-
-#ifndef OPENGL_FRAMEWORK_PATH
-#define OPENGL_FRAMEWORK_PATH "/System/Library/Frameworks/OpenGL.framework/OpenGL"
-#endif
+#include "apple_cgl.h"
 
 struct _glapi_table * __ogl_framework_api = NULL;
 struct _glapi_table * __applegl_api = NULL;
 
 void apple_glapi_set_dispatch(void) {
-    static void *handle;
-    const char *opengl_framework_path;
-
     if(__applegl_api)  {
         _glapi_set_dispatch(__applegl_api);
         return;
     }
 
-    opengl_framework_path = getenv("OPENGL_FRAMEWORK_PATH");
-    if (!opengl_framework_path) {
-        opengl_framework_path = OPENGL_FRAMEWORK_PATH;
-    }
-
-    (void) dlerror();            /*drain dlerror */
-    handle = dlopen(opengl_framework_path, RTLD_LOCAL);
-
-    if (!handle) {
-        fprintf(stderr, "error: unable to dlopen %s : %s\n",
-                opengl_framework_path, dlerror());
-        abort();
-    }
-
-    __ogl_framework_api = _glapi_create_table_from_handle(handle, "gl");
+    __ogl_framework_api = _glapi_create_table_from_handle(apple_cgl_get_dl_handle(), "gl");
     assert(__ogl_framework_api);
 
     __applegl_api = malloc(sizeof(struct _glapi_table));

commit 10562fbc5c630b7f1a97344bc3d6b2649c7393a5
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 20:11:50 2011 +0100

    scons: List all targets.

diff --git a/SConstruct b/SConstruct
index 6b725c4..029daa1 100644
--- a/SConstruct
+++ b/SConstruct
@@ -143,3 +143,18 @@ SConscript(
 	duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
 )
 
+
+########################################################################
+# List all aliases
+
+try:
+    from SCons.Node.Alias import default_ans
+except ImportError:
+    pass
+else:
+    aliases = default_ans.keys()
+    aliases.sort()
+    env.Help('\n')
+    env.Help('Recognized targets:\n')
+    for alias in aliases:
+        env.Help('    %s\n' % alias)

commit ef4bf40db03ff1df2bae2db8f4a65421bf4a7c06
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 20:11:35 2011 +0100

    scons: Remember the options set on the command line.
    
    Save them in config.py

diff --git a/SConstruct b/SConstruct
index 104cc38..6b725c4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -40,6 +40,8 @@ env = Environment(
 	ENV = os.environ,
 )
 
+opts.Save('config.py', env)
+
 # Backwards compatability with old target configuration variable
 try:
     targets = ARGUMENTS['targets']

commit c9be435c79e2bbc883701c5533ae0490780495be
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 20:07:12 2011 +0100

    scons: Don't list MSVS_VERSION option outside windows platforms.

diff --git a/common.py b/common.py
index f218e6f..8f13186 100644
--- a/common.py
+++ b/common.py
@@ -91,4 +91,5 @@ def AddOptions(opts):
 	opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
 	opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
 	opts.Add(BoolOption('quiet', 'DEPRECATED: quiet command lines', 'yes'))
-	opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
+	if host_platform == 'windows':
+		opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))

commit d6a0fe19e8da0cb12d73977e4e3ece596a26320f
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 19:23:06 2011 +0100

    scons: Correct glapi USE_xxx_ASM flags.

diff --git a/src/mapi/glapi/SConscript b/src/mapi/glapi/SConscript
index 276b216..a776474 100644
--- a/src/mapi/glapi/SConscript
+++ b/src/mapi/glapi/SConscript
@@ -52,30 +52,23 @@ if env['platform'] != 'winddk':
     if env['gcc'] and env['platform'] != 'windows':
         if env['machine'] == 'x86':
             env.Append(CPPDEFINES = [
-                'USE_X86_ASM', 
-                'USE_MMX_ASM',
-                'USE_3DNOW_ASM',
-                'USE_SSE_ASM',
+                'USE_X86_ASM',
             ])
             glapi_sources += [
                 'glapi_x86.S',
             ]
         elif env['machine'] == 'x86_64':
             env.Append(CPPDEFINES = [
-                'USE_X86_64_ASM', 
+                'USE_X86_64_ASM',
             ])
             glapi_sources += [
                 'glapi_x86-64.S'
             ]
-        elif env['machine'] == 'ppc':
+        elif env['machine'] == 'sparc':
             env.Append(CPPDEFINES = [
-                'USE_PPC_ASM', 
-                'USE_VMX_ASM', 
+                'USE_SPARC_ASM',
             ])
             glapi_sources += [
-            ]
-        elif env['machine'] == 'sparc':
-            glapi_sources += [
                 'glapi_sparc.S'
             ]
         else:

commit c7bd0fa4851187c3102948f5f4d70c26d1b55a5e
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 18:42:39 2011 +0100

    scons: Accept verbose=yes instead of quiet=no.
    
    'verbose' is affirmative, and much more common name for this sort of option.

diff --git a/common.py b/common.py
index 052929e..f218e6f 100644
--- a/common.py
+++ b/common.py
@@ -79,7 +79,7 @@ def AddOptions(opts):
 		from SCons.Options.EnumOption import EnumOption
 	opts.Add(EnumOption('build', 'build type', 'debug',
 	                  allowed_values=('debug', 'checked', 'profile', 'release')))
-	opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
+	opts.Add(BoolOption('verbose', 'verbose output', 'no'))
 	opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
 											 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
 	opts.Add(EnumOption('platform', 'target platform', host_platform,
@@ -90,4 +90,5 @@ def AddOptions(opts):
 	opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
 	opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
 	opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
+	opts.Add(BoolOption('quiet', 'DEPRECATED: quiet command lines', 'yes'))
 	opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
diff --git a/scons/custom.py b/scons/custom.py
index a2c690f..029f99b 100644
--- a/scons/custom.py
+++ b/scons/custom.py
@@ -157,7 +157,8 @@ def createCodeGenerateMethod(env):
 def generate(env):
     """Common environment generation code"""
 
-    if env.get('quiet', True):
+    verbose = env.get('verbose', False) or not env.get('quiet', True)
+    if not verbose:
         quietCommandLines(env)
 
     # Custom builders and methods

commit bf69ce37f0dcbb479078ee676d5100ac63e20750
Author: Stéphane Marchesin <marcheu@chromium.org>
Date:   Wed Jun 15 15:09:12 2011 -0700

    glx: implement drawable refcounting.
    
    The current dri context unbind logic will leak drawables until the process
    dies (they will then get released by the GEM code). There are two ways to fix
    this: either always call driReleaseDrawables every time we unbind a context
    (but that costs us round trips to the X server at getbuffers() time) or
    implement proper drawable refcounting. This patch implements the latter.
    
    Signed-off-by: Antoine Labour <piman@chromium.org>
    Signed-off-by: Stéphane Marchesin <marcheu@chromium.org>
    Reviewed-by: Adam Jackson <ajax@redhat.com>

diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 506754c..e7c18ff 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -143,6 +143,8 @@ dri2_bind_context(struct glx_context *context, struct glx_context *old,
    pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw);
    pread = (struct dri2_drawable *) driFetchDrawable(context, read);
 
+   driReleaseDrawables(&pcp->base);
+
    if (pdraw == NULL || pread == NULL)
       return GLXBadDrawable;
 
@@ -170,9 +172,6 @@ dri2_unbind_context(struct glx_context *context, struct glx_context *new)
    struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
 
    (*psc->core->unbindContext) (pcp->driContext);
-
-   if (context == new)
-      driReleaseDrawables(&pcp->base);
 }
 
 static struct glx_context *
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index 06a73e4..bac0c9e 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -369,8 +369,10 @@ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
    if (priv->drawHash == NULL)
       return NULL;
 
-   if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0)
+   if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) {
+      pdraw->refcount ++;
       return pdraw;
+   }
 
    pdraw = psc->driScreen->createDrawable(psc, glxDrawable,
                                           glxDrawable, gc->config);
@@ -378,6 +380,7 @@ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
       (*pdraw->destroyDrawable) (pdraw);
       return NULL;
    }
+   pdraw->refcount = 1;
 
    return pdraw;
 }
@@ -394,19 +397,28 @@ driReleaseDrawables(struct glx_context *gc)
    if (__glxHashLookup(priv->drawHash,
 		       gc->currentDrawable, (void *) &pdraw) == 0) {
       if (pdraw->drawable == pdraw->xDrawable) {
-	 (*pdraw->destroyDrawable)(pdraw);
-	 __glxHashDelete(priv->drawHash, gc->currentDrawable);
+	 pdraw->refcount --;
+	 if (pdraw->refcount == 0) {
+	    (*pdraw->destroyDrawable)(pdraw);
+	    __glxHashDelete(priv->drawHash, gc->currentDrawable);
+	 }
       }
    }
 
-   if (gc->currentDrawable != gc->currentReadable &&
-       __glxHashLookup(priv->drawHash,
+   if (__glxHashLookup(priv->drawHash,
 		       gc->currentReadable, (void *) &pdraw) == 0) {
       if (pdraw->drawable == pdraw->xDrawable) {
-	 (*pdraw->destroyDrawable)(pdraw);
-	 __glxHashDelete(priv->drawHash, gc->currentReadable);
+	 pdraw->refcount --;
+	 if (pdraw->refcount == 0) {
+	    (*pdraw->destroyDrawable)(pdraw);
+	    __glxHashDelete(priv->drawHash, gc->currentReadable);
+	 }
       }
    }
+
+   gc->currentDrawable = None;
+   gc->currentReadable = None;
+
 }
 
 #endif /* GLX_DIRECT_RENDERING */
diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c
index ff027dc..d59784c 100644
--- a/src/glx/dri_glx.c
+++ b/src/glx/dri_glx.c
@@ -503,6 +503,8 @@ dri_destroy_context(struct glx_context * context)
    struct dri_context *pcp = (struct dri_context *) context;
    struct dri_screen *psc = (struct dri_screen *) context->psc;
 
+   driReleaseDrawables(&pcp->base);
+
    if (context->xid)
       glx_send_destroy_context(psc->base.dpy, context->xid);
 
@@ -526,6 +528,8 @@ dri_bind_context(struct glx_context *context, struct glx_context *old,
    pdraw = (struct dri_drawable *) driFetchDrawable(context, draw);
    pread = (struct dri_drawable *) driFetchDrawable(context, read);
 
+   driReleaseDrawables(&pcp->base);
+
    if (pdraw == NULL || pread == NULL)
       return GLXBadDrawable;
 
@@ -543,8 +547,6 @@ dri_unbind_context(struct glx_context *context, struct glx_context *new)
    struct dri_screen *psc = (struct dri_screen *) pcp->base.psc;
 
    (*psc->core->unbindContext) (pcp->driContext);
-
-   driReleaseDrawables(&pcp->base);
 }
 
 static const struct glx_context_vtable dri_context_vtable = {
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 2eaa3c5..0075695 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -242,6 +242,8 @@ drisw_destroy_context(struct glx_context *context)
    struct drisw_context *pcp = (struct drisw_context *) context;
    struct drisw_screen *psc = (struct drisw_screen *) context->psc;
 
+   driReleaseDrawables(&pcp->base);
+
    if (context->xid)
       glx_send_destroy_context(psc->base.dpy, context->xid);
 
@@ -264,6 +266,8 @@ drisw_bind_context(struct glx_context *context, struct glx_context *old,
    pdraw = (struct drisw_drawable *) driFetchDrawable(context, draw);
    pread = (struct drisw_drawable *) driFetchDrawable(context, read);
 
+   driReleaseDrawables(&pcp->base);
+
    if (pdraw == NULL || pread == NULL)
       return GLXBadDrawable;
 
@@ -281,8 +285,6 @@ drisw_unbind_context(struct glx_context *context, struct glx_context *new)
    struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc;
 
    (*psc->core->unbindContext) (pcp->driContext);
-
-   driReleaseDrawables(&pcp->base);
 }
 
 static const struct glx_context_vtable drisw_context_vtable = {
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index fa2e2d3..88a6edd 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -138,6 +138,7 @@ struct __GLXDRIdrawableRec
    GLenum textureTarget;
    GLenum textureFormat;        /* EXT_texture_from_pixmap support */
    unsigned long eventMask;
+   int refcount;
 };
 
 /*
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index 064fd71..9eb7d5a 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -255,8 +255,6 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
       if (--oldGC->thread_refcount == 0) {
 	 oldGC->vtable->unbind(oldGC, gc);
 	 oldGC->currentDpy = 0;
-	 oldGC->currentDrawable = None;
-	 oldGC->currentReadable = None;
 
 	 if (oldGC->xid == None && oldGC != gc) {
 	    /* We are switching away from a context that was
@@ -268,13 +266,15 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
    }
 
    if (gc) {
-      if (gc->thread_refcount++ == 0) {
-	 gc->currentDpy = dpy;
-	 gc->currentDrawable = draw;
-	 gc->currentReadable = read;
-      }
+      if (gc->thread_refcount == 0)
+         gc->currentDpy = dpy;
       __glXSetCurrentContext(gc);
       ret = gc->vtable->bind(gc, oldGC, draw, read);
+      if (gc->thread_refcount == 0) {
+         gc->currentDrawable = draw;
+         gc->currentReadable = read;
+      }
+      gc->thread_refcount++;
    } else {
       __glXSetCurrentContextNull();
    }

commit 8173471fc25f4c768cab54fa840fd4c53d1c3c0f
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 16:28:27 2011 +0100

    scons: Move all env setup to scons/gallium.py

diff --git a/SConstruct b/SConstruct
index dc5fd77..104cc38 100644
--- a/SConstruct
+++ b/SConstruct
@@ -80,27 +80,6 @@ env.Append(CPPPATH = [
 if env['msvc']:
     env.Append(CPPPATH = ['#include/c99'])
 
-# Posix
-if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
-	env.Append(CPPDEFINES = [
-		'_POSIX_SOURCE',
-		('_POSIX_C_SOURCE', '199309L'), 
-		'_SVID_SOURCE',
-		'_BSD_SOURCE', 
-		'_GNU_SOURCE',
-		'PTHREADS',
-		'HAVE_POSIX_MEMALIGN',
-	])
-	if env['gcc']:
-		env.Append(CFLAGS = ['-fvisibility=hidden'])
-	if env['platform'] == 'darwin':
-		env.Append(CPPDEFINES = ['_DARWIN_C_SOURCE'])
-	env.Append(LIBS = [
-		'm',
-		'pthread',
-		'dl',
-	])
-
 # for debugging
 #print env.Dump()
 
diff --git a/scons/gallium.py b/scons/gallium.py
index 57acfe0..9d08efd 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -279,6 +279,18 @@ def generate(env):
         cppdefines += ['NDEBUG']
     if env['build'] == 'profile':
         cppdefines += ['PROFILE']
+    if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
+        cppdefines += [
+            '_POSIX_SOURCE',
+            ('_POSIX_C_SOURCE', '199309L'),
+            '_SVID_SOURCE',
+            '_BSD_SOURCE',
+            '_GNU_SOURCE',
+            'PTHREADS',
+            'HAVE_POSIX_MEMALIGN',
+        ]
+    if env['platform'] == 'darwin':
+        cppdefines += ['_DARWIN_C_SOURCE']
     if platform == 'windows':
         cppdefines += [
             'WIN32',
@@ -405,6 +417,8 @@ def generate(env):
             ccflags += ['-m64']
             if platform == 'darwin':
                 ccflags += ['-fno-common']
+        if env['platform'] != 'windows':
+            ccflags += ['-fvisibility=hidden']
         # See also:
         # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
         ccflags += [
@@ -597,7 +611,10 @@ def generate(env):
         env['LINK'] = env['CXX']
 
     # Default libs
-    env.Append(LIBS = [])
+    libs = []
+    if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
+        libs += ['m', 'pthread', 'dl']
+    env.Append(LIBS = libs)
 
     # Load tools
     env.Tool('lex')

commit 41750107496858a047afa8d81d20fe903f285a78
Author: José Fonseca <jfonseca@vmware.com>
Date:   Fri Jun 17 14:48:28 2011 +0100

    scons: make embedding orthogonal to the platform
    
    To enable embedding in platforms other than linux.

diff --git a/SConstruct b/SConstruct
index 8607d2c..dc5fd77 100644
--- a/SConstruct
+++ b/SConstruct
@@ -80,23 +80,6 @@ env.Append(CPPPATH = [
 if env['msvc']:
     env.Append(CPPPATH = ['#include/c99'])
 
-# Embedded
-if env['platform'] == 'embedded':
-	env.Append(CPPDEFINES = [
-		'_POSIX_SOURCE',
-		('_POSIX_C_SOURCE', '199309L'), 
-		'_SVID_SOURCE',
-		'_BSD_SOURCE', 
-		'_GNU_SOURCE',
-		
-		'PTHREADS',
-	])
-	env.Append(LIBS = [
-		'm',
-		'pthread',
-		'dl',
-	])
-
 # Posix
 if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
 	env.Append(CPPDEFINES = [
@@ -130,7 +113,7 @@ if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
 #
 
 # Create host environent
-if env['crosscompile'] and env['platform'] != 'embedded':
+if env['crosscompile'] and not env['embedded']:
     host_env = Environment(
         options = opts,
         # no tool used
diff --git a/common.py b/common.py
index 0a3dcdc..052929e 100644
--- a/common.py
+++ b/common.py
@@ -83,7 +83,8 @@ def AddOptions(opts):
 	opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
 											 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
 	opts.Add(EnumOption('platform', 'target platform', host_platform,
-											 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos', 'freebsd8')))
+											 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'cygwin', 'sunos', 'freebsd8')))
+	opts.Add(BoolOption('embedded', 'embedded build', 'no'))
 	opts.Add('toolchain', 'compiler toolchain', default_toolchain)
 	opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
 	opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
diff --git a/scons/gallium.py b/scons/gallium.py
index a94bf73..57acfe0 100755
--- a/scons/gallium.py
+++ b/scons/gallium.py
@@ -247,6 +247,8 @@ def generate(env):
     # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
     build_topdir = 'build'
     build_subdir = env['platform']
+    if env['embedded']:
+        build_subdir =  'embedded-' + build_subdir
     if env['machine'] != 'generic':
         build_subdir += '-' + env['machine']
     if env['build'] != 'release':
@@ -349,8 +351,8 @@ def generate(env):
     if platform == 'wince':
         cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
         cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
-    if platform == 'embedded':
-        cppdefines += ['PIPE_OS_EMBEDDED']
+    if env['embedded']:
+        cppdefines += ['PIPE_SUBSYSTEM_EMBEDDED']
     env.Append(CPPDEFINES = cppdefines)
 
     # C compiler options
diff --git a/src/gallium/SConscript b/src/gallium/SConscript
index 428bc31..3072ee9 100644
--- a/src/gallium/SConscript
+++ b/src/gallium/SConscript
@@ -53,7 +53,7 @@ if env['drm']:
 # Needed by some state trackers
 SConscript('winsys/sw/null/SConscript')
 
-if env['platform'] != 'embedded':
+if not env['embedded']:
     SConscript('state_trackers/vega/SConscript')
     SConscript('state_trackers/egl/SConscript')
 
@@ -66,8 +66,8 @@ if env['platform'] != 'embedded':
     if env['dri'] and env['xorg']:
         SConscript('state_trackers/xorg/SConscript')
 
-if env['platform'] == 'windows':
-    SConscript('state_trackers/wgl/SConscript')
+    if env['platform'] == 'windows':
+        SConscript('state_trackers/wgl/SConscript')
 
 #
 # Winsys
@@ -83,55 +83,55 @@ SConscript([
     'targets/graw-null/SConscript',
 ])
 
-if env['platform'] != 'embedded':
+if not env['embedded']:
     SConscript([
         'targets/egl-static/SConscript'
     ])
 
-if env['x11']:
-    SConscript([
-        'targets/graw-xlib/SConscript',
-        'targets/libgl-xlib/SConscript',
-    ])
+    if env['x11']:
+        SConscript([
+            'targets/graw-xlib/SConscript',
+            'targets/libgl-xlib/SConscript',
+        ])
 
-if env['platform'] == 'windows':
-    SConscript([
-        'targets/graw-gdi/SConscript',
-        'targets/libgl-gdi/SConscript',
-    ])
+    if env['platform'] == 'windows':
+        SConscript([
+            'targets/graw-gdi/SConscript',
+            'targets/libgl-gdi/SConscript',
+        ])
 
-if env['dri']:
-    SConscript([
-        'targets/SConscript.dri',
-        'targets/dri-swrast/SConscript',
-        'targets/dri-vmwgfx/SConscript',
-        #'targets/dri-nouveau/SConscript',
-    ])
-    if env['drm_intel']:
+    if env['dri']:
         SConscript([
-            'targets/dri-i915/SConscript',
-            'targets/dri-i965/SConscript',
+            'targets/SConscript.dri',
+            'targets/dri-swrast/SConscript',
+            'targets/dri-vmwgfx/SConscript',
+            #'targets/dri-nouveau/SConscript',
         ])
-    if env['drm_radeon']:
+        if env['drm_intel']:
+            SConscript([
+                'targets/dri-i915/SConscript',
+                'targets/dri-i965/SConscript',
+            ])
+        if env['drm_radeon']:
+            SConscript([
+                'targets/dri-r300/SConscript',
+                'targets/dri-r600/SConscript',
+            ])
+
+    if env['xorg'] and env['drm']:
         SConscript([
-            'targets/dri-r300/SConscript',
-            'targets/dri-r600/SConscript',
+            #'targets/xorg-i915/SConscript',
+            #'targets/xorg-i965/SConscript',
+            #'targets/xorg-nouveau/SConscript',
+            #'targets/xorg-radeon/SConscript',
+            'targets/xorg-vmwgfx/SConscript',
         ])
 
-if env['xorg'] and env['drm']:
-    SConscript([
-        #'targets/xorg-i915/SConscript',
-        #'targets/xorg-i965/SConscript',
-        #'targets/xorg-nouveau/SConscript',
-        #'targets/xorg-radeon/SConscript',
-        'targets/xorg-vmwgfx/SConscript',
-    ])
-
 
 #
 # Unit tests & tools
 #
 
-if env['platform'] != 'embedded':
+if not env['embedded']:
     SConscript('tests/unit/SConscript')
     SConscript('tests/graw/SConscript')
diff --git a/src/gallium/auxiliary/os/os_memory.h b/src/gallium/auxiliary/os/os_memory.h
index 556662d..91a84a2 100644
--- a/src/gallium/auxiliary/os/os_memory.h
+++ b/src/gallium/auxiliary/os/os_memory.h
@@ -39,7 +39,7 @@
 #include "pipe/p_compiler.h"
 
 
-#if defined(PIPE_OS_EMBEDDED)
+#if defined(PIPE_SUBSYSTEM_EMBEDDED)
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/gallium/auxiliary/os/os_misc.h b/src/gallium/auxiliary/os/os_misc.h
index d59f981..48522da 100644
--- a/src/gallium/auxiliary/os/os_misc.h
+++ b/src/gallium/auxiliary/os/os_misc.h
@@ -58,8 +58,6 @@ extern "C" {
 #  define os_break()  __debugbreak()
 #elif defined(PIPE_OS_UNIX)
 #  define os_break() kill(getpid(), SIGTRAP)
-#elif defined(PIPE_OS_EMBEDDED)
-void os_break(void);
 #else
 #  define os_break() abort()
 #endif
@@ -70,8 +68,6 @@ void os_break(void);
  */
 #if defined(DEBUG) || defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
 #  define os_abort() os_break()
-#elif defined(PIPE_OS_EMBEDDED)
-void os_abort(void);
 #else
 #  define os_abort() abort()
 #endif
diff --git a/src/gallium/auxiliary/os/os_thread.h b/src/gallium/auxiliary/os/os_thread.h
index 6b4281a..8f1245b 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -40,7 +40,7 @@
 #include "util/u_debug.h" /* for assert */
 
 
-#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_EMBEDDED) || defined(PIPE_OS_CYGWIN)
+#if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) || defined(PIPE_OS_APPLE) || defined(PIPE_OS_HAIKU) || defined(PIPE_OS_CYGWIN)
 
 #include <pthread.h> /* POSIX threads headers */
 #include <stdio.h> /* for perror() */
@@ -314,7 +314,7 @@ typedef int64_t pipe_condvar;
  * pipe_barrier
  */


Reply to: