It is implemented by adding a new depth/stencil native attachment.
While depth seems to work even without this, due to the Mesa state tracker 
creating it itself, this is the way other DRI2 drivers work and might work 
better in some cases.
If we pass to validate a non-existent attachment or 
NATIVE_ATTACHMENT_DEPTH_STENCIL: for a surface without a depth/stencil format, 
we simply return 0 rather than asserting. This simplifies the common code.
---
 .../state_trackers/egl_g3d/common/egl_g3d.c        |    1 +
 src/gallium/state_trackers/egl_g3d/common/egl_st.h |    1 +
 src/gallium/state_trackers/egl_g3d/common/native.h |    1 +
 .../state_trackers/egl_g3d/x11/native_dri2.c       |   68 +++++++++++++++++---
 4 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c 
b/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
index e993fa4..d68f49e 100644
--- a/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl_g3d/common/egl_g3d.c
@@ -135,6 +135,7 @@ egl_g3d_route_context(_EGLDisplay *dpy, _EGLContext *ctx)
       ST_SURFACE_BACK_LEFT,
       ST_SURFACE_FRONT_RIGHT,
       ST_SURFACE_BACK_RIGHT,
+      ST_SURFACE_DEPTH
    };
    EGLint s, i;
 
diff --git a/src/gallium/state_trackers/egl_g3d/common/egl_st.h 
b/src/gallium/state_trackers/egl_g3d/common/egl_st.h
index 8fb464b..e1d821a 100644
--- a/src/gallium/state_trackers/egl_g3d/common/egl_st.h
+++ b/src/gallium/state_trackers/egl_g3d/common/egl_st.h
@@ -39,6 +39,7 @@
 #define ST_SURFACE_BACK_LEFT    1
 #define ST_SURFACE_FRONT_RIGHT  2
 #define ST_SURFACE_BACK_RIGHT   3
+#define ST_SURFACE_DEPTH        8
 
 #define ST_TEXTURE_2D    0x2
 
diff --git a/src/gallium/state_trackers/egl_g3d/common/native.h 
b/src/gallium/state_trackers/egl_g3d/common/native.h
index 34abd86..a59ceac 100644
--- a/src/gallium/state_trackers/egl_g3d/common/native.h
+++ b/src/gallium/state_trackers/egl_g3d/common/native.h
@@ -43,6 +43,7 @@ enum native_attachment {
    NATIVE_ATTACHMENT_BACK_LEFT,
    NATIVE_ATTACHMENT_FRONT_RIGHT,
    NATIVE_ATTACHMENT_BACK_RIGHT,
+   NATIVE_ATTACHMENT_DEPTH_STENCIL,
 
    NUM_NATIVE_ATTACHMENTS
 };
diff --git a/src/gallium/state_trackers/egl_g3d/x11/native_dri2.c 
b/src/gallium/state_trackers/egl_g3d/x11/native_dri2.c
index c4194f9..138f797 100644
--- a/src/gallium/state_trackers/egl_g3d/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl_g3d/x11/native_dri2.c
@@ -59,6 +59,8 @@ struct dri2_surface {
    Drawable drawable;
    enum dri2_surface_type type;
    enum pipe_format color_format;
+   enum pipe_format depth_stencil_format;
+   int dri2_depth_stencil_attachment;
    struct dri2_display *dri2dpy;
 
    struct pipe_texture *pbuffer_textures[NUM_NATIVE_ATTACHMENTS];
@@ -154,8 +156,6 @@ dri2_surface_validate(struct native_surface *nsurf,
       templ.width0 = dri2surf->width;
       templ.height0 = dri2surf->height;
       templ.depth0 = 1;
-      templ.format = dri2surf->color_format;
-      templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
 
       memset(textures, 0, sizeof(*textures) * num_natts);
    }
@@ -184,9 +184,9 @@ dri2_surface_validate(struct native_surface *nsurf,
       texture_indices[i] = -1;
 
    /* prepare the attachments */
-   num_ins = num_natts;
+   num_ins = 0;
    for (i = 0; i < num_natts; i++) {
-      unsigned int dri2att;
+      int dri2att = -1;
 
       switch (natts[i]) {
       case NATIVE_ATTACHMENT_FRONT_LEFT:
@@ -201,12 +201,12 @@ dri2_surface_validate(struct native_surface *nsurf,
       case NATIVE_ATTACHMENT_BACK_RIGHT:
          dri2att = DRI2BufferBackRight;
          break;
-      default:
-         assert(0);
-         dri2att = 0;
+      case NATIVE_ATTACHMENT_DEPTH_STENCIL:
+         dri2att = dri2surf->dri2_depth_stencil_attachment;
          break;
       }
-      dri2atts[i] = dri2att;
+      if(dri2att > 0)
+         dri2atts[num_ins++] = dri2att;
       texture_indices[natts[i]] = i;
    }
 
@@ -243,6 +243,24 @@ dri2_surface_validate(struct native_surface *nsurf,
          desc = "DRI2 Back Buffer";
          dri2surf->have_back = TRUE;
          break;
+      case DRI2BufferFrontRight:
+         natt = NATIVE_ATTACHMENT_FRONT_RIGHT;
+         desc = "DRI2 Front Right Buffer";
+         break;
+      case DRI2BufferFakeFrontRight:
+         natt = NATIVE_ATTACHMENT_FRONT_RIGHT;
+         desc = "DRI2 Fake Front Right Buffer";
+         break;
+      case DRI2BufferBackRight:
+         natt = NATIVE_ATTACHMENT_BACK_RIGHT;
+         desc = "DRI2 Back Right Buffer";
+         break;
+      case DRI2BufferDepth:
+      case DRI2BufferStencil:
+      case DRI2BufferDepthStencil:
+         natt = NATIVE_ATTACHMENT_DEPTH_STENCIL;
+         desc = "DRI2 Depth/Stencil Buffer";
+         break;
       default:
          desc = NULL;
          break;
@@ -254,12 +272,29 @@ dri2_surface_validate(struct native_surface *nsurf,
             _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment);
          else if (texture_indices[natt] < 0)
             _eglLog(_EGL_WARNING, "unexpected buffer %d", xbuf->attachment);
+         /* Gallium doesn't support separate depth/stencil and thus neither do 
we */
          else if (textures && textures[texture_indices[natt]])
-            _eglLog(_EGL_WARNING, "both real and fake front buffers are 
listed");
+         {
+            if(natt == NATIVE_ATTACHMENT_DEPTH_STENCIL)
+               _eglLog(_EGL_WARNING, "multiple depth/stencil buffers are 
listed");
+            else
+               _eglLog(_EGL_WARNING, "both real and fake front buffers are 
listed");
+         }
          continue;
       }
 
       if (textures) {
+         if(natt == NATIVE_ATTACHMENT_DEPTH_STENCIL)
+         {
+            templ.format = dri2surf->depth_stencil_format;
+            templ.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+         }
+         else
+         {
+            templ.format = dri2surf->color_format;
+            templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+         }
+
          struct pipe_texture *ptex =
             dri2dpy->api->texture_from_shared_handle(dri2dpy->api,
                   dri2dpy->base.screen, &templ,
@@ -332,6 +367,21 @@ dri2_display_create_surface(struct native_display *ndpy,
    dri2surf->type = type;
    dri2surf->drawable = drawable;
    dri2surf->color_format = dri2conf->base.color_format;
+   dri2surf->depth_stencil_format = dri2conf->base.depth_format;
+
+   dri2surf->dri2_depth_stencil_attachment = -1;
+   if(dri2surf->depth_stencil_format)
+   {
+      unsigned depth, stencil;
+      depth = util_format_get_component_bits(dri2surf->depth_stencil_format, 
UTIL_FORMAT_COLORSPACE_ZS, 0);
+      stencil = util_format_get_component_bits(dri2surf->depth_stencil_format, 
UTIL_FORMAT_COLORSPACE_ZS, 1);
+      if(depth && stencil)
+         dri2surf->dri2_depth_stencil_attachment = DRI2BufferDepthStencil;
+      else if(depth)
+         dri2surf->dri2_depth_stencil_attachment = DRI2BufferDepth;
+      else if(stencil)
+         dri2surf->dri2_depth_stencil_attachment = DRI2BufferStencil;
+   }
 
    dri2surf->base.destroy = dri2_surface_destroy;
    dri2surf->base.swap_buffers = dri2_surface_swap_buffers;
-- 
1.6.3.3


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to