summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/radeon
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2009-03-19 15:31:03 +1000
committerDave Airlie <airlied@redhat.com>2009-03-19 15:31:03 +1000
commitbdaa0341caffc353fd26bbd91865c2d86eed11c1 (patch)
treee829e2e3ac5571493d90c7d88e54d6f7b4a17b12 /src/mesa/drivers/dri/radeon
parentc0c06803fee4d5cd04da03f1984ae99e411e1588 (diff)
radeon/r200/r300: cleanup some of the renderbuffer code
Diffstat (limited to 'src/mesa/drivers/dri/radeon')
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_common.h19
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_common_context.c114
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_common_context.h2
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_lock.c9
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_screen.c1
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_texstate.c2
6 files changed, 69 insertions, 78 deletions
diff --git a/src/mesa/drivers/dri/radeon/radeon_common.h b/src/mesa/drivers/dri/radeon/radeon_common.h
index 95b718184b..814da1b4f5 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common.h
+++ b/src/mesa/drivers/dri/radeon/radeon_common.h
@@ -30,6 +30,23 @@ void radeonDrawBuffer( GLcontext *ctx, GLenum mode );
void radeonReadBuffer( GLcontext *ctx, GLenum mode );
void radeon_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height);
+static inline struct radeon_renderbuffer *radeon_renderbuffer(struct gl_renderbuffer *rb)
+{
+ struct radeon_renderbuffer *rrb = (struct radeon_renderbuffer *)rb;
+ if (rrb && rrb->base.ClassID == RADEON_RB_CLASS)
+ return rrb;
+ else
+ return NULL;
+}
+
+static inline struct radeon_renderbuffer *radeon_get_renderbuffer(struct gl_framebuffer *fb, int att_index)
+{
+ if (att_index >= 0)
+ return radeon_renderbuffer(fb->Attachment[att_index].Renderbuffer);
+ else
+ return NULL;
+}
+
static inline struct radeon_renderbuffer *radeon_get_depthbuffer(radeonContextPtr rmesa)
{
struct radeon_renderbuffer *rrb;
@@ -47,7 +64,7 @@ static inline struct radeon_renderbuffer *radeon_get_colorbuffer(radeonContextPt
rrb = rmesa->state.color.rrb;
if (rmesa->radeonScreen->driScreen->dri2.enabled) {
- rrb = (struct radeon_renderbuffer *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+ rrb = radeon_get_renderbuffer(&rfb->base, BUFFER_BACK_LEFT);
}
if (!rrb)
return NULL;
diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.c b/src/mesa/drivers/dri/radeon/radeon_common_context.c
index b63aba2f89..a818440faf 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_common_context.c
@@ -183,33 +183,33 @@ void radeonCleanupContext(radeonContextPtr radeon)
_mesa_destroy_context(radeon->glCtx);
rfb = (void*)radeon->dri.drawable->driverPrivate;
- rb = (void *)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+ rb = rfb->color_rb[0];
if (rb && rb->bo) {
radeon_bo_unref(rb->bo);
rb->bo = NULL;
}
- rb = (void *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+ rb = rfb->color_rb[1];
if (rb && rb->bo) {
radeon_bo_unref(rb->bo);
rb->bo = NULL;
}
- rb = (void *)rfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
+ rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
if (rb && rb->bo) {
radeon_bo_unref(rb->bo);
rb->bo = NULL;
}
rfb = (void*)radeon->dri.readable->driverPrivate;
- rb = (void *)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+ rb = rfb->color_rb[0];
if (rb && rb->bo) {
radeon_bo_unref(rb->bo);
rb->bo = NULL;
}
- rb = (void *)rfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+ rb = rfb->color_rb[1];
if (rb && rb->bo) {
radeon_bo_unref(rb->bo);
rb->bo = NULL;
}
- rb = (void *)rfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
+ rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
if (rb && rb->bo) {
radeon_bo_unref(rb->bo);
rb->bo = NULL;
@@ -391,6 +391,7 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
int i, count;
struct radeon_framebuffer *draw;
radeonContextPtr radeon;
+ char *regname;
if (RADEON_DEBUG & DEBUG_DRI)
fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
@@ -399,15 +400,14 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
screen = context->driScreenPriv;
radeon = (radeonContextPtr) context->driverPrivate;
i = 0;
- if ((rb = (void *)draw->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer)) {
+ if (draw->color_rb[0])
attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
- }
- if ((rb = (void *)draw->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer)) {
+ if (draw->color_rb[1])
attachments[i++] = __DRI_BUFFER_BACK_LEFT;
- }
- if ((rb = (void *)draw->base.Attachment[BUFFER_DEPTH].Renderbuffer)) {
+ if (radeon_get_renderbuffer(&draw->base, BUFFER_DEPTH))
attachments[i++] = __DRI_BUFFER_DEPTH;
- }
+ if (radeon_get_renderbuffer(&draw->base, BUFFER_STENCIL))
+ attachments[i++] = __DRI_BUFFER_STENCIL;
buffers = (*screen->dri2.loader->getBuffers)(drawable,
&drawable->w,
@@ -436,64 +436,20 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
for (i = 0; i < count; i++) {
switch (buffers[i].attachment) {
case __DRI_BUFFER_FRONT_LEFT:
- rb = (void *)draw->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
- if (rb->bo) {
- radeon_bo_unref(rb->bo);
- rb->bo = NULL;
- }
- rb->cpp = buffers[i].cpp;
- rb->pitch = buffers[i].pitch;
- rb->width = drawable->w;
- rb->height = drawable->h;
- rb->has_surface = 0;
- rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
- buffers[i].name,
- 0,
- 0,
- RADEON_GEM_DOMAIN_VRAM,
- buffers[i].flags);
- if (rb->bo == NULL) {
- fprintf(stderr, "failled to attach front %d\n",
- buffers[i].name);
- }
+ rb = draw->color_rb[0];
+ regname = "dri2 front buffer";
break;
case __DRI_BUFFER_BACK_LEFT:
- rb = (void *)draw->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
- if (rb->bo) {
- radeon_bo_unref(rb->bo);
- rb->bo = NULL;
- }
- rb->cpp = buffers[i].cpp;
- rb->pitch = buffers[i].pitch;
- rb->width = drawable->w;
- rb->height = drawable->h;
- rb->has_surface = 0;
- rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
- buffers[i].name,
- 0,
- 0,
- RADEON_GEM_DOMAIN_VRAM,
- buffers[i].flags);
+ rb = draw->color_rb[1];
+ regname = "dri2 back buffer";
break;
case __DRI_BUFFER_DEPTH:
- rb = (void *)draw->base.Attachment[BUFFER_DEPTH].Renderbuffer;
- if (rb->bo) {
- radeon_bo_unref(rb->bo);
- rb->bo = NULL;
- }
- rb->cpp = buffers[i].cpp;
- rb->pitch = buffers[i].pitch;
- rb->width = drawable->w;
- rb->height = drawable->h;
- rb->has_surface = 0;
- rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
- buffers[i].name,
- 0,
- 0,
- RADEON_GEM_DOMAIN_VRAM,
- buffers[i].flags);
+ rb = radeon_get_renderbuffer(&draw->base, BUFFER_DEPTH);
+ regname = "dri2 depth buffer";
break;
case __DRI_BUFFER_STENCIL:
+ rb = radeon_get_renderbuffer(&draw->base, BUFFER_DEPTH);
+ regname = "dri2 stencil buffer";
break;
case __DRI_BUFFER_ACCUM:
default:
@@ -502,8 +458,32 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
buffers[i].attachment);
return;
}
+
+ if (rb == NULL)
+ continue;
+
+ if (rb->bo) {
+ radeon_bo_unref(rb->bo);
+ rb->bo = NULL;
+ }
+ rb->cpp = buffers[i].cpp;
+ rb->pitch = buffers[i].pitch;
+ rb->width = drawable->w;
+ rb->height = drawable->h;
+ rb->has_surface = 0;
+ rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+ buffers[i].name,
+ 0,
+ 0,
+ RADEON_GEM_DOMAIN_VRAM,
+ buffers[i].flags);
+ if (rb->bo == NULL) {
+ fprintf(stderr, "failed to attach %s %d\n",
+ regname, buffers[i].name);
+
+ }
}
- radeon = (radeonContextPtr) context->driverPrivate;
+
driUpdateFramebufferSize(radeon->glCtx, drawable);
}
@@ -534,9 +514,9 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
if (driDrawPriv != driReadPriv)
radeon_update_renderbuffers(driContextPriv, driReadPriv);
radeon->state.color.rrb =
- (void *)drfb->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+ radeon_get_renderbuffer(&drfb->base, BUFFER_BACK_LEFT);
radeon->state.depth.rrb =
- (void *)drfb->base.Attachment[BUFFER_DEPTH].Renderbuffer;
+ radeon_get_renderbuffer(&drfb->base, BUFFER_DEPTH);
} else {
radeon_make_renderbuffer_current(radeon, drfb);
}
diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.h b/src/mesa/drivers/dri/radeon/radeon_common_context.h
index 4aeb50fe68..e5ada622b0 100644
--- a/src/mesa/drivers/dri/radeon/radeon_common_context.h
+++ b/src/mesa/drivers/dri/radeon/radeon_common_context.h
@@ -70,6 +70,8 @@ typedef struct radeon_context *radeonContextPtr;
#include "tnl_dd/t_dd_vertex.h"
#undef TAG
+#define RADEON_RB_CLASS 0xdeadbeef
+
struct radeon_renderbuffer
{
struct gl_renderbuffer base;
diff --git a/src/mesa/drivers/dri/radeon/radeon_lock.c b/src/mesa/drivers/dri/radeon/radeon_lock.c
index fb9e5e025e..e1bb2cd6e2 100644
--- a/src/mesa/drivers/dri/radeon/radeon_lock.c
+++ b/src/mesa/drivers/dri/radeon/radeon_lock.c
@@ -90,15 +90,6 @@ void radeonGetLock(radeonContextPtr rmesa, GLuint flags)
rmesa->lost_context = GL_TRUE;
}
-static INLINE struct radeon_renderbuffer *
-radeon_get_renderbuffer(struct gl_framebuffer *fb, int attIndex)
-{
- if (attIndex >= 0)
- return (struct radeon_renderbuffer *)fb->Attachment[attIndex].Renderbuffer;
- else
- return NULL;
-}
-
void radeon_lock_hardware(radeonContextPtr radeon)
{
__DRIdrawable *dPriv = radeon->dri.drawable;
diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c
index e90dffd766..02101978ac 100644
--- a/src/mesa/drivers/dri/radeon/radeon_screen.c
+++ b/src/mesa/drivers/dri/radeon/radeon_screen.c
@@ -1197,6 +1197,7 @@ radeon_create_renderbuffer(GLenum format, __DRIdrawablePrivate *driDrawPriv)
return NULL;
_mesa_init_renderbuffer(&ret->base, 0);
+ ret->base.ClassID = RADEON_RB_CLASS;
/* XXX format junk */
switch (format) {
diff --git a/src/mesa/drivers/dri/radeon/radeon_texstate.c b/src/mesa/drivers/dri/radeon/radeon_texstate.c
index 06771a359b..b9adab18d4 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texstate.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texstate.c
@@ -678,7 +678,7 @@ void radeonSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPri
radeon_bo_unref(rb->bo);
rb->bo = NULL;
}
- rb = (void*)rfb->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+ rb = rfb->color_rb[0];
if (rb->bo == NULL) {
/* Failed to BO for the buffer */
return;