(RGL) Tweaks

This commit is contained in:
Twinaphex 2012-08-06 05:05:16 +02:00
parent fd3ee5a9dd
commit 7fb25a76c8
2 changed files with 256 additions and 273 deletions

View File

@ -107,7 +107,7 @@ GLuint nvFenceCounter = 0;
#define DECLARE_TYPE(TYPE,CTYPE,MAXVAL) \ #define DECLARE_TYPE(TYPE,CTYPE,MAXVAL) \
typedef CTYPE type_##TYPE; \ typedef CTYPE type_##TYPE; \
static inline type_##TYPE _RGLFloatTo_##TYPE(float v) { return (type_##TYPE)(_RGLClampf(v)*MAXVAL); } \ static inline type_##TYPE _RGLFloatTo_##TYPE(float v) { return (type_##TYPE)((MAX(MIN(v, 1.f), 0.f)) * MAXVAL); } \
static inline float _RGLFloatFrom_##TYPE(type_##TYPE v) { return ((float)v)/MAXVAL; } static inline float _RGLFloatFrom_##TYPE(type_##TYPE v) { return ((float)v)/MAXVAL; }
DECLARE_C_TYPES DECLARE_C_TYPES
#undef DECLARE_TYPE #undef DECLARE_TYPE
@ -256,55 +256,51 @@ static inline void _RGLFifoGlVertexAttribPointer
GLuint offset GLuint offset
) )
{ {
switch ( size )
{ switch(size)
case 0: {
stride = 0; case 0:
normalized = 0; stride = 0;
type = RGL_FLOAT; normalized = 0;
offset = 0; type = RGL_FLOAT;
break; offset = 0;
case 1: break;
case 2: case 1:
case 3: case 2:
case 4: case 3:
break; case 4:
default: break;
break; default:
} break;
}
uint8_t gcmType = 0; uint8_t gcmType = 0;
switch ( type ) switch ( type )
{ {
case RGL_UNSIGNED_BYTE: case RGL_UNSIGNED_BYTE:
if (normalized) if (normalized)
gcmType = CELL_GCM_VERTEX_UB; gcmType = CELL_GCM_VERTEX_UB;
else else
gcmType = CELL_GCM_VERTEX_UB256; gcmType = CELL_GCM_VERTEX_UB256;
break; break;
case RGL_SHORT:
case RGL_SHORT: gcmType = normalized ? CELL_GCM_VERTEX_S1 : CELL_GCM_VERTEX_S32K;
gcmType = normalized ? CELL_GCM_VERTEX_S1 : CELL_GCM_VERTEX_S32K; break;
break; case RGL_FLOAT:
gcmType = CELL_GCM_VERTEX_F;
case RGL_FLOAT: break;
gcmType = CELL_GCM_VERTEX_F; case RGL_HALF_FLOAT:
break; gcmType = CELL_GCM_VERTEX_SF;
break;
case RGL_HALF_FLOAT: case RGL_CMP:
gcmType = CELL_GCM_VERTEX_SF; size = 1;
break; gcmType = CELL_GCM_VERTEX_CMP;
break;
case RGL_CMP: default:
size = 1; break;
gcmType = CELL_GCM_VERTEX_CMP;
break;
default:
break;
} }
cellGcmSetVertexDataArrayInline( &_RGLState.fifo, index, frequency, stride, size, gcmType, CELL_GCM_LOCATION_LOCAL, offset ); cellGcmSetVertexDataArrayInline( &_RGLState.fifo, index, frequency, stride, size, gcmType, CELL_GCM_LOCATION_LOCAL, offset );
} }
static void _RGLResetAttributeState( jsAttributeState* as ) static void _RGLResetAttributeState( jsAttributeState* as )
@ -350,9 +346,9 @@ static void _RGLResetAttributeState( jsAttributeState* as )
static jsAttribSet* _RGLCreateAttribSet( void ) static jsAttribSet* _RGLCreateAttribSet( void )
{ {
jsAttribSet* attribSet = ( jsAttribSet * )memalign( 16, sizeof( jsAttribSet ) ); jsAttribSet* attribSet = (jsAttribSet*)memalign(16, sizeof(jsAttribSet));
_RGLResetAttributeState( &attribSet->attribs ); _RGLResetAttributeState(&attribSet->attribs);
attribSet->dirty = GL_TRUE; attribSet->dirty = GL_TRUE;
attribSet->beenUpdatedMask = 0; attribSet->beenUpdatedMask = 0;
@ -379,8 +375,10 @@ static void _RGLAttribSetDeleteBuffer( PSGLcontext *LContext, GLuint buffName )
jsAttribSet *attribSet = bufferObject->attribSets[i]; jsAttribSet *attribSet = bufferObject->attribSets[i];
for(GLuint j = 0; j < MAX_VERTEX_ATTRIBS; ++j) for(GLuint j = 0; j < MAX_VERTEX_ATTRIBS; ++j)
if ( attribSet->attribs.attrib[j].arrayBuffer == buffName ) {
if(attribSet->attribs.attrib[j].arrayBuffer == buffName)
attribSet->attribs.attrib[j].arrayBuffer = 0; attribSet->attribs.attrib[j].arrayBuffer = 0;
}
attribSet->dirty = GL_TRUE; attribSet->dirty = GL_TRUE;
} }
@ -390,8 +388,8 @@ static void _RGLAttribSetDeleteBuffer( PSGLcontext *LContext, GLuint buffName )
static jsBufferObject *_RGLCreateBufferObject (void) static jsBufferObject *_RGLCreateBufferObject (void)
{ {
GLuint size = sizeof( jsBufferObject ) + sizeof( RGLBufferObject); GLuint size = sizeof(jsBufferObject) + sizeof(RGLBufferObject);
jsBufferObject *buffer = ( jsBufferObject * )malloc( size ); jsBufferObject *buffer = (jsBufferObject*)malloc(size);
if( !buffer ) if( !buffer )
return NULL; return NULL;
@ -407,9 +405,9 @@ static jsBufferObject *_RGLCreateBufferObject (void)
static void _RGLPlatformDestroyBufferObject( jsBufferObject* bufferObject ) static void _RGLPlatformDestroyBufferObject( jsBufferObject* bufferObject )
{ {
RGLBufferObject *jsBuffer = ( RGLBufferObject * )bufferObject->platformBufferObject; RGLBufferObject *jsBuffer = (RGLBufferObject*)bufferObject->platformBufferObject;
switch ( jsBuffer->pool ) switch(jsBuffer->pool)
{ {
case SURFACE_POOL_SYSTEM: case SURFACE_POOL_SYSTEM:
case SURFACE_POOL_LINEAR: case SURFACE_POOL_LINEAR:
@ -427,11 +425,12 @@ static void _RGLPlatformDestroyBufferObject( jsBufferObject* bufferObject )
static void _RGLFreeBufferObject( jsBufferObject *buffer ) static void _RGLFreeBufferObject( jsBufferObject *buffer )
{ {
if ( --buffer->refCount == 0 ) if(--buffer->refCount == 0)
{ {
_RGLPlatformDestroyBufferObject( buffer ); _RGLPlatformDestroyBufferObject( buffer );
buffer->textureReferences.~Vector<jsTexture *>(); buffer->textureReferences.~Vector<jsTexture *>();
buffer->attribSets.~Vector<jsAttribSet *>(); buffer->attribSets.~Vector<jsAttribSet *>();
if(buffer != NULL) if(buffer != NULL)
free( buffer ); free( buffer );
} }
@ -448,7 +447,7 @@ GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name )
if(name) if(name)
_RGLTexNameSpaceCreateNameLazy( &LContext->bufferObjectNameSpace, name ); _RGLTexNameSpaceCreateNameLazy( &LContext->bufferObjectNameSpace, name );
switch ( target ) switch(target)
{ {
case GL_ARRAY_BUFFER: case GL_ARRAY_BUFFER:
LContext->ArrayBuffer = name; LContext->ArrayBuffer = name;
@ -479,8 +478,10 @@ GLAPI void APIENTRY glDeleteBuffers(GLsizei n, const GLuint *buffers)
if(buffers[i] ) if(buffers[i] )
{ {
GLuint name = buffers[i]; GLuint name = buffers[i];
if(LContext->ArrayBuffer == name) if(LContext->ArrayBuffer == name)
LContext->ArrayBuffer = 0; LContext->ArrayBuffer = 0;
if(LContext->PixelUnpackBuffer == name) if(LContext->PixelUnpackBuffer == name)
LContext->PixelUnpackBuffer = 0; LContext->PixelUnpackBuffer = 0;
@ -504,11 +505,6 @@ GLAPI void APIENTRY glGenBuffers(GLsizei n, GLuint *buffers)
_RGLTexNameSpaceGenNames( &LContext->bufferObjectNameSpace, n, buffers ); _RGLTexNameSpaceGenNames( &LContext->bufferObjectNameSpace, n, buffers );
} }
static inline jsFramebuffer *_RGLGetFramebuffer(PSGLcontext *LContext, GLuint name)
{
return (jsFramebuffer *)LContext->framebufferNameSpace.data[name];
}
static inline void _RGLTextureTouchFBOs(jsTexture *texture) static inline void _RGLTextureTouchFBOs(jsTexture *texture)
{ {
PSGLcontext *LContext = _CurrentContext; PSGLcontext *LContext = _CurrentContext;
@ -516,9 +512,10 @@ static inline void _RGLTextureTouchFBOs(jsTexture *texture)
return; return;
GLuint fbCount = texture->framebuffers.getCount(); GLuint fbCount = texture->framebuffers.getCount();
if(fbCount > 0) if(fbCount > 0)
{ {
jsFramebuffer *contextFramebuffer = LContext->framebuffer ? _RGLGetFramebuffer( LContext, LContext->framebuffer ) : NULL; jsFramebuffer *contextFramebuffer = LContext->framebuffer ? (jsFramebuffer *)LContext->framebufferNameSpace.data[LContext->framebuffer] : NULL;
for (GLuint i = 0; i < fbCount; ++i) for (GLuint i = 0; i < fbCount; ++i)
{ {
@ -530,23 +527,23 @@ static inline void _RGLTextureTouchFBOs(jsTexture *texture)
} }
} }
static void _RGLAllocateBuffer( jsBufferObject* bufferObject ) static void _RGLAllocateBuffer(jsBufferObject* bufferObject)
{ {
RGLBufferObject *jsBuffer = ( RGLBufferObject * )bufferObject->platformBufferObject; RGLBufferObject *jsBuffer = (RGLBufferObject *)bufferObject->platformBufferObject;
_RGLPlatformDestroyBufferObject( bufferObject ); _RGLPlatformDestroyBufferObject(bufferObject);
jsBuffer->pool = SURFACE_POOL_LINEAR; jsBuffer->pool = SURFACE_POOL_LINEAR;
jsBuffer->bufferId = gmmAlloc(0, jsBuffer->bufferSize); jsBuffer->bufferId = gmmAlloc(0, jsBuffer->bufferSize);
jsBuffer->pitch = 0; jsBuffer->pitch = 0;
if ( jsBuffer->bufferId == GMM_ERROR ) if(jsBuffer->bufferId == GMM_ERROR)
jsBuffer->pool = SURFACE_POOL_NONE; jsBuffer->pool = SURFACE_POOL_NONE;
GLuint referenceCount = bufferObject->textureReferences.getCount(); GLuint referenceCount = bufferObject->textureReferences.getCount();
if ( referenceCount > 0 ) if(referenceCount > 0)
{ {
for ( GLuint i = 0;i < referenceCount;++i ) for (GLuint i = 0;i < referenceCount; ++i)
{ {
jsTexture *texture = bufferObject->textureReferences[i]; jsTexture *texture = bufferObject->textureReferences[i];
RGLTexture *gcmTexture = ( RGLTexture * )texture->platformTexture; RGLTexture *gcmTexture = ( RGLTexture * )texture->platformTexture;
@ -641,36 +638,37 @@ static void _RGLPlatformBufferObjectSetData( jsBufferObject* bufferObject, GLint
memcpy( gmmIdToAddress( jsBuffer->bufferId ) + offset, data, size ); memcpy( gmmIdToAddress( jsBuffer->bufferId ) + offset, data, size );
else else
{ {
unsigned int dstId = jsBuffer->bufferId; unsigned int dstId = jsBuffer->bufferId;
unsigned int pitch = jsBuffer->pitch; unsigned int pitch = jsBuffer->pitch;
const char *src = (const char *)data; const char *src = (const char *)data;
switch ( bufferObject->usage )
{
case GL_STREAM_DRAW:
case GL_STREAM_READ:
case GL_STREAM_COPY:
case GL_DYNAMIC_DRAW:
case GL_DYNAMIC_READ:
case GL_DYNAMIC_COPY:
{
GLuint id = gmmAlloc(0, size);
memcpy( gmmIdToAddress(id), src, size ); switch ( bufferObject->usage )
_RGLMemcpy( dstId, offset, pitch, id, size ); {
case GL_STREAM_DRAW:
case GL_STREAM_READ:
case GL_STREAM_COPY:
case GL_DYNAMIC_DRAW:
case GL_DYNAMIC_READ:
case GL_DYNAMIC_COPY:
{
GLuint id = gmmAlloc(0, size);
gmmFree( id ); memcpy( gmmIdToAddress(id), src, size );
} _RGLMemcpy( dstId, offset, pitch, id, size );
break;
default: gmmFree( id );
cellGcmSetInvalidateVertexCacheInline( &_RGLState.fifo); }
_RGLFifoFinish( &_RGLState.fifo ); break;
memcpy( gmmIdToAddress( dstId ) + offset, src, size ); default:
break; cellGcmSetInvalidateVertexCacheInline( &_RGLState.fifo);
}; _RGLFifoFinish( &_RGLState.fifo );
memcpy( gmmIdToAddress( dstId ) + offset, src, size );
break;
};
} }
} }
((RGLDriver *)_CurrentDevice->rasterDriver)->invalidateVertexCache = GL_TRUE; ((RGLDriver *)_CurrentDevice->rasterDriver)->invalidateVertexCache = GL_TRUE;
} }
static GLboolean _RGLPlatformCreateBufferObject( jsBufferObject* bufferObject ) static GLboolean _RGLPlatformCreateBufferObject( jsBufferObject* bufferObject )
@ -683,7 +681,7 @@ static GLboolean _RGLPlatformCreateBufferObject( jsBufferObject* bufferObject )
jsBuffer->mapAccess = GL_NONE; jsBuffer->mapAccess = GL_NONE;
jsBuffer->bufferSize = _RGLPad( bufferObject->size, _RGL_BUFFER_OBJECT_BLOCK_SIZE ); jsBuffer->bufferSize = _RGLPad( bufferObject->size, _RGL_BUFFER_OBJECT_BLOCK_SIZE );
_RGLAllocateBuffer( bufferObject ); _RGLAllocateBuffer(bufferObject);
return jsBuffer->bufferId != GMM_ERROR; return jsBuffer->bufferId != GMM_ERROR;
} }
@ -835,52 +833,56 @@ static void _RGLFramebufferGetAttachmentTexture(
jsTexture** texture) jsTexture** texture)
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
switch ( attachment->type )
{ switch ( attachment->type )
case FRAMEBUFFER_ATTACHMENT_NONE: {
*texture = NULL; case FRAMEBUFFER_ATTACHMENT_NONE:
break; *texture = NULL;
case FRAMEBUFFER_ATTACHMENT_RENDERBUFFER: break;
break; case FRAMEBUFFER_ATTACHMENT_RENDERBUFFER:
case FRAMEBUFFER_ATTACHMENT_TEXTURE: break;
*texture = _RGLTexNameSpaceIsName( &LContext->textureNameSpace, attachment->name ) ? ( jsTexture* )LContext->textureNameSpace.data[attachment->name] : NULL; case FRAMEBUFFER_ATTACHMENT_TEXTURE:
break; *texture = _RGLTexNameSpaceIsName( &LContext->textureNameSpace, attachment->name ) ? ( jsTexture* )LContext->textureNameSpace.data[attachment->name] : NULL;
default: break;
*texture = NULL; default:
break; *texture = NULL;
} break;
}
} }
static GLboolean _RGLTextureIsValid( const jsTexture* texture ) static GLboolean _RGLTextureIsValid(const jsTexture* texture)
{ {
if ( texture->imageCount < 1 ) if(texture->imageCount < 1)
return GL_FALSE; return GL_FALSE;
if ( !texture->image ) if ( !texture->image )
return GL_FALSE; return GL_FALSE;
const jsImage* image = texture->image;
int width = image->width; const jsImage* image = texture->image;
int height = image->height;
GLenum format = image->format;
GLenum type = image->type;
GLenum internalFormat = image->internalFormat;
if (( internalFormat == 0 ) || ( format == 0 ) || ( type == 0 ) )
return GL_FALSE;
if ( !image->isSet ) int width = image->width;
return GL_FALSE; int height = image->height;
if ( width != image->width )
return GL_FALSE;
if ( height != image->height )
return GL_FALSE;
if ( format != image->format )
return GL_FALSE;
if ( type != image->type )
return GL_FALSE;
if ( internalFormat != image->internalFormat )
return GL_FALSE;
return GL_TRUE; GLenum format = image->format;
GLenum type = image->type;
GLenum internalFormat = image->internalFormat;
if (( internalFormat == 0 ) || ( format == 0 ) || ( type == 0 ) )
return GL_FALSE;
if(!image->isSet)
return GL_FALSE;
if(width != image->width)
return GL_FALSE;
if(height != image->height)
return GL_FALSE;
if(format != image->format)
return GL_FALSE;
if(type != image->type)
return GL_FALSE;
if(internalFormat != image->internalFormat)
return GL_FALSE;
return GL_TRUE;
} }
static GLenum _RGLPlatformFramebufferCheckStatus(jsFramebuffer* framebuffer) static GLenum _RGLPlatformFramebufferCheckStatus(jsFramebuffer* framebuffer)
@ -933,29 +935,36 @@ static GLenum _RGLPlatformFramebufferCheckStatus(jsFramebuffer* framebuffer)
return GL_FRAMEBUFFER_COMPLETE_OES; return GL_FRAMEBUFFER_COMPLETE_OES;
} }
enum _RGLTextureStrategy { enum _RGLTextureStrategy
_RGL_TEXTURE_STRATEGY_END, {
_RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, TEXTURE_STRATEGY_END,
_RGL_TEXTURE_STRATEGY_UNTILED_CLEAR, TEXTURE_STRATEGY_UNTILED_ALLOC,
TEXTURE_STRATEGY_UNTILED_CLEAR,
}; };
static enum _RGLTextureStrategy linearGPUStrategy[] = static enum _RGLTextureStrategy linearGPUStrategy[] =
{ {
_RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, TEXTURE_STRATEGY_UNTILED_ALLOC,
_RGL_TEXTURE_STRATEGY_UNTILED_CLEAR, TEXTURE_STRATEGY_UNTILED_CLEAR,
_RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, TEXTURE_STRATEGY_UNTILED_ALLOC,
_RGL_TEXTURE_STRATEGY_END, TEXTURE_STRATEGY_END,
}; };
static void _RGLImageAllocCPUStorage( jsImage *image ) static void _RGLImageAllocCPUStorage( jsImage *image )
{ {
if (( image->storageSize > image->mallocStorageSize ) || ( !image->mallocData ) ) if((image->storageSize > image->mallocStorageSize) || (!image->mallocData))
{ {
if ( image->mallocData ) free( image->mallocData ); if(image->mallocData)
image->mallocData = ( char * )malloc( image->storageSize + 128 ); free( image->mallocData );
image->mallocStorageSize = image->storageSize;
} image->mallocData = ( char * )malloc( image->storageSize + 128 );
image->data = _RGLPadPtr( image->mallocData, 128 ); image->mallocStorageSize = image->storageSize;
}
intptr_t x = (intptr_t)image->mallocData;
x = ( x + 128 - 1 ) / 128 * 128;
image->data = (char*)x;
} }
static inline int _RGLGetComponentCount( GLenum format ) static inline int _RGLGetComponentCount( GLenum format )
@ -1272,11 +1281,6 @@ int _RGLGetPixelSize( GLenum format, GLenum type )
return _RGLGetComponentCount( format )*componentSize; return _RGLGetComponentCount( format )*componentSize;
} }
static inline int _RGLGetStorageSize( GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth )
{
return _RGLGetPixelSize( format, type )*width*height*depth;
}
static void _RGLPlatformChooseGPUFormatAndLayout( static void _RGLPlatformChooseGPUFormatAndLayout(
const jsTexture* texture, const jsTexture* texture,
GLboolean forceLinear, GLboolean forceLinear,
@ -1289,18 +1293,20 @@ static void _RGLPlatformChooseGPUFormatAndLayout(
newLayout->baseHeight = image->height; newLayout->baseHeight = image->height;
newLayout->internalFormat = ( RGLEnum )image->internalFormat; newLayout->internalFormat = ( RGLEnum )image->internalFormat;
newLayout->pixelBits = _RGLPlatformGetBitsPerPixel( newLayout->internalFormat ); newLayout->pixelBits = _RGLPlatformGetBitsPerPixel( newLayout->internalFormat );
newLayout->pitch = pitch ? pitch : _RGLPad( _RGLGetStorageSize( texture->image->format, texture->image->type, texture->image->width, 1, 1 ), 64 ); newLayout->pitch = pitch ? pitch : _RGLPad( _RGLGetPixelSize( texture->image->format, texture->image->type )*texture->image->width, 64);
} }
void _RGLPlatformDropUnboundTextures( GLenum pool ) void _RGLPlatformDropUnboundTextures(GLenum pool)
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
GLuint i, j; GLuint i, j;
for (i = 0; i < LContext->textureNameSpace.capacity; ++i) for (i = 0; i < LContext->textureNameSpace.capacity; ++i)
{ {
GLboolean bound = GL_FALSE; GLboolean bound = GL_FALSE;
jsTexture *texture = ( jsTexture * )LContext->textureNameSpace.data[i]; jsTexture *texture = ( jsTexture * )LContext->textureNameSpace.data[i];
if ( !texture || ( texture->referenceBuffer != 0 ) ) continue; if(!texture || (texture->referenceBuffer != 0))
continue;
for (j = 0; j < _RGL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++j) for (j = 0; j < _RGL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++j)
{ {
@ -1355,7 +1361,7 @@ static void _RGLPlatformReallocateGcmTexture( jsTexture* texture )
switch ( *step++ ) switch ( *step++ )
{ {
case _RGL_TEXTURE_STRATEGY_UNTILED_ALLOC: case TEXTURE_STRATEGY_UNTILED_ALLOC:
_RGLPlatformChooseGPUFormatAndLayout( texture, GL_TRUE, 0, &newLayout ); _RGLPlatformChooseGPUFormatAndLayout( texture, GL_TRUE, 0, &newLayout );
size = _RGLPad( newLayout.baseHeight * newLayout.pitch, 1); size = _RGLPad( newLayout.baseHeight * newLayout.pitch, 1);
@ -1388,10 +1394,10 @@ static void _RGLPlatformReallocateGcmTexture( jsTexture* texture )
} }
} }
break; break;
case _RGL_TEXTURE_STRATEGY_UNTILED_CLEAR: case TEXTURE_STRATEGY_UNTILED_CLEAR:
_RGLPlatformDropUnboundTextures(SURFACE_POOL_LINEAR); _RGLPlatformDropUnboundTextures(SURFACE_POOL_LINEAR);
break; break;
case _RGL_TEXTURE_STRATEGY_END: case TEXTURE_STRATEGY_END:
_RGLSetError( GL_OUT_OF_MEMORY ); _RGLSetError( GL_OUT_OF_MEMORY );
done = GL_TRUE; done = GL_TRUE;
break; break;
@ -1511,10 +1517,10 @@ static void _RGLPlatformValidateTextureResources( jsTexture *texture )
GLuint gamma = 0; GLuint gamma = 0;
GLuint remap = texture->gammaRemap; GLuint remap = texture->gammaRemap;
gamma |= ( remap & RGL_GAMMA_REMAP_RED_BIT ) ? CELL_GCM_TEXTURE_GAMMA_R : 0; gamma |= (remap & RGL_GAMMA_REMAP_RED_BIT) ? CELL_GCM_TEXTURE_GAMMA_R : 0;
gamma |= ( remap & RGL_GAMMA_REMAP_GREEN_BIT ) ? CELL_GCM_TEXTURE_GAMMA_G : 0; gamma |= (remap & RGL_GAMMA_REMAP_GREEN_BIT) ? CELL_GCM_TEXTURE_GAMMA_G : 0;
gamma |= ( remap & RGL_GAMMA_REMAP_BLUE_BIT ) ? CELL_GCM_TEXTURE_GAMMA_B : 0; gamma |= (remap & RGL_GAMMA_REMAP_BLUE_BIT) ? CELL_GCM_TEXTURE_GAMMA_B : 0;
gamma |= ( remap & RGL_GAMMA_REMAP_ALPHA_BIT ) ? CELL_GCM_TEXTURE_GAMMA_A : 0; gamma |= (remap & RGL_GAMMA_REMAP_ALPHA_BIT) ? CELL_GCM_TEXTURE_GAMMA_A : 0;
platformTexture->gcmMethods.address.gamma = gamma; platformTexture->gcmMethods.address.gamma = gamma;
@ -1534,7 +1540,7 @@ static void _RGLPlatformValidateTextureResources( jsTexture *texture )
platformTexture->gcmTexture.cubemap = CELL_GCM_FALSE; platformTexture->gcmTexture.cubemap = CELL_GCM_FALSE;
platformTexture->gcmTexture.dimension = CELL_GCM_TEXTURE_DIMENSION_2; platformTexture->gcmTexture.dimension = CELL_GCM_TEXTURE_DIMENSION_2;
if ( gmmIdIsMain(platformTexture->gpuAddressId) ) if(gmmIdIsMain(platformTexture->gpuAddressId))
platformTexture->gcmTexture.location = CELL_GCM_LOCATION_MAIN; platformTexture->gcmTexture.location = CELL_GCM_LOCATION_MAIN;
else else
platformTexture->gcmTexture.location = CELL_GCM_LOCATION_LOCAL; platformTexture->gcmTexture.location = CELL_GCM_LOCATION_LOCAL;
@ -1558,7 +1564,8 @@ static void jsPlatformFramebuffer_validate( jsPlatformFramebuffer * fb, PSGLcont
GLuint defaultPitch = 0; GLuint defaultPitch = 0;
GLuint defaultId = GMM_ERROR; GLuint defaultId = GMM_ERROR;
GLuint defaultIdOffset = 0; GLuint defaultIdOffset = 0;
for ( int i = 0; i < RGL_SETRENDERTARGET_MAXCOUNT; ++i )
for(int i = 0; i < RGL_SETRENDERTARGET_MAXCOUNT; ++i)
{ {
jsTexture* colorTexture = NULL; jsTexture* colorTexture = NULL;
_RGLFramebufferGetAttachmentTexture(&fb->color[i], &colorTexture); _RGLFramebufferGetAttachmentTexture(&fb->color[i], &colorTexture);
@ -1618,7 +1625,7 @@ static void _RGLValidateFramebuffer( void )
if(LContext->framebuffer) if(LContext->framebuffer)
{ {
jsPlatformFramebuffer* framebuffer = static_cast<jsPlatformFramebuffer *>( _RGLGetFramebuffer( LContext, LContext->framebuffer ) ); jsPlatformFramebuffer* framebuffer = static_cast<jsPlatformFramebuffer *>((jsFramebuffer *)LContext->framebufferNameSpace.data[LContext->framebuffer] );
if ( framebuffer->needValidate ) if ( framebuffer->needValidate )
jsPlatformFramebuffer_validate( framebuffer, LContext ); jsPlatformFramebuffer_validate( framebuffer, LContext );
@ -1721,10 +1728,10 @@ GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, G
{ {
PSGLcontext *LContext = _CurrentContext; PSGLcontext *LContext = _CurrentContext;
LContext->ClearColor.R = _RGLClampf( red ); LContext->ClearColor.R = MAX(MIN(red, 1.f), 0.f);
LContext->ClearColor.G = _RGLClampf( green ); LContext->ClearColor.G = MAX(MIN(green, 1.f), 0.f);
LContext->ClearColor.B = _RGLClampf( blue ); LContext->ClearColor.B = MAX(MIN(blue, 1.f), 0.f);
LContext->ClearColor.A = _RGLClampf( alpha ); LContext->ClearColor.A = MAX(MIN(alpha, 1.f), 0.f);
} }
GLAPI void APIENTRY glBlendEquation( GLenum mode ) GLAPI void APIENTRY glBlendEquation( GLenum mode )
@ -1735,19 +1742,18 @@ GLAPI void APIENTRY glBlendEquation( GLenum mode )
LContext->needValidate |= PSGL_VALIDATE_BLENDING; LContext->needValidate |= PSGL_VALIDATE_BLENDING;
} }
GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) GLAPI void APIENTRY glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
LContext->BlendColor.R = _RGLClampf( red ); LContext->BlendColor.R = MAX(MIN(red, 1.f), 0.f);
LContext->BlendColor.G = _RGLClampf( green ); LContext->BlendColor.G = MAX(MIN(green, 1.f), 0.f);
LContext->BlendColor.B = _RGLClampf( blue ); LContext->BlendColor.B = MAX(MIN(blue, 1.f), 0.f);
LContext->BlendColor.A = _RGLClampf( alpha ); LContext->BlendColor.A = MAX(MIN(alpha, 1.f), 0.f);
LContext->needValidate |= PSGL_VALIDATE_BLENDING; LContext->needValidate |= PSGL_VALIDATE_BLENDING;
} }
GLAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor )
{ {
PSGLcontext *LContext = _CurrentContext; PSGLcontext *LContext = _CurrentContext;
@ -1814,7 +1820,7 @@ GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum target )
if ( LContext->framebuffer ) if ( LContext->framebuffer )
{ {
jsFramebuffer* framebuffer = _RGLGetFramebuffer( LContext, LContext->framebuffer ); jsFramebuffer* framebuffer = (jsFramebuffer *)LContext->framebufferNameSpace.data[LContext->framebuffer];
return _RGLPlatformFramebufferCheckStatus( framebuffer ); return _RGLPlatformFramebufferCheckStatus( framebuffer );
} }
@ -1825,7 +1831,7 @@ GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum target, GLenum attachment,
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
jsFramebuffer* framebuffer = _RGLGetFramebuffer( LContext, LContext->framebuffer ); jsFramebuffer* framebuffer = (jsFramebuffer *)LContext->framebufferNameSpace.data[LContext->framebuffer];
jsFramebufferAttachment* attach = _RGLFramebufferGetAttachment( framebuffer, GL_COLOR_ATTACHMENT0_EXT ); jsFramebufferAttachment* attach = _RGLFramebufferGetAttachment( framebuffer, GL_COLOR_ATTACHMENT0_EXT );
@ -2095,10 +2101,7 @@ static uint32_t gmmInitFixedAllocator (void)
return CELL_OK; return CELL_OK;
} }
static void gmmRemovePendingFree( static void gmmRemovePendingFree(GmmAllocator *pAllocator, GmmBlock *pBlock)
GmmAllocator *pAllocator,
GmmBlock *pBlock
)
{ {
if (pBlock == pAllocator->pPendingFreeHead) if (pBlock == pAllocator->pPendingFreeHead)
pAllocator->pPendingFreeHead = pBlock->pNextFree; pAllocator->pPendingFreeHead = pBlock->pNextFree;
@ -3268,10 +3271,10 @@ template<int SIZE> inline static void swapandsetfp( int ucodeSize, unsigned int
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 *ptr = NULL;
const int paddedSIZE = (SIZE + 1) & ~1; const int paddedSIZE = (SIZE + 1) & ~1;
cellGcmSetInlineTransferPointerInline( &_RGLState.fifo, gmmIdToOffset( loadProgramId ) + loadProgramOffset + *(ec++), paddedSIZE, &pointer); cellGcmSetInlineTransferPointerInline( &_RGLState.fifo, gmmIdToOffset( loadProgramId ) + loadProgramOffset + *(ec++), paddedSIZE, &ptr);
float *fp = (float*)pointer; float *fp = (float*)ptr;
float *src = (float*)v; float *src = (float*)v;
for (uint32_t j=0; j<SIZE;j++) for (uint32_t j=0; j<SIZE;j++)
{ {
@ -3294,9 +3297,10 @@ template<int SIZE> static void setVectorTypefp( CgRuntimeParameter* __restrict p
CgParameterResource *parameterResource = _RGLGetParameterResource( ptr->program, ptr->parameterEntry ); CgParameterResource *parameterResource = _RGLGetParameterResource( ptr->program, ptr->parameterEntry );
unsigned short resource = parameterResource->resource; unsigned short resource = parameterResource->resource;
unsigned short *ec = ( unsigned short * )( ptr->program->resources ) + resource + 1; unsigned short *ec = ( unsigned short * )( ptr->program->resources ) + resource + 1;
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, (unsigned int *)data);
} }
} }
@ -3309,8 +3313,8 @@ template<int SIZE> static void setVectorTypeSharedvpIndex( CgRuntimeParameter* _
const float * __restrict f = ( const float * __restrict )v; const float * __restrict f = ( const float * __restrict )v;
const CgParameterResource *parameterResource = _RGLGetParameterResource( ptr->program, ptr->parameterEntry ); const CgParameterResource *parameterResource = _RGLGetParameterResource( ptr->program, ptr->parameterEntry );
unsigned short resource = parameterResource->resource; unsigned short resource = parameterResource->resource;
float * __restrict dst = ( float * __restrict )ptr->pushBufferPointer; float * __restrict dst = (float * __restrict)ptr->pushBufferPointer;
for ( long i = 0; i < SIZE; ++ i ) for (long i = 0; i < SIZE; ++i)
dst[i] = f[i]; dst[i] = f[i];
_RGLPlatformSetVertexRegister4fv( resource, dst ); _RGLPlatformSetVertexRegister4fv( resource, dst );
} }
@ -3407,11 +3411,10 @@ template <int ROWS, int COLS, int ORDER> static void setMatrixSharedvpIndex( CgR
float tmp[ROWS*4]; float tmp[ROWS*4];
for ( long row = 0; row < ROWS; ++row ) for ( long row = 0; row < ROWS; ++row )
{ {
for ( long col = 0; col < COLS; ++col ) for(long col = 0; col < COLS; ++col)
{ tmp[row*4 + col] = dst[row * 4 + col] = ( ORDER == ROW_MAJOR ) ? f[row * COLS + col] : f[col * ROWS + row];
tmp[row*4 + col] = dst[row * 4 + col] = ( ORDER == ROW_MAJOR ) ? f[row * COLS + col] : f[col * ROWS + row]; for(long col = COLS; col < 4; ++col)
} tmp[row*4 + col] = dst[row*4+col];
for ( long col = COLS; col < 4; ++col ) tmp[row*4 + col] = dst[row*4+col];
} }
cellGcmSetVertexProgramParameterBlockInline( &_RGLState.fifo, resource, ROWS, (const float*)tmp); cellGcmSetVertexProgramParameterBlockInline( &_RGLState.fifo, resource, ROWS, (const float*)tmp);
@ -4407,13 +4410,6 @@ static void _RGLPlatformDestroyTexture( jsTexture* texture )
_RGLTextureTouchFBOs( texture ); _RGLTextureTouchFBOs( texture );
} }
// Get size of texture in GPU layout
static inline GLuint _RGLPlatformTextureGetGPUSize( const jsTexture* texture )
{
RGLTexture *gcmTexture = ( RGLTexture * )texture->platformTexture;
return _RGLPad( gcmTexture->gpuLayout.baseHeight * gcmTexture->gpuLayout.pitch, 1);
}
#include <cell/gcm/gcm_method_data.h> #include <cell/gcm/gcm_method_data.h>
static void _RGLPlatformValidateTextureStage( int unit, jsTexture* texture ) static void _RGLPlatformValidateTextureStage( int unit, jsTexture* texture )
@ -4573,9 +4569,7 @@ static GLenum _RGLPlatformChooseInternalStorage( jsImage* image, GLenum internal
image->internalFormat = platformInternalFormat; image->internalFormat = platformInternalFormat;
_RGLPlatformExpandInternalFormat( platformInternalFormat, &image->format, &image->type ); _RGLPlatformExpandInternalFormat( platformInternalFormat, &image->format, &image->type );
image->storageSize = _RGLGetStorageSize( image->storageSize = _RGLGetPixelSize(image->format, image->type) * image->width * image->height;
image->format, image->type,
image->width, image->height, 1 );
return GL_NO_ERROR; return GL_NO_ERROR;
} }
@ -4662,9 +4656,7 @@ static GLboolean _RGLPlatformTexturePBOImage(
if ( LContext->PixelUnpackBuffer == 0 ) if ( LContext->PixelUnpackBuffer == 0 )
return GL_FALSE; return GL_FALSE;
const GLuint pboPitch = _RGLPad( const GLuint pboPitch = _RGLPad(_RGLGetPixelSize(format, type) * width, LContext->unpackAlignment );
_RGLGetStorageSize( format, type, width, 1, 1 ),
LContext->unpackAlignment );
if (( pboPitch&3 ) != 0 ) if (( pboPitch&3 ) != 0 )
{ {
RARCH_WARN("PBO image pitch not a multiple of 4, using slow path.\n" ); RARCH_WARN("PBO image pitch not a multiple of 4, using slow path.\n" );
@ -4722,14 +4714,15 @@ static GLboolean _RGLPlatformTexturePBOImage(
{ {
gcmTexture->gpuLayout = newLayout; gcmTexture->gpuLayout = newLayout;
if ( gcmTexture->gpuAddressId != GMM_ERROR && gcmTexture->pbo == NULL ) if ( gcmTexture->gpuAddressId != GMM_ERROR && gcmTexture->pbo == NULL )
{ _RGLPlatformFreeGcmTexture( texture );
_RGLPlatformFreeGcmTexture( texture );
}
gcmTexture->pbo = bufferObject; gcmTexture->pbo = bufferObject;
gcmTexture->gpuAddressId = gpuId; gcmTexture->gpuAddressId = gpuId;
gcmTexture->gpuAddressIdOffset = gpuIdOffset; gcmTexture->gpuAddressIdOffset = gpuIdOffset;
gcmTexture->pool = SURFACE_POOL_LINEAR; gcmTexture->pool = SURFACE_POOL_LINEAR;
gcmTexture->gpuSize = _RGLPlatformTextureGetGPUSize( texture ); RGLTexture *gcmTexture = ( RGLTexture * )texture->platformTexture;
// Get size of texture in GPU layout
gcmTexture->gpuSize = _RGLPad( gcmTexture->gpuLayout.baseHeight * gcmTexture->gpuLayout.pitch, 1);
++bufferObject->refCount; ++bufferObject->refCount;
} }
else else
@ -6464,7 +6457,7 @@ GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const G
LContext->needValidate |= PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_VERTEX_TEXTURES_USED; LContext->needValidate |= PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_VERTEX_TEXTURES_USED;
} }
GLAPI void APIENTRY glActiveTexture( GLenum texture ) GLAPI void APIENTRY glActiveTexture(GLenum texture)
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
@ -6474,13 +6467,13 @@ GLAPI void APIENTRY glActiveTexture( GLenum texture )
LContext->CurrentCoordsUnit = unit < _RGL_MAX_TEXTURE_COORDS ? LContext->TextureCoordsUnits + unit : NULL; LContext->CurrentCoordsUnit = unit < _RGL_MAX_TEXTURE_COORDS ? LContext->TextureCoordsUnits + unit : NULL;
} }
GLAPI void APIENTRY glClientActiveTexture( GLenum texture ) GLAPI void APIENTRY glClientActiveTexture(GLenum texture)
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
LContext->CS_ActiveTexture = texture - GL_TEXTURE0; LContext->CS_ActiveTexture = texture - GL_TEXTURE0;
} }
GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ) GLAPI void APIENTRY glPixelStorei(GLenum pname, GLint param)
{ {
PSGLcontext* LContext = _CurrentContext; PSGLcontext* LContext = _CurrentContext;
@ -6584,7 +6577,7 @@ static _CGprogram* _RGLCgProgramFindPrev( _CGcontext* ctx, _CGprogram* prog )
{ {
_CGprogram* ptr = ctx->programList; _CGprogram* ptr = ctx->programList;
while ( NULL != ptr && prog != ptr->next ) while ( ptr != NULL && prog != ptr->next )
ptr = ptr->next; ptr = ptr->next;
return ptr; return ptr;
@ -6775,7 +6768,7 @@ static CGprogram _RGLCgCreateProgram( CGcontext ctx, CGprofile profile, const Cg
// The parameters and the actual program are generated from the ABI specific calls. // The parameters and the actual program are generated from the ABI specific calls.
_CGprogram* prog = ( _CGprogram* )malloc( sizeof( _CGprogram ) ); _CGprogram* prog = ( _CGprogram* )malloc( sizeof( _CGprogram ) );
if ( prog == NULL ) if(prog == NULL)
{ {
_RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return NULL; return NULL;
@ -6792,9 +6785,9 @@ static CGprogram _RGLCgCreateProgram( CGcontext ctx, CGprofile profile, const Cg
// create a name for the program and record it in the object // create a name for the program and record it in the object
CGprogram id = ( CGprogram )_RGLCreateName( &_CurrentContext->cgProgramNameSpace, prog ); CGprogram id = ( CGprogram )_RGLCreateName( &_CurrentContext->cgProgramNameSpace, prog );
if ( !id ) if(!id)
{ {
free( prog ); free(prog);
_RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return NULL; return NULL;
} }
@ -6837,8 +6830,10 @@ static CGprogram _RGLCgCreateProgram( CGcontext ctx, CGprofile profile, const Cg
} }
// success! add the program to the program list in the context. // success! add the program to the program list in the context.
_RGLCgProgramPushFront( prog->parentContext, prog ); _RGLCgProgramPushFront(prog->parentContext, prog);
if ( _cgProgramCreateHook ) _cgProgramCreateHook( prog );
if(_cgProgramCreateHook)
_cgProgramCreateHook(prog);
// everything worked. // everything worked.
return id; return id;
@ -6878,10 +6873,10 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx,
char* compiled_program = NULL; char* compiled_program = NULL;
if ( program_type == CG_SOURCE ) if ( program_type == CG_SOURCE )
{ {
if ( _cgRTCgcCompileProgramHook ) if(_cgRTCgcCompileProgramHook)
{ {
_cgRTCgcCompileProgramHook( program, cgGetProfileString(profile), entry, args, &compiled_program ); _cgRTCgcCompileProgramHook( program, cgGetProfileString(profile), entry, args, &compiled_program );
if ( !compiled_program ) if(!compiled_program)
{ {
_RGLCgRaiseError( CG_COMPILER_ERROR ); _RGLCgRaiseError( CG_COMPILER_ERROR );
return NULL; return NULL;
@ -6931,7 +6926,7 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx,
else else
totalSize = nvProgram->totalSize; totalSize = nvProgram->totalSize;
int res = convertNvToElfFromMemory( binaryBuffer, totalSize, 2, 0, ( void** ) & runtimeElfShader, &compiled_program_size, stringTableArray, defaultValuesArray ); int res = convertNvToElfFromMemory( binaryBuffer, totalSize, 2, 0, ( void** )&runtimeElfShader, &compiled_program_size, stringTableArray, defaultValuesArray );
if ( res != 0 ) if ( res != 0 )
{ {
RARCH_ERR("Invalid CG binary program.\n"); RARCH_ERR("Invalid CG binary program.\n");
@ -6990,13 +6985,13 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx,
return NULL; return NULL;
} }
bool res = cgOpenElf( binaryBuffer, 0, &elfBinary ); bool res = cgOpenElf( binaryBuffer, 0, &elfBinary );
if ( !res ) if(!res)
{ {
RARCH_ERR("Not a valid ELF.\n"); RARCH_ERR("Not a valid ELF.\n");
_RGLCgRaiseError( CG_PROGRAM_LOAD_ERROR ); _RGLCgRaiseError( CG_PROGRAM_LOAD_ERROR );
return NULL; return NULL;
} }
if ( !cgGetElfProgramByName( &elfBinary, entry, &elfProgram ) ) if(!cgGetElfProgramByName( &elfBinary, entry, &elfProgram))
{ {
RARCH_ERR("Couldn't find the shader entry in the CG binary.\n"); RARCH_ERR("Couldn't find the shader entry in the CG binary.\n");
return NULL; return NULL;
@ -7011,10 +7006,10 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx,
CGprogram prog = _RGLCgCreateProgram( ctx, profile, programHeader, ucode, parameterHeader, stringTable, defaultValues ); CGprogram prog = _RGLCgCreateProgram( ctx, profile, programHeader, ucode, parameterHeader, stringTable, defaultValues );
if ( bConvertedToElf ) if(bConvertedToElf)
{ {
_CGprogram* ptr = _cgGetProgPtr( prog ); _CGprogram* ptr = _cgGetProgPtr( prog );
ptr->runtimeElf = programHeader; ptr->runtimeElf = programHeader;
} }
return prog; return prog;
@ -7033,10 +7028,10 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
profile = CG_PROFILE_SCE_FP_RSX; profile = CG_PROFILE_SCE_FP_RSX;
if ( program_type == CG_ROW_MAJOR ) if ( program_type == CG_ROW_MAJOR )
program_type = CG_BINARY; program_type = CG_BINARY;
if ( !_RGLCgCreateProgramChecks( ctx, profile, program_type ) ) if ( !_RGLCgCreateProgramChecks( ctx, profile, program_type ) )
return NULL; return NULL;
FILE* fp = NULL; FILE* fp = NULL;
if ( RGL_LIKELY( program_type == CG_BINARY ) ) if ( RGL_LIKELY( program_type == CG_BINARY ) )
@ -7074,12 +7069,12 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
return ret; return ret;
else else
{ {
fp = fopen( program_file, "rb" ); fp = fopen( program_file, "rb");
if ( fp == NULL ) if ( fp == NULL )
{ {
_RGLCgRaiseError( CG_FILE_READ_ERROR ); _RGLCgRaiseError( CG_FILE_READ_ERROR );
return ( CGprogram )NULL; return (CGprogram)NULL;
} }
unsigned int filetag = 0; unsigned int filetag = 0;
@ -7132,12 +7127,12 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx,
} }
size_t file_size = 0; size_t file_size = 0;
fseek( fp, 0, SEEK_END ); fseek(fp, 0, SEEK_END);
file_size = ftell( fp ); file_size = ftell(fp);
rewind( fp ); rewind(fp);
char* ptr = ( char* )malloc( file_size + 1 ); char* ptr = (char*)malloc( file_size + 1 );
if ( ptr == NULL ) if (ptr == NULL)
{ {
_RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR );
fclose( fp ); fclose( fp );
@ -7176,17 +7171,17 @@ CG_API CGprogram cgCopyProgram( CGprogram program )
size_t ucodeSize = 0; size_t ucodeSize = 0;
if (prog->header.profile == CG_PROFILE_SCE_FP_TYPEB || prog->header.profile == CG_PROFILE_SCE_FP_RSX) if (prog->header.profile == CG_PROFILE_SCE_FP_TYPEB || prog->header.profile == CG_PROFILE_SCE_FP_RSX)
{ {
paddedProgramSize = _RGLPad( sizeof( _CGprogram ), 16); paddedProgramSize = _RGLPad( sizeof( _CGprogram ), 16);
ucodeSize = prog->header.instructionCount * 16; ucodeSize = prog->header.instructionCount * 16;
newprog = ( _CGprogram* )malloc( paddedProgramSize + ucodeSize ); newprog = ( _CGprogram* )malloc(paddedProgramSize + ucodeSize);
} }
else else
{ {
newprog = ( _CGprogram* )malloc( sizeof( _CGprogram ) ); newprog = (_CGprogram*)malloc(sizeof(_CGprogram));
} }
if ( newprog == NULL ) if(newprog == NULL)
{ {
_RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return ( CGprogram )NULL; return ( CGprogram )NULL;
@ -7221,10 +7216,10 @@ CG_API CGprogram cgCopyProgram( CGprogram program )
} }
if (prog->header.profile == CG_PROFILE_SCE_FP_TYPEB || prog->header.profile == CG_PROFILE_SCE_FP_RSX) if (prog->header.profile == CG_PROFILE_SCE_FP_TYPEB || prog->header.profile == CG_PROFILE_SCE_FP_RSX)
{ {
newprog->ucode = (char*)newprog + paddedProgramSize; newprog->ucode = (char*)newprog + paddedProgramSize;
memcpy((char*)newprog->ucode, (char*)prog->ucode, ucodeSize); memcpy((char*)newprog->ucode, (char*)prog->ucode, ucodeSize);
} }
if ( prog->programGroup ) if ( prog->programGroup )
{ {
@ -7233,9 +7228,10 @@ CG_API CGprogram cgCopyProgram( CGprogram program )
_RGLCgUpdateProgramAtIndex( newprog->programGroup, -1, 1 ); _RGLCgUpdateProgramAtIndex( newprog->programGroup, -1, 1 );
} }
_RGLCgProgramPushFront( newprog->parentContext, newprog ); _RGLCgProgramPushFront(newprog->parentContext, newprog);
if ( _cgProgramCopyHook ) _cgProgramCopyHook( newprog, prog ); if(_cgProgramCopyHook)
_cgProgramCopyHook(newprog, prog);
return newprog->id; return newprog->id;
} }
@ -7248,7 +7244,9 @@ CG_API void cgDestroyProgram( CGprogram program )
_RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); _RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR );
return; return;
} }
_CGprogram* ptr = _cgGetProgPtr( program ); _CGprogram* ptr = _cgGetProgPtr( program );
if ( ptr == NULL ) if ( ptr == NULL )
{ {
_RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); _RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR );
@ -7282,7 +7280,7 @@ CG_API void cgDestroyProgram( CGprogram program )
ctx->programList = p->next; ctx->programList = p->next;
_RGLCgProgramErase( p ); _RGLCgProgramErase( p );
if(p != NULL) if(p != NULL)
free( p ); free( p );
} }
else else
{ {
@ -8109,12 +8107,6 @@ CGGL_API void cgGLEnableTextureParameter( CGparameter param )
ptr->samplerSetter( ptr, NULL, 0 ); ptr->samplerSetter( ptr, NULL, 0 );
} }
static void _RGLCgContextZero( _CGcontext* p )
{
memset( p, 0, sizeof( *p ) );
p->compileType = CG_UNKNOWN;
}
static void _RGLCgContextPushFront(_CGcontext* ctx) static void _RGLCgContextPushFront(_CGcontext* ctx)
{ {
if(_CurrentContext->RGLcgContextHead) if(_CurrentContext->RGLcgContextHead)
@ -8131,7 +8123,9 @@ static void destroy_context(_CGcontext*ctx)
_cgContextDestroyHook(ctx); _cgContextDestroyHook(ctx);
_RGLEraseName( &_CurrentContext->cgContextNameSpace, ( jsName )ctx->id ); _RGLEraseName( &_CurrentContext->cgContextNameSpace, ( jsName )ctx->id );
_RGLCgContextZero( ctx ); memset(ctx, 0, sizeof( *ctx ) );
ctx->compileType = CG_UNKNOWN;
free( ctx ); free( ctx );
} }
@ -8146,7 +8140,8 @@ CG_API CGcontext cgCreateContext(void)
return ( CGcontext )NULL; return ( CGcontext )NULL;
} }
_RGLCgContextZero( ptr ); memset( ptr, 0, sizeof( *ptr ) );
ptr->compileType = CG_UNKNOWN;
CGcontext result = ( CGcontext )_RGLCreateName( &_CurrentContext->cgContextNameSpace, ptr ); CGcontext result = ( CGcontext )_RGLCreateName( &_CurrentContext->cgContextNameSpace, ptr );
if ( !result ) if ( !result )

View File

@ -550,11 +550,6 @@ struct PSGLcontext
#define RGL_LIKELY(COND) (COND) #define RGL_LIKELY(COND) (COND)
#define RGL_UNLIKELY(COND) (COND) #define RGL_UNLIKELY(COND) (COND)
static inline float _RGLClampf( const float value )
{
return MAX( MIN( value, 1.f ), 0.f );
}
static inline unsigned int endianSwapWord( unsigned int v ) static inline unsigned int endianSwapWord( unsigned int v )
{ {
return ( v&0xff ) << 24 | ( v&0xff00 ) << 8 | return ( v&0xff ) << 24 | ( v&0xff00 ) << 8 |
@ -577,13 +572,6 @@ static inline unsigned long _RGLPad(unsigned long x, unsigned long pad)
return ( x + pad - 1 ) / pad*pad; return ( x + pad - 1 ) / pad*pad;
} }
static inline char* _RGLPadPtr(const char* p, unsigned int pad)
{
intptr_t x = (intptr_t)p;
x = ( x + pad - 1 ) / pad * pad;
return ( char* )x;
}
typedef struct MemoryBlockManager_t_ typedef struct MemoryBlockManager_t_
{ {
char *memory; char *memory;
@ -798,7 +786,7 @@ struct RGLResource
char * dmaPushBuffer; char * dmaPushBuffer;
GLuint dmaPushBufferSize; GLuint dmaPushBufferSize;
void* dmaControl; void* dmaControl;
RGLSemaphoreMemory *semaphores; RGLSemaphoreMemory *semaphores;
}; };
typedef volatile struct typedef volatile struct
@ -927,7 +915,7 @@ static inline GLuint _RGLPlatformGetBitsPerPixel( GLenum internalFormat )
} }
void static inline _RGLFifoGlViewport( GLint x, GLint y, GLsizei width, GLsizei height, GLclampf zNear = 0.0f, GLclampf zFar = 1.0f ) static inline void _RGLFifoGlViewport( GLint x, GLint y, GLsizei width, GLsizei height, GLclampf zNear = 0.0f, GLclampf zFar = 1.0f )
{ {
RGLViewportState *vp = &_RGLState.state.viewport; RGLViewportState *vp = &_RGLState.state.viewport;
RGLRenderTarget *rt = &_RGLState.renderTarget; RGLRenderTarget *rt = &_RGLState.renderTarget;