(RGL PS3) Simplify gmmAlloc

This commit is contained in:
twinaphex 2013-11-17 20:47:46 +01:00
parent de1bae69c9
commit dfddb4a530
5 changed files with 39 additions and 64 deletions

View File

@ -111,7 +111,8 @@ typedef struct GmmAllocator
uint32_t gmmDestroy(void); uint32_t gmmDestroy(void);
char *gmmIdToAddress(const uint32_t id); char *gmmIdToAddress(const uint32_t id);
uint32_t gmmFree (const uint32_t freeId); uint32_t gmmFree (const uint32_t freeId);
uint32_t gmmAlloc(const uint8_t isTile, const uint32_t size); uint32_t gmmAlloc(const uint32_t size);
uint32_t gmmAllocTiled(const uint32_t size);
extern GmmAllocator *pGmmLocalAllocator; extern GmmAllocator *pGmmLocalAllocator;

View File

@ -366,7 +366,7 @@ static inline void rglGcmSetVertexProgramParameterBlock(struct CellGcmContextDat
(thisContext->current) += 2; (thisContext->current) += 2;
#define rglGcmSend(dstId, dstOffset, pitch, src, size) \ #define rglGcmSend(dstId, dstOffset, pitch, src, size) \
GLuint id = gmmAlloc(0, size); \ GLuint id = gmmAlloc(size); \
memcpy( gmmIdToAddress(id), (src), size ); \ memcpy( gmmIdToAddress(id), (src), size ); \
rglGcmTransferData( dstId, dstOffset, size, id, 0, size, size, 1 ); \ rglGcmTransferData( dstId, dstOffset, size, id, 0, size, size, 1 ); \
gmmFree( id ) gmmFree( id )

View File

@ -1317,28 +1317,6 @@ static void gmmAllocSweep(void *data)
} }
} }
static uint32_t gmmInternalAlloc(
GmmAllocator *pAllocator,
const uint8_t isTile,
const uint32_t size
)
{
uint32_t retId;
if (isTile)
{
GmmTileBlock *pBlock = gmmFindFreeTileBlock(pAllocator, size);
retId = (uint32_t)gmmAllocTileBlock(pAllocator, size, pBlock);
}
else
retId = (uint32_t)gmmAllocBlock(pAllocator, size);
if (retId == 0)
return GMM_ERROR;
return retId;
}
static void gmmRemoveFree( static void gmmRemoveFree(
GmmAllocator *pAllocator, GmmAllocator *pAllocator,
GmmBlock *pBlock, GmmBlock *pBlock,
@ -1415,45 +1393,22 @@ static uint32_t gmmFindFreeBlock(
return retId; return retId;
} }
uint32_t gmmAlloc(const uint8_t isTile, const uint32_t size) uint32_t gmmAlloc(const uint32_t size)
{ {
GmmAllocator *pAllocator; GmmAllocator *pAllocator = pGmmLocalAllocator;
uint32_t retId; uint32_t newSize = PAD(size, GMM_ALIGNMENT);
uint32_t newSize; uint32_t retId = gmmFindFreeBlock(pAllocator, newSize);
if (size == 0)
return GMM_ERROR;
pAllocator = pGmmLocalAllocator;
if (!isTile)
{
newSize = PAD(size, GMM_ALIGNMENT);
retId = gmmFindFreeBlock(pAllocator, newSize);
}
else
{
newSize = PAD(size, GMM_TILE_ALIGNMENT);
retId = GMM_ERROR;
}
if (retId == GMM_ERROR) if (retId == GMM_ERROR)
{ {
retId = gmmInternalAlloc(pAllocator, retId = (uint32_t)gmmAllocBlock(pAllocator, newSize);
isTile,
newSize);
if (retId == GMM_ERROR) if (retId == GMM_ERROR)
{ {
gmmAllocSweep((CellGcmContextData*)&rglGcmState_i.fifo); gmmAllocSweep((CellGcmContextData*)&rglGcmState_i.fifo);
retId = (uint32_t)gmmAllocBlock(pAllocator, newSize);
retId = gmmInternalAlloc(pAllocator, if (retId == GMM_ERROR)
isTile,
newSize);
if (!isTile &&
retId == GMM_ERROR)
retId = gmmFindFreeBlock(pAllocator, newSize); retId = gmmFindFreeBlock(pAllocator, newSize);
} }
} }
@ -1461,6 +1416,25 @@ uint32_t gmmAlloc(const uint8_t isTile, const uint32_t size)
return retId; return retId;
} }
uint32_t gmmAllocTiled(const uint32_t size)
{
GmmAllocator *pAllocator = pGmmLocalAllocator;
uint32_t newSize = PAD(size, GMM_TILE_ALIGNMENT);
uint32_t retId = GMM_ERROR;
GmmTileBlock *pBlock = gmmFindFreeTileBlock(pAllocator, newSize);
retId = (uint32_t)gmmAllocTileBlock(pAllocator, newSize, pBlock);
if (retId == GMM_ERROR)
{
gmmAllocSweep((CellGcmContextData*)&rglGcmState_i.fifo);
pBlock = gmmFindFreeTileBlock(pAllocator, newSize);
retId = (uint32_t)gmmAllocTileBlock(pAllocator, newSize, pBlock);
}
return retId;
}
/*============================================================ /*============================================================
FIFO BUFFER FIFO BUFFER
============================================================ */ ============================================================ */
@ -2227,7 +2201,7 @@ GLuint rglGcmAllocCreateRegion(
{ {
uint32_t id; uint32_t id;
if ((id = gmmAlloc(1, size)) != GMM_ERROR) if ((id = gmmAllocTiled(size)) != GMM_ERROR)
{ {
if ( rglGcmTryResizeTileRegion( (GLuint)gmmIdToOffset(id), gmmGetBlockSize(id), data ) ) if ( rglGcmTryResizeTileRegion( (GLuint)gmmIdToOffset(id), gmmGetBlockSize(id), data ) )
{ {
@ -2510,8 +2484,8 @@ static void rescInit( const RGLdeviceParameters* params, rglGcmDevice *gcmDevice
// allocate space for vertex array and fragment shader for drawing the rescaling texture-mapped quad // allocate space for vertex array and fragment shader for drawing the rescaling texture-mapped quad
int32_t colorBuffersSize, vertexArraySize, fragmentShaderSize; int32_t colorBuffersSize, vertexArraySize, fragmentShaderSize;
cellRescGetBufferSize( &colorBuffersSize, &vertexArraySize, &fragmentShaderSize ); cellRescGetBufferSize( &colorBuffersSize, &vertexArraySize, &fragmentShaderSize );
gcmDevice->RescVertexArrayId = gmmAlloc(0, vertexArraySize); gcmDevice->RescVertexArrayId = gmmAlloc(vertexArraySize);
gcmDevice->RescFragmentShaderId = gmmAlloc(0, fragmentShaderSize); gcmDevice->RescFragmentShaderId = gmmAlloc(fragmentShaderSize);
// tell resc how to access the destination (scanout) buffer // tell resc how to access the destination (scanout) buffer
@ -2528,7 +2502,7 @@ static void rescInit( const RGLdeviceParameters* params, rglGcmDevice *gcmDevice
{ {
const unsigned int tableLength = 32; // this was based on the guidelines in the resc reference guide const unsigned int tableLength = 32; // this was based on the guidelines in the resc reference guide
unsigned int tableSize = sizeof(uint16_t) * 4 * tableLength; // 2 bytes per FLOAT16 * 4 values per entry * length of table unsigned int tableSize = sizeof(uint16_t) * 4 * tableLength; // 2 bytes per FLOAT16 * 4 values per entry * length of table
void *interlaceTable = gmmIdToAddress(gmmAlloc(0, tableSize)); void *interlaceTable = gmmIdToAddress(gmmAlloc(tableSize));
int32_t errorCode = cellRescCreateInterlaceTable(interlaceTable,params->renderHeight,CELL_RESC_ELEMENT_HALF,tableLength); int32_t errorCode = cellRescCreateInterlaceTable(interlaceTable,params->renderHeight,CELL_RESC_ELEMENT_HALF,tableLength);
(void)errorCode; (void)errorCode;
} }

View File

@ -181,7 +181,7 @@ static int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramH
if ( program->loadProgramId == GMM_ERROR ) if ( program->loadProgramId == GMM_ERROR )
{ {
program->loadProgramId = gmmAlloc(0, ucodeSize); program->loadProgramId = gmmAlloc(ucodeSize);
program->loadProgramOffset = 0; program->loadProgramOffset = 0;
} }

View File

@ -792,7 +792,7 @@ static void rglpsAllocateBuffer (void *data)
// allocate in GPU memory // allocate in GPU memory
rglBuffer->pool = RGLGCM_SURFACE_POOL_LINEAR; rglBuffer->pool = RGLGCM_SURFACE_POOL_LINEAR;
rglBuffer->bufferId = gmmAlloc(0, rglBuffer->bufferSize); rglBuffer->bufferId = gmmAlloc(rglBuffer->bufferSize);
rglBuffer->pitch = 0; rglBuffer->pitch = 0;
if ( rglBuffer->bufferId == GMM_ERROR ) if ( rglBuffer->bufferId == GMM_ERROR )
@ -1004,7 +1004,7 @@ static void rglPlatformBufferObjectSetDataTextureReference(void *buf_data, GLint
// partial buffer write // partial buffer write
// STREAM and DYNAMIC buffers get transfer via a bounce buffer. // STREAM and DYNAMIC buffers get transfer via a bounce buffer.
// copy via bounce buffer // copy via bounce buffer
GLuint id = gmmAlloc(0, size); GLuint id = gmmAlloc(size);
memset(gmmIdToAddress(id), 0, size); memset(gmmIdToAddress(id), 0, size);
rglGcmTransferData(rglBuffer->bufferId, offset, rglBuffer->pitch, id, 0, size, size, 1); rglGcmTransferData(rglBuffer->bufferId, offset, rglBuffer->pitch, id, 0, size, size, 1);
gmmFree(id); gmmFree(id);
@ -1723,7 +1723,7 @@ beginning:
GLuint VBOId = GMM_ERROR; GLuint VBOId = GMM_ERROR;
if ( RGL_UNLIKELY( dparams->xferTotalSize ) ) if ( RGL_UNLIKELY( dparams->xferTotalSize ) )
{ {
xferId = gmmAlloc(0, dparams->xferTotalSize); xferId = gmmAlloc(dparams->xferTotalSize);
xferBuffer = gmmIdToAddress(xferId); xferBuffer = gmmIdToAddress(xferId);
} }
@ -2082,7 +2082,7 @@ static void rglPlatformValidateTextureResources (void *data)
rglPlatformDropTexture( texture ); rglPlatformDropTexture( texture );
// allocate in the specified pool // allocate in the specified pool
id = gmmAlloc(0, size); id = gmmAlloc(size);
// set new // set new
gcmTexture->pool = RGLGCM_SURFACE_POOL_LINEAR; gcmTexture->pool = RGLGCM_SURFACE_POOL_LINEAR;
@ -2137,7 +2137,7 @@ source: RGLGCM_SURFACE_SOURCE_TEXTURE,
{ {
// lazy allocation of bounce buffer // lazy allocation of bounce buffer
if ( bounceBufferId == GMM_ERROR && layout->baseDepth == 1 ) if ( bounceBufferId == GMM_ERROR && layout->baseDepth == 1 )
bounceBufferId = gmmAlloc(0, gcmTexture->gpuSize); bounceBufferId = gmmAlloc(gcmTexture->gpuSize);
if ( bounceBufferId != GMM_ERROR ) if ( bounceBufferId != GMM_ERROR )
{ {