diff options
Diffstat (limited to 'src/mesa')
20 files changed, 2116 insertions, 1802 deletions
diff --git a/src/mesa/drivers/dri/unichrome/Makefile b/src/mesa/drivers/dri/unichrome/Makefile index 3e2f813f957..3c9203636e3 100644 --- a/src/mesa/drivers/dri/unichrome/Makefile +++ b/src/mesa/drivers/dri/unichrome/Makefile @@ -20,16 +20,14 @@ COMMON_SOURCES = \ DRIVER_SOURCES = \ via_context.c \ via_fb.c \ + via_tex.c \ via_ioctl.c \ via_render.c \ via_screen.c \ via_span.c \ via_state.c \ - via_tex.c \ - via_texmem.c \ - via_texstate.c \ - via_tris.c \ - via_texcombine.c + via_texcombine.c \ + via_tris.c C_SOURCES = \ $(COMMON_SOURCES) \ diff --git a/src/mesa/drivers/dri/unichrome/server/via_dri.c b/src/mesa/drivers/dri/unichrome/server/via_dri.c index 72735abc82c..b8c8ffc68ef 100644 --- a/src/mesa/drivers/dri/unichrome/server/via_dri.c +++ b/src/mesa/drivers/dri/unichrome/server/via_dri.c @@ -317,7 +317,7 @@ static int VIADRIScreenInit(DRIDriverContext * ctx) #if 0 ctx->shared.SAREASize = ((sizeof(drm_sarea_t) + 0xfff) & 0x1000); #else - if (sizeof(drm_sarea_t)+sizeof(VIASAREAPriv) > SAREA_MAX) { + if (sizeof(drm_sarea_t)+sizeof(drm_via_sarea_t) > SAREA_MAX) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Data does not fit in SAREA\n"); return GL_FALSE; @@ -446,10 +446,6 @@ static int VIADRIScreenInit(DRIDriverContext * ctx) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[dri] frame buffer initialized.\n" ); - /*pVIADRI->drixinerama = pVia->drixinerama;*/ - /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/ - pVIADRI->VQEnable = pVia->VQEnable; - return VIADRIFinishScreenInit(ctx); } @@ -503,13 +499,13 @@ VIADRIFinishScreenInit(DRIDriverContext * ctx) /* set SAREA value */ { - VIASAREAPriv *saPriv; + drm_via_sarea_t *saPriv; - saPriv=(VIASAREAPriv*)(((char*)ctx->pSAREA) + + saPriv=(drm_via_sarea_t*)(((char*)ctx->pSAREA) + sizeof(drm_sarea_t)); assert(saPriv); memset(saPriv, 0, sizeof(*saPriv)); - saPriv->CtxOwner = -1; + saPriv->ctxOwner = -1; } pVIADRI=(VIADRIPtr)pVia->devPrivate; pVIADRI->deviceID=pVia->Chipset; @@ -1218,7 +1214,7 @@ static int viaInitFBDev(DRIDriverContext *ctx) pVia->FBFreeStart = ctx->shared.virtualWidth * ctx->cpp * ctx->shared.virtualHeight; -#if 0 +#if 1 /* Alloc a second framebuffer for the second head */ pVia->FBFreeStart += ctx->shared.virtualWidth * ctx->cpp * ctx->shared.virtualHeight; diff --git a/src/mesa/drivers/dri/unichrome/via_common.h b/src/mesa/drivers/dri/unichrome/via_common.h index bf2fd6455d5..c1453520956 100644 --- a/src/mesa/drivers/dri/unichrome/via_common.h +++ b/src/mesa/drivers/dri/unichrome/via_common.h @@ -99,8 +99,13 @@ #define VIA_BACK 0x2 #define VIA_DEPTH 0x4 #define VIA_STENCIL 0x8 -#define VIDEO 0 -#define AGP 1 + +#define VIA_MEM_VIDEO 0 /* matches drm constant */ +#define VIA_MEM_AGP 1 /* matches drm constant */ +#define VIA_MEM_SYSTEM 2 +#define VIA_MEM_MIXED 3 +#define VIA_MEM_UNKNOWN 4 + typedef struct { u_int32_t offset; u_int32_t size; @@ -172,7 +177,6 @@ typedef struct _drm_via_sarea { unsigned int nbox; drm_clip_rect_t boxes[VIA_NR_SAREA_CLIPRECTS]; drm_via_tex_region_t texList[VIA_NR_TEX_REGIONS + 1]; - int texAge; /* last time texture was uploaded */ int ctxOwner; /* last context to upload state */ int vertexPrim; @@ -188,6 +192,10 @@ typedef struct _drm_via_sarea { unsigned int XvMCSubPicOn[VIA_NR_XVMC_PORTS]; unsigned int XvMCCtxNoGrabbed; /* Last context to hold decoder */ + /* Used by the 3d driver only at this point, for pageflipping: + */ + unsigned int pfCurrentOffset; + } drm_via_sarea_t; typedef struct _drm_via_cmdbuf_size { diff --git a/src/mesa/drivers/dri/unichrome/via_context.c b/src/mesa/drivers/dri/unichrome/via_context.c index 51ed375bb3c..b4385eb50fd 100644 --- a/src/mesa/drivers/dri/unichrome/via_context.c +++ b/src/mesa/drivers/dri/unichrome/via_context.c @@ -64,10 +64,7 @@ #include "vblank.h" #include "utils.h" -#ifdef DEBUG GLuint VIA_DEBUG = 0; -#endif - /** * Return various strings for \c glGetString. @@ -92,8 +89,8 @@ static const GLubyte *viaGetString(GLcontext *ctx, GLenum name) "UniChrome (K8M800)", "UniChrome (PM8x0/CN400)", }; - const viaContext * const via = VIA_CONTEXT(ctx); - const unsigned id = via->viaScreen->deviceID; + struct via_context *vmesa = VIA_CONTEXT(ctx); + unsigned id = vmesa->viaScreen->deviceID; offset = driGetRendererString( buffer, chipset_names[(id > VIA_PM800) ? 0 : id], @@ -134,7 +131,7 @@ buffer_align( unsigned width ) * \sa AllocateBuffer */ static GLboolean -calculate_buffer_parameters( viaContextPtr vmesa ) +calculate_buffer_parameters( struct via_context *vmesa ) { const unsigned shift = vmesa->viaScreen->bitsPerPixel / 16; const unsigned extra = 32; @@ -155,15 +152,17 @@ calculate_buffer_parameters( viaContextPtr vmesa ) if (!via_alloc_draw_buffer(vmesa, &vmesa->front)) return GL_FALSE; - } - else { + } 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; + if (getenv("ALTERNATE_SCREEN")) + vmesa->front.offset = vmesa->front.size; + else + vmesa->front.offset = 0; vmesa->front.map = (char *) vmesa->driScreen->pFB; } @@ -171,7 +170,9 @@ calculate_buffer_parameters( viaContextPtr vmesa ) /* Allocate back-buffer */ if (vmesa->hasBack) { vmesa->back.bpp = vmesa->viaScreen->bitsPerPixel; - vmesa->back.pitch = (buffer_align( vmesa->driDrawable->w ) << shift) + extra; + vmesa->back.pitch = (buffer_align( vmesa->driDrawable->w ) << shift); + vmesa->back.pitch += extra; + vmesa->back.pitch = MIN2(vmesa->back.pitch, vmesa->front.pitch); vmesa->back.size = vmesa->back.pitch * vmesa->driDrawable->h; if (vmesa->back.map) via_free_draw_buffer(vmesa, &vmesa->back); @@ -191,7 +192,8 @@ calculate_buffer_parameters( viaContextPtr vmesa ) if (vmesa->depth.bpp == 24) vmesa->depth.bpp = 32; - vmesa->depth.pitch = (buffer_align( vmesa->driDrawable->w ) * (vmesa->depth.bpp/8)) + extra; + vmesa->depth.pitch = (buffer_align( vmesa->driDrawable->w ) * + (vmesa->depth.bpp/8)) + extra; vmesa->depth.size = vmesa->depth.pitch * vmesa->driDrawable->h; if (vmesa->depth.map) @@ -206,17 +208,10 @@ calculate_buffer_parameters( viaContextPtr vmesa ) (void) memset( & vmesa->depth, 0, sizeof( vmesa->depth ) ); } - /*=* 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->currentPage = 0; */ + vmesa->doPageFlip = vmesa->allowPageFlip; assert(vmesa->back.pitch == vmesa->front.pitch); -#else - vmesa->doPageFlip = GL_FALSE; -#endif } else vmesa->doPageFlip = GL_FALSE; @@ -228,7 +223,7 @@ calculate_buffer_parameters( viaContextPtr vmesa ) void viaReAllocateBuffers(GLframebuffer *drawbuffer) { GET_CURRENT_CONTEXT(ctx); - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); _swrast_alloc_buffers( drawbuffer ); calculate_buffer_parameters( vmesa ); @@ -237,7 +232,7 @@ void viaReAllocateBuffers(GLframebuffer *drawbuffer) static void viaBufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height) { GET_CURRENT_CONTEXT(ctx); - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); *width = vmesa->driDrawable->w; *height = vmesa->driDrawable->h; } @@ -281,8 +276,28 @@ static const struct tnl_pipeline_stage *via_pipeline[] = { }; +static const struct dri_debug_control debug_control[] = +{ + { "fall", DEBUG_FALLBACKS }, + { "tex", DEBUG_TEXTURE }, + { "ioctl", DEBUG_IOCTL }, + { "prim", DEBUG_PRIMS }, + { "vert", DEBUG_VERTS }, + { "state", DEBUG_STATE }, + { "verb", DEBUG_VERBOSE }, + { "dri", DEBUG_DRI }, + { "dma", DEBUG_DMA }, + { "san", DEBUG_SANITY }, + { "sync", DEBUG_SYNC }, + { "sleep", DEBUG_SLEEP }, + { "pix", DEBUG_PIXEL }, + { "2d", DEBUG_2D }, + { NULL, 0 } +}; + + static GLboolean -AllocateDmaBuffer(const GLvisual *visual, viaContextPtr vmesa) +AllocateDmaBuffer(const GLvisual *visual, struct via_context *vmesa) { if (vmesa->dma) via_free_dma_buffer(vmesa); @@ -296,7 +311,7 @@ AllocateDmaBuffer(const GLvisual *visual, viaContextPtr vmesa) } static void -FreeBuffer(viaContextPtr vmesa) +FreeBuffer(struct via_context *vmesa) { if (vmesa->front.map && vmesa->drawType == GLX_PBUFFER_BIT) via_free_draw_buffer(vmesa, &vmesa->front); @@ -307,6 +322,9 @@ FreeBuffer(viaContextPtr vmesa) if (vmesa->depth.map) via_free_draw_buffer(vmesa, &vmesa->depth); + if (vmesa->breadcrumb.map) + via_free_draw_buffer(vmesa, &vmesa->breadcrumb); + if (vmesa->dma) via_free_dma_buffer(vmesa); } @@ -324,7 +342,7 @@ viaCreateContext(const __GLcontextModes *mesaVis, void *sharedContextPrivate) { GLcontext *ctx, *shareCtx; - viaContextPtr vmesa; + struct via_context *vmesa; __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private; drm_via_sarea_t *saPriv = (drm_via_sarea_t *) @@ -332,11 +350,10 @@ viaCreateContext(const __GLcontextModes *mesaVis, struct dd_function_table functions; /* Allocate via context */ - vmesa = (viaContextPtr) CALLOC_STRUCT(via_context_t); + vmesa = (struct via_context *) CALLOC_STRUCT(via_context); if (!vmesa) { return GL_FALSE; } - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); /* Parse configuration files. */ @@ -391,17 +408,22 @@ viaCreateContext(const __GLcontextModes *mesaVis, break; } + make_empty_list(&vmesa->freed_tex_buffers); + make_empty_list(&vmesa->tex_image_list[VIA_MEM_VIDEO]); + make_empty_list(&vmesa->tex_image_list[VIA_MEM_AGP]); + make_empty_list(&vmesa->tex_image_list[VIA_MEM_SYSTEM]); _mesa_init_driver_functions(&functions); viaInitTextureFuncs(&functions); /* Allocate the Mesa context */ if (sharedContextPrivate) - shareCtx = ((viaContextPtr) sharedContextPrivate)->glCtx; + shareCtx = ((struct via_context *) sharedContextPrivate)->glCtx; else shareCtx = NULL; - vmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, &functions, (void*) vmesa); + vmesa->glCtx = _mesa_create_context(mesaVis, shareCtx, &functions, + (void*) vmesa); vmesa->shareCtx = shareCtx; @@ -466,9 +488,7 @@ viaCreateContext(const __GLcontextModes *mesaVis, vmesa->viaScreen = viaScreen; vmesa->driScreen = sPriv; vmesa->sarea = saPriv; - vmesa->glBuffer = NULL; - vmesa->texHeap = mmInit(0, viaScreen->textureSize); vmesa->renderIndex = ~0; vmesa->setupIndex = ~0; vmesa->hwPrimitive = GL_POLYGON+1; @@ -479,12 +499,6 @@ viaCreateContext(const __GLcontextModes *mesaVis, vmesa->drawType = GLX_WINDOW_BIT; - make_empty_list(&vmesa->TexObjList); - make_empty_list(&vmesa->SwappedOut); - - vmesa->CurrentTexObj[0] = 0; - vmesa->CurrentTexObj[1] = 0; - _math_matrix_ctr(&vmesa->ViewportMatrix); /* Do this early, before VIA_FLUSH_DMA can be called: @@ -496,27 +510,33 @@ viaCreateContext(const __GLcontextModes *mesaVis, return GL_FALSE; } + /* Allocate a small piece of fb memory for synchronization: + */ + vmesa->breadcrumb.bpp = 32; + vmesa->breadcrumb.pitch = buffer_align( 64 ) << 2; + vmesa->breadcrumb.size = vmesa->breadcrumb.pitch; + + if (!via_alloc_draw_buffer(vmesa, &vmesa->breadcrumb)) { + fprintf(stderr ,"AllocateDmaBuffer fail\n"); + FreeBuffer(vmesa); + FREE(vmesa); + return GL_FALSE; + } + driInitExtensions( ctx, card_extensions, GL_TRUE ); viaInitStateFuncs(ctx); - viaInitTextures(ctx); viaInitTriFuncs(ctx); viaInitSpanFuncs(ctx); viaInitIoctlFuncs(ctx); viaInitState(ctx); -#ifdef DEBUG if (getenv("VIA_DEBUG")) - VIA_DEBUG = 1; - else - VIA_DEBUG = 0; -#endif + VIA_DEBUG = driParseDebugString( getenv( "VIA_DEBUG" ), + debug_control ); if (getenv("VIA_NO_RAST")) FALLBACK(vmesa, VIA_FALLBACK_USER_DISABLE, 1); - if (getenv("VIA_CONFORM")) - vmesa->strictConformance = 1; - /* I don't understand why this isn't working: */ vmesa->vblank_flags = @@ -525,10 +545,14 @@ viaCreateContext(const __GLcontextModes *mesaVis, /* Hack this up in its place: */ - vmesa->vblank_flags = getenv("VIA_VSYNC") ? VBLANK_FLAG_SYNC : VBLANK_FLAG_NO_IRQ; - - - vmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" ); + vmesa->vblank_flags = (getenv("VIA_VSYNC") ? + VBLANK_FLAG_SYNC : VBLANK_FLAG_NO_IRQ); + + if (getenv("VIA_PAGEFLIP")) + vmesa->allowPageFlip = 1; + + vmesa->get_ust = + (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" ); if ( vmesa->get_ust == NULL ) { vmesa->get_ust = get_ust_nop; } @@ -541,11 +565,7 @@ viaCreateContext(const __GLcontextModes *mesaVis, vmesa->regTranSet = (GLuint *)((GLuint)viaScreen->reg + 0x43C); vmesa->regTranSpace = (GLuint *)((GLuint)viaScreen->reg + 0x440); vmesa->agpBase = viaScreen->agpBase; - if (VIA_DEBUG) { - fprintf(stderr, "regEngineStatus = %x\n", *vmesa->regEngineStatus); - } - - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); + return GL_TRUE; } @@ -553,9 +573,9 @@ void viaDestroyContext(__DRIcontextPrivate *driContextPriv) { GET_CURRENT_CONTEXT(ctx); - viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate; - viaContextPtr current = ctx ? VIA_CONTEXT(ctx) : NULL; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); + struct via_context *vmesa = + (struct via_context *)driContextPriv->driverPrivate; + struct via_context *current = ctx ? VIA_CONTEXT(ctx) : NULL; assert(vmesa); /* should never be null */ /* check if we're deleting the currently bound context */ @@ -565,25 +585,36 @@ viaDestroyContext(__DRIcontextPrivate *driContextPriv) } if (vmesa) { - /*=* John Sheng [2003.5.31] agp tex *=*/ - WAIT_IDLE(vmesa); - if(VIA_DEBUG) fprintf(stderr, "agpFullCount = %d\n", vmesa->agpFullCount); + viaWaitIdle(vmesa); + if (vmesa->doPageFlip) { + LOCK_HARDWARE(vmesa); + if (vmesa->pfCurrentOffset != 0) { + fprintf(stderr, "%s - reset pf\n", __FUNCTION__); + viaResetPageFlippingLocked(vmesa); + } + UNLOCK_HARDWARE(vmesa); + } _swsetup_DestroyContext(vmesa->glCtx); _tnl_DestroyContext(vmesa->glCtx); _ac_DestroyContext(vmesa->glCtx); _swrast_DestroyContext(vmesa->glCtx); - FreeBuffer(vmesa); /* free the Mesa context */ _mesa_destroy_context(vmesa->glCtx); + /* release our data */ + FreeBuffer(vmesa); + + assert (is_empty_list(&vmesa->tex_image_list[VIA_MEM_AGP])); + assert (is_empty_list(&vmesa->tex_image_list[VIA_MEM_VIDEO])); + assert (is_empty_list(&vmesa->tex_image_list[VIA_MEM_SYSTEM])); + assert (is_empty_list(&vmesa->freed_tex_buffers)); + FREE(vmesa); } - - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); } -void viaXMesaWindowMoved(viaContextPtr vmesa) +void viaXMesaWindowMoved(struct via_context *vmesa) { __DRIdrawablePrivate *dPriv = vmesa->driDrawable; GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3; @@ -615,7 +646,8 @@ void viaXMesaWindowMoved(viaContextPtr vmesa) vmesa->drawH != dPriv->h) calculate_buffer_parameters( vmesa ); - vmesa->drawXoff = (GLuint)(((dPriv->x * bytePerPixel) & 0x1f) / bytePerPixel); + vmesa->drawXoff = (GLuint)(((dPriv->x * bytePerPixel) & 0x1f) / + bytePerPixel); vmesa->drawX = dPriv->x - vmesa->drawXoff; vmesa->drawY = dPriv->y; vmesa->drawW = dPriv->w; @@ -640,8 +672,6 @@ void viaXMesaWindowMoved(viaContextPtr vmesa) GLboolean viaUnbindContext(__DRIcontextPrivate *driContextPriv) { - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); return GL_TRUE; } @@ -650,16 +680,15 @@ viaMakeCurrent(__DRIcontextPrivate *driContextPriv, __DRIdrawablePrivate *driDrawPriv, __DRIdrawablePrivate *driReadPriv) { - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - - if (VIA_DEBUG) { + if (VIA_DEBUG & DEBUG_DRI) { fprintf(stderr, "driContextPriv = %08x\n", (GLuint)driContextPriv); fprintf(stderr, "driDrawPriv = %08x\n", (GLuint)driDrawPriv); fprintf(stderr, "driReadPriv = %08x\n", (GLuint)driReadPriv); } if (driContextPriv) { - viaContextPtr vmesa = (viaContextPtr)driContextPriv->driverPrivate; + struct via_context *vmesa = + (struct via_context *)driContextPriv->driverPrivate; GLcontext *ctx = vmesa->glCtx; if ( vmesa->driDrawable != driDrawPriv ) { @@ -670,12 +699,10 @@ viaMakeCurrent(__DRIcontextPrivate *driContextPriv, } ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] ); } - if (VIA_DEBUG) fprintf(stderr, "viaMakeCurrent: w = %d\n", vmesa->driDrawable->w); _mesa_make_current2(vmesa->glCtx, (GLframebuffer *)driDrawPriv->driverPrivate, (GLframebuffer *)driReadPriv->driverPrivate); - if (VIA_DEBUG) fprintf(stderr, "Context %d MakeCurrent\n", vmesa->hHWContext); viaXMesaWindowMoved(vmesa); ctx->Driver.Scissor(vmesa->glCtx, @@ -688,11 +715,10 @@ viaMakeCurrent(__DRIcontextPrivate *driContextPriv, _mesa_make_current(0,0); } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); return GL_TRUE; } -void viaGetLock(viaContextPtr vmesa, GLuint flags) +void viaGetLock(struct via_context *vmesa, GLuint flags) { __DRIdrawablePrivate *dPriv = vmesa->driDrawable; __DRIscreenPrivate *sPriv = vmesa->driScreen; @@ -710,6 +736,12 @@ void viaGetLock(viaContextPtr vmesa, GLuint flags) viaXMesaWindowMoved(vmesa); vmesa->lastStamp = dPriv->lastStamp; } + + if (vmesa->doPageFlip && + vmesa->pfCurrentOffset != vmesa->sarea->pfCurrentOffset) { + fprintf(stderr, "%s - reset pf\n", __FUNCTION__); + viaResetPageFlippingLocked(vmesa); + } } @@ -717,13 +749,14 @@ void viaSwapBuffers(__DRIdrawablePrivate *drawablePrivate) { __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *)drawablePrivate; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - if (dPriv && dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) { - viaContextPtr vmesa; - GLcontext *ctx; - - vmesa = (viaContextPtr)dPriv->driContextPriv->driverPrivate; - ctx = vmesa->glCtx; + + if (dPriv && + dPriv->driContextPriv && + dPriv->driContextPriv->driverPrivate) { + struct via_context *vmesa = + (struct via_context *)dPriv->driContextPriv->driverPrivate; + GLcontext *ctx = vmesa->glCtx; + if (ctx->Visual.doubleBufferMode) { _mesa_notifySwapBuffers(ctx); if (vmesa->doPageFlip) { @@ -739,5 +772,4 @@ viaSwapBuffers(__DRIdrawablePrivate *drawablePrivate) else { _mesa_problem(NULL, "viaSwapBuffers: drawable has no context!\n"); } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); } diff --git a/src/mesa/drivers/dri/unichrome/via_context.h b/src/mesa/drivers/dri/unichrome/via_context.h index 28da220029d..9db382d49cd 100644 --- a/src/mesa/drivers/dri/unichrome/via_context.h +++ b/src/mesa/drivers/dri/unichrome/via_context.h @@ -26,10 +26,6 @@ #ifndef _VIACONTEXT_H #define _VIACONTEXT_H -typedef struct via_context_t viaContext; -typedef struct via_context_t *viaContextPtr; -typedef struct via_texture_object_t *viaTextureObjectPtr; - #include "dri_util.h" #include "mtypes.h" @@ -41,6 +37,8 @@ typedef struct via_texture_object_t *viaTextureObjectPtr; #include "via_tex.h" #include "via_common.h" +struct via_context; + /* Chip tags. These are used to group the adapters into * related families. */ @@ -79,39 +77,84 @@ enum VIACHIPTAGS { #include "tnl_dd/t_dd_vertex.h" #undef TAG -typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *, +typedef void (*via_tri_func)(struct via_context *, viaVertex *, viaVertex *, viaVertex *); -typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *); -typedef void (*via_point_func)(viaContextPtr, viaVertex *); - -typedef struct { - drm_handle_t handle; - drmSize size; - GLuint offset; - GLuint index; - GLuint pitch; - GLuint bpp; - char *map; - GLuint orig; /* The drawing origin, - * at (drawX,drawY) in screen space. - */ - char *origMap; -} viaBuffer, *viaBufferPtr; - - -struct via_context_t { - GLint refcount; - GLcontext *glCtx; - GLcontext *shareCtx; - viaBuffer front; - viaBuffer back; - viaBuffer depth; - GLboolean hasBack; - GLboolean hasDepth; - GLboolean hasStencil; - GLboolean hasAccum; - GLuint depthBits; - GLuint stencilBits; +typedef void (*via_line_func)(struct via_context *, viaVertex *, viaVertex *); +typedef void (*via_point_func)(struct via_context *, viaVertex *); + +struct via_buffer { + drm_handle_t handle; + drmSize size; + GLuint offset; + GLuint index; + GLuint pitch; + GLuint bpp; + char *map; + GLuint orig; /* The drawing origin, + * at (drawX,drawY) in screen space. + */ + char *origMap; +}; + + +#define VIA_MAX_TEXLEVELS 10 + +struct via_tex_buffer { + struct via_tex_buffer *next, *prev; + struct via_texture_image *image; + GLuint index; + GLuint offset; + GLuint size; + GLuint memType; + unsigned char *bufAddr; + GLuint texBase; + GLuint lastUsed; +}; + + + +struct via_texture_image { + struct gl_texture_image image; + struct via_tex_buffer *texMem; + GLint pitchLog2; +}; + +struct via_texture_object { + struct gl_texture_object obj; /* The "parent" object */ + + GLuint texelBytes; + GLuint memType; + + GLuint regTexFM; + GLuint regTexWidthLog2[2]; + GLuint regTexHeightLog2[2]; + GLuint regTexBaseH[4]; + struct { + GLuint baseL; + GLuint pitchLog2; + } regTexBaseAndPitch[12]; + + GLint firstLevel, lastLevel; /* upload tObj->Image[first .. lastLevel] */ +}; + + + +struct via_context { + GLint refcount; + GLcontext *glCtx; + GLcontext *shareCtx; + + struct via_buffer front; + struct via_buffer back; + struct via_buffer depth; + struct via_buffer breadcrumb; + + GLboolean hasBack; + GLboolean hasDepth; + GLboolean hasStencil; + GLboolean hasAccum; + GLuint depthBits; + GLuint stencilBits; GLboolean have_hw_stencil; GLuint ClearDepth; @@ -120,174 +163,148 @@ struct via_context_t { GLfloat depth_max; GLfloat polygon_offset_scale; - GLubyte *dma; - viaRegion tex; + GLubyte *dma; + viaRegion tex; - GLuint isAGP; + /* Bit flag to keep 0track of fallbacks. + */ + GLuint Fallback; - /* Textures + /* State for via_tris.c. */ - viaTextureObjectPtr CurrentTexObj[2]; - struct via_texture_object_t TexObjList; - struct via_texture_object_t SwappedOut; - memHeap_t *texHeap; - - /* Bit flag to keep 0track of fallbacks. - */ - GLuint Fallback; - - /* State for via_tris.c. - */ - GLuint newState; /* _NEW_* flags */ - GLuint newEmitState; /* _NEW_* flags */ - GLuint newRenderState; /* _NEW_* flags */ - - struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX]; - GLuint vertex_attr_count; - - GLuint setupIndex; - GLuint renderIndex; - GLmatrix ViewportMatrix; - GLenum renderPrimitive; - GLenum hwPrimitive; - unsigned char *verts; - - /* drmBufPtr dma_buffer; + GLuint newState; /* _NEW_* flags */ + GLuint newEmitState; /* _NEW_* flags */ + GLuint newRenderState; /* _NEW_* flags */ + + struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX]; + GLuint vertex_attr_count; + + GLuint setupIndex; + GLuint renderIndex; + GLmatrix ViewportMatrix; + GLenum renderPrimitive; + GLenum hwPrimitive; + unsigned char *verts; + + /* drmBufPtr dma_buffer; */ - GLuint dmaLow; - GLuint dmaCliprectAddr; - GLuint dmaLastPrim; - GLboolean useAgp; + GLuint dmaLow; + GLuint dmaCliprectAddr; + GLuint dmaLastPrim; + GLboolean useAgp; - /* Fallback rasterization functions - */ - via_point_func drawPoint; - via_line_func drawLine; - via_tri_func drawTri; - - /* Hardware register - */ - GLuint regCmdA_End; - GLuint regCmdB; - - GLuint regEnable; - GLuint regHFBBMSKL; - GLuint regHROP; - - GLuint regHZWTMD; - GLuint regHSTREF; - GLuint regHSTMD; - - GLuint regHATMD; - GLuint regHABLCsat; - GLuint regHABLCop; - GLuint regHABLAsat; - GLuint regHABLAop; - GLuint regHABLRCa; - GLuint regHABLRFCa; - GLuint regHABLRCbias; - GLuint regHABLRCb; - GLuint regHABLRFCb; - GLuint regHABLRAa; - GLuint regHABLRAb; - GLuint regHFogLF; - GLuint regHFogCL; - GLuint regHFogCH; - - GLuint regHLP; - GLuint regHLPRF; - - GLuint regHTXnTB_0; - GLuint regHTXnMPMD_0; - GLuint regHTXnTBLCsat_0; - GLuint regHTXnTBLCop_0; - GLuint regHTXnTBLMPfog_0; - GLuint regHTXnTBLAsat_0; - GLuint regHTXnTBLRCb_0; - GLuint regHTXnTBLRAa_0; - GLuint regHTXnTBLRFog_0; - /*=* John Sheng [2003.7.18] texture combine *=*/ - GLuint regHTXnTBLRCa_0; - GLuint regHTXnTBLRCc_0; - GLuint regHTXnTBLRCbias_0; - - GLuint regHTXnTB_1; - GLuint regHTXnMPMD_1; - GLuint regHTXnTBLCsat_1; - GLuint regHTXnTBLCop_1; - GLuint regHTXnTBLMPfog_1; - GLuint regHTXnTBLAsat_1; - GLuint regHTXnTBLRCb_1; - GLuint regHTXnTBLRAa_1; - GLuint regHTXnTBLRFog_1; - GLuint regHTXnTBLRCa_1; - GLuint regHTXnTBLRCc_1; - GLuint regHTXnTBLRCbias_1; - - int vertexSize; - int hwVertexSize; - GLboolean ptexHack; - int coloroffset; - int specoffset; - - GLint lastStamp; - - GLenum TexEnvImageFmt[2]; - GLuint ClearColor; - GLuint ClearMask; - - /* DRI stuff - */ - GLuint needClip; - GLframebuffer *glBuffer; - GLboolean doPageFlip; - /*=* John Sheng [2003.5.31] flip *=*/ - GLuint currentPage; - - viaBuffer *drawBuffer; - viaBuffer *readBuffer; - int drawX; /* origin of drawable in draw buffer */ - int drawY; - - int drawW; - int drawH; - - int drawXoff; - GLuint numClipRects; /* cliprects for that buffer */ - drm_clip_rect_t *pClipRects; - - int lastSwap; - int texAge; - int ctxAge; - int dirtyAge; - - GLboolean scissor; - drm_clip_rect_t drawRect; - drm_clip_rect_t scissorRect; - - drm_context_t hHWContext; - drm_hw_lock_t *driHwLock; - int driFd; - __DRInativeDisplay *display; - - __DRIdrawablePrivate *driDrawable; - __DRIscreenPrivate *driScreen; - viaScreenPrivate *viaScreen; - drm_via_sarea_t *sarea; - volatile GLuint* regMMIOBase; - volatile GLuint* pnGEMode; - volatile GLuint* regEngineStatus; - volatile GLuint* regTranSet; - volatile GLuint* regTranSpace; - GLuint* agpBase; - GLuint drawType; + /* Fallback rasterization functions + */ + via_point_func drawPoint; + via_line_func drawLine; + via_tri_func drawTri; + + /* Hardware register + */ + GLuint regCmdA_End; + GLuint regCmdB; + + GLuint regEnable; + GLuint regHFBBMSKL; + GLuint regHROP; + + GLuint regHZWTMD; + GLuint regHSTREF; + GLuint regHSTMD; + + GLuint regHATMD; + GLuint regHABLCsat; + GLuint regHABLCop; + GLuint regHABLAsat; + GLuint regHABLAop; + GLuint regHABLRCa; + GLuint regHABLRFCa; + GLuint regHABLRCbias; + GLuint regHABLRCb; + GLuint regHABLRFCb; + GLuint regHABLRAa; + GLuint regHABLRAb; + GLuint regHFogLF; + GLuint regHFogCL; + GLuint regHFogCH; + + GLuint regHLP; + GLuint regHLPRF; + + GLuint regHTXnCLOD[2]; + GLuint regHTXnTB[2]; + GLuint regHTXnMPMD[2]; + GLuint regHTXnTBLCsat[2]; + GLuint regHTXnTBLCop[2]; + GLuint regHTXnTBLMPfog[2]; + GLuint regHTXnTBLAsat[2]; + GLuint regHTXnTBLRCb[2]; + GLuint regHTXnTBLRAa[2]; + GLuint regHTXnTBLRFog[2]; + GLuint regHTXnTBLRCa[2]; + GLuint regHTXnTBLRCc[2]; + GLuint regHTXnTBLRCbias[2]; + GLuint regHTXnTBC[2]; + GLuint regHTXnTRAH[2]; + + int vertexSize; + int hwVertexSize; + GLboolean ptexHack; + int coloroffset; + int specoffset; + + GLint lastStamp; + + GLuint ClearColor; + GLuint ClearMask; + + /* DRI stuff + */ + GLboolean doPageFlip; + + struct via_buffer *drawBuffer; + struct via_buffer *readBuffer; + + int drawX; /* origin of drawable in draw buffer */ + int drawY; + int drawW; + int drawH; + + int drawXoff; /* drawX is 32byte aligned - this is + * the delta to the real origin, in + * pixel units. + */ + + GLuint numClipRects; /* cliprects for that buffer */ + drm_clip_rect_t *pClipRects; + + GLboolean scissor; + drm_clip_rect_t drawRect; + drm_clip_rect_t scissorRect; + + drm_context_t hHWContext; + drm_hw_lock_t *driHwLock; + int driFd; + __DRInativeDisplay *display; + + __DRIdrawablePrivate *driDrawable; + __DRIscreenPrivate *driScreen; + viaScreenPrivate *viaScreen; + drm_via_sarea_t *sarea; + volatile GLuint* regMMIOBase; + volatile GLuint* pnGEMode; + volatile GLuint* regEngineStatus; + volatile GLuint* regTranSet; + volatile GLuint* regTranSpace; + GLuint* agpBase; + GLuint drawType; GLuint nDoneFirstFlip; GLuint agpFullCount; - GLboolean strictConformance; GLboolean clearTexCache; + GLboolean thrashing; /* Configuration cache */ @@ -304,14 +321,25 @@ struct via_context_t { PFNGLXGETUSTPROC get_ust; + GLuint pfCurrentOffset; + GLboolean allowPageFlip; + + GLuint lastBreadcrumbRead; + GLuint lastBreadcrumbWrite; + GLuint lastSwap[2]; + GLuint lastDma; + + GLuint total_alloc[VIA_MEM_SYSTEM+1]; + + struct via_tex_buffer tex_image_list[VIA_MEM_SYSTEM+1]; + struct via_tex_buffer freed_tex_buffers; + }; -#define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx)) +#define VIA_CONTEXT(ctx) ((struct via_context *)(ctx->DriverCtx)) -#define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch -#define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue /* Lock the hardware and validate our state. @@ -331,31 +359,37 @@ struct via_context_t { #define UNLOCK_HARDWARE(vmesa) \ DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext); -#define WAIT_IDLE(vmesa) \ - do { \ - if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \ - break; \ - } while (1) -#ifdef DEBUG extern GLuint VIA_DEBUG; -#else -#define VIA_DEBUG 0 -#endif - -extern void viaGetLock(viaContextPtr vmesa, GLuint flags); -extern void viaLock(viaContextPtr vmesa, GLuint flags); -extern void viaUnLock(viaContextPtr vmesa, GLuint flags); -extern void viaEmitHwStateLocked(viaContextPtr vmesa); -extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit); -extern void viaXMesaSetBackClipRects(viaContextPtr vmesa); -extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa); +#define DEBUG_TEXTURE 0x1 +#define DEBUG_STATE 0x2 +#define DEBUG_IOCTL 0x4 +#define DEBUG_PRIMS 0x8 +#define DEBUG_VERTS 0x10 +#define DEBUG_FALLBACKS 0x20 +#define DEBUG_VERBOSE 0x40 +#define DEBUG_DRI 0x80 +#define DEBUG_DMA 0x100 +#define DEBUG_SANITY 0x200 +#define DEBUG_SYNC 0x400 +#define DEBUG_SLEEP 0x800 +#define DEBUG_PIXEL 0x1000 +#define DEBUG_2D 0x2000 + + +extern void viaGetLock(struct via_context *vmesa, GLuint flags); +extern void viaLock(struct via_context *vmesa, GLuint flags); +extern void viaUnLock(struct via_context *vmesa, GLuint flags); +extern void viaEmitHwStateLocked(struct via_context *vmesa); +extern void viaEmitScissorValues(struct via_context *vmesa, int box_nr, int emit); +extern void viaXMesaSetBackClipRects(struct via_context *vmesa); +extern void viaXMesaSetFrontClipRects(struct via_context *vmesa); extern void viaReAllocateBuffers(GLframebuffer *drawbuffer); -extern void viaXMesaWindowMoved(viaContextPtr vmesa); +extern void viaXMesaWindowMoved(struct via_context *vmesa); -extern GLboolean viaTexCombineState(viaContextPtr vmesa, +extern GLboolean viaTexCombineState(struct via_context *vmesa, const struct gl_tex_env_combine_state * combine, unsigned unit ); diff --git a/src/mesa/drivers/dri/unichrome/via_dri.h b/src/mesa/drivers/dri/unichrome/via_dri.h index a624398f1aa..7b5574ec29e 100644 --- a/src/mesa/drivers/dri/unichrome/via_dri.h +++ b/src/mesa/drivers/dri/unichrome/via_dri.h @@ -9,10 +9,6 @@ #define VIA_VERSION_MINOR 1 typedef struct { - int CtxOwner; -} VIASAREAPriv; - -typedef struct { drm_handle_t handle; drmSize size; drmAddress map; @@ -29,6 +25,7 @@ typedef struct { int priv2; int fbOffset; int fbSize; + char drixinerama; int backOffset; int depthOffset; int textureOffset; @@ -36,10 +33,8 @@ typedef struct { int irqEnabled; unsigned int scrnX, scrnY; int sarea_priv_offset; - /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/ - int VQEnable; - int DRIIrqEnable; int ringBufActive; + unsigned int reg_pause_addr; } VIADRIRec, *VIADRIPtr; typedef struct { @@ -50,13 +45,4 @@ typedef struct { int dummy; } VIADRIContextRec, *VIADRIContextPtr; -#ifdef XFree86Server - -#include "screenint.h" - -Bool VIADRIScreenInit(ScreenPtr pScreen); -void VIADRICloseScreen(ScreenPtr pScreen); -Bool VIADRIFinishScreenInit(ScreenPtr pScreen); - -#endif #endif diff --git a/src/mesa/drivers/dri/unichrome/via_fb.c b/src/mesa/drivers/dri/unichrome/via_fb.c index b590e833b69..e1215585ae1 100644 --- a/src/mesa/drivers/dri/unichrome/via_fb.c +++ b/src/mesa/drivers/dri/unichrome/via_fb.c @@ -28,15 +28,19 @@ #include "via_ioctl.h" #include "via_fb.h" #include "xf86drm.h" +#include "imports.h" +#include "simple_list.h" #include <sys/ioctl.h> GLboolean -via_alloc_draw_buffer(viaContextPtr vmesa, viaBuffer *buf) +via_alloc_draw_buffer(struct via_context *vmesa, struct via_buffer *buf) { drm_via_mem_t mem; mem.context = vmesa->hHWContext; mem.size = buf->size; - mem.type = VIDEO; + mem.type = VIA_MEM_VIDEO; + mem.offset = 0; + mem.index = 0; if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &mem)) return GL_FALSE; @@ -49,7 +53,7 @@ via_alloc_draw_buffer(viaContextPtr vmesa, viaBuffer *buf) } void -via_free_draw_buffer(viaContextPtr vmesa, viaBuffer *buf) +via_free_draw_buffer(struct via_context *vmesa, struct via_buffer *buf) { drm_via_mem_t mem; @@ -57,135 +61,183 @@ via_free_draw_buffer(viaContextPtr vmesa, viaBuffer *buf) mem.context = vmesa->hHWContext; mem.index = buf->index; - mem.type = VIDEO; + mem.type = VIA_MEM_VIDEO; + mem.offset = buf->offset; + mem.size = buf->size; + ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &mem); buf->map = NULL; } GLboolean -via_alloc_dma_buffer(viaContextPtr vmesa) +via_alloc_dma_buffer(struct via_context *vmesa) { drm_via_dma_init_t init; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); vmesa->dma = (GLubyte *) malloc(VIA_DMA_BUFSIZ); /* * Check whether AGP DMA has been initialized. */ + memset(&init, 0, sizeof(init)); init.func = VIA_DMA_INITIALIZED; + vmesa->useAgp = ( 0 == drmCommandWrite(vmesa->driFd, DRM_VIA_DMA_INIT, &init, sizeof(init))); - if (VIA_DEBUG) { + if (VIA_DEBUG & DEBUG_DMA) { if (vmesa->useAgp) fprintf(stderr, "unichrome_dri.so: Using AGP.\n"); else fprintf(stderr, "unichrome_dri.so: Using PCI.\n"); - - fprintf(stderr, "%s - out\n", __FUNCTION__); } return ((vmesa->dma) ? GL_TRUE : GL_FALSE); } void -via_free_dma_buffer(viaContextPtr vmesa) +via_free_dma_buffer(struct via_context *vmesa) { if (!vmesa) return; free(vmesa->dma); vmesa->dma = 0; } -GLboolean -via_alloc_texture(viaContextPtr vmesa, viaTextureObjectPtr t) + +/* These functions now allocate and free the via_tex_buffer struct as well: + */ +struct via_tex_buffer * +via_alloc_texture(struct via_context *vmesa, + GLuint size, + GLuint memType) { - drm_via_mem_t fb; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - fb.context = vmesa->hHWContext; - fb.size = t->texMem.size; - fb.type = VIDEO; - if (VIA_DEBUG) { - fprintf(stderr, "texture size = %d\n", fb.size); - fprintf(stderr, "texture type = %d\n", fb.type); - } - if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) { - fprintf(stderr, "via_alloc_texture fail\n"); - return GL_FALSE; - } - - t->texMem.offset = fb.offset; - t->texMem.index = fb.index; - if (VIA_DEBUG) fprintf(stderr, "texture index = %d\n", (GLuint)fb.index); - - t->bufAddr = (unsigned char *)(fb.offset + (GLuint)vmesa->driScreen->pFB); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); - return GL_TRUE; + struct via_tex_buffer *t = CALLOC_STRUCT(via_tex_buffer); + + if (!t) + goto cleanup; + + t->size = size; + t->memType = memType; + insert_at_tail(&vmesa->tex_image_list[memType], t); + + if (t->memType == VIA_MEM_AGP || + t->memType == VIA_MEM_VIDEO) { + drm_via_mem_t fb; + + fb.context = vmesa->hHWContext; + fb.size = t->size; + fb.type = t->memType; + fb.offset = 0; + fb.index = 0; + + if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb) != 0 || + fb.index == 0) + goto cleanup; + + if (0) + fprintf(stderr, "offset %lx index %lx\n", fb.offset, fb.index); + + t->offset = fb.offset; + t->index = fb.index; + + if (t->memType == VIA_MEM_AGP) { + t->bufAddr = (GLubyte *)((GLuint)vmesa->viaScreen->agpLinearStart + + fb.offset); + t->texBase = (GLuint)vmesa->agpBase + fb.offset; + } + else { + t->bufAddr = (GLubyte *)(fb.offset + (GLuint)vmesa->driScreen->pFB); + t->texBase = fb.offset; + } + + vmesa->total_alloc[t->memType] += t->size; + return t; + } + else if (t->memType == VIA_MEM_SYSTEM) { + + t->bufAddr = MESA_PBUFFER_ALLOC(t->size); + if (!t->bufAddr) + goto cleanup; + + vmesa->total_alloc[t->memType] += t->size; + return t; + } + + cleanup: + if (t) { + remove_from_list(t); + FREE(t); + } + + return NULL; } -/*=* John Sheng [2003.5.31] agp tex *=*/ -GLboolean -via_alloc_texture_agp(viaContextPtr vmesa, viaTextureObjectPtr t) + + +static void +via_do_free_texture(struct via_context *vmesa, struct via_tex_buffer *t) { - drm_via_mem_t fb; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - fb.context = vmesa->hHWContext; - fb.size = t->texMem.size; - fb.type = AGP; - if (VIA_DEBUG) { - fprintf(stderr, "texture_agp size = %d\n", fb.size); - fprintf(stderr, "texture type = %d\n", fb.type); - } - if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_ALLOCMEM, &fb)) { - fprintf(stderr, "via_alloc_texture_agp fail\n"); - return GL_FALSE; - } - - t->texMem.offset = fb.offset; - t->texMem.index = fb.index; - if (VIA_DEBUG) fprintf(stderr, "texture agp index = %d\n", (GLuint)fb.index); - - t->bufAddr = (unsigned char *)((GLuint)vmesa->viaScreen->agpLinearStart + fb.offset); - /*=* John Sheng [2003.5.31] agp tex *=*/ - t->inAGP = GL_TRUE; - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); - return GL_TRUE; + drm_via_mem_t fb; + + remove_from_list( t ); + + vmesa->total_alloc[t->memType] -= t->size; + + fb.context = vmesa->hHWContext; + fb.index = t->index; + fb.offset = t->offset; + fb.type = t->memType; + fb.size = t->size; + + if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) { + fprintf(stderr, "via_free_texture fail\n"); + } + + FREE(t); +} + + +/* Release textures which were potentially still being referenced by + * hardware at the time when they were originally freed. + */ +void +via_release_pending_textures( struct via_context *vmesa ) +{ + struct via_tex_buffer *s, *tmp; + + foreach_s( s, tmp, &vmesa->freed_tex_buffers ) { + if (s->lastUsed < vmesa->lastBreadcrumbRead) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s: release tex sz %d lastUsed %x\n", + __FUNCTION__, s->size, s->lastUsed); + via_do_free_texture(vmesa, s); + } + } } + + void -via_free_texture(viaContextPtr vmesa, viaTextureObjectPtr t) +via_free_texture(struct via_context *vmesa, struct via_tex_buffer *t) { - drm_via_mem_t fb; - if (VIA_DEBUG) { - fprintf(stderr, "via_free_texture: index = %d\n", - t->texMem.index); - fprintf(stderr, "via_free_texture: size = %d\n", - t->texMem.size); - } - if (!vmesa) { - fprintf(stderr, "!mesa\n"); - return; - } - - fb.context = vmesa->hHWContext; - fb.index = t->texMem.index; - - /*=* John Sheng [2003.5.31] agp tex *=*/ - if(t->inAGP) - fb.type = AGP; - else - fb.type = VIDEO; - - if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) { - if(vmesa->shareCtx) { - fb.context = ((viaContextPtr)((GLcontext *)(vmesa->shareCtx)->DriverCtx))->hHWContext; - if (ioctl(vmesa->driFd, DRM_IOCTL_VIA_FREEMEM, &fb)) { - fprintf(stderr, "via_free_texture fail\n"); - } - } - else - fprintf(stderr, "via_free_texture fail\n"); - } - - t->bufAddr = NULL; + if (!t) { + return; + } + else if (t->memType == VIA_MEM_SYSTEM) { + remove_from_list(t); + vmesa->total_alloc[t->memType] -= t->size; + MESA_PBUFFER_FREE(t->bufAddr); + FREE(t); + } + else if (t->index && viaCheckBreadcrumb(vmesa, t->lastUsed)) { + via_do_free_texture( vmesa, t ); + } + else { + /* Close current breadcrumb so that we can free this eventually: + */ + if (t->lastUsed == vmesa->lastBreadcrumbWrite) + viaEmitBreadcrumb(vmesa); + + move_to_tail( &vmesa->freed_tex_buffers, t ); + } } diff --git a/src/mesa/drivers/dri/unichrome/via_fb.h b/src/mesa/drivers/dri/unichrome/via_fb.h index 23fc861459f..7ee153f474f 100644 --- a/src/mesa/drivers/dri/unichrome/via_fb.h +++ b/src/mesa/drivers/dri/unichrome/via_fb.h @@ -27,12 +27,16 @@ #include "via_context.h" -extern GLboolean via_alloc_draw_buffer(viaContextPtr vmesa, viaBuffer *buf); -extern GLboolean via_alloc_dma_buffer(viaContextPtr vmesa); -extern GLboolean via_alloc_texture(viaContextPtr vmesa, viaTextureObjectPtr t); -extern GLboolean via_alloc_texture_agp(viaContextPtr vmesa, viaTextureObjectPtr t); +extern GLboolean via_alloc_draw_buffer(struct via_context *vmesa, struct via_buffer *buf); +extern GLboolean via_alloc_dma_buffer(struct via_context *vmesa); -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); +struct via_tex_buffer * +via_alloc_texture(struct via_context *vmesa, + GLuint size, + GLuint memType); + +extern void via_free_draw_buffer(struct via_context *vmesa, struct via_buffer *buf); +extern void via_free_dma_buffer(struct via_context *vmesa); +extern void via_free_texture(struct via_context *vmesa, struct via_tex_buffer *t); +void via_release_pending_textures( struct via_context *vmesa ); #endif diff --git a/src/mesa/drivers/dri/unichrome/via_ioctl.c b/src/mesa/drivers/dri/unichrome/via_ioctl.c index e90ec0f78e4..b9997be1efb 100644 --- a/src/mesa/drivers/dri/unichrome/via_ioctl.c +++ b/src/mesa/drivers/dri/unichrome/via_ioctl.c @@ -35,6 +35,8 @@ #include "via_tris.h" #include "via_ioctl.h" #include "via_state.h" +#include "via_fb.h" +#include "via_3d_reg.h" #include "vblank.h" #include "drm.h" @@ -73,7 +75,7 @@ #define VIA_BLIT_FILL 0xF0 #define VIA_BLIT_SET 0xFF -static void dump_dma( viaContextPtr vmesa ) +static void dump_dma( struct via_context *vmesa ) { GLuint i; GLuint *data = (GLuint *)vmesa->dma; @@ -89,7 +91,7 @@ static void dump_dma( viaContextPtr vmesa ) -void viaCheckDma(viaContextPtr vmesa, GLuint bytes) +void viaCheckDma(struct via_context *vmesa, GLuint bytes) { VIA_FINISH_PRIM( vmesa ); if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) { @@ -105,7 +107,7 @@ void viaCheckDma(viaContextPtr vmesa, GLuint bytes) } while (0) -static void viaBlit(viaContextPtr vmesa, GLuint bpp, +static void viaBlit(struct via_context *vmesa, GLuint bpp, GLuint srcBase, GLuint srcPitch, GLuint dstBase, GLuint dstPitch, GLuint w, GLuint h, @@ -116,9 +118,12 @@ static void viaBlit(viaContextPtr vmesa, GLuint bpp, GLuint dwGEMode, srcX, dstX, cmd; RING_VARS; - if (VIA_DEBUG) - fprintf(stderr, "%s bpp %d src %x/%x dst %x/%x w %d h %d mode: %x color: 0x%08x mask 0x%08x\n", - __FUNCTION__, bpp, srcBase, srcPitch, dstBase, dstPitch, w,h, blitMode, color, nMask); + if (VIA_DEBUG & DEBUG_2D) + fprintf(stderr, + "%s bpp %d src %x/%x dst %x/%x w %d h %d " + " mode: %x color: 0x%08x mask 0x%08x\n", + __FUNCTION__, bpp, srcBase, srcPitch, dstBase, + dstPitch, w,h, blitMode, color, nMask); if (!w || !h) @@ -166,8 +171,8 @@ static void viaBlit(viaContextPtr vmesa, GLuint bpp, ADVANCE_RING(); } -static void viaFillBuffer(viaContextPtr vmesa, - viaBuffer *buffer, +static void viaFillBuffer(struct via_context *vmesa, + struct via_buffer *buffer, drm_clip_rect_t *pbox, int nboxes, GLuint pixel, @@ -200,7 +205,7 @@ static void viaFillBuffer(viaContextPtr vmesa, static void viaClear(GLcontext *ctx, GLbitfield mask, GLboolean all, GLint cx, GLint cy, GLint cw, GLint ch) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); __DRIdrawablePrivate *dPriv = vmesa->driDrawable; int flag = 0; GLuint i = 0; @@ -236,8 +241,8 @@ static void viaClear(GLcontext *ctx, GLbitfield mask, GLboolean all, mask &= ~DD_STENCIL_BIT; } else { - if (VIA_DEBUG) - fprintf(stderr, "XXX: Clear stencil writemask %x -- need triangles (or a ROP?)\n", + if (VIA_DEBUG & DEBUG_2D) + fprintf(stderr, "Clear stencil writemask %x\n", ctx->Stencil.WriteMask[0]); } } @@ -267,8 +272,9 @@ static void viaClear(GLcontext *ctx, GLbitfield mask, GLboolean all, if (!all) { drm_clip_rect_t *b = vmesa->pClipRects; - boxes = tmp_boxes = (drm_clip_rect_t *)malloc(vmesa->numClipRects * - sizeof(drm_clip_rect_t)); + boxes = tmp_boxes = + (drm_clip_rect_t *)malloc(vmesa->numClipRects * + sizeof(drm_clip_rect_t)); if (!boxes) { UNLOCK_HARDWARE(vmesa); return; @@ -300,15 +306,18 @@ static void viaClear(GLcontext *ctx, GLbitfield mask, GLboolean all, } if (flag & VIA_FRONT) { - viaFillBuffer(vmesa, &vmesa->front, boxes, nr, vmesa->ClearColor, vmesa->ClearMask); + viaFillBuffer(vmesa, &vmesa->front, boxes, nr, vmesa->ClearColor, + vmesa->ClearMask); } if (flag & VIA_BACK) { - viaFillBuffer(vmesa, &vmesa->back, boxes, nr, vmesa->ClearColor, vmesa->ClearMask); + viaFillBuffer(vmesa, &vmesa->back, boxes, nr, vmesa->ClearColor, + vmesa->ClearMask); } if (flag & VIA_DEPTH) { - viaFillBuffer(vmesa, &vmesa->depth, boxes, nr, clear_depth, clear_depth_mask); + viaFillBuffer(vmesa, &vmesa->depth, boxes, nr, clear_depth, + clear_depth_mask); } viaFlushDmaLocked(vmesa, VIA_NO_CLIPRECTS); @@ -325,13 +334,13 @@ static void viaClear(GLcontext *ctx, GLbitfield mask, GLboolean all, -static void viaDoSwapBuffers(viaContextPtr vmesa, +static void viaDoSwapBuffers(struct via_context *vmesa, drm_clip_rect_t *b, GLuint nbox) { GLuint bytePerPixel = vmesa->viaScreen->bitsPerPixel >> 3; - viaBuffer *front = &vmesa->front; - viaBuffer *back = &vmesa->back; + struct via_buffer *front = &vmesa->front; + struct via_buffer *back = &vmesa->back; GLuint i; for (i = 0; i < nbox; i++, b++) { @@ -350,96 +359,295 @@ static void viaDoSwapBuffers(viaContextPtr vmesa, w, h, VIA_BLIT_COPY, 0, 0); } + + viaFlushDmaLocked(vmesa, VIA_NO_CLIPRECTS); /* redundant */ +} + + +static void viaEmitBreadcrumbLocked( struct via_context *vmesa ) +{ + struct via_buffer *buffer = &vmesa->breadcrumb; + GLuint value = vmesa->lastBreadcrumbWrite + 1; + + if (VIA_DEBUG & DEBUG_IOCTL) + fprintf(stderr, "%s %d\n", __FUNCTION__, value); + + assert(!vmesa->dmaLow); + + viaBlit(vmesa, + buffer->bpp, + buffer->offset, buffer->pitch, + buffer->offset, buffer->pitch, + 1, 1, + VIA_BLIT_FILL, value, 0); + + viaFlushDmaLocked(vmesa, VIA_NO_CLIPRECTS); /* often redundant */ + vmesa->lastBreadcrumbWrite = value; +} + +void viaEmitBreadcrumb( struct via_context *vmesa ) +{ + LOCK_HARDWARE(vmesa); + if (vmesa->dmaLow) + viaFlushDmaLocked(vmesa, 0); + + viaEmitBreadcrumbLocked( vmesa ); + UNLOCK_HARDWARE(vmesa); +} + +static GLboolean viaCheckIdle( struct via_context *vmesa ) +{ + if ((vmesa->regEngineStatus[0] & 0xFFFEFFFF) == 0x00020000) { + return GL_TRUE; + } + return GL_FALSE; +} + + +GLboolean viaCheckBreadcrumb( struct via_context *vmesa, GLuint value ) +{ + GLuint *buf = (GLuint *)vmesa->breadcrumb.map; + vmesa->lastBreadcrumbRead = *buf; + + if (VIA_DEBUG & DEBUG_IOCTL) + fprintf(stderr, "%s %d < %d: %d\n", __FUNCTION__, value, + vmesa->lastBreadcrumbRead, + value < vmesa->lastBreadcrumbRead); + + return value < vmesa->lastBreadcrumbRead; +} + +static void viaWaitBreadcrumb( struct via_context *vmesa, GLuint value ) +{ + if (VIA_DEBUG & DEBUG_IOCTL) + fprintf(stderr, "%s %d\n", __FUNCTION__, value); + + assert(value < vmesa->lastBreadcrumbWrite); + + while (!viaCheckBreadcrumb( vmesa, value )) { + viaSwapOutWork( vmesa ); + via_release_pending_textures( vmesa ); + } +} + + +void viaWaitIdle( struct via_context *vmesa ) +{ + VIA_FLUSH_DMA(vmesa); + + if (VIA_DEBUG & DEBUG_IOCTL) + fprintf(stderr, "%s lastDma %d lastBreadcrumbWrite %d\n", + __FUNCTION__, vmesa->lastDma, vmesa->lastBreadcrumbWrite); + + /* Need to emit a new breadcrumb? + */ + if (vmesa->lastDma == vmesa->lastBreadcrumbWrite) { + LOCK_HARDWARE(vmesa); + viaEmitBreadcrumbLocked( vmesa ); + UNLOCK_HARDWARE(vmesa); + } + + /* Need to wait? + */ + if (vmesa->lastDma >= vmesa->lastBreadcrumbRead) + viaWaitBreadcrumb( vmesa, vmesa->lastDma ); + + while(!viaCheckIdle(vmesa)) + ; + + via_release_pending_textures(vmesa); +} + + +void viaWaitIdleLocked( struct via_context *vmesa ) +{ + if (vmesa->dmaLow) + viaFlushDmaLocked(vmesa, 0); + + if (VIA_DEBUG & DEBUG_IOCTL) + fprintf(stderr, "%s lastDma %d lastBreadcrumbWrite %d\n", + __FUNCTION__, vmesa->lastDma, vmesa->lastBreadcrumbWrite); + + /* Need to emit a new breadcrumb? + */ + if (vmesa->lastDma == vmesa->lastBreadcrumbWrite) { + viaEmitBreadcrumbLocked( vmesa ); + } + + /* Need to wait? + */ + if (vmesa->lastDma >= vmesa->lastBreadcrumbRead) + viaWaitBreadcrumb( vmesa, vmesa->lastDma ); + + while(!viaCheckIdle(vmesa)) + ; + + via_release_pending_textures(vmesa); } +/* Wait for command stream to be processed *and* the next vblank to + * occur. Equivalent to calling WAIT_IDLE() and then WaitVBlank, + * except that WAIT_IDLE() will spin the CPU polling, while this is + * IRQ driven. + */ +static void viaWaitIdleVBlank( const __DRIdrawablePrivate *dPriv, + struct via_context *vmesa, + GLuint value ) +{ + GLboolean missed_target; + + VIA_FLUSH_DMA(vmesa); + + if (!value) + return; + + do { + if (value < vmesa->lastBreadcrumbRead || + vmesa->thrashing) + viaSwapOutWork(vmesa); + + driWaitForVBlank( dPriv, & vmesa->vbl_seq, + vmesa->vblank_flags, & missed_target ); + if ( missed_target ) { + vmesa->swap_missed_count++; + vmesa->get_ust( &vmesa->swap_missed_ust ); + } + } + while (!viaCheckBreadcrumb(vmesa, value)); + + vmesa->thrashing = 0; /* reset flag on swap */ + vmesa->swap_count++; + via_release_pending_textures( vmesa ); +} + + + +static void viaDoPageFlipLocked(struct via_context *vmesa, GLuint offset) +{ + RING_VARS; + + if (VIA_DEBUG & DEBUG_2D) + fprintf(stderr, "%s %x\n", __FUNCTION__, offset); + + if (!vmesa->nDoneFirstFlip) { + vmesa->nDoneFirstFlip = GL_TRUE; + BEGIN_RING(4); + OUT_RING(HALCYON_HEADER2); + OUT_RING(0x00fe0000); + OUT_RING(0x0000000e); + OUT_RING(0x0000000e); + ADVANCE_RING(); + } + + BEGIN_RING(4); + OUT_RING( HALCYON_HEADER2 ); + OUT_RING( 0x00fe0000 ); + OUT_RING((HC_SubA_HFBBasL << 24) | (offset & 0xFFFFF8) | 0x2); + OUT_RING((HC_SubA_HFBDrawFirst << 24) | + ((offset & 0xFF000000) >> 24) | 0x0100); + ADVANCE_RING(); + + vmesa->pfCurrentOffset = vmesa->sarea->pfCurrentOffset = offset; + + viaFlushDmaLocked(vmesa, VIA_NO_CLIPRECTS); /* often redundant */ +} + +void viaResetPageFlippingLocked(struct via_context *vmesa) +{ + if (VIA_DEBUG & DEBUG_2D) + fprintf(stderr, "%s\n", __FUNCTION__); + + viaDoPageFlipLocked( vmesa, 0 ); + + if (vmesa->front.offset != 0) { + struct via_buffer buffer_tmp; + memcpy(&buffer_tmp, &vmesa->back, sizeof(struct via_buffer)); + memcpy(&vmesa->back, &vmesa->front, sizeof(struct via_buffer)); + memcpy(&vmesa->front, &buffer_tmp, sizeof(struct via_buffer)); + } + + assert(vmesa->front.offset == 0); + vmesa->doPageFlip = vmesa->allowPageFlip = 0; +} + /* * Copy the back buffer to the front buffer. */ void viaCopyBuffer(const __DRIdrawablePrivate *dPriv) { - viaContextPtr vmesa = (viaContextPtr)dPriv->driContextPriv->driverPrivate; - GLboolean missed_target; + struct via_context *vmesa = + (struct via_context *)dPriv->driContextPriv->driverPrivate; + + if (VIA_DEBUG & DEBUG_IOCTL) + fprintf(stderr, + "%s: lastSwap[1] %d lastSwap[0] %d lastWrite %d lastRead %d\n", + __FUNCTION__, + vmesa->lastSwap[1], + vmesa->lastSwap[0], + vmesa->lastBreadcrumbWrite, + vmesa->lastBreadcrumbRead); VIA_FLUSH_DMA(vmesa); - driWaitForVBlank( dPriv, & vmesa->vbl_seq, vmesa->vblank_flags, & missed_target ); - if ( missed_target ) { - vmesa->swap_missed_count++; - vmesa->get_ust( &vmesa->swap_missed_ust ); - } + + if (vmesa->vblank_flags == VBLANK_FLAG_SYNC && + vmesa->lastBreadcrumbWrite > 1) + viaWaitIdleVBlank(dPriv, vmesa, vmesa->lastBreadcrumbWrite-1); + else + viaWaitIdleVBlank(dPriv, vmesa, vmesa->lastSwap[1]); + LOCK_HARDWARE(vmesa); - viaDoSwapBuffers(vmesa, dPriv->pClipRects, dPriv->numClipRects); - viaFlushDmaLocked(vmesa, VIA_NO_CLIPRECTS); + /* Catch and cleanup situation where we were pageflipping but have + * stopped. + */ + if (dPriv->numClipRects && vmesa->sarea->pfCurrentOffset != 0) { + viaResetPageFlippingLocked(vmesa); + UNLOCK_HARDWARE(vmesa); + return; + } + viaDoSwapBuffers(vmesa, dPriv->pClipRects, dPriv->numClipRects); + vmesa->lastSwap[1] = vmesa->lastSwap[0]; + vmesa->lastSwap[0] = vmesa->lastBreadcrumbWrite; + viaEmitBreadcrumbLocked(vmesa); UNLOCK_HARDWARE(vmesa); - vmesa->swap_count++; + vmesa->get_ust( &vmesa->swap_ust ); } -/* - * XXX implement when full-screen extension is done. - */ + void viaPageFlip(const __DRIdrawablePrivate *dPriv) { - viaContextPtr vmesa = (viaContextPtr)dPriv->driContextPriv->driverPrivate; - viaBuffer buffer_tmp; - GLboolean missed_target; - + struct via_context *vmesa = + (struct via_context *)dPriv->driContextPriv->driverPrivate; + struct via_buffer buffer_tmp; VIA_FLUSH_DMA(vmesa); - driWaitForVBlank( dPriv, &vmesa->vbl_seq, vmesa->vblank_flags, &missed_target ); - if ( missed_target ) { - vmesa->swap_missed_count++; - vmesa->get_ust( &vmesa->swap_missed_ust ); - } - LOCK_HARDWARE(vmesa); - - { - RING_VARS; - - if (!vmesa->nDoneFirstFlip) { - vmesa->nDoneFirstFlip = GL_FALSE; /* XXX: FIXME LATER!!! */ - BEGIN_RING(4); - OUT_RING(HALCYON_HEADER2); - OUT_RING(0x00fe0000); - OUT_RING(0x0000000e); - OUT_RING(0x0000000e); - ADVANCE_RING(); - } - - BEGIN_RING(4); - OUT_RING( HALCYON_HEADER2 ); - OUT_RING( 0x00fe0000 ); - OUT_RING((HC_SubA_HFBBasL << 24) | (vmesa->back.offset & 0xFFFFF8) | 0x2); - OUT_RING((HC_SubA_HFBDrawFirst << 24) | - ((vmesa->back.offset & 0xFF000000) >> 24) | 0x0100); - ADVANCE_RING(); - - } + if (vmesa->vblank_flags == VBLANK_FLAG_SYNC && + vmesa->lastBreadcrumbWrite > 1) + viaWaitIdleVBlank(dPriv, vmesa, vmesa->lastBreadcrumbWrite - 1); + else + viaWaitIdleVBlank(dPriv, vmesa, vmesa->lastSwap[0]); - viaFlushDmaLocked(vmesa, VIA_NO_CLIPRECTS); + LOCK_HARDWARE(vmesa); + viaDoPageFlipLocked(vmesa, vmesa->back.offset); + vmesa->lastSwap[1] = vmesa->lastSwap[0]; + vmesa->lastSwap[0] = vmesa->lastBreadcrumbWrite; + viaEmitBreadcrumbLocked(vmesa); UNLOCK_HARDWARE(vmesa); - vmesa->swap_count++; + vmesa->get_ust( &vmesa->swap_ust ); + /* KW: FIXME: When buffers are freed, could free frontbuffer by * accident: */ - memcpy(&buffer_tmp, &vmesa->back, sizeof(viaBuffer)); - memcpy(&vmesa->back, &vmesa->front, sizeof(viaBuffer)); - memcpy(&vmesa->front, &buffer_tmp, sizeof(viaBuffer)); - - if(vmesa->currentPage) { - vmesa->currentPage = 0; - } - else { - vmesa->currentPage = 1; - } - - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); + memcpy(&buffer_tmp, &vmesa->back, sizeof(struct via_buffer)); + memcpy(&vmesa->back, &vmesa->front, sizeof(struct via_buffer)); + memcpy(&vmesa->front, &buffer_tmp, sizeof(struct via_buffer)); } @@ -447,7 +655,7 @@ void viaPageFlip(const __DRIdrawablePrivate *dPriv) #define VIA_CMDBUF_MAX_LAG 50000 -static int fire_buffer(viaContextPtr vmesa) +static int fire_buffer(struct via_context *vmesa) { drm_via_cmdbuffer_t bufI; int ret; @@ -469,7 +677,8 @@ static int fire_buffer(viaContextPtr vmesa) } while (ret == -EAGAIN); if (ret) { UNLOCK_HARDWARE(vmesa); - fprintf(stderr, "%s: DRM_VIA_CMDBUF_SIZE returned %d\n", __FUNCTION__, ret); + fprintf(stderr, "%s: DRM_VIA_CMDBUF_SIZE returned %d\n", + __FUNCTION__, ret); abort(); return ret; } @@ -482,7 +691,8 @@ static int fire_buffer(viaContextPtr vmesa) } while (ret == -EAGAIN); if (ret) { UNLOCK_HARDWARE(vmesa); - fprintf(stderr, "%s: DRM_VIA_CMDBUFFER returned %d\n", __FUNCTION__, ret); + fprintf(stderr, "%s: DRM_VIA_CMDBUFFER returned %d\n", + __FUNCTION__, ret); abort(); /* If this fails, the original code fell back to the PCI path. */ @@ -492,14 +702,14 @@ static int fire_buffer(viaContextPtr vmesa) /* Fall through to PCI handling?!? */ - WAIT_IDLE(vmesa); + viaWaitIdleLocked(vmesa); } ret = drmCommandWrite(vmesa->driFd, DRM_VIA_PCICMD, &bufI, sizeof(bufI)); if (ret) { UNLOCK_HARDWARE(vmesa); dump_dma(vmesa); - fprintf(stderr, "%s: DRM_VIA_PCICMD returned %d\n", __FUNCTION__, ret); + fprintf(stderr, "%s: DRM_VIA_PCICMD returned %d\n", __FUNCTION__, ret); abort(); } @@ -511,10 +721,10 @@ static int fire_buffer(viaContextPtr vmesa) * into the head of the DMA buffer being flushed. Fires the buffer * for each cliprect. */ -static void via_emit_cliprect(viaContextPtr vmesa, +static void via_emit_cliprect(struct via_context *vmesa, drm_clip_rect_t *b) { - viaBuffer *buffer = vmesa->drawBuffer; + struct via_buffer *buffer = vmesa->drawBuffer; GLuint *vb = (GLuint *)(vmesa->dma + vmesa->dmaCliprectAddr); GLuint format = (vmesa->viaScreen->bitsPerPixel == 0x20 @@ -525,7 +735,8 @@ static void via_emit_cliprect(viaContextPtr vmesa, GLuint offset = buffer->orig; if (0) - fprintf(stderr, "emit cliprect for box %d,%d %d,%d\n", b->x1, b->y1, b->x2, b->y2); + fprintf(stderr, "emit cliprect for box %d,%d %d,%d\n", + b->x1, b->y1, b->x2, b->y2); vb[0] = HC_HEADER2; vb[1] = (HC_ParaType_NotTex << 16); @@ -539,11 +750,11 @@ static void via_emit_cliprect(viaContextPtr vmesa, vb[3] = (HC_SubA_HClipLR << 24) | (b->x1 << 12) | b->x2; } - vb[4] = ((HC_SubA_HDBBasL << 24) | (offset & 0xFFFFFF)); - vb[5] = ((HC_SubA_HDBBasH << 24) | ((offset & 0xFF000000)) >> 24); + vb[4] = (HC_SubA_HDBBasL << 24) | (offset & 0xFFFFFF); + vb[5] = (HC_SubA_HDBBasH << 24) | ((offset & 0xFF000000) >> 24); - vb[6] = ((HC_SubA_HSPXYOS << 24) | ((31 - vmesa->drawXoff) << HC_HSPXOS_SHIFT)); - vb[7] = ((HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch); + vb[6] = (HC_SubA_HSPXYOS << 24) | ((31-vmesa->drawXoff) << HC_HSPXOS_SHIFT); + vb[7] = (HC_SubA_HDBFM << 24) | HC_HDBLoc_Local | format | pitch; } @@ -570,16 +781,17 @@ static int intersect_rect(drm_clip_rect_t *out, return 1; } -void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags) +void viaFlushDmaLocked(struct via_context *vmesa, GLuint flags) { int i; RING_VARS; - if (VIA_DEBUG) + if (VIA_DEBUG & (DEBUG_IOCTL|DEBUG_DMA)) fprintf(stderr, "%s\n", __FUNCTION__); if (*(GLuint *)vmesa->driHwLock != (DRM_LOCK_HELD|vmesa->hHWContext) && - *(GLuint *)vmesa->driHwLock != (DRM_LOCK_HELD|DRM_LOCK_CONT|vmesa->hHWContext)) { + *(GLuint *)vmesa->driHwLock != + (DRM_LOCK_HELD|DRM_LOCK_CONT|vmesa->hHWContext)) { fprintf(stderr, "%s called without lock held\n", __FUNCTION__); abort(); } @@ -633,13 +845,14 @@ void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags) case 0: break; default: - if (VIA_DEBUG) + if (VIA_DEBUG & DEBUG_IOCTL) fprintf(stderr, "%s: unaligned value for vmesa->dmaLow: %x\n", __FUNCTION__, vmesa->dmaLow); } + vmesa->lastDma = vmesa->lastBreadcrumbWrite; - if (VIA_DEBUG) + if (VIA_DEBUG & DEBUG_DMA) dump_dma( vmesa ); if (flags & VIA_NO_CLIPRECTS) { @@ -655,7 +868,6 @@ void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags) } else if (vmesa->numClipRects) { drm_clip_rect_t *pbox = vmesa->pClipRects; - if (0) fprintf(stderr, "%s: %d cliprects\n", __FUNCTION__, vmesa->numClipRects); for (i = 0; i < vmesa->numClipRects; i++) { drm_clip_rect_t b; @@ -694,12 +906,12 @@ void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags) vmesa->newEmitState = ~0; } -void viaWrapPrimitive( viaContextPtr vmesa ) +void viaWrapPrimitive( struct via_context *vmesa ) { GLenum renderPrimitive = vmesa->renderPrimitive; GLenum hwPrimitive = vmesa->hwPrimitive; - if (VIA_DEBUG) fprintf(stderr, "%s\n", __FUNCTION__); + if (VIA_DEBUG & DEBUG_PRIMS) fprintf(stderr, "%s\n", __FUNCTION__); if (vmesa->dmaLastPrim) viaFinishPrimitive( vmesa ); @@ -713,7 +925,7 @@ void viaWrapPrimitive( viaContextPtr vmesa ) } -void viaFlushDma(viaContextPtr vmesa) +void viaFlushDma(struct via_context *vmesa) { if (vmesa->dmaLow) { assert(!vmesa->dmaLastPrim); @@ -726,15 +938,15 @@ void viaFlushDma(viaContextPtr vmesa) static void viaFlush(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); VIA_FLUSH_DMA(vmesa); } static void viaFinish(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); VIA_FLUSH_DMA(vmesa); - WAIT_IDLE(vmesa); + viaWaitIdle(vmesa); } static void viaClearStencil(GLcontext *ctx, int s) diff --git a/src/mesa/drivers/dri/unichrome/via_ioctl.h b/src/mesa/drivers/dri/unichrome/via_ioctl.h index 5facad50f76..88bc52b7c40 100644 --- a/src/mesa/drivers/dri/unichrome/via_ioctl.h +++ b/src/mesa/drivers/dri/unichrome/via_ioctl.h @@ -28,14 +28,21 @@ #include "via_context.h" -void viaFinishPrimitive(viaContextPtr vmesa); -void viaFlushDma(viaContextPtr vmesa); -void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags); +void viaFinishPrimitive(struct via_context *vmesa); +void viaFlushDma(struct via_context *vmesa); +void viaFlushDmaLocked(struct via_context *vmesa, GLuint flags); void viaInitIoctlFuncs(GLcontext *ctx); void viaCopyBuffer(const __DRIdrawablePrivate *dpriv); void viaPageFlip(const __DRIdrawablePrivate *dpriv); -void viaCheckDma(viaContextPtr vmesa, GLuint bytes); +void viaCheckDma(struct via_context *vmesa, GLuint bytes); +void viaResetPageFlippingLocked(struct via_context *vmesa); +void viaWaitIdle(struct via_context *vmesa); +void viaWaitIdleLocked(struct via_context *vmesa); + +GLboolean viaCheckBreadcrumb( struct via_context *vmesa, GLuint value ); +void viaEmitBreadcrumb( struct via_context *vmesa ); + #define VIA_FINISH_PRIM(vmesa) do { \ if (vmesa->dmaLastPrim) \ @@ -49,9 +56,9 @@ void viaCheckDma(viaContextPtr vmesa, GLuint bytes); } while (0) -void viaWrapPrimitive( viaContextPtr vmesa ); +void viaWrapPrimitive( struct via_context *vmesa ); -static __inline__ GLuint *viaAllocDma(viaContextPtr vmesa, int bytes) +static __inline__ GLuint *viaAllocDma(struct via_context *vmesa, int bytes) { if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) { viaFlushDma(vmesa); @@ -65,7 +72,7 @@ static __inline__ GLuint *viaAllocDma(viaContextPtr vmesa, int bytes) } -static GLuint __inline__ *viaExtendPrimitive(viaContextPtr vmesa, int bytes) +static GLuint __inline__ *viaExtendPrimitive(struct via_context *vmesa, int bytes) { if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) { viaWrapPrimitive(vmesa); diff --git a/src/mesa/drivers/dri/unichrome/via_render.c b/src/mesa/drivers/dri/unichrome/via_render.c index fc4c9e09f7e..201235410db 100644 --- a/src/mesa/drivers/dri/unichrome/via_render.c +++ b/src/mesa/drivers/dri/unichrome/via_render.c @@ -59,7 +59,7 @@ #define HAVE_ELTS 0 -#define LOCAL_VARS viaContextPtr vmesa = VIA_CONTEXT(ctx) +#define LOCAL_VARS struct via_context *vmesa = VIA_CONTEXT(ctx) #define INIT(prim) do { \ viaRasterPrimitive(ctx, prim, prim); \ } while (0) @@ -88,7 +88,7 @@ static GLboolean via_run_fastrender(GLcontext *ctx, struct tnl_pipeline_stage *stage) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLuint i; @@ -119,7 +119,8 @@ static GLboolean via_run_fastrender(GLcontext *ctx, } -static void via_check_fastrender(GLcontext *ctx, struct tnl_pipeline_stage *stage) +static void via_check_fastrender(GLcontext *ctx, + struct tnl_pipeline_stage *stage) { stage->inputs = TNL_CONTEXT(ctx)->render_inputs; } diff --git a/src/mesa/drivers/dri/unichrome/via_screen.c b/src/mesa/drivers/dri/unichrome/via_screen.c index 7ced8fe50fa..dbe7a38c3d3 100644 --- a/src/mesa/drivers/dri/unichrome/via_screen.c +++ b/src/mesa/drivers/dri/unichrome/via_screen.c @@ -83,12 +83,21 @@ static drmBufMapPtr via_create_empty_buffers(void) return retval; } +static void via_free_empty_buffers( drmBufMapPtr bufs ) +{ + if (bufs && bufs->list) + FREE(bufs->list); + + if (bufs) + FREE(bufs); +} + + static GLboolean viaInitDriver(__DRIscreenPrivate *sPriv) { viaScreenPrivate *viaScreen; VIADRIPtr gDRIPriv = (VIADRIPtr)sPriv->pDevPriv; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); /* Allocate the private area */ @@ -117,20 +126,13 @@ viaInitDriver(__DRIscreenPrivate *sPriv) viaScreen->irqEnabled = gDRIPriv->irqEnabled; viaScreen->irqEnabled = 1; - if (VIA_DEBUG) { + if (VIA_DEBUG & DEBUG_DRI) { fprintf(stderr, "deviceID = %08x\n", viaScreen->deviceID); fprintf(stderr, "width = %08x\n", viaScreen->width); fprintf(stderr, "height = %08x\n", viaScreen->height); fprintf(stderr, "cpp = %08x\n", viaScreen->cpp); fprintf(stderr, "fbOffset = %08x\n", viaScreen->fbOffset); } - /* DBG */ - /* - if (gDRIPriv->bitsPerPixel == 15) - viaScreen->fbFormat = DV_PF_555; - else - viaScreen->fbFormat = DV_PF_565; - */ viaScreen->bufs = via_create_empty_buffers(); if (viaScreen->bufs == NULL) { @@ -170,7 +172,8 @@ viaInitDriver(__DRIscreenPrivate *sPriv) if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) { PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension = - (PFNGLXSCRENABLEEXTENSIONPROC) glXGetProcAddress( (const GLubyte *) "__glXScrEnableExtension" ); + (PFNGLXSCRENABLEEXTENSIONPROC) glXGetProcAddress( + (const GLubyte *) "__glXScrEnableExtension" ); void * const psc = sPriv->psc->screenConfigs; if ( glx_enable_extension != NULL ) { @@ -190,9 +193,6 @@ viaInitDriver(__DRIscreenPrivate *sPriv) } } - - - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); return GL_TRUE; } @@ -201,11 +201,13 @@ viaDestroyScreen(__DRIscreenPrivate *sPriv) { viaScreenPrivate *viaScreen = (viaScreenPrivate *)sPriv->private; VIADRIPtr gDRIPriv = (VIADRIPtr)sPriv->pDevPriv; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); + drmUnmap(viaScreen->reg, gDRIPriv->regs.size); if (gDRIPriv->agp.size) drmUnmap(viaScreen->agpLinearStart, gDRIPriv->agp.size); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); + + via_free_empty_buffers(viaScreen->bufs); + FREE(viaScreen); sPriv->private = NULL; } @@ -231,7 +233,6 @@ viaCreateBuffer(__DRIscreenPrivate *driScrnPriv, mesaVis->accumRedBits > 0, GL_FALSE /* s/w alpha planes */); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); return (driDrawPriv->driverPrivate != NULL); #endif return GL_FALSE; @@ -333,7 +334,8 @@ viaFillInModes( unsigned pixel_bits, GLboolean have_back_buffer ) modes = (*create_context_modes)( num_modes, sizeof( __GLcontextModes ) ); m = modes; if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, back_buffer_factor, GLX_TRUE_COLOR ) ) { fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", @@ -342,7 +344,8 @@ viaFillInModes( unsigned pixel_bits, GLboolean have_back_buffer ) } if ( ! driFillInModes( & m, fb_format, fb_type, - depth_bits_array, stencil_bits_array, depth_buffer_factor, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, back_buffer_factor, GLX_DIRECT_COLOR ) ) { fprintf( stderr, "[%s:%u] Error creating FBConfig!\n", @@ -367,7 +370,8 @@ viaFillInModes( unsigned pixel_bits, GLboolean have_back_buffer ) */ #ifdef USE_NEW_INTERFACE PUBLIC -void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc, +void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, + __DRIscreen *psc, const __GLcontextModes * modes, const __DRIversion * ddx_version, const __DRIversion * dri_version, @@ -416,7 +420,7 @@ void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) { - viaContextPtr vmesa; + struct via_context *vmesa; if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL) || (dPriv->driContextPriv->driverPrivate == NULL) @@ -424,7 +428,7 @@ getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) return -1; } - vmesa = (viaContextPtr) dPriv->driContextPriv->driverPrivate; + vmesa = (struct via_context *) dPriv->driContextPriv->driverPrivate; sInfo->swap_count = vmesa->swap_count; sInfo->swap_ust = vmesa->swap_ust; sInfo->swap_missed_count = vmesa->swap_missed_count; diff --git a/src/mesa/drivers/dri/unichrome/via_span.c b/src/mesa/drivers/dri/unichrome/via_span.c index 4773f51627d..e5e25f08c1c 100644 --- a/src/mesa/drivers/dri/unichrome/via_span.c +++ b/src/mesa/drivers/dri/unichrome/via_span.c @@ -51,15 +51,15 @@ #define Y_FLIP(_y) (height - _y - 1) #define HW_LOCK() -#define HW_CLIPLOOP() \ - do { \ - __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; +#define HW_CLIPLOOP() \ + do { \ + __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; #define HW_ENDCLIPLOOP() \ @@ -70,7 +70,7 @@ #undef LOCAL_VARS #define LOCAL_VARS \ - viaContextPtr vmesa = VIA_CONTEXT(ctx); \ + struct via_context *vmesa = VIA_CONTEXT(ctx); \ __DRIdrawablePrivate *dPriv = vmesa->driDrawable; \ GLuint draw_pitch = vmesa->drawBuffer->pitch; \ GLuint read_pitch = vmesa->readBuffer->pitch; \ @@ -111,7 +111,7 @@ /* 16 bit depthbuffer functions. */ #define LOCAL_DEPTH_VARS \ - viaContextPtr vmesa = VIA_CONTEXT(ctx); \ + struct via_context *vmesa = VIA_CONTEXT(ctx); \ __DRIdrawablePrivate *dPriv = vmesa->driDrawable; \ GLuint depth_pitch = vmesa->depth.pitch; \ GLuint height = dPriv->h; \ @@ -176,7 +176,7 @@ static void viaSetBuffer(GLcontext *ctx, GLframebuffer *colorBuffer, GLuint bufferBit) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); if (bufferBit == DD_FRONT_LEFT_BIT) { vmesa->drawBuffer = vmesa->readBuffer = &vmesa->front; @@ -193,23 +193,21 @@ static void viaSetBuffer(GLcontext *ctx, GLframebuffer *colorBuffer, */ void viaSpanRenderStart( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - VIA_FINISH_PRIM(vmesa); + struct via_context *vmesa = VIA_CONTEXT(ctx); + viaWaitIdle(vmesa); LOCK_HARDWARE(vmesa); - viaFlushDmaLocked(vmesa, 0); - WAIT_IDLE(vmesa); } void viaSpanRenderFinish( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); _swrast_flush( ctx ); UNLOCK_HARDWARE( vmesa ); } void viaInitSpanFuncs(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx); swdd->SetBuffer = viaSetBuffer; diff --git a/src/mesa/drivers/dri/unichrome/via_state.c b/src/mesa/drivers/dri/unichrome/via_state.c index 97f9a030436..91531e6cc34 100644 --- a/src/mesa/drivers/dri/unichrome/via_state.c +++ b/src/mesa/drivers/dri/unichrome/via_state.c @@ -38,6 +38,7 @@ #include "via_tex.h" #include "via_tris.h" #include "via_ioctl.h" +#include "via_3d_reg.h" #include "swrast/swrast.h" #include "array_cache/acache.h" @@ -66,17 +67,26 @@ static GLuint ROP[16] = { HC_HROP_WHITE /* GL_SET 1 */ }; +/* + * Compute the 'S5.5' lod bias factor from the floating point OpenGL bias. + */ +static GLuint viaComputeLodBias(GLfloat bias) +{ + int b = (int) (bias * 32.0); + if (b > 511) + b = 511; + else if (b < -512) + b = -512; + return (GLuint) b; +} - -void viaEmitState(viaContextPtr vmesa) +void viaEmitState(struct via_context *vmesa) { GLcontext *ctx = vmesa->glCtx; GLuint i = 0; GLuint j = 0; RING_VARS; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - viaCheckDma(vmesa, 0x110); BEGIN_RING(5); @@ -95,27 +105,23 @@ void viaEmitState(viaContextPtr vmesa) pitch = vmesa->depth.pitch; BEGIN_RING(6); - OUT_RING( ((HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF)) ); - OUT_RING( ((HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24)) ); - OUT_RING( ((HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK | - format | pitch) ); - OUT_RING( ((HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD) ); - OUT_RING( ((HC_SubA_HSTREF << 24) | vmesa->regHSTREF) ); - OUT_RING( ((HC_SubA_HSTMD << 24) | vmesa->regHSTMD) ); + OUT_RING( (HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF) ); + OUT_RING( (HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24) ); + OUT_RING( (HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK | + format | pitch ); + OUT_RING( (HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD ); + OUT_RING( (HC_SubA_HSTREF << 24) | vmesa->regHSTREF ); + OUT_RING( (HC_SubA_HSTMD << 24) | vmesa->regHSTMD ); ADVANCE_RING(); } else if (vmesa->hasDepth) { GLuint pitch, format, offset; if (vmesa->depthBits == 16) { - /* We haven't support 16bit depth yet */ format = HC_HZWBFM_16; - /*format = HC_HZWBFM_32;*/ - if (VIA_DEBUG) fprintf(stderr, "z format = 16\n"); } else { format = HC_HZWBFM_32; - if (VIA_DEBUG) fprintf(stderr, "z format = 32\n"); } @@ -123,60 +129,54 @@ void viaEmitState(viaContextPtr vmesa) pitch = vmesa->depth.pitch; BEGIN_RING(4); - OUT_RING( ((HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF)) ); - OUT_RING( ((HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24)) ); - OUT_RING( ((HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK | - format | pitch) ); - OUT_RING( ((HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD) ); + OUT_RING( (HC_SubA_HZWBBasL << 24) | (offset & 0xFFFFFF) ); + OUT_RING( (HC_SubA_HZWBBasH << 24) | ((offset & 0xFF000000) >> 24) ); + OUT_RING( (HC_SubA_HZWBType << 24) | HC_HDBLoc_Local | HC_HZONEasFF_MASK | + format | pitch ); + OUT_RING( (HC_SubA_HZWTMD << 24) | vmesa->regHZWTMD ); ADVANCE_RING(); } if (ctx->Color.AlphaEnabled) { BEGIN_RING(1); - OUT_RING( ((HC_SubA_HATMD << 24) | vmesa->regHATMD) ); + OUT_RING( (HC_SubA_HATMD << 24) | vmesa->regHATMD ); ADVANCE_RING(); i++; } if (ctx->Color.BlendEnabled) { BEGIN_RING(11); - OUT_RING( ((HC_SubA_HABLCsat << 24) | vmesa->regHABLCsat) ); - OUT_RING( ((HC_SubA_HABLCop << 24) | vmesa->regHABLCop) ); - OUT_RING( ((HC_SubA_HABLAsat << 24) | vmesa->regHABLAsat) ); - OUT_RING( ((HC_SubA_HABLAop << 24) | vmesa->regHABLAop) ); - OUT_RING( ((HC_SubA_HABLRCa << 24) | vmesa->regHABLRCa) ); - OUT_RING( ((HC_SubA_HABLRFCa << 24) | vmesa->regHABLRFCa) ); - OUT_RING( ((HC_SubA_HABLRCbias << 24) | vmesa->regHABLRCbias) ); - OUT_RING( ((HC_SubA_HABLRCb << 24) | vmesa->regHABLRCb) ); - OUT_RING( ((HC_SubA_HABLRFCb << 24) | vmesa->regHABLRFCb) ); - OUT_RING( ((HC_SubA_HABLRAa << 24) | vmesa->regHABLRAa) ); - OUT_RING( ((HC_SubA_HABLRAb << 24) | vmesa->regHABLRAb) ); + OUT_RING( (HC_SubA_HABLCsat << 24) | vmesa->regHABLCsat ); + OUT_RING( (HC_SubA_HABLCop << 24) | vmesa->regHABLCop ); + OUT_RING( (HC_SubA_HABLAsat << 24) | vmesa->regHABLAsat ); + OUT_RING( (HC_SubA_HABLAop << 24) | vmesa->regHABLAop ); + OUT_RING( (HC_SubA_HABLRCa << 24) | vmesa->regHABLRCa ); + OUT_RING( (HC_SubA_HABLRFCa << 24) | vmesa->regHABLRFCa ); + OUT_RING( (HC_SubA_HABLRCbias << 24) | vmesa->regHABLRCbias ); + OUT_RING( (HC_SubA_HABLRCb << 24) | vmesa->regHABLRCb ); + OUT_RING( (HC_SubA_HABLRFCb << 24) | vmesa->regHABLRFCb ); + OUT_RING( (HC_SubA_HABLRAa << 24) | vmesa->regHABLRAa ); + OUT_RING( (HC_SubA_HABLRAb << 24) | vmesa->regHABLRAb ); ADVANCE_RING(); } if (ctx->Fog.Enabled) { BEGIN_RING(3); - OUT_RING( ((HC_SubA_HFogLF << 24) | vmesa->regHFogLF) ); - OUT_RING( ((HC_SubA_HFogCL << 24) | vmesa->regHFogCL) ); - OUT_RING( ((HC_SubA_HFogCH << 24) | vmesa->regHFogCH) ); + OUT_RING( (HC_SubA_HFogLF << 24) | vmesa->regHFogLF ); + OUT_RING( (HC_SubA_HFogCL << 24) | vmesa->regHFogCL ); + OUT_RING( (HC_SubA_HFogCH << 24) | vmesa->regHFogCH ); ADVANCE_RING(); } if (ctx->Line.StippleFlag) { BEGIN_RING(2); - OUT_RING( ((HC_SubA_HLP << 24) | ctx->Line.StipplePattern) ); - OUT_RING( ((HC_SubA_HLPRF << 24) | ctx->Line.StippleFactor) ); - ADVANCE_RING(); - } - else { - BEGIN_RING(2); - OUT_RING( ((HC_SubA_HLP << 24) | 0xFFFF) ); - OUT_RING( ((HC_SubA_HLPRF << 24) | 0xFFFF) ); + OUT_RING( (HC_SubA_HLP << 24) | ctx->Line.StipplePattern ); + OUT_RING( (HC_SubA_HLPRF << 24) | ctx->Line.StippleFactor ); ADVANCE_RING(); } BEGIN_RING(1); - OUT_RING( ((HC_SubA_HPixGC << 24) | 0x0) ); + OUT_RING( (HC_SubA_HPixGC << 24) | 0x0 ); ADVANCE_RING(); QWORD_PAD_RING(); @@ -195,12 +195,9 @@ void viaEmitState(viaContextPtr vmesa) OUT_RING( (HC_ParaType_Tex << 16) | (HC_SubType_TexGeneral << 24) ); if (texUnit0->Enabled && texUnit1->Enabled) { - if (VIA_DEBUG) fprintf(stderr, "multi texture\n"); - nDummyValue = (HC_SubA_HTXSMD << 24) | (1 << 3); - + nDummyValue = (HC_SubA_HTXSMD << 24) | (1 << 3); } else { - if (VIA_DEBUG) fprintf(stderr, "single texture\n"); nDummyValue = (HC_SubA_HTXSMD << 24) | 0; } @@ -223,11 +220,10 @@ void viaEmitState(viaContextPtr vmesa) if (texUnit0->Enabled) { struct gl_texture_object *texObj = texUnit0->_Current; - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; + struct via_texture_object *t = (struct via_texture_object *)texObj; GLuint numLevels = t->lastLevel - t->firstLevel + 1; - if (VIA_DEBUG) { + if (VIA_DEBUG & DEBUG_STATE) { fprintf(stderr, "texture0 enabled\n"); - fprintf(stderr, "texture level %d\n", t->actualLevel); } if (numLevels == 8) { BEGIN_RING(27); @@ -312,31 +308,26 @@ void viaEmitState(viaContextPtr vmesa) ADVANCE_RING(); } - BEGIN_RING(12); - OUT_RING( (HC_SubA_HTXnTB << 24) | vmesa->regHTXnTB_0 ); - OUT_RING( (HC_SubA_HTXnMPMD << 24) | vmesa->regHTXnMPMD_0 ); - OUT_RING( (HC_SubA_HTXnTBLCsat << 24) | vmesa->regHTXnTBLCsat_0 ); - OUT_RING( (HC_SubA_HTXnTBLCop << 24) | vmesa->regHTXnTBLCop_0 ); - OUT_RING( (HC_SubA_HTXnTBLMPfog << 24) | vmesa->regHTXnTBLMPfog_0 ); - OUT_RING( (HC_SubA_HTXnTBLAsat << 24) | vmesa->regHTXnTBLAsat_0 ); - OUT_RING( (HC_SubA_HTXnTBLRCb << 24) | vmesa->regHTXnTBLRCb_0 ); - OUT_RING( (HC_SubA_HTXnTBLRAa << 24) | vmesa->regHTXnTBLRAa_0 ); - OUT_RING( (HC_SubA_HTXnTBLRFog << 24) | vmesa->regHTXnTBLRFog_0 ); - OUT_RING( (HC_SubA_HTXnTBLRCa << 24) | vmesa->regHTXnTBLRCa_0 ); - OUT_RING( (HC_SubA_HTXnTBLRCc << 24) | vmesa->regHTXnTBLRCc_0 ); - OUT_RING( (HC_SubA_HTXnTBLRCbias << 24) | vmesa->regHTXnTBLRCbias_0 ); - - if (0) { - fprintf(stderr, "emitted Ca_0 %08x\n", vmesa->regHTXnTBLRCa_0); - fprintf(stderr, "emitted Cb_0 %08x\n", vmesa->regHTXnTBLRCb_0); - fprintf(stderr, "emitted Cc_0 %08x\n", vmesa->regHTXnTBLRCc_0); - fprintf(stderr, "emitted Cbias_0 %08x\n", vmesa->regHTXnTBLRCbias_0); - fprintf(stderr, "emitted Aa_0 %08x\n", vmesa->regHTXnTBLRAa_0); - fprintf(stderr, "emitted Fog_0 %08x\n", vmesa->regHTXnTBLRFog_0); - } - + BEGIN_RING(15); + OUT_RING( (HC_SubA_HTXnTB << 24) | vmesa->regHTXnTB[0] ); + OUT_RING( (HC_SubA_HTXnMPMD << 24) | vmesa->regHTXnMPMD[0] ); + OUT_RING( (HC_SubA_HTXnTBLCsat << 24) | vmesa->regHTXnTBLCsat[0] ); + OUT_RING( (HC_SubA_HTXnTBLCop << 24) | vmesa->regHTXnTBLCop[0] ); + OUT_RING( (HC_SubA_HTXnTBLMPfog << 24) | vmesa->regHTXnTBLMPfog[0] ); + OUT_RING( (HC_SubA_HTXnTBLAsat << 24) | vmesa->regHTXnTBLAsat[0] ); + OUT_RING( (HC_SubA_HTXnTBLRCb << 24) | vmesa->regHTXnTBLRCb[0] ); + OUT_RING( (HC_SubA_HTXnTBLRAa << 24) | vmesa->regHTXnTBLRAa[0] ); + OUT_RING( (HC_SubA_HTXnTBLRFog << 24) | vmesa->regHTXnTBLRFog[0] ); + OUT_RING( (HC_SubA_HTXnTBLRCa << 24) | vmesa->regHTXnTBLRCa[0] ); + OUT_RING( (HC_SubA_HTXnTBLRCc << 24) | vmesa->regHTXnTBLRCc[0] ); + OUT_RING( (HC_SubA_HTXnTBLRCbias << 24) | vmesa->regHTXnTBLRCbias[0] ); + OUT_RING( (HC_SubA_HTXnTBC << 24) | vmesa->regHTXnTBC[0] ); + OUT_RING( (HC_SubA_HTXnTRAH << 24) | vmesa->regHTXnTRAH[0] ); + OUT_RING( (HC_SubA_HTXnCLODu << 24) | vmesa->regHTXnCLOD[0] ); ADVANCE_RING(); + /* KW: This test never succeeds: + */ if (t->regTexFM == HC_HTXnFM_Index8) { struct gl_color_table *table = &texObj->Palette; GLfloat *tableF = (GLfloat *)table->Table; @@ -355,12 +346,11 @@ void viaEmitState(viaContextPtr vmesa) if (texUnit1->Enabled) { struct gl_texture_object *texObj = texUnit1->_Current; - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; + struct via_texture_object *t = (struct via_texture_object *)texObj; GLuint numLevels = t->lastLevel - t->firstLevel + 1; int texunit = (texUnit0->Enabled ? 1 : 0); - if (VIA_DEBUG) { + if (VIA_DEBUG & DEBUG_STATE) { fprintf(stderr, "texture1 enabled\n"); - fprintf(stderr, "texture level %d\n", t->actualLevel); } if (numLevels == 8) { BEGIN_RING(27); @@ -443,21 +433,26 @@ void viaEmitState(viaContextPtr vmesa) ADVANCE_RING(); } - BEGIN_RING(12); - OUT_RING( (HC_SubA_HTXnTB << 24) | vmesa->regHTXnTB_1 ); - OUT_RING( (HC_SubA_HTXnMPMD << 24) | vmesa->regHTXnMPMD_1 ); - OUT_RING( (HC_SubA_HTXnTBLCsat << 24) | vmesa->regHTXnTBLCsat_1 ); - OUT_RING( (HC_SubA_HTXnTBLCop << 24) | vmesa->regHTXnTBLCop_1 ); - OUT_RING( (HC_SubA_HTXnTBLMPfog << 24) | vmesa->regHTXnTBLMPfog_1 ); - OUT_RING( (HC_SubA_HTXnTBLAsat << 24) | vmesa->regHTXnTBLAsat_1 ); - OUT_RING( (HC_SubA_HTXnTBLRCb << 24) | vmesa->regHTXnTBLRCb_1 ); - OUT_RING( (HC_SubA_HTXnTBLRAa << 24) | vmesa->regHTXnTBLRAa_1 ); - OUT_RING( (HC_SubA_HTXnTBLRFog << 24) | vmesa->regHTXnTBLRFog_1 ); - OUT_RING( (HC_SubA_HTXnTBLRCa << 24) | vmesa->regHTXnTBLRCa_1 ); - OUT_RING( (HC_SubA_HTXnTBLRCc << 24) | vmesa->regHTXnTBLRCc_1 ); - OUT_RING( (HC_SubA_HTXnTBLRCbias << 24) | vmesa->regHTXnTBLRCbias_1 ); + BEGIN_RING(15); + OUT_RING( (HC_SubA_HTXnTB << 24) | vmesa->regHTXnTB[1] ); + OUT_RING( (HC_SubA_HTXnMPMD << 24) | vmesa->regHTXnMPMD[1] ); + OUT_RING( (HC_SubA_HTXnTBLCsat << 24) | vmesa->regHTXnTBLCsat[1] ); + OUT_RING( (HC_SubA_HTXnTBLCop << 24) | vmesa->regHTXnTBLCop[1] ); + OUT_RING( (HC_SubA_HTXnTBLMPfog << 24) | vmesa->regHTXnTBLMPfog[1] ); + OUT_RING( (HC_SubA_HTXnTBLAsat << 24) | vmesa->regHTXnTBLAsat[1] ); + OUT_RING( (HC_SubA_HTXnTBLRCb << 24) | vmesa->regHTXnTBLRCb[1] ); + OUT_RING( (HC_SubA_HTXnTBLRAa << 24) | vmesa->regHTXnTBLRAa[1] ); + OUT_RING( (HC_SubA_HTXnTBLRFog << 24) | vmesa->regHTXnTBLRFog[1] ); + OUT_RING( (HC_SubA_HTXnTBLRCa << 24) | vmesa->regHTXnTBLRCa[1] ); + OUT_RING( (HC_SubA_HTXnTBLRCc << 24) | vmesa->regHTXnTBLRCc[1] ); + OUT_RING( (HC_SubA_HTXnTBLRCbias << 24) | vmesa->regHTXnTBLRCbias[1] ); + OUT_RING( (HC_SubA_HTXnTBC << 24) | vmesa->regHTXnTBC[1] ); + OUT_RING( (HC_SubA_HTXnTRAH << 24) | vmesa->regHTXnTRAH[1] ); + OUT_RING( (HC_SubA_HTXnCLODu << 24) | vmesa->regHTXnCLOD[1] ); ADVANCE_RING(); + /* KW: This test never succeeds: + */ if (t->regTexFM == HC_HTXnFM_Index8) { struct gl_color_table *table = &texObj->Palette; GLfloat *tableF = (GLfloat *)table->Table; @@ -515,41 +510,45 @@ void viaEmitState(viaContextPtr vmesa) OUT_RING( stipple[0] ); OUT_RING( HC_HEADER2 ); OUT_RING( (HC_ParaType_NotTex << 16) ); - OUT_RING( ((HC_SubA_HSPXYOS << 24) | (((31 - vmesa->drawX) & 0x1f) << HC_HSPXOS_SHIFT))); - OUT_RING( ((HC_SubA_HSPXYOS << 24) | (((31 - vmesa->drawX) & 0x1f) << HC_HSPXOS_SHIFT))); + OUT_RING( (HC_SubA_HSPXYOS << 24) | + (((31 - vmesa->drawX) & 0x1f) << HC_HSPXOS_SHIFT)); + OUT_RING( (HC_SubA_HSPXYOS << 24) | + (((31 - vmesa->drawX) & 0x1f) << HC_HSPXOS_SHIFT)); ADVANCE_RING(); } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); - vmesa->newEmitState = 0; } -static __inline__ GLuint viaPackColor(GLuint format, +static __inline__ GLuint viaPackColor(GLuint bpp, GLubyte r, GLubyte g, GLubyte b, GLubyte a) { - switch (format) { - case 0x10: + switch (bpp) { + case 16: return PACK_COLOR_565(r, g, b); - case 0x20: + case 32: return PACK_COLOR_8888(a, r, g, b); default: - if (VIA_DEBUG) fprintf(stderr, "unknown format %d\n", (int)format); - return PACK_COLOR_8888(a, r, g, b); + assert(0); + return 0; } } -static void viaBlendEquationSeparate(GLcontext *ctx, GLenum rgbMode, GLenum aMode) +static void viaBlendEquationSeparate(GLcontext *ctx, + GLenum rgbMode, + GLenum aMode) { - if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__); + if (VIA_DEBUG & DEBUG_STATE) + fprintf(stderr, "%s in\n", __FUNCTION__); /* GL_EXT_blend_equation_separate not supported */ ASSERT(rgbMode == aMode); /* Can only do GL_ADD equation in hardware */ - FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_BLEND_EQ, rgbMode != GL_FUNC_ADD_EXT); + FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_BLEND_EQ, + rgbMode != GL_FUNC_ADD_EXT); /* BlendEquation sets ColorLogicOpEnabled in an unexpected * manner. @@ -557,14 +556,14 @@ static void viaBlendEquationSeparate(GLcontext *ctx, GLenum rgbMode, GLenum aMod FALLBACK(VIA_CONTEXT(ctx), VIA_FALLBACK_LOGICOP, (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY)); - if (VIA_DEBUG) fprintf(stderr, "%s out\n", __FUNCTION__); } static void viaBlendFunc(GLcontext *ctx, GLenum sfactor, GLenum dfactor) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); GLboolean fallback = GL_FALSE; - if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__); + if (VIA_DEBUG & DEBUG_STATE) + fprintf(stderr, "%s in\n", __FUNCTION__); switch (ctx->Color.BlendSrcRGB) { case GL_SRC_ALPHA_SATURATE: @@ -590,7 +589,6 @@ static void viaBlendFunc(GLcontext *ctx, GLenum sfactor, GLenum dfactor) } FALLBACK(vmesa, VIA_FALLBACK_BLEND_FUNC, fallback); - if (VIA_DEBUG) fprintf(stderr, "%s out\n", __FUNCTION__); } /* Shouldn't be called as the extension is disabled. @@ -615,13 +613,14 @@ static void viaBlendFuncSeparate(GLcontext *ctx, GLenum sfactorRGB, static void viaScissor(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); if (!vmesa->driDrawable) return; - if (VIA_DEBUG) - fprintf(stderr, "%s %d,%d %dx%d, drawH %d\n", __FUNCTION__, x,y,w,h, vmesa->driDrawable->h); + if (VIA_DEBUG & DEBUG_STATE) + fprintf(stderr, "%s %d,%d %dx%d, drawH %d\n", __FUNCTION__, + x,y,w,h, vmesa->driDrawable->h); if (vmesa->scissor) { VIA_FLUSH_DMA(vmesa); /* don't pipeline cliprect changes */ @@ -631,13 +630,11 @@ static void viaScissor(GLcontext *ctx, GLint x, GLint y, vmesa->scissorRect.y1 = vmesa->driDrawable->h - y - h; vmesa->scissorRect.x2 = x + w; vmesa->scissorRect.y2 = vmesa->driDrawable->h - y; - - if (VIA_DEBUG) fprintf(stderr, "%s out\n", __FUNCTION__); } static void viaEnable(GLcontext *ctx, GLenum cap, GLboolean state) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); switch (cap) { case GL_SCISSOR_TEST: @@ -661,8 +658,11 @@ static void viaRenderMode(GLcontext *ctx, GLenum mode) static void viaDrawBuffer(GLcontext *ctx, GLenum mode) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__); + struct via_context *vmesa = VIA_CONTEXT(ctx); + + if (VIA_DEBUG & (DEBUG_DRI|DEBUG_STATE)) + fprintf(stderr, "%s in\n", __FUNCTION__); + if (mode == GL_FRONT) { VIA_FLUSH_DMA(vmesa); vmesa->drawBuffer = vmesa->readBuffer = &vmesa->front; @@ -686,14 +686,11 @@ static void viaDrawBuffer(GLcontext *ctx, GLenum mode) * gets called. */ _swrast_DrawBuffer(ctx, mode); - - - if (VIA_DEBUG) fprintf(stderr, "%s out\n", __FUNCTION__); } static void viaClearColor(GLcontext *ctx, const GLfloat color[4]) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); GLubyte pcolor[4]; CLAMPED_FLOAT_TO_UBYTE(pcolor[0], color[0]); CLAMPED_FLOAT_TO_UBYTE(pcolor[1], color[1]); @@ -702,7 +699,6 @@ static void viaClearColor(GLcontext *ctx, const GLfloat color[4]) vmesa->ClearColor = viaPackColor(vmesa->viaScreen->bitsPerPixel, pcolor[0], pcolor[1], pcolor[2], pcolor[3]); - } #define WRITEMASK_ALPHA_SHIFT 31 @@ -714,9 +710,9 @@ static void viaColorMask(GLcontext *ctx, GLboolean r, GLboolean g, GLboolean b, GLboolean a) { - viaContextPtr vmesa = VIA_CONTEXT( ctx ); + struct via_context *vmesa = VIA_CONTEXT( ctx ); - if (VIA_DEBUG) + if (VIA_DEBUG & DEBUG_STATE) fprintf(stderr, "%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__, r, g, b, a); vmesa->ClearMask = (((!r) << WRITEMASK_RED_SHIFT) | @@ -736,7 +732,7 @@ static void viaColorMask(GLcontext *ctx, */ void viaCalcViewport(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); const GLfloat *v = ctx->Viewport._WindowMap.m; GLfloat *m = vmesa->ViewportMatrix.m; @@ -765,30 +761,9 @@ static void viaDepthRange(GLcontext *ctx, viaCalcViewport(ctx); } -#if 0 -static void -flip_bytes( GLubyte *p, GLuint n ) -{ - register GLuint i, a, b; - - for (i=0;i<n;i++) { - b = (GLuint) p[i]; /* words are often faster than bytes */ - a = ((b & 0x01) << 7) | - ((b & 0x02) << 5) | - ((b & 0x04) << 3) | - ((b & 0x08) << 1) | - ((b & 0x10) >> 1) | - ((b & 0x20) >> 3) | - ((b & 0x40) >> 5) | - ((b & 0x80) >> 7); - p[i] = (GLubyte) a; - } -} -#endif - void viaInitState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); vmesa->regCmdB = HC_ACMD_HCmdB; vmesa->regEnable = HC_HenCW_MASK; @@ -850,199 +825,164 @@ get_wrap_mode( GLenum sWrap, GLenum tWrap ) return v; } +static u_int32_t +get_minmag_filter( GLenum min, GLenum mag ) +{ + u_int32_t v = 0; + + switch (min) { + case GL_NEAREST: + v = HC_HTXnFLSs_Nearest | + HC_HTXnFLTs_Nearest; + break; + case GL_LINEAR: + v = HC_HTXnFLSs_Linear | + HC_HTXnFLTs_Linear; + break; + case GL_NEAREST_MIPMAP_NEAREST: + v = HC_HTXnFLSs_Nearest | + HC_HTXnFLTs_Nearest; + v |= HC_HTXnFLDs_Nearest; + break; + case GL_LINEAR_MIPMAP_NEAREST: + v = HC_HTXnFLSs_Linear | + HC_HTXnFLTs_Linear; + v |= HC_HTXnFLDs_Nearest; + break; + case GL_NEAREST_MIPMAP_LINEAR: + v = HC_HTXnFLSs_Nearest | + HC_HTXnFLTs_Nearest; + v |= HC_HTXnFLDs_Linear; + break; + case GL_LINEAR_MIPMAP_LINEAR: + v = HC_HTXnFLSs_Linear | + HC_HTXnFLTs_Linear; + v |= HC_HTXnFLDs_Linear; + break; + default: + break; + } + + switch (mag) { + case GL_LINEAR: + v |= HC_HTXnFLSe_Linear | + HC_HTXnFLTe_Linear; + break; + case GL_NEAREST: + v |= HC_HTXnFLSe_Nearest | + HC_HTXnFLTe_Nearest; + break; + default: + break; + } + + return v; +} + static GLboolean viaChooseTextureState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); struct gl_texture_unit *texUnit0 = &ctx->Texture.Unit[0]; struct gl_texture_unit *texUnit1 = &ctx->Texture.Unit[1]; - /*=* John Sheng [2003.7.18] texture combine *=*/ - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); if (texUnit0->_ReallyEnabled || texUnit1->_ReallyEnabled) { - if (VIA_DEBUG) { - fprintf(stderr, "Texture._ReallyEnabled - in\n"); - fprintf(stderr, "texUnit0->_ReallyEnabled = %x\n",texUnit0->_ReallyEnabled); - } - - if (VIA_DEBUG) { - struct gl_texture_object *texObj0 = texUnit0->_Current; - struct gl_texture_object *texObj1 = texUnit1->_Current; - - fprintf(stderr, "env mode: 0x%04x / 0x%04x\n", texUnit0->EnvMode, texUnit1->EnvMode); - - if ( (texObj0 != NULL) && (texObj0->Image[0][0] != NULL) ) - fprintf(stderr, "format 0: 0x%04x\n", texObj0->Image[0][0]->Format); - - if ( (texObj1 != NULL) && (texObj1->Image[0][0] != NULL) ) - fprintf(stderr, "format 1: 0x%04x\n", texObj1->Image[0][0]->Format); - } - + vmesa->regEnable |= HC_HenTXMP_MASK | HC_HenTXCH_MASK | HC_HenTXPP_MASK; if (texUnit0->_ReallyEnabled) { struct gl_texture_object *texObj = texUnit0->_Current; - - if (VIA_DEBUG) fprintf(stderr, "texUnit0->_ReallyEnabled\n"); - - vmesa->regEnable |= HC_HenTXMP_MASK | HC_HenTXCH_MASK | HC_HenTXPP_MASK; - switch (texObj->MinFilter) { - case GL_NEAREST: - vmesa->regHTXnTB_0 = HC_HTXnFLSs_Nearest | - HC_HTXnFLTs_Nearest; - break; - case GL_LINEAR: - vmesa->regHTXnTB_0 = HC_HTXnFLSs_Linear | - HC_HTXnFLTs_Linear; - break; - case GL_NEAREST_MIPMAP_NEAREST: - vmesa->regHTXnTB_0 = HC_HTXnFLSs_Nearest | - HC_HTXnFLTs_Nearest; - vmesa->regHTXnTB_0 |= HC_HTXnFLDs_Nearest; - break; - case GL_LINEAR_MIPMAP_NEAREST: - vmesa->regHTXnTB_0 = HC_HTXnFLSs_Linear | - HC_HTXnFLTs_Linear; - vmesa->regHTXnTB_0 |= HC_HTXnFLDs_Nearest; - break; - case GL_NEAREST_MIPMAP_LINEAR: - vmesa->regHTXnTB_0 = HC_HTXnFLSs_Nearest | - HC_HTXnFLTs_Nearest; - vmesa->regHTXnTB_0 |= HC_HTXnFLDs_Linear; - break; - case GL_LINEAR_MIPMAP_LINEAR: - vmesa->regHTXnTB_0 = HC_HTXnFLSs_Linear | - HC_HTXnFLTs_Linear; - vmesa->regHTXnTB_0 |= HC_HTXnFLDs_Linear; - break; - default: - break; - } - - switch (texObj->MagFilter) { - case GL_LINEAR: - vmesa->regHTXnTB_0 |= HC_HTXnFLSe_Linear | - HC_HTXnFLTe_Linear; - break; - case GL_NEAREST: - vmesa->regHTXnTB_0 |= HC_HTXnFLSe_Nearest | - HC_HTXnFLTe_Nearest; - break; - default: - break; - } + vmesa->regHTXnTB[0] = get_minmag_filter( texObj->MinFilter, + texObj->MagFilter ); - vmesa->regHTXnMPMD_0 &= ~(HC_HTXnMPMD_SMASK | HC_HTXnMPMD_TMASK); - vmesa->regHTXnMPMD_0 |= get_wrap_mode( texObj->WrapS, + vmesa->regHTXnMPMD[0] &= ~(HC_HTXnMPMD_SMASK | HC_HTXnMPMD_TMASK); + vmesa->regHTXnMPMD[0] |= get_wrap_mode( texObj->WrapS, texObj->WrapT ); - if (VIA_DEBUG) fprintf(stderr, "texUnit0->EnvMode %x\n",texUnit0->EnvMode); + vmesa->regHTXnTB[0] &= ~(HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); + if (texObj->Image[0][texObj->BaseLevel]->Border > 0) { + vmesa->regHTXnTB[0] |= (HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); + vmesa->regHTXnTBC[0] = + PACK_COLOR_888(FLOAT_TO_UBYTE(texObj->BorderColor[0]), + FLOAT_TO_UBYTE(texObj->BorderColor[1]), + FLOAT_TO_UBYTE(texObj->BorderColor[2])); + vmesa->regHTXnTRAH[0] = FLOAT_TO_UBYTE(texObj->BorderColor[3]); + } + + if (texUnit0->LodBias != 0.0f) { + GLuint b = viaComputeLodBias(texUnit0->LodBias); + vmesa->regHTXnTB[0] &= ~HC_HTXnFLDs_MASK; + vmesa->regHTXnTB[0] |= HC_HTXnFLDs_ConstLOD; + vmesa->regHTXnCLOD[0] = b | ((~b&0x1f)<<10); /* FIXME */ + } - if (!viaTexCombineState( vmesa, texUnit0->_CurrentCombine, 0 )) + if (!viaTexCombineState( vmesa, texUnit0->_CurrentCombine, 0 )) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "viaTexCombineState failed for unit 0\n"); return GL_FALSE; + } } if (texUnit1->_ReallyEnabled) { struct gl_texture_object *texObj = texUnit1->_Current; - vmesa->regEnable |= HC_HenTXMP_MASK | HC_HenTXCH_MASK | HC_HenTXPP_MASK; - - switch (texObj->MinFilter) { - case GL_NEAREST: - vmesa->regHTXnTB_1 = HC_HTXnFLSs_Nearest | - HC_HTXnFLTs_Nearest; - break; - case GL_LINEAR: - vmesa->regHTXnTB_1 = HC_HTXnFLSs_Linear | - HC_HTXnFLTs_Linear; - break; - case GL_NEAREST_MIPMAP_NEAREST: - vmesa->regHTXnTB_1 = HC_HTXnFLSs_Nearest | - HC_HTXnFLTs_Nearest; - vmesa->regHTXnTB_1 |= HC_HTXnFLDs_Nearest; - break ; - case GL_LINEAR_MIPMAP_NEAREST: - vmesa->regHTXnTB_1 = HC_HTXnFLSs_Linear | - HC_HTXnFLTs_Linear; - vmesa->regHTXnTB_1 |= HC_HTXnFLDs_Nearest; - break ; - case GL_NEAREST_MIPMAP_LINEAR: - vmesa->regHTXnTB_1 = HC_HTXnFLSs_Nearest | - HC_HTXnFLTs_Nearest; - vmesa->regHTXnTB_1 |= HC_HTXnFLDs_Linear; - break ; - case GL_LINEAR_MIPMAP_LINEAR: - vmesa->regHTXnTB_1 = HC_HTXnFLSs_Linear | - HC_HTXnFLTs_Linear; - vmesa->regHTXnTB_1 |= HC_HTXnFLDs_Linear; - break ; - default: - break; + vmesa->regHTXnTB[1] = get_minmag_filter( texObj->MinFilter, + texObj->MagFilter ); + vmesa->regHTXnMPMD[1] &= ~(HC_HTXnMPMD_SMASK | HC_HTXnMPMD_TMASK); + vmesa->regHTXnMPMD[1] |= get_wrap_mode( texObj->WrapS, + texObj->WrapT ); + + vmesa->regHTXnTB[1] &= ~(HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); + if (texObj->Image[0][texObj->BaseLevel]->Border > 0) { + vmesa->regHTXnTB[1] |= (HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); + vmesa->regHTXnTBC[1] = + PACK_COLOR_888(FLOAT_TO_UBYTE(texObj->BorderColor[0]), + FLOAT_TO_UBYTE(texObj->BorderColor[1]), + FLOAT_TO_UBYTE(texObj->BorderColor[2])); + vmesa->regHTXnTRAH[1] = FLOAT_TO_UBYTE(texObj->BorderColor[3]); } - switch(texObj->MagFilter) { - case GL_LINEAR: - vmesa->regHTXnTB_1 |= HC_HTXnFLSe_Linear | - HC_HTXnFLTe_Linear; - break; - case GL_NEAREST: - vmesa->regHTXnTB_1 |= HC_HTXnFLSe_Nearest | - HC_HTXnFLTe_Nearest; - break; - default: - break; + + if (texUnit1->LodBias != 0.0f) { + GLuint b = viaComputeLodBias(texUnit1->LodBias); + vmesa->regHTXnTB[1] &= ~HC_HTXnFLDs_MASK; + vmesa->regHTXnTB[1] |= HC_HTXnFLDs_ConstLOD; + vmesa->regHTXnCLOD[1] = b | ((~b&0x1f)<<10); /* FIXME */ } - - vmesa->regHTXnMPMD_1 &= ~(HC_HTXnMPMD_SMASK | HC_HTXnMPMD_TMASK); - vmesa->regHTXnMPMD_1 |= get_wrap_mode( texObj->WrapS, - texObj->WrapT ); - if (!viaTexCombineState( vmesa, texUnit1->_CurrentCombine, 1 )) + if (!viaTexCombineState( vmesa, texUnit1->_CurrentCombine, 1 )) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "viaTexCombineState failed for unit 1\n"); return GL_FALSE; + } } - - if (VIA_DEBUG) { - fprintf( stderr, "Csat_0 / Cop_0 = 0x%08x / 0x%08x\n", - vmesa->regHTXnTBLCsat_0, vmesa->regHTXnTBLCop_0 ); - fprintf( stderr, "Asat_0 = 0x%08x\n", - vmesa->regHTXnTBLAsat_0 ); - fprintf( stderr, "RCb_0 / RAa_0 = 0x%08x / 0x%08x\n", - vmesa->regHTXnTBLRCb_0, vmesa->regHTXnTBLRAa_0 ); - fprintf( stderr, "RCa_0 / RCc_0 = 0x%08x / 0x%08x\n", - vmesa->regHTXnTBLRCa_0, vmesa->regHTXnTBLRCc_0 ); - fprintf( stderr, "RCbias_0 = 0x%08x\n", - vmesa->regHTXnTBLRCbias_0 ); - } } else { - vmesa->regEnable &= (~(HC_HenTXMP_MASK | HC_HenTXCH_MASK | HC_HenTXPP_MASK)); + vmesa->regEnable &= ~(HC_HenTXMP_MASK | HC_HenTXCH_MASK | + HC_HenTXPP_MASK); } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); return GL_TRUE; } static void viaChooseColorState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); GLenum s = ctx->Color.BlendSrcRGB; GLenum d = ctx->Color.BlendDstRGB; /* The HW's blending equation is: * (Ca * FCa + Cbias + Cb * FCb) << Cshift */ - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); if (ctx->Color.BlendEnabled) { vmesa->regEnable |= HC_HenABL_MASK; /* Ca -- always from source color. */ - vmesa->regHABLCsat = HC_HABLCsat_MASK | HC_HABLCa_OPC | - HC_HABLCa_Csrc; + vmesa->regHABLCsat = HC_HABLCsat_MASK | HC_HABLCa_OPC | HC_HABLCa_Csrc; /* Aa -- always from source alpha. */ - vmesa->regHABLAsat = HC_HABLAsat_MASK | HC_HABLAa_OPA | - HC_HABLAa_Asrc; + vmesa->regHABLAsat = HC_HABLAsat_MASK | HC_HABLAa_OPA | HC_HABLAa_Asrc; /* FCa -- depend on following condition. * FAa -- depend on following condition. */ @@ -1104,8 +1044,10 @@ static void viaChooseColorState(GLcontext *ctx) if (vmesa->viaScreen->bitsPerPixel == 16) { /* (1, 1, 1, 1) */ - vmesa->regHABLCsat |= HC_HABLFCa_InvOPC | HC_HABLFCa_HABLRCa; - vmesa->regHABLAsat |= HC_HABLFAa_InvOPA | HC_HABLFAa_HABLFRA; + vmesa->regHABLCsat |= (HC_HABLFCa_InvOPC | + HC_HABLFCa_HABLRCa); + vmesa->regHABLAsat |= (HC_HABLFAa_InvOPA | + HC_HABLFAa_HABLFRA); vmesa->regHABLRFCa = 0x0; vmesa->regHABLRAa = 0x0; } @@ -1142,15 +1084,18 @@ static void viaChooseColorState(GLcontext *ctx) * So (f, f, f, 1) = (0, 0, 0, 1) */ vmesa->regHABLCsat |= HC_HABLFCa_OPC | HC_HABLFCa_HABLRCa; - vmesa->regHABLAsat |= HC_HABLFAa_InvOPA | HC_HABLFAa_HABLFRA; + vmesa->regHABLAsat |= (HC_HABLFAa_InvOPA | + HC_HABLFAa_HABLFRA); vmesa->regHABLRFCa = 0x0; vmesa->regHABLRAa = 0x0; } else { /* (f, f, f, 1), f = min(As, 1 - Ad) */ - vmesa->regHABLCsat |= HC_HABLFCa_OPC | HC_HABLFCa_mimAsrcInvAdst; - vmesa->regHABLAsat |= HC_HABLFAa_InvOPA | HC_HABLFAa_HABLFRA; + vmesa->regHABLCsat |= (HC_HABLFCa_OPC | + HC_HABLFCa_mimAsrcInvAdst); + vmesa->regHABLAsat |= (HC_HABLFAa_InvOPA | + HC_HABLFAa_HABLFRA); vmesa->regHABLRFCa = 0x0; vmesa->regHABLRAa = 0x0; } @@ -1314,13 +1259,11 @@ static void viaChooseColorState(GLcontext *ctx) vmesa->regEnable |= HC_HenAW_MASK; else vmesa->regEnable &= ~HC_HenAW_MASK; - - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); } static void viaChooseFogState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); if (ctx->Fog.Enabled) { GLubyte r, g, b, a; @@ -1345,7 +1288,7 @@ static void viaChooseFogState(GLcontext *ctx) static void viaChooseDepthState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); if (ctx->Depth.Test) { vmesa->regEnable |= HC_HenZT_MASK; if (ctx->Depth.Mask) @@ -1369,16 +1312,7 @@ static void viaChooseDepthState(GLcontext *ctx) static void viaChooseLineState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - - if (ctx->Line.SmoothFlag) { - vmesa->regEnable |= HC_HenAA_MASK; - } - else { - if (!ctx->Polygon.SmoothFlag) { - vmesa->regEnable &= ~HC_HenAA_MASK; - } - } + struct via_context *vmesa = VIA_CONTEXT(ctx); if (ctx->Line.StippleFlag) { vmesa->regEnable |= HC_HenLP_MASK; @@ -1392,18 +1326,7 @@ static void viaChooseLineState(GLcontext *ctx) static void viaChoosePolygonState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - - /* KW: FIXME: this should be in viaRasterPrimitive (somehow) - */ - if (ctx->Polygon.SmoothFlag) { - vmesa->regEnable |= HC_HenAA_MASK; - } - else { - if (!ctx->Line.SmoothFlag) { - vmesa->regEnable &= ~HC_HenAA_MASK; - } - } + struct via_context *vmesa = VIA_CONTEXT(ctx); if (ctx->Polygon.StippleFlag) { vmesa->regEnable |= HC_HenSP_MASK; @@ -1422,8 +1345,7 @@ static void viaChoosePolygonState(GLcontext *ctx) static void viaChooseStencilState(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); + struct via_context *vmesa = VIA_CONTEXT(ctx); if (ctx->Stencil.Enabled) { GLuint temp; @@ -1503,23 +1425,14 @@ static void viaChooseStencilState(GLcontext *ctx) else { vmesa->regEnable &= ~HC_HenST_MASK; } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); } static void viaChooseTriangle(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - if (VIA_DEBUG) { - fprintf(stderr, "%s - in\n", __FUNCTION__); - fprintf(stderr, "GL_CULL_FACE = %x\n", GL_CULL_FACE); - fprintf(stderr, "ctx->Polygon.CullFlag = %x\n", ctx->Polygon.CullFlag); - fprintf(stderr, "GL_FRONT = %x\n", GL_FRONT); - fprintf(stderr, "ctx->Polygon.CullFaceMode = %x\n", ctx->Polygon.CullFaceMode); - fprintf(stderr, "GL_CCW = %x\n", GL_CCW); - fprintf(stderr, "ctx->Polygon.FrontFace = %x\n", ctx->Polygon.FrontFace); - } + struct via_context *vmesa = VIA_CONTEXT(ctx); + if (ctx->Polygon.CullFlag == GL_TRUE) { switch (ctx->Polygon.CullFaceMode) { case GL_FRONT: @@ -1538,13 +1451,12 @@ static void viaChooseTriangle(GLcontext *ctx) return; } } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); } void viaValidateState( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - + struct via_context *vmesa = VIA_CONTEXT(ctx); + if (vmesa->newState & _NEW_TEXTURE) { GLboolean ok = (viaChooseTextureState(ctx) && viaUpdateTextureState(ctx)); @@ -1577,13 +1489,20 @@ void viaValidateState( GLcontext *ctx ) else vmesa->regEnable &= ~HC_HenCS_MASK; + if (ctx->Point.SmoothFlag || + ctx->Line.SmoothFlag || + ctx->Polygon.SmoothFlag) + vmesa->regEnable |= HC_HenAA_MASK; + else + vmesa->regEnable &= ~HC_HenAA_MASK; + vmesa->newEmitState |= vmesa->newState; vmesa->newState = 0; } static void viaInvalidateState(GLcontext *ctx, GLuint newState) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); VIA_FINISH_PRIM( vmesa ); vmesa->newState |= newState; diff --git a/src/mesa/drivers/dri/unichrome/via_state.h b/src/mesa/drivers/dri/unichrome/via_state.h index 2603c158719..065ec57d331 100644 --- a/src/mesa/drivers/dri/unichrome/via_state.h +++ b/src/mesa/drivers/dri/unichrome/via_state.h @@ -31,9 +31,9 @@ extern void viaInitState(GLcontext *ctx); extern void viaInitStateFuncs(GLcontext *ctx); extern void viaCalcViewport(GLcontext *ctx); extern void viaValidateState(GLcontext *ctx); -extern void viaEmitState(viaContextPtr vmesa); +extern void viaEmitState(struct via_context *vmesa); -extern void viaFallback(viaContextPtr vmesa, GLuint bit, GLboolean mode); +extern void viaFallback(struct via_context *vmesa, GLuint bit, GLboolean mode); #define FALLBACK(vmesa, bit, mode) viaFallback(vmesa, bit, mode) #endif diff --git a/src/mesa/drivers/dri/unichrome/via_tex.c b/src/mesa/drivers/dri/unichrome/via_tex.c index 3ed1a530882..94cdf61accd 100644 --- a/src/mesa/drivers/dri/unichrome/via_tex.c +++ b/src/mesa/drivers/dri/unichrome/via_tex.c @@ -27,126 +27,802 @@ #include <stdio.h> #include "glheader.h" +#include "macros.h" #include "mtypes.h" -#include "simple_list.h" #include "enums.h" -#include "teximage.h" +#include "colortab.h" +#include "convolve.h" +#include "context.h" +#include "simple_list.h" +#include "texcompress.h" +#include "texformat.h" #include "texobj.h" #include "texstore.h" -#include "texformat.h" -#include "swrast/swrast.h" -#include "context.h" + +#include "mm.h" #include "via_context.h" +#include "via_fb.h" #include "via_tex.h" #include "via_state.h" #include "via_ioctl.h" +#include "via_3d_reg.h" + +static const struct gl_texture_format * +viaChooseTexFormat( GLcontext *ctx, GLint internalFormat, + GLenum format, GLenum type ) +{ + struct via_context *vmesa = VIA_CONTEXT(ctx); + const GLboolean do32bpt = ( vmesa->viaScreen->bitsPerPixel == 32 +/* && vmesa->viaScreen->textureSize > 4*1024*1024 */ + ); + + + switch ( internalFormat ) { + case 4: + case GL_RGBA: + case GL_COMPRESSED_RGBA: + if ( format == GL_BGRA ) { + if ( type == GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL_UNSIGNED_BYTE ) { + return &_mesa_texformat_argb8888; + } + else if ( type == GL_UNSIGNED_SHORT_4_4_4_4_REV ) { + return &_mesa_texformat_argb4444; + } + else if ( type == GL_UNSIGNED_SHORT_1_5_5_5_REV ) { + return &_mesa_texformat_argb1555; + } + } + else if ( type == GL_UNSIGNED_BYTE || + type == GL_UNSIGNED_INT_8_8_8_8_REV || + type == GL_UNSIGNED_INT_8_8_8_8 ) { + return &_mesa_texformat_argb8888; + } + return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; + + case 3: + case GL_RGB: + case GL_COMPRESSED_RGB: + if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) { + return &_mesa_texformat_rgb565; + } + else if ( type == GL_UNSIGNED_BYTE ) { + return &_mesa_texformat_argb8888; + } + return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565; + + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return &_mesa_texformat_argb8888; + + case GL_RGBA4: + case GL_RGBA2: + return &_mesa_texformat_argb4444; + + case GL_RGB5_A1: + return &_mesa_texformat_argb1555; + + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return &_mesa_texformat_argb8888; + + case GL_RGB5: + case GL_RGB4: + case GL_R3_G3_B2: + return &_mesa_texformat_rgb565; + + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + case GL_COMPRESSED_ALPHA: + return &_mesa_texformat_a8; + + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + case GL_COMPRESSED_LUMINANCE: + return &_mesa_texformat_l8; + + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + case GL_COMPRESSED_LUMINANCE_ALPHA: + return &_mesa_texformat_al88; + + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + case GL_COMPRESSED_INTENSITY: + return &_mesa_texformat_i8; + + case GL_YCBCR_MESA: + if (type == GL_UNSIGNED_SHORT_8_8_MESA || + type == GL_UNSIGNED_BYTE) + return &_mesa_texformat_ycbcr; + else + return &_mesa_texformat_ycbcr_rev; + case GL_COMPRESSED_RGB_FXT1_3DFX: + return &_mesa_texformat_rgb_fxt1; + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return &_mesa_texformat_rgba_fxt1; -viaTextureObjectPtr viaAllocTextureObject(struct gl_texture_object *texObj) + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + return &_mesa_texformat_rgb_dxt1; + + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + return &_mesa_texformat_rgba_dxt1; + + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + return &_mesa_texformat_rgba_dxt3; + + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + return &_mesa_texformat_rgba_dxt5; + + case GL_COLOR_INDEX: + case GL_COLOR_INDEX1_EXT: + case GL_COLOR_INDEX2_EXT: + case GL_COLOR_INDEX4_EXT: + case GL_COLOR_INDEX8_EXT: + case GL_COLOR_INDEX12_EXT: + case GL_COLOR_INDEX16_EXT: + return &_mesa_texformat_ci8; + + default: + fprintf(stderr, "unexpected texture format %s in %s\n", + _mesa_lookup_enum_by_nr(internalFormat), + __FUNCTION__); + return NULL; + } + + return NULL; /* never get here */ +} + +static int logbase2(int n) { - viaTextureObjectPtr t; + GLint i = 1; + GLint log2 = 0; + + while (n > i) { + i *= 2; + log2++; + } - t = (viaTextureObjectPtr)CALLOC_STRUCT(via_texture_object_t); - if (!t) - return NULL; + return log2; +} - /* Initialize non-image-dependent parts of the state: - */ - t->bufAddr = NULL; - t->dirtyImages = ~0; - t->actualLevel = 0; - t->globj = texObj; - make_empty_list(t); +static const char *get_memtype_name( GLint memType ) +{ + static const char *names[] = { + "VIA_MEM_VIDEO", + "VIA_MEM_AGP", + "VIA_MEM_SYSTEM", + "VIA_MEM_MIXED", + "VIA_MEM_UNKNOWN" + }; - return t; + return names[memType]; } -static void viaTexImage1D(GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) + +static GLboolean viaMoveTexBuffers( struct via_context *vmesa, + struct via_tex_buffer **buffers, + GLuint nr, + GLint newMemType ) { - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; - if (VIA_DEBUG) fprintf(stderr, "viaTexImage1D - in\n"); - if (t) { - if (level == 0) { - viaSwapOutTexObj(VIA_CONTEXT(ctx), t); - t->actualLevel = 0; - } - else - t->actualLevel++; - } - else { - t = viaAllocTextureObject(texObj); - if (!t) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "viaTexImage1D"); - return; - } - texObj->DriverData = t; - } - _mesa_store_teximage1d(ctx, target, level, internalFormat, - width, border, format, type, - pixels, packing, texObj, texImage); - if (VIA_DEBUG) fprintf(stderr, "viaTexImage1D - out\n"); + struct via_tex_buffer *newTexBuf[VIA_MAX_TEXLEVELS]; + GLint i; + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s to %s\n", + __FUNCTION__, + get_memtype_name(newMemType)); + + memset(newTexBuf, 0, sizeof(newTexBuf)); + + /* First do all the allocations (or fail): + */ + for (i = 0; i < nr; i++) { + if (buffers[i]->memType != newMemType) { + + /* Don't allow uploads in a thrash state. Should try and + * catch this earlier. + */ + if (vmesa->thrashing && newMemType != VIA_MEM_SYSTEM) + goto cleanup; + + newTexBuf[i] = via_alloc_texture(vmesa, + buffers[i]->size, + newMemType); + if (!newTexBuf[i]) + goto cleanup; + } + } + + + /* Now copy all the image data and free the old texture memory. + */ + for (i = 0; i < nr; i++) { + if (newTexBuf[i]) { + memcpy(newTexBuf[i]->bufAddr, + buffers[i]->bufAddr, + buffers[i]->size); + + newTexBuf[i]->image = buffers[i]->image; + newTexBuf[i]->image->texMem = newTexBuf[i]; + newTexBuf[i]->image->image.Data = newTexBuf[i]->bufAddr; + via_free_texture(vmesa, buffers[i]); + } + } + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s - success\n", __FUNCTION__); + + return GL_TRUE; + + cleanup: + /* Release any allocations made prior to failure: + */ + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s - failed\n", __FUNCTION__); + + for (i = 0; i < nr; i++) { + if (newTexBuf[i]) { + via_free_texture(vmesa, newTexBuf[i]); + } + } + + return GL_FALSE; } -static void viaTexSubImage1D(GLcontext *ctx, - GLenum target, - GLint level, - GLint xoffset, - GLsizei width, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) + +static GLboolean viaMoveTexObject( struct via_context *vmesa, + struct via_texture_object *viaObj, + GLint newMemType ) +{ + struct via_texture_image **viaImage = + (struct via_texture_image **)&viaObj->obj.Image[0][0]; + struct via_tex_buffer *buffers[VIA_MAX_TEXLEVELS]; + GLuint i, nr = 0; + + for (i = viaObj->firstLevel; i <= viaObj->lastLevel; i++) + buffers[nr++] = viaImage[i]->texMem; + + if (viaMoveTexBuffers( vmesa, &buffers[0], nr, newMemType )) { + viaObj->memType = newMemType; + return GL_TRUE; + } + + return GL_FALSE; +} + + + +static GLboolean viaSwapInTexObject( struct via_context *vmesa, + struct via_texture_object *viaObj ) { - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; - - if (t) { - viaSwapOutTexObj(VIA_CONTEXT(ctx), t); - } - _mesa_store_texsubimage1d(ctx, target, level, xoffset, width, - format, type, pixels, packing, texObj, - texImage); + const struct via_texture_image *baseImage = + (struct via_texture_image *)viaObj->obj.Image[0][viaObj->obj.BaseLevel]; + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s\n", __FUNCTION__); + + if (baseImage->texMem->memType != VIA_MEM_SYSTEM) + return viaMoveTexObject( vmesa, viaObj, baseImage->texMem->memType ); + + return (viaMoveTexObject( vmesa, viaObj, VIA_MEM_AGP ) || + viaMoveTexObject( vmesa, viaObj, VIA_MEM_VIDEO )); +} + +/* This seems crude, but it asks a fairly pertinent question and gives + * an accurate answer: + */ +static GLboolean viaIsTexMemLow( struct via_context *vmesa, + GLuint heap ) +{ + struct via_tex_buffer *buf = via_alloc_texture(vmesa, 512 * 1024, heap ); + if (!buf) + return GL_TRUE; + + via_free_texture(vmesa, buf); + return GL_FALSE; } -static void viaTexImage2D(GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLenum format, GLenum type, const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) +/* Speculatively move texture images which haven't been used in a + * while back to system memory. + * + * TODO: only do this when texture memory is low. + * + * TODO: use dma. + * + * TODO: keep the fb/agp version hanging around and use the local + * version as backing store, so re-upload might be avoided. + * + * TODO: do this properly in the kernel... + */ +GLboolean viaSwapOutWork( struct via_context *vmesa ) { - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; - if (VIA_DEBUG) fprintf(stderr, "viaTexImage2D - in\n"); - if (t) { - if (level == 0) { - viaSwapOutTexObj(VIA_CONTEXT(ctx), t); - t->actualLevel = 0; - } - else - t->actualLevel++; - } - else { - t = viaAllocTextureObject(texObj); - if (!t) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "viaTexImage2D"); - return; - } - texObj->DriverData = t; - } - _mesa_store_teximage2d(ctx, target, level, internalFormat, - width, height, border, format, type, - pixels, packing, texObj, texImage); - if (VIA_DEBUG) fprintf(stderr, "viaTexImage2D - out\n"); + struct via_tex_buffer *s, *tmp; + GLuint done = 0; + GLuint heap, target; + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s VID %d AGP %d SYS %d\n", __FUNCTION__, + vmesa->total_alloc[VIA_MEM_VIDEO], + vmesa->total_alloc[VIA_MEM_AGP], + vmesa->total_alloc[VIA_MEM_SYSTEM]); + + + for (heap = VIA_MEM_VIDEO; heap <= VIA_MEM_AGP; heap++) { + GLuint nr = 0, sz = 0; + + if (vmesa->thrashing) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "Heap %d: trash flag\n", heap); + target = 1*1024*1024; + } + else if (viaIsTexMemLow(vmesa, heap)) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "Heap %d: low memory\n", heap); + target = 64*1024; + } + else { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "Heap %d: nothing to do\n", heap); + continue; + } + + foreach_s( s, tmp, &vmesa->tex_image_list[heap] ) { + if (s->lastUsed < vmesa->lastSwap[1]) { + struct via_texture_object *viaObj = + (struct via_texture_object *) s->image->image.TexObject; + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, + "back copy tex sz %d, lastUsed %d lastSwap %d\n", + s->size, s->lastUsed, vmesa->lastSwap[1]); + + if (viaMoveTexBuffers( vmesa, &s, 1, VIA_MEM_SYSTEM )) { + viaObj->memType = VIA_MEM_MIXED; + done += s->size; + } + else { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "Failed to back copy texture!\n"); + sz += s->size; + } + } + else { + nr ++; + sz += s->size; + } + + if (done > target) { + vmesa->thrashing = GL_FALSE; /* might not get set otherwise? */ + return GL_TRUE; + } + } + + assert(sz == vmesa->total_alloc[heap]); + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "Heap %d: nr %d tot sz %d\n", heap, nr, sz); + } + + + return done != 0; +} + + + +/* Basically, just collect the image dimensions and addresses for each + * image and update the texture object state accordingly. + */ +static GLboolean viaSetTexImages(GLcontext *ctx, + struct gl_texture_object *texObj) +{ + struct via_context *vmesa = VIA_CONTEXT(ctx); + struct via_texture_object *viaObj = (struct via_texture_object *)texObj; + const struct via_texture_image *baseImage = + (struct via_texture_image *)texObj->Image[0][texObj->BaseLevel]; + GLint firstLevel, lastLevel, numLevels; + GLuint texFormat; + GLint w, h, p; + GLint i, j = 0, k = 0, l = 0, m = 0; + GLuint texBase; + GLuint basH = 0; + GLuint widthExp = 0; + GLuint heightExp = 0; + + switch (baseImage->image.TexFormat->MesaFormat) { + case MESA_FORMAT_ARGB8888: + texFormat = HC_HTXnFM_ARGB8888; + break; + case MESA_FORMAT_ARGB4444: + texFormat = HC_HTXnFM_ARGB4444; + break; + case MESA_FORMAT_RGB565: + texFormat = HC_HTXnFM_RGB565; + break; + case MESA_FORMAT_ARGB1555: + texFormat = HC_HTXnFM_ARGB1555; + break; + case MESA_FORMAT_RGB888: + texFormat = HC_HTXnFM_ARGB0888; + break; + case MESA_FORMAT_L8: + texFormat = HC_HTXnFM_L8; + break; + case MESA_FORMAT_I8: + texFormat = HC_HTXnFM_T8; + break; + case MESA_FORMAT_CI8: + texFormat = HC_HTXnFM_Index8; + break; + case MESA_FORMAT_AL88: + texFormat = HC_HTXnFM_AL88; + break; + case MESA_FORMAT_A8: + texFormat = HC_HTXnFM_A8; + break; + default: + _mesa_problem(vmesa->glCtx, "Bad texture format in viaSetTexImages"); + return GL_FALSE; + } + + /* Compute which mipmap levels we really want to send to the hardware. + * This depends on the base image size, GL_TEXTURE_MIN_LOD, + * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL. + * Yes, this looks overly complicated, but it's all needed. + */ + if (texObj->MinFilter == GL_LINEAR || texObj->MinFilter == GL_NEAREST) { + firstLevel = lastLevel = texObj->BaseLevel; + } + else { + firstLevel = texObj->BaseLevel + (GLint)(texObj->MinLod + 0.5); + firstLevel = MAX2(firstLevel, texObj->BaseLevel); + lastLevel = texObj->BaseLevel + (GLint)(texObj->MaxLod + 0.5); + lastLevel = MAX2(lastLevel, texObj->BaseLevel); + lastLevel = MIN2(lastLevel, texObj->BaseLevel + baseImage->image.MaxLog2); + lastLevel = MIN2(lastLevel, texObj->MaxLevel); + lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */ + } + + numLevels = lastLevel - firstLevel + 1; + + /* save these values, check if they effect the residency of the + * texture: + */ + if (viaObj->firstLevel != firstLevel || + viaObj->lastLevel != lastLevel) { + viaObj->firstLevel = firstLevel; + viaObj->lastLevel = lastLevel; + viaObj->memType = VIA_MEM_MIXED; + } + + if (VIA_DEBUG & DEBUG_TEXTURE & 0) + fprintf(stderr, "%s, current memType: %s\n", + __FUNCTION__, + get_memtype_name(viaObj->memType)); + + + if (viaObj->memType == VIA_MEM_MIXED || + viaObj->memType == VIA_MEM_SYSTEM) { + if (!viaSwapInTexObject(vmesa, viaObj)) { + if (VIA_DEBUG & DEBUG_TEXTURE) + if (!vmesa->thrashing) + fprintf(stderr, "Thrashing flag set for frame %d\n", + vmesa->swap_count); + vmesa->thrashing = GL_TRUE; + return GL_FALSE; + } + } + + if (viaObj->memType == VIA_MEM_AGP) + viaObj->regTexFM = (HC_SubA_HTXnFM << 24) | HC_HTXnLoc_AGP | texFormat; + else + viaObj->regTexFM = (HC_SubA_HTXnFM << 24) | HC_HTXnLoc_Local | texFormat; + + + for (i = 0; i < numLevels; i++) { + struct via_texture_image *viaImage = + (struct via_texture_image *)texObj->Image[0][firstLevel + i]; + + w = viaImage->image.WidthLog2; + h = viaImage->image.HeightLog2; + p = viaImage->pitchLog2; + + assert(viaImage->texMem->memType == viaObj->memType); + + texBase = viaImage->texMem->texBase; + if (!texBase) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s: no texBase[%d]\n", __FUNCTION__, i); + return GL_FALSE; + } + + /* Image has to remain resident until the coming fence is retired. + */ + move_to_head( &vmesa->tex_image_list[viaImage->texMem->memType], + viaImage->texMem ); + viaImage->texMem->lastUsed = vmesa->lastBreadcrumbWrite; + + + viaObj->regTexBaseAndPitch[i].baseL = + ((HC_SubA_HTXnL0BasL + i) << 24) | (texBase & 0xFFFFFF); + + viaObj->regTexBaseAndPitch[i].pitchLog2 = + ((HC_SubA_HTXnL0Pit + i) << 24) | (p << 20); + + + /* The base high bytes for each 3 levels are packed + * together into one register: + */ + j = i / 3; + k = 3 - (i % 3); + basH |= ((texBase & 0xFF000000) >> (k << 3)); + if (k == 1) { + viaObj->regTexBaseH[j] = ((j + HC_SubA_HTXnL012BasH) << 24) | basH; + basH = 0; + } + + /* Likewise, sets of 6 log2width and log2height values are + * packed into individual registers: + */ + l = i / 6; + m = i % 6; + widthExp |= (((GLuint)w & 0xF) << (m << 2)); + heightExp |= (((GLuint)h & 0xF) << (m << 2)); + if (m == 5) { + viaObj->regTexWidthLog2[l] = + (l + HC_SubA_HTXnL0_5WE) << 24 | widthExp; + viaObj->regTexHeightLog2[l] = + (l + HC_SubA_HTXnL0_5HE) << 24 | heightExp; + widthExp = 0; + heightExp = 0; + } + if (w) w--; + if (h) h--; + if (p) p--; + } + + if (k != 1) { + viaObj->regTexBaseH[j] = ((j + HC_SubA_HTXnL012BasH) << 24) | basH; + } + if (m != 5) { + viaObj->regTexWidthLog2[l] = (l + HC_SubA_HTXnL0_5WE) << 24 | widthExp; + viaObj->regTexHeightLog2[l] = (l + HC_SubA_HTXnL0_5HE) << 24 | heightExp; + } + + return GL_TRUE; +} + + +GLboolean viaUpdateTextureState( GLcontext *ctx ) +{ + struct gl_texture_unit *texUnit = ctx->Texture.Unit; + GLuint i; + + for (i = 0; i < 2; i++) { + if (texUnit[i]._ReallyEnabled == TEXTURE_2D_BIT || + texUnit[i]._ReallyEnabled == TEXTURE_1D_BIT) { + + if (!viaSetTexImages(ctx, texUnit[i]._Current)) + return GL_FALSE; + } + else if (texUnit[i]._ReallyEnabled) { + return GL_FALSE; + } + } + + return GL_TRUE; +} + + + + + + + + +static void viaTexImage(GLcontext *ctx, + GLint dims, + GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint height, GLint border, + GLenum format, GLenum type, const void *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) +{ + struct via_context *vmesa = VIA_CONTEXT(ctx); + GLint postConvWidth = width; + GLint postConvHeight = height; + GLint texelBytes, sizeInBytes; + struct via_texture_object *viaObj = (struct via_texture_object *)texObj; + struct via_texture_image *viaImage = (struct via_texture_image *)texImage; + int heaps[3], nheaps, i; + + if (!is_empty_list(&vmesa->freed_tex_buffers)) { + viaCheckBreadcrumb(vmesa, 0); + via_release_pending_textures(vmesa); + } + + if (ctx->_ImageTransferState & IMAGE_CONVOLUTION_BIT) { + _mesa_adjust_image_for_convolution(ctx, dims, &postConvWidth, + &postConvHeight); + } + + /* choose the texture format */ + texImage->TexFormat = viaChooseTexFormat(ctx, internalFormat, + format, type); + + assert(texImage->TexFormat); + + if (dims == 1) { + texImage->FetchTexelc = texImage->TexFormat->FetchTexel1D; + texImage->FetchTexelf = texImage->TexFormat->FetchTexel1Df; + } + else { + texImage->FetchTexelc = texImage->TexFormat->FetchTexel2D; + texImage->FetchTexelf = texImage->TexFormat->FetchTexel2Df; + } + texelBytes = texImage->TexFormat->TexelBytes; + + + /* Minimum pitch of 32 bytes */ + if (postConvWidth * texelBytes < 32) { + postConvWidth = 32 / texelBytes; + texImage->RowStride = postConvWidth; + } + + assert(texImage->RowStride == postConvWidth); + viaImage->pitchLog2 = logbase2(postConvWidth * texelBytes); + + /* allocate memory */ + if (texImage->IsCompressed) + sizeInBytes = texImage->CompressedSize; + else + sizeInBytes = postConvWidth * postConvHeight * texelBytes; + + + /* Attempt to allocate texture memory directly, otherwise use main + * memory and this texture will always be a fallback. FIXME! + * + * TODO: make room in agp if this fails. + * TODO: use fb ram for textures as well. + */ + + + switch (viaObj->memType) { + case VIA_MEM_UNKNOWN: + heaps[0] = VIA_MEM_AGP; + heaps[1] = VIA_MEM_VIDEO; + heaps[2] = VIA_MEM_SYSTEM; + nheaps = 3; + break; + case VIA_MEM_AGP: + case VIA_MEM_VIDEO: + heaps[0] = viaObj->memType; + heaps[1] = VIA_MEM_SYSTEM; + nheaps = 2; + break; + case VIA_MEM_MIXED: + case VIA_MEM_SYSTEM: + default: + heaps[0] = VIA_MEM_SYSTEM; + nheaps = 1; + break; + } + + for (i = 0; i < nheaps && !viaImage->texMem; i++) { + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "try %s (obj %s)\n", get_memtype_name(heaps[i]), + get_memtype_name(viaObj->memType)); + viaImage->texMem = via_alloc_texture(vmesa, sizeInBytes, heaps[i]); + } + + if (!viaImage->texMem) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + return; + } + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "upload %d bytes to %s\n", sizeInBytes, + get_memtype_name(viaImage->texMem->memType)); + + viaImage->texMem->image = viaImage; + texImage->Data = viaImage->texMem->bufAddr; + + if (viaObj->memType == VIA_MEM_UNKNOWN) + viaObj->memType = viaImage->texMem->memType; + else if (viaObj->memType != viaImage->texMem->memType) + viaObj->memType = VIA_MEM_MIXED; + + if (VIA_DEBUG & DEBUG_TEXTURE) + fprintf(stderr, "%s, obj %s, image : %s\n", + __FUNCTION__, + get_memtype_name(viaObj->memType), + get_memtype_name(viaImage->texMem->memType)); + + vmesa->clearTexCache = 1; + + pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1, + format, type, + pixels, packing, "glTexImage"); + if (!pixels) { + /* Note: we check for a NULL image pointer here, _after_ we allocated + * memory for the texture. That's what the GL spec calls for. + */ + return; + } + else { + GLint dstRowStride, dstImageStride = 0; + GLboolean success; + if (texImage->IsCompressed) { + dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat,width); + } + else { + dstRowStride = postConvWidth * texImage->TexFormat->TexelBytes; + } + ASSERT(texImage->TexFormat->StoreImage); + success = texImage->TexFormat->StoreImage(ctx, dims, texImage->Format, + texImage->TexFormat, + texImage->Data, + 0, 0, 0, /* dstX/Y/Zoffset */ + dstRowStride, dstImageStride, + width, height, 1, + format, type, pixels, packing); + if (!success) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + } + } + + /* GL_SGIS_generate_mipmap */ + if (level == texObj->BaseLevel && texObj->GenerateMipmap) { + _mesa_generate_mipmap(ctx, target, + &ctx->Texture.Unit[ctx->Texture.CurrentUnit], + texObj); + } + + _mesa_unmap_teximage_pbo(ctx, packing); +} + +static void viaTexImage2D(GLcontext *ctx, + GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint height, GLint border, + GLenum format, GLenum type, const void *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) +{ + viaTexImage( ctx, 2, target, level, + internalFormat, width, height, border, + format, type, pixels, + packing, texObj, texImage ); } static void viaTexSubImage2D(GLcontext *ctx, @@ -160,191 +836,120 @@ static void viaTexSubImage2D(GLcontext *ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; - - if (t) { - viaSwapOutTexObj(VIA_CONTEXT(ctx), t); - } - _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width, - height, format, type, pixels, packing, texObj, - texImage); - - if(vmesa->shareCtx) - vmesa->shareCtx->NewState |= _NEW_TEXTURE; + struct via_context *vmesa = VIA_CONTEXT(ctx); + + VIA_FLUSH_DMA(vmesa); + vmesa->clearTexCache = 1; + _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width, + height, format, type, pixels, packing, texObj, + texImage); } -static void viaBindTexture(GLcontext *ctx, GLenum target, - struct gl_texture_object *texObj) +static void viaTexImage1D(GLcontext *ctx, + GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint border, + GLenum format, GLenum type, const void *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) { - if (VIA_DEBUG) fprintf(stderr, "viaBindTexture - in\n"); - if (target == GL_TEXTURE_2D) { - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; - - if (!t) { - - t = viaAllocTextureObject(texObj); - if (!t) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "viaBindTexture"); - return; - } - texObj->DriverData = t; - } - } - if (VIA_DEBUG) fprintf(stderr, "viaBindTexture - out\n"); + viaTexImage( ctx, 1, target, level, + internalFormat, width, 1, border, + format, type, pixels, + packing, texObj, texImage ); } -static void viaDeleteTexture(GLcontext *ctx, struct gl_texture_object *texObj) +static void viaTexSubImage1D(GLcontext *ctx, + GLenum target, + GLint level, + GLint xoffset, + GLsizei width, + GLenum format, GLenum type, + const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) { - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; - if (VIA_DEBUG) fprintf(stderr, "viaDeleteTexture - in\n"); - if (t) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - if (vmesa) { - if (vmesa->dma) { /* imply vmesa is not under destroying */ - VIA_FLUSH_DMA(vmesa); - } - viaDestroyTexObj(vmesa, t); - } - texObj->DriverData = 0; - } - if (VIA_DEBUG) fprintf(stderr, "viaDeleteTexture - out\n"); - - /* Free mipmap images and the texture object itself */ - _mesa_delete_texture_object(ctx, texObj); + struct via_context *vmesa = VIA_CONTEXT(ctx); + + VIA_FLUSH_DMA(vmesa); + vmesa->clearTexCache = 1; + + _mesa_store_texsubimage1d(ctx, target, level, xoffset, width, + format, type, pixels, packing, texObj, + texImage); } + + static GLboolean viaIsTextureResident(GLcontext *ctx, struct gl_texture_object *texObj) { - viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData; + struct via_texture_object *viaObj = + (struct via_texture_object *)texObj; - return t && t->bufAddr; + return (viaObj->memType == VIA_MEM_AGP || + viaObj->memType == VIA_MEM_VIDEO); } -static const struct gl_texture_format * -viaChooseTexFormat(GLcontext *ctx, GLint internalFormat, - GLenum format, GLenum type) + + +static struct gl_texture_image *viaNewTextureImage( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); - (void)format; - (void)type; - if (VIA_DEBUG) fprintf(stderr, "%s in\n", __FUNCTION__); - if (VIA_DEBUG) fprintf(stderr, "internalFormat:%d format:%d\n", internalFormat, format); - switch (internalFormat) { - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - return &_mesa_texformat_l8; - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - return &_mesa_texformat_al88; - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB5: - if (VIA_DEBUG) fprintf(stderr, "2 &_mesa_texformat_arg565\n"); - return &_mesa_texformat_rgb565; - case 3: - case GL_RGB: - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - if (vmesa->viaScreen->bitsPerPixel == 0x20) { - if (VIA_DEBUG) fprintf(stderr,"3 argb8888\n"); - return &_mesa_texformat_argb8888; - } - else { - if (VIA_DEBUG) fprintf(stderr,"3 rgb565\n"); - return &_mesa_texformat_rgb565; - } - case 4: - if (vmesa->viaScreen->bitsPerPixel == 0x20) { - if (VIA_DEBUG) fprintf(stderr, "4 &_mesa_texformat_argb8888\n"); - return &_mesa_texformat_argb8888; - } - else { - if (VIA_DEBUG) fprintf(stderr, "4 &_mesa_texformat_argb4444\n"); - return &_mesa_texformat_argb4444; - } - case GL_RGBA2: - case GL_RGBA4: - if (VIA_DEBUG) fprintf(stderr, "GL_RGBA4 &_mesa_texformat_argb4444\n"); - return &_mesa_texformat_argb4444; - - case GL_RGB5_A1: - if (VIA_DEBUG) fprintf(stderr, "GL_RGB5_A1 &_mesa_texformat_argb1555\n"); - return &_mesa_texformat_argb1555; - case GL_RGBA: - case GL_RGBA8: - case GL_RGBA12: - case GL_RGBA16: - case GL_RGB10_A2: - if (VIA_DEBUG) fprintf(stderr, "GL_RGBA &_mesa_texformat_argb8888\n"); - return &_mesa_texformat_argb8888; - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - return &_mesa_texformat_a8; - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - return &_mesa_texformat_i8; - case GL_COLOR_INDEX: - case GL_COLOR_INDEX1_EXT: - case GL_COLOR_INDEX2_EXT: - case GL_COLOR_INDEX4_EXT: - case GL_COLOR_INDEX8_EXT: - case GL_COLOR_INDEX12_EXT: - case GL_COLOR_INDEX16_EXT: - return &_mesa_texformat_ci8; - default: - _mesa_problem(ctx, "unexpected format in viaChooseTextureFormat"); - return NULL; - } -} + (void) ctx; + return (struct gl_texture_image *)CALLOC_STRUCT(via_texture_image); +} -void viaInitTextureFuncs(struct dd_function_table * functions) + +static struct gl_texture_object *viaNewTextureObject( GLcontext *ctx, + GLuint name, + GLenum target ) { - if (VIA_DEBUG) fprintf(stderr, "viaInitTextureFuncs - in\n"); - functions->ChooseTextureFormat = viaChooseTexFormat; - functions->TexImage1D = viaTexImage1D; - functions->TexImage2D = viaTexImage2D; - functions->TexSubImage1D = viaTexSubImage1D; - functions->TexSubImage2D = viaTexSubImage2D; - - functions->NewTextureObject = _mesa_new_texture_object; - functions->BindTexture = viaBindTexture; - functions->DeleteTexture = viaDeleteTexture; - functions->UpdateTexturePalette = 0; - functions->IsTextureResident = viaIsTextureResident; - - if (VIA_DEBUG) fprintf(stderr, "viaInitTextureFuncs - out\n"); + struct via_texture_object *obj = CALLOC_STRUCT(via_texture_object); + + _mesa_initialize_texture_object(&obj->obj, name, target); + (void) ctx; + + obj->memType = VIA_MEM_UNKNOWN; + + return &obj->obj; } -void viaInitTextures(GLcontext *ctx) + +static void viaFreeTextureImageData( GLcontext *ctx, + struct gl_texture_image *texImage ) { - GLuint tmp = ctx->Texture.CurrentUnit; - ctx->Texture.CurrentUnit = 0; - viaBindTexture(ctx, GL_TEXTURE_1D, ctx->Texture.Unit[0].Current1D); - viaBindTexture(ctx, GL_TEXTURE_2D, ctx->Texture.Unit[0].Current2D); - ctx->Texture.CurrentUnit = 1; - viaBindTexture(ctx, GL_TEXTURE_1D, ctx->Texture.Unit[1].Current1D); - viaBindTexture(ctx, GL_TEXTURE_2D, ctx->Texture.Unit[1].Current2D); - ctx->Texture.CurrentUnit = tmp; + struct via_context *vmesa = VIA_CONTEXT(ctx); + struct via_texture_image *image = (struct via_texture_image *)texImage; + + if (image->texMem) { + via_free_texture(vmesa, image->texMem); + image->texMem = NULL; + } + + texImage->Data = NULL; } + + + + +void viaInitTextureFuncs(struct dd_function_table * functions) +{ + functions->ChooseTextureFormat = viaChooseTexFormat; + functions->TexImage1D = viaTexImage1D; + functions->TexImage2D = viaTexImage2D; + functions->TexSubImage1D = viaTexSubImage1D; + functions->TexSubImage2D = viaTexSubImage2D; + + functions->NewTextureObject = viaNewTextureObject; + functions->NewTextureImage = viaNewTextureImage; + functions->DeleteTexture = _mesa_delete_texture_object; + functions->FreeTexImageData = viaFreeTextureImageData; + + functions->UpdateTexturePalette = 0; + functions->IsTextureResident = viaIsTextureResident; +} + + diff --git a/src/mesa/drivers/dri/unichrome/via_tex.h b/src/mesa/drivers/dri/unichrome/via_tex.h index 1b5611a2158..f6c024e4381 100644 --- a/src/mesa/drivers/dri/unichrome/via_tex.h +++ b/src/mesa/drivers/dri/unichrome/via_tex.h @@ -27,86 +27,11 @@ #define _VIATEX_H #include "mtypes.h" -#include "mm.h" -#include "via_context.h" -#include "via_3d_reg.h" +struct via_context; -#define VIA_TEX_MAXLEVELS 10 - - -/* For shared texture space managment, these texture objects may also - * be used as proxies for regions of texture memory containing other - * client's textures. Such proxy textures (not to be confused with GL - * proxy textures) are subject to the same LRU aging we use for our - * own private textures, and thus we have a mechanism where we can - * fairly decide between kicking out our own textures and those of - * other clients. - * - * Non-local texture objects have a valid MemBlock to describe the - * region managed by the other client, and can be identified by - * 't->globj == 0' - */ -struct via_texture_object_t { - struct via_texture_object_t *next, *prev; - - GLuint age; - struct gl_texture_object *globj; - - int texelBytes; - int totalSize; - - struct { - GLuint index; - GLuint offset; - GLuint size; - } texMem; - unsigned char* bufAddr; - - GLuint inAGP; - GLuint needClearCache; - GLuint actualLevel; - - GLuint maxLevel; - GLuint dirtyImages; - - struct { - const struct gl_texture_image *image; - int offset; /* into bufAddr */ - int height; - int internalFormat; - } image[VIA_TEX_MAXLEVELS]; - - GLuint dirty; - - GLuint regTexFM; - GLuint regTexWidthLog2[2]; - GLuint regTexHeightLog2[2]; - GLuint regTexBaseH[4]; - struct { - GLuint baseL; - GLuint pitchLog2; - } regTexBaseAndPitch[12]; - - GLint firstLevel, lastLevel; /* upload tObj->Image[first .. lastLevel] */ -}; - -viaTextureObjectPtr viaAllocTextureObject(struct gl_texture_object *texObj); GLboolean viaUpdateTextureState(GLcontext *ctx); void viaInitTextureFuncs(struct dd_function_table * functions); -void viaInitTextures(GLcontext *ctx); - -void viaDestroyTexObj(viaContextPtr vmesa, viaTextureObjectPtr t); -void viaSwapOutTexObj(viaContextPtr vmesa, viaTextureObjectPtr t); -void viaUploadTexImages(viaContextPtr vmesa, viaTextureObjectPtr t); - -void viaResetGlobalLRU(viaContextPtr vmesa); -void viaTexturesGone(viaContextPtr vmesa, - GLuint start, GLuint end, - GLuint in_use); - -void viaPrintLocalLRU(viaContextPtr vmesa); -void viaPrintGlobalLRU(viaContextPtr vmesa); -void viaUpdateTexLRU(viaContextPtr vmesa, viaTextureObjectPtr t); +GLboolean viaSwapOutWork( struct via_context *vmesa ); #endif diff --git a/src/mesa/drivers/dri/unichrome/via_texcombine.c b/src/mesa/drivers/dri/unichrome/via_texcombine.c index d30cc056290..e691c553f99 100644 --- a/src/mesa/drivers/dri/unichrome/via_texcombine.c +++ b/src/mesa/drivers/dri/unichrome/via_texcombine.c @@ -36,21 +36,12 @@ #include "macros.h" #include "colormac.h" #include "enums.h" -#include "dd.h" -#include "mm.h" #include "via_context.h" #include "via_state.h" #include "via_tex.h" -#include "via_tris.h" -#include "via_ioctl.h" +#include "via_3d_reg.h" -#include "swrast/swrast.h" -#include "array_cache/acache.h" -#include "tnl/tnl.h" -#include "swrast_setup/swrast_setup.h" - -#include "tnl/t_pipeline.h" #define VIA_USE_ALPHA (HC_XTC_Adif - HC_XTC_Dif) @@ -90,24 +81,18 @@ static const unsigned a_shift_table[3] = { * Calculate the hardware state for the specified texture combine mode * * \bug - * For the alpha combine, \c GL_CONSTANT is still probably wrong. - * - * \bug * All forms of DOT3 bumpmapping are completely untested, and are most - * likely wrong. - * - * \bug - * This code still fails progs/demos/texenv for all modes with \c GL_ALPHA - * textures. This was also the case with the code that Via supplied. It - * also fails for \c GL_REPLACE with \c GL_RGBA textures. Everything else - * that texenv tests looks good. + * likely wrong. KW: Looks like it will never be quite right as the + * hardware seems to experience overflow in color calculation at the + * 4x shift levels, which need to be programed for DOT3. Maybe newer + * hardware fixes these issues. * * \bug * KW: needs attention to the case where texunit 1 is enabled but * texunit 0 is not. */ GLboolean -viaTexCombineState( viaContextPtr vmesa, +viaTexCombineState( struct via_context *vmesa, const struct gl_tex_env_combine_state * combine, unsigned unit ) { @@ -126,7 +111,8 @@ viaTexCombineState( viaContextPtr vmesa, unsigned constant_alpha[3]; unsigned bias_alpha = 0; unsigned abc_alpha = 0; - const struct gl_texture_unit const * texUnit = & vmesa->glCtx->Texture.Unit[unit]; + const struct gl_texture_unit const * texUnit = + &vmesa->glCtx->Texture.Unit[unit]; unsigned env_color[4]; /* It seems that the color clamping can be overwhelmed at the 4x @@ -329,7 +315,9 @@ viaTexCombineState( viaContextPtr vmesa, case GL_PREVIOUS: alpha_arg[i] = (unit == 0) ? HC_XTA_Adif : HC_XTA_Acur; alpha_arg[i] += alpha_operand_modifier[op]; - bias_alpha_arg[i] = (unit == 0) ? HC_HTXnTBLAbias_Adif : HC_HTXnTBLAbias_Acur; + bias_alpha_arg[i] = (unit == 0 ? + HC_HTXnTBLAbias_Adif : + HC_HTXnTBLAbias_Acur); bias_alpha_arg[i] += bias_alpha_operand_modifier[op]; break; } @@ -418,34 +406,18 @@ viaTexCombineState( viaContextPtr vmesa, op |= c_shift_table[ c_shift ] | a_shift_table[ a_shift ]; - if ( unit == 0 ) { - vmesa->regHTXnTBLMPfog_0 = HC_HTXnTBLMPfog_Fog; + vmesa->regHTXnTBLMPfog[unit] = HC_HTXnTBLMPfog_Fog; - vmesa->regHTXnTBLCsat_0 = color; - vmesa->regHTXnTBLAsat_0 = alpha; - vmesa->regHTXnTBLCop_0 = op | bias; - vmesa->regHTXnTBLRAa_0 = abc_alpha; - vmesa->regHTXnTBLRFog_0 = bias_alpha; + vmesa->regHTXnTBLCsat[unit] = color; + vmesa->regHTXnTBLAsat[unit] = alpha; + vmesa->regHTXnTBLCop[unit] = op | bias; + vmesa->regHTXnTBLRAa[unit] = abc_alpha; + vmesa->regHTXnTBLRFog[unit] = bias_alpha; - vmesa->regHTXnTBLRCa_0 = ordered_constant_color[0]; - vmesa->regHTXnTBLRCb_0 = ordered_constant_color[1]; - vmesa->regHTXnTBLRCc_0 = ordered_constant_color[2]; - vmesa->regHTXnTBLRCbias_0 = ordered_constant_color[3]; - } - else { - vmesa->regHTXnTBLMPfog_1 = HC_HTXnTBLMPfog_Fog; - - vmesa->regHTXnTBLCsat_1 = color; - vmesa->regHTXnTBLAsat_1 = alpha; - vmesa->regHTXnTBLCop_1 = op | bias; - vmesa->regHTXnTBLRAa_1 = abc_alpha; - vmesa->regHTXnTBLRFog_1 = bias_alpha; - - vmesa->regHTXnTBLRCa_1 = ordered_constant_color[0]; - vmesa->regHTXnTBLRCb_1 = ordered_constant_color[1]; - vmesa->regHTXnTBLRCc_1 = ordered_constant_color[2]; - vmesa->regHTXnTBLRCbias_1 = ordered_constant_color[3]; - } + vmesa->regHTXnTBLRCa[unit] = ordered_constant_color[0]; + vmesa->regHTXnTBLRCb[unit] = ordered_constant_color[1]; + vmesa->regHTXnTBLRCc[unit] = ordered_constant_color[2]; + vmesa->regHTXnTBLRCbias[unit] = ordered_constant_color[3]; return GL_TRUE; } diff --git a/src/mesa/drivers/dri/unichrome/via_texmem.c b/src/mesa/drivers/dri/unichrome/via_texmem.c deleted file mode 100644 index 78153f68177..00000000000 --- a/src/mesa/drivers/dri/unichrome/via_texmem.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. - * Copyright 2001-2003 S3 Graphics, Inc. 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 - * VIA, S3 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. - */ - - -#include <stdlib.h> -#include <stdio.h> - -#include "glheader.h" -#include "macros.h" -#include "mtypes.h" -#include "simple_list.h" -#include "enums.h" -#include "texformat.h" - -#include "mm.h" -#include "via_context.h" -#include "via_tex.h" -#include "via_state.h" -#include "via_ioctl.h" -#include "via_fb.h" -/*=* John Sheng [2003.5.31] agp tex *=*/ - -void viaDestroyTexObj(viaContextPtr vmesa, viaTextureObjectPtr t) -{ - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - if (!t) - return; - - /* This is sad - need to sync *in case* we upload a texture - * to this newly free memory... - */ - if (t->bufAddr) { - via_free_texture(vmesa, t); - - if (vmesa && t->age > vmesa->dirtyAge) - vmesa->dirtyAge = t->age; - } - - if (t->globj) - t->globj->DriverData = 0; - - if (vmesa) { - if (vmesa->CurrentTexObj[0] == t) { - vmesa->CurrentTexObj[0] = 0; - } - - if (vmesa->CurrentTexObj[1] == t) { - vmesa->CurrentTexObj[1] = 0; - } - } - - remove_from_list(t); - free(t); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); -} - -void viaSwapOutTexObj(viaContextPtr vmesa, viaTextureObjectPtr t) -{ - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - if (t->bufAddr) { - via_free_texture(vmesa, t); - - if (t->age > vmesa->dirtyAge) - vmesa->dirtyAge = t->age; - } - - t->dirtyImages = ~0; - move_to_tail(&(vmesa->SwappedOut), t); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); -} - -/* Upload an image from mesa's internal copy. - */ -static void viaUploadTexLevel(viaTextureObjectPtr t, int level) -{ - const struct gl_texture_image *image = t->image[level].image; - int i, j; - if (VIA_DEBUG) { - fprintf(stderr, "%s - in\n", __FUNCTION__); - fprintf(stderr, "width = %d, height = %d \n", image->Width, image->Height); - } - switch (t->image[level].internalFormat) { - case GL_RGB: - { - if (image->TexFormat->MesaFormat == MESA_FORMAT_ARGB8888) { - GLuint *dst = (GLuint *)(t->bufAddr + t->image[level].offset); - GLuint *src = (GLuint *)image->Data; - if (VIA_DEBUG) fprintf(stderr, "GL_RGB MESA_FORMAT_ARGB8888\n"); - if (image->Width < 8) { - for (i = 0; i < image->Height ; i++) { - for (j = 0; j < image->Width ; j++) { - dst[j] = *src; - src++; - } - dst += 8; - } - } - else { - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - /*memcpy(dst, src, image->Height * image->Width * sizeof(GLuint));*/ - } - else { - GLushort *dst = (GLushort *)(t->bufAddr + t->image[level].offset); - GLushort *src = (GLushort *)image->Data; - if (VIA_DEBUG) fprintf(stderr, "GL_RGB !MESA_FORMAT_ARGB8888\n"); - if (image->Width < 16) { - for (i = 0; i < image->Height ; i++) { - for (j = 0; j < image->Width ; j++) { - dst[j] = *src; - src++; - } - dst += 16; - } - } - else { - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - /*memcpy(dst, src, image->Height * image->Width * sizeof(GLushort));*/ - } - } - break; - - case GL_RGBA: - { - if (image->TexFormat->MesaFormat == MESA_FORMAT_ARGB4444) { - - GLushort *dst = (GLushort *)(t->bufAddr + t->image[level].offset); - GLushort *src = (GLushort *)image->Data; - if (image->Width < 16) { - for (i = 0; i < image->Height ; i++) { - for (j = 0; j < image->Width ; j++) { - dst[j] = *src; - src++; - } - dst += 16; - } - } - else { - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - src++; - dst++; - } - } - /*memcpy(dst, src, image->Height * image->Width * sizeof(GLushort));*/ - if (VIA_DEBUG) fprintf(stderr, "GL_RGBA MESA_FORMAT_ARGB4444\n"); - } - else if(image->TexFormat->MesaFormat == MESA_FORMAT_ARGB8888) { - GLuint *dst = (GLuint *)(t->bufAddr + t->image[level].offset); - GLuint *src = (GLuint *)image->Data; - if (VIA_DEBUG) fprintf(stderr, "GL_RGBA !MESA_FORMAT_ARGB4444\n"); - if (image->Width < 8) { - for (i = 0; i < image->Height ; i++) { - for (j = 0; j < image->Width ; j++) { - dst[j] = *src; - src++; - } - dst += 8; - } - } - else { - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - /*memcpy(dst, src, image->Height * image->Width * sizeof(GLuint));*/ - } - else if(image->TexFormat->MesaFormat == MESA_FORMAT_ARGB1555) { - GLushort *dst = (GLushort *)(t->bufAddr + t->image[level].offset); - GLushort *src = (GLushort *)image->Data; - if (image->Width < 16) { - for (i = 0; i < image->Height ; i++) { - for (j = 0; j < image->Width ; j++) { - dst[j] = *src; - src++; - } - dst += 16; - } - } - else { - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - src++; - dst++; - } - } - /*memcpy(dst, src, image->Height * image->Width * sizeof(GLushort));*/ - if (VIA_DEBUG) fprintf(stderr, "GL_RGBA MESA_FORMAT_ARGB1555\n"); - } - } - break; - - case GL_LUMINANCE: - { - GLubyte *dst = (GLubyte *)(t->bufAddr + t->image[level].offset); - GLubyte *src = (GLubyte *)image->Data; - - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - break; - - case GL_INTENSITY: - { - GLubyte *dst = (GLubyte *)(t->bufAddr + t->image[level].offset); - GLubyte *src = (GLubyte *)image->Data; - - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - break; - - case GL_LUMINANCE_ALPHA: - { - GLushort *dst = (GLushort *)(t->bufAddr + t->image[level].offset); - GLushort *src = (GLushort *)image->Data; - - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - break; - - case GL_ALPHA: - { - GLubyte *dst = (GLubyte *)(t->bufAddr + t->image[level].offset); - GLubyte *src = (GLubyte *)image->Data; - - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - break; - - /* TODO: Translate color indices *now*: - */ - case GL_COLOR_INDEX: - { - GLubyte *dst = (GLubyte *)(t->bufAddr + t->image[level].offset); - GLubyte *src = (GLubyte *)image->Data; - - for (j = 0; j < image->Height * image->Width; j++) { - *dst = *src; - dst++; - src++; - } - } - break; - - default:; - if (VIA_DEBUG) fprintf(stderr, "Not supported texture format %s\n", - _mesa_lookup_enum_by_nr(image->Format)); - } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); -} - -void viaPrintLocalLRU(viaContextPtr vmesa) -{ - viaTextureObjectPtr t; - - foreach (t, &vmesa->TexObjList) { - if (!t->globj) { - if (VIA_DEBUG) { - fprintf(stderr, "offset = %x, index = %x, size = %x\n", - t->texMem.offset, - t->texMem.index, - t->texMem.size); - } - else { - if (VIA_DEBUG) { - fprintf(stderr, "offset = %x, siez = %x\n", - t->texMem.offset, - t->texMem.size); - } - } - } - } -} - -void viaPrintGlobalLRU(viaContextPtr vmesa) -{ - int i, j; - drm_via_tex_region_t *list = vmesa->sarea->texList; - - for (i = 0, j = VIA_NR_TEX_REGIONS; i < VIA_NR_TEX_REGIONS; i++) { - if (VIA_DEBUG) fprintf(stderr, "list[%d] age %d next %d prev %d\n", - j, list[j].age, list[j].next, list[j].prev); - j = list[j].next; - if (j == VIA_NR_TEX_REGIONS) break; - } - if (j != VIA_NR_TEX_REGIONS) - if (VIA_DEBUG) fprintf(stderr, "Loop detected in global LRU\n"); -} - -void viaResetGlobalLRU(viaContextPtr vmesa) -{ - drm_via_tex_region_t *list = vmesa->sarea->texList; - int sz = 1 << vmesa->viaScreen->logTextureGranularity; - int i; - - /* (Re)initialize the global circular LRU list. The last element - * in the array (VIA_NR_TEX_REGIONS) is the sentinal. Keeping it - * at the end of the array allows it to be addressed rationally - * when looking up objects at a particular location in texture - * memory. - */ - for (i = 0; (i + 1) * sz <= vmesa->viaScreen->textureSize; i++) { - list[i].prev = i - 1; - list[i].next = i + 1; - list[i].age = 0; - } - - i--; - list[0].prev = VIA_NR_TEX_REGIONS; - list[i].prev = i - 1; - list[i].next = VIA_NR_TEX_REGIONS; - list[VIA_NR_TEX_REGIONS].prev = i; - list[VIA_NR_TEX_REGIONS].next = 0; - vmesa->sarea->texAge = 0; -} - -void viaUpdateTexLRU(viaContextPtr vmesa, viaTextureObjectPtr t) -{ - vmesa->texAge = ++vmesa->sarea->texAge; - move_to_head(&(vmesa->TexObjList), t); -} - -/* Called for every shared texture region which has increased in age - * since we last held the lock. - * - * Figures out which of our textures have been ejected by other clients, - * and pushes a placeholder texture onto the LRU list to represent - * the other client's textures. - */ -void viaTexturesGone(viaContextPtr vmesa, - GLuint offset, - GLuint size, - GLuint inUse) -{ - viaTextureObjectPtr t, tmp; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - foreach_s (t, tmp, &vmesa->TexObjList) { - viaSwapOutTexObj(vmesa, t); - } - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); -} - -/* This is called with the lock held. May have to eject our own and/or - * other client's texture objects to make room for the upload. - */ -void viaUploadTexImages(viaContextPtr vmesa, viaTextureObjectPtr t) -{ - int i, j; - int numLevels; - if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__); - LOCK_HARDWARE(vmesa); - - j = 0; - if (!t->bufAddr) { - while (1) { - - /*=* John Sheng [2003.5.31] agp tex *=*/ - if (via_alloc_texture_agp(vmesa, t)) - break; - if (via_alloc_texture(vmesa, t)) - break; - - vmesa->agpFullCount++; - if (vmesa->TexObjList.prev == vmesa->CurrentTexObj[0] || - vmesa->TexObjList.prev == vmesa->CurrentTexObj[1]) { - if (VIA_DEBUG) fprintf(stderr, "Hit bound texture in upload\n"); - viaPrintLocalLRU(vmesa); - UNLOCK_HARDWARE(vmesa); - return; - } - - if (vmesa->TexObjList.prev == &(vmesa->TexObjList)) { - if (VIA_DEBUG) fprintf(stderr, "Failed to upload texture, sz %d\n", t->totalSize); - mmDumpMemInfo(vmesa->texHeap); - UNLOCK_HARDWARE(vmesa); - return; - } - - viaSwapOutTexObj(vmesa, vmesa->TexObjList.prev); - } - /*=* John Sheng [2003.5.31] agp tex *=*/ - /*t->bufAddr = (char *)((GLuint)vmesa->driScreen->pFB + t->texMem.offset);*/ - - if (t == vmesa->CurrentTexObj[0]) - VIA_FLUSH_DMA(vmesa); - - if (t == vmesa->CurrentTexObj[1]) - VIA_FLUSH_DMA(vmesa); - - viaUpdateTexLRU(vmesa, t); - - j++; - } - - numLevels = t->lastLevel - t->firstLevel + 1; - - for (i = 0; i < numLevels; i++) - if (t->dirtyImages & (1 << i)) - viaUploadTexLevel(t, i); - - t->dirtyImages = 0; - vmesa->clearTexCache = 1; - - UNLOCK_HARDWARE(vmesa); - if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__); -} diff --git a/src/mesa/drivers/dri/unichrome/via_tris.c b/src/mesa/drivers/dri/unichrome/via_tris.c index 2d9bf37f039..5e697e32f7a 100644 --- a/src/mesa/drivers/dri/unichrome/via_tris.c +++ b/src/mesa/drivers/dri/unichrome/via_tris.c @@ -42,6 +42,7 @@ #include "via_state.h" #include "via_span.h" #include "via_ioctl.h" +#include "via_3d_reg.h" /*********************************************************************** * Emit primitives as inline vertices * @@ -68,7 +69,7 @@ } while (0) #endif -static void via_draw_triangle(viaContextPtr vmesa, +static void via_draw_triangle(struct via_context *vmesa, viaVertexPtr v0, viaVertexPtr v1, viaVertexPtr v2) @@ -82,7 +83,7 @@ static void via_draw_triangle(viaContextPtr vmesa, } -static void via_draw_quad(viaContextPtr vmesa, +static void via_draw_quad(struct via_context *vmesa, viaVertexPtr v0, viaVertexPtr v1, viaVertexPtr v2, @@ -99,7 +100,7 @@ static void via_draw_quad(viaContextPtr vmesa, COPY_DWORDS(vb, vertsize, v3); } -static void via_draw_line(viaContextPtr vmesa, +static void via_draw_line(struct via_context *vmesa, viaVertexPtr v0, viaVertexPtr v1) { @@ -110,7 +111,7 @@ static void via_draw_line(viaContextPtr vmesa, } -static void via_draw_point(viaContextPtr vmesa, +static void via_draw_point(struct via_context *vmesa, viaVertexPtr v0) { GLuint vertsize = vmesa->vertexSize; @@ -132,7 +133,7 @@ do { \ tmp.f[vertex_size-1] *= rhw; \ } while (0) -static void via_ptex_tri (viaContextPtr vmesa, +static void via_ptex_tri (struct via_context *vmesa, viaVertexPtr v0, viaVertexPtr v1, viaVertexPtr v2) @@ -146,7 +147,7 @@ static void via_ptex_tri (viaContextPtr vmesa, PTEX_VERTEX(tmp, vertsize, v2); COPY_DWORDS(vb, vertsize, &tmp); } -static void via_ptex_line (viaContextPtr vmesa, +static void via_ptex_line (struct via_context *vmesa, viaVertexPtr v0, viaVertexPtr v1) { @@ -158,7 +159,7 @@ static void via_ptex_line (viaContextPtr vmesa, PTEX_VERTEX(tmp, vertsize, v1); COPY_DWORDS(vb, vertsize, &tmp); } -static void via_ptex_point (viaContextPtr vmesa, +static void via_ptex_point (struct via_context *vmesa, viaVertexPtr v0) { GLuint vertsize = vmesa->hwVertexSize; @@ -312,7 +313,7 @@ do { \ #define LOCAL_VARS(n) \ - viaContextPtr vmesa = VIA_CONTEXT(ctx); \ + struct via_context *vmesa = VIA_CONTEXT(ctx); \ GLuint color[n], spec[n]; \ GLuint coloroffset = vmesa->coloroffset; \ GLuint specoffset = vmesa->specoffset; \ @@ -447,7 +448,7 @@ static void init_rast_tab(void) * primitives. */ static void -via_fallback_tri(viaContextPtr vmesa, +via_fallback_tri(struct via_context *vmesa, viaVertex *v0, viaVertex *v1, viaVertex *v2) @@ -464,7 +465,7 @@ via_fallback_tri(viaContextPtr vmesa, static void -via_fallback_line(viaContextPtr vmesa, +via_fallback_line(struct via_context *vmesa, viaVertex *v0, viaVertex *v1) { @@ -479,7 +480,7 @@ via_fallback_line(viaContextPtr vmesa, static void -via_fallback_point(viaContextPtr vmesa, +via_fallback_point(struct via_context *vmesa, viaVertex *v0) { GLcontext *ctx = vmesa->glCtx; @@ -492,7 +493,7 @@ via_fallback_point(viaContextPtr vmesa, static void viaResetLineStipple( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); vmesa->regCmdB |= HC_HLPrst_MASK; } @@ -509,7 +510,7 @@ static void viaResetLineStipple( GLcontext *ctx ) #define INIT(x) viaRasterPrimitive(ctx, x, hwPrim[x]) #undef LOCAL_VARS #define LOCAL_VARS \ - viaContextPtr vmesa = VIA_CONTEXT(ctx); \ + struct via_context *vmesa = VIA_CONTEXT(ctx); \ GLubyte *vertptr = (GLubyte *)vmesa->verts; \ const GLuint vertsize = vmesa->vertexSize; \ const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \ @@ -572,7 +573,7 @@ static void viaRenderClippedLine(GLcontext *ctx, GLuint ii, GLuint jj) static void viaFastRenderClippedPoly(GLcontext *ctx, const GLuint *elts, GLuint n) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); GLuint vertsize = vmesa->vertexSize; GLuint *vb = viaExtendPrimitive(vmesa, (n - 2) * 3 * 4 * vertsize); GLubyte *vertptr = (GLubyte *)vmesa->verts; @@ -615,7 +616,7 @@ static void viaFastRenderClippedPoly(GLcontext *ctx, const GLuint *elts, static void viaChooseRenderState(GLcontext *ctx) { TNLcontext *tnl = TNL_CONTEXT(ctx); - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); GLuint flags = ctx->_TriangleCaps; GLuint index = 0; @@ -702,7 +703,7 @@ do { \ static void viaChooseVertexState( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); GLuint index = tnl->render_inputs; GLuint regCmdB = HC_HVPMSK_X | HC_HVPMSK_Y | HC_HVPMSK_Z; @@ -723,13 +724,15 @@ static void viaChooseVertexState( GLcontext *ctx ) } /* t_context.c always includes a diffuse color */ - EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VIA_EMIT_RGBA, HC_HVPMSK_Cd ); + EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VIA_EMIT_RGBA, + HC_HVPMSK_Cd ); vmesa->specoffset = 0; if (index & (_TNL_BIT_COLOR1|_TNL_BIT_FOG)) { if ((index & _TNL_BIT_COLOR1)) { vmesa->specoffset = vmesa->coloroffset + 1; - EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VIA_EMIT_SPEC, HC_HVPMSK_Cs ); + EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VIA_EMIT_SPEC, + HC_HVPMSK_Cs ); } else EMIT_PAD( 3 ); @@ -742,13 +745,16 @@ static void viaChooseVertexState( GLcontext *ctx ) if (index & _TNL_BIT_TEX(0)) { if (vmesa->ptexHack) - EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, VIA_EMIT_PTEX0, (HC_HVPMSK_S | HC_HVPMSK_T) ); + EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, VIA_EMIT_PTEX0, + (HC_HVPMSK_S | HC_HVPMSK_T) ); else - EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_2F, VIA_EMIT_TEX0, (HC_HVPMSK_S | HC_HVPMSK_T) ); + EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_2F, VIA_EMIT_TEX0, + (HC_HVPMSK_S | HC_HVPMSK_T) ); } if (index & _TNL_BIT_TEX(1)) { - EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, VIA_EMIT_TEX1, (HC_HVPMSK_S | HC_HVPMSK_T) ); + EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, VIA_EMIT_TEX1, + (HC_HVPMSK_S | HC_HVPMSK_T) ); } if (setupIndex != vmesa->setupIndex) { @@ -806,7 +812,7 @@ static GLboolean viaCheckPTexHack( GLcontext *ctx ) static void viaRenderStart(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; @@ -852,20 +858,22 @@ void viaRasterPrimitive(GLcontext *ctx, GLenum glprim, GLenum hwprim) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); GLuint regCmdB; RING_VARS; - if (VIA_DEBUG) - fprintf(stderr, "%s: %s/%s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(glprim), + if (VIA_DEBUG & DEBUG_PRIMS) + fprintf(stderr, "%s: %s/%s\n", + __FUNCTION__, _mesa_lookup_enum_by_nr(glprim), _mesa_lookup_enum_by_nr(hwprim)); vmesa->renderPrimitive = glprim; if (hwprim != vmesa->hwPrimitive) { VIA_FINISH_PRIM(vmesa); - - viaCheckDma( vmesa, 1024 ); /* Ensure no wrapping inside this function */ + + /* Ensure no wrapping inside this function */ + viaCheckDma( vmesa, 1024 ); if (vmesa->newEmitState) { viaEmitState(vmesa); @@ -882,10 +890,12 @@ void viaRasterPrimitive(GLcontext *ctx, switch (hwprim) { case GL_POINTS: vmesa->regCmdA_End |= HC_HPMType_Point | HC_HVCycle_Full; - vmesa->regCmdA_End |= HC_HShading_Gouraud; /* always Gouraud shade points?!? */ + vmesa->regCmdA_End |= HC_HShading_Gouraud; /* always Gouraud + shade points?!? */ break; case GL_LINES: vmesa->regCmdA_End |= HC_HPMType_Line | HC_HVCycle_Full; + regCmdB |= HC_HLPrst_MASK; if (ctx->Light.ShadeModel == GL_FLAT) vmesa->regCmdA_End |= HC_HShading_FlatB; break; @@ -937,7 +947,8 @@ void viaRasterPrimitive(GLcontext *ctx, /* assert((vmesa->dmaLow & 0x4) == 0); */ if (vmesa->dmaCliprectAddr == ~0) { - if (VIA_DEBUG) fprintf(stderr, "reserve cliprect space at %x\n", vmesa->dmaLow); + if (VIA_DEBUG & DEBUG_DMA) + fprintf(stderr, "reserve cliprect space at %x\n", vmesa->dmaLow); vmesa->dmaCliprectAddr = vmesa->dmaLow; BEGIN_RING(8); OUT_RING( HC_HEADER2 ); @@ -981,16 +992,17 @@ static void viaRenderPrimitive( GLcontext *ctx, GLuint prim ) } -void viaFinishPrimitive(viaContextPtr vmesa) +void viaFinishPrimitive(struct via_context *vmesa) { - if (VIA_DEBUG) + if (VIA_DEBUG & (DEBUG_DMA|DEBUG_PRIMS)) fprintf(stderr, "%s\n", __FUNCTION__); if (!vmesa->dmaLastPrim || vmesa->dmaCliprectAddr == ~0) { assert(0); } else if (vmesa->dmaLow != vmesa->dmaLastPrim) { - GLuint cmdA = vmesa->regCmdA_End | HC_HPLEND_MASK | HC_HPMValidN_MASK | HC_HE3Fire_MASK; + GLuint cmdA = (vmesa->regCmdA_End | HC_HPLEND_MASK | + HC_HPMValidN_MASK | HC_HE3Fire_MASK); RING_VARS; vmesa->dmaLastPrim = 0; @@ -1013,7 +1025,7 @@ void viaFinishPrimitive(viaContextPtr vmesa) viaFlushDma( vmesa ); } else { - if (VIA_DEBUG) + if (VIA_DEBUG & (DEBUG_DMA|DEBUG_PRIMS)) fprintf(stderr, "remove empty primitive\n"); /* Remove the primitive header: @@ -1040,19 +1052,20 @@ void viaFinishPrimitive(viaContextPtr vmesa) /**********************************************************************/ -void viaFallback(viaContextPtr vmesa, GLuint bit, GLboolean mode) +void viaFallback(struct via_context *vmesa, GLuint bit, GLboolean mode) { GLcontext *ctx = vmesa->glCtx; TNLcontext *tnl = TNL_CONTEXT(ctx); GLuint oldfallback = vmesa->Fallback; - if (VIA_DEBUG) fprintf(stderr, "%s old %x bit %x mode %d\n", __FUNCTION__, - vmesa->Fallback, bit, mode); if (mode) { vmesa->Fallback |= bit; if (oldfallback == 0) { VIA_FLUSH_DMA(vmesa); - if (0) fprintf(stderr, "ENTER FALLBACK %x\n", bit); + + if (VIA_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, "ENTER FALLBACK %x\n", bit); + _swsetup_Wakeup(ctx); vmesa->renderIndex = ~0; } @@ -1062,7 +1075,8 @@ void viaFallback(viaContextPtr vmesa, GLuint bit, GLboolean mode) if (oldfallback == bit) { _swrast_flush( ctx ); - if (0) fprintf(stderr, "LEAVE FALLBACK %x\n", bit); + if (VIA_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, "LEAVE FALLBACK %x\n", bit); tnl->Driver.Render.Start = viaRenderStart; tnl->Driver.Render.PrimitiveNotify = viaRenderPrimitive; @@ -1087,7 +1101,7 @@ void viaFallback(viaContextPtr vmesa, GLuint bit, GLboolean mode) static void viaRunPipeline( GLcontext *ctx ) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); if (vmesa->newState) { vmesa->newRenderState |= vmesa->newState; @@ -1105,7 +1119,7 @@ static void viaRunPipeline( GLcontext *ctx ) void viaInitTriFuncs(GLcontext *ctx) { - viaContextPtr vmesa = VIA_CONTEXT(ctx); + struct via_context *vmesa = VIA_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); static int firsttime = 1; |