From 471acec6c97ca20ab1bb932becd5aa754c9bae77 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 3 Jan 2013 14:31:25 +0100 Subject: [PATCH] (RGL) Cleanups --- console/rgl/include/RGL/Utils.h | 15 +- console/rgl/include/RGL/private.h | 66 ++------ console/rgl/src/Utils/NameSpace.cpp | 56 ++++--- console/rgl/src/ps3/include/GmmAlloc.h | 43 ++--- console/rgl/src/ps3/include/rgl-externs.h | 54 +++---- console/rgl/src/ps3/include/rgl-inline.h | 19 +-- console/rgl/src/ps3/rgl_ps3.cpp | 76 ++++----- console/rgl/src/ps3/rgl_ps3_raster.cpp | 187 ++++++++++++---------- console/rgl/src/rgl.cpp | 66 +++++--- 9 files changed, 272 insertions(+), 310 deletions(-) diff --git a/console/rgl/include/RGL/Utils.h b/console/rgl/include/RGL/Utils.h index 53aaab5220..e8a30f1eca 100644 --- a/console/rgl/include/RGL/Utils.h +++ b/console/rgl/include/RGL/Utils.h @@ -6,8 +6,7 @@ #include "platform.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif #ifndef MSVC @@ -87,11 +86,11 @@ extern "C" // names API - RGL_EXPORT void rglInitNameSpace( struct rglNameSpace * name ); - RGL_EXPORT void rglFreeNameSpace( struct rglNameSpace * name ); - RGL_EXPORT unsigned int rglCreateName( struct rglNameSpace * ns, void* object ); - RGL_EXPORT unsigned int rglIsName( struct rglNameSpace* ns, unsigned int name ); - RGL_EXPORT void rglEraseName( struct rglNameSpace* ns, unsigned int name ); + RGL_EXPORT void rglInitNameSpace (void *data); + RGL_EXPORT void rglFreeNameSpace (void *data); + RGL_EXPORT unsigned int rglCreateName (void *data, void* object); + RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name); + RGL_EXPORT void rglEraseName (void *data, unsigned int name); static inline void * rglGetNamedValue( struct rglNameSpace* ns, unsigned int name ) { return ns->data[name - 1]; @@ -109,7 +108,7 @@ extern "C" #ifdef __cplusplus -} // Close scope of 'extern "C"' declaration that encloses file. +} #endif #ifndef RGLT_UNUSED diff --git a/console/rgl/include/RGL/private.h b/console/rgl/include/RGL/private.h index 77abc8e17c..8fb602d194 100644 --- a/console/rgl/include/RGL/private.h +++ b/console/rgl/include/RGL/private.h @@ -56,7 +56,7 @@ extern "C" extern GLuint rglValidateStates( GLuint mask ); void rglAttachContext( RGLdevice *device, RGLcontext* context ); void rglDetachContext( RGLdevice *device, RGLcontext* context ); - void rglInvalidateAllStates( RGLcontext* context ); + void rglInvalidateAllStates (void *data); void rglResetAttributeState( rglAttributeState* as ); void rglSetFlipHandler(void (*handler)(const GLuint head), RGLdevice *device); void rglSetVBlankHandler(void (*handler)(const GLuint head), RGLdevice *device); @@ -64,8 +64,8 @@ extern "C" //---------------------------------------- // Texture.c //---------------------------------------- - rglTexture *rglAllocateTexture(); - void rglFreeTexture( rglTexture *texture ); + rglTexture *rglAllocateTexture (void); + void rglFreeTexture (void *data); void rglTextureUnbind( RGLcontext* context, GLuint name ); extern int rglTextureInit( RGLcontext* context, GLuint name ); extern void rglTextureDelete( RGLcontext* context, GLuint name ); @@ -111,8 +111,8 @@ extern "C" GLboolean rglIsType( GLenum type ); GLboolean rglIsFormat( GLenum format ); GLboolean rglIsValidPair( GLenum format, GLenum type ); - void rglImageAllocCPUStorage( rglImage *image ); - void rglImageFreeCPUStorage( rglImage *image ); + void rglImageAllocCPUStorage (void *data); + void rglImageFreeCPUStorage (void *data); extern void rglSetImage( rglImage* image, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const GLvoid* pixels ); extern void rglSetSubImage( GLenum target, GLint level, rglTexture *texture, rglImage* image, GLint x, GLint y, GLint z, GLsizei width, GLsizei height, GLsizei depth, GLsizei alignment, GLenum format, GLenum type, const GLvoid* pixels ); extern int rglGetPixelSize( GLenum format, GLenum type ); @@ -126,7 +126,7 @@ extern "C" extern int rglGetStorageSize( GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth ); extern void rglImageToRaster( const rglImage* image, rglRaster* raster, GLuint x, GLuint y, GLuint z ); extern void rglRasterToImage( const rglRaster* raster, rglImage* image, GLuint x, GLuint y, GLuint z ); - extern void rglRawRasterToImage( const rglRaster* raster, rglImage* image, GLuint x, GLuint y, GLuint z ); + extern void rglRawRasterToImage (const void *in_data, void *out_data, GLuint x, GLuint y, GLuint z); void rglResampleImage3D( rglImage* src, rglImage* dst ); //---------------------------------------- @@ -210,9 +210,9 @@ extern "C" //---------------------------------------- // Raster/.../PlatformRaster.c //---------------------------------------- - void* rglPlatformRasterInit(); - void rglPlatformRasterExit( void* driver ); - void rglPlatformRasterDestroyResources(); + void* rglPlatformRasterInit (void); + void rglPlatformRasterExit (void* driver); + void rglPlatformRasterDestroyResources (void); void rglPlatformDraw( rglDrawParams* dparams ); GLboolean rglPlatformNeedsConversion( const rglAttributeState* as, GLuint index ); // [YLIN] Try to avoid LHS inside this function. @@ -232,51 +232,19 @@ extern "C" //---------------------------------------- // Raster/.../PlatformTexture.c //---------------------------------------- - extern int rglPlatformTextureSize(); - extern int rglPlatformTextureMaxUnits(); + extern int rglPlatformTextureSize (void); + extern int rglPlatformTextureMaxUnits (void); extern void rglPlatformCreateTexture( rglTexture* texture ); extern void rglPlatformDestroyTexture( rglTexture* texture ); - extern void rglPlatformValidateTextureStage( int unit, rglTexture*texture ); - void rglPlatformValidateVertexTextures(); - extern GLenum rglPlatformChooseInternalStorage( rglImage* image, GLenum internalformat ); + extern void rglPlatformValidateTextureStage (int unit, void *data); + void rglPlatformValidateVertexTextures (void); + extern GLenum rglPlatformChooseInternalStorage (void *data, GLenum internalformat); extern GLenum rglPlatformTranslateTextureFormat( GLenum internalFormat ); extern void rglPlatformCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); GLenum rglPlatformChooseInternalFormat( GLenum internalformat ); void rglPlatformExpandInternalFormat( GLenum internalformat, GLenum *format, GLenum *type ); void rglPlatformGetImageData( GLenum target, GLint level, rglTexture *texture, rglImage *image ); - extern void rglPlatformSetCompressedTexture( - GLenum target, - GLint level, - GLenum internalformat, - GLsizei width, GLsizei height, GLsizei depth, - GLint border, - GLsizei imageSize, - const GLvoid* data ); - extern void rglPlatformSetCompressedTextureSub( - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, - GLsizei imageSize, - const GLvoid* data ); - extern GLboolean rglPlatformTexturePBOImage( - rglTexture* texture, - rglImage* image, - GLint level, - GLint internalformat, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - const GLvoid *offset ); - extern GLboolean rglPlatformTexturePBOSubImage( - rglTexture* texture, - rglImage* image, - GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - const GLvoid *pixels ); - GLboolean rglPlatformTextureReference( rglTexture *texture, GLuint pitch, rglBufferObject *bufferObject, GLintptr offset ); + GLboolean rglPlatformTextureReference (void *data, GLuint pitch, rglBufferObject *bufferObject, GLintptr offset); //---------------------------------------- // Raster/.../PlatformFBops.c @@ -302,14 +270,14 @@ extern "C" GLboolean rglPlatformCreateBufferObject( rglBufferObject* bufferObject ); void rglPlatformDestroyBufferObject( rglBufferObject* bufferObject ); void rglPlatformBufferObjectSetData( rglBufferObject* bufferObject, GLintptr offset, GLsizeiptr size, const GLvoid *data, GLboolean tryImmediateCopy ); - GLvoid rglPlatformBufferObjectCopyData( rglBufferObject* bufferObjectDst, rglBufferObject* bufferObjectSrc ); + GLvoid rglPlatformBufferObjectCopyData (void *dst, void *src); // map / unmap buffers. Internally refcounted char *rglPlatformBufferObjectMap( rglBufferObject* bufferObject, GLenum access ); GLboolean rglPlatformBufferObjectUnmap( rglBufferObject* bufferObject ); void rglPlatformGetBufferParameteriv( rglBufferObject *bufferObject, GLenum pname, int *params ); // this is shared in glBindTexture and cgGL code - RGL_EXPORT void rglBindTextureInternal( rglTextureImageUnit *unit, GLuint name, GLenum target ); + RGL_EXPORT void rglBindTextureInternal (void *data, GLuint name, GLenum target); void rglBindVertexTextureInternal( GLuint unit, GLuint name ); //---------------------------------------- diff --git a/console/rgl/src/Utils/NameSpace.cpp b/console/rgl/src/Utils/NameSpace.cpp index d7e6e1b34b..1c8f435438 100644 --- a/console/rgl/src/Utils/NameSpace.cpp +++ b/console/rgl/src/Utils/NameSpace.cpp @@ -5,31 +5,36 @@ #include -void rglInitNameSpace( rglNameSpace * name ) +void rglInitNameSpace(void *data) { + rglNameSpace *name = (rglNameSpace*)data; name->data = NULL; name->firstFree = NULL; name->capacity = 0; } -void rglFreeNameSpace( rglNameSpace * ns ) +void rglFreeNameSpace(void *data) { - // XXX should we verify all names were freed ? + rglNameSpace *name = (rglNameSpace*)data; - if ( ns->data ) { free( ns->data ); }; - ns->data = NULL; - ns->capacity = 0; - ns->firstFree = NULL; + if (name->data) + free(name->data); + + name->data = NULL; + name->capacity = 0; + name->firstFree = NULL; } static const int NAME_INCREMENT = 4; -unsigned int rglCreateName( rglNameSpace * ns, void* object ) + +unsigned int rglCreateName(void *data, void* object) { + rglNameSpace *name = (rglNameSpace*)data; // NULL is reserved for the guard of the linked list. - if (ns->firstFree == NULL) + if (name->firstFree == NULL) { // need to allocate more pointer space - int newCapacity = ns->capacity + NAME_INCREMENT; + int newCapacity = name->capacity + NAME_INCREMENT; // realloc the block of pointers void** newData = ( void** )malloc( newCapacity * sizeof( void* ) ); @@ -39,37 +44,41 @@ unsigned int rglCreateName( rglNameSpace * ns, void* object ) rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); return 0; } - memcpy( newData, ns->data, ns->capacity * sizeof( void* ) ); - if ( ns->data != NULL ) free( ns->data ); - ns->data = newData; + memcpy( newData, name->data, name->capacity * sizeof( void* ) ); + + if (name->data != NULL) + free (name->data); + + name->data = newData; // initialize the pointers to the next free elements. // (effectively build a linked list of free elements in place) // treat the last item differently, by linking it to NULL - for ( int index = ns->capacity; index < newCapacity - 1; ++index ) - ns->data[index] = ns->data + index + 1; + for ( int index = name->capacity; index < newCapacity - 1; ++index ) + name->data[index] = name->data + index + 1; - ns->data[newCapacity - 1] = NULL; + name->data[newCapacity - 1] = NULL; // update the first free element to the new data pointer. - ns->firstFree = ns->data + ns->capacity; + name->firstFree = name->data + name->capacity; // update the new capacity. - ns->capacity = newCapacity; + name->capacity = newCapacity; } // firstFree is a pointer, compute the index of it - unsigned int result = ns->firstFree - ns->data; + unsigned int result = name->firstFree - name->data; // update the first free to the next free element. - ns->firstFree = ( void** ) * ns->firstFree; + name->firstFree = (void**)*name->firstFree; // store the object in data. - ns->data[result] = object; + name->data[result] = object; // offset the index by 1 to avoid the name 0 return result + 1; } -unsigned int rglIsName( rglNameSpace* ns, unsigned int name ) +unsigned int rglIsName (void *data, unsigned int name ) { + rglNameSpace *ns = (rglNameSpace*)data; // there should always be a namesepace // 0 is never valid. if (RGL_UNLIKELY(name == 0)) @@ -95,8 +104,9 @@ unsigned int rglIsName( rglNameSpace* ns, unsigned int name ) return 1; } -void rglEraseName( rglNameSpace* ns, unsigned int name ) +void rglEraseName(void *data, unsigned int name ) { + rglNameSpace *ns = (rglNameSpace*)data; if (rglIsName(ns, name)) { --name; diff --git a/console/rgl/src/ps3/include/GmmAlloc.h b/console/rgl/src/ps3/include/GmmAlloc.h index 84dc4f5c06..fc091a22ff 100644 --- a/console/rgl/src/ps3/include/GmmAlloc.h +++ b/console/rgl/src/ps3/include/GmmAlloc.h @@ -116,15 +116,9 @@ uint32_t gmmInit( const uint32_t mainSize ); -uint32_t gmmDestroy(); - -uint32_t gmmIdToOffset( - const uint32_t id - ); - -char *gmmIdToAddress( - const uint32_t id - ); +uint32_t gmmDestroy(void); +uint32_t gmmIdToOffset(const uint32_t id); +char *gmmIdToAddress(const uint32_t id); uint32_t gmmFPOffsetToId( const uint32_t offset, @@ -132,21 +126,10 @@ uint32_t gmmFPOffsetToId( bool bLocalMemory ); -void gmmPinId( - const uint32_t id - ); - -void gmmUnpinId( - const uint32_t id - ); - -uint32_t gmmFree( - const uint32_t freeId - ); - -void gmmUpdateFreeList( - const uint8_t location - ); +void gmmPinId (const uint32_t id); +void gmmUnpinId (const uint32_t id); +uint32_t gmmFree (const uint32_t freeId); +void gmmUpdateFreeList (const uint8_t location); uint32_t gmmAlloc( void *data, @@ -161,9 +144,7 @@ uint32_t gmmAllocExtendedTileBlock( const uint32_t tag ); -uint32_t gmmGetBlockSize( - const uint32_t id - ); +uint32_t gmmGetBlockSize (const uint32_t id); void gmmSetTileAttrib( const uint32_t id, @@ -171,13 +152,13 @@ void gmmSetTileAttrib( void *pData ); -void *gmmGetTileData(const uint32_t id); +void *gmmGetTileData (const uint32_t id); -void gmmPinAllocations(void); +void gmmPinAllocations (void); -void gmmUnpinAllocations(void); +void gmmUnpinAllocations (void); -static inline uint8_t gmmIdIsMain(const uint32_t id) +static inline uint8_t gmmIdIsMain (const uint32_t id) { return false; } diff --git a/console/rgl/src/ps3/include/rgl-externs.h b/console/rgl/src/ps3/include/rgl-externs.h index 1b9cc1ee5a..c5c9809c58 100644 --- a/console/rgl/src/ps3/include/rgl-externs.h +++ b/console/rgl/src/ps3/include/rgl-externs.h @@ -1,41 +1,29 @@ -void rglGcmFifoFinish(rglGcmFifo *fifo); -GLboolean rglGcmFifoReferenceInUse( rglGcmFifo *fifo, GLuint reference ); -GLuint rglGcmFifoPutReference( rglGcmFifo *fifo ); -void rglGcmFifoFlush( rglGcmFifo *fifo ); -uint32_t * rglGcmFifoWaitForFreeSpace( rglGcmFifo *fifo, GLuint spaceInWords ); -void rglGcmGetTileRegionInfo( void* data, GLuint *address, GLuint *size ); +void rglGcmFifoFinish (rglGcmFifo *fifo); +GLboolean rglGcmFifoReferenceInUse (rglGcmFifo *fifo, GLuint reference); +GLuint rglGcmFifoPutReference (rglGcmFifo *fifo); +void rglGcmFifoFlush (rglGcmFifo *fifo); +uint32_t * rglGcmFifoWaitForFreeSpace (rglGcmFifo *fifo, GLuint spaceInWords); +void rglGcmGetTileRegionInfo (void* data, GLuint *address, GLuint *size); GLboolean rglGcmTryResizeTileRegion( GLuint address, GLuint size, void* data ); -void rglGcmTransferData -( - GLuint dstId, - GLuint dstIdOffset, - GLint dstPitch, - GLuint srcId, - GLuint srcIdOffset, - GLint srcPitch, - GLint bytesPerRow, - GLint rowCount - ); +void rglGcmTransferData (GLuint dstId, GLuint dstIdOffset, + GLint dstPitch, GLuint srcId, GLuint srcIdOffset, + GLint srcPitch, GLint bytesPerRow, GLint rowCount); -int32_t rglOutOfSpaceCallback( struct CellGcmContextData* fifoContext, uint32_t spaceInWords ); -void rglGcmFifoGlSetRenderTarget( rglGcmRenderTargetEx const * const args ); -void rglpFifoGlFinish( void ); -void rglCreatePushBuffer( _CGprogram *program ); +int32_t rglOutOfSpaceCallback (struct CellGcmContextData* fifoContext, uint32_t spaceInWords); +void rglGcmFifoGlSetRenderTarget (rglGcmRenderTargetEx const * const args); +void rglpFifoGlFinish (void); +void rglCreatePushBuffer (void *data); void rglSetDefaultValuesFP( _CGprogram *program ); void rglSetDefaultValuesVP( _CGprogram *program ); void rglGcmSend( unsigned int dstId, unsigned dstOffset, unsigned int pitch, const char *src, unsigned int size ); void rglGcmMemcpy( const GLuint dstId, unsigned dstOffset, unsigned int pitch, const GLuint srcId, GLuint srcOffset, unsigned int size ); -void rglPlatformValidateTextureResources( rglTexture *texture ); -GLuint rglGetGcmImageOffset( rglGcmTextureLayout *layout, GLuint face, GLuint level ); -void rglSetNativeCgFragmentProgram( const GLvoid *header ); -void rglGcmFreeTiledSurface( GLuint bufferId ); +void rglPlatformValidateTextureResources (void *data); +GLuint rglGetGcmImageOffset (rglGcmTextureLayout *layout, GLuint face, GLuint level ); +void rglSetNativeCgFragmentProgram(const void *data); +void rglGcmFreeTiledSurface (GLuint bufferId); -void rglGcmCopySurface( - const rglGcmSurface* src, - GLuint srcX, GLuint srcY, - const rglGcmSurface* dst, - GLuint dstX, GLuint dstY, - GLuint width, GLuint height, - GLboolean writeSync); -void rglSetNativeCgVertexProgram( const void *header ); +void rglGcmCopySurface(const void *data, GLuint srcX, GLuint srcY, + const void *data_dst, GLuint dstX, GLuint dstY, + GLuint width, GLuint height, GLboolean writeSync); +void rglSetNativeCgVertexProgram (const void *data); diff --git a/console/rgl/src/ps3/include/rgl-inline.h b/console/rgl/src/ps3/include/rgl-inline.h index 523f766106..3f44e596f9 100644 --- a/console/rgl/src/ps3/include/rgl-inline.h +++ b/console/rgl/src/ps3/include/rgl-inline.h @@ -553,21 +553,14 @@ static inline void rglGcmFifoGlFinishFenceRef( const GLuint ref ) rglGcmFifo *fifo = &rglGcmState_i.fifo; // wait for completion - for ( ;; ) - { - // gpu passed reference ? - if ( !rglGcmFifoReferenceInUse( fifo, ref ) ) - break; - - // avoid polling on bus (interrupts memory traffic) + while (rglGcmFifoReferenceInUse(fifo, ref)) sys_timer_usleep(10); - } } #define RGLGCM_UTIL_LABEL_INDEX 253 // Utility to let RSX wait for complete RSX pipeline idle -static inline void rglGcmUtilWaitForIdle() +static inline void rglGcmUtilWaitForIdle (void) { // set write label command in push buffer, and wait // NOTE: this is for RSX to wailt @@ -686,7 +679,7 @@ static inline void rglGcmFifoGlBlendFunc( rglGcmEnum sf, rglGcmEnum df, rglGcmEn // Can be used for printing out macro and constant values. // example: rglPrintIt( RGLGCM_3DCONST(SET_SURFACE_FORMAT, COLOR, LE_A8R8G8B8) ); // 00 00 00 08 : 00000000 00000000 00000000 00001000 */ -void static inline rglPrintIt( unsigned int v ) +void static inline rglPrintIt (unsigned int v ) { // HEX (space between bytes) printf( "%02x %02x %02x %02x : ", ( v >> 24 )&0xff, ( v >> 16 )&0xff, ( v >> 8 )&0xff, v&0xff ); @@ -925,9 +918,11 @@ static inline void rglGcmFifoGlDisable( rglGcmEnum cap ) } } -static inline void rglFifoGlProgramParameterfvVP( const _CGprogram *program, const CgParameterEntry *parameterEntry, const GLfloat *value ) +static inline void rglFifoGlProgramParameterfvVP (const void *data, const CgParameterEntry *parameterEntry, const GLfloat *value) { + const _CGprogram *program = (const _CGprogram*)data; const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); + if ( parameterResource->resource != ( unsigned short ) - 1 ) { switch ( parameterResource->type ) @@ -1028,7 +1023,7 @@ static inline void rglFifoGlProgramParameterfvVP( const _CGprogram *program, con } // Look up the memory location of a buffer object (VBO, PBO) -static inline GLuint rglGcmGetBufferObjectOrigin( GLuint buffer ) +static inline GLuint rglGcmGetBufferObjectOrigin (GLuint buffer) { rglBufferObject *bufferObject = (rglBufferObject*)_CurrentContext->bufferObjectNameSpace.data[buffer]; rglGcmBufferObject *gcmBuffer = ( rglGcmBufferObject * ) & bufferObject->platformBufferObject; diff --git a/console/rgl/src/ps3/rgl_ps3.cpp b/console/rgl/src/ps3/rgl_ps3.cpp index c8cd7a238c..58f7c49907 100644 --- a/console/rgl/src/ps3/rgl_ps3.cpp +++ b/console/rgl/src/ps3/rgl_ps3.cpp @@ -384,9 +384,7 @@ uint32_t gmmIdToOffset(const uint32_t id) return offset; } -char *gmmIdToAddress( - const uint32_t id - ) +char *gmmIdToAddress (const uint32_t id) { GmmBaseBlock *pBaseBlock = (GmmBaseBlock *)id; @@ -704,8 +702,9 @@ static GmmTileBlock *gmmAllocTileBlock(GmmAllocator *pAllocator, return pBlock; } -static void gmmFreeBlock(GmmBlock *pBlock) +static void gmmFreeBlock (void *data) { + GmmBlock *pBlock = (GmmBlock*)data; GmmAllocator *pAllocator; if (pBlock->pPrev) @@ -745,7 +744,7 @@ static void gmmFreeBlock(GmmBlock *pBlock) gmmFreeFixedBlock(pBlock); } -static void gmmAddPendingFree(void *data) +static void gmmAddPendingFree (void *data) { GmmBlock *pBlock = (GmmBlock*)data; GmmAllocator *pAllocator; @@ -1224,14 +1223,10 @@ static void gmmRemovePendingFree( void gmmUpdateFreeList(const uint8_t location) { - GmmAllocator *pAllocator; const uint32_t fence = rglGcmState_i.semaphores->userSemaphores[RGLGCM_SEMA_FENCE].val; GmmBlock *pBlock = NULL; GmmBlock *pTemp = NULL; - - - pAllocator = pGmmLocalAllocator; - + GmmAllocator *pAllocator = pGmmLocalAllocator; pBlock = pAllocator->pPendingFreeHead; @@ -1251,12 +1246,9 @@ void gmmUpdateFreeList(const uint8_t location) static void gmmFreeAll(const uint8_t location) { - GmmAllocator *pAllocator; GmmBlock *pBlock; GmmBlock *pTemp; - - - pAllocator = pGmmLocalAllocator; + GmmAllocator *pAllocator = pGmmLocalAllocator; pBlock = pAllocator->pPendingFreeHead; while (pBlock) @@ -1444,31 +1436,31 @@ uint32_t gmmAlloc(void *data, const uint8_t location, FRAGMENT SHADER ============================================================ */ -void rglSetNativeCgFragmentProgram(const void *header) +void rglSetNativeCgFragmentProgram(const void *data) { - const _CGprogram *ps = (const _CGprogram *)header; + const _CGprogram *program = (const _CGprogram *)data; CellCgbFragmentProgramConfiguration conf; - conf.offset = gmmIdToOffset(ps->loadProgramId) + ps->loadProgramOffset; + conf.offset = gmmIdToOffset(program->loadProgramId) + program->loadProgramOffset; rglGcmInterpolantState *s = &rglGcmState_i.state.interpolant; - s->fragmentProgramAttribMask |= ps->header.attributeInputMask | CELL_GCM_ATTRIB_OUTPUT_MASK_POINTSIZE; + s->fragmentProgramAttribMask |= program->header.attributeInputMask | CELL_GCM_ATTRIB_OUTPUT_MASK_POINTSIZE; conf.attributeInputMask = ( s->vertexProgramAttribMask) & s->fragmentProgramAttribMask; - conf.texCoordsInputMask = ps->header.fragmentProgram.texcoordInputMask; - conf.texCoords2D = ps->header.fragmentProgram.texcoord2d; - conf.texCoordsCentroid = ps->header.fragmentProgram.texcoordCentroid; + conf.texCoordsInputMask = program->header.fragmentProgram.texcoordInputMask; + conf.texCoords2D = program->header.fragmentProgram.texcoord2d; + conf.texCoordsCentroid = program->header.fragmentProgram.texcoordCentroid; int fragmentControl = ( 1 << 15 ) | ( 1 << 10 ); - fragmentControl |= ps->header.fragmentProgram.flags & CGF_DEPTHREPLACE ? 0xE : 0x0; - fragmentControl |= ps->header.fragmentProgram.flags & CGF_OUTPUTFROMH0 ? 0x00 : 0x40; - fragmentControl |= ps->header.fragmentProgram.flags & CGF_PIXELKILL ? 0x80 : 0x00; + fragmentControl |= program->header.fragmentProgram.flags & CGF_DEPTHREPLACE ? 0xE : 0x0; + fragmentControl |= program->header.fragmentProgram.flags & CGF_OUTPUTFROMH0 ? 0x00 : 0x40; + fragmentControl |= program->header.fragmentProgram.flags & CGF_PIXELKILL ? 0x80 : 0x00; conf.fragmentControl = fragmentControl; - conf.registerCount = ps->header.fragmentProgram.registerCount < 2 ? 2 : ps->header.fragmentProgram.registerCount; + conf.registerCount = program->header.fragmentProgram.registerCount < 2 ? 2 : program->header.fragmentProgram.registerCount; uint32_t controlTxp = _CurrentContext->AllowTXPDemotion; conf.fragmentControl &= ~CELL_GCM_MASK_SET_SHADER_CONTROL_CONTROL_TXP; @@ -1476,41 +1468,41 @@ void rglSetNativeCgFragmentProgram(const void *header) GCM_FUNC( cellGcmSetFragmentProgramLoad, &conf ); - GCM_FUNC( cellGcmSetZMinMaxControl, ( ps->header.fragmentProgram.flags & CGF_DEPTHREPLACE ) ? RGLGCM_FALSE : RGLGCM_TRUE, RGLGCM_FALSE, RGLGCM_FALSE ); + GCM_FUNC( cellGcmSetZMinMaxControl, ( program->header.fragmentProgram.flags & CGF_DEPTHREPLACE ) ? RGLGCM_FALSE : RGLGCM_TRUE, RGLGCM_FALSE, RGLGCM_FALSE ); } /*============================================================ VERTEX SHADER ============================================================ */ -void rglSetNativeCgVertexProgram(const void *header) +void rglSetNativeCgVertexProgram(const void *data) { - const _CGprogram *vs = (const _CGprogram*) header; + const _CGprogram *program = (const _CGprogram*)data; - __dcbt(vs->ucode); - __dcbt(((uint8_t*)vs->ucode)+128); - __dcbt(((uint8_t*)vs->ucode)+256); - __dcbt(((uint8_t*)vs->ucode)+384); + __dcbt(program->ucode); + __dcbt(((uint8_t*)program->ucode)+128); + __dcbt(((uint8_t*)program->ucode)+256); + __dcbt(((uint8_t*)program->ucode)+384); CellCgbVertexProgramConfiguration conf; - conf.instructionSlot = vs->header.vertexProgram.instructionSlot; - conf.instructionCount = vs->header.instructionCount; - conf.registerCount = vs->header.vertexProgram.registerCount; - conf.attributeInputMask = vs->header.attributeInputMask; + conf.instructionSlot = program->header.vertexProgram.instructionSlot; + conf.instructionCount = program->header.instructionCount; + conf.registerCount = program->header.vertexProgram.registerCount; + conf.attributeInputMask = program->header.attributeInputMask; rglGcmFifoWaitForFreeSpace( &rglGcmState_i.fifo, 7 + 5 * conf.instructionCount ); - GCM_FUNC( cellGcmSetVertexProgramLoad, &conf, vs->ucode ); + GCM_FUNC( cellGcmSetVertexProgramLoad, &conf, program->ucode ); GCM_FUNC( cellGcmSetUserClipPlaneControl, 0, 0, 0, 0, 0, 0 ); rglGcmInterpolantState *s = &rglGcmState_i.state.interpolant; - s->vertexProgramAttribMask = vs->header.vertexProgram.attributeOutputMask; + s->vertexProgramAttribMask = program->header.vertexProgram.attributeOutputMask; GCM_FUNC( cellGcmSetVertexAttribOutputMask, (( s->vertexProgramAttribMask) & s->fragmentProgramAttribMask) ); - _CGprogram *program = ( _CGprogram* )vs; + program = (_CGprogram*)data; int count = program->defaultValuesIndexCount; for ( int i = 0;i < count;i++ ) { @@ -1529,13 +1521,15 @@ void rglSetNativeCgVertexProgram(const void *header) ============================================================ */ void rglGcmCopySurface( - const rglGcmSurface* src, + const void *data, GLuint srcX, GLuint srcY, - const rglGcmSurface* dst, + const void *data_dst, GLuint dstX, GLuint dstY, GLuint width, GLuint height, GLboolean writeSync ) // don't overwrite dst directly (not used yet) { + const rglGcmSurface *src = (const rglGcmSurface*)data; + const rglGcmSurface *dst = (const rglGcmSurface*)data_dst; const GLuint srcPitch = src->pitch ? src->pitch : src->bpp * src->width; const GLuint dstPitch = dst->pitch ? dst->pitch : dst->bpp * dst->width; diff --git a/console/rgl/src/ps3/rgl_ps3_raster.cpp b/console/rgl/src/ps3/rgl_ps3_raster.cpp index 1bc5f551a8..523447c5a1 100644 --- a/console/rgl/src/ps3/rgl_ps3_raster.cpp +++ b/console/rgl/src/ps3/rgl_ps3_raster.cpp @@ -61,10 +61,11 @@ static void setAttribConstantIndex( CgRuntimeParameter* __restrict ptr, const vo rglVertexAttrib4fNV( index, f[0], f[1], f[2], f[3] ); } -void rglPlatformSetVertexRegister4fv( unsigned int reg, const float * __restrict v ) +void rglPlatformSetVertexRegister4fv (unsigned int reg, const float * __restrict v) { // save to shared memory for context restore after flip - __builtin_memcpy( rglGetGcmDriver()->sharedVPConstants + reg*4*sizeof( float ), v, 4*sizeof( float ) ); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; + __builtin_memcpy(driver->sharedVPConstants + reg*4*sizeof( float ), v, 4*sizeof( float ) ); GCM_FUNC( cellGcmSetVertexProgramParameterBlock, reg, 1, v ); } @@ -81,11 +82,6 @@ void rglPlatformSetVertexRegister4fv( unsigned int reg, const float * __restrict //here ec has been advanced and is already on top of the embedded constant count template inline static void swapandsetfp( int ucodeSize, unsigned int loadProgramId, unsigned int loadProgramOffset, unsigned short *ec, const unsigned int * __restrict v ) { - //unsigned int v2[4]; - //for (long i=0; i < SIZE; ++i) - //{ - // v2[i] = SWAP_IF_BIG_ENDIAN(v[i]); - //} GCM_FUNC( cellGcmSetTransferLocation, CELL_GCM_LOCATION_LOCAL ); unsigned short count = *( ec++ ); for ( unsigned long offsetIndex = 0; offsetIndex < count; ++offsetIndex ) @@ -124,7 +120,7 @@ template static void setVectorTypefp( CgRuntimeParameter* __restrict p template static void setVectorTypeSharedfpIndex( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int /*index*/ ) { RGLcontext * LContext = _CurrentContext; - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; const CgParameterResource *parameterResource = rglGetParameterResource( ptr->program, ptr->parameterEntry ); unsigned short resource = parameterResource->resource; unsigned short sharedResource = *(( unsigned short * )( ptr->program->resources ) + resource ); @@ -146,7 +142,7 @@ template static void setVectorTypeSharedfpIndex( CgRuntimeParameter* _ template static void setVectorTypeSharedfpIndexArray( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int index ) { RGLcontext * LContext = _CurrentContext; - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; const CgParameterResource *parameterResource = rglGetParameterResource( ptr->program, ptr->parameterEntry ); unsigned short resource = parameterResource->resource; @@ -320,7 +316,7 @@ template static void setMatrixSharedvpIndexArray template static void setMatrixSharedfpIndex( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int /*index*/ ) { - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; const CgParameterResource *parameterResource = rglGetParameterResource( ptr->program, ptr->parameterEntry ); unsigned short resource = parameterResource->resource; @@ -360,7 +356,7 @@ template static void setMatrixSharedfpIndex( CgR template static void setMatrixSharedfpIndexArray( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int index ) { //TODO: double check for the semi endian swap... not done here, is it done by the RSX ? - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; const CgParameterResource *parameterResource = rglGetParameterResource( ptr->program, ptr->parameterEntry ); unsigned short resource = parameterResource->resource; @@ -575,9 +571,7 @@ static void setSamplerfp( CgRuntimeParameter*ptr, const void*v, int ) //index // the spec says that the set should not cause the bind // so only do the bind when the call comes from cgGLEnableTextureParameter if ( v ) - { *( GLuint* )ptr->pushBufferPointer = *( GLuint* )v; - } else { rglTextureImageUnit *unit = _CurrentContext->TextureImageUnits + ( parameterResource->resource - CG_TEXUNIT0 ); @@ -608,8 +602,10 @@ static void setSamplervp( CgRuntimeParameter*ptr, const void*v, int ) //index #define COL_MAJOR 1 //This function creates the push buffer and the related structures -void rglCreatePushBuffer( _CGprogram *program ) +void rglCreatePushBuffer(void *data) { + _CGprogram *program = (_CGprogram*)data; + //first pass to compute the space needed int bufferSize = 0; int programPushBufferPointersSize = 0; @@ -882,11 +878,10 @@ void rglCreatePushBuffer( _CGprogram *program ) } else { - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; + if ( parameterEntry->flags & CGP_CONTIGUOUS ) - { rtParameter->pushBufferPointer = driver->sharedVPConstants + parameterResource->resource * 4 * sizeof( float ); - } else { int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; @@ -1252,6 +1247,7 @@ void rglPlatformDestroyBufferObject( rglBufferObject* bufferObject ) void rglPlatformBufferObjectSetData( rglBufferObject* bufferObject, GLintptr offset, GLsizeiptr size, const GLvoid *data, GLboolean tryImmediateCopy ) { + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; rglGcmBufferObject *rglBuffer = ( rglGcmBufferObject * )bufferObject->platformBufferObject; if ( size == bufferObject->size && tryImmediateCopy ) @@ -1292,15 +1288,17 @@ void rglPlatformBufferObjectSetData( rglBufferObject* bufferObject, GLintptr off } // be conservative here. Whenever we write to any Buffer Object, invalidate the vertex cache - rglGetGcmDriver()->invalidateVertexCache = GL_TRUE; + driver->invalidateVertexCache = GL_TRUE; } -GLvoid rglPlatformBufferObjectCopyData( - rglBufferObject* bufferObjectDst, - rglBufferObject* bufferObjectSrc ) +GLvoid rglPlatformBufferObjectCopyData(void *bufferObjectDst, void *bufferObjectSrc) { - rglGcmBufferObject* dst = ( rglGcmBufferObject* )bufferObjectDst->platformBufferObject; - rglGcmBufferObject* src = ( rglGcmBufferObject* )bufferObjectSrc->platformBufferObject; + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; + + rglBufferObject *in_dst = (rglBufferObject*)bufferObjectDst; + rglBufferObject *in_src = (rglBufferObject*)bufferObjectSrc; + rglGcmBufferObject* dst = (rglGcmBufferObject*)in_dst->platformBufferObject; + rglGcmBufferObject* src = (rglGcmBufferObject*)in_src->platformBufferObject; // copy data // There is currently no requirement to copy from one pool to another. @@ -1308,7 +1306,7 @@ GLvoid rglPlatformBufferObjectCopyData( rglGcmMemcpy( dst->bufferId, 0, dst->pitch, src->bufferId, 0, src->bufferSize ); // be conservative here. Whenever we write to any Buffer Object, invalidate the vertex cache - rglGetGcmDriver()->invalidateVertexCache = GL_TRUE; + driver->invalidateVertexCache = GL_TRUE; } char *rglPlatformBufferObjectMap( rglBufferObject* bufferObject, GLenum access ) @@ -1339,7 +1337,7 @@ char *rglPlatformBufferObjectMap( rglBufferObject* bufferObject, GLenum access ) // flush the vertex cache in case VBO data has been modified. if ( rglBuffer->mapAccess != GL_READ_ONLY ) { - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; ++driver->flushBufferCount; } @@ -1362,7 +1360,7 @@ GLboolean rglPlatformBufferObjectUnmap( rglBufferObject* bufferObject ) // flush the vertex cache in case VBO data has been modified. if ( rglBuffer->mapAccess != GL_READ_ONLY ) { - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; --driver->flushBufferCount; // make sure we flush for the next draw @@ -1384,17 +1382,22 @@ GLboolean rglPlatformBufferObjectUnmap( rglBufferObject* bufferObject ) void rglFBClear( GLbitfield mask ) { RGLcontext* LContext = _CurrentContext; + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - rglGcmDriver *driver = rglGetGcmDriver(); - if ( !driver->rtValid ) return; + if (!driver->rtValid) + return; GLbitfield newmask = 0; - if (( mask & GL_COLOR_BUFFER_BIT ) && driver->rt.colorBufferCount ) newmask |= RGLGCM_COLOR_BUFFER_BIT; + + if ((mask & GL_COLOR_BUFFER_BIT) && driver->rt.colorBufferCount) + newmask |= RGLGCM_COLOR_BUFFER_BIT; - if ( !newmask ) return; + if (!newmask) + return; GLbitfield clearMask = newmask; - if ( driver->rt.colorFormat != RGLGCM_ARGB8 ) clearMask &= ~RGLGCM_COLOR_BUFFER_BIT; + if (driver->rt.colorFormat != RGLGCM_ARGB8) + clearMask &= ~RGLGCM_COLOR_BUFFER_BIT; // always use quad clear for colors with MRT // There is one global clear mask for all render targets. This doesn't @@ -1497,13 +1500,10 @@ GLenum rglPlatformFramebufferCheckStatus( rglFramebuffer* framebuffer ) &colorTexture, &colorFace ); // TODO: Complete texture may not be required. - if ( colorTexture != NULL ) + if (colorTexture != NULL) { - if ( colorTexture->referenceBuffer && !colorTexture->isRenderTarget ) - { - //RGL_REPORT_EXTRA( RGL_REPORT_FRAMEBUFFER_UNSUPPORTED, "Framebuffer color attachment texture is a reference in a format that cannot be rendered to (swizzled texture, smaller than 16x16 or with more than 32 bits per pixel)" ); + if (colorTexture->referenceBuffer && !colorTexture->isRenderTarget) return GL_FRAMEBUFFER_UNSUPPORTED_OES; - } // all attachments must have the same dimensions image[nBuffers] = colorTexture->image; @@ -1516,10 +1516,8 @@ GLenum rglPlatformFramebufferCheckStatus( rglFramebuffer* framebuffer ) // all color attachments need the same format if ( colorFormat && colorFormat != image[nBuffers]->internalFormat ) - { - //RGL_REPORT_EXTRA( RGL_REPORT_FRAMEBUFFER_INCOMPLETE, "Framebuffer attachments have inconsistent color formats" ); return GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES; - } + colorFormat = image[nBuffers]->internalFormat; ++nBuffers; @@ -1530,10 +1528,8 @@ GLenum rglPlatformFramebufferCheckStatus( rglFramebuffer* framebuffer ) if ( nBuffers ) { if ( !rglIsDrawableColorFormat( colorFormat ) ) - { - //RGL_REPORT_EXTRA( RGL_REPORT_FRAMEBUFFER_UNSUPPORTED, "Color attachment to framebuffer must be a supported drawable format (GL_ARGB_SCE, GL_RGB16F_ARB, GL_RGBA16F_ARB, GL_RGB32F_ARB, GL_RGBA32F_ARB, GL_LUMINANCE32F_ARB)" ); return GL_FRAMEBUFFER_UNSUPPORTED_OES; - } + switch ( colorFormat ) { case RGLGCM_ARGB8: @@ -1563,8 +1559,10 @@ GLenum rglPlatformFramebufferCheckStatus( rglFramebuffer* framebuffer ) void rglPlatformFramebuffer::validate( RGLcontext *LContext ) { - complete = ( rglPlatformFramebufferCheckStatus( this ) == GL_FRAMEBUFFER_COMPLETE_OES ); - if ( !complete ) return; + complete = (rglPlatformFramebufferCheckStatus(this) == GL_FRAMEBUFFER_COMPLETE_OES); + + if (!complete) + return; GLuint width = RGLGCM_MAX_RT_DIMENSION; GLuint height = RGLGCM_MAX_RT_DIMENSION; @@ -1578,6 +1576,7 @@ void rglPlatformFramebuffer::validate( RGLcontext *LContext ) GLuint defaultPitch = 0; GLuint defaultId = GMM_ERROR; GLuint defaultIdOffset = 0; + for ( int i = 0; i < RGLGCM_SETRENDERTARGET_MAXCOUNT; ++i ) { // get the texture and face @@ -1641,17 +1640,19 @@ void rglValidateFramebuffer( void ) rglGcmDevice *gcmDevice = ( rglGcmDevice * )LDevice->platformDevice; RGLcontext* LContext = _CurrentContext; - rglGcmDriver * gcmDriver = rglGetGcmDriver(); + rglGcmDriver *gcmDriver = (rglGcmDriver*)_CurrentDevice->rasterDriver; // reset buffer data gcmDriver->rtValid = GL_FALSE; // get buffer parameters // This may come from a framebuffer_object or the default framebuffer. - if ( LContext->framebuffer ) + + if (LContext->framebuffer) { rglPlatformFramebuffer* framebuffer = static_cast( rglGetFramebuffer( LContext, LContext->framebuffer ) ); - if ( framebuffer->needValidate ) framebuffer->validate( LContext ); + if (framebuffer->needValidate) + framebuffer->validate( LContext ); gcmDriver->rt = framebuffer->rt; } @@ -1680,7 +1681,7 @@ void rglValidateFramebuffer( void ) // Initialize the driver and setup the fixed function pipeline // shader and needed connections between GL state and the shader -void *rglPlatformRasterInit() +void *rglPlatformRasterInit (void) { rglpFifoGlFinish(); rglGcmDriver *driver = ( rglGcmDriver * )malloc( sizeof( rglGcmDriver ) ); @@ -1700,9 +1701,9 @@ void *rglPlatformRasterInit() } // Destroy the driver, and free all its used memory -void rglPlatformRasterExit( void *drv ) +void rglPlatformRasterExit (void *data) { - rglGcmDriver *driver = ( rglGcmDriver * )drv; + rglGcmDriver *driver = (rglGcmDriver*)data; gmmFree( driver->sharedFPConstantsId ); free( driver->sharedVPConstants ); @@ -1725,7 +1726,8 @@ extern bool _cellRSXFifoDisassembleToFileMask; // memory setup operations first void rglPlatformDraw( rglDrawParams* dparams ) { - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; + if (RGL_UNLIKELY(!driver->rtValid)) return; @@ -1760,17 +1762,15 @@ void rglPlatformDraw( rglDrawParams* dparams ) gmmIdToOffset( driver->fpLoadProgramId ) + driver->fpLoadProgramOffset ); } - - // glDrawArrays() rglGcmFifoGlDrawArrays(( rglGcmEnum )dparams->mode, dparams->firstVertex, dparams->vertexCount ); } // Set up the current fragment program on hardware -void rglValidateFragmentProgram() +void rglValidateFragmentProgram (void) { RGLcontext* LContext = _CurrentContext; - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; _CGprogram *program = LContext->BoundFragmentProgram; // params are set directly in the GPU memory, so there is nothing to be done here. @@ -1818,12 +1818,12 @@ GLboolean rglPlatformRequiresSlowPath( rglDrawParams* dparams, const GLenum inde } // Return the current RGLGcmDriver -rglGcmDriver* rglGetRGLGcmDriver() +rglGcmDriver* rglGetRGLGcmDriver (void) { return ( rglGcmDriver * )( _CurrentDevice->rasterDriver ); } -void rglPlatformRasterFlush() +void rglPlatformRasterFlush (void) { rglGcmFifoGlFlush(); } @@ -1839,7 +1839,7 @@ void rglpFifoGlFinish( void ) GLuint rglValidateAttributesSlow( rglDrawParams *dparams, GLboolean *isMain ) { RGLcontext* LContext = _CurrentContext; - rglGcmDriver *driver = rglGetGcmDriver(); + rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; rglAttributeState* as = LContext->attribs; // allocate upload transfer buffer if necessary @@ -1868,7 +1868,8 @@ GLuint rglValidateAttributesSlow( rglDrawParams *dparams, GLboolean *isMain ) for(GLuint i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i) { // skip this attribute if not needing update - if ( ! RGLBIT_GET( needsUpdateMask, i ) ) continue; + if (!RGLBIT_GET( needsUpdateMask, i)) + continue; rglAttribute* attrib = as->attrib + i; if ( RGLBIT_GET( as->EnabledMask, i ) ) @@ -1974,14 +1975,15 @@ GLuint rglGetGcmImageOffset( rglGcmTextureLayout *layout, GLuint face, GLuint le GLuint minWidth = 1; GLuint minHeight = 1; - for ( GLuint f = 0;f < layout->faces;++f ) + for (GLuint f = 0; f < layout->faces; ++f) { GLuint width = layout->baseWidth; GLuint height = layout->baseHeight; GLuint depth = layout->baseDepth; for ( GLuint i = 0;i < layout->levels; ++i ) { - if (( level == i ) && ( face == f ) ) return bytes; + if ((level == i) && (face == f)) + return bytes; width = MAX( minWidth, width ); height = MAX( minHeight, height ); @@ -2008,19 +2010,19 @@ int rglPlatformTextureSize() } // Calculate pitch for a texture -static GLuint _getTexturePitch( const rglTexture * texture ) +static GLuint _getTexturePitch(const rglTexture * texture) { return rglPad( rglGetStorageSize( texture->image->format, texture->image->type, texture->image->width, 1, 1 ), 64 ); // TransferVid2Vid needs 64byte pitch alignment } // Return maximum number of texture image units -int rglPlatformTextureMaxUnits() +int rglPlatformTextureMaxUnits (void) { return RGLGCM_MAX_TEXIMAGE_COUNT; } // Create a gcm texture by initializing memory to 0 -void rglPlatformCreateTexture( rglTexture* texture ) +void rglPlatformCreateTexture (rglTexture* texture) { rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; memset( gcmTexture, 0, sizeof( rglGcmTexture ) ); @@ -2052,9 +2054,7 @@ void rglPlatformDropTexture( rglTexture *texture ) rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; if (gcmTexture->pool != RGLGCM_SURFACE_POOL_NONE) - { rglPlatformFreeGcmTexture( texture ); - } gcmTexture->pool = RGLGCM_SURFACE_POOL_NONE; gcmTexture->gpuAddressId = GMM_ERROR; @@ -2139,9 +2139,7 @@ void rglPlatformChooseGPUFormatAndLayout( // if we don't want mipmapping, but still have valid mipmaps, load all the mipmaps. // This is to avoid a big cost when switching from mipmaps to non-mipmaps. if (( texture->minFilter == GL_LINEAR ) || ( texture->minFilter == GL_NEAREST ) ) - { levels = 1; - } newLayout->levels = levels; newLayout->faces = texture->faceCount; @@ -2448,8 +2446,11 @@ void rglPlatformUploadTexture( rglTexture* texture ) } // map RGL internal types to GCM -static inline void rglGcmUpdateGcmTexture( rglTexture * texture, rglGcmTextureLayout * layout, rglGcmTexture * platformTexture ) +static inline void rglGcmUpdateGcmTexture (void *data_tex, rglGcmTextureLayout * layout, void *data_plattex) { + rglTexture *texture = (rglTexture*)data_tex; + rglGcmTexture *platformTexture = (rglGcmTexture*)data_plattex; + // use color format for depth with no compare mode // This hack is needed because the hardware will not read depth // textures without performing a compare. The depth value will need to @@ -2476,6 +2477,8 @@ static inline void rglGcmUpdateGcmTexture( rglTexture * texture, rglGcmTextureLa platformTexture->gcmTexture.cubemap = CELL_GCM_FALSE; // set dimension, swizzled implies P2 width/height/depth + +#if 0 switch ( texture->target ) { case 0: @@ -2483,6 +2486,9 @@ static inline void rglGcmUpdateGcmTexture( rglTexture * texture, rglGcmTextureLa platformTexture->gcmTexture.dimension = CELL_GCM_TEXTURE_DIMENSION_2; break; } +#else + platformTexture->gcmTexture.dimension = CELL_GCM_TEXTURE_DIMENSION_2; +#endif // system or local texture platformTexture->gcmTexture.location = CELL_GCM_LOCATION_LOCAL; @@ -2490,9 +2496,9 @@ static inline void rglGcmUpdateGcmTexture( rglTexture * texture, rglGcmTextureLa } // map RGL internal types to GCM -void rglGcmUpdateMethods( rglTexture * texture ) +void rglGcmUpdateMethods(void *data) { - + rglTexture *texture = (rglTexture*)data; rglGcmTexture *platformTexture = ( rglGcmTexture * )texture->platformTexture; rglGcmTextureLayout *layout = &platformTexture->gpuLayout; @@ -2566,8 +2572,9 @@ void rglGcmUpdateMethods( rglTexture * texture ) } // Validate texture resources -void rglPlatformValidateTextureResources( rglTexture *texture ) +void rglPlatformValidateTextureResources (void *data) { + rglTexture *texture = (rglTexture*)data; texture->isComplete = GL_TRUE; // We may need to reallocate the texture when the parameters are changed @@ -2594,8 +2601,9 @@ void rglPlatformValidateTextureResources( rglTexture *texture ) #include // Set a texture to a gcm texture unit -static inline void rglGcmSetTextureUnit( GLuint unit, rglGcmTexture *platformTexture ) +static inline void rglGcmSetTextureUnit (GLuint unit, void *data) { + rglGcmTexture *platformTexture = (rglGcmTexture*)data; const GLuint imageOffset = gmmIdToOffset(platformTexture->gpuAddressId) + platformTexture->gpuAddressIdOffset; platformTexture->gcmTexture.offset = imageOffset; @@ -2642,8 +2650,6 @@ static inline void rglGcmSetTextureUnit( GLuint unit, rglGcmTexture *platformTex platformTexture->gcmTexture.pitch, platformTexture->gcmTexture.depth); gcm_context->current = ¤t[11]; - - } // Validate incomplete texture by remapping @@ -2671,8 +2677,10 @@ inline static void rglPlatformValidateIncompleteTexture( GLuint unit ) #undef RGLGCM_REMAP_MODES // Valiate resources of a texture and set it to a unit -void rglPlatformValidateTextureStage( int unit, rglTexture* texture ) +void rglPlatformValidateTextureStage( int unit, void *data) { + rglTexture *texture = (rglTexture*)data; + if ( RGL_UNLIKELY( texture->revalidate ) ) { // this updates the isComplete bit. @@ -2691,8 +2699,6 @@ void rglPlatformValidateTextureStage( int unit, rglTexture* texture ) //RGL_REPORT_EXTRA( RGL_REPORT_TEXTURE_INCOMPLETE, "Texture %d bound to unit %d(%s) is incomplete.", texture->name, unit, rglGetGLEnumName( texture->target ) ); rglPlatformValidateIncompleteTexture( unit ); } - - } // Choose internal format closest to given format @@ -2776,8 +2782,9 @@ void rglPlatformExpandInternalFormat( GLenum internalFormat, GLenum *format, GLe } // Choose internal storage type and size, and set it to image, based on given format -GLenum rglPlatformChooseInternalStorage( rglImage* image, GLenum internalFormat ) +GLenum rglPlatformChooseInternalStorage (void *data, GLenum internalFormat ) { + rglImage *image = (rglImage*)data; // see note at bottom concerning storageSize image->storageSize = 0; @@ -2812,8 +2819,9 @@ GLenum rglPlatformTranslateTextureFormat( GLenum internalFormat ) // Implementation of texture reference // Associate bufferObject to texture by assigning buffer's gpu address to the gcm texture -GLboolean rglPlatformTextureReference( rglTexture *texture, GLuint pitch, rglBufferObject *bufferObject, GLintptr offset ) +GLboolean rglPlatformTextureReference (void *data, GLuint pitch, rglBufferObject *bufferObject, GLintptr offset ) { + rglTexture *texture = (rglTexture*)data; rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; // XXX check pitch restrictions ? @@ -2866,9 +2874,10 @@ GLboolean rglPlatformTextureReference( rglTexture *texture, GLuint pitch, rglBuf // Render target rt's color and depth buffer parameters are updated with args // Fifo functions are called as required -void static inline rglGcmSetColorDepthBuffers( rglGcmRenderTarget *rt, rglGcmRenderTargetEx const * const args ) +void static inline rglGcmSetColorDepthBuffers(void *data, rglGcmRenderTargetEx const * const args ) { - CellGcmSurface * grt = &rt->gcmRenderTarget; + rglGcmRenderTarget *rt = (rglGcmRenderTarget*)data; + CellGcmSurface *grt = &rt->gcmRenderTarget; rt->colorBufferCount = args->colorBufferCount; @@ -2931,10 +2940,10 @@ void static inline rglGcmSetColorDepthBuffers( rglGcmRenderTarget *rt, rglGcmRen } } - // Update rt's color and depth format with args -void static inline rglGcmSetColorDepthFormats( rglGcmRenderTarget *rt, rglGcmRenderTargetEx const * const args ) +void static inline rglGcmSetColorDepthFormats (void *data, rglGcmRenderTargetEx const * const args) { + rglGcmRenderTarget *rt = (rglGcmRenderTarget*)data; CellGcmSurface * grt = &rt->gcmRenderTarget; // set the color format @@ -2962,8 +2971,9 @@ void static inline rglGcmSetColorDepthFormats( rglGcmRenderTarget *rt, rglGcmRen } // Update rt's color targets -static void inline rglGcmSetTarget( rglGcmRenderTarget *rt, rglGcmRenderTargetEx const * const args ) +static void inline rglGcmSetTarget (void *data, rglGcmRenderTargetEx const * const args ) { + rglGcmRenderTarget *rt = (rglGcmRenderTarget*)data; CellGcmSurface * grt = &rt->gcmRenderTarget; // set target combo @@ -3021,7 +3031,7 @@ void rglGcmFifoGlSetRenderTarget( rglGcmRenderTargetEx const * const args ) PLATFORM TNL ============================================================ */ -void rglValidateVertexProgram() +void rglValidateVertexProgram (void) { // if validation is required, it means the program has to be downloaded. RGLcontext* LContext = _CurrentContext; @@ -3033,7 +3043,7 @@ void rglValidateVertexProgram() rglValidateVertexConstants(); } -void rglValidateVertexConstants() +void rglValidateVertexConstants (void) { RGLcontext* LContext = _CurrentContext; _CGprogram *cgprog = LContext->BoundVertexProgram; @@ -3059,6 +3069,9 @@ void rglValidateVertexConstants() void rglDrawUtilQuad( GLboolean useFixedVP, GLboolean useFixedFP, GLuint x, GLuint y, GLuint width, GLuint height ) { + (void)useFixedVP; + (void)useFixedFP; + RGLcontext* LContext = _CurrentContext; rglGcmFifoGlDisable( RGLGCM_BLEND ); diff --git a/console/rgl/src/rgl.cpp b/console/rgl/src/rgl.cpp index 5a001a21e3..640a4bea5c 100644 --- a/console/rgl/src/rgl.cpp +++ b/console/rgl/src/rgl.cpp @@ -37,8 +37,10 @@ static rglBufferObject *rglCreateBufferObject(void) return buffer; } -static void rglFreeBufferObject( rglBufferObject *buffer ) +static void rglFreeBufferObject (void *data) { + rglBufferObject *buffer = (rglBufferObject*)data; + if ( --buffer->refCount == 0 ) { rglPlatformDestroyBufferObject( buffer ); @@ -47,8 +49,9 @@ static void rglFreeBufferObject( rglBufferObject *buffer ) } } -static void rglUnbindBufferObject( RGLcontext *LContext, GLuint name ) +static void rglUnbindBufferObject (void *data, GLuint name) { + RGLcontext *LContext = (RGLcontext*)data; if ( LContext->ArrayBuffer == name ) LContext->ArrayBuffer = 0; if ( LContext->PixelUnpackBuffer == name ) LContext->PixelUnpackBuffer = 0; for ( int i = 0;i < RGL_MAX_VERTEX_ATTRIBS;++i ) @@ -631,11 +634,11 @@ int rglGetPixelSize( GLenum format, GLenum type ) return rglGetComponentCount( format )*componentSize; } -void rglRawRasterToImage( - const rglRaster* raster, - rglImage* image, - GLuint x, GLuint y, GLuint z ) +void rglRawRasterToImage(const void *in_data, + void *out_data, GLuint x, GLuint y, GLuint z ) { + const rglRaster* raster = (const rglRaster*)in_data; + rglImage *image = (rglImage*)out_data; const int pixelBits = rglGetPixelSize( image->format, image->type ) * 8; const GLuint size = pixelBits / 8; @@ -696,8 +699,10 @@ void rglRawRasterToImage( } } -void rglImageAllocCPUStorage( rglImage *image ) +void rglImageAllocCPUStorage (void *data) { + rglImage *image = (rglImage*)data; + if (( image->storageSize > image->mallocStorageSize ) || ( !image->mallocData ) ) { if (image->mallocData) @@ -709,8 +714,9 @@ void rglImageAllocCPUStorage( rglImage *image ) image->data = rglPadPtr( image->mallocData, 128 ); } -void rglImageFreeCPUStorage( rglImage *image ) +void rglImageFreeCPUStorage(void *data) { + rglImage *image = (rglImage*)data; if (!image->mallocData) return; @@ -985,8 +991,10 @@ void rglResetAttributeState( rglAttributeState* as ) as->HasVBOMask = 0; } -static void rglResetContext( RGLcontext *LContext ) +static void rglResetContext (void *data) { + RGLcontext *LContext = (RGLcontext*)data; + rglTexNameSpaceResetNames( &LContext->textureNameSpace ); rglTexNameSpaceResetNames( &LContext->bufferObjectNameSpace ); rglTexNameSpaceResetNames( &LContext->framebufferNameSpace ); @@ -1067,7 +1075,9 @@ static void rglResetContext( RGLcontext *LContext ) RGLcontext* psglCreateContext(void) { RGLcontext* LContext = ( RGLcontext* )malloc( sizeof( RGLcontext ) ); - if ( !LContext ) return NULL; + + if (!LContext) + return NULL; memset( LContext, 0, sizeof( RGLcontext ) ); @@ -1158,8 +1168,9 @@ void RGL_EXPORT psglDestroyContext( RGLcontext* LContext ) free( LContext ); } -void rglInvalidateAllStates( RGLcontext* context ) +void rglInvalidateAllStates (void *data) { + RGLcontext *context = (RGLcontext*)data; context->needValidate = RGL_VALIDATE_ALL; context->attribs->DirtyMask = ( 1 << RGL_MAX_VERTEX_ATTRIBS ) - 1; } @@ -1367,9 +1378,10 @@ rglTexture *rglAllocateTexture(void) return texture; } -void rglFreeTexture( rglTexture *texture ) +void rglFreeTexture (void *data) { - rglTextureTouchFBOs( texture ); + rglTexture *texture = (rglTexture*)data; + rglTextureTouchFBOs(texture); texture->framebuffers.~Vector(); if ( texture->image ) @@ -1404,8 +1416,9 @@ void rglTextureUnbind( RGLcontext* context, GLuint name ) } } -GLboolean rglTextureIsValid( const rglTexture* texture ) +GLboolean rglTextureIsValid (const void *data) { + const rglTexture *texture = (const rglTexture*)data; if ( texture->imageCount < 1 + texture->baseLevel ) return GL_FALSE; if ( !texture->image ) @@ -1449,11 +1462,11 @@ GLenum rglGetEnabledTextureMode( const rglTextureImageUnit *unit ) // here, if fragment program is enabled and a valid program is set, get the enabled // units from the program instead of the texture units. if ( _CurrentContext->BoundFragmentProgram != NULL && _CurrentContext->FragmentProgram != GL_FALSE) - { return unit->fragmentTarget; - } - else if ( unit->enable2D ) return GL_TEXTURE_2D; - else return 0; + else if ( unit->enable2D ) + return GL_TEXTURE_2D; + + return 0; } rglTexture *rglGetCurrentTexture( const rglTextureImageUnit *unit, GLenum target ) @@ -1508,8 +1521,9 @@ int rglGetImage( GLenum target, GLint level, rglTexture **texture, rglImage **im return 0; } -void rglBindTextureInternal( rglTextureImageUnit *unit, GLuint name, GLenum target ) +void rglBindTextureInternal (void *data, GLuint name, GLenum target ) { + rglTextureImageUnit *unit = (rglTextureImageUnit*)data; RGLcontext* LContext = _CurrentContext; rglTexture *texture = NULL; if ( name ) @@ -1524,6 +1538,7 @@ void rglBindTextureInternal( rglTextureImageUnit *unit, GLuint name, GLenum targ } } +#if 0 switch ( target ) { case GL_TEXTURE_2D: @@ -1532,6 +1547,10 @@ void rglBindTextureInternal( rglTextureImageUnit *unit, GLuint name, GLenum targ default: break; } +#else + unit->bound2D = name; +#endif + rglUpdateCurrentTextureCache( unit ); LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; } @@ -1565,9 +1584,7 @@ GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ) case GL_TEXTURE_MIN_FILTER: texture->minFilter = param; if ( texture->referenceBuffer == 0 ) - { texture->revalidate |= RGL_TEXTURE_REVALIDATE_LAYOUT; - } break; case GL_TEXTURE_MAG_FILTER: texture->magFilter = param; @@ -1586,10 +1603,9 @@ GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ) break; case GL_TEXTURE_FROM_VERTEX_PROGRAM_SCE: if ( param != 0 ) - { texture->vertexEnable = GL_TRUE; - } - else texture->vertexEnable = GL_FALSE; + else + texture->vertexEnable = GL_FALSE; texture->revalidate |= RGL_TEXTURE_REVALIDATE_LAYOUT; break; case GL_TEXTURE_ALLOCATION_HINT_SCE: @@ -1660,9 +1676,7 @@ GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalForm if ( LContext->PixelUnpackBuffer != 0 ) - { rglPlatformBufferObjectUnmap( bufferObject ); - } texture->revalidate |= RGL_TEXTURE_REVALIDATE_IMAGES;