(GCMGL) Cleanups #3

This commit is contained in:
twinaphex 2014-02-26 05:57:13 +01:00
parent c6a091ef7f
commit c7daeb29a9
5 changed files with 115 additions and 163 deletions

View File

@ -131,15 +131,12 @@ extern PSGLdeviceParameters * rglShadowDeviceParameters (void);
extern GLboolean rglPlatformDeviceInit (void *data); extern GLboolean rglPlatformDeviceInit (void *data);
extern void rglPlatformDeviceExit (void); extern void rglPlatformDeviceExit (void);
extern int rglPlatformCreateDevice (void *data); extern int rglPlatformCreateDevice (void *data);
extern void rglPlatformDestroyDevice (void *data);
extern void rglPlatformSwapBuffers (void *data); extern void rglPlatformSwapBuffers (void *data);
extern const GLvoid* rglPlatformGetProcAddress (const char *funcName); extern const GLvoid* rglPlatformGetProcAddress (const char *funcName);
//---------------------------------------- //----------------------------------------
// Raster/.../PlatformRaster.c // Raster/.../PlatformRaster.c
//---------------------------------------- //----------------------------------------
void* rglPlatformRasterInit (void);
void rglPlatformRasterExit (void* data);
void rglPlatformRasterDestroyResources (void); void rglPlatformRasterDestroyResources (void);
GLboolean rglPlatformNeedsConversion (const rglAttributeState* as, GLuint index); GLboolean rglPlatformNeedsConversion (const rglAttributeState* as, GLuint index);
void rglInvalidateAttributes (void); void rglInvalidateAttributes (void);

View File

@ -285,7 +285,7 @@
gcm_emit_at(thisContext->current, 1, ((enable) | ((alphaToCoverage) << 4) | ((alphaToOne) << 8) | ((sampleMask) << 16))); \ gcm_emit_at(thisContext->current, 1, ((enable) | ((alphaToCoverage) << 4) | ((alphaToOne) << 8) | ((sampleMask) << 16))); \
gcm_finish_n_commands(thisContext->current, 2); gcm_finish_n_commands(thisContext->current, 2);
#define rglGcmFifoFinish(ref, offset_bytes) \ #define rglGcmFifoFinish(fifo, ref, offset_bytes) \
ref = rglGcmFifoPutReference( fifo ); \ ref = rglGcmFifoPutReference( fifo ); \
rglGcmFifoFlush( fifo, offset_bytes ); \ rglGcmFifoFlush( fifo, offset_bytes ); \
while (rglGcmFifoReferenceInUse(fifo, ref)); while (rglGcmFifoReferenceInUse(fifo, ref));

View File

@ -52,7 +52,7 @@ typedef struct
// double/triple buffering management // double/triple buffering management
GLuint drawBuffer; // 0, 1, or 2 GLuint drawBuffer; // 0, 1, or 2
GLuint scanBuffer; // 0, 1, or 2 GLuint scanBuffer; // 0, 1, or 2
// resc buffers (maintain pointers for freeing in rglPlatformDestroyDevice) // resc buffers
GLuint RescColorBuffersId; GLuint RescColorBuffersId;
GLuint RescVertexArrayId; GLuint RescVertexArrayId;
GLuint RescFragmentShaderId; GLuint RescFragmentShaderId;

View File

@ -21,7 +21,6 @@
#include <cell/sysmodule.h> #include <cell/sysmodule.h>
#include <cell/gcm.h> #include <cell/gcm.h>
#include <cell/gcm/gcm_method_data.h>
#include <cell/resc.h> #include <cell/resc.h>
static GLuint nvFenceCounter = 0; static GLuint nvFenceCounter = 0;
@ -890,10 +889,7 @@ static uint8_t gmmSizeToFreeIndex(uint32_t size)
return 21; return 21;
} }
static void gmmAddFree( static void gmmAddFree(GmmAllocator *pAllocator, GmmBlock *pBlock)
GmmAllocator *pAllocator,
GmmBlock *pBlock
)
{ {
uint8_t freeIndex = gmmSizeToFreeIndex(pBlock->base.size); uint8_t freeIndex = gmmSizeToFreeIndex(pBlock->base.size);
@ -1428,7 +1424,7 @@ GLuint rglGcmFifoPutReference (void *data)
if (( fifo->lastSWReferenceWritten & 0x7fffffff ) == 0 ) if (( fifo->lastSWReferenceWritten & 0x7fffffff ) == 0 )
{ {
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
} }
return fifo->lastSWReferenceWritten; return fifo->lastSWReferenceWritten;
@ -1526,7 +1522,7 @@ GLboolean rglGcmInitFromRM( rglGcmResource *rmResource )
rglGcmFifoInit( &rglGcmSt->fifo, rmResource->dmaControl, rmResource->dmaPushBufferOffset, (uint32_t*)rmResource->dmaPushBuffer, rmResource->dmaPushBufferSize ); rglGcmFifoInit( &rglGcmSt->fifo, rmResource->dmaControl, rmResource->dmaPushBufferOffset, (uint32_t*)rmResource->dmaPushBuffer, rmResource->dmaPushBufferSize );
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
// Set the GPU to a known state // Set the GPU to a known state
// initialize the default OpenGL state // initialize the default OpenGL state
@ -1571,7 +1567,7 @@ GLboolean rglGcmInitFromRM( rglGcmResource *rmResource )
// wait for setup to complete // wait for setup to complete
offset_bytes = 0; offset_bytes = 0;
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
return GL_TRUE; return GL_TRUE;
} }
@ -1679,44 +1675,6 @@ enable: 0,
static int rglInitCompleted = 0; static int rglInitCompleted = 0;
void rglPsglPlatformInit (void *data)
{
RGLinitOptions *options = (RGLinitOptions*)data;
if ( !rglInitCompleted )
{
cellSysmoduleLoadModule( CELL_SYSMODULE_GCM_SYS );
cellSysmoduleLoadModule( CELL_SYSMODULE_RESC );
rglDeviceInit( options );
_CurrentContext = NULL;
_CurrentDevice = NULL;
}
rglInitCompleted = 1;
}
void rglPsglPlatformExit(void)
{
RGLcontext* LContext = _CurrentContext;
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
rglGcmFifo * fifo = &rglGcmState_i.fifo;
if ( LContext )
{
unsigned int offset_bytes = 0;
rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFlush(fifo, offset_bytes);
psglMakeCurrent( NULL, NULL );
rglDeviceExit();
_CurrentContext = NULL;
rglInitCompleted = 0;
}
}
RGL_EXPORT RGLdevice* rglPlatformCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode ) RGL_EXPORT RGLdevice* rglPlatformCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode )
{ {
RGLdeviceParameters parameters; RGLdeviceParameters parameters;
@ -2010,7 +1968,6 @@ GLboolean rglPlatformDeviceInit (void *data)
return rglGcmInit( options, &rglGcmResource ); return rglGcmInit( options, &rglGcmResource );
} }
void rglPlatformDeviceExit (void) void rglPlatformDeviceExit (void)
{ {
rglGcmDestroy(); rglGcmDestroy();
@ -2098,7 +2055,7 @@ GLboolean rglGcmTryResizeTileRegion( GLuint address, GLuint size, void* data )
rglGcmUtilWaitForIdle(); rglGcmUtilWaitForIdle();
retVal = cellGcmUnbindTile( region->id ); retVal = cellGcmUnbindTile( region->id );
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
} }
return GL_TRUE; return GL_TRUE;
} }
@ -2121,7 +2078,7 @@ GLboolean rglGcmTryResizeTileRegion( GLuint address, GLuint size, void* data )
retVal = cellGcmBindTile( region->id ); retVal = cellGcmBindTile( region->id );
offset_bytes = 0; offset_bytes = 0;
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
return GL_TRUE; return GL_TRUE;
} }
@ -2741,7 +2698,7 @@ int rglPlatformCreateDevice (void *data)
cellGcmSetFlipMode( gcmDevice->vsync ? CELL_GCM_DISPLAY_VSYNC : CELL_GCM_DISPLAY_HSYNC ); cellGcmSetFlipMode( gcmDevice->vsync ? CELL_GCM_DISPLAY_VSYNC : CELL_GCM_DISPLAY_HSYNC );
rglGcmSetInvalidateVertexCache(thisContext); rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
for ( int i = 0; i < params->bufferingMode; ++i ) for ( int i = 0; i < params->bufferingMode; ++i )
{ {
@ -2761,52 +2718,6 @@ int rglPlatformCreateDevice (void *data)
return 0; return 0;
} }
void rglPlatformDestroyDevice (void *data)
{
RGLdevice *device = (RGLdevice*)data;
rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo;
rglGcmDevice *gcmDevice = ( rglGcmDevice * )device->platformDevice;
RGLdeviceParameters *params = &device->deviceParameters;
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
GLuint ref;
unsigned int offset_bytes = 0;
rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(ref, offset_bytes);
// Stop flip callback
if ( rescIsEnabled( params ) )
cellRescSetFlipHandler(NULL);
else
cellGcmSetFlipHandler(NULL);
// Stop VBlank callback
if ( rescIsEnabled( &device->deviceParameters ) )
cellRescSetVBlankHandler(NULL);
else
cellGcmSetVBlankHandler(NULL);
// Destroy semaphore
int res = sys_semaphore_destroy(FlipSem);
(void)res; // prevent unused variable warning in opt build
if ( rescIsEnabled( params ) )
{
cellRescExit();
rglGcmFreeTiledSurface(gcmDevice->RescColorBuffersId);
gmmFree(gcmDevice->RescVertexArrayId);
gmmFree(gcmDevice->RescFragmentShaderId);
}
rglDuringDestroyDevice = GL_TRUE;
for ( int i = 0; i < params->bufferingMode; ++i )
{
if ( gcmDevice->color[i].pool != RGLGCM_SURFACE_POOL_NONE )
rglGcmFreeTiledSurface( gcmDevice->color[i].dataId );
}
rglDuringDestroyDevice = GL_FALSE;
}
GLAPI void RGL_EXPORT psglSwap (void) GLAPI void RGL_EXPORT psglSwap (void)
{ {
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
@ -3857,7 +3768,7 @@ void RGL_EXPORT psglDestroyContext (void *data)
if ( _CurrentContext == LContext ) if ( _CurrentContext == LContext )
{ {
rglGcmSetInvalidateVertexCache(thisContext); rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
} }
while ( LContext->RGLcgContextHead != ( CGcontext )NULL ) while ( LContext->RGLcgContextHead != ( CGcontext )NULL )
@ -4001,12 +3912,40 @@ GLAPI const GLubyte* APIENTRY glGetString( GLenum name )
void psglInit (void *data) void psglInit (void *data)
{ {
rglPsglPlatformInit((RGLinitOptions*)data); RGLinitOptions *options = (RGLinitOptions*)data;
if ( !rglInitCompleted )
{
cellSysmoduleLoadModule( CELL_SYSMODULE_GCM_SYS );
cellSysmoduleLoadModule( CELL_SYSMODULE_RESC );
rglDeviceInit( options );
_CurrentContext = NULL;
_CurrentDevice = NULL;
}
rglInitCompleted = 1;
} }
void psglExit(void) void psglExit(void)
{ {
rglPsglPlatformExit(); RGLcontext* LContext = _CurrentContext;
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
rglGcmFifo * fifo = &rglGcmState_i.fifo;
if ( LContext )
{
unsigned int offset_bytes = 0;
rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFlush(fifo, offset_bytes);
psglMakeCurrent( NULL, NULL );
rglDeviceExit();
_CurrentContext = NULL;
rglInitCompleted = 0;
}
} }
/*============================================================ /*============================================================
@ -4405,13 +4344,54 @@ RGL_EXPORT void psglGetRenderBufferDimensions (const RGLdevice * device, GLuint
RGL_EXPORT void psglDestroyDevice (void *data) RGL_EXPORT void psglDestroyDevice (void *data)
{ {
RGLdevice *device = (RGLdevice*)data; RGLdevice *device = (RGLdevice*)data;
rglGcmDriver *driver = (rglGcmDriver*)device->rasterDriver;
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo;
rglGcmDevice *gcmDevice = ( rglGcmDevice * )device->platformDevice;
RGLdeviceParameters *params = &device->deviceParameters;
GLuint ref;
unsigned int offset_bytes = 0;
if (_CurrentDevice == device) if (_CurrentDevice == device)
psglMakeCurrent( NULL, NULL ); psglMakeCurrent( NULL, NULL );
if (device->rasterDriver) if (driver)
rglPlatformRasterExit( device->rasterDriver ); free(driver);
rglPlatformDestroyDevice( device ); rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(fifo, ref, offset_bytes);
// Stop flip callback
if ( rescIsEnabled( params ) )
cellRescSetFlipHandler(NULL);
else
cellGcmSetFlipHandler(NULL);
// Stop VBlank callback
if ( rescIsEnabled( &device->deviceParameters ) )
cellRescSetVBlankHandler(NULL);
else
cellGcmSetVBlankHandler(NULL);
// Destroy semaphore
int res = sys_semaphore_destroy(FlipSem);
(void)res; // prevent unused variable warning in opt build
if ( rescIsEnabled( params ) )
{
cellRescExit();
rglGcmFreeTiledSurface(gcmDevice->RescColorBuffersId);
gmmFree(gcmDevice->RescVertexArrayId);
gmmFree(gcmDevice->RescFragmentShaderId);
}
rglDuringDestroyDevice = GL_TRUE;
for ( int i = 0; i < params->bufferingMode; ++i )
{
if ( gcmDevice->color[i].pool != RGLGCM_SURFACE_POOL_NONE )
rglGcmFreeTiledSurface( gcmDevice->color[i].dataId );
}
rglDuringDestroyDevice = GL_FALSE;
free( device ); free( device );
} }
@ -4427,7 +4407,24 @@ void RGL_EXPORT psglMakeCurrent (RGLcontext *context, RGLdevice *device)
_CurrentDevice = device; _CurrentDevice = device;
if ( !device->rasterDriver ) if ( !device->rasterDriver )
device->rasterDriver = rglPlatformRasterInit(); {
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo;
GLuint ref;
unsigned int offset_bytes = 0;
rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(fifo, ref, offset_bytes);
rglGcmDriver *driver = (rglGcmDriver*)malloc(sizeof(rglGcmDriver));
memset(driver, 0, sizeof(rglGcmDriver));
driver->rt.yInverted = true;
driver->invalidateVertexCache = GL_FALSE;
driver->flushBufferCount = 0;
device->rasterDriver = driver;
}
//attach context //attach context
if (!context->everAttached) if (!context->everAttached)

View File

@ -892,7 +892,7 @@ char *rglPlatformBufferObjectMap (void *data, GLenum access)
unsigned int offset_bytes = 0; unsigned int offset_bytes = 0;
// must wait in order to read // must wait in order to read
rglGcmSetInvalidateVertexCache(thisContext); rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(ref, offset_bytes); rglGcmFifoFinish(fifo, ref, offset_bytes);
} }
rglBuffer->mapAccess = access; rglBuffer->mapAccess = access;
@ -1204,39 +1204,6 @@ GLenum rglPlatformFramebufferCheckStatus (void *data)
#define RGLGCM_MAX_VERTEX_BUFFER_SIZE (2 << 20) #define RGLGCM_MAX_VERTEX_BUFFER_SIZE (2 << 20)
#define RGLGCM_MAX_INDEX_BUFFER_SIZE (1 << 20) #define RGLGCM_MAX_INDEX_BUFFER_SIZE (1 << 20)
// Initialize the driver and setup the fixed function pipeline
// shader and needed connections between GL state and the shader
void *rglPlatformRasterInit (void)
{
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo;
GLuint ref;
unsigned int offset_bytes = 0;
rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(ref, offset_bytes);
rglGcmDriver *driver = (rglGcmDriver*)malloc(sizeof(rglGcmDriver));
memset(driver, 0, sizeof(rglGcmDriver));
driver->rt.yInverted = true;
driver->invalidateVertexCache = GL_FALSE;
driver->flushBufferCount = 0;
// [YLIN] Make it 16 byte align
return driver;
}
// Destroy the driver, and free all its used memory
void rglPlatformRasterExit (void *data)
{
rglGcmDriver *driver = (rglGcmDriver*)data;
if (driver)
free(driver);
}
void rglDumpFifo (char *name); void rglDumpFifo (char *name);
#undef RGLGCM_REMAP_MODES #undef RGLGCM_REMAP_MODES
@ -2449,26 +2416,6 @@ GLenum rglPlatformChooseInternalStorage (void *data, GLenum internalFormat )
return GL_NO_ERROR; return GL_NO_ERROR;
} }
static inline void textureReferences_pushBack(rglTexture *element)
{
RGLcontext* LContext = (RGLcontext*)_CurrentContext;
rglTexture *texture = (rglTexture*)rglGetCurrentTexture( LContext->CurrentImageUnit, GL_TEXTURE_2D );
rglBufferObject *bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[LContext->TextureBuffer];
uint32_t newCapacity = bufferObject->textureReferences.count + 1;
if (newCapacity > bufferObject->textureReferences.capacity)
{
if ( newCapacity > bufferObject->textureReferences.capacity )
newCapacity = ( newCapacity > bufferObject->textureReferences.capacity + bufferObject->textureReferences.increment ) ? newCapacity : ( bufferObject->textureReferences.capacity + bufferObject->textureReferences.increment );
bufferObject->textureReferences.array = (rglTexture**)realloc((void *)(bufferObject->textureReferences.array), sizeof(rglTexture) * newCapacity);
bufferObject->textureReferences.capacity = newCapacity;
}
new((void *)(bufferObject->textureReferences.array + bufferObject->textureReferences.count))rglTexture((const rglTexture&)element);
++bufferObject->textureReferences.count;
}
GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels,
GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset ) GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset )
{ {
@ -2543,7 +2490,18 @@ GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels,
texture->revalidate |= RGL_TEXTURE_REVALIDATE_PARAMETERS; texture->revalidate |= RGL_TEXTURE_REVALIDATE_PARAMETERS;
rglTextureTouchFBOs( texture ); rglTextureTouchFBOs( texture );
textureReferences_pushBack(texture); uint32_t newCapacity = bufferObject->textureReferences.count + 1;
if (newCapacity > bufferObject->textureReferences.capacity)
{
if ( newCapacity > bufferObject->textureReferences.capacity )
newCapacity = ( newCapacity > bufferObject->textureReferences.capacity + bufferObject->textureReferences.increment ) ? newCapacity : ( bufferObject->textureReferences.capacity + bufferObject->textureReferences.increment );
bufferObject->textureReferences.array = (rglTexture**)realloc((void *)(bufferObject->textureReferences.array), sizeof(rglTexture) * newCapacity);
bufferObject->textureReferences.capacity = newCapacity;
}
new((void *)(bufferObject->textureReferences.array + bufferObject->textureReferences.count))rglTexture((const rglTexture&)texture);
++bufferObject->textureReferences.count;
texture->referenceBuffer = bufferObject; texture->referenceBuffer = bufferObject;
texture->offset = offset; texture->offset = offset;