intel: Define span functions for S8 renderbuffers
authorChad Versace <chad@chad-versace.us>
Wed, 1 Jun 2011 18:31:56 +0000 (11:31 -0700)
committerChad Versace <chad@chad-versace.us>
Wed, 8 Jun 2011 17:06:39 +0000 (10:06 -0700)
Since the stencil buffer is interleaved, the generic Mesa renderbuffer
accessors do not suffice. Custom span functions are necessary.

Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Chad Versace <chad@chad-versace.us>
src/mesa/drivers/dri/intel/intel_span.c

index 5290342c3e15465f1f41aca57c6ceb5abb218c7e..a4a1d6bd6ebe5f7e712b42e874dc394c5259ddda 100644 (file)
@@ -1,6 +1,7 @@
 /**************************************************************************
  * 
  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2011 Intel Corporation
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
+ * Authors:
+ *     Chad Versace <chad@chad-versace.us>
+ *
  **************************************************************************/
 
 #include <stdbool.h>
+#include <stdint.h>
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
@@ -112,6 +117,64 @@ intel_set_span_functions(struct intel_context *intel,
 #define TAG2(x,y) intel_##x##y##_A8
 #include "spantmp2.h"
 
+/* ------------------------------------------------------------------------- */
+/* s8 stencil span and pixel functions                                       */
+/* ------------------------------------------------------------------------- */
+
+/*
+ * HAVE_HW_STENCIL_SPANS determines if stencil buffer read/writes are done with
+ * memcpy or for loops. Since the stencil buffer is interleaved, memcpy won't
+ * work.
+ */
+#define HAVE_HW_STENCIL_SPANS 0
+
+#define LOCAL_STENCIL_VARS                                             \
+   (void) ctx;                                                         \
+   int minx = 0;                                                       \
+   int miny = 0;                                                       \
+   int maxx = rb->Width;                                               \
+   int maxy = rb->Height;                                              \
+   int stride = rb->RowStride;                                         \
+   uint8_t *buf = rb->Data;                                            \
+
+/* Don't flip y. */
+#undef Y_FLIP
+#define Y_FLIP(y) y
+
+/**
+ * \brief Get pointer offset into stencil buffer.
+ *
+ * The stencil buffer interleaves two rows into one. Yay for crazy hardware.
+ * The table below demonstrates how the pointer arithmetic behaves for a buffer
+ * with positive stride (s=stride).
+ *
+ *     x    | y     | byte offset
+ *     --------------------------
+ *     0    | 0     | 0
+ *     0    | 0     | 1
+ *     1    | 0     | 2
+ *     1    | 1     | 3
+ *     ...  | ...   | ...
+ *     0    | 2     | s
+ *     0    | 3     | s + 1
+ *     1    | 2     | s + 2
+ *     1    | 3     | s + 3
+ *
+ *
+ */
+static inline intptr_t
+intel_offset_S8(int stride, GLint x, GLint y)
+{
+   return 2 * ((y / 2) * stride + x) + y % 2;
+}
+
+#define WRITE_STENCIL(x, y, src)  buf[intel_offset_S8(stride, x, y)] = src;
+#define READ_STENCIL(dest, x, y) dest = buf[intel_offset_S8(stride, x, y)]
+#define TAG(x) intel_##x##_S8
+#include "stenciltmp.h"
+
+/* ------------------------------------------------------------------------- */
+
 void
 intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
 {
@@ -332,6 +395,7 @@ static span_init_func intel_span_init_funcs[MESA_FORMAT_COUNT] =
    [MESA_FORMAT_Z16] = _mesa_set_renderbuffer_accessors,
    [MESA_FORMAT_X8_Z24] = _mesa_set_renderbuffer_accessors,
    [MESA_FORMAT_S8_Z24] = _mesa_set_renderbuffer_accessors,
+   [MESA_FORMAT_S8] = intel_InitStencilPointers_S8,
    [MESA_FORMAT_R8] = _mesa_set_renderbuffer_accessors,
    [MESA_FORMAT_RG88] = _mesa_set_renderbuffer_accessors,
    [MESA_FORMAT_R16] = _mesa_set_renderbuffer_accessors,