summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-07-31 17:42:03 -0600
committerBrian <[email protected]>2007-07-31 17:42:03 -0600
commit20adf45c23dd9ec86a1439ad87c1473395bbb1a7 (patch)
treeeee17a4b7b1572651c2b20661b26b82def9cdd34
parent2f245bce420c7a6c6928c4927d0f9a5701cde17f (diff)
Redesign pipe_surface in terms of pipe_region.
struct pipe_buffer goes away. Added basic region functions to softpipe to allocate/release malloc'd regions. Surface-related code is fairly coherent now.
-rw-r--r--src/mesa/drivers/dri/i915pipe/intel_fbo.c3
-rw-r--r--src/mesa/drivers/dri/i915pipe/intel_surface.c85
-rw-r--r--src/mesa/drivers/x11/xm_buffer.c13
-rw-r--r--src/mesa/drivers/x11/xm_surface.c42
-rw-r--r--src/mesa/drivers/x11/xmesaP.h2
-rw-r--r--src/mesa/main/renderbuffer.c54
-rw-r--r--src/mesa/pipe/p_context.h8
-rw-r--r--src/mesa/pipe/p_state.h53
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c19
-rw-r--r--src/mesa/pipe/softpipe/sp_region.c105
-rw-r--r--src/mesa/pipe/softpipe/sp_region.h40
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.c236
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.h7
-rw-r--r--src/mesa/pipe/softpipe/sp_z_surface.c138
-rw-r--r--src/mesa/sources3
15 files changed, 538 insertions, 270 deletions
diff --git a/src/mesa/drivers/dri/i915pipe/intel_fbo.c b/src/mesa/drivers/dri/i915pipe/intel_fbo.c
index bac2ef8467b..1470ce7d82c 100644
--- a/src/mesa/drivers/dri/i915pipe/intel_fbo.c
+++ b/src/mesa/drivers/dri/i915pipe/intel_fbo.c
@@ -291,11 +291,10 @@ intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
rb->Width = width;
rb->Height = height;
-#if 1
/* update the surface's size too */
rb->surface->width = width;
rb->surface->height = height;
-#endif
+ rb->surface->region = irb->region;
/* This sets the Get/PutRow/Value functions */
intel_set_span_functions(&irb->Base);
diff --git a/src/mesa/drivers/dri/i915pipe/intel_surface.c b/src/mesa/drivers/dri/i915pipe/intel_surface.c
index 58f5cb5f96e..936c9cb5e75 100644
--- a/src/mesa/drivers/dri/i915pipe/intel_surface.c
+++ b/src/mesa/drivers/dri/i915pipe/intel_surface.c
@@ -33,9 +33,9 @@ static void
read_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rrrr)[QUAD_SIZE])
{
- const GLint bytesPerRow = sps->surface.stride * sps->surface.cpp;
+ const GLint bytesPerRow = sps->surface.region->pitch * sps->surface.region->cpp;
const GLint invY = sps->surface.height - y - 1;
- const GLubyte *src = sps->surface.ptr + invY * bytesPerRow + x * sps->surface.cpp;
+ const GLubyte *src = sps->surface.region->map + invY * bytesPerRow + x * sps->surface.region->cpp;
GLfloat *dst = (GLfloat *) rrrr;
GLubyte temp[16];
GLuint j;
@@ -59,9 +59,9 @@ write_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rrrr)[QUAD_SIZE])
{
const GLfloat *src = (const GLfloat *) rrrr;
- const GLint bytesPerRow = sps->surface.stride * sps->surface.cpp;
+ const GLint bytesPerRow = sps->surface.region->pitch * sps->surface.region->cpp;
const GLint invY = sps->surface.height - y - 1;
- GLubyte *dst = sps->surface.ptr + invY * bytesPerRow + x * sps->surface.cpp;
+ GLubyte *dst = sps->surface.region->map + invY * bytesPerRow + x * sps->surface.region->cpp;
GLubyte temp[16];
GLuint j;
@@ -87,16 +87,16 @@ read_quad_z24(struct softpipe_surface *sps,
static const GLuint mask = 0xffffff;
const GLint invY = sps->surface.height - y - 1;
const GLuint *src
- = (GLuint *) (sps->surface.ptr
- + (invY * sps->surface.stride + x) * sps->surface.cpp);
+ = (GLuint *) (sps->surface.region->map
+ + (invY * sps->surface.region->pitch + x) * sps->surface.region->cpp);
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
/* extract lower three bytes */
zzzz[0] = src[0] & mask;
zzzz[1] = src[1] & mask;
- zzzz[2] = src[-sps->surface.stride] & mask;
- zzzz[3] = src[-sps->surface.stride + 1] & mask;
+ zzzz[2] = src[-sps->surface.region->pitch] & mask;
+ zzzz[3] = src[-sps->surface.region->pitch + 1] & mask;
}
static void
@@ -106,15 +106,15 @@ write_quad_z24(struct softpipe_surface *sps,
static const GLuint mask = 0xff000000;
const GLint invY = sps->surface.height - y - 1;
GLuint *dst
- = (GLuint *) (sps->surface.ptr
- + (invY * sps->surface.stride + x) * sps->surface.cpp);
+ = (GLuint *) (sps->surface.region->map
+ + (invY * sps->surface.region->pitch + x) * sps->surface.region->cpp);
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
/* write lower three bytes */
dst[0] = (dst[0] & mask) | zzzz[0];
dst[1] = (dst[1] & mask) | zzzz[1];
- dst -= sps->surface.stride;
+ dst -= sps->surface.region->pitch;
dst[0] = (dst[0] & mask) | zzzz[2];
dst[1] = (dst[1] & mask) | zzzz[3];
}
@@ -125,15 +125,15 @@ read_quad_stencil(struct softpipe_surface *sps,
GLint x, GLint y, GLubyte ssss[QUAD_SIZE])
{
const GLint invY = sps->surface.height - y - 1;
- const GLuint *src = (const GLuint *) (sps->surface.ptr
- + (invY * sps->surface.stride + x) * sps->surface.cpp);
+ const GLuint *src = (const GLuint *) (sps->surface.region->map
+ + (invY * sps->surface.region->pitch + x) * sps->surface.region->cpp);
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
/* extract high byte */
ssss[0] = src[0] >> 24;
ssss[1] = src[1] >> 24;
- src -= sps->surface.stride;
+ src -= sps->surface.region->pitch;
ssss[2] = src[0] >> 24;
ssss[3] = src[1] >> 24;
}
@@ -144,68 +144,20 @@ write_quad_stencil(struct softpipe_surface *sps,
{
static const GLuint mask = 0x00ffffff;
const GLint invY = sps->surface.height - y - 1;
- GLuint *dst = (GLuint *) (sps->surface.ptr
- + (invY * sps->surface.stride + x) * sps->surface.cpp);
+ GLuint *dst = (GLuint *) (sps->surface.region->map
+ + (invY * sps->surface.region->pitch + x) * sps->surface.region->cpp);
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
/* write high byte */
dst[0] = (dst[0] & mask) | (ssss[0] << 24);
dst[1] = (dst[1] & mask) | (ssss[1] << 24);
- dst -= sps->surface.stride;
+ dst -= sps->surface.region->pitch;
dst[0] = (dst[0] & mask) | (ssss[2] << 24);
dst[1] = (dst[1] & mask) | (ssss[3] << 24);
}
-static void *
-map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode)
-{
- struct softpipe_surface *sps = (struct softpipe_surface *) pb;
- struct intel_renderbuffer *irb = (struct intel_renderbuffer *) sps->surface.rb;
- assert(access_mode == PIPE_MAP_READ_WRITE);
-
- /*LOCK_HARDWARE(intel);*/
-
- if (irb->region) {
- GET_CURRENT_CONTEXT(ctx);
- struct intel_context *intel = intel_context(ctx);
-#if 0
- intelFinish(&intel->ctx); /* XXX need this? */
-#endif
- intel->pipe->region_map(intel->pipe, irb->region);
- }
- pb->ptr = irb->region->map;
-
- sps->surface.stride = irb->region->pitch;
- sps->surface.cpp = irb->region->cpp;
- sps->surface.ptr = irb->region->map;
-
- return pb->ptr;
-}
-
-
-static void
-unmap_surface_buffer(struct pipe_buffer *pb)
-{
- struct softpipe_surface *sps = (struct softpipe_surface *) pb;
- struct intel_renderbuffer *irb = (struct intel_renderbuffer *) sps->surface.rb;
-
- if (irb->region) {
- GET_CURRENT_CONTEXT(ctx);
- struct intel_context *intel = intel_context(ctx);
- intel->pipe->region_unmap(intel->pipe, irb->region);
- }
- pb->ptr = NULL;
-
- sps->surface.stride = 0;
- sps->surface.cpp = 0;
- sps->surface.ptr = NULL;
-
- /*UNLOCK_HARDWARE(intel);*/
-}
-
-
struct pipe_surface *
intel_new_surface(GLuint intFormat)
{
@@ -241,8 +193,5 @@ intel_new_surface(GLuint intFormat)
}
- sps->surface.buffer.map = map_surface_buffer;
- sps->surface.buffer.unmap = unmap_surface_buffer;
-
return &sps->surface;
}
diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c
index 8fbd9a783b0..5bba52da48a 100644
--- a/src/mesa/drivers/x11/xm_buffer.c
+++ b/src/mesa/drivers/x11/xm_buffer.c
@@ -269,7 +269,10 @@ xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->Height = height;
rb->InternalFormat = internalFormat;
- rb->surface->resize(rb->surface, width, height);
+ if (!xrb->Base.surface)
+ xrb->Base.surface = xmesa_new_surface(ctx, xrb);
+ xrb->Base.surface->width = width;
+ xrb->Base.surface->height = height;
return GL_TRUE;
}
@@ -320,7 +323,10 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
xrb->origin4 = NULL;
}
- rb->surface->resize(rb->surface, width, height);
+ if (!xrb->Base.surface)
+ xrb->Base.surface = xmesa_new_surface(ctx, xrb);
+ xrb->Base.surface->width = width;
+ xrb->Base.surface->height = height;
return GL_TRUE;
}
@@ -357,9 +363,6 @@ xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual,
xrb->Base.IndexBits = visual->indexBits;
}
/* only need to set Red/Green/EtcBits fields for user-created RBs */
-
- xrb->Base.surface = xmesa_new_surface(xrb);
-
}
return xrb;
}
diff --git a/src/mesa/drivers/x11/xm_surface.c b/src/mesa/drivers/x11/xm_surface.c
index 17f5f28a9dd..e8e795c00f7 100644
--- a/src/mesa/drivers/x11/xm_surface.c
+++ b/src/mesa/drivers/x11/xm_surface.c
@@ -42,25 +42,11 @@
#include "framebuffer.h"
#include "renderbuffer.h"
-#include "pipe/p_state.h"
+#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/softpipe/sp_context.h"
#include "pipe/softpipe/sp_surface.h"
-
-
-static void *
-map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode)
-{
- /* no-op */
- return NULL;
-}
-
-
-static void
-unmap_surface_buffer(struct pipe_buffer *pb)
-{
- /* no-op */
-}
+#include "state_tracker/st_context.h"
static INLINE struct xmesa_renderbuffer *
@@ -174,27 +160,22 @@ write_mono_row_ub(struct softpipe_surface *sps, GLuint count, GLint x, GLint y,
}
-static void
-resize_surface(struct pipe_surface *ps, GLuint width, GLuint height)
-{
- ps->width = width;
- ps->height = height;
-}
-
-
/**
* Called to create a pipe_surface for each X renderbuffer.
+ * Note: this is being used instead of pipe->surface_alloc() since we
+ * have special/unique quad read/write functions for X.
*/
struct pipe_surface *
-xmesa_new_surface(struct xmesa_renderbuffer *xrb)
+xmesa_new_surface(GLcontext *ctx, struct xmesa_renderbuffer *xrb)
{
+ struct pipe_context *pipe = ctx->st->pipe;
struct softpipe_surface *sps;
sps = CALLOC_STRUCT(softpipe_surface);
if (!sps)
return NULL;
- sps->surface.rb = xrb;
+ sps->surface.rb = xrb; /* XXX only needed for quad funcs above */
sps->surface.width = xrb->Base.Width;
sps->surface.height = xrb->Base.Height;
@@ -206,9 +187,12 @@ xmesa_new_surface(struct xmesa_renderbuffer *xrb)
sps->write_quad_ub = write_quad_ub;
sps->write_mono_row_ub = write_mono_row_ub;
- sps->surface.buffer.map = map_surface_buffer;
- sps->surface.buffer.unmap = unmap_surface_buffer;
- sps->surface.resize = resize_surface;
+ /* Note, the region we allocate doesn't actually have any storage
+ * since we're drawing into an XImage or Pixmap.
+ * The region's size will get set in the xmesa_alloc_front/back_storage()
+ * functions.
+ */
+ sps->surface.region = pipe->region_alloc(pipe, 0, 0, 0);
return &sps->surface;
}
diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h
index daf6a3f9424..098b9218ae5 100644
--- a/src/mesa/drivers/x11/xmesaP.h
+++ b/src/mesa/drivers/x11/xmesaP.h
@@ -589,7 +589,7 @@ extern void xmesa_register_swrast_functions( GLcontext *ctx );
struct pipe_surface;
struct pipe_surface *
-xmesa_new_surface(struct xmesa_renderbuffer *xrb);
+xmesa_new_surface(GLcontext *ctx, struct xmesa_renderbuffer *xrb);
#endif
diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index a900de169e5..7c35575d12e 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -51,7 +51,9 @@
#include "pipe/softpipe/sp_z_surface.h"
#include "pipe/p_state.h"
+#include "pipe/p_context.h"
#include "pipe/p_defines.h"
+#include "state_tracker/st_context.h"
/* 32-bit color index format. Not a public format. */
@@ -949,6 +951,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
GLenum internalFormat,
GLuint width, GLuint height)
{
+ struct pipe_context *pipe = ctx->st->pipe;
GLuint pixelSize;
/* first clear these fields */
@@ -1065,6 +1068,9 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoValues = put_mono_values_ubyte;
rb->StencilBits = 8 * sizeof(GLubyte);
pixelSize = sizeof(GLubyte);
+ if (!rb->surface)
+ rb->surface = (struct pipe_surface *)
+ pipe->surface_alloc(pipe, PIPE_FORMAT_U_S8);
break;
case GL_STENCIL_INDEX16_EXT:
rb->_ActualFormat = GL_STENCIL_INDEX16_EXT;
@@ -1095,8 +1101,9 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort;
rb->DepthBits = 8 * sizeof(GLushort);
- rb->surface
- = (struct pipe_surface *) softpipe_new_z_surface(PIPE_FORMAT_U_Z16);
+ if (!rb->surface)
+ rb->surface = (struct pipe_surface *)
+ pipe->surface_alloc(pipe, PIPE_FORMAT_U_Z16);
pixelSize = sizeof(GLushort);
break;
case GL_DEPTH_COMPONENT24:
@@ -1119,8 +1126,9 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->_ActualFormat = GL_DEPTH_COMPONENT32;
rb->DepthBits = 32;
}
- rb->surface
- = (struct pipe_surface *) softpipe_new_z_surface(PIPE_FORMAT_U_Z32);
+ if (!rb->surface)
+ rb->surface = (struct pipe_surface *)
+ pipe->surface_alloc(pipe, PIPE_FORMAT_U_Z32);
pixelSize = sizeof(GLuint);
break;
case GL_DEPTH_STENCIL_EXT:
@@ -1138,8 +1146,9 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutMonoValues = put_mono_values_uint;
rb->DepthBits = 24;
rb->StencilBits = 8;
- rb->surface
- = (struct pipe_surface *) softpipe_new_z_surface(PIPE_FORMAT_Z24_S8);
+ if (!rb->surface)
+ rb->surface = (struct pipe_surface *)
+ pipe->surface_alloc(pipe, PIPE_FORMAT_Z24_S8);
pixelSize = sizeof(GLuint);
break;
case GL_COLOR_INDEX8_EXT:
@@ -1202,28 +1211,33 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
ASSERT(rb->PutMonoValues);
/* free old buffer storage */
- if (rb->Data) {
- if (rb->surface) {
- /* pipe surface */
- }
- else {
- /* legacy renderbuffer */
- _mesa_free(rb->Data);
- }
- rb->Data = NULL;
+ if (rb->surface) {
+ /* pipe_surface/region */
}
+ else if (rb->Data) {
+ /* legacy renderbuffer (this will go away) */
+ _mesa_free(rb->Data);
+ }
+ rb->Data = NULL;
if (width > 0 && height > 0) {
/* allocate new buffer storage */
if (rb->surface) {
- /* pipe surface */
- rb->surface->resize(rb->surface, width, height);
- rb->Data = rb->surface->buffer.ptr;
+ /* pipe_surface/region */
+ if (rb->surface->region) {
+ pipe->region_unmap(pipe, rb->surface->region);
+ pipe->region_release(pipe, &rb->surface->region);
+ }
+ rb->surface->region = pipe->region_alloc(pipe, pixelSize, width, height);
+ /* XXX probably don't want to really map here */
+ pipe->region_map(pipe, rb->surface->region);
+ rb->Data = rb->surface->region->map;
}
else {
- /* legacy renderbuffer */
- rb->Data = _mesa_malloc(width * height * pixelSize);
+ /* legacy renderbuffer (this will go away) */
+ rb->Data = malloc(width * height * pixelSize);
}
+
if (rb->Data == NULL) {
rb->Width = 0;
rb->Height = 0;
diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h
index bfae55a4bab..b48c7775de3 100644
--- a/src/mesa/pipe/p_context.h
+++ b/src/mesa/pipe/p_context.h
@@ -117,6 +117,14 @@ struct pipe_context {
/*
+ * Surface functions
+ * This might go away...
+ */
+ struct pipe_surface *(*surface_alloc)(struct pipe_context *pipe,
+ GLuint format);
+
+
+ /*
* Memory region functions
* Some of these may go away...
*/
diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h
index d81c3f17782..0767fc2fcb5 100644
--- a/src/mesa/pipe/p_state.h
+++ b/src/mesa/pipe/p_state.h
@@ -233,51 +233,17 @@ struct pipe_sampler_state
/***
- *** Non-state Objects
+ *** Resource Objects
***/
-/**
- * A mappable buffer (vertex data, pixel data, etc)
- * XXX replace with "intel_region".
- */
-struct pipe_buffer
-{
- void (*buffer_data)(struct pipe_buffer *pb, GLuint size, const void *src);
- void (*buffer_sub_data)(struct pipe_buffer *pb, GLuint offset, GLuint size,
- const void *src);
- void *(*map)(struct pipe_buffer *pb, GLuint access_mode);
- void (*unmap)(struct pipe_buffer *pb);
- GLubyte *ptr; /**< address, only valid while mapped */
- GLuint mode; /**< PIPE_MAP_x, only valid while mapped */
-};
-
-
-/**
- * 2D surface.
- * May be a renderbuffer, texture mipmap level, etc.
- */
-struct pipe_surface
-{
- struct pipe_buffer buffer; /**< surfaces can be mapped */
- GLuint format:5; /**< PIPE_FORMAT_x */
- GLuint width, height;
-
- GLint stride, cpp;
- GLubyte *ptr; /**< only valid while mapped, may not equal buffer->ptr */
-
- void *rb; /**< Ptr back to renderbuffer (temporary?) */
-
- void (*resize)(struct pipe_surface *ps, GLuint width, GLuint height);
-};
-
-
struct _DriBufferObject;
struct intel_buffer_object;
struct pipe_region
{
struct _DriBufferObject *buffer; /**< buffer manager's buffer ID */
+
GLuint refcount; /**< Reference count for region */
GLuint cpp; /**< bytes per pixel */
GLuint pitch; /**< in pixels */
@@ -290,6 +256,21 @@ struct pipe_region
struct intel_buffer_object *pbo; /* zero-copy uploads */
};
+
+/**
+ * 2D surface.
+ * May be a renderbuffer, texture mipmap level, etc.
+ */
+struct pipe_surface
+{
+ struct pipe_region *region;
+ GLuint format:5; /**< PIPE_FORMAT_x */
+ GLuint width, height;
+
+ void *rb; /**< Ptr back to renderbuffer (temporary?) */
+};
+
+
/**
* Texture object.
* Mipmap levels, cube faces, 3D slices can be accessed as surfaces.
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
index 8655aa83fd4..002fe73b59d 100644
--- a/src/mesa/pipe/softpipe/sp_context.c
+++ b/src/mesa/pipe/softpipe/sp_context.c
@@ -35,6 +35,7 @@
#include "pipe/p_defines.h"
#include "sp_context.h"
#include "sp_clear.h"
+#include "sp_region.h"
#include "sp_state.h"
#include "sp_surface.h"
#include "sp_prim_setup.h"
@@ -42,18 +43,16 @@
static void map_surfaces(struct softpipe_context *sp)
{
+ struct pipe_context *pipe = &sp->pipe;
GLuint i;
for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
- struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]);
- struct pipe_buffer *buf = &sps->surface.buffer;
- buf->map(buf, PIPE_MAP_READ_WRITE);
+ struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]); pipe->region_map(pipe, sps->surface.region);
}
if (sp->framebuffer.zbuf) {
struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
- struct pipe_buffer *buf = &sps->surface.buffer;
- buf->map(buf, PIPE_MAP_READ_WRITE);
+ pipe->region_map(pipe, sps->surface.region);
}
/* XXX depth & stencil bufs */
@@ -62,18 +61,17 @@ static void map_surfaces(struct softpipe_context *sp)
static void unmap_surfaces(struct softpipe_context *sp)
{
+ struct pipe_context *pipe = &sp->pipe;
GLuint i;
for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.cbufs[i]);
- struct pipe_buffer *buf = &sps->surface.buffer;
- buf->unmap(buf);
+ pipe->region_unmap(pipe, sps->surface.region);
}
if (sp->framebuffer.zbuf) {
struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
- struct pipe_buffer *buf = &sps->surface.buffer;
- buf->unmap(buf);
+ pipe->region_unmap(pipe, sps->surface.region);
}
/* XXX depth & stencil bufs */
}
@@ -161,6 +159,9 @@ struct pipe_context *softpipe_create( void )
softpipe->draw = draw_create();
draw_set_setup_stage(softpipe->draw, sp_draw_render_stage(softpipe));
+ sp_init_region_functions(softpipe);
+ sp_init_surface_functions(softpipe);
+
/*
* XXX we could plug GL selection/feedback into the drawing pipeline
* by specifying a different setup/render stage.
diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c
new file mode 100644
index 00000000000..04ae5e94f9e
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_region.c
@@ -0,0 +1,105 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/**
+ * Software-based region allocation and management.
+ * A hardware driver would override these functions.
+ */
+
+
+#include "sp_context.h"
+#include "sp_region.h"
+#include "sp_surface.h"
+#include "main/imports.h"
+
+
+static struct pipe_region *
+sp_region_alloc(struct pipe_context *pipe,
+ GLuint cpp, GLuint pitch, GLuint height)
+{
+ struct pipe_region *region = CALLOC_STRUCT(pipe_region);
+ if (!region)
+ return NULL;
+
+ region->refcount = 1;
+ region->cpp = cpp;
+ region->pitch = pitch;
+ region->height = height;
+ region->map = malloc(cpp * pitch * height);
+
+ return region;
+}
+
+
+static void
+sp_region_release(struct pipe_context *pipe, struct pipe_region **region)
+{
+ assert((*region)->refcount > 0);
+ (*region)->refcount--;
+
+ if ((*region)->refcount == 0) {
+ assert((*region)->map_refcount == 0);
+
+#if 0
+ if ((*region)->pbo)
+ (*region)->pbo->region = NULL;
+ (*region)->pbo = NULL;
+#endif
+
+ free(*region);
+ }
+ *region = NULL;
+}
+
+
+
+static GLubyte *
+sp_region_map(struct pipe_context *pipe, struct pipe_region *region)
+{
+ region->map_refcount++;
+ return region->map;
+}
+
+
+static void
+sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region)
+{
+ region->map_refcount--;
+}
+
+
+void
+sp_init_region_functions(struct softpipe_context *sp)
+{
+ sp->pipe.region_alloc = sp_region_alloc;
+ sp->pipe.region_release = sp_region_release;
+
+ sp->pipe.region_map = sp_region_map;
+ sp->pipe.region_unmap = sp_region_unmap;
+
+ /* XXX lots of other region functions needed... */
+}
diff --git a/src/mesa/pipe/softpipe/sp_region.h b/src/mesa/pipe/softpipe/sp_region.h
new file mode 100644
index 00000000000..432746b27f1
--- /dev/null
+++ b/src/mesa/pipe/softpipe/sp_region.h
@@ -0,0 +1,40 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#ifndef SP_REGION_H
+#define SP_REGION_H
+
+
+struct softpipe_context;
+
+
+extern void
+sp_init_region_functions(struct softpipe_context *sp);
+
+
+#endif /* SP_REGION_H */
diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c
index 16bbacb12b9..cf89d28941e 100644
--- a/src/mesa/pipe/softpipe/sp_surface.c
+++ b/src/mesa/pipe/softpipe/sp_surface.c
@@ -28,8 +28,22 @@
#include "sp_context.h"
#include "sp_state.h"
#include "sp_surface.h"
-#include "sp_headers.h"
+#include "pipe/p_defines.h"
+#include "main/imports.h"
+
+/**
+ * Softpipe surface functions.
+ * Basically, create surface of a particular type, then plug in default
+ * read/write_quad functions.
+ * Note that these quad funcs assume the buffer/region is in a linear
+ * layout with Y=0=bottom.
+ * If we had swizzled/AOS buffers the read/write functions could be
+ * simplified a lot....
+ */
+
+
+#if 000 /* OLD... should be recycled... */
static void rgba8_read_quad_f( struct softpipe_surface *gs,
GLint x, GLint y,
GLfloat (*rgba)[NUM_CHANNELS] )
@@ -98,9 +112,6 @@ static void rgba8_write_quad_f_swz( struct softpipe_surface *gs,
}
}
-
-
-
static void rgba8_read_quad_ub( struct softpipe_surface *gs,
GLint x, GLint y,
GLubyte (*rgba)[NUM_CHANNELS] )
@@ -118,7 +129,6 @@ static void rgba8_read_quad_ub( struct softpipe_surface *gs,
}
}
-
static void rgba8_write_quad_ub( struct softpipe_surface *gs,
GLint x, GLint y,
GLubyte (*rgba)[NUM_CHANNELS] )
@@ -136,18 +146,216 @@ static void rgba8_write_quad_ub( struct softpipe_surface *gs,
}
}
+#endif
+
+
+
+static void
+z16_read_quad_z(struct softpipe_surface *sps,
+ GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
+{
+ const GLushort *src
+ = (GLushort *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_Z16);
+
+ /* converting GLushort to GLuint: */
+ zzzz[0] = src[0];
+ zzzz[1] = src[1];
+ src += sps->surface.region->pitch;
+ zzzz[2] = src[0];
+ zzzz[3] = src[1];
+}
+
+static void
+z16_write_quad_z(struct softpipe_surface *sps,
+ GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
+{
+ GLushort *dst = (GLushort *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_Z16);
+
+ /* converting GLuint to GLushort: */
+ dst[0] = zzzz[0];
+ dst[1] = zzzz[1];
+ dst += sps->surface.region->pitch;
+ dst[0] = zzzz[2];
+ dst[1] = zzzz[3];
+}
+
+static void
+z32_read_quad_z(struct softpipe_surface *sps,
+ GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
+{
+ const GLuint *src
+ = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_Z32);
+
+ zzzz[0] = src[0];
+ zzzz[1] = src[1];
+ src += sps->surface.region->pitch;
+ zzzz[2] = src[0];
+ zzzz[3] = src[1];
+}
+
+static void
+z32_write_quad_z(struct softpipe_surface *sps,
+ GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
+{
+ GLuint *dst = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_Z32);
+
+ dst[0] = zzzz[0];
+ dst[1] = zzzz[1];
+ dst += sps->surface.region->pitch;
+ dst[0] = zzzz[2];
+ dst[1] = zzzz[3];
+}
+
+static void
+z24s8_read_quad_z(struct softpipe_surface *sps,
+ GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
+{
+ const GLuint *src
+ = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
+
+ zzzz[0] = src[0] >> 8;
+ zzzz[1] = src[1] >> 8;
+ src += sps->surface.region->pitch;
+ zzzz[2] = src[0] >> 8;
+ zzzz[3] = src[1] >> 8;
+}
+
+static void
+z24s8_write_quad_z(struct softpipe_surface *sps,
+ GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
+{
+ GLuint *dst = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
+ assert(zzzz[0] <= 0xffffff);
+
+ dst[0] = (dst[0] & 0xff) | (zzzz[0] << 8);
+ dst[1] = (dst[1] & 0xff) | (zzzz[1] << 8);
+ dst += sps->surface.region->pitch;
+ dst[0] = (dst[0] & 0xff) | (zzzz[2] << 8);
+ dst[1] = (dst[1] & 0xff) | (zzzz[3] << 8);
+}
+
+static void
+z24s8_read_quad_stencil(struct softpipe_surface *sps,
+ GLint x, GLint y, GLubyte ssss[QUAD_SIZE])
+{
+ const GLuint *src
+ = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
+
+ ssss[0] = src[0] & 0xff;
+ ssss[1] = src[1] & 0xff;
+ src += sps->surface.region->pitch;
+ ssss[2] = src[0] & 0xff;
+ ssss[3] = src[1] & 0xff;
+}
+static void
+z24s8_write_quad_stencil(struct softpipe_surface *sps,
+ GLint x, GLint y, const GLubyte ssss[QUAD_SIZE])
+{
+ GLuint *dst = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
+ dst[0] = (dst[0] & 0xffffff00) | ssss[0];
+ dst[1] = (dst[1] & 0xffffff00) | ssss[1];
+ dst += sps->surface.region->pitch;
+ dst[0] = (dst[0] & 0xffffff00) | ssss[2];
+ dst[1] = (dst[1] & 0xffffff00) | ssss[3];
+}
-struct softpipe_surface_type gs_rgba8 = {
- G_SURFACE_RGBA_8888,
- rgba8_read_quad_f,
- rgba8_read_quad_f_swz,
- rgba8_read_quad_ub,
- rgba8_write_quad_f,
- rgba8_write_quad_f_swz,
- rgba8_write_quad_ub,
-};
+static void
+s8_read_quad_stencil(struct softpipe_surface *sps,
+ GLint x, GLint y, GLubyte ssss[QUAD_SIZE])
+{
+ const GLubyte *src
+ = sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_S8);
+
+ ssss[0] = src[0];
+ ssss[1] = src[1];
+ src += sps->surface.region->pitch;
+ ssss[2] = src[0];
+ ssss[3] = src[1];
+}
+
+static void
+s8_write_quad_stencil(struct softpipe_surface *sps,
+ GLint x, GLint y, const GLubyte ssss[QUAD_SIZE])
+{
+ GLubyte *dst
+ = sps->surface.region->map + y * sps->surface.region->pitch + x;
+ assert(sps->surface.format == PIPE_FORMAT_U_S8);
+ dst[0] = ssss[0];
+ dst[1] = ssss[1];
+ dst += sps->surface.region->pitch;
+ dst[0] = ssss[2];
+ dst[1] = ssss[3];
+}
+
+
+
+static void
+init_quad_funcs(struct softpipe_surface *sps)
+{
+ switch (sps->surface.format) {
+ case PIPE_FORMAT_U_Z16:
+ sps->read_quad_z = z16_read_quad_z;
+ sps->write_quad_z = z16_write_quad_z;
+ break;
+ case PIPE_FORMAT_U_Z32:
+ sps->read_quad_z = z32_read_quad_z;
+ sps->write_quad_z = z32_write_quad_z;
+ break;
+ case PIPE_FORMAT_Z24_S8:
+ sps->read_quad_z = z24s8_read_quad_z;
+ sps->write_quad_z = z24s8_write_quad_z;
+ sps->read_quad_stencil = z24s8_read_quad_stencil;
+ sps->write_quad_stencil = z24s8_write_quad_stencil;
+ break;
+ case PIPE_FORMAT_U_S8:
+ sps->read_quad_stencil = s8_read_quad_stencil;
+ sps->write_quad_stencil = s8_write_quad_stencil;
+ break;
+ default:
+ assert(0);
+ }
+}
+
+
+static struct pipe_surface *
+sp_surface_alloc(struct pipe_context *pipe, GLenum format)
+{
+ struct softpipe_surface *sps = CALLOC_STRUCT(softpipe_surface);
+ if (!sps)
+ return NULL;
+
+ sps->surface.format = format;
+ init_quad_funcs(sps);
+
+ return &sps->surface;
+}
+
+
+void
+sp_init_surface_functions(struct softpipe_context *sp)
+{
+ sp->pipe.surface_alloc = sp_surface_alloc;
+}
diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h
index 3ba732cebe4..e8466256dbd 100644
--- a/src/mesa/pipe/softpipe/sp_surface.h
+++ b/src/mesa/pipe/softpipe/sp_surface.h
@@ -35,8 +35,7 @@
#include "sp_headers.h"
struct softpipe_surface;
-
-#define G_SURFACE_RGBA_8888 0x1
+struct softpipe_context;
/**
@@ -98,4 +97,8 @@ softpipe_surface(struct pipe_surface *ps)
}
+extern void
+sp_init_surface_functions(struct softpipe_context *sp);
+
+
#endif /* SP_SURFACE_H */
diff --git a/src/mesa/pipe/softpipe/sp_z_surface.c b/src/mesa/pipe/softpipe/sp_z_surface.c
index 744737cb6c1..7ff1a0cbc84 100644
--- a/src/mesa/pipe/softpipe/sp_z_surface.c
+++ b/src/mesa/pipe/softpipe/sp_z_surface.c
@@ -40,75 +40,35 @@
#include "sp_surface.h"
#include "sp_z_surface.h"
-static void*
-z_map(struct pipe_buffer *pb, GLuint access_mode)
-{
- struct softpipe_surface *sps = (struct softpipe_surface *) pb;
- sps->surface.ptr = pb->ptr;
- sps->surface.stride = sps->surface.width;
- return pb->ptr;
-}
-
-static void
-z_unmap(struct pipe_buffer *pb)
-{
- struct softpipe_surface *sps = (struct softpipe_surface *) pb;
- sps->surface.ptr = NULL;
- sps->surface.stride = 0;
-}
-
-static void
-z_resize(struct pipe_surface *ps, GLuint width, GLuint height)
-{
- struct softpipe_surface *sps = (struct softpipe_surface *) ps;
-
- if (sps->surface.buffer.ptr)
- free(sps->surface.buffer.ptr);
-
- sps->surface.stride = sps->surface.width;
- if (sps->surface.format == PIPE_FORMAT_U_Z16)
- sps->surface.cpp = 2;
- else if (sps->surface.format == PIPE_FORMAT_U_Z32 ||
- sps->surface.format == PIPE_FORMAT_Z24_S8)
- sps->surface.cpp = 4;
- else
- assert(0);
-
- ps->buffer.ptr = (GLubyte *) malloc(width * height * sps->surface.cpp);
- ps->width = width;
- ps->height = height;
-
-}
-
static void
z16_read_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
{
const GLushort *src
- = (GLushort *) sps->surface.ptr + y * sps->surface.stride + x;
+ = (GLushort *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_U_Z16);
/* converting GLushort to GLuint: */
zzzz[0] = src[0];
zzzz[1] = src[1];
- zzzz[2] = src[sps->surface.width + 0];
- zzzz[3] = src[sps->surface.width + 1];
+ zzzz[2] = src[sps->surface.region->pitch + 0];
+ zzzz[3] = src[sps->surface.region->pitch + 1];
}
static void
z16_write_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
{
- GLushort *dst = (GLushort *) sps->surface.ptr + y * sps->surface.stride + x;
+ GLushort *dst = (GLushort *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_U_Z16);
/* converting GLuint to GLushort: */
dst[0] = zzzz[0];
dst[1] = zzzz[1];
- dst[sps->surface.width + 0] = zzzz[2];
- dst[sps->surface.width + 1] = zzzz[3];
+ dst[sps->surface.region->pitch + 0] = zzzz[2];
+ dst[sps->surface.region->pitch + 1] = zzzz[3];
}
static void
@@ -116,28 +76,28 @@ z32_read_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
{
const GLuint *src
- = (GLuint *) sps->surface.ptr + y * sps->surface.stride + x;
+ = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_U_Z32);
zzzz[0] = src[0];
zzzz[1] = src[1];
- zzzz[2] = src[sps->surface.width + 0];
- zzzz[3] = src[sps->surface.width + 1];
+ zzzz[2] = src[sps->surface.region->pitch + 0];
+ zzzz[3] = src[sps->surface.region->pitch + 1];
}
static void
z32_write_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
{
- GLuint *dst = (GLuint *) sps->surface.ptr + y * sps->surface.stride + x;
+ GLuint *dst = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_U_Z32);
dst[0] = zzzz[0];
dst[1] = zzzz[1];
- dst[sps->surface.width + 0] = zzzz[2];
- dst[sps->surface.width + 1] = zzzz[3];
+ dst[sps->surface.region->pitch + 0] = zzzz[2];
+ dst[sps->surface.region->pitch + 1] = zzzz[3];
}
static void
@@ -145,28 +105,28 @@ z24s8_read_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
{
const GLuint *src
- = (GLuint *) sps->surface.ptr + y * sps->surface.stride + x;
+ = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
zzzz[0] = src[0] >> 8;
zzzz[1] = src[1] >> 8;
- zzzz[2] = src[sps->surface.width + 0] >> 8;
- zzzz[3] = src[sps->surface.width + 1] >> 8;
+ zzzz[2] = src[sps->surface.region->pitch + 0] >> 8;
+ zzzz[3] = src[sps->surface.region->pitch + 1] >> 8;
}
static void
z24s8_write_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
{
- GLuint *dst = (GLuint *) sps->surface.ptr + y * sps->surface.stride + x;
+ GLuint *dst = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
assert(zzzz[0] <= 0xffffff);
dst[0] = (dst[0] & 0xff) | (zzzz[0] << 8);
dst[1] = (dst[1] & 0xff) | (zzzz[1] << 8);
- dst += sps->surface.width;
+ dst += sps->surface.region->pitch;
dst[0] = (dst[0] & 0xff) | (zzzz[2] << 8);
dst[1] = (dst[1] & 0xff) | (zzzz[3] << 8);
}
@@ -176,32 +136,65 @@ z24s8_read_quad_stencil(struct softpipe_surface *sps,
GLint x, GLint y, GLubyte ssss[QUAD_SIZE])
{
const GLuint *src
- = (GLuint *) sps->surface.ptr + y * sps->surface.stride + x;
+ = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
ssss[0] = src[0] & 0xff;
ssss[1] = src[1] & 0xff;
- ssss[2] = src[sps->surface.width + 0] & 0xff;
- ssss[3] = src[sps->surface.width + 1] & 0xff;
+ ssss[2] = src[sps->surface.region->pitch + 0] & 0xff;
+ ssss[3] = src[sps->surface.region->pitch + 1] & 0xff;
}
static void
z24s8_write_quad_stencil(struct softpipe_surface *sps,
GLint x, GLint y, const GLubyte ssss[QUAD_SIZE])
{
- GLuint *dst = (GLuint *) sps->surface.ptr + y * sps->surface.stride + x;
+ GLuint *dst = (GLuint *) sps->surface.region->map + y * sps->surface.region->pitch + x;
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
dst[0] = (dst[0] & 0xffffff00) | ssss[0];
dst[1] = (dst[1] & 0xffffff00) | ssss[1];
- dst += sps->surface.width;
+ dst += sps->surface.region->pitch;
dst[0] = (dst[0] & 0xffffff00) | ssss[2];
dst[1] = (dst[1] & 0xffffff00) | ssss[3];
}
+static void
+s8_read_quad_stencil(struct softpipe_surface *sps,
+ GLint x, GLint y, GLubyte ssss[QUAD_SIZE])
+{
+ const GLubyte *src
+ = sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_S8);
+
+ ssss[0] = src[0];
+ ssss[1] = src[1];
+ src += sps->surface.region->pitch;
+ ssss[2] = src[0];
+ ssss[3] = src[1];
+}
+
+static void
+s8_write_quad_stencil(struct softpipe_surface *sps,
+ GLint x, GLint y, const GLubyte ssss[QUAD_SIZE])
+{
+ GLubyte *dst
+ = sps->surface.region->map + y * sps->surface.region->pitch + x;
+
+ assert(sps->surface.format == PIPE_FORMAT_U_S8);
+
+ dst[0] = ssss[0];
+ dst[1] = ssss[1];
+ dst += sps->surface.region->pitch;
+ dst[0] = ssss[2];
+ dst[1] = ssss[3];
+}
+
+
/**
* Create a new software-based Z buffer.
@@ -215,27 +208,6 @@ softpipe_new_z_surface(GLuint format)
return NULL;
sps->surface.format = format;
- sps->surface.resize = z_resize;
- sps->surface.buffer.map = z_map;
- sps->surface.buffer.unmap = z_unmap;
-
- if (format == PIPE_FORMAT_U_Z16) {
- sps->read_quad_z = z16_read_quad_z;
- sps->write_quad_z = z16_write_quad_z;
- }
- else if (format == PIPE_FORMAT_U_Z32) {
- sps->read_quad_z = z32_read_quad_z;
- sps->write_quad_z = z32_write_quad_z;
- }
- else if (format == PIPE_FORMAT_Z24_S8) {
- sps->read_quad_z = z24s8_read_quad_z;
- sps->write_quad_z = z24s8_write_quad_z;
- sps->read_quad_stencil = z24s8_read_quad_stencil;
- sps->write_quad_stencil = z24s8_write_quad_stencil;
- }
- else {
- assert(0);
- }
return sps;
}
diff --git a/src/mesa/sources b/src/mesa/sources
index 32c2ff23500..3b820b71f0e 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -157,6 +157,7 @@ VF_SOURCES = \
SOFTPIPE_SOURCES = \
pipe/softpipe/sp_clear.c \
pipe/softpipe/sp_context.c \
+ pipe/softpipe/sp_region.c \
pipe/softpipe/sp_quad.c \
pipe/softpipe/sp_quad_alpha_test.c \
pipe/softpipe/sp_quad_blend.c \
@@ -176,7 +177,7 @@ SOFTPIPE_SOURCES = \
pipe/softpipe/sp_state_sampler.c \
pipe/softpipe/sp_state_setup.c \
pipe/softpipe/sp_state_surface.c \
- pipe/softpipe/sp_z_surface.c \
+ pipe/softpipe/sp_surface.c \
pipe/softpipe/sp_prim_setup.c
DRAW_SOURCES = \