(RGL PS3) Cleanups
This commit is contained in:
parent
6f5b28cd60
commit
664d6e6e06
|
@ -76,19 +76,15 @@ unsigned int rglCreateName(void *data, void* object)
|
||||||
{
|
{
|
||||||
rglNameSpace *name = (rglNameSpace*)data;
|
rglNameSpace *name = (rglNameSpace*)data;
|
||||||
// NULL is reserved for the guard of the linked list.
|
// NULL is reserved for the guard of the linked list.
|
||||||
if (name->firstFree == NULL)
|
if (!name->firstFree)
|
||||||
{
|
{
|
||||||
// need to allocate more pointer space
|
// need to allocate more pointer space
|
||||||
int newCapacity = name->capacity + NAME_INCREMENT;
|
int newCapacity = name->capacity + NAME_INCREMENT;
|
||||||
|
|
||||||
// realloc the block of pointers
|
// realloc the block of pointers
|
||||||
void** newData = ( void** )malloc( newCapacity * sizeof( void* ) );
|
void** newData = ( void** )malloc( newCapacity * sizeof( void* ) );
|
||||||
if ( newData == NULL )
|
if (!newData)
|
||||||
{
|
|
||||||
// XXX what should we generally do here ?
|
|
||||||
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
memcpy( newData, name->data, name->capacity * sizeof( void* ) );
|
memcpy( newData, name->data, name->capacity * sizeof( void* ) );
|
||||||
|
|
||||||
if (name->data != NULL)
|
if (name->data != NULL)
|
||||||
|
@ -292,7 +288,7 @@ static uint32_t gmmInitFixedAllocator(void)
|
||||||
|
|
||||||
pGmmFixedAllocData = (GmmFixedAllocData *)malloc(sizeof(GmmFixedAllocData));
|
pGmmFixedAllocData = (GmmFixedAllocData *)malloc(sizeof(GmmFixedAllocData));
|
||||||
|
|
||||||
if (pGmmFixedAllocData == NULL)
|
if (!pGmmFixedAllocData)
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
memset(pGmmFixedAllocData, 0, sizeof(GmmFixedAllocData));
|
memset(pGmmFixedAllocData, 0, sizeof(GmmFixedAllocData));
|
||||||
|
@ -303,23 +299,23 @@ static uint32_t gmmInitFixedAllocator(void)
|
||||||
int blockSize = (i==0) ? sizeof(GmmBlock): sizeof(GmmTileBlock);
|
int blockSize = (i==0) ? sizeof(GmmBlock): sizeof(GmmTileBlock);
|
||||||
|
|
||||||
pGmmFixedAllocData->ppBlockList[i] = (char **)malloc(sizeof(char *));
|
pGmmFixedAllocData->ppBlockList[i] = (char **)malloc(sizeof(char *));
|
||||||
if (pGmmFixedAllocData->ppBlockList[i] == NULL)
|
if (!pGmmFixedAllocData->ppBlockList[i])
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
pGmmFixedAllocData->ppBlockList[i][0] = (char *)malloc(blockSize * blockCount);
|
pGmmFixedAllocData->ppBlockList[i][0] = (char *)malloc(blockSize * blockCount);
|
||||||
if (pGmmFixedAllocData->ppBlockList[i][0] == NULL)
|
if (!pGmmFixedAllocData->ppBlockList[i][0])
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
pGmmFixedAllocData->ppFreeBlockList[i] = (uint16_t **)malloc(sizeof(uint16_t *));
|
pGmmFixedAllocData->ppFreeBlockList[i] = (uint16_t **)malloc(sizeof(uint16_t *));
|
||||||
if (pGmmFixedAllocData->ppFreeBlockList[i] == NULL)
|
if (!pGmmFixedAllocData->ppFreeBlockList[i])
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
pGmmFixedAllocData->ppFreeBlockList[i][0] = (uint16_t *)malloc(sizeof(uint16_t) * blockCount);
|
pGmmFixedAllocData->ppFreeBlockList[i][0] = (uint16_t *)malloc(sizeof(uint16_t) * blockCount);
|
||||||
if (pGmmFixedAllocData->ppFreeBlockList[i][0] == NULL)
|
if (!pGmmFixedAllocData->ppFreeBlockList[i][0])
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
pGmmFixedAllocData->pBlocksUsed[i] = (uint16_t *)malloc(sizeof(uint16_t));
|
pGmmFixedAllocData->pBlocksUsed[i] = (uint16_t *)malloc(sizeof(uint16_t));
|
||||||
if (pGmmFixedAllocData->pBlocksUsed[i] == NULL)
|
if (!pGmmFixedAllocData->pBlocksUsed[i])
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
for (int j=0; j<blockCount; j++)
|
for (int j=0; j<blockCount; j++)
|
||||||
|
@ -352,7 +348,7 @@ static void *gmmAllocFixed(uint8_t isTile)
|
||||||
(char **)realloc(pGmmFixedAllocData->ppBlockList[isTile],
|
(char **)realloc(pGmmFixedAllocData->ppBlockList[isTile],
|
||||||
(listCount + 1) * sizeof(char *));
|
(listCount + 1) * sizeof(char *));
|
||||||
|
|
||||||
if (ppBlockList == NULL)
|
if (!ppBlockList)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pGmmFixedAllocData->ppBlockList[isTile] = ppBlockList;
|
pGmmFixedAllocData->ppBlockList[isTile] = ppBlockList;
|
||||||
|
@ -360,14 +356,14 @@ static void *gmmAllocFixed(uint8_t isTile)
|
||||||
pGmmFixedAllocData->ppBlockList[isTile][listCount] =
|
pGmmFixedAllocData->ppBlockList[isTile][listCount] =
|
||||||
(char *)malloc(blockSize * blockCount);
|
(char *)malloc(blockSize * blockCount);
|
||||||
|
|
||||||
if (pGmmFixedAllocData->ppBlockList[isTile][listCount] == NULL)
|
if (!pGmmFixedAllocData->ppBlockList[isTile][listCount])
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
uint16_t **ppFreeBlockList =
|
uint16_t **ppFreeBlockList =
|
||||||
(uint16_t **)realloc(pGmmFixedAllocData->ppFreeBlockList[isTile],
|
(uint16_t **)realloc(pGmmFixedAllocData->ppFreeBlockList[isTile],
|
||||||
(listCount + 1) * sizeof(uint16_t *));
|
(listCount + 1) * sizeof(uint16_t *));
|
||||||
|
|
||||||
if (ppFreeBlockList == NULL)
|
if (!ppFreeBlockList)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pGmmFixedAllocData->ppFreeBlockList[isTile] = ppFreeBlockList;
|
pGmmFixedAllocData->ppFreeBlockList[isTile] = ppFreeBlockList;
|
||||||
|
@ -375,14 +371,14 @@ static void *gmmAllocFixed(uint8_t isTile)
|
||||||
pGmmFixedAllocData->ppFreeBlockList[isTile][listCount] =
|
pGmmFixedAllocData->ppFreeBlockList[isTile][listCount] =
|
||||||
(uint16_t *)malloc(sizeof(uint16_t) * blockCount);
|
(uint16_t *)malloc(sizeof(uint16_t) * blockCount);
|
||||||
|
|
||||||
if (pGmmFixedAllocData->ppFreeBlockList[isTile][listCount] == NULL)
|
if (!pGmmFixedAllocData->ppFreeBlockList[isTile][listCount])
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
uint16_t *pBlocksUsed =
|
uint16_t *pBlocksUsed =
|
||||||
(uint16_t *)realloc(pGmmFixedAllocData->pBlocksUsed[isTile],
|
(uint16_t *)realloc(pGmmFixedAllocData->pBlocksUsed[isTile],
|
||||||
(listCount + 1) * sizeof(uint16_t));
|
(listCount + 1) * sizeof(uint16_t));
|
||||||
|
|
||||||
if (pBlocksUsed == NULL)
|
if (!pBlocksUsed)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pGmmFixedAllocData->pBlocksUsed[isTile] = pBlocksUsed;
|
pGmmFixedAllocData->pBlocksUsed[isTile] = pBlocksUsed;
|
||||||
|
@ -452,7 +448,7 @@ static uint32_t gmmInit(const void *localMemoryBase, const void *localStartAddre
|
||||||
|
|
||||||
pAllocator = (GmmAllocator *)malloc(sizeof(GmmAllocator));
|
pAllocator = (GmmAllocator *)malloc(sizeof(GmmAllocator));
|
||||||
|
|
||||||
if (pAllocator == NULL)
|
if (!pAllocator)
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
memset(pAllocator, 0, sizeof(GmmAllocator));
|
memset(pAllocator, 0, sizeof(GmmAllocator));
|
||||||
|
@ -539,7 +535,7 @@ static GmmBlock *gmmAllocBlock(
|
||||||
address + size <= pAllocator->startAddress + pAllocator->size)
|
address + size <= pAllocator->startAddress + pAllocator->size)
|
||||||
{
|
{
|
||||||
pNewBlock = GMM_ALLOC_FIXED_BLOCK();
|
pNewBlock = GMM_ALLOC_FIXED_BLOCK();
|
||||||
if (pNewBlock == NULL)
|
if (!pNewBlock)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(pNewBlock, 0, sizeof(GmmBlock));
|
memset(pNewBlock, 0, sizeof(GmmBlock));
|
||||||
|
@ -594,7 +590,7 @@ static GmmTileBlock *gmmFindFreeTileBlock(
|
||||||
if (pBestAfterBlock)
|
if (pBestAfterBlock)
|
||||||
{
|
{
|
||||||
pNewBlock = gmmAllocFixedTileBlock();
|
pNewBlock = gmmAllocFixedTileBlock();
|
||||||
if (pNewBlock == NULL)
|
if (!pNewBlock)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(pNewBlock, 0, sizeof(GmmTileBlock));
|
memset(pNewBlock, 0, sizeof(GmmTileBlock));
|
||||||
|
@ -636,7 +632,7 @@ static GmmTileBlock *gmmCreateTileBlock(
|
||||||
pAllocator->tileStartAddress = address;
|
pAllocator->tileStartAddress = address;
|
||||||
|
|
||||||
pNewBlock = gmmAllocFixedTileBlock();
|
pNewBlock = gmmAllocFixedTileBlock();
|
||||||
if (pNewBlock == NULL)
|
if (!pNewBlock)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(pNewBlock, 0, sizeof(GmmTileBlock));
|
memset(pNewBlock, 0, sizeof(GmmTileBlock));
|
||||||
|
@ -728,7 +724,7 @@ static uint32_t gmmAllocExtendedTileBlock(const uint32_t size, const uint32_t ta
|
||||||
(pBlock->pPrev && pBlock->base.address-pBlock->pPrev->base.address-pBlock->pPrev->base.size >= newSize))
|
(pBlock->pPrev && pBlock->base.address-pBlock->pPrev->base.address-pBlock->pPrev->base.size >= newSize))
|
||||||
{
|
{
|
||||||
GmmTileBlock *pNewBlock = gmmAllocFixedTileBlock();
|
GmmTileBlock *pNewBlock = gmmAllocFixedTileBlock();
|
||||||
if (pNewBlock == NULL)
|
if (!pNewBlock)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
retId = (uint32_t)pNewBlock;
|
retId = (uint32_t)pNewBlock;
|
||||||
|
@ -820,7 +816,7 @@ static void gmmFreeBlock (void *data)
|
||||||
pAllocator->pTail->pNext = NULL;
|
pAllocator->pTail->pNext = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlock->pPrev == NULL)
|
if (!pBlock->pPrev)
|
||||||
pAllocator->pSweepHead = pAllocator->pHead;
|
pAllocator->pSweepHead = pAllocator->pHead;
|
||||||
else if (pBlock->pPrev &&
|
else if (pBlock->pPrev &&
|
||||||
(pAllocator->pSweepHead == NULL ||
|
(pAllocator->pSweepHead == NULL ||
|
||||||
|
@ -928,7 +924,7 @@ static void gmmAddFree(
|
||||||
while (pInsertBefore && pInsertBefore->base.size < pBlock->base.size)
|
while (pInsertBefore && pInsertBefore->base.size < pBlock->base.size)
|
||||||
pInsertBefore = pInsertBefore->pNextFree;
|
pInsertBefore = pInsertBefore->pNextFree;
|
||||||
|
|
||||||
if (pInsertBefore == NULL)
|
if (!pInsertBefore)
|
||||||
{
|
{
|
||||||
pBlock->pNextFree = NULL;
|
pBlock->pNextFree = NULL;
|
||||||
pBlock->pPrevFree = pAllocator->pFreeTail[freeIndex];
|
pBlock->pPrevFree = pAllocator->pFreeTail[freeIndex];
|
||||||
|
@ -1166,7 +1162,7 @@ static uint8_t gmmInternalSweep(void *data)
|
||||||
srcAddress = 0;
|
srcAddress = 0;
|
||||||
dstAddress = 0;
|
dstAddress = 0;
|
||||||
|
|
||||||
if (pBlock->pPrev == NULL)
|
if (!pBlock->pPrev)
|
||||||
availableSize = pBlock->base.address - pAllocator->startAddress;
|
availableSize = pBlock->base.address - pAllocator->startAddress;
|
||||||
else
|
else
|
||||||
availableSize = pBlock->base.address - (pBlock->pPrev->base.address + pBlock->pPrev->base.size);
|
availableSize = pBlock->base.address - (pBlock->pPrev->base.address + pBlock->pPrev->base.size);
|
||||||
|
@ -1368,7 +1364,7 @@ static uint32_t gmmFindFreeBlock(
|
||||||
if (pBlock->base.size != size)
|
if (pBlock->base.size != size)
|
||||||
{
|
{
|
||||||
GmmBlock *pNewBlock = GMM_ALLOC_FIXED_BLOCK();
|
GmmBlock *pNewBlock = GMM_ALLOC_FIXED_BLOCK();
|
||||||
if (pNewBlock == NULL)
|
if (!pNewBlock)
|
||||||
return GMM_ERROR;
|
return GMM_ERROR;
|
||||||
|
|
||||||
memset(pNewBlock, 0, sizeof(GmmBlock));
|
memset(pNewBlock, 0, sizeof(GmmBlock));
|
||||||
|
|
|
@ -103,7 +103,7 @@ static int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramH
|
||||||
program->rtParametersCount = parameterHeader->entryCount;
|
program->rtParametersCount = parameterHeader->entryCount;
|
||||||
program->runtimeParameters = ( CgRuntimeParameter* )memoryBlock;
|
program->runtimeParameters = ( CgRuntimeParameter* )memoryBlock;
|
||||||
|
|
||||||
if ( parameterEntries == NULL ) // the param entry can be supplied if not right after parameterHeader in memory, it happens when there's a program copy
|
if (!parameterEntries) // the param entry can be supplied if not right after parameterHeader in memory, it happens when there's a program copy
|
||||||
parameterEntries = ( CgParameterEntry* )( parameterHeader + 1 );
|
parameterEntries = ( CgParameterEntry* )( parameterHeader + 1 );
|
||||||
|
|
||||||
program->parametersEntries = parameterEntries;
|
program->parametersEntries = parameterEntries;
|
||||||
|
@ -231,11 +231,8 @@ static CGprogramGroup rglCgCreateProgramGroupFromFile( CGcontext ctx, const char
|
||||||
// check that file exists
|
// check that file exists
|
||||||
FILE* fp = fopen( group_file, "rb" );
|
FILE* fp = fopen( group_file, "rb" );
|
||||||
|
|
||||||
if (fp == NULL)
|
if (!fp)
|
||||||
{
|
|
||||||
rglCgRaiseError( CG_FILE_READ_ERROR );
|
|
||||||
return ( CGprogramGroup )NULL;
|
return ( CGprogramGroup )NULL;
|
||||||
}
|
|
||||||
|
|
||||||
// find the file length
|
// find the file length
|
||||||
size_t file_size = 0;
|
size_t file_size = 0;
|
||||||
|
@ -844,7 +841,7 @@ static int rglGetSizeofSubArray( const short *dimensions, int count )
|
||||||
|
|
||||||
static _CGparameter *_cgGetNamedParameter( _CGprogram* progPtr, const char* name, CGenum name_space, int *arrayIndex, const CgParameterEntry *_startEntry = NULL, int _entryCount = -1 )
|
static _CGparameter *_cgGetNamedParameter( _CGprogram* progPtr, const char* name, CGenum name_space, int *arrayIndex, const CgParameterEntry *_startEntry = NULL, int _entryCount = -1 )
|
||||||
{
|
{
|
||||||
if ( name == NULL )
|
if (!name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*arrayIndex = -1;
|
*arrayIndex = -1;
|
||||||
|
@ -875,7 +872,7 @@ static _CGparameter *_cgGetNamedParameter( _CGprogram* progPtr, const char* name
|
||||||
while (( !done ) && ( *structureStart ) && ( containerCount != -1 ) )
|
while (( !done ) && ( *structureStart ) && ( containerCount != -1 ) )
|
||||||
{
|
{
|
||||||
structureEnd = strpbrk( structureStart, ".[" );
|
structureEnd = strpbrk( structureStart, ".[" );
|
||||||
if ( structureEnd == NULL )
|
if (!structureEnd)
|
||||||
{
|
{
|
||||||
structureEnd = structureStart + strlen( structureStart );
|
structureEnd = structureStart + strlen( structureStart );
|
||||||
done = 1;
|
done = 1;
|
||||||
|
@ -1515,7 +1512,7 @@ _CGprogram* rglCgProgramFindPrev( _CGcontext* ctx, _CGprogram* prog )
|
||||||
|
|
||||||
_CGprogram* ptr = ctx->programList;
|
_CGprogram* ptr = ctx->programList;
|
||||||
|
|
||||||
while ( ptr != NULL && prog != ptr->next )
|
while (ptr && prog != ptr->next )
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -1880,7 +1877,7 @@ void AccumulateSizeForParamResource( CgParameterEntry* paramEntry, CgParameterEn
|
||||||
defaults = ( float* )consttab->data + defaultIndex->defaultValueIndex;
|
defaults = ( float* )consttab->data + defaultIndex->defaultValueIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( defaults )
|
if (defaults)
|
||||||
{
|
{
|
||||||
// defaults are always padded to 4 floats per param
|
// defaults are always padded to 4 floats per param
|
||||||
unsigned int defaultsCount = ( rowCount ? rowCount : 1 ) * 4;
|
unsigned int defaultsCount = ( rowCount ? rowCount : 1 ) * 4;
|
||||||
|
@ -1890,7 +1887,7 @@ void AccumulateSizeForParamResource( CgParameterEntry* paramEntry, CgParameterEn
|
||||||
// offsets
|
// offsets
|
||||||
// fragment programs
|
// fragment programs
|
||||||
// do we want this referenced param test???
|
// do we want this referenced param test???
|
||||||
if ( nvParamOffsetsSize != NULL && paramEntry->flags & CGPF_REFERENCED )
|
if (nvParamOffsetsSize && paramEntry->flags & CGPF_REFERENCED )
|
||||||
{
|
{
|
||||||
// non varying params
|
// non varying params
|
||||||
if ( paramEntry->flags & CGPV_CONSTANT || paramEntry->flags & CGPV_UNIFORM )
|
if ( paramEntry->flags & CGPV_CONSTANT || paramEntry->flags & CGPV_UNIFORM )
|
||||||
|
@ -2180,7 +2177,7 @@ void PopulateDataForParamResource( CgParameterEntry* paramEntry, CgParameterEntr
|
||||||
}
|
}
|
||||||
|
|
||||||
// vertex programs
|
// vertex programs
|
||||||
if ( nvParamOffsets == NULL )
|
if (!nvParamOffsets)
|
||||||
{
|
{
|
||||||
// element of an array
|
// element of an array
|
||||||
if ( elementResourceIndex >= 0 )
|
if ( elementResourceIndex >= 0 )
|
||||||
|
@ -2500,7 +2497,7 @@ void PopulateDataForParamArray( CgParameterEntry* paramEntry, CgParameterEntry*
|
||||||
// rest of array name for array and index
|
// rest of array name for array and index
|
||||||
sprintf( *nvParamStrings, "%s[%d]", ( strtab->data + paramEntry->nameOffset ), element );
|
sprintf( *nvParamStrings, "%s[%d]", ( strtab->data + paramEntry->nameOffset ), element );
|
||||||
|
|
||||||
if ( prefix == NULL )
|
if (!prefix)
|
||||||
prefix = *nvParamStrings;
|
prefix = *nvParamStrings;
|
||||||
|
|
||||||
*nvParamStrings += strlen( *nvParamStrings );
|
*nvParamStrings += strlen( *nvParamStrings );
|
||||||
|
@ -2574,7 +2571,7 @@ void PopulateDataForParamStruct( CgParameterEntry* paramEntry, CgParameterEntry*
|
||||||
CgParameterEntry* memberEntry = paramEntry + 1;
|
CgParameterEntry* memberEntry = paramEntry + 1;
|
||||||
|
|
||||||
// set the prefix pointer if it is not already set
|
// set the prefix pointer if it is not already set
|
||||||
if ( prefix == NULL )
|
if (!prefix)
|
||||||
prefix = *nvParamStrings;
|
prefix = *nvParamStrings;
|
||||||
|
|
||||||
// add prefix of struct name and .
|
// add prefix of struct name and .
|
||||||
|
@ -2790,7 +2787,7 @@ static bool cgGetElfProgramByName( CGELFBinary *elfBinary, const char *name, CGE
|
||||||
{
|
{
|
||||||
//if no name try to return the first program
|
//if no name try to return the first program
|
||||||
int res;
|
int res;
|
||||||
if ( name == NULL || name[0] == '\0' )
|
if (!name || name[0] == '\0' )
|
||||||
res = 0;
|
res = 0;
|
||||||
else
|
else
|
||||||
res = lookupSymbolValueInPlace( elfBinary->symtab, elfBinary->symbolSize, elfBinary->symbolCount, elfBinary->symbolstrtab, name );
|
res = lookupSymbolValueInPlace( elfBinary->symtab, elfBinary->symbolSize, elfBinary->symbolCount, elfBinary->symbolstrtab, name );
|
||||||
|
@ -3108,7 +3105,7 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
|
||||||
if ( groupName && !strcmp( groupName, program_file ) )
|
if ( groupName && !strcmp( groupName, program_file ) )
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
if ( entry == NULL )
|
if (!entry)
|
||||||
index = 0;
|
index = 0;
|
||||||
else
|
else
|
||||||
index = rglCgGetProgramIndex( group, entry );
|
index = rglCgGetProgramIndex( group, entry );
|
||||||
|
@ -3135,11 +3132,8 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
|
||||||
// check that file exists
|
// check that file exists
|
||||||
fp = fopen( program_file, "rb" );
|
fp = fopen( program_file, "rb" );
|
||||||
|
|
||||||
if (fp == NULL)
|
if (!fp)
|
||||||
{
|
|
||||||
rglCgRaiseError( CG_FILE_READ_ERROR );
|
|
||||||
return ( CGprogram )NULL;
|
return ( CGprogram )NULL;
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int filetag = 0;
|
unsigned int filetag = 0;
|
||||||
int res = fread( &filetag, sizeof( filetag ), 1, fp );
|
int res = fread( &filetag, sizeof( filetag ), 1, fp );
|
||||||
|
@ -3159,7 +3153,7 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
|
||||||
{
|
{
|
||||||
_CGprogramGroup *_group = ( _CGprogramGroup * )group;
|
_CGprogramGroup *_group = ( _CGprogramGroup * )group;
|
||||||
_group->userCreated = false;
|
_group->userCreated = false;
|
||||||
if ( entry == NULL )
|
if (!entry)
|
||||||
{
|
{
|
||||||
if ( group->programCount == 1 )
|
if ( group->programCount == 1 )
|
||||||
{
|
{
|
||||||
|
@ -3188,11 +3182,8 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
|
||||||
if ( !fp )
|
if ( !fp )
|
||||||
{
|
{
|
||||||
fp = fopen( program_file, "rb" );
|
fp = fopen( program_file, "rb" );
|
||||||
if (fp == NULL)
|
if (!fp)
|
||||||
{
|
|
||||||
rglCgRaiseError( CG_FILE_READ_ERROR );
|
|
||||||
return ( CGprogram )NULL;
|
return ( CGprogram )NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the file length
|
// find the file length
|
||||||
|
@ -3203,11 +3194,10 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
|
||||||
|
|
||||||
// alloc memory for the file
|
// alloc memory for the file
|
||||||
char* ptr = ( char* )malloc( file_size + 1 );
|
char* ptr = ( char* )malloc( file_size + 1 );
|
||||||
if (ptr == NULL)
|
if (!ptr)
|
||||||
{
|
{
|
||||||
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
|
fclose(fp);
|
||||||
fclose( fp );
|
return (CGprogram)NULL;
|
||||||
return ( CGprogram )NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the entire file into memory then close the file
|
// read the entire file into memory then close the file
|
||||||
|
@ -3234,16 +3224,11 @@ CG_API CGprogram cgCopyProgram( CGprogram program )
|
||||||
// check input parameter
|
// check input parameter
|
||||||
|
|
||||||
if ( !CG_IS_PROGRAM( program ) )
|
if ( !CG_IS_PROGRAM( program ) )
|
||||||
{
|
|
||||||
rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR );
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
_CGprogram* prog = _cgGetProgPtr( program );
|
_CGprogram* prog = _cgGetProgPtr( program );
|
||||||
if (prog == NULL)
|
if (!prog)
|
||||||
{
|
|
||||||
rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR );
|
|
||||||
return ( CGprogram )NULL;
|
return ( CGprogram )NULL;
|
||||||
}
|
|
||||||
|
|
||||||
_CGprogram* newprog;
|
_CGprogram* newprog;
|
||||||
size_t paddedProgramSize = 0;
|
size_t paddedProgramSize = 0;
|
||||||
|
@ -3647,10 +3632,14 @@ CGGL_API void cgGLSetTextureParameter( CGparameter param, GLuint texobj )
|
||||||
CGGL_API GLuint cgGLGetTextureParameter( CGparameter param )
|
CGGL_API GLuint cgGLGetTextureParameter( CGparameter param )
|
||||||
{
|
{
|
||||||
CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param );
|
CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param );
|
||||||
if ( ptr == NULL ) return 0;
|
if (!ptr)
|
||||||
if ( !( ptr->parameterEntry->flags & CGPF_REFERENCED ) ) { rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); return 0; }
|
return 0;
|
||||||
|
if (!(ptr->parameterEntry->flags & CGPF_REFERENCED))
|
||||||
|
{
|
||||||
|
rglCgRaiseError( CG_INVALID_PARAMETER_ERROR );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return *( GLuint* )ptr->pushBufferPointer;
|
return *( GLuint* )ptr->pushBufferPointer;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGGL_API void cgGLEnableTextureParameter( CGparameter param )
|
CGGL_API void cgGLEnableTextureParameter( CGparameter param )
|
||||||
|
@ -4044,7 +4033,7 @@ int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness
|
||||||
}
|
}
|
||||||
|
|
||||||
// test if we are done finding structural information
|
// test if we are done finding structural information
|
||||||
if (structureEnd == NULL)
|
if (!structureEnd)
|
||||||
{
|
{
|
||||||
//set structureEnd correctly so that the rest of the function performs correctly
|
//set structureEnd correctly so that the rest of the function performs correctly
|
||||||
structureEnd = structureStart + strlen(structureStart);
|
structureEnd = structureStart + strlen(structureStart);
|
||||||
|
|
|
@ -76,29 +76,26 @@ static void setAttribConstantIndex (void *data, const void* __restrict v, const
|
||||||
}
|
}
|
||||||
|
|
||||||
//here ec has been advanced and is already on top of the embedded constant count
|
//here ec has been advanced and is already on top of the embedded constant count
|
||||||
template<int SIZE> inline static void swapandsetfp( int ucodeSize, unsigned int loadProgramId, unsigned int loadProgramOffset, unsigned short *ec, const unsigned int * __restrict v )
|
#define swapandsetfp(SIZE, ucodeSize, loadProgramId, loadProgramOffset, ec, v) \
|
||||||
{
|
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; \
|
||||||
CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext;
|
rglGcmSetTransferLocation(thisContext, CELL_GCM_LOCATION_LOCAL ); \
|
||||||
rglGcmSetTransferLocation(thisContext, CELL_GCM_LOCATION_LOCAL );
|
unsigned short count = *( ec++ ); \
|
||||||
unsigned short count = *( ec++ );
|
for ( unsigned long offsetIndex = 0; offsetIndex < count; ++offsetIndex ) \
|
||||||
for ( unsigned long offsetIndex = 0; offsetIndex < count; ++offsetIndex )
|
{ \
|
||||||
{
|
void *pointer=NULL; \
|
||||||
void *pointer=NULL;
|
const int paddedSIZE = (SIZE + 1) & ~1; /* even width only */ \
|
||||||
const int paddedSIZE = (SIZE + 1) & ~1; // even width only
|
uint32_t var = gmmIdToOffset( loadProgramId ) + loadProgramOffset + *( ec++ ); \
|
||||||
uint32_t var = gmmIdToOffset( loadProgramId ) + loadProgramOffset + *( ec++ );
|
rglGcmSetInlineTransferPointer(thisContext, var, paddedSIZE, pointer); \
|
||||||
rglGcmSetInlineTransferPointer(thisContext, var, paddedSIZE, pointer);
|
float *fp = (float*)pointer; \
|
||||||
float *fp = (float*)pointer;
|
float *src = (float*)v; \
|
||||||
float *src = (float*)v;
|
for (uint32_t j=0; j<SIZE;j++) \
|
||||||
for (uint32_t j=0; j<SIZE;j++)
|
{ \
|
||||||
{
|
rglGcmSwap16Float32(fp, src); \
|
||||||
rglGcmSwap16Float32(fp, src);
|
fp++; \
|
||||||
fp++;
|
src++; \
|
||||||
src++;
|
} \
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int SIZE> static void setVectorTypefp( void *dat, const void* __restrict v )
|
template<int SIZE> static void setVectorTypefp( void *dat, const void* __restrict v )
|
||||||
{
|
{
|
||||||
CgRuntimeParameter *ptr = (CgRuntimeParameter*)dat;
|
CgRuntimeParameter *ptr = (CgRuntimeParameter*)dat;
|
||||||
|
@ -113,7 +110,7 @@ template<int SIZE> static void setVectorTypefp( void *dat, const void* __restric
|
||||||
unsigned short *ec = ( unsigned short * )( ptr->program->resources ) + resource + 1;//+1 to skip the register
|
unsigned short *ec = ( unsigned short * )( ptr->program->resources ) + resource + 1;//+1 to skip the register
|
||||||
if ( RGL_LIKELY( *ec ) )
|
if ( RGL_LIKELY( *ec ) )
|
||||||
{
|
{
|
||||||
swapandsetfp<SIZE>( program->header.instructionCount*16, program->loadProgramId, program->loadProgramOffset, ec, ( unsigned int * )data );
|
swapandsetfp(SIZE, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +161,9 @@ template<int SIZE, bool isIndex> static void setVectorTypefpIndex (void *dat, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( RGL_LIKELY( *ec ) )
|
if ( RGL_LIKELY( *ec ) )
|
||||||
swapandsetfp<SIZE>( program->header.instructionCount*16, program->loadProgramId, program->loadProgramOffset, ec, ( unsigned int * )data );
|
{
|
||||||
|
swapandsetfp(SIZE, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//matrices
|
//matrices
|
||||||
|
@ -212,7 +211,8 @@ template <int ROWS, int COLS, int ORDER> static void setMatrixfpIndex (void *dat
|
||||||
int count = *ec;
|
int count = *ec;
|
||||||
if ( RGL_LIKELY( count ) )
|
if ( RGL_LIKELY( count ) )
|
||||||
{
|
{
|
||||||
swapandsetfp<COLS>( program->header.instructionCount*16, program->loadProgramId, program->loadProgramOffset, ec, ( unsigned int * )dst + row * 4 );
|
const unsigned int * __restrict v = ( unsigned int * )dst + row * 4;
|
||||||
|
swapandsetfp(COLS, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, v);
|
||||||
}
|
}
|
||||||
ec += count + 2; //+1 for the register, +1 for the count, + count for the number of embedded consts
|
ec += count + 2; //+1 for the register, +1 for the count, + count for the number of embedded consts
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,8 @@ template <int ROWS, int COLS, int ORDER> static void setMatrixfpIndexArray (void
|
||||||
int count = *ec;
|
int count = *ec;
|
||||||
if ( RGL_LIKELY( count ) )
|
if ( RGL_LIKELY( count ) )
|
||||||
{
|
{
|
||||||
swapandsetfp<COLS>( program->header.instructionCount*16, program->loadProgramId, program->loadProgramOffset, ec, ( unsigned int * )dst + row * 4 );
|
const unsigned int * __restrict v = ( unsigned int * )dst + row * 4;
|
||||||
|
swapandsetfp(COLS, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, v);
|
||||||
}
|
}
|
||||||
ec += count + 2;//+1 for the register, +1 for the count, +count for the number of embedded consts
|
ec += count + 2;//+1 for the register, +1 for the count, +count for the number of embedded consts
|
||||||
}
|
}
|
||||||
|
@ -473,7 +474,6 @@ void rglCreatePushBuffer(void *data)
|
||||||
program->constantPushBufferWordSize = bufferSize;
|
program->constantPushBufferWordSize = bufferSize;
|
||||||
GLuint *currentStorage = ( GLuint * )( rglGcmCurrent + bufferSize );
|
GLuint *currentStorage = ( GLuint * )( rglGcmCurrent + bufferSize );
|
||||||
|
|
||||||
int outOfMemory = 0;
|
|
||||||
//second pass to fill the buffer
|
//second pass to fill the buffer
|
||||||
arrayCount = 1;
|
arrayCount = 1;
|
||||||
const CgParameterEntry *containerEntry = NULL;
|
const CgParameterEntry *containerEntry = NULL;
|
||||||
|
@ -494,10 +494,7 @@ void rglCreatePushBuffer(void *data)
|
||||||
|
|
||||||
CGparameter id = ( CGparameter )rglCreateName( &_CurrentContext->cgParameterNameSpace, ( void* )rtParameter );
|
CGparameter id = ( CGparameter )rglCreateName( &_CurrentContext->cgParameterNameSpace, ( void* )rtParameter );
|
||||||
if ( !id )
|
if ( !id )
|
||||||
{
|
|
||||||
outOfMemory = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
rtParameter->id = id;
|
rtParameter->id = id;
|
||||||
rtParameter->parameterEntry = parameterEntry;
|
rtParameter->parameterEntry = parameterEntry;
|
||||||
|
@ -749,7 +746,7 @@ void rglCreatePushBuffer(void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//add padding
|
//add padding
|
||||||
if ( bufferSize > 0 )
|
if (bufferSize)
|
||||||
{
|
{
|
||||||
CellGcmContextData gcmContext, *thisContext;
|
CellGcmContextData gcmContext, *thisContext;
|
||||||
int i, nopCount;
|
int i, nopCount;
|
||||||
|
@ -1955,7 +1952,19 @@ void rglPlatformCreateTexture (void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void rglPlatformFreeGcmTexture (void *data);
|
// Free memory pooled by a GCM texture
|
||||||
|
static void rglPlatformFreeGcmTexture (void *data)
|
||||||
|
{
|
||||||
|
rglTexture *texture = (rglTexture*)data;
|
||||||
|
rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture;
|
||||||
|
|
||||||
|
if ( gcmTexture->pool == RGLGCM_SURFACE_POOL_LINEAR)
|
||||||
|
gmmFree( gcmTexture->gpuAddressId );
|
||||||
|
|
||||||
|
gcmTexture->gpuAddressId = GMM_ERROR;
|
||||||
|
gcmTexture->gpuAddressIdOffset = 0;
|
||||||
|
gcmTexture->gpuSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy a texture by freeing a gcm texture and an associated PBO
|
// Destroy a texture by freeing a gcm texture and an associated PBO
|
||||||
void rglPlatformDestroyTexture (void *data)
|
void rglPlatformDestroyTexture (void *data)
|
||||||
|
@ -1985,20 +1994,6 @@ void rglPlatformDropTexture (void *data)
|
||||||
rglTextureTouchFBOs( texture );
|
rglTextureTouchFBOs( texture );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free memory pooled by a GCM texture
|
|
||||||
void rglPlatformFreeGcmTexture (void *data)
|
|
||||||
{
|
|
||||||
rglTexture *texture = (rglTexture*)data;
|
|
||||||
rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture;
|
|
||||||
|
|
||||||
if ( gcmTexture->pool == RGLGCM_SURFACE_POOL_LINEAR)
|
|
||||||
gmmFree( gcmTexture->gpuAddressId );
|
|
||||||
|
|
||||||
gcmTexture->gpuAddressId = GMM_ERROR;
|
|
||||||
gcmTexture->gpuAddressIdOffset = 0;
|
|
||||||
gcmTexture->gpuSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate texture resources
|
// Validate texture resources
|
||||||
static void rglPlatformValidateTextureResources (void *data)
|
static void rglPlatformValidateTextureResources (void *data)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue