Re: [Mesa-dev] [PATCH 1/6] mesa: Add field gl_renderbuffer.Unwrapped

2011-06-16 Thread Chad Versace
On 06/16/2011 08:01 AM, Alex Deucher wrote:
 On Wed, Jun 15, 2011 at 9:09 PM, Chad Versace c...@chad-versace.us wrote:
 If a renderbuffer wraps multiple renderbuffers, then Unwrapped points to
 the them.

 For example, if hardware requires separate depth and stencil buffers
 (X8_Z24 and S8), then glRenderbufferStorage(GL_DEPTH24_STENCIL8) may
 create a fake S8_Z24 renderbuffer for which Unwrapped[BUFFER_DEPTH] and
 Unwrapped[BUFFER_STENCIL] point to the real X8_Z24 and S8 renderbuffers.

 
 FWIW, evergreen and newer chips only support separate stencil and
 depth, so we had a similar issue.  We ended up using
 GL_ARB_shader_stencil_export to implement writes to the stencil.
 Start of the thread:
 http://lists.freedesktop.org/archives/mesa-dev/2010-September/003318.html
 
 Alex

The thread mentions some strange behaviour on r600:
 so on r600g, the only way to directly write to the stencil is via the
 shader, using a transfer would require an extra step to flush the DS
 buffer

I've observed mysterious behaviour when writing to intel's stencil buffer 
through a memory mapped pointer. It's seems that the
hardware fails to recognize that the writes ever occurred. (Writes via 
rendering work fine).  I still need to investigate the
problem further, but perhaps GL_ARB_shader_stencil_export is what the intel 
driver needs to work around this problem.

Thanks for pointing this out.

-- 
Chad Versace
c...@chad-versace.us
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/6] mesa: Add field gl_renderbuffer.Unwrapped

2011-06-15 Thread Chad Versace
If a renderbuffer wraps multiple renderbuffers, then Unwrapped points to
the them.

For example, if hardware requires separate depth and stencil buffers
(X8_Z24 and S8), then glRenderbufferStorage(GL_DEPTH24_STENCIL8) may
create a fake S8_Z24 renderbuffer for which Unwrapped[BUFFER_DEPTH] and
Unwrapped[BUFFER_STENCIL] point to the real X8_Z24 and S8 renderbuffers.

Alter the following function to take Unwrapped into account:
_mesa_framebuffer_renderbuffer
_mesa_update_depth_buffer
_mesa_update_stencil_buffer
_mesa_reference_renderbuffer

Signed-off-by: Chad Versace c...@chad-versace.us
---
 src/mesa/main/fbobject.c |   26 +---
 src/mesa/main/framebuffer.c  |   54 +++---
 src/mesa/main/mtypes.h   |   11 
 src/mesa/main/renderbuffer.c |6 
 4 files changed, 79 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 2230b26..61a0619 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -379,10 +379,28 @@ _mesa_framebuffer_renderbuffer(struct gl_context *ctx,
if (rb) {
   _mesa_set_renderbuffer_attachment(ctx, att, rb);
   if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
- /* do stencil attachment here (depth already done above) */
- att = _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
- assert(att);
- _mesa_set_renderbuffer_attachment(ctx, att, rb);
+struct gl_renderbuffer_attachment *depth_att =
+   _mesa_get_attachment(ctx, fb, GL_DEPTH_ATTACHMENT);
+struct gl_renderbuffer_attachment *stencil_att =
+   _mesa_get_attachment(ctx, fb, GL_STENCIL_ATTACHMENT_EXT);
+struct gl_renderbuffer *depth_rb;
+struct gl_renderbuffer *stencil_rb;
+
+/* Set depth attachment. */
+if (rb-Unwrapped[BUFFER_DEPTH]) {
+   depth_rb = rb-Unwrapped[BUFFER_DEPTH];
+} else {
+   depth_rb = rb;
+}
+_mesa_set_renderbuffer_attachment(ctx, depth_att, depth_rb);
+
+/* Set stencil attachment. */
+if (rb-Unwrapped[BUFFER_STENCIL]) {
+   stencil_rb = rb-Unwrapped[BUFFER_STENCIL];
+} else {
+   stencil_rb = rb;
+}
+_mesa_set_renderbuffer_attachment(ctx, stencil_att, stencil_rb);
   }
   rb-AttachedAnytime = GL_TRUE;
}
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 66c9bd9..6e1f1f1 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -604,14 +604,20 @@ _mesa_update_framebuffer_visual(struct gl_context *ctx,
 
 
 /**
- * Update the framebuffer's _DepthBuffer field using the renderbuffer
- * found at the given attachment index.
+ * \brief Update gl_framebuffer._DepthBuffer.
  *
- * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
- * create and install a depth wrapper/adaptor.
+ * Set gl_framebuffer._DepthBuffer to the attachment's renderbuffer, unless
+ * the renderbuffer has packed depth/stencil format.
+ *
+ * Renderbuffers with packed depth/stencil format are a special case. If the
+ * attachment's renderbuffer contains a depth unwrapper (that is,
+ * gl_renderbuffer.Unwrapper[BUFFER_DEPTH != NULL), then install the
+ * unwrapper. Otherwise, create and install a x8_z24 depth wrapper.
  *
  * \param fb  the framebuffer whose _DepthBuffer field to update
  * \param attIndex  indicates the renderbuffer to possibly wrap
+ *
+ * \see _mesa_new_z24_renderbuffer_wrapper
  */
 void
 _mesa_update_depth_buffer(struct gl_context *ctx,
@@ -627,9 +633,16 @@ _mesa_update_depth_buffer(struct gl_context *ctx,
 
if (depthRb  _mesa_is_format_packed_depth_stencil(depthRb-Format)) {
   /* The attached depth buffer is a GL_DEPTH_STENCIL renderbuffer */
-  if (!fb-_DepthBuffer
-  || fb-_DepthBuffer-Wrapped != depthRb
-  || _mesa_get_format_base_format(fb-_DepthBuffer-Format) != 
GL_DEPTH_COMPONENT) {
+  struct gl_renderbuffer *unwrapper = depthRb-Unwrapped[BUFFER_DEPTH];
+  if (unwrapper) {
+if (fb-_DepthBuffer != unwrapper) {
+   _mesa_reference_renderbuffer(fb-_DepthBuffer, unwrapper);
+}
+  }
+  else if (!fb-_DepthBuffer
+  || fb-_DepthBuffer-Wrapped != depthRb
+  || _mesa_get_format_base_format(fb-_DepthBuffer-Format)
+ != GL_DEPTH_COMPONENT) {
  /* need to update wrapper */
  struct gl_renderbuffer *wrapper
 = _mesa_new_z24_renderbuffer_wrapper(ctx, depthRb);
@@ -645,14 +658,20 @@ _mesa_update_depth_buffer(struct gl_context *ctx,
 
 
 /**
- * Update the framebuffer's _StencilBuffer field using the renderbuffer
- * found at the given attachment index.
+ * \brief Update gl_framebuffer._StencilBuffer.
  *
- * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer,
- * create and install a stencil wrapper/adaptor.
+ * Set gl_framebuffer._StencilBuffer to the