Lots of improvements to the surface-related code.

Z testing now works with i915 driver.
Add gl_renderbuffer::surface pointer (and reverse pointer).
Remove intel_surface and xmesa_surface types - no longer used.
This commit is contained in:
Brian
2007-07-30 17:17:44 -06:00
parent 6558af67d3
commit 4576d754c9
14 changed files with 447 additions and 351 deletions

View File

@@ -289,6 +289,12 @@ intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
rb->Width = width; rb->Width = width;
rb->Height = height; rb->Height = height;
#if 1
/* update the surface's size too */
rb->surface->width = width;
rb->surface->height = height;
#endif
/* This sets the Get/PutRow/Value functions */ /* This sets the Get/PutRow/Value functions */
intel_set_span_functions(&irb->Base); intel_set_span_functions(&irb->Base);
@@ -451,6 +457,12 @@ intel_create_renderbuffer(GLenum intFormat, GLsizei width, GLsizei height,
return irb; return irb;
} }
/**
* Create a new renderbuffer which corresponds to an X window buffer
* (color, depth, stencil, etc) - not a user-created GL renderbuffer.
* The internal format is set at creation time and does not change.
*/
struct gl_renderbuffer * struct gl_renderbuffer *
intel_new_renderbuffer_fb(GLcontext * ctx, GLuint intFormat) intel_new_renderbuffer_fb(GLcontext * ctx, GLuint intFormat)
{ {
@@ -472,6 +484,9 @@ intel_new_renderbuffer_fb(GLcontext * ctx, GLuint intFormat)
irb->Base.GetPointer = intel_get_pointer; irb->Base.GetPointer = intel_get_pointer;
/* span routines set in alloc_storage function */ /* span routines set in alloc_storage function */
irb->Base.surface = intel_new_surface(intFormat);
irb->Base.surface->rb = irb;
return &irb->Base; return &irb->Base;
} }
@@ -500,6 +515,9 @@ intel_new_renderbuffer(GLcontext * ctx, GLuint name)
irb->Base.GetPointer = intel_get_pointer; irb->Base.GetPointer = intel_get_pointer;
/* span routines set in alloc_storage function */ /* span routines set in alloc_storage function */
irb->Base.surface = intel_new_surface(0 /*unknown format*/);
irb->Base.surface->rb = irb;
return &irb->Base; return &irb->Base;
} }

View File

@@ -37,17 +37,6 @@ struct intel_context;
struct intel_region; struct intel_region;
/**
* Intel "pipe" surface. This is kind of a temporary thing as
* renderbuffers and surfaces should eventually become one.
*/
struct intel_surface
{
struct softpipe_surface surface; /**< base class */
struct intel_renderbuffer *rb; /**< ptr back to matching renderbuffer */
};
/** /**
* Intel framebuffer, derived from gl_framebuffer. * Intel framebuffer, derived from gl_framebuffer.
*/ */
@@ -129,5 +118,8 @@ extern struct intel_region *intel_get_rb_region(struct gl_framebuffer *fb,
extern struct pipe_surface *
intel_new_surface(GLuint intFormat);
#endif /* INTEL_FBO_H */ #endif /* INTEL_FBO_H */

View File

@@ -23,27 +23,33 @@
* XXX a lof of this is a temporary kludge * XXX a lof of this is a temporary kludge
*/ */
/**
* Note: the arithmetic/addressing in these functions is a little
* tricky since we need to invert the Y axis.
*/
static void static void
read_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y, read_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rrrr)[QUAD_SIZE]) GLfloat (*rrrr)[QUAD_SIZE])
{ {
struct intel_surface *is = (struct intel_surface *) sps; const GLint bytesPerRow = sps->surface.stride * sps->surface.cpp;
struct intel_renderbuffer *irb = is->rb; const GLint invY = sps->surface.height - y - 1;
const GLubyte *src = (const GLubyte *) irb->region->map const GLubyte *src = sps->surface.ptr + invY * bytesPerRow + x * sps->surface.cpp;
+ (y * irb->region->pitch + x) * irb->region->cpp;
GLfloat *dst = (GLfloat *) rrrr; GLfloat *dst = (GLfloat *) rrrr;
GLubyte temp[16]; GLubyte temp[16];
GLuint i, j; GLuint j;
memcpy(temp, src, 8); assert(sps->surface.format == PIPE_FORMAT_U_A8_R8_G8_B8);
memcpy(temp + 8, src + irb->region->pitch * irb->region->cpp, 8);
for (i = 0; i < 4; i++) { memcpy(temp + 8, src, 8);
for (j = 0; j < 4; j++) { memcpy(temp + 0, src + bytesPerRow, 8);
dst[j * 4 + i] = UBYTE_TO_FLOAT(temp[i * 4 + j]);
} for (j = 0; j < 4; j++) {
dst[0 * 4 + j] = UBYTE_TO_FLOAT(temp[j * 4 + 2]); /*R*/
dst[1 * 4 + j] = UBYTE_TO_FLOAT(temp[j * 4 + 1]); /*G*/
dst[2 * 4 + j] = UBYTE_TO_FLOAT(temp[j * 4 + 0]); /*B*/
dst[3 * 4 + j] = UBYTE_TO_FLOAT(temp[j * 4 + 3]); /*A*/
} }
} }
@@ -52,45 +58,128 @@ static void
write_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y, write_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rrrr)[QUAD_SIZE]) GLfloat (*rrrr)[QUAD_SIZE])
{ {
struct intel_surface *is = (struct intel_surface *) sps;
struct intel_renderbuffer *irb = is->rb;
const GLfloat *src = (const GLfloat *) rrrr; const GLfloat *src = (const GLfloat *) rrrr;
GLubyte *dst = (GLubyte *) irb->region->map const GLint bytesPerRow = sps->surface.stride * sps->surface.cpp;
+ (y * irb->region->pitch + x) * irb->region->cpp; const GLint invY = sps->surface.height - y - 1;
GLubyte *dst = sps->surface.ptr + invY * bytesPerRow + x * sps->surface.cpp;
GLubyte temp[16]; GLubyte temp[16];
GLuint i, j; GLuint j;
for (i = 0; i < 4; i++) { assert(sps->surface.format == PIPE_FORMAT_U_A8_R8_G8_B8);
for (j = 0; j < 4; j++) {
UNCLAMPED_FLOAT_TO_UBYTE(temp[j * 4 + i], src[i * 4 + j]); for (j = 0; j < 4; j++) {
} UNCLAMPED_FLOAT_TO_UBYTE(temp[j * 4 + 2], src[0 * 4 + j]); /*R*/
UNCLAMPED_FLOAT_TO_UBYTE(temp[j * 4 + 1], src[1 * 4 + j]); /*G*/
UNCLAMPED_FLOAT_TO_UBYTE(temp[j * 4 + 0], src[2 * 4 + j]); /*B*/
UNCLAMPED_FLOAT_TO_UBYTE(temp[j * 4 + 3], src[3 * 4 + j]); /*A*/
} }
memcpy(dst, temp, 8); memcpy(dst, temp + 8, 8);
memcpy(dst + irb->region->pitch * irb->region->cpp, temp + 8, 8); memcpy(dst + bytesPerRow, temp + 0, 8);
} }
static void
read_quad_z24(struct softpipe_surface *sps,
GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
{
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);
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;
}
static void
write_quad_z24(struct softpipe_surface *sps,
GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
{
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);
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[0] = (dst[0] & mask) | zzzz[2];
dst[1] = (dst[1] & mask) | zzzz[3];
}
static void
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);
assert(sps->surface.format == PIPE_FORMAT_Z24_S8);
/* extract high byte */
ssss[0] = src[0] >> 24;
ssss[1] = src[1] >> 24;
ssss[2] = src[-sps->surface.width] >> 24;
ssss[3] = src[-sps->surface.width + 1] >> 24;
}
static void
write_quad_stencil(struct softpipe_surface *sps,
GLint x, GLint y, const GLubyte ssss[QUAD_SIZE])
{
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);
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[0] = (dst[0] & mask) | (ssss[2] << 24);
dst[1] = (dst[1] & mask) | (ssss[3] << 24);
}
static void * static void *
map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode) map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode)
{ {
struct intel_surface *is = (struct intel_surface *) pb; struct softpipe_surface *sps = (struct softpipe_surface *) pb;
struct intel_renderbuffer *irb = is->rb; struct intel_renderbuffer *irb = (struct intel_renderbuffer *) sps->surface.rb;
GET_CURRENT_CONTEXT(ctx);
struct intel_context *intel = intel_context(ctx);
assert(access_mode == PIPE_MAP_READ_WRITE); assert(access_mode == PIPE_MAP_READ_WRITE);
intelFinish(&intel->ctx);
/*LOCK_HARDWARE(intel);*/ /*LOCK_HARDWARE(intel);*/
if (irb->region) { if (irb->region) {
GET_CURRENT_CONTEXT(ctx);
struct intel_context *intel = intel_context(ctx);
#if 0
intelFinish(&intel->ctx); /* XXX need this? */
#endif
intel_region_map(intel->intelScreen, irb->region); intel_region_map(intel->intelScreen, irb->region);
} }
pb->ptr = irb->region->map; 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; return pb->ptr;
} }
@@ -98,68 +187,66 @@ map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode)
static void static void
unmap_surface_buffer(struct pipe_buffer *pb) unmap_surface_buffer(struct pipe_buffer *pb)
{ {
struct intel_surface *is = (struct intel_surface *) pb; struct softpipe_surface *sps = (struct softpipe_surface *) pb;
struct intel_renderbuffer *irb = is->rb; struct intel_renderbuffer *irb = (struct intel_renderbuffer *) sps->surface.rb;
GET_CURRENT_CONTEXT(ctx);
struct intel_context *intel = intel_context(ctx);
if (irb->region) { if (irb->region) {
GET_CURRENT_CONTEXT(ctx);
struct intel_context *intel = intel_context(ctx);
intel_region_unmap(intel->intelScreen, irb->region); intel_region_unmap(intel->intelScreen, irb->region);
} }
pb->ptr = NULL; pb->ptr = NULL;
sps->surface.stride = 0;
sps->surface.cpp = 0;
sps->surface.ptr = NULL;
/*UNLOCK_HARDWARE(intel);*/ /*UNLOCK_HARDWARE(intel);*/
} }
struct pipe_surface * struct pipe_surface *
xmesa_get_color_surface(GLcontext *ctx, GLuint i) intel_new_surface(GLuint intFormat)
{ {
struct intel_context *intel = intel_context(ctx); struct softpipe_surface *sps = CALLOC_STRUCT(softpipe_surface);
struct intel_framebuffer *intel_fb; if (!sps)
struct intel_renderbuffer *intel_rb; return NULL;
intel_fb = (struct intel_framebuffer *) ctx->DrawBuffer; sps->surface.width = 0; /* set in intel_alloc_renderbuffer_storage() */
intel_rb = intel_fb->color_rb[1]; sps->surface.height = 0;
if (!intel_rb->surface) { if (intFormat == GL_RGBA8) {
/* create surface and attach to intel_rb */ sps->surface.format = PIPE_FORMAT_U_A8_R8_G8_B8;
struct intel_surface *is; sps->read_quad_f_swz = read_quad_f_swz;
is = CALLOC_STRUCT(intel_surface); sps->write_quad_f_swz = write_quad_f_swz;
if (is) { }
is->surface.surface.width = intel_rb->Base.Width; else if (intFormat == GL_RGB5) {
is->surface.surface.height = intel_rb->Base.Height; sps->surface.format = PIPE_FORMAT_U_R5_G6_B5;
is->surface.read_quad_f_swz = read_quad_f_swz; }
is->surface.write_quad_f_swz = write_quad_f_swz; else if (intFormat == GL_DEPTH_COMPONENT16) {
sps->surface.format = PIPE_FORMAT_U_Z16;
is->surface.surface.buffer.map = map_surface_buffer; }
is->surface.surface.buffer.unmap = unmap_surface_buffer; else if (intFormat == GL_DEPTH24_STENCIL8_EXT) {
sps->surface.format = PIPE_FORMAT_Z24_S8;
is->rb = intel_rb; sps->read_quad_z = read_quad_z24;
} sps->write_quad_z = write_quad_z24;
intel_rb->surface = is; sps->read_quad_stencil = read_quad_stencil;
sps->write_quad_stencil = write_quad_stencil;
} }
else { else {
/* update surface size */ /* TBD / unknown */
struct intel_surface *is = intel_rb->surface;
is->surface.surface.width = intel_rb->Base.Width;
is->surface.surface.height = intel_rb->Base.Height;
/* sanity check */
assert(is->surface.surface.buffer.map == map_surface_buffer);
} }
return &intel_rb->surface->surface.surface; sps->surface.buffer.map = map_surface_buffer;
sps->surface.buffer.unmap = unmap_surface_buffer;
return &sps->surface;
} }
struct pipe_surface *
xmesa_get_z_surface(GLcontext *ctx)
{
/* XXX fix */
return NULL;
}
struct pipe_surface * struct pipe_surface *
xmesa_get_stencil_surface(GLcontext *ctx) xmesa_get_stencil_surface(GLcontext *ctx)

View File

@@ -35,6 +35,7 @@
#include "imports.h" #include "imports.h"
#include "framebuffer.h" #include "framebuffer.h"
#include "renderbuffer.h" #include "renderbuffer.h"
#include "pipe/p_state.h"
#if defined(USE_XSHM) && !defined(XFree86Server) #if defined(USE_XSHM) && !defined(XFree86Server)
@@ -268,6 +269,8 @@ xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->Height = height; rb->Height = height;
rb->InternalFormat = internalFormat; rb->InternalFormat = internalFormat;
rb->surface->resize(rb->surface, width, height);
return GL_TRUE; return GL_TRUE;
} }
@@ -317,6 +320,8 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
xrb->origin4 = NULL; xrb->origin4 = NULL;
} }
rb->surface->resize(rb->surface, width, height);
return GL_TRUE; return GL_TRUE;
} }
@@ -352,6 +357,9 @@ xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual,
xrb->Base.IndexBits = visual->indexBits; xrb->Base.IndexBits = visual->indexBits;
} }
/* only need to set Red/Green/EtcBits fields for user-created RBs */ /* only need to set Red/Green/EtcBits fields for user-created RBs */
xrb->Base.surface = xmesa_new_surface(xrb);
} }
return xrb; return xrb;
} }

View File

@@ -24,7 +24,7 @@
/** /**
* \file xm_surface.h * \file xm_surface.c
* Code to allow the softpipe code to write to X windows/buffers. * Code to allow the softpipe code to write to X windows/buffers.
* This is a bit of a hack for now. We've basically got two different * This is a bit of a hack for now. We've basically got two different
* abstractions for color buffers: gl_renderbuffer and softpipe_surface. * abstractions for color buffers: gl_renderbuffer and softpipe_surface.
@@ -48,31 +48,11 @@
#include "pipe/softpipe/sp_surface.h" #include "pipe/softpipe/sp_surface.h"
/**
* An xm_surface is derived from a softpipe_surface
*/
struct xmesa_surface
{
struct softpipe_surface sps;
struct xmesa_renderbuffer *xrb; /** ptr back to matching xmesa_renderbuffer */
struct gl_renderbuffer *rb; /* ptr to matching gl_renderbuffer */
};
/**
* Cast wrapper
*/
static INLINE struct xmesa_surface *
xmesa_surface(struct softpipe_surface *sps)
{
return (struct xmesa_surface *) sps;
}
static void * static void *
map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode) map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode)
{ {
/* no-op */ /* no-op */
return NULL;
} }
@@ -83,6 +63,13 @@ unmap_surface_buffer(struct pipe_buffer *pb)
} }
static INLINE struct xmesa_renderbuffer *
xmesa_rb(struct softpipe_surface *sps)
{
return (struct xmesa_renderbuffer *) sps->surface.rb;
}
/** /**
* quad reading/writing * quad reading/writing
* These functions are just wrappers around the existing renderbuffer * These functions are just wrappers around the existing renderbuffer
@@ -90,11 +77,10 @@ unmap_surface_buffer(struct pipe_buffer *pb)
*/ */
static void static void
read_quad_f(struct softpipe_surface *gs, GLint x, GLint y, read_quad_f(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rgba)[NUM_CHANNELS]) GLfloat (*rgba)[NUM_CHANNELS])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GLubyte temp[16]; GLubyte temp[16];
GLfloat *dst = (GLfloat *) rgba; GLfloat *dst = (GLfloat *) rgba;
GLuint i; GLuint i;
@@ -107,11 +93,10 @@ read_quad_f(struct softpipe_surface *gs, GLint x, GLint y,
} }
static void static void
read_quad_f_swz(struct softpipe_surface *gs, GLint x, GLint y, read_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rrrr)[QUAD_SIZE]) GLfloat (*rrrr)[QUAD_SIZE])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GLubyte temp[16]; GLubyte temp[16];
GLfloat *dst = (GLfloat *) rrrr; GLfloat *dst = (GLfloat *) rrrr;
GLuint i, j; GLuint i, j;
@@ -126,11 +111,10 @@ read_quad_f_swz(struct softpipe_surface *gs, GLint x, GLint y,
} }
static void static void
write_quad_f(struct softpipe_surface *gs, GLint x, GLint y, write_quad_f(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rgba)[NUM_CHANNELS]) GLfloat (*rgba)[NUM_CHANNELS])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GLubyte temp[16]; GLubyte temp[16];
const GLfloat *src = (const GLfloat *) rgba; const GLfloat *src = (const GLfloat *) rgba;
GLuint i; GLuint i;
@@ -143,11 +127,10 @@ write_quad_f(struct softpipe_surface *gs, GLint x, GLint y,
} }
static void static void
write_quad_f_swz(struct softpipe_surface *gs, GLint x, GLint y, write_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
GLfloat (*rrrr)[QUAD_SIZE]) GLfloat (*rrrr)[QUAD_SIZE])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GLubyte temp[16]; GLubyte temp[16];
const GLfloat *src = (const GLfloat *) rrrr; const GLfloat *src = (const GLfloat *) rrrr;
GLuint i, j; GLuint i, j;
@@ -162,251 +145,70 @@ write_quad_f_swz(struct softpipe_surface *gs, GLint x, GLint y,
} }
static void static void
read_quad_ub(struct softpipe_surface *gs, GLint x, GLint y, read_quad_ub(struct softpipe_surface *sps, GLint x, GLint y,
GLubyte (*rgba)[NUM_CHANNELS]) GLubyte (*rgba)[NUM_CHANNELS])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y, rgba); xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y, rgba);
xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, rgba + 2); xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, rgba + 2);
} }
static void static void
write_quad_ub(struct softpipe_surface *gs, GLint x, GLint y, write_quad_ub(struct softpipe_surface *sps, GLint x, GLint y,
GLubyte (*rgba)[NUM_CHANNELS]) GLubyte (*rgba)[NUM_CHANNELS])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y, rgba); xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y, rgba);
xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, rgba + 2); xrb->Base.GetRow(ctx, &xrb->Base, 2, x, y + 1, rgba + 2);
} }
static void static void
write_mono_row_ub(struct softpipe_surface *gs, GLuint count, GLint x, GLint y, write_mono_row_ub(struct softpipe_surface *sps, GLuint count, GLint x, GLint y,
GLubyte rgba[NUM_CHANNELS]) GLubyte rgba[NUM_CHANNELS])
{ {
struct xmesa_surface *xmsurf = xmesa_surface(gs); struct xmesa_renderbuffer *xrb = xmesa_rb(sps);
struct xmesa_renderbuffer *xrb = xmsurf->xrb;
GET_CURRENT_CONTEXT(ctx); GET_CURRENT_CONTEXT(ctx);
xrb->Base.PutMonoRow(ctx, &xrb->Base, count, x, y, rgba, NULL); xrb->Base.PutMonoRow(ctx, &xrb->Base, count, x, y, rgba, NULL);
} }
static struct xmesa_surface *
create_surface(XMesaContext xmctx, struct xmesa_renderbuffer *xrb)
{
struct xmesa_surface *xmsurf;
xmsurf = CALLOC_STRUCT(xmesa_surface);
if (xmsurf) {
xmsurf->xrb = xrb;
xmsurf->sps.surface.width = xrb->Base.Width;
xmsurf->sps.surface.height = xrb->Base.Height;
xmsurf->sps.read_quad_f = read_quad_f;
xmsurf->sps.read_quad_f_swz = read_quad_f_swz;
xmsurf->sps.read_quad_ub = read_quad_ub;
xmsurf->sps.write_quad_f = write_quad_f;
xmsurf->sps.write_quad_f_swz = write_quad_f_swz;
xmsurf->sps.write_quad_ub = write_quad_ub;
xmsurf->sps.write_mono_row_ub = write_mono_row_ub;
xmsurf->sps.surface.buffer.map = map_surface_buffer;
xmsurf->sps.surface.buffer.unmap = unmap_surface_buffer;
#if 0
if (xrb->ximage) {
xmsurf->sps.surface.ptr = (GLubyte *) xrb->ximage->data;
xmsurf->sps.surface.stride = xrb->ximage->bytes_per_line;
xmsurf->sps.surface.cpp = xrb->ximage->depth;
}
#endif
}
return xmsurf;
}
static void static void
free_surface(struct softpipe_surface *sps) resize_surface(struct pipe_surface *ps, GLuint width, GLuint height)
{ {
/* XXX may need to do more in the future */ ps->width = width;
free(sps); ps->height = height;
} }
/** /**
* Return generic surface pointer corresponding to the current color buffer. * Called to create a pipe_surface for each X renderbuffer.
*/ */
struct pipe_surface * struct pipe_surface *
xmesa_get_color_surface(GLcontext *ctx, GLuint buf) xmesa_new_surface(struct xmesa_renderbuffer *xrb)
{ {
XMesaContext xmctx = XMESA_CONTEXT(ctx); struct softpipe_surface *sps;
struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][buf];
struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
struct softpipe_surface *sps = (struct softpipe_surface *) xrb->pSurface;
if (!sps) { sps = CALLOC_STRUCT(softpipe_surface);
xrb->pSurface = create_surface(xmctx, xrb); if (!sps)
}
else if (sps->surface.width != rb->Width ||
sps->surface.height != rb->Height) {
free_surface(sps);
xrb->pSurface = create_surface(xmctx, xrb);
}
return (struct pipe_surface *) xrb->pSurface;
}
static void
read_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, GLuint zzzz[QUAD_SIZE])
{
struct xmesa_surface *xmsurf = xmesa_surface(sps);
struct gl_renderbuffer *rb = xmsurf->rb;
GLushort temp[4];
GLuint i;
GET_CURRENT_CONTEXT(ctx);
rb->GetRow(ctx, rb, 2, x, y, temp);
rb->GetRow(ctx, rb, 2, x, y + 1, temp + 2);
/* convert from GLushort to GLuint */
for (i = 0; i < 4; i++) {
zzzz[i] = temp[i];
}
}
static void
write_quad_z(struct softpipe_surface *sps,
GLint x, GLint y, const GLuint zzzz[QUAD_SIZE])
{
struct xmesa_surface *xmsurf = xmesa_surface(sps);
struct gl_renderbuffer *rb = xmsurf->rb;
GLushort temp[4];
GLuint i;
GET_CURRENT_CONTEXT(ctx);
/* convert from GLuint to GLushort */
for (i = 0; i < 4; i++) {
temp[i] = zzzz[i];
}
rb->PutRow(ctx, rb, 2, x, y, temp, NULL);
rb->PutRow(ctx, rb, 2, x, y + 1, temp + 2, NULL);
}
static struct xmesa_surface *
create_z_surface(XMesaContext xmctx, struct gl_renderbuffer *rb)
{
struct xmesa_surface *xmsurf;
xmsurf = CALLOC_STRUCT(xmesa_surface);
if (xmsurf) {
xmsurf->sps.surface.format = PIPE_FORMAT_U_Z16;
xmsurf->sps.surface.width = rb->Width;
xmsurf->sps.surface.height = rb->Height;
xmsurf->sps.read_quad_z = read_quad_z;
xmsurf->sps.write_quad_z = write_quad_z;
xmsurf->rb = rb;
}
return xmsurf;
}
static void
read_quad_stencil(struct softpipe_surface *sps,
GLint x, GLint y, GLubyte ssss[QUAD_SIZE])
{
struct xmesa_surface *xmsurf = xmesa_surface(sps);
struct gl_renderbuffer *rb = xmsurf->rb;
GET_CURRENT_CONTEXT(ctx);
rb->GetRow(ctx, rb, 2, x, y, ssss);
rb->GetRow(ctx, rb, 2, x, y + 1, ssss + 2);
}
static void
write_quad_stencil(struct softpipe_surface *sps,
GLint x, GLint y, const GLubyte ssss[QUAD_SIZE])
{
struct xmesa_surface *xmsurf = xmesa_surface(sps);
struct gl_renderbuffer *rb = xmsurf->rb;
GET_CURRENT_CONTEXT(ctx);
rb->PutRow(ctx, rb, 2, x, y, ssss, NULL);
rb->PutRow(ctx, rb, 2, x, y + 1, ssss + 2, NULL);
}
static struct xmesa_surface *
create_stencil_surface(XMesaContext xmctx, struct gl_renderbuffer *rb)
{
struct xmesa_surface *xmsurf;
xmsurf = CALLOC_STRUCT(xmesa_surface);
if (xmsurf) {
xmsurf->sps.surface.format = PIPE_FORMAT_U_S8;
xmsurf->sps.surface.width = rb->Width;
xmsurf->sps.surface.height = rb->Height;
xmsurf->sps.read_quad_stencil = read_quad_stencil;
xmsurf->sps.write_quad_stencil = write_quad_stencil;
xmsurf->rb = rb;
}
return xmsurf;
}
/**
* Return a pipe_surface that wraps the current Z/depth buffer.
* XXX this is pretty much a total hack until gl_renderbuffers and
* pipe_surfaces are merged...
*/
struct pipe_surface *
xmesa_get_z_surface(GLcontext *ctx)
{
XMesaContext xmctx = XMESA_CONTEXT(ctx);
struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer;
static struct xmesa_surface *xms = NULL;
if (!rb)
return NULL; return NULL;
if (!xms) { sps->surface.rb = xrb;
xms = create_z_surface(xmctx, rb); sps->surface.width = xrb->Base.Width;
} sps->surface.height = xrb->Base.Height;
else if (xms->sps.surface.width != rb->Width ||
xms->sps.surface.height != rb->Height) {
free_surface(&xms->sps);
xms = create_z_surface(xmctx, rb);
}
return (struct pipe_surface *) &xms->sps.surface; sps->read_quad_f = read_quad_f;
sps->read_quad_f_swz = read_quad_f_swz;
sps->read_quad_ub = read_quad_ub;
sps->write_quad_f = write_quad_f;
sps->write_quad_f_swz = write_quad_f_swz;
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;
return &sps->surface;
} }
struct pipe_surface *
xmesa_get_stencil_surface(GLcontext *ctx)
{
XMesaContext xmctx = XMESA_CONTEXT(ctx);
struct gl_renderbuffer *rb = ctx->DrawBuffer->_StencilBuffer;
static struct xmesa_surface *xms = NULL;
if (!rb)
return NULL;
if (!xms) {
xms = create_stencil_surface(xmctx, rb);
}
else if (xms->sps.surface.width != rb->Width ||
xms->sps.surface.height != rb->Height) {
free_surface(&xms->sps);
xms = create_stencil_surface(xmctx, rb);
}
return (struct pipe_surface *) &xms->sps.surface;
}

View File

@@ -585,23 +585,11 @@ extern void xmesa_register_swrast_functions( GLcontext *ctx );
#define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */ #define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */
#endif #endif
#if 0
GLboolean xmesa_get_cbuf_details( GLcontext *ctx,
void **ptr,
GLuint *cpp,
GLint *stride,
GLuint *format );
#endif
struct pipe_surface; struct pipe_surface;
struct pipe_surface *
xmesa_get_color_surface(GLcontext *ctx, GLuint buf);
struct pipe_surface * struct pipe_surface *
xmesa_get_z_surface(GLcontext *ctx); xmesa_new_surface(struct xmesa_renderbuffer *xrb);
struct pipe_surface *
xmesa_get_stencil_surface(GLcontext *ctx);
#endif #endif

View File

@@ -127,6 +127,7 @@ struct gl_texture_format;
struct gl_texture_image; struct gl_texture_image;
struct gl_texture_object; struct gl_texture_object;
struct st_context; struct st_context;
struct pipe_surface;
typedef struct __GLcontextRec GLcontext; typedef struct __GLcontextRec GLcontext;
typedef struct __GLcontextModesRec GLvisual; typedef struct __GLcontextModesRec GLvisual;
typedef struct gl_framebuffer GLframebuffer; typedef struct gl_framebuffer GLframebuffer;
@@ -2268,6 +2269,8 @@ struct gl_renderbuffer
GLubyte StencilBits; GLubyte StencilBits;
GLvoid *Data; /**< This may not be used by some kinds of RBs */ GLvoid *Data; /**< This may not be used by some kinds of RBs */
struct pipe_surface *surface;
/* Used to wrap one renderbuffer around another: */ /* Used to wrap one renderbuffer around another: */
struct gl_renderbuffer *Wrapped; struct gl_renderbuffer *Wrapped;

View File

@@ -49,6 +49,9 @@
#include "rbadaptors.h" #include "rbadaptors.h"
#include "pipe/softpipe/sp_z_surface.h"
#include "pipe/p_state.h"
/* 32-bit color index format. Not a public format. */ /* 32-bit color index format. Not a public format. */
#define COLOR_INDEX32 0x424243 #define COLOR_INDEX32 0x424243
@@ -1091,6 +1094,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
rb->PutValues = put_values_ushort; rb->PutValues = put_values_ushort;
rb->PutMonoValues = put_mono_values_ushort; rb->PutMonoValues = put_mono_values_ushort;
rb->DepthBits = 8 * sizeof(GLushort); rb->DepthBits = 8 * sizeof(GLushort);
rb->surface = (struct pipe_surface *) softpipe_new_z_surface(16);
pixelSize = sizeof(GLushort); pixelSize = sizeof(GLushort);
break; break;
case GL_DEPTH_COMPONENT24: case GL_DEPTH_COMPONENT24:
@@ -1193,13 +1197,27 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
/* free old buffer storage */ /* free old buffer storage */
if (rb->Data) { if (rb->Data) {
_mesa_free(rb->Data); if (rb->surface) {
/* pipe surface */
}
else {
/* legacy renderbuffer */
_mesa_free(rb->Data);
}
rb->Data = NULL; rb->Data = NULL;
} }
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
/* allocate new buffer storage */ /* allocate new buffer storage */
rb->Data = _mesa_malloc(width * height * pixelSize); if (rb->surface) {
/* pipe surface */
rb->surface->resize(rb->surface, width, height);
rb->Data = rb->surface->buffer.ptr;
}
else {
/* legacy renderbuffer */
rb->Data = _mesa_malloc(width * height * pixelSize);
}
if (rb->Data == NULL) { if (rb->Data == NULL) {
rb->Width = 0; rb->Width = 0;
rb->Height = 0; rb->Height = 0;

View File

@@ -239,6 +239,7 @@ struct pipe_sampler_state
/** /**
* A mappable buffer (vertex data, pixel data, etc) * A mappable buffer (vertex data, pixel data, etc)
* XXX replace with "intel_region".
*/ */
struct pipe_buffer struct pipe_buffer
{ {
@@ -247,7 +248,7 @@ struct pipe_buffer
const void *src); const void *src);
void *(*map)(struct pipe_buffer *pb, GLuint access_mode); void *(*map)(struct pipe_buffer *pb, GLuint access_mode);
void (*unmap)(struct pipe_buffer *pb); void (*unmap)(struct pipe_buffer *pb);
void *ptr; /**< address, only valid while mapped */ GLubyte *ptr; /**< address, only valid while mapped */
GLuint mode; /**< PIPE_MAP_x, only valid while mapped */ GLuint mode; /**< PIPE_MAP_x, only valid while mapped */
}; };
@@ -261,12 +262,13 @@ struct pipe_surface
struct pipe_buffer buffer; /**< surfaces can be mapped */ struct pipe_buffer buffer; /**< surfaces can be mapped */
GLuint format:5; /**< PIPE_FORMAT_x */ GLuint format:5; /**< PIPE_FORMAT_x */
GLuint width, height; GLuint width, height;
#if 0
GLubyte *ptr; GLint stride, cpp;
GLint stride; GLubyte *ptr; /**< only valid while mapped, may not equal buffer->ptr */
GLuint cpp;
GLuint format; void *rb; /**< Ptr back to renderbuffer (temporary?) */
#endif
void (*resize)(struct pipe_surface *ps, GLuint width, GLuint height);
}; };

View File

@@ -49,6 +49,13 @@ static void map_surfaces(struct softpipe_context *sp)
struct pipe_buffer *buf = &sps->surface.buffer; struct pipe_buffer *buf = &sps->surface.buffer;
buf->map(buf, PIPE_MAP_READ_WRITE); buf->map(buf, PIPE_MAP_READ_WRITE);
} }
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);
}
/* XXX depth & stencil bufs */ /* XXX depth & stencil bufs */
} }
@@ -62,6 +69,12 @@ static void unmap_surfaces(struct softpipe_context *sp)
struct pipe_buffer *buf = &sps->surface.buffer; struct pipe_buffer *buf = &sps->surface.buffer;
buf->unmap(buf); buf->unmap(buf);
} }
if (sp->framebuffer.zbuf) {
struct softpipe_surface *sps = softpipe_surface(sp->framebuffer.zbuf);
struct pipe_buffer *buf = &sps->surface.buffer;
buf->unmap(buf);
}
/* XXX depth & stencil bufs */ /* XXX depth & stencil bufs */
} }

View File

@@ -0,0 +1,118 @@
/**************************************************************************
*
* Copyright 2003 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 Z buffer/surface.
*
* \author Brian Paul
*/
#include "main/imports.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "sp_surface.h"
#include "sp_z_surface.h"
static void*
z16_map(struct pipe_buffer *pb, GLuint access_mode)
{
struct softpipe_surface *sps = (struct softpipe_surface *) pb;
sps->surface.ptr = pb->ptr;
return pb->ptr;
}
static void
z16_unmap(struct pipe_buffer *pb)
{
struct softpipe_surface *sps = (struct softpipe_surface *) pb;
sps->surface.ptr = NULL;
}
static void
z16_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);
ps->buffer.ptr = (GLubyte *) malloc(width * height * sizeof(GLushort));
ps->width = width;
ps->height = height;
sps->surface.stride = sps->surface.width;
sps->surface.cpp = 2;
}
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;
/* converting GLushort to GLuint: */
zzzz[0] = src[0];
zzzz[1] = src[1];
zzzz[2] = src[sps->surface.width];
zzzz[3] = src[sps->surface.width + 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;
/* converting GLuint to GLushort: */
dst[0] = zzzz[0];
dst[1] = zzzz[1];
dst[sps->surface.width] = zzzz[2];
dst[sps->surface.width + 1] = zzzz[3];
}
struct softpipe_surface *
softpipe_new_z_surface(GLuint depth)
{
struct softpipe_surface *sps = CALLOC_STRUCT(softpipe_surface);
if (!sps)
return NULL;
/* XXX ignoring depth param for now */
sps->surface.format = PIPE_FORMAT_U_Z16;
sps->surface.resize = z16_resize;
sps->surface.buffer.map = z16_map;
sps->surface.buffer.unmap = z16_unmap;
sps->read_quad_z = z16_read_quad_z;
sps->write_quad_z = z16_write_quad_z;
return sps;
}

View File

@@ -0,0 +1,37 @@
/**************************************************************************
*
* Copyright 2003 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_Z_SURFACE_H
#define SP_Z_SURFACE_H
extern struct softpipe_surface *
softpipe_new_z_surface(GLuint depth);
#endif /* SP_Z_SURFACE_H */

View File

@@ -176,6 +176,7 @@ SOFTPIPE_SOURCES = \
pipe/softpipe/sp_state_sampler.c \ pipe/softpipe/sp_state_sampler.c \
pipe/softpipe/sp_state_setup.c \ pipe/softpipe/sp_state_setup.c \
pipe/softpipe/sp_state_surface.c \ pipe/softpipe/sp_state_surface.c \
pipe/softpipe/sp_z_surface.c \
pipe/softpipe/sp_prim_setup.c pipe/softpipe/sp_prim_setup.c
DRAW_SOURCES = \ DRAW_SOURCES = \

View File

@@ -54,22 +54,31 @@ static void
update_framebuffer_state( struct st_context *st ) update_framebuffer_state( struct st_context *st )
{ {
struct pipe_framebuffer_state framebuffer; struct pipe_framebuffer_state framebuffer;
struct gl_renderbuffer *rb;
GLuint i; GLuint i;
memset(&framebuffer, 0, sizeof(framebuffer));
/* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
* to determine which surfaces to draw to * to determine which surfaces to draw to
*/ */
framebuffer.num_cbufs = st->ctx->DrawBuffer->_NumColorDrawBuffers[0]; framebuffer.num_cbufs = st->ctx->DrawBuffer->_NumColorDrawBuffers[0];
for (i = 0; i < framebuffer.num_cbufs; i++) { for (i = 0; i < framebuffer.num_cbufs; i++) {
framebuffer.cbufs[i] = xmesa_get_color_surface(st->ctx, i); rb = st->ctx->DrawBuffer->_ColorDrawBuffers[0][i];
assert(rb->surface);
framebuffer.cbufs[i] = rb->surface;
} }
if (st->ctx->DrawBuffer->_DepthBuffer/*Attachment[BUFFER_DEPTH].Renderbuffer*/) { rb = st->ctx->DrawBuffer->_DepthBuffer;
framebuffer.zbuf = xmesa_get_z_surface(st->ctx); if (rb) {
assert(rb->surface);
framebuffer.zbuf = rb->Wrapped->surface;
} }
if (st->ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer) { rb = st->ctx->DrawBuffer->_StencilBuffer;
framebuffer.sbuf = xmesa_get_stencil_surface(st->ctx); if (rb) {
assert(rb->surface);
framebuffer.sbuf = rb->Wrapped->surface;
} }
if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) { if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) {