Simplfy clear() and swapbuffers() code.

Fix various mishandling of cliprects.
Allow multiple primitives to be emitted to a single dma buffer, which
was largely impossible previously.
Re-enable the fast unclipped render stage.
This commit is contained in:
Keith Whitwell 2004-12-29 20:46:27 +00:00
parent ef494c06b6
commit 490e764d7a
10 changed files with 835 additions and 1225 deletions

View File

@ -68,39 +68,7 @@
#ifdef DEBUG
GLuint VIA_DEBUG = 0;
#endif
#define DMA_SIZE 2
/*=* John Sheng [2003.5.31] agp tex *=*/
static GLboolean
AllocateBuffer(viaContextPtr vmesa)
{
vmesa->front_base = vmesa->driScreen->pFB;
if (vmesa->drawType == GLX_PBUFFER_BIT) {
if (vmesa->front.map)
via_free_front_buffer(vmesa);
if (!via_alloc_front_buffer(vmesa))
return GL_FALSE;
}
if (vmesa->hasBack) {
if (vmesa->back.map)
via_free_back_buffer(vmesa);
if (!via_alloc_back_buffer(vmesa))
return GL_FALSE;
}
if (vmesa->hasDepth || vmesa->hasStencil) {
if (vmesa->depth.map)
via_free_depth_buffer(vmesa);
if (!via_alloc_depth_buffer(vmesa)) {
via_free_depth_buffer(vmesa);
return GL_FALSE;
}
}
return GL_TRUE;
}
/**
* Return various strings for \c glGetString.
@ -169,79 +137,92 @@ buffer_align( unsigned width )
static GLboolean
calculate_buffer_parameters( viaContextPtr vmesa )
{
const unsigned shift = vmesa->viaScreen->bitsPerPixel / 16;
const unsigned extra = (vmesa->drawType == GLX_PBUFFER_BIT) ? 0 : 32;
unsigned w;
unsigned h;
const unsigned shift = vmesa->viaScreen->bitsPerPixel / 16;
const unsigned extra = 32;
unsigned w;
unsigned h;
if (vmesa->drawType == GLX_PBUFFER_BIT) {
w = vmesa->driDrawable->w;
h = vmesa->driDrawable->h;
}
else {
w = vmesa->viaScreen->width;
h = vmesa->viaScreen->height;
/* Allocate front-buffer */
if (vmesa->drawType == GLX_PBUFFER_BIT) {
w = vmesa->driDrawable->w;
h = vmesa->driDrawable->h;
vmesa->front.offset = 0;
vmesa->front.map = (char *) vmesa->driScreen->pFB;
}
vmesa->front.bpp = vmesa->viaScreen->bitsPerPixel;
vmesa->front.pitch = buffer_align( w ) << shift;
vmesa->front.size = vmesa->front.pitch * h;
vmesa->front.pitch = buffer_align( w ) << shift;
vmesa->front.size = vmesa->front.pitch * h;
if (vmesa->front.map)
via_free_draw_buffer(vmesa, &vmesa->front);
if (!via_alloc_draw_buffer(vmesa, &vmesa->front))
return GL_FALSE;
}
else {
w = vmesa->viaScreen->width;
h = vmesa->viaScreen->height;
vmesa->front.bpp = vmesa->viaScreen->bitsPerPixel;
vmesa->front.pitch = buffer_align( w ) << shift;
vmesa->front.size = vmesa->front.pitch * h;
vmesa->front.offset = 0;
vmesa->front.map = (char *) vmesa->driScreen->pFB;
}
/* Allocate back-buffer */
/* Allocate back-buffer */
if (vmesa->hasBack) {
vmesa->back.bpp = vmesa->viaScreen->bitsPerPixel;
vmesa->back.pitch = (buffer_align( vmesa->driDrawable->w ) << shift) + extra;
vmesa->back.size = vmesa->back.pitch * vmesa->driDrawable->h;
if (vmesa->back.map)
via_free_draw_buffer(vmesa, &vmesa->back);
if (!via_alloc_draw_buffer(vmesa, &vmesa->back))
return GL_FALSE;
}
else {
/* KW: mem leak if vmesa->hasBack ever changes:
*/
(void) memset( &vmesa->back, 0, sizeof( vmesa->back ) );
}
vmesa->back.pitch = (buffer_align( vmesa->driDrawable->w ) << shift)
+ extra;
vmesa->back.size = vmesa->back.pitch * vmesa->driDrawable->h;
if (VIA_DEBUG) fprintf(stderr, "%s backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
__FUNCTION__,
vmesa->back.pitch,
vmesa->driDrawable->h,
8 << shift,
vmesa->back.size);
/* Allocate depth-buffer */
if ( vmesa->hasStencil || vmesa->hasDepth ) {
vmesa->depth.bpp = vmesa->depthBits;
if (vmesa->depth.bpp == 24)
vmesa->depth.bpp = 32;
/* Allocate depth-buffer */
if ( vmesa->hasStencil || vmesa->hasDepth ) {
vmesa->depth.bpp = vmesa->depthBits;
if (vmesa->depth.bpp == 24)
vmesa->depth.bpp = 32;
vmesa->depth.pitch = (buffer_align( vmesa->driDrawable->w ) * (vmesa->depth.bpp/8)) + extra;
vmesa->depth.size = vmesa->depth.pitch * vmesa->driDrawable->h;
vmesa->depth.pitch = (buffer_align( vmesa->driDrawable->w ) * (vmesa->depth.bpp/8)) + extra;
vmesa->depth.size = vmesa->depth.pitch * vmesa->driDrawable->h;
}
else {
(void) memset( & vmesa->depth, 0, sizeof( vmesa->depth ) );
}
if (vmesa->depth.map)
via_free_draw_buffer(vmesa, &vmesa->depth);
if (!via_alloc_draw_buffer(vmesa, &vmesa->depth)) {
return GL_FALSE;
}
}
else {
/* KW: mem leak if vmesa->hasStencil/hasDepth ever changes:
*/
(void) memset( & vmesa->depth, 0, sizeof( vmesa->depth ) );
}
if (VIA_DEBUG) fprintf(stderr, "%s depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
__FUNCTION__,
vmesa->depth.pitch,
vmesa->driDrawable->h,
vmesa->depth.bpp,
vmesa->depth.size);
/*=* John Sheng [2003.5.31] flip *=*/
if( vmesa->viaScreen->width == vmesa->driDrawable->w &&
vmesa->viaScreen->height == vmesa->driDrawable->h ) {
/*=* John Sheng [2003.5.31] flip *=*/
if( vmesa->viaScreen->width == vmesa->driDrawable->w &&
vmesa->viaScreen->height == vmesa->driDrawable->h ) {
#define ALLOW_EXPERIMENTAL_PAGEFLIP 0
#if ALLOW_EXPERIMENTAL_PAGEFLIP
vmesa->doPageFlip = GL_TRUE;
vmesa->doPageFlip = GL_TRUE;
#else
vmesa->doPageFlip = GL_FALSE;
vmesa->doPageFlip = GL_FALSE;
#endif
vmesa->currentPage = 0;
vmesa->back.pitch = vmesa->front.pitch;
}
/* vmesa->currentPage = 0; */
assert(vmesa->back.pitch == vmesa->front.pitch);
}
else
vmesa->doPageFlip = GL_FALSE;
if (!AllocateBuffer(vmesa)) {
FREE(vmesa);
return GL_FALSE;
}
return GL_TRUE;
return GL_TRUE;
}
@ -250,20 +231,8 @@ void viaReAllocateBuffers(GLframebuffer *drawbuffer)
GET_CURRENT_CONTEXT(ctx);
viaContextPtr vmesa = VIA_CONTEXT(ctx);
ctx->DrawBuffer->Width = drawbuffer->Width;
ctx->DrawBuffer->Height = drawbuffer->Height;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
ctx->DrawBuffer->Accum = 0;
vmesa->driDrawable->w = ctx->DrawBuffer->Width;
vmesa->driDrawable->h = ctx->DrawBuffer->Height;
LOCK_HARDWARE(vmesa);
_swrast_alloc_buffers( drawbuffer );
calculate_buffer_parameters( vmesa );
UNLOCK_HARDWARE(vmesa);
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
}
static void viaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
@ -303,9 +272,7 @@ static const struct tnl_pipeline_stage *via_pipeline[] = {
&_tnl_texgen_stage,
&_tnl_texture_transform_stage,
/* REMOVE: point attenuation stage */
#if 0
&_via_fastrender_stage, /* ADD: unclipped rastersetup-to-dma */
#endif
&_tnl_render_stage,
0,
};
@ -314,39 +281,14 @@ static const struct tnl_pipeline_stage *via_pipeline[] = {
static GLboolean
AllocateDmaBuffer(const GLvisual *visual, viaContextPtr vmesa)
{
GLuint *addr;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
if (vmesa->dma)
via_free_dma_buffer(vmesa);
if (!via_alloc_dma_buffer(vmesa)) {
if (vmesa->front.map)
via_free_front_buffer(vmesa);
if (vmesa->back.map)
via_free_back_buffer(vmesa);
if (vmesa->depth.map)
via_free_depth_buffer(vmesa);
if (!via_alloc_dma_buffer(vmesa))
return GL_FALSE;
}
/* Insert placeholder for a cliprect:
*/
addr = (GLuint *)vmesa->dma;
addr[0] = HC_HEADER2;
addr[1] = (HC_ParaType_NotTex << 16);
addr[2] = HC_DUMMY;
addr[3] = HC_DUMMY;
addr[4] = HC_DUMMY;
addr[5] = HC_DUMMY;
addr[6] = HC_DUMMY;
addr[7] = HC_DUMMY;
vmesa->dmaLow = DMA_OFFSET;
vmesa->dmaAddr = (unsigned char *)vmesa->dma;
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
vmesa->dmaLow = 0;
vmesa->dmaCliprectAddr = 0;
return GL_TRUE;
}
@ -354,13 +296,13 @@ static void
FreeBuffer(viaContextPtr vmesa)
{
if (vmesa->front.map)
via_free_front_buffer(vmesa);
via_free_draw_buffer(vmesa, &vmesa->front);
if (vmesa->back.map)
via_free_back_buffer(vmesa);
via_free_draw_buffer(vmesa, &vmesa->back);
if (vmesa->depth.map)
via_free_depth_buffer(vmesa);
via_free_draw_buffer(vmesa, &vmesa->depth);
if (vmesa->dma)
via_free_dma_buffer(vmesa);
@ -536,6 +478,7 @@ viaCreateContext(const __GLcontextModes *mesaVis,
*/
if (!AllocateDmaBuffer(mesaVis, vmesa)) {
fprintf(stderr ,"AllocateDmaBuffer fail\n");
FreeBuffer(vmesa);
FREE(vmesa);
return GL_FALSE;
}
@ -576,7 +519,7 @@ viaCreateContext(const __GLcontextModes *mesaVis,
if ( vmesa->get_ust == NULL ) {
vmesa->get_ust = get_ust_nop;
}
(*vmesa->get_ust)( & vmesa->swap_ust );
vmesa->get_ust( &vmesa->swap_ust );
vmesa->regMMIOBase = (GLuint *)((GLuint)viaScreen->reg);
@ -620,64 +563,59 @@ viaDestroyContext(__DRIcontextPrivate *driContextPriv)
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
}
void viaXMesaSetFrontClipRects(viaContextPtr vmesa)
{
__DRIdrawablePrivate *dPriv = vmesa->driDrawable;
if (!dPriv)
return;
vmesa->numClipRects = dPriv->numClipRects;
vmesa->pClipRects = dPriv->pClipRects;
vmesa->drawX = dPriv->x;
vmesa->drawY = dPriv->y;
vmesa->drawW = dPriv->w;
vmesa->drawH = dPriv->h;
{
GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
vmesa->drawXoff = (GLuint)(((vmesa->drawX * bytePerPixel) & 0x1f) / bytePerPixel);
}
viaCalcViewport(vmesa->glCtx);
}
void viaXMesaSetBackClipRects(viaContextPtr vmesa)
void viaXMesaWindowMoved(viaContextPtr vmesa)
{
__DRIdrawablePrivate *dPriv = vmesa->driDrawable;
GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3;
if (!dPriv)
return;
/*=* John Sheng [2003.6.9] fix glxgears dirty screen */
vmesa->numClipRects = dPriv->numClipRects;
vmesa->pClipRects = dPriv->pClipRects;
vmesa->drawX = dPriv->x;
switch (vmesa->glCtx->Color._DrawDestMask[0]) {
case DD_FRONT_LEFT_BIT:
if (dPriv->numBackClipRects == 0) {
vmesa->numClipRects = dPriv->numClipRects;
vmesa->pClipRects = dPriv->pClipRects;
}
else {
vmesa->numClipRects = dPriv->numBackClipRects;
vmesa->pClipRects = dPriv->pBackClipRects;
}
break;
case DD_BACK_LEFT_BIT:
vmesa->numClipRects = dPriv->numClipRects;
vmesa->pClipRects = dPriv->pClipRects;
break;
default:
vmesa->numClipRects = 0;
break;
}
if (vmesa->drawW != dPriv->w ||
vmesa->drawH != dPriv->h)
calculate_buffer_parameters( vmesa );
vmesa->drawXoff = (GLuint)(((dPriv->x * bytePerPixel) & 0x1f) / bytePerPixel);
vmesa->drawX = dPriv->x - vmesa->drawXoff;
vmesa->drawY = dPriv->y;
vmesa->drawW = dPriv->w;
vmesa->drawH = dPriv->h;
vmesa->front.orig = (vmesa->front.offset +
vmesa->drawY * vmesa->front.pitch +
vmesa->drawX * bytePerPixel);
vmesa->drawXoff = 0;
vmesa->front.origMap = (vmesa->front.map +
vmesa->drawY * vmesa->front.pitch +
vmesa->drawX * bytePerPixel);
viaCalcViewport(vmesa->glCtx);
}
void viaXMesaWindowMoved(viaContextPtr vmesa)
{
switch (vmesa->glCtx->Color._DrawDestMask[0]) {
case DD_FRONT_LEFT_BIT:
viaXMesaSetFrontClipRects(vmesa);
break;
case DD_BACK_LEFT_BIT:
viaXMesaSetBackClipRects(vmesa);
break;
default:
viaXMesaSetFrontClipRects(vmesa);
break;
}
vmesa->back.orig = vmesa->back.offset;
vmesa->depth.orig = vmesa->depth.offset;
vmesa->back.origMap = vmesa->back.map;
vmesa->depth.origMap = vmesa->depth.map;
viaCalcViewport(vmesa->glCtx);
}
GLboolean
@ -736,30 +674,20 @@ void viaGetLock(viaContextPtr vmesa, GLuint flags)
{
__DRIdrawablePrivate *dPriv = vmesa->driDrawable;
__DRIscreenPrivate *sPriv = vmesa->driScreen;
drm_via_sarea_t *sarea = vmesa->sarea;
int me = vmesa->hHWContext;
__DRIdrawablePrivate *pdp;
__DRIscreenPrivate *psp;
pdp = dPriv;
psp = sPriv;
if (VIA_DEBUG) {
fprintf(stderr, "%s - in\n", __FUNCTION__);
fprintf(stderr, "is: %x non-contend: %x want: %x\n",
*(GLuint *)vmesa->driHwLock, vmesa->hHWContext,
(DRM_LOCK_HELD|vmesa->hHWContext));
}
drmGetLock(vmesa->driFd, vmesa->hHWContext, flags);
DRI_VALIDATE_DRAWABLE_INFO( sPriv, dPriv );
if (sarea->ctxOwner != me) {
sarea->ctxOwner = me;
vmesa->newState = ~0;
if (vmesa->sarea->ctxOwner != vmesa->hHWContext) {
vmesa->sarea->ctxOwner = vmesa->hHWContext;
vmesa->newState = ~0;
}
viaXMesaWindowMoved(vmesa);
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
if (vmesa->lastStamp != dPriv->lastStamp) {
viaXMesaWindowMoved(vmesa);
vmesa->lastStamp = dPriv->lastStamp;
}
}
@ -768,7 +696,7 @@ viaSwapBuffers(__DRIdrawablePrivate *drawablePrivate)
{
__DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *)drawablePrivate;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
if (dPriv && dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
viaContextPtr vmesa;
GLcontext *ctx;

View File

@ -52,9 +52,12 @@ typedef struct via_texture_object_t *viaTextureObjectPtr;
#define VIA_FALLBACK_BLEND_FUNC 0x400
#define VIA_FALLBACK_USER_DISABLE 0x800
#define VIA_DMA_BUFSIZ 500000
#define VIA_DMA_BUFSIZ 5000
#define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 256)
#define VIA_NO_CLIPRECTS 0x1
/* Use the templated vertex formats:
*/
#define TAG(x) via##x
@ -74,6 +77,10 @@ typedef struct {
GLuint pitch;
GLuint bpp;
char *map;
GLuint orig; /* The drawing origin,
* at (drawX,drawY) in screen space.
*/
char *origMap;
} viaBuffer, *viaBufferPtr;
@ -81,7 +88,6 @@ struct via_context_t {
GLint refcount;
GLcontext *glCtx;
GLcontext *shareCtx;
unsigned char* front_base;
viaBuffer front;
viaBuffer back;
viaBuffer depth;
@ -98,7 +104,7 @@ struct via_context_t {
GLuint stencil_clear_mask;
GLfloat depth_max;
GLuint *dma;
GLubyte *dma;
viaRegion tex;
GLuint isAGP;
@ -127,8 +133,8 @@ struct via_context_t {
/* drmBufPtr dma_buffer;
*/
unsigned char* dmaAddr;
GLuint dmaLow;
GLuint dmaCliprectAddr;
GLuint dmaLastPrim;
GLboolean useAgp;
@ -202,7 +208,6 @@ struct via_context_t {
int vertexSize;
int vertexFormat;
GLint lastStamp;
GLboolean stippleInHw;
GLenum TexEnvImageFmt[2];
GLuint ClearColor;
@ -213,16 +218,15 @@ struct via_context_t {
GLboolean doPageFlip;
/*=* John Sheng [2003.5.31] flip *=*/
GLuint currentPage;
char *drawMap; /* draw buffer address in virtual mem */
char *readMap;
viaBuffer *drawBuffer;
viaBuffer *readBuffer;
int drawX; /* origin of drawable in draw buffer */
int drawY;
int drawW;
int drawH;
int drawPitch;
int readPitch;
int drawXoff;
GLuint numClipRects; /* cliprects for that buffer */
drm_clip_rect_t *pClipRects;
@ -325,6 +329,8 @@ extern void viaXMesaWindowMoved(viaContextPtr vmesa);
extern void viaTexCombineState(viaContextPtr vmesa,
const struct gl_tex_env_combine_state * combine, unsigned unit );
/* Via hw already adjusted for GL pixel centers:
*/
#define SUBPIXEL_X 0
#define SUBPIXEL_Y 0

View File

@ -31,126 +31,37 @@
#include <sys/ioctl.h>
GLboolean
via_alloc_back_buffer(viaContextPtr vmesa)
via_alloc_draw_buffer(viaContextPtr vmesa, viaBuffer *buf)
{
drm_via_mem_t fb;
unsigned char *pFB;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
fb.context = vmesa->hHWContext;
fb.size = vmesa->back.size;
fb.type = VIDEO;
if (VIA_DEBUG) fprintf(stderr, "context = %d, size =%d, type = %d\n", fb.context, fb.size, fb.type);
if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb))
return GL_FALSE;
pFB = vmesa->driScreen->pFB;
vmesa->back.offset = fb.offset;
vmesa->back.map = (char *)(fb.offset + (GLuint)pFB);
vmesa->back.index = fb.index;
if (VIA_DEBUG) {
fprintf(stderr, "back offset = %08x\n", vmesa->back.offset);
fprintf(stderr, "back index = %d\n", vmesa->back.index);
}
drm_via_mem_t mem;
mem.context = vmesa->hHWContext;
mem.size = buf->size;
mem.type = VIDEO;
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
return GL_TRUE;
}
GLboolean
via_alloc_front_buffer(viaContextPtr vmesa)
{
drm_via_mem_t fb;
unsigned char *pFB;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
fb.context = vmesa->hHWContext;
fb.size = vmesa->back.size;
fb.type = VIDEO;
if (VIA_DEBUG) fprintf(stderr, "context = %d, size =%d, type = %d\n", fb.context, fb.size, fb.type);
if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb))
return GL_FALSE;
if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &mem))
return GL_FALSE;
pFB = vmesa->driScreen->pFB;
vmesa->front.offset = fb.offset;
vmesa->front.map = (char *)(fb.offset + (GLuint)pFB);
vmesa->front.index = fb.index;
if (VIA_DEBUG) {
fprintf(stderr, "front offset = %08x\n", vmesa->front.offset);
fprintf(stderr, "front index = %d\n", vmesa->front.index);
}
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
return GL_TRUE;
buf->offset = mem.offset;
buf->map = (char *)vmesa->driScreen->pFB + mem.offset;
buf->index = mem.index;
return GL_TRUE;
}
void
via_free_back_buffer(viaContextPtr vmesa)
via_free_draw_buffer(viaContextPtr vmesa, viaBuffer *buf)
{
drm_via_mem_t fb;
drm_via_mem_t mem;
if (!vmesa) return;
fb.context = vmesa->hHWContext;
fb.index = vmesa->back.index;
fb.type = VIDEO;
ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
vmesa->back.map = NULL;
if (!vmesa) return;
mem.context = vmesa->hHWContext;
mem.index = buf->index;
mem.type = VIDEO;
ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &mem);
buf->map = NULL;
}
void
via_free_front_buffer(viaContextPtr vmesa)
{
drm_via_mem_t fb;
if (!vmesa) return;
fb.context = vmesa->hHWContext;
fb.index = vmesa->front.index;
fb.type = VIDEO;
ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
vmesa->front.map = NULL;
}
GLboolean
via_alloc_depth_buffer(viaContextPtr vmesa)
{
drm_via_mem_t fb;
unsigned char *pFB;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
fb.context = vmesa->hHWContext;
fb.size = vmesa->depth.size;
fb.type = VIDEO;
if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) {
return GL_FALSE;
}
pFB = vmesa->driScreen->pFB;
vmesa->depth.offset = fb.offset;
vmesa->depth.map = (char *)(fb.offset + (GLuint)pFB);
vmesa->depth.index = fb.index;
if (VIA_DEBUG) {
fprintf(stderr, "depth offset = %08x\n", vmesa->depth.offset);
fprintf(stderr, "depth index = %d\n", vmesa->depth.index);
}
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
return GL_TRUE;
}
void
via_free_depth_buffer(viaContextPtr vmesa)
{
drm_via_mem_t fb;
if (!vmesa) return;
fb.context = vmesa->hHWContext;
fb.index = vmesa->depth.index;
fb.type = VIDEO;
ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb);
vmesa->depth.map = NULL;
}
GLboolean
via_alloc_dma_buffer(viaContextPtr vmesa)
@ -158,7 +69,7 @@ via_alloc_dma_buffer(viaContextPtr vmesa)
drmVIADMAInit init;
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
vmesa->dma = (GLuint *) malloc(VIA_DMA_BUFSIZ);
vmesa->dma = (GLubyte *) malloc(VIA_DMA_BUFSIZ);
/*
* Check whether AGP DMA has been initialized.

View File

@ -25,18 +25,14 @@
#ifndef _VIAFB_INC
#define _VIAFB_INC
#include "mtypes.h"
#include "swrast/swrast.h"
extern GLboolean via_alloc_front_buffer(viaContextPtr vmesa);
extern GLboolean via_alloc_back_buffer(viaContextPtr vmesa);
extern void via_free_back_buffer(viaContextPtr vmesa);
extern void via_free_front_buffer(viaContextPtr vmesa);
extern GLboolean via_alloc_depth_buffer(viaContextPtr vmesa);
extern void via_free_depth_buffer(viaContextPtr vmesa);
#include "via_context.h"
extern GLboolean via_alloc_draw_buffer(viaContextPtr vmesa, viaBuffer *buf);
extern GLboolean via_alloc_dma_buffer(viaContextPtr vmesa);
extern void via_free_dma_buffer(viaContextPtr vmesa);
extern GLboolean via_alloc_texture(viaContextPtr vmesa, viaTextureObjectPtr t);
/*=* John Sheng [2003.5.31] agp tex *=*/
extern GLboolean via_alloc_texture_agp(viaContextPtr vmesa, viaTextureObjectPtr t);
extern void via_free_draw_buffer(viaContextPtr vmesa, viaBuffer *buf);
extern void via_free_dma_buffer(viaContextPtr vmesa);
extern void via_free_texture(viaContextPtr vmesa, viaTextureObjectPtr t);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -29,18 +29,12 @@
void viaFinishPrimitive(viaContextPtr vmesa);
void viaFlushPrims(viaContextPtr vmesa);
void viaFlushPrimsLocked(viaContextPtr vmesa);
void viaFlushDma(viaContextPtr vmesa);
void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags);
void viaInitIoctlFuncs(GLcontext *ctx);
void viaCopyBuffer(const __DRIdrawablePrivate *dpriv);
void viaPageFlip(const __DRIdrawablePrivate *dpriv);
void viaFillFrontBuffer(viaContextPtr vmesa);
void viaFillFrontPBuffer(viaContextPtr vmesa);
void viaFillBackBuffer(viaContextPtr vmesa);
void viaFillDepthBuffer(viaContextPtr vmesa, GLuint pixel, GLuint mask);
void viaDoSwapBuffers(viaContextPtr vmesa);
void viaDoSwapPBuffers(viaContextPtr vmesa);
void viaCheckDma(viaContextPtr vmesa, GLuint bytes);
#define VIA_FINISH_PRIM(vmesa) do { \
@ -50,8 +44,8 @@ void viaCheckDma(viaContextPtr vmesa, GLuint bytes);
#define VIA_FLUSH_DMA(vmesa) do { \
VIA_FINISH_PRIM(vmesa); \
if (vmesa->dmaLow != DMA_OFFSET) \
viaFlushPrims(vmesa); \
if (vmesa->dmaLow) \
viaFlushDma(vmesa); \
} while (0)
@ -59,12 +53,6 @@ GLuint *viaAllocDmaFunc(viaContextPtr vmesa, int bytes, const char *func, int li
#define viaAllocDma( v, b ) viaAllocDmaFunc(v, b, __FUNCTION__, __LINE__)
/* Room for the cliprect and other preamble at the head of each dma
* buffer: (What about buffers which only contain blits?)
*/
#define DMA_OFFSET 32
#define RING_VARS GLuint *_vb = 0, _nr, _x;
#define BEGIN_RING(n) do { \
@ -76,7 +64,7 @@ GLuint *viaAllocDmaFunc(viaContextPtr vmesa, int bytes, const char *func, int li
#define BEGIN_RING_NOCHECK(n) do { \
if (_vb != 0) abort(); \
_vb = (GLuint *)(vmesa->dmaAddr + vmesa->dmaLow); \
_vb = (GLuint *)(vmesa->dma + vmesa->dmaLow); \
vmesa->dmaLow += (n) * sizeof(GLuint); \
_nr = (n); \
_x = 0; \

View File

@ -36,9 +36,9 @@
#define LOCAL_DEPTH_VARS \
__DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
viaScreenPrivate *viaScreen = vmesa->viaScreen; \
GLuint pitch = viaScreen->backPitch; \
GLuint depth_pitch = vmesa->depth.pitch; \
GLuint height = dPriv->h; \
char *buf = (char *)(vmesa->depth.map)
char *buf = (char *)(vmesa->depth.map + (vmesa->drawXoff * vmesa->depth.bpp/8))
#define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
_y >= miny && _y < maxy)
@ -63,10 +63,10 @@
__DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
int _nc = dPriv->numClipRects; \
while (_nc--) { \
int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \
int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \
int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \
int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
int minx = dPriv->pClipRects[_nc].x1 - vmesa->drawX; \
int miny = dPriv->pClipRects[_nc].y1 - vmesa->drawY; \
int maxx = dPriv->pClipRects[_nc].x2 - vmesa->drawX; \
int maxy = dPriv->pClipRects[_nc].y2 - vmesa->drawY;
#define HW_ENDCLIPLOOP() \
@ -81,38 +81,28 @@
#define LOCAL_VARS \
viaContextPtr vmesa = VIA_CONTEXT(ctx); \
__DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
GLuint pitch = vmesa->drawPitch; \
GLuint draw_pitch = vmesa->drawBuffer->pitch; \
GLuint read_pitch = vmesa->readBuffer->pitch; \
GLuint height = dPriv->h; \
GLushort p; \
char *buf, *read_buf; \
p = 0; \
if (vmesa->glCtx->Color._DrawDestMask[0] == DD_BACK_LEFT_BIT) { \
buf = (char *)(vmesa->drawMap); \
read_buf = (char *)(vmesa->readMap); \
} \
else { \
buf = (char *)(vmesa->drawMap + \
dPriv->x * 2 + \
dPriv->y * pitch); \
read_buf = (char *)(vmesa->readMap + \
dPriv->x * 2 + \
dPriv->y * pitch); \
}
GLushort p = 0; \
char *buf = (char *)(vmesa->drawBuffer->origMap + vmesa->drawXoff * 2); \
char *read_buf = (char *)(vmesa->readBuffer->origMap + vmesa->drawXoff * 2); \
(void) (read_pitch && draw_pitch && buf && read_buf && p);
#define INIT_MONO_PIXEL(p, color) \
p = PACK_COLOR_565(color[0], color[1], color[2])
#define WRITE_RGBA(_x, _y, r, g, b, a) \
*(GLushort *)(buf + _x * 2 + _y * pitch) = ((((int)r & 0xf8) << 8) | \
*(GLushort *)(buf + _x * 2 + _y * draw_pitch) = ((((int)r & 0xf8) << 8) | \
(((int)g & 0xfc) << 3) | \
(((int)b & 0xf8) >> 3))
#define WRITE_PIXEL(_x, _y, p) \
*(GLushort *)(buf + _x * 2 + _y * pitch) = p
*(GLushort *)(buf + _x * 2 + _y * draw_pitch) = p
#define READ_RGBA(rgba, _x, _y) \
do { \
GLushort p = *(GLushort *)(read_buf + _x * 2 + _y * pitch); \
GLushort p = *(GLushort *)(read_buf + _x * 2 + _y * read_pitch); \
rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
@ -133,26 +123,16 @@
#define LOCAL_VARS \
viaContextPtr vmesa = VIA_CONTEXT(ctx); \
__DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
GLuint pitch = vmesa->drawPitch; \
GLuint draw_pitch = vmesa->drawBuffer->pitch; \
GLuint read_pitch = vmesa->readBuffer->pitch; \
GLuint height = dPriv->h; \
GLuint p; \
char *buf, *read_buf; \
p = 0; \
if (vmesa->glCtx->Color._DrawDestMask[0] == DD_BACK_LEFT_BIT) { \
buf = (char *)(vmesa->drawMap); \
read_buf = (char *)(vmesa->readMap); \
} \
else { \
buf = (char *)(vmesa->drawMap + \
dPriv->x * 4 + \
dPriv->y * pitch); \
read_buf = (char *)(vmesa->readMap + \
dPriv->x * 4 + \
dPriv->y * pitch); \
}
GLuint p = 0; \
char *buf = (char *)(vmesa->drawBuffer->origMap + vmesa->drawXoff * 4); \
char *read_buf = (char *)(vmesa->readBuffer->origMap + vmesa->drawXoff * 4); \
(void) (read_pitch && draw_pitch && buf && read_buf && p);
#define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * pitch)
#define GET_DST_PTR(_x, _y) ( buf + _x * 4 + _y * pitch)
#define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * read_pitch)
#define GET_DST_PTR(_x, _y) ( buf + _x * 4 + _y * draw_pitch)
#define SPANTMP_PIXEL_FMT GL_BGRA
#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
@ -166,7 +146,7 @@
#define LOCAL_DEPTH_VARS \
viaContextPtr vmesa = VIA_CONTEXT(ctx); \
__DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
GLuint pitch = vmesa->depth.pitch; \
GLuint depth_pitch = vmesa->depth.pitch; \
GLuint height = dPriv->h; \
char *buf = (char *)(vmesa->depth.map)
@ -174,10 +154,10 @@
#define WRITE_DEPTH(_x, _y, d) \
*(GLushort *)(buf + _x * 2 + _y * pitch) = d;
*(GLushort *)(buf + _x * 2 + _y * depth_pitch) = d;
#define READ_DEPTH(d, _x, _y) \
d = *(GLushort *)(buf + _x * 2 + _y * pitch);
d = *(GLushort *)(buf + _x * 2 + _y * depth_pitch);
#define TAG(x) via##x##_16
#include "depthtmp.h"
@ -185,10 +165,10 @@
/* 32 bit depthbuffer functions.
*/
#define WRITE_DEPTH(_x, _y, d) \
*(GLuint *)(buf + _x * 4 + _y * pitch) = d;
*(GLuint *)(buf + _x * 4 + _y * depth_pitch) = d;
#define READ_DEPTH(d, _x, _y) \
d = *(GLuint *)(buf + _x * 4 + _y * pitch);
d = *(GLuint *)(buf + _x * 4 + _y * depth_pitch);
#define TAG(x) via##x##_32
#include "depthtmp.h"
@ -198,28 +178,28 @@
/* 24/8 bit interleaved depth/stencil functions
*/
#define WRITE_DEPTH( _x, _y, d ) { \
GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
tmp &= 0x000000ff; \
tmp |= ((d)<<8); \
*(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
}
#define READ_DEPTH( d, _x, _y ) \
d = (*(GLuint *)(buf + (_x)*4 + (_y)*pitch)) >> 8;
d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
#define TAG(x) via##x##_24_8
#include "depthtmp.h"
#define WRITE_STENCIL( _x, _y, d ) { \
GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
tmp &= 0xffffff00; \
tmp |= (d); \
*(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
}
#define READ_STENCIL( d, _x, _y ) \
d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & 0xff;
d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
#define TAG(x) via##x##_24_8
#include "stenciltmp.h"
@ -230,23 +210,16 @@ static void viaSetBuffer(GLcontext *ctx, GLframebuffer *colorBuffer,
GLuint bufferBit)
{
viaContextPtr vmesa = VIA_CONTEXT(ctx);
if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__);
if (bufferBit == DD_FRONT_LEFT_BIT) {
vmesa->drawMap = (char *)vmesa->driScreen->pFB;
vmesa->readMap = (char *)vmesa->driScreen->pFB;
vmesa->drawPitch = vmesa->front.pitch;
vmesa->readPitch = vmesa->front.pitch;
vmesa->drawBuffer = vmesa->readBuffer = &vmesa->front;
}
else if (bufferBit == DD_BACK_LEFT_BIT) {
vmesa->drawMap = vmesa->back.map;
vmesa->readMap = vmesa->back.map;
vmesa->drawPitch = vmesa->back.pitch;
vmesa->readPitch = vmesa->back.pitch;
vmesa->drawBuffer = vmesa->readBuffer = &vmesa->back;
}
else {
ASSERT(0);
}
if (VIA_DEBUG) fprintf(stderr, "%s out\n", __FUNCTION__);
}
/* Move locking out to get reasonable span performance.
@ -256,7 +229,7 @@ void viaSpanRenderStart( GLcontext *ctx )
viaContextPtr vmesa = VIA_CONTEXT(ctx);
VIA_FINISH_PRIM(vmesa);
LOCK_HARDWARE(vmesa);
viaFlushPrimsLocked(vmesa);
viaFlushDmaLocked(vmesa, 0);
WAIT_IDLE(vmesa);
}

View File

@ -642,21 +642,13 @@ static void viaDrawBuffer(GLcontext *ctx, GLenum mode)
if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__);
if (mode == GL_FRONT) {
VIA_FLUSH_DMA(vmesa);
vmesa->drawMap = (char *)vmesa->driScreen->pFB;
vmesa->readMap = (char *)vmesa->driScreen->pFB;
vmesa->drawPitch = vmesa->front.pitch;
vmesa->readPitch = vmesa->front.pitch;
viaXMesaSetFrontClipRects(vmesa);
vmesa->drawBuffer = vmesa->readBuffer = &vmesa->front;
FALLBACK(vmesa, VIA_FALLBACK_DRAW_BUFFER, GL_FALSE);
return;
}
else if (mode == GL_BACK) {
VIA_FLUSH_DMA(vmesa);
vmesa->drawMap = vmesa->back.map;
vmesa->readMap = vmesa->back.map;
vmesa->drawPitch = vmesa->back.pitch;
vmesa->readPitch = vmesa->back.pitch;
viaXMesaSetBackClipRects(vmesa);
vmesa->drawBuffer = vmesa->readBuffer = &vmesa->back;
FALLBACK(vmesa, VIA_FALLBACK_DRAW_BUFFER, GL_FALSE);
return;
}
@ -665,6 +657,8 @@ static void viaDrawBuffer(GLcontext *ctx, GLenum mode)
return;
}
viaXMesaWindowMoved(vmesa);
/* We want to update the s/w rast state too so that r200SetBuffer()
* gets called.
*/
@ -693,6 +687,10 @@ static void viaClearColor(GLcontext *ctx, const GLfloat color[4])
*/
/* Using drawXoff like this is incorrect outside of locked regions.
* This hardware just isn't capable of private back buffers without
* glitches and/or a hefty locking scheme.
*/
void viaCalcViewport(GLcontext *ctx)
{
viaContextPtr vmesa = VIA_CONTEXT(ctx);
@ -1550,6 +1548,8 @@ void viaValidateState( GLcontext *ctx )
viaChooseStencilState(ctx);
if (!vmesa->Fallback) {
viaChooseVertexState(ctx);
viaChooseRenderState(ctx);
via_emit_state(vmesa);
vmesa->newState = 0;
}

View File

@ -555,7 +555,7 @@ static void viaFastRenderClippedPoly(GLcontext *ctx, const GLuint *elts,
#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
static void viaChooseRenderState(GLcontext *ctx)
void viaChooseRenderState(GLcontext *ctx)
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
viaContextPtr vmesa = VIA_CONTEXT(ctx);
@ -633,11 +633,6 @@ static void viaRunPipeline(GLcontext *ctx)
if (vmesa->newState) {
viaValidateState( ctx );
if (!vmesa->Fallback) {
viaChooseVertexState(ctx);
viaChooseRenderState(ctx);
}
}
_tnl_run_pipeline(ctx);
@ -677,9 +672,8 @@ void viaRasterPrimitive(GLcontext *ctx,
_mesa_lookup_enum_by_nr(hwprim));
VIA_FINISH_PRIM(vmesa);
viaCheckDma( vmesa, 1024 ); /* Ensure no wrapping inside this function */
vmesa->renderPrimitive = glprim;
regCmdB = vmesa->regCmdB;
switch (hwprim) {
@ -738,7 +732,24 @@ void viaRasterPrimitive(GLcontext *ctx,
return;
}
assert((vmesa->dmaLow & 0x4) == 0);
/* assert((vmesa->dmaLow & 0x4) == 0); */
if (vmesa->dmaCliprectAddr == 0) {
if (VIA_DEBUG) fprintf(stderr, "reserve cliprect space at %x\n", vmesa->dmaLow);
assert(vmesa->dmaLow);
vmesa->dmaCliprectAddr = vmesa->dmaLow;
BEGIN_RING(8);
OUT_RING( HC_HEADER2 );
OUT_RING( (HC_ParaType_NotTex << 16) );
OUT_RING( 0xCCCCCCCC );
OUT_RING( 0xCCCCCCCC );
OUT_RING( 0xCCCCCCCC );
OUT_RING( 0xCCCCCCCC );
OUT_RING( 0xCCCCCCCC );
OUT_RING( 0xCCCCCCCC );
ADVANCE_RING();
}
BEGIN_RING(8);
OUT_RING( HC_HEADER2 );
@ -752,8 +763,10 @@ void viaRasterPrimitive(GLcontext *ctx,
OUT_RING( vmesa->regCmdA_End );
ADVANCE_RING();
vmesa->renderPrimitive = glprim;
vmesa->hwPrimitive = hwprim;
vmesa->dmaLastPrim = vmesa->dmaLow;
vmesa->hwPrimitive = hwprim;
}
/* Callback for mesa:
@ -766,36 +779,46 @@ static void viaRenderPrimitive( GLcontext *ctx, GLuint prim )
void viaFinishPrimitive(viaContextPtr vmesa)
{
if (!vmesa->dmaLastPrim) {
return;
}
else if (vmesa->dmaLow != vmesa->dmaLastPrim) {
GLuint cmdA = vmesa->regCmdA_End | HC_HPLEND_MASK | HC_HPMValidN_MASK | HC_HE3Fire_MASK;
RING_VARS;
if (VIA_DEBUG) fprintf(stderr, "%s\n", __FUNCTION__);
/* KW: modified 0x1 to 0x4 below:
*/
if ((vmesa->dmaLow & 0x1) || !vmesa->useAgp) {
BEGIN_RING_NOCHECK( 1 );
OUT_RING( cmdA );
ADVANCE_RING();
}
else {
BEGIN_RING_NOCHECK( 2 );
OUT_RING( cmdA );
OUT_RING( cmdA );
ADVANCE_RING();
}
vmesa->dmaLastPrim = 0;
if (!vmesa->dmaLastPrim) {
return;
}
else if (vmesa->dmaLow != vmesa->dmaLastPrim) {
GLuint cmdA = vmesa->regCmdA_End | HC_HPLEND_MASK | HC_HPMValidN_MASK | HC_HE3Fire_MASK;
RING_VARS;
if (1 || vmesa->dmaLow > VIA_DMA_HIGHWATER)
viaFlushPrims( vmesa );
}
else {
assert(vmesa->dmaLow >= (32 + DMA_OFFSET));
vmesa->dmaLow -= 32;
vmesa->dmaLastPrim = 0;
}
/* KW: modified 0x1 to 0x4 below:
*/
if ((vmesa->dmaLow & 0x1) || !vmesa->useAgp) {
BEGIN_RING_NOCHECK( 1 );
OUT_RING( cmdA );
ADVANCE_RING();
}
else {
BEGIN_RING_NOCHECK( 2 );
OUT_RING( cmdA );
OUT_RING( cmdA );
ADVANCE_RING();
}
vmesa->dmaLastPrim = 0;
if (vmesa->dmaLow > VIA_DMA_HIGHWATER)
viaFlushDma( vmesa );
}
else {
/* Remove the primitive header:
*/
vmesa->dmaLastPrim = 0;
vmesa->dmaLow -= 8 * sizeof(GLuint);
/* Maybe remove the cliprect as well:
*/
if (vmesa->dmaCliprectAddr == vmesa->dmaLow - 8 * sizeof(GLuint)) {
vmesa->dmaLow -= 8 * sizeof(GLuint);
vmesa->dmaCliprectAddr = 0;
}
}
}

View File

@ -86,9 +86,11 @@ static struct {
#define HAVE_TEX3_VERTICES 0
#define HAVE_PTEX_VERTICES 0
#define UNVIEWPORT_VARS GLfloat h = VIA_CONTEXT(ctx)->driDrawable->h, \
depth_max = VIA_CONTEXT(ctx)->depth_max;
#define UNVIEWPORT_X(x) x - SUBPIXEL_X
#define UNVIEWPORT_VARS \
viaContextPtr vmesa = VIA_CONTEXT(ctx); \
GLfloat h = vmesa->driDrawable->h, depth_max = vmesa->depth_max, xoff = vmesa->drawXoff;
#define UNVIEWPORT_X(x) x - (SUBPIXEL_X + xoff)
#define UNVIEWPORT_Y(y) - y + h + SUBPIXEL_Y
#define UNVIEWPORT_Z(z) z * (float)depth_max