⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r128_ioctl.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_ioctl.c,v 1.10 2002/12/16 16:18:53 dawes Exp $ *//**************************************************************************Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,                                               Cedar Park, Texas.All Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationon the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whomthe Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice (including the nextparagraph) shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALLATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THEUSE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * Authors: *   Gareth Hughes <gareth@valinux.com> * */#include <errno.h>#define STANDALONE_MMIO#include "r128_context.h"#include "r128_state.h"#include "r128_ioctl.h"#include "imports.h"#include "macros.h"#include "swrast/swrast.h"#include "vblank.h"#include "mmio.h"#include "drirenderbuffer.h"#define R128_TIMEOUT        2048#define R128_IDLE_RETRY       32/* ============================================================= * Hardware vertex buffer handling *//* Get a new VB from the pool of vertex buffers in AGP space. */drmBufPtr r128GetBufferLocked( r128ContextPtr rmesa ){   int fd = rmesa->r128Screen->driScreen->fd;   int index = 0;   int size = 0;   drmDMAReq dma;   drmBufPtr buf = NULL;   int to = 0;   int ret;   dma.context = rmesa->hHWContext;   dma.send_count = 0;   dma.send_list = NULL;   dma.send_sizes = NULL;   dma.flags = 0;   dma.request_count = 1;   dma.request_size = R128_BUFFER_SIZE;   dma.request_list = &index;   dma.request_sizes = &size;   dma.granted_count = 0;   while ( !buf && ( to++ < R128_TIMEOUT ) ) {      ret = drmDMA( fd, &dma );      if ( ret == 0 ) {	 buf = &rmesa->r128Screen->buffers->list[index];	 buf->used = 0;#if ENABLE_PERF_BOXES	 /* Bump the performance counter */	 rmesa->c_vertexBuffers++;#endif	 return buf;      }   }   if ( !buf ) {      drmCommandNone( fd, DRM_R128_CCE_RESET);      UNLOCK_HARDWARE( rmesa );      fprintf( stderr, "Error: Could not get new VB... exiting\n" );      exit( -1 );   }   return buf;}void r128FlushVerticesLocked( r128ContextPtr rmesa ){   drm_clip_rect_t *pbox = rmesa->pClipRects;   int nbox = rmesa->numClipRects;   drmBufPtr buffer = rmesa->vert_buf;   int count = rmesa->num_verts;   int prim = rmesa->hw_primitive;   int fd = rmesa->driScreen->fd;   drm_r128_vertex_t vertex;   int i;   rmesa->num_verts = 0;   rmesa->vert_buf = NULL;   if ( !buffer )      return;   if ( rmesa->dirty & ~R128_UPLOAD_CLIPRECTS )      r128EmitHwStateLocked( rmesa );   if ( !nbox )      count = 0;   if ( nbox >= R128_NR_SAREA_CLIPRECTS )      rmesa->dirty |= R128_UPLOAD_CLIPRECTS;   if ( !count || !(rmesa->dirty & R128_UPLOAD_CLIPRECTS) )   {      if ( nbox < 3 ) {	 rmesa->sarea->nbox = 0;      } else {	 rmesa->sarea->nbox = nbox;      }      vertex.prim = prim;      vertex.idx = buffer->idx;      vertex.count = count;      vertex.discard = 1;      drmCommandWrite( fd, DRM_R128_VERTEX, &vertex, sizeof(vertex) );   }   else   {      for ( i = 0 ; i < nbox ; ) {	 int nr = MIN2( i + R128_NR_SAREA_CLIPRECTS, nbox );	 drm_clip_rect_t *b = rmesa->sarea->boxes;	 int discard = 0;	 rmesa->sarea->nbox = nr - i;	 for ( ; i < nr ; i++ ) {	    *b++ = pbox[i];	 }	 /* Finished with the buffer?	  */	 if ( nr == nbox ) {	    discard = 1;	 }	 rmesa->sarea->dirty |= R128_UPLOAD_CLIPRECTS;         vertex.prim = prim;         vertex.idx = buffer->idx;         vertex.count = count;         vertex.discard = discard;         drmCommandWrite( fd, DRM_R128_VERTEX, &vertex, sizeof(vertex) );      }   }   rmesa->dirty &= ~R128_UPLOAD_CLIPRECTS;}/* ================================================================ * Texture uploads */void r128FireBlitLocked( r128ContextPtr rmesa, drmBufPtr buffer,			 GLint offset, GLint pitch, GLint format,			 GLint x, GLint y, GLint width, GLint height ){   drm_r128_blit_t blit;   GLint ret;   blit.idx = buffer->idx;   blit.offset = offset;   blit.pitch = pitch;   blit.format = format;   blit.x = x;   blit.y = y;   blit.width = width;   blit.height = height;   ret = drmCommandWrite( rmesa->driFd, DRM_R128_BLIT,                           &blit, sizeof(blit) );   if ( ret ) {      UNLOCK_HARDWARE( rmesa );      fprintf( stderr, "DRM_R128_BLIT: return = %d\n", ret );      exit( 1 );   }}/* ================================================================ * SwapBuffers with client-side throttling */static void delay( void ) {/* Prevent an optimizing compiler from removing a spin loop */}#define R128_MAX_OUTSTANDING	2/* Throttle the frame rate -- only allow one pending swap buffers * request at a time. * GH: We probably don't want a timeout here, as we can wait as * long as we want for a frame to complete.  If it never does, then * the card has locked. */static int r128WaitForFrameCompletion( r128ContextPtr rmesa ){   unsigned char *R128MMIO = rmesa->r128Screen->mmio.map;   int i;   int wait = 0;   while ( 1 ) {      u_int32_t frame = read_MMIO_LE32( R128MMIO, R128_LAST_FRAME_REG );      if ( rmesa->sarea->last_frame - frame <= R128_MAX_OUTSTANDING ) {	 break;      }      /* Spin in place a bit so we aren't hammering the register */      wait++;      for ( i = 0 ; i < 1024 ; i++ ) {	 delay();      }   }   return wait;}/* Copy the back color buffer to the front color buffer. */void r128CopyBuffer( __DRIdrawablePrivate *dPriv ){   r128ContextPtr rmesa;   GLint nbox, i, ret;   GLboolean missed_target;   assert(dPriv);   assert(dPriv->driContextPriv);   assert(dPriv->driContextPriv->driverPrivate);   rmesa = (r128ContextPtr) dPriv->driContextPriv->driverPrivate;   if ( R128_DEBUG & DEBUG_VERBOSE_API ) {      fprintf( stderr, "\n********************************\n" );      fprintf( stderr, "\n%s( %p )\n\n",	       __FUNCTION__, (void *)rmesa->glCtx );      fflush( stderr );   }   FLUSH_BATCH( rmesa );   LOCK_HARDWARE( rmesa );   /* Throttle the frame rate -- only allow one pending swap buffers    * request at a time.    */   if ( !r128WaitForFrameCompletion( rmesa ) ) {      rmesa->hardwareWentIdle = 1;   } else {      rmesa->hardwareWentIdle = 0;   }   UNLOCK_HARDWARE( rmesa );   driWaitForVBlank( dPriv, &missed_target );   LOCK_HARDWARE( rmesa );   nbox = dPriv->numClipRects;	/* must be in locked region */   for ( i = 0 ; i < nbox ; ) {      GLint nr = MIN2( i + R128_NR_SAREA_CLIPRECTS , nbox );      drm_clip_rect_t *box = dPriv->pClipRects;      drm_clip_rect_t *b = rmesa->sarea->boxes;      GLint n = 0;      for ( ; i < nr ; i++ ) {	 *b++ = box[i];	 n++;      }      rmesa->sarea->nbox = n;      ret = drmCommandNone( rmesa->driFd, DRM_R128_SWAP );      if ( ret ) {	 UNLOCK_HARDWARE( rmesa );	 fprintf( stderr, "DRM_R128_SWAP: return = %d\n", ret );	 exit( 1 );      }   }   if ( R128_DEBUG & DEBUG_ALWAYS_SYNC ) {      i = 0;      do {         ret = drmCommandNone(rmesa->driFd, DRM_R128_CCE_IDLE);      } while ( ret && errno == EBUSY && i++ < R128_IDLE_RETRY );   }   UNLOCK_HARDWARE( rmesa );   rmesa->new_state |= R128_NEW_CONTEXT;   rmesa->dirty |= (R128_UPLOAD_CONTEXT |		    R128_UPLOAD_MASKS |		    R128_UPLOAD_CLIPRECTS);#if ENABLE_PERF_BOXES   /* Log the performance counters if necessary */   r128PerformanceCounters( rmesa );#endif}void r128PageFlip( __DRIdrawablePrivate *dPriv ){   r128ContextPtr rmesa;   GLint ret;   GLboolean missed_target;   assert(dPriv);   assert(dPriv->driContextPriv);   assert(dPriv->driContextPriv->driverPrivate);   rmesa = (r128ContextPtr) dPriv->driContextPriv->driverPrivate;   if ( R128_DEBUG & DEBUG_VERBOSE_API ) {      fprintf( stderr, "\n%s( %p ): page=%d\n\n",	       __FUNCTION__, (void *)rmesa->glCtx, rmesa->sarea->pfCurrentPage );   }   FLUSH_BATCH( rmesa );   LOCK_HARDWARE( rmesa );   /* Throttle the frame rate -- only allow one pending swap buffers    * request at a time.    */   if ( !r128WaitForFrameCompletion( rmesa ) ) {      rmesa->hardwareWentIdle = 1;   } else {      rmesa->hardwareWentIdle = 0;   }   UNLOCK_HARDWARE( rmesa );   driWaitForVBlank( dPriv, &missed_target );   LOCK_HARDWARE( rmesa );   /* The kernel will have been initialized to perform page flipping    * on a swapbuffers ioctl.    */   ret = drmCommandNone( rmesa->driFd, DRM_R128_FLIP );   UNLOCK_HARDWARE( rmesa );   if ( ret ) {      fprintf( stderr, "DRM_R128_FLIP: return = %d\n", ret );      exit( 1 );   }   /* Get ready for drawing next frame.  Update the renderbuffers'    * flippedOffset/Pitch fields so we draw into the right place.    */   driFlipRenderbuffers(rmesa->glCtx->WinSysDrawBuffer,                        rmesa->sarea->pfCurrentPage);   rmesa->new_state |= R128_NEW_WINDOW;   /* FIXME: Do we need this anymore? */   rmesa->new_state |= R128_NEW_CONTEXT;   rmesa->dirty |= (R128_UPLOAD_CONTEXT |		    R128_UPLOAD_MASKS |		    R128_UPLOAD_CLIPRECTS);#if ENABLE_PERF_BOXES   /* Log the performance counters if necessary */   r128PerformanceCounters( rmesa );#endif}/* ================================================================ * Buffer clear */static void r128Clear( GLcontext *ctx, GLbitfield mask ){   r128ContextPtr rmesa = R128_CONTEXT(ctx);   __DRIdrawablePrivate *dPriv = rmesa->driDrawable;   drm_r128_clear_t clear;   GLuint flags = 0;   GLint i;   GLint ret;   GLuint depthmask = 0;   GLint cx, cy, cw, ch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -