From 949e2c3cae49fc86874b7450b83815b3a653d621 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 17:07:42 +0100 Subject: [PATCH 1/9] (RGL PS3) Remove cgGLSet/GetManageTextureParameters - take away more state code associated to it (and speed up cgGLBindProgram in the process) --- ps3/rgl/include/Cg/CgCommon.h | 93 ------------------------------ ps3/rgl/include/RGL/private.h | 3 +- ps3/rgl/src/ps3/rgl_ps3.cpp | 6 +- ps3/rgl/src/ps3/rgl_ps3_cg.cpp | 63 ++++++++++++++------ ps3/rgl/src/ps3/rgl_ps3_raster.cpp | 76 ++++++++++++------------ 5 files changed, 86 insertions(+), 155 deletions(-) diff --git a/ps3/rgl/include/Cg/CgCommon.h b/ps3/rgl/include/Cg/CgCommon.h index 5cfc4342c4..2bd5ca6385 100644 --- a/ps3/rgl/include/Cg/CgCommon.h +++ b/ps3/rgl/include/Cg/CgCommon.h @@ -149,7 +149,6 @@ typedef struct _CGcontext struct _CGprogram* programList; // head of singly linked list of programs CGenum compileType; // compile manual, immediate or lazy (unused so far) - CGbool GLmanageTextures; unsigned int controlFlowBoolsSharedMask; unsigned int controlFlowBoolsShared; @@ -331,98 +330,6 @@ inline static void _pullConnectedParameterValues (void *data) } } -static inline void _cgGLBindVertexProgram (void *data) -{ - _CGprogram *program = (_CGprogram*)data; - // the program is a vertex program, just update the GL state - _CurrentContext->BoundVertexProgram = program; - - // and inform the GL state to re-upload the vertex program - _CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM; - - // This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine - _pullConnectedParameterValues( program ); - - CGbool is_managed = program->parentContext->GLmanageTextures; - // enable texture parameters if the managed flag is set. - if ( is_managed ) - { - for ( GLuint index = 0; index < program->samplerCount; ++index ) - { - // walk the array of sampler parameters - CgRuntimeParameter *rtParameter = program->runtimeParameters + program->samplerIndices[index]; - rtParameter->samplerSetter( rtParameter, NULL, 0 ); - } - } -} - -static inline void _cgGLBindFragmentProgram (void *data) -{ - _CGprogram *program = (_CGprogram*)data; - _CurrentContext->BoundFragmentProgram = program; - - // need to revalidate the textures in order to update which targets to fetch from - _CurrentContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS; - - // This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine - _pullConnectedParameterValues( program ); - - // TODO: push texture state - // Needs to be done per profile. Can't use glPushAttrib. - - CGbool is_managed = program->parentContext->GLmanageTextures; - - // deal with the texture parameters now. - for ( GLuint index = 0; index < program->samplerCount; ++index ) - { - // walk the array of sampler parameters - CgRuntimeParameter *rtParameter = program->runtimeParameters + program->samplerIndices[index]; - CgParameterResource *parameter = ( CgParameterResource * )( program->parameterResources + rtParameter->parameterEntry->typeIndex ); - // find out which texture unit this parameter has been assigned to - unsigned int unit = parameter->resource - CG_TEXUNIT0; - - _CurrentContext->TextureImageUnits[unit].fragmentTarget = rtParameter->glType; - - // enable texture parameters if the managed flag is set. - if ( is_managed ) - { - //tmp - rtParameter->samplerSetter( rtParameter, NULL, 0 ); - } - else - { - rglUpdateCurrentTextureCache( &_CurrentContext->TextureImageUnits[unit] ); - } - } -} - -static inline void _cgGLUnbindVertexProgram (void) -{ - _CurrentContext->BoundVertexProgram = NULL; - _CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM; -} - -static inline void rglLeaveFFXFP (void *data) -{ - RGLcontext *LContext = (RGLcontext*)data; - LContext->FragmentProgram = GL_TRUE; - struct _CGprogram* current = LContext->BoundFragmentProgram; - if ( current ) - { - for ( GLuint i = 0; i < current->samplerCount; ++i ) - { - int unit = current->samplerUnits[i]; - rglUpdateCurrentTextureCache( &_CurrentContext->TextureImageUnits[unit] ); - } - } - LContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS; -} - -static inline void _cgGLUnbindFragmentProgram (void) -{ - _CurrentContext->BoundFragmentProgram = NULL; -} - static inline GLenum rglCgGetSamplerGLTypeFromCgType( CGtype type ) { switch ( type ) diff --git a/ps3/rgl/include/RGL/private.h b/ps3/rgl/include/RGL/private.h index 89b6ba4a06..08fc6388ea 100644 --- a/ps3/rgl/include/RGL/private.h +++ b/ps3/rgl/include/RGL/private.h @@ -86,7 +86,7 @@ static inline void rglTextureTouchFBOs (void *data) rglFramebuffer* framebuffer = texture->framebuffers[i]; framebuffer->needValidate = GL_TRUE; if (RGL_UNLIKELY( framebuffer == contextFramebuffer)) - LContext->needValidate |= PSGL_VALIDATE_SCISSOR_BOX | PSGL_VALIDATE_FRAMEBUFFER; + LContext->needValidate |= PSGL_VALIDATE_FRAMEBUFFER; } } } @@ -199,7 +199,6 @@ void rglPlatformGetImageData( GLenum target, GLint level, rglTexture *texture, r //---------------------------------------- // Raster/.../PlatformFBops.c //---------------------------------------- -extern void rglValidateFramebuffer( void ); extern void rglPlatformReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLboolean flip, GLenum format, GLenum type, GLvoid *pixels ); extern GLboolean rglPlatformReadPBOPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLboolean flip, GLenum format, GLenum type, GLvoid *pixels ); diff --git a/ps3/rgl/src/ps3/rgl_ps3.cpp b/ps3/rgl/src/ps3/rgl_ps3.cpp index 93bfc5a8e0..15627ad7fa 100644 --- a/ps3/rgl/src/ps3/rgl_ps3.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3.cpp @@ -3476,7 +3476,7 @@ GLAPI void APIENTRY glBindFramebufferOES( GLenum target, GLuint framebuffer ) rglTexNameSpaceCreateNameLazy( &LContext->framebufferNameSpace, framebuffer ); LContext->framebuffer = framebuffer; - LContext->needValidate |= RGL_VALIDATE_SCISSOR_BOX | RGL_VALIDATE_FRAMEBUFFER; + LContext->needValidate |= RGL_VALIDATE_FRAMEBUFFER; } GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei n, const GLuint *framebuffers ) @@ -3541,7 +3541,7 @@ GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum target, GLenum attachment, attach->textureTarget = textarget; framebuffer->needValidate = GL_TRUE; - LContext->needValidate |= RGL_VALIDATE_SCISSOR_BOX | RGL_VALIDATE_FRAMEBUFFER; + LContext->needValidate |= RGL_VALIDATE_FRAMEBUFFER; } @@ -4776,7 +4776,7 @@ void RGL_EXPORT psglMakeCurrent (RGLcontext *context, RGLdevice *device) { context->ViewPort.XSize = device->deviceParameters.width; context->ViewPort.YSize = device->deviceParameters.height; - context->needValidate |= RGL_VALIDATE_VIEWPORT | RGL_VALIDATE_SCISSOR_BOX; + context->needValidate |= RGL_VALIDATE_VIEWPORT; context->everAttached = GL_TRUE; } diff --git a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp index e030d8c6e9..d6ed0c582c 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp @@ -6437,7 +6437,19 @@ CGGL_API void cgGLEnableProfile( CGprofile profile ) case CG_PROFILE_SCE_FP_TYPEB: case CG_PROFILE_SCE_FP_RSX: - rglLeaveFFXFP( LContext ); + { + LContext->FragmentProgram = GL_TRUE; + struct _CGprogram* current = LContext->BoundFragmentProgram; + if ( current ) + { + for ( GLuint i = 0; i < current->samplerCount; ++i ) + { + int unit = current->samplerUnits[i]; + rglUpdateCurrentTextureCache( &_CurrentContext->TextureImageUnits[unit] ); + } + } + LContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED; + } break; default: rglCgRaiseError( CG_INVALID_PROFILE_ERROR ); @@ -6521,14 +6533,42 @@ CGGL_API void cgGLBindProgram( CGprogram program ) //hack to counter removal of TypeC during beta case 7005: case CG_PROFILE_SCE_VP_RSX: - _cgGLBindVertexProgram( ptr ); + // the program is a vertex program, just update the GL state + _CurrentContext->BoundVertexProgram = ptr; + + // and inform the GL state to re-upload the vertex program + _CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM; + + // This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine + _pullConnectedParameterValues( ptr ); break; case CG_PROFILE_SCE_FP_TYPEB: //hack to counter removal of TypeC during beta case 7006: case CG_PROFILE_SCE_FP_RSX: - _cgGLBindFragmentProgram( ptr ); + _CurrentContext->BoundFragmentProgram = ptr; + + // need to revalidate the textures in order to update which targets to fetch from + _CurrentContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED; + + // This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine + _pullConnectedParameterValues( ptr ); + + // TODO: push texture state + // Needs to be done per profile. Can't use glPushAttrib. + + // deal with the texture parameters now. + for ( GLuint index = 0; index < ptr->samplerCount; ++index ) + { + // walk the array of sampler parameters + CgRuntimeParameter *rtParameter = ptr->runtimeParameters + ptr->samplerIndices[index]; + CgParameterResource *parameter = ( CgParameterResource * )( ptr->parameterResources + rtParameter->parameterEntry->typeIndex ); + // find out which texture unit this parameter has been assigned to + unsigned int unit = parameter->resource - CG_TEXUNIT0; + _CurrentContext->TextureImageUnits[unit].fragmentTarget = rtParameter->glType; + rglUpdateCurrentTextureCache( &_CurrentContext->TextureImageUnits[unit] ); + } break; default: @@ -6547,7 +6587,8 @@ CGGL_API void cgGLUnbindProgram( CGprofile profile ) case CG_PROFILE_SCE_VP_RSX: //hack to counter removal of TypeC during beta case 7005: - _cgGLUnbindVertexProgram(); + _CurrentContext->BoundVertexProgram = NULL; + _CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM; // no need to invalidate textures because they are only available on programmable pipe. break; case CG_PROFILE_SCE_FP_TYPEB: @@ -6555,8 +6596,7 @@ CGGL_API void cgGLUnbindProgram( CGprofile profile ) case CG_PROFILE_SCE_FP_RSX: //hack to counter removal of TypeC during beta case 7006: - _cgGLUnbindFragmentProgram(); - + _CurrentContext->BoundFragmentProgram = NULL; break; default: rglCgRaiseError( CG_INVALID_PROFILE_ERROR ); @@ -7368,17 +7408,6 @@ CGGL_API GLenum cgGLGetTextureEnum( CGparameter param ) return GL_TEXTURE0 + parameterResource->resource - CG_TEXUNIT0; } -CGGL_API void cgGLSetManageTextureParameters( CGcontext ctx, CGbool flag ) -{ - _cgGetContextPtr( ctx )->GLmanageTextures = flag; -} - -CGGL_API CGbool cgGLGetManageTextureParameters( CGcontext ctx ) -{ - return _cgGetContextPtr( ctx )->GLmanageTextures; -} - - void cgGLSetParameter1b( CGparameter param, CGbool v ) { CgRuntimeParameter* ptr = rglCgGLTestParameter( param ); diff --git a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp index 3a507f6a8d..882040c744 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp @@ -131,7 +131,6 @@ template static void setVectorTypeSharedfpIndex (void *data, const voi values[3] = ( 3 < SIZE ) ? SWAP_IF_BIG_ENDIAN( vi[3] ) : 0; GCM_FUNC( cellGcmInlineTransfer, dstVidOffset, values, 4, 0 ); - LContext->needValidate |= RGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS; // XXX we don't care about 32bit wrapping, do we ? ++LContext->LastFPConstantModification; } @@ -164,7 +163,6 @@ template static void setVectorTypeSharedfpIndexArray (void *data, cons values[3] = ( 3 < SIZE ) ? SWAP_IF_BIG_ENDIAN( vi[3] ) : 0; GCM_FUNC( cellGcmInlineTransfer, dstVidOffset, values, 4, 0 ); - LContext->needValidate |= RGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS; // XXX we don't care about 32bit wrapping, do we ? ++LContext->LastFPConstantModification; } @@ -359,7 +357,6 @@ template static void setMatrixSharedfpIndex (voi } RGLcontext * LContext = _CurrentContext; - LContext->needValidate |= RGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS; ++LContext->LastFPConstantModification; } @@ -408,7 +405,6 @@ template static void setMatrixSharedfpIndexArray } RGLcontext * LContext = _CurrentContext; - LContext->needValidate |= RGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS; ++LContext->LastFPConstantModification; } @@ -1322,6 +1318,41 @@ GLboolean rglPlatformBufferObjectUnmap (void *data) PLATFORM FRAMEBUFFER ============================================================ */ +// set render targets +static void rglValidateFramebuffer (void) +{ + RGLdevice *LDevice = _CurrentDevice; + rglGcmDevice *gcmDevice = ( rglGcmDevice * )LDevice->platformDevice; + + RGLcontext* LContext = _CurrentContext; + rglGcmDriver *gcmDriver = (rglGcmDriver*)_CurrentDevice->rasterDriver; + + // reset buffer data + gcmDriver->rtValid = GL_FALSE; + // get buffer parameters + // This may come from a framebuffer_object or the default framebuffer. + // + gcmDriver->rt = gcmDevice->rt; + + if (LContext->framebuffer) + { + rglPlatformFramebuffer* framebuffer = (rglPlatformFramebuffer *)rglGetFramebuffer(LContext, LContext->framebuffer); + + if (framebuffer->needValidate) + framebuffer->validate( LContext ); + + gcmDriver->rt = framebuffer->rt; + } + + gcmDriver->rtValid = GL_TRUE; + + // update GPU configuration + rglGcmFifoGlSetRenderTarget( &gcmDriver->rt ); + + LContext->needValidate &= ~RGL_VALIDATE_FRAMEBUFFER; + LContext->needValidate |= RGL_VALIDATE_VIEWPORT; +} + GLAPI void APIENTRY glClear( GLbitfield mask ) { RGLcontext* LContext = _CurrentContext; @@ -1404,7 +1435,7 @@ GLAPI void APIENTRY glClear( GLbitfield mask ) int clearcolor = 0; GCM_FUNC( cellGcmSetVertexData4f, RGL_ATTRIB_PRIMARY_COLOR_INDEX, ( GLfloat* )&clearcolor ); - LContext->needValidate |= RGL_VALIDATE_WRITE_MASK | RGL_VALIDATE_FRAGMENT_PROGRAM; + LContext->needValidate |= RGL_VALIDATE_FRAGMENT_PROGRAM; gmmFree( bufferId ); } @@ -1570,41 +1601,6 @@ void rglPlatformFramebuffer::validate (void *data) needValidate = GL_FALSE; } -// set render targets -void rglValidateFramebuffer (void) -{ - RGLdevice *LDevice = _CurrentDevice; - rglGcmDevice *gcmDevice = ( rglGcmDevice * )LDevice->platformDevice; - - RGLcontext* LContext = _CurrentContext; - rglGcmDriver *gcmDriver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - - // reset buffer data - gcmDriver->rtValid = GL_FALSE; - // get buffer parameters - // This may come from a framebuffer_object or the default framebuffer. - - if (LContext->framebuffer) - { - rglPlatformFramebuffer* framebuffer = (rglPlatformFramebuffer *)rglGetFramebuffer(LContext, LContext->framebuffer); - - if (framebuffer->needValidate) - framebuffer->validate( LContext ); - - gcmDriver->rt = framebuffer->rt; - } - else // use default framebuffer - gcmDriver->rt = gcmDevice->rt; - - gcmDriver->rtValid = GL_TRUE; - - // update GPU configuration - rglGcmFifoGlSetRenderTarget( &gcmDriver->rt ); - - LContext->needValidate &= ~RGL_VALIDATE_FRAMEBUFFER; - LContext->needValidate |= RGL_VALIDATE_VIEWPORT | RGL_VALIDATE_SCISSOR_BOX - | RGL_VALIDATE_WRITE_MASK; -} /*============================================================ PLATFORM RASTER From a3692f88548e244148cb04bfc351e6768cdb80ac Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 19:18:48 +0100 Subject: [PATCH 2/9] (RGL PS3) Slim down Cg implementation --- ps3/rgl/include/Cg/CgCommon.h | 14 +- ps3/rgl/src/ps3/rgl_ps3_cg.cpp | 2006 +--------------------------- ps3/rgl/src/ps3/rgl_ps3_raster.cpp | 27 +- 3 files changed, 16 insertions(+), 2031 deletions(-) diff --git a/ps3/rgl/include/Cg/CgCommon.h b/ps3/rgl/include/Cg/CgCommon.h index 2bd5ca6385..b7fa56afcf 100644 --- a/ps3/rgl/include/Cg/CgCommon.h +++ b/ps3/rgl/include/Cg/CgCommon.h @@ -83,8 +83,6 @@ struct _CGprogram unsigned int * samplerIndices; unsigned int * samplerUnits; - unsigned int controlFlowBools; - //binary format additions //info previously contained in platformProgram ( loadAddress + nvBinary ) CgProgramHeader header; @@ -150,9 +148,6 @@ typedef struct _CGcontext CGenum compileType; // compile manual, immediate or lazy (unused so far) - unsigned int controlFlowBoolsSharedMask; - unsigned int controlFlowBoolsShared; - // default program, fake owner of the context parameters _CGprogram defaultProgram; @@ -170,16 +165,13 @@ RGL_EXPORT void rglCgRaiseError( CGerror error ); // interface between object types extern void rglCgProgramDestroyAll( _CGcontext* c ); extern void rglCgDestroyContextParam( CgRuntimeParameter* p ); -RGL_EXPORT CgRuntimeParameter*rglCgCreateParameterInternal( _CGprogram *program, const char* name, CGtype type ); RGL_EXPORT void rglCgProgramErase( _CGprogram* prog ); // default setters void _cgRaiseInvalidParam( void *data, const void*v ); void _cgRaiseNotMatrixParam( void *data, const void*v ); void _cgIgnoreSetParam( void *dat, const void*v ); -void _cgRaiseInvalidParamIndex( void *dat, const void*v, const int index ); -void _cgRaiseNotMatrixParamIndex( void *dat, const void*v, const int index ); -void _cgIgnoreSetParamIndex( void *dat, const void*v, const int index ); +void _cgIgnoreParamIndex( void *dat, const void*v, const int index ); // cg helpers @@ -212,7 +204,6 @@ static inline bool isSampler (CGtype type) unsigned int rglCountFloatsInCgType( CGtype type ); -CGbool _cgMatrixDimensions( CGtype type, unsigned int* nrows, unsigned int* ncols ); unsigned int rglGetTypeRowCount( CGtype parameterType ); unsigned int rglGetTypeColCount( CGtype parameterType ); @@ -314,9 +305,8 @@ void rglPlatformSetFragmentRegisterBlock (unsigned int reg, unsigned int count, void rglPlatformSetBoolVertexRegisters (unsigned int values ); // names API -RGL_EXPORT unsigned int _cgHashString (const char *str); -inline static void _pullConnectedParameterValues (void *data) +static inline void _pullConnectedParameterValues (void *data) { _CGprogram *ptr = (_CGprogram*)data; // we now use a pull method to get the data into the children parameters diff --git a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp index d6ed0c582c..f0b9d30854 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp @@ -834,136 +834,19 @@ unsigned int rglCountFloatsInCgType( CGtype type ) void _cgRaiseInvalidParam (void *data, const void*v ) { (void)data; - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); -} -void _cgRaiseInvalidParamIndex (void *data, const void*v, const int index ) -{ - (void)data; - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); } void _cgRaiseNotMatrixParam (void *data, const void*v ) { (void)data; - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); } -void _cgRaiseNotMatrixParamIndex( void *data, const void*v, const int index ) -{ - (void)data; - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); -} - -void _cgIgnoreSetParamIndex (void *data, const void*v, const int index ) +void _cgIgnoreParamIndex (void *data, const void*v, const int index ) { (void)data; // nothing } -CGbool _cgMatrixDimensions( CGtype type, unsigned int* nrows, unsigned int* ncols ) -{ - CGbool isMatrixType = CG_TRUE; - switch ( type ) - { - case CG_FLOAT: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_FLOAT1: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_HALF: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_HALF1: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_INT: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_INT1: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_BOOL: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_BOOL1: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_FIXED: *nrows = 1; *ncols = 1; isMatrixType = CG_FALSE; break; - case CG_FIXED1: *nrows = 1; *ncols = 2; isMatrixType = CG_FALSE; break; - - - case CG_FLOAT1x1: *nrows = 1; *ncols = 1; break; - case CG_FLOAT1x2: *nrows = 1; *ncols = 2; break; - case CG_FLOAT1x3: *nrows = 1; *ncols = 3; break; - case CG_FLOAT1x4: *nrows = 1; *ncols = 4; break; - case CG_FLOAT2x1: *nrows = 2; *ncols = 1; break; - case CG_FLOAT2x2: *nrows = 2; *ncols = 2; break; - case CG_FLOAT2x3: *nrows = 2; *ncols = 3; break; - case CG_FLOAT2x4: *nrows = 2; *ncols = 4; break; - case CG_FLOAT3x1: *nrows = 3; *ncols = 1; break; - case CG_FLOAT3x2: *nrows = 3; *ncols = 2; break; - case CG_FLOAT3x3: *nrows = 3; *ncols = 3; break; - case CG_FLOAT3x4: *nrows = 3; *ncols = 4; break; - case CG_FLOAT4x1: *nrows = 4; *ncols = 1; break; - case CG_FLOAT4x2: *nrows = 4; *ncols = 2; break; - case CG_FLOAT4x3: *nrows = 4; *ncols = 3; break; - case CG_FLOAT4x4: *nrows = 4; *ncols = 4; break; - case CG_HALF1x1: *nrows = 1; *ncols = 1; break; - case CG_HALF1x2: *nrows = 1; *ncols = 2; break; - case CG_HALF1x3: *nrows = 1; *ncols = 3; break; - case CG_HALF1x4: *nrows = 1; *ncols = 4; break; - case CG_HALF2x1: *nrows = 2; *ncols = 1; break; - case CG_HALF2x2: *nrows = 2; *ncols = 2; break; - case CG_HALF2x3: *nrows = 2; *ncols = 3; break; - case CG_HALF2x4: *nrows = 2; *ncols = 4; break; - case CG_HALF3x1: *nrows = 3; *ncols = 1; break; - case CG_HALF3x2: *nrows = 3; *ncols = 2; break; - case CG_HALF3x3: *nrows = 3; *ncols = 3; break; - case CG_HALF3x4: *nrows = 3; *ncols = 4; break; - case CG_HALF4x1: *nrows = 4; *ncols = 1; break; - case CG_HALF4x2: *nrows = 4; *ncols = 2; break; - case CG_HALF4x3: *nrows = 4; *ncols = 3; break; - case CG_HALF4x4: *nrows = 4; *ncols = 4; break; - case CG_INT1x1: *nrows = 1; *ncols = 1; break; - case CG_INT1x2: *nrows = 1; *ncols = 2; break; - case CG_INT1x3: *nrows = 1; *ncols = 3; break; - case CG_INT1x4: *nrows = 1; *ncols = 4; break; - case CG_INT2x1: *nrows = 2; *ncols = 1; break; - case CG_INT2x2: *nrows = 2; *ncols = 2; break; - case CG_INT2x3: *nrows = 2; *ncols = 3; break; - case CG_INT2x4: *nrows = 2; *ncols = 4; break; - case CG_INT3x1: *nrows = 3; *ncols = 1; break; - case CG_INT3x2: *nrows = 3; *ncols = 2; break; - case CG_INT3x3: *nrows = 3; *ncols = 3; break; - case CG_INT3x4: *nrows = 3; *ncols = 4; break; - case CG_INT4x1: *nrows = 4; *ncols = 1; break; - case CG_INT4x2: *nrows = 4; *ncols = 2; break; - case CG_INT4x3: *nrows = 4; *ncols = 3; break; - case CG_INT4x4: *nrows = 4; *ncols = 4; break; - case CG_BOOL1x1: *nrows = 1; *ncols = 1; break; - case CG_BOOL1x2: *nrows = 1; *ncols = 2; break; - case CG_BOOL1x3: *nrows = 1; *ncols = 3; break; - case CG_BOOL1x4: *nrows = 1; *ncols = 4; break; - case CG_BOOL2x1: *nrows = 2; *ncols = 1; break; - case CG_BOOL2x2: *nrows = 2; *ncols = 2; break; - case CG_BOOL2x3: *nrows = 2; *ncols = 3; break; - case CG_BOOL2x4: *nrows = 2; *ncols = 4; break; - case CG_BOOL3x1: *nrows = 3; *ncols = 1; break; - case CG_BOOL3x2: *nrows = 3; *ncols = 2; break; - case CG_BOOL3x3: *nrows = 3; *ncols = 3; break; - case CG_BOOL3x4: *nrows = 3; *ncols = 4; break; - case CG_BOOL4x1: *nrows = 4; *ncols = 1; break; - case CG_BOOL4x2: *nrows = 4; *ncols = 2; break; - case CG_BOOL4x3: *nrows = 4; *ncols = 3; break; - case CG_BOOL4x4: *nrows = 4; *ncols = 4; break; - case CG_FIXED1x1: *nrows = 1; *ncols = 1; break; - case CG_FIXED1x2: *nrows = 1; *ncols = 2; break; - case CG_FIXED1x3: *nrows = 1; *ncols = 3; break; - case CG_FIXED1x4: *nrows = 1; *ncols = 4; break; - case CG_FIXED2x1: *nrows = 2; *ncols = 1; break; - case CG_FIXED2x2: *nrows = 2; *ncols = 2; break; - case CG_FIXED2x3: *nrows = 2; *ncols = 3; break; - case CG_FIXED2x4: *nrows = 2; *ncols = 4; break; - case CG_FIXED3x1: *nrows = 3; *ncols = 1; break; - case CG_FIXED3x2: *nrows = 3; *ncols = 2; break; - case CG_FIXED3x3: *nrows = 3; *ncols = 3; break; - case CG_FIXED3x4: *nrows = 3; *ncols = 4; break; - case CG_FIXED4x1: *nrows = 4; *ncols = 1; break; - case CG_FIXED4x2: *nrows = 4; *ncols = 2; break; - case CG_FIXED4x3: *nrows = 4; *ncols = 3; break; - case CG_FIXED4x4: *nrows = 4; *ncols = 4; break; - default: *nrows = 0; *ncols = 0; break; - } - - return isMatrixType; -} - - CgRuntimeParameter* _cgGLTestArrayParameter( CGparameter paramIn, long offset, long nelements ) { CgRuntimeParameter* param = rglCgGLTestParameter( paramIn ); @@ -1014,107 +897,6 @@ static const CGenum dir_table[] = {CG_IN, CG_OUT, CG_INOUT, CG_ERROR}; RGL_EXPORT CgparameterHookFunction _cgParameterCreateHook = NULL; RGL_EXPORT CgparameterHookFunction _cgParameterDestroyHook = NULL; -static void rglCgGetParameterResourceInfo( CgRuntimeParameter *rtParameter, int arrayIndex, CGresource *resource, unsigned long *resourceIndex, unsigned short* numEmbeddedConstants) -{ - const CgParameterEntry *paramEntry = rtParameter->parameterEntry; - const CgParameterResource *paramResource = rglGetParameterResource( rtParameter->program, paramEntry ); - - const unsigned short *paramResourceTable = rtParameter->program->resources; - - if (( paramEntry->flags & CGPV_MASK ) == CGPV_VARYING ) - { - *resource = ( CGresource )paramResource->resource; - *resourceIndex = -1U; - } - else if ((( paramEntry->flags & CGPV_MASK ) & CGPV_CONSTANT ) || (( paramEntry->flags & CGPV_MASK ) & CGPV_UNIFORM ) ) - { - CGtype parameterResourceType = rglGetParameterCGtype( rtParameter->program, paramEntry ); - - if ( parameterResourceType >= CG_SAMPLER1D && parameterResourceType <= CG_SAMPLERCUBE ) - { - *resource = ( CGresource )paramResource->resource; - *resourceIndex = 0; - } - else - { - if ( parameterResourceType == CGP_SCF_BOOL ) - *resource = CG_B; - else - *resource = CG_C; - - bool bIsVertexProgram; - switch ( rtParameter->program->header.profile ) - { - case CG_PROFILE_SCE_VP_TYPEB: - case ( CGprofile )7005: - case CG_PROFILE_SCE_VP_RSX: - bIsVertexProgram = true; - break; - default: - bIsVertexProgram = false; - break; - } - - - unsigned int rows = rglGetTypeRowCount( parameterResourceType ); - if ( rows == 0 ) - rows = 1; - - *numEmbeddedConstants = 0; - - if ( bIsVertexProgram ) - { - if ( arrayIndex >= 0 ) - { - if ( paramEntry->flags & CGP_CONTIGUOUS ) - { - *resourceIndex = paramResource->resource + arrayIndex * rows; - } - else - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + arrayIndex * rows ); - *resourceIndex = ( tempResIndex == 0xFFFF ) ? -1U : ( int )tempResIndex; - } - } - else - { - unsigned short tempResIndex = paramResource->resource; - *resourceIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - } - else - { - const unsigned short* resPtr = paramResourceTable + paramResource->resource; - if ( arrayIndex < 0 ) - arrayIndex = 0; - - int skipCount = arrayIndex * rows; - while ( skipCount ) - { - resPtr++; - int embeddedCount = *( resPtr++ ); - resPtr += embeddedCount; - skipCount--; - } - unsigned short tempResIndex = *( resPtr ); - - while (rows) - { - resPtr++; // skip register - unsigned short ecCount = *resPtr; - resPtr++; - *numEmbeddedConstants += ecCount; - resPtr += ecCount; - rows--; - } - - *resourceIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - } - - } -} - static CGparameter rglAdvanceParameter( CGparameter param, int distance ) { CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); @@ -1203,47 +985,6 @@ static CGparameter rglAdvanceParameter( CGparameter param, int distance ) } } -unsigned int _cgHashString( const char *str ) -{ - unsigned int h = 0; - unsigned int g; - while ( *str ) - { - h = ( h << 4 ) + *str++; - if (( g = h & 0xf0000000 ) ) h ^= g >> 24; - h &= ~g; - } - return h; -} - -static int connection_creates_cycle( CgRuntimeParameter* paramFrom, CgRuntimeParameter* paramTo ) -{ - CgRuntimeParameter* paramHierarchyIter = paramFrom; - while ( paramHierarchyIter != NULL ) - { - if ( paramHierarchyIter == paramTo ) - { - return 1; - } - - std::vector::iterator paramConnectionTableIter = paramHierarchyIter->program->connectionTable.begin(); - while ( paramConnectionTableIter != paramHierarchyIter->program->connectionTable.end() ) - { - if ( paramConnectionTableIter->child == paramHierarchyIter ) - { - paramHierarchyIter = paramConnectionTableIter->parent; - break; - } - paramConnectionTableIter++; - } - if ( paramConnectionTableIter == paramHierarchyIter->program->connectionTable.end() ) - { - paramHierarchyIter = NULL; - } - } - return 0; -} - void rglCgDestroyContextParam( CgRuntimeParameter* ptr ) { std::vector::iterator semanticIter = ptr->program->parameterSemantics.begin(); @@ -1286,129 +1027,6 @@ void rglCgDestroyContextParam( CgRuntimeParameter* ptr ) free( ptr ); } -static void _setSamplerRuntimeParameter (void *data, const void*v, int /*index*/ ) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - if (v) - { - *( GLuint* )ptr->pushBufferPointer = *( GLuint* )v; - } -} - -CgRuntimeParameter* rglCgCreateParameterInternal( _CGprogram *program, const char* name, CGtype type ) -{ - CgRuntimeParameter* param = NULL; - int isSampler = 0; - switch ( type ) - { - case CG_SAMPLER2D: - case CG_SAMPLER3D: - case CG_SAMPLERCUBE: - isSampler = 1; - case CG_FLOAT: // fall through - case CG_FLOAT1: - case CG_FLOAT2: - case CG_FLOAT3: - case CG_FLOAT4: - case CG_FLOAT1x1: - case CG_FLOAT2x1: - case CG_FLOAT1x2: - case CG_FLOAT3x1: - case CG_FLOAT1x3: - case CG_FLOAT4x1: - case CG_FLOAT1x4: - case CG_FLOAT2x2: - case CG_FLOAT2x3: - case CG_FLOAT3x2: - case CG_FLOAT2x4: - case CG_FLOAT4x2: - case CG_FLOAT3x3: - case CG_FLOAT3x4: - case CG_FLOAT4x3: - case CG_FLOAT4x4: - { - unsigned int size = sizeof( CgRuntimeParameter ) + sizeof( CgParameterEntry ) + - ( rglCountFloatsInCgType( type ) * sizeof( float ) ) + ( name ? strlen( name ) + 1 : 1 ); - - param = ( CgRuntimeParameter* ) malloc( size ); - - if ( !param ) { rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); return NULL; } - memset( param, 0, size ); - - CGparameter id = ( CGparameter )rglCreateName( &_CurrentContext->cgParameterNameSpace, param ); - if ( !id ) { free( param ); return NULL;} - - param->id = id; - - param->program = program; - - param->parameterEntry = ( CgParameterEntry * )(( char* )param + sizeof( CgRuntimeParameter ) ); - param->pushBufferPointer = ( void * )(( char* )param->parameterEntry + sizeof( CgParameterEntry ) ); - - CgParameterEntry* paramEntryInitializer = const_cast( param->parameterEntry ); - - paramEntryInitializer->nameOffset = ( unsigned int )(( char* )param->pushBufferPointer + rglCountFloatsInCgType( type ) * sizeof( float ) ); - - program->runtimeCreatedParameters.push_back( param ); - - if ( name ) - { - strcpy( reinterpret_cast( paramEntryInitializer->nameOffset ), name ); - } - - paramEntryInitializer->typeIndex = ( unsigned short )type; - - paramEntryInitializer->flags = 0; - paramEntryInitializer->flags |= CGP_RTCREATED; - paramEntryInitializer->flags |= CGPD_IN | CGPV_UNIFORM; - paramEntryInitializer->flags |= CGPF_GLOBAL; - - if ( isSampler ) - { - param->glType = rglCgGetSamplerGLTypeFromCgType( type ); - paramEntryInitializer->flags |= CGPF_REFERENCED; - } - - param->setterIndex = _cgRaiseInvalidParamIndex; - param->settercIndex = _cgRaiseNotMatrixParamIndex; - param->setterrIndex = _cgRaiseNotMatrixParamIndex; - param->samplerSetter = _cgRaiseInvalidParamIndex; - - switch ( type ) - { - case CG_FLOAT: - case CG_FLOAT1: case CG_FLOAT2: case CG_FLOAT3: case CG_FLOAT4: - { - unsigned int floatCount = rglCountFloatsInCgType( type ); - param->setterIndex = getVectorTypeIndexSetterFunction( 0, 0, VERTEX_PROFILE_INDEX, floatCount - 1 ); - } - break; - case CG_FLOAT1x1: case CG_FLOAT1x2: case CG_FLOAT1x3: case CG_FLOAT1x4: - case CG_FLOAT2x1: case CG_FLOAT2x2: case CG_FLOAT2x3: case CG_FLOAT2x4: - case CG_FLOAT3x1: case CG_FLOAT3x2: case CG_FLOAT3x3: case CG_FLOAT3x4: - case CG_FLOAT4x1: case CG_FLOAT4x2: case CG_FLOAT4x3: case CG_FLOAT4x4: - param->setterrIndex = getMatrixTypeIndexSetterFunction( 0, 0, VERTEX_PROFILE_INDEX, rglGetTypeRowCount( type ) - 1, rglGetTypeColCount( type ) - 1, 0 ); - param->settercIndex = getMatrixTypeIndexSetterFunction( 0, 0, VERTEX_PROFILE_INDEX, rglGetTypeRowCount( type ) - 1, rglGetTypeColCount( type ) - 1, 1 ); - break; - case CG_SAMPLER1D: case CG_SAMPLER2D: case CG_SAMPLER3D: case CG_SAMPLERRECT: case CG_SAMPLERCUBE: - param->samplerSetter = _setSamplerRuntimeParameter; - break; - case CGP_SCF_BOOL: - break; - default: - break; - } - - if ( _cgParameterCreateHook ) _cgParameterCreateHook( param ); - break; - } - default: - rglCgRaiseError( CG_INVALID_VALUE_TYPE_ERROR ); - break; - } - return param; -} - static int rglGetSizeofSubArray( const short *dimensions, int count ) { int res = 1; @@ -1628,364 +1246,9 @@ static _CGparameter *_cgGetNamedParameter( _CGprogram* progPtr, const char* name else return NULL; } + // API functions ---------------------------------------- -CG_API CGparameter cgCreateParameter( CGcontext ctx, CGtype type ) -{ - // This routine is currently (release 0.2.1) a nop. When it is changed to generate new parameters this will impact the - // debugger runtime because all cg routines that take parameters as inputs must be matched to their production. - // See the discussion of producer-consumer deficiencies in the design document for the debugger runtime (RGLPerfTool). - - // check context handle - if ( !CG_IS_CONTEXT( ctx ) ) - { - rglCgRaiseError( CG_INVALID_CONTEXT_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - _CGcontext * ctxPtr = _cgGetContextPtr( ctx ); - _CGprogram * program = &ctxPtr->defaultProgram; - CgRuntimeParameter *param = rglCgCreateParameterInternal( program, NULL, type ); - return param ? param->id : NULL; -} - -CG_API CGparameter cgCreateParameterArray( CGcontext ctx, CGtype type, int length ) -{ - // check context handle - if ( !CG_IS_CONTEXT( ctx ) ) - { - rglCgRaiseError( CG_INVALID_CONTEXT_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - // TODO ********** - return ( CGparameter )NULL; -} - -CG_API CGparameter cgCreateParameterMultiDimArray( CGcontext ctx, CGtype type, int dim, const int* lengths ) -{ - // check context handle - if ( !CG_IS_CONTEXT( ctx ) ) - { - rglCgRaiseError( CG_INVALID_CONTEXT_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - // TODO ********** - return ( CGparameter )NULL; -} - - -CG_API void cgDestroyParameter( CGparameter param ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - CgRuntimeParameter *rtParam = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - - // check that the param was created via cgCreateParameter - if ( !is_created_param( rtParam ) ) - { - rglCgRaiseError( CG_PARAMETER_IS_NOT_SHARED_ERROR ); - return; - } - - // check to see if parameter is not a source before deletion - bool isConnectionParent = false; - struct _CGprogram* programIter = rtParam->program->parentContext->programList; - while ( programIter != NULL ) - { - // search the program's connection table to find if this is a parent param to anybody - std::vector::iterator paramConnectionTableIter = programIter->connectionTable.begin(); - while ( paramConnectionTableIter != programIter->connectionTable.end() ) - { - if ( paramConnectionTableIter->parent == rtParam ) - { - isConnectionParent = true; - break; - } - paramConnectionTableIter++; - } - programIter = programIter->next; - } - if ( isConnectionParent ) - { - rglCgRaiseError( CG_CANNOT_DESTROY_PARAMETER_ERROR ); - return; - } - - // this call will call a hook function to clean up the fx if needed - rglCgDestroyContextParam( rtParam ); - -} - -CG_API void cgConnectParameter( CGparameter from, CGparameter to ) -{ - // check parameter handles - if ( !CG_IS_PARAMETER( from ) || !CG_IS_PARAMETER( to ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - // check and get parameter handles - CgRuntimeParameter *rtParamFrom = ( CgRuntimeParameter* )rglCgGLTestParameter( from ); - CgRuntimeParameter *rtParamTo = ( CgRuntimeParameter* )rglCgGLTestParameter( to ); - - // check that the param was created via cgCreateParameter - if ( !is_created_param( rtParamFrom ) ) - { - rglCgRaiseError( CG_PARAMETER_IS_NOT_SHARED_ERROR ); - return; - } - - if ( connection_creates_cycle( rtParamFrom, rtParamTo ) ) - { - rglCgRaiseError( CG_BIND_CREATES_CYCLE_ERROR ); - return; - } - - // type index is actually the offset into the block of memory following the entries - CGtype typeFrom = rglGetParameterCGtype( rtParamFrom->program, rtParamFrom->parameterEntry ); - CGtype typeTo = rglGetParameterCGtype( rtParamTo->program, rtParamTo->parameterEntry ); - if ( typeFrom != typeTo ) - { - // simple for now. - rglCgRaiseError( CG_PARAMETERS_DO_NOT_MATCH_ERROR ); - return; - } - - // (for array types) check that types match - // rglCgRaiseError(CG_ARRAY_TYPES_DO_NOT_MATCH_ERROR); - - // (for array types) check that all dimensions match - // rglCgRaiseError(CG_ARRAY_DIMENSIONS_DO_NOT_MATCH_ERROR); - - // we will need the top param to all for quick pull from arbitrarily deep hierarchies - // it gets updated if top gets disconnected from parent - // all the checks will have already happened when the initial connection was made - CgRuntimeParameter *rtParamTop = rtParamFrom; - // search parent connections in parent program and walk up to top - std::vector::iterator paramConnectionTableIter = rtParamTop->program->connectionTable.begin(); - while ( paramConnectionTableIter != rtParamTop->program->connectionTable.end() ) - { - // if this parameter is the child in a table, return its parent - if ( paramConnectionTableIter->child == rtParamTop ) - { - rtParamTop = paramConnectionTableIter->parent; - paramConnectionTableIter = rtParamTop->program->connectionTable.begin(); - } - else - { - paramConnectionTableIter++; - } - } - - // add new entry to the destination param's program's connection table - CgParameterConnection newConnection; - newConnection.child = rtParamTo; - newConnection.parent = rtParamFrom; - newConnection.top = rtParamTop; - newConnection.childOnBindSetter = _cgRaiseInvalidParamIndex; - switch ( typeTo ) - { - case CG_FLOAT: - case CG_FLOAT1: case CG_FLOAT2: case CG_FLOAT3: case CG_FLOAT4: - newConnection.childOnBindSetter = rtParamTo->setterIndex; - break; - case CG_FLOAT1x1: case CG_FLOAT1x2: case CG_FLOAT1x3: case CG_FLOAT1x4: - case CG_FLOAT2x1: case CG_FLOAT2x2: case CG_FLOAT2x3: case CG_FLOAT2x4: - case CG_FLOAT3x1: case CG_FLOAT3x2: case CG_FLOAT3x3: case CG_FLOAT3x4: - case CG_FLOAT4x1: case CG_FLOAT4x2: case CG_FLOAT4x3: case CG_FLOAT4x4: - newConnection.childOnBindSetter = rtParamTo->setterrIndex; - break; - case CG_SAMPLER1D: case CG_SAMPLER2D: case CG_SAMPLER3D: case CG_SAMPLERRECT: case CG_SAMPLERCUBE: - newConnection.childOnBindSetter = rtParamTo->samplerSetter; - break; - case CGP_SCF_BOOL: - break; - default: - break; - } - - rtParamTo->program->connectionTable.push_back( newConnection ); -} - -CG_API void cgDisconnectParameter( CGparameter param ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - // check and get parameter handles - CgRuntimeParameter *rtParamTo = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - - // check parameter handles - if ( !CG_IS_PARAMETER( rtParamTo ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - // search the program's connection table to find the connection info for this parameter - // each parameter only ever has one parent - std::vector::iterator paramConnectionTableIter = rtParamTo->program->connectionTable.begin(); - while ( paramConnectionTableIter != rtParamTo->program->connectionTable.end() ) - { - if ( paramConnectionTableIter->child == rtParamTo ) - break; - paramConnectionTableIter++; - } - - // if the parameter is not found in the connection table, it was never connected in the first place - if ( paramConnectionTableIter == rtParamTo->program->connectionTable.end() ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - // parameter was found to be connected, delete its entry from the table to disconnect - rtParamTo->program->connectionTable.erase( paramConnectionTableIter ); - - // check to see if parameter is a parent to for anyone in an arbitrarily deep hierarchy - // if it is, we must update all the children's top pointers to point to this param - struct _CGprogram* programIter = rtParamTo->program->parentContext->programList; - while ( programIter != NULL ) - { - // search the connection table of all the programs in this context to find if this is a parent param to anybody - paramConnectionTableIter = programIter->connectionTable.begin(); - while ( paramConnectionTableIter != programIter->connectionTable.end() ) - { - if ( paramConnectionTableIter->parent == rtParamTo ) - { - // this is the case where rt was the parent, and now must be the top because - // it was just disconnected from its own parent - paramConnectionTableIter->top = rtParamTo; - } - paramConnectionTableIter++; - } - programIter = programIter->next; - } -} - -CG_API CGparameter cgGetConnectedParameter( CGparameter param ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - CgRuntimeParameter* ptr = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - std::vector::iterator paramConnectionTableIter = ptr->program->connectionTable.begin(); - while ( paramConnectionTableIter != ptr->program->connectionTable.end() ) - { - // if this parameter is the child in a table, return its parent - if ( paramConnectionTableIter->child == ptr ) - return paramConnectionTableIter->parent->id; - paramConnectionTableIter++; - } - - // not found in connection table, has no parent - return NULL; -} - -CG_API int cgGetNumConnectedToParameters( CGparameter param ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return 0; - } - - int ret = 0; - CgRuntimeParameter *ptr = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - - _CGprogram* prog = ptr->program; - _CGcontext* context = prog->parentContext; - - // must iterate over all the programs in this context to see which of them - // have parameters which are connected to this parent - _CGprogram* programIter = context->programList; - while ( programIter != NULL ) - { - std::vector::iterator paramConnectionTableIter = programIter->connectionTable.begin(); - while ( paramConnectionTableIter != programIter->connectionTable.end() ) - { - // if this connection uses the param ptr as the parent, increment the count - if ( paramConnectionTableIter->parent == ptr ) - { - ret++; - } - paramConnectionTableIter++; - } - - programIter = programIter->next; - } - - return ret; -} - -CG_API CGparameter cgGetConnectedToParameter( CGparameter param, int index ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - if ( index < 0 ) - { - rglCgRaiseError( CG_OUT_OF_ARRAY_BOUNDS_ERROR ); - return ( CGparameter )NULL; - } - - - int ret = 0; - CgRuntimeParameter *ptr = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - - _CGprogram* prog = ptr->program; - _CGcontext* context = prog->parentContext; - - // must iterate over all the programs in this context to see which of them - // have parameters which are connected to this parent - _CGprogram* programIter = context->programList; - while ( programIter != NULL ) - { - std::vector::iterator paramConnectionTableIter = programIter->connectionTable.begin(); - while ( paramConnectionTableIter != programIter->connectionTable.end() ) - { - // if this is the n'th child, where n == index, return its id - if ( paramConnectionTableIter->parent == ptr ) - { - if ( ret == index ) - { - return paramConnectionTableIter->child->id; - } - ret++; - } - paramConnectionTableIter++; - } - - programIter = programIter->next; - } - - // else the index is greater than the number of children of this parameter - rglCgRaiseError( CG_OUT_OF_ARRAY_BOUNDS_ERROR ); - - return ( CGparameter )NULL; -} - - CG_API CGparameter cgGetNamedParameter( CGprogram prog, const char* name ) { // check program handle @@ -2010,46 +1273,6 @@ CG_API CGparameter cgGetNamedParameter( CGprogram prog, const char* name ) return ( CGparameter )NULL; } -CG_API CGparameter cgGetNamedProgramParameter( CGprogram prog, CGenum name_space, const char* name ) -{ - // Same as cgGetNamedParameter, but restricts search to a specific namespace - // i.e. only return parameters of this CGprogram that are global. - // - // Valid namespaces are CG_GLOBAL and CG_PROGRAM, - - // check program handle - if ( !CG_IS_PROGRAM( prog ) ) - { - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - // check namespace - switch ( name_space ) - { - case CG_GLOBAL : - break; - case CG_PROGRAM : - break; - default : - // ********* NOTE: docs say nothing about this check. - return NULL; - break; - } - _CGprogram* progPtr = _cgGetProgPtr( prog ); - int arrayIndex = -1; - CgRuntimeParameter *param = ( CgRuntimeParameter * )_cgGetNamedParameter( progPtr, name, name_space, &arrayIndex ); - if ( param ) - { - int ret = ( int )param->id; - if ( arrayIndex != -1 ) - ret |= ( arrayIndex << CG_PARAMETERSIZE ); - return ( CGparameter )ret; - } - else - return ( CGparameter )NULL; -} - CG_API CGparameter cgGetFirstParameter( CGprogram prog, CGenum name_space ) { // check program handle @@ -2081,106 +1304,6 @@ CG_API CGparameter cgGetFirstParameter( CGprogram prog, CGenum name_space ) return ( CGparameter )NULL; } -//this function returns the parent array if the parameter passed is member of an array as well as the position in the array -//returns null other wise -static CgRuntimeParameter *rglGetArrayItemParent( CGparameter param, int *arrayIndex ) -{ - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return NULL; - - // the case of the array element is easy to solve: - if ( rtParameter > rtParameter->program->runtimeParameters ) - { - CgRuntimeParameter *previousParameter = rtParameter - 1; - if ( previousParameter->parameterEntry->flags & CGP_ARRAY ) - { - if ( previousParameter->parameterEntry->flags & CGP_UNROLLED ) - { - //that's easy, we are on the first item of the array - //the other positions will be discovered by the main loop later - if ( arrayIndex ) - *arrayIndex = 0; - return previousParameter; - } - else - { - //we have an array item - if ( arrayIndex ) - *arrayIndex = CG_GETINDEX( param ); - return previousParameter; - } - } - } - - //we are in the case where we don't have the first item of an unrolled array and where we don't have an item of a compact array - //the algorithm it to walk back the parameter list until we found the parent. - //if the parent is a structure or if there is no parent, returns NULL, else return the parent and the index, - - //get the parent of the current as well as its location - const CgParameterEntry *paramEntry = rtParameter->parameterEntry; - const CgParameterEntry *firstEntry = rtParameter->program->parametersEntries; - - //we have already treated the current entry at that point, the loop starts on the previous one, the distance is 1 - int distance = 1; - paramEntry--; - - *arrayIndex = 0; - bool haveResult = false; - while ( paramEntry >= firstEntry && !haveResult ) - { - switch ( paramEntry->flags & CGP_TYPE_MASK ) - { - case CGP_ARRAY: - //we found it - haveResult = true; - break; - case CGP_STRUCTURE: - { - const CgParameterStructure *parameterStructure = rglGetParameterStructure( rtParameter->program, paramEntry ); - if ( distance >= parameterStructure->memberCount ) - { - //the parameter is not in this structure, so I need to remove from the distance all the structure item - distance -= parameterStructure->memberCount; - //I need to patch the array Index, we have counted some items which were not in the array - //this struct should count just for one - //so basically it means we are in an array of struct if this struct is one item. - //if we only have homogeneous array, we can speed up that function, I don't do it, - //in case we extend the behaviour in the future - ( *arrayIndex ) -= parameterStructure->memberCount; - //increment the arrayIndex - ( *arrayIndex )++; - } - else - { - //so we are in the structure, not in an array - ( *arrayIndex ) = -1; - return NULL; - } - break; - } - case CGP_INTRINSIC: - //increment the arrayIndex - ( *arrayIndex )++; - break; - } - distance++; - paramEntry--; - } - - if ( haveResult ) - { - size_t offset = ( rtParameter->parameterEntry - paramEntry ); - CgRuntimeParameter *parentParameter = rtParameter - offset; - return parentParameter; - } - else - { - ( *arrayIndex ) = -1; - return NULL; - } -} - CG_API CGparameter cgGetNextParameter( CGparameter param ) { //check parameter handle @@ -2338,53 +1461,6 @@ CG_API CGparameter cgGetFirstStructParameter( CGparameter param ) return ( CGparameter )NULL; //we have a struct with 0 items ? } -CG_API CGparameter cgGetNamedStructParameter( CGparameter param, const char* name ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return ( CGparameter )NULL; - - // check input string - if ( NULL == name ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return ( CGparameter )NULL; - } - - if ( !( rtParameter->parameterEntry->flags & CGP_STRUCTURE ) ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return ( CGparameter )NULL; - } - - - const CgParameterStructure *parameterStructure = rglGetParameterStructure( rtParameter->program, rtParameter->parameterEntry ); - - int arrayIndex = -1; - CgRuntimeParameter *structParam = ( CgRuntimeParameter * )_cgGetNamedParameter( rtParameter->program, name, ( CGenum )0, &arrayIndex, rtParameter->parameterEntry + 1, parameterStructure->memberCount ); - if ( structParam ) - { - int ret = ( int )structParam->id; - if ( arrayIndex != -1 ) - ret |= ( arrayIndex << CG_PARAMETERSIZE ); - return ( CGparameter )ret; - } - else - return ( CGparameter )NULL; -} - -CG_API CGparameter cgGetFirstDependentParameter( CGparameter param ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - return ( CGparameter )NULL; -} - CG_API CGparameter cgGetArrayParameter( CGparameter param, int arrayIndex ) { // check parameter handle @@ -2423,80 +1499,6 @@ CG_API CGparameter cgGetArrayParameter( CGparameter param, int arrayIndex ) return arrayItemID; } -CG_API int cgGetArrayDimension( CGparameter param ) -{ - // return how many dimensions this array has. - // TODO: API should be an unsigned int. - - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return -1; - - // ***** NOT IN CG DOCUMENTATION, but should be **** - - // this is a rarely queried value, so we do not store it. - // instead we calculate it every time it is requested. - // recurse down the array tree until the parameter type is not CG_ARRAY - // counting the depth as we go. - - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - if (( parameterEntry->flags & CGP_ARRAY ) == 0 ) - { - // ***** NOT IN CG DOCUMENTATION, but should be **** - rglCgRaiseError( CG_ARRAY_PARAM_ERROR ); - return 0; - } - else - { - const CgParameterArray *parameterArray = rglGetParameterArray( rtParameter->program, parameterEntry ); - return ( int )parameterArray->dimensionCount; - } - return 0; -} - -CG_API CGtype cgGetArrayType( CGparameter param ) -{ - // return the type of the leaf node of this CG_ARRAY type - - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return CG_UNKNOWN_TYPE; - - // ***** NOT IN CG DOCUMENTATION, but should be **** - - // this is a rarely queried value, so we do not store it. - // instead we calculate it every time it is requested. - // recurse down the array tree until the parameter type is not CG_ARRAY - // and return the first child that is not a CG_ARRAY type. - - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - if (( parameterEntry->flags & CGP_ARRAY ) == 0 ) - { - // ***** NOT IN CG DOCUMENTATION, but should be **** - rglCgRaiseError( CG_ARRAY_PARAM_ERROR ); - return CG_UNKNOWN_TYPE; - } - else - { - //get the parameter type inside the array - rtParameter++; - parameterEntry = rtParameter->parameterEntry; - if ( parameterEntry->flags & CGP_STRUCTURE ) - { - return CG_STRUCT; - } - else - { - // when we are able to support runtime created arrays of params we must handle that here - const CgParameterResource *parameterResource = rglGetParameterResource( rtParameter->program, parameterEntry ); - return ( CGtype )parameterResource->type; - } - } - return CG_UNKNOWN_TYPE; -} - CG_API int cgGetArraySize( CGparameter param, int dimension ) { // check parameter handle @@ -2533,24 +1535,6 @@ CG_API int cgGetArraySize( CGparameter param, int dimension ) return -1; } -CG_API void cgSetArraySize( CGparameter param, int size ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - } -} - -CG_API void cgSetMultiDimArraySize( CGparameter param, const int* sizes ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - } -} - CG_API CGprogram cgGetParameterProgram( CGparameter param ) { // check parameter handle @@ -2668,193 +1652,6 @@ CG_API const char* cgGetParameterSemantic( CGparameter param ) } } -CG_API CGresource cgGetParameterBaseResource( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return CG_UNDEFINED; - else - { - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - - unsigned short type = parameterEntry->flags & CGP_TYPE_MASK; - if ( type == CGP_STRUCTURE || type == CGP_ARRAY ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return CG_UNDEFINED; - } - - CGresource resource = cgGetParameterResource( param ); - return rglGetBaseResource( resource ); - } -} - -CG_API CGparameter cgGetFirstLeafParameter( CGprogram prog, CGenum name_space ) -{ - // check program handle - if ( !CG_IS_PROGRAM( prog ) ) - { - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - _CGprogram* progPtr = _cgGetProgPtr( prog ); - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )progPtr->runtimeParameters; - - //find the first leaf param of the requested namespace - for ( int i = 0; i < progPtr->rtParametersCount; ++i ) - { - // check parameter handle - bool isGlobal = ( rtParameter->parameterEntry->flags & CGPF_GLOBAL ) == CGPF_GLOBAL; - if (( isGlobal && name_space == CG_GLOBAL ) || ( !isGlobal && name_space == CG_PROGRAM ) ) - { - int type = ( rtParameter->parameterEntry->flags & CGP_TYPE_MASK ); - if ( type == CGP_INTRINSIC ) - return ( CGparameter )rtParameter->id; - else if ( type == CGP_ARRAY ) - { - if ( !( rtParameter->parameterEntry->flags & CGP_UNROLLED ) ) - { - //can we have a parameter of size 0 ? - const CgParameterArray *parameterArray = rglGetParameterArray( rtParameter->program, rtParameter->parameterEntry ); - int arraySize = ( int )rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - rtParameter++; //we move on the type parameter - if ( arraySize ) - { - //sending back ARRAY ITEM 0 here, should really use a macro to create the CGparameter handle - return rtParameter->id; - } - //else we just continue - } - //else unrolled, just continue - } - //else if (type == CGP_STRUCTURE) //just continue - } - rtParameter++; - } - return ( CGparameter )NULL; -} - -CG_API CGparameter cgGetNextLeafParameter( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return ( CGparameter )NULL; - - //this parameter should be an intrinsic - if (( rtParameter->parameterEntry->flags & CGP_TYPE_MASK ) != CGP_INTRINSIC ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return ( CGparameter )NULL; - } - - // runtime created parameters are treated separately because they are in a different namespace - // as such, you never need to traverse from a program param to a runtime param, or visa-versa - // additionally, in the current implementation, we only support creation of leaf types. - if ( rtParameter->parameterEntry->flags & CGP_RTCREATED ) - { - // we have a runtime created parameter - std::vector::iterator rtCreatedIter = rtParameter->program->runtimeCreatedParameters.begin(); - while ( rtCreatedIter != rtParameter->program->runtimeCreatedParameters.end() ) - { - if ( *rtCreatedIter == rtParameter ) - { - rtCreatedIter++; - if ( rtCreatedIter == rtParameter->program->runtimeCreatedParameters.end() ) - { - break; - } - return ( *rtCreatedIter )->id; - } - rtCreatedIter++; - } - // no next parameter for this one - return ( CGparameter )NULL; - } - - // the case of the array element is easy to solve: - if ( rtParameter > rtParameter->program->runtimeParameters ) - { - CgRuntimeParameter *previousParameter = rtParameter - 1; - if (( previousParameter->parameterEntry->flags & CGP_ARRAY ) && !( previousParameter->parameterEntry->flags & CGP_UNROLLED ) ) - { - //we have an array item - int arrayIndex = CG_GETINDEX( param ); - arrayIndex++; - const CgParameterArray *parameterArray = rglGetParameterArray( previousParameter->program, previousParameter->parameterEntry ); - int arraySize = rglGetSizeofSubArray(( short* )parameterArray->dimensions, parameterArray->dimensionCount ); - if ( arrayIndex < arraySize ) - { - int ret = ( int )rtParameter->id; - ret |= ( arrayIndex << CG_PARAMETERSIZE ); - return ( CGparameter )ret; - } - //else - //we need to leave this array and continue the traversal - } - } - - bool isCurrentGlobal = ( rtParameter->parameterEntry->flags & CGPF_GLOBAL ) == CGPF_GLOBAL; - - const CgParameterEntry *endEntry = rtParameter->program->parametersEntries + rtParameter->program->rtParametersCount; - const CgParameterEntry *paramEntry = rtParameter->parameterEntry + 1; - while ( paramEntry < endEntry ) - { - size_t offset = ( paramEntry - rtParameter->parameterEntry ); - CgRuntimeParameter *nextParameter = rtParameter + offset; - bool isNextGlobal = ( nextParameter->parameterEntry->flags & CGPF_GLOBAL ) == CGPF_GLOBAL; - if ( isNextGlobal != isCurrentGlobal ) - { - paramEntry++; // let's not quit, but continue to look for a matching namespace - continue; - //return ( CGparameter )NULL; //the items are gathered by namespace, so if different namespace then we quit - } - switch ( paramEntry->flags & CGP_TYPE_MASK ) - { - case CGP_ARRAY: - { - if ( paramEntry->flags & CGP_UNROLLED ) - { - //we skip unrolled array - break; - } - else - { - //we need to go inside and send back the first array item - //check how many item do we have in the array - const CgParameterArray *parameterArray = rglGetParameterArray( rtParameter->program, paramEntry ); - int arraySize = ( int )rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - if ( arraySize ) - { - nextParameter++; //go on the array time - //sending back ARRAY ITEM 0 here, should really use a macro to create the CGparameter handle - return nextParameter->id; - } - else - { - //no item in the array skip the item time continue - nextParameter++; //go on the array time, will be skipped - } - } - break; - } - case CGP_STRUCTURE: - { - //we just skip structures - break; - } - case CGP_INTRINSIC: - //we are done we found an intrinsic - return nextParameter->id; - break; - } - paramEntry++; - } - return ( CGparameter )NULL; -} - static bool rglPrependString( char *dst, const char *src, size_t size ) { int len = strlen( src ); @@ -2960,115 +1757,6 @@ CG_API const char* cgGetParameterName( CGparameter param ) } -CG_API CGresource cgGetParameterResource( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - { - return CG_UNDEFINED; - } - - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - - if ( parameterEntry->flags & CGP_RTCREATED ) - { - // runtime created parameters do not have resources - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return CG_UNDEFINED; - } - - unsigned short type = parameterEntry->flags & CGP_TYPE_MASK; - if ( type == CGP_STRUCTURE || type == CGP_ARRAY ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return CG_UNDEFINED; - } - - // TODO ************* docs say something incoherent about returning - // CG_INVALID_VALUE if cgIsParameterReferenced() == CG_FALSE? - if ( !( parameterEntry->flags & CGPF_REFERENCED ) ) - { - return CG_UNDEFINED; - } - - int arrayIndex = -1; - if ( rtParameter > rtParameter->program->runtimeParameters ) - { - CgRuntimeParameter *previousParameter = rtParameter - 1; - if ( previousParameter->parameterEntry->flags & CGP_ARRAY ) - { - //we have an array item - arrayIndex = CG_GETINDEX( param ); - } - } - - unsigned long resourceIndex = 0; - CGresource resource = ( CGresource )0; - unsigned short numEmbeddedConstants = 0; - rglCgGetParameterResourceInfo( rtParameter, arrayIndex, &resource, &resourceIndex, &numEmbeddedConstants ); - - // this returns undefined for array items that are not allocated - if (arrayIndex >= 0 && resourceIndex == -1U && numEmbeddedConstants == 0) - return CG_UNDEFINED; - - return resource; -} - -CG_API unsigned long cgGetParameterResourceIndex( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - { - return CG_UNDEFINED; - } - - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - - if ( parameterEntry->flags & CGP_RTCREATED ) - { - // runtime created parameters do not have resources - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return CG_UNDEFINED; - } - - unsigned short type = parameterEntry->flags & CGP_TYPE_MASK; - if ( type == CGP_STRUCTURE || CGP_STRUCTURE == CGP_ARRAY ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return -1U; - } - - // TODO ************* docs say something incoherent about returning - // CG_INVALID_VALUE if cgIsParameterReferenced() == CG_FALSE? - if ( !( parameterEntry->flags & CGPF_REFERENCED ) ) - { - return -1U; - } - - int arrayIndex = -1; - if ( rtParameter > rtParameter->program->runtimeParameters ) - { - CgRuntimeParameter *previousParameter = rtParameter - 1; - if ( previousParameter->parameterEntry->flags & CGP_ARRAY ) - { - //we have an array item - arrayIndex = CG_GETINDEX( param ); - } - } - - unsigned long resourceIndex = 0; - CGresource resource = ( CGresource )0; - unsigned short numEmbeddedConstants; - rglCgGetParameterResourceInfo( rtParameter, arrayIndex, &resource, &resourceIndex, &numEmbeddedConstants ); - if ( resource == CG_B || resource == CG_C ) - return ( unsigned long )resourceIndex; - else - return ( unsigned long )( resource - rglGetBaseResource( resource ) ); - -} - CG_API CGenum cgGetParameterVariability( CGparameter param ) { // check parameter handle @@ -3111,342 +1799,6 @@ CG_API CGenum cgGetParameterDirection( CGparameter param ) } } -CG_API CGbool cgIsParameterReferenced( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return CG_FALSE; - else - { - return (( rtParameter->parameterEntry->flags & CGPF_REFERENCED ) != 0 ); - } -} - -CG_API CGbool cgIsParameterUsed( CGparameter param, CGhandle handle ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - - // TODO: make a more accurate and general definition of "used", including runtime created parameters. - if ( !rtParameter ) - { - return CG_FALSE; - } - - if ( !CG_IS_PROGRAM( (CGprogram)handle ) ) - { - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return CG_FALSE; - } - - // adding support for effect handles would require moving this to RGLFX or something that would break the abstraction of that library - _CGprogram* progPtr = _cgGetProgPtr( (CGprogram)handle ); - - if ( !progPtr ) - { - return CG_FALSE; - } - - if (rtParameter->program != progPtr) - { - return CG_FALSE; - } - - return (( rtParameter->parameterEntry->flags & CGPF_REFERENCED ) != 0 ); -} - -CG_API const double* cgGetParameterValues( CGparameter paramIn, CGenum value_type, int *nvalues ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( paramIn ); - if ( !rtParameter ) - return NULL; - - // check nvalues pointer - if ( NULL == nvalues ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return NULL; - } - - // check if we are trying to get the current value of a uniform that is - // unreferenced and unbound (happens when compiler folds global constants), - // we can only return the default value in this case. - if ( value_type == CG_CURRENT ) - { - int var = ( rtParameter->parameterEntry->flags & CGPV_MASK ); - if ( var == CGPV_UNIFORM && - !( rtParameter->parameterEntry->flags & CGPF_REFERENCED ) && - !( rtParameter->parameterEntry->flags & CGP_RTCREATED ) && - !( rtParameter->parameterEntry->flags & CGP_ARRAY ) ) - { - const CgParameterResource* parameterResource = rglGetParameterResource( rtParameter->program, rtParameter->parameterEntry ); - if ( parameterResource ) - { - if ( parameterResource->resource == 0xffff ) - { - value_type = CG_DEFAULT; - } - } - } - - // this is the case for const parameters that never have a push buffer allocated - // because they can not be set since they are const in the shader, so the value - // will always be the defaults. - if ( rtParameter->pushBufferPointer == NULL ) - { - value_type = CG_DEFAULT; - } - } - - // as this function returns a pointer to an array of doubles we have - // to allocate space for this array, make sure it's never re-allocated for - // this parameter, plus make sure it is deleted when the CGcontext is - // destroyed. - // - // All in all a nasty API function. - - double values[16]; - *nvalues = 0; - _CGprogram *program = rtParameter->program; - - // check value type then copy the approriate values into the local values buffer - switch ( value_type ) - { - case CG_CONSTANT: - break; - - case CG_DEFAULT: - // return contents of default value field. - { - if ( rtParameter->parameterEntry->flags & CGP_RTCREATED ) - { - // runtime created parameters do not have default values - break; - } - // if there are defaults, they will only be in the platformParam - //do a slow linear search in the constants we have - int count = program->defaultValuesIndexCount; - for ( int i = 0;i < count;i++ ) - { - int index = ( int )program->defaultValuesIndices[i].entryIndex; - CgRuntimeParameter *tmp = program->runtimeParameters + index; - if ( tmp == rtParameter ) - { - //found - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - if ( parameterEntry->flags & CGP_ARRAY ) - return NULL; - const float *itemDefaultValues = program->defaultValues + program->defaultValuesIndices[i].defaultValueIndex; - CGtype parameterResourceType = rglGetParameterCGtype( program, parameterEntry ); - unsigned int cols = rglGetTypeColCount( parameterResourceType ); - unsigned int rows = rglGetTypeRowCount( parameterResourceType ); - if ( rows == 0 ) - rows = 1; //flat types versus matrices - - // the defaults must be copied out for each row, from each successive child - for ( GLuint r = 0; r < rows; r++ ) - { - const float* src = itemDefaultValues + 4 * r;//right now default values always come by 4 - // copy the values into the local buffer, just the right number of values for the column - for ( GLuint floatIndex = 0; floatIndex < cols; ++floatIndex ) - values[floatIndex + r * cols] = src[floatIndex]; - } - *nvalues = rows * cols; - break; //loop to find the defaults of the parameter - } - } - break; - } - case CG_CURRENT: - // return contents of current value field. - // **** this is documented in cgSetParameter docs, but not the cgGetParameterValues docs. - { - if ( rtParameter->pushBufferPointer ) - { - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - if ( parameterEntry->flags & CGP_ARRAY ) - return NULL; - - CGtype parameterResourceType = rglGetParameterCGtype( program, parameterEntry ); - - unsigned int cols = rglGetTypeColCount( parameterResourceType ); - unsigned int rows = rglGetTypeRowCount( parameterResourceType ); - if ( rows == 0 ) - rows = 1; //flat types versus matrices - - int floatcount = cols * rows; - // take the padding in the matrices into account - int colCount = 4; - int paddingSize = 0; - if ( cols ) - { - colCount = cols; - paddingSize = 4 - cols; - } - - bool isInArray = false; - unsigned int testParam = ((( unsigned int )paramIn ) & CG_PARAMETERMASK ); - // array parameter handle = ( base array handle + 1 ) + ((parameter index)<< 22) - if (( testParam != ( unsigned int )paramIn ) || // masking it like this will chop the index off the array - (( rtParameter > rtParameter->program->runtimeParameters ) && ( rtParameter - 1 )->parameterEntry->flags & CGP_ARRAY ) ) // this handles the case of the first array element at index 0 (and hopefully compact arrays i think) - { - isInArray = true; - } - - // if this parameter is connected as the child to a parent parameter, - // it is possible that the values will not have been pulled into the pushbuffer yet - // if the program that owns this parameter has not been bound since the parent was set. - // pull the values, just to be sure, even though this will pull values for - // every parameter in this program. it's a slow call anyway. - _pullConnectedParameterValues( rtParameter->program ); - - float *source; - - if ( isInArray ) - { - source = ( float* )( *(( unsigned int ** )rtParameter->pushBufferPointer + CG_GETINDEX( paramIn ) ) ); - } - else - { - source = ( float* )rtParameter->pushBufferPointer; - } - - for ( int i = 0; i < floatcount; ++i ) - { - values[i] = source[i + ( i / colCount ) * paddingSize]; - } - - *nvalues = floatcount; - } - break; - } - default: - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - return NULL; - break; - } - - if ( *nvalues > 0 ) - { - double *parameterValues = rtParameter->program->parentContext->currentParameterValue; - for ( int i = 0; i < *nvalues; i++ ) - { - parameterValues[i] = values[i]; - } - return parameterValues; - } - return NULL; -} - -CG_API int cgGetParameterOrdinalNumber( CGparameter param ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return CG_FALSE; - } - - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return CG_FALSE; - } - - // not implemented yet on the new runtime - // AND the spec on what this function does has actually been changed - // for globals and constants according to more recent nv documentation. - // yuck. - return -123; - - // if param of a CG_CONSTANT, return 0. We do not currently expose - // constants, and I am not sure why we would raise any error - // anyways. - -} - -CG_API CGbool cgIsParameterGlobal( CGparameter param ) -{ - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return CG_FALSE; - else - { - return (( rtParameter->parameterEntry->flags & CGPF_GLOBAL ) != 0 ); - } -} - -CG_API int cgGetParameterIndex( CGparameter param ) -{ - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return -1; - - // currently we don't support the runtime creation of array parameters so runtime created params never have an array index - if ( rtParameter->parameterEntry->flags & CGP_RTCREATED ) - return -1; - - int arrayIndex = -1; - CgRuntimeParameter *parent = rglGetArrayItemParent( param, &arrayIndex ); - if ( parent ) - return arrayIndex; - else - return -1; -} - -CG_API void cgSetParameterVariability( CGparameter param, CGenum vary ) -{ - // check parameter handle - if ( !CG_IS_PARAMETER( param ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - // check vary enum for validity. - switch ( vary ) - { - case CG_UNIFORM: - case CG_LITERAL: - case CG_DEFAULT: - break; - default: - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - return; - } - - // check that requested variability can be applied to this param - CGenum var = cgGetParameterVariability( param ); - if ( CG_VARYING == var ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_VARIABILITY_ERROR ); - return; - } - else - { - switch ( vary ) - { - case CG_UNIFORM: - case CG_LITERAL: - // **** record the change of variability, forcing a recompile. - // **** but we're pre-compiled so it does nothing to us. - break; - case CG_DEFAULT: - // **** if the param is connected, we can change the target - // **** param back to its default variability. - // **** but we got no connected params yet. So give up. - break; - default: - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - break; - } - } - return; -} - CG_API void cgSetParameterSemantic( CGparameter param, const char* semantic ) { // check parameter handle @@ -3859,40 +2211,6 @@ CG_API CGtype cgGetTypeBase( CGtype type ) return CG_UNKNOWN_TYPE; } - -CG_API CGbool cgGetTypeSizes( CGtype type, int *nrows, int *ncols ) -{ - // TODO ***************** - return _cgMatrixDimensions( type, ( unsigned int* )nrows, ( unsigned int* )ncols ); - -} - -CG_API void cgGetMatrixSize( CGtype type, int *nrows, int *ncols ) -{ - if (( nrows == 0 ) || ( ncols == 0 ) ) - { - rglCgRaiseError( CG_INVALID_POINTER_ERROR ); - return; - } - - if (( type >= CG_FLOAT1x1 && type <= CG_FLOAT4x4 ) || - ( type >= CG_HALF1x1 && type <= CG_HALF4x4 ) || - ( type >= CG_INT1x1 && type <= CG_INT4x4 ) || - ( type >= CG_BOOL1x1 && type <= CG_BOOL4x4 ) || - ( type >= CG_FIXED1x1 && type <= CG_FIXED4x4 )) - { - _cgMatrixDimensions( type, ( unsigned int* )nrows, ( unsigned int* )ncols ); - return; - } - - // type supplied is not a recognised matrix type - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - // NOTE: but fall through to return 0,0... - *nrows = 0; - *ncols = 0; - -} - /*============================================================ CG CONTEXT ============================================================ */ @@ -7063,32 +5381,6 @@ CGGL_API void cgGLSetParameterPointer( CGparameter param, pointer ); // data pointer } -CGGL_API void cgGLAttribPointer( GLuint index, GLint fsize, GLenum type, GLboolean normalize, GLsizei stride, const GLvoid *pointer ) -{ - rglVertexAttribPointerNV( - index, // attribute index - fsize, // element size - type, // GL_FLOAT - normalize, - stride, // element to element in bytes - pointer ); // data pointer -} - -CGGL_API void cgGLAttribValues( GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) -{ - rglVertexAttrib4fNV( index, x, y, z, w ); -} - -CGGL_API void cgGLEnableAttrib( GLuint index ) -{ - rglEnableVertexAttribArrayNV( index ); -} - -CGGL_API void cgGLDisableAttrib( GLuint index ) -{ - rglDisableVertexAttribArrayNV( index ); -} - CGGL_API void cgGLEnableClientState( CGparameter param ) { CgRuntimeParameter *_ptr = rglCgGLTestParameter( param ); @@ -7120,235 +5412,6 @@ CGGL_API void cgGLSetMatrixParameterfc( CGparameter param, const float *matrix ) ptr->settercIndex( ptr, matrix, CG_GETINDEX( param ) ); } -CGGL_API void cgGLSetMatrixParameterfr( CGparameter param, const float *matrix ) -{ - - CgRuntimeParameter *ptr = rglCgGLTestParameter( param ); - ptr->setterrIndex( ptr, matrix, CG_GETINDEX( param ) ); -} - -CGGL_API void cgGLGetMatrixParameterfr( CGparameter param, float *matrix ) -{ - - //check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return; - - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - if (( parameterEntry->flags & CGP_TYPE_MASK ) != CGP_INTRINSIC || - (( parameterEntry->flags & CGPV_MASK ) != CGPV_UNIFORM && ( parameterEntry->flags & CGPV_MASK ) != CGPV_CONSTANT ) ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return; - } - - // uniforms only - float* value = rglGetUniformValuePtr( param, rtParameter ); - if ( !value ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return; - } - - CGtype parameterType = rglGetParameterCGtype( rtParameter->program, parameterEntry ); - unsigned int rows = rglGetTypeRowCount( parameterType ); - unsigned int cols = rglGetTypeColCount( parameterType ); - - if ( rows == 0 ) - { - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - return; - } - - /* peek into argument block */ - for ( GLuint i = 0; i < rows; ++i ) - for ( GLuint j = 0; j < cols; ++j ) - matrix[i*cols + j] = value[i * 4 + j]; -} - -CGGL_API void cgGLGetMatrixParameterfc( CGparameter param, float *matrix ) -{ - - //check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return; - - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - if (( parameterEntry->flags & CGP_TYPE_MASK ) != CGP_INTRINSIC || - (( parameterEntry->flags & CGPV_MASK ) != CGPV_UNIFORM && ( parameterEntry->flags & CGPV_MASK ) != CGPV_CONSTANT ) ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return; - } - - float* value = rglGetUniformValuePtr( param, rtParameter ); - if ( !value ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return; - } - - CGtype parameterType = rglGetParameterCGtype( rtParameter->program, parameterEntry ); - unsigned int rows = rglGetTypeRowCount( parameterType ); - unsigned int cols = rglGetTypeColCount( parameterType ); - - if ( rows == 0 ) - { - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - return; - } - - /* peek into argument block */ - for ( GLuint i = 0; i < rows; ++i ) - for ( GLuint j = 0; j < cols; ++j ) - matrix[i*cols + j] = value[i + j * 4]; -} - -CGGL_API void cgGLSetMatrixParameterArrayfc( CGparameter param, - long offset, - long nelements, - const float *matrices ) -{ - - CgRuntimeParameter* _ptr = _cgGLTestArrayParameter( param, offset, nelements ); - const CgParameterEntry *parameterEntry = _ptr->parameterEntry; - - if ( nelements == 0 ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( _ptr->program, parameterEntry ); - nelements = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ) - offset; - } - //we have an array here, the parameterEntry of the type is the next one - _ptr++; - //get the type stride - CGtype parameterType = rglGetParameterCGtype( _ptr->program, _ptr->parameterEntry ); - unsigned int melems = rglGetTypeRowCount( parameterType ) * rglGetTypeColCount( parameterType ); - - // loop over array elements - for ( int i = 0; i < nelements; ++i ) - { - _ptr->settercIndex( _ptr, matrices + i * melems, i + offset ); - } -} - -CGGL_API void cgGLSetMatrixParameterArrayfr( CGparameter param, - long offset, - long nelements, - const float *matrices ) -{ - - CgRuntimeParameter *_ptr = _cgGLTestArrayParameter( param, offset, nelements ); - const CgParameterEntry *parameterEntry = _ptr->parameterEntry; - - if ( nelements == 0 ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( _ptr->program, parameterEntry ); - nelements = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ) - offset; - } - //we have an array here, the parameterEntry of the type is the next one - _ptr++; - //get the type stride - CGtype parameterType = rglGetParameterCGtype( _ptr->program, _ptr->parameterEntry ); - unsigned int melems = rglGetTypeRowCount( parameterType ) * rglGetTypeColCount( parameterType ); - - // loop over array elements - for ( int i = 0; i < nelements; ++i ) - { - _ptr->setterrIndex( _ptr, matrices + i * melems, i + offset ); - } -} - -CGGL_API void cgGLGetMatrixParameterArrayfc( CGparameter param, - long offset, - long nelements, - float *matrices ) -{ - CgRuntimeParameter *_ptr = _cgGLTestArrayParameter( param, offset, nelements ); - if ( RGL_LIKELY( _ptr != NULL ) ) - { - const CgParameterEntry *parameterEntry = _ptr->parameterEntry; - if ( nelements == 0 ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( _ptr->program, parameterEntry ); - nelements = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ) - offset; - } - //we have an array here, the parameterEntry of the type is the next one - _ptr++; - - parameterEntry = _ptr->parameterEntry; - if (( parameterEntry->flags & CGP_TYPE_MASK ) != CGP_INTRINSIC || - (( parameterEntry->flags & CGPV_MASK ) != CGPV_UNIFORM && ( parameterEntry->flags & CGPV_MASK ) != CGPV_CONSTANT ) ) - { - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - return; - } - - int arrayID = ( int )_ptr->id; - - //get the type stride - CGtype parameterType = rglGetParameterCGtype( _ptr->program, _ptr->parameterEntry ); - unsigned int melems = rglGetTypeRowCount( parameterType ) * rglGetTypeColCount( parameterType ); - if ( !melems ) - { - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - return ; - } - // loop over array elements - for ( int i = 0; i < nelements; ++i ) - { - int arrayParameter = arrayID | (( i + offset ) << CG_PARAMETERSIZE ); - cgGLGetMatrixParameterfc(( CGparameter )arrayParameter, matrices + i*melems ); - } - } - -} - -CGGL_API void cgGLGetMatrixParameterArrayfr( CGparameter param, - long offset, - long nelements, - float *matrices ) -{ - CgRuntimeParameter *_ptr = _cgGLTestArrayParameter( param, offset, nelements ); - if ( RGL_LIKELY( _ptr != NULL ) ) - { - const CgParameterEntry *parameterEntry = _ptr->parameterEntry; - if ( nelements == 0 ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( _ptr->program, parameterEntry ); - nelements = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ) - offset; - } - //we have an array here, the parameterEntry of the type is the next one - _ptr++; - parameterEntry = _ptr->parameterEntry; - if (( parameterEntry->flags & CGP_TYPE_MASK ) != CGP_INTRINSIC || - (( parameterEntry->flags & CGPV_MASK ) != CGPV_UNIFORM && ( parameterEntry->flags & CGPV_MASK ) != CGPV_CONSTANT ) ) - { - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - return; - } - - int arrayID = ( int )_ptr->id; - - //get the type stride - CGtype parameterType = rglGetParameterCGtype( _ptr->program, _ptr->parameterEntry ); - unsigned int melems = rglGetTypeRowCount( parameterType ) * rglGetTypeColCount( parameterType ); - if ( !melems ) - { - rglCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); - return ; - } - // loop over array elements - for ( int i = 0; i < nelements; ++i ) - { - int arrayParameter = arrayID | (( i + offset ) << CG_PARAMETERSIZE ); - cgGLGetMatrixParameterfr(( CGparameter )arrayParameter, matrices + i*melems ); - } - } - -} - CGGL_API void cgGLSetTextureParameter( CGparameter param, GLuint texobj ) { // According to the cg implementation from nvidia, set just stores the obj. @@ -7408,75 +5471,10 @@ CGGL_API GLenum cgGLGetTextureEnum( CGparameter param ) return GL_TEXTURE0 + parameterResource->resource - CG_TEXUNIT0; } -void cgGLSetParameter1b( CGparameter param, CGbool v ) -{ - CgRuntimeParameter* ptr = rglCgGLTestParameter( param ); - if ( !ptr->parameterEntry->flags & CGPF_REFERENCED ) //ignore - return; - - _CGprogram* program = ptr->program; - - const CgParameterResource *parameterResource = rglGetParameterResource( program, ptr->parameterEntry ); - - // not sure what to do if no program like for global effect params that can be connected - // maybe actually do the propagation?! - if ( program ) - { - unsigned short resource = parameterResource->resource; - - unsigned int isShared = ( 1 << resource ) & ( program->parentContext->controlFlowBoolsSharedMask ); - unsigned int mask = ( 1 << resource ); - - // if the parameter is shared, initialize bools from context, otherwise from program - unsigned int bools = isShared ? program->parentContext->controlFlowBoolsShared : program->controlFlowBools; - - // set or unset the appropriate bit - if ( v ) - { - bools |= mask; - } - else - { - mask = ~mask; - bools &= mask; - } - - if ( isShared ) - { - program->parentContext->controlFlowBoolsShared = bools; - } - else - { - program->controlFlowBools = bools; - } - - _CurrentContext->needValidate |= RGL_VALIDATE_VERTEX_CONSTANTS; - } -} - CGGL_API void cgGLSetDebugMode( CGbool debug ) { } -unsigned int cgGLGetRegisterCount( CGprogram program ) -{ - _CGprogram* ptr = _cgGetProgPtr( program ); - return rglGetProgramProfileIndex(( CGprofile )ptr->header.profile ) == FRAGMENT_PROFILE_INDEX ? - ptr->header.fragmentProgram.registerCount : ptr->header.vertexProgram.registerCount; -} - - -void cgGLSetRegisterCount( CGprogram program, const unsigned int regCount ) -{ - _CGprogram* ptr = _cgGetProgPtr( program ); - if ( rglGetProgramProfileIndex(( CGprofile )ptr->header.profile ) == FRAGMENT_PROFILE_INDEX ) - { - ptr->header.fragmentProgram.registerCount = regCount; - if ( _CurrentContext->BoundFragmentProgram == program ) - _CurrentContext->needValidate |= RGL_VALIDATE_FRAGMENT_PROGRAM; - } -} - /*============================================================ CG NV2ELF ============================================================ */ diff --git a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp index 882040c744..bb5eb5f93c 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp @@ -770,15 +770,12 @@ void rglCreatePushBuffer(void *data) if ( containerEntry == NULL ) containerEntry = parameterEntry; - //rtParameter->setter = _cgRaiseInvalidParam; - //rtParameter->setterr = _cgRaiseNotMatrixParam; - //rtParameter->setterc = _cgRaiseNotMatrixParam; - rtParameter->samplerSetter = _cgRaiseInvalidParamIndex; + rtParameter->samplerSetter = _cgIgnoreParamIndex; //tentative - rtParameter->setterIndex = _cgRaiseInvalidParamIndex; - rtParameter->setterrIndex = _cgRaiseNotMatrixParamIndex; - rtParameter->settercIndex = _cgRaiseNotMatrixParamIndex; + rtParameter->setterIndex = _cgIgnoreParamIndex; + rtParameter->setterrIndex = _cgIgnoreParamIndex; + rtParameter->settercIndex = _cgIgnoreParamIndex; CGparameter id = ( CGparameter )rglCreateName( &_CurrentContext->cgParameterNameSpace, ( void* )rtParameter ); if ( !id ) @@ -833,7 +830,7 @@ void rglCreatePushBuffer(void *data) // the parameters should have a "validate" function instead if ( profileIndex == VERTEX_PROFILE_INDEX ) { - rtParameter->setterIndex = _cgIgnoreSetParamIndex; + rtParameter->setterIndex = _cgIgnoreParamIndex; rtParameter->samplerSetter = setSamplervp; } else @@ -1001,17 +998,17 @@ void rglCreatePushBuffer(void *data) { case CG_FLOAT: case CG_FLOAT1: case CG_FLOAT2: case CG_FLOAT3: case CG_FLOAT4: - rtParameter->setterIndex = _cgIgnoreSetParamIndex; + rtParameter->setterIndex = _cgIgnoreParamIndex; break; case CG_FLOAT1x1: case CG_FLOAT1x2: case CG_FLOAT1x3: case CG_FLOAT1x4: case CG_FLOAT2x1: case CG_FLOAT2x2: case CG_FLOAT2x3: case CG_FLOAT2x4: case CG_FLOAT3x1: case CG_FLOAT3x2: case CG_FLOAT3x3: case CG_FLOAT3x4: case CG_FLOAT4x1: case CG_FLOAT4x2: case CG_FLOAT4x3: case CG_FLOAT4x4: - rtParameter->setterrIndex = _cgIgnoreSetParamIndex; - rtParameter->settercIndex = _cgIgnoreSetParamIndex; + rtParameter->setterrIndex = _cgIgnoreParamIndex; + rtParameter->settercIndex = _cgIgnoreParamIndex; break; case CG_SAMPLER1D: case CG_SAMPLER2D: case CG_SAMPLER3D: case CG_SAMPLERRECT: case CG_SAMPLERCUBE: - rtParameter->samplerSetter = _cgIgnoreSetParamIndex; + rtParameter->samplerSetter = _cgIgnoreParamIndex; break; case CGP_SCF_BOOL: break; @@ -1023,7 +1020,7 @@ void rglCreatePushBuffer(void *data) case CG_BOOL1: case CG_BOOL2: case CG_BOOL3: case CG_BOOL4: case CG_FIXED: case CG_FIXED1: case CG_FIXED2: case CG_FIXED3: case CG_FIXED4: - rtParameter->setterIndex = _cgIgnoreSetParamIndex; + rtParameter->setterIndex = _cgIgnoreParamIndex; break; case CG_HALF1x1: case CG_HALF1x2: case CG_HALF1x3: case CG_HALF1x4: case CG_HALF2x1: case CG_HALF2x2: case CG_HALF2x3: case CG_HALF2x4: @@ -1041,8 +1038,8 @@ void rglCreatePushBuffer(void *data) case CG_FIXED2x1: case CG_FIXED2x2: case CG_FIXED2x3: case CG_FIXED2x4: case CG_FIXED3x1: case CG_FIXED3x2: case CG_FIXED3x3: case CG_FIXED3x4: case CG_FIXED4x1: case CG_FIXED4x2: case CG_FIXED4x3: case CG_FIXED4x4: - rtParameter->setterrIndex = _cgIgnoreSetParamIndex; - rtParameter->settercIndex = _cgIgnoreSetParamIndex; + rtParameter->setterrIndex = _cgIgnoreParamIndex; + rtParameter->settercIndex = _cgIgnoreParamIndex; break; // addition to be compatible with cgc 2.0 case CG_STRING: From 5a43f485d9e75aeeb542ad308ff3f418efd18192 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 20:27:55 +0100 Subject: [PATCH 3/9] (RGL PS3 Cg) Remove runime created parameters (CG_RT) and connection parameters --- ps3/rgl/include/Cg/CgCommon.h | 20 ------- ps3/rgl/src/ps3/rgl_ps3_cg.cpp | 100 --------------------------------- 2 files changed, 120 deletions(-) diff --git a/ps3/rgl/include/Cg/CgCommon.h b/ps3/rgl/include/Cg/CgCommon.h index b7fa56afcf..92c4c4e3a2 100644 --- a/ps3/rgl/include/Cg/CgCommon.h +++ b/ps3/rgl/include/Cg/CgCommon.h @@ -126,12 +126,6 @@ struct _CGprogram _CGprogramGroup *programGroup; int programIndexInGroup; - // supports runtime created parameters - std::vector runtimeCreatedParameters; - - // supports parameter connections - std::vector connectionTable; - // supports runtime allocation of semantics std::vector parameterSemantics; @@ -306,20 +300,6 @@ void rglPlatformSetBoolVertexRegisters (unsigned int values ); // names API -static inline void _pullConnectedParameterValues (void *data) -{ - _CGprogram *ptr = (_CGprogram*)data; - // we now use a pull method to get the data into the children parameters - // when their program is bound they pull the data from their parents - std::vector::iterator connectionIter = ptr->connectionTable.begin(); - while ( connectionIter != ptr->connectionTable.end() ) - { - // pull data into connectionIter->child from connectionIter->top - connectionIter->childOnBindSetter( connectionIter->child, connectionIter->top->pushBufferPointer, 0 ); - connectionIter++; - } -} - static inline GLenum rglCgGetSamplerGLTypeFromCgType( CGtype type ) { switch ( type ) diff --git a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp index f0b9d30854..f53cd3c8b8 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp @@ -998,30 +998,8 @@ void rglCgDestroyContextParam( CgRuntimeParameter* ptr ) semanticIter++; } - std::vector::iterator paramConnectionTableIter = ptr->program->connectionTable.begin(); - while ( paramConnectionTableIter != ptr->program->connectionTable.end() ) - { - if ( paramConnectionTableIter->child == ptr ) - { - ptr->program->connectionTable.erase( paramConnectionTableIter ); - break; - } - paramConnectionTableIter++; - } - if ( _cgParameterDestroyHook ) _cgParameterDestroyHook( ptr ); - std::vector::iterator rtCreatedIter = ptr->program->runtimeCreatedParameters.begin(); - while ( rtCreatedIter != ptr->program->runtimeCreatedParameters.end() ) - { - if ( *rtCreatedIter == ptr ) - { - ptr->program->runtimeCreatedParameters.erase( rtCreatedIter ); - break; - } - rtCreatedIter++; - } - rglEraseName( &_CurrentContext->cgParameterNameSpace, (unsigned int)( ptr->id ) ); free( ptr ); @@ -1311,29 +1289,6 @@ CG_API CGparameter cgGetNextParameter( CGparameter param ) if ( !rtParameter ) return ( CGparameter )NULL; - // runtime created parameters are treated separately because they are in a different namespace - // as such, you never need to traverse from a program param to a runtime param, or visa-versa - if ( rtParameter->parameterEntry->flags & CGP_RTCREATED ) - { - // we have a runtime created parameter - std::vector::iterator rtCreatedIter = rtParameter->program->runtimeCreatedParameters.begin(); - while ( rtCreatedIter != rtParameter->program->runtimeCreatedParameters.end() ) - { - if ( *rtCreatedIter == rtParameter ) - { - rtCreatedIter++; - if ( rtCreatedIter == rtParameter->program->runtimeCreatedParameters.end() ) - { - break; - } - return ( *rtCreatedIter )->id; - } - rtCreatedIter++; - } - // no next parameter for this one - return ( CGparameter )NULL; - } - // the case of the array element of a compact array is easy to solve int arrayIndex = -1; if ( rtParameter > rtParameter->program->runtimeParameters ) @@ -2324,17 +2279,6 @@ CG_API void cgDestroyContext( CGcontext c ) _CGcontext* ctx = _cgGetContextPtr( c ); - // if we are really destroying the context, let's remove all the connections first. - // if we don't do this first, I think the clean up gets grumpy. - ctx->defaultProgram.connectionTable.clear(); - struct _CGprogram* programIter = ctx->programList; - while ( programIter != NULL ) - { - programIter->connectionTable.clear(); - programIter = programIter->next; - } - - rglCgProgramErase( &ctx->defaultProgram ); // destroy all programs @@ -2505,47 +2449,9 @@ void rglCgProgramErase( _CGprogram* prog ) break; } - // check to see if each effect parameter is a parent in a connection and remove that reference before deletion - // - // for every effect param, check every program in its context and every connection in each program, - // then remove any where the effect param is a parent - std::vector::iterator effectParamIter = prog->runtimeCreatedParameters.begin(); - while ( effectParamIter != prog->runtimeCreatedParameters.end() ) - { - struct _CGprogram* programIter = prog->parentContext->programList; - while ( programIter != NULL ) - { - // search the program's connection table to find if this is a parent param to anybody - std::vector::iterator paramConnectionTableIter = programIter->connectionTable.begin(); - while ( paramConnectionTableIter != programIter->connectionTable.end() ) - { - if ( paramConnectionTableIter->parent == *effectParamIter ) - { - // Use iterator returned by erase() function as "nextParam" iterator - paramConnectionTableIter = programIter->connectionTable.erase( paramConnectionTableIter ); - } - else - { - paramConnectionTableIter++; - } - } - programIter = programIter->next; - } - //rglCgDestroyContextParam(*effectParamIter); - effectParamIter++; - } - - while ( prog->runtimeCreatedParameters.size() > 0 ) - { - // this routine removes the parameter from the array - rglCgDestroyContextParam( prog->runtimeCreatedParameters[0] ); - } - // free allocated memory in these stl containers. // Current clear() implementation deallocates the memory. // Is it better to explicitly call a "destructor" of this prog before freeing its memory? - prog->runtimeCreatedParameters.clear(); - prog->connectionTable.clear(); prog->parameterSemantics.clear(); // return program and node to free store @@ -4856,9 +4762,6 @@ CGGL_API void cgGLBindProgram( CGprogram program ) // and inform the GL state to re-upload the vertex program _CurrentContext->needValidate |= PSGL_VALIDATE_VERTEX_PROGRAM; - - // This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine - _pullConnectedParameterValues( ptr ); break; case CG_PROFILE_SCE_FP_TYPEB: @@ -4870,9 +4773,6 @@ CGGL_API void cgGLBindProgram( CGprogram program ) // need to revalidate the textures in order to update which targets to fetch from _CurrentContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED; - // This must happen before the sampler setters so texture parameters have the correct value in their push buffers for that routine - _pullConnectedParameterValues( ptr ); - // TODO: push texture state // Needs to be done per profile. Can't use glPushAttrib. From 8aaf6bea394c524577957c7fb23f29b43b1cb6ce Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 20:51:03 +0100 Subject: [PATCH 4/9] (RGL PS3) Remove runtime semantics --- ps3/rgl/include/Cg/CgCommon.h | 5 -- ps3/rgl/src/ps3/rgl_ps3_cg.cpp | 145 ++++++--------------------------- 2 files changed, 23 insertions(+), 127 deletions(-) diff --git a/ps3/rgl/include/Cg/CgCommon.h b/ps3/rgl/include/Cg/CgCommon.h index 92c4c4e3a2..cfb3ff9f71 100644 --- a/ps3/rgl/include/Cg/CgCommon.h +++ b/ps3/rgl/include/Cg/CgCommon.h @@ -6,7 +6,6 @@ #include "../export/RGL/rgl.h" #include "../RGL/private.h" -#include #include #include "Cg/CgInternal.h" @@ -55,7 +54,6 @@ typedef struct typedef struct { CgRuntimeParameter* param; - std::vector semantic; } CgRuntimeSemantic; struct _CGprogram @@ -126,9 +124,6 @@ struct _CGprogram _CGprogramGroup *programGroup; int programIndexInGroup; - // supports runtime allocation of semantics - std::vector parameterSemantics; - //runtime compilation / conversion void *runtimeElf; }; diff --git a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp index f53cd3c8b8..c7deb1ea3c 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp @@ -987,17 +987,6 @@ static CGparameter rglAdvanceParameter( CGparameter param, int distance ) void rglCgDestroyContextParam( CgRuntimeParameter* ptr ) { - std::vector::iterator semanticIter = ptr->program->parameterSemantics.begin(); - while ( semanticIter != ptr->program->parameterSemantics.end() ) - { - if ( semanticIter->param == ptr ) - { - ptr->program->parameterSemantics.erase( semanticIter ); - break; - } - semanticIter++; - } - if ( _cgParameterDestroyHook ) _cgParameterDestroyHook( ptr ); rglEraseName( &_CurrentContext->cgParameterNameSpace, (unsigned int)( ptr->id ) ); @@ -1562,49 +1551,31 @@ CG_API const char* cgGetParameterSemantic( CGparameter param ) CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); if ( !rtParameter ) return NULL; - else + + const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; + + unsigned short type = parameterEntry->flags & CGP_TYPE_MASK; + if ( type == CGP_STRUCTURE || CGP_STRUCTURE == CGP_ARRAY ) { - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - - unsigned short type = parameterEntry->flags & CGP_TYPE_MASK; - if ( type == CGP_STRUCTURE || CGP_STRUCTURE == CGP_ARRAY ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return NULL; - } - - // this table holds semantics that were created at runtime for either program or context or effect scope parameters - // this search happens first because you can overwrite what was set in the binary at runtime - // and we won't remove the entry from the binary representation of semantics - // but we will add an entry into this table which should be returned here. - std::vector::iterator semanticIter = rtParameter->program->parameterSemantics.begin(); - while ( semanticIter != rtParameter->program->parameterSemantics.end() ) - { - if ( semanticIter->param == rtParameter ) - { - return &semanticIter->semantic[0]; - } - semanticIter++; - } - - size_t entryIndex = ( parameterEntry - rtParameter->program->parametersEntries ); - - //look for the parameter semantic in the semantic table for semantics set in the compiled source - int count = rtParameter->program->semanticCount; - int i; - for ( i = 0;i < count;i++ ) - { - const CgParameterSemantic *semantic = rtParameter->program->semanticIndices + i; - if ( semantic->entryIndex == ( unsigned short )entryIndex ) - { - //found - return rtParameter->program->stringTable + semantic->semanticOffset; - } - } - - //not found, we don't have the semantic for this parameter, returns empty strings - return ""; + rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); + return NULL; } + + size_t entryIndex = ( parameterEntry - rtParameter->program->parametersEntries ); + + //look for the parameter semantic in the semantic table for semantics set in the compiled source + int count = rtParameter->program->semanticCount; + int i; + for ( i = 0;i < count;i++ ) + { + const CgParameterSemantic *semantic = rtParameter->program->semanticIndices + i; + + if ( semantic->entryIndex == ( unsigned short )entryIndex ) + return rtParameter->program->stringTable + semantic->semanticOffset; // found + } + + //not found, we don't have the semantic for this parameter, returns empty strings + return ""; } static bool rglPrependString( char *dst, const char *src, size_t size ) @@ -1754,71 +1725,6 @@ CG_API CGenum cgGetParameterDirection( CGparameter param ) } } -CG_API void cgSetParameterSemantic( CGparameter param, const char* semantic ) -{ - // check parameter handle - if ( RGL_UNLIKELY( !CG_IS_PARAMETER( param ) ) ) - { - rglCgRaiseError( CG_INVALID_PARAM_HANDLE_ERROR ); - return; - } - - CgRuntimeParameter* rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - - unsigned short type = rtParameter->parameterEntry->flags & CGP_TYPE_MASK; - if ( type == CGP_STRUCTURE || CGP_STRUCTURE == CGP_ARRAY ) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return; - } - - // first see if the parameter already has this semantic set from compile time, in which case, just return, it is already set - size_t entryIndex = ( rtParameter->parameterEntry - rtParameter->program->parametersEntries ) / sizeof( CgParameterEntry ); - //look for the parameter semantic in the semantic table for semantics set in the compiled source - int count = rtParameter->program->semanticCount; - int i; - for ( i = 0;i < count;i++ ) - { - const CgParameterSemantic *semanticEntry = rtParameter->program->semanticIndices + i; - if ( semanticEntry->entryIndex == ( unsigned short )entryIndex ) - { - //found the semantic for this parameter - if ( strcmp( semantic, rtParameter->program->stringTable + semanticEntry->semanticOffset ) == 0 ) - { - // if it already has the value we want, just return - return; - } - else - { - // if it has a different value, break out of this loop and give it a new one - break; - } - } - } - - // this table holds semantics that were created at runtime for either program or context or effect scope parameters - // must check this table to see if the param already has one set, in which case the semantic should just be updated - std::vector::iterator semanticIter = rtParameter->program->parameterSemantics.begin(); - while ( semanticIter != rtParameter->program->parameterSemantics.end() ) - { - if ( semanticIter->param == rtParameter ) - { - // we found this parameter already has a runtime set semantic, reassign it. - semanticIter->semantic.clear(); - semanticIter->semantic.insert( semanticIter->semantic.end(), semantic, semantic + strlen( semantic ) + 1 ); - return; - } - semanticIter++; - } - - // finally, if this parameter has no semantic yet, create an entry in the semantics table to store this semantic - CgRuntimeSemantic newSemanticEntry; - newSemanticEntry.param = rtParameter; - newSemanticEntry.semantic.clear(); - newSemanticEntry.semantic.insert( newSemanticEntry.semantic.end(), semantic, semantic + strlen( semantic ) + 1 ); - rtParameter->program->parameterSemantics.push_back( newSemanticEntry ); -} - /*============================================================ CG TOKENS ============================================================ */ @@ -2449,11 +2355,6 @@ void rglCgProgramErase( _CGprogram* prog ) break; } - // free allocated memory in these stl containers. - // Current clear() implementation deallocates the memory. - // Is it better to explicitly call a "destructor" of this prog before freeing its memory? - prog->parameterSemantics.clear(); - // return program and node to free store if ( prog->id ) rglEraseName( &_CurrentContext->cgProgramNameSpace, (unsigned int)prog->id ); From 05e94a23266dfb194a906ed3ea505c68450dfa33 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 22:12:26 +0100 Subject: [PATCH 5/9] (RGL PS3) Don't set embedded constants to default values - we presume shader already does this --- ps3/rgl/include/Cg/CgCommon.h | 13 -------- ps3/rgl/src/ps3/rgl_ps3_cg.cpp | 56 +--------------------------------- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/ps3/rgl/include/Cg/CgCommon.h b/ps3/rgl/include/Cg/CgCommon.h index cfb3ff9f71..ea5a73540d 100644 --- a/ps3/rgl/include/Cg/CgCommon.h +++ b/ps3/rgl/include/Cg/CgCommon.h @@ -43,19 +43,6 @@ typedef struct CgRuntimeParameter CGparameter id; } CgRuntimeParameter; -typedef struct -{ - CgRuntimeParameter* child; - CgRuntimeParameter* parent; - CgRuntimeParameter* top; - _cgSetArrayIndexFunction childOnBindSetter; -} CgParameterConnection; - -typedef struct -{ - CgRuntimeParameter* param; -} CgRuntimeSemantic; - struct _CGprogram { struct _CGprogram* next; // link to next in NULL-terminated singly linked list of programs diff --git a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp index c7deb1ea3c..580e0e13da 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp @@ -143,61 +143,7 @@ static int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramH rglCreatePushBuffer( program ); int count = program->defaultValuesIndexCount; - if ( profileIndex == FRAGMENT_PROFILE_INDEX ) - { - //this function sets the embedded constant to their default value in the ucode of a fragment shader - //it's called at setup time right after loading the program. this function could be removed if the - //default values were already in the shader code - /* modifies the ucode */ - - for ( int i = 0;i < count;i++ ) - { - const void * __restrict pItemDefaultValues = program->defaultValues + program->defaultValuesIndices[i].defaultValueIndex; - const unsigned int * itemDefaultValues = ( const unsigned int * )pItemDefaultValues; - int index = ( int )program->defaultValuesIndices[i].entryIndex; - - CgRuntimeParameter *rtParameter = program->runtimeParameters + index; - float *hostMemoryCopy = ( float * )rtParameter->pushBufferPointer; - - if ( hostMemoryCopy ) //certain parameter are not referenced but still have a default value. - { - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - int arrayCount = 1; - if ( parameterEntry->flags & CGP_ARRAY ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( program, parameterEntry ); - arrayCount = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - i++; - parameterEntry++; - } - const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); - unsigned short *resource = program->resources + parameterResource->resource + 1; //+1 to skip the register - int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; - int registerCount = arrayCount * registerStride; - int j; - - for ( j = 0;j < registerCount;j++ ) - { - unsigned short embeddedConstCount = *( resource++ ); - int k; - for ( k = 0;k < embeddedConstCount;k++ ) - { - unsigned short ucodePatchOffset = *( resource )++; - unsigned int *dst = ( unsigned int* )(( char* )program->ucode + ucodePatchOffset ); - dst[0] = SWAP_IF_BIG_ENDIAN( itemDefaultValues[0] ); - dst[1] = SWAP_IF_BIG_ENDIAN( itemDefaultValues[1] ); - dst[2] = SWAP_IF_BIG_ENDIAN( itemDefaultValues[2] ); - dst[3] = SWAP_IF_BIG_ENDIAN( itemDefaultValues[3] ); - } - __builtin_memcpy(( void* )hostMemoryCopy, ( void* )itemDefaultValues, sizeof( float )*4 ); - hostMemoryCopy += 4; - itemDefaultValues += 4; - resource++; //skip the register of the next item - } - } - } - } - else + if ( profileIndex != FRAGMENT_PROFILE_INDEX ) { /* modifies the push buffer */ From acdbd054e9c4e9f3248797e16f78ef2ccf40bb64 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 22:46:17 +0100 Subject: [PATCH 6/9] (RGL PS3) Remove ifndef __CELLOS_LV2__ code in rgl_ps3_cg.cpp --- ps3/rgl/src/ps3/rgl_ps3_cg.cpp | 99 ---------------------------------- 1 file changed, 99 deletions(-) diff --git a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp index 580e0e13da..991afced32 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_cg.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_cg.cpp @@ -6074,16 +6074,7 @@ int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness //containers._defaultValuesIndices[containers._defaultValuesIndices.size()-1] and the current parameter position in //the structure for ( int jj = 0; jj < (int)dv.size(); ++jj ) - { -#ifndef __CELLOS_LV2__ - unsigned int val = *(unsigned int*)&dv[jj]; - unsigned int tmp = CNV2END(val); - float tmp2 = *(float*)&tmp; - defaultValues.push_back(tmp2); -#else defaultValues.push_back(dv[jj]); -#endif - } } if (done) @@ -7678,27 +7669,8 @@ namespace cgc { nvb_reader_impl::loadFromString( const char* source, size_t length) { if ( loaded_ ) - { return CGBIO_ERROR_LOADED; - } -#if defined(RGL_USE_STD_STRING) && !(defined(__CELLOS_LV2__)) - std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary; - std::istringstream* iss = new std::istringstream(mode); - if (iss == 0) - { - return CGBIO_ERROR_MEMORY; - } - std::string sourceString((const char*)source,length); - iss->str(sourceString); - if ( !*iss ) - { - return CGBIO_ERROR_FILEIO; - } - strStream_ = true; - owner_ = true; - CGBIO_ERROR ret = load( iss, 0 ); -#else CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR; while (1) { @@ -7725,72 +7697,9 @@ namespace cgc { ret = CGBIO_ERROR_NO_ERROR; break; } -#endif return ret; } -#ifndef __CELLOS_LV2__ - - CGBIO_ERROR - nvb_reader_impl::load( const char* filename ) - { - if ( loaded_ ) - return CGBIO_ERROR_LOADED; - std::ifstream* ifs = new std::ifstream; - if (ifs == 0) - return CGBIO_ERROR_MEMORY; - ifs->open( filename, std::ios::in | std::ios::binary ); - if ( !*ifs ) - { - return CGBIO_ERROR_FILEIO; - } - CGBIO_ERROR ret = load( ifs, 0 ); - strStream_ = false; - owner_ = true; - return ret; - } - - CGBIO_ERROR - nvb_reader_impl::load( std::istream* stream, int start, bool owner ) - { - if ( loaded_ ) - { - return CGBIO_ERROR_LOADED; - } - owner_ = owner; - offset_ = start; - stream->seekg( offset_ ); - stream->read( reinterpret_cast( &header_ ), sizeof( header_ ) ); - if ( stream->gcount() != sizeof( header_ ) ) - { - return CGBIO_ERROR_FORMAT; - } - if ( CG_BINARY_FORMAT_REVISION != header_.binaryFormatRevision ) - { - endianness_ = ( CGBIODATALSB == endianness_ ) ? CGBIODATAMSB : CGBIODATALSB; - - int binaryRevision = convert_endianness( header_.binaryFormatRevision, endianness_ ); - if ( CG_BINARY_FORMAT_REVISION != binaryRevision ) - { - return CGBIO_ERROR_FORMAT; - } - } - unsigned int sz = size(); - image_ = new char[sz]; - stream->seekg( offset_ ); - stream->read( image_, sz ); - loaded_ = true; - - if (owner_) - { - ((std::ifstream*) stream)->close(); - delete stream; - } - return CGBIO_ERROR_NO_ERROR; - } - -#endif - bool nvb_reader_impl::is_loaded() const { @@ -7926,20 +7835,12 @@ namespace cgc { char *vp = &image_[dv_offset]; for (int ii = 0; ii < 4; ++ii) { - /*#ifndef __CELLOS_LV2__ - float *fv = static_cast( vp ); - float f = fv[ii]; - unsigned int tmp = *(unsigned int*)&f; - tmp = convert_endianness(tmp,endianness()); - default_value.push_back( *(float*)&tmp ); -#else*/ int tmp; memcpy(&tmp,vp+4*ii,4); tmp = convert_endianness(tmp,endianness()); float tmp2; memcpy(&tmp2,&tmp,4); default_value.push_back( tmp2 ); - //#endif } } if (ec_offset != 0) From 35935010030e98da5742aa5fd92b98372947e31e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 27 Mar 2013 23:32:27 +0100 Subject: [PATCH 7/9] (RGL PS3) Clean up what we no longer need --- ps3/rgl/include/Cg/CgCommon.h | 65 ------------------------------ ps3/rgl/src/ps3/rgl_ps3_raster.cpp | 10 ----- 2 files changed, 75 deletions(-) diff --git a/ps3/rgl/include/Cg/CgCommon.h b/ps3/rgl/include/Cg/CgCommon.h index ea5a73540d..13d2342cb7 100644 --- a/ps3/rgl/include/Cg/CgCommon.h +++ b/ps3/rgl/include/Cg/CgCommon.h @@ -216,51 +216,6 @@ static inline int rglGetSizeofSubArray( const unsigned short *dimensions, unsign return res; } -static inline CGresource rglGetBaseResource( CGresource resource ) -{ - switch ( resource ) - { - case CG_ATTR0: case CG_ATTR1: case CG_ATTR2: case CG_ATTR3: - case CG_ATTR4: case CG_ATTR5: case CG_ATTR6: case CG_ATTR7: - case CG_ATTR8: case CG_ATTR9: case CG_ATTR10: case CG_ATTR11: - case CG_ATTR12: case CG_ATTR13: case CG_ATTR14: case CG_ATTR15: - return CG_ATTR0; - case CG_HPOS: - return CG_HPOS; - case CG_COL0: case CG_COL1: case CG_COL2: case CG_COL3: - return CG_COL0; - case CG_TEXCOORD0: case CG_TEXCOORD1: case CG_TEXCOORD2: case CG_TEXCOORD3: - case CG_TEXCOORD4: case CG_TEXCOORD5: case CG_TEXCOORD6: case CG_TEXCOORD7: - case CG_TEXCOORD8: case CG_TEXCOORD9: - return CG_TEXCOORD0; - case CG_TEXUNIT0: case CG_TEXUNIT1: case CG_TEXUNIT2: case CG_TEXUNIT3: - case CG_TEXUNIT4: case CG_TEXUNIT5: case CG_TEXUNIT6: case CG_TEXUNIT7: - case CG_TEXUNIT8: case CG_TEXUNIT9: case CG_TEXUNIT10: case CG_TEXUNIT11: - case CG_TEXUNIT12: case CG_TEXUNIT13: case CG_TEXUNIT14: case CG_TEXUNIT15: - return CG_TEXUNIT0; - case CG_FOGCOORD: - return CG_FOGCOORD; - case CG_PSIZ: - return CG_PSIZ; - case CG_WPOS: - return CG_WPOS; - case CG_COLOR0: case CG_COLOR1: case CG_COLOR2: case CG_COLOR3: - return CG_COLOR0; - case CG_DEPTH0: - return CG_DEPTH0; - case CG_C: - return CG_C; - case CG_B: - return CG_B; - case CG_CLP0: case CG_CLP1: case CG_CLP2: case CG_CLP3: case CG_CLP4: case CG_CLP5: - return CG_CLP0; - case CG_UNDEFINED: - return CG_UNDEFINED; - default: - return CG_UNDEFINED; - } -} - // platform API CGprofile rglPlatformGetLatestProfile( CGGLenum profile_type ); int rglPlatformCopyProgram( _CGprogram* source, _CGprogram* destination ); @@ -299,25 +254,11 @@ static inline GLenum rglCgGetSamplerGLTypeFromCgType( CGtype type ) } } -static inline int is_created_param( CgRuntimeParameter* ptr ) -{ - if ( ptr->parameterEntry->flags & CGP_RTCREATED ) - return 1; - return 0; -} - struct rglNameSpace; #define VERTEX_PROFILE_INDEX 0 #define FRAGMENT_PROFILE_INDEX 1 -// these functions return the statically allocated table of function pointers originally -// written for NV unshared vertex parameter setters, but now also used by runtime -// created parameters cause these setters just do straight copies into the pushbuffer memory -// -_cgSetArrayIndexFunction getVectorTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d ); -_cgSetArrayIndexFunction getMatrixTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d, unsigned short e, unsigned short f ); - // ------------------------------------------- typedef void( * CgcontextHookFunction )( _CGcontext *context ); @@ -342,12 +283,6 @@ extern RGL_EXPORT cgRTCgcFreeHookFunction _cgRTCgcFreeCompiledProgramHook; //----------------------------------------------- //inlined helper functions -static inline int rglGetParameterType (const void *data, const CgParameterEntry *entry) -{ - const CGprogram *program = (const CGprogram*)data; - return (entry->flags & CGP_TYPE_MASK); -} - static inline const CgParameterResource *rglGetParameterResource (const void *data, const CgParameterEntry *entry ) { const _CGprogram *program = (const _CGprogram*)data; diff --git a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp index bb5eb5f93c..facb984fc4 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp @@ -559,16 +559,6 @@ static _cgSetArrayIndexFunction setMatrixTypeIndex[2][2][2][4][4][2] = } }; -_cgSetArrayIndexFunction getVectorTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d ) -{ - return setVectorTypeIndex[a][b][c][d]; -} - -_cgSetArrayIndexFunction getMatrixTypeIndexSetterFunction( unsigned short a, unsigned short b, unsigned short c, unsigned short d, unsigned short e, unsigned short f ) -{ - return setMatrixTypeIndex[a][b][c][d][e][f]; -} - static void setSamplerfp (void *data, const void*v, int /* index */) { CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; From e6bc99f9298df9075efc66c78c7573ab54e4ae96 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 28 Mar 2013 01:14:30 +0100 Subject: [PATCH 8/9] (RGL PS3) Faster texture upload --- ps3/rgl/src/ps3/rgl_ps3.cpp | 4 - ps3/rgl/src/ps3/rgl_ps3_raster.cpp | 229 +++++++---------------------- 2 files changed, 54 insertions(+), 179 deletions(-) diff --git a/ps3/rgl/src/ps3/rgl_ps3.cpp b/ps3/rgl/src/ps3/rgl_ps3.cpp index 15627ad7fa..e0ed86f6f4 100644 --- a/ps3/rgl/src/ps3/rgl_ps3.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3.cpp @@ -4530,10 +4530,6 @@ GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ) texture->vertexEnable = GL_FALSE; texture->revalidate |= RGL_TEXTURE_REVALIDATE_LAYOUT; break; - case GL_TEXTURE_ALLOCATION_HINT_SCE: - texture->usage = param; - texture->revalidate |= RGL_TEXTURE_REVALIDATE_LAYOUT; - break; case GL_TEXTURE_COMPARE_MODE_ARB: texture->compareMode = param; break; diff --git a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp index facb984fc4..1101fdade9 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp @@ -2347,177 +2347,6 @@ static inline GLenum unFilter( GLenum filter ) return newFilter; } -// texture strategy actions -// A texture strategy is a sequence of actions represented by these tokens. -// RGL_TEXTURE_STRATEGY_END must be the last token in any strategy. -enum rglTextureStrategy { - RGL_TEXTURE_STRATEGY_END, // allocation failed, give up - RGL_TEXTURE_STRATEGY_FORCE_LINEAR, - RGL_TEXTURE_STRATEGY_TILED_ALLOC, - RGL_TEXTURE_STRATEGY_TILED_CLEAR, - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, - RGL_TEXTURE_STRATEGY_UNTILED_CLEAR, - RGL_TEXTURE_STRATEGY_SYSTEM_ALLOC, - RGL_TEXTURE_STRATEGY_SYSTEM_CLEAR, // XXX probably not useful -}; - -static enum rglTextureStrategy tiledGPUStrategy[] = -{ - RGL_TEXTURE_STRATEGY_TILED_ALLOC, // try tiled alloction - RGL_TEXTURE_STRATEGY_FORCE_LINEAR, - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, // if failure, try linear allocation - RGL_TEXTURE_STRATEGY_UNTILED_CLEAR, // if failure, drop linear textures - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, // try linear again - RGL_TEXTURE_STRATEGY_END, // give up -}; -static enum rglTextureStrategy linearGPUStrategy[] = -{ - RGL_TEXTURE_STRATEGY_FORCE_LINEAR, - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, - RGL_TEXTURE_STRATEGY_UNTILED_CLEAR, - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, - RGL_TEXTURE_STRATEGY_END, -}; -static enum rglTextureStrategy swizzledGPUStrategy[] = -{ - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, - RGL_TEXTURE_STRATEGY_UNTILED_CLEAR, - RGL_TEXTURE_STRATEGY_UNTILED_ALLOC, - RGL_TEXTURE_STRATEGY_END, -}; -static enum rglTextureStrategy linearSystemStrategy[] = -{ - RGL_TEXTURE_STRATEGY_FORCE_LINEAR, - RGL_TEXTURE_STRATEGY_SYSTEM_ALLOC, - RGL_TEXTURE_STRATEGY_END, -}; -static enum rglTextureStrategy swizzledSystemStrategy[] = -{ - RGL_TEXTURE_STRATEGY_SYSTEM_ALLOC, - RGL_TEXTURE_STRATEGY_END, -}; - -// Reallocate texture based on usage, pool system, and strategy -void rglPlatformReallocateGcmTexture (void *data) -{ - rglTexture *texture = (rglTexture*)data; - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - - // select the allocation strategy - enum rglTextureStrategy *step = NULL; - switch ( texture->usage ) - { - case GL_TEXTURE_TILED_GPU_SCE: - step = tiledGPUStrategy; - break; - case GL_TEXTURE_LINEAR_GPU_SCE: - step = linearGPUStrategy; - break; - case GL_TEXTURE_SWIZZLED_GPU_SCE: - step = swizzledGPUStrategy; - break; - case GL_TEXTURE_LINEAR_SYSTEM_SCE: - step = linearSystemStrategy; - break; - case GL_TEXTURE_SWIZZLED_SYSTEM_SCE: - step = swizzledSystemStrategy; - break; - default: - step = swizzledGPUStrategy; - break; - } - - GLuint size = 0; - GLuint id = GMM_ERROR; - - // allow swizzled format unless explicitly disallowed - // PBO textures cannot be swizzled. - GLboolean forceLinear = GL_FALSE; - - const rglGcmTextureLayout currentLayout = gcmTexture->gpuLayout; - const GLuint currentSize = gcmTexture->gpuSize; - - // process strategy - GLboolean done = GL_FALSE; - while ( !done ) - { - rglGcmTextureLayout newLayout; - - switch ( *step++ ) - { - case RGL_TEXTURE_STRATEGY_FORCE_LINEAR: - forceLinear = GL_TRUE; - break; - case RGL_TEXTURE_STRATEGY_UNTILED_ALLOC: - { - // get layout and size compatible with this pool - rglImage *image = texture->image + texture->baseLevel; - - newLayout.levels = 1; - newLayout.faces = 1; - newLayout.baseWidth = image->width; - newLayout.baseHeight = image->height; - newLayout.baseDepth = image->depth; - newLayout.internalFormat = ( rglGcmEnum )image->internalFormat; - newLayout.pixelBits = rglPlatformGetBitsPerPixel( newLayout.internalFormat ); - newLayout.pitch = GET_TEXTURE_PITCH(texture); - - size = rglGetGcmTextureSize( &newLayout ); - - // determine if current allocation already works - // If the current allocation has the right size and pool, we - // don't have to do anything. If not, we only drop from the - // target pool because we may reuse the allocation from a - // different pool in a later step. - if ( gcmTexture->pool == RGLGCM_SURFACE_POOL_LINEAR ) - { - if ( currentSize >= size && newLayout.pitch == currentLayout.pitch ) - { - gcmTexture->gpuLayout = newLayout; - done = GL_TRUE; - } - else - rglPlatformDropTexture( texture ); - } - - if ( !done ) - { - // allocate in the specified pool - id = gmmAlloc((CellGcmContextData*)&rglGcmState_i.fifo, - 0, size); - - if ( id != GMM_ERROR ) - { - // drop old allocation - if ( gcmTexture->pool != RGLGCM_SURFACE_POOL_NONE ) - rglPlatformDropTexture( texture ); - - // set new - gcmTexture->pool = RGLGCM_SURFACE_POOL_LINEAR; - gcmTexture->gpuAddressId = id; - gcmTexture->gpuAddressIdOffset = 0; - gcmTexture->gpuSize = size; - gcmTexture->gpuLayout = newLayout; - - done = GL_TRUE; - } - } - } - break; - case RGL_TEXTURE_STRATEGY_UNTILED_CLEAR: - rglPlatformDropUnboundTextures( RGLGCM_SURFACE_POOL_LINEAR ); - break; - case RGL_TEXTURE_STRATEGY_END: - rglSetError( GL_OUT_OF_MEMORY ); - done = GL_TRUE; - break; - default: - break; - } - } // while loop for allocation strategy steps - rglTextureTouchFBOs( texture ); -} - // Free memory pooled by a GCM texture void rglPlatformFreeGcmTexture (void *data) { @@ -2560,11 +2389,61 @@ static void rglPlatformValidateTextureResources (void *data) if ( texture->revalidate & RGL_TEXTURE_REVALIDATE_IMAGES || texture->revalidate & RGL_TEXTURE_REVALIDATE_LAYOUT ) { // upload images - rglPlatformReallocateGcmTexture( texture ); - - // Upload texure from host memory to GPU memory - // + // Reallocate texture based on usage, pool system, and strategy rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; + + // select the allocation strategy + GLboolean done = GL_FALSE; + GLuint size = 0; + GLuint id = GMM_ERROR; + + if (texture->usage == GL_TEXTURE_LINEAR_SYSTEM_SCE || + texture->usage == GL_TEXTURE_SWIZZLED_SYSTEM_SCE) + done = GL_TRUE; + + const rglGcmTextureLayout currentLayout = gcmTexture->gpuLayout; + const GLuint currentSize = gcmTexture->gpuSize; + + if (!done) + { + rglGcmTextureLayout newLayout; + + // get layout and size compatible with this pool + rglImage *image = texture->image + texture->baseLevel; + + newLayout.levels = 1; + newLayout.faces = 1; + newLayout.baseWidth = image->width; + newLayout.baseHeight = image->height; + newLayout.baseDepth = image->depth; + newLayout.internalFormat = ( rglGcmEnum )image->internalFormat; + newLayout.pixelBits = rglPlatformGetBitsPerPixel( newLayout.internalFormat ); + newLayout.pitch = GET_TEXTURE_PITCH(texture); + + size = rglGetGcmTextureSize( &newLayout ); + + if ( currentSize >= size && newLayout.pitch == currentLayout.pitch ) + gcmTexture->gpuLayout = newLayout; + else + { + rglPlatformDropTexture( texture ); + + // allocate in the specified pool + id = gmmAlloc((CellGcmContextData*)&rglGcmState_i.fifo, + 0, size); + + // set new + gcmTexture->pool = RGLGCM_SURFACE_POOL_LINEAR; + gcmTexture->gpuAddressId = id; + gcmTexture->gpuAddressIdOffset = 0; + gcmTexture->gpuSize = size; + gcmTexture->gpuLayout = newLayout; + + } + } + rglTextureTouchFBOs( texture ); + + // Upload texture from host memory to GPU memory rglGcmTextureLayout *layout = &gcmTexture->gpuLayout; const GLuint pixelBytes = layout->pixelBits / 8; From ea916d95d5739a0c48634bf0419e0992538f1311 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 28 Mar 2013 07:24:44 +0100 Subject: [PATCH 9/9] (RGL PS3) Disable RGB remap - was never used up to now - set gamma to 0 - call GCM functions directly - some other ghetto inlining tweaks --- ps3/rgl/src/ps3/include/rgl-inline.h | 414 --------------------------- ps3/rgl/src/ps3/rgl_ps3.cpp | 24 +- ps3/rgl/src/ps3/rgl_ps3_raster.cpp | 326 ++++++++++++++++----- 3 files changed, 264 insertions(+), 500 deletions(-) diff --git a/ps3/rgl/src/ps3/include/rgl-inline.h b/ps3/rgl/src/ps3/include/rgl-inline.h index cb76340694..da6fd0ff9e 100644 --- a/ps3/rgl/src/ps3/include/rgl-inline.h +++ b/ps3/rgl/src/ps3/include/rgl-inline.h @@ -196,224 +196,6 @@ static inline GLuint rglGcmMapWrapMode( GLuint mode ) return 0; } -static inline void rglGcmMapTextureFormat( GLuint internalFormat, uint8_t *gcmFormat, uint32_t *remap ) -{ - *gcmFormat = 0; - - switch (internalFormat) - { - case RGLGCM_ALPHA8: // in_rgba = xxAx, out_rgba = 000A - { - *gcmFormat = CELL_GCM_TEXTURE_B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO ); - - } - break; - case RGLGCM_ALPHA16: // in_rgba = xAAx, out_rgba = 000A - { - *gcmFormat = CELL_GCM_TEXTURE_X16; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO ); - - } - break; - case RGLGCM_HILO8: // in_rgba = HLxx, out_rgba = HL11 - { - *gcmFormat = CELL_GCM_TEXTURE_COMPRESSED_HILO8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_ONE ); - - } - break; - case RGLGCM_HILO16: // in_rgba = HLxx, out_rgba = HL11 - { - *gcmFormat = CELL_GCM_TEXTURE_Y16_X16; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_ONE ); - - } - break; - case RGLGCM_ARGB8: // in_rgba = RGBA, out_rgba = RGBA - { - *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - case RGLGCM_BGRA8: // in_rgba = GRAB, out_rgba = RGBA ** NEEDS TO BE TESTED - { - *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - case RGLGCM_RGBA8: // in_rgba = GBAR, out_rgba = RGBA ** NEEDS TO BE TESTED - { - *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - } - break; - case RGLGCM_ABGR8: // in_rgba = BGRA, out_rgba = RGBA ** NEEDS TO BE TESTED - { - *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - case RGLGCM_RGBX8: // in_rgba = BGRA, out_rgba = RGB1 ** NEEDS TO BE TESTED - { - *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - case RGLGCM_XBGR8: // in_rgba = BGRA, out_rgba = RGB1 ** NEEDS TO BE TESTED - { - *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - case RGLGCM_FLOAT_R32: // in_rgba = Rxxx, out_rgba = R001 - { - *gcmFormat = CELL_GCM_TEXTURE_X32_FLOAT; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO ); - - } - break; - case RGLGCM_RGB5_A1_SCE: // in_rgba = RGBA, out_rgba = RGBA - { - *gcmFormat = CELL_GCM_TEXTURE_A1R5G5B5; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - case RGLGCM_RGB565_SCE: // in_rgba = RGBA, out_rgba = RGBA - { - *gcmFormat = CELL_GCM_TEXTURE_R5G6B5; - *remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - default: - break; - } -} - // Fast conversion for values between 0.0 and 65535.0 static inline GLuint RGLGCM_QUICK_FLOAT2UINT (const GLfloat f) { @@ -461,99 +243,6 @@ static inline void rglGcmUtilWaitForIdle (void) rglGcmState_i.labelValue++; } -// Sets the source and destination factor used for blending. -static inline void rglGcmFifoGlBlendFunc( rglGcmEnum sf, rglGcmEnum df, rglGcmEnum sfAlpha, rglGcmEnum dfAlpha ) -{ - // syntax check - switch ( sf ) - { - case RGLGCM_ZERO: - case RGLGCM_ONE: - case RGLGCM_SRC_COLOR: - case RGLGCM_ONE_MINUS_SRC_COLOR: - case RGLGCM_SRC_ALPHA: - case RGLGCM_ONE_MINUS_SRC_ALPHA: - case RGLGCM_DST_ALPHA: - case RGLGCM_ONE_MINUS_DST_ALPHA: - case RGLGCM_DST_COLOR: - case RGLGCM_ONE_MINUS_DST_COLOR: - case RGLGCM_SRC_ALPHA_SATURATE: - case RGLGCM_CONSTANT_COLOR: - case RGLGCM_ONE_MINUS_CONSTANT_COLOR: - case RGLGCM_CONSTANT_ALPHA: - case RGLGCM_ONE_MINUS_CONSTANT_ALPHA: - break; - default: - break; - } - switch ( sfAlpha ) - { - case RGLGCM_ZERO: - case RGLGCM_ONE: - case RGLGCM_SRC_COLOR: - case RGLGCM_ONE_MINUS_SRC_COLOR: - case RGLGCM_SRC_ALPHA: - case RGLGCM_ONE_MINUS_SRC_ALPHA: - case RGLGCM_DST_ALPHA: - case RGLGCM_ONE_MINUS_DST_ALPHA: - case RGLGCM_DST_COLOR: - case RGLGCM_ONE_MINUS_DST_COLOR: - case RGLGCM_SRC_ALPHA_SATURATE: - case RGLGCM_CONSTANT_COLOR: - case RGLGCM_ONE_MINUS_CONSTANT_COLOR: - case RGLGCM_CONSTANT_ALPHA: - case RGLGCM_ONE_MINUS_CONSTANT_ALPHA: - break; - default: - break; - } - - switch ( df ) - { - case RGLGCM_ZERO: - case RGLGCM_ONE: - case RGLGCM_SRC_COLOR: - case RGLGCM_ONE_MINUS_SRC_COLOR: - case RGLGCM_SRC_ALPHA: - case RGLGCM_ONE_MINUS_SRC_ALPHA: - case RGLGCM_DST_ALPHA: - case RGLGCM_ONE_MINUS_DST_ALPHA: - case RGLGCM_DST_COLOR: - case RGLGCM_ONE_MINUS_DST_COLOR: - case RGLGCM_SRC_ALPHA_SATURATE: - case RGLGCM_CONSTANT_COLOR: - case RGLGCM_ONE_MINUS_CONSTANT_COLOR: - case RGLGCM_CONSTANT_ALPHA: - case RGLGCM_ONE_MINUS_CONSTANT_ALPHA: - break; - default: - break; - } - switch ( dfAlpha ) - { - case RGLGCM_ZERO: - case RGLGCM_ONE: - case RGLGCM_SRC_COLOR: - case RGLGCM_ONE_MINUS_SRC_COLOR: - case RGLGCM_SRC_ALPHA: - case RGLGCM_ONE_MINUS_SRC_ALPHA: - case RGLGCM_DST_ALPHA: - case RGLGCM_ONE_MINUS_DST_ALPHA: - case RGLGCM_DST_COLOR: - case RGLGCM_ONE_MINUS_DST_COLOR: - case RGLGCM_SRC_ALPHA_SATURATE: - case RGLGCM_CONSTANT_COLOR: - case RGLGCM_ONE_MINUS_CONSTANT_COLOR: - case RGLGCM_CONSTANT_ALPHA: - case RGLGCM_ONE_MINUS_CONSTANT_ALPHA: - break; - default: - break; - } - - GCM_FUNC( cellGcmSetBlendFunc, sf, df, sfAlpha, dfAlpha ); -} - // Prints out an int in hexedecimal and binary, broken into bytes. // Can be used for printing out macro and constant values. // example: rglPrintIt( RGLGCM_3DCONST(SET_SURFACE_FORMAT, COLOR, LE_A8R8G8B8) ); @@ -599,71 +288,6 @@ static inline void rglGcmFifoGlIncFenceRef (GLuint *ref) *ref = rglGcmFifoPutReference( fifo ); } -// Flush the current FIFO. -static inline void rglGcmFifoGlFlush (void) -{ - GCM_FUNC_NO_ARGS( cellGcmSetInvalidateVertexCache ); - rglGcmFifoFlush( &rglGcmState_i.fifo ); -} - -// Set blending constant, used for certain blending modes. -static inline void rglGcmFifoGlBlendColor( GLfloat r, GLfloat g, GLfloat b, GLfloat a ) -{ - rglGcmBlendState *blend = &rglGcmState_i.state.blend; - GLuint hwColor; - - // syntax check - blend->r = r; - blend->g = g; - blend->b = b; - blend->a = a; - - // program hw - switch ( rglGcmState_i.renderTarget.colorFormat ) - { - case RGLGCM_ARGB8: - RGLGCM_CALC_COLOR_LE_ARGB8( &hwColor, r, g, b, a ); - GCM_FUNC( cellGcmSetBlendColor, hwColor, hwColor ); - break; - case RGLGCM_NONE: - case RGLGCM_FLOAT_R32: - // no native support support - break; - default: - break; - } -} - -// Set the current blend equation. -static inline void rglGcmFifoGlBlendEquation( rglGcmEnum mode, rglGcmEnum modeAlpha ) -{ - // syntax check - switch ( mode ) - { - case RGLGCM_FUNC_ADD: - case RGLGCM_MIN: - case RGLGCM_MAX: - case RGLGCM_FUNC_SUBTRACT: - case RGLGCM_FUNC_REVERSE_SUBTRACT: - break; - default: - break; - } - switch ( modeAlpha ) - { - case RGLGCM_FUNC_ADD: - case RGLGCM_MIN: - case RGLGCM_MAX: - case RGLGCM_FUNC_SUBTRACT: - case RGLGCM_FUNC_REVERSE_SUBTRACT: - break; - default: - break; - } - - GCM_FUNC( cellGcmSetBlendEquation, mode, modeAlpha ); -} - static inline void rglGcmFifoGlVertexAttribPointer ( GLuint index, @@ -729,44 +353,6 @@ static inline void rglGcmFifoGlVertexAttribPointer GCM_FUNC( cellGcmSetVertexDataArray, index, frequency, stride, size, gcmType, CELL_GCM_LOCATION_LOCAL, offset ); } -static inline void rglGcmFifoGlEnable( rglGcmEnum cap ) -{ - switch (cap) - { - case RGLGCM_BLEND: - GCM_FUNC( cellGcmSetBlendEnable, RGLGCM_TRUE ); - GCM_FUNC( cellGcmSetBlendEnableMrt, RGLGCM_TRUE, RGLGCM_TRUE, RGLGCM_TRUE ); - break; - case RGLGCM_DITHER: - GCM_FUNC( cellGcmSetDitherEnable, RGLGCM_TRUE ); - break; - case RGLGCM_PSHADER_SRGB_REMAPPING: - GCM_FUNC( cellGcmSetFragmentProgramGammaEnable, RGLGCM_TRUE ); - break; - default: - break; - } -} - -static inline void rglGcmFifoGlDisable( rglGcmEnum cap ) -{ - switch (cap) - { - case RGLGCM_BLEND: - GCM_FUNC( cellGcmSetBlendEnable, RGLGCM_FALSE ); - GCM_FUNC( cellGcmSetBlendEnableMrt, RGLGCM_FALSE, RGLGCM_FALSE, RGLGCM_FALSE ); - break; - case RGLGCM_DITHER: - GCM_FUNC( cellGcmSetDitherEnable, RGLGCM_FALSE ); - break; - case RGLGCM_PSHADER_SRGB_REMAPPING: - GCM_FUNC( cellGcmSetFragmentProgramGammaEnable, RGLGCM_FALSE ); - break; - default: - break; - } -} - // Look up the memory location of a buffer object (VBO, PBO) static inline GLuint rglGcmGetBufferObjectOrigin (GLuint buffer) { diff --git a/ps3/rgl/src/ps3/rgl_ps3.cpp b/ps3/rgl/src/ps3/rgl_ps3.cpp index e0ed86f6f4..7f74f1ecf6 100644 --- a/ps3/rgl/src/ps3/rgl_ps3.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3.cpp @@ -1570,19 +1570,20 @@ void rglGcmSetOpenGLState (void *data) GLuint i; // initialize the default OpenGL state - rglGcmFifoGlBlendColor( 0.0f, 0.0f, 0.0f, 0.0f ); - rglGcmFifoGlBlendEquation( RGLGCM_FUNC_ADD, RGLGCM_FUNC_ADD ); - rglGcmFifoGlBlendFunc( RGLGCM_ONE, RGLGCM_ZERO, RGLGCM_ONE, RGLGCM_ZERO ); + GCM_FUNC( cellGcmSetBlendColor, 0, 0); + GCM_FUNC( cellGcmSetBlendEquation, RGLGCM_FUNC_ADD, RGLGCM_FUNC_ADD ); + GCM_FUNC( cellGcmSetBlendFunc, RGLGCM_ONE, RGLGCM_ZERO, RGLGCM_ONE, RGLGCM_ZERO ); GCM_FUNC( cellGcmSetClearColor, 0 ); - rglGcmFifoGlDisable( RGLGCM_BLEND ); - rglGcmFifoGlDisable( RGLGCM_PSHADER_SRGB_REMAPPING ); + GCM_FUNC( cellGcmSetBlendEnable, RGLGCM_FALSE ); + GCM_FUNC( cellGcmSetBlendEnableMrt, RGLGCM_FALSE, RGLGCM_FALSE, RGLGCM_FALSE ); + GCM_FUNC( cellGcmSetFragmentProgramGammaEnable, RGLGCM_FALSE ); for ( i = 0; i < RGLGCM_ATTRIB_COUNT; i++ ) { GCM_FUNC( cellGcmSetVertexDataArray, i, 0, 0, 0, CELL_GCM_VERTEX_F, CELL_GCM_LOCATION_LOCAL, 0); } - rglGcmFifoGlEnable( RGLGCM_DITHER ); + GCM_FUNC( cellGcmSetDitherEnable, RGLGCM_TRUE ); for ( i = 0; i < RGLGCM_MAX_TEXIMAGE_COUNT; i++ ) { @@ -1895,7 +1896,8 @@ void rglPsglPlatformExit(void) if ( LContext ) { - rglGcmFifoGlFlush(); + GCM_FUNC_NO_ARGS( cellGcmSetInvalidateVertexCache ); + rglGcmFifoFlush( &rglGcmState_i.fifo ); psglMakeCurrent( NULL, NULL ); rglDeviceExit(); @@ -3145,17 +3147,19 @@ GLAPI void RGL_EXPORT psglSwap (void) const char * __restrict v = driver->sharedVPConstants; GCM_FUNC( cellGcmSetVertexProgramParameterBlock, 0, 8, ( float* )v ); // GCM_PORT_UNTESTED [KHOFF] - rglGcmFifoGlEnable( RGLGCM_DITHER ); + GCM_FUNC( cellGcmSetDitherEnable, RGLGCM_TRUE ); RGLcontext *context = (RGLcontext*)_CurrentContext; context->needValidate = RGL_VALIDATE_ALL; context->attribs->DirtyMask = ( 1 << RGL_MAX_VERTEX_ATTRIBS ) - 1; - rglGcmFifoGlFlush(); + GCM_FUNC_NO_ARGS( cellGcmSetInvalidateVertexCache ); + rglGcmFifoFlush( &rglGcmState_i.fifo ); while (sys_semaphore_wait(FlipSem,1000) != CELL_OK); - rglGcmFifoGlFlush(); + GCM_FUNC_NO_ARGS( cellGcmSetInvalidateVertexCache ); + rglGcmFifoFlush( &rglGcmState_i.fifo ); if ( device->deviceParameters.bufferingMode == RGL_BUFFERING_MODE_DOUBLE ) { diff --git a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp index 1101fdade9..c1b891d092 100644 --- a/ps3/rgl/src/ps3/rgl_ps3_raster.cpp +++ b/ps3/rgl/src/ps3/rgl_ps3_raster.cpp @@ -1427,7 +1427,8 @@ GLAPI void APIENTRY glClear( GLbitfield mask ) gmmFree( bufferId ); } - rglGcmFifoGlFlush(); + GCM_FUNC_NO_ARGS( cellGcmSetInvalidateVertexCache ); + rglGcmFifoFlush( &rglGcmState_i.fifo ); } rglFramebuffer* rglCreateFramebuffer (void) @@ -1980,15 +1981,23 @@ static inline void rglValidateStates (GLuint mask) { GCM_FUNC( cellGcmSetBlendEnable, LContext->Blending ); - rglGcmFifoGlBlendColor( - LContext->BlendColor.R, - LContext->BlendColor.G, - LContext->BlendColor.B, - LContext->BlendColor.A); - rglGcmFifoGlBlendEquation( - (rglGcmEnum)LContext->BlendEquationRGB, - (rglGcmEnum)LContext->BlendEquationAlpha); - rglGcmFifoGlBlendFunc((rglGcmEnum)LContext->BlendFactorSrcRGB,(rglGcmEnum)LContext->BlendFactorDestRGB,(rglGcmEnum)LContext->BlendFactorSrcAlpha,(rglGcmEnum)LContext->BlendFactorDestAlpha); + rglGcmBlendState *blend = &rglGcmState_i.state.blend; + GLuint hwColor; + + blend->r = LContext->BlendColor.R; + blend->g = LContext->BlendColor.G; + blend->b = LContext->BlendColor.B; + blend->a = LContext->BlendColor.A; + + if (rglGcmState_i.renderTarget.colorFormat == RGLGCM_ARGB8) + { + RGLGCM_CALC_COLOR_LE_ARGB8( &hwColor, blend->r, blend->g, blend->b, blend->a ); + GCM_FUNC( cellGcmSetBlendColor, hwColor, hwColor ); + } + + GCM_FUNC( cellGcmSetBlendEquation, (rglGcmEnum)LContext->BlendEquationRGB, + (rglGcmEnum)LContext->BlendEquationAlpha ); + GCM_FUNC( cellGcmSetBlendFunc, (rglGcmEnum)LContext->BlendFactorSrcRGB,(rglGcmEnum)LContext->BlendFactorDestRGB,(rglGcmEnum)LContext->BlendFactorSrcAlpha,(rglGcmEnum)LContext->BlendFactorDestAlpha); } } @@ -2284,69 +2293,6 @@ void rglPlatformDropTexture (void *data) rglTextureTouchFBOs( texture ); } -// Drop unbound textures from the GPU memory -// This is kind of slow, but we hit a slow path anyway. -// If the pool argument is not RGLGCM_SURFACE_POOL_NONE, then only textures -// in the specified pool will be dropped. -void rglPlatformDropUnboundTextures (GLenum pool) -{ - RGLcontext* LContext = _CurrentContext; - GLuint i, j; - - for (i = 0; i < LContext->textureNameSpace.capacity; ++i) - { - GLboolean bound = GL_FALSE; - rglTexture *texture = ( rglTexture * )LContext->textureNameSpace.data[i]; - - if (!texture || (texture->referenceBuffer != 0)) - continue; - - // check if bound - for ( j = 0;j < RGL_MAX_TEXTURE_IMAGE_UNITS;++j ) - { - rglTextureImageUnit *tu = LContext->TextureImageUnits + j; - if ( tu->bound2D == i) - { - bound = GL_TRUE; - break; - } - } - if ( bound ) - continue; - - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - - // check pool - if ( pool != RGLGCM_SURFACE_POOL_NONE && - pool != gcmTexture->pool ) - continue; - - rglPlatformDropTexture( texture ); - } -} - -// Drop filitering mode for FP32 texture -static inline GLenum unFilter( GLenum filter ) -{ - GLenum newFilter; - switch ( filter ) - { - case GL_NEAREST: - case GL_LINEAR: - newFilter = GL_NEAREST; - break; - case GL_NEAREST_MIPMAP_NEAREST: - case GL_NEAREST_MIPMAP_LINEAR: - case GL_LINEAR_MIPMAP_NEAREST: - case GL_LINEAR_MIPMAP_LINEAR: - newFilter = GL_NEAREST_MIPMAP_NEAREST; - break; - default: - newFilter = GL_NEAREST; - } - return newFilter; -} - // Free memory pooled by a GCM texture void rglPlatformFreeGcmTexture (void *data) { @@ -2565,6 +2511,7 @@ source: RGLGCM_SURFACE_SOURCE_TEXTURE, platformTexture->gcmMethods.address.wrapR = rglGcmMapWrapMode( texture->wrapR ); platformTexture->gcmMethods.address.unsignedRemap = CELL_GCM_TEXTURE_UNSIGNED_REMAP_NORMAL; +#if 0 // now for gamma remap GLuint gamma = 0; GLuint remap = texture->gammaRemap; @@ -2574,6 +2521,9 @@ source: RGLGCM_SURFACE_SOURCE_TEXTURE, gamma |= ( remap & RGLGCM_GAMMA_REMAP_ALPHA_BIT ) ? CELL_GCM_TEXTURE_GAMMA_A : 0; platformTexture->gcmMethods.address.gamma = gamma; +#else + platformTexture->gcmMethods.address.gamma = 0; +#endif // set border colors RGLGCM_CALC_COLOR_LE_ARGB8(&(platformTexture->gcmMethods.borderColor), @@ -2591,8 +2541,225 @@ source: RGLGCM_SURFACE_SOURCE_TEXTURE, GLuint internalFormat = layout->internalFormat; // set the format and remap( control 1) - rglGcmMapTextureFormat( internalFormat, - &platformTexture->gcmTexture.format, &platformTexture->gcmTexture.remap ); + uint8_t *gcmFormat = &platformTexture->gcmTexture.format; + uint32_t *remap = &platformTexture->gcmTexture.remap; + + *gcmFormat = 0; + + switch (internalFormat) + { + case RGLGCM_ALPHA8: // in_rgba = xxAx, out_rgba = 000A + { + *gcmFormat = CELL_GCM_TEXTURE_B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO ); + + } + break; + case RGLGCM_ALPHA16: // in_rgba = xAAx, out_rgba = 000A + { + *gcmFormat = CELL_GCM_TEXTURE_X16; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO ); + + } + break; +#if 0 + case RGLGCM_HILO8: // in_rgba = HLxx, out_rgba = HL11 + { + *gcmFormat = CELL_GCM_TEXTURE_COMPRESSED_HILO8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_ONE ); + + } + break; + case RGLGCM_HILO16: // in_rgba = HLxx, out_rgba = HL11 + { + *gcmFormat = CELL_GCM_TEXTURE_Y16_X16; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_ONE ); + + } + break; +#endif + case RGLGCM_ARGB8: // in_rgba = RGBA, out_rgba = RGBA + { + *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; +#if 0 + case RGLGCM_BGRA8: // in_rgba = GRAB, out_rgba = RGBA ** NEEDS TO BE TESTED + { + *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; + case RGLGCM_RGBA8: // in_rgba = GBAR, out_rgba = RGBA ** NEEDS TO BE TESTED + { + *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + } + break; + case RGLGCM_ABGR8: // in_rgba = BGRA, out_rgba = RGBA ** NEEDS TO BE TESTED + { + *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; + case RGLGCM_RGBX8: // in_rgba = BGRA, out_rgba = RGB1 ** NEEDS TO BE TESTED + { + *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; + case RGLGCM_XBGR8: // in_rgba = BGRA, out_rgba = RGB1 ** NEEDS TO BE TESTED + { + *gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; + case RGLGCM_FLOAT_R32: // in_rgba = Rxxx, out_rgba = R001 + { + *gcmFormat = CELL_GCM_TEXTURE_X32_FLOAT; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO ); + + } + break; + case RGLGCM_RGB5_A1_SCE: // in_rgba = RGBA, out_rgba = RGBA + { + *gcmFormat = CELL_GCM_TEXTURE_A1R5G5B5; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; +#endif + case RGLGCM_RGB565_SCE: // in_rgba = RGBA, out_rgba = RGBA + { + *gcmFormat = CELL_GCM_TEXTURE_R5G6B5; + *remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); + + } + break; + } // This is just to cover the conversion from swizzled to linear if(layout->pitch) @@ -2851,8 +3018,15 @@ void static inline rglGcmSetColorDepthBuffers(void *data, const void *data_args) { // ARGB8 and FP16 interpret some registers differently rglGcmBlendState *blend = &rglGcmState_i.state.blend; + GLuint hwColor; + rt->colorFormat = args->colorFormat; - rglGcmFifoGlBlendColor( blend->r, blend->g, blend->b, blend->a ); + + if (rglGcmState_i.renderTarget.colorFormat == RGLGCM_ARGB8) + { + RGLGCM_CALC_COLOR_LE_ARGB8( &hwColor, blend->r, blend->g, blend->b, blend->a ); + GCM_FUNC( cellGcmSetBlendColor, hwColor, hwColor ); + } } GLuint i = 0;