[Mesa-dev] [Bug 43629] mesa# gmake freebsd-dri-amd64 breaks

2011-12-11 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=43629

--- Comment #3 from zap...@berentweb.com 2011-12-11 06:55:32 PST ---
Some Developments:
Git Update pulled in some changes so I ran mesa/autogen.sh to try again. I get
some better diagnosic output this time and here are the results:

1. First error was
configure: error: Package requirements (dri2proto = 2.6) were not met:
Requested 'dri2proto = 2.6' but version of DRI2Proto is 2.3
So I got the latest from here and installed.
git://anongit.freedesktop.org/xorg/proto/dri2proto  (the wiki page is therefore
out-of-date, btw)

2. Ran mesa/autogen.sh a second time. This time error is:
checking for expat.h... no
configure: error: Expat required for DRI.
textproc/expat2 is installed however. I re-installed expat, no change.

3. I noticed installed depends (glproto, libXxf86vm, xf86vidmodeproto, libXmu,
drm) do not register correct in the FreeBSD installed package DB. Running
portmaster --check-depends (which checks for and corrects broken dependencies)
lists all these ports as NOT INSTALLED. This will create a problem in with
other ports when performing system updates.

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
--- You are receiving this mail because: ---
You are the assignee for the bug.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] mesa: remove buggy assertions in unpack Z24

2011-12-11 Thread Marek Olšák
On Mon, Nov 21, 2011 at 6:52 PM, Eric Anholt e...@anholt.net wrote:
 On Sun, 20 Nov 2011 15:08:55 +0100, Marek Olšák mar...@gmail.com wrote:
 unpack_float_z_Z24_X8 fails with -O2 in:
 - fbo-blit-d24s8
 - fbo-depth-sample-compare
 - fbo-readpixels-depth-formats
 - glean/depthStencil

 With -O0, it works fine.

 I am removing all the assertions. There's not much point in having them,
 is there?

 Is -ffast-math involved at all?

Yes, -fno-fast-math makes the problem go away.


 At a guess, replacing * scale with / (float)0xff makes the
 failure happen either way?

Yes. Only using GLdouble fixes it.

It makes sense. The mantissa without the sign has 23 bits, but 24 bits
are required to exactly represent 0xff if I am not mistaken.

I have found a couple more cases where it could fail in the same way
and fixed them in the attached patch. Please review.

Marek
From 255ac5e56056bd29d36466f47e0dc82e8b145264 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= mar...@gmail.com
Date: Sun, 11 Dec 2011 16:18:36 +0100
Subject: [PATCH] mesa: fix possible precision issues in pack/unpack/fetch functions

GLfloat doesn't have enough precision to exactly represent 0xff
and 0x. (and a reciprocal of those, if I am not mistaken)

If -ffast-math is enabled, using GLfloat causes assertion failures in:
- fbo-blit-d24s8
- fbo-depth-sample-compare
- fbo-readpixels-depth-formats
- glean/depthStencil

For example:
fbo-depth-sample-compare: main/format_unpack.c:1769:
unpack_float_z_Z24_X8: Assertion `dst[i] = 1.0F' failed.
---
 src/mesa/main/format_pack.c  |   20 ++--
 src/mesa/main/format_unpack.c|8 
 src/mesa/swrast/s_texfetch_tmp.h |4 ++--
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index ba23bab..390b494 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -2058,7 +2058,7 @@ pack_float_z_Z24_S8(const GLfloat *src, void *dst)
 {
/* don't disturb the stencil values */
GLuint *d = ((GLuint *) dst);
-   const GLfloat scale = (GLfloat) 0xff;
+   const GLdouble scale = (GLdouble) 0xff;
GLuint s = *d  0xff;
GLuint z = (GLuint) (*src * scale);
assert(z = 0xff);
@@ -2070,7 +2070,7 @@ pack_float_z_S8_Z24(const GLfloat *src, void *dst)
 {
/* don't disturb the stencil values */
GLuint *d = ((GLuint *) dst);
-   const GLfloat scale = (GLfloat) 0xff;
+   const GLdouble scale = (GLdouble) 0xff;
GLuint s = *d  0xff00;
GLuint z = (GLuint) (*src * scale);
assert(z = 0xff);
@@ -2089,7 +2089,7 @@ static void
 pack_float_z_Z32(const GLfloat *src, void *dst)
 {
GLuint *d = ((GLuint *) dst);
-   const GLfloat scale = (GLfloat) 0x;
+   const GLdouble scale = (GLdouble) 0x;
*d = (GLuint) (*src * scale);
 }
 
@@ -2169,7 +2169,7 @@ static void
 pack_uint_z_Z32_FLOAT(const GLuint *src, void *dst)
 {
GLuint *d = ((GLuint *) dst);
-   const GLfloat scale = 1.0f / (GLfloat) 0x;
+   const GLdouble scale = 1.0 / (GLdouble) 0x;
*d = *src * scale;
assert(*d = 0.0f);
assert(*d = 1.0f);
@@ -2179,7 +2179,7 @@ static void
 pack_uint_z_Z32_FLOAT_X24S8(const GLuint *src, void *dst)
 {
GLfloat *d = ((GLfloat *) dst);
-   const GLfloat scale = 1.0f / (GLfloat) 0x;
+   const GLdouble scale = 1.0 / (GLdouble) 0x;
*d = *src * scale;
assert(*d = 0.0f);
assert(*d = 1.0f);
@@ -2280,7 +2280,7 @@ _mesa_pack_float_z_row(gl_format format, GLuint n,
   {
  /* don't disturb the stencil values */
  GLuint *d = ((GLuint *) dst);
- const GLfloat scale = (GLfloat) 0xff;
+ const GLdouble scale = (GLdouble) 0xff;
  GLuint i;
  for (i = 0; i  n; i++) {
 GLuint s = d[i]  0xff;
@@ -2295,7 +2295,7 @@ _mesa_pack_float_z_row(gl_format format, GLuint n,
   {
  /* don't disturb the stencil values */
  GLuint *d = ((GLuint *) dst);
- const GLfloat scale = (GLfloat) 0xff;
+ const GLdouble scale = (GLdouble) 0xff;
  GLuint i;
  for (i = 0; i  n; i++) {
 GLuint s = d[i]  0xff00;
@@ -2318,7 +2318,7 @@ _mesa_pack_float_z_row(gl_format format, GLuint n,
case MESA_FORMAT_Z32:
   {
  GLuint *d = ((GLuint *) dst);
- const GLfloat scale = (GLfloat) 0x;
+ const GLdouble scale = (GLdouble) 0x;
  GLuint i;
  for (i = 0; i  n; i++) {
 d[i] = (GLuint) (src[i] * scale);
@@ -2392,7 +2392,7 @@ _mesa_pack_uint_z_row(gl_format format, GLuint n,
case MESA_FORMAT_Z32_FLOAT:
   {
  GLuint *d = ((GLuint *) dst);
- const GLfloat scale = 1.0f / (GLfloat) 0x;
+ const GLdouble scale = 1.0 / (GLdouble) 0x;
  GLuint i;
  for (i = 0; i  n; i++) {
 d[i] = src[i] * scale;
@@ -2404,7 +2404,7 @@ 

[Mesa-dev] [PATCH] i915g: Fix wrong indices for LINE_LOOP case

2011-12-11 Thread Fatih Aşıcı
---
 src/gallium/drivers/i915/i915_prim_vbuf.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/i915/i915_prim_vbuf.c 
b/src/gallium/drivers/i915/i915_prim_vbuf.c
index 79db3b6..3f85466 100644
--- a/src/gallium/drivers/i915/i915_prim_vbuf.c
+++ b/src/gallium/drivers/i915/i915_prim_vbuf.c
@@ -400,8 +400,8 @@ draw_arrays_generate_indices(struct vbuf_render *render,
case PIPE_PRIM_LINE_LOOP:
   if (nr = 2) {
  for (i = start + 1; i  end; i++)
-OUT_BATCH((i-0) | (i+0)  16);
- OUT_BATCH((i-0) | ( start)  16);
+OUT_BATCH((i-1) | (i+0)  16);
+ OUT_BATCH((i-1) | ( start)  16);
   }
   break;
case PIPE_PRIM_QUADS:
-- 
1.7.7.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] vdpau: Handle destination rectangles correctly

2011-12-11 Thread Andy Furniss

Maarten Lankhorst wrote:

The brokenness in vlVdpVideoMixerRender was compensating for
brokenness in vlVdpPresentationQueueDisplay, so fix both at
the same time.

Signed-off-by: Maarten Lankhorstm.b.lankho...@gmail.com


Tested-by: Andy Furniss andy...@ukfsn.org

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] vl: Handle custom destination rectangles correctly

2011-12-11 Thread Andy Furniss

Maarten Lankhorst wrote:

When layers are still being added, the total width/height is not known.
As such extra care has to be taken to get output rectangle correct. This
is required to support a custom dest rectangle, which is currently not used
and buggy.

Signed-off-by: Maarten Lankhorstm.b.lankho...@gmail.com


Tested-by: Andy Furniss andy...@ukfsn.org

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/6 v3] g3dvl: Get rid of video_buffer.sampler_view_components

2011-12-11 Thread Andy Furniss

Maarten Lankhorst wrote:

No point in having it when just having sampler_view_planes is good enough.

Signed-off-by: Maarten Lankhorstm.b.lankho...@gmail.com


Tested-by: Andy Furniss andy...@ukfsn.org

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] [i915g] fix debug dump on 64 bit systems

2011-12-11 Thread Stéphane Marchesin
Applied, thanks!
Stéphane
On Mon, Dec 5, 2011 at 13:02, Michael Karcher
freedesktop-bugzi...@mkarcher.dialup.fu-berlin.de wrote:
 Signed-off-by: Michael Karcher 
 freedesktop-bugzi...@mkarcher.dialup.fu-berlin.de
 ---
  src/gallium/drivers/i915/i915_debug.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/src/gallium/drivers/i915/i915_debug.c 
 b/src/gallium/drivers/i915/i915_debug.c
 index 295c47e..b6c442d 100644
 --- a/src/gallium/drivers/i915/i915_debug.c
 +++ b/src/gallium/drivers/i915/i915_debug.c
 @@ -232,7 +232,7 @@ BITS(
                         ... )
  {
    va_list  args;
 -   unsigned himask = ~0UL  (31 - (hi));
 +   unsigned himask = 0xUL  (31 - (hi));

    PRINTF(stream, \t\t );

 --
 1.7.7.1

 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] i915g: Fix wrong indices for LINE_LOOP case

2011-12-11 Thread Stéphane Marchesin
Applied, thanks!
Stéphane
2011/12/11 Fatih Aşıcı fatih.as...@gmail.com:
 ---
  src/gallium/drivers/i915/i915_prim_vbuf.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

 diff --git a/src/gallium/drivers/i915/i915_prim_vbuf.c 
 b/src/gallium/drivers/i915/i915_prim_vbuf.c
 index 79db3b6..3f85466 100644
 --- a/src/gallium/drivers/i915/i915_prim_vbuf.c
 +++ b/src/gallium/drivers/i915/i915_prim_vbuf.c
 @@ -400,8 +400,8 @@ draw_arrays_generate_indices(struct vbuf_render *render,
    case PIPE_PRIM_LINE_LOOP:
       if (nr = 2) {
          for (i = start + 1; i  end; i++)
 -            OUT_BATCH((i-0) | (i+0)  16);
 -         OUT_BATCH((i-0) | ( start)  16);
 +            OUT_BATCH((i-1) | (i+0)  16);
 +         OUT_BATCH((i-1) | ( start)  16);
       }
       break;
    case PIPE_PRIM_QUADS:
 --
 1.7.7.1

 ___
 mesa-dev mailing list
 mesa-dev@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] mesa: remove buggy assertions in unpack Z24

2011-12-11 Thread Brian Paul
On Sun, Dec 11, 2011 at 8:46 AM, Marek Olšák mar...@gmail.com wrote:
 On Mon, Nov 21, 2011 at 6:52 PM, Eric Anholt e...@anholt.net wrote:
 On Sun, 20 Nov 2011 15:08:55 +0100, Marek Olšák mar...@gmail.com wrote:
 unpack_float_z_Z24_X8 fails with -O2 in:
 - fbo-blit-d24s8
 - fbo-depth-sample-compare
 - fbo-readpixels-depth-formats
 - glean/depthStencil

 With -O0, it works fine.

 I am removing all the assertions. There's not much point in having them,
 is there?

 Is -ffast-math involved at all?

 Yes, -fno-fast-math makes the problem go away.


 At a guess, replacing * scale with / (float)0xff makes the
 failure happen either way?

 Yes. Only using GLdouble fixes it.

 It makes sense. The mantissa without the sign has 23 bits, but 24 bits
 are required to exactly represent 0xff if I am not mistaken.

 I have found a couple more cases where it could fail in the same way
 and fixed them in the attached patch. Please review.

Looks good.  Thanks for fixing this.

I guess it would have saved you some work if we'd have #defined some
Z24SCALE and Z32SCALE constants at the top of the file in the first
place...

Reviewed-by: Brian Paul bri...@vmware.com
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [Bug 43678] Compilation error for OSMesa 7.10

2011-12-11 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=43678

Brian Paul bri...@vmware.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||WONTFIX

--- Comment #1 from Brian Paul bri...@vmware.com 2011-12-11 16:07:43 PST ---
There aren't going to be any more 7.10.x releases.  This is fixed in 7.11 and
later.

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
--- You are receiving this mail because: ---
You are the assignee for the bug.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] mesa: fix an out-of-bounds access in prog_print.c

2011-12-11 Thread Marek Olšák
---
 src/mesa/program/prog_print.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c
index e9bf3aa..b4d142f 100644
--- a/src/mesa/program/prog_print.c
+++ b/src/mesa/program/prog_print.c
@@ -112,6 +112,7 @@ arb_input_attrib_string(GLint index, GLenum progType)
   vertex.texcoord[5],
   vertex.texcoord[6],
   vertex.texcoord[7],
+  vertex.pointsize,
   vertex.attrib[0],
   vertex.attrib[1],
   vertex.attrib[2],
-- 
1.7.4.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] mesa: add const flags to skip MaxVarying and MaxUniform linker checks (v2)

2011-12-11 Thread Marek Olšák
This is only temporary until a better solution is available.

v2: print warnings and add gallium CAPs
---
 src/gallium/drivers/r300/r300_screen.c |2 +
 src/gallium/include/pipe/p_defines.h   |4 ++-
 src/glsl/linker.cpp|   43 ---
 src/mesa/main/mtypes.h |9 ++
 src/mesa/state_tracker/st_extensions.c |6 
 5 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_screen.c 
b/src/gallium/drivers/r300/r300_screen.c
index e734ff2..0bae065 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -100,6 +100,8 @@ static int r300_get_param(struct pipe_screen* pscreen, enum 
pipe_cap param)
 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
 case PIPE_CAP_CONDITIONAL_RENDER:
 case PIPE_CAP_TEXTURE_BARRIER:
+case PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS:
+case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
 return 1;
 
 /* r300 cannot do swizzling of compressed textures. Supported 
otherwise. */
diff --git a/src/gallium/include/pipe/p_defines.h 
b/src/gallium/include/pipe/p_defines.h
index f00077c..30f1d7f 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -465,7 +465,9 @@ enum pipe_cap {
PIPE_CAP_MIN_TEXEL_OFFSET = 50,
PIPE_CAP_MAX_TEXEL_OFFSET = 51,
PIPE_CAP_CONDITIONAL_RENDER = 52,
-   PIPE_CAP_TEXTURE_BARRIER = 53
+   PIPE_CAP_TEXTURE_BARRIER = 53,
+   PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS = 54, /* temporary */
+   PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS = 55 /* temporary */
 };
 
 /**
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 3527088..b8a7126 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1815,18 +1815,34 @@ assign_varying_locations(struct gl_context *ctx,
 
if (ctx-API == API_OPENGLES2 || prog-Version == 100) {
   if (varying_vectors  ctx-Const.MaxVarying) {
-linker_error(prog, shader uses too many varying vectors 
- (%u  %u)\n,
- varying_vectors, ctx-Const.MaxVarying);
-return false;
+ if (ctx-Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+linker_warning(prog, shader uses too many varying vectors 
+   (%u  %u), but the driver will try to optimize 
+   them out; this is non-portable out-of-spec 
+   behavior\n,
+   varying_vectors, ctx-Const.MaxVarying);
+ } else {
+linker_error(prog, shader uses too many varying vectors 
+ (%u  %u)\n,
+ varying_vectors, ctx-Const.MaxVarying);
+return false;
+ }
   }
} else {
   const unsigned float_components = varying_vectors * 4;
   if (float_components  ctx-Const.MaxVarying * 4) {
-linker_error(prog, shader uses too many varying components 
- (%u  %u)\n,
- float_components, ctx-Const.MaxVarying * 4);
-return false;
+ if (ctx-Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+linker_warning(prog, shader uses too many varying components 
+   (%u  %u), but the driver will try to optimize 
+   them out; this is non-portable out-of-spec 
+   behavior\n,
+   float_components, ctx-Const.MaxVarying * 4);
+ } else {
+linker_error(prog, shader uses too many varying components 
+ (%u  %u)\n,
+ float_components, ctx-Const.MaxVarying * 4);
+return false;
+ }
   }
}
 
@@ -1960,8 +1976,15 @@ check_resources(struct gl_context *ctx, struct 
gl_shader_program *prog)
   }
 
   if (sh-num_uniform_components  max_uniform_components[i]) {
- linker_error(prog, Too many %s shader uniform components,
- shader_names[i]);
+ if (ctx-Const.GLSLSkipStrictMaxUniformLimitCheck) {
+linker_warning(prog, Too many %s shader uniform components, 
+   but the driver will try to optimize them out; 
+   this is non-portable out-of-spec behavior\n,
+   shader_names[i]);
+ } else {
+linker_error(prog, Too many %s shader uniform components,
+ shader_names[i]);
+ }
   }
}
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index fc494f7..2073c8f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2829,6 +2829,15 @@ struct gl_constants
 * Texture borders are deprecated in GL 3.0.
 **/
GLboolean StripTextureBorder;
+
+   /**
+* For drivers which can do a better job at eliminating unused varyings
+* and uniforms than the GLSL compiler.
+*
+* XXX Remove 

Re: [Mesa-dev] Bug#651370: libgl1-mesa-glx: need close on exec for dri device

2011-12-11 Thread David Fries
Set the close on exec flag when opening dri character devices, so they
will be closed and free any resouces allocated in exec.
---
Just for fun I included a git bundle of the commit.
Please Cc me on any replies as I'm not subscribed to the mesa list.

 src/egl/drivers/dri2/platform_wayland.c|   11 ++-
 src/egl/drivers/dri2/platform_x11.c|9 +
 src/gallium/state_trackers/egl/drm/native_drm.c|   11 ++-
 .../state_trackers/egl/fbdev/native_fbdev.c|   11 ++-
 .../state_trackers/egl/wayland/native_drm.c|   10 +-
 src/gallium/state_trackers/egl/x11/x11_screen.c|   10 +-
 src/glx/dri2_glx.c |   10 +-
 7 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 7a70d8d..2dfde69 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -747,7 +747,16 @@ drm_handle_device(void *data, struct wl_drm *drm, const 
char *device)
if (!dri2_dpy-device_name)
   return;
 
-   dri2_dpy-fd = open(dri2_dpy-device_name, O_RDWR);
+#ifdef O_CLOEXEC
+   dri2_dpy-fd = open(dri2_dpy-device_name, O_RDWR | O_CLOEXEC);
+   if (dri2_dpy-fd == -1  errno == EINVAL)
+#endif
+   {
+  dri2_dpy-fd = open(dri2_dpy-device_name, O_RDWR);
+  if (dri2_dpy-fd != -1)
+ fcntl(dri2_dpy-fd, F_SETFD, fcntl(dri2_dpy-fd, F_GETFD) |
+FD_CLOEXEC);
+   }
if (dri2_dpy-fd == -1) {
   _eglLog(_EGL_WARNING, wayland-egl: could not open %s (%s),
  dri2_dpy-device_name, strerror(errno));
diff --git a/src/egl/drivers/dri2/platform_x11.c 
b/src/egl/drivers/dri2/platform_x11.c
index 8dd231a..a31a587 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -998,7 +998,16 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay 
*disp)
if (!dri2_load_driver(disp))
   goto cleanup_conn;
 
+#ifdef O_CLOEXEC
dri2_dpy-fd = open(dri2_dpy-device_name, O_RDWR | O_CLOEXEC);
+   if (dri2_dpy-fd == -1  errno == EINVAL)
+#endif
+   {
+  dri2_dpy-fd = open(dri2_dpy-device_name, O_RDWR);
+  if (dri2_dpy-fd != -1)
+ fcntl(dri2_dpy-fd, F_SETFD, fcntl(dri2_dpy-fd, F_GETFD) |
+FD_CLOEXEC);
+   }
if (dri2_dpy-fd == -1) {
   _eglLog(_EGL_WARNING,
  DRI2: could not open %s (%s), dri2_dpy-device_name,
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c 
b/src/gallium/state_trackers/egl/drm/native_drm.c
index c013769..a762f8f 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.c
+++ b/src/gallium/state_trackers/egl/drm/native_drm.c
@@ -312,7 +312,16 @@ native_create_display(void *dpy, boolean use_sw)
gbm = dpy;
 
if (gbm == NULL) {
-  fd = open(/dev/dri/card0, O_RDWR);
+  const char *device_name=/dev/dri/card0;
+#ifdef O_CLOEXEC
+  fd = open(device_name, O_RDWR | O_CLOEXEC);
+  if (fd == -1  errno == EINVAL)
+#endif
+  {
+ fd = open(device_name, O_RDWR);
+ if (fd != -1)
+fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+  }
   /* FIXME: Use an internal constructor to create a gbm
* device with gallium backend directly, without setenv */
   setenv(GBM_BACKEND, gbm_gallium_drm.so, 1);
diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c 
b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
index e126888..b45ab5c 100644
--- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
+++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
@@ -515,7 +515,16 @@ native_create_display(void *dpy, boolean use_sw)
 
/* well, this makes fd 0 being ignored */
if (!dpy) {
-  fd = open(/dev/fb0, O_RDWR);
+  const char *device_name=/dev/fb0;
+#ifdef O_CLOEXEC
+  fd = open(device_name, O_RDWR | O_CLOEXEC);
+  if (fd == -1  errno == EINVAL)
+#endif
+  {
+ fd = open(device_name, O_RDWR);
+ if (fd != -1)
+fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+  }
}
else {
   fd = dup((int) pointer_to_intptr(dpy));
diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c 
b/src/gallium/state_trackers/egl/wayland/native_drm.c
index 5618f3e..92e73ed 100644
--- a/src/gallium/state_trackers/egl/wayland/native_drm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
@@ -134,7 +134,15 @@ drm_handle_device(void *data, struct wl_drm *drm, const 
char *device)
if (!drmdpy-device_name)
   return;
 
-   drmdpy-fd = open(drmdpy-device_name, O_RDWR);
+#ifdef O_CLOEXEC
+   drmdpy-fd = open(drmdpy-device_name, O_RDWR | O_CLOEXEC);
+   if (drmdpy-fd == -1  errno == EINVAL)
+#endif
+   {
+  drmdpy-fd = open(drmdpy-device_name, O_RDWR);
+  if (drmdpy-fd != -1)
+ fcntl(drmdpy-fd, F_SETFD, fcntl(drmdpy-fd, F_GETFD) | FD_CLOEXEC);
+   }
if (drmdpy-fd == -1) {
   _eglLog(_EGL_WARNING,