diff --git a/Makefile.ps3.rgl b/Makefile.ps3.rgl deleted file mode 100644 index c2841723d2..0000000000 --- a/Makefile.ps3.rgl +++ /dev/null @@ -1,56 +0,0 @@ -#which compiler to build with - GCC or SNC -#set to GCC for debug builds for use with debugger -CELL_BUILD_TOOLS = GCC -CELL_GPU_TYPE = RSX - -DEBUG = 0 -STRIPPING_ENABLE = 1 -RGL_2D = 1 - -PC_DEVELOPMENT_IP_ADDRESS = "192.168.1.7" -PC_DEVELOPMENT_UDP_PORT = 3490 - -CELL_MK_DIR ?= $(CELL_SDK)/samples/mk -include $(CELL_MK_DIR)/sdk.makedef.mk - -PPU_LIB_TARGET = librgl_ps3.a - -LDDIRS = -L. -INCDIRS = -I. -Ips3/gcmgl/include -Ilibretro-common/include - -RGL_DIR = ps3/gcmgl/src - -PPU_SRCS = $(RGL_DIR)/libelf/readelf.c \ - $(RGL_DIR)/rgl_ps3_raster.cpp \ - $(RGL_DIR)/rgl_ps3.cpp - - -ifeq ($(CELL_BUILD_TOOLS), SNC) - PPU_CXXLD = $(CELL_SDK)/host-win32/sn/bin/ps3ppuld.exe - PPU_CXX = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe - PPU_CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe - SNC_PPU_AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe -else - PPU_CXX = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-g++.exe - PPU_CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe - PPU_CXXLD = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ld.exe - PPU_AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe -endif - -PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe - - -PPU_LDLIBS = -lio_stub - -DEFINES += -D__CELLOS_LV2__ -DRARCH_INTERNAL - -ifeq ($(DEBUG), 1) - PPU_OPTIMIZE_LV := -O0 -g -else - PPU_OPTIMIZE_LV := -O3 -endif - -PPU_CFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES) -PPU_CXXFLAGS = $(PPU_OPTIMIZE_LV) $(INCDIRS) $(DEFINES) - -include $(CELL_MK_DIR)/sdk.target.mk diff --git a/dist-scripts/ps3-cores-dex.sh b/dist-scripts/ps3-cores-dex.sh index 5df73d0dc6..8900acb0d4 100755 --- a/dist-scripts/ps3-cores-dex.sh +++ b/dist-scripts/ps3-cores-dex.sh @@ -1,11 +1,9 @@ #!/bin/sh make -C ../ -f Makefile.ps3.salamander clean || exit 1 -make -C ../ -f Makefile.ps3.rgl clean || exit 1 make -C ../ -f Makefile.ps3 clean || exit 1 make -C ../ -f Makefile.ps3.salamander || exit 1 -make -C ../ -f Makefile.ps3.rgl || exit 1 EXE_PATH=/usr/local/cell/host-win32/bin MAKE_FSELF_NPDRM=$EXE_PATH/make_fself_npdrm.exe diff --git a/ps3/gcmgl/include/Cg/CgCommon.h b/ps3/gcmgl/include/Cg/CgCommon.h deleted file mode 100644 index 104784f971..0000000000 --- a/ps3/gcmgl/include/Cg/CgCommon.h +++ /dev/null @@ -1,326 +0,0 @@ -#ifndef _cg_common_h -#define _cg_common_h - -#include - -#include "../export/PSGL/psgl.h" -#include "../PSGL/private.h" - -#include - -#include "Cg/CgInternal.h" -#include "Cg/CgProgramGroup.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define RGL_MAX_VP_SHARED_CONSTANTS 256 -#define RGL_MAX_FP_SHARED_CONSTANTS 1024 -#define RGL_BOOLEAN_REGISTERS_COUNT 32 - -// parameter setter, prototype of functions called when a uniform is set. -typedef void(*_cgSetFunction) (void *, const void*); -typedef void(*_cgSetArrayIndexFunction) (void *, const void*, const int index); - -typedef struct _CgUniform -{ - void *pushBufferPtr; -} _CgUniform; - -typedef struct _CGprogram _CGprogram; - -typedef struct CgRuntimeParameter -{ - _cgSetArrayIndexFunction samplerSetter; - _cgSetArrayIndexFunction setterIndex; - _cgSetArrayIndexFunction settercIndex; - _cgSetArrayIndexFunction setterrIndex; - void *pushBufferPointer; - const CgParameterEntry *parameterEntry; - _CGprogram *program; - int glType; - CGparameter id; -} CgRuntimeParameter; - -struct _CGprogram -{ - struct _CGprogram* next; // link to next in NULL-terminated singly linked list of programs - CGprogram id; // numerical id for this program object - struct _CGcontext* parentContext; // parent context for this program - void* parentEffect; // parent effect for this program (only used for default program of an effect, containing effect parameters) - bool inLocalMemory; // only pertains to fragment programs which can be in location local, the default, or location main via cgb interfaces - // parameters in the CG_PROGRAM namespace - - unsigned int constantPushBufferWordSize; - unsigned int* constantPushBuffer; - unsigned int lastConstantUpdate; - - // executable program image - void* platformProgram; - - // entire binary program image from compiler - void* platformProgramBinary; - - // extra information to ease the coding of the rgl runtime - // the following are used to know which parameters are samplers, so that we can walk them in a quick way. - unsigned int samplerCount; - unsigned int * samplerIndices; - unsigned int * samplerUnits; - - //binary format additions - //info previously contained in platformProgram ( loadAddress + nvBinary ) - CgProgramHeader header; - const char *name; - const void *ucode; - - GLuint loadProgramId; - // offset into the allocation id above, normally zero for internal use. - // But for psglSetFragmentProgramConfiguration it's possible for - // users to manage sub-heap in allocation and put multiple - // program in each allocation. - GLuint loadProgramOffset; - - int version; //contained a boolean indicating if the structure pointers have been patched or not - - char *parameterResources; - int rtParametersCount; - CgRuntimeParameter *runtimeParameters; - const CgParameterEntry *parametersEntries; - - unsigned short *resources; - unsigned short *pushBufferPointers; - - int defaultValuesIndexCount; - const CgParameterDefaultValue *defaultValuesIndices; - - int semanticCount; - const CgParameterSemantic *semanticIndices; - - int defaultValueCount; - const float *defaultValues; - - const char *stringTable; - - unsigned int **constantPushBufferPointers; - - //tmp - unsigned int *samplerValuesLocation; - void *memoryBlock; - - _CGprogramGroup *programGroup; - int programIndexInGroup; - - //runtime compilation / conversion - void *runtimeElf; -}; - -typedef struct _CGcontext -{ - struct _CGcontext* next; // for global linked list of CGcontexts - CGcontext id; // numerical handle for this object - unsigned int programCount; // number of programs in the list - struct _CGprogram* programList; // head of singly linked list of programs - - CGenum compileType; // compile manual, immediate or lazy (unused so far) - - // default program, fake owner of the context parameters - _CGprogram defaultProgram; - - //groups - CGprogramGroup groupList; - - //"static" variable used to store the values of the last parameter for which getParameterValue has been called - double currentParameterValue[16]; - char currentParameterName[128]; -} _CGcontext; - - -// internal error handling -RGL_EXPORT void rglCgRaiseError( CGerror error ); -// interface between object types -extern void rglCgProgramDestroyAll( _CGcontext* c ); -extern void rglCgDestroyContextParam( CgRuntimeParameter* p ); -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 _cgIgnoreParamIndex( void *dat, const void*v, const int index ); - -// cg helpers - -// Is macros -#define CG_IS_CONTEXT(_ctx) rglIsName(&_CurrentContext->cgContextNameSpace, (unsigned int)_ctx) -#define CG_IS_PROGRAM(_program) rglIsName(&_CurrentContext->cgProgramNameSpace, (unsigned int)_program) -#define CG_IS_PARAMETER(_param) rglIsName(&_CurrentContext->cgParameterNameSpace, (unsigned int)(((unsigned int)_param)&CG_PARAMETERMASK)) - -//array indices -#define CG_PARAMETERSIZE 22 //22 bits == 4 millions parameters -#define CG_PARAMETERMASK ((1<>CG_PARAMETERSIZE) - - -static inline bool isMatrix (CGtype type) -{ - 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 )) - return true; - return false; -} - -static inline bool isSampler (CGtype type) -{ - return ( type >= CG_SAMPLER1D && type <= CG_SAMPLERCUBE ); -} - - -unsigned int rglCountFloatsInCgType( CGtype type ); - -unsigned int rglGetTypeRowCount( CGtype parameterType ); -unsigned int rglGetTypeColCount( CGtype parameterType ); - -// the internal cg conversions -inline static CgRuntimeParameter* _cgGetParamPtr (CGparameter p) -{ - return ( CgRuntimeParameter* )rglGetNamedValue( &_CurrentContext->cgParameterNameSpace, ( unsigned int )((( unsigned int )p )&CG_PARAMETERMASK ) ); -} - -inline static _CGprogram* _cgGetProgPtr( CGprogram p ) -{ - return ( _CGprogram* )rglGetNamedValue( &_CurrentContext->cgProgramNameSpace, (unsigned int)p ); -} - -inline static _CGcontext* _cgGetContextPtr( CGcontext c ) -{ - return ( _CGcontext* )rglGetNamedValue( &_CurrentContext->cgContextNameSpace, (unsigned int)c ); -} - -inline static CgRuntimeParameter* rglCgGLTestParameter( CGparameter param ) -{ - return _cgGetParamPtr( param ); -} - -CgRuntimeParameter* _cgGLTestArrayParameter( CGparameter paramIn, long offset, long nelements ); -CgRuntimeParameter* _cgGLTestTextureParameter( CGparameter param ); - -static inline int rglGetSizeofSubArray( const unsigned short *dimensions, unsigned short count ) -{ - int res = 1; - for (int i = 0;i < count;i++) - res *= ( int )(*(dimensions++)); - return res; -} - -// platform API -CGprofile rglPlatformGetLatestProfile( CGGLenum profile_type ); -int rglPlatformCopyProgram( _CGprogram* source, _CGprogram* destination ); - -void rglPlatformProgramErase (void *data); - -int rglPlatformGenerateVertexProgram (void *data, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues ); -CGbool rglPlatformSupportsVertexProgram ( CGprofile p ); - -int rglPlatformGenerateFragmentProgram (void *data, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues ); -CGbool rglPlatformSupportsFragmentProgram ( CGprofile p ); - -// names API - -static inline GLenum rglCgGetSamplerGLTypeFromCgType( CGtype type ) -{ - switch ( type ) - { - case CG_SAMPLER1D: - case CG_SAMPLER2D: - case CG_SAMPLERRECT: - return GL_TEXTURE_2D; - case CG_SAMPLER3D: - return GL_TEXTURE_3D; - case CG_SAMPLERCUBE: - return GL_TEXTURE_CUBE_MAP; - default: - return 0; - } -} - -struct rglNameSpace; - -#define VERTEX_PROFILE_INDEX 0 -#define FRAGMENT_PROFILE_INDEX 1 - -// ------------------------------------------- - -typedef void( * CgcontextHookFunction )( _CGcontext *context ); -extern RGL_EXPORT CgcontextHookFunction _cgContextCreateHook; -extern RGL_EXPORT CgcontextHookFunction _cgContextDestroyHook; - -typedef void( * CgparameterHookFunction )( CgRuntimeParameter *parameter ); -extern RGL_EXPORT CgparameterHookFunction _cgParameterCreateHook; -extern RGL_EXPORT CgparameterHookFunction _cgParameterDestroyHook; - -typedef void( * CgprogramHookFunction )( _CGprogram *program ); -typedef void( * CgprogramCopyHookFunction )( _CGprogram *newprogram, _CGprogram *oldprogram ); -extern RGL_EXPORT CgprogramHookFunction _cgProgramCreateHook; -extern RGL_EXPORT CgprogramHookFunction _cgProgramDestroyHook; -extern RGL_EXPORT CgprogramCopyHookFunction _cgProgramCopyHook; - -typedef int (*cgRTCgcCompileHookFunction) (const char*, const char*, const char*, const char**, char**); -typedef void(*cgRTCgcFreeHookFunction) (char*); -extern RGL_EXPORT cgRTCgcCompileHookFunction _cgRTCgcCompileProgramHook; -extern RGL_EXPORT cgRTCgcFreeHookFunction _cgRTCgcFreeCompiledProgramHook; - - -//----------------------------------------------- -//inlined helper functions -static inline const CgParameterResource *rglGetParameterResource (const void *data, const CgParameterEntry *entry ) -{ - const _CGprogram *program = (const _CGprogram*)data; - return (CgParameterResource *)(program->parameterResources + entry->typeIndex); -} - -static inline CGtype rglGetParameterCGtype (const void *data, const CgParameterEntry *entry) -{ - const _CGprogram *program = (const _CGprogram*)data; - - if (entry->flags & CGP_RTCREATED) - return (CGtype)entry->typeIndex; - else - { - const CgParameterResource *parameterResource = rglGetParameterResource(program, entry); - if (parameterResource) - return (CGtype)parameterResource->type; - } - return CG_UNKNOWN_TYPE; -} - -static inline const CgParameterArray *rglGetParameterArray (const void *data, const CgParameterEntry *entry) -{ - const _CGprogram *program = (const _CGprogram*)data; - return (CgParameterArray*)(program->parameterResources + entry->typeIndex); -} - -static inline const CgParameterStructure *rglGetParameterStructure (const void *data, const CgParameterEntry *entry ) -{ - const _CGprogram *program = (const _CGprogram*)data; - return (CgParameterStructure*)(program->parameterResources + entry->typeIndex); -} - -inline int rglGetProgramProfileIndex( CGprofile profile ) -{ - if ( profile == CG_PROFILE_SCE_FP_TYPEB || profile == CG_PROFILE_SCE_FP_TYPEC || profile == CG_PROFILE_SCE_FP_RSX ) - return FRAGMENT_PROFILE_INDEX; - else if ( profile == CG_PROFILE_SCE_VP_TYPEB || profile == CG_PROFILE_SCE_VP_TYPEC || profile == CG_PROFILE_SCE_VP_RSX ) - return VERTEX_PROFILE_INDEX; - else - return -1; -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ps3/gcmgl/include/Cg/CgInternal.h b/ps3/gcmgl/include/Cg/CgInternal.h deleted file mode 100644 index 53f46e3796..0000000000 --- a/ps3/gcmgl/include/Cg/CgInternal.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef _cg_internal_h -#define _cg_internal_h - -#ifdef __cplusplus -extern "C" { -#endif - - //Hardware shader settings -#define CGF_OUTPUTFROMH0 0x01 -#define CGF_DEPTHREPLACE 0x02 -#define CGF_PIXELKILL 0x04 - - //CgParameterEntry flags - - //variability -#define CGPV_MASK 0x03 -#define CGPV_VARYING 0x00 -#define CGPV_UNIFORM 0x01 -#define CGPV_CONSTANT 0x02 -#define CGPV_MIXED 0x03 - - //direction -#define CGPD_MASK 0x0C -#define CGPD_IN 0x00 -#define CGPD_OUT 0x04 -#define CGPD_INOUT 0x08 - - //is_referenced -#define CGPF_REFERENCED 0x10 - //is_shared -#define CGPF_SHARED 0x20 - //is_global -#define CGPF_GLOBAL 0x40 - //internal parameter -#define CGP_INTERNAL 0x80 - - //type -#define CGP_INTRINSIC 0x0000 -#define CGP_STRUCTURE 0x100 -#define CGP_ARRAY 0x200 -#define CGP_TYPE_MASK (CGP_STRUCTURE + CGP_ARRAY) - - //storage -#define CGP_UNROLLED 0x400 -#define CGP_UNPACKED 0x800 -#define CGP_CONTIGUOUS 0x1000 - -#define CGP_NORMALIZE 0x2000 // (attrib) if the usual cgGLSetParameterPointer should normalize the attrib - -#define CGP_RTCREATED 0x4000 // indicates that the parameter was created at runtime - - //static control flow boolean type -#define CGP_SCF_BOOL (CG_TYPE_START_ENUM + 1024) - - //data types - typedef struct _CgParameterTableHeader - { - unsigned short entryCount; - unsigned short resourceTableOffset; - unsigned short defaultValueIndexTableOffset; - unsigned short defaultValueIndexCount; - unsigned short semanticIndexTableOffset; - unsigned short semanticIndexCount; - } - CgParameterTableHeader; - - typedef struct _CgParameterEntry - { - unsigned int nameOffset; - unsigned short typeIndex; - unsigned short flags; - } - CgParameterEntry; - - typedef struct _CgParameterArray - { - unsigned short arrayType; - unsigned short dimensionCount; - unsigned short dimensions[]; - } CgParameterArray; //padded to 4 bytes - - typedef struct _CgParameterStructure - { - unsigned short memberCount; - unsigned short reserved; - } - CgParameterStructure; - - typedef struct _CgParameterResource - { - unsigned short type; - unsigned short resource; - } - CgParameterResource; - - typedef struct _CgParameterSemantic - { - unsigned short entryIndex; - unsigned short reserved; - unsigned int semanticOffset; - } - CgParameterSemantic; - - typedef struct _CgParameterDefaultValue - { - unsigned short entryIndex; - unsigned short defaultValueIndex; - } - CgParameterDefaultValue; - - typedef struct CgProgramHeader - { - //28 bytes - unsigned short profile; // Vertex / Fragment - unsigned short compilerVersion; - unsigned int instructionCount; - unsigned int attributeInputMask; - union - { - struct - { - //16 bytes - unsigned int instructionSlot; - unsigned int registerCount; - unsigned int attributeOutputMask; - } - vertexProgram; - struct - { - //12 bytes - unsigned int partialTexType; - unsigned short texcoordInputMask; - unsigned short texcoord2d; - unsigned short texcoordCentroid; - unsigned char registerCount; - unsigned char flags; //combination of CGF_OUTPUTFROMH0,CGF_DEPTHREPLACE,CGF_PIXELKILL - } - fragmentProgram; - }; - } - CgProgramHeader; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ps3/gcmgl/include/Cg/CgProgramGroup.h b/ps3/gcmgl/include/Cg/CgProgramGroup.h deleted file mode 100644 index c608b13691..0000000000 --- a/ps3/gcmgl/include/Cg/CgProgramGroup.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CGPROGRAMGROUP_HEADER -#define CGPROGRAMGROUP_HEADER - -#include "Cg/cgBinary.h" - -typedef struct _CGnamedProgram -{ - const char *name; - CGprogram program; - int refCount; -} -_CGnamedProgram; - -typedef struct _CGprogramGroup -{ - struct _CGprogramGroup *next; - CGcontext ctx; - unsigned int *constantTable; - unsigned int *stringTable; - unsigned int programCount; - _CGnamedProgram *programs; - int refCount; //total number of program refCounted - bool userCreated; - char *filedata; - char *name; -} -_CGprogramGroup; - -/* Program groups */ -typedef struct _CGprogramGroup *CGprogramGroup; - -CGprogramGroup rglCgCreateProgramGroup( CGcontext ctx, const char *name, void *ptr, int size ); -void rglCgDestroyProgramGroup( CGprogramGroup group ); - -int rglCgGetProgramCount( CGprogramGroup group ); -CGprogram rglCgGetProgram( CGprogramGroup group, const char *name ); -int rglCgGetProgramIndex( CGprogramGroup group, const char *name ); -CGprogram rglCgGetProgramAtIndex( CGprogramGroup group, unsigned int index ); -const char *rglCgGetProgramGroupName( CGprogramGroup group ); - -#endif diff --git a/ps3/gcmgl/include/Cg/cgBinary.h b/ps3/gcmgl/include/Cg/cgBinary.h deleted file mode 100644 index 59b21df577..0000000000 --- a/ps3/gcmgl/include/Cg/cgBinary.h +++ /dev/null @@ -1,115 +0,0 @@ -#if !defined(_H_CG_BINARY_H_) -#define _H_CG_BINARY_H_ - -#ifdef __cplusplus -extern "C" { -#endif - - /*************************************************************************/ - /*** CgBinaryGL binary data/file format ***/ - /*************************************************************************/ - -#define CG_BINARY_FORMAT_REVISION 0x00000006 - - // we don't encode pointers in the binary file so cross compiling - // with differnt pointer sizes works. - typedef unsigned int CgBinaryOffset; - typedef CgBinaryOffset CgBinaryEmbeddedConstantOffset; - typedef CgBinaryOffset CgBinaryFloatOffset; - typedef CgBinaryOffset CgBinaryStringOffset; - typedef CgBinaryOffset CgBinaryParameterOffset; - - // a few typedefs - typedef struct CgBinaryParameter CgBinaryParameter; - typedef struct CgBinaryEmbeddedConstant CgBinaryEmbeddedConstant; - typedef struct CgBinaryVertexProgram CgBinaryVertexProgram; - typedef struct CgBinaryFragmentProgram CgBinaryFragmentProgram; - typedef struct CgBinaryProgram CgBinaryProgram; - - // fragment programs have their constants embedded in the microcode - struct CgBinaryEmbeddedConstant - { - unsigned int ucodeCount; // occurances - unsigned int ucodeOffset[1]; // offsets that need to be patched follow - }; - - // describe a binary program parameter (CgParameter is opaque) - struct CgBinaryParameter - { - CGtype type; // cgGetParameterType() - CGresource res; // cgGetParameterResource() - CGenum var; // cgGetParameterVariability() - int resIndex; // cgGetParameterResourceIndex() - CgBinaryStringOffset name; // cgGetParameterName() - CgBinaryFloatOffset defaultValue; // default constant value - CgBinaryEmbeddedConstantOffset embeddedConst; // embedded constant information - CgBinaryStringOffset semantic; // cgGetParameterSemantic() - CGenum direction; // cgGetParameterDirection() - int paramno; // 0..n: cgGetParameterIndex() -1: globals - CGbool isReferenced; // cgIsParameterReferenced() - CGbool isShared; // cgIsParameterShared() - }; - - // attributes needed for vshaders - struct CgBinaryVertexProgram - { - unsigned int instructionCount; // #instructions - unsigned int instructionSlot; // load address (indexed reads!) - unsigned int registerCount; // R registers count - unsigned int attributeInputMask; // attributes vs reads from - unsigned int attributeOutputMask; // attributes vs writes (uses SET_VERTEX_ATTRIB_OUTPUT_MASK bits) - }; - - typedef enum { - CgBinaryPTTNone = 0, - CgBinaryPTT2x16 = 1, - CgBinaryPTT1x32 = 2, - } CgBinaryPartialTexType; - - // attributes needed for pshaders - struct CgBinaryFragmentProgram - { - unsigned int instructionCount; // #instructions - unsigned int attributeInputMask; // attributes fp reads (uses SET_VERTEX_ATTRIB_OUTPUT_MASK bits) - unsigned int partialTexType; // texid 0..15 use two bits each marking whether the texture format requires partial load: see CgBinaryPartialTexType - unsigned short texCoordsInputMask; // tex coords used by frag prog. (tex is bit n) - unsigned short texCoords2D; // tex coords that are 2d (tex is bit n) - unsigned short texCoordsCentroid; // tex coords that are centroid (tex is bit n) - unsigned char registerCount; // R registers count - unsigned char outputFromH0; // final color from R0 or H0 - unsigned char depthReplace; // fp generated z epth value - unsigned char pixelKill; // fp uses kill operations - }; - - // defines a binary program -- *all* address/offsets are relative to the begining of CgBinaryProgram - struct CgBinaryProgram - { - // vertex/pixel shader identification (BE/LE as well) - CGprofile profile; - - // binary revision (used to verify binary and driver structs match) - unsigned int binaryFormatRevision; - - // total size of this struct including profile and totalSize field! - unsigned int totalSize; - - // parameter usually queried using cgGet[First/Next]LeafParameter - unsigned int parameterCount; - CgBinaryParameterOffset parameterArray; - - // depending on profile points to a CgBinaryVertexProgram or CgBinaryFragmentProgram struct - CgBinaryOffset program; - - // raw ucode data - unsigned int ucodeSize; - CgBinaryOffset ucode; - - // variable length data follows - unsigned char data[1]; - }; - -#ifdef __cplusplus -} -#endif - -#endif // !_H_CG_BINARY_H_ diff --git a/ps3/gcmgl/include/PSGL/Base.h b/ps3/gcmgl/include/PSGL/Base.h deleted file mode 100644 index 86cb523c3d..0000000000 --- a/ps3/gcmgl/include/PSGL/Base.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _BASE_H_ -#define _BASE_H_ - -#include -#include - -namespace RGL -{ - template class Vector - { - public: - T* array; - unsigned int capacity; - unsigned int increment; - unsigned int count; - void * operator new( size_t size ) { return malloc( size ); } - void * operator new( size_t /*size*/, void *p ) { return p; } - void operator delete( void * /*ptr*/, void * /*p*/ ) { } - Vector(): array( 0 ), count( 0 ), capacity( 0 ), increment( 4 ) {} - ~Vector() - { - if (array) - { - for ( unsigned int i = 0;i < count;++i ) - ( array + i )->~T(); - count = 0; - free(array); - } - array = 0; - } - - inline void removeElement( const T &element ) - { - for ( unsigned int i = count; i > 0; --i ) - { - if ( array[i-1] == element ) - { - unsigned int index = i - 1; - ( array + index )->~T(); - --count; - if ( count > index ) - memmove( array + index, array + index + 1, ( count - index )*sizeof( T ) ); - return; - } - } - } - }; - -} - -#endif diff --git a/ps3/gcmgl/include/PSGL/TypeUtils.h b/ps3/gcmgl/include/PSGL/TypeUtils.h deleted file mode 100644 index e75cc44a29..0000000000 --- a/ps3/gcmgl/include/PSGL/TypeUtils.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef _TYPE_UTILS_H -#define _TYPE_UTILS_H - -/* Following NV_half_float specification - * The half data type is a floating-point - * data type encoded in an unsigned scalar data type. If the unsigned scalar - * holding a half has a value of N, the corresponding floating point number - * is - - * (-1)^S * 0.0, if E == 0 and M == 0, - * (-1)^S * 2^-14 * (M / 2^10), if E == 0 and M != 0, - * (-1)^S * 2^(E-15) * (1 + M/2^10), if 0 < E < 31, - * (-1)^S * INF, if E == 31 and M == 0, or - * NaN, if E == 31 and M != 0, - * - * where - * - * S = floor((N mod 65536) / 32768), - * E = floor((N mod 32768) / 1024), and - * M = N mod 1024. - * - * INF (Infinity) is a special representation indicating numerical overflow. - * NaN (Not a Number) is a special representation indicating the result of - * illegal arithmetic operations, such as division by zero. Note that all - * normal values, zero, and INF have an associated sign. -0.0 and +0.0 - * should be considered equivalent for the purposes of comparisons. Note - * also that half is not a native type in most CPUs, so some special - * processing may be required to generate or interpret half data. - * - * That is SEEEEEMMMMMMMMMM - */ - -typedef union -{ - unsigned int i; - float f; -} rglIntAndFloat; - -static const rglIntAndFloat rglNan = {i: 0x7fc00000U}; -static const rglIntAndFloat rglInfinity = {i: 0x7f800000U}; -#define RGL_NAN (rglNan.f) -#define RGL_INFINITY (rglInfinity.f) - -static inline GLhalfARB rglFloatToHalf( float v ) -{ - rglIntAndFloat V = {f: v}; - // extract float components - unsigned int S = ( V.i >> 31 ) & 1; - int E = (( V.i >> 23 ) & 0xff ) - 0x7f; - unsigned int M = V.i & 0x007fffff; - if (( E == 0x80 ) && ( M ) ) return 0x7fff; // NaN - else if ( E >= 15 ) return( S << 15 ) | 0x7c00; // Inf - else if ( E <= -14 ) return( S << 15 ) | (( 0x800000 + M ) >> ( -14 - E ) ); // Denorm or zero. Works for input denorms and zero - else return( S << 15 ) | ((( E + 15 )&0x1f ) << 10 ) | ( M >> 13 ); -} - -static inline float rglHalfToFloat( GLhalfARB v ) -{ - unsigned int S, E, M; - float f; - - S = v >> 15; - E = ( v & 0x7C00 ) >> 10; - M = v & 0x03ff; - - if ( E == 31 ) - { - if ( M == 0 ) - f = RGL_INFINITY; - else - f = RGL_NAN; - } - else if ( E == 0 ) - { - if ( M == 0 ) - f = 0.f; - else - f = M * 1.f / ( 1 << 24 ); - } - else - f = ( 0x400 + M ) * 1.f / ( 1 << 25 ) * ( 1 << E ); - return S ? -f : f; -} - -//---------------------------------------- -// Fixed Point Conversion Macros -// FixedPoint.c -//---------------------------------------- - -#define X2F(X) (((float)(X))* 1.f/65536.f) -#define F2X(A) ((int)((A)* 65536.f)) - -#endif // _TYPE_UTILS_H diff --git a/ps3/gcmgl/include/PSGL/Types.h b/ps3/gcmgl/include/PSGL/Types.h deleted file mode 100644 index cc8fb12093..0000000000 --- a/ps3/gcmgl/include/PSGL/Types.h +++ /dev/null @@ -1,811 +0,0 @@ -#ifndef _RGL_TYPES_H -#define _RGL_TYPES_H - -#include -#include - -#include "../export/PSGL/psgl.h" -#include "Types.h" -#include "Base.h" - -#include - -#define RGL_MAX_COLOR_ATTACHMENTS 4 -#define RGL_MAX_TEXTURE_IMAGE_UNITS 16 -#define RGL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 4 - -#define RGL_MAX_VERTEX_ATTRIBS 16 - -#define RGLGCM_BIG_ENDIAN - -#define ENDIAN_32(X, F) ((F) ? endianSwapWord(X) : (X)) - -#define FRAGMENT_PROFILE_INDEX 1 -#define RGLP_MAX_TEXTURE_SIZE 4096 - -#define RGLGCM_LINEAR_BUFFER_ALIGNMENT 128 -#define RGLGCM_HOST_BUFFER_ALIGNMENT 128 - -#define RGLGCM_TRANSIENT_MEMORY_DEFAULT (32 << 20) -#define RGLGCM_PERSISTENT_MEMORY_DEFAULT (160 << 20) -#define RGLGCM_FIFO_SIZE_DEFAULT (256 * 1024) -#define RGLGCM_HOST_SIZE_DEFAULT (0) -#define RGLGCM_TRANSIENT_ENTRIES_DEFAULT 64 - -// There are 6 clock domains, each with a maximum of 4 experiments, plus 4 elapsed exp. -#define RGL_MAX_DPM_QUERIES (4 * 6 + 4) - -// RSX semaphore allocation -// 64-191 events -// 192 fence implementation (independent of nv_glFence) -// 253 used in RGLGcmFifoUtils.h -#define RGLGCM_SEMA_NEVENTS 128 -#define RGLGCM_SEMA_BASE 64 // libgcm uses 0-63 -#define RGLGCM_SEMA_FENCE 192 - -// synchronization -// rglGcmSync enables GPU waiting by sending nv_glAcquireSemaphore to the -// GPU and returning a memory mapped pointer to the semaphore. The GPU -// will be released when 0 is written to the memory location. -// -// rglGcm{Inc,Test,Finish}FenceRef are intended to be drop-in replacements -// for the corresponding RGLGCM routines, using a semaphore instead of the -// fence mechanism (so IncFence uses the 3D class). - -#define RGLGCM_MAX_COLOR_SURFACES 4 - -// allocation unit for buffer objects -// Each buffer object is allocated to a multiple of this block size. This -// must be at least 64 so that nv_glTransferDataVidToVid() can be used to -// copy buffer objects within video memory. This function performs a 2D -// blit, and there is a 64-byte minimum pitch constraint. -// -// Swizzled textures require 128-byte alignment, so this takes precedence. -#define RGL_BUFFER_OBJECT_BLOCK_SIZE 128 - -#define VERTEX_PROFILE_INDEX 0 - -// GCM can render to 4 color buffers at once. -#define RGLGCM_SETRENDERTARGET_MAXCOUNT 4 - -// max amount of semaphore we allocate space for -#define RGLGCM_MAX_USER_SEMAPHORES 256 -#define RGLGCM_PAGE_SIZE 0x1000 // 4KB - -#define RGLGCM_LM_MAX_TOTAL_QUERIES 800 -#define RGLGCM_LM_MAX_ZPASS_REPORTS (RGLGCM_LM_MAX_TOTAL_QUERIES - 10) -#define RGLGCM_LM_MAX_USER_QUERIES (RGLGCM_LM_MAX_ZPASS_REPORTS) - -// For main memory query PSGL is going to enable 5000 at any given time -// compared to the 800 currently for the Local memory queries -// However, if you really need more than 5k then change the line below -// and recompile [RSTENSON] -// Maximum value for RGLGCM_MM_MAX_TOTAL_QUERIES is 65,000 -#define RGLGCM_MM_MAX_TOTAL_QUERIES 5000 // Should be plenty. -#define RGLGCM_MM_MAX_ZPASS_REPORTS (RGLGCM_MM_MAX_TOTAL_QUERIES - 10) -#define RGLGCM_MM_MAX_USER_QUERIES (RGLGCM_MM_MAX_ZPASS_REPORTS) - -// For 2.50 PSGL will use reports in main memory by default -// To revert to reports in local memory comment out this define -#define RGLGCM_USE_MAIN_MEMORY_REPORTS -#ifdef RGLGCM_USE_MAIN_MEMORY_REPORTS -#define RGLGCM_MAX_USER_QUERIES RGLGCM_MM_MAX_USER_QUERIES -#else -#define RGLGCM_MAX_USER_QUERIES RGLGCM_LM_MAX_USER_QUERIES -#endif - - -#define RGLGCM_357C_NOTIFIERS_MAXCOUNT 11 - -enum -{ - // dma contexts - RGLGCM_CHANNEL_DMA_SCRATCH_NOTIFIER, - RGLGCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER, - RGLGCM_CONTEXT_DMA_TO_MEMORY_GET_REPORT, - RGLGCM_CONTEXT_DMA_MEMORY_HOST_BUFFER, - RGLGCM_CONTEXT_DMA_MEMORY_SEMAPHORE_RW, - RGLGCM_CONTEXT_DMA_MEMORY_SEMAPHORE_RO, - - // classes - RGLGCM_CURIE_PRIMITIVE, - RGLGCM_MEM2MEM_HOST_TO_VIDEO, - - RGLGCM_IMAGEFROMCPU, - RGLGCM_SCALEDIMAGE, - RGLGCM_CONTEXT_2D_SURFACE, - RGLGCM_CONTEXT_SWIZ_SURFACE, - - RGLGCM_HANDLE_COUNT -}; - -// For quick float->int conversions -#define RGLGCM_F0_DOT_0 12582912.0f - -// some other useful push buf defines/commands -#define RGLGCM_COUNT_SHIFT (18) -#define RGLGCM_SUBCHANNEL_SHIFT (13) -#define RGLGCM_METHOD_SHIFT (0) - -#define DEFAULT_FIFO_BLOCK_SIZE (0x10000) // 64KB -#define FIFO_RESERVE_SIZE 8 // reserved words needed at the beginning of the fifo - -#define BUFFER_HSYNC_NEGATIVE 0 -#define BUFFER_HSYNC_POSITIVE 1 -#define BUFFER_VSYNC_NEGATIVE 0 -#define BUFFER_VSYNC_POSITIVE 1 - -// This is the format that the mode timing parameters are handed back - -enum { - RGLGCM_SURFACE_SOURCE_TEMPORARY, - RGLGCM_SURFACE_SOURCE_DEVICE, - RGLGCM_SURFACE_SOURCE_TEXTURE, - RGLGCM_SURFACE_SOURCE_RENDERBUFFER, - RGLGCM_SURFACE_SOURCE_PBO, -}; - -enum { - RGLGCM_SURFACE_POOL_NONE, - RGLGCM_SURFACE_POOL_LINEAR, -}; - - -#define RGLGCM_DEVICE_SYNC_FENCE 1 -#define RGLGCM_DEVICE_SYNC_COND 2 - -// max attrib count -#define RGLGCM_ATTRIB_COUNT 16 - -// Names for each of the vertex attributes -#define RGLGCM_ATTRIB_POSITION 0 -#define RGLGCM_ATTRIB_VERTEX_WEIGHT 1 -#define RGLGCM_ATTRIB_NORMAL 2 -#define RGLGCM_ATTRIB_COLOR 3 -#define RGLGCM_ATTRIB_SECONDARY_C OLOR 4 -#define RGLGCM_ATTRIB_FOG_COORD 5 -#define RGLGCM_ATTRIB_PSIZE 6 -#define RGLGCM_ATTRIB_UNUSED1 7 -#define RGLGCM_ATTRIB_TEXCOORD0 8 -#define RGLGCM_ATTRIB_TEXCOORD1 9 -#define RGLGCM_ATTRIB_TEXCOORD2 10 -#define RGLGCM_ATTRIB_TEXCOORD3 11 -#define RGLGCM_ATTRIB_TEXCOORD4 12 -#define RGLGCM_ATTRIB_TEXCOORD5 13 -#define RGLGCM_ATTRIB_TEXCOORD6 14 -#define RGLGCM_ATTRIB_TEXCOORD7 15 - -// Names for the vertex output components: -#define RGLGCM_ATTRIB_OUTPUT_HPOS 0 -#define RGLGCM_ATTRIB_OUTPUT_COL0 1 -#define RGLGCM_ATTRIB_OUTPUT_COL1 2 -#define RGLGCM_ATTRIB_OUTPUT_BFC0 3 -#define RGLGCM_ATTRIB_OUTPUT_BFC1 4 -#define RGLGCM_ATTRIB_OUTPUT_FOGC 5 -#define RGLGCM_ATTRIB_OUTPUT_PSIZ 6 -#define RGLGCM_ATTRIB_OUTPUT_TEX0 7 -#define RGLGCM_ATTRIB_OUTPUT_TEX1 8 -#define RGLGCM_ATTRIB_OUTPUT_TEX2 9 -#define RGLGCM_ATTRIB_OUTPUT_TEX3 10 -#define RGLGCM_ATTRIB_OUTPUT_TEX4 11 -#define RGLGCM_ATTRIB_OUTPUT_TEX5 12 -#define RGLGCM_ATTRIB_OUTPUT_TEX6 13 -#define RGLGCM_ATTRIB_OUTPUT_TEX7 14 - -// viewport adjusting -#define RGLGCM_SUBPIXEL_ADJUST (0.5/(1<<12)) -#define RGLGCM_VIEWPORT_EPSILON 0.0f - -#define RGLGCM_HAS_INVALIDATE_TILE - -#define RGLGCM_TILED_BUFFER_ALIGNMENT 0x10000 // 64KB -#define RGLGCM_TILED_BUFFER_HEIGHT_ALIGNMENT 64 - -#define RGLGCM_MAX_TILED_REGIONS 15 - -typedef enum rglGcmEnum -{ - // gleSetRenderTarget - RGLGCM_NONE = 0x0000, - - // glDrawArrays, glDrawElements, glBegin - RGLGCM_POINTS = 0x0000, - RGLGCM_LINES = 0x0001, - RGLGCM_LINE_LOOP = 0x0002, - RGLGCM_LINE_STRIP = 0x0003, - RGLGCM_TRIANGLES = 0x0004, - RGLGCM_TRIANGLE_STRIP = 0x0005, - RGLGCM_TRIANGLE_FAN = 0x0006, - RGLGCM_QUADS = 0x0007, - RGLGCM_QUAD_STRIP = 0x0008, - RGLGCM_POLYGON = 0x0009, - - // glClear - RGLGCM_DEPTH_BUFFER_BIT = 0x0100, - RGLGCM_STENCIL_BUFFER_BIT = 0x0400, - RGLGCM_COLOR_BUFFER_BIT = 0x4000, - - // glBlendFunc, glStencilFunc - RGLGCM_ZERO = 0, - RGLGCM_ONE = 1, - RGLGCM_SRC_COLOR = 0x0300, - RGLGCM_ONE_MINUS_SRC_COLOR = 0x0301, - RGLGCM_SRC_ALPHA = 0x0302, - RGLGCM_ONE_MINUS_SRC_ALPHA = 0x0303, - RGLGCM_DST_ALPHA = 0x0304, - RGLGCM_ONE_MINUS_DST_ALPHA = 0x0305, - RGLGCM_DST_COLOR = 0x0306, - RGLGCM_ONE_MINUS_DST_COLOR = 0x0307, - RGLGCM_SRC_ALPHA_SATURATE = 0x0308, - - // glAlphaFunc, glDepthFunc, glStencilFunc - RGLGCM_NEVER = 0x0200, - RGLGCM_LESS = 0x0201, - RGLGCM_EQUAL = 0x0202, - RGLGCM_LEQUAL = 0x0203, - RGLGCM_GREATER = 0x0204, - RGLGCM_NOTEQUAL = 0x0205, - RGLGCM_GEQUAL = 0x0206, - RGLGCM_ALWAYS = 0x0207, - - // glLogicOp - RGLGCM_CLEAR = 0x1500, - RGLGCM_AND = 0x1501, - RGLGCM_AND_REVERSE = 0x1502, - RGLGCM_COPY = 0x1503, - RGLGCM_AND_INVERTED = 0x1504, - RGLGCM_NOOP = 0x1505, - RGLGCM_XOR = 0x1506, - RGLGCM_OR = 0x1507, - RGLGCM_NOR = 0x1508, - RGLGCM_EQUIV = 0x1509, - RGLGCM_INVERT = 0x150A, - RGLGCM_OR_REVERSE = 0x150B, - RGLGCM_COPY_INVERTED = 0x150C, - RGLGCM_OR_INVERTED = 0x150D, - RGLGCM_NAND = 0x150E, - RGLGCM_SET = 0x150F, - - // BlendFunc - RGLGCM_CONSTANT_COLOR = 0x8001, - RGLGCM_ONE_MINUS_CONSTANT_COLOR = 0x8002, - RGLGCM_CONSTANT_ALPHA = 0x8003, - RGLGCM_ONE_MINUS_CONSTANT_ALPHA = 0x8004, - RGLGCM_BLEND_COLOR = 0x8005, - RGLGCM_FUNC_ADD = 0x8006, - RGLGCM_MIN = 0x8007, - RGLGCM_MAX = 0x8008, - RGLGCM_BLEND_EQUATION = 0x8009, - RGLGCM_FUNC_SUBTRACT = 0x800A, - RGLGCM_FUNC_REVERSE_SUBTRACT = 0x800B, - - // glTexImage binary formats -- keep in sync with glTexImage tables! - RGLGCM_ALPHA8 = 0x803C, - RGLGCM_ALPHA16 = 0x803E, - RGLGCM_HILO8 = 0x885E, - RGLGCM_HILO16 = 0x86F8, - RGLGCM_ARGB8 = 0x6007, // does not exist in classic OpenGL - RGLGCM_BGRA8 = 0xff01, // does not exist in classic OpenGL - RGLGCM_RGBA8 = 0x8058, - RGLGCM_ABGR8 = 0xff02, // does not exist in classic OpenGL - RGLGCM_XBGR8 = 0xff03, // does not exist in classic OpenGL - RGLGCM_RGBX8 = 0xff07, // does not exist in classic OpenGL - RGLGCM_COMPRESSED_RGB_S3TC_DXT1 = 0x83F0, - RGLGCM_COMPRESSED_RGBA_S3TC_DXT1 = 0x83F1, - RGLGCM_COMPRESSED_RGBA_S3TC_DXT3 = 0x83F2, - RGLGCM_COMPRESSED_RGBA_S3TC_DXT5 = 0x83F3, - RGLGCM_DEPTH_COMPONENT16 = 0x81A5, - RGLGCM_DEPTH_COMPONENT24 = 0x81A6, - RGLGCM_FLOAT_R32 = 0x8885, - RGLGCM_RGB5_A1_SCE = 0x600C, - RGLGCM_RGB565_SCE = 0x600D, - - // glEnable/glDisable - RGLGCM_BLEND = 0x0be0, - RGLGCM_COLOR_LOGIC_OP = 0x0bf2, - RGLGCM_DITHER = 0x0bd0, - - // glVertexAttribPointer - RGLGCM_VERTEX_ATTRIB_ARRAY0 = 0x8650, - RGLGCM_VERTEX_ATTRIB_ARRAY1 = 0x8651, - RGLGCM_VERTEX_ATTRIB_ARRAY2 = 0x8652, - RGLGCM_VERTEX_ATTRIB_ARRAY3 = 0x8653, - RGLGCM_VERTEX_ATTRIB_ARRAY4 = 0x8654, - RGLGCM_VERTEX_ATTRIB_ARRAY5 = 0x8655, - RGLGCM_VERTEX_ATTRIB_ARRAY6 = 0x8656, - RGLGCM_VERTEX_ATTRIB_ARRAY7 = 0x8657, - RGLGCM_VERTEX_ATTRIB_ARRAY8 = 0x8658, - RGLGCM_VERTEX_ATTRIB_ARRAY9 = 0x8659, - RGLGCM_VERTEX_ATTRIB_ARRAY10 = 0x865a, - RGLGCM_VERTEX_ATTRIB_ARRAY11 = 0x865b, - RGLGCM_VERTEX_ATTRIB_ARRAY12 = 0x865c, - RGLGCM_VERTEX_ATTRIB_ARRAY13 = 0x865d, - RGLGCM_VERTEX_ATTRIB_ARRAY14 = 0x865e, - RGLGCM_VERTEX_ATTRIB_ARRAY15 = 0x865f, - - // glTexImage - RGLGCM_TEXTURE_3D = 0x806F, - RGLGCM_TEXTURE_CUBE_MAP = 0x8513, - RGLGCM_TEXTURE_1D = 0x0DE0, - RGLGCM_TEXTURE_2D = 0x0DE1, - - // glTexParameter/TextureMagFilter - RGLGCM_NEAREST = 0x2600, - RGLGCM_LINEAR = 0x2601, - // glTexParameter/TextureMinFilter - RGLGCM_NEAREST_MIPMAP_NEAREST = 0x2700, - RGLGCM_LINEAR_MIPMAP_NEAREST = 0x2701, - RGLGCM_NEAREST_MIPMAP_LINEAR = 0x2702, - RGLGCM_LINEAR_MIPMAP_LINEAR = 0x2703, - - // glTexParameter/TextureWrapMode - RGLGCM_CLAMP = 0x2900, - RGLGCM_REPEAT = 0x2901, - RGLGCM_CLAMP_TO_EDGE = 0x812F, - RGLGCM_CLAMP_TO_BORDER = 0x812D, - RGLGCM_MIRRORED_REPEAT = 0x8370, - RGLGCM_MIRROR_CLAMP = 0x8742, - RGLGCM_MIRROR_CLAMP_TO_EDGE = 0x8743, - RGLGCM_MIRROR_CLAMP_TO_BORDER = 0x8912, - - // glTexParameter/GammaRemap - RGLGCM_GAMMA_REMAP_RED_BIT = 0x0001, - RGLGCM_GAMMA_REMAP_GREEN_BIT = 0x0002, - RGLGCM_GAMMA_REMAP_BLUE_BIT = 0x0004, - RGLGCM_GAMMA_REMAP_ALPHA_BIT = 0x0008, - - // glTexParameter - RGLGCM_TEXTURE_WRAP_S = 0x2802, - RGLGCM_TEXTURE_WRAP_T = 0x2803, - RGLGCM_TEXTURE_WRAP_R = 0x8072, - RGLGCM_TEXTURE_MIN_FILTER = 0x2801, - RGLGCM_TEXTURE_MAG_FILTER = 0x2800, - RGLGCM_TEXTURE_MAX_ANISOTROPY = 0x84FE, - RGLGCM_TEXTURE_COMPARE_FUNC = 0x884D, - RGLGCM_TEXTURE_MIN_LOD = 0x813A, - RGLGCM_TEXTURE_MAX_LOD = 0x813B, - RGLGCM_TEXTURE_LOD_BIAS = 0x8501, - RGLGCM_TEXTURE_BORDER_COLOR = 0x1004, - RGLGCM_TEXTURE_GAMMA_REMAP = 0xff30, - - // ARB_vertex_program - RGLGCM_VERTEX_PROGRAM = 0x8620, - RGLGCM_FRAGMENT_PROGRAM = 0x8804, - - // glVertexAttribPointer - RGLGCM_FLOAT = 0x1406, - RGLGCM_HALF_FLOAT = 0x140B, - RGLGCM_SHORT = 0x1402, - RGLGCM_UNSIGNED_BYTE = 0x1401, - RGLGCM_UNSIGNED_SHORT = 0x1403, - RGLGCM_UNSIGNED_INT = 0x1405, - RGLGCM_BYTE = 0x1400, - RGLGCM_INT = 0x1404, - - // query support - RGLGCM_SAMPLES_PASSED = 0xff10, - - // semaphore support - RGLGCM_SEMAPHORE_USING_GPU = 0xff20, - RGLGCM_SEMAPHORE_USING_CPU = 0xff21, - RGLGCM_SEMAPHORE_USING_GPU_NO_WRITE_FLUSH = 0xff22, - - // depth clamp - RGLGCM_DEPTH_CLAMP = 0x864F, - - // 11/11/10 bit 3-component attributes - RGLGCM_CMP = 0x6020, -} rglGcmEnum; - -struct rglFramebufferAttachment -{ - GLenum type; // renderbuffer or texture - GLuint name; - - // only valid for texture attachment - GLenum textureTarget; - rglFramebufferAttachment(): type( GL_NONE ), name( 0 ), textureTarget( GL_NONE ) - {}; -}; - - -// gleSetRenderTarget has enough arguments to define its own struct -typedef struct rglGcmRenderTargetEx rglGcmRenderTargetEx; -struct rglGcmRenderTargetEx -{ - // color buffers - rglGcmEnum colorFormat; - GLuint colorBufferCount; - - GLuint colorId[RGLGCM_SETRENDERTARGET_MAXCOUNT]; - GLuint colorIdOffset[RGLGCM_SETRENDERTARGET_MAXCOUNT]; - GLuint colorPitch[RGLGCM_SETRENDERTARGET_MAXCOUNT]; - - // (0,0) is in the lower left - GLboolean yInverted; - - // window offset - GLuint xOffset; - GLuint yOffset; - - // render dimensions - GLuint width; - GLuint height; -}; - -struct rglFramebuffer -{ - rglFramebufferAttachment color[RGL_MAX_COLOR_ATTACHMENTS]; - rglGcmRenderTargetEx rt; - GLboolean complete; - GLboolean needValidate; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -#define RGLBIT_GET(f,n) ((f) & (1<<(n))) -#define RGLBIT_TRUE(f,n) ((f) |= (1<<(n))) -#define RGLBIT_FALSE(f,n) ((f) &= ~(1<<(n))) -#define RGLBIT_ASSIGN(f,n,val) do { if(val) RGLBIT_TRUE(f,n); else RGLBIT_FALSE(f,n); } while(0) - -typedef struct -{ - GLfloat R, G, B, A; -} rglColorRGBAf; - -typedef struct -{ - int X, Y, XSize, YSize; -} rglViewPort; - -// image location flags -// These are flag bits that indicate where the valid image data is. Data -// can be valid nowhere, on the host, on the GPU, or in both places. -enum { - RGL_IMAGE_DATASTATE_UNSET = 0x0, // not a flag, just a meaningful 0 - RGL_IMAGE_DATASTATE_HOST = 0x1, - RGL_IMAGE_DATASTATE_GPU = 0x2 -}; - -// Image data structure -typedef struct rglImage_ -{ - // isSet indicates whether a gl*TexImage* call has been made on that image, - // to know whether calling gl*TexSubImage* is valid or not. - GLboolean isSet; - - GLenum internalFormat; - GLenum format; - GLenum type; - GLsizei width; - GLsizei height; - GLsizei depth; - GLsizei alignment; - - // image storage - // For raster - // storage, the platform driver sets strides (in bytes) between - // lines and layers and the library takes care of the rest. - - // These values are initially zero, but may be set by the platform - // rglPlatformChooseInternalStorage to specify custom storage - // (compressed, swizzled, etc.). They should be considered - // read-only except by the platform driver. - GLsizei storageSize; // minimum allocation - GLsizei xstride, ystride, zstride; // strides - GLuint xblk, yblk; // block storage size - - char *data; - char *mallocData; - GLsizei mallocStorageSize; - GLenum dataState; // valid data location (see enum above) -} rglImage; - -// Raster data structure -// This struct is used internally to define 3D raster data for writing -// to or reading from a rglImage. The GL-level interface for pixel/texel -// level operations always uses a raster, even though the underlying -// platform-specific storage may not be a raster (e.g. compressed -// blocks). The internal routines rglRasterToImage and rglImageToRaster -// convert between the two. -// -// A clean alternative would have been to use rglImage for everything and -// implement a single rglImageToImage copying function. However, given -// that one side will always be a raster, the implementation cost was -// not seen as worth the generality. -typedef struct -{ - GLenum format; - GLenum type; - GLsizei width; - GLsizei height; - GLsizei depth; - GLsizei xstride; - GLsizei ystride; - GLsizei zstride; - void* data; -} rglRaster; - -#define RGL_TEXTURE_REVALIDATE_LAYOUT 0x01 -#define RGL_TEXTURE_REVALIDATE_IMAGES 0x02 -#define RGL_TEXTURE_REVALIDATE_PARAMETERS 0x04 - -typedef struct rglBufferObject rglBufferObject; - -// Texture data structure -typedef struct -{ - GLuint revalidate; - GLuint target; - - GLuint minFilter; - GLuint magFilter; - GLfloat minLod; - GLfloat maxLod; - GLuint maxLevel; - GLuint wrapS; - GLuint wrapT; - GLuint wrapR; - GLfloat lodBias; - GLfloat maxAnisotropy; - GLenum compareMode; - GLenum compareFunc; - GLuint gammaRemap; - GLenum usage; - - rglColorRGBAf borderColor; - - GLboolean vertexEnable; - GLboolean isRenderTarget; - // this is valid when the revalidate bits do not have any resource bit set. - // the validation of the resources update the bit. - GLboolean isComplete; - - rglBufferObject *referenceBuffer; - intptr_t offset; - - RGL::Vector framebuffers; - - GLuint imageCount; - rglImage* image; - void * platformTexture[]; // C99 flexible array member -} rglTexture; - -typedef struct -{ - GLboolean isSet; - void* platformFenceObject[]; -} rglFenceObject; - -// For now, we'll use a static array for lights -// - -// Texture image unit data structure -typedef struct -{ - GLuint bound2D; - - rglTexture* default2D; - - GLboolean enable2D; - - // the current fragment program's target for this unit, if in use. - // this is invalid otherwise - GLenum fragmentTarget; - GLfloat lodBias; - - rglTexture* currentTexture; -} rglTextureImageUnit; - -enum -{ - RGL_FRAMEBUFFER_ATTACHMENT_NONE, - RGL_FRAMEBUFFER_ATTACHMENT_RENDERBUFFER, - RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE, -}; - -struct RGLdevice -{ - PSGLdeviceParameters deviceParameters; - - GLvoid* rasterDriver; - char platformDevice[]; // C99 flexible array member -}; - -typedef struct -{ - // parameters to glDraw* calls - GLenum mode; - GLint firstVertex; - GLsizei vertexCount; - GLuint indexMin; - GLuint indexMax; // 0==glDrawElements; 0!=glDrawRangeElements - GLsizei indexCount; - - // internal draw parameters - // client-side array transfer buffer params - GLuint xferTotalSize; - GLuint indexXferOffset; - GLuint indexXferSize; - GLuint attribXferTotalSize; - GLuint attribXferOffset[RGL_MAX_VERTEX_ATTRIBS]; - GLuint attribXferSize[RGL_MAX_VERTEX_ATTRIBS]; -} rglDrawParams; - -// define mapping of vertex semantics to attributes -// These indices specify the aliasing of vertex attributes with -// conventional per-vertex parameters. This mapping is the same as -// specified in the NV_vertex_program extension. -#define RGL_ATTRIB_POSITION_INDEX 0 -#define RGL_ATTRIB_WEIGHT_INDEX 1 -#define RGL_ATTRIB_NORMAL_INDEX 2 -#define RGL_ATTRIB_PRIMARY_COLOR_INDEX 3 -#define RGL_ATTRIB_SECONDARY_COLOR_INDEX 4 -#define RGL_ATTRIB_FOG_COORD_INDEX 5 -#define RGL_ATTRIB_POINT_SIZE_INDEX 6 -#define RGL_ATTRIB_BLEND_INDICES_INDEX 7 -#define RGL_ATTRIB_TEX_COORD0_INDEX 8 -#define RGL_ATTRIB_TEX_COORD1_INDEX 9 -#define RGL_ATTRIB_TEX_COORD2_INDEX 10 -#define RGL_ATTRIB_TEX_COORD3_INDEX 11 -#define RGL_ATTRIB_TEX_COORD4_INDEX 12 -#define RGL_ATTRIB_TEX_COORD5_INDEX 13 -#define RGL_ATTRIB_TEX_COORD6_INDEX 14 -#define RGL_ATTRIB_TEX_COORD7_INDEX 15 - -// per-attribute descriptor and data -typedef struct -{ - // GL state - GLvoid* clientData; // client-side array pointer or VBO offset - GLuint clientSize; // number of components 1-4 - GLenum clientType; // GL_SHORT, GL_INT, GL_FLOAT - GLsizei clientStride; // element-to-element distance [bytes] - GLuint arrayBuffer; // name of buffer object; 0==none (ie client-side) - GLfloat value[4]; // constant attribute value - GLuint frequency; // instancing divisor - GLboolean normalized; -} __attribute__((aligned (16))) rglAttribute; - -// state for the entire set of vertex attributes, plus -// other AttribSet-encapsulated state. -// (this is the block of state applied en mass during glBindAttribSetSCE()) -typedef struct -{ - // Vertex attribute descriptors and data are stored in this array. - // The fixed function attributes are aliased to the array via the - // indices defined by _RGL_ATTRIB_*_INDEX. - rglAttribute attrib[RGL_MAX_VERTEX_ATTRIBS]; - - // bitfields corresponding to the attrib[] array elements: - unsigned int DirtyMask; // 1 == attribute has changed & needs updating - unsigned int EnabledMask; // 1 == attribute is enabled for drawing - unsigned int HasVBOMask; // 1 == attribute is in a VBO (ie server-side) -} __attribute__((aligned (16))) rglAttributeState; - -struct rglBufferObject -{ - GLuint refCount; - GLsizeiptr size; - GLboolean mapped; - GLenum internalFormat; - GLuint width; - GLuint height; - RGL::Vector textureReferences; - void *platformBufferObject[]; -}; - - -#define RGL_CONTEXT_RED_MASK 0x01 -#define RGL_CONTEXT_GREEN_MASK 0x02 -#define RGL_CONTEXT_BLUE_MASK 0x04 -#define RGL_CONTEXT_ALPHA_MASK 0x08 -#define RGL_CONTEXT_DEPTH_MASK 0x10 -#define RGL_CONTEXT_COLOR_MASK 0x0F - -enum -{ - RGL_CONTEXT_ACTIVE_SURFACE_COLOR0, - RGL_CONTEXT_ACTIVE_SURFACE_COLOR1, - RGL_CONTEXT_ACTIVE_SURFACE_COLOR2, - RGL_CONTEXT_ACTIVE_SURFACE_COLOR3, - RGL_CONTEXT_ACTIVE_SURFACE_DEPTH, - RGL_CONTEXT_ACTIVE_SURFACE_STENCIL, - RGL_CONTEXT_ACTIVE_SURFACES -}; - -typedef struct rglNameSpace -{ - void** data; - void** firstFree; - unsigned long capacity; -} rglNameSpace; - -typedef void *( *rglTexNameSpaceCreateFunction )( void ); -typedef void( *rglTexNameSpaceDestroyFunction )( void * ); - -typedef struct rglTexNameSpace -{ - void** data; - GLuint capacity; - rglTexNameSpaceCreateFunction create; - rglTexNameSpaceDestroyFunction destroy; -} rglTexNameSpace; - -struct RGLcontext -{ - GLenum error; - - rglViewPort ViewPort; - GLclampf DepthNear; - GLclampf DepthFar; - - rglAttributeState defaultAttribs0; // a default rglAttributeState, for bind = 0 - rglAttributeState *attribs; // ptr to current rglAttributeState - - // Frame buffer-related fields - // - GLenum DrawBuffer, ReadBuffer; - - GLboolean Blending; // enable for mrt color target 0 - GLenum BlendEquationRGB; - GLenum BlendEquationAlpha; - GLenum BlendFactorSrcRGB; - GLenum BlendFactorDestRGB; - GLenum BlendFactorSrcAlpha; - GLenum BlendFactorDestAlpha; - rglColorRGBAf BlendColor; - - GLboolean ColorLogicOp; - GLenum LogicOp; - - GLboolean Dithering; - - GLuint TexCoordReplaceMask; - - rglTexNameSpace textureNameSpace; - GLuint ActiveTexture; - rglTextureImageUnit TextureImageUnits[RGL_MAX_TEXTURE_IMAGE_UNITS]; - rglTextureImageUnit* CurrentImageUnit; - - GLsizei packAlignment; - GLsizei unpackAlignment; - - rglTexNameSpace bufferObjectNameSpace; - GLuint ArrayBuffer; - GLuint PixelUnpackBuffer; - GLuint TextureBuffer; - - // framebuffer objects - GLuint framebuffer; // GL_FRAMEBUFFER_OES binding - rglTexNameSpace framebufferNameSpace; - - GLboolean VertexProgram; - struct _CGprogram* BoundVertexProgram; - - GLboolean FragmentProgram; - struct _CGprogram* BoundFragmentProgram; - unsigned int LastFPConstantModification; - - GLboolean VSync; - GLboolean SkipFirstVSync; - - GLuint needValidate; - GLboolean everAttached; - - CGerror RGLcgLastError; - CGerrorCallbackFunc RGLcgErrorCallbackFunction; - // Cg containers - CGcontext RGLcgContextHead; - rglNameSpace cgContextNameSpace; - rglNameSpace cgProgramNameSpace; - rglNameSpace cgParameterNameSpace; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ps3/gcmgl/include/PSGL/Utils.h b/ps3/gcmgl/include/PSGL/Utils.h deleted file mode 100644 index 39e580abf0..0000000000 --- a/ps3/gcmgl/include/PSGL/Utils.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _RGLUTILS_H_ -#define _RGLUTILS_H_ - -#include "Types.h" -#include "../export/PSGL/export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define RGL_LIKELY(COND) __builtin_expect((COND),1) -#define RGL_UNLIKELY(COND) __builtin_expect((COND),0) - -#define MAX(A,B) ((A)>(B)?(A):(B)) -#define MIN(A,B) ((A)<(B)?(A):(B)) - -#define _RGL_FLOAT_AS_UINT(x) ({union {float f; unsigned int i;} u; u.f=(x); u.i;}) - -#define rglClampf(value) (MAX( MIN((value), 1.f ), 0.f )) -#define endianSwapHalf(v) (((v) >> 8 & 0x00ff) | ((v) << 8 & 0xff00)) -#define endianSwapWord(v) (((v) & 0xff ) << 24 | ((v) & 0xff00 ) << 8 | ((v) & 0xff0000 ) >> 8 | ((v) & 0xff000000 ) >> 24) -#define endianSwapWordByHalf(v) (((v) & 0xffff ) << 16 | (v) >> 16) - -static inline int rglLog2( unsigned int i ) -{ - int l = 0; - while ( i ) - { - ++l; - i >>= 1; - } - return l -1; -} - -#define rglIsPow2(i) (((i) & ((i) - 1 )) == 0) -// Pad argument x to the next multiple of argument pad. -#define rglPad(x, pad) (((x) + (pad) - 1 ) / (pad) * (pad)) -// Pad pointer x to the next multiple of argument pad. -#define rglPadPtr(p, pad) ((char*)(((intptr_t)(p) + (pad) - 1 ) / (pad) * (pad))) - -// names API - -RGL_EXPORT unsigned int rglCreateName (void *data, void* object); -RGL_EXPORT unsigned int rglIsName( void *data, unsigned int name); -RGL_EXPORT void rglEraseName (void *data, unsigned int name); - -#define rglGetNamedValue(x, name) (((struct rglNameSpace*)(x))->data[(name) - 1]) - -void rglTexNameSpaceResetNames(void *data); -GLboolean rglTexNameSpaceCreateNameLazy(void *data, GLuint name ); -GLboolean rglTexNameSpaceIsName(void *data, GLuint name ); -void rglTexNameSpaceDeleteNames(void *data, GLsizei n, const GLuint *names ); -void rglTexNameSpaceReinit(void *saved, void *active); - -#ifdef __cplusplus -} -#endif - -#endif // _RGL_UTILS_H_ diff --git a/ps3/gcmgl/include/PSGL/private.h b/ps3/gcmgl/include/PSGL/private.h deleted file mode 100644 index 1c49d368f3..0000000000 --- a/ps3/gcmgl/include/PSGL/private.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef _RGL_PRIVATE_H -#define _RGL_PRIVATE_H - -#include "../export/PSGL/psgl.h" -#include "Types.h" -#include "Utils.h" - -#ifndef OS_VERSION_NUMERIC -#define OS_VERSION_NUMERIC 0x160 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -extern RGL_EXPORT RGLcontext* _CurrentContext; -extern RGLdevice* _CurrentDevice; -extern RGL_EXPORT char* rglVersion; - -// only for internal purpose -#define GL_UNSIGNED_BYTE_4_4 0x4A00 -#define GL_UNSIGNED_BYTE_4_4_REV 0x4A01 -#define GL_UNSIGNED_BYTE_6_2 0x4A02 -#define GL_UNSIGNED_BYTE_2_6_REV 0x4A03 -#define GL_UNSIGNED_SHORT_12_4 0x4A04 -#define GL_UNSIGNED_SHORT_4_12_REV 0x4A05 -#define GL_UNSIGNED_BYTE_2_2_2_2 0x4A06 -#define GL_UNSIGNED_BYTE_2_2_2_2_REV 0x4A07 - -#define GL_FLOAT_RGBA32 0x888B - -typedef void( * RGLcontextHookFunction )( RGLcontext *context ); -extern RGL_EXPORT RGLcontextHookFunction rglContextCreateHook; -extern RGL_EXPORT RGLcontextHookFunction rglContextDestroyHook; - -extern RGLcontext* rglContextCreate(void); -extern void rglContextFree( RGLcontext* LContext ); -extern void rglSetError( GLenum error ); -void rglDetachContext( RGLdevice *device, RGLcontext* context ); -void rglSetFlipHandler(void (*handler)(const GLuint head), RGLdevice *device); -void rglSetVBlankHandler(void (*handler)(const GLuint head), RGLdevice *device); - -//---------------------------------------- -// Texture.c -//---------------------------------------- -extern int rglTextureInit( RGLcontext* context, GLuint name ); -extern void rglTextureDelete( RGLcontext* context, GLuint name ); -extern GLboolean rglTextureHasValidLevels( const rglTexture *texture, int levels, int width, int height, int depth, GLenum format, GLenum type, GLenum internalFormat ); -extern rglTexture *rglGetCurrentTexture (const void *data, GLenum target); -void rglReallocateImages (void *data, GLint level, GLsizei dimension); - -static inline rglTexture* rglGetTextureSafe (RGLcontext *LContext, GLuint name) -{ - return rglTexNameSpaceIsName( &LContext->textureNameSpace, name ) ? ( rglTexture* )LContext->textureNameSpace.data[name] : NULL; -} - -static inline rglFramebuffer *rglGetFramebuffer( RGLcontext *LContext, GLuint name ); - -static inline void rglTextureTouchFBOs (void *data) -{ - rglTexture *texture = (rglTexture*)data; - RGLcontext *LContext = (RGLcontext*)_CurrentContext; - - if (!LContext ) - return; // may be called in psglDestroyContext - - // check if bound to any framebuffer - GLuint fbCount = texture->framebuffers.count; - - if ( fbCount > 0 ) - { - rglFramebuffer *contextFramebuffer = LContext->framebuffer ? rglGetFramebuffer( LContext, LContext->framebuffer ) : NULL; - for ( GLuint i = 0;i < fbCount;++i ) - { - rglFramebuffer* framebuffer = texture->framebuffers.array[i]; - framebuffer->needValidate = GL_TRUE; - if (RGL_UNLIKELY( framebuffer == contextFramebuffer)) - LContext->needValidate |= PSGL_VALIDATE_FRAMEBUFFER; - } - } -} - -//---------------------------------------- -// Image.c -//---------------------------------------- -GLboolean rglIsType( GLenum type ); -GLboolean rglIsFormat( GLenum format ); -GLboolean rglIsValidPair( GLenum format, GLenum type ); -void rglImageAllocCPUStorage (void *data); -void rglImageFreeCPUStorage (void *data); -extern int rglGetPixelSize( GLenum format, GLenum type ); - -//---------------------------------------- -// FramebufferObject.c -//---------------------------------------- -rglFramebuffer *rglCreateFramebuffer( void ); -void rglDestroyFramebuffer (void *data); - -static inline rglFramebuffer *rglGetFramebuffer( RGLcontext *LContext, GLuint name ) -{ - return ( rglFramebuffer * )LContext->framebufferNameSpace.data[name]; -} - -static inline rglFramebuffer *rglGetFramebufferSafe( RGLcontext *LContext, GLuint name ) -{ - return rglTexNameSpaceIsName( &LContext->framebufferNameSpace, name ) ? ( rglFramebuffer * )LContext->framebufferNameSpace.data[name] : NULL; -} - -void rglFramebufferGetAttachmentTexture( RGLcontext* LContext, const rglFramebufferAttachment* attachment, rglTexture** texture, GLuint* face ); -GLenum rglPlatformFramebufferCheckStatus (void *data); -void rglPlatformFramebufferGetParameteriv( GLenum pname, GLint* params ); - -//---------------------------------------- -// VertexArray.c -//---------------------------------------- -void rglVertexAttribPointerNV( GLuint index, GLint fsize, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer ); -void rglEnableVertexAttribArrayNV( GLuint index ); -void rglDisableVertexAttribArrayNV( GLuint index ); - -//---------------------------------------- -// Device/Device.c -//---------------------------------------- -extern void rglDeviceInit (void *data); -extern void rglDeviceExit (void); -extern PSGLdeviceParameters * rglShadowDeviceParameters (void); - - -//---------------------------------------- -// Device/.../PlatformDevice.c -//---------------------------------------- -extern GLboolean rglPlatformDeviceInit (void *data); -extern void rglPlatformDeviceExit (void); -extern int rglPlatformCreateDevice (void *data); -extern void rglPlatformSwapBuffers (void *data); -extern const GLvoid* rglPlatformGetProcAddress (const char *funcName); - -//---------------------------------------- -// Raster/.../PlatformRaster.c -//---------------------------------------- -void rglPlatformRasterDestroyResources (void); -GLboolean rglPlatformNeedsConversion (const rglAttributeState* as, GLuint index); -void rglInvalidateAttributes (void); - -//---------------------------------------- -// Raster/.../PlatformTexture.c -//---------------------------------------- -extern void rglPlatformCreateTexture (void *data); -extern void rglPlatformDestroyTexture (void *data); -void rglPlatformValidateVertexTextures (void); -extern GLenum rglPlatformChooseInternalStorage (void *data, GLenum internalformat); -extern void rglPlatformCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); -void rglPlatformGetImageData( GLenum target, GLint level, rglTexture *texture, rglImage *image ); - -//---------------------------------------- -// Raster/.../PlatformFBops.c -//---------------------------------------- -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 ); - -//---------------------------------------- -// Raster/.../PlatformBuffer.c -//---------------------------------------- -int rglPlatformBufferObjectSize (void); -GLboolean rglPlatformCreateBufferObject( rglBufferObject* bufferObject ); -void rglPlatformDestroyBufferObject (void *data); -void rglPlatformBufferObjectSetData (void *buf_data, GLintptr offset, GLsizeiptr size, const GLvoid *data, GLboolean tryImmediateCopy ); -char *rglPlatformBufferObjectMap (void *data, GLenum access ); -GLboolean rglPlatformBufferObjectUnmap (void *data); -void rglPlatformGetBufferParameteriv( rglBufferObject *bufferObject, GLenum pname, int *params ); - -// this is shared in glBindTexture and cgGL code -RGL_EXPORT void rglBindTextureInternal (void *data, GLuint name, GLenum target); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ps3/gcmgl/include/export/GLES/gl.h b/ps3/gcmgl/include/export/GLES/gl.h deleted file mode 100644 index 0494d68df1..0000000000 --- a/ps3/gcmgl/include/export/GLES/gl.h +++ /dev/null @@ -1,547 +0,0 @@ -#ifndef __gl_h_ -#define __gl_h_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* - ** License Applicability. Except to the extent portions of this file are - ** made subject to an alternative license as permitted in the SGI Free - ** Software License B, Version 1.0 (the "License"), the contents of this - ** file are subject only to the provisions of the License. You may not use - ** this file except in compliance with the License. You may obtain a copy - ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 - ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: - ** - ** http://oss.sgi.com/projects/FreeB - ** - ** Note that, as provided in the License, the Software is distributed on an - ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS - ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND - ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A - ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - ** - ** Original Code. The Original Code is: OpenGL Sample Implementation, - ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, - ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. - ** Copyright in any portions created by third parties is as indicated - ** elsewhere herein. All Rights Reserved. - ** - ** Additional Notice Provisions: The application programming interfaces - ** established by SGI in conjunction with the Original Code are The - ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released - ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version - ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X - ** Window System(R) (Version 1.3), released October 19, 1998. This software - ** was created using the OpenGL(R) version 1.2.1 Sample Implementation - ** published by SGI, but has not been independently verified as being - ** compliant with the OpenGL(R) version 1.2.1 Specification. - */ - -#ifdef RGL_EXPORT -#define GLAPI RGL_EXPORT -#endif - -#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SYMBIAN32__) -#define WIN32_LEAN_AND_MEAN 1 -#include -#endif - - -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef GLAPI -#define GLAPI extern -#endif - - typedef unsigned int GLenum; - typedef unsigned char GLboolean; - typedef unsigned int GLbitfield; - typedef signed char GLbyte; - typedef short GLshort; - typedef int GLint; - typedef int GLsizei; - typedef unsigned char GLubyte; - typedef unsigned short GLushort; - typedef unsigned int GLuint; - typedef float GLfloat; - typedef float GLclampf; - typedef void GLvoid; - typedef int GLfixed; - typedef int GLclampx; - /* Internal convenience typedefs */ - typedef void( *_GLfuncptr )(); - - /*************************************************************/ - - /* Extensions */ -#define GL_OES_VERSION_1_0 1 -#define GL_OES_read_format 1 -#define GL_OES_compressed_paletted_texture 1 - - /* ClearBufferMask */ -#define GL_DEPTH_BUFFER_BIT 0x00000100 -#define GL_STENCIL_BUFFER_BIT 0x00000400 -#define GL_COLOR_BUFFER_BIT 0x00004000 - - /* Boolean */ -#define GL_FALSE 0 -#define GL_TRUE 1 - - /* BeginMode */ -#define GL_POINTS 0x0000 -#define GL_LINES 0x0001 -#define GL_LINE_LOOP 0x0002 -#define GL_LINE_STRIP 0x0003 -#define GL_TRIANGLES 0x0004 -#define GL_TRIANGLE_STRIP 0x0005 -#define GL_TRIANGLE_FAN 0x0006 - - /* AlphaFunction */ -#define GL_NEVER 0x0200 -#define GL_LESS 0x0201 -#define GL_EQUAL 0x0202 -#define GL_LEQUAL 0x0203 -#define GL_GREATER 0x0204 -#define GL_NOTEQUAL 0x0205 -#define GL_GEQUAL 0x0206 -#define GL_ALWAYS 0x0207 - - /* BlendingFactorDest */ -#define GL_ZERO 0 -#define GL_ONE 1 -#define GL_SRC_COLOR 0x0300 -#define GL_ONE_MINUS_SRC_COLOR 0x0301 -#define GL_SRC_ALPHA 0x0302 -#define GL_ONE_MINUS_SRC_ALPHA 0x0303 -#define GL_DST_ALPHA 0x0304 -#define GL_ONE_MINUS_DST_ALPHA 0x0305 - - /* BlendingFactorSrc */ - /* GL_ZERO */ - /* GL_ONE */ -#define GL_DST_COLOR 0x0306 -#define GL_ONE_MINUS_DST_COLOR 0x0307 -#define GL_SRC_ALPHA_SATURATE 0x0308 - /* GL_SRC_ALPHA */ - /* GL_ONE_MINUS_SRC_ALPHA */ - /* GL_DST_ALPHA */ - /* GL_ONE_MINUS_DST_ALPHA */ - - /* ColorMaterialFace */ - /* GL_FRONT_AND_BACK */ - - /* ColorMaterialParameter */ - /* GL_AMBIENT_AND_DIFFUSE */ - - /* ColorPointerType */ - /* GL_UNSIGNED_BYTE */ - /* GL_FLOAT */ - /* GL_FIXED */ - - /* CullFaceMode */ -#define GL_FRONT 0x0404 -#define GL_BACK 0x0405 -#define GL_FRONT_AND_BACK 0x0408 - - /* DepthFunction */ - /* GL_NEVER */ - /* GL_LESS */ - /* GL_EQUAL */ - /* GL_LEQUAL */ - /* GL_GREATER */ - /* GL_NOTEQUAL */ - /* GL_GEQUAL */ - /* GL_ALWAYS */ - - /* EnableCap */ -#define GL_FOG 0x0B60 -#define GL_LIGHTING 0x0B50 -#define GL_TEXTURE_2D 0x0DE1 -#define GL_CULL_FACE 0x0B44 -#define GL_BLEND 0x0BE2 -#define GL_COLOR_LOGIC_OP 0x0BF2 -#define GL_DITHER 0x0BD0 -#define GL_STENCIL_TEST 0x0B90 -#define GL_DEPTH_TEST 0x0B71 - /* GL_LIGHT0 */ - /* GL_LIGHT1 */ - /* GL_LIGHT2 */ - /* GL_LIGHT3 */ - /* GL_LIGHT4 */ - /* GL_LIGHT5 */ - /* GL_LIGHT6 */ - /* GL_LIGHT7 */ -#define GL_POINT_SMOOTH 0x0B10 -#define GL_LINE_SMOOTH 0x0B20 -#define GL_SCISSOR_TEST 0x0C11 -#define GL_COLOR_MATERIAL 0x0B57 -#define GL_NORMALIZE 0x0BA1 -#define GL_RESCALE_NORMAL 0x803A -#define GL_POLYGON_OFFSET_FILL 0x8037 -#define GL_VERTEX_ARRAY 0x8074 -#define GL_NORMAL_ARRAY 0x8075 -#define GL_COLOR_ARRAY 0x8076 -#define GL_TEXTURE_COORD_ARRAY 0x8078 -#define GL_MULTISAMPLE 0x809D -#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E -#define GL_SAMPLE_ALPHA_TO_ONE 0x809F -#define GL_SAMPLE_COVERAGE 0x80A0 - - /* ErrorCode */ -#define GL_NO_ERROR 0 -#define GL_INVALID_ENUM 0x0500 -#define GL_INVALID_VALUE 0x0501 -#define GL_INVALID_OPERATION 0x0502 -#define GL_STACK_OVERFLOW 0x0503 -#define GL_STACK_UNDERFLOW 0x0504 -#define GL_OUT_OF_MEMORY 0x0505 - - /* FogMode */ - /* GL_LINEAR */ -#define GL_EXP 0x0800 -#define GL_EXP2 0x0801 - - /* FogParameter */ -#define GL_FOG_DENSITY 0x0B62 -#define GL_FOG_START 0x0B63 -#define GL_FOG_END 0x0B64 -#define GL_FOG_MODE 0x0B65 -#define GL_FOG_COLOR 0x0B66 - - /* FrontFaceDirection */ -#define GL_CW 0x0900 -#define GL_CCW 0x0901 - - /* GetPName */ -#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 -#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 -#define GL_ALIASED_POINT_SIZE_RANGE 0x846D -#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E -#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A -#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B -#define GL_MAX_LIGHTS 0x0D31 -#define GL_MAX_TEXTURE_SIZE 0x0D33 -#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 -#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 -#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 -#define GL_MAX_VIEWPORT_DIMS 0x0D3A -#define GL_MAX_ELEMENTS_VERTICES 0x80E8 -#define GL_MAX_ELEMENTS_INDICES 0x80E9 -#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 -#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 -#define GL_SUBPIXEL_BITS 0x0D50 - - /* HintMode */ -#define GL_DONT_CARE 0x1100 -#define GL_FASTEST 0x1101 -#define GL_NICEST 0x1102 - - /* HintTarget */ -#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 -#define GL_POINT_SMOOTH_HINT 0x0C51 -#define GL_LINE_SMOOTH_HINT 0x0C52 -#define GL_POLYGON_SMOOTH_HINT 0x0C53 -#define GL_FOG_HINT 0x0C54 - - /* LightModelParameter */ -#define GL_LIGHT_MODEL_AMBIENT 0x0B53 -#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 - - /* LightParameter */ -#define GL_AMBIENT 0x1200 -#define GL_DIFFUSE 0x1201 -#define GL_SPECULAR 0x1202 -#define GL_POSITION 0x1203 -#define GL_SPOT_DIRECTION 0x1204 -#define GL_SPOT_EXPONENT 0x1205 -#define GL_SPOT_CUTOFF 0x1206 -#define GL_CONSTANT_ATTENUATION 0x1207 -#define GL_LINEAR_ATTENUATION 0x1208 -#define GL_QUADRATIC_ATTENUATION 0x1209 - - /* DataType */ -#define GL_BYTE 0x1400 -#define GL_UNSIGNED_BYTE 0x1401 -#define GL_SHORT 0x1402 -#define GL_UNSIGNED_SHORT 0x1403 -#define GL_FLOAT 0x1406 -#define GL_FIXED 0x140C - - /* LogicOp */ -#define GL_CLEAR 0x1500 -#define GL_AND 0x1501 -#define GL_AND_REVERSE 0x1502 -#define GL_COPY 0x1503 -#define GL_AND_INVERTED 0x1504 -#define GL_NOOP 0x1505 -#define GL_XOR 0x1506 -#define GL_OR 0x1507 -#define GL_NOR 0x1508 -#define GL_EQUIV 0x1509 -#define GL_INVERT 0x150A -#define GL_OR_REVERSE 0x150B -#define GL_COPY_INVERTED 0x150C -#define GL_OR_INVERTED 0x150D -#define GL_NAND 0x150E -#define GL_SET 0x150F - - /* MaterialFace */ - /* GL_FRONT_AND_BACK */ - - /* MaterialParameter */ -#define GL_EMISSION 0x1600 -#define GL_SHININESS 0x1601 -#define GL_AMBIENT_AND_DIFFUSE 0x1602 - /* GL_AMBIENT */ - /* GL_DIFFUSE */ - /* GL_SPECULAR */ - - /* MatrixMode */ -#define GL_MODELVIEW 0x1700 -#define GL_PROJECTION 0x1701 -#define GL_TEXTURE 0x1702 - - /* NormalPointerType */ - /* GL_BYTE */ - /* GL_SHORT */ - /* GL_FLOAT */ - /* GL_FIXED */ - - /* PixelFormat */ -#define GL_ALPHA 0x1906 -#define GL_RGB 0x1907 -#define GL_RGBA 0x1908 - - /* PixelStoreParameter */ -#define GL_UNPACK_ALIGNMENT 0x0CF5 -#define GL_PACK_ALIGNMENT 0x0D05 - - /* PixelType */ - /* GL_UNSIGNED_BYTE */ -#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 -#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 -#define GL_UNSIGNED_SHORT_5_6_5 0x8363 - - /* ShadingModel */ -#define GL_FLAT 0x1D00 -#define GL_SMOOTH 0x1D01 - - /* StencilFunction */ - /* GL_NEVER */ - /* GL_LESS */ - /* GL_EQUAL */ - /* GL_LEQUAL */ - /* GL_GREATER */ - /* GL_NOTEQUAL */ - /* GL_GEQUAL */ - /* GL_ALWAYS */ - - /* StencilOp */ - /* GL_ZERO */ -#define GL_KEEP 0x1E00 -#define GL_REPLACE 0x1E01 -#define GL_INCR 0x1E02 -#define GL_DECR 0x1E03 - /* GL_INVERT */ - - /* StringName */ -#define GL_VENDOR 0x1F00 -#define GL_RENDERER 0x1F01 -#define GL_VERSION 0x1F02 -#define GL_EXTENSIONS 0x1F03 - - /* TexCoordPointerType */ - /* GL_SHORT */ - /* GL_FLOAT */ - /* GL_FIXED */ - /* GL_BYTE */ - - /* TextureEnvMode */ -#define GL_MODULATE 0x2100 -#define GL_DECAL 0x2101 - /* GL_BLEND */ -#define GL_ADD 0x0104 - /* GL_REPLACE */ - - /* TextureEnvParameter */ -#define GL_TEXTURE_ENV_MODE 0x2200 -#define GL_TEXTURE_ENV_COLOR 0x2201 - - /* TextureEnvTarget */ -#define GL_TEXTURE_ENV 0x2300 - - /* TextureMagFilter */ -#define GL_NEAREST 0x2600 -#define GL_LINEAR 0x2601 - - /* TextureMinFilter */ - /* GL_NEAREST */ - /* GL_LINEAR */ -#define GL_NEAREST_MIPMAP_NEAREST 0x2700 -#define GL_LINEAR_MIPMAP_NEAREST 0x2701 -#define GL_NEAREST_MIPMAP_LINEAR 0x2702 -#define GL_LINEAR_MIPMAP_LINEAR 0x2703 - - /* TextureParameterName */ -#define GL_TEXTURE_MAG_FILTER 0x2800 -#define GL_TEXTURE_MIN_FILTER 0x2801 -#define GL_TEXTURE_WRAP_S 0x2802 -#define GL_TEXTURE_WRAP_T 0x2803 - - /* TextureTarget */ - /* GL_TEXTURE_2D */ - - /* TextureUnit */ -#define GL_TEXTURE0 0x84C0 -#define GL_TEXTURE1 0x84C1 -#define GL_TEXTURE2 0x84C2 -#define GL_TEXTURE3 0x84C3 -#define GL_TEXTURE4 0x84C4 -#define GL_TEXTURE5 0x84C5 -#define GL_TEXTURE6 0x84C6 -#define GL_TEXTURE7 0x84C7 -#define GL_TEXTURE8 0x84C8 -#define GL_TEXTURE9 0x84C9 -#define GL_TEXTURE10 0x84CA -#define GL_TEXTURE11 0x84CB -#define GL_TEXTURE12 0x84CC -#define GL_TEXTURE13 0x84CD -#define GL_TEXTURE14 0x84CE -#define GL_TEXTURE15 0x84CF -#define GL_TEXTURE16 0x84D0 -#define GL_TEXTURE17 0x84D1 -#define GL_TEXTURE18 0x84D2 -#define GL_TEXTURE19 0x84D3 -#define GL_TEXTURE20 0x84D4 -#define GL_TEXTURE21 0x84D5 -#define GL_TEXTURE22 0x84D6 -#define GL_TEXTURE23 0x84D7 -#define GL_TEXTURE24 0x84D8 -#define GL_TEXTURE25 0x84D9 -#define GL_TEXTURE26 0x84DA -#define GL_TEXTURE27 0x84DB -#define GL_TEXTURE28 0x84DC -#define GL_TEXTURE29 0x84DD -#define GL_TEXTURE30 0x84DE -#define GL_TEXTURE31 0x84DF - - /* TextureWrapMode */ -#define GL_REPEAT 0x2901 -#define GL_CLAMP_TO_EDGE 0x812F - - /* PixelInternalFormat */ -#define GL_PALETTE4_RGB8_OES 0x8B90 -#define GL_PALETTE4_RGBA8_OES 0x8B91 -#define GL_PALETTE4_R5_G6_B5_OES 0x8B92 -#define GL_PALETTE4_RGBA4_OES 0x8B93 -#define GL_PALETTE4_RGB5_A1_OES 0x8B94 -#define GL_PALETTE8_RGB8_OES 0x8B95 -#define GL_PALETTE8_RGBA8_OES 0x8B96 -#define GL_PALETTE8_R5_G6_B5_OES 0x8B97 -#define GL_PALETTE8_RGBA4_OES 0x8B98 -#define GL_PALETTE8_RGB5_A1_OES 0x8B99 - - /* VertexPointerType */ - /* GL_SHORT */ - /* GL_FLOAT */ - /* GL_FIXED */ - /* GL_BYTE */ - - /* LightName */ -#define GL_LIGHT0 0x4000 -#define GL_LIGHT1 0x4001 -#define GL_LIGHT2 0x4002 -#define GL_LIGHT3 0x4003 -#define GL_LIGHT4 0x4004 -#define GL_LIGHT5 0x4005 -#define GL_LIGHT6 0x4006 -#define GL_LIGHT7 0x4007 - - - /*************************************************************/ - - GLAPI void APIENTRY glActiveTexture( GLenum texture ); - GLAPI void APIENTRY glAlphaFunc( GLenum func, GLclampf ref ); - GLAPI void APIENTRY glAlphaFuncx( GLenum func, GLclampx ref ); - GLAPI void APIENTRY glBindTexture( GLenum target, GLuint texture ); - GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ); - GLAPI void APIENTRY glClear( GLbitfield mask ); - GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); - GLAPI void APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha ); - GLAPI void APIENTRY glClearDepthf( GLclampf depth ); - GLAPI void APIENTRY glClearDepthx( GLclampx depth ); - GLAPI void APIENTRY glClearStencil( GLint s ); - GLAPI void APIENTRY glClientActiveTexture( GLenum texture ); - GLAPI void APIENTRY glColor4x( GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha ); - GLAPI void APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); - GLAPI void APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); - GLAPI void APIENTRY glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border ); - GLAPI void APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - GLAPI void APIENTRY glCullFace( GLenum mode ); - GLAPI void APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures ); - GLAPI void APIENTRY glDepthFunc( GLenum func ); - GLAPI void APIENTRY glDepthMask( GLboolean flag ); - GLAPI void APIENTRY glDepthRangef( GLclampf zNear, GLclampf zFar ); - GLAPI void APIENTRY glDepthRangex( GLclampx zNear, GLclampx zFar ); - GLAPI void APIENTRY glDisable( GLenum cap ); - GLAPI void APIENTRY glDisableClientState( GLenum array ); - GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ); - GLAPI void APIENTRY glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices ); - GLAPI void APIENTRY glEnable( GLenum cap ); - GLAPI void APIENTRY glEnableClientState( GLenum array ); - GLAPI void APIENTRY glFinish( void ); - GLAPI void APIENTRY glFlush( void ); - GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures ); - GLAPI GLenum APIENTRY glGetError( void ); - GLAPI void APIENTRY glGetIntegerv( GLenum pname, GLint *params ); - GLAPI const GLubyte * APIENTRY glGetString( GLenum name ); - GLAPI void APIENTRY glHint( GLenum target, GLenum mode ); - GLAPI void APIENTRY glLineWidth( GLfloat width ); - GLAPI void APIENTRY glLineWidthx( GLfixed width ); - GLAPI void APIENTRY glLoadIdentity( void ); - GLAPI void APIENTRY glLogicOp( GLenum opcode ); - GLAPI void APIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param ); - GLAPI void APIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params ); - GLAPI void APIENTRY glMaterialx( GLenum face, GLenum pname, GLfixed param ); - GLAPI void APIENTRY glMaterialxv( GLenum face, GLenum pname, const GLfixed *params ); - GLAPI void APIENTRY glMatrixMode( GLenum mode ); - GLAPI void APIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q ); - GLAPI void APIENTRY glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q ); - GLAPI void APIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz ); - GLAPI void APIENTRY glNormal3x( GLfixed nx, GLfixed ny, GLfixed nz ); - GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ); - GLAPI void APIENTRY glOrthox( GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar ); - GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ); - GLAPI void APIENTRY glPointSize( GLfloat size ); - GLAPI void APIENTRY glPointSizex( GLfixed size ); - GLAPI void APIENTRY glPolygonOffset( GLfloat factor, GLfloat units ); - GLAPI void APIENTRY glPolygonOffsetx( GLfixed factor, GLfixed units ); - GLAPI void APIENTRY glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels ); - GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); - GLAPI void APIENTRY glRotatex( GLfixed angle, GLfixed x, GLfixed y, GLfixed z ); - GLAPI void APIENTRY glSampleCoverage( GLclampf value, GLboolean invert ); - GLAPI void APIENTRY glSampleCoveragex( GLclampx value, GLboolean invert ); - GLAPI void APIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z ); - GLAPI void APIENTRY glScalex( GLfixed x, GLfixed y, GLfixed z ); - GLAPI void APIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height ); - GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); - GLAPI void APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param ); - GLAPI void APIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params ); - GLAPI void APIENTRY glTexEnvx( GLenum target, GLenum pname, GLfixed param ); - GLAPI void APIENTRY glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params ); - GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); - GLAPI void APIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param ); - GLAPI void APIENTRY glTexParameterx( GLenum target, GLenum pname, GLfixed param ); - GLAPI void APIENTRY glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels ); - GLAPI void APIENTRY glVertexPointer( GLint size, GLenum type, Glsizei stride, const GLvoid *pointer ); - GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height ); - -#ifdef __cplusplus -} -#endif - -#endif /* __gl_h_ */ diff --git a/ps3/gcmgl/include/export/GLES/glext.h b/ps3/gcmgl/include/export/GLES/glext.h deleted file mode 100644 index 4c26d108b3..0000000000 --- a/ps3/gcmgl/include/export/GLES/glext.h +++ /dev/null @@ -1,422 +0,0 @@ -#ifndef __gl_ext_h_ -#define __gl_ext_h_ - - -#ifndef _MSC_VER -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - - typedef intptr_t GLintptr; - typedef intptr_t GLsizeiptr; - typedef unsigned short GLhalfARB; - -#define GL_QUADS 0x0007 -#define GL_QUAD_STRIP 0x0008 - -#define GL_INT 0x1404 -#define GL_UNSIGNED_INT 0x1405 - - /* Image types */ -#define GL_UNSIGNED_BYTE_3_3_2 0x8032 -#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 -#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 -#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 -#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 -#define GL_UNSIGNED_INT_8_8_8_8 0x8035 -#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 -#define GL_UNSIGNED_INT_10_10_10_2 0x8036 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_UNSIGNED_INT_24_8_SCE 0x6008 -#define GL_UNSIGNED_INT_8_24_REV_SCE 0x6009 - -#define GL_HALF_FLOAT_ARB 0x140B - - /* Image internal formats */ -#define GL_ALPHA4 0x803B -#define GL_ALPHA12 0x803D -#define GL_ALPHA16 0x803E -#define GL_R3_G3_B2 0x2A10 -#define GL_RGB4 0x804F -#define GL_RGB5 0x8050 -#define GL_RGB8 0x8051 -#define GL_RGBA2 0x8055 -#define GL_RGBA4 0x8056 -#define GL_RGB5_A1 0x8057 -#define GL_RGBA12 0x805A -#define GL_RGBA16 0x805B -#define GL_BGR 0x80E0 -#define GL_BGRA 0x80E1 -#define GL_ABGR 0x8000 -#define GL_RED 0x1903 -#define GL_GREEN 0x1904 -#define GL_BLUE 0x1905 -#define GL_ARGB_SCE 0x6007 - -#define GL_RGBA32F_ARB 0x8814 -#define GL_RGB32F_ARB 0x8815 -#define GL_ALPHA32F_ARB 0x8816 -#define GL_RGBA16F_ARB 0x881A -#define GL_RGB16F_ARB 0x881B -#define GL_ALPHA16F_ARB 0x881C - -#define GL_UNSIGNED_SHORT_8_8_SCE 0x600B -#define GL_UNSIGNED_SHORT_8_8_REV_SCE 0x600C -#define GL_UNSIGNED_INT_16_16_SCE 0x600D -#define GL_UNSIGNED_INT_16_16_REV_SCE 0x600E - -#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 -#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 -#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 -#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 - - - /* TexGen */ -#define GL_EYE_LINEAR 0x2400 -#define GL_OBJECT_LINEAR 0x2401 -#define GL_SPHERE_MAP 0x2402 -#define GL_NORMAL_MAP 0x8511 -#define GL_REFLECTION_MAP 0x8512 -#define GL_S 0x2000 -#define GL_T 0x2001 -#define GL_R 0x2002 -#define GL_Q 0x2003 -#define GL_OBJECT_PLANE 0x2501 -#define GL_EYE_PLANE 0x2502 -#define GL_TEXTURE_GEN_MODE 0x2500 -#define GL_TEXTURE_GEN_S 0x0C60 -#define GL_TEXTURE_GEN_T 0x0C61 -#define GL_TEXTURE_GEN_R 0x0C62 -#define GL_TEXTURE_GEN_Q 0x0C63 - - /* Blending */ -#define GL_CONSTANT_COLOR 0x8001 -#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 -#define GL_CONSTANT_ALPHA 0x8003 -#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 -#define GL_BLEND_EQUATION 0x8009 -#define GL_FUNC_ADD 0x8006 -#define GL_MIN 0x8007 -#define GL_MAX 0x8008 -#define GL_FUNC_SUBTRACT 0x800A -#define GL_FUNC_REVERSE_SUBTRACT 0x800B - - /* Texture3D */ -#define GL_TEXTURE_3D 0x806F -#define GL_TEXTURE_WRAP_R 0x8072 -#define GL_MAX_3D_TEXTURE_SIZE 0x8073 - - /* CubeMap */ -#define GL_TEXTURE_CUBE_MAP 0x8513 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 -#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 -#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A - - /* PolygonMode */ -#define GL_POINT 0x1B00 -#define GL_LINE 0x1B01 -#define GL_FILL 0x1B02 - - /* PolygonOffset for GL_LINE */ -#define GL_POLYGON_OFFSET_LINE 0x2A02 - - /* Filter Control */ -#define GL_TEXTURE_FILTER_CONTROL 0x8500 -#define GL_TEXTURE_LOD_BIAS 0x8501 -#define GL_TEXTURE_MIN_LOD 0x813A -#define GL_TEXTURE_MAX_LOD 0x813B -#define GL_TEXTURE_MAX_LEVEL 0x813D -#define GL_TEXTURE_BORDER_COLOR 0x1004 - - /* depth/shadow */ -#define GL_NONE 0x0 -#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B -#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C -#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D -#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E - - /* Wrap modes */ -#define GL_CLAMP 0x2900 -#define GL_MIRRORED_REPEAT 0x8370 -#define GL_MIRROR_CLAMP_EXT 0x8742 -#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 -#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 -#define GL_CLAMP_TO_BORDER 0x812D - - /* Fog Coordinate Source */ -#define GL_FOG_COORDINATE_SOURCE 0x8450 -#define GL_FOG_COORDINATE 0x8451 -#define GL_FRAGMENT_DEPTH 0x8452 - - /* Fragment Control TXP */ -#define GL_FRAGMENT_PROGRAM_CONTROL_CONTROLTXP_SCE 0x8453 - - /* Gets */ -#define GL_MODELVIEW_MATRIX 0x0BA6 -#define GL_TEXTURE_MATRIX 0x0BA8 -#define GL_PROJECTION_MATRIX 0x0BA7 -#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 - - - /* Surface targets */ -#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 -#define GL_DRAW_BUFFER0_ATI 0x8825 -#define GL_DRAW_BUFFER1_ATI 0x8826 -#define GL_DRAW_BUFFER2_ATI 0x8827 -#define GL_DRAW_BUFFER3_ATI 0x8828 -#define GL_DRAW_BUFFER4_ATI 0x8829 -#define GL_DRAW_BUFFER5_ATI 0x882A -#define GL_DRAW_BUFFER6_ATI 0x882B -#define GL_DRAW_BUFFER7_ATI 0x882C -#define GL_DRAW_BUFFER8_ATI 0x882D -#define GL_DRAW_BUFFER9_ATI 0x882E -#define GL_DRAW_BUFFER10_ATI 0x882F -#define GL_DRAW_BUFFER11_ATI 0x8830 -#define GL_DRAW_BUFFER12_ATI 0x8831 -#define GL_DRAW_BUFFER13_ATI 0x8832 -#define GL_DRAW_BUFFER14_ATI 0x8833 -#define GL_DRAW_BUFFER15_ATI 0x8834 -#define GL_DRAW_DEPTH_SCE 0x6004 -#define GL_DRAW_STENCIL_SCE 0x6005 - - -#define GL_RGBA8 0x8058 -#define GL_FLOAT_DEPTH_COMPONENT16_SCE 0x6000 -#define GL_FLOAT_DEPTH_COMPONENT32_SCE 0x6001 -#define GL_DEPTH24_STENCIL8_SCE 0x6002 -#define GL_STENCIL8_SCE 0x6003 -#define GL_DEPTH_COMPONENT 0x1902 -#define GL_DEPTH_COMPONENT16 0x81A5 -#define GL_DEPTH_COMPONENT24 0x81A6 -#define GL_DEPTH_COMPONENT32 0x81A7 -#define GL_STENCIL_INDEX 0x1901 - -#define GL_DRAWABLE_BIT_SCE 0x0001 -#define GL_ALLOW_SCAN_OUT_BIT_SCE 0x0002 -#define GL_TEXTURE_READ_BIT_SCE 0x0004 -#define GL_ANTIALIASED_BIT_SCE 0x0008 - - /* VBO & PBO */ -#define GL_ARRAY_BUFFER 0x8892 -#define GL_ELEMENT_ARRAY_BUFFER 0x8893 -#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB -#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC -#define GL_STREAM_DRAW 0x88E0 -#define GL_STREAM_READ 0x88E1 -#define GL_STREAM_COPY 0x88E2 -#define GL_STATIC_DRAW 0x88E4 -#define GL_STATIC_READ 0x88E5 -#define GL_STATIC_COPY 0x88E6 -#define GL_DYNAMIC_DRAW 0x88E8 -#define GL_DYNAMIC_READ 0x88E9 -#define GL_DYNAMIC_COPY 0x88EA -#define GL_SYSTEM_DRAW 0x6020 - - /* Map/Unmap */ -#define GL_READ_ONLY 0x88B8 -#define GL_WRITE_ONLY 0x88B9 -#define GL_READ_WRITE 0x88BA - - /* VSYNC */ -#define GL_VSYNC_SCE 0x6006 - -#define GL_TEXTURE_GAMMA_REMAP_R_SCE 0x6010 -#define GL_TEXTURE_GAMMA_REMAP_G_SCE 0x6011 -#define GL_TEXTURE_GAMMA_REMAP_B_SCE 0x6012 -#define GL_TEXTURE_GAMMA_REMAP_A_SCE 0x6013 - -#define GL_SHADER_SRGB_REMAP_SCE 0x6014 - -#define GL_DIVIDE_SCE 0x6015 -#define GL_MODULO_SCE 0x6016 - -#define GL_TEXTURE_FROM_VERTEX_PROGRAM_SCE 0x6017 - - /* Primitive restart */ -#define GL_PRIMITIVE_RESTART_NV 0x8558 - - /* Anisotropic filtering */ -#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE -#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF - - /* Sync */ -#define GL_ALL_COMPLETED_NV 0x84F2 -#define GL_FENCE_STATUS_NV 0x84F3 -#define GL_FENCE_CONDITION_NV 0x84F4 - - /* User clip planes */ -#define GL_MAX_CLIP_PLANES 0x0D32 -#define GL_CLIP_PLANE0 0x3000 -#define GL_CLIP_PLANE1 0x3001 -#define GL_CLIP_PLANE2 0x3002 -#define GL_CLIP_PLANE3 0x3003 -#define GL_CLIP_PLANE4 0x3004 -#define GL_CLIP_PLANE5 0x3005 - - /* Point Sprites */ -#define GL_POINT_SPRITE_OES 0x8861 -#define GL_COORD_REPLACE_OES 0x8862 -#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 - - /* Framebuffer object */ -#define GL_INVALID_FRAMEBUFFER_OPERATION_OES 0x0506 -#define GL_MAX_RENDERBUFFER_SIZE_OES 0x84E8 -#define GL_FRAMEBUFFER_BINDING_OES 0x8CA6 -#define GL_RENDERBUFFER_BINDING_OES 0x8CA7 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES 0x8CD0 -#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES 0x8CD1 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES 0x8CD2 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_OES 0x8CD3 -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 -#define GL_FRAMEBUFFER_COMPLETE_OES 0x8CD5 -#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES 0x8CD6 -#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES 0x8CD7 -#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_OES 0x8CD8 -#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES 0x8CD9 -#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES 0x8CDA -#define GL_FRAMEBUFFER_UNSUPPORTED_OES 0x8CDD -#define GL_MAX_COLOR_ATTACHMENTS_OES 0x8CDF -#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 -#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 -#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 -#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 -#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 -#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 -#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 -#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 -#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 -#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 -#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA -#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB -#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC -#define GL_COLOR_ATTACHMENT13_EXT 0x8CED -#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE -#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF -#define GL_DEPTH_ATTACHMENT_OES 0x8D00 -#define GL_STENCIL_ATTACHMENT_OES 0x8D20 -#define GL_FRAMEBUFFER_OES 0x8D40 -#define GL_RENDERBUFFER_OES 0x8D41 -#define GL_RENDERBUFFER_WIDTH_OES 0x8D42 -#define GL_RENDERBUFFER_HEIGHT_OES 0x8D43 -#define GL_RENDERBUFFER_INTERNAL_FORMAT_OES 0x8D44 -#define GL_STENCIL_INDEX_OES 0x8D45 -#define GL_STENCIL_INDEX4_OES 0x8D47 -#define GL_STENCIL_INDEX8_OES 0x8D48 - - /* multiple render target blend enable enums */ -#define GL_BLEND_MRT0_SCE GL_COLOR_ATTACHMENT0_EXT -#define GL_BLEND_MRT1_SCE GL_COLOR_ATTACHMENT1_EXT -#define GL_BLEND_MRT2_SCE GL_COLOR_ATTACHMENT2_EXT -#define GL_BLEND_MRT3_SCE GL_COLOR_ATTACHMENT3_EXT - - /* Texture usage hint */ -#define GL_TEXTURE_ALLOCATION_HINT_SCE 0x6018 -#define GL_TEXTURE_TILED_GPU_SCE 0x6019 -#define GL_TEXTURE_LINEAR_GPU_SCE 0x601A -#define GL_TEXTURE_SWIZZLED_GPU_SCE 0x601B -#define GL_TEXTURE_LINEAR_SYSTEM_SCE 0x601C -#define GL_TEXTURE_SWIZZLED_SYSTEM_SCE 0x601D - - /* Occlusion query & Conditional rendering */ -#define GL_SAMPLES_PASSED_ARB 0x8914 -#define GL_QUERY_COUNTER_BITS_ARB 0x8864 -#define GL_CURRENT_QUERY_ARB 0x8865 -#define GL_QUERY_RESULT_ARB 0x8866 -#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 - - /* Two-sided stencil, Stencil wrap */ -#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 -#define GL_INCR_WRAP 0x8507 -#define GL_DECR_WRAP 0x8508 - - /* depth clamp */ -#define GL_DEPTH_CLAMP_NV 0x864F - - /* 32-bit 3-component attributes (11/11/10) */ -#define GL_FIXED_11_11_10_SCE 0x6020 - - /* Anti-aliasing */ -#define GL_REDUCE_DST_COLOR_SCE 0x6021 -#define GL_TEXTURE_MULTISAMPLING_HINT_SCE 0x6022 -#define GL_FRAMEBUFFER_MULTISAMPLING_MODE_SCE 0x6023 - -#define GL_MULTISAMPLING_NONE_SCE 0x6030 -#define GL_MULTISAMPLING_2X_DIAGONAL_CENTERED_SCE 0x6031 -#define GL_MULTISAMPLING_4X_SQUARE_CENTERED_SCE 0x6032 -#define GL_MULTISAMPLING_4X_SQUARE_ROTATED_SCE 0x6033 - - /* Texture reference buffer */ -#define GL_TEXTURE_REFERENCE_BUFFER_SCE 0x6040 -#define GL_BUFFER_SIZE 0x8764 -#define GL_BUFFER_PITCH_SCE 0x6041 - - /******************************************************************************/ - GLAPI void APIENTRY glBlendEquation( GLenum mode ); - GLAPI void APIENTRY glBlendEquationSeparate( GLenum modeRGB, GLenum modeAlpha ); - GLAPI void APIENTRY glBlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha ); - GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); - GLAPI void APIENTRY glNormal3fv( const GLfloat* v ); - GLAPI void APIENTRY glGetBooleanv( GLenum pname, GLboolean* params ); - GLAPI void APIENTRY glGetFloatv( GLenum pname, GLfloat* params ); - GLAPI void APIENTRY glTexParameterfv( GLenum target, GLenum pname, const GLfloat* params ); - GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ); - GLAPI void APIENTRY glTexParameteriv( GLenum target, GLenum pname, const GLint* params ); - GLAPI void APIENTRY glTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels ); - - /* VBO & PBO */ - GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name ); - GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers ); - GLAPI void APIENTRY glGenBuffers( GLsizei n, GLuint *buffers ); - GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage ); - GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data ); - GLAPI void APIENTRY glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params ); - /* VBO & PBO map/unmap */ - GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access ); - GLAPI GLboolean APIENTRY glUnmapBuffer( GLenum target ); - - /* Sync */ - GLAPI void APIENTRY glDeleteFencesNV( GLsizei n, const GLuint *fences ); - GLAPI void APIENTRY glGenFencesNV( GLsizei n, GLuint *fences ); - GLAPI GLboolean APIENTRY glIsFenceNV( GLuint fence ); - GLAPI GLboolean APIENTRY glTestFenceNV( GLuint fence ); - GLAPI void APIENTRY glGetFenceivNV( GLuint fence, GLenum pname, GLint *params ); - GLAPI void APIENTRY glFinishFenceNV( GLuint fence ); - GLAPI void APIENTRY glSetFenceNV( GLuint fence, GLenum condition ); - - /* Framebuffer object */ - GLAPI GLboolean APIENTRY glIsRenderbufferOES( GLuint ); - GLAPI void APIENTRY glBindRenderbufferOES( GLenum, GLuint ); - GLAPI void APIENTRY glDeleteRenderbuffersOES( GLsizei, const GLuint * ); - GLAPI void APIENTRY glGenRenderbuffersOES( GLsizei, GLuint * ); - GLAPI void APIENTRY glRenderbufferStorageOES( GLenum, GLenum, GLsizei, GLsizei ); - GLAPI void APIENTRY glGetRenderbufferParameterivOES( GLenum, GLenum, GLint * ); - GLAPI GLboolean APIENTRY glIsFramebufferOES( GLuint ); - GLAPI void APIENTRY glBindFramebufferOES( GLenum, GLuint ); - GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei, const GLuint * ); - GLAPI void APIENTRY glGenFramebuffersOES( GLsizei, GLuint * ); - GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum ); - GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum, GLenum, GLenum, GLuint, GLint ); - GLAPI void APIENTRY glFramebufferRenderbufferOES( GLenum, GLenum, GLenum, GLuint ); - GLAPI void APIENTRY glGetFramebufferAttachmentParameterivOES( GLenum, GLenum, GLenum, GLint * ); - GLAPI void APIENTRY glGenerateMipmapOES( GLenum ); - GLAPI void APIENTRY glGenerateMipmap( GLenum target); - - /* Texture Reference */ - GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset ); - GLAPI GLvoid* APIENTRY glMapBufferTextureReferenceRA( GLenum target, GLenum access ); - GLAPI GLboolean APIENTRY glUnmapBufferTextureReferenceRA( GLenum target ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ps3/gcmgl/include/export/PSGL/export.h b/ps3/gcmgl/include/export/PSGL/export.h deleted file mode 100644 index 3f52f58954..0000000000 --- a/ps3/gcmgl/include/export/PSGL/export.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _RGL_EXPORT_DEFINE_H -#define _RGL_EXPORT_DEFINE_H - -#define PSGL_EXPORT -#define RGL_EXPORT - -#endif diff --git a/ps3/gcmgl/include/export/PSGL/psgl.h b/ps3/gcmgl/include/export/PSGL/psgl.h deleted file mode 100644 index 62927bdeac..0000000000 --- a/ps3/gcmgl/include/export/PSGL/psgl.h +++ /dev/null @@ -1,320 +0,0 @@ -#ifndef _RGL_EXPORT_H -#define _RGL_EXPORT_H - -#include -#include "export.h" -#include -#include -#include -#include - -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct PSGLdevice PSGLdevice; -typedef struct PSGLcontext PSGLcontext; - -typedef enum PSGLtvStandard -{ - PSGL_TV_STANDARD_NONE, - PSGL_TV_STANDARD_NTSC_M, - PSGL_TV_STANDARD_NTSC_J, - PSGL_TV_STANDARD_PAL_M, - PSGL_TV_STANDARD_PAL_B, - PSGL_TV_STANDARD_PAL_D, - PSGL_TV_STANDARD_PAL_G, - PSGL_TV_STANDARD_PAL_H, - PSGL_TV_STANDARD_PAL_I, - PSGL_TV_STANDARD_PAL_N, - PSGL_TV_STANDARD_PAL_NC, - PSGL_TV_STANDARD_HD480I, - PSGL_TV_STANDARD_HD480P, - PSGL_TV_STANDARD_HD576I, - PSGL_TV_STANDARD_HD576P, - PSGL_TV_STANDARD_HD720P, - PSGL_TV_STANDARD_HD1080I, - PSGL_TV_STANDARD_HD1080P, - PSGL_TV_STANDARD_1280x720_ON_VESA_1280x768 = 128, - PSGL_TV_STANDARD_1280x720_ON_VESA_1280x1024, - PSGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200, -} PSGLtvStandard; - -#define RGL_TV_STANDARD_NONE (PSGL_TV_STANDARD_NONE) -#define RGL_TV_STANDARD_NTSC_M 1 -#define RGL_TV_STANDARD_NTSC_J 2 -#define RGL_TV_STANDARD_PAL_M 3 -#define RGL_TV_STANDARD_PAL_B 4 -#define RGL_TV_STANDARD_PAL_D 5 -#define RGL_TV_STANDARD_PAL_G 6 -#define RGL_TV_STANDARD_PAL_H 7 -#define RGL_TV_STANDARD_PAL_I 8 -#define RGL_TV_STANDARD_PAL_N 9 -#define RGL_TV_STANDARD_PAL_NC 10 -#define RGL_TV_STANDARD_HD480I 11 -#define RGL_TV_STANDARD_HD480P 12 -#define RGL_TV_STANDARD_HD576I 13 -#define RGL_TV_STANDARD_HD576P 14 -#define RGL_TV_STANDARD_HD720P 15 -#define RGL_TV_STANDARD_HD1080I 16 -#define RGL_TV_STANDARD_HD1080P 17 -#define RGL_TV_STANDARD_1280x720_ON_VESA_1280x768 128 -#define RGL_TV_STANDARD_1280x720_ON_VESA_1280x1024 129 -#define RGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200 130 - -typedef enum PSGLbufferingMode -{ - PSGL_BUFFERING_MODE_SINGLE = 1, - PSGL_BUFFERING_MODE_DOUBLE = 2, - PSGL_BUFFERING_MODE_TRIPLE = 3, -} PSGLbufferingMode; - -/* spoof as PSGL */ -#define RGL_BUFFERING_MODE_SINGLE (PSGL_BUFFERING_MODE_SINGLE) -#define RGL_BUFFERING_MODE_DOUBLE (PSGL_BUFFERING_MODE_DOUBLE) -#define RGL_BUFFERING_MODE_TRIPLE (PSGL_BUFFERING_MODE_TRIPLE) - -typedef enum PSGLdeviceConnector -{ - PSGL_DEVICE_CONNECTOR_NONE, - PSGL_DEVICE_CONNECTOR_VGA, - PSGL_DEVICE_CONNECTOR_DVI, - PSGL_DEVICE_CONNECTOR_HDMI, - PSGL_DEVICE_CONNECTOR_COMPOSITE, - PSGL_DEVICE_CONNECTOR_SVIDEO, - PSGL_DEVICE_CONNECTOR_COMPONENT, -} PSGLdeviceConnector; - -#define RGL_DEVICE_CONNECTOR_NONE (PSGL_DEVICE_CONNECTOR_NONE) -#define RGL_DEVICE_CONNECTOR_VGA 1 -#define RGL_DEVICE_CONNECTOR_DVI 2 -#define RGL_DEVICE_CONNECTOR_HDMI 3 -#define RGL_DEVICE_CONNECTOR_COMPOSITE 4 -#define RGL_DEVICE_CONNECTOR_SVIDEO 5 -#define RGL_DEVICE_CONNECTOR_COMPONENT 6 - -typedef enum RescRatioMode -{ - RESC_RATIO_MODE_FULLSCREEN, - RESC_RATIO_MODE_LETTERBOX, // default - RESC_RATIO_MODE_PANSCAN, -} RescRatioMode; - -typedef enum RescPalTemporalMode -{ - RESC_PAL_TEMPORAL_MODE_50_NONE, // default - no conversion - RESC_PAL_TEMPORAL_MODE_60_DROP, - RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE, - RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_30_DROP, - RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_DROP_FLEXIBLE, -} RescPalTemporalMode; - -typedef enum RescInterlaceMode -{ - RESC_INTERLACE_MODE_NORMAL_BILINEAR, - RESC_INTERLACE_MODE_INTERLACE_FILTER, -} RescInterlaceMode; - -#define PSGL_DEVICE_PARAMETERS_COLOR_FORMAT 0x0001 -#define PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT 0x0002 -#define PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE 0x0004 -#define PSGL_DEVICE_PARAMETERS_TV_STANDARD 0x0008 -#define PSGL_DEVICE_PARAMETERS_CONNECTOR 0x0010 -#define PSGL_DEVICE_PARAMETERS_BUFFERING_MODE 0x0020 -#define PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT 0x0040 -#define PSGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT 0x0080 -#define PSGL_DEVICE_PARAMETERS_RESC_RATIO_MODE 0x0100 -#define PSGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE 0x0200 -#define PSGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE 0x0400 -#define PSGL_DEVICE_PARAMETERS_RESC_ADJUST_ASPECT_RATIO 0x0800 - -/* spoof as PSGL */ - -#define RGL_DEVICE_PARAMETERS_COLOR_FORMAT 0x0001 -#define RGL_DEVICE_PARAMETERS_DEPTH_FORMAT 0x0002 -#define RGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE 0x0004 -#define RGL_DEVICE_PARAMETERS_TV_STANDARD 0x0008 -#define RGL_DEVICE_PARAMETERS_CONNECTOR 0x0010 -#define RGL_DEVICE_PARAMETERS_BUFFERING_MODE 0x0020 -#define RGL_DEVICE_PARAMETERS_WIDTH_HEIGHT 0x0040 -#define RGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT 0x0080 -#define RGL_DEVICE_PARAMETERS_RESC_RATIO_MODE 0x0100 -#define RGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE 0x0200 -#define RGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE 0x0400 -#define RGL_DEVICE_PARAMETERS_RESC_ADJUST_ASPECT_RATIO 0x0800 - -// mask for validation -#define PSGL_VALIDATE_NONE 0x00000000 -#define PSGL_VALIDATE_FRAMEBUFFER 0x00000001 -#define PSGL_VALIDATE_TEXTURES_USED 0x00000002 -#define PSGL_VALIDATE_VERTEX_PROGRAM 0x00000004 -#define PSGL_VALIDATE_VERTEX_CONSTANTS 0x00000008 -#define PSGL_VALIDATE_VERTEX_TEXTURES_USED 0x00000010 -#define PSGL_VALIDATE_FFX_VERTEX_PROGRAM 0x00000020 -#define PSGL_VALIDATE_FRAGMENT_PROGRAM 0x00000040 -#define PSGL_VALIDATE_FFX_FRAGMENT_PROGRAM 0x00000080 -#define PSGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS 0x00000100 -#define PSGL_VALIDATE_VIEWPORT 0x00000200 -#define PSGL_VALIDATE_DEPTH_TEST 0x00000800 -#define PSGL_VALIDATE_WRITE_MASK 0x00001000 -#define PSGL_VALIDATE_STENCIL_TEST 0x00002000 -#define PSGL_VALIDATE_STENCIL_OP_AND_MASK 0x00004000 -#define PSGL_VALIDATE_SCISSOR_BOX 0x00008000 -#define PSGL_VALIDATE_FACE_CULL 0x00010000 -#define PSGL_VALIDATE_BLENDING 0x00020000 -#define PSGL_VALIDATE_POINT_RASTER 0x00040000 -#define PSGL_VALIDATE_LINE_RASTER 0x00080000 -#define PSGL_VALIDATE_POLYGON_OFFSET 0x00100000 -#define PSGL_VALIDATE_SHADE_MODEL 0x00200000 -#define PSGL_VALIDATE_LOGIC_OP 0x00400000 -#define PSGL_VALIDATE_MULTISAMPLING 0x00800000 -#define PSGL_VALIDATE_POLYGON_MODE 0x01000000 -#define PSGL_VALIDATE_PRIMITIVE_RESTART 0x02000000 -#define PSGL_VALIDATE_CLIP_PLANES 0x04000000 -#define PSGL_VALIDATE_SHADER_SRGB_REMAP 0x08000000 -#define PSGL_VALIDATE_POINT_SPRITE 0x10000000 -#define PSGL_VALIDATE_TWO_SIDE_COLOR 0x20000000 -#define PSGL_VALIDATE_ALL 0x3FFFFFFF - -/* spoof as PSGL */ -#define RGL_VALIDATE_NONE 0x00000000 -#define RGL_VALIDATE_FRAMEBUFFER 0x00000001 -#define RGL_VALIDATE_TEXTURES_USED 0x00000002 -#define RGL_VALIDATE_VERTEX_PROGRAM 0x00000004 -#define RGL_VALIDATE_VERTEX_CONSTANTS 0x00000008 -#define RGL_VALIDATE_VERTEX_TEXTURES_USED 0x00000010 -#define RGL_VALIDATE_FFX_VERTEX_PROGRAM 0x00000020 -#define RGL_VALIDATE_FRAGMENT_PROGRAM 0x00000040 -#define RGL_VALIDATE_FFX_FRAGMENT_PROGRAM 0x00000080 -#define RGL_VALIDATE_FRAGMENT_SHARED_CONSTANTS 0x00000100 -#define RGL_VALIDATE_VIEWPORT 0x00000200 -#define RGL_VALIDATE_DEPTH_TEST 0x00000800 -#define RGL_VALIDATE_WRITE_MASK 0x00001000 -#define RGL_VALIDATE_STENCIL_TEST 0x00002000 -#define RGL_VALIDATE_STENCIL_OP_AND_MASK 0x00004000 -#define RGL_VALIDATE_SCISSOR_BOX 0x00008000 -#define RGL_VALIDATE_FACE_CULL 0x00010000 -#define RGL_VALIDATE_BLENDING 0x00020000 -#define RGL_VALIDATE_POINT_RASTER 0x00040000 -#define RGL_VALIDATE_LINE_RASTER 0x00080000 -#define RGL_VALIDATE_POLYGON_OFFSET 0x00100000 -#define RGL_VALIDATE_SHADE_MODEL 0x00200000 -#define RGL_VALIDATE_LOGIC_OP 0x00400000 -#define RGL_VALIDATE_MULTISAMPLING 0x00800000 -#define RGL_VALIDATE_POLYGON_MODE 0x01000000 -#define RGL_VALIDATE_PRIMITIVE_RESTART 0x02000000 -#define RGL_VALIDATE_CLIP_PLANES 0x04000000 -#define RGL_VALIDATE_SHADER_SRGB_REMAP 0x08000000 -#define RGL_VALIDATE_POINT_SPRITE 0x10000000 -#define RGL_VALIDATE_TWO_SIDE_COLOR 0x20000000 -#define RGL_VALIDATE_ALL 0x3FFFFFFF - -#define RGLdevice PSGLdevice -#define RGLdeviceParameters PSGLdeviceParameters -#define RGLcontext PSGLcontext - -typedef struct -{ - GLuint enable; - GLenum colorFormat; - GLenum depthFormat; - GLenum multisamplingMode; - PSGLtvStandard TVStandard; - PSGLdeviceConnector connector; - PSGLbufferingMode bufferingMode; - GLuint width; // dimensions of display device (scanout buffer) - GLuint height; - - // dimensions of render buffer. Only set explicitly if the render target buffer - // needs to be different size than display scanout buffer (resolution scaling required). - // These can only be set if PSGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT is set in the "enable" mask, - // otherwise, render buffer dimensions are set to device dimensions (width/height). - GLuint renderWidth; - GLuint renderHeight; - - RescRatioMode rescRatioMode; // RESC aspect ratio rescaling mode: full screen, letterbox, or pan & scan - RescPalTemporalMode rescPalTemporalMode; // RESC pal frame rate conversion mode: none, drop frame, interpolate - RescInterlaceMode rescInterlaceMode; // RESC interlace filter mode: normal bilinear or use the anti-flicker interlace filter - - // horizontal and vertical scaling to adjust for the difference in overscan rates for each SD/HD mode or TV - GLfloat horizontalScale; - GLfloat verticalScale; -} PSGLdeviceParameters; - - -#define PSGL_INIT_MAX_SPUS 0x0001 -#define PSGL_INIT_INITIALIZE_SPUS 0x0002 -#define PSGL_INIT_PERSISTENT_MEMORY_SIZE 0x0004 -#define PSGL_INIT_TRANSIENT_MEMORY_SIZE 0x0008 -#define PSGL_INIT_ERROR_CONSOLE 0x0010 -#define PSGL_INIT_FIFO_SIZE 0x0020 -#define PSGL_INIT_HOST_MEMORY_SIZE 0x0040 -#define PSGL_INIT_USE_PMQUERIES 0x0080 - - /* spoof as PSGL */ -#define RGL_INIT_MAX_SPUS 0x0001 -#define RGL_INIT_INITIALIZE_SPUS 0x0002 -#define RGL_INIT_PERSISTENT_MEMORY_SIZE 0x0004 -#define RGL_INIT_TRANSIENT_MEMORY_SIZE 0x0008 -#define RGL_INIT_ERROR_CONSOLE 0x0010 -#define RGL_INIT_FIFO_SIZE 0x0020 -#define RGL_INIT_HOST_MEMORY_SIZE 0x0040 -#define RGL_INIT_USE_PMQUERIES 0x0080 - -typedef struct PSGLinitOptions -{ - GLuint enable; // bitfield of options to set - GLuint maxSPUs; - GLboolean initializeSPUs; - GLuint persistentMemorySize; - GLuint transientMemorySize; - int errorConsole; - GLuint fifoSize; - GLuint hostMemorySize; -} PSGLinitOptions; - -#define RGLinitOptions PSGLinitOptions - -typedef void*( *PSGLmallocFunc )( size_t LSize ); // expected to return 16-byte aligned -typedef void*( *PSGLmemalignFunc )( size_t align, size_t LSize ); -typedef void*( *PSGLreallocFunc )( void* LBlock, size_t LSize ); -typedef void( *PSGLfreeFunc )( void* LBlock ); - -extern PSGL_EXPORT void psglInit (void *data); -extern PSGL_EXPORT void psglExit (void); - -PSGL_EXPORT PSGLdevice* psglCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode ); -PSGL_EXPORT PSGLdevice* psglCreateDeviceExtended( const void *data); -PSGL_EXPORT GLfloat psglGetDeviceAspectRatio( const PSGLdevice * device ); -PSGL_EXPORT void psglGetDeviceDimensions( const PSGLdevice * device, GLuint *width, GLuint *height ); -PSGL_EXPORT void psglGetRenderBufferDimensions( const PSGLdevice * device, GLuint *width, GLuint *height ); -PSGL_EXPORT void psglDestroyDevice (void *data); - -PSGL_EXPORT void psglMakeCurrent( PSGLcontext* context, PSGLdevice* device ); -PSGL_EXPORT PSGLcontext* psglCreateContext (void); -PSGL_EXPORT void psglDestroyContext (void *data); -PSGL_EXPORT void psglResetCurrentContext (void); -PSGL_EXPORT PSGLcontext* psglGetCurrentContext (void); -PSGL_EXPORT PSGLdevice* psglGetCurrentDevice (void); -PSGL_EXPORT void psglSwap (void); - -static inline PSGL_EXPORT void psglRescAdjustAspectRatio( const float horizontalScale, const float verticalScale ) -{ - cellRescAdjustAspectRatio( horizontalScale, verticalScale ); -} - -/* hw cursor error code */ -#define PSGL_HW_CURSOR_OK CELL_OK -#define PSGL_HW_CURSOR_ERROR_FAILURE CELL_GCM_ERROR_FAILURE -#define PSGL_HW_CURSOR_ERROR_INVALID_VALUE CELL_GCM_ERROR_INVALID_VALUE - -#ifdef __cplusplus -} -#endif - -#endif /* RGL_EXPORT_H */ diff --git a/ps3/gcmgl/src/cg/cgbdefs.hpp b/ps3/gcmgl/src/cg/cgbdefs.hpp deleted file mode 100644 index 7fb27a4021..0000000000 --- a/ps3/gcmgl/src/cg/cgbdefs.hpp +++ /dev/null @@ -1,262 +0,0 @@ -#ifndef _CGC_CGBIO_CGBDEFS_HPP -#define _CGC_CGBIO_CGBDEFS_HPP - -/////////////////////// -// ELF Header Constants - -// File type -#define ET_NONE 0 -#define ET_REL 1 -#define ET_EXEC 2 -#define ET_DYN 3 -#define ET_CORE 4 -#define ET_LOOS 0xFE00 -#define ET_HIOS 0xFEFF -#define ET_LOPROC 0xFF00 -#define ET_HIPROC 0xFFFF - -// Machine/Architecture -#define EM_NONE 0 // No machine -#define EM_RSX 0x528e // RSX - -// Machine/Architecture flags -#define EM_RSX_NONE 0 - -// Machine/Architecture ABI version -#define EI_ABIVERSION_RSX 1 - -// ELF File version -#define EV_NONE 0 -#define EV_CURRENT 1 - -// Identification index -#define EI_MAG0 0 -#define EI_MAG1 1 -#define EI_MAG2 2 -#define EI_MAG3 3 -#define EI_CLASS 4 -#define EI_DATA 5 -#define EI_VERSION 6 -#define EI_OSABI 7 -#define EI_ABIVERSION 8 -#define EI_PAD 9 -#define EI_NIDENT 16 - -// Magic number - -#ifndef ELFMAG0 -#define ELFMAG0 0x7F -#endif - -#define ELFMAG1 'E' -#define ELFMAG2 'L' -#define ELFMAG3 'F' - -// File class -#define ELFCLASSNONE 0 -#define ELFCLASS32 1 -#define ELFCLASS64 2 - -// Encoding -#define ELFDATANONE 0 -#define ELFDATA2LSB 1 -#define ELFDATA2MSB 2 - -// OS extensions -#define ELFOSABI_NONE 0 // No extensions or unspecified -#define ELFOSABI_HPUX 1 // Hewlett-Packard HP-UX -#define ELFOSABI_NETBSD 2 // NetBSD -#define ELFOSABI_LINUX 3 // Linux -#define ELFOSABI_SOLARIS 6 // Sun Solaris -#define ELFOSABI_AIX 7 // AIX -#define ELFOSABI_IRIX 8 // IRIX -#define ELFOSABI_FREEBSD 9 // FreeBSD -#define ELFOSABI_TRU64 10 // Compaq TRU64 UNIX -#define ELFOSABI_MODESTO 11 // Novell Modesto -#define ELFOSABI_OPENBSD 12 // Open BSD -#define ELFOSABI_CGRUNTIME 19 // Cg Run-Time - - - -///////////////////// -// Sections constants - -// Section indexes -#ifndef SHN_UNDEF -#define SHN_UNDEF 0 -#endif - -#ifndef SHN_LORESERVE -#define SHN_LORESERVE 0xFF00 -#endif - -#ifndef SHN_LOPROC -#define SHN_LOPROC 0xFF00 -#endif - -#ifndef SHN_HIPROC -#define SHN_HIPROC 0xFF1F -#endif - -#ifndef SHN_LOOS -#define SHN_LOOS 0xFF20 -#endif - -#ifndef SHN_HIOS -#define SHN_HIOS 0xFF3F -#endif - -#ifndef SHN_ABS -#define SHN_ABS 0xFFF1 -#endif - -#ifndef SHN_COMMON -#define SHN_COMMON 0xFFF2 -#endif - -#ifndef SHN_XINDEX -#define SHN_XINDEX 0xFFFF -#endif - -#ifndef SHN_HIRESERVE -#define SHN_HIRESERVE 0xFFFF -#endif - -// Section types -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_INIT_ARRAY 14 -#define SHT_FINI_ARRAY 15 -#define SHT_PREINIT_ARRAY 16 -#define SHT_GROUP 17 -#define SHT_SYMTAB_SHNDX 18 -#define SHT_LOOS 0x60000000 -#define SHT_HIOS 0x6fffffff -#define SHT_LOPROC 0x70000000 -#define SHT_RSX_PARAM 0x70000000 -#define SHT_RSX_SHADERTAB 0x70000001 -#define SHT_RSX_FXTAB 0x70000002 -#define SHT_RSX_ANNOTATE 0x70000003 -#define SHT_HIPROC 0x7FFFFFFF -#define SHT_LOUSER 0x80000000 -#define SHT_HIUSER 0xFFFFFFFF - -// Section flags -#ifndef SHF_WRITE -#define SHF_WRITE 0x1 -#endif - -#ifndef SHF_ALLOC -#define SHF_ALLOC 0x2 -#endif - -#ifndef SHF_EXECINSTR -#define SHF_EXECINSTR 0x4 -#endif - -#ifndef SHF_MERGE -#define SHF_MERGE 0x10 -#endif - -#ifndef SHF_STRINGS -#define SHF_STRINGS 0x20 -#endif - -#ifndef SHF_INFO_LINK -#define SHF_INFO_LINK 0x40 -#endif - -#ifndef SHF_LINK_ORDER -#define SHF_LINK_ORDER 0x80 -#endif - -#ifndef SHF_OS_NONCONFORMING -#define SHF_OS_NONCONFORMING 0x100 -#endif - -#define SHF_GROUP 0x200 -#define SHF_TLS 0x400 -#define SHF_MASKOS 0x0ff00000 - -#ifndef SHF_MASKPROC -#define SHF_MASKPROC 0xF0000000 -#endif - -// Section group flags -#define GRP_COMDAT 0x1 -#define GRP_MASKOS 0x0ff00000 -#define GRP_MASKPROC 0xf0000000 - -// Symbol binding -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 -#define STB_LOOS 10 -#define STB_HIOS 12 -#define STB_LOPROC 13 -#define STB_HIPROC 15 - -// Symbol types -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 -#define STT_COMMON 5 -#define STT_TLS 6 -#define STT_LOOS 10 -#define STT_HIOS 12 -#define STT_LOPROC 13 -#define STT_HIPROC 15 - -// Symbol visibility -#define STV_DEFAULT 0 -#define STV_INTERNAL 1 -#define STV_HIDDEN 2 -#define STV_PROTECTED 3 - -// Shader Function type (st_other field) -#define STO_RSX_SHADER 0 -#define STO_RSX_EFFECT 1 - -// Undefined name -#define STN_UNDEF 0 - -// Relocation types -#define R_RSX_NONE 0 -#define R_RSX_FLOAT4 1 - -/* Note header in a PT_NOTE section */ -struct Elf32_Note -{ - unsigned int n_namesz; /* Name size */ - unsigned int n_descsz; /* Content size */ - unsigned int n_type; /* Content type */ -}; - - -// Relocation entries - -// Dynamic structure -struct Elf32_Dyn -{ - signed int d_tag; - union - { - unsigned int d_val; - unsigned int d_ptr; - } d_un; -}; - - -#endif // CGC_CGBIO_CGBDEFS_HPP diff --git a/ps3/gcmgl/src/cg/cgbio.hpp b/ps3/gcmgl/src/cg/cgbio.hpp deleted file mode 100644 index 701b9c981e..0000000000 --- a/ps3/gcmgl/src/cg/cgbio.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* cgbio.hpp -- interface to the whole cg binary input/output library. - * - * This is the only header file, that an application need to include - * in order to manipulate both elf and nvidia original cg binary - * format. - */ - -#ifndef CGC_CGBIO_CGBIO_HPP -#define CGC_CGBIO_CGBIO_HPP - -#include "cgbdefs.hpp" - -#include - -namespace cgc -{ - namespace bio - { - enum CGBIO_ERROR - { - CGBIO_ERROR_NO_ERROR, - CGBIO_ERROR_LOADED, - CGBIO_ERROR_FILEIO, - CGBIO_ERROR_FORMAT, - CGBIO_ERROR_INDEX, - CGBIO_ERROR_MEMORY, - CGBIO_ERROR_RELOC, - CGBIO_ERROR_SYMBOL, - CGBIO_ERROR_UNKNOWN_TYPE - }; - - } // bio namespace -} // cgc namespace - -#include "nvbi.hpp" - -namespace cgc -{ - namespace bio - { - class bin_io - { - public: - static const bin_io* instance(); - static void delete_instance(); - - CGBIO_ERROR new_nvb_reader( nvb_reader** obj ) const; - - const char *error_string( CGBIO_ERROR error ) const; - - private: - bin_io(); - bin_io( const bin_io& ); - - static bin_io* instance_; - }; // bin_io - - } // bio namespace -} // cgc namespace - -#endif // CGC_CGBIO_CGBIO_HPP diff --git a/ps3/gcmgl/src/cg/cgbtypes.h b/ps3/gcmgl/src/cg/cgbtypes.h deleted file mode 100644 index 2394447bae..0000000000 --- a/ps3/gcmgl/src/cg/cgbtypes.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef CGBTYPES_HEADER -#define CGBTYPES_HEADER - -// parameter structure -typedef struct _Elf32_cgParameter -{ - uint32_t cgp_name; // index of name in strtab - uint32_t cgp_semantic; // index of semantic string in strtab - uint16_t cgp_default; // index of default data in const //Reduced to half - uint16_t cgp_reloc; // index of reloc indices in rel - uint16_t cgp_resource; // index of hardware resource assigned - uint16_t cgp_resource_index; // index of hardware resource assigned - unsigned char cgp_type; - uint16_t cgp_info; - unsigned char unused; -} Elf32_cgParameter; //20 bytes - -#define CGF_OUTPUTFROMH0 0x01 -#define CGF_DEPTHREPLACE 0x02 -#define CGF_PIXELKILL 0x04 - -#endif diff --git a/ps3/gcmgl/src/cg/cgbutils.hpp b/ps3/gcmgl/src/cg/cgbutils.hpp deleted file mode 100644 index f7b2c71023..0000000000 --- a/ps3/gcmgl/src/cg/cgbutils.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef CGC_CGBIO_CGBUTILS_HPP -#define CGC_CGBIO_CGBUTILS_HPP - -#include "cgbdefs.hpp" - -#define ELF32_ST_BIND(idx) ( idx >> 4 ) -#define ELF32_ST_TYPE(idx) ( idx & 0xf ) -#define ELF32_ST_INFO(b, t) (( b << 4 ) + ( t & 0xf )) -#define ELF32_ST_VISIBILITY(o) ( o & 0x3 ) - -namespace cgc -{ - namespace bio - { - typedef enum - { - CGBIODATANONE = ELFDATANONE, - CGBIODATALSB = ELFDATA2LSB, - CGBIODATAMSB = ELFDATA2MSB - } HOST_ENDIANNESS; // endianness - - inline HOST_ENDIANNESS host_endianness(void) - { - const int ii = 1; - const char* cp = (const char*) ⅈ - return ( cp[0] == 1 ) ? CGBIODATALSB : CGBIODATAMSB; - } - - template< typename T > inline T convert_endianness( const T value, unsigned char endianness ) - { - if ( host_endianness() == endianness ) - return value; - - if ( sizeof( T ) == 1 ) - return value; - - if ( sizeof( T ) == 2 ) - return ( ((value & 0x00FF) << 8) | ((value & 0xFF00) >> 8) ); - - if ( sizeof( T ) == 4 ) - return ( ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8) - | ((value & 0x00FF0000) >> 8) | ((value & 0xFF000000) >> 24) ); - - if ( sizeof( T ) == 8 ) - { - T result = value; - for ( int ii = 0; ii < 4; ++ii ) - { - char ch = *( (( char* ) &result) + ii ); - *( (( char* ) &result) + ii ) = *( (( char* ) &result) + (7 - ii) ); - *( (( char* ) &result) + (7 - ii) ) = ch; - } - return result; - } - - // exception - return value; - } - } // bio namespace -} // cgc namespace - - -#endif // CGC_CGBIO_CGBUTILS_HPP diff --git a/ps3/gcmgl/src/cg/cgnv2rt.h b/ps3/gcmgl/src/cg/cgnv2rt.h deleted file mode 100644 index 0b513926c8..0000000000 --- a/ps3/gcmgl/src/cg/cgnv2rt.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CGNV2RT_HEADER -#define CGNV2RT_HEADER - -#include -#include - -#define CNV2END(val) convert_endianness((val), elfEndianness) -#define ENDSWAP(val) convert_endianness((val), (host_endianness() == 1) ? 2 : 1) - -int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize, - std::vector &stringTable, std::vector &defaultValues); - -int convertNvToElfFreeBinaryShader(void *binaryShader); - -#endif diff --git a/ps3/gcmgl/src/cg/nvbi.hpp b/ps3/gcmgl/src/cg/nvbi.hpp deleted file mode 100644 index e37cadc0d1..0000000000 --- a/ps3/gcmgl/src/cg/nvbi.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef CGC_CGBIO_NVBI_HPP -#define CGC_CGBIO_NVBI_HPP - -#include "cgbdefs.hpp" - -#include -#include -#include - -#include -#include - -namespace cgc -{ - namespace bio - { - class nvb_reader - { - public: - virtual ~nvb_reader() {} - - virtual ptrdiff_t - reference() const = 0; - - virtual ptrdiff_t - release() const = 0; - - virtual CGBIO_ERROR - loadFromString( const char* source, size_t length ) = 0; - - virtual bool - is_loaded() const = 0; - - virtual unsigned char - endianness() const = 0; - - virtual CGprofile - profile() const = 0; - - virtual unsigned int - revision() const = 0; - - virtual unsigned int - size() const = 0; - - virtual unsigned int - number_of_params() const = 0; - - virtual unsigned int - ucode_size() const = 0; - - virtual const char* - ucode() const = 0; - - virtual const CgBinaryFragmentProgram* - fragment_program() const = 0; - - virtual const CgBinaryVertexProgram* - vertex_program() const = 0; - - virtual CGBIO_ERROR - get_param( unsigned int index, - CGtype& type, - CGresource& resource, - CGenum& variability, - int& resource_index, - const char** name, - std::vector& default_value, - std::vector& embedded_constants, - const char** semantic, - CGenum& direction, - int& paramno, - bool& is_referenced, - bool& is_shared ) const = 0; - - virtual CGBIO_ERROR get_param_name( unsigned int index, const char** name, bool& is_referenced) const = 0; - - }; // nvb_reader - } // bio namespace -} // cgc namespace - -#endif // CGC_CGBIO_NVBI_HPP diff --git a/ps3/gcmgl/src/cg/nvbiimpl.hpp b/ps3/gcmgl/src/cg/nvbiimpl.hpp deleted file mode 100644 index 4c36ed1ddf..0000000000 --- a/ps3/gcmgl/src/cg/nvbiimpl.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CGC_CGBIO_NVBIIMPL_HPP -#define CGC_CGBIO_NVBIIMPL_HPP - -#include - -#include -#include - -#include "cgbio.hpp" - -namespace cgc -{ - namespace bio - { - class nvb_reader_impl : public nvb_reader - { - public: - nvb_reader_impl(); - - virtual - ~nvb_reader_impl(); - - virtual ptrdiff_t - reference() const; - - virtual ptrdiff_t - release() const; - - virtual CGBIO_ERROR - loadFromString( const char* source, size_t length); - - virtual bool - is_loaded() const; - - virtual unsigned char - endianness() const; - - virtual CGprofile - profile() const; - - virtual unsigned int - revision() const; - - virtual unsigned int - size() const; - - virtual unsigned int - number_of_params() const; - - virtual unsigned int - ucode_size() const; - - virtual const char* - ucode() const; - - virtual const CgBinaryFragmentProgram* - fragment_program() const; - - virtual const CgBinaryVertexProgram* - vertex_program() const; - - virtual CGBIO_ERROR - get_param( unsigned int index, - CGtype& type, - CGresource& resource, - CGenum& variability, - int& resource_index, - const char ** name, - std::vector& default_value, - std::vector& embedded_constants, - const char ** semantic, - CGenum& direction, - int& paramno, - bool& is_referenced, - bool& is_shared ) const; - - virtual CGBIO_ERROR get_param_name( unsigned int index, const char ** name , bool& is_referenced) const; - - private: - mutable ptrdiff_t ref_count_; - int offset_; - bool loaded_; - bool owner_; - bool strStream_; - CgBinaryProgram header_; - unsigned char endianness_; - char* image_; - }; // nvb_reader_impl - - } // bio namespace -} // cgc namespace - -#endif // CGC_CGBIO_NVBIIMPL_HPP diff --git a/ps3/gcmgl/src/include/GmmAlloc.h b/ps3/gcmgl/src/include/GmmAlloc.h deleted file mode 100644 index 04093ab531..0000000000 --- a/ps3/gcmgl/src/include/GmmAlloc.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef _GMM_ALLOC_H_ -#define _GMM_ALLOC_H_ - -void gmmPrintState(); // print out all blocks and their current states - -#define GMM_ASSERT(cond) ((void)0) - -#define GMM_ERROR 0xFFFFFFFF -#define GMM_TILE_ALIGNMENT 0x10000 // 16K -#define GMM_ALIGNMENT 128 // non-tile is 128 byte -#define GMM_RSX_WAIT_INDEX 254 // label index -#define GMM_PPU_WAIT_INDEX 255 // label index -#define GMM_BLOCK_COUNT 512 // initial memory block pool -#define GMM_TILE_BLOCK_COUNT 16 // initial tile memory block pool - -#define GMM_NUM_FREE_BINS 22 -#define GMM_FREE_BIN_0 0x80 // 0x00 - 0x80 -#define GMM_FREE_BIN_1 0x100 // 0x80 - 0x100 -#define GMM_FREE_BIN_2 0x180 // ... -#define GMM_FREE_BIN_3 0x200 -#define GMM_FREE_BIN_4 0x280 -#define GMM_FREE_BIN_5 0x300 -#define GMM_FREE_BIN_6 0x380 -#define GMM_FREE_BIN_7 0x400 -#define GMM_FREE_BIN_8 0x800 -#define GMM_FREE_BIN_9 0x1000 -#define GMM_FREE_BIN_10 0x2000 -#define GMM_FREE_BIN_11 0x4000 -#define GMM_FREE_BIN_12 0x8000 -#define GMM_FREE_BIN_13 0x10000 -#define GMM_FREE_BIN_14 0x20000 -#define GMM_FREE_BIN_15 0x40000 -#define GMM_FREE_BIN_16 0x80000 -#define GMM_FREE_BIN_17 0x100000 -#define GMM_FREE_BIN_18 0x200000 -#define GMM_FREE_BIN_19 0x400000 -#define GMM_FREE_BIN_20 0x800000 -#define GMM_FREE_BIN_21 0x1000000 - -// data structure for the fixed allocater -typedef struct GmmFixedAllocData{ - char **ppBlockList[2]; // pre-allocated list of block descriptors - uint16_t **ppFreeBlockList[2]; - uint16_t *pBlocksUsed[2]; - uint16_t BlockListCount[2]; -}GmmFixedAllocData; - -// common shared block descriptor for tile and non-tile block -// "base class" for GmmBlock and GmmTileBlock -typedef struct GmmBaseBlock{ - - uint8_t isTile; - uint32_t address; - uint32_t size; -}GmmBaseBlock; - -typedef struct GmmBlock{ - GmmBaseBlock base; // inheritence - struct GmmBlock *pPrev; - struct GmmBlock *pNext; - - uint8_t isPinned; - - // these would only be valid if the block is in - // pending free list or free list - struct GmmBlock *pPrevFree; - struct GmmBlock *pNextFree; - - uint32_t fence; -}GmmBlock; - -typedef struct GmmTileBlock -{ - GmmBaseBlock base; // inheritence - struct GmmTileBlock *pPrev; - struct GmmTileBlock *pNext; - - uint32_t tileTag; - void *pData; -} GmmTileBlock; - -typedef struct GmmAllocator -{ - uint32_t memoryBase; - - uint32_t startAddress; - uint32_t size; - uint32_t freeAddress; - - GmmBlock *pHead; - GmmBlock *pTail; - GmmBlock *pSweepHead; - uint32_t freedSinceSweep; - - uint32_t tileStartAddress; - uint32_t tileSize; - - GmmTileBlock *pTileHead; - GmmTileBlock *pTileTail; - - GmmBlock *pPendingFreeHead; - GmmBlock *pPendingFreeTail; - - // Acceleration data structure for free blocks - GmmBlock *pFreeHead[GMM_NUM_FREE_BINS]; - GmmBlock *pFreeTail[GMM_NUM_FREE_BINS]; - - uint32_t totalSize; // == size + tileSize -} GmmAllocator; - -uint32_t gmmDestroy(void); -char *gmmIdToAddress(const uint32_t id); -uint32_t gmmFree (const uint32_t freeId); -uint32_t gmmAlloc(const uint32_t size); -uint32_t gmmAllocTiled(const uint32_t size); - -extern GmmAllocator *pGmmLocalAllocator; - -#define GMM_ADDRESS_TO_OFFSET(address) (address - pGmmLocalAllocator->memoryBase) - -#define gmmGetBlockSize(id) (((GmmBaseBlock*)id)->size) -#define gmmGetTileData(id) (((GmmTileBlock*)id)->pData) -#define gmmIdToOffset(id) (GMM_ADDRESS_TO_OFFSET(((GmmBaseBlock*)id)->address)) -#define gmmAllocFixedTileBlock() ((GmmTileBlock*)gmmAllocFixed(1)) -#define gmmFreeFixedTileBlock(data) (gmmFreeFixed(1, (GmmTileBlock*)data)) -#define gmmFreeFixedBlock(data) (gmmFreeFixed(0, (GmmBlock*)data)) -#define gmmAllocTileBlock(pAllocator, size, pBlock) ((pBlock == NULL) ? gmmCreateTileBlock(pAllocator, size) : pBlock) - -#define gmmSetTileAttrib(id, tag, data) \ - ((GmmTileBlock*)id)->tileTag = tag; \ - ((GmmTileBlock*)id)->pData = data; - -#define gmmPinId(id) \ - if (!((GmmBaseBlock*)id)->isTile) \ - ((GmmBlock *)id)->isPinned = 1; - -#define gmmUnpinId(id) \ - if (!((GmmBaseBlock*)id)->isTile) \ - ((GmmBlock *)id)->isPinned = 0; - -#endif diff --git a/ps3/gcmgl/src/include/rgl-gcm-cmds.h b/ps3/gcmgl/src/include/rgl-gcm-cmds.h deleted file mode 100644 index 32f34287ce..0000000000 --- a/ps3/gcmgl/src/include/rgl-gcm-cmds.h +++ /dev/null @@ -1,691 +0,0 @@ -#ifndef _GCM_CMDS_H -#define _GCM_CMDS_H - -#define gcm_emit_at(buffer, location, word) ((buffer)[(location)] = (word)) -#define gcm_emit_method_at(buffer, location, method, n) gcm_emit_at((buffer),(location), (method) |((n) << 18)) -#define gcm_finish_n_commands(buffer, n) (buffer) += n - -#define rglGcmSetTextureAddress(thisContext, index, wraps, wrapt, wrapr, unsignedRemap, zfunc, gamma) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TEXTURE_ADDRESS + 0x20 * ((index)), 1); \ - gcm_emit_at(thisContext->current, 1, (((wraps)) | ((0) << 4) | (((wrapt)) << 8) | (((unsignedRemap)) << 12) | (((wrapr)) << 16) | (((gamma)) << 20) |((0) << 24) | (((zfunc)) << 28))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetTextureFilter(thisContext, index, bias, min, mag, conv) \ -{ \ - bool continue_func = true; \ - if(thisContext->current + (2) > thisContext->end) \ - { \ - if((*thisContext->callback)(thisContext, (2)) != 0) \ - continue_func = false; \ - } \ - if (continue_func) \ - { \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_TEXTURE_FILTER + 0x20 * ((index))), 1); \ - gcm_emit_at(thisContext->current, 1, (((bias)) | (((conv)) << 13) | (((min)) << 16) | (((mag)) << 24) | ((0) << 28) | ((0) << 29) | ((0) << 30) | ((0) << 31))); \ - gcm_finish_n_commands(thisContext->current, 2); \ - } \ -} - -#define rglGcmSetReferenceCommandInline(thisContext, ref) \ -{ \ - bool continue_func = true; \ - if(thisContext->current + (2) > thisContext->end) \ - { \ - if((*thisContext->callback)(thisContext, (2)) != 0) \ - continue_func = false; \ - } \ - if (continue_func) \ - { \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV406E_SET_REFERENCE, 1); \ - gcm_emit_at(thisContext->current, 1, ref); \ - gcm_finish_n_commands(thisContext->current, 2); \ - } \ -} - -#define rglGcmSetTextureBorderColor(thisContext, index, color) \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_TEXTURE_BORDER_COLOR + 0x20 * ((index))), 1); \ - gcm_emit_at(thisContext->current, 1, color); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglDisableVertexAttribArrayNVInline(context, index) \ - RGLBIT_FALSE(context->attribs->EnabledMask, index); \ - RGLBIT_TRUE(context->attribs->DirtyMask, index); - -#define rglEnableVertexAttribArrayNVInline(context, index) \ - RGLBIT_TRUE(context->attribs->EnabledMask, index); \ - RGLBIT_TRUE(context->attribs->DirtyMask, index); - -#define rglGcmSetVertexData4f(thisContext, index, v) \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_VERTEX_DATA4F_M + (index) * 16), 4); \ - memcpy(&thisContext->current[1], v, sizeof(float)*4); \ - gcm_finish_n_commands(thisContext->current, 5); - -#define rglGcmSetJumpCommand(thisContext, offset) \ - gcm_emit_at(thisContext->current, 0, ((offset) | (0x20000000))); \ - gcm_finish_n_commands(thisContext->current, 1); - -#define rglGcmSetVertexDataArray(thisContext, index, frequency, stride, size, type, location, offset) \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_VERTEX_DATA_ARRAY_FORMAT + ((index)) * 4), 1); \ - gcm_emit_at(thisContext->current, 1, ((((frequency)) << 16) | (((stride)) << 8) | (((size)) << 4) | ((type)))); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_VERTEX_DATA_ARRAY_OFFSET + ((index)) * 4), 1); \ - gcm_emit_at(thisContext->current, 1, ((((location)) << 31) | (offset))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetInlineTransferPointer(thisContext, offset, count, pointer) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_OFFSET_DESTIN, 1); \ - gcm_emit_at(thisContext->current, 1, (offset & ~63)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_COLOR_FORMAT, 2); \ - gcm_emit_at(thisContext->current, 1, CELL_GCM_TRANSFER_SURFACE_FORMAT_Y32); \ - gcm_emit_at(thisContext->current, 2, ((0x1000) | ((0x1000) << 16))); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_POINT, 3); \ - gcm_emit_at(thisContext->current, 1, (((0) << 16) | ((offset & 63) >> 2))); \ - gcm_emit_at(thisContext->current, 2, (((1) << 16) | (count))); \ - gcm_emit_at(thisContext->current, 3, (((1) << 16) | (count))); \ - gcm_finish_n_commands(thisContext->current, 4); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_COLOR, ((count + 1) & ~1)); \ - gcm_finish_n_commands(thisContext->current, 1); \ - pointer = thisContext->current; \ - gcm_finish_n_commands(thisContext->current, ((count + 1) & ~1)); - -#define rglGcmSetWriteBackEndLabel(thisContext, index, value) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SEMAPHORE_OFFSET, 1); \ - gcm_emit_at(thisContext->current, 1, 0x10 * index); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_BACK_END_WRITE_SEMAPHORE_RELEASE, 1); \ - gcm_emit_at(thisContext->current, 1, ( value & 0xff00ff00) | ((value >> 16) & 0xff) | (((value >> 0 ) & 0xff) << 16)); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetWaitLabel(thisContext, index, value) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV406E_SEMAPHORE_OFFSET, 1); \ - gcm_emit_at(thisContext->current, 1, 0x10 * index); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV406E_SEMAPHORE_ACQUIRE, 1); \ - gcm_emit_at(thisContext->current, 1, value); \ - gcm_finish_n_commands(thisContext->current, 2); - - -#define rglGcmSetInvalidateVertexCache(thisContext) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_INVALIDATE_VERTEX_CACHE_FILE, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetClearSurface(thisContext, mask) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_CLEAR_SURFACE, 1); \ - gcm_emit_at(thisContext->current, 1, mask); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_NO_OPERATION, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetTextureControl(thisContext, index, enable, minlod, maxlod, maxaniso) \ - gcm_emit_at(thisContext->current, 0, (((1) << (18)) | (CELL_GCM_NV4097_SET_TEXTURE_CONTROL0 + 0x20 * ((index))))); \ - gcm_emit_at(thisContext->current, 1, ((((0) << 2) | ((maxaniso)) << 4) | (((maxlod)) << 7) | (((minlod)) << 19) | ((enable) << 31))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetTextureRemap(thisContext, index, remap) \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_TEXTURE_CONTROL1 + ((index)) * 32), 1); \ - gcm_emit_at(thisContext->current, 1, remap); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetTransferLocation(thisContext, location) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_CONTEXT_DMA_IMAGE_DESTIN, 1); \ - gcm_emit_at(thisContext->current, 1, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + location)); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmInlineTransfer(thisContext, dstOffset, srcAdr, sizeInWords, location) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_CONTEXT_DMA_IMAGE_DESTIN, 1); \ - gcm_emit_at(thisContext->current, 1, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + location)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - rglGcmSetInlineTransfer(thisContext, dstOffset, srcAdr, sizeInWords); - -#define rglGcmSetClearColor(thisContext, color) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_COLOR_CLEAR_VALUE, 1); \ - gcm_emit_at(thisContext->current, 1, color); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetTextureBorder(thisContext, index, texture, border) \ - gcm_emit_at(thisContext->current, 0, (((2) << (18)) | (CELL_GCM_NV4097_SET_TEXTURE_OFFSET + ((index)) * 32))); \ - gcm_emit_at(thisContext->current, 1, texture->offset); \ - gcm_emit_at(thisContext->current, 2, (texture->location + 1) | (texture->cubemap << 2) | (border << 3) | (texture->dimension << 4) | (texture->format << 8) | (texture->mipmap << 16)); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_at(thisContext->current, 0, (((1) << (18)) | (CELL_GCM_NV4097_SET_TEXTURE_IMAGE_RECT + ((index)) * 32))); \ - gcm_emit_at(thisContext->current, 1, texture->height | (texture->width << 16)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_at(thisContext->current, 0, (((1) << (18)) | (CELL_GCM_NV4097_SET_TEXTURE_CONTROL3 + ((index)) * 4))); \ - gcm_emit_at(thisContext->current, 1, texture->pitch | (texture->depth << 20)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_at(thisContext->current, 0, (((1) << (18)) | (CELL_GCM_NV4097_SET_TEXTURE_CONTROL1 + ((index)) * 32))); \ - gcm_emit_at(thisContext->current, 1, texture->remap); \ - gcm_finish_n_commands(thisContext->current, 2); - - -#define rglGcmSetBlendEnable(thisContext, enable) \ -{ \ - bool continue_func = true; \ - if(thisContext->current + (2) > thisContext->end) \ - { \ - if((*thisContext->callback)(thisContext, (2)) != 0) \ - continue_func = false; \ - } \ - if (continue_func) \ - { \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BLEND_ENABLE, 1); \ - gcm_emit_at(thisContext->current, 1, enable); \ - gcm_finish_n_commands(thisContext->current, 2); \ - } \ -} - -#define rglGcmSetBlendEnableMrt(thisContext, mrt1, mrt2, mrt3) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BLEND_ENABLE_MRT, 1); \ - gcm_emit_at(thisContext->current, 1, (((mrt1) << 1)|((mrt2) << 2)|((mrt3) << 3))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetBlendEquation(thisContext, color, alpha) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BLEND_EQUATION, 1); \ - gcm_emit_at(thisContext->current, 1, (((color)) | (((alpha)) << 16))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetBlendFunc(thisContext, sfcolor, dfcolor, sfalpha, dfalpha) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BLEND_FUNC_SFACTOR, 2); \ - gcm_emit_at(thisContext->current, 1, (((sfcolor)) | (((sfalpha)) << 16))); \ - gcm_emit_at(thisContext->current, 2, (((dfcolor)) | (((dfalpha)) << 16))); \ - gcm_finish_n_commands(thisContext->current, 3); - -#define rglGcmSetUserClipPlaneControl(thisContext, plane0, plane1, plane2, plane3, plane4, plane5) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_USER_CLIP_PLANE_CONTROL, 1); \ - gcm_emit_at(thisContext->current, 1, ((plane0) | ((plane1) << 4) | ((plane2) << 8) | ((plane3) << 12) | ((plane4) << 16) | ((plane5) << 20))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetInvalidateTextureCache(thisContext, value) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_INVALIDATE_L2, 1); \ - gcm_emit_at(thisContext->current, 1, value); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetViewport(thisContext, x, y, w, h, min, max, scale, offset) \ - CellGcmCast d0,d1; \ - d0.f = min; \ - d1.f = max; \ - CellGcmCast o[4],s[4]; \ - o[0].f = offset[0]; \ - o[1].f = offset[1]; \ - o[2].f = offset[2]; \ - o[3].f = offset[3]; \ - s[0].f = scale[0]; \ - s[1].f = scale[1]; \ - s[2].f = scale[2]; \ - s[3].f = scale[3]; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VIEWPORT_HORIZONTAL, 2); \ - gcm_emit_at(thisContext->current, 1, (((x)) | (((w)) << 16))); \ - gcm_emit_at(thisContext->current, 2, (((y)) | (((h)) << 16))); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_CLIP_MIN, 2); \ - gcm_emit_at(thisContext->current, 1, (d0.u)); \ - gcm_emit_at(thisContext->current, 2, (d1.u)); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VIEWPORT_OFFSET, 8); \ - gcm_emit_at(thisContext->current, 1, (o[0].u)); \ - gcm_emit_at(thisContext->current, 2, (o[1].u)); \ - gcm_emit_at(thisContext->current, 3, (o[2].u)); \ - gcm_emit_at(thisContext->current, 4, (o[3].u)); \ - gcm_emit_at(thisContext->current, 5, (s[0].u)); \ - gcm_emit_at(thisContext->current, 6, (s[1].u)); \ - gcm_emit_at(thisContext->current, 7, (s[2].u)); \ - gcm_emit_at(thisContext->current, 8, (s[3].u)); \ - gcm_finish_n_commands(thisContext->current, 9); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VIEWPORT_OFFSET, 8); \ - gcm_emit_at(thisContext->current, 1, (o[0].u)); \ - gcm_emit_at(thisContext->current, 2, (o[1].u)); \ - gcm_emit_at(thisContext->current, 3, (o[2].u)); \ - gcm_emit_at(thisContext->current, 4, (o[3].u)); \ - gcm_emit_at(thisContext->current, 5, (s[0].u)); \ - gcm_emit_at(thisContext->current, 6, (s[1].u)); \ - gcm_emit_at(thisContext->current, 7, (s[2].u)); \ - gcm_emit_at(thisContext->current, 8, (s[3].u)); \ - gcm_finish_n_commands(thisContext->current, 9); - -#define rglGcmSetDitherEnable(thisContext, enable) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_DITHER_ENABLE, 1); \ - gcm_emit_at(thisContext->current, 1, enable); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetReferenceCommand(thisContext, ref) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV406E_SET_REFERENCE, 1); \ - gcm_emit_at(thisContext->current, 1, ref); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetZMinMaxControl(thisContext, cullNearFarEnable, zclampEnable, cullIgnoreW) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_ZMIN_MAX_CONTROL, 1); \ - gcm_emit_at(thisContext->current, 1, ((cullNearFarEnable) | ((zclampEnable) << 4) | ((cullIgnoreW)<<8))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetVertexAttribOutputMask(thisContext, mask) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_OUTPUT_MASK, 1); \ - gcm_emit_at(thisContext->current, 1, mask); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetNopCommand(thisContext, i, count) \ - for(i = 0;i < count; i++) \ - gcm_emit_at(thisContext->current, i, 0); \ - gcm_finish_n_commands(thisContext->current, count); - -#define rglGcmSetAntiAliasingControl(thisContext, enable, alphaToCoverage, alphaToOne, sampleMask) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_ANTI_ALIASING_CONTROL, 1); \ - gcm_emit_at(thisContext->current, 1, ((enable) | ((alphaToCoverage) << 4) | ((alphaToOne) << 8) | ((sampleMask) << 16))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmFifoFinish(fifo, ref, offset_bytes) \ - ref = rglGcmFifoPutReference( fifo ); \ - rglGcmFifoFlush( fifo, offset_bytes ); \ - while (rglGcmFifoReferenceInUse(fifo, ref)); - -#define rglGcmFifoReadReference(fifo) (fifo->lastHWReferenceRead = *((volatile GLuint *)&fifo->dmaControl->Reference)) - -#define rglGcmFifoFlush(fifo, offsetInBytes) \ - cellGcmAddressToOffset( fifo->ctx.current, ( uint32_t * )&offsetInBytes ); \ - rglGcmFlush(gCellGcmCurrentContext); \ - fifo->dmaControl->Put = offsetInBytes; \ - fifo->lastPutWritten = fifo->ctx.current; \ - fifo->lastSWReferenceFlushed = fifo->lastSWReferenceWritten; - -#define rglGcmFlush(thisContext) cellGcmFlushUnsafe(thisContext) - -#define rglGcmSetSurface(thisContext, surface, origin, pixelCenter, log2Width, log2Height) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_CONTEXT_DMA_COLOR_A, 1); \ - gcm_emit_at(thisContext->current, 1, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + surface->colorLocation[0])); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_CONTEXT_DMA_COLOR_B, 1); \ - gcm_emit_at(thisContext->current, 1, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + surface->colorLocation[1])); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_CONTEXT_DMA_COLOR_C, 2); \ - gcm_emit_at(thisContext->current, 1, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + surface->colorLocation[2])); \ - gcm_emit_at(thisContext->current, 2, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + surface->colorLocation[3])); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_CONTEXT_DMA_ZETA, 1); \ - gcm_emit_at(thisContext->current, 1, (CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER + surface->depthLocation)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SURFACE_FORMAT, 6); \ - gcm_emit_at(thisContext->current, 1, ((surface->colorFormat) | ((surface->depthFormat) << 5) | ((surface->type) << 8) | ((surface->antialias) << 12) | ((log2Width) << 16) | ((log2Height) << 24))); \ - gcm_emit_at(thisContext->current, 2, (surface->colorPitch[0])); \ - gcm_emit_at(thisContext->current, 3, (surface->colorOffset[0])); \ - gcm_emit_at(thisContext->current, 4, (surface->depthOffset)); \ - gcm_emit_at(thisContext->current, 5, (surface->colorOffset[1])); \ - gcm_emit_at(thisContext->current, 6, (surface->colorPitch[1])); \ - gcm_finish_n_commands(thisContext->current, 7); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SURFACE_PITCH_Z, 1); \ - gcm_emit_at(thisContext->current, 1, (surface->depthPitch)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SURFACE_PITCH_C, 4); \ - gcm_emit_at(thisContext->current, 1, (surface->colorPitch[2])); \ - gcm_emit_at(thisContext->current, 2, (surface->colorPitch[3])); \ - gcm_emit_at(thisContext->current, 3, (surface->colorOffset[2])); \ - gcm_emit_at(thisContext->current, 4, (surface->colorOffset[3])); \ - gcm_finish_n_commands(thisContext->current, 5); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SURFACE_COLOR_TARGET, 1); \ - gcm_emit_at(thisContext->current, 1, surface->colorTarget); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_WINDOW_OFFSET, 1); \ - gcm_emit_at(thisContext->current, 1, ((surface->x) | ((surface->y) << 16))); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SURFACE_CLIP_HORIZONTAL, 2); \ - gcm_emit_at(thisContext->current, 1, ((surface->x) | ((surface->width) << 16))); \ - gcm_emit_at(thisContext->current, 2, ((surface->y) | ((surface->height) << 16))); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_WINDOW, 1); \ - gcm_emit_at(thisContext->current, 1, ((surface->height - (((surface->height) & 0x1000) >> 12)) | ((origin) << 12) | ((pixelCenter) << 16))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSend(thisContext, dstId, dstOffset, pitch, src, size) \ - GLuint id = gmmAlloc(size); \ - memcpy( gmmIdToAddress(id), (src), size ); \ - rglGcmTransferData(thisContext, dstId, dstOffset, size, id, 0, size, size, 1 ); \ - gmmFree( id ) - -#define rglGcmSetUpdateFragmentProgramParameter(thisContext, offset, location) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_PROGRAM, 1); \ - gcm_emit_at(thisContext->current, 1, ((location+1) | (offset))); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetBlendColor(thisContext, color, color2) \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BLEND_COLOR, 1); \ - gcm_emit_at(thisContext->current, 1, color); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BLEND_COLOR2, 1); \ - gcm_emit_at(thisContext->current, 1, color2); \ - gcm_finish_n_commands(thisContext->current, 2); - -#define rglGcmSetVertexProgramParameterBlock(thisContext, baseConst, constCount, value) \ -{ \ - uint32_t blockCount, blockRemain, i; \ - blockCount = (constCount * 4) >> 5; \ - blockRemain = (constCount * 4) & 0x1f; \ - for (i=0; i < blockCount; i++) \ - { \ - uint32_t loadAt = baseConst + i * 8; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, 33); \ - gcm_emit_at(thisContext->current, 1, loadAt); \ - memcpy(&thisContext->current[2], value, 16 * sizeof(float)); \ - memcpy(&thisContext->current[18], &value[16], 16 * sizeof(float)); \ - gcm_finish_n_commands(thisContext->current, 34); \ - value += 32; \ - } \ - if (blockRemain == 0) \ - return; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, blockRemain + 1); \ - gcm_emit_at(thisContext->current, 1, (baseConst + blockCount * 8)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - blockRemain >>= 2; \ - for (i=0; i < blockRemain; ++i) \ - { \ - memcpy(thisContext->current, value, 4 * sizeof(float)); \ - gcm_finish_n_commands(thisContext->current, 4); \ - value += 4; \ - } \ -} - -#define rglGcmSetInlineTransfer(thisContext, dstOffset, srcAdr, sizeInWords) \ -{ \ - uint32_t *src, *srcEnd, paddedSizeInWords; \ - paddedSizeInWords = (sizeInWords + 1) & ~1; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_OFFSET_DESTIN, 1); \ - gcm_emit_at(thisContext->current, 1, dstOffset & ~63); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_COLOR_FORMAT, 2); \ - gcm_emit_at(thisContext->current, 1, CELL_GCM_TRANSFER_SURFACE_FORMAT_Y32); \ - gcm_emit_at(thisContext->current, 2, ((0x1000) | ((0x1000) << 16))); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_POINT, 3); \ - gcm_emit_at(thisContext->current, 1, (((0) << 16) | ((dstOffset & 63) >> 2))); \ - gcm_emit_at(thisContext->current, 2, (((1) << 16) | (sizeInWords))); \ - gcm_emit_at(thisContext->current, 3, (((1) << 16) | (sizeInWords))); \ - gcm_finish_n_commands(thisContext->current, 4); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV308A_COLOR, paddedSizeInWords); \ - gcm_finish_n_commands(thisContext->current, 1); \ - src = (uint32_t*)srcAdr; \ - srcEnd = src + sizeInWords; \ - while(src < srcEnd) \ - { \ - gcm_emit_at(thisContext->current, 0, src[0]); \ - gcm_finish_n_commands(thisContext->current, 1); \ - src += 1; \ - } \ - if (paddedSizeInWords != sizeInWords) \ - { \ - gcm_emit_at(thisContext->current, 0, 0); \ - gcm_finish_n_commands(thisContext->current, 1); \ - } \ -} - -#define rglGcmSetFragmentProgramLoad(thisContext, conf, location) \ -{ \ - uint32_t registerCount, texMask, texMask2D, texMaskCentroid, i; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_PROGRAM, 1); \ - gcm_emit_at(thisContext->current, 1, ((location+1) | ((conf->offset) & 0x1fffffff))); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_OUTPUT_MASK, 1); \ - gcm_emit_at(thisContext->current, 1, conf->attributeInputMask); \ - gcm_finish_n_commands(thisContext->current, 2); \ - texMask = conf->texCoordsInputMask; \ - texMask2D = conf->texCoords2D; \ - texMaskCentroid = conf->texCoordsCentroid; \ - for(i = 0; texMask; i++) \ - { \ - if (texMask & 1) \ - { \ - gcm_emit_method_at(thisContext->current, 0, (CELL_GCM_NV4097_SET_TEX_COORD_CONTROL + (i) * 4), 1); \ - gcm_emit_at(thisContext->current, 1, (texMask2D & 1) | ((texMaskCentroid & 1) << 4)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - } \ - texMask >>= 1; \ - texMask2D >>= 1; \ - texMaskCentroid >>= 1; \ - } \ - registerCount = conf->registerCount; \ - if (registerCount < 2) \ - registerCount = 2; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_SHADER_CONTROL, 1); \ - gcm_emit_at(thisContext->current, 1, conf->fragmentControl | (registerCount << 24)); \ - gcm_finish_n_commands(thisContext->current, 2); \ -} - -#define rglGcmSetDrawArrays(thisContext, mode, first, count) \ -{ \ - if ((mode) == GL_TRIANGLE_STRIP && (first) == 0 && (count) == 4) \ - { \ - gcm_emit_at(thisContext->current, 0, (((3) << (18)) | CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE | (0x40000000))); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_emit_at(thisContext->current, 2, 0); \ - gcm_emit_at(thisContext->current, 3, 0); \ - gcm_finish_n_commands(thisContext->current, 4); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); \ - gcm_emit_at(thisContext->current, 1, (mode)); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_DRAW_ARRAYS, 1); \ - gcm_emit_at(thisContext->current, 1, (((first)) | (3 <<24))); \ - gcm_finish_n_commands(thisContext->current, 2); \ - (first) += 4; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); \ - } \ - else \ - rglGcmSetDrawArraysSlow(thisContext, (mode), (first), (count)); \ -} - -#define rglGcmSetVertexProgramLoad(thisContext, conf, ucode) \ -{ \ - uint32_t *rawData, instCount, instIndex, loop, rest, i, j; \ - rawData = (uint32_t*)(ucode); \ - instCount = conf->instructionCount; \ - instIndex = conf->instructionSlot; \ - loop = instCount / 8; \ - rest = (instCount % 8) * 4; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM_LOAD, 2); \ - gcm_emit_at(thisContext->current, 1, instIndex); \ - gcm_emit_at(thisContext->current, 2, instIndex); \ - gcm_finish_n_commands(thisContext->current, 3); \ - for (i = 0; i < loop; i++) \ - { \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM, 32); \ - memcpy(&thisContext->current[1], &rawData[0], sizeof(uint32_t)*16); \ - memcpy(&thisContext->current[17], &rawData[16], sizeof(uint32_t)*16); \ - gcm_finish_n_commands(thisContext->current, (1 + 32)); \ - rawData += 32; \ - } \ - if (rest > 0) \ - { \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_PROGRAM, rest); \ - for (j = 0; j < rest; j++) \ - gcm_emit_at(thisContext->current, j + 1, rawData[j]); \ - gcm_finish_n_commands(thisContext->current, (1 + rest)); \ - } \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_VERTEX_ATTRIB_INPUT_MASK, 1); \ - gcm_emit_at(thisContext->current, 1, conf->attributeInputMask); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_TIMEOUT, 1); \ - if (conf->registerCount <= 32) \ - { \ - gcm_emit_at(thisContext->current, 1, ((0xFFFF) | ((32) << 16))); \ - } \ - else \ - { \ - gcm_emit_at(thisContext->current, 1, ((0xFFFF) | ((48) << 16))); \ - } \ - gcm_finish_n_commands(thisContext->current, 2); \ -} - -#define rglGcmFifoGlViewport(data, zNear, zFar) \ -{ \ - GLint clipY0, clipY1, clipX0, clipX1; \ - GLfloat z_scale, z_center; \ - rglGcmViewportState *vp; \ - rglGcmRenderTarget *rt; \ - vp = (rglGcmViewportState*)data; \ - rt = (rglGcmRenderTarget*)&rglGcmState_i.renderTarget; \ - clipX0 = vp->x; \ - clipX1 = vp->x + vp->w; \ - clipY0 = vp->y; \ - clipY1 = vp->y + vp->h; \ - if (rt->yInverted) \ - { \ - clipY0 = rt->gcmRenderTarget.height - (vp->y + vp->h); \ - clipY1 = rt->gcmRenderTarget.height - vp->y; \ - } \ - if (clipX0 < 0) \ - clipX0 = 0; \ - if (clipY0 < 0) \ - clipY0 = 0; \ - if (clipX1 >= CELL_GCM_MAX_RT_DIMENSION) \ - clipX1 = CELL_GCM_MAX_RT_DIMENSION; \ - if (clipY1 >= CELL_GCM_MAX_RT_DIMENSION) \ - clipY1 = CELL_GCM_MAX_RT_DIMENSION; \ - if ((clipX1 <= clipX0) || (clipY1 <= clipY0)) \ - clipX0 = clipY0 = clipX1 = clipY1 = 0; \ - vp->xScale = vp->w * 0.5f; \ - vp->xCenter = (GLfloat)(vp->x + vp->xScale + RGLGCM_SUBPIXEL_ADJUST); \ - vp->yScale = vp->h * 0.5f; \ - vp->yCenter = (GLfloat)(vp->y + vp->yScale + RGLGCM_SUBPIXEL_ADJUST); \ - if (rt->yInverted) \ - { \ - vp->yScale = vp->h * -0.5f; \ - vp->yCenter = (GLfloat)(rt->gcmRenderTarget.height - RGLGCM_VIEWPORT_EPSILON - vp->y + vp->yScale + RGLGCM_SUBPIXEL_ADJUST); \ - } \ - z_scale = (GLfloat)( 0.5f * ( (zFar) - (zNear) ) ); \ - z_center = (GLfloat)( 0.5f * ( (zFar) + (zNear) ) ); \ - float scale[4] = { vp->xScale, vp->yScale, z_scale, 0.0f}; \ - float offset[4] = { vp->xCenter, vp->yCenter, z_center, 0.0f}; \ - rglGcmSetViewport(thisContext, clipX0, clipY0, clipX1 - clipX0, clipY1 - clipY0, (zNear), (zFar), scale, offset ); \ -} - -#define rglGcmTransferData(thisContext, a,b,c,d,e,f,g,h) \ -{ \ - GLuint dstId = a; \ - GLuint dstIdOffset = b; \ - GLint dstPitch = c; \ - GLuint srcId = d; \ - GLuint srcIdOffset = e; \ - GLint srcPitch = f; \ - GLint bytesPerRow = g; \ - GLint rowCount = h; \ - uint32_t colCount, rows, cols; \ - GLuint dstOffset, srcOffset; \ - dstOffset = gmmIdToOffset(dstId) + dstIdOffset; \ - srcOffset = gmmIdToOffset(srcId) + srcIdOffset; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_SET_CONTEXT_DMA_BUFFER_IN, 2); \ - gcm_emit_at(thisContext->current, 1, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); \ - gcm_emit_at(thisContext->current, 2, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); \ - gcm_finish_n_commands(thisContext->current, 3); \ - if ((srcPitch == bytesPerRow) && (dstPitch == bytesPerRow)) \ - { \ - bytesPerRow *= rowCount; \ - rowCount = 1; \ - srcPitch = 0; \ - dstPitch = 0; \ - } \ - while(--rowCount >= 0) \ - { \ - for(colCount = bytesPerRow; colCount>0; colCount -= cols) \ - { \ - cols = (colCount > CL0039_MAX_LINES) ? CL0039_MAX_LINES : colCount; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_OFFSET_IN, 8); \ - gcm_emit_at(thisContext->current, 1, (srcOffset + (bytesPerRow - colCount))); \ - gcm_emit_at(thisContext->current, 2, (dstOffset + (bytesPerRow - colCount))); \ - gcm_emit_at(thisContext->current, 3, 0); \ - gcm_emit_at(thisContext->current, 4, 0); \ - gcm_emit_at(thisContext->current, 5, cols); \ - gcm_emit_at(thisContext->current, 6, 1); \ - gcm_emit_at(thisContext->current, 7, (((1) << 8) | (1))); \ - gcm_emit_at(thisContext->current, 8, 0); \ - gcm_finish_n_commands(thisContext->current, 9); \ - } \ - dstOffset += dstPitch; \ - srcOffset += srcPitch; \ - } \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV0039_OFFSET_OUT, 1); \ - gcm_emit_at(thisContext->current, 1, 0); \ - gcm_finish_n_commands(thisContext->current, 2); \ -} - -#define rglGcmSetTransferImage(thisContext, mode, dstOffset, dstPitch, dstX, dstY, srcOffset, srcPitch, srcX, srcY, width, height, bytesPerPixel) \ -{ \ - uint32_t srcFormat, dstFormat, x, y, finalDstX, finalDstY; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_CONTEXT_DMA_IMAGE_DESTIN, 1); \ - gcm_emit_at(thisContext->current, 1, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3089_SET_CONTEXT_DMA_IMAGE, 1); \ - gcm_emit_at(thisContext->current, 1, CELL_GCM_CONTEXT_DMA_MEMORY_FRAME_BUFFER); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3089_SET_CONTEXT_SURFACE, 1); \ - gcm_emit_at(thisContext->current, 1, 0x313371C3); \ - gcm_finish_n_commands(thisContext->current, 2); \ - srcFormat = 0; \ - dstFormat = 0; \ - switch (bytesPerPixel) \ - { \ - case 2: \ - srcFormat = CELL_GCM_TRANSFER_SCALE_FORMAT_R5G6B5; \ - dstFormat = CELL_GCM_TRANSFER_SURFACE_FORMAT_R5G6B5; \ - break; \ - case 4: \ - srcFormat = CELL_GCM_TRANSFER_SCALE_FORMAT_A8R8G8B8; \ - dstFormat = CELL_GCM_TRANSFER_SURFACE_FORMAT_A8R8G8B8; \ - break; \ - } \ - finalDstX = dstX + width; \ - finalDstY = dstY + height; \ - for (y = dstY; y < finalDstY;) \ - { \ - uint32_t dstTop, dstBltHeight; \ - dstTop = y & ~(BLOCKSIZE_MAX_DIMENSIONS - 1); \ - dstBltHeight = (( (dstTop + BLOCKSIZE_MAX_DIMENSIONS) < finalDstY) ? (dstTop + BLOCKSIZE_MAX_DIMENSIONS) : finalDstY) - y; \ - for (x = dstX; x < finalDstX;) \ - { \ - uint32_t dstLeft, dstRight, dstBltWidth, dstBlockOffset, srcBlockOffset, safeDstBltWidth; \ - dstLeft = x & ~(BLOCKSIZE_MAX_DIMENSIONS - 1); \ - dstRight = dstLeft + BLOCKSIZE_MAX_DIMENSIONS; \ - dstBltWidth = ((dstRight < finalDstX) ? dstRight : finalDstX) - x; \ - dstBlockOffset = bytesPerPixel * (dstLeft & ~(BLOCKSIZE_MAX_DIMENSIONS - 1)) + dstPitch * dstTop; \ - srcBlockOffset = bytesPerPixel * (srcX + x-dstX) + srcPitch * (srcY + y-dstY); \ - safeDstBltWidth = (dstBltWidth < 16) ? 16 : (dstBltWidth + 1) & ~1; \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_OFFSET_DESTIN, 1); \ - gcm_emit_at(thisContext->current, 1, dstOffset + dstBlockOffset); \ - gcm_finish_n_commands(thisContext->current, 2); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3062_SET_COLOR_FORMAT, 2); \ - gcm_emit_at(thisContext->current, 1, dstFormat); \ - gcm_emit_at(thisContext->current, 2, ((dstPitch) | ((dstPitch) << 16))); \ - gcm_finish_n_commands(thisContext->current, 3); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3089_SET_COLOR_CONVERSION, 9); \ - gcm_emit_at(thisContext->current, 1, CELL_GCM_TRANSFER_CONVERSION_TRUNCATE); \ - gcm_emit_at(thisContext->current, 2, srcFormat); \ - gcm_emit_at(thisContext->current, 3, CELL_GCM_TRANSFER_OPERATION_SRCCOPY); \ - gcm_emit_at(thisContext->current, 4, (((y - dstTop) << 16) | (x - dstLeft))); \ - gcm_emit_at(thisContext->current, 5, (((dstBltHeight) << 16) | (dstBltWidth))); \ - gcm_emit_at(thisContext->current, 6, (((y - dstTop) << 16) | (x - dstLeft))); \ - gcm_emit_at(thisContext->current, 7, (((dstBltHeight) << 16) | (dstBltWidth))); \ - gcm_emit_at(thisContext->current, 8, 1048576); \ - gcm_emit_at(thisContext->current, 9, 1048576); \ - gcm_finish_n_commands(thisContext->current, 10); \ - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV3089_IMAGE_IN_SIZE, 4); \ - gcm_emit_at(thisContext->current, 1, (((dstBltHeight) << 16) | (safeDstBltWidth))); \ - gcm_emit_at(thisContext->current, 2, ((srcPitch) | ((CELL_GCM_TRANSFER_ORIGIN_CORNER) << 16) | ((CELL_GCM_TRANSFER_INTERPOLATOR_ZOH) << 24))); \ - gcm_emit_at(thisContext->current, 3, (srcOffset + srcBlockOffset)); \ - gcm_emit_at(thisContext->current, 4, 0); \ - gcm_finish_n_commands(thisContext->current, 5); \ - x += dstBltWidth; \ - } \ - y += dstBltHeight; \ - } \ -} - -#endif diff --git a/ps3/gcmgl/src/include/rgl-inline.h b/ps3/gcmgl/src/include/rgl-inline.h deleted file mode 100644 index 93ac58d181..0000000000 --- a/ps3/gcmgl/src/include/rgl-inline.h +++ /dev/null @@ -1,260 +0,0 @@ -#ifndef _RGL_INLINE_H -#define _RGL_INLINE_H - - -#define SUBPIXEL_BITS 12 -#define SUBPIXEL_ADJUST (0.5/(1<>16) | (v.ui<<16); \ - *fp = v.f; \ -} - -#define rglDeallocateBuffer(bufferObject, rglBuffer) \ - if (rglBuffer->pool == RGLGCM_SURFACE_POOL_LINEAR) \ - gmmFree( rglBuffer->bufferId ); \ - rglBuffer->pool = RGLGCM_SURFACE_POOL_NONE; \ - rglBuffer->bufferId = GMM_ERROR - - -static void rglGcmSetDrawArraysSlow(struct CellGcmContextData *thisContext, uint8_t mode, - uint32_t first, uint32_t count) -{ - uint32_t lcount, i,j, loop, rest; - - --count; - lcount = count & 0xff; - count >>= 8; - - loop = count / CELL_GCM_MAX_METHOD_COUNT; - rest = count % CELL_GCM_MAX_METHOD_COUNT; - - (thisContext->current)[0] = (((3) << (18)) | CELL_GCM_NV4097_INVALIDATE_VERTEX_FILE | (0x40000000)); - gcm_emit_at(thisContext->current, 1, 0); - gcm_emit_at(thisContext->current, 2, 0); - gcm_emit_at(thisContext->current, 3, 0); - gcm_finish_n_commands(thisContext->current, 4); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); - gcm_emit_at(thisContext->current, 1, mode); - gcm_finish_n_commands(thisContext->current, 2); - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_DRAW_ARRAYS, 1); - gcm_emit_at(thisContext->current, 1, ((first) | ((lcount)<<24))); - gcm_finish_n_commands(thisContext->current, 2); - first += lcount + 1; - - for(i=0;icurrent[0] = ((((2047)) << (18)) | CELL_GCM_NV4097_DRAW_ARRAYS | (0x40000000)); - gcm_finish_n_commands(thisContext->current, 1); - - for(j = 0; j < CELL_GCM_MAX_METHOD_COUNT; j++) - { - gcm_emit_at(thisContext->current, 0, ((first) | ((255U)<<24))); - gcm_finish_n_commands(thisContext->current, 1); - first += 256; - } - } - - if(rest) - { - thisContext->current[0] = (((rest) << (18)) | CELL_GCM_NV4097_DRAW_ARRAYS | (0x40000000)); - gcm_finish_n_commands(thisContext->current, 1); - - for(j = 0;j < rest; j++) - { - gcm_emit_at(thisContext->current, 0, ((first) | ((255U)<<24))); - gcm_finish_n_commands(thisContext->current, 1); - first += 256; - } - } - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_BEGIN_END, 1); - gcm_emit_at(thisContext->current, 1, 0); - gcm_finish_n_commands(thisContext->current, 2); -} - -static inline GLuint rglGcmMapMinTextureFilter( GLenum filter ) -{ - switch (filter) - { - case GL_NEAREST: - return CELL_GCM_TEXTURE_NEAREST; - break; - case GL_LINEAR: - return CELL_GCM_TEXTURE_LINEAR; - break; - case GL_NEAREST_MIPMAP_NEAREST: - return CELL_GCM_TEXTURE_NEAREST_NEAREST; - break; - case GL_NEAREST_MIPMAP_LINEAR: - return CELL_GCM_TEXTURE_NEAREST_LINEAR; - break; - case GL_LINEAR_MIPMAP_NEAREST: - return CELL_GCM_TEXTURE_LINEAR_NEAREST; - break; - case GL_LINEAR_MIPMAP_LINEAR: - return CELL_GCM_TEXTURE_LINEAR_LINEAR; - break; - default: - return 0; - } - return filter; -} - -static inline GLuint rglGcmMapWrapMode( GLuint mode ) -{ - switch ( mode ) - { - case RGLGCM_CLAMP: - return CELL_GCM_TEXTURE_CLAMP; - break; - case RGLGCM_REPEAT: - return CELL_GCM_TEXTURE_WRAP; - break; - case RGLGCM_CLAMP_TO_EDGE: - return CELL_GCM_TEXTURE_CLAMP_TO_EDGE; - break; - case RGLGCM_CLAMP_TO_BORDER: - return CELL_GCM_TEXTURE_BORDER; - break; - case RGLGCM_MIRRORED_REPEAT: - return CELL_GCM_TEXTURE_MIRROR; - break; - case RGLGCM_MIRROR_CLAMP_TO_EDGE: - return CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP_TO_EDGE; - break; - case RGLGCM_MIRROR_CLAMP_TO_BORDER: - return CELL_GCM_TEXTURE_MIRROR_ONCE_BORDER; - break; - case RGLGCM_MIRROR_CLAMP: - return CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP; - break; - default: - return 0; - break; - } - return 0; -} - -// Fast conversion for values between 0.0 and 65535.0 -static inline GLuint RGLGCM_QUICK_FLOAT2UINT (const GLfloat f) -{ - union - { - GLfloat f; - GLuint ui; - } t; - t.f = f + RGLGCM_F0_DOT_0; - return t.ui & 0xffff; -} - -// construct a packed unsigned int ARGB8 color -static inline void RGLGCM_CALC_COLOR_LE_ARGB8( GLuint *color0, const GLfloat r, - const GLfloat g, const GLfloat b, const GLfloat a ) -{ - GLuint r2, g2, b2, a2; - r2 = RGLGCM_QUICK_FLOAT2UINT( r * 255.0f ); - g2 = RGLGCM_QUICK_FLOAT2UINT( g * 255.0f ); - b2 = RGLGCM_QUICK_FLOAT2UINT( b * 255.0f ); - a2 = RGLGCM_QUICK_FLOAT2UINT( a * 255.0f ); - *color0 = ( a2 << 24 ) | ( r2 << 16 ) | ( g2 << 8 ) | ( b2 << 0 ); -} - - -// Utility to let RSX wait for complete RSX pipeline idle -static inline void rglGcmUtilWaitForIdle (void) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - - // set write label command in push buffer, and wait - // NOTE: this is for RSX to wailt - rglGcmSetWriteBackEndLabel(thisContext, RGLGCM_UTIL_LABEL_INDEX, rglGcmState_i.labelValue ); - rglGcmSetWaitLabel(thisContext, RGLGCM_UTIL_LABEL_INDEX, rglGcmState_i.labelValue); - - // increment label value for next time. - rglGcmState_i.labelValue++; - - // make sure the entire pipe in clear not just the front end - // Utility function that does GPU 'finish'. - rglGcmSetWriteBackEndLabel(thisContext, RGLGCM_UTIL_LABEL_INDEX, rglGcmState_i.labelValue ); - rglGcmFlush(gCellGcmCurrentContext); - - while( *(cellGcmGetLabelAddress( RGLGCM_UTIL_LABEL_INDEX)) != rglGcmState_i.labelValue); - - rglGcmState_i.labelValue++; -} - -// 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) ); -// 00 00 00 08 : 00000000 00000000 00000000 00001000 */ -static inline void rglPrintIt (unsigned int v) -{ - // HEX (space between bytes) - printf( "%02x %02x %02x %02x : ", ( v >> 24 )&0xff, ( v >> 16 )&0xff, ( v >> 8 )&0xff, v&0xff ); - - // BINARY (space between bytes) - for ( unsigned int mask = ( 0x1 << 31 ), i = 1; mask != 0; mask >>= 1, i++ ) - printf( "%d%s", ( v & mask ) ? 1 : 0, ( i % 8 == 0 ) ? " " : "" ); - printf( "\n" ); -} - -// prints the last numWords of the command fifo -static inline void rglPrintFifoFromPut( unsigned int numWords ) -{ - for ( int i = -numWords; i <= -1; i++ ) - rglPrintIt((( uint32_t* )rglGcmState_i.fifo.ctx.current )[i] ); -} - -// prints the last numWords of the command fifo -static inline void rglPrintFifoFromGet( unsigned int numWords ) -{ - for ( int i = -numWords; i <= -1; i++ ) - rglPrintIt((( uint32_t* )rglGcmState_i.fifo.lastGetRead )[i] ); -} - -#endif diff --git a/ps3/gcmgl/src/include/rgl-typedefs.h b/ps3/gcmgl/src/include/rgl-typedefs.h deleted file mode 100644 index 8daeb2f295..0000000000 --- a/ps3/gcmgl/src/include/rgl-typedefs.h +++ /dev/null @@ -1,371 +0,0 @@ -#ifndef _RGL_TYPEDEFS_H -#define _RGL_TYPEDEFS_H - -#include "../include/export/PSGL/psgl.h" -#include "../include/PSGL/Types.h" - -typedef struct rglGcmRenderTargetEx rglGcmRenderTargetEx; - -typedef struct _tagMODESTRUC -{ - GLushort wHorizVisible; - GLushort wVertVisible; - GLushort wInterlacedMode; - GLushort wRefresh; - GLushort wHorizTotal; - GLushort wHorizBlankStart; - GLushort wHorizSyncStart; - GLushort wHorizSyncEnd; - GLushort wHorizBlankEnd; - GLushort wVertTotal; - GLushort wVertBlankStart; - GLushort wVertSyncStart; - GLushort wVertSyncEnd; - GLushort wVertBlankEnd; - GLuint dwDotClock; // In 10K Hertz - GLushort wHSyncPolarity; - GLushort wVSyncPolarity; -} MODESTRUC; - -// descriptor for 2D data -typedef struct -{ - GLenum source; // device, texture, renderbuffer - GLuint width, height; - GLuint bpp; // bytes per pixel, derived from format - GLuint pitch; // 0 if swizzled - - rglGcmEnum format; // e.g. RGLGCM_ARGB8 - - GLenum pool; // type of memory - - GLuint dataId; // id to get address and offset - GLuint dataIdOffset; -} rglGcmSurface; - -typedef struct -{ - // TODO: get rid of this member - rglGcmRenderTargetEx rt; - // framebuffers - rglGcmSurface color[3]; - // double/triple buffering management - GLuint drawBuffer; // 0, 1, or 2 - GLuint scanBuffer; // 0, 1, or 2 - // resc buffers - GLuint RescColorBuffersId; - GLuint RescVertexArrayId; - GLuint RescFragmentShaderId; - const MODESTRUC *ms; - GLboolean vsync; - GLboolean skipFirstVsync; - GLenum deviceType; - GLenum TVStandard; - GLenum TVFormat; - GLuint swapFifoRef; - GLuint swapFifoRef2; // Added for supporting Triple buffering [RSTENSON] - GLboolean setOffset; - GLboolean signal; - GLuint semaValue; - unsigned int syncMethod; -} rglGcmDevice; - -typedef struct rglGcmDriver_ -{ - rglGcmRenderTargetEx rt; - GLboolean rtValid; - GLboolean invalidateVertexCache; - int xSuperSampling; // supersampling factor in X - int ySuperSampling; // supersampling factor in Y - - GLuint flushBufferCount; // # of mapped buffer objects in bounce buffer - - GLuint fpLoadProgramId; // address of the currently bound fragment program - GLuint fpLoadProgramOffset; - - GLuint sharedFPConstantsId; - char *sharedVPConstants; -} rglGcmDriver; - -typedef struct -{ - GLuint SET_TEXTURE_CONTROL3; // pitch and depth - GLuint SET_TEXTURE_OFFSET; // gpu addr (from dma ctx) - GLuint SET_TEXTURE_FORMAT; // which dma ctx, [123]D, border source, mem layout, mip levels - GLuint SET_TEXTURE_ADDRESS; // wrap, signed and unsigned remap control, gamma, zfunc - GLuint SET_TEXTURE_CONTROL0; // enable, lod clamp, aniso, image field, alpha kill, colorkey - GLuint SET_TEXTURE_CONTROL1; // remap and crossbar setup. - GLuint SET_TEXTURE_FILTER; // lod bias, convol filter, min/mag filter, component signedness - GLuint SET_TEXTURE_IMAGE_RECT; // texture width/height -} rglGcmTextureMethods; - -// Gcm Specific function parameter mappings. -// for cellGcmSetControl -struct rglGcmTextureControl0 -{ - GLuint minLOD; - GLuint maxLOD; - GLuint maxAniso; -}; - -// for cellGcmSetAddress -struct rglGcmTextureAddress -{ - GLuint wrapS; - GLuint wrapT; - GLuint wrapR; - GLuint unsignedRemap; - GLuint zfunc; - GLuint gamma; -}; - -// for cellGcmSetTextureFilter -struct rglGcmTextureFilter -{ - GLuint min; - GLuint mag; - GLuint conv; - GLint bias; -}; - -// Structure to contain Gcm Function Parameters for setting later. -// Control1 and Control3 will be set by cellGcmSetTexture -struct rglGcmTextureMethodParams -{ - rglGcmTextureControl0 control0; - rglGcmTextureAddress address; - rglGcmTextureFilter filter; - GLuint borderColor; // texture border color -}; - -typedef struct -{ - // These are enough to describe the GPU format - GLuint faces; - GLuint levels; - GLuint baseWidth; - GLuint baseHeight; - GLuint baseDepth; - rglGcmEnum internalFormat; - GLuint pixelBits; - GLuint pitch; -} rglGcmTextureLayout; - -// GCM texture data structure -typedef struct -{ - GLenum pool; - rglGcmTextureMethods methods; // [RSTENSON] soon to be legacy - rglGcmTextureMethodParams gcmMethods; - CellGcmTexture gcmTexture; - GLuint gpuAddressId; - GLuint gpuAddressIdOffset; - GLuint gpuSize; - rglGcmTextureLayout gpuLayout; -} rglGcmTexture; - -/* pio flow control data structure */ -typedef volatile struct -{ - GLuint Ignored00[0x010]; - GLuint Put; /* put offset, write only 0040-0043*/ - GLuint Get; /* get offset, read only 0044-0047*/ - GLuint Reference; /* reference value, read only 0048-004b*/ - GLuint Ignored01[0x1]; - GLuint SetReference; /* set reference value 0050-0053*/ - GLuint TopLevelGet; /* top level get offset, read only 0054-0057*/ - GLuint Ignored02[0x2]; - GLuint SetContextDmaSemaphore; /* set sema ctxdma, write only 0060-0063*/ - GLuint SetSemaphoreOffset; /* set sema offset, write only 0064-0067*/ - GLuint SetSemaphoreAcquire; /* set sema acquire, write only 0068-006b*/ - GLuint SetSemaphoreRelease; /* set sema release, write only 006c-006f*/ - GLuint Ignored03[0x7e4]; -} rglGcmControlDma; - -// _only_ update lastGetRead if the Get is in our pushbuffer - -#define fifoUpdateGetLastRead(fifo) \ - uint32_t* tmp = (uint32_t*)(( char* )fifo->dmaPushBufferBegin - fifo->dmaPushBufferOffset + ( *(( volatile GLuint* )&fifo->dmaControl->Get))); \ - if ((tmp >= fifo->ctx.begin) && (tmp <= fifo->ctx.end)) \ - fifo->lastGetRead = tmp; - -// all fifo related data is kept here -struct rglGcmFifo -{ - CellGcmContextData ctx; - // dmaControl for allocated channel - rglGcmControlDma *dmaControl; - - // for storing the start of the push buffer - // begin will be moving around - uint32_t *dmaPushBufferBegin; - uint32_t *dmaPushBufferEnd; - - // Fifo block size - GLuint fifoBlockSize; - - // pushbuffer location etc. - // members around here were moved up - unsigned long dmaPushBufferOffset; - GLuint dmaPushBufferSizeInWords; - - // the last Put value we wrote - uint32_t *lastPutWritten; - - // the last Get value we know of - uint32_t *lastGetRead; - - // cached value of last reference write - GLuint lastSWReferenceWritten; - - // cached value of lastSWReferenceWritten at most - // recent fifo flush - GLuint lastSWReferenceFlushed; - - // cached value of last reference read - GLuint lastHWReferenceRead; - uint32_t *dmaPushBufferGPU; - int spuid; -}; - -// 16 byte aligned semaphores -struct rglGcmSemaphore -{ - GLuint val; - GLuint pad0; - GLuint pad1; - GLuint pad2; -}; - -// semaphore storage -struct rglGcmSemaphoreMemory -{ - rglGcmSemaphore userSemaphores[RGLGCM_MAX_USER_SEMAPHORES]; -}; - -struct rglGcmResource -{ - char *localAddress; - GLuint localSize; - GLuint MemoryClock; - GLuint GraphicsClock; - - char * linearMemory; - unsigned int persistentMemorySize; - - // host memory window the gpu can access - char * hostMemoryBase; - GLuint hostMemorySize; - - // offset of dmaPushBuffer relative to its DMA CONTEXT - unsigned long dmaPushBufferOffset; - char * dmaPushBuffer; - GLuint dmaPushBufferSize; - void* dmaControl; - - // semaphores - rglGcmSemaphoreMemory *semaphores; -}; - -typedef struct -{ - GLenum pool; // LINEAR, or NONE - unsigned int bufferId; // allocated Id - unsigned int bufferSize; - unsigned int pitch; - - GLuint mapCount; // map reference count - GLenum mapAccess; // READ_ONLY, WRITE_ONLY, or READ_WRITE -} -rglGcmBufferObject; - -typedef struct rglGcmShader_ -{ - GLuint loadAddressId; - CgBinaryProgram __attribute__(( aligned( 16 ) ) ) program; -} rglGcmShader; - -// the current rendering surface/target -typedef struct rglGcmRenderTarget rglGcmRenderTarget; - -struct rglGcmRenderTarget -{ - GLuint colorFormat; - GLuint colorBufferCount; - - // (0,0) is in the lower left - GLuint yInverted; - - // gcm render target structure [RSTENSON] - CellGcmSurface gcmRenderTarget; -}; - -// cached state: viewport -typedef struct rglGcmViewportState rglGcmViewportState; -struct rglGcmViewportState -{ - // user values given as input to glViewport - GLint x, y, w, h; - // from glViewport - GLfloat xScale, xCenter; - GLfloat yScale, yCenter; -}; - -// cached state: blend -typedef struct rglGcmBlendState rglGcmBlendState; -struct rglGcmBlendState -{ - // current blend color - GLfloat r, g, b, a; - - // alpha blend reference - GLuint alphaFunc; - GLfloat alphaRef; -}; - -typedef struct rglGcmInterpolantState rglGcmInterpolantState; -struct rglGcmInterpolantState -{ - // mask of inputs used by programs - // Uses bits from SET_VERTEX_ATTRIB_OUTPUT_MASK. - GLuint vertexProgramAttribMask; - GLuint fragmentProgramAttribMask; -}; - -// cached state (because no dedecated method exist) -typedef struct rglGcmCachedState rglGcmCachedState; -struct rglGcmCachedState -{ - // we need to track blending color, too - rglGcmBlendState blend; - - // need to cache viewport values, because of yInverted - rglGcmViewportState viewport; - - // all interpolants are enabled/disabled with a single mask - rglGcmInterpolantState interpolant; -}; - -// ** the master instance representing a channel/context ** -struct rglGcmState -{ - char *localAddress; - - // host memory window the gpu can access - void *hostMemoryBase; - GLuint hostMemorySize; - - // semaphores - rglGcmSemaphoreMemory *semaphores; - - // -- context state -- - rglGcmFifo fifo; - rglGcmRenderTarget renderTarget; - rglGcmCachedState state; - CellGcmConfig config; - GLuint labelValue; -}; - -extern rglGcmState rglGcmState_i; - -#endif diff --git a/ps3/gcmgl/src/libelf/elf.h b/ps3/gcmgl/src/libelf/elf.h deleted file mode 100644 index ffc93b1885..0000000000 --- a/ps3/gcmgl/src/libelf/elf.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef ELF_H -#define ELF_H - -/* - * ELF header - */ - -/* e_ident[] Identification Indexes */ -#define EI_MAG0 0 /* File identification */ -#define EI_MAG1 1 /* File identification */ -#define EI_MAG2 2 /* File identification */ -#define EI_MAG3 3 /* File identification */ -#define EI_CLASS 4 /* File class */ -#define EI_DATA 5 /* Data encoding */ -#define EI_VERSION 6 /* File version */ -#define EI_OSABI 7 /* Operating system/ABI identification */ -#define EI_ABIVERSION 8 /* ABI version */ -#define EI_PAD 9 /* Start of padding bytes */ -#define EI_NIDENT 16 /* Size of e_ident[] */ - -/* e_ident[EI_MAG0] to e_ident[EI_MAG3] */ -#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ -#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ -#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ -#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ - -/* e_ident[EI_CLASS] */ -#define ELFCLASSNONE 0 /* Invalid class */ -#define ELFCLASS32 1 /* 32-bit objects */ -#define ELFCLASS64 2 /* 64-bit objects */ - -/* e_ident[EI_DATA] */ -#define ELFDATANONE 0 /* Invalid data encoding */ -#define ELFDATA2LSB 1 /* little endian */ -#define ELFDATA2MSB 2 /* big endian */ - -/* e_ident[EI_VERSION] */ -#define EV_NONE 0 /* Invalid version */ -#define EV_CURRENT 1 /* Current version */ - -/* e_type */ -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* Relocatable file */ -#define ET_EXEC 2 /* Executable file */ -#define ET_DYN 3 /* Shared object file */ -#define ET_CORE 4 /* Core file */ - -/* e_machine */ -#define EM_PPC 20 /* PowerPC 32-bit */ -#define EM_PPC64 21 /* PowerPC 64-bit */ - -typedef struct { - unsigned char e_ident[EI_NIDENT]; - uint16_t e_type; - uint16_t e_machine; - uint32_t e_version; - uint32_t e_entry; - int32_t e_phoff; - int32_t e_shoff; - uint32_t e_flags; - uint16_t e_ehsize; - uint16_t e_phentsize; - uint16_t e_phnum; - uint16_t e_shentsize; - uint16_t e_shnum; - uint16_t e_shstrndx; -} Elf32_Ehdr; - -typedef struct { - unsigned char e_ident[EI_NIDENT]; - uint16_t e_type; - uint16_t e_machine; - uint32_t e_version; - uint64_t e_entry; - uint64_t e_phoff; - uint64_t e_shoff; - uint32_t e_flags; - uint16_t e_ehsize; - uint16_t e_phentsize; - uint16_t e_phnum; - uint16_t e_shentsize; - uint16_t e_shnum; - uint16_t e_shstrndx; -} Elf64_Ehdr; - -/* - * Program Header - */ - -/* Segment Types, p_type */ -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_LOOS 0x60000000 -#define PT_HIOS 0x6fffffff -#define PT_LOPROC 0x70000000 -#define PT_HIPROC 0x7fffffff - -typedef struct { - uint32_t p_type; - int32_t p_offset; - uint32_t p_vaddr; - uint32_t p_paddr; - uint32_t p_filesz; - uint32_t p_memsz; - uint32_t p_flags; - uint32_t p_align; -} Elf32_Phdr; - -typedef struct { - uint32_t p_type; - uint32_t p_flags; - uint64_t p_offset; - uint64_t p_vaddr; - uint64_t p_paddr; - uint64_t p_filesz; - uint64_t p_memsz; - uint64_t p_align; -} Elf64_Phdr; - -/* - * Section Header - */ - -/* sh_type */ -#define SHT_NULL 0 /* Section header table entry unused */ -#define SHT_PROGBITS 1 /* Program data */ -#define SHT_SYMTAB 2 /* Symbol table */ -#define SHT_STRTAB 3 /* String table */ -#define SHT_RELA 4 /* Relocation entries with addends */ -#define SHT_HASH 5 /* Symbol hash table */ -#define SHT_DYNAMIC 6 /* Dynamic linking information */ -#define SHT_NOTE 7 /* Notes */ -#define SHT_NOBITS 8 /* Program space with no data (bss) */ -#define SHT_REL 9 /* Relocation entries, no addends */ -#define SHT_SHLIB 10 /* Reserved */ -#define SHT_DYNSYM 11 /* Dynamic linker symbol table */ - -#define SHF_WRITE (1 << 0) /* Writable */ -#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ -#define SHF_EXECINSTR (1 << 2) /* Executable */ -#define SHF_MERGE (1 << 4) /* Might be merged */ -#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ -#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ -#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ -#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling - required */ -#define SHF_MASKOS 0x0ff00000 /* OS-specific. */ -#define SHF_MASKPROC 0xf0000000 /* Processor-specific */ - - -typedef struct { - uint32_t sh_name; - uint32_t sh_type; - uint32_t sh_flags; - uint32_t sh_addr; - int32_t sh_offset; - uint32_t sh_size; - uint32_t sh_link; - uint32_t sh_info; - uint32_t sh_addralign; - uint32_t sh_entsize; -} Elf32_Shdr; - -/* Special section indices. */ - -#define SHN_UNDEF 0 /* Undefined section */ -#define SHN_LORESERVE 0xff00 /* Start of reserved indices */ -#define SHN_LOPROC 0xff00 /* Start of processor-specific */ -#define SHN_HIPROC 0xff1f /* End of processor-specific */ -#define SHN_LOOS 0xff20 /* Start of OS-specific */ -#define SHN_HIOS 0xff3f /* End of OS-specific */ -#define SHN_ABS 0xfff1 /* Associated symbol is absolute */ - -#ifndef SHN_COMMON -#define SHN_COMMON 0xfff2 /* Associated symbol is common */ -#endif - -#ifndef SHN_XINDEX -#define SHN_XINDEX 0xffff /* Index is in extra table. */ -#endif - -#ifndef SHN_HIRESERVE -#define SHN_HIRESERVE 0xffff /* End of reserved indices */ -#endif - -/* - * Symbol Header - */ - -typedef struct { - uint32_t st_name; - uint32_t st_value; - uint32_t st_size; - unsigned char st_info; - unsigned char st_other; - uint16_t st_shndx; -} Elf32_Sym; - - -/* Relocation table entry without addend (in section of type SHT_REL). */ - -typedef struct -{ - uint32_t r_offset; /* Address */ - uint32_t r_info; /* Relocation type and symbol index */ -} Elf32_Rel; - -/* I have seen two different definitions of the Elf64_Rel and - Elf64_Rela structures, so we'll leave them out until Novell (or - whoever) gets their act together. */ -/* The following, at least, is used on Sparc v9, MIPS, and Alpha. */ - -typedef struct -{ - uint64_t r_offset; /* Address */ - uint64_t r_info; /* Relocation type and symbol index */ -} Elf64_Rel; - -/* Relocation table entry with addend (in section of type SHT_RELA). */ - -typedef struct -{ - uint32_t r_offset; /* Address */ - uint32_t r_info; /* Relocation type and symbol index */ - int32_t r_addend; /* Addend */ -} Elf32_Rela; - -typedef struct -{ - uint64_t r_offset; /* Address */ - uint64_t r_info; /* Relocation type and symbol index */ - int64_t r_addend; /* Addend */ -} Elf64_Rela; - -/* How to extract and insert information held in the r_info field. */ - -#define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) - -#define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define ELF64_R_INFO(sym,type)((((uint64_t) (sym)) << 32) + (type)) - -#endif /* ELF_H */ diff --git a/ps3/gcmgl/src/libelf/readelf.c b/ps3/gcmgl/src/libelf/readelf.c deleted file mode 100644 index 6a45d902a1..0000000000 --- a/ps3/gcmgl/src/libelf/readelf.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Spu simulator library - ELF reader. - * AUTHORS: Antoine Labour, Robin Green - * DATE: 2003-Oct-16 - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include "readelf.h" - -const Elf32_Sym *getSymbolByIndex(const ELF_t *elf,int idx) -{ - if(!elf) - return NULL; - - if(elf->symbolsSection<=0) - return NULL; - - ELF_section_t *section=elf->sections+elf->symbolsSection; - - if(!section->data) - return NULL; - - if ((idx<0) || (idx>=(int)elf->symbolCount)) - return NULL; - - return(Elf32_Sym *)(section->data+section->header.sh_entsize*idx); -} - -int lookupSymbol(const ELF_t *elf,const char *name) -{ - unsigned int i; - - if(!elf||!name) - return -1; - - ELF_symbol_t *symbol=elf->symbols; - - if(!symbol) - return -1; - - for (i = 0; i < elf->symbolCount; ++i, ++symbol) - if (strcmp(name,symbol->name)==0) - return i; - return -1; -} - -static const char *_getStringTable(const Elf32_Ehdr *ehdr) -{ - const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff; - const Elf32_Shdr *shstrtabHeader = (const Elf32_Shdr*)sectionHeaderStart + ehdr->e_shstrndx; - return (const char*)ehdr + shstrtabHeader->sh_offset; -} - -const char *findSectionInPlace(const char* memory, const char *name, size_t *sectionSize) -{ - const Elf32_Ehdr *ehdr = (const Elf32_Ehdr*)memory; - - //first get the string section header - const char *shstrtab = _getStringTable(ehdr); - - //find the section - size_t sectionCount = ehdr->e_shnum; - const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff; - - for (size_t i=0;ish_name; - if (!strcmp(name,sectionName)) - { - *sectionSize = sectionHeader->sh_size; - return (const char*)ehdr + sectionHeader->sh_offset; - } - } - return NULL; -} - -const char *findSymbolSectionInPlace(const char *memory, size_t *symbolSize, size_t *symbolCount, const char **symbolstrtab) -{ - const Elf32_Ehdr *ehdr = (const Elf32_Ehdr*)memory; - - //find the section - size_t sectionCount = ehdr->e_shnum; - const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff; - - for (size_t i = 0; i < sectionCount; i++) - { - const Elf32_Shdr *sectionHeader = (const Elf32_Shdr *)sectionHeaderStart + i; - if (sectionHeader->sh_type == SHT_SYMTAB) - { - *symbolSize = sectionHeader->sh_entsize; - *symbolCount = sectionHeader->sh_size / sectionHeader->sh_entsize; - - const Elf32_Shdr *symbolStrHeader = (const Elf32_Shdr *)sectionHeaderStart + sectionHeader->sh_link; - *symbolstrtab = (const char*)ehdr + symbolStrHeader->sh_offset; - return (const char*)ehdr + sectionHeader->sh_offset; - } - } - - return NULL; -} - - -int lookupSymbolValueInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, const char *name) -{ - for (size_t i=0;ist_name, name)) - return elf_sym->st_value; - symbolSection+= symbolSize; - } - return -1; -} - -const char *getSymbolByIndexInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, int index) -{ - Elf32_Sym* elf_sym = (Elf32_Sym*)symbolSection + index; - return symbolstrtab + elf_sym->st_name; -} diff --git a/ps3/gcmgl/src/libelf/readelf.h b/ps3/gcmgl/src/libelf/readelf.h deleted file mode 100644 index f09bbda8ca..0000000000 --- a/ps3/gcmgl/src/libelf/readelf.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef READELF_H -#define READELF_H - -#include "elf.h" - -#ifdef __cplusplus -extern "C" { -#endif - - typedef struct _ELF_section_t - { - Elf32_Shdr header; - const char* name; - char* data; - } ELF_section_t; - - typedef struct _ELF_segment_t - { - Elf32_Phdr header; - unsigned char* pointer; - unsigned char* data; - } ELF_segment_t; - - typedef struct - { - const char* name; - unsigned int vma; - unsigned int size; - int section; - unsigned char resolved; - unsigned char foreign; - } ELF_symbol_t; - - typedef struct _ELF_t - { - unsigned int endian; - unsigned int relocatable; - unsigned int sectionCount; - unsigned int segmentCount; - unsigned int symbolCount; - unsigned int entrypoint; - ELF_section_t* sections; - ELF_segment_t* segments; - ELF_symbol_t* symbols; - unsigned int symbolsSection; - unsigned int symbolNamesSection; - unsigned int paramSection; - } ELF_t; - - typedef struct - { - unsigned int relative; - unsigned int shift; - unsigned int size; - unsigned int position; - unsigned int mask; - } ELF_rel_type_t; - - ELF_t* readElfFromFile(const char* filename); - ELF_t* readElfFromMemory(const char* memory,unsigned int size); - ELF_section_t* findSection(const ELF_t* elf,const char* name); - int lookupSymbol(const ELF_t* elf,const char* name); - int lookupResolvedSymbol(const ELF_t* elf,const char* name); - const Elf32_Sym* getSymbolByIndex(const ELF_t* elf,int idx); - int resolveElf(ELF_t* main_elf,ELF_t* elf); - int relocateSymbols(ELF_t* elf,unsigned int origin); - int loadSectionsToMemory(ELF_t* elf,char* memory,int memorySize,unsigned int origin); - void doRelocations(ELF_t* elf,char* memory,int memorySize,int origin,const ELF_rel_type_t* rel_types,unsigned int rel_types_count); - int loadElfToMemory(unsigned char* memory, unsigned int size, unsigned int load_address, ELF_t* elf); - void freeElf(ELF_t* elf); - - //in place API - const char *findSectionInPlace(const char* memory, const char *name,size_t *sectionSize); - const char *findSymbolSectionInPlace(const char *memory, size_t *symbolSize, size_t *symbolCount, const char **symbolstrtab); - int lookupSymbolValueInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, const char *name); - const char *getSymbolByIndexInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, int index); - - void spuDoRelocations(ELF_t* elf,char* memory,int memorySize,int origin); - - uint16_t endian_half(int endian, uint16_t v); - uint32_t endian_word(int endian, uint32_t v); - -#define endian_addr(e, v) endian_word(e, v) -#define endian_off(e, v) endian_word(e, v) -#define endian_size(e, v) endian_half(e, v) - -#ifdef __cplusplus -} -#endif - -#endif // READELF_H diff --git a/ps3/gcmgl/src/rgl.h b/ps3/gcmgl/src/rgl.h deleted file mode 100644 index be529324f2..0000000000 --- a/ps3/gcmgl/src/rgl.h +++ /dev/null @@ -1,63 +0,0 @@ -/* RetroArch - A frontend for libretro. - * RGL - An OpenGL subset wrapper library. - * Copyright (C) 2012 - Hans-Kristian Arntzen - * Copyright (C) 2012 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#ifndef _RGL_H -#define _RGL_H - -#include "../include/export/PSGL/psgl.h" -#include "../include/PSGL/Types.h" -#include "../include/PSGL/TypeUtils.h" -#include "../include/PSGL/private.h" -#include "../include/PSGL/Utils.h" -#include -#include -#include - -#include - -// endian swapping of the fragment uniforms, if necessary -#define SWAP_IF_BIG_ENDIAN(arg) endianSwapWordByHalf(arg) - -#ifdef __cplusplus -extern "C" { -#endif - -void rglPsglPlatformInit (void *data); -void rglPsglPlatformExit (void); - -RGL_EXPORT RGLdevice* rglPlatformCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode ); -RGL_EXPORT RGLdevice* rglPlatformCreateDeviceExtended (const void *data); -RGL_EXPORT GLfloat rglPlatformGetDeviceAspectRatio (const void *data); - - -GLboolean rglPlatformBufferObjectUnmapTextureReference (void *data); -GLboolean rglpCreateBufferObject (void *data); -GLboolean rglGcmFifoReferenceInUse (void *data, GLuint reference); -GLuint rglGcmFifoPutReference (void *data); -void rglGcmGetTileRegionInfo (void *data, GLuint *address, GLuint *size); -GLboolean rglGcmTryResizeTileRegion( GLuint address, GLuint size, void *data); - -int32_t rglOutOfSpaceCallback (void *data, uint32_t spaceInWords); -void rglGcmFifoGlSetRenderTarget (const void *args); -void rglCreatePushBuffer (void *data); -void rglGcmFreeTiledSurface (GLuint bufferId); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ps3/gcmgl/src/rgl_cg.h b/ps3/gcmgl/src/rgl_cg.h deleted file mode 100644 index 2e72af11a8..0000000000 --- a/ps3/gcmgl/src/rgl_cg.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _RGL_CG_H -#define _RGL_CG_H - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "../include/export/PSGL/psgl.h" -#include "../include/PSGL/private.h" -#include "../include/PSGL/Types.h" -#include "../include/PSGL/Utils.h" -#include "libelf/readelf.h" - -#include "cg/cgbtypes.h" -#include "cg/cgnv2rt.h" - -#include "cg/cgbio.hpp" -#include "cg/nvbiimpl.hpp" -#include "cg/cgbutils.hpp" -#include "cg/cgbtypes.h" - -typedef struct -{ - const char* elfFile; - size_t elfFileSize; - - const char *symtab; - size_t symbolSize; - size_t symbolCount; - const char *symbolstrtab; - - const char* shadertab; - size_t shadertabSize; - const char* strtab; - size_t strtabSize; - const char* consttab; - size_t consttabSize; -} CGELFBinary; - -typedef struct -{ - const char *texttab; - size_t texttabSize; - const char *paramtab; - size_t paramtabSize; - int index; -} CGELFProgram; - -extern int rglpCopyProgram (void *src_data, void *dst_data); -extern int rglpGenerateFragmentProgram (void *data, - const CgProgramHeader *programHeader, const void *ucode, - const CgParameterTableHeader *parameterHeader, - const char *stringTable, const float *defaultValues ); - -extern int rglpGenerateVertexProgram (void *data, - const CgProgramHeader *programHeader, const void *ucode, - const CgParameterTableHeader *parameterHeader, const char *stringTable, - const float *defaultValues ); - -extern CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, - int refcount ); - -extern void rglpProgramErase (void *data); - -extern bool cgOpenElf( const void *ptr, size_t size, CGELFBinary *elfBinary ); -extern bool cgGetElfProgramByIndex( CGELFBinary *elfBinary, int index, CGELFProgram *elfProgram ); - -extern CGprogram rglCgCreateProgram( CGcontext ctx, CGprofile profile, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues ); - -#endif diff --git a/ps3/gcmgl/src/rgl_ps3.cpp b/ps3/gcmgl/src/rgl_ps3.cpp deleted file mode 100644 index 38658ff02e..0000000000 --- a/ps3/gcmgl/src/rgl_ps3.cpp +++ /dev/null @@ -1,4432 +0,0 @@ -#include -#include -#include "rgl.h" - -#include - -#include "include/GmmAlloc.h" -#include "include/rgl-typedefs.h" -#include "include/rgl-inline.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -static GLuint nvFenceCounter = 0; - -// the global instance of the rglGcmState_i structure -rglGcmState rglGcmState_i; - -#define NAME_INCREMENT 4 -#define CAPACITY_INCREMENT 16 - -static void rglInitNameSpace(void *data) -{ - rglNameSpace *name = (rglNameSpace*)data; - name->data = NULL; - name->firstFree = NULL; - name->capacity = 0; -} - -static void rglFreeNameSpace(void *data) -{ - rglNameSpace *name = (rglNameSpace*)data; - - if (name->data) - free(name->data); - - name->data = NULL; - name->capacity = 0; - name->firstFree = NULL; -} - -unsigned int rglCreateName(void *data, void* object) -{ - rglNameSpace *name = (rglNameSpace*)data; - // NULL is reserved for the guard of the linked list. - if (!name->firstFree) - { - // need to allocate more pointer space - int newCapacity = name->capacity + NAME_INCREMENT; - - // realloc the block of pointers - void** newData = ( void** )malloc( newCapacity * sizeof( void* ) ); - if (!newData) - return 0; - memcpy( newData, name->data, name->capacity * sizeof( void* ) ); - - if (name->data) - free (name->data); - - name->data = newData; - - // initialize the pointers to the next free elements. - // (effectively build a linked list of free elements in place) - // treat the last item differently, by linking it to NULL - for ( int index = name->capacity; index < newCapacity - 1; ++index ) - name->data[index] = name->data + index + 1; - - name->data[newCapacity - 1] = NULL; - // update the first free element to the new data pointer. - name->firstFree = name->data + name->capacity; - // update the new capacity. - name->capacity = newCapacity; - } - // firstFree is a pointer, compute the index of it - unsigned int result = name->firstFree - name->data; - - // update the first free to the next free element. - name->firstFree = (void**)*name->firstFree; - - // store the object in data. - name->data[result] = object; - - // offset the index by 1 to avoid the name 0 - return result + 1; -} - -unsigned int rglIsName (void *data, unsigned int name ) -{ - rglNameSpace *ns = (rglNameSpace*)data; - // there should always be a namespace - // 0 is never valid. - if (RGL_UNLIKELY(name == 0)) - return 0; - - // names start numbering from 1, so convert from a name to an index - --name; - - // test whether it is in the namespace range - if ( RGL_UNLIKELY( name >= ns->capacity ) ) - return 0; - - // test whether the pointer is inside the data block. - // if so, it means it is free. - // if it points to NULL, it means it is the last free name in the linked list. - void** value = ( void** )ns->data[name]; - - if ( RGL_UNLIKELY(value == NULL || - ( value >= ns->data && value < ns->data + ns->capacity ) ) ) - return 0; - - // The pointer is not free and allocated, so name is a real name. - return 1; -} - -void rglEraseName(void *data, unsigned int name ) -{ - rglNameSpace *ns = (rglNameSpace*)data; - if (rglIsName(ns, name)) - { - --name; - ns->data[name] = ns->firstFree; - ns->firstFree = ns->data + name; - } -} - -// Initialize texture namespace ns with creation and destruction functions -static void rglTexNameSpaceInit(void *data, - rglTexNameSpaceCreateFunction create, - rglTexNameSpaceDestroyFunction destroy) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - ns->capacity = CAPACITY_INCREMENT; - ns->data = (void **)calloc(ns->capacity, sizeof(void*)); - ns->create = create; - ns->destroy = destroy; -} - -// Free texture namespace ns -static void rglTexNameSpaceFree(void *data) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - for (GLuint i = 1;i < ns->capacity; ++i) - if (ns->data[i]) - ns->destroy( ns->data[i] ); - - free( ns->data ); - ns->data = NULL; -} - -// Reset all names in namespace ns to NULL -void rglTexNameSpaceResetNames(void *data) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - for ( GLuint i = 1;i < ns->capacity;++i ) - { - if ( ns->data[i] ) - { - ns->destroy( ns->data[i] ); - ns->data[i] = NULL; - } - } -} - -// Get an index of the first free name in namespace ns -static GLuint rglTexNameSpaceGetFree(void *data) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - GLuint i; - - for (i = 1;i < ns->capacity;++i) - if (!ns->data[i]) - break; - return i; -} - -// Add name to namespace by increasing capacity and calling creation call back function -// Return GL_TRUE for success, GL_FALSE for failure -GLboolean rglTexNameSpaceCreateNameLazy(void *data, GLuint name ) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - if (name >= ns->capacity) - { - int newCapacity = name >= ns->capacity + CAPACITY_INCREMENT ? name + 1 : ns->capacity + CAPACITY_INCREMENT; - void **newData = ( void ** )realloc( ns->data, newCapacity * sizeof( void * ) ); - memset( newData + ns->capacity, 0, ( newCapacity - ns->capacity )*sizeof( void * ) ); - ns->data = newData; - ns->capacity = newCapacity; - } - if ( !ns->data[name] ) - { - ns->data[name] = ns->create(); - if (ns->data[name]) - return GL_TRUE; - } - return GL_FALSE; -} - -// Check if name is a valid name in namespace ns -// Return GL_TRUE if so, GL_FALSE otherwise -GLboolean rglTexNameSpaceIsName(void *data, GLuint name ) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - if ((name > 0) && (name < ns->capacity)) - return( ns->data[name] != 0 ); - return GL_FALSE; -} - -// Generate new n names in namespace ns -static void rglTexNameSpaceGenNames(void *data, GLsizei n, GLuint *names ) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - for ( int i = 0;i < n;++i ) - { - GLuint name = rglTexNameSpaceGetFree( ns ); - names[i] = name; - if (name) - rglTexNameSpaceCreateNameLazy( ns, name ); - } -} - -// Delete n names from namespace ns -void rglTexNameSpaceDeleteNames(void *data, GLsizei n, const GLuint *names ) -{ - rglTexNameSpace *ns = (rglTexNameSpace*)data; - - for ( int i = 0;i < n;++i ) - { - GLuint name = names[i]; - if (!rglTexNameSpaceIsName(ns, name)) - continue; - ns->destroy( ns->data[name] ); - ns->data[name] = NULL; - } -} - -/*============================================================ - MEMORY MANAGER - ============================================================ */ - -GmmAllocator *pGmmLocalAllocator = NULL; -static volatile uint32_t *pLock = NULL; -static uint32_t cachedLockValue = 0; -static GmmFixedAllocData *pGmmFixedAllocData = NULL; - -#define PAD(x, pad) ((x + pad - 1) / pad * pad) - -static uint32_t gmmInitFixedAllocator(void) -{ - - pGmmFixedAllocData = (GmmFixedAllocData *)calloc(1, sizeof(GmmFixedAllocData)); - - if (!pGmmFixedAllocData) - return GMM_ERROR; - - for (int i=0; i<2; i++) - { - int blockCount = (i==0) ? GMM_BLOCK_COUNT : GMM_TILE_BLOCK_COUNT; - int blockSize = (i==0) ? sizeof(GmmBlock): sizeof(GmmTileBlock); - - pGmmFixedAllocData->ppBlockList[i] = (char **)malloc(sizeof(char *)); - if (!pGmmFixedAllocData->ppBlockList[i]) - return GMM_ERROR; - - pGmmFixedAllocData->ppBlockList[i][0] = (char *)malloc(blockSize * blockCount); - if (!pGmmFixedAllocData->ppBlockList[i][0]) - return GMM_ERROR; - - pGmmFixedAllocData->ppFreeBlockList[i] = (uint16_t **)malloc(sizeof(uint16_t *)); - if (!pGmmFixedAllocData->ppFreeBlockList[i]) - return GMM_ERROR; - - pGmmFixedAllocData->ppFreeBlockList[i][0] = (uint16_t *)malloc(sizeof(uint16_t) * blockCount); - if (!pGmmFixedAllocData->ppFreeBlockList[i][0]) - return GMM_ERROR; - - pGmmFixedAllocData->pBlocksUsed[i] = (uint16_t *)malloc(sizeof(uint16_t)); - if (!pGmmFixedAllocData->pBlocksUsed[i]) - return GMM_ERROR; - - for (int j=0; jppFreeBlockList[i][0][j] = j; - - pGmmFixedAllocData->pBlocksUsed[i][0] = 0; - pGmmFixedAllocData->BlockListCount[i] = 1; - } - - return CELL_OK; -} - -static void *gmmAllocFixed(uint8_t isTile) -{ - int blockCount = isTile ? GMM_TILE_BLOCK_COUNT : GMM_BLOCK_COUNT; - int blockSize = isTile ? sizeof(GmmTileBlock) : sizeof(GmmBlock); - int listCount = pGmmFixedAllocData->BlockListCount[isTile]; - - for (int i=0; ipBlocksUsed[isTile][i] < blockCount) - { - return pGmmFixedAllocData->ppBlockList[isTile][i] + - (pGmmFixedAllocData->ppFreeBlockList[isTile][i][pGmmFixedAllocData->pBlocksUsed[isTile][i]++] * - blockSize); - } - } - - char **ppBlockList = - (char **)realloc(pGmmFixedAllocData->ppBlockList[isTile], - (listCount + 1) * sizeof(char *)); - - if (!ppBlockList) - return NULL; - - pGmmFixedAllocData->ppBlockList[isTile] = ppBlockList; - - pGmmFixedAllocData->ppBlockList[isTile][listCount] = - (char *)malloc(blockSize * blockCount); - - if (!pGmmFixedAllocData->ppBlockList[isTile][listCount]) - return NULL; - - uint16_t **ppFreeBlockList = - (uint16_t **)realloc(pGmmFixedAllocData->ppFreeBlockList[isTile], - (listCount + 1) * sizeof(uint16_t *)); - - if (!ppFreeBlockList) - return NULL; - - pGmmFixedAllocData->ppFreeBlockList[isTile] = ppFreeBlockList; - - pGmmFixedAllocData->ppFreeBlockList[isTile][listCount] = - (uint16_t *)malloc(sizeof(uint16_t) * blockCount); - - if (!pGmmFixedAllocData->ppFreeBlockList[isTile][listCount]) - return NULL; - - uint16_t *pBlocksUsed = - (uint16_t *)realloc(pGmmFixedAllocData->pBlocksUsed[isTile], - (listCount + 1) * sizeof(uint16_t)); - - if (!pBlocksUsed) - return NULL; - - pGmmFixedAllocData->pBlocksUsed[isTile] = pBlocksUsed; - - for (int i=0; ippFreeBlockList[isTile][listCount][i] = i; - - pGmmFixedAllocData->pBlocksUsed[isTile][listCount] = 0; - pGmmFixedAllocData->BlockListCount[isTile]++; - - return pGmmFixedAllocData->ppBlockList[isTile][listCount] + - (pGmmFixedAllocData->ppFreeBlockList[isTile][listCount][pGmmFixedAllocData->pBlocksUsed[isTile][listCount]++] * - blockSize); -} - -static void gmmFreeFixed(uint8_t isTile, void *pBlock) -{ - int blockCount = isTile ? GMM_TILE_BLOCK_COUNT : GMM_BLOCK_COUNT; - int blockSize = isTile ? sizeof(GmmTileBlock) : sizeof(GmmBlock); - uint8_t found = 0; - - for (int i=0; iBlockListCount[isTile]; i++) - { - if (pBlock >= pGmmFixedAllocData->ppBlockList[isTile][i] && - pBlock < (pGmmFixedAllocData->ppBlockList[isTile][i] + blockSize * blockCount)) - { - int index = ((char *)pBlock - pGmmFixedAllocData->ppBlockList[isTile][i]) / blockSize; - pGmmFixedAllocData->ppFreeBlockList[isTile][i][--pGmmFixedAllocData->pBlocksUsed[isTile][i]] = index; - found = 1; - } - } -} - -static void gmmDestroyFixedAllocator (void) -{ - if (pGmmFixedAllocData) - { - for (int i=0; i<2; i++) - { - for(int j=0; jBlockListCount[i]; j++) - { - free(pGmmFixedAllocData->ppBlockList[i][j]); - free(pGmmFixedAllocData->ppFreeBlockList[i][j]); - } - free(pGmmFixedAllocData->ppBlockList[i]); - free(pGmmFixedAllocData->ppFreeBlockList[i]); - free(pGmmFixedAllocData->pBlocksUsed[i]); - } - - free(pGmmFixedAllocData); - pGmmFixedAllocData = NULL; - } -} - -#define GMM_ALLOC_FIXED_BLOCK() ((GmmBlock*)gmmAllocFixed(0)) - -static uint32_t gmmInit(const void *localMemoryBase, const void *localStartAddress, - const uint32_t localSize) -{ - GmmAllocator *pAllocator; - uint32_t alignedLocalSize; - uint32_t localEndAddress = (uint32_t)localStartAddress + localSize; - - localEndAddress = (localEndAddress / GMM_TILE_ALIGNMENT) * GMM_TILE_ALIGNMENT; - - alignedLocalSize = localEndAddress - (uint32_t)localStartAddress; - - pAllocator = (GmmAllocator *)calloc(1, sizeof(GmmAllocator)); - - if (!pAllocator) - return GMM_ERROR; - - pAllocator->memoryBase = (uint32_t)localMemoryBase; - pAllocator->startAddress = (uint32_t)localStartAddress; - pAllocator->size = alignedLocalSize; - pAllocator->freeAddress = pAllocator->startAddress; - pAllocator->tileStartAddress = ((uint32_t)localStartAddress) + alignedLocalSize; - pAllocator->totalSize = alignedLocalSize; - - pGmmLocalAllocator = pAllocator; - - pLock = cellGcmGetLabelAddress(GMM_PPU_WAIT_INDEX); - *pLock = 0; - cachedLockValue = 0; - - return gmmInitFixedAllocator(); -} - -uint32_t gmmDestroy (void) -{ - GmmBlock *pBlock, *pTmpBlock; - GmmTileBlock *pTileBlock, *pTmpTileBlock; - GmmAllocator *pAllocator; - - pAllocator = pGmmLocalAllocator; - - { - if (pAllocator) - { - pBlock = pAllocator->pHead; - - while (pBlock) - { - pTmpBlock = pBlock; - pBlock = pBlock->pNext; - gmmFreeFixedBlock(pTmpBlock); - } - - pTileBlock = pAllocator->pTileHead; - - while (pTileBlock) - { - pTmpTileBlock = pTileBlock; - pTileBlock = pTileBlock->pNext; - gmmFreeFixedTileBlock(pTmpTileBlock); - } - - free(pAllocator); - } - } - - pGmmLocalAllocator = NULL; - - gmmDestroyFixedAllocator(); - - return CELL_OK; -} - -char *gmmIdToAddress (const uint32_t id) -{ - while ((cachedLockValue = *pLock) != 0); - return (char *)((GmmBaseBlock*)id)->address; -} - -static GmmBlock *gmmAllocBlock( - GmmAllocator *pAllocator, - uint32_t size - ) -{ - uint32_t address; - GmmBlock *pNewBlock = NULL; - GmmBlock *pBlock = pAllocator->pTail; - - address = pAllocator->freeAddress; - - if (UINT_MAX - address >= size && - address + size <= pAllocator->startAddress + pAllocator->size) - { - pNewBlock = GMM_ALLOC_FIXED_BLOCK(); - if (!pNewBlock) - return NULL; - - memset(pNewBlock, 0, sizeof(GmmBlock)); - - pNewBlock->base.address = address; - pNewBlock->base.size = size; - pAllocator->freeAddress = address + size; - - if (pBlock) - { - pNewBlock->pPrev = pBlock; - pBlock->pNext = pNewBlock; - } - else - { - pAllocator->pHead = pNewBlock; - } - pAllocator->pTail = pNewBlock; - } - - return pNewBlock; -} - -static GmmTileBlock *gmmFindFreeTileBlock( - GmmAllocator *pAllocator, - const uint32_t size - ) -{ - GmmTileBlock *pBlock = pAllocator->pTileHead; - GmmTileBlock *pBestAfterBlock = NULL; - GmmTileBlock *pNewBlock = NULL; - uint32_t bestSize = 0; - uint32_t freeSize = 0; - - while (pBlock && pBlock->pNext) - { - freeSize = pBlock->pNext->base.address - pBlock->base.address - pBlock->base.size; - - if (freeSize >= size && - (pBestAfterBlock == NULL || freeSize < bestSize) && - (pBlock->pNext == NULL || - pBlock->pData != pBlock->pNext->pData)) - { - pBestAfterBlock = pBlock; - bestSize = freeSize; - } - - pBlock = pBlock->pNext; - } - - if (pBestAfterBlock) - { - pNewBlock = gmmAllocFixedTileBlock(); - if (!pNewBlock) - return NULL; - - memset(pNewBlock, 0, sizeof(GmmTileBlock)); - - pNewBlock->base.address = pBestAfterBlock->base.address + pBestAfterBlock->base.size; - pNewBlock->base.isTile = 1; - pNewBlock->base.size = size; - - pNewBlock->pNext = pBestAfterBlock->pNext; - pNewBlock->pPrev = pBestAfterBlock; - pNewBlock->pPrev->pNext = pNewBlock; - pNewBlock->pNext->pPrev = pNewBlock; - - return pNewBlock; - } - return NULL; -} - -static GmmTileBlock *gmmCreateTileBlock( - GmmAllocator *pAllocator, - const uint32_t size - ) -{ - GmmTileBlock *pNewBlock; - uint32_t address; - - address = pAllocator->tileStartAddress - size; - - if (address > pAllocator->startAddress + pAllocator->size) - return NULL; - - if (pAllocator->pTail && - pAllocator->pTail->base.address + pAllocator->pTail->base.size > address) - return NULL; - - pAllocator->size = address - pAllocator->startAddress; - pAllocator->tileSize = pAllocator->tileStartAddress + pAllocator->tileSize - address; - pAllocator->tileStartAddress = address; - - pNewBlock = (GmmTileBlock*)gmmAllocFixedTileBlock(); - if (!pNewBlock) - return NULL; - - memset(pNewBlock, 0, sizeof(GmmTileBlock)); - - pNewBlock->base.address = address; - pNewBlock->base.isTile = 1; - pNewBlock->base.size = size; - pNewBlock->pNext = pAllocator->pTileHead; - - if (pAllocator->pTileHead) - pAllocator->pTileHead->pPrev = pNewBlock; - else - pAllocator->pTileTail = pNewBlock; - pAllocator->pTileHead = pNewBlock; - - return pNewBlock; -} - -static void gmmFreeTileBlock (void *data) -{ - GmmTileBlock *pTileBlock = (GmmTileBlock*)data; - GmmAllocator *pAllocator; - - if (pTileBlock->pPrev) - pTileBlock->pPrev->pNext = pTileBlock->pNext; - - if (pTileBlock->pNext) - pTileBlock->pNext->pPrev = pTileBlock->pPrev; - - pAllocator = pGmmLocalAllocator; - - if (pAllocator->pTileHead == pTileBlock) - { - pAllocator->pTileHead = pTileBlock->pNext; - - if (pAllocator->pTileHead) - pAllocator->pTileHead->pPrev = NULL; - - uint32_t prevSize; - prevSize = pAllocator->size; - pAllocator->size = pAllocator->pTileHead ? - pAllocator->pTileHead->base.address - pAllocator->startAddress : - pAllocator->totalSize; - pAllocator->tileSize = pAllocator->totalSize - pAllocator->size; - pAllocator->tileStartAddress = pAllocator->pTileHead ? - pAllocator->pTileHead->base.address : - pAllocator->startAddress + pAllocator->size; - } - - if (pAllocator->pTileTail == pTileBlock) - { - pAllocator->pTileTail = pTileBlock->pPrev; - - if (pAllocator->pTileTail) - pAllocator->pTileTail->pNext = NULL; - } - - gmmFreeFixedTileBlock(pTileBlock); -} - -static uint32_t gmmAllocExtendedTileBlock(const uint32_t size, const uint32_t tag) -{ - GmmAllocator *pAllocator; - uint32_t retId = 0; - uint32_t newSize; - uint8_t resizeSucceed = 1; - - - pAllocator = pGmmLocalAllocator; - - - newSize = PAD(size, GMM_TILE_ALIGNMENT); - - GmmTileBlock *pBlock = pAllocator->pTileTail; - - while (pBlock) - { - if (pBlock->tileTag == tag) - { - GLuint address, tileSize; - rglGcmGetTileRegionInfo(pBlock->pData, &address, &tileSize); - - if ((pBlock->pNext && pBlock->pNext->base.address-pBlock->base.address-pBlock->base.size >= newSize) || - (pBlock->pPrev && pBlock->base.address-pBlock->pPrev->base.address-pBlock->pPrev->base.size >= newSize)) - { - GmmTileBlock *pNewBlock = gmmAllocFixedTileBlock(); - if (!pNewBlock) - break; - - retId = (uint32_t)pNewBlock; - - memset(pNewBlock, 0, sizeof(GmmTileBlock)); - - pNewBlock->base.isTile = 1; - pNewBlock->base.size = newSize; - - if (pBlock->pNext && pBlock->pNext->base.address-pBlock->base.address-pBlock->base.size >= newSize) - { - pNewBlock->base.address = pBlock->base.address+pBlock->base.size; - pNewBlock->pNext = pBlock->pNext; - pNewBlock->pPrev = pBlock; - pBlock->pNext->pPrev = pNewBlock; - pBlock->pNext = pNewBlock; - - if (pNewBlock->pPrev->pData != pNewBlock->pNext->pData) - resizeSucceed = rglGcmTryResizeTileRegion( address, tileSize+newSize, pBlock->pData ); - } - else - { - pNewBlock->base.address = pBlock->base.address-newSize; - pNewBlock->pNext = pBlock; - pNewBlock->pPrev = pBlock->pPrev; - pBlock->pPrev->pNext = pNewBlock; - pBlock->pPrev = pNewBlock; - - if (pNewBlock->pPrev->pData != pNewBlock->pNext->pData) - resizeSucceed = rglGcmTryResizeTileRegion( (GLuint)gmmIdToOffset((uint32_t)pNewBlock), tileSize+newSize, pBlock->pData ); - } - gmmSetTileAttrib(retId, tag, pBlock->pData); - break; - } - - if (pBlock == pAllocator->pTileHead) - { - retId = (uint32_t)gmmCreateTileBlock(pAllocator, newSize); - if (retId == 0) - break; - - resizeSucceed = rglGcmTryResizeTileRegion( (GLuint)gmmIdToOffset(retId), tileSize+newSize, pBlock->pData ); - gmmSetTileAttrib( retId, tag, pBlock->pData ); - break; - } - } - - pBlock = pBlock->pPrev; - } - - if (retId == 0) - return GMM_ERROR; - - if (!resizeSucceed) - { - gmmFreeTileBlock((GmmTileBlock *)retId); - return GMM_ERROR; - } - - return retId; -} - -static void gmmFreeBlock (void *data) -{ - GmmBlock *pBlock = (GmmBlock*)data; - GmmAllocator *pAllocator; - - if (pBlock->pPrev) - pBlock->pPrev->pNext = pBlock->pNext; - - if (pBlock->pNext) - pBlock->pNext->pPrev = pBlock->pPrev; - - pAllocator = pGmmLocalAllocator; - - if (pAllocator->pHead == pBlock) - { - pAllocator->pHead = pBlock->pNext; - - if (pAllocator->pHead) - pAllocator->pHead->pPrev = NULL; - } - - if (pAllocator->pTail == pBlock) - { - pAllocator->pTail = pBlock->pPrev; - - if (pAllocator->pTail) - pAllocator->pTail->pNext = NULL; - } - - if (!pBlock->pPrev) - pAllocator->pSweepHead = pAllocator->pHead; - else if (pBlock->pPrev && - (pAllocator->pSweepHead == NULL || - (pAllocator->pSweepHead && - pAllocator->pSweepHead->base.address > pBlock->pPrev->base.address))) - pAllocator->pSweepHead = pBlock->pPrev; - - pAllocator->freedSinceSweep += pBlock->base.size; - - gmmFreeFixedBlock(pBlock); -} - -static void gmmAddPendingFree (void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - GmmBlock *pBlock = (GmmBlock*)data; - GmmAllocator *pAllocator; - - pAllocator = pGmmLocalAllocator; - - pBlock->pNextFree = NULL; - - if (pAllocator->pPendingFreeTail) - { - pBlock->pPrevFree = pAllocator->pPendingFreeTail; - pAllocator->pPendingFreeTail->pNextFree = pBlock; - } - else - { - pBlock->pPrevFree = NULL; - pAllocator->pPendingFreeHead = pBlock; - } - pAllocator->pPendingFreeTail = pBlock; - - pBlock->isPinned = 0; - - ++nvFenceCounter; - - /* semaphore ID : RGLGCM_SEMA_FENCE, new fence value: nvFenceCounter */ - rglGcmSetWriteBackEndLabel(thisContext, RGLGCM_SEMA_FENCE, nvFenceCounter ); - - pBlock->fence = nvFenceCounter; -} - -static uint8_t gmmSizeToFreeIndex(uint32_t size) -{ - if (size >= GMM_FREE_BIN_0 && size < GMM_FREE_BIN_1) - return 0; - if (size >= GMM_FREE_BIN_1 && size < GMM_FREE_BIN_2) - return 1; - if (size >= GMM_FREE_BIN_2 && size < GMM_FREE_BIN_3) - return 2; - if (size >= GMM_FREE_BIN_3 && size < GMM_FREE_BIN_4) - return 3; - if (size >= GMM_FREE_BIN_4 && size < GMM_FREE_BIN_5) - return 4; - if (size >= GMM_FREE_BIN_5 && size < GMM_FREE_BIN_6) - return 5; - if (size >= GMM_FREE_BIN_6 && size < GMM_FREE_BIN_7) - return 6; - if (size >= GMM_FREE_BIN_7 && size < GMM_FREE_BIN_8) - return 7; - if (size >= GMM_FREE_BIN_8 && size < GMM_FREE_BIN_9) - return 8; - if (size >= GMM_FREE_BIN_9 && size < GMM_FREE_BIN_10) - return 9; - if (size >= GMM_FREE_BIN_10 && size < GMM_FREE_BIN_11) - return 10; - if (size >= GMM_FREE_BIN_11 && size < GMM_FREE_BIN_12) - return 11; - if (size >= GMM_FREE_BIN_12 && size < GMM_FREE_BIN_13) - return 12; - if (size >= GMM_FREE_BIN_13 && size < GMM_FREE_BIN_14) - return 13; - if (size >= GMM_FREE_BIN_14 && size < GMM_FREE_BIN_15) - return 14; - if (size >= GMM_FREE_BIN_15 && size < GMM_FREE_BIN_16) - return 15; - if (size >= GMM_FREE_BIN_16 && size < GMM_FREE_BIN_17) - return 16; - if (size >= GMM_FREE_BIN_17 && size < GMM_FREE_BIN_18) - return 17; - if (size >= GMM_FREE_BIN_18 && size < GMM_FREE_BIN_19) - return 18; - if (size >= GMM_FREE_BIN_19 && size < GMM_FREE_BIN_20) - return 19; - if (size >= GMM_FREE_BIN_20 && size < GMM_FREE_BIN_21) - return 20; - return 21; -} - -static void gmmAddFree(GmmAllocator *pAllocator, GmmBlock *pBlock) -{ - uint8_t freeIndex = gmmSizeToFreeIndex(pBlock->base.size); - - if (pAllocator->pFreeHead[freeIndex]) - { - GmmBlock *pInsertBefore = pAllocator->pFreeHead[freeIndex]; - - while (pInsertBefore && pInsertBefore->base.size < pBlock->base.size) - pInsertBefore = pInsertBefore->pNextFree; - - if (!pInsertBefore) - { - pBlock->pNextFree = NULL; - pBlock->pPrevFree = pAllocator->pFreeTail[freeIndex]; - pAllocator->pFreeTail[freeIndex]->pNextFree = pBlock; - pAllocator->pFreeTail[freeIndex] = pBlock; - } - else if (pInsertBefore == pAllocator->pFreeHead[freeIndex]) - { - pBlock->pNextFree = pInsertBefore; - pBlock->pPrevFree = pInsertBefore->pPrevFree; - pInsertBefore->pPrevFree = pBlock; - pAllocator->pFreeHead[freeIndex] = pBlock; - } - else - { - pBlock->pNextFree = pInsertBefore; - pBlock->pPrevFree = pInsertBefore->pPrevFree; - pInsertBefore->pPrevFree->pNextFree = pBlock; - pInsertBefore->pPrevFree = pBlock; - } - } - else - { - pBlock->pNextFree = NULL; - pBlock->pPrevFree = NULL; - pAllocator->pFreeHead[freeIndex] = pBlock; - pAllocator->pFreeTail[freeIndex] = pBlock; - } -} - -uint32_t gmmFree(const uint32_t freeId) -{ - GmmBaseBlock *pBaseBlock = (GmmBaseBlock *)freeId; - - if (pBaseBlock->isTile) - { - GmmTileBlock *pTileBlock = (GmmTileBlock *)pBaseBlock; - - if (pTileBlock->pPrev && - pTileBlock->pNext && - pTileBlock->pPrev->pData == pTileBlock->pNext->pData) - { - } - else if (pTileBlock->pPrev && pTileBlock->pPrev->pData == pTileBlock->pData) - { - GLuint address, size; - - rglGcmGetTileRegionInfo(pTileBlock->pData, &address, &size); - if ( !rglGcmTryResizeTileRegion(address, (size-pTileBlock->base.size), pTileBlock->pData) ) - { - rglGcmTryResizeTileRegion(address, 0, pTileBlock->pData); - if ( !rglGcmTryResizeTileRegion(address, (size-pTileBlock->base.size), pTileBlock->pData) ) - { - } - } - } - else if (pTileBlock->pNext && pTileBlock->pNext->pData == pTileBlock->pData) - { - GLuint address, size; - - rglGcmGetTileRegionInfo(pTileBlock->pData, &address, &size); - if ( !rglGcmTryResizeTileRegion((address+pTileBlock->base.size), (size-pTileBlock->base.size), pTileBlock->pData) ) - { - rglGcmTryResizeTileRegion(address, 0, pTileBlock->pData); - if ( !rglGcmTryResizeTileRegion((address+pTileBlock->base.size), (size-pTileBlock->base.size), pTileBlock->pData) ) - { - } - } - } - else - { - if ( !rglGcmTryResizeTileRegion( (GLuint)gmmIdToOffset(freeId), 0, gmmGetTileData(freeId) ) ) - { - } - } - - gmmFreeTileBlock(pTileBlock); - } - else - { - GmmBlock *pBlock = (GmmBlock *)pBaseBlock; - - gmmAddPendingFree(pBlock); - } - - return CELL_OK; -} - -static inline void gmmLocalMemcpy(void *data, const uint32_t dstOffset, - const uint32_t srcOffset, const uint32_t moveSize) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)data; - int32_t offset = 0; - int32_t sizeLeft = moveSize; - int32_t dimension = 4096; - - while (sizeLeft) - { - while(sizeLeft >= dimension*dimension*4) - { - rglGcmSetTransferImage(thisContext, - CELL_GCM_TRANSFER_LOCAL_TO_LOCAL, - dstOffset+offset, - dimension*4, - 0, - 0, - srcOffset+offset, - dimension*4, - 0, - 0, - dimension, - dimension, - 4); - - offset = offset + dimension*dimension*4; - sizeLeft -= (dimension*dimension*4); - } - - dimension = dimension >> 1; - - if (dimension == 32) - break; - } - - if (sizeLeft) - { - rglGcmSetTransferImage(thisContext, - CELL_GCM_TRANSFER_LOCAL_TO_LOCAL, - dstOffset+offset, - sizeLeft, - 0, - 0, - srcOffset+offset, - sizeLeft, - 0, - 0, - sizeLeft/4, - 1, - 4); - } -} - -static inline void gmmMemcpy(void *data, const uint8_t mode, - const uint32_t dstOffset, const uint32_t srcOffset, - const uint32_t moveSize) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)data; - - if (dstOffset + moveSize <= srcOffset) - gmmLocalMemcpy(thisContext, - dstOffset, - srcOffset, - moveSize); - else - { - uint32_t moveBlockSize = srcOffset-dstOffset; - uint32_t iterations = (moveSize+moveBlockSize-1)/moveBlockSize; - - for (uint32_t i=0; ipSweepHead; - GmmBlock *pSrcBlock = pBlock; - GmmBlock *pTempBlock; - GmmBlock *pTempBlockNext; - uint32_t dstAddress = 0; - uint32_t srcAddress = 0; - uint32_t srcOffset, dstOffset; - uint32_t prevEndAddress = 0; - uint32_t moveSize, moveDistance; - uint8_t mode = CELL_GCM_TRANSFER_LOCAL_TO_LOCAL; - uint8_t ret = 0; - uint32_t totalMoveSize = 0; - - while (pBlock) - { - if (pBlock->isPinned == 0) - { - if (pBlock->pPrev) - prevEndAddress = pBlock->pPrev->base.address + pBlock->pPrev->base.size; - else - prevEndAddress = pAllocator->startAddress; - - if (pBlock->base.address > prevEndAddress) - { - dstAddress = prevEndAddress; - srcAddress = pBlock->base.address; - pSrcBlock = pBlock; - } - - moveSize = pBlock->base.address + pBlock->base.size - srcAddress; - - if (srcAddress > dstAddress && - (pBlock->pNext == NULL || - pBlock->pNext->base.address > pBlock->base.address + pBlock->base.size || - pBlock->pNext->isPinned)) - { - dstOffset = GMM_ADDRESS_TO_OFFSET(dstAddress); - srcOffset = GMM_ADDRESS_TO_OFFSET(srcAddress); - - totalMoveSize += moveSize; - - gmmMemcpy(thisContext, - mode, - dstOffset, - srcOffset, - moveSize); - - pTempBlock = pSrcBlock; - - moveDistance = srcOffset - dstOffset; - - while (pTempBlock != pBlock->pNext) - { - pTempBlock->base.address -= moveDistance; - pTempBlock = pTempBlock->pNext; - } - } - } - else - { - uint32_t availableSize; - - srcAddress = 0; - dstAddress = 0; - - if (!pBlock->pPrev) - availableSize = pBlock->base.address - pAllocator->startAddress; - else - availableSize = pBlock->base.address - (pBlock->pPrev->base.address + pBlock->pPrev->base.size); - - pTempBlock = pBlock->pNext; - - while (availableSize >= GMM_ALIGNMENT && - pTempBlock) - { - pTempBlockNext = pTempBlock->pNext; - - if (pTempBlock->isPinned == 0 && - pTempBlock->base.size <= availableSize) - { - uint32_t pinDstAddress = (pBlock->pPrev == NULL) ? - pAllocator->startAddress : - pBlock->pPrev->base.address + pBlock->pPrev->base.size; - uint32_t pinSrcAddress = pTempBlock->base.address; - - dstOffset = GMM_ADDRESS_TO_OFFSET(pinDstAddress); - srcOffset = GMM_ADDRESS_TO_OFFSET(pinSrcAddress); - - totalMoveSize += pTempBlock->base.size; - - gmmMemcpy(thisContext, - mode, - dstOffset, - srcOffset, - pTempBlock->base.size); - - pTempBlock->base.address = pinDstAddress; - - if (pTempBlock == pAllocator->pTail) - { - if (pTempBlock->pNext) - pAllocator->pTail = pTempBlock->pNext; - else - pAllocator->pTail = pTempBlock->pPrev; - } - - if (pTempBlock->pNext) - pTempBlock->pNext->pPrev = pTempBlock->pPrev; - if (pTempBlock->pPrev) - pTempBlock->pPrev->pNext = pTempBlock->pNext; - - if (pBlock->pPrev) - pBlock->pPrev->pNext = pTempBlock; - else - pAllocator->pHead = pTempBlock; - pTempBlock->pPrev = pBlock->pPrev; - pTempBlock->pNext = pBlock; - pBlock->pPrev = pTempBlock; - } - - if (pBlock->pPrev) - availableSize = pBlock->base.address - (pBlock->pPrev->base.address + pBlock->pPrev->base.size); - - pTempBlock = pTempBlockNext; - } - - if (availableSize > 0) - { - GmmBlock *pNewBlock = GMM_ALLOC_FIXED_BLOCK(); - - if (pNewBlock) - { - memset(pNewBlock, 0, sizeof(GmmBlock)); - pNewBlock->base.address = pBlock->base.address - availableSize; - pNewBlock->base.size = availableSize; - pNewBlock->pNext = pBlock; - pNewBlock->pPrev = pBlock->pPrev; - if (pBlock->pPrev) - pBlock->pPrev->pNext = pNewBlock; - - pBlock->pPrev = pNewBlock; - - if (pBlock == pAllocator->pHead) - pAllocator->pHead = pNewBlock; - - gmmAddFree(pAllocator, pNewBlock); - - ret = 1; - } - } - } - - pBlock = pBlock->pNext; - } - - uint32_t newFreeAddress = pAllocator->pTail ? - pAllocator->pTail->base.address + pAllocator->pTail->base.size : - pAllocator->startAddress; - - if (pAllocator->freeAddress != newFreeAddress) - { - pAllocator->freeAddress = newFreeAddress; - ret = 1; - } - - pAllocator->freedSinceSweep = 0; - pAllocator->pSweepHead = NULL; - - return ret; -} - -static void gmmFreeAll(void) -{ - GmmBlock *pBlock; - GmmBlock *pTemp; - GmmAllocator *pAllocator = pGmmLocalAllocator; - - pBlock = pAllocator->pPendingFreeHead; - while (pBlock) - { - pTemp = pBlock->pNextFree; - gmmFreeBlock(pBlock); - pBlock = pTemp; - } - pAllocator->pPendingFreeHead = NULL; - pAllocator->pPendingFreeTail = NULL; - - for (int i=0; ipFreeHead[i]; - while (pBlock) - { - pTemp = pBlock->pNextFree; - gmmFreeBlock(pBlock); - pBlock = pTemp; - } - pAllocator->pFreeHead[i] = NULL; - pAllocator->pFreeTail[i] = NULL; - } -} - -static void gmmAllocSweep(void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - gmmFreeAll(); - - if (gmmInternalSweep(thisContext)) - { - *pLock = 1; - cachedLockValue = 1; - rglGcmSetWriteBackEndLabel(thisContext, GMM_PPU_WAIT_INDEX, 0); - - rglGcmFlush(thisContext); - } -} - -static void gmmRemoveFree( - GmmAllocator *pAllocator, - GmmBlock *pBlock, - uint8_t freeIndex - ) -{ - if (pBlock == pAllocator->pFreeHead[freeIndex]) - pAllocator->pFreeHead[freeIndex] = pBlock->pNextFree; - - if (pBlock == pAllocator->pFreeTail[freeIndex]) - pAllocator->pFreeTail[freeIndex] = pBlock->pPrevFree; - - if (pBlock->pNextFree) - pBlock->pNextFree->pPrevFree = pBlock->pPrevFree; - - if (pBlock->pPrevFree) - pBlock->pPrevFree->pNextFree = pBlock->pNextFree; -} - -static uint32_t gmmFindFreeBlock( - GmmAllocator *pAllocator, - uint32_t size - ) -{ - uint32_t retId = GMM_ERROR; - GmmBlock *pBlock; - uint8_t found = 0; - uint8_t freeIndex = gmmSizeToFreeIndex(size); - - pBlock = pAllocator->pFreeHead[freeIndex]; - - while (freeIndex < GMM_NUM_FREE_BINS) - { - if (pBlock) - { - if (pBlock->base.size >= size) - { - found = 1; - break; - } - pBlock = pBlock->pNextFree; - } - else if (++freeIndex < GMM_NUM_FREE_BINS) - pBlock = pAllocator->pFreeHead[freeIndex]; - } - - if (found) - { - if (pBlock->base.size != size) - { - GmmBlock *pNewBlock = GMM_ALLOC_FIXED_BLOCK(); - if (!pNewBlock) - return GMM_ERROR; - - memset(pNewBlock, 0, sizeof(GmmBlock)); - pNewBlock->base.address = pBlock->base.address + size; - pNewBlock->base.size = pBlock->base.size - size; - pNewBlock->pNext = pBlock->pNext; - pNewBlock->pPrev = pBlock; - if (pBlock->pNext) - pBlock->pNext->pPrev = pNewBlock; - pBlock->pNext = pNewBlock; - - if (pBlock == pAllocator->pTail) - pAllocator->pTail = pNewBlock; - - gmmAddFree(pAllocator, pNewBlock); - } - pBlock->base.size = size; - gmmRemoveFree(pAllocator, pBlock, freeIndex); - retId = (uint32_t)pBlock; - } - - return retId; -} - -uint32_t gmmAlloc(const uint32_t size) -{ - GmmAllocator *pAllocator = pGmmLocalAllocator; - uint32_t newSize = PAD(size, GMM_ALIGNMENT); - uint32_t retId = gmmFindFreeBlock(pAllocator, newSize); - - if (retId == GMM_ERROR) - { - retId = (uint32_t)gmmAllocBlock(pAllocator, newSize); - - if (retId == GMM_ERROR) - { - gmmAllocSweep((CellGcmContextData*)&rglGcmState_i.fifo); - retId = (uint32_t)gmmAllocBlock(pAllocator, newSize); - - if (retId == GMM_ERROR) - retId = gmmFindFreeBlock(pAllocator, newSize); - } - } - - return retId; -} - -uint32_t gmmAllocTiled(const uint32_t size) -{ - GmmAllocator *pAllocator = pGmmLocalAllocator; - uint32_t newSize = PAD(size, GMM_TILE_ALIGNMENT); - uint32_t retId = GMM_ERROR; - GmmTileBlock *pBlock = gmmFindFreeTileBlock(pAllocator, newSize); - - retId = (uint32_t)gmmAllocTileBlock(pAllocator, newSize, pBlock); - - if (retId == GMM_ERROR) - { - gmmAllocSweep((CellGcmContextData*)&rglGcmState_i.fifo); - pBlock = gmmFindFreeTileBlock(pAllocator, newSize); - retId = (uint32_t)gmmAllocTileBlock(pAllocator, newSize, pBlock); - } - - return retId; -} - -/*============================================================ - FIFO BUFFER - ============================================================ */ - -GLuint rglGcmFifoPutReference (void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmFifo *fifo = (rglGcmFifo*)data; - GLuint ref; - unsigned int offset_bytes = 0; - - fifo->lastSWReferenceWritten++; - - rglGcmSetReferenceCommand(thisContext, fifo->lastSWReferenceWritten ); - - if (( fifo->lastSWReferenceWritten & 0x7fffffff ) == 0 ) - { - rglGcmFifoFinish(fifo, ref, offset_bytes); - } - - return fifo->lastSWReferenceWritten; -} - -GLboolean rglGcmFifoReferenceInUse (void *data, GLuint reference) -{ - rglGcmFifo *fifo = (rglGcmFifo*)data; - // compare against cached hw ref value (accounting wrap) - if ( !(( fifo->lastHWReferenceRead - reference ) & 0x80000000 ) ) - return GL_FALSE; - - // has the reference already been flushed out ? - if (( fifo->lastSWReferenceFlushed - reference ) & 0x80000000 ) - { - unsigned int offset_bytes = 0; - rglGcmFifoFlush(fifo, offset_bytes); - } - - // read current hw reference - rglGcmFifoReadReference(fifo); - - // compare against hw ref value (accounting wrap) - if ( !(( fifo->lastHWReferenceRead - reference ) & 0x80000000 ) ) - return GL_FALSE; - - return GL_TRUE; -} - -void rglGcmFifoInit (void *data, void *dmaControl, uint32_t dmaPushBufferOffset, uint32_t*dmaPushBuffer, - GLuint dmaPushBufferSize ) -{ - rglGcmFifo *fifo = (rglGcmFifo*)data; - - // init fifoBlockSize - fifo->fifoBlockSize = DEFAULT_FIFO_BLOCK_SIZE; - - // init fifo context pointers to first fifo block which will be set at the the dmaPushPuffer position - fifo->ctx.begin = (uint32_t*) dmaPushBuffer; - fifo->ctx.end = fifo->ctx.begin + ( fifo->fifoBlockSize / sizeof( uint32_t ) ) - 1; - // init rest of context - fifo->ctx.current = fifo->ctx.begin; - fifo->lastGetRead = fifo->ctx.current; - fifo->lastPutWritten = fifo->ctx.current; - - // store fifo values - fifo->dmaPushBufferBegin = dmaPushBuffer; - fifo->dmaPushBufferEnd = (uint32_t*)(( size_t )dmaPushBuffer + dmaPushBufferSize ) - 1; - fifo->dmaControl = (rglGcmControlDma*)dmaControl; - fifo->dmaPushBufferOffset = dmaPushBufferOffset; - fifo->dmaPushBufferSizeInWords = dmaPushBufferSize / sizeof(uint32_t); - - fifo->lastHWReferenceRead = 0; - fifo->lastSWReferenceWritten = 0; - fifo->lastSWReferenceFlushed = 0; - - gCellGcmCurrentContext = &fifo->ctx; - // setting our own out of space callback here to handle our fifo - gCellGcmCurrentContext->callback = ( CellGcmContextCallback )rglOutOfSpaceCallback; - - // ensure the ref is initted to 0. - if ( rglGcmFifoReadReference( fifo ) != 0 ) - { - unsigned int offset_bytes = 0; - rglGcmSetReferenceCommand(gCellGcmCurrentContext, 0 ); - rglGcmFifoFlush(fifo, offset_bytes); // Here, we jump to this new buffer - - // a finish that waits for 0 specifically. - while (rglGcmFifoReadReference(fifo) != 0); - } - fifo->dmaPushBufferGPU = dmaPushBuffer; - fifo->spuid = 0; - -} - -/*============================================================ - GL INITIALIZATION - ============================================================ */ - -GLboolean rglGcmInitFromRM( rglGcmResource *rmResource ) -{ - rglGcmState *rglGcmSt = &rglGcmState_i; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmSt->fifo; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - GLuint i, ref; - unsigned int offset_bytes = 0; - - memset( rglGcmSt, 0, sizeof( *rglGcmSt ) ); - - rglGcmSt->localAddress = rmResource->localAddress; - rglGcmSt->hostMemoryBase = rmResource->hostMemoryBase; - rglGcmSt->hostMemorySize = rmResource->hostMemorySize; - - rglGcmSt->semaphores = rmResource->semaphores; - - rglGcmFifoInit( &rglGcmSt->fifo, rmResource->dmaControl, rmResource->dmaPushBufferOffset, (uint32_t*)rmResource->dmaPushBuffer, rmResource->dmaPushBufferSize ); - - rglGcmFifoFinish(fifo, ref, offset_bytes); - - // Set the GPU to a known state - // initialize the default OpenGL state - rglGcmSetBlendColor(thisContext, 0, 0); - rglGcmSetBlendEquation(thisContext, RGLGCM_FUNC_ADD, RGLGCM_FUNC_ADD ); - rglGcmSetBlendFunc(thisContext, RGLGCM_ONE, RGLGCM_ZERO, RGLGCM_ONE, RGLGCM_ZERO ); - rglGcmSetClearColor(thisContext, 0 ); - rglGcmSetBlendEnable(thisContext, false ); - rglGcmSetBlendEnableMrt(thisContext, false, false, false ); - - for ( i = 0; i < RGLGCM_ATTRIB_COUNT; i++ ) - { - rglGcmSetVertexDataArray(thisContext, i, 0, 0, 0, CELL_GCM_VERTEX_F, CELL_GCM_LOCATION_LOCAL, 0); - } - - rglGcmSetDitherEnable(thisContext, true ); - - for ( i = 0; i < CELL_GCM_MAX_TEXIMAGE_COUNT; i++ ) - { - static const GLuint borderColor = 0; - - // update the setTextureAddress Portion - rglGcmSetTextureAddress(thisContext, i, CELL_GCM_TEXTURE_WRAP, CELL_GCM_TEXTURE_WRAP, CELL_GCM_TEXTURE_CLAMP_TO_EDGE, CELL_GCM_TEXTURE_UNSIGNED_REMAP_NORMAL, CELL_GCM_TEXTURE_ZFUNC_NEVER, 0 ); - - // update the setTextureFilter Portion - rglGcmSetTextureFilter(thisContext, i, 0, CELL_GCM_TEXTURE_NEAREST_LINEAR, CELL_GCM_TEXTURE_LINEAR, CELL_GCM_TEXTURE_CONVOLUTION_QUINCUNX ); - - // update the texture control to setup anisotropic settings - rglGcmSetTextureControl(thisContext, i, CELL_GCM_TRUE, 0, 12 << 8, CELL_GCM_TEXTURE_MAX_ANISO_1 ); - - // update border color - rglGcmSetTextureBorderColor(thisContext, i, borderColor ); - } - - // Set zNear and zFar to the default 0.0f and 1.0f here - rglGcmViewportState *v = &rglGcmState_i.state.viewport; - v->x = 0; - v->y = 0; - v->w = CELL_GCM_MAX_RT_DIMENSION; - v->h = CELL_GCM_MAX_RT_DIMENSION; - rglGcmFifoGlViewport(v, 0.0f, 1.0f ); - - // wait for setup to complete - offset_bytes = 0; - rglGcmFifoFinish(fifo, ref, offset_bytes); - - return GL_TRUE; -} - -void rglGcmDestroy(void) -{ - rglGcmState *rglGcmSt = &rglGcmState_i; - memset( rglGcmSt, 0, sizeof( *rglGcmSt ) ); -} - -/*============================================================ - GCM UTILITIES - ============================================================ */ - -static GLuint MemoryClock = 0; -static GLuint GraphicsClock = 0; - -GLuint rglGcmGetMemoryClock(void) -{ - return MemoryClock; -} - -GLuint rglGcmGetGraphicsClock(void) -{ - return GraphicsClock; -} - -GLboolean rglGcmInit (void *opt_data, void *res_data) -{ - rglGcmResource *resource = (rglGcmResource*)res_data; - RGLinitOptions *options = (RGLinitOptions*)opt_data; - if ( !rglGcmInitFromRM( resource ) ) - { - fprintf( stderr, "RGL GCM failed initialisation" ); - return GL_FALSE; - } - MemoryClock = resource->MemoryClock; - GraphicsClock = resource->GraphicsClock; - - if ( gmmInit( resource->localAddress, // pass in the base address, which "could" diff from start address - resource->localAddress, - resource->localSize) == GMM_ERROR ) - { - fprintf( stderr, "Could not init GPU memory manager" ); - rglGcmDestroy(); - return GL_FALSE; - } - - // initialize DMA sync mechanism - // use one semaphore to implement fence - rglGcmSemaphoreMemory *semaphores = rglGcmState_i.semaphores; - semaphores->userSemaphores[RGLGCM_SEMA_FENCE].val = nvFenceCounter; - - // also need to init the labelValue for waiting for idle - rglGcmState_i.labelValue = 1; - - return GL_TRUE; -} - -void rglGcmAllocDestroy() -{ - gmmDestroy(); - - rglGcmDestroy(); -} - -/*============================================================ - PLATFORM INITIALIZATION - ============================================================ */ - -// resc is enabled by setting ANY of the resc related device parameters (using the enable mask) -static inline int rescIsEnabled (void *data) -{ - RGLdeviceParameters *params = (RGLdeviceParameters*)data; - return params->enable & ( RGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT | - RGL_DEVICE_PARAMETERS_RESC_RATIO_MODE | - RGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE | - RGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE | - RGL_DEVICE_PARAMETERS_RESC_ADJUST_ASPECT_RATIO ); -} - -/*============================================================ - DEVICE CONTEXT CREATION - ============================================================ */ - -static const RGLdeviceParameters defaultParameters = -{ -enable: 0, - colorFormat: GL_ARGB_SCE, - depthFormat: GL_NONE, - multisamplingMode: GL_MULTISAMPLING_NONE_SCE, - TVStandard: RGL_TV_STANDARD_NONE, - connector: RGL_DEVICE_CONNECTOR_NONE, - bufferingMode: RGL_BUFFERING_MODE_DOUBLE, - width: 0, - height: 0, - renderWidth: 0, - renderHeight: 0, - rescRatioMode: RESC_RATIO_MODE_LETTERBOX, - rescPalTemporalMode: RESC_PAL_TEMPORAL_MODE_50_NONE, - rescInterlaceMode: RESC_INTERLACE_MODE_NORMAL_BILINEAR, - horizontalScale: 1.0f, - verticalScale: 1.0f -}; - -static int rglInitCompleted = 0; - -RGL_EXPORT RGLdevice* rglPlatformCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode ) -{ - RGLdeviceParameters parameters; - parameters.enable = RGL_DEVICE_PARAMETERS_COLOR_FORMAT | RGL_DEVICE_PARAMETERS_DEPTH_FORMAT | RGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; - parameters.colorFormat = colorFormat; - parameters.depthFormat = depthFormat; - parameters.multisamplingMode = multisamplingMode; - return psglCreateDeviceExtended( ¶meters ); -} - -RGL_EXPORT RGLdevice* rglPlatformCreateDeviceExtended (const void *data) -{ - RGLdeviceParameters *parameters = (RGLdeviceParameters*)data; - RGLdevice *device = (RGLdevice*)calloc(1, sizeof( RGLdevice ) + sizeof( rglGcmDevice ) ); - - if ( !device ) - { - rglSetError( GL_OUT_OF_MEMORY ); - return NULL; - } - - // initialize fields - memcpy( &device->deviceParameters, parameters, sizeof( RGLdeviceParameters ) ); - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_COLOR_FORMAT ) == 0 ) - device->deviceParameters.colorFormat = defaultParameters.colorFormat; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_DEPTH_FORMAT ) == 0 ) - device->deviceParameters.depthFormat = defaultParameters.depthFormat; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE ) == 0 ) - device->deviceParameters.multisamplingMode = defaultParameters.multisamplingMode; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_TV_STANDARD ) == 0 ) - device->deviceParameters.TVStandard = defaultParameters.TVStandard; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_CONNECTOR ) == 0 ) - device->deviceParameters.connector = defaultParameters.connector; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_BUFFERING_MODE ) == 0 ) - device->deviceParameters.bufferingMode = defaultParameters.bufferingMode; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_WIDTH_HEIGHT ) == 0 ) - { - device->deviceParameters.width = defaultParameters.width; - device->deviceParameters.height = defaultParameters.height; - } - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT ) == 0 ) - { - device->deviceParameters.renderWidth = defaultParameters.renderWidth; - device->deviceParameters.renderHeight = defaultParameters.renderHeight; - } - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_RESC_RATIO_MODE ) == 0 ) - device->deviceParameters.rescRatioMode = defaultParameters.rescRatioMode; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE ) == 0 ) - device->deviceParameters.rescPalTemporalMode = defaultParameters.rescPalTemporalMode; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE ) == 0 ) - device->deviceParameters.rescInterlaceMode = defaultParameters.rescInterlaceMode; - - if (( parameters->enable & RGL_DEVICE_PARAMETERS_RESC_ADJUST_ASPECT_RATIO ) == 0 ) - { - device->deviceParameters.horizontalScale = defaultParameters.horizontalScale; - device->deviceParameters.verticalScale = defaultParameters.verticalScale; - } - - device->rasterDriver = NULL; - - // platform-specific initialization - // This creates the default framebuffer. - if ( rglPlatformCreateDevice(device) < 0 ) - { - free( device ); - return NULL; - } - return device; -} - -RGL_EXPORT GLfloat rglPlatformGetDeviceAspectRatio (const void *data) -{ - const RGLdevice *device = (const RGLdevice*)data; - CellVideoOutState videoState; - cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &videoState); - - switch (videoState.displayMode.aspect){ - case CELL_VIDEO_OUT_ASPECT_4_3: return 4.0f/3.0f; - case CELL_VIDEO_OUT_ASPECT_16_9: return 16.0f/9.0f; - }; - - return 16.0f/9.0f; -} - -/*============================================================ - DEVICE CONTEXT INITIALIZATION - ============================================================ */ - -#define RGLGCM_DMA_PUSH_BUFFER_PREFETCH_PADDING 0x1000 // 4KB -#define RGLGCM_FIFO_SIZE (64<<10) // 64 kb - -int32_t rglOutOfSpaceCallback (void *data, uint32_t spaceInWords) -{ - struct CellGcmContextData *fifoContext = (struct CellGcmContextData*)data; - rglGcmFifo * fifo = &rglGcmState_i.fifo; - - rglGcmFlush((CellGcmContextData*)fifo); - - uint32_t *nextbegin, *nextend, nextbeginoffset, nextendoffset; - - // make sure that the space requested will actually fit in to - // a single fifo block! - - fifoUpdateGetLastRead(fifo); - - // If the current end isn't the same as the full fifo end we - // aren't at the end. Just go ahead and set the next begin and end - if(fifo->ctx.end != fifo->dmaPushBufferEnd) - nextbegin = (uint32_t *)fifo->ctx.end + 1; - else - nextbegin = (uint32_t *)fifo->dmaPushBufferBegin; - nextend = nextbegin + (fifo->fifoBlockSize)/sizeof(uint32_t) - 1; - - cellGcmAddressToOffset(nextbegin, &nextbeginoffset); - cellGcmAddressToOffset(nextend, &nextendoffset); - - struct CellGcmContextData *thisContext = (CellGcmContextData*)fifo; - - //use this version so as not to trigger another callback - rglGcmSetJumpCommand(thisContext, nextbeginoffset); - - //set up new context - fifo->ctx.begin = nextbegin; - fifo->ctx.current = nextbegin; - fifo->ctx.end = nextend; - - //if Gpu busy with the new area, stall and flush - uint32_t get = fifo->dmaControl->Get; - - void * getEA = NULL; - - cellGcmIoOffsetToAddress( get, &getEA ); - - // We are going to stall on 3 things - // 1. If the get is still with in the new fifo block area - // 2. If the get is in gcm's initiazation fifo block - // 3. If the user stall call back returns RGL_STALL/true that - // 3A. the get is in one of their called SCB fifos AND 3B. the last call - // position in RGL's fifo is in the next block we want to jump to - // we have to stall... few! [RSTENSON] - while(((get >= nextbeginoffset) && (get <= nextendoffset)) - || ((0 <= get) && (get < 0x10000))) - { - get = fifo->dmaControl->Get; - cellGcmIoOffsetToAddress( get, &getEA ); - } - - // need to add some nops here at the beginning for a issue with the get and the put being at the - // same position when the fifo is in GPU memory. - for ( GLuint i = 0; i < 8; i++ ) - { - gcm_emit_at(fifo->ctx.current, 0, 0); - gcm_finish_n_commands(fifo->ctx.current, 1); - } - - return CELL_OK; -} - -void rglGcmDestroyRM( rglGcmResource* gcmResource ) -{ - if ( gcmResource->hostMemoryBase ) - free( gcmResource->hostMemoryBase ); - - memset(( void* )gcmResource, 0, sizeof( rglGcmResource ) ); -} - -static int rglGcmInitRM( rglGcmResource *gcmResource, int inSysMem, unsigned int dmaPushBufferSize ) -{ - memset( gcmResource, 0, sizeof( rglGcmResource ) ); - - // XXX currently we need to decide how much host memory is needed before we know the GPU type - // It sucks because we don't know if the push buffer is in host memory or not. - // So, assume that it is... - dmaPushBufferSize = rglPad( dmaPushBufferSize, RGLGCM_HOST_BUFFER_ALIGNMENT ); - - // in case of host push buffer we need to add padding to avoid GPU push buffer prefetch to - // cause a problem fetching invalid addresses at the end of the push buffer. - gcmResource->hostMemorySize = rglPad( RGLGCM_FIFO_SIZE + dmaPushBufferSize + RGLGCM_DMA_PUSH_BUFFER_PREFETCH_PADDING + (RGLGCM_LM_MAX_TOTAL_QUERIES * sizeof( GLuint )), 1 << 20 ); - - if (gcmResource->hostMemorySize) - gcmResource->hostMemoryBase = (char *)memalign( 1 << 20, gcmResource->hostMemorySize ); - - // Initialize RSXIF - // 64 KB is minimum fifo size for libgpu (for now) - if (cellGcmInit( RGLGCM_FIFO_SIZE, gcmResource->hostMemorySize, gcmResource->hostMemoryBase ) != 0) - { - fprintf( stderr, "RSXIF failed initialization\n" ); - return GL_FALSE; - } - - // Get Gpu configuration - CellGcmConfig config; - cellGcmGetConfiguration( &config ); - - gcmResource->localAddress = ( char * )config.localAddress; - gcmResource->localSize = config.localSize; - gcmResource->MemoryClock = config.memoryFrequency; - gcmResource->GraphicsClock = config.coreFrequency; - - gcmResource->semaphores = ( rglGcmSemaphoreMemory * )cellGcmGetLabelAddress( 0 ); - gcmResource->dmaControl = ( char* ) cellGcmGetControlRegister() - (( char * ) & (( rglGcmControlDma* )0 )->Put - ( char * )0 ); - - cellGcmFinish(gCellGcmCurrentContext, 1); - - gcmResource->hostMemorySize -= dmaPushBufferSize + RGLGCM_DMA_PUSH_BUFFER_PREFETCH_PADDING; - gcmResource->dmaPushBuffer = gcmResource->hostMemoryBase + gcmResource->hostMemorySize; - gcmResource->dmaPushBufferOffset = ( char * )gcmResource->dmaPushBuffer - ( char * )gcmResource->hostMemoryBase; - gcmResource->linearMemory = ( char* )0x0; - gcmResource->persistentMemorySize = gcmResource->localSize; - gcmResource->dmaPushBufferSize = dmaPushBufferSize; - - // Set Jump command to our fifo structure - const uint32_t offset = ( char * )gcmResource->dmaPushBuffer - ( char * )gcmResource->hostMemoryBase; - rglGcmSetJumpCommand(gCellGcmCurrentContext, offset); - - // Set our Fifo functions - gCellGcmCurrentContext->callback = ( CellGcmContextCallback )rglOutOfSpaceCallback; - - fprintf(stderr, "RGLGCM resource: MClk: %f Mhz NVClk: %f Mhz\n", ( float )gcmResource->MemoryClock / 1E6, ( float )gcmResource->GraphicsClock / 1E6 ); - fprintf(stderr, "RGLGCM resource: Video Memory: %i MB\n", gcmResource->localSize / ( 1024*1024 ) ); - fprintf(stderr, "RGLGCM resource: localAddress mapped at %p\n", gcmResource->localAddress ); - fprintf(stderr, "RGLGCM resource: push buffer at %p - %p (size = 0x%X), offset=0x%lx\n", - gcmResource->dmaPushBuffer, ( char* )gcmResource->dmaPushBuffer + gcmResource->dmaPushBufferSize, gcmResource->dmaPushBufferSize, gcmResource->dmaPushBufferOffset ); - fprintf(stderr, "RGLGCM resource: dma control at %p\n", gcmResource->dmaControl ); - - return 1; -} - -/*============================================================ - DEVICE CONTEXT IMPLEMENTATION - ============================================================ */ - -// tiled memory manager -typedef struct -{ - int id; - GLuint offset; - GLuint size; // 0 size indicates an unused tile - GLuint pitch; // in bytes - GLuint bank; -} rglTiledRegion; - -typedef struct -{ - rglTiledRegion region[RGLGCM_MAX_TILED_REGIONS]; -} rglTiledMemoryManager; - - -// TODO: put in device state? -static rglTiledMemoryManager rglGcmTiledMemoryManager; -static rglGcmResource rglGcmResource; - -void rglGcmTiledMemoryInit( void ) -{ - rglTiledMemoryManager* mm = &rglGcmTiledMemoryManager; - int32_t retVal; - - memset( mm->region, 0, sizeof( mm->region ) ); - for ( int i = 0;i < RGLGCM_MAX_TILED_REGIONS;++i ) - retVal = cellGcmUnbindTile( i ); -} - -GLboolean rglPlatformDeviceInit (void *data) -{ - RGLinitOptions *options = (RGLinitOptions*)data; - GLuint fifoSize = RGLGCM_FIFO_SIZE_DEFAULT; - - if (options) - { - if ( options->enable & RGL_INIT_FIFO_SIZE ) - fifoSize = options->fifoSize; - } - - if ( !rglGcmInitRM( &rglGcmResource, 0, fifoSize ) ) - { - fprintf( stderr, "RM resource failed initialisation\n" ); - return GL_FALSE; - } - - return rglGcmInit( options, &rglGcmResource ); -} - -void rglPlatformDeviceExit (void) -{ - rglGcmDestroy(); - rglGcmDestroyRM( &rglGcmResource ); -} - -///////////////////////////////////////////////////////////////////////////// - -static unsigned int validPitch[] = -{ - 0x0200, - 0x0300, - 0x0400, - 0x0500, - 0x0600, - 0x0700, - 0x0800, - 0x0A00, - 0x0C00, - 0x0D00, - 0x0E00, - 0x1000, - 0x1400, - 0x1800, - 0x1A00, - 0x1C00, - 0x2000, - 0x2800, - 0x3000, - 0x3400, - 0x3800, - 0x4000, - 0x5000, - 0x6000, - 0x6800, - 0x7000, - 0x8000, - 0xA000, - 0xC000, - 0xD000, - 0xE000, - 0x10000, -}; -static const unsigned int validPitchCount = sizeof( validPitch ) / sizeof( validPitch[0] ); - -static unsigned int findValidPitch( unsigned int pitch ) -{ - if (pitch <= validPitch[0]) - return validPitch[0]; - - // dummy linear search - for ( GLuint i = 0;i < validPitchCount - 1;++i ) - if (( pitch > validPitch[i] ) && ( pitch <= validPitch[i+1] ) ) - return validPitch[i+1]; - - return validPitch[validPitchCount-1]; -} - -static GLboolean rglDuringDestroyDevice = GL_FALSE; - -// region update callback -// This callback is passed to rglGcmAllocCreateRegion to notify when the -// region is resized or deleted. -GLboolean rglGcmTryResizeTileRegion( GLuint address, GLuint size, void* data ) -{ - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - rglTiledRegion* region = ( rglTiledRegion* )data; - int32_t retVal = 0; - GLuint ref; - unsigned int offset_bytes = 0; - - // delete always succeeds - if ( size == 0 ) - { - region->offset = 0; - region->size = 0; - region->pitch = 0; - - if ( ! rglDuringDestroyDevice ) - { - unsigned int offset_bytes = 0; - // must wait until RSX is completely idle before calling cellGcmUnbindTile - rglGcmUtilWaitForIdle(); - - retVal = cellGcmUnbindTile( region->id ); - rglGcmFifoFinish(fifo, ref, offset_bytes); - } - return GL_TRUE; - } - region->offset = address; - region->size = size; - - // must wait until RSX is completely idle before calling cellGcmSetTileInfo - rglGcmUtilWaitForIdle(); - - retVal = cellGcmSetTileInfo( - region->id, - CELL_GCM_LOCATION_LOCAL, - region->offset, - region->size, - region->pitch, - CELL_GCM_COMPMODE_DISABLED, // if no tag bits, disable compression - 0, - region->bank ); - - retVal = cellGcmBindTile( region->id ); - - offset_bytes = 0; - rglGcmFifoFinish(fifo, ref, offset_bytes); - return GL_TRUE; -} - -void rglGcmGetTileRegionInfo( void* data, GLuint *address, GLuint *size ) -{ - rglTiledRegion* region = ( rglTiledRegion* )data; - - *address = region->offset; - *size = region->size; -} - -#define RGLGCM_TILED_BUFFER_ALIGNMENT 0x10000 // 64KB -#define RGLGCM_TILED_BUFFER_HEIGHT_ALIGNMENT 64 - -GLuint rglGcmAllocCreateRegion( - GLuint size, - GLint tag, - void* data ) -{ - uint32_t id; - - if ((id = gmmAllocTiled(size)) != GMM_ERROR) - { - if ( rglGcmTryResizeTileRegion( (GLuint)gmmIdToOffset(id), gmmGetBlockSize(id), data ) ) - { - gmmSetTileAttrib( id, tag, data ); - } - else - { - gmmFree( id ); - id = GMM_ERROR; - } - } - - return id; -} - -///////////////////////////////////////////////////////////////////////////// -// tiled surface allocation - -static void rglGcmAllocateTiledSurface( - rglTiledMemoryManager* mm, - GLuint width, - GLuint height, - GLuint bitsPerPixel, - GLuint antiAliasing, - GLuint* id, - GLuint* pitchAllocated, - GLuint* bytesAllocated ) -{ - // determine pitch (in bytes) - const unsigned int pitch = width * bitsPerPixel / 8; - const unsigned int tiledPitch = findValidPitch( pitch ); - if ( tiledPitch < pitch ) - *pitchAllocated = rglPad( pitch, tiledPitch ); - else - *pitchAllocated = tiledPitch; - - // fix alignment - // Render targets must be aligned to 8*pitch from the start of their - // region. In addition, tiled regions must be aligned to 65536. In - // order to keep both requirements satisfied as the region is extended - // or shrunken, the allocation size is padded to the smallest common - // multiple. - // - // This can result in a fairly large percentage of wasted memory for - // certain dimension combinations, but this is simple and may conserve - // tiled region usage over some alternatives. - GLuint padSize = RGLGCM_TILED_BUFFER_ALIGNMENT; // 64KB - - while (( padSize % ( tiledPitch*8 ) ) != 0 ) - padSize += RGLGCM_TILED_BUFFER_ALIGNMENT; - - // determine allocation size - height = rglPad( height, RGLGCM_TILED_BUFFER_HEIGHT_ALIGNMENT ); - *bytesAllocated = rglPad(( *pitchAllocated ) * height, padSize ); - - // attempt to extend an existing region - // The region tag is a hash of the pitch, compression, and isZBuffer. - const GLuint tag = *pitchAllocated | 0; - - *id = gmmAllocExtendedTileBlock(*bytesAllocated, tag); - - if ( *id == GMM_ERROR ) - { - // find an unused region - for ( int i = 0; i < RGLGCM_MAX_TILED_REGIONS; ++i ) - { - if ( mm->region[i].size == 0 ) - { - // assign a region - // Address and size will be set in the callback. - mm->region[i].id = i; - mm->region[i].pitch = *pitchAllocated; - mm->region[i].bank = 0x0; // XXX experiment - - // allocate space for our region - *id = rglGcmAllocCreateRegion( - *bytesAllocated, - tag, - &mm->region[i] ); - - break; - } - } // loop to find an unused region - } - - // if we don't have a valid id, give up - if ( *id == GMM_ERROR ) - { - *bytesAllocated = 0; - *pitchAllocated = 0; - } -} - -///////////////////////////////////////////////////////////////////////////// -// color surface allocation - -GLboolean rglGcmAllocateColorSurface( - GLuint width, - GLuint height, - GLuint bitsPerPixel, - GLuint scanoutSupported, - GLuint antiAliasing, - GLuint *id, - GLuint *pitchAllocated, - GLuint *bytesAllocated ) -{ - rglTiledMemoryManager* mm = &rglGcmTiledMemoryManager; - - rglGcmAllocateTiledSurface(mm, width, height, bitsPerPixel, - antiAliasing, id, pitchAllocated, bytesAllocated ); - - return *bytesAllocated > 0; -} - -void rglGcmFreeTiledSurface( GLuint bufferId ) -{ - gmmFree( bufferId ); -} - -///////////////////////////////////////////////////////////////////////////// -// video mode selection - -typedef struct -{ - int width; - int height; - unsigned char hwMode; -} -VideoMode; - -static const VideoMode sysutilModes[] = -{ - {720, 480, CELL_VIDEO_OUT_RESOLUTION_480}, - {720, 576, CELL_VIDEO_OUT_RESOLUTION_576}, - {1280, 720, CELL_VIDEO_OUT_RESOLUTION_720}, - {1920, 1080, CELL_VIDEO_OUT_RESOLUTION_1080}, -#if (OS_VERSION_NUMERIC >= 0x150) - {1600, 1080, CELL_VIDEO_OUT_RESOLUTION_1600x1080}, // hardware scales to 1920x1080 from 1600x1080 buffer - {1440, 1080, CELL_VIDEO_OUT_RESOLUTION_1440x1080}, // hardware scales to 1920x1080 from 1440x1080 buffer - {1280, 1080, CELL_VIDEO_OUT_RESOLUTION_1280x1080}, // hardware scales to 1920x1080 from 1280x1080 buffer - {960, 1080, CELL_VIDEO_OUT_RESOLUTION_960x1080}, // hardware scales to 1920x1080 from 960x1080 buffer -#endif -}; -static const int sysutilModeCount = sizeof( sysutilModes ) / sizeof( sysutilModes[0] ); - -static const VideoMode *findModeByResolutionInTable( int width, int height, const VideoMode *table, int modeCount ) -{ - for ( int i = 0;i < modeCount;++i ) - { - const VideoMode *vm = table + i; - if (( vm->width == width ) && ( vm->height == height ) ) return vm; - } - return NULL; -} - -static inline const VideoMode *findModeByResolution( int width, int height ) -{ - return findModeByResolutionInTable( width, height, sysutilModes, sysutilModeCount ); -} - -static const VideoMode *findModeByEnum( GLenum TVStandard ) -{ - const VideoMode *vm = NULL; - switch ( TVStandard ) - { - case RGL_TV_STANDARD_NTSC_M: - case RGL_TV_STANDARD_NTSC_J: - case RGL_TV_STANDARD_HD480P: - case RGL_TV_STANDARD_HD480I: - vm = &(sysutilModes[0]); - break; - case RGL_TV_STANDARD_PAL_M: - case RGL_TV_STANDARD_PAL_B: - case RGL_TV_STANDARD_PAL_D: - case RGL_TV_STANDARD_PAL_G: - case RGL_TV_STANDARD_PAL_H: - case RGL_TV_STANDARD_PAL_I: - case RGL_TV_STANDARD_PAL_N: - case RGL_TV_STANDARD_PAL_NC: - case RGL_TV_STANDARD_HD576I: - case RGL_TV_STANDARD_HD576P: - vm = &(sysutilModes[1]); - break; - case RGL_TV_STANDARD_HD720P: - case RGL_TV_STANDARD_1280x720_ON_VESA_1280x768: - case RGL_TV_STANDARD_1280x720_ON_VESA_1280x1024: - vm = &(sysutilModes[2]); - break; - case RGL_TV_STANDARD_HD1080I: - case RGL_TV_STANDARD_HD1080P: - case RGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200: - vm = &(sysutilModes[3]); - break; - default: - vm = &(sysutilModes[2]); - break; // do nothing - } - - return vm; -} - -// XXX ugly global to be returned by the function -static VideoMode _sysutilDetectedVideoMode; - -const VideoMode *rglDetectVideoMode(void) -{ - CellVideoOutState videoState; - int ret = cellVideoOutGetState( CELL_VIDEO_OUT_PRIMARY, 0, &videoState ); - if ( ret < 0 ) - { - //RGL_REPORT_EXTRA( RGL_REPORT_ASSERT, "couldn't read the video configuration, using a default 720p resolution" ); - videoState.displayMode.scanMode = CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE; - videoState.displayMode.resolutionId = CELL_VIDEO_OUT_RESOLUTION_720; - } - CellVideoOutResolution resolution; - cellVideoOutGetResolution( videoState.displayMode.resolutionId, &resolution ); - - _sysutilDetectedVideoMode.width = resolution.width; - _sysutilDetectedVideoMode.height = resolution.height; - _sysutilDetectedVideoMode.hwMode = videoState.displayMode.resolutionId; - return &_sysutilDetectedVideoMode; -} - -static void rescInit( const RGLdeviceParameters* params, rglGcmDevice *gcmDevice ) -{ - //RGL_REPORT_EXTRA(RGL_REPORT_RESC,"WARNING: RESC is enabled."); - GLboolean result = 0; - - CellRescBufferMode dstBufferMode; - if ( params->width == 720 && params->height == 480 ) dstBufferMode = CELL_RESC_720x480; - else if ( params->width == 720 && params->height == 576 ) dstBufferMode = CELL_RESC_720x576; - else if ( params->width == 1280 && params->height == 720 ) dstBufferMode = CELL_RESC_1280x720; - else if ( params->width == 1920 && params->height == 1080 ) dstBufferMode = CELL_RESC_1920x1080; - else - { - dstBufferMode = CELL_RESC_720x480; - fprintf( stderr, "Invalid display resolution for resolution conversion: %ux%u. Defaulting to 720x480...\n", params->width, params->height ); - } - - CellRescInitConfig conf; - memset( &conf, 0, sizeof( CellRescInitConfig ) ); - conf.size = sizeof( CellRescInitConfig ); - conf.resourcePolicy = CELL_RESC_MINIMUM_GPU_LOAD | CELL_RESC_CONSTANT_VRAM; - conf.supportModes = CELL_RESC_720x480 | CELL_RESC_720x576 | CELL_RESC_1280x720 | CELL_RESC_1920x1080; - conf.ratioMode = ( params->rescRatioMode == RESC_RATIO_MODE_FULLSCREEN ) ? CELL_RESC_FULLSCREEN : - ( params->rescRatioMode == RESC_RATIO_MODE_PANSCAN ) ? CELL_RESC_PANSCAN : - CELL_RESC_LETTERBOX; - conf.palTemporalMode = ( params->rescPalTemporalMode == RESC_PAL_TEMPORAL_MODE_60_DROP ) ? CELL_RESC_PAL_60_DROP : - ( params->rescPalTemporalMode == RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE ) ? CELL_RESC_PAL_60_INTERPOLATE : - ( params->rescPalTemporalMode == RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_30_DROP ) ? CELL_RESC_PAL_60_INTERPOLATE_30_DROP : - ( params->rescPalTemporalMode == RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_DROP_FLEXIBLE ) ? CELL_RESC_PAL_60_INTERPOLATE_DROP_FLEXIBLE : - CELL_RESC_PAL_50; - conf.interlaceMode = ( params->rescInterlaceMode == RESC_INTERLACE_MODE_INTERLACE_FILTER ) ? CELL_RESC_INTERLACE_FILTER : - CELL_RESC_NORMAL_BILINEAR; - cellRescInit( &conf ); - - // allocate all the destination scanout buffers using the RGL memory manager - GLuint size; - GLuint colorBuffersPitch; - uint32_t numColorBuffers = cellRescGetNumColorBuffers( dstBufferMode, ( CellRescPalTemporalMode )conf.palTemporalMode, 0 ); - result = rglGcmAllocateColorSurface(params->width, params->height * numColorBuffers, - 4*8, true, 1, &(gcmDevice->RescColorBuffersId), &colorBuffersPitch, &size ); - - // set the destination buffer format and pitch - CellRescDsts dsts = { CELL_RESC_SURFACE_A8R8G8B8, colorBuffersPitch, 1 }; - cellRescSetDsts( dstBufferMode, &dsts ); - - // set the resc output display mode (destination format) - cellRescSetDisplayMode( dstBufferMode ); - - // allocate space for vertex array and fragment shader for drawing the rescaling texture-mapped quad - int32_t colorBuffersSize, vertexArraySize, fragmentShaderSize; - cellRescGetBufferSize( &colorBuffersSize, &vertexArraySize, &fragmentShaderSize ); - gcmDevice->RescVertexArrayId = gmmAlloc(vertexArraySize); - gcmDevice->RescFragmentShaderId = gmmAlloc(fragmentShaderSize); - - - // tell resc how to access the destination (scanout) buffer - cellRescSetBufferAddress( gmmIdToAddress(gcmDevice->RescColorBuffersId), - gmmIdToAddress(gcmDevice->RescVertexArrayId), - gmmIdToAddress(gcmDevice->RescFragmentShaderId) ); - - // scale to adjust for overscan - cellRescAdjustAspectRatio( params->horizontalScale, params->verticalScale ); - - // allocate an interlace table if interlace filtering is used - if ((params->enable & RGL_DEVICE_PARAMETERS_RESC_INTERLACE_MODE) && - (params->rescInterlaceMode == RESC_INTERLACE_MODE_INTERLACE_FILTER)) - { - const unsigned int tableLength = 32; // this was based on the guidelines in the resc reference guide - unsigned int tableSize = sizeof(uint16_t) * 4 * tableLength; // 2 bytes per FLOAT16 * 4 values per entry * length of table - void *interlaceTable = gmmIdToAddress(gmmAlloc(tableSize)); - int32_t errorCode = cellRescCreateInterlaceTable(interlaceTable,params->renderHeight,CELL_RESC_ELEMENT_HALF,tableLength); - (void)errorCode; - } -} - -// Semaphore for PPU wait -static sys_semaphore_t FlipSem; - -// A flip callback function to release semaphore and write a label to lock the GPU -static void rglFlipCallbackFunction(const uint32_t head) -{ - //printf("Flip callback: label value: %d -> 0\n", *labelAddress); - int res = sys_semaphore_post(FlipSem,1); - (void)res; // unused variable is ok -} - -// A label for GPU to skip VSYNC -static volatile uint32_t *labelAddress = NULL; -static const uint32_t WaitLabelIndex = 111; - -// VBlank callback function to write a label to release GPU -static void rglVblankCallbackFunction(const uint32_t head) -{ - (void)head; - int status = *labelAddress; - switch(status){ - case 2: - if (cellGcmGetFlipStatus()==0){ - cellGcmResetFlipStatus(); - *labelAddress=1; - } - break; - case 1: - *labelAddress = 0; - break; - default: - break; - // wait until rsx set the status to 2 - } -} - -// Resc version of VBlank callback function to write a label to release GPU -static void rglRescVblankCallbackFunction(const uint32_t head) -{ - (void)head; - int status = *labelAddress; - switch(status){ - case 2: - if (cellRescGetFlipStatus()==0){ - cellRescResetFlipStatus(); - *labelAddress=1; - } - break; - case 1: - *labelAddress = 0; - break; - default: - break; - // wait until rsx set the status to 2 - } -} - -///////////////////////////////////////////////////////////////////////////// -// create device - -static void rglSetDisplayMode( const VideoMode *vm, GLushort bitsPerPixel, GLuint pitch ) -{ - CellVideoOutConfiguration videocfg; - memset( &videocfg, 0, sizeof( videocfg ) ); - videocfg.resolutionId = vm->hwMode; - videocfg.format = ( bitsPerPixel == 32 ) ? CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_X8R8G8B8 : CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT; - videocfg.pitch = pitch; - videocfg.aspect = CELL_VIDEO_OUT_ASPECT_AUTO; - cellVideoOutConfigure( CELL_VIDEO_OUT_PRIMARY, &videocfg, NULL, 0 ); -} - -int rglPlatformCreateDevice (void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - RGLdevice *device = (RGLdevice*)data; - rglGcmDevice *gcmDevice = ( rglGcmDevice * )device->platformDevice; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - RGLdeviceParameters* params = &device->deviceParameters; - rglDuringDestroyDevice = GL_FALSE; - GLboolean result = 0; - GLuint ref; - - // Tile memory manager init - rglGcmTiledMemoryInit(); - - const VideoMode *vm = NULL; - if ( params->enable & RGL_DEVICE_PARAMETERS_TV_STANDARD ) - { - vm = findModeByEnum( params->TVStandard ); - if ( !vm ) return -1; - params->width = vm->width; - params->height = vm->height; - } - else if ( params->enable & RGL_DEVICE_PARAMETERS_WIDTH_HEIGHT ) - { - vm = findModeByResolution( params->width, params->height ); - if ( !vm ) return -1; - } - else - { - vm = rglDetectVideoMode(); - if ( !vm ) return -1; - params->width = vm->width; - params->height = vm->height; - } - - // set render width and height to match the display width and height, unless resolution conversion is specified - if ( !(params->enable & RGL_DEVICE_PARAMETERS_RESC_RENDER_WIDTH_HEIGHT) ) - { - params->renderWidth = params->width; - params->renderHeight = params->height; - } - - if (rescIsEnabled(params)) - rescInit( params, gcmDevice ); - - gcmDevice->deviceType = 0; - gcmDevice->TVStandard = params->TVStandard; - - // if resc enabled, vsync is always enabled - gcmDevice->vsync = rescIsEnabled( params ) ? GL_TRUE : GL_FALSE; - - gcmDevice->skipFirstVsync = GL_FALSE; - - gcmDevice->ms = NULL; - - const GLuint width = params->renderWidth; - const GLuint height = params->renderHeight; - - GLboolean fpColor = GL_FALSE; - switch ( params->colorFormat ) - { - case GL_RGBA16F_ARB: - fpColor = GL_TRUE; - break; - case GL_ARGB_SCE: - break; - // GL_RGBA ? - default: - return -1; - } - - GLuint antiAliasingMode=1; - - // create color buffers - // The default color buffer format is currently always ARGB8. - // single, double, or triple buffering - for ( int i = 0; i < params->bufferingMode; ++i ) - { - gcmDevice->color[i].source = RGLGCM_SURFACE_SOURCE_DEVICE; - gcmDevice->color[i].width = width; - gcmDevice->color[i].height = height; - gcmDevice->color[i].bpp = fpColor ? 8 : 4; - gcmDevice->color[i].format = RGLGCM_ARGB8; - gcmDevice->color[i].pool = RGLGCM_SURFACE_POOL_LINEAR; - - // allocate tiled memory - GLuint size; - result = rglGcmAllocateColorSurface( - width, height, // dimensions - gcmDevice->color[i].bpp*8, // bits per sample - true, // scan out enable - antiAliasingMode, // antiAliasing - &gcmDevice->color[i].dataId, // returned buffer - &gcmDevice->color[i].pitch, - &size ); - } - - memset( &gcmDevice->rt, 0, sizeof( rglGcmRenderTargetEx ) ); - gcmDevice->rt.colorBufferCount = 1; - gcmDevice->rt.yInverted = GL_TRUE; - gcmDevice->rt.width = width; - gcmDevice->rt.height = height; - - rglGcmViewportState *v = &rglGcmState_i.state.viewport; - v->x = 0; - v->y = 0; - v->w = width; - v->h = height; - rglGcmFifoGlViewport(v, 0.0f, 1.0f); - rglGcmSetClearColor(thisContext, 0 ); - - if ( fpColor ) - { - // we don't yet have a fragment program to clear the buffer with a quad. - // so we'll cheat pretending we have a RGBA buffer with twice the width. - // Since we clear with 0 (which is the same in fp16), it works. - - gcmDevice->rt.width = 2 * width; - gcmDevice->rt.colorFormat = RGLGCM_ARGB8; - for ( int i = 0; i < params->bufferingMode; ++i ) - { - gcmDevice->rt.colorId[0] = gcmDevice->color[i].dataId; - gcmDevice->rt.colorPitch[0] = gcmDevice->color[i].pitch; - rglGcmFifoGlSetRenderTarget( &gcmDevice->rt ); - - if (rglGcmState_i.renderTarget.colorFormat) - rglGcmSetClearSurface(thisContext, CELL_GCM_CLEAR_R | CELL_GCM_CLEAR_G | - CELL_GCM_CLEAR_B | CELL_GCM_CLEAR_A ); - } - // restore parameters - gcmDevice->rt.width = width; - gcmDevice->rt.colorFormat = gcmDevice->color[0].format; - } - else - { - // clear the buffers for compression to work best - gcmDevice->rt.colorFormat = RGLGCM_ARGB8; - for ( int i = 0; i < params->bufferingMode; ++i ) - { - gcmDevice->rt.colorId[0] = gcmDevice->color[i].dataId; - gcmDevice->rt.colorPitch[0] = gcmDevice->color[i].pitch; - rglGcmFifoGlSetRenderTarget( &gcmDevice->rt ); - - if (rglGcmState_i.renderTarget.colorFormat) - rglGcmSetClearSurface(thisContext, CELL_GCM_CLEAR_R | CELL_GCM_CLEAR_G | - CELL_GCM_CLEAR_B | CELL_GCM_CLEAR_A ); - } - } - - gcmDevice->scanBuffer = 0; - if ( params->bufferingMode == RGL_BUFFERING_MODE_SINGLE ) - gcmDevice->drawBuffer = 0; - else if ( params->bufferingMode == RGL_BUFFERING_MODE_DOUBLE ) - gcmDevice->drawBuffer = 1; - else if ( params->bufferingMode == RGL_BUFFERING_MODE_TRIPLE ) - gcmDevice->drawBuffer = 2; - - - // Create semaphore - sys_semaphore_attribute_t attr;//todo: configure - sys_semaphore_attribute_initialize(attr); - - // Set initial and max count of semaphore based on buffering mode - sys_semaphore_value_t initial_val = 0; - sys_semaphore_value_t max_val = 1; - switch (device->deviceParameters.bufferingMode) - { - case RGL_BUFFERING_MODE_SINGLE: - initial_val = 0; - max_val = 1; - break; - case RGL_BUFFERING_MODE_DOUBLE: - initial_val = 1; - max_val = 2; - break; - case RGL_BUFFERING_MODE_TRIPLE: - initial_val = 2; - max_val = 3; - break; - default: - break; - } - - int res = sys_semaphore_create(&FlipSem, &attr, initial_val, max_val); - (void)res; // unused variable is ok - - // Register flip callback - if ( rescIsEnabled( params ) ) - cellRescSetFlipHandler(rglFlipCallbackFunction); - else - cellGcmSetFlipHandler(rglFlipCallbackFunction); - - // Initialize label by getting address - labelAddress = (volatile uint32_t *)cellGcmGetLabelAddress(WaitLabelIndex); - *labelAddress = 0; - - // Regiter VBlank callback - if ( rescIsEnabled( params ) ) - cellRescSetVBlankHandler(rglRescVblankCallbackFunction); - else - cellGcmSetVBlankHandler(rglVblankCallbackFunction); - - if ( rescIsEnabled( params ) ) - { - for ( int i = 0; i < params->bufferingMode; ++i ) // bufferingMode should always be single, but for now.... - { - // Set the RESC CellRescSrc buffer (source buffer to scale - psgl's render target): - // **NOT SURE WHAT TO DO ABOUT FP BUFFERS YET** case CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT for fp16 - - CellRescSrc rescSrc = { CELL_GCM_TEXTURE_A8R8G8B8 | CELL_GCM_TEXTURE_LN | CELL_GCM_TEXTURE_NR, // uint8_t format - gcmDevice->color[i].pitch, // uint32_t pitch - width, // uint16_t width - height, // uint16_t height - gmmIdToOffset( gcmDevice->color[i].dataId ) }; // uint32_t offset - - if ( cellRescSetSrc( i, &rescSrc ) != CELL_OK ) - { - fprintf( stderr, "Registering display buffer %d failed\n", i ); - return -1; - } - } - } - else - { - unsigned int offset_bytes = 0; - rglSetDisplayMode( vm, gcmDevice->color[0].bpp*8, gcmDevice->color[0].pitch ); - - cellGcmSetFlipMode( gcmDevice->vsync ? CELL_GCM_DISPLAY_VSYNC : CELL_GCM_DISPLAY_HSYNC ); - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFinish(fifo, ref, offset_bytes); - - for ( int i = 0; i < params->bufferingMode; ++i ) - { - if ( cellGcmSetDisplayBuffer( i, gmmIdToOffset( gcmDevice->color[i].dataId ), gcmDevice->color[i].pitch , width, height ) != CELL_OK ) - { - fprintf( stderr, "Registering display buffer %d failed\n", i ); - return -1; - } - } - } - - // Add a reference marker to the command buffer to determine whether a location - // in the command buffer has been passed - gcmDevice->swapFifoRef = rglGcmFifoPutReference(fifo); - gcmDevice->swapFifoRef2 = gcmDevice->swapFifoRef; //used for triple buffering - - return 0; -} - -GLAPI void RGL_EXPORT psglSwap (void) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - const uint32_t fence = rglGcmState_i.semaphores->userSemaphores[RGLGCM_SEMA_FENCE].val; - GmmBlock *pBlock, *pTemp; - GmmAllocator *pAllocator = pGmmLocalAllocator; - rglGcmFifo * fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - unsigned int offset_bytes = 0; - - pBlock = pAllocator->pPendingFreeHead; - - while (pBlock) - { - pTemp = pBlock->pNextFree; - - if ( !(( fence - pBlock->fence ) & 0x80000000 ) ) - { - /* remove pending free */ - if (pBlock == pAllocator->pPendingFreeHead) - pAllocator->pPendingFreeHead = pBlock->pNextFree; - if (pBlock == pAllocator->pPendingFreeTail) - pAllocator->pPendingFreeTail = pBlock->pPrevFree; - if (pBlock->pNextFree) - pBlock->pNextFree->pPrevFree = pBlock->pPrevFree; - if (pBlock->pPrevFree) - pBlock->pPrevFree->pNextFree = pBlock->pNextFree; - - gmmAddFree(pAllocator, pBlock); - } - - pBlock = pTemp; - } - - RGLdevice *device = (RGLdevice*)_CurrentDevice; - rglGcmDevice *gcmDevice = (rglGcmDevice *)device->platformDevice; - - const GLuint drawBuffer = gcmDevice->drawBuffer; - - GLboolean vsync = _CurrentContext->VSync; - if ( vsync != gcmDevice->vsync ) - { - if ( ! rescIsEnabled( &device->deviceParameters ) ) - { - cellGcmSetFlipMode( vsync ? CELL_GCM_DISPLAY_VSYNC : CELL_GCM_DISPLAY_HSYNC ); - gcmDevice->vsync = vsync; - } - } - - if ( device->deviceParameters.bufferingMode == RGL_BUFFERING_MODE_TRIPLE ) - { - if ( rescIsEnabled( &device->deviceParameters ) ) - cellRescSetWaitFlip(); // GPU will wait until flip actually occurs - else - { - // GPU will wait until flip actually occurs - rglGcmSetWaitLabel(gCellGcmCurrentContext, 1, 0); - } - } - - if ( rescIsEnabled( &device->deviceParameters ) ) - { - int32_t res = cellRescSetConvertAndFlip(( uint8_t ) drawBuffer ); - if ( res != CELL_OK ) - { - //RGL_REPORT_EXTRA(RGL_REPORT_RESC_FLIP_ERROR, "WARNING: RESC cellRescSetConvertAndFlip returned error code %d.\n", res); - if ( _CurrentContext ) - _CurrentContext->needValidate |= RGL_VALIDATE_FRAMEBUFFER; - return; - } - } - else - cellGcmSetFlipUnsafe(gCellGcmCurrentContext, (uint8_t)drawBuffer); - - if ( device->deviceParameters.bufferingMode != RGL_BUFFERING_MODE_TRIPLE ) - { - if ( rescIsEnabled( &device->deviceParameters ) ) - cellRescSetWaitFlip(); // GPU will wait until flip actually occurs - else - { - // GPU will wait until flip actually occurs - rglGcmSetWaitLabel(gCellGcmCurrentContext, 1, 0); - } - } - - gcm_emit_method_at(thisContext->current, 0, CELL_GCM_NV4097_SET_TRANSFORM_CONSTANT_LOAD, 33); - gcm_emit_at(thisContext->current, 1, 0); - - rglGcmSetDitherEnable(thisContext, true ); - - RGLcontext *context = (RGLcontext*)_CurrentContext; - context->needValidate = RGL_VALIDATE_ALL; - context->attribs->DirtyMask = ( 1 << RGL_MAX_VERTEX_ATTRIBS ) - 1; - - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFlush(fifo, offset_bytes); - - while (sys_semaphore_wait(FlipSem,1000) != CELL_OK); - - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFlush(fifo, offset_bytes); - - if ( device->deviceParameters.bufferingMode == RGL_BUFFERING_MODE_DOUBLE ) - { - gcmDevice->drawBuffer = gcmDevice->scanBuffer; - gcmDevice->scanBuffer = drawBuffer; - - gcmDevice->rt.colorId[0] = gcmDevice->color[gcmDevice->drawBuffer].dataId; - gcmDevice->rt.colorPitch[0] = gcmDevice->color[gcmDevice->drawBuffer].pitch; - } - else if ( device->deviceParameters.bufferingMode == RGL_BUFFERING_MODE_TRIPLE ) - { - gcmDevice->drawBuffer = gcmDevice->scanBuffer; - - if ( gcmDevice->scanBuffer == 2 ) - gcmDevice->scanBuffer = 0; - else - gcmDevice->scanBuffer++; - - gcmDevice->rt.colorId[0] = gcmDevice->color[gcmDevice->drawBuffer].dataId; - gcmDevice->rt.colorPitch[0] = gcmDevice->color[gcmDevice->drawBuffer].pitch; - } -} - -/*============================================================ - BUFFERS - ============================================================ */ - -static rglBufferObject *rglCreateBufferObject (void) -{ - GLuint size = sizeof( rglBufferObject ) + sizeof(rglGcmBufferObject); - rglBufferObject *buffer = (rglBufferObject*)calloc(1, size); - - if(!buffer ) - return NULL; - - buffer->refCount = 1; - new( &buffer->textureReferences ) RGL::Vector(); - - return buffer; -} - -static void rglFreeBufferObject (void *data) -{ - rglBufferObject *buffer = (rglBufferObject*)data; - - if ( --buffer->refCount == 0 ) - { - rglPlatformDestroyBufferObject( buffer ); - buffer->textureReferences.~Vector(); - free( buffer ); - } -} - -GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name ) -{ - RGLcontext *LContext = _CurrentContext; - - if (name) - rglTexNameSpaceCreateNameLazy( &LContext->bufferObjectNameSpace, name ); - - switch ( target ) - { - case GL_ARRAY_BUFFER: - LContext->ArrayBuffer = name; - break; - case GL_PIXEL_UNPACK_BUFFER_ARB: - LContext->PixelUnpackBuffer = name; - break; - case GL_TEXTURE_REFERENCE_BUFFER_SCE: - LContext->TextureBuffer = name; - break; - default: - break; - } -} - -#ifdef __cplusplus -extern "C" { -#endif - -GLAPI GLvoid* APIENTRY glMapBufferTextureReferenceRA( GLenum target, GLenum access ) -{ - RGLcontext *LContext = _CurrentContext; - - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[LContext->TextureBuffer]; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - rglGcmBufferObject *rglBuffer = (rglGcmBufferObject*)bufferObject->platformBufferObject; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - - bufferObject->mapped = GL_TRUE; - rglBuffer->mapAccess = access; - - // only need to pin the first time we map - gmmPinId( rglBuffer->bufferId ); - - return gmmIdToAddress( rglBuffer->bufferId ); -} - -GLAPI GLboolean APIENTRY glUnmapBufferTextureReferenceRA( GLenum target ) -{ - RGLcontext *LContext = _CurrentContext; - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[LContext->TextureBuffer]; - rglGcmBufferObject *rglBuffer = ( rglGcmBufferObject * )bufferObject->platformBufferObject; - - bufferObject->mapped = GL_FALSE; - rglBuffer->mapAccess = GL_NONE; - - gmmUnpinId( rglBuffer->bufferId ); - return GL_TRUE; -} - -#ifdef __cplusplus -} -#endif - -GLAPI GLvoid* APIENTRY glMapBuffer( GLenum target, GLenum access ) -{ - RGLcontext *LContext = _CurrentContext; - GLuint name = 0; - - switch ( target ) - { - case GL_ARRAY_BUFFER: - name = LContext->ArrayBuffer; - break; - case GL_PIXEL_UNPACK_BUFFER_ARB: - name = LContext->PixelUnpackBuffer; - break; - case GL_TEXTURE_REFERENCE_BUFFER_SCE: - name = LContext->TextureBuffer; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return NULL; - } - - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; - bufferObject->mapped = GL_TRUE; - - return rglPlatformBufferObjectMap( bufferObject, access ); -} - -GLAPI GLboolean APIENTRY glUnmapBuffer( GLenum target ) -{ - RGLcontext *LContext = _CurrentContext; - GLuint name = 0; - - switch ( target ) - { - case GL_ARRAY_BUFFER: - name = LContext->ArrayBuffer; - break; - case GL_TEXTURE_REFERENCE_BUFFER_SCE: - name = LContext->TextureBuffer; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return GL_FALSE; - } - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; - - bufferObject->mapped = GL_FALSE; - - GLboolean result = rglPlatformBufferObjectUnmap( bufferObject ); - - return result; -} - - -GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers ) -{ - RGLcontext *LContext = (RGLcontext*)_CurrentContext; - for (int i = 0; i < n; ++i) - { - if(!rglTexNameSpaceIsName(&LContext->bufferObjectNameSpace, buffers[i])) - continue; - if (buffers[i]) - { - GLuint name = buffers[i]; - - if (LContext->ArrayBuffer == name) - LContext->ArrayBuffer = 0; - if (LContext->PixelUnpackBuffer == name) - LContext->PixelUnpackBuffer = 0; - - for ( int i = 0;i < RGL_MAX_VERTEX_ATTRIBS;++i ) - { - if ( LContext->attribs->attrib[i].arrayBuffer == name ) - { - LContext->attribs->attrib[i].arrayBuffer = 0; - LContext->attribs->HasVBOMask &= ~( 1 << i ); - } - } - } - } - rglTexNameSpaceDeleteNames( &LContext->bufferObjectNameSpace, n, buffers ); -} - -GLAPI void APIENTRY glGenBuffers( GLsizei n, GLuint *buffers ) -{ - rglTexNameSpaceGenNames( &((RGLcontext*)_CurrentContext)->bufferObjectNameSpace, n, buffers ); -} - -GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage ) -{ - RGLcontext *LContext = (RGLcontext*)_CurrentContext; - - GLuint name = 0; - - switch ( target ) - { - case GL_ARRAY_BUFFER: - name = LContext->ArrayBuffer; - break; - case GL_PIXEL_UNPACK_BUFFER_ARB: - name = LContext->PixelUnpackBuffer; - break; - case GL_TEXTURE_REFERENCE_BUFFER_SCE: - name = LContext->TextureBuffer; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return; - } - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; - - if (bufferObject->size > 0) - rglPlatformDestroyBufferObject( bufferObject ); - - bufferObject->size = size; - bufferObject->width = 0; - bufferObject->height = 0; - bufferObject->internalFormat = GL_NONE; - - if (size) - { - if (!rglpCreateBufferObject(bufferObject)) - { - rglSetError( GL_OUT_OF_MEMORY ); - return; - } - - if (data) - rglPlatformBufferObjectSetData( bufferObject, 0, size, data, GL_TRUE ); - } -} - -/*============================================================ - FRAMEBUFFER - ============================================================ */ - -GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) -{ -} - -GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - LContext->BlendColor.R = rglClampf(red); - LContext->BlendColor.G = rglClampf(green); - LContext->BlendColor.B = rglClampf(blue); - LContext->BlendColor.A = rglClampf(alpha); - - LContext->needValidate |= RGL_VALIDATE_BLENDING; -} - -GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - - LContext->BlendFactorSrcRGB = sfactor; - LContext->BlendFactorSrcAlpha = sfactor; - LContext->BlendFactorDestRGB = dfactor; - LContext->BlendFactorDestAlpha = dfactor; - LContext->needValidate |= RGL_VALIDATE_BLENDING; -} - -GLAPI void APIENTRY glBlendEquation( GLenum func ) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - - LContext->BlendEquationRGB = func; - LContext->BlendEquationAlpha = func; - LContext->needValidate |= RGL_VALIDATE_BLENDING; -} - -/*============================================================ - FRAMEBUFFER OBJECTS - ============================================================ */ - -void rglFramebufferGetAttachmentTexture( - RGLcontext* LContext, - const rglFramebufferAttachment* attachment, - rglTexture** texture, - GLuint* face ) -{ - switch ( attachment->type ) - { - case RGL_FRAMEBUFFER_ATTACHMENT_NONE: - *texture = NULL; - *face = 0; - break; - case RGL_FRAMEBUFFER_ATTACHMENT_RENDERBUFFER: - break; - case RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE: - *texture = rglGetTextureSafe( LContext, attachment->name ); - *face = 0; - if ( *texture ) - { - switch ( attachment->textureTarget ) - { - case GL_TEXTURE_2D: - break; - default: - *texture = NULL; - } - } - break; - default: - *face = 0; - *texture = NULL; - } -} - -rglFramebufferAttachment* rglFramebufferGetAttachment(void *data, GLenum attachment) -{ - rglFramebuffer *framebuffer = (rglFramebuffer*)data; - - switch ( attachment ) - { - case GL_COLOR_ATTACHMENT0_EXT: - case GL_COLOR_ATTACHMENT1_EXT: - case GL_COLOR_ATTACHMENT2_EXT: - case GL_COLOR_ATTACHMENT3_EXT: - return &framebuffer->color[attachment - GL_COLOR_ATTACHMENT0_EXT]; - default: - rglSetError( GL_INVALID_ENUM ); - return NULL; - } -} - -GLAPI GLboolean APIENTRY glIsFramebufferOES( GLuint framebuffer ) -{ - RGLcontext* LContext = _CurrentContext; - - if ( !rglTexNameSpaceIsName( &LContext->framebufferNameSpace, framebuffer ) ) - return GL_FALSE; - - return GL_TRUE; -} - -GLAPI void APIENTRY glBindFramebufferOES( GLenum target, GLuint framebuffer ) -{ - RGLcontext* LContext = _CurrentContext; - - if ( framebuffer ) - rglTexNameSpaceCreateNameLazy( &LContext->framebufferNameSpace, framebuffer ); - - LContext->framebuffer = framebuffer; - LContext->needValidate |= RGL_VALIDATE_FRAMEBUFFER; -} - -GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei n, const GLuint *framebuffers ) -{ - RGLcontext *LContext = _CurrentContext; - - for ( int i = 0; i < n; ++i ) - { - if ( framebuffers[i] && framebuffers[i] == LContext->framebuffer ) - glBindFramebufferOES( GL_FRAMEBUFFER_OES, 0 ); - } - - rglTexNameSpaceDeleteNames( &LContext->framebufferNameSpace, n, framebuffers ); -} - -GLAPI void APIENTRY glGenFramebuffersOES( GLsizei n, GLuint *framebuffers ) -{ - rglTexNameSpaceGenNames( &_CurrentContext->framebufferNameSpace, n, framebuffers ); -} - -GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum target ) -{ - RGLcontext* LContext = _CurrentContext; - - if (LContext->framebuffer) - return rglPlatformFramebufferCheckStatus(rglGetFramebuffer(LContext, LContext->framebuffer)); - - return GL_FRAMEBUFFER_COMPLETE_OES; -} - -static inline void frameBuffer_pushBack(GLuint texture, rglFramebuffer *element) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - rglTexture *textureObject = (rglTexture*)LContext->textureNameSpace.data[texture]; - - uint32_t newCapacity = textureObject->framebuffers.count + 1; - - if (newCapacity > textureObject->framebuffers.capacity) - { - if ( newCapacity > textureObject->framebuffers.capacity ) - newCapacity = ( newCapacity > textureObject->framebuffers.capacity + textureObject->framebuffers.increment ) ? newCapacity : ( textureObject->framebuffers.capacity + textureObject->framebuffers.increment ); - - textureObject->framebuffers.array = (rglFramebuffer**)realloc((void *)(textureObject->framebuffers.array), sizeof(rglFramebuffer) * newCapacity); - textureObject->framebuffers.capacity = newCapacity; - } - new((void *)(textureObject->framebuffers.array + textureObject->framebuffers.count))rglFramebuffer((const rglFramebuffer&)element); - ++textureObject->framebuffers.count; -} - -GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level ) -{ - RGLcontext* LContext = _CurrentContext; - - rglFramebuffer* framebuffer = rglGetFramebuffer( LContext, LContext->framebuffer ); - rglFramebufferAttachment* attach = rglFramebufferGetAttachment( framebuffer, attachment ); - - if (!attach) - return; - - rglTexture *textureObject = NULL; - GLuint face; - rglFramebufferGetAttachmentTexture( LContext, attach, &textureObject, &face ); - - if (textureObject) - textureObject->framebuffers.removeElement( framebuffer ); - - if (texture) - { - attach->type = RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE; - frameBuffer_pushBack(texture, framebuffer); - } - else - attach->type = RGL_FRAMEBUFFER_ATTACHMENT_NONE; - attach->name = texture; - attach->textureTarget = textarget; - - framebuffer->needValidate = GL_TRUE; - LContext->needValidate |= RGL_VALIDATE_FRAMEBUFFER; -} - - -/*============================================================ - IMAGE CONVERSION - ============================================================ */ - -#define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_SCE -#define GL_UNSIGNED_INT_8_24_REV GL_UNSIGNED_INT_8_24_REV_SCE - -#define GL_UNSIGNED_SHORT_8_8 GL_UNSIGNED_SHORT_8_8_SCE -#define GL_UNSIGNED_SHORT_8_8_REV GL_UNSIGNED_SHORT_8_8_REV_SCE -#define GL_UNSIGNED_INT_16_16 GL_UNSIGNED_INT_16_16_SCE -#define GL_UNSIGNED_INT_16_16_REV GL_UNSIGNED_INT_16_16_REV_SCE - -#define DECLARE_C_TYPES \ - DECLARE_TYPE(GL_BYTE,GLbyte,127.f) \ -DECLARE_TYPE(GL_UNSIGNED_BYTE,GLubyte,255.f) \ -DECLARE_TYPE(GL_SHORT,GLshort,32767.f) \ -DECLARE_TYPE(GL_UNSIGNED_SHORT,GLushort,65535.f) \ -DECLARE_TYPE(GL_INT,GLint,2147483647.f) \ -DECLARE_TYPE(GL_UNSIGNED_INT,GLuint,4294967295.0) \ -DECLARE_TYPE(GL_FIXED,GLfixed,65535.f) - -#define DECLARE_UNPACKED_TYPES \ - DECLARE_UNPACKED_TYPE(GL_BYTE) \ -DECLARE_UNPACKED_TYPE(GL_UNSIGNED_BYTE) \ -DECLARE_UNPACKED_TYPE(GL_SHORT) \ -DECLARE_UNPACKED_TYPE(GL_UNSIGNED_SHORT) \ -DECLARE_UNPACKED_TYPE(GL_INT) \ -DECLARE_UNPACKED_TYPE(GL_UNSIGNED_INT) \ -DECLARE_UNPACKED_TYPE(GL_HALF_FLOAT_ARB) \ -DECLARE_UNPACKED_TYPE(GL_FLOAT) \ -DECLARE_UNPACKED_TYPE(GL_FIXED) - - -#define DECLARE_PACKED_TYPES \ - DECLARE_PACKED_TYPE_AND_REV_2(UNSIGNED_BYTE,4,4) \ -DECLARE_PACKED_TYPE_AND_REV_2(UNSIGNED_BYTE,6,2) \ -DECLARE_PACKED_TYPE_AND_REV_3(UNSIGNED_BYTE,3,3,2) \ -DECLARE_PACKED_TYPE_AND_REV_4(UNSIGNED_BYTE,2,2,2,2) \ -DECLARE_PACKED_TYPE_AND_REV_2(UNSIGNED_SHORT,12,4) \ -DECLARE_PACKED_TYPE_AND_REV_2(UNSIGNED_SHORT,8,8) \ -DECLARE_PACKED_TYPE_AND_REV_3(UNSIGNED_SHORT,5,6,5) \ -DECLARE_PACKED_TYPE_AND_REV_4(UNSIGNED_SHORT,4,4,4,4) \ -DECLARE_PACKED_TYPE_AND_REV_4(UNSIGNED_SHORT,5,5,5,1) \ -DECLARE_PACKED_TYPE_AND_REV_2(UNSIGNED_INT,16,16) \ -DECLARE_PACKED_TYPE_AND_REV_2(UNSIGNED_INT,24,8) \ -DECLARE_PACKED_TYPE_AND_REV_4(UNSIGNED_INT,8,8,8,8) \ -DECLARE_PACKED_TYPE_AND_REV_4(UNSIGNED_INT,10,10,10,2) - -#define DECLARE_TYPE(TYPE,CTYPE,MAXVAL) \ - typedef CTYPE type_##TYPE; \ -static inline type_##TYPE rglFloatTo_##TYPE(float v) { return (type_##TYPE)(rglClampf(v)*MAXVAL); } \ -static inline float rglFloatFrom_##TYPE(type_##TYPE v) { return ((float)v)/MAXVAL; } -DECLARE_C_TYPES -#undef DECLARE_TYPE - -typedef GLfloat type_GL_FLOAT; -typedef GLhalfARB type_GL_HALF_FLOAT_ARB; - -#define rglFloatTo_GL_FLOAT(v) (v) -#define rglFloatFrom_GL_FLOAT(v) (v) -#define rglFloatTo_GL_HALF_FLOAT_ARB(x) (rglFloatToHalf(x)) -#define rglFloatFrom_GL_HALF_FLOAT_ARB(x) (rglHalfToFloat(x)) - -#define DECLARE_PACKED_TYPE_AND_REV_2(REALTYPE,S1,S2) \ - DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S1##_##S2,2,S1,S2,0,0,) \ -DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S2##_##S1##_REV,2,S2,S1,0,0,_REV) - -#define DECLARE_PACKED_TYPE_AND_REV_3(REALTYPE,S1,S2,S3) \ - DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S1##_##S2##_##S3,3,S1,S2,S3,0,) \ -DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S3##_##S2##_##S1##_REV,3,S3,S2,S1,0,_REV) - -#define DECLARE_PACKED_TYPE_AND_REV_4(REALTYPE,S1,S2,S3,S4) \ - DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S1##_##S2##_##S3##_##S4,4,S1,S2,S3,S4,) \ -DECLARE_PACKED_TYPE(GL_##REALTYPE,GL_##REALTYPE##_##S4##_##S3##_##S2##_##S1##_REV,4,S4,S3,S2,S1,_REV) - -#define DECLARE_PACKED_TYPE_AND_REALTYPE(REALTYPE,N,S1,S2,S3,S4,REV) \ - DECLARE_PACKED_TYPE(GL_##REALTYPE,PACKED_TYPE(REALTYPE,N,S1,S2,S3,S4,REV),N,S1,S2,S3,S4,REV) - -#define INDEX(N,X) (X) -#define INDEX_REV(N,X) (N-1-X) - -#define GET_BITS(to,from,first,count) if ((count)>0) to=((GLfloat)(((from)>>(first))&((1<<(count))-1)))/(GLfloat)((1<<((count==0)?1:count))-1) -#define PUT_BITS(from,to,first,count) if ((count)>0) to|=((unsigned int)((from)*((GLfloat)((1<<((count==0)?1:count))-1))))<<(first); - -static inline int rglGetComponentCount (GLenum format) -{ - switch ( format ) - { - case GL_RGB: - case GL_BGR: - return 3; - case GL_RGBA: - case GL_BGRA: - case GL_ABGR: - case GL_ARGB_SCE: - return 4; - case GL_RED: - case GL_GREEN: - case GL_BLUE: - case GL_ALPHA: - return 1; - default: - return 0; - } -} - -static inline int rglGetTypeSize( GLenum type ) -{ - switch ( type ) - { - -#define DECLARE_PACKED_TYPE(REALTYPE,TYPE,N,S1,S2,S3,S4,REV) \ - case TYPE: \ - return sizeof(type_##REALTYPE); - DECLARE_PACKED_TYPES -#undef DECLARE_PACKED_TYPE - -#define DECLARE_UNPACKED_TYPE(TYPE) \ - case TYPE: \ - return sizeof(type_##TYPE); - DECLARE_UNPACKED_TYPES -#undef DECLARE_UNPACKED_TYPE - - default: - return 0; - } -} - -int rglGetPixelSize( GLenum format, GLenum type ) -{ - int componentSize; - switch ( type ) - { - -#define DECLARE_PACKED_TYPE(REALTYPE,TYPE,N,S1,S2,S3,S4,REV) \ - case TYPE: \ - return sizeof(type_##REALTYPE); - DECLARE_PACKED_TYPES -#undef DECLARE_PACKED_TYPE - -#define DECLARE_UNPACKED_TYPE(TYPE) \ - case TYPE: \ - componentSize=sizeof(type_##TYPE); \ - break; - DECLARE_UNPACKED_TYPES -#undef DECLARE_UNPACKED_TYPE - - default: - return 0; - } - return rglGetComponentCount(format) * componentSize; -} - -static void rglRawRasterToImage(const void *in_data, - void *out_data, GLuint x, GLuint y, GLuint z ) -{ - const rglRaster* raster = (const rglRaster*)in_data; - rglImage *image = (rglImage*)out_data; - const int pixelBits = rglGetPixelSize( image->format, image->type ) * 8; - - const GLuint size = pixelBits / 8; - - if ( raster->xstride == image->xstride && - raster->ystride == image->ystride && - raster->zstride == image->zstride ) - { - memcpy((char*)image->data + - x*image->xstride + y*image->ystride + z*image->zstride, - raster->data, raster->zstride ); - - return; - } - else if ( raster->xstride == image->xstride ) - { - const GLuint lineBytes = raster->width * raster->xstride; - for ( int j = 0; j < raster->height; ++j ) - { - const char *src = ( const char * )raster->data + - raster->zstride + j * raster->ystride; - char *dst = ( char * )image->data + - z * image->zstride + - ( j + y ) * image->ystride + - x * image->xstride; - memcpy( dst, src, lineBytes ); - } - - return; - } - - for ( int j = 0; j < raster->height; ++j ) - { - const char *src = ( const char * )raster->data + - raster->zstride + j * raster->ystride; - char *dst = ( char * )image->data + - z * image->zstride + - ( j + y ) * image->ystride + - x * image->xstride; - - for ( int k = 0; k < raster->width; ++k ) - { - memcpy( dst, src, size ); - - src += raster->xstride; - dst += image->xstride; - } - } -} - -void rglImageAllocCPUStorage (void *data) -{ - rglImage *image = (rglImage*)data; - - if (( image->storageSize > image->mallocStorageSize ) || ( !image->mallocData ) ) - { - if (image->mallocData) - free( image->mallocData ); - - image->mallocData = (char *)malloc( image->storageSize + 128 ); - image->mallocStorageSize = image->storageSize; - } - image->data = rglPadPtr( image->mallocData, 128 ); -} - -void rglImageFreeCPUStorage(void *data) -{ - rglImage *image = (rglImage*)data; - - if (!image->mallocData) - return; - - free( image->mallocData ); - image->mallocStorageSize = 0; - image->data = NULL; - image->mallocData = NULL; - image->dataState &= ~RGL_IMAGE_DATASTATE_HOST; -} - -/*============================================================ - ENGINE - ============================================================ */ - -static char* rglVendorString = "RetroArch"; - -static char* rglRendererString = "RGL"; -static char* rglExtensionsString = "GL_ARB_texture_float"; - -static char* rglVersionNumber = "2.00"; -char* rglVersion = "2.00"; - -#define NUM_EXTENSIONS 1 - -RGLcontext* _CurrentContext = NULL; - -RGL_EXPORT RGLcontextHookFunction rglContextCreateHook = NULL; -RGL_EXPORT RGLcontextHookFunction rglContextDestroyHook = NULL; - -void rglSetError( GLenum error ) -{ -} - -GLAPI GLenum APIENTRY glGetError(void) -{ - if (!_CurrentContext ) - return GL_INVALID_OPERATION; - - GLenum error = _CurrentContext->error; - _CurrentContext->error = GL_NO_ERROR; - return error; -} - -GLAPI void APIENTRY glGetIntegerv(GLenum pname, GLint* params) -{ - switch (pname) - { - case GL_MAX_TEXTURE_SIZE: - params[0] = RGLP_MAX_TEXTURE_SIZE; - break; -#if 0 - case GL_NUM_EXTENSIONS: - params[0] = NUM_EXTENSIONS; - break; -#endif - default: - fprintf(stderr, "glGetIntegerv: enum not supported.\n"); - break; - } -} - -static void rglResetContext (void *data) -{ - RGLcontext *LContext = (RGLcontext*)data; - - rglTexNameSpaceResetNames( &LContext->textureNameSpace ); - rglTexNameSpaceResetNames( &LContext->bufferObjectNameSpace ); - rglTexNameSpaceResetNames( &LContext->framebufferNameSpace ); - - LContext->ViewPort.X = 0; - LContext->ViewPort.Y = 0; - LContext->ViewPort.XSize = 0; - LContext->ViewPort.YSize = 0; - - LContext->DepthNear = 0.f; - LContext->DepthFar = 1.f; - - LContext->DrawBuffer = LContext->ReadBuffer = GL_COLOR_ATTACHMENT0_EXT; - - LContext->Blending = GL_FALSE; - LContext->BlendColor.R = 0.0f; - LContext->BlendColor.G = 0.0f; - LContext->BlendColor.B = 0.0f; - LContext->BlendColor.A = 0.0f; - LContext->BlendEquationRGB = GL_FUNC_ADD; - LContext->BlendEquationAlpha = GL_FUNC_ADD; - LContext->BlendFactorSrcRGB = GL_ONE; - LContext->BlendFactorDestRGB = GL_ZERO; - LContext->BlendFactorSrcAlpha = GL_ONE; - LContext->BlendFactorDestAlpha = GL_ZERO; - - LContext->ColorLogicOp = GL_FALSE; - LContext->LogicOp = GL_COPY; - - LContext->Dithering = GL_TRUE; - - LContext->TexCoordReplaceMask = 0; - - for ( int i = 0;i < RGL_MAX_TEXTURE_IMAGE_UNITS;++i ) - { - rglTextureImageUnit *tu = LContext->TextureImageUnits + i; - tu->bound2D = 0; - - tu->enable2D = GL_FALSE; - tu->fragmentTarget = 0; - - tu->lodBias = 0.f; - tu->currentTexture = NULL; - } - - LContext->ActiveTexture = 0; - LContext->CurrentImageUnit = LContext->TextureImageUnits; - - LContext->packAlignment = 4; - LContext->unpackAlignment = 4; - - rglAttributeState *as = (rglAttributeState*)&LContext->defaultAttribs0; - - for ( int i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i ) - { - as->attrib[i].clientSize = 4; - as->attrib[i].clientType = GL_FLOAT; - as->attrib[i].clientStride = 16; - as->attrib[i].clientData = NULL; - - as->attrib[i].value[0] = 0.0f; - as->attrib[i].value[1] = 0.0f; - as->attrib[i].value[2] = 0.0f; - as->attrib[i].value[3] = 1.0f; - - as->attrib[i].normalized = GL_FALSE; - as->attrib[i].frequency = 1; - - as->attrib[i].arrayBuffer = 0; - } - - as->attrib[RGL_ATTRIB_PRIMARY_COLOR_INDEX].value[0] = 1.0f; - as->attrib[RGL_ATTRIB_PRIMARY_COLOR_INDEX].value[1] = 1.0f; - as->attrib[RGL_ATTRIB_PRIMARY_COLOR_INDEX].value[2] = 1.0f; - as->attrib[RGL_ATTRIB_PRIMARY_COLOR_INDEX].value[3] = 1.0f; - - as->attrib[RGL_ATTRIB_SECONDARY_COLOR_INDEX].value[0] = 1.0f; - as->attrib[RGL_ATTRIB_SECONDARY_COLOR_INDEX].value[1] = 1.0f; - as->attrib[RGL_ATTRIB_SECONDARY_COLOR_INDEX].value[2] = 1.0f; - as->attrib[RGL_ATTRIB_SECONDARY_COLOR_INDEX].value[3] = 1.0f; - - as->attrib[RGL_ATTRIB_NORMAL_INDEX].value[0] = 0.f; - as->attrib[RGL_ATTRIB_NORMAL_INDEX].value[1] = 0.f; - as->attrib[RGL_ATTRIB_NORMAL_INDEX].value[2] = 1.f; - - as->DirtyMask = ( 1 << RGL_MAX_VERTEX_ATTRIBS ) - 1; - as->EnabledMask = 0; - as->HasVBOMask = 0; - - LContext->attribs = &LContext->defaultAttribs0; - - LContext->framebuffer = 0; - - LContext->VertexProgram = GL_FALSE; - LContext->BoundVertexProgram = 0; - - LContext->FragmentProgram = GL_FALSE; - LContext->BoundFragmentProgram = 0; - - LContext->ArrayBuffer = 0; - LContext->PixelUnpackBuffer = 0; - LContext->TextureBuffer = 0; - - LContext->VSync = GL_FALSE; -} - -static rglTexture *rglAllocateTexture(void) -{ - rglTexture *texture = (rglTexture*)calloc(1, sizeof(rglTexture) + sizeof(rglGcmTexture)); - texture->target = 0; - texture->minFilter = GL_NEAREST_MIPMAP_LINEAR; - texture->magFilter = GL_LINEAR; - texture->minLod = -1000.f; - texture->maxLod = 1000.f; - texture->maxLevel = 1000; - texture->wrapS = GL_REPEAT; - texture->wrapT = GL_REPEAT; - texture->wrapR = GL_REPEAT; - texture->lodBias = 0.f; - texture->maxAnisotropy = 1.f; - texture->compareMode = GL_NONE; - texture->compareFunc = GL_LEQUAL; - texture->gammaRemap = 0; - texture->usage = 0; - texture->isRenderTarget = GL_FALSE; - texture->image = NULL; - texture->isComplete = GL_FALSE; - texture->imageCount = 0; - texture->revalidate = 0; - texture->referenceBuffer = NULL; - new( &texture->framebuffers ) RGL::Vector(); - rglPlatformCreateTexture( texture ); - return texture; -} - -static void rglFreeTexture (void *data) -{ - rglTexture *texture = (rglTexture*)data; - rglTextureTouchFBOs(texture); - texture->framebuffers.~Vector(); - - if ( texture->image ) - { - rglImage *image = texture->image; - rglImageFreeCPUStorage( image ); - free( texture->image ); - } - if (texture->referenceBuffer) - texture->referenceBuffer->textureReferences.removeElement( texture ); - rglPlatformDestroyTexture( texture ); - free( texture ); -} - -RGLcontext* psglCreateContext(void) -{ - RGLcontext* LContext = (RGLcontext*)calloc(1, sizeof(RGLcontext)); - - if (!LContext) - return NULL; - - LContext->error = GL_NO_ERROR; - - rglTexNameSpaceInit( &LContext->textureNameSpace, ( rglTexNameSpaceCreateFunction )rglAllocateTexture, ( rglTexNameSpaceDestroyFunction )rglFreeTexture ); - - for ( int i = 0;i < RGL_MAX_TEXTURE_IMAGE_UNITS;++i ) - { - rglTextureImageUnit *tu = LContext->TextureImageUnits + i; - - tu->default2D = rglAllocateTexture(); - if ( !tu->default2D ) - { - psglDestroyContext( LContext ); - return NULL; - } - tu->default2D->target = GL_TEXTURE_2D; - } - - rglTexNameSpaceInit( &LContext->bufferObjectNameSpace, ( rglTexNameSpaceCreateFunction )rglCreateBufferObject, ( rglTexNameSpaceDestroyFunction )rglFreeBufferObject ); - rglTexNameSpaceInit( &LContext->framebufferNameSpace, ( rglTexNameSpaceCreateFunction )rglCreateFramebuffer, ( rglTexNameSpaceDestroyFunction )rglDestroyFramebuffer ); - - LContext->needValidate = 0; - LContext->everAttached = 0; - - LContext->RGLcgLastError = CG_NO_ERROR; - LContext->RGLcgErrorCallbackFunction = NULL; - LContext->RGLcgContextHead = ( CGcontext )NULL; - - rglInitNameSpace( &LContext->cgProgramNameSpace ); - rglInitNameSpace( &LContext->cgParameterNameSpace ); - rglInitNameSpace( &LContext->cgContextNameSpace ); - - rglResetContext( LContext ); - - if (rglContextCreateHook) - rglContextCreateHook( LContext ); - - return( LContext ); -} - -void RGL_EXPORT psglResetCurrentContext(void) -{ - RGLcontext *context = _CurrentContext; - rglResetContext(context); - context->needValidate |= RGL_VALIDATE_ALL; -} - -RGLcontext *psglGetCurrentContext(void) -{ - return _CurrentContext; -} - -void RGL_EXPORT psglDestroyContext (void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - RGLcontext *LContext = (RGLcontext*)data; - GLuint ref; - unsigned int offset_bytes = 0; - - if ( _CurrentContext == LContext ) - { - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFinish(fifo, ref, offset_bytes); - } - - while ( LContext->RGLcgContextHead != ( CGcontext )NULL ) - { - RGLcontext* current = _CurrentContext; - _CurrentContext = LContext; - cgDestroyContext( LContext->RGLcgContextHead ); - _CurrentContext = current; - } - rglFreeNameSpace( &LContext->cgProgramNameSpace ); - rglFreeNameSpace( &LContext->cgParameterNameSpace ); - rglFreeNameSpace( &LContext->cgContextNameSpace ); - - if ( rglContextDestroyHook ) rglContextDestroyHook( LContext ); - - for ( int i = 0; i < RGL_MAX_TEXTURE_IMAGE_UNITS; ++i ) - { - rglTextureImageUnit* tu = LContext->TextureImageUnits + i; - if ( tu->default2D ) rglFreeTexture( tu->default2D ); - } - - rglTexNameSpaceFree( &LContext->textureNameSpace ); - rglTexNameSpaceFree( &LContext->bufferObjectNameSpace ); - rglTexNameSpaceFree( &LContext->framebufferNameSpace ); - - if ( _CurrentContext == LContext ) - psglMakeCurrent( NULL, NULL ); - - free( LContext ); -} - -GLAPI void APIENTRY glEnable( GLenum cap ) -{ - RGLcontext* LContext = _CurrentContext; - - switch ( cap ) - { - case GL_TEXTURE_2D: - LContext->CurrentImageUnit->enable2D = GL_TRUE; - LContext->CurrentImageUnit->currentTexture = rglGetCurrentTexture( LContext->CurrentImageUnit, - LContext->CurrentImageUnit->fragmentTarget ); - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; - break; - case GL_BLEND: - LContext->Blending = GL_TRUE; - LContext->needValidate |= RGL_VALIDATE_BLENDING; - break; - case GL_DITHER: - LContext->Dithering = GL_TRUE; - break; - case GL_VSYNC_SCE: - LContext->VSync = GL_TRUE; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return; - } -} - -GLAPI void APIENTRY glDisable( GLenum cap ) -{ - RGLcontext* LContext = _CurrentContext; - - switch ( cap ) - { - case GL_TEXTURE_2D: - LContext->CurrentImageUnit->enable2D = GL_FALSE; - LContext->CurrentImageUnit->currentTexture = rglGetCurrentTexture( LContext->CurrentImageUnit, - LContext->CurrentImageUnit->fragmentTarget ); - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; - break; - case GL_BLEND: - LContext->Blending = GL_FALSE; - LContext->needValidate |= RGL_VALIDATE_BLENDING; - break; - case GL_DITHER: - LContext->Dithering = GL_FALSE; - break; - case GL_VSYNC_SCE: - LContext->VSync = GL_FALSE; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return; - } -} - -GLAPI void APIENTRY glEnableClientState( GLenum array ) -{ - RGLcontext *context = (RGLcontext*)_CurrentContext; - switch (array) - { - case GL_VERTEX_ARRAY: - rglEnableVertexAttribArrayNVInline(context, RGL_ATTRIB_POSITION_INDEX ); - break; - case GL_COLOR_ARRAY: - rglEnableVertexAttribArrayNVInline(context, RGL_ATTRIB_PRIMARY_COLOR_INDEX ); - break; - case GL_NORMAL_ARRAY: - rglEnableVertexAttribArrayNVInline(context, RGL_ATTRIB_NORMAL_INDEX ); - break; - } -} - -GLAPI void APIENTRY glDisableClientState( GLenum array ) -{ - RGLcontext *context = (RGLcontext*)_CurrentContext; - switch (array) - { - case GL_VERTEX_ARRAY: - rglDisableVertexAttribArrayNVInline(context, RGL_ATTRIB_POSITION_INDEX ); - break; - case GL_COLOR_ARRAY: - rglDisableVertexAttribArrayNVInline(context, RGL_ATTRIB_PRIMARY_COLOR_INDEX ); - break; - case GL_NORMAL_ARRAY: - rglDisableVertexAttribArrayNVInline(context, RGL_ATTRIB_NORMAL_INDEX ); - break; - } -} - -GLAPI const GLubyte* APIENTRY glGetString( GLenum name ) -{ - switch ( name ) - { - case GL_VENDOR: - return(( GLubyte* )rglVendorString ); - case GL_RENDERER: - return(( GLubyte* )rglRendererString ); - case GL_VERSION: - return(( GLubyte* )rglVersionNumber ); - case GL_EXTENSIONS: - return(( GLubyte* )rglExtensionsString ); - default: - { - rglSetError( GL_INVALID_ENUM ); - return(( GLubyte* )NULL ); - } - } -} - -void psglInit (void *data) -{ - RGLinitOptions *options = (RGLinitOptions*)data; - - if ( !rglInitCompleted ) - { - cellSysmoduleLoadModule( CELL_SYSMODULE_GCM_SYS ); - cellSysmoduleLoadModule( CELL_SYSMODULE_RESC ); - - rglDeviceInit( options ); - _CurrentContext = NULL; - _CurrentDevice = NULL; - } - - rglInitCompleted = 1; -} - -void psglExit(void) -{ - RGLcontext* LContext = _CurrentContext; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmFifo * fifo = &rglGcmState_i.fifo; - - if ( LContext ) - { - unsigned int offset_bytes = 0; - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFlush(fifo, offset_bytes); - - psglMakeCurrent( NULL, NULL ); - rglDeviceExit(); - - _CurrentContext = NULL; - - rglInitCompleted = 0; - } -} - -/*============================================================ - RASTER - ============================================================ */ - -GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height ) -{ - RGLcontext* LContext = _CurrentContext; - - LContext->ViewPort.X = x; - LContext->ViewPort.Y = y; - LContext->ViewPort.XSize = width; - LContext->ViewPort.YSize = height; - LContext->needValidate |= RGL_VALIDATE_VIEWPORT; -} - -/*============================================================ - TEXTURES (INTERNAL) - ============================================================ */ - -// Reallocate images held by a texture -void rglReallocateImages (void *data, GLint level, GLsizei dimension ) -{ - rglTexture *texture = (rglTexture*)data; - GLuint oldCount = texture->imageCount; - - if (dimension <= 0) - dimension = 1; - - GLuint n = level + 1 + rglLog2( dimension ); - n = MAX( n, oldCount ); - - rglImage *image = ( rglImage * )realloc( texture->image, n * sizeof( rglImage ) ); - memset( image + oldCount, 0, ( n - oldCount )*sizeof( rglImage ) ); - - texture->image = image; - texture->imageCount = n; -} - -rglTexture *rglGetCurrentTexture (const void *data, GLenum target) -{ - const rglTextureImageUnit *unit = (const rglTextureImageUnit*)data; - RGLcontext* LContext = _CurrentContext; - GLuint name = unit->bound2D; - rglTexture *defaultTexture = unit->default2D; - - if (name) - defaultTexture = (rglTexture *)LContext->textureNameSpace.data[name]; - - return defaultTexture; -} - -static void rglGetImage( GLenum target, GLint level, rglTexture **texture, rglImage **image, GLsizei reallocateSize ) -{ - RGLcontext* LContext = _CurrentContext; - rglTextureImageUnit *unit = (rglTextureImageUnit*)LContext->CurrentImageUnit; - - GLenum expectedTarget = GL_TEXTURE_2D; - - rglTexture *tex = rglGetCurrentTexture( unit, expectedTarget ); - - if (level >= ( int )tex->imageCount) - rglReallocateImages( tex, level, reallocateSize ); - - *image = tex->image + level; - *texture = tex; -} - -void rglBindTextureInternal (void *data, GLuint name, GLenum target ) -{ - rglTextureImageUnit *unit = (rglTextureImageUnit*)data; - RGLcontext* LContext = _CurrentContext; - rglTexture *texture = NULL; - - if (name) - { - rglTexNameSpaceCreateNameLazy( &LContext->textureNameSpace, name ); - texture = ( rglTexture * )LContext->textureNameSpace.data[name]; - - if (!texture->target) - texture->target = target; - } - - unit->bound2D = name; - unit->currentTexture = rglGetCurrentTexture( unit, unit->fragmentTarget ); - - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; -} - -/*============================================================ - TEXTURES - ============================================================ */ - -GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures ) -{ - RGLcontext* LContext = _CurrentContext; - rglTexNameSpaceGenNames( &LContext->textureNameSpace, n, textures ); -} - -GLAPI void APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures ) -{ - RGLcontext* LContext = _CurrentContext; - - for ( int i = 0;i < n;++i ) - { - if (textures[i]) - { - GLuint name = textures[i]; - int unit; - - for ( unit = 0; unit < RGL_MAX_TEXTURE_IMAGE_UNITS; ++unit) - { - rglTextureImageUnit *tu = LContext->TextureImageUnits + unit; - GLboolean dirty = GL_FALSE; - if ( tu->bound2D == name ) - { - tu->bound2D = 0; - dirty = GL_TRUE; - } - if ( dirty ) - { - tu->currentTexture = rglGetCurrentTexture( tu, tu->fragmentTarget ); - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; - } - } - } - } - - rglTexNameSpaceDeleteNames( &LContext->textureNameSpace, n, textures ); -} - -GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ) -{ - RGLcontext* LContext = _CurrentContext; - rglTexture *texture = rglGetCurrentTexture( LContext->CurrentImageUnit, target ); - switch ( pname ) - { - case GL_TEXTURE_MIN_FILTER: - texture->minFilter = param; - if ( texture->referenceBuffer == 0 ) - texture->revalidate |= RGL_TEXTURE_REVALIDATE_LAYOUT; - break; - case GL_TEXTURE_MAG_FILTER: - texture->magFilter = param; - break; - case GL_TEXTURE_MAX_LEVEL: - texture->maxLevel = param; - break; - case GL_TEXTURE_WRAP_S: - texture->wrapS = param; - break; - case GL_TEXTURE_WRAP_T: - texture->wrapT = param; - break; - case GL_TEXTURE_WRAP_R: - texture->wrapR = param; - break; - case GL_TEXTURE_COMPARE_MODE_ARB: - texture->compareMode = param; - break; - case GL_TEXTURE_COMPARE_FUNC_ARB: - texture->compareFunc = param; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return; - } - texture->revalidate |= RGL_TEXTURE_REVALIDATE_PARAMETERS; - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; -} - -GLAPI void APIENTRY glBindTexture( GLenum target, GLuint name ) -{ - RGLcontext* LContext = _CurrentContext; - rglTextureImageUnit *unit = LContext->CurrentImageUnit; - - rglBindTextureInternal( unit, name, target ); -} - -GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalFormat, - GLsizei width, GLsizei height, GLint border, GLenum format, - GLenum type, const GLvoid *pixels ) -{ - RGLcontext* LContext = _CurrentContext; - - rglTexture *texture; - rglImage *image; - rglGetImage(target, level, &texture, &image, MAX(width, height)); - - image->dataState = RGL_IMAGE_DATASTATE_UNSET; - - rglBufferObject* bufferObject = NULL; - if ( LContext->PixelUnpackBuffer != 0 ) - { - bufferObject = - (rglBufferObject*)LContext->bufferObjectNameSpace.data[LContext->PixelUnpackBuffer]; - pixels = rglPlatformBufferObjectMap( bufferObject, GL_READ_ONLY ) + - (( const GLubyte* )pixels - ( const GLubyte* )NULL ); - } - - image->width = width; - image->height = height; - image->depth = 1; - image->alignment = LContext->unpackAlignment; - - image->xblk = 0; - image->yblk = 0; - - image->xstride = 0; - image->ystride = 0; - image->zstride = 0; - - image->format = 0; - image->type = 0; - image->internalFormat = 0; - - rglPlatformChooseInternalStorage( image, internalFormat); - - image->data = NULL; - image->mallocData = NULL; - image->mallocStorageSize = 0; - - image->isSet = GL_TRUE; - - { - if ( image->xstride == 0 ) - image->xstride = rglGetPixelSize( image->format, image->type ); - if ( image->ystride == 0 ) - image->ystride = image->width * image->xstride; - if ( image->zstride == 0 ) - image->zstride = image->height * image->ystride; - } - - if (pixels) - { - rglImageAllocCPUStorage( image ); - if (image->data ) - { - rglRaster raster; - raster.format = format; - raster.type = type; - raster.width = width; - raster.height = height; - raster.depth = 1; - raster.data = (void*)pixels; - - raster.xstride = rglGetPixelSize( raster.format, raster.type ); - raster.ystride = (raster.width * raster.xstride + LContext->unpackAlignment - 1) / LContext->unpackAlignment * LContext->unpackAlignment; - raster.zstride = raster.height * raster.ystride; - - rglRawRasterToImage( &raster, image, 0, 0, 0 ); - image->dataState = RGL_IMAGE_DATASTATE_HOST; - } - } - else - image->dataState = RGL_IMAGE_DATASTATE_UNSET; - - - if ( LContext->PixelUnpackBuffer != 0 ) - rglPlatformBufferObjectUnmap( bufferObject ); - - texture->revalidate |= RGL_TEXTURE_REVALIDATE_IMAGES; - - rglTextureTouchFBOs( texture ); - - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; -} - -GLAPI void APIENTRY glActiveTexture( GLenum texture ) -{ - RGLcontext* LContext = _CurrentContext; - - int unit = texture - GL_TEXTURE0; - LContext->ActiveTexture = unit; - LContext->CurrentImageUnit = NULL; - - if(unit < RGL_MAX_TEXTURE_IMAGE_UNITS) - LContext->CurrentImageUnit = LContext->TextureImageUnits + unit; -} - -/*============================================================ - VERTEX ARRAYS - ============================================================ */ - -GLAPI void APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid* pointer ) -{ - rglVertexAttribPointerNV( RGL_ATTRIB_POSITION_INDEX, size, type, GL_FALSE, stride, pointer ); -} - -void rglVertexAttribPointerNV( - GLuint index, - GLint fsize, - GLenum type, - GLboolean normalized, - GLsizei stride, - const void* pointer) -{ - RGLcontext* LContext = _CurrentContext; - - GLsizei defaultStride = 0; - switch (type) - { - case GL_FLOAT: - case GL_HALF_FLOAT_ARB: - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_FIXED: - defaultStride = fsize * rglGetTypeSize(type); - break; - case GL_FIXED_11_11_10_SCE: - defaultStride = 4; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return; - } - - rglAttributeState* as = LContext->attribs; - rglAttribute* attrib = as->attrib + index; - attrib->clientSize = fsize; - attrib->clientType = type; - attrib->clientStride = stride ? stride : defaultStride; - attrib->clientData = (void*)pointer; - attrib->arrayBuffer = LContext->ArrayBuffer; - attrib->normalized = normalized; - RGLBIT_ASSIGN( as->HasVBOMask, index, attrib->arrayBuffer != 0 ); - - RGLBIT_TRUE( as->DirtyMask, index ); -} - -void rglEnableVertexAttribArrayNV (GLuint index) -{ - RGLcontext *LContext = _CurrentContext; - - RGLBIT_TRUE( LContext->attribs->EnabledMask, index ); - RGLBIT_TRUE( LContext->attribs->DirtyMask, index ); -} - -void rglDisableVertexAttribArrayNV (GLuint index) -{ - RGLcontext *LContext = _CurrentContext; - - RGLBIT_FALSE( LContext->attribs->EnabledMask, index ); - RGLBIT_TRUE( LContext->attribs->DirtyMask, index ); -} - -/*============================================================ - DEVICE CONTEXT CREATION - ============================================================ */ - -RGLdevice *_CurrentDevice = NULL; - -void rglDeviceInit (void *data) -{ - RGLinitOptions *options = (RGLinitOptions*)data; - rglPlatformDeviceInit(options); -} - -void rglDeviceExit(void) -{ - rglPlatformDeviceExit(); -} - -RGL_EXPORT RGLdevice* psglCreateDeviceAuto( GLenum colorFormat, GLenum depthFormat, GLenum multisamplingMode ) -{ - return rglPlatformCreateDeviceAuto(colorFormat, depthFormat, multisamplingMode); -} - -RGL_EXPORT RGLdevice* psglCreateDeviceExtended (const void *data) -{ - const RGLdeviceParameters *parameters = (const RGLdeviceParameters*)data; - return rglPlatformCreateDeviceExtended(parameters); -} - -RGL_EXPORT GLfloat psglGetDeviceAspectRatio (const void *data) -{ - const RGLdevice *device = (const RGLdevice*)data; - return rglPlatformGetDeviceAspectRatio(device); -} - -RGL_EXPORT void psglGetDeviceDimensions (const RGLdevice * device, GLuint *width, GLuint *height) -{ - *width = device->deviceParameters.width; - *height = device->deviceParameters.height; -} - -RGL_EXPORT void psglGetRenderBufferDimensions (const RGLdevice * device, GLuint *width, GLuint *height) -{ - *width = device->deviceParameters.renderWidth; - *height = device->deviceParameters.renderHeight; -} - -RGL_EXPORT void psglDestroyDevice (void *data) -{ - RGLdevice *device = (RGLdevice*)data; - rglGcmDriver *driver = (rglGcmDriver*)device->rasterDriver; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - rglGcmDevice *gcmDevice = ( rglGcmDevice * )device->platformDevice; - RGLdeviceParameters *params = &device->deviceParameters; - GLuint ref; - unsigned int offset_bytes = 0; - - if (_CurrentDevice == device) - psglMakeCurrent( NULL, NULL ); - - if (driver) - free(driver); - - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFinish(fifo, ref, offset_bytes); - - // Stop flip callback - if ( rescIsEnabled( params ) ) - cellRescSetFlipHandler(NULL); - else - cellGcmSetFlipHandler(NULL); - - // Stop VBlank callback - if ( rescIsEnabled( &device->deviceParameters ) ) - cellRescSetVBlankHandler(NULL); - else - cellGcmSetVBlankHandler(NULL); - - // Destroy semaphore - int res = sys_semaphore_destroy(FlipSem); - (void)res; // prevent unused variable warning in opt build - - if ( rescIsEnabled( params ) ) - { - cellRescExit(); - rglGcmFreeTiledSurface(gcmDevice->RescColorBuffersId); - gmmFree(gcmDevice->RescVertexArrayId); - gmmFree(gcmDevice->RescFragmentShaderId); - } - - rglDuringDestroyDevice = GL_TRUE; - for ( int i = 0; i < params->bufferingMode; ++i ) - { - if ( gcmDevice->color[i].pool != RGLGCM_SURFACE_POOL_NONE ) - rglGcmFreeTiledSurface( gcmDevice->color[i].dataId ); - } - rglDuringDestroyDevice = GL_FALSE; - - free( device ); -} - -void RGL_EXPORT psglMakeCurrent (RGLcontext *context, RGLdevice *device) -{ - _CurrentContext = NULL; - _CurrentDevice = NULL; - - if ( context && device ) - { - _CurrentContext = context; - _CurrentDevice = device; - - if ( !device->rasterDriver ) - { - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - GLuint ref; - unsigned int offset_bytes = 0; - - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFinish(fifo, ref, offset_bytes); - - rglGcmDriver *driver = (rglGcmDriver*)calloc(1, sizeof(rglGcmDriver)); - - if (!driver) - return; - - driver->rt.yInverted = true; - driver->invalidateVertexCache = GL_FALSE; - driver->flushBufferCount = 0; - - device->rasterDriver = driver; - } - - //attach context - if (!context->everAttached) - { - context->ViewPort.XSize = device->deviceParameters.width; - context->ViewPort.YSize = device->deviceParameters.height; - context->needValidate |= RGL_VALIDATE_VIEWPORT; - context->everAttached = GL_TRUE; - } - - context->needValidate = RGL_VALIDATE_ALL; - context->attribs->DirtyMask = ( 1 << RGL_MAX_VERTEX_ATTRIBS ) - 1; - } -} - -RGLdevice *psglGetCurrentDevice (void) -{ - return _CurrentDevice; -} - -#include "rgl_ps3_cg.cpp" diff --git a/ps3/gcmgl/src/rgl_ps3_cg.cpp b/ps3/gcmgl/src/rgl_ps3_cg.cpp deleted file mode 100644 index 57dccc982e..0000000000 --- a/ps3/gcmgl/src/rgl_ps3_cg.cpp +++ /dev/null @@ -1,5135 +0,0 @@ -#include "rgl_cg.h" -#include - -static CGbool rglpSupportsVertexProgram( CGprofile p ) -{ - if ( p == CG_PROFILE_SCE_VP_RSX ) - return CG_TRUE; - return CG_FALSE; -} - -static CGbool rglpSupportsFragmentProgram( CGprofile p ) -{ - if ( CG_PROFILE_SCE_FP_RSX == p ) - return CG_TRUE; - return CG_FALSE; -} - -static CGprofile rglpGetLatestProfile( CGGLenum profile_type ) -{ - switch ( profile_type ) - { - case CG_GL_VERTEX: - return CG_PROFILE_SCE_VP_RSX; - case CG_GL_FRAGMENT: - return CG_PROFILE_SCE_FP_RSX; - default: - break; - } - return CG_PROFILE_UNKNOWN; -} - -static int rglGcmGenerateProgram (void *data, int profileIndex, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, - const CgParameterEntry *parameterEntries, const char *stringTable, const float *defaultValues ) -{ - _CGprogram *program = (_CGprogram*)data; - CGprofile profile = ( CGprofile )programHeader->profile; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - - int need_swapping = 0; - - // if can't match a known profile, the data may be in wrong endianness - if ((( profile != CG_PROFILE_SCE_FP_RSX ) && ( profile != CG_PROFILE_SCE_VP_RSX ) )) - need_swapping = 1; - - // check that this program block is of the right revision - // i.e. that the cgBinary.h header hasn't changed since it was - // compiled. - - // validate the profile - int invalidProfile = 0; - - switch ( ENDIAN_32( profile, need_swapping ) ) - { - case CG_PROFILE_SCE_VP_RSX: - if ( profileIndex != VERTEX_PROFILE_INDEX ) - invalidProfile = 1; - break; - case CG_PROFILE_SCE_FP_RSX: - if ( profileIndex != FRAGMENT_PROFILE_INDEX ) - invalidProfile = 1; - break; - default: - invalidProfile = 1; - break; - } - - if ( invalidProfile ) - { - rglCgRaiseError( CG_UNKNOWN_PROFILE_ERROR ); - return 0; - } - - memcpy( &program->header, programHeader, sizeof( program->header ) ); - - program->ucode = ucode; - program->loadProgramId = GMM_ERROR; - program->loadProgramOffset = 0; - program->inLocalMemory = true; - - - size_t parameterSize = parameterHeader->entryCount * sizeof( CgRuntimeParameter ); - void *memoryBlock = NULL; - if ( parameterSize ) - memoryBlock = memalign( 16, parameterSize ); - - program->rtParametersCount = parameterHeader->entryCount; - program->runtimeParameters = ( CgRuntimeParameter* )memoryBlock; - - if (!parameterEntries) // the param entry can be supplied if not right after parameterHeader in memory, it happens when there's a program copy - parameterEntries = ( CgParameterEntry* )( parameterHeader + 1 ); - - program->parametersEntries = parameterEntries; - program->parameterResources = ( char* )( program->parametersEntries + program->rtParametersCount ); - program->resources = ( unsigned short* )(( char* )program->parametersEntries + ( parameterHeader->resourceTableOffset - sizeof( CgParameterTableHeader ) ) ); - program->defaultValuesIndexCount = parameterHeader->defaultValueIndexCount; - program->defaultValuesIndices = ( CgParameterDefaultValue* )(( char* )program->parametersEntries + ( parameterHeader->defaultValueIndexTableOffset - sizeof( CgParameterTableHeader ) ) ); - program->semanticCount = parameterHeader->semanticIndexCount; - program->semanticIndices = ( CgParameterSemantic* )( program->defaultValuesIndices + program->defaultValuesIndexCount ); - - program->defaultValues = NULL; - - memset( program->runtimeParameters, 0, parameterHeader->entryCount*sizeof( CgRuntimeParameter ) ); - - //string table - program->stringTable = stringTable; - //default values - program->defaultValues = defaultValues; - - rglCreatePushBuffer( program ); - int count = program->defaultValuesIndexCount; - - if ( profileIndex != FRAGMENT_PROFILE_INDEX ) - { - /* modifies the push buffer */ - for (int i = 0; i < count; i++) - { - int index = ( int )program->defaultValuesIndices[i].entryIndex; - CgRuntimeParameter *rtParameter = program->runtimeParameters + index; - - int arrayCount = 1; - const CgParameterEntry *parameterEntry = rtParameter->parameterEntry; - bool isArray = false; - if ( parameterEntry->flags & CGP_ARRAY ) - { - isArray = true; - const CgParameterArray *parameterArray = rglGetParameterArray( program, parameterEntry ); - arrayCount = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - parameterEntry++; - rtParameter++; - } - - if ( rtParameter->pushBufferPointer ) //unreferenced might have default values - { - const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); - const float *itemDefaultValues = program->defaultValues + program->defaultValuesIndices[i].defaultValueIndex; - int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; - if ( parameterEntry->flags & CGP_CONTIGUOUS ) - memcpy( rtParameter->pushBufferPointer, itemDefaultValues, arrayCount * registerStride *4*sizeof( float ) ); - else - { - unsigned int *pushBufferPointer = (( unsigned int * )rtParameter->pushBufferPointer ); - for ( int j = 0;j < arrayCount;j++ ) - { - unsigned int *pushBufferAddress = isArray ? ( *( unsigned int** )pushBufferPointer ) : pushBufferPointer; - memcpy( pushBufferAddress, itemDefaultValues, registerStride*4*sizeof( float ) ); - pushBufferPointer += isArray ? 1 : 3 + registerStride * 4; - itemDefaultValues += 4 * registerStride; - } - } - } - } - } - - // not loaded yet - program->loadProgramId = GMM_ERROR; - program->loadProgramOffset = 0; - - if ( profileIndex == FRAGMENT_PROFILE_INDEX ) - { - // always load fragment shaders. - // uploads the given fp shader to gpu memory. Allocates if needed. - // This also builds the shared constants push buffer if needed, since it depends on the load address - unsigned int ucodeSize = program->header.instructionCount * 16; - - if ( program->loadProgramId == GMM_ERROR ) - { - program->loadProgramId = gmmAlloc(ucodeSize); - program->loadProgramOffset = 0; - } - - rglGcmSend(thisContext, program->loadProgramId, program->loadProgramOffset, 0, ( char* )program->ucode, ucodeSize ); - } - - program->programGroup = NULL; - program->programIndexInGroup = -1; - - return 1; -} - -CGprogram rglpCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refcount ) -{ - if (index < ( int )group->programCount) - { - //index can be < 0 , in that case refcount update on the group only, used when destroying a copied program - if (index >= 0) - { - //if it has already been referenced duplicate instead of returning the same index, until the API offer a native support for - //group of programs ( //fixed bug 13007 ) - if (refcount == 1 && group->programs[index].refCount == 1) - { - //it will handle the refcounting - CGprogram res = cgCopyProgram( group->programs[index].program ); - return res; - } - group->programs[index].refCount += refcount; - } - - group->refCount += refcount; - - if (refcount < 0) - { - if (group->refCount == 0 && !group->userCreated) - rglCgDestroyProgramGroup( group ); - return NULL; - } - return group->programs[index].program; - } - return NULL; -} - -static CGprogramGroup rglCgCreateProgramGroupFromFile( CGcontext ctx, const char *group_file ) -{ - char *ptr = NULL; - size_t file_size = 0; - FILE* fp = fopen(group_file, "rb"); - - if (!fp) - return (CGprogramGroup)NULL; - - fseek( fp, 0, SEEK_END ); - file_size = ftell(fp); - rewind( fp ); - - // alloc memory for new binary program and read the data - ptr = (char*)malloc(file_size + 1); - if (!ptr) - { - rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); - fclose(fp); - return ( CGprogramGroup )NULL; - } - - fread( ptr, file_size, 1, fp ); - fclose( fp ); - - CGprogramGroup group = rglCgCreateProgramGroup( ctx, group_file, ptr, file_size ); - if ( !group ) - free( ptr ); - - return group; -} - -CGprogramGroup rglCgCreateProgramGroup( CGcontext ctx, const char *name, void *ptr, int size ) -{ - _CGprogramGroup *group = NULL; - CGELFBinary elfBinary; - elfBinary.elfFile = NULL; - - while ( 1 ) - { - bool res = cgOpenElf( ptr, size, &elfBinary ); - if ( !res ) - break; - - size_t elfConstTableSize = ( size_t )elfBinary.consttabSize; - size_t elfStringTableSize = ( size_t )elfBinary.strtabSize; - - //first pass to get the size of each item ( could be faster if the embedded constants index table size was in the header - int programCount = elfBinary.shadertabSize / sizeof( CgProgramHeader ); - int i; - - //structure of the memory buffer storing the group - size_t nvProgramNamesOffset = rglPad( sizeof( _CGprogramGroup ), sizeof( _CGnamedProgram ) ); //program name offset - size_t nvDefaultValuesTableOffset = rglPad( nvProgramNamesOffset + programCount * sizeof( _CGnamedProgram ), 16 );//shared default value table - - size_t nvStringTableOffset = nvDefaultValuesTableOffset + elfConstTableSize; //shared string table - size_t structureSize = nvStringTableOffset + elfStringTableSize;//total structure size - - //create the program group - group = ( CGprogramGroup )malloc( structureSize ); - if ( !group ) //out of memory - break; - - //fill the group structure - group->ctx = ctx; - group->next = NULL; - group->programCount = ( unsigned int )programCount; - group->constantTable = ( unsigned int * )(( char* )group + nvDefaultValuesTableOffset ); - group->stringTable = ( unsigned int * )(( char* )group + nvStringTableOffset ); - group->programs = ( _CGnamedProgram * )(( char* )group + nvProgramNamesOffset ); - group->userCreated = true; - group->refCount = 0; - group->filedata = ( char* )ptr; - group->name = NULL; - - if ( name ) - { - int len = strlen( name ); - group->name = ( char* )malloc( len + 1 ); - if ( !group->name )//out of memory - break; - strlcpy( group->name, name, sizeof(group->name)); - } - - //copy the default values - if ( elfConstTableSize ) - memcpy(( char* )group + nvDefaultValuesTableOffset, elfBinary.consttab, elfConstTableSize ); - //copy the string table - if ( elfStringTableSize ) - memcpy(( char* )group + nvStringTableOffset, elfBinary.strtab, elfStringTableSize ); - - //add the group to the context: - _CGcontext *context = _cgGetContextPtr(ctx); - if ( !context->groupList ) - context->groupList = group; - else - { - _CGprogramGroup *current = context->groupList; - while ( current->next ) - current = current->next; - current->next = group; - } - - //create all the shaders contained in the package and add them to the group - for ( i = 0;i < ( int )group->programCount;i++ ) - { - CgProgramHeader *cgShader = ( CgProgramHeader* )elfBinary.shadertab + i; - - //hack to counter removal of TypeC during beta - if ( cgShader->profile == ( CGprofile )7005 ) - cgShader->profile = CG_PROFILE_SCE_VP_RSX; - if ( cgShader->profile == ( CGprofile )7006 ) - cgShader->profile = CG_PROFILE_SCE_FP_RSX; - - CGELFProgram elfProgram; - bool res = cgGetElfProgramByIndex( &elfBinary, i, &elfProgram ); - if ( !res ) - return false; - - //I reference the buffer passed as parameter here, so it will have to stay around - CgProgramHeader *programHeader = cgShader; - char *ucode = ( char * )elfProgram.texttab; - CgParameterTableHeader *parameterHeader = ( CgParameterTableHeader * )elfProgram.paramtab; - - const char *programName = getSymbolByIndexInPlace( elfBinary.symtab, elfBinary.symbolSize, elfBinary.symbolCount, elfBinary.symbolstrtab, i + 1 ); - group->programs[i].name = programName; - group->programs[i].program = rglCgCreateProgram( ctx, ( CGprofile )cgShader->profile, programHeader, ucode, parameterHeader, ( const char* )group->stringTable, ( const float* )group->constantTable ); - _CGprogram *cgProgram = _cgGetProgPtr( group->programs[i].program ); - cgProgram->programGroup = group; - cgProgram->programIndexInGroup = i; - group->programs[i].refCount = 0; - } - break; - } - - return group; -} - -void rglCgDestroyProgramGroup( CGprogramGroup group ) -{ - int i; - _CGprogramGroup *_group = ( _CGprogramGroup * )group; - for (i = 0;i < (int)_group->programCount;i++ ) - { - //unlink the program - _CGprogram *cgProgram = _cgGetProgPtr( group->programs[i].program ); - cgProgram->programGroup = NULL; - cgDestroyProgram( _group->programs[i].program ); - } - free( _group->filedata ); - if ( _group->name ) - free( _group->name ); - - //remove the group from the group list - _CGcontext *context = _cgGetContextPtr( group->ctx ); - _CGprogramGroup *current = context->groupList; - _CGprogramGroup *previous = NULL; - - while ( current && current != group) - { - previous = current; - current = current->next; - } - - if ( current ) - { - if ( !previous ) - context->groupList = current->next; - else - previous->next = current->next; - } - free( _group ); -} - -const char *rglCgGetProgramGroupName (CGprogramGroup group) -{ - _CGprogramGroup *_group = ( _CGprogramGroup * )group; - if (_group) - return _group->name; - return NULL; -} - -int rglCgGetProgramIndex (CGprogramGroup group, const char *name) -{ - int i; - for ( i = 0;i < ( int )group->programCount;i++ ) - if ( !strcmp( name, group->programs[i].name ) ) - return i; - - return -1; -} - -void rglpProgramErase (void *data) -{ - _CGprogram* platformProgram = (_CGprogram*)data; - _CGprogram* program = (_CGprogram*)platformProgram; - - if (!program) - return; - - if (program->loadProgramId != GMM_ERROR ) - { - gmmFree( program->loadProgramId ); - program->loadProgramId = GMM_ERROR; - program->loadProgramOffset = 0; - } - - //free the runtime parameters - if ( program->runtimeParameters ) - { - //need to erase all the program parameter "names" - int i; - int count = ( int )program->rtParametersCount; - - for ( i = 0; i < count;i++ ) - rglEraseName( &_CurrentContext->cgParameterNameSpace, (unsigned int)program->runtimeParameters[i].id ); - - free( program->runtimeParameters ); - } - - //free the push buffer block - if ( program->memoryBlock ) - free( program->memoryBlock ); - - //free the samplers lookup tables - if ( program->samplerIndices ) - { - free( program->samplerValuesLocation ); - free( program->samplerIndices ); - free( program->samplerUnits ); - } - - //free the "pointers" on the push buffer used for fast access - if ( program->constantPushBufferPointers ) - free( program->constantPushBufferPointers ); -} - -//TODO: use a ref mechanism for the string table or duplicate it ! -int rglpCopyProgram (void *src_data, void *dst_data) -{ - _CGprogram *source = (_CGprogram*)src_data; - _CGprogram *destination = (_CGprogram*)dst_data; - //extract the layout of the parameter buffers from the source - CgParameterTableHeader parameterHeader; - parameterHeader.entryCount = source->rtParametersCount; - parameterHeader.resourceTableOffset = (uintptr_t)((char*)source->resources - ( char* )source->parametersEntries + sizeof( CgParameterTableHeader ) ); - parameterHeader.defaultValueIndexCount = source->defaultValuesIndexCount; - parameterHeader.defaultValueIndexTableOffset = (uintptr_t)(( char* )source->defaultValuesIndices - ( char* )source->parametersEntries + sizeof( CgParameterTableHeader ) ); - parameterHeader.semanticIndexCount = source->semanticCount; - parameterHeader.semanticIndexTableOffset = (uintptr_t)(( char* )source->defaultValuesIndices - ( char* )source->parametersEntries + sizeof( CgParameterTableHeader ) ); - - int profileIndex; - - //allocate the copy of the program - switch ( source->header.profile ) - { - case CG_PROFILE_SCE_VP_RSX: - profileIndex = VERTEX_PROFILE_INDEX; - break; - case CG_PROFILE_SCE_FP_RSX: - profileIndex = FRAGMENT_PROFILE_INDEX; - break; - default: - return 0; - } - return rglGcmGenerateProgram( destination, - profileIndex, &source->header, - source->ucode, ¶meterHeader, - source->parametersEntries, - source->stringTable, source->defaultValues ); -} - -int rglpGenerateVertexProgram (void *data, const CgProgramHeader *programHeader, - const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, - const float *defaultValues ) -{ - return rglGcmGenerateProgram( (_CGprogram*)data, VERTEX_PROFILE_INDEX, programHeader, - ucode, parameterHeader, NULL, stringTable, defaultValues ); - -} - -int rglpGenerateFragmentProgram (void *data, - const CgProgramHeader *programHeader, const void *ucode, - const CgParameterTableHeader *parameterHeader, const char *stringTable, - const float *defaultValues ) -{ - return rglGcmGenerateProgram( (_CGprogram*)data, - FRAGMENT_PROFILE_INDEX, programHeader, ucode, parameterHeader, - NULL, stringTable, defaultValues ); -} - -/*============================================================ - RTC CGC - ============================================================ */ - -void cgRTCgcInit( void ) -{ - _cgRTCgcCompileProgramHook = &compile_program_from_string; - _cgRTCgcFreeCompiledProgramHook = &free_compiled_program; -} - -void cgRTCgcFree( void ) -{ - _cgRTCgcCompileProgramHook = 0; - _cgRTCgcFreeCompiledProgramHook = 0; -} - -/*============================================================ - CG COMMON - ============================================================ */ - -void rglCgRaiseError( CGerror error ) -{ - _CurrentContext->RGLcgLastError = error; - - if ( _CurrentContext->RGLcgErrorCallbackFunction ) - _CurrentContext->RGLcgErrorCallbackFunction(); -} - -unsigned int rglCountFloatsInCgType( CGtype type ) -{ - int size = 0; - switch ( type ) - { - case CG_FLOAT: - case CG_FLOAT1: - case CG_FLOAT1x1: - case CG_INT: - case CG_INT1: - case CG_INT1x1: - case CG_SAMPLER1D: - case CG_SAMPLER2D: - case CG_SAMPLER3D: - case CG_SAMPLERRECT: - case CG_SAMPLERCUBE: - case CG_BOOL: - case CG_HALF: - case CG_HALF1: - case CG_HALF1x1: - case CG_FIXED: - case CG_FIXED1: - case CG_FIXED1x1: - case CG_BOOL1: - case CG_BOOL1x1: - size = 1; - break; - case CG_FLOAT2: - case CG_FLOAT2x1: - case CG_FLOAT1x2: - case CG_HALF2: - case CG_HALF2x1: - case CG_HALF1x2: - case CG_INT2: - case CG_INT2x1: - case CG_INT1x2: - case CG_BOOL2: - case CG_BOOL2x1: - case CG_BOOL1x2: - case CG_FIXED2: - case CG_FIXED2x1: - case CG_FIXED1x2: - size = 2; - break; - case CG_FLOAT3: - case CG_FLOAT3x1: - case CG_FLOAT1x3: - case CG_HALF3: - case CG_HALF3x1: - case CG_HALF1x3: - case CG_INT3: - case CG_INT3x1: - case CG_INT1x3: - case CG_BOOL3: - case CG_BOOL3x1: - case CG_BOOL1x3: - case CG_FIXED3: - case CG_FIXED3x1: - case CG_FIXED1x3: - size = 3; - break; - case CG_FLOAT4: - case CG_FLOAT4x1: - case CG_FLOAT1x4: - case CG_FLOAT2x2: - case CG_HALF4: - case CG_HALF4x1: - case CG_HALF1x4: - case CG_HALF2x2: - case CG_INT4: - case CG_INT4x1: - case CG_INT1x4: - case CG_INT2x2: - case CG_BOOL4: - case CG_BOOL4x1: - case CG_BOOL1x4: - case CG_BOOL2x2: - case CG_FIXED4: - case CG_FIXED4x1: - case CG_FIXED1x4: - case CG_FIXED2x2: - size = 4; - break; - case CG_FLOAT2x3: - case CG_FLOAT3x2: - case CG_HALF2x3: - case CG_HALF3x2: - case CG_INT2x3: - case CG_INT3x2: - case CG_BOOL2x3: - case CG_BOOL3x2: - case CG_FIXED2x3: - case CG_FIXED3x2: - size = 6; - break; - case CG_FLOAT2x4: - case CG_FLOAT4x2: - case CG_HALF2x4: - case CG_HALF4x2: - case CG_INT2x4: - case CG_INT4x2: - case CG_BOOL2x4: - case CG_BOOL4x2: - case CG_FIXED2x4: - case CG_FIXED4x2: - size = 8; - break; - case CG_FLOAT3x3: - case CG_HALF3x3: - case CG_INT3x3: - case CG_BOOL3x3: - case CG_FIXED3x3: - size = 9; - break; - case CG_FLOAT3x4: - case CG_FLOAT4x3: - case CG_HALF3x4: - case CG_HALF4x3: - case CG_INT3x4: - case CG_INT4x3: - case CG_BOOL3x4: - case CG_BOOL4x3: - case CG_FIXED3x4: - case CG_FIXED4x3: - size = 12; - break; - case CG_FLOAT4x4: - case CG_HALF4x4: - case CG_INT4x4: - case CG_BOOL4x4: - case CG_FIXED4x4: - size = 16; - break; - default: - size = 0; - break; - } - return size; -} - -void _cgRaiseInvalidParam (void *data, const void*v ) -{ - (void)data; -} - -void _cgRaiseNotMatrixParam (void *data, const void*v ) -{ - (void)data; -} - -void _cgIgnoreParamIndex (void *data, const void*v, const int index ) -{ - (void)data; - // nothing -} - -CgRuntimeParameter* _cgGLTestTextureParameter( CGparameter param ) -{ - CgRuntimeParameter* ptr = rglCgGLTestParameter( param ); - return ptr; -} - - -#define CG_DATATYPE_MACRO(name, compiler_name, enum_name, base_enum, nrows, ncols,classname) \ - nrows , -static int _typesRowCount[] = -{ -#include "Cg/cg_datatypes.h" -}; - -#define CG_DATATYPE_MACRO(name, compiler_name, enum_name, base_enum, nrows, ncols,classname) \ - ncols , -static int _typesColCount[] = -{ -#include "Cg/cg_datatypes.h" -}; - -unsigned int rglGetTypeRowCount( CGtype parameterType ) -{ - int typeIndex = parameterType - 1 - CG_TYPE_START_ENUM; - return _typesRowCount[typeIndex]; -} - -unsigned int rglGetTypeColCount( CGtype parameterType ) -{ - int typeIndex = parameterType - 1 - CG_TYPE_START_ENUM; - return _typesColCount[typeIndex]; -} - -/*============================================================ - CG PARAMETER - ============================================================ */ - -static const CGenum var_table[] = {CG_VARYING, CG_UNIFORM, CG_CONSTANT, CG_MIXED}; -static const CGenum dir_table[] = {CG_IN, CG_OUT, CG_INOUT, CG_ERROR}; - -RGL_EXPORT CgparameterHookFunction _cgParameterCreateHook = NULL; -RGL_EXPORT CgparameterHookFunction _cgParameterDestroyHook = NULL; - -static CGparameter rglAdvanceParameter( CGparameter param, int distance ) -{ - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return NULL; - - if ( distance == 0 ) - return param; - - if ( rtParameter > rtParameter->program->runtimeParameters ) - { - CgRuntimeParameter *previousParameter = rtParameter - 1; - if (( previousParameter->parameterEntry->flags & CGP_ARRAY ) && - !( previousParameter->parameterEntry->flags & CGP_UNROLLED ) ) - { - int arrayIndex = CG_GETINDEX( param ); - arrayIndex += distance; - const CgParameterArray *parameterArray = rglGetParameterArray( previousParameter->program, previousParameter->parameterEntry ); - int arraySize = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - if ( arrayIndex < arraySize ) - { - int ret = ( int )rtParameter->id; - ret |= ( arrayIndex << CG_PARAMETERSIZE ); - return ( CGparameter )ret; - } - return ( CGparameter )NULL; - } - } - - //stop when the distance is 0 - const CgParameterEntry *endEntry = rtParameter->program->parametersEntries + rtParameter->program->rtParametersCount; - const CgParameterEntry *paramEntry = rtParameter->parameterEntry; - - while ( distance && paramEntry < endEntry ) - { - switch ( paramEntry->flags & CGP_TYPE_MASK ) - { - case CGP_ARRAY: - { - if ( paramEntry->flags & CGP_UNROLLED ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( rtParameter->program, paramEntry ); - int arraySize = ( int )rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - - paramEntry++; - distance--; - - paramEntry++; - distance += arraySize; - } - else - { - paramEntry++; - distance--; - paramEntry++; - } - break; - } - case CGP_STRUCTURE: - { - const CgParameterStructure *parameterStructure = rglGetParameterStructure( rtParameter->program, paramEntry ); - paramEntry++; - distance--; - distance += parameterStructure->memberCount; - break; - } - case CGP_INTRINSIC: - paramEntry++; - distance--; - break; - } - } - - if ( paramEntry < endEntry ) - { - size_t offset = ( paramEntry - rtParameter->parameterEntry ); - CgRuntimeParameter *nextParameter = rtParameter + offset; - return nextParameter->id; - } - return ( CGparameter )NULL; -} - -void rglCgDestroyContextParam( CgRuntimeParameter* ptr ) -{ - if (_cgParameterDestroyHook) - _cgParameterDestroyHook( ptr ); - - rglEraseName( &_CurrentContext->cgParameterNameSpace, (unsigned int)( ptr->id ) ); - - free( ptr ); -} - -static int rglGetSizeofSubArray( const short *dimensions, int count ) -{ - int res = 1; - for ( int i = 0;i < count;i++ ) - res *= ( int )( *( dimensions++ ) ); - return res; -} - - -static _CGparameter *_cgGetNamedParameter(_CGprogram* progPtr, - const char* name, CGenum name_space, int *arrayIndex, - const CgParameterEntry *_startEntry = NULL, int _entryCount = -1) -{ - if (!name) - return NULL; - - *arrayIndex = -1; - int done = 0; - const char *structureEnd; - const char *structureStart = name; - int itemIndex = -1; - _CGprogram *program = progPtr; - - const CgParameterEntry *currentEntry; - const CgParameterEntry *lastEntry; - - int containerCount = -2; - if ( _startEntry && _entryCount != -1 ) - { - currentEntry = _startEntry; - containerCount = _entryCount; - } - else - currentEntry = program->parametersEntries; - - lastEntry = program->parametersEntries + program->rtParametersCount; - - int isInArray = 0; - bool bWasUnrolled = false; - const char *prevStructureStart = structureStart; //for unrolled - - while (( !done ) && ( *structureStart ) && ( containerCount != -1 ) ) - { - structureEnd = strpbrk( structureStart, ".[" ); - if (!structureEnd) - { - structureEnd = structureStart + strlen( structureStart ); - done = 1; - } - - if ( bWasUnrolled ) - { - bWasUnrolled = false; - structureStart = prevStructureStart; - } - char structName[256]; - int length = ( int )( structureEnd - structureStart ); - strncpy( structName, structureStart, length ); - structName[length] = '\0'; - prevStructureStart = structureStart; //for unrolled - structureStart = structureEnd + 1; - - bool found = false; - while ( !found && currentEntry < lastEntry && ( containerCount == -2 || containerCount > 0 ) ) - { - if ( !strncmp( structName, program->stringTable + currentEntry->nameOffset, length ) - && ( name_space == 0 || ( name_space == CG_GLOBAL && ( currentEntry->flags & CGPF_GLOBAL ) ) - || ( name_space == CG_PROGRAM && !( currentEntry->flags & CGPF_GLOBAL ) ) ) ) - { - if (( int )strlen( program->stringTable + currentEntry->nameOffset ) != length ) - { - if ( !strcmp( name, program->stringTable + currentEntry->nameOffset ) ) - { - found = true; - done = 1; - } - - if ( !strncmp( name, program->stringTable + currentEntry->nameOffset, length ) && - !strcmp( "[0]", program->stringTable + currentEntry->nameOffset + length ) ) - { - found = true; - done = 1; - } - } - else - found = true; - } - - if ( !found ) - { - //we are skipping entries here, the search stays at the same level - int skipCount = 1; - while ( skipCount && currentEntry < lastEntry ) - { - //skip as many entry as necessary - if ( currentEntry->flags & CGP_STRUCTURE ) - { - const CgParameterStructure *parameterStructure = (const CgParameterStructure*)rglGetParameterStructure( program, currentEntry ); - skipCount += parameterStructure->memberCount; - } - else if ( currentEntry->flags & CGP_ARRAY ) - { - if ( currentEntry->flags & CGP_UNROLLED ) - { - const CgParameterArray *parameterArray = (const CgParameterArray*)rglGetParameterArray( program, currentEntry ); - skipCount += rglGetSizeofSubArray(( short* )parameterArray->dimensions, parameterArray->dimensionCount ); - } - else - skipCount++; //the following item will be the type ( can't be a structure as they are always enrolled at the moment ) - } - currentEntry++; - skipCount--; - } - } - if ( containerCount != -2 ) //denotes that we are in a structure or in an array and that we shouldn't look beyond - containerCount--; - } - //at that point we failed or we succeeded to find the entry at that level. - //if we have succeed we continue in the lower level if needed. if we have failed, we return not found. - - if ( found ) - { - switch ( currentEntry->flags & CGP_TYPE_MASK ) { - case 0: - itemIndex = ( int )( currentEntry - program->parametersEntries ); - break; - case CGP_ARRAY: - { - - const CgParameterEntry *arrayEntry = currentEntry; - const CgParameterArray *parameterArray = rglGetParameterArray( program, arrayEntry ); - - if ( *structureEnd == '\0' ) //if we are asked for the array parameter itself and not an array item: - { - itemIndex = ( int )( currentEntry - program->parametersEntries ); - break; - } - - //go inside: - currentEntry++; - if ( currentEntry->flags &CGP_STRUCTURE ) - { - //continue to look into the list, but we should stop before the end of the array - bWasUnrolled = true; - containerCount = rglGetSizeofSubArray(( short* )parameterArray->dimensions, parameterArray->dimensionCount ); - break; - } - else - { - //the array contains base types - isInArray = 1; - const char *arrayStart = structureEnd; - const char *arrayEnd = structureEnd; - - int dimensionCount = 0; - int arrayCellIndex = 0; - while ( *arrayStart == '[' && dimensionCount < parameterArray->dimensionCount ) - { - arrayEnd = strchr( arrayStart + 1, ']' ); - int length = ( int )( arrayEnd - arrayStart - 1 ); - char indexString[16]; - strncpy( indexString, arrayStart + 1, length ); - indexString[length] = '\0'; - int index = atoi( indexString ); - int rowSize = parameterArray->dimensions[dimensionCount]; - if ( index >= rowSize ) - { - //index out of range: not found - return NULL; - } - arrayCellIndex += index * rglGetSizeofSubArray(( short* )parameterArray->dimensions + dimensionCount, parameterArray->dimensionCount - dimensionCount - 1 ); - - arrayStart = arrayEnd + 1; - dimensionCount++; - } - structureEnd = arrayStart; - if ( *structureEnd == '\0' ) - done = 1; - - if ( done ) - { - //found the item in the array - ( *arrayIndex ) = arrayCellIndex; - itemIndex = ( int )( currentEntry - program->parametersEntries ); - } - //else... don't know what to do, it's a array of structure not unrolled - } - } - break; - case CGP_STRUCTURE: - if ( done ) - { - //the user is getting back a strut... not sure that all the checks are in place for such a return value - itemIndex = ( int )( currentEntry - program->parametersEntries ); - } - else - { - const CgParameterStructure *parameterStructure = rglGetParameterStructure( program, currentEntry ); - containerCount = parameterStructure->memberCount; - } - break; - default: - break; - } - } - if ( found ) - { - if ( !bWasUnrolled ) - currentEntry++; - } - break;//not found - } - - //have we found it ? - if ( itemIndex != -1 ) - return ( _CGparameter* )( program->runtimeParameters + itemIndex ); - return NULL; -} - -// API functions ---------------------------------------- - -CG_API CGparameter cgGetNamedParameter( CGprogram prog, const char* name ) -{ - // check program handle - if ( !CG_IS_PROGRAM( prog ) ) - { - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return ( CGparameter )NULL; - } - - _CGprogram* progPtr = _cgGetProgPtr( prog ); - // 0 means don't care - int arrayIndex = -1; - CgRuntimeParameter *param = ( CgRuntimeParameter * )_cgGetNamedParameter( progPtr, name, ( CGenum )0, &arrayIndex ); - if ( param ) - { - int ret = ( int )param->id; - if ( arrayIndex != -1 ) - ret |= ( arrayIndex << CG_PARAMETERSIZE ); - return ( CGparameter )ret; - } - return ( CGparameter )NULL; -} - -CG_API CGparameter cgGetFirstParameter( 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 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 ) - { - return ( CGparameter )rtParameter->id; - } - if ( !isGlobal && name_space == CG_PROGRAM ) - { - return ( CGparameter )rtParameter->id; - } - rtParameter++; - } - return ( CGparameter )NULL; -} - -CG_API CGparameter cgGetNextParameter( CGparameter param ) -{ - //check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - 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 ) - { - CgRuntimeParameter *previousParameter = rtParameter - 1; - if (( previousParameter->parameterEntry->flags & CGP_ARRAY ) && - !( previousParameter->parameterEntry->flags & CGP_UNROLLED ) ) - { - //we have an array item - arrayIndex = CG_GETINDEX( param ); - const CgParameterArray *parameterArray = rglGetParameterArray( previousParameter->program, previousParameter->parameterEntry ); - int arraySize = rglGetSizeofSubArray(( short* )parameterArray->dimensions, parameterArray->dimensionCount ); - arrayIndex++; - if ( arrayIndex < arraySize ) - { - int ret = ( int )rtParameter->id; - ret |= ( arrayIndex << CG_PARAMETERSIZE ); - return ( CGparameter )ret; - } - return ( CGparameter )NULL; - } - } - - //get the parent of the current as well as its location - const CgParameterEntry *paramEntry = rtParameter->parameterEntry; - const CgParameterEntry *firstEntry = rtParameter->program->parametersEntries; - - int distance = 1; - paramEntry--; - - bool bNextExists = false; - while ( paramEntry >= firstEntry && !bNextExists ) - { - switch ( paramEntry->flags & CGP_TYPE_MASK ) - { - case CGP_ARRAY: - distance--; // the array has one extra item, whether it's a structure or if it's an intrinsic type - //Ced: not it's not true, if it's unrolled there is no extra item - break; - case CGP_STRUCTURE: - { - const CgParameterStructure *parameterStructure = rglGetParameterStructure( rtParameter->program, paramEntry ); - //+1 because of the structure element, there's structure - if ( distance >= ( parameterStructure->memberCount + 1 ) ) - { - //the parameter is not in this structure, so I need to remove from the distance all the structure item - //so this structure will count for a distance of just one ( the distance is the level distance ) - distance -= parameterStructure->memberCount; - } - else - { - //We are going to exit here - //ok so we were in this structure, so check if we have more item in the structure after the current one - if ( distance < parameterStructure->memberCount ) - { - //we still have some items in the structure, take the next item - bNextExists = true; - break; - } - //no more items at this level return null - return ( CGparameter )NULL; - } - break; - } - case CGP_INTRINSIC: - break; - } - distance++; - paramEntry--; - } - //we have now elimated the case where we were in a struct and there were no more items, now if the item has a successor, - //this is what we are looking for - - //we have already treated the current entry at that point, the loop starts on the previous one, the distance is 1 - CGparameter nextParam = rglAdvanceParameter( rtParameter->id, 1 ); - - if ( nextParam ) - { - CgRuntimeParameter *nextParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( nextParam ); - - //check that next param is still in the same namespace as param - bool isCurrentGlobal = ( rtParameter->parameterEntry->flags & CGPF_GLOBAL ) == CGPF_GLOBAL; - bool isNextGlobal = ( nextParameter->parameterEntry->flags & CGPF_GLOBAL ) == CGPF_GLOBAL; - if ( isNextGlobal != isCurrentGlobal ) - { - //the next item doesn't have the same global flag... since they are grouped, it means we have quitted the current struct - return ( CGparameter )NULL; - } - return nextParam; - } - //case where we were at the root and there is no more items - return ( CGparameter )NULL; -} - -CG_API const char* cgGetParameterSemantic( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return NULL; - - 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; - } - - 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 ) -{ - int len = strlen(src); - int previousLen = strlen(dst); - int spaceLeft = size - (previousLen + 1); //+1 for white space - if (spaceLeft < len) - return false; - memmove(dst + len, dst, previousLen + 1); - strncpy(dst, src, len); - return true; -} - -CG_API CGenum cgGetParameterVariability( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return ( CGenum )0; - - { - unsigned int variability = rtParameter->parameterEntry->flags & CGPV_MASK; - if ( variability == CGPV_UNIFORM ) - return CG_UNIFORM; - if ( variability == CGPV_VARYING ) - return CG_VARYING; - if ( variability == CGPV_CONSTANT ) - return CG_CONSTANT; - if ( variability == CGPV_MIXED ) - return CG_MIXED; - return ( CGenum )0; - } -} - -CG_API CGenum cgGetParameterDirection( CGparameter param ) -{ - // check parameter handle - CgRuntimeParameter *rtParameter = ( CgRuntimeParameter* )rglCgGLTestParameter( param ); - if ( !rtParameter ) - return CG_ERROR; - { - unsigned int direction = rtParameter->parameterEntry->flags & CGPD_MASK; - if ( direction == CGPD_IN ) - return CG_IN; - if ( direction == CGPD_OUT ) - return CG_OUT; - if ( direction == CGPD_INOUT ) - return CG_INOUT; - return CG_ERROR; - } -} - -/*============================================================ - CG TOKENS - ============================================================ */ - -// ErrorFunctions ---------------------------- -CG_API CGerror cgGetError( void ) -{ - CGerror err = _CurrentContext->RGLcgLastError; - _CurrentContext->RGLcgLastError = CG_NO_ERROR; - return err; -} - -CG_API const char* cgGetErrorString( CGerror error ) -{ - return "cgGetErrorString not implemented.\n"; -} - -CG_API void cgSetErrorCallback( CGerrorCallbackFunc func ) -{ - _CurrentContext->RGLcgErrorCallbackFunction = func; -} - -CG_API CGerrorCallbackFunc cgGetErrorCallback( void ) -{ - return _CurrentContext->RGLcgErrorCallbackFunction; -} - - -// Misc Functions ----------------------------- - -CG_API const char* cgGetString( CGenum sname ) -{ - if ( sname == CG_VERSION ) - { - // this should return the version of the runtime or perhaps more meaninfully, the runtime compiler - static char versionstring[8]; - sprintf( versionstring, "%d", CG_VERSION_NUM ); - return versionstring; - } - - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - return NULL; -} - -/*============================================================ - CG CONTEXT - ============================================================ */ - -RGL_EXPORT CgcontextHookFunction _cgContextCreateHook = NULL; -RGL_EXPORT CgcontextHookFunction _cgContextDestroyHook = NULL; - -void rglCgContextPushFront( _CGcontext* ctx ) -{ - if ( _CurrentContext->RGLcgContextHead ) - { - _CGcontext* head = _cgGetContextPtr( _CurrentContext->RGLcgContextHead ); - // insert this context at the head of the list - ctx->next = head; - } - _CurrentContext->RGLcgContextHead = ctx->id; -} - -static void destroy_context( _CGcontext*ctx ) -{ - if ( _cgContextDestroyHook ) _cgContextDestroyHook( ctx ); - // free the id - rglEraseName( &_CurrentContext->cgContextNameSpace, (unsigned int)ctx->id ); - // zero the memory - memset(ctx, 0, sizeof( *ctx)); - ctx->compileType = CG_UNKNOWN; - // return context to free store - free( ctx ); -} - -// API functions ---------------------------------------- - -CG_API CGcontext cgCreateContext( void ) -{ - // create a context out of thin air and add it to the hidden global list. - - _CGcontext* ptr = (_CGcontext*)calloc(1, sizeof(_CGcontext)); - - if (!ptr) - { - rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); - return ( CGcontext )NULL; - } - - ptr->compileType = CG_UNKNOWN; - - // get a new id for the object - CGcontext result = ( CGcontext )rglCreateName( &_CurrentContext->cgContextNameSpace, ptr ); - if ( !result ) { free( ptr ); return NULL; } - - ptr->id = result; - ptr->defaultProgram.parentContext = ptr; - - // insert context at head of global list - rglCgContextPushFront( ptr ); - - if ( _cgContextCreateHook ) _cgContextCreateHook( ptr ); - - return result; -} - -CG_API void cgDestroyContext( CGcontext c ) -{ - // check if context is valid - if ( !CG_IS_CONTEXT( c ) ) - { - rglCgRaiseError( CG_INVALID_CONTEXT_HANDLE_ERROR ); - return; - } - - _CGcontext* ctx = _cgGetContextPtr( c ); - - rglCgProgramErase( &ctx->defaultProgram ); - - // destroy all programs - rglCgProgramDestroyAll( ctx ); - - // unlink from global CGContext list - _CGcontext * const head = _cgGetContextPtr( _CurrentContext->RGLcgContextHead ); - if ( head != ctx ) - { - // node is not the head, find and erase it - - // find the context that occurs before this one - _CGcontext* ptr = head; - while ( ptr->next != ctx ) - ptr = ptr->next; - // relink - ptr->next = ctx->next; - destroy_context( ctx ); - } - else - { - - // node is the head, erase it - _CGcontext* second = head->next; - destroy_context( head ); - - // link to second element - if ( second ) - _CurrentContext->RGLcgContextHead = second->id; - // nothing left - else - _CurrentContext->RGLcgContextHead = 0; - } -} - -CG_API const char* cgGetLastListing( CGcontext c ) -{ - // check to see if context is a valid one - // NOTE: Cg API Reference docs omit this test for this API function. - if ( !CG_IS_CONTEXT( c ) ) - { - rglCgRaiseError( CG_INVALID_CONTEXT_HANDLE_ERROR ); - return NULL; - } - - // currently does nothing - // TODO **************************** - - return NULL; -} - - -/*============================================================ - CG PROGRAM - ============================================================ */ - -RGL_EXPORT CgprogramHookFunction _cgProgramCreateHook = NULL; -RGL_EXPORT CgprogramHookFunction _cgProgramDestroyHook = NULL; -RGL_EXPORT CgprogramCopyHookFunction _cgProgramCopyHook = NULL; - -RGL_EXPORT cgRTCgcCompileHookFunction _cgRTCgcCompileProgramHook = NULL; -RGL_EXPORT cgRTCgcFreeHookFunction _cgRTCgcFreeCompiledProgramHook; - -// Program list functions -// The context can contain many programs, but each one is a variable sized -// chunk of data produced by the CGC compiler and loaded at runtime. We cannot -// include intrusive "next" pointers in this data block so instead we'll use -// a non-intrusive list. The list is walked using cgGetFirstProgram() and -// cgGetNextProgram() - -void rglCgProgramPushFront( _CGcontext* ctx, _CGprogram* prog ) -{ - // push the program to the context. - // updates the linked list and program count - - // link the node into the head of the list - prog->next = ctx->programList; - ctx->programList = prog; - - // update the parent context - prog->parentContext = ctx; - - // update the program count - ctx->programCount++; -} - -_CGprogram* rglCgProgramFindPrev( _CGcontext* ctx, _CGprogram* prog ) -{ - // get a pointer the the list element *before* prog in the list - // this allows us to unlink it safely. - - _CGprogram* ptr = ctx->programList; - - while (ptr && prog != ptr->next ) - ptr = ptr->next; - - return ptr; -} - -inline void rglCgProgramEraseAndFree( _CGprogram* prog ) -{ - rglCgProgramErase( prog ); - free( prog ); -} - -void rglCgProgramErase( _CGprogram* prog ) -{ - // remove the program from the linked list and deallocate it's storage. - - if ( _cgProgramDestroyHook ) _cgProgramDestroyHook( prog ); - - switch ( prog->header.profile ) - { - case CG_PROFILE_SCE_VP_RSX: - case CG_PROFILE_SCE_FP_RSX: - rglpProgramErase( prog ); - break; - default: - // default program - break; - } - - // return program and node to free store - if ( prog->id ) rglEraseName( &_CurrentContext->cgProgramNameSpace, (unsigned int)prog->id ); - - //free ELF data obtained from the runtime converter - if ( prog->runtimeElf ) - free( prog->runtimeElf ); - - // zero out all pointers - memset( prog, 0, sizeof( _CGprogram ) ); -} - -void rglCgProgramEraseAfter( _CGprogram* prog ) -{ - // delete the list entry after the current pointer. - // (use in conjunction with find_prev for full effect!) - - _CGprogram* next = prog->next; - if ( next ) - { - prog->next = next->next; - rglCgProgramEraseAndFree( next ); - } -} - -void rglCgProgramDestroyAll( _CGcontext* ctx ) -{ - // destroy all programs in this context - while ( ctx->programList ) - { - _CGprogram * p = ctx->programList; - ctx->programList = p->next; - // erase the program - rglCgProgramEraseAndFree( p ); - } -} - - -static inline unsigned int getMatrixRowCount( CGtype type ) -{ - unsigned int rc = 0; - switch ( type ) - { - case CG_FLOAT1x1: - case CG_FLOAT1x2: - case CG_FLOAT1x3: - case CG_FLOAT1x4: - case CG_HALF1x1: - case CG_HALF1x2: - case CG_HALF1x3: - case CG_HALF1x4: - case CG_INT1x1: - case CG_INT1x2: - case CG_INT1x3: - case CG_INT1x4: - case CG_BOOL1x1: - case CG_BOOL1x2: - case CG_BOOL1x3: - case CG_BOOL1x4: - case CG_FIXED1x1: - case CG_FIXED1x2: - case CG_FIXED1x3: - case CG_FIXED1x4: - rc = 1; - break; - case CG_FLOAT2x1: - case CG_FLOAT2x2: - case CG_FLOAT2x3: - case CG_FLOAT2x4: - case CG_HALF2x1: - case CG_HALF2x2: - case CG_HALF2x3: - case CG_HALF2x4: - case CG_INT2x1: - case CG_INT2x2: - case CG_INT2x3: - case CG_INT2x4: - case CG_BOOL2x1: - case CG_BOOL2x2: - case CG_BOOL2x3: - case CG_BOOL2x4: - case CG_FIXED2x1: - case CG_FIXED2x2: - case CG_FIXED2x3: - case CG_FIXED2x4: - rc = 2; - break; - case CG_FLOAT3x1: - case CG_FLOAT3x2: - case CG_FLOAT3x3: - case CG_FLOAT3x4: - case CG_HALF3x1: - case CG_HALF3x2: - case CG_HALF3x3: - case CG_HALF3x4: - case CG_INT3x1: - case CG_INT3x2: - case CG_INT3x3: - case CG_INT3x4: - case CG_BOOL3x1: - case CG_BOOL3x2: - case CG_BOOL3x3: - case CG_BOOL3x4: - case CG_FIXED3x1: - case CG_FIXED3x2: - case CG_FIXED3x3: - case CG_FIXED3x4: - rc = 3; - break; - case CG_FLOAT4x1: - case CG_FLOAT4x2: - case CG_FLOAT4x3: - case CG_FLOAT4x4: - case CG_HALF4x1: - case CG_HALF4x2: - case CG_HALF4x3: - case CG_HALF4x4: - case CG_INT4x1: - case CG_INT4x2: - case CG_INT4x3: - case CG_INT4x4: - case CG_BOOL4x1: - case CG_BOOL4x2: - case CG_BOOL4x3: - case CG_BOOL4x4: - case CG_FIXED4x1: - case CG_FIXED4x2: - case CG_FIXED4x3: - case CG_FIXED4x4: - rc = 4; - break; - default: - break; - } - return rc; -} - -CGtype getMatrixRowType( CGtype type ) -{ - CGtype rt = ( CGtype )0; - switch ( type ) - { - case CG_FLOAT1x1: - case CG_FLOAT2x1: - case CG_FLOAT3x1: - case CG_FLOAT4x1: - rt = CG_FLOAT1; - break; - case CG_FLOAT1x2: - case CG_FLOAT2x2: - case CG_FLOAT3x2: - case CG_FLOAT4x2: - rt = CG_FLOAT2; - break; - case CG_FLOAT1x3: - case CG_FLOAT2x3: - case CG_FLOAT3x3: - case CG_FLOAT4x3: - rt = CG_FLOAT3; - break; - case CG_FLOAT1x4: - case CG_FLOAT2x4: - case CG_FLOAT3x4: - case CG_FLOAT4x4: - rt = CG_FLOAT4; - break; - case CG_HALF1x1: - case CG_HALF2x1: - case CG_HALF3x1: - case CG_HALF4x1: - rt = CG_HALF1; - break; - case CG_HALF1x2: - case CG_HALF2x2: - case CG_HALF3x2: - case CG_HALF4x2: - rt = CG_HALF2; - break; - case CG_HALF1x3: - case CG_HALF2x3: - case CG_HALF3x3: - case CG_HALF4x3: - rt = CG_HALF3; - break; - case CG_HALF1x4: - case CG_HALF2x4: - case CG_HALF3x4: - case CG_HALF4x4: - rt = CG_HALF4; - break; - case CG_INT1x1: - case CG_INT2x1: - case CG_INT3x1: - case CG_INT4x1: - rt = CG_INT1; - break; - case CG_INT1x2: - case CG_INT2x2: - case CG_INT3x2: - case CG_INT4x2: - rt = CG_INT2; - break; - case CG_INT1x3: - case CG_INT2x3: - case CG_INT3x3: - case CG_INT4x3: - rt = CG_INT3; - break; - case CG_INT1x4: - case CG_INT2x4: - case CG_INT3x4: - case CG_INT4x4: - rt = CG_INT4; - break; - case CG_BOOL1x1: - case CG_BOOL2x1: - case CG_BOOL3x1: - case CG_BOOL4x1: - rt = CG_BOOL1; - break; - case CG_BOOL1x2: - case CG_BOOL2x2: - case CG_BOOL3x2: - case CG_BOOL4x2: - rt = CG_BOOL2; - break; - case CG_BOOL1x3: - case CG_BOOL2x3: - case CG_BOOL3x3: - case CG_BOOL4x3: - rt = CG_BOOL3; - break; - case CG_BOOL1x4: - case CG_BOOL2x4: - case CG_BOOL3x4: - case CG_BOOL4x4: - rt = CG_BOOL4; - break; - case CG_FIXED1x1: - case CG_FIXED2x1: - case CG_FIXED3x1: - case CG_FIXED4x1: - rt = CG_FIXED1; - break; - case CG_FIXED1x2: - case CG_FIXED2x2: - case CG_FIXED3x2: - case CG_FIXED4x2: - rt = CG_FIXED2; - break; - case CG_FIXED1x3: - case CG_FIXED2x3: - case CG_FIXED3x3: - case CG_FIXED4x3: - rt = CG_FIXED3; - break; - case CG_FIXED1x4: - case CG_FIXED2x4: - case CG_FIXED3x4: - case CG_FIXED4x4: - rt = CG_FIXED4; - break; - default: - break; - } - return rt; -} - - -// forward declaration for recursion -void AccumulateSizeForParams( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - unsigned int prefixLength, int elementResourceIndex, - size_t* nvParamSize, size_t* nvParamStringsSize, size_t* nvParamOffsetsSize, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, size_t* nvParamDefaultsSize, - ELF_section_t* consttab ); - -void AccumulateSizeForParamResource( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - unsigned int prefixLength, int elementResourceIndex, - size_t* nvParamSize, size_t* nvParamStringsSize, size_t* nvParamOffsetsSize, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, size_t* nvParamDefaultsSize, - ELF_section_t* consttab ) -{ - // type index is actually the offset into the block of memory following the entries - CgParameterResource* paramResource = ( CgParameterResource* )(( char* )( paramEntries + paramEntriesCount ) + paramEntry->typeIndex ); - - unsigned int rowCount = getMatrixRowCount(( CGtype )paramResource->type ); - - // param - *nvParamSize += sizeof( CgBinaryParameter ); - // and for the row params of a matrix - *nvParamSize += rowCount * sizeof( CgBinaryParameter ); - - // name - *nvParamStringsSize += ( prefixLength + strlen( strtab->data + paramEntry->nameOffset ) + 1 ); - // and for each row of a matrix which assumes just an extra 3 characters for [i] - *nvParamStringsSize += ( rowCount * ( prefixLength + strlen( strtab->data + paramEntry->nameOffset ) + 3 + 1 ) ); - - - // semantic - - // totally inefficient, but easiest implementation for now is to do the On^2 search - // in the semantic and default tables for the data associated with this parameter - unsigned int entryIndex = paramEntry - paramEntries; - - // semantic - char* semantic = NULL; - for ( unsigned int sem = 0; sem < semanticIndexCount; sem++ ) - { - CgParameterSemantic* semanticIndex = semanticIndexTable + sem; - if ( semanticIndex->entryIndex == entryIndex ) - { - // found the semantic for this parameter - semantic = strtab->data + semanticIndex->semanticOffset; - break; - } - } - if ( semantic ) - { - // increment the names size buffer - *nvParamStringsSize += strlen( semantic ) + 1; - } - - // default - float* defaults = NULL; - for ( unsigned int def = 0; def < defaultIndexCount; def++ ) - { - CgParameterDefaultValue* defaultIndex = defaultIndexTable + def; - if ( defaultIndex->entryIndex == entryIndex ) - { - // found the default for this parameter - defaults = ( float* )consttab->data + defaultIndex->defaultValueIndex; - } - } - if (defaults) - { - // defaults are always padded to 4 floats per param - unsigned int defaultsCount = ( rowCount ? rowCount : 1 ) * 4; - *nvParamDefaultsSize += sizeof( float ) * defaultsCount; - } - - // offsets - // fragment programs - // do we want this referenced param test??? - if (nvParamOffsetsSize && paramEntry->flags & CGPF_REFERENCED ) - { - // non varying params - if ( paramEntry->flags & CGPV_CONSTANT || paramEntry->flags & CGPV_UNIFORM ) - { - // non sampler types - if ( !isSampler(( CGtype )paramResource->type ) ) - { - unsigned short* resPtr = paramResourceTable + paramResource->resource; - - if ( elementResourceIndex >= 0 ) - { - //advance resPtr to the arrayIndex - int skipCount = elementResourceIndex; - while ( skipCount ) - { - resPtr++; - int embeddedCount = *( resPtr++ ); - resPtr += embeddedCount; - // if an array of matrices, must skip row parameter resources too - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - resPtr++; - int embeddedCount = *( resPtr++ ); - resPtr += embeddedCount; - } - skipCount--; - } - //resPtr points to the resource of the arrayIndex - } - - if ( !isMatrix(( CGtype )( paramResource->type ) ) ) - { - // advance past register to second field that contains embedded count - resPtr++; - unsigned int embeddedConstantCount = *( resPtr++ ); - *nvParamOffsetsSize += sizeof( CgBinaryEmbeddedConstant ) + sizeof( unsigned int ) * ( embeddedConstantCount - 1 ); - } - else - { - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - // advance past register to second field that contains embedded count - resPtr++; - unsigned int embeddedConstantCount = *( resPtr++ ); - *nvParamOffsetsSize += sizeof( CgBinaryEmbeddedConstant ) + sizeof( unsigned int ) * ( embeddedConstantCount - 1 ); - } - } - - } - } - - } - - - // entry cursor - *nextEntry = paramEntry + 1; -} - -void AccumulateSizeForParamArray( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - unsigned int prefixLength, int elementResourceIndex, - size_t* nvParamSize, size_t* nvParamStringsSize, size_t* nvParamOffsetsSize, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, size_t* nvParamDefaultsSize, - ELF_section_t* consttab ) -{ - // type index is actually the offset into the block of memory following the entries - CgParameterArray* paramArray = ( CgParameterArray* )(( char* )( paramEntries + paramEntriesCount ) + paramEntry->typeIndex ); - - // this parameter's entry says it's an array - // this parameter's entry says its packing in the flags - // the next entry specifies its type... - // ... either a list of every element in the array - // ... or a single element in the array to represent all because they are the same - // ... or a single element to specify the layout of the parameter, but not every element has a resource - - // this would give the number of intrinsics OR structs, but if base type is struct - // to get the number of parameters, must recurse over struct fields - unsigned int numElements = 1; - for ( unsigned int dim = 0; dim < paramArray->dimensionCount; dim++ ) - numElements *= paramArray->dimensions[dim]; - - unsigned int prefixLengthIn = prefixLength; - - // next entry will always be either an intrinsic or a struct - - if ( !( paramEntry->flags & CGP_UNROLLED ) ) // one bit is not enough cause there are 3 representations! - { - // all elements are the same so have one entry to represent all of them - CgParameterEntry* elementEntry = paramEntry + 1; - - // entries are same type, and packed, so just repeat same param - for ( unsigned int element = 0; element < numElements; element++ ) - { - // name length for prefixIn + rest of array name for array + 16 bytes generously for [index] - prefixLength = prefixLengthIn + strlen( strtab->data + paramEntry->nameOffset ) + 16; - - // right now i think this is always intrinsics for the not unrolled case, current limitation - AccumulateSizeForParamResource( elementEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - prefixLength, element, - nvParamSize, nvParamStringsSize, nvParamOffsetsSize, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, nvParamDefaultsSize, - consttab ); - - *nextEntry = *nextEntry - 1; // undo the increment on the next entry for this special case of shared entries - } - *nextEntry = *nextEntry + 1; // redo the increment upon exiting the loop, could be smarter, whatever - } - else if ( paramEntry->flags & CGP_UNROLLED ) - { - // here everything is unrolled - - CgParameterEntry* elementEntry = paramEntry + 1; - - for ( unsigned int element = 0; element < numElements; element++ ) - { - // name length for prefixIn + rest of array name for array + 16 bytes generously for [index] - prefixLength = prefixLengthIn + strlen( strtab->data + paramEntry->nameOffset ) + 16; - - AccumulateSizeForParams( elementEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - prefixLength, -1, - nvParamSize, nvParamStringsSize, nvParamOffsetsSize, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, nvParamDefaultsSize, - consttab ); - - elementEntry = *nextEntry; - } - } -} - -void AccumulateSizeForParamStruct( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - unsigned int prefixLength, int elementResourceIndex, - size_t* nvParamSize, size_t* nvParamStringsSize, size_t* nvParamOffsetsSize, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, size_t* nvParamDefaultsSize, - ELF_section_t* consttab ) -{ - // type index is actually the offset into the block of memory following the entries - CgParameterStructure* paramStruct = ( CgParameterStructure* )(( char* )( paramEntries + paramEntriesCount ) + paramEntry->typeIndex ); - - // add prefix of struct name and . - // !!! but what about if we are inside an array??? then no struct name - if ( paramEntry->nameOffset > 0 ) // is this the right test??? - { - prefixLength += strlen( strtab->data + paramEntry->nameOffset ); - } - prefixLength += 1; // allow for the dot - - unsigned short memberCount = paramStruct->memberCount; - CgParameterEntry* memberEntry = paramEntry + 1; - - for ( unsigned int member = 0; member < memberCount; member++ ) - { - AccumulateSizeForParams( memberEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - prefixLength, -1, - nvParamSize, nvParamStringsSize, nvParamOffsetsSize, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, nvParamDefaultsSize, - consttab ); - - memberEntry = *nextEntry; - } -} - -void AccumulateSizeForParams( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - unsigned int prefixLength, int elementResourceIndex, - size_t* nvParamSize, size_t* nvParamStringsSize, size_t* nvParamOffsetsSize, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, size_t* nvParamDefaultsSize, - ELF_section_t* consttab ) -{ - // expand for intrinsics, arrays, and structs - // flags hold which type of parameter it is (along with other information) - switch ( paramEntry->flags & CGP_TYPE_MASK ) - { - case CGP_INTRINSIC: - { - //printf("resource --- %p\n", paramEntry); - AccumulateSizeForParamResource( paramEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - prefixLength, elementResourceIndex, - nvParamSize, nvParamStringsSize, nvParamOffsetsSize, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, nvParamDefaultsSize, - consttab ); - break; - } - case CGP_ARRAY: - { - //printf("array --- %p\n", paramEntry); - AccumulateSizeForParamArray( paramEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - prefixLength, elementResourceIndex, - nvParamSize, nvParamStringsSize, nvParamOffsetsSize, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, nvParamDefaultsSize, - consttab ); - break; - } - case CGP_STRUCTURE: - { - //printf("structure --- %p\n", paramEntry); - AccumulateSizeForParamStruct( paramEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - prefixLength, elementResourceIndex, - nvParamSize, nvParamStringsSize, nvParamOffsetsSize, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, nvParamDefaultsSize, - consttab ); - break; - } - default: - { - break; - } - - } - -} - -// forward declaration for recursion -void PopulateDataForParams( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - int elementResourceIndex, unsigned int* localParamNo, char* nvBinary, - CgBinaryParameter** nvParams, char** nvParamStrings, - CgBinaryEmbeddedConstant** nvParamOffsets, float** nvParamDefaults, - char* prefix, unsigned int prefixLength, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, - ELF_section_t* consttab ); - -void PopulateDataForParamResource( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - int elementResourceIndex, unsigned int* localParamNo, char* nvBinary, - CgBinaryParameter** nvParams, char** nvParamStrings, - CgBinaryEmbeddedConstant** nvParamOffsets, float** nvParamDefaults, - char* prefix, unsigned int prefixLength, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, - ELF_section_t* consttab ) -{ - // type index is actually the offset into the block of memory following the entries - CgParameterResource* paramResource = ( CgParameterResource* )(( char* )( paramEntries + paramEntriesCount ) + paramEntry->typeIndex ); - - unsigned int rowCount = getMatrixRowCount(( CGtype )paramResource->type ); - - // type - ( *nvParams )->type = ( CGtype )( paramResource->type ); - // sub type for row params of matrix - for ( int row = 1; row <= ( int )rowCount; row++ ) - ( *nvParams + row )->type = getMatrixRowType(( CGtype )paramResource->type ); - - // varying parameters - if (( paramEntry->flags & CGPV_MASK ) == CGPV_VARYING ) - { - ( *nvParams )->res = ( CGresource )paramResource->resource; - ( *nvParams )->resIndex = -1; - } - else if ((( paramEntry->flags & CGPV_MASK ) & CGPV_CONSTANT ) || (( paramEntry->flags & CGPV_MASK ) & CGPV_UNIFORM ) ) - { - // sampler types - if ( isSampler(( CGtype )paramResource->type ) ) - { - ( *nvParams )->res = ( CGresource )paramResource->resource; //should be CG_TEXUNIT0 .. 15 - ( *nvParams )->resIndex = 0; - } - // nonsampler types - else - { - // CG_B requires support too - for ( int row = 0; row <= ( int )rowCount; row++ ) - { - if ( paramResource->type == CGP_SCF_BOOL ) //(paramEntry->flags & CGP_SCFBOOL) - { - ( *nvParams + row )->res = CG_B; - ( *nvParams )->type = CG_BOOL; - } - else - ( *nvParams + row )->res = CG_C; - } - - // vertex programs - if (!nvParamOffsets) - { - // element of an array - if ( elementResourceIndex >= 0 ) - { - if ( !isMatrix(( CGtype )( paramResource->type ) ) ) - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + elementResourceIndex ); - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - else if ( paramEntry->flags & CGP_CONTIGUOUS ) - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + elementResourceIndex ); - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + elementResourceIndex ) + row - 1; - ( *nvParams + row )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - } - else - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + elementResourceIndex * rowCount ); - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + elementResourceIndex * rowCount + row - 1 ); - ( *nvParams + row )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - } - } - // not array - else - { - if ( !isMatrix(( CGtype )( paramResource->type ) ) ) - { - unsigned short tempResIndex = paramResource->resource; - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - else - { - if ( paramEntry->flags & CGP_CONTIGUOUS ) - { - unsigned short tempResIndex = paramResource->resource; - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - unsigned short tempResIndex = paramResource->resource + row - 1; - ( *nvParams + row )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - } - else - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource ); - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - unsigned short tempResIndex = *( paramResourceTable + paramResource->resource + row - 1 ); - ( *nvParams + row )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - } - } - } - } - } - // fragment programs - else - { - unsigned short* resPtr = paramResourceTable + paramResource->resource; - - if ( elementResourceIndex >= 0 ) - { - // !!! matrices should be handled here too, i think - //advance resPtr to the arrayIndex - int skipCount = elementResourceIndex; - while ( skipCount ) - { - resPtr++; - int embeddedCount = *( resPtr++ ); - resPtr += embeddedCount; - // if an array of matrices, must skip row parameter resources too - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - resPtr++; - int embeddedCount = *( resPtr++ ); - resPtr += embeddedCount; - } - skipCount--; - } - //resPtr points to the resource of the arrayIndex - } - - if ( !isMatrix(( CGtype )( paramResource->type ) ) ) - { - unsigned short tempResIndex = *( resPtr++ ); - ( *nvParams )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - unsigned int embeddedConstantCount = *( resPtr++ ); - ( *nvParamOffsets )->ucodeCount = embeddedConstantCount; - unsigned int ec = 0; - for ( ec = 0; ec < embeddedConstantCount; ec++ ) - ( *nvParamOffsets )->ucodeOffset[ec] = *( resPtr++ ); - // set the field in the nv param - ( *nvParams )->embeddedConst = ( char* )( *nvParamOffsets ) - nvBinary; - // forward pointer to nvParamOffsets - *nvParamOffsets = ( CgBinaryEmbeddedConstant* )( &(( *nvParamOffsets )->ucodeOffset[ec] ) ); - } - else - { - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - unsigned short tempResIndex = *( resPtr++ ); - ( *nvParams + row )->resIndex = ( tempResIndex == 0xFFFF ) ? -1 : ( int )tempResIndex; - unsigned int embeddedConstantCount = *( resPtr++ ); - ( *nvParamOffsets )->ucodeCount = embeddedConstantCount; - unsigned int ec = 0; - for ( ec = 0; ec < embeddedConstantCount; ec++ ) - ( *nvParamOffsets )->ucodeOffset[ec] = *( resPtr++ ); - // set the field in the nv param - ( *nvParams + row )->embeddedConst = ( char* )( *nvParamOffsets ) - nvBinary; - // forward pointer to nvParamOffsets - *nvParamOffsets = ( CgBinaryEmbeddedConstant* )( &(( *nvParamOffsets )->ucodeOffset[ec] ) ); - } - } - } - } - - } - // RESOURCE DECODING ALGORTITHM END - - - // name - if ( paramEntry->nameOffset ) - { - // copy the name and store its offset in the param - // i think prefix is already handled for this base case - strcpy( *nvParamStrings, strtab->data + paramEntry->nameOffset ); - } - // set the name offset in the param, starting from the prefix - char* namebase = NULL; - if ( prefix ) - { - ( *nvParams )->name = prefix - nvBinary; - namebase = prefix; - } - else - { - ( *nvParams )->name = *nvParamStrings - nvBinary; - namebase = *nvParamStrings; - } - - - // increment the names cursor - *nvParamStrings += strlen( *nvParamStrings ) + 1; - - // and now handle the matrix rows - for ( int row = 1; row <= ( int )rowCount; row++ ) - { - // copy the name and store its offset in the param - sprintf( *nvParamStrings, "%s[%d]", namebase, row - 1 ); - // set the name offset in the param - ( *nvParams + row )->name = *nvParamStrings - nvBinary; - // increment the names cursor - *nvParamStrings += strlen( *nvParamStrings ) + 1; - } - - // totally inefficient, but easiest implementation for now is to do the On^2 search - // in the semantic and default tables for the data associated with this parameter - unsigned int entryIndex = paramEntry - paramEntries; - - // semantic - char* semantic = NULL; - for ( unsigned int sem = 0; sem < semanticIndexCount; sem++ ) - { - CgParameterSemantic* semanticIndex = semanticIndexTable + sem; - if ( semanticIndex->entryIndex == entryIndex ) - { - // found the semantic for this parameter - semantic = strtab->data + semanticIndex->semanticOffset; - break; - } - } - if ( semantic ) - { - // copy the name and store its offset in the param - strcpy( *nvParamStrings, semantic ); - // set the name offset in the param (or params if a matrix) - for ( int row = 0; row <= ( int )rowCount; row++ ) - ( *nvParams )->semantic = *nvParamStrings - nvBinary; - // increment the names cursor - *nvParamStrings += strlen( semantic ) + 1; - } - - // default - float* defaults = NULL; - for ( unsigned int def = 0; def < defaultIndexCount; def++ ) - { - CgParameterDefaultValue* defaultIndex = defaultIndexTable + def; - if ( defaultIndex->entryIndex == entryIndex ) // found the default for this parameter - defaults = ( float* )consttab->data + defaultIndex->defaultValueIndex; - } - if ( defaults ) - { - // defaults are always padded to 4 floats per param - unsigned int defaultsCount = ( rowCount ? rowCount : 1 ) * 4; - // copy the values into the right place in the buffer - memcpy( *nvParamDefaults, defaults, defaultsCount * sizeof( float ) ); - // set the field in the param to point to them - if ( rowCount == 0 ) - ( *nvParams )->defaultValue = ( char* )( *nvParamDefaults ) - nvBinary; - else - { - for ( int row = 1; row <= ( int )rowCount; row++ ) - ( *nvParams + row )->defaultValue = ( char* )( *nvParamDefaults + 4 * ( row - 1 ) ) - nvBinary; - } - - // forward the buffer pointer - *nvParamDefaults += defaultsCount; - } - - - // fill other fields, once for the matrix and once for every row - for ( int row = 0; row <= ( int )rowCount; row++ ) - { - // var - unsigned int variability = paramEntry->flags & CGPV_MASK; - if ( variability == CGPV_VARYING ) - ( *nvParams )->var = CG_VARYING; - else if ( variability == CGPV_UNIFORM ) - ( *nvParams )->var = CG_UNIFORM; - else if ( variability == CGPV_CONSTANT ) - ( *nvParams )->var = CG_CONSTANT; - else if ( variability == CGPV_MIXED ) - ( *nvParams )->var = CG_MIXED; - else - ( *nvParams )->var = ( CGenum )0; - - //direction - unsigned int direction = paramEntry->flags & CGPD_MASK; - if ( direction == CGPD_IN ) - ( *nvParams )->direction = CG_IN; - else if ( direction == CGPD_OUT ) - ( *nvParams )->direction = CG_OUT; - else if ( direction == CGPD_INOUT ) - ( *nvParams )->direction = CG_INOUT; - else - ( *nvParams )->direction = ( CGenum )0; - - // paramno - if ( paramEntry->flags & CGPF_GLOBAL ) - ( *nvParams )->paramno = -1; - else if ( paramEntry->flags & CGP_INTERNAL ) - ( *nvParams )->paramno = -2; - else - { - ( *nvParams )->paramno = *localParamNo; - if ( row == 0 ) - *localParamNo += 1; - } - - // isReferenced - ( *nvParams )->isReferenced = (( paramEntry->flags & CGPF_REFERENCED ) != 0 ); - - // isShared - ( *nvParams )->isShared = false; - - - // increment param cursor - *nvParams += 1; - - - } - - // entry cursor - *nextEntry = paramEntry + 1; - -} - -void PopulateDataForParamArray( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - int elementResourceIndex, unsigned int* localParamNo, char* nvBinary, - CgBinaryParameter** nvParams, char** nvParamStrings, - CgBinaryEmbeddedConstant** nvParamOffsets, float** nvParamDefaults, - char* prefix, unsigned int prefixLength, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, - ELF_section_t* consttab ) -{ - // type index is actually the offset into the block of memory following the entries - CgParameterArray* paramArray = ( CgParameterArray* )(( char* )( paramEntries + paramEntriesCount ) + paramEntry->typeIndex ); - - // this would give the number of intrinsics OR structs, but if base type is struct - // to get the number of parameters, must recurse over struct fields - unsigned int numElements = 1; - for ( unsigned int dim = 0; dim < paramArray->dimensionCount; dim++ ) - numElements *= paramArray->dimensions[dim]; - - // for name handling - char* prefixIn = prefix; - unsigned int prefixLengthIn = prefixLength; - - if ( !( paramEntry->flags & CGP_UNROLLED ) ) // one bit is not enough cause there are 3 representations! - { - // all elements are the same so have one entry to represent all of them - CgParameterEntry* elementEntry = paramEntry + 1; - - // entries are same type, and packed, so just repeat same param - for ( unsigned int element = 0; element < numElements; element++ ) - { - // where is the array name??? in paramEntry or elementEntry??? - - // name - // copy prefix if it's not the first element whose prefix is already in place - if ( element > 0 ) - { - strncpy( *nvParamStrings, prefixIn, prefixLengthIn ); - prefix = *nvParamStrings; - *nvParamStrings += prefixLengthIn; - } - // rest of array name for array and index - sprintf( *nvParamStrings, "%s[%u]", ( strtab->data + paramEntry->nameOffset ), element ); - - if (!prefix) - prefix = *nvParamStrings; - - *nvParamStrings += strlen( *nvParamStrings ); - - prefixLength = strlen( prefix ); - - PopulateDataForParamResource( elementEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - element, localParamNo, nvBinary, - nvParams, nvParamStrings, nvParamOffsets, nvParamDefaults, - prefix, prefixLength, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, - consttab ); - - *nextEntry = *nextEntry - 1; // undo the increment on the next entry for this special case of shared entries - } - *nextEntry = *nextEntry + 1; // redo the increment on the next entry upon leaving the loop - } - else if ( paramEntry->flags & CGP_UNROLLED ) - { - // here everything is unrolled - - CgParameterEntry* elementEntry = paramEntry + 1; - - for ( unsigned int element = 0; element < numElements; element++ ) - { - // where is the array name??? in paramEntry or elementEntry??? - - // name - // copy prefix if it's not the first element whose prefix is already in place - if ( element > 0 ) - { - strncpy( *nvParamStrings, prefixIn, prefixLengthIn ); - prefix = *nvParamStrings; - *nvParamStrings += prefixLengthIn; - } - // rest of array name for array and index - sprintf( *nvParamStrings, "%s[%u]", ( strtab->data + paramEntry->nameOffset ), element ); - *nvParamStrings += strlen( *nvParamStrings ); - prefixLength = strlen( prefix ); - - PopulateDataForParams( elementEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - -1, localParamNo, nvBinary, - nvParams, nvParamStrings, nvParamOffsets, nvParamDefaults, - prefix, prefixLength, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, - consttab ); - - elementEntry = *nextEntry; - } - } -} - -void PopulateDataForParamStruct( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - int elementResourceIndex, unsigned int* localParamNo, char* nvBinary, - CgBinaryParameter** nvParams, char** nvParamStrings, - CgBinaryEmbeddedConstant** nvParamOffsets, float** nvParamDefaults, - char* prefix, unsigned int prefixLength, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, - ELF_section_t* consttab ) -{ - // type index is actually the offset into the block of memory following the entries - CgParameterStructure* paramStruct = ( CgParameterStructure* )(( char* )( paramEntries + paramEntriesCount ) + paramEntry->typeIndex ); - - unsigned short memberCount = paramStruct->memberCount; - CgParameterEntry* memberEntry = paramEntry + 1; - - // set the prefix pointer if it is not already set - if (!prefix) - prefix = *nvParamStrings; - - // add prefix of struct name and . - // !!! but what about if we are inside an array??? then no struct name? or is . built in? - if ( paramEntry->nameOffset > 0 ) // is this the right test??? - { - // name - unsigned int nameLength = strlen( strtab->data + paramEntry->nameOffset ); - // copy the name and store its offset in the param - strcpy( *nvParamStrings, strtab->data + paramEntry->nameOffset ); - - // increment the names cursor but don't include null term - *nvParamStrings += nameLength; - prefixLength += nameLength; - } - - // add the dot - strcpy( *nvParamStrings, "." ); - *nvParamStrings += 1; - prefixLength += 1; - - for ( unsigned int member = 0; member < memberCount; member++ ) - { - // put the prefix in place for each subsequent member - if ( member > 0 ) - { - strncpy( *nvParamStrings, prefix, prefixLength ); - prefix = *nvParamStrings; - *nvParamStrings += prefixLength; - } - - PopulateDataForParams( memberEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - -1, localParamNo, nvBinary, - nvParams, nvParamStrings, nvParamOffsets, nvParamDefaults, - prefix, prefixLength, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, - consttab ); - - memberEntry = *nextEntry; - } -} - -void PopulateDataForParams( CgParameterEntry* paramEntry, CgParameterEntry* paramEntries, unsigned int paramEntriesCount, - unsigned short* paramResourceTable, ELF_section_t* strtab, CgParameterEntry** nextEntry, - int elementResourceIndex, unsigned int* localParamNo, char* nvBinary, - CgBinaryParameter** nvParams, char** nvParamStrings, - CgBinaryEmbeddedConstant** nvParamOffsets, float** nvParamDefaults, - char* prefix, unsigned int prefixLength, - CgParameterSemantic* semanticIndexTable, unsigned int semanticIndexCount, - CgParameterDefaultValue* defaultIndexTable, unsigned int defaultIndexCount, - ELF_section_t* consttab ) -{ - - // expand for intrinsics, arrays, and structs - // flags hold which type of parameter it is (along with other information) - switch ( paramEntry->flags & CGP_TYPE_MASK ) - { - case CGP_INTRINSIC: - { - //printf("resource --- %p\n", paramEntry); - PopulateDataForParamResource( paramEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - elementResourceIndex, localParamNo, nvBinary, - nvParams, nvParamStrings, nvParamOffsets, nvParamDefaults, - prefix, prefixLength, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, - consttab ); - break; - } - case CGP_ARRAY: - { - //printf("array --- %p\n", paramEntry); - PopulateDataForParamArray( paramEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - elementResourceIndex, localParamNo, nvBinary, - nvParams, nvParamStrings, nvParamOffsets, nvParamDefaults, - prefix, prefixLength, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, - consttab ); - break; - } - case CGP_STRUCTURE: - { - //printf("structure --- %p\n", paramEntry); - PopulateDataForParamStruct( paramEntry, paramEntries, paramEntriesCount, - paramResourceTable, strtab, nextEntry, - elementResourceIndex, localParamNo, nvBinary, - nvParams, nvParamStrings, nvParamOffsets, nvParamDefaults, - prefix, prefixLength, - semanticIndexTable, semanticIndexCount, - defaultIndexTable, defaultIndexCount, - consttab ); - break; - } - default: - { - break; - } - - } -} - -bool rglCgCreateProgramChecks( CGcontext ctx, CGprofile profile, CGenum program_type ) -{ - // check context - if ( !CG_IS_CONTEXT( ctx ) ) - { - rglCgRaiseError( CG_INVALID_CONTEXT_HANDLE_ERROR ); - return false; - } - - // check the profile. - switch ( profile ) - { - case CG_PROFILE_SCE_VP_RSX: - case CG_PROFILE_SCE_FP_RSX: - break; - default: - rglCgRaiseError( CG_UNKNOWN_PROFILE_ERROR ); - return false; - } - - // check the program_type - switch ( program_type ) - { - case CG_BINARY: - case CG_SOURCE: - break; - default: // currently reject CG_OBJECT (assembly code in ASCII) and CG_UNDEFINED - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - return false; - } - - return true; -} - -bool cgOpenElf( const void *ptr, size_t size, CGELFBinary *elfBinary ) -{ - while ( 1 ) - { - size_t symbolSize; - size_t symbolCount; - const char *symbolstrtab; - const char *symtab = findSymbolSectionInPlace((const char *)ptr, &symbolSize, &symbolCount, &symbolstrtab ); - if ( !symtab ) - break; - - size_t shadertabSize; - const char *shadertab = findSectionInPlace((const char*)ptr, ".shadertab", &shadertabSize ); - if ( !shadertab ) - break; - size_t strtabSize; - const char *strtab = findSectionInPlace((const char*)ptr, ".strtab", &strtabSize ); - if ( !strtab ) - break; - size_t consttabSize; - const char *consttab = findSectionInPlace((const char* )ptr, ".const", &consttabSize ); - if ( !consttab ) - break; - - elfBinary->elfFile = ( const char* )ptr; - elfBinary->elfFileSize = size; - elfBinary->symtab = symtab; - elfBinary->symbolSize = symbolSize; - elfBinary->symbolCount = symbolCount; - elfBinary->symbolstrtab = symbolstrtab; - - elfBinary->shadertab = shadertab; - elfBinary->shadertabSize = shadertabSize; - elfBinary->strtab = strtab; - elfBinary->strtabSize = strtabSize; - - elfBinary->consttab = consttab; - elfBinary->consttabSize = consttabSize; - - return true; - } - - return false; -} - -bool cgGetElfProgramByIndex( CGELFBinary *elfBinary, int index, CGELFProgram *elfProgram ) -{ - while ( true ) - { - char sectionName[64]; - sprintf( sectionName, ".text%04i", index ); - size_t texttabSize; - const char *texttab = findSectionInPlace( elfBinary->elfFile, sectionName, &texttabSize ); - if ( !texttab ) - break; - sprintf( sectionName, ".paramtab%04i", index ); - size_t paramtabSize; - const char *paramtab = findSectionInPlace( elfBinary->elfFile, sectionName, ¶mtabSize ); - if ( !paramtab ) - break; - - elfProgram->texttab = texttab; - elfProgram->texttabSize = texttabSize; - elfProgram->paramtab = paramtab; - elfProgram->paramtabSize = paramtabSize; - elfProgram->index = index; - return true; - } - return false; -} - -static bool cgGetElfProgramByName( CGELFBinary *elfBinary, const char *name, CGELFProgram *elfProgram ) -{ - //if no name try to return the first program - int res; - if (!name || name[0] == '\0' ) - res = 0; - else - res = lookupSymbolValueInPlace( elfBinary->symtab, elfBinary->symbolSize, elfBinary->symbolCount, elfBinary->symbolstrtab, name ); - - if ( res != -1 ) - return cgGetElfProgramByIndex( elfBinary, res, elfProgram ); - return false; -} - -CGprogram rglCgCreateProgram( CGcontext ctx, CGprofile profile, const CgProgramHeader *programHeader, const void *ucode, const CgParameterTableHeader *parameterHeader, const char *stringTable, const float *defaultValues ) -{ - // Create the program structure. - // all the structural data is filled in here, - // as well as the profile. - // The parameters and the actual program are generated from the ABI specific calls. - - _CGprogram* prog = ( _CGprogram* )calloc(1, sizeof( _CGprogram)); - if (!prog) - { - rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); - return NULL; - } - - // fill in the fields we know - prog->parentContext = _cgGetContextPtr( ctx ); - prog->header.profile = profile; - - int success = 0; - - // create a name for the program and record it in the object - CGprogram id = ( CGprogram )rglCreateName( &_CurrentContext->cgProgramNameSpace, prog ); - if ( !id ) - { - free( prog ); - rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); - return NULL; - } - prog->id = id; - - //hack to counter removal of TypeC during beta - if ( profile == ( CGprofile )7005 ) - profile = CG_PROFILE_SCE_VP_RSX; - if ( profile == ( CGprofile )7006 ) - profile = CG_PROFILE_SCE_FP_RSX; - - // load the binary into the program object - switch ( profile ) - { - case CG_PROFILE_SCE_VP_RSX: - // TODO ************** need to include the entry symbol too - success = rglpGenerateVertexProgram( prog, programHeader, ucode, parameterHeader, stringTable, defaultValues ); - break; - case CG_PROFILE_SCE_FP_RSX: - success = rglpGenerateFragmentProgram( prog, programHeader, ucode, parameterHeader, stringTable, defaultValues ); - break; - default: - // should never reach here - break; - } - - // if the creation failed, free all resources. - // the error was raised when the error was encoutered. - if ( success == 0 ) - { - // free the program object - free( prog ); - // release the id too - rglEraseName( &_CurrentContext->cgProgramNameSpace, (unsigned int)id ); - return NULL; - } - - // success! add the program to the program list in the context. - rglCgProgramPushFront( prog->parentContext, prog ); - if ( _cgProgramCreateHook ) _cgProgramCreateHook( prog ); - - // everything worked. - return id; -} - -CG_API CGprogram cgCreateProgram( CGcontext ctx, - CGenum program_type, - const char* program, - CGprofile profile, - const char* entry, - const char** args ) -{ - // Load a program from a memory pointer. - // NOTE: in our API all programs are pre-compiled binaries - // so entry point and compiler arguments are ignored. - - //hack to counter removal of TypeC during beta - if ( profile == ( CGprofile )7005 ) - profile = CG_PROFILE_SCE_VP_RSX; - if ( profile == ( CGprofile )7006 ) - profile = CG_PROFILE_SCE_FP_RSX; - - //hack to counter change of defines for program_type at r5294 - // previously CG_BINARY was defined the same as CG_ROW_MAJOR - // if those values are passed in here, move them to the new values and remove this hack after we have - // an sdk that incorporates these changes so that prebuild libs (aka debugfont) can be used meanwhile - if ( program_type == CG_ROW_MAJOR ) - program_type = CG_BINARY; - - if ( !rglCgCreateProgramChecks( ctx, profile, program_type ) ) - return NULL; - - //data to extract from the buffer passed: - CgProgramHeader *programHeader = NULL; - const void *ucode = NULL; - CgParameterTableHeader *parameterHeader = NULL; - const char *stringTable = NULL; - const float *defaultValues = NULL; - - //first step, compile any source file - const char *binaryBuffer = NULL; - char* compiled_program = NULL; - if ( program_type == CG_SOURCE ) - { - if ( _cgRTCgcCompileProgramHook ) - { - _cgRTCgcCompileProgramHook( program, (profile == CG_PROFILE_SCE_FP_RSX) ? "sce_fp_rsx" : "sce_vp_rsx", entry, args, &compiled_program ); - if ( !compiled_program ) - { - rglCgRaiseError( CG_COMPILER_ERROR ); - return NULL; - } - binaryBuffer = compiled_program; - } - else - { - //_RGL_REPORT_EXTRA( RGL_REPORT_CG_ERROR, "The CG runtime compiler hasn't been setup. cgRTCgcInit() should be called prior to this function." ); - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - return NULL; - } - } - else - binaryBuffer = program; - - bool bConvertedToElf = false; - - //At that point we have a binary file which is either any ELF or an NV format file - const unsigned int ElfTag = 0x7F454C46; // == MAKEFOURCC(0x7F,'E','L','F'); - if ( !( *( unsigned int* )binaryBuffer == ElfTag ) ) - { - //we have an NV file, convert it to the runtime format - - // if it was initially binary, throw warning about old format and recommend conversion to new with cgnv2elf - // don't throw the warning if it was source, cause clearly that would have been on purpose. - if ( program_type == CG_BINARY ) - { - //_RGL_REPORT_EXTRA( RGL_REPORT_CG_ERROR, "A binary shader is being loaded using a deprecated binary format. Please use the cgnv2elf tool to convert to the new, memory-saving, faster-loading format." ); - } - - //convert from NV format to the runtime format - int compiled_program_size = 0; - std::vector stringTableArray; - std::vector defaultValuesArray; - CgBinaryProgram* nvProgram = ( CgBinaryProgram* )binaryBuffer; - char *runtimeElfShader = NULL; - //check the endianness - int totalSize; - - if (( nvProgram->profile != ( CGprofile )7006 ) && ( nvProgram->profile != ( CGprofile )7005 ) && - ( nvProgram->profile != CG_PROFILE_SCE_FP_RSX ) && ( nvProgram->profile != CG_PROFILE_SCE_VP_RSX ) ) - totalSize = endianSwapWord( nvProgram->totalSize ); - else - totalSize = nvProgram->totalSize; - - int res = convertNvToElfFromMemory( binaryBuffer, totalSize, 2, 0, ( void** ) & runtimeElfShader, &compiled_program_size, stringTableArray, defaultValuesArray ); - if (res != 0) - { - //_RGL_REPORT_EXTRA( RGL_REPORT_CG_ERROR, "invalid CG binary program" ); - rglCgRaiseError( CG_COMPILER_ERROR ); - if ( compiled_program ) - _cgRTCgcFreeCompiledProgramHook( compiled_program ); - return NULL; - } - - if ( compiled_program ) - _cgRTCgcFreeCompiledProgramHook( compiled_program ); - - //TODO: remove all the unnecessary data shuffling, when this gets included in the compiler - //prepare the same buffer as the one that would be extracted from the binary file - size_t stringTableSize = stringTableArray.size() * sizeof( stringTable[0] ); - size_t defaultTableSize = defaultValuesArray.size() * sizeof( defaultValues[0] ); - int paddedSize = rglPad( compiled_program_size, 4 ); - //the following pointer will be remembered in the _CGprogram structure to be freed when the - //program will be deleted, the ucode and the param info are used in place at runtime - char *runtimeElf = ( char* )memalign( 16, paddedSize + stringTableSize + defaultTableSize ); - if ( !runtimeElf ) - { - rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); - return NULL; - } - bConvertedToElf = true; //to free the memalign - //program header, ucode and parameters - memcpy( runtimeElf, runtimeElfShader, compiled_program_size ); - - //we can free the intermediate buffer used to receive the converted program //may be we should keep it rather than reallocating ? - convertNvToElfFreeBinaryShader( runtimeElfShader ); - - //default values - //the pointer is stored right after the program data ( padded to 4 ) and after the string table pointer - float* pDefaultValues = ( float* )(( char* )runtimeElf + paddedSize ); - defaultValues = pDefaultValues; - - if ( defaultTableSize ) - memcpy( pDefaultValues, &defaultValuesArray[0], defaultTableSize ); - - //string table - //the pointer is stored right after the program data ( padded to 4 ) - char *pStringTable = ( char* )runtimeElf + paddedSize + defaultTableSize; - stringTable = pStringTable; - - if ( stringTableSize ) - memcpy( pStringTable, &stringTableArray[0], stringTableSize ); - - - //success - programHeader = ( CgProgramHeader* )runtimeElf; - size_t elfUcodeSize = programHeader->instructionCount * 16; - size_t ucodeOffset = rglPad( sizeof( CgProgramHeader ), 16 ); - size_t parameterOffset = rglPad( ucodeOffset + elfUcodeSize, 16 ); - ucode = ( char* )runtimeElf + ucodeOffset; - parameterHeader = ( CgParameterTableHeader* )(( char* )runtimeElf + parameterOffset ); - } - else - { - //we have an ELF file, it will be used in place ( case where the elf file has been passed as a memory pointer ) - CGELFBinary elfBinary; - CGELFProgram elfProgram; - - /* CG binary not aligned to 16 bytes, needed for ucode section */ - if ((( intptr_t )binaryBuffer ) & 15 ) - { - rglCgRaiseError( CG_PROGRAM_LOAD_ERROR ); - return NULL; - } - bool res = cgOpenElf( binaryBuffer, 0, &elfBinary ); - - /* Not a valid ELF file */; - if ( !res ) - { - rglCgRaiseError( CG_PROGRAM_LOAD_ERROR ); - return NULL; - } - - /* Couldn't find the shader entry in the CG binary */ - if ( !cgGetElfProgramByName( &elfBinary, entry, &elfProgram ) ) - return NULL; - - programHeader = ( CgProgramHeader* )elfBinary.shadertab + elfProgram.index; - ucode = ( char* )elfProgram.texttab; - parameterHeader = ( CgParameterTableHeader* )elfProgram.paramtab; - stringTable = elfBinary.strtab; - defaultValues = ( float* )elfBinary.consttab; - } - - CGprogram prog = rglCgCreateProgram( ctx, profile, programHeader, ucode, parameterHeader, stringTable, defaultValues ); - - //if we used the runtime compiler/converter we need to delete the buffer on exit - if ( bConvertedToElf ) - { - _CGprogram* ptr = _cgGetProgPtr( prog ); - ptr->runtimeElf = programHeader; - } - - return prog; -} - -CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx, - CGenum program_type, - const char* program_file, - CGprofile profile, - const char* entry, - const char** args ) -{ - //hack to counter removal of TypeC during beta - if ( profile == ( CGprofile )7005 ) - profile = CG_PROFILE_SCE_VP_RSX; - if ( profile == ( CGprofile )7006 ) - profile = CG_PROFILE_SCE_FP_RSX; - - //hack to counter change of defines for program_type at r5294 - // previously CG_BINARY was defined the same as CG_ROW_MAJOR - // if those values are passed in here, move them to the new values and remove this hack after we have - // an sdk that incorporates these changes so that prebuild libs (aka debugfont) can be used meanwhile - if ( program_type == CG_ROW_MAJOR ) - program_type = CG_BINARY; - - if ( !rglCgCreateProgramChecks( ctx, profile, program_type ) ) - return NULL; - - // load a program from a file - // NOTE: in our API all programs are pre-compiled binaries - // so profile and compiler arguments are ignored. - FILE* fp = NULL; - if ( RGL_LIKELY( program_type == CG_BINARY ) ) - { - unsigned int filetag = 0; - const unsigned int ElfTag = 0x7F454C46; // == MAKEFOURCC(0x7F,'E','L','F'); - CGprogram ret = NULL; - _CGcontext *context = _cgGetContextPtr( ctx ); - /* can we find it in the groups already loaded ? */ - CGprogramGroup group = context->groupList; - - while ( group ) - { - //check the group name - const char *groupName = rglCgGetProgramGroupName( group ); - if ( groupName && !strcmp( groupName, program_file ) ) - { - int index = 0; - - if (entry) - index = rglCgGetProgramIndex( group, entry ); - - if ( index >= 0 ) - { - ret = rglpCgUpdateProgramAtIndex( group, index, 1 ); - break; - } - - //we couldn't find the entry in the group which has the right name - return ( CGprogram )NULL; - } - group = group->next; - } - - if ( ret ) - return ret; - - //do we have an elf file ? - //read file tag: - // check that file exists - fp = fopen( program_file, "rb" ); - - if (!fp) - return ( CGprogram )NULL; - - int res = fread( &filetag, sizeof( filetag ), 1, fp ); - if ( !res ) - { - fclose( fp ); - rglCgRaiseError( CG_FILE_READ_ERROR ); - return ( CGprogram )NULL; - } - if ( filetag == ElfTag ) - { - fclose( fp ); - - group = rglCgCreateProgramGroupFromFile( ctx, program_file ); - if ( group ) - { - _CGprogramGroup *_group = ( _CGprogramGroup * )group; - _group->userCreated = false; - if (!entry) - { - if ( group->programCount == 1) - ret = rglpCgUpdateProgramAtIndex( group, 0, 1 ); - } - else - { - int index = rglCgGetProgramIndex( group, entry ); - if ( index != -1 ) - ret = rglpCgUpdateProgramAtIndex( group, index, 1 ); - } - } - return ret; - } - } - - //we have a NV file or a CG source: - if ( !fp ) - { - fp = fopen( program_file, "rb" ); - if (!fp) - return ( CGprogram )NULL; - } - - // find the file length - size_t file_size = 0; - fseek( fp, 0, SEEK_END ); - file_size = ftell( fp ); - rewind( fp ); - - // alloc memory for the file - char* ptr = (char*)malloc(file_size + 1); - if (!ptr) - { - fclose(fp); - return (CGprogram)NULL; - } - - // read the entire file into memory then close the file - // TODO ********* just loading the file is a bit lame really. We can do better. - fread( ptr, file_size, 1, fp ); - fclose( fp ); - - if ( program_type == CG_SOURCE ) - ptr[file_size] = '\0'; - - // call the CreateProgram API to do the rest of the job. - CGprogram ret = cgCreateProgram( ctx, program_type, ptr, profile, entry, args ); - - // free the memory for the file, we're done with it - free(ptr); - - return ret; -} - -CG_API CGprogram cgCopyProgram( CGprogram program ) -{ - _CGprogram* prog = NULL; - _CGprogram* newprog = NULL; - size_t paddedProgramSize = 0, ucodeSize = 0; - int success = 0; - // check input parameter - - if ( !CG_IS_PROGRAM( program ) ) - return NULL; - - prog = (_CGprogram*)_cgGetProgPtr( program ); - - if (!prog) - return ( CGprogram )NULL; - - if (prog->header.profile == CG_PROFILE_SCE_FP_RSX) - { - paddedProgramSize = rglPad( sizeof( _CGprogram ), 16); - ucodeSize = prog->header.instructionCount * 16; - newprog = ( _CGprogram* )malloc( paddedProgramSize + ucodeSize ); - } - else - { - newprog = ( _CGprogram* )malloc( sizeof( _CGprogram ) ); - } - - if (!newprog) - { - rglCgRaiseError( CG_MEMORY_ALLOC_ERROR ); - return ( CGprogram )NULL; - } - memset( newprog, 0, sizeof( _CGprogram ) ); - - // copy information from the old program - newprog->header.profile = prog->header.profile; - newprog->parentContext = prog->parentContext; - - // generate a new id - newprog->id = ( CGprogram )rglCreateName( &_CurrentContext->cgProgramNameSpace, newprog ); - - // copy all the parameter information - - // copy the binary program information - // TODO ******** copy the entire elf here, not just the executable. - switch ( prog->header.profile ) - { - case CG_PROFILE_SCE_VP_RSX: - case CG_PROFILE_SCE_FP_RSX: - success = rglpCopyProgram( prog, newprog ); - break; - default: - rglCgRaiseError( CG_UNKNOWN_PROFILE_ERROR ); - break; - } - - if ( success == 0 ) - { - // we failed to create a new program object, clean up - free( newprog ); - rglEraseName( &_CurrentContext->cgProgramNameSpace, (unsigned int)newprog->id ); - return ( CGprogram )NULL; - } - - if (prog->header.profile == CG_PROFILE_SCE_FP_RSX) - { - newprog->ucode = (char*)newprog + paddedProgramSize; - memcpy((char*)newprog->ucode, (char*)prog->ucode, ucodeSize); - } - - //handle refcounting for string table and default values - if ( prog->programGroup ) - { - //refcount for the string and the default table - newprog->programGroup = prog->programGroup; - newprog->programIndexInGroup = -1; - rglpCgUpdateProgramAtIndex( newprog->programGroup, -1, 1 ); - } - - // add the new program object to the program list in the context - rglCgProgramPushFront( newprog->parentContext, newprog ); - - if ( _cgProgramCopyHook ) - _cgProgramCopyHook( newprog, prog ); - - return newprog->id; -} - -CG_API void cgDestroyProgram( CGprogram program ) -{ - _CGprogram* ptr = NULL; - _CGcontext* ctx = NULL; - _CGprogram* p = NULL; - - // check the program input - if ( !CG_IS_PROGRAM( program ) ) - { - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return; - } - ptr = (_CGprogram*)_cgGetProgPtr( program ); - - if (!ptr) - { - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return; - } - - if ( ptr->programGroup ) - { - if ( !ptr->programGroup->userCreated ) - { - if ( ptr->programIndexInGroup != -1 && ptr->programGroup->programs[ptr->programIndexInGroup].refCount == 0 ) - { - //not a valid handle, the refcount is 0, this handle has already been freed - rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return; - } - else - { - bool isGroupMember = ( ptr->programIndexInGroup != -1 ); - rglpCgUpdateProgramAtIndex( ptr->programGroup, ptr->programIndexInGroup, -1 ); - if ( isGroupMember ) - return; - //else continue, it needs to be deleted here, the group won't delete it. - //such program which have a programGroup but are not member of the group are - //clone of a program coming from a group. but those program still need the group - //because the group holds their stringtable and their default table. - } - } - } - - // get the context that this program belongs to. - ctx = (_CGcontext*)ptr->parentContext; - - // find and unlink the program from the program list - if ( ptr == ctx->programList ) - { - // node is the head of the list, so unlink it. - p = ctx->programList; - ctx->programList = p->next; - // erase the program - rglCgProgramEraseAndFree(p); - - return; - } - - // node not the head, so use find_previous and delete_after - // NOTE: if the program is not found in the list, returns silently. - p = rglCgProgramFindPrev(ctx, ptr); - rglCgProgramEraseAfter(p); -} - - -/*============================================================ - CG GL - ============================================================ */ - -/****************************************************************************** - *** Profile Functions - *****************************************************************************/ - -CGGL_API CGbool cgGLIsProfileSupported( CGprofile profile ) -{ - switch ( profile ) - { - case CG_PROFILE_SCE_VP_RSX: - return (CGbool)rglpSupportsVertexProgram( profile ); - case CG_PROFILE_SCE_FP_RSX: - return (CGbool)rglpSupportsFragmentProgram( profile ); - } - - return CG_FALSE; -} - -CGGL_API void cgGLEnableProfile( CGprofile profile ) -{ - // this is a logical extension to glEnable - RGLcontext* LContext = _CurrentContext; - - switch ( profile ) - { - case CG_PROFILE_SCE_VP_RSX: - LContext->VertexProgram = GL_TRUE; - LContext->needValidate |= RGL_VALIDATE_VERTEX_PROGRAM; - break; - case CG_PROFILE_SCE_FP_RSX: - { - struct _CGprogram* current = (struct _CGprogram*)LContext->BoundFragmentProgram; - - LContext->FragmentProgram = GL_TRUE; - - if ( current ) - { - for ( GLuint i = 0; i < current->samplerCount; ++i ) - { - int unit = current->samplerUnits[i]; - rglTextureImageUnit *unit_ptr = (rglTextureImageUnit*)&_CurrentContext->TextureImageUnits[unit]; - unit_ptr->currentTexture = rglGetCurrentTexture( unit_ptr, unit_ptr->fragmentTarget ); - } - } - LContext->needValidate |= PSGL_VALIDATE_FRAGMENT_PROGRAM | PSGL_VALIDATE_TEXTURES_USED; - } - break; - default: - rglCgRaiseError( CG_INVALID_PROFILE_ERROR ); - break; - } -} - -CGGL_API void cgGLDisableProfile( CGprofile profile ) -{ - // this is a logical extension to glDisable - RGLcontext* LContext = _CurrentContext; - switch ( profile ) - { - case CG_PROFILE_SCE_VP_RSX: - LContext->VertexProgram = GL_FALSE; - // no need to invalidate textures because they are only available on programmable pipe. - LContext->needValidate |= RGL_VALIDATE_VERTEX_PROGRAM ; - break; - case CG_PROFILE_SCE_FP_RSX: - LContext->FragmentProgram = GL_FALSE; - break; - default: - rglCgRaiseError( CG_INVALID_PROFILE_ERROR ); - break; - } -} - - -CGGL_API CGprofile cgGLGetLatestProfile( CGGLenum profile_type ) -{ - switch ( profile_type ) - { - case CG_GL_VERTEX: - case CG_GL_FRAGMENT: - return rglpGetLatestProfile( profile_type ); - } - - rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); - return CG_PROFILE_UNKNOWN; -} - -CGGL_API void cgGLSetOptimalOptions( CGprofile profile ) -{ - // This does nothing because we don't compile at run-time. -} - -/****************************************************************************** - *** Program Managment Functions - *****************************************************************************/ - -CGGL_API void cgGLLoadProgram( CGprogram program ) -{ - // noop since there is integration of cg in js. -} - -CGGL_API CGbool cgGLIsProgramLoaded( CGprogram program ) -{ - // TODO: for now a valid program is always loaded. - return CG_TRUE; -} - - -CGGL_API void cgGLBindProgram( CGprogram program ) -{ - _CGprogram* ptr = _cgGetProgPtr( program ); - - // now do the binding. - switch ( ptr->header.profile ) - { - case 7005: - case CG_PROFILE_SCE_VP_RSX: - // 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; - break; - - case 7006: - case CG_PROFILE_SCE_FP_RSX: - _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; - - // 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; - rglTextureImageUnit *unit_ptr = (rglTextureImageUnit*)&_CurrentContext->TextureImageUnits[unit]; - unit_ptr->currentTexture = rglGetCurrentTexture( unit_ptr, unit_ptr->fragmentTarget ); - } - break; - - default: - rglCgRaiseError( CG_INVALID_PROFILE_ERROR ); - return; - } - -} - -CGGL_API void cgGLUnbindProgram( CGprofile profile ) -{ - switch ( profile ) - { - case CG_PROFILE_SCE_VP_RSX: - _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_RSX: - _CurrentContext->BoundFragmentProgram = NULL; - break; - default: - rglCgRaiseError( CG_INVALID_PROFILE_ERROR ); - return; - } - -} - -/****************************************************************************** - *** Parameter Managment Functions - *****************************************************************************/ - -CGGL_API void cgGLSetParameter1f( CGparameter param, float x ) -{ - float v[4] = {x, x, x, x}; - CgRuntimeParameter *ptr = rglCgGLTestParameter( param ); - - if (ptr) - ptr->setterIndex( ptr, v, CG_GETINDEX( param ) ); -} - -CGGL_API void cgGLSetParameter2f( CGparameter param, float x, float y ) -{ - float v[4] = {x, y, y, y}; - CgRuntimeParameter *ptr = rglCgGLTestParameter( param ); - - if (ptr) - ptr->setterIndex( ptr, v, CG_GETINDEX( param ) ); -} - -CGGL_API void cgGLSetParameterPointer( CGparameter param, - GLint fsize, - GLenum type, - GLsizei stride, - const GLvoid *pointer ) -{ - CgRuntimeParameter *_ptr = rglCgGLTestParameter( param ); - - const CgParameterResource *parameterResource = rglGetParameterResource( _ptr->program, _ptr->parameterEntry ); - GLuint index = ( GLuint )( parameterResource->resource - CG_ATTR0 ); - - rglVertexAttribPointerNV( - index, // attribute index - fsize, // element size - type, // GL_FLOAT - ( _ptr->parameterEntry->flags & CGP_NORMALIZE ) ? 1 : 0, // from the semantic of the param - stride, // element to element in bytes - pointer ); // data pointer -} - -CGGL_API void cgGLEnableClientState( CGparameter param ) -{ - CgRuntimeParameter *_ptr = rglCgGLTestParameter( param ); - - const CgParameterResource *parameterResource = rglGetParameterResource( _ptr->program, _ptr->parameterEntry ); - - GLuint index = ( GLuint )( parameterResource->resource - CG_ATTR0 ); - rglEnableVertexAttribArrayNV( index ); -} - -CGGL_API void cgGLDisableClientState( CGparameter param ) -{ - GLuint index; - CgParameterResource *parameterResource = NULL; - CgRuntimeParameter *_ptr = (CgRuntimeParameter*)rglCgGLTestParameter( param ); - - if (_ptr) - parameterResource = (CgParameterResource*)rglGetParameterResource( _ptr->program, _ptr->parameterEntry ); - - if (parameterResource) - { - index = (GLuint)( parameterResource->resource - CG_ATTR0 ); - rglDisableVertexAttribArrayNV( index ); - } -} - -/****************************************************************************** - *** Matrix Parameter Managment Functions - *****************************************************************************/ - -CGGL_API void cgGLSetMatrixParameterfc( CGparameter param, const float *matrix ) -{ - - CgRuntimeParameter* ptr = rglCgGLTestParameter( param ); - if (ptr) - ptr->settercIndex( ptr, matrix, CG_GETINDEX( param ) ); -} - -CGGL_API void cgGLSetTextureParameter( CGparameter param, GLuint texobj ) -{ - // According to the cg implementation from nvidia, set just stores the obj. - // Enable does the actual work. - CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param ); - if (ptr) - ptr->samplerSetter( ptr, &texobj, 0 ); -} - -CGGL_API GLuint cgGLGetTextureParameter( CGparameter param ) -{ - CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param ); - if (!ptr) - return 0; - if (!(ptr->parameterEntry->flags & CGPF_REFERENCED)) - { - rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); - return 0; - } - return *( GLuint* )ptr->pushBufferPointer; -} - -CGGL_API void cgGLEnableTextureParameter( CGparameter param ) -{ - CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param ); - ptr->samplerSetter( ptr, NULL, 0 ); -} - -CGGL_API void cgGLDisableTextureParameter( CGparameter param ) -{ - /* Should remain stub. */ -} - -/*============================================================ - CG NV2ELF - ============================================================ */ - -using namespace cgc::bio; - -class CgBaseType -{ - public: - CgBaseType() {_type = 0;} - virtual ~CgBaseType() {} - unsigned short _type; //index of the type in the types array of the program if >= STRUCT, else it's a BASETYPE - short _resourceIndex; //index of the type in the types array of the program if >= STRUCT, else it's a BASETYPE - unsigned short _resource; //index of the type in the types array of the program if >= STRUCT, else it's a BASETYPE -}; - -//array -class CgArrayType : public CgBaseType -{ - public: - CgArrayType():_elementType(NULL) { _type = (unsigned char)(CG_ARRAY + 128); } - virtual ~CgArrayType() - { - if (_elementType) - free(_elementType); - } - CgBaseType *_elementType; - unsigned char _dimensionCount; - unsigned short _dimensionItemCountsOffset; -}; - -//structure -class CgStructureType : public CgBaseType -{ - public: - //definitions - class CgStructuralElement - { - public: - char _name[256]; - char _semantic[256]; - CgBaseType *_type; - unsigned short _flags; //in,out,global,varying,const,uniform,shared, hasDefaults(base types only) -> consecutive reg allocation flag - unsigned short _index; //helper index ? - }; - - //implementation - CgStructureType() - { - _type = (unsigned char)(CG_STRUCT + 128); - _root = false; - } - - virtual ~CgStructureType() - { - int i=0; - int count = (int)_elements.size(); - for (i = 0;i < count; i++) - { - if (_elements[i]._type) - free(_elements[i]._type); - } - } - - //members - std::vector _elements; - bool _insideArray; //modifies the way the resources are stored, they should be sent directly to the resources, - //the array is keeping track of the resource offset in that case - bool _root; -}; - -typedef struct -{ - const char *name; - int resIndex; -} BINDLOCATION; - - - -////////////////////////////////////////////////////////////////////////////// -// static arrays containing type information - -#define CG_DATATYPE_MACRO(name, compiler_name, enum_name, base_enum, nrows, ncols,classname) \ - classname , -static int classnames[] = { -#include "Cg/cg_datatypes.h" -}; - -#define CG_DATATYPE_MACRO(name, compiler_name, enum_name, base_enum, nrows, ncols,classname) \ - nrows , -static int rows[] = { -#include "Cg/cg_datatypes.h" -}; - -typedef float _float4[4]; - -////////////////////////////////////////////////////////////////////////////// -// static buffers containing the information extracted from the shaders - -typedef struct -{ - std::vector _resources; - std::vector _defaultValuesIndices; - std::vector _elfDefaultsIndices; - std::vector _dimensions; - std::vector _semanticIndices; -} _CGNVCONTAINERS; - -static bool bIsVertexProgram = true; - - -////////////////////////////////////////////////////////////////////////////// -// forward declarations - -static int getStride(CgBaseType *type); -static int getSizeofSubArray(_CGNVCONTAINERS &containers, int dimensionIndex, int dimensionCount, int endianness); - -static unsigned int stringTableFind( std::vector &stringTable, const char* str ) -{ - const char *p; - const char* data = &stringTable[0]; - size_t size = stringTable.size(); - const char *end = data + size; - size_t length = strlen(str); - - if (length+1 > size) - return 0; - - data += length; - - p = (char*)memchr(data,'\0',end-data); - - while (p && (end-data)>0) - { - if (!memcmp(p - length, str, length)) - return (unsigned int)(p - length - &stringTable[0]); - data = p+1; - p = (char*)memchr(data,'\0',end-data); - } - return 0; -} - -static unsigned int stringTableAdd( std::vector &stringTable, const char* str ) -{ - unsigned int ret = (unsigned int)stringTable.size(); - - if ( ret == 0 ) - { - stringTable.push_back('\0'); //add the empty string - ret = 1; - } - - size_t stringLength = strlen(str) + 1; - stringTable.resize(ret + stringLength); - memcpy(&stringTable[0] + ret,str,stringLength); - - return ret; -} - -static unsigned int stringTableAddUnique( std::vector &stringTable, const char* str ) -{ - if ( stringTable.size() == 0 ) - stringTable.push_back('\0'); //add the empty string - unsigned int ret = stringTableFind(stringTable, str); - if (ret == 0 && str[0] != '\0') - ret = stringTableAdd(stringTable, str); - return ret; -} - -static unsigned short getFlags(CGenum var, CGenum dir, int no, bool is_referenced, bool is_shared, int paramIndex); - -////////////////////////////////////////////////////////////////////////////// -// implementation - -static void fillStructureItems(_CGNVCONTAINERS &containers, CgStructureType *structure, - int endianness, - std::vector ¶meterEntries, - std::vector ¶meterResources, std::vector &stringTable, unsigned short *arrayResourceIndex, - unsigned short *arrayDefaultValueIndex); - - -#define swap16(v) ((v>>16) | (v<<16)) - -int convertNvToElfFromMemory(const void *sourceData, size_t size, - int endianness, int constTableOffset, void **binaryShader, int *binarySize, - std::vector &stringTable, std::vector &defaultValues) -{ - _CGNVCONTAINERS containers; - unsigned char elfEndianness = endianness; //used in the macro CNVEND - nvb_reader* nvbr = 0; - - bin_io::instance()->new_nvb_reader( &nvbr ); - CGBIO_ERROR err = nvbr->loadFromString((const char*)sourceData,size); - if (err != CGBIO_ERROR_NO_ERROR) - return -1; - - //flag which tells if we have to swap data coming from nv and going to elf - bool doSwap = !(nvbr->endianness() == (HOST_ENDIANNESS)elfEndianness); - - CGprofile NVProfile = nvbr->profile(); - - if (NVProfile == CG_PROFILE_SCE_VP_RSX) - bIsVertexProgram = true; - else if (NVProfile == CG_PROFILE_SCE_FP_RSX) - bIsVertexProgram = false; - else - return -1; - - //Fill the shader header structure and save it into the shadertab - CgProgramHeader cgShader; - memset(&cgShader,0,sizeof(CgProgramHeader)); - cgShader.profile = CNV2END((unsigned short) NVProfile); //ok cnv2end here we go from platform endiannes to elf endiannes - cgShader.compilerVersion = 0;//TODO - - if (bIsVertexProgram) - { - const CgBinaryVertexProgram *nvVertex = nvbr->vertex_program(); - if (doSwap) //here we go directly from nv to elf endiannes without going to the platform endianness - { - cgShader.instructionCount = ENDSWAP(nvVertex->instructionCount); - cgShader.attributeInputMask = ENDSWAP(nvVertex->attributeInputMask); - //vertex program specific - cgShader.vertexProgram.instructionSlot = ENDSWAP(nvVertex->instructionSlot); - cgShader.vertexProgram.registerCount = ENDSWAP(nvVertex->registerCount); - cgShader.vertexProgram.attributeOutputMask = ENDSWAP(nvVertex->attributeOutputMask); - } - else - { - cgShader.instructionCount = nvVertex->instructionCount; - cgShader.attributeInputMask = nvVertex->attributeInputMask; - //vertex program specific - cgShader.vertexProgram.instructionSlot = nvVertex->instructionSlot; - cgShader.vertexProgram.registerCount = nvVertex->registerCount; - cgShader.vertexProgram.attributeOutputMask = nvVertex->attributeOutputMask; - } - } - else - { - const CgBinaryFragmentProgram *nvFragment = nvbr->fragment_program(); - unsigned char flags; - if (doSwap) - { - cgShader.instructionCount = ENDSWAP(nvFragment->instructionCount); - cgShader.attributeInputMask = ENDSWAP(nvFragment->attributeInputMask); - //fragment program specific - cgShader.fragmentProgram.partialTexType = ENDSWAP(nvFragment->partialTexType); - cgShader.fragmentProgram.texcoordInputMask = ENDSWAP(nvFragment->texCoordsInputMask); - cgShader.fragmentProgram.texcoord2d = ENDSWAP(nvFragment->texCoords2D); - cgShader.fragmentProgram.texcoordCentroid = ENDSWAP(nvFragment->texCoordsCentroid); - cgShader.fragmentProgram.registerCount = ENDSWAP(nvFragment->registerCount); - flags = - (nvFragment->outputFromH0 ? CGF_OUTPUTFROMH0 : 0) | - (nvFragment->depthReplace ? CGF_DEPTHREPLACE : 0) | - (nvFragment->pixelKill ? CGF_PIXELKILL : 0); - } - else - { - cgShader.instructionCount = nvFragment->instructionCount; - cgShader.attributeInputMask = nvFragment->attributeInputMask; - //fragment program specific - cgShader.fragmentProgram.partialTexType = nvFragment->partialTexType; - cgShader.fragmentProgram.texcoordInputMask = nvFragment->texCoordsInputMask; - cgShader.fragmentProgram.texcoord2d = nvFragment->texCoords2D; - cgShader.fragmentProgram.texcoordCentroid = nvFragment->texCoordsCentroid; - cgShader.fragmentProgram.registerCount = nvFragment->registerCount; - flags = - (nvFragment->outputFromH0 ? CGF_OUTPUTFROMH0 : 0) | - (nvFragment->depthReplace ? CGF_DEPTHREPLACE : 0) | - (nvFragment->pixelKill ? CGF_PIXELKILL : 0); - } - cgShader.fragmentProgram.flags = CNV2END(flags); - } - - //shader specific info ( the shader header is in the shader tab ) - - //ucode - uint32_t *tmp = (uint32_t *)nvbr->ucode(); - const char *ucode; - int i; - uint32_t *buffer = NULL; - - if (doSwap) - { - int size = (int)nvbr->ucode_size()/sizeof(uint32_t); - buffer = (uint32_t*)malloc(size * sizeof(uint32_t)); - - for (i = 0; i < size; i++) - { - uint32_t val = ENDSWAP(tmp[i]); - if (!bIsVertexProgram) - val = swap16(val); - buffer[i] = val; - } - ucode = (const char*)buffer; - } - else - { - ucode = (const char*)tmp; - // !!!xxx this is to workaround what appears to be a linux platform specific bug - // that manifests as a memory overwrite in properly allocated memory during a std::vector resize - int size = (int)nvbr->ucode_size()/sizeof(uint32_t); - buffer = (uint32_t*)malloc(size * sizeof(uint32_t)); - - for (i = 0; i < size; i++) - buffer[i] = tmp[i]; - ucode = (const char*)buffer; - // end workaround - } - - int ucodeSize = nvbr->ucode_size(); - - //ucode, ucodeSize; - - //RGL_ASSERT2(CNV2END(cgShader.instructionCount)*16 ==nvbr->ucode_size(),("%i, %i",CNV2END(cgShader.instructionCount)*16,nvbr->ucode_size())); - - //parameters - CgStructureType root; - root._insideArray = false; - root._root = true; - - //we don't have the names of the user structures, so to share structures we will have to rely on the - //layout of the data, we might do mistakes, but it's not important, since what we want to represent is - //the structure layout. - //parameters - //the parameters represents a hierarchical structure, I am reconstructing this structure - - int paramIndex = -1; - - //just for sanity check purpose: it's use to detect when there's a change of structural element to reset the embedded constant counter - CgStructureType::CgStructuralElement *current = NULL; - int embeddedConstants = 0; - bool rootChildDefaultValues = false; - int rootChildIndex = -1; - - char currentRefStructureName[256]; - currentRefStructureName[0] = '\0'; - - for (i = 0; i < (int)nvbr->number_of_params(); i++) - { - CGtype type; - CGresource res; - CGenum var; - int rin; - const char *name; - std::vector dv; - std::vector ec; - const char *sem; - CGenum dir; - int no; - bool is_referenced; - bool is_shared; - nvbr->get_param( i, type, res, var, rin, &name, dv, ec, &sem, dir, no, is_referenced, is_shared ); - - const char *parameterName = name; - const char *structureEnd = NULL; - CgStructureType *container = &root; - int done = 0; - const char * structureStart = parameterName; - while (!done && *structureStart) - { - // process the next structural element - structureEnd = strpbrk(structureStart, ".["); - - if (structureEnd) - { - //there's a special case for sampler, we don't support arrays of sampler, so unrolled the array here - //and don't even register the structure as being an array - if (*structureEnd == '[' && type >= CG_SAMPLER1D && type <= CG_SAMPLERCUBE) - { - //do we have an array of samplers and are we at the end ? - const char *closed = strchr(structureEnd, ']'); - //RGL_ASSERT2(closed,("name error for parameter %s",parameterName)); - const char *somethingElse = strpbrk(closed, ".["); - if (!somethingElse) - structureEnd = NULL; //so we are at the end we are in an array of samplers - } - } - - // test if we are done finding structural information - if (!structureEnd) - { - //set structureEnd correctly so that the rest of the function performs correctly - structureEnd = structureStart + strlen(structureStart); - //set the done flag to exit the loop - done = 1; - } - - //extract the current structural element name - char structName[256]; - int length = (int)(structureEnd - structureStart); - strncpy(structName, structureStart, length); - structName[length] = '\0'; - - //do we already have it in the structure ? - CgStructureType::CgStructuralElement *structuralElement = NULL; - int j=0; - int elementCount = (int)container->_elements.size(); - for (j=0;j_elements[j]; - if (!strcmp(structuralElement->_name,structName)) - { - //same name, we need to check that this is the same scope ( program versus global ) - if ( (no == -1 && (structuralElement->_flags & CGPF_GLOBAL)) || - (no != -1 && !(structuralElement->_flags & CGPF_GLOBAL))) - break; - } - } - if (j==elementCount) - { - if (container == &root) - { - if (rootChildIndex != j) - { - rootChildDefaultValues = false; - rootChildIndex = j; - } - } - - //we don't have it yet, add it - container->_elements.resize(elementCount+1); - structuralElement = &container->_elements[elementCount]; - strncpy(structuralElement->_name,structName,sizeof(structuralElement->_name)); - structuralElement->_name[sizeof(structuralElement->_name)-1] = '\0'; - structuralElement->_flags = getFlags(var,dir,no,is_referenced,is_shared,paramIndex); - int dimensionCount = 0; - - if (strncmp(sem, "COLOR", 5) == 0 || strncmp(sem, "NORMAL", 6) == 0) - structuralElement->_flags |= CGP_NORMALIZE; - - - //check if we have a structure or an array of structure or an array of basetypes - //then: - // - create an array type if we have an array - // - update the container if we have a structure or an array of structure - int isStructure = (*structureEnd == '.'); - if (*structureEnd == '[') - { - dimensionCount++; - const char *arrayEnd = strchr(structureEnd,']')+1; - while (*arrayEnd == '[') - { - arrayEnd = strchr(arrayEnd,']')+1; - dimensionCount++; - } - if (*arrayEnd == '.') - isStructure = true; - } - - //we have an array, create an array type - if (dimensionCount) - { - CgArrayType *arrayType = new CgArrayType; - arrayType->_dimensionCount = dimensionCount; - arrayType->_dimensionItemCountsOffset = (unsigned short)containers._dimensions.size(); - //initialize the dimension count; - int k; - for (k=0;k_type = arrayType; - if (isStructure) - { - //we have a structure inside the array - container = new CgStructureType; - container->_insideArray = true; - arrayType->_elementType = container; - } - else - { - //we have a base type inside the array - arrayType->_elementType = new CgBaseType; - arrayType->_elementType->_type = type - CG_TYPE_START_ENUM; - } - arrayType->_elementType->_resource = res; - arrayType->_elementType->_resourceIndex = -1; - structuralElement->_type->_resourceIndex = (int)containers._resources.size(); - structuralElement->_type->_resource = res; - } - else - { - //we have a structure - if (isStructure) - { - bool insideArray = container->_insideArray; - container = new CgStructureType; - container->_insideArray = insideArray; - structuralElement->_type = container; - } - else - { - //assign the basetype and resource - structuralElement->_type = new CgBaseType; - structuralElement->_type->_type = type - CG_TYPE_START_ENUM; - structuralElement->_type->_resource = res; - if (classnames[structuralElement->_type->_type-1] == CG_PARAMETERCLASS_MATRIX) - { - //TODO, Cedric: for vertexprogram assume the matrices are always fully allocated and that they have consecuttive assignements - if (bIsVertexProgram) - structuralElement->_type->_resourceIndex = (short)rin; - else - structuralElement->_type->_resourceIndex = (int)containers._resources.size(); - } - else - { - if (!container->_insideArray) - { - //vertex program - if (bIsVertexProgram) - structuralElement->_type->_resourceIndex = rin; - else - { - //fragment program - if (structuralElement->_flags & CGPV_VARYING) - structuralElement->_type->_resourceIndex = -1; - else - { - int k, size; - structuralElement->_type->_resourceIndex = (int)containers._resources.size(); - containers._resources.push_back(CNV2END((unsigned short)rin)); - size = (int)ec.size(); - containers._resources.push_back(CNV2END((unsigned short)size)); - - for (k=0;k_type->_resourceIndex = (short)-1; - structuralElement->_type->_resource = (unsigned short)res; - } - } - } - } - } - else - { - if (structuralElement->_type->_type == CG_STRUCT+128) - { - container = (CgStructureType*)structuralElement->_type; - } - else if (structuralElement->_type->_type == CG_ARRAY+128) - { - CgArrayType *arrayType = (CgArrayType *)structuralElement->_type; - if (arrayType->_elementType->_type >128 ) - { - container = (CgStructureType*)arrayType->_elementType; - } - } - } - - //default values should only be at the root of the hierarchical parameter structure - //RGL_ASSERT2(!rootChildDefaultValues || dv.size(),("all the parameter below a root child should have a default value")); - //if (dv.size() && !rootChildDefaultValues) - if (dv.size()) - { - int size = (int)containers._defaultValuesIndices.size(); - if (!size || (containers._defaultValuesIndices[size-2] != CNV2END((unsigned short)(rootChildIndex)))) - { - //assert for default values on structures: - //now supported: - /*RGL_ASSERT2(structuralElement->_type->_type != CG_STRUCT + 128,("default values on structure not yet supported")); - RGL_ASSERT2(structuralElement->_type->_type != CG_ARRAY + 128 || - ((CgArrayType *)structuralElement->_type)->_elementType->_type != CG_STRUCT + 128, - ("default values on arrays of structures not yet supported"));*/ - - //push the index of the parameter in the global structure - containers._defaultValuesIndices.push_back(CNV2END((unsigned short)(rootChildIndex))); - //push the index of the default value ( could add the size if necessary ) - containers._defaultValuesIndices.push_back(CNV2END((unsigned short)defaultValues.size())); - } - } - - //this case is for when we have item within a struct which is in an array, we don't duplicate the struct - //but we still need to save the resources at the array level, so with this code when we reach the end of the parameter - //name, we only need to save the resources - if (container->_insideArray && done) - { - //the reason of the reset of the flag is because the first item of the array might unreferenced - //so it doesn't has the correct resource type - if (is_referenced) - structuralElement->_flags = getFlags(var,dir,no,is_referenced,is_shared,paramIndex); - - if (bIsVertexProgram) - containers._resources.push_back(CNV2END((unsigned short)rin)); - else - { - //fragment program - if (structuralElement->_flags & CGPV_VARYING) - containers._resources.push_back(CNV2END((unsigned short)rin)); - else - { - int k, size; - containers._resources.push_back(CNV2END((unsigned short)rin)); - size = (int)ec.size(); - containers._resources.push_back(CNV2END((unsigned short)size)); - - for (k = 0; k < size; k++) - containers._resources.push_back(CNV2END((unsigned short)ec[k])); - } - } - } - - //if we have an array we need to update the item counts and skip the array for the parsing of the name of the structure - CgArrayType *arrayType = NULL; - if (*structureEnd == '[') - { - int arrayCellIndex = 0; - const char *arrayStart = structureEnd; - const char *arrayEnd = structureEnd; - CgBaseType *itemType = structuralElement->_type; - if (itemType->_type >= 128) - { - arrayType = (CgArrayType *)itemType; - int dimensionCount = 0; - while (*arrayStart == '[' && dimensionCount_dimensionCount) - { - arrayEnd = strchr(arrayStart+1,']'); - int length =(int)(arrayEnd - arrayStart - 1); - char indexString[16]; - strncpy(indexString,arrayStart+1,length); - indexString[length] = '\0'; - int index = atoi(indexString); - int dim = CNV2END(containers._dimensions[arrayType->_dimensionItemCountsOffset + dimensionCount]); - if ((index+1) > dim) - containers._dimensions[arrayType->_dimensionItemCountsOffset + dimensionCount] = CNV2END((short)(index+1)); - arrayCellIndex += index*getSizeofSubArray(containers,arrayType->_dimensionItemCountsOffset + dimensionCount,arrayType->_dimensionCount - dimensionCount -1,endianness); - arrayStart = arrayEnd+1; - dimensionCount++; - } - structureEnd = arrayStart; - - itemType = arrayType->_elementType; - if (itemType->_type<128) - { - int rowCount = rows[itemType->_type-1]; - if (!rowCount) //no matrix here - { - containers._resources.push_back(CNV2END((unsigned short)rin)); - - //fragment program - if (!bIsVertexProgram) - { - int size = (int)ec.size(); - containers._resources.push_back(CNV2END((unsigned short)size)); - int k; - for (k=0;k_type <128)//matrix - { - if (structuralElement != current) - { - embeddedConstants = 0; - current = structuralElement; - } - - int length =(int)(arrayEnd - arrayStart - 1); - char indexString[16]; - strncpy(indexString,arrayStart+1,length); - indexString[length] = '\0'; - - //TODO: Cedric: for vertex program and matrices not in array, I am not adding any resource: - if (bIsVertexProgram) - { - if (arrayType) - { - //add the resource index ... scary - containers._resources.push_back(CNV2END((unsigned short)rin)); - } - } - else - { - containers._resources.push_back(CNV2END((unsigned short)rin)); - int size = (int)ec.size(); - containers._resources.push_back(CNV2END((unsigned short)size)); - int k; - for (k=0;k_flags = flag; - structuralElement->_type->_resource = res; - //if array - if (arrayType) - arrayType->_elementType->_resource = res; - } - } - - - if (done && dv.size()) - { - //very difficult to check that there is no mistake done... should do a diff with - //containers._defaultValuesIndices[containers._defaultValuesIndices.size()-1] and the current parameter position in - //the structure - for ( int jj = 0; jj < (int)dv.size(); ++jj ) - defaultValues.push_back(dv[jj]); - } - - if (done) - { - if (strlen(sem)) - strncpy(structuralElement->_semantic,sem,sizeof(structuralElement->_semantic)); - else - structuralElement->_semantic[0] = '\0'; - } - structureStart = structureEnd+1; - } - } - - //we are done with the reader - nvbr->release(); - //release singleton - bin_io::delete_instance(); - - //print the structure that we have extracted - - //transform the extracted structure into the file format - std::vector parameterEntries; - std::vector parameterResources; - fillStructureItems(containers,&root,endianness,parameterEntries,parameterResources,stringTable, NULL, NULL); - - //save it - CgParameterTableHeader header; - memset(&header,0,sizeof(CgParameterTableHeader)); - header.entryCount = (unsigned short)parameterEntries.size(); - header.resourceTableOffset = sizeof(CgParameterTableHeader) + (unsigned short)(parameterEntries.size()*sizeof(parameterEntries[0]) + parameterResources.size()*sizeof(parameterResources[0])); - header.defaultValueIndexTableOffset = header.resourceTableOffset + (unsigned short)containers._resources.size() * sizeof(containers._resources[0]); - header.defaultValueIndexCount = (unsigned short)containers._elfDefaultsIndices.size()/2; - header.semanticIndexTableOffset = header.defaultValueIndexTableOffset + (unsigned short)containers._elfDefaultsIndices.size() * sizeof (containers._elfDefaultsIndices[0]); - header.semanticIndexCount = (unsigned short)containers._semanticIndices.size(); - - header.entryCount = CNV2END(header.entryCount); - header.resourceTableOffset = CNV2END(header.resourceTableOffset); - header.defaultValueIndexTableOffset = CNV2END(header.defaultValueIndexTableOffset); - header.defaultValueIndexCount = CNV2END(header.defaultValueIndexCount); - header.semanticIndexTableOffset = CNV2END(header.semanticIndexTableOffset); - header.semanticIndexCount = CNV2END(header.semanticIndexCount); - - //fill the parameter section - size_t parameterTableSize = sizeof(CgParameterTableHeader); - parameterTableSize += (unsigned int)parameterEntries.size() * sizeof(parameterEntries[0]); - parameterTableSize += (unsigned int)parameterResources.size() * sizeof(parameterResources[0]); - parameterTableSize += (unsigned int)containers._resources.size() * sizeof(containers._resources[0]); - //parameterTableSize += (unsigned int)containers._defaultValuesIndices.size() * sizeof(containers._defaultValuesIndices[0]); - parameterTableSize += (unsigned int)containers._elfDefaultsIndices.size() * sizeof(containers._elfDefaultsIndices[0]); - parameterTableSize += (unsigned int)containers._semanticIndices.size() * sizeof(containers._semanticIndices[0]); - - //Allocate the binary file - int ucodeOffset = (((sizeof(CgProgramHeader)-1)/16)+1)*16; - size_t programSize = ucodeOffset + ucodeSize + parameterTableSize; - char *program = (char*)malloc(programSize * sizeof(char)); - - //header - memcpy(program,&cgShader,sizeof(CgProgramHeader)); - if (ucodeOffset-sizeof(CgProgramHeader)) - memset(program+sizeof(CgProgramHeader),0,ucodeOffset-sizeof(CgProgramHeader)); - - //ucode - memcpy(program + ucodeOffset,ucode,ucodeSize); - if (buffer) - free(buffer); - - //parameters - char *parameterOffset = program + ucodeOffset + ucodeSize; - size_t datasize; - - memcpy(parameterOffset,&header,sizeof(CgParameterTableHeader)); - parameterOffset += sizeof(CgParameterTableHeader); - - datasize = parameterEntries.size() * sizeof(parameterEntries[0]); - memcpy(parameterOffset, ¶meterEntries[0], datasize); - parameterOffset += datasize; - - datasize = parameterResources.size() * sizeof(parameterResources[0]); - memcpy(parameterOffset, ¶meterResources[0], datasize); - parameterOffset += datasize; - - datasize = containers._resources.size() * sizeof(containers._resources[0]); - memcpy(parameterOffset, &containers._resources[0], datasize); - parameterOffset += datasize; - - datasize = containers._elfDefaultsIndices.size() * sizeof(containers._elfDefaultsIndices[0]); - memcpy(parameterOffset, &containers._elfDefaultsIndices[0], datasize); - parameterOffset += datasize; - - datasize = containers._semanticIndices.size() * sizeof(containers._semanticIndices[0]); - memcpy(parameterOffset, &containers._semanticIndices[0], datasize); - parameterOffset += datasize; - - //RGL_ASSERT2(parameterOffset == program + programSize,("error\n")); - //set the return values - *binarySize = (int)programSize; - *binaryShader = program; - - return 0; -} - -int convertNvToElfFreeBinaryShader(void *binaryShader) -{ - char *program = (char *)binaryShader; - - if (program) - free(program); - return 0; -} - -static void pushbackUnsignedShort(std::vector ¶meterResources, unsigned short value) -{ - size_t size = parameterResources.size(); - parameterResources.resize(size + 2); - *((unsigned short*)¶meterResources[size]) = value; -} - -//This function fill the parameter tables that will be written to the files -static void fillStructureItems(_CGNVCONTAINERS &containers, CgStructureType *structure, int endianness, - std::vector ¶meterEntries,std::vector ¶meterResources, - std::vector &stringTable, unsigned short *arrayResourceIndex, unsigned short *arrayDefaultValueIndex) -{ - int i; - unsigned char elfEndianness = endianness; //used in the macro CNVEND - int currentDefaultIndex = 0; - int count = (int)structure->_elements.size(); - - for (i = 0; i < count; i++) - { - CgStructureType::CgStructuralElement *structuralElement = &structure->_elements[i]; - size_t size = parameterEntries.size(); - parameterEntries.resize(size+1); - CgParameterEntry *parameterEntry = ¶meterEntries[size]; - parameterEntry->nameOffset = CNV2END((int)stringTableAddUnique(stringTable, structuralElement->_name)); - if (structuralElement->_semantic[0]) - { - CgParameterSemantic semantic; - semantic.entryIndex = CNV2END((unsigned short)size); - semantic.reserved = 0; - semantic.semanticOffset = CNV2END((int)stringTableAddUnique(stringTable, structuralElement->_semantic)); - containers._semanticIndices.push_back(semantic); - } - parameterEntry->flags = CNV2END(structuralElement->_flags); - //prepare the typeIndex - unsigned short typeIndex = ((unsigned short)parameterResources.size()); - //RGL_ASSERT2((typeIndex&3) == 0,("typeindex must be aligned on 4 bytes")); - parameterEntry->typeIndex = CNV2END(typeIndex); - - CgBaseType *itemType = structuralElement->_type; - unsigned short _resource = itemType->_resource; - unsigned short _resourceIndex = itemType->_resourceIndex; - - //will contain the parameterEntry for this item, for simple type arrays the value will be corrected - //parameterEntry.size() is not parameterEntryIndex in that case. - int parameterEntryIndex; - - if (itemType->_type-128 == CG_ARRAY) - { - CgArrayType *arrayType = (CgArrayType *)structuralElement->_type; - int arraySize = getSizeofSubArray(containers,arrayType->_dimensionItemCountsOffset,arrayType->_dimensionCount,endianness); - itemType = arrayType->_elementType; - //RGL_ASSERT2(!(itemType->_type +CG_TYPE_START_ENUM >= CG_SAMPLER1D && itemType->_type +CG_TYPE_START_ENUM<= CG_SAMPLERCUBE),("array of samplers not yet supported")); - unsigned short arrayFlag = CGP_ARRAY; - parameterEntry->flags |= CNV2END(arrayFlag); - parameterResources.resize(typeIndex+sizeof(CgParameterArray)); - - CgParameterArray *parameterArray = (CgParameterArray *)(¶meterResources[typeIndex]); - if (itemType->_type-128 == CG_STRUCT ) - parameterArray->arrayType = CNV2END((unsigned short)CG_STRUCT); - else - parameterArray->arrayType = CNV2END(itemType->_type+128); - parameterArray->dimensionCount = CNV2END((unsigned short)arrayType->_dimensionCount); - int j; - for (j=0;j_dimensionCount;j++) - { - pushbackUnsignedShort(parameterResources,(unsigned short)containers._dimensions[arrayType->_dimensionItemCountsOffset+j]); //already endian-swapped - } - //padding - if (arrayType->_dimensionCount&1) - pushbackUnsignedShort(parameterResources,CNV2END((unsigned short)0)); - - //unroll the array of structure here, create one structure for each item of the array - if (itemType->_type-128 == CG_STRUCT ) - { - unsigned short unrolledFlag = CGP_UNROLLED; - parameterEntry->flags |= CNV2END(unrolledFlag); - CgStructureType *structureType = (CgStructureType*)itemType; - int k; - - //those lines won't work for arrays of structures containing arrays - unsigned short _arrayResourceIndex = (unsigned short)(arrayType->_resourceIndex); - unsigned short _arrayDefaultValueIndex = 0; - - bool hasDefaults = false; - if (structure->_root && containers._defaultValuesIndices.size()) - { - if (containers._defaultValuesIndices[currentDefaultIndex*2] == CNV2END((unsigned short)i)) - { - hasDefaults = true; - _arrayDefaultValueIndex = containers._defaultValuesIndices[currentDefaultIndex*2+1]; - //containers._defaultValuesIndices[currentDefaultIndex*2] = CNV2END((unsigned short)(parameterEntries.size() - 1)); - //currentDefaultIndex++; - } - } - - for (k=0;k_name,k); - parameterArrayEntry.nameOffset = CNV2END((int)stringTableAddUnique(stringTable, buffer)); - parameterArrayEntry.flags = CNV2END(structuralElement->_flags); - unsigned short structureFlag = CGP_STRUCTURE; - parameterArrayEntry.flags |= CNV2END(structureFlag); - - unsigned short arrayEntryTypeIndex = (unsigned short)parameterResources.size(); - //RGL_ASSERT2((arrayEntryTypeIndex&3) == 0,("typeindex must be aligned on 4 bytes")); - parameterResources.resize(arrayEntryTypeIndex+sizeof(CgParameterStructure)); - parameterArrayEntry.typeIndex = CNV2END(arrayEntryTypeIndex); - - CgParameterStructure *parameterStructure = (CgParameterStructure*)(¶meterResources[arrayEntryTypeIndex]); - parameterStructure->memberCount = CNV2END((unsigned short)structureType->_elements.size()); - parameterStructure->reserved = CNV2END((unsigned short)0); - - if (hasDefaults) - fillStructureItems(containers,structureType,endianness,parameterEntries,parameterResources,stringTable,&_arrayResourceIndex,&_arrayDefaultValueIndex); - else - fillStructureItems(containers,structureType,endianness,parameterEntries,parameterResources,stringTable,&_arrayResourceIndex, NULL); - } - - if (hasDefaults) - { - //should check this value, but it's not really easy, need the entire size of the complex structure in registers - //unsigned short ArrayBaseTypeCount = _arrayDefaultValueIndex -containers._defaultValuesIndices[currentDefaultIndex*2+1]; - currentDefaultIndex++; - } - //containers._defaultValuesIndices[currentDefaultIndex*2] = CNV2END((unsigned short)(parameterEntries.size() - 1)); - //currentDefaultIndex++; - - - //default value expansion: we have an array of struct: we have one default value index for the array - //since the array is unrolled we don't give any resource to the array, but instead we give the resource to each item of each structure - //those items can be arrays or structure themselves - - //we have already output the content of the array continue to the next structure item - continue; - } - else - { - //create the type item following the array , the type section will fill typeindex value - size_t size = parameterEntries.size(); - parameterEntries.resize(size+1); - parameterEntry = ¶meterEntries[size]; - parameterEntry->nameOffset = CNV2END(0); - parameterEntry->flags = CNV2END(structuralElement->_flags); - - //prepare a typeIndex for this type - typeIndex = ((unsigned short)parameterResources.size()); - //RGL_ASSERT2((typeIndex&3) == 0,("typeindex must be aligned on 4 bytes")); - parameterEntry->typeIndex = CNV2END(typeIndex); - - //keep the parameterEntryIndex to assign the default values to the proper item - parameterEntryIndex = (int)size - 1; - } - } - else - { - unsigned short contiguousFlag = CGP_CONTIGUOUS; - parameterEntry->flags |= CNV2END(contiguousFlag); - size_t size = parameterEntries.size(); - parameterEntryIndex = (int)size - 1; - } - - if (itemType->_type<128) - { - parameterResources.resize(typeIndex+sizeof(CgParameterResource)); - CgParameterResource *parameterResource = (CgParameterResource*)(¶meterResources[typeIndex]); - - if (itemType->_type + CG_TYPE_START_ENUM == CG_BOOL) // checking _resource == CG_B only works if referenced - { - parameterResource->type = CNV2END((unsigned short)CGP_SCF_BOOL); - } - else - { - parameterResource->type = CNV2END((unsigned short)(itemType->_type + CG_TYPE_START_ENUM)); - } - - if ((structuralElement->_flags & CGPV_MASK) == CGPV_UNIFORM || (structuralElement->_flags & CGPV_MASK) == CGPV_CONSTANT) - { - //use the resource index of the array if we are in an array: pbl with arrays containing samplers... - if (itemType->_type +CG_TYPE_START_ENUM >= CG_SAMPLER1D && itemType->_type +CG_TYPE_START_ENUM<= CG_SAMPLERCUBE) - parameterResource->resource = CNV2END(_resource); //sampler we need the texture unit - else - { - if (arrayResourceIndex) - { - unsigned short tmp = *arrayResourceIndex; - unsigned short localflags = CNV2END(parameterEntry->flags); - if (!bIsVertexProgram) - { - parameterResource->resource = CNV2END(tmp); - int embeddedConstantCount = CNV2END(containers._resources[tmp+1]); - (*arrayResourceIndex) = tmp+1+1+embeddedConstantCount; - if (embeddedConstantCount == 0 && (CNV2END(containers._resources[tmp]) == 0)) - { - //we are unrolling an array of struct, so we get individual items - //we should mark if they are referenced individually - if (parameterResource->resource == 0xffff) - localflags &= ~CGPF_REFERENCED; - } - } - else - { - parameterResource->resource = containers._resources[tmp];//_resources is already converted - (*arrayResourceIndex) = tmp+1; - - //we are unrolling an array of struct, so we get individual items - //we should mark if they are referenced individually - if (parameterResource->resource == 0xffff) - localflags &= ~CGPF_REFERENCED; - } - //update the flags - parameterEntry->flags = CNV2END(localflags); - } - else - parameterResource->resource = CNV2END(_resourceIndex); //uniform not a sampler we need the register - } - } - else - { - //RGL_ASSERT2((structuralElement->_flags & CGPV_MASK) == CGPV_VARYING,("assumed varying")); - //RGL_ASSERT2(arrayResourceIndex == NULL,("varying within array of structures not yet supported")); - parameterResource->resource = CNV2END(itemType->_resource); //we need the bind location for the varying - } - - if (containers._defaultValuesIndices.size()) - { - if (structure->_root) - { - //TODO: what about default values on structures at the root level, the structure will flatten out so the default should go on the individual items - //but they are not at root so the indices cannot be represented right now I guess. - //semantics and default values indices need to be updated: - //we are trying to find the index in the sorted array of default value indices, if we are already at the end of the array we stop here - if (currentDefaultIndex < (int)(containers._defaultValuesIndices.size()/2) && containers._defaultValuesIndices[currentDefaultIndex*2] == CNV2END((unsigned short)i)) - { - containers._elfDefaultsIndices.push_back(CNV2END((unsigned short)(parameterEntryIndex))); - containers._elfDefaultsIndices.push_back(containers._defaultValuesIndices[currentDefaultIndex*2+1]); - //containers._defaultValuesIndices[currentDefaultIndex*2] = CNV2END((unsigned short)(parameterEntries.size() - 1)); - currentDefaultIndex++; - } - } - else if (arrayDefaultValueIndex) - { - //we are in a struct or in an array of struct which has a top level default, each time we have a basic type we need to increase - //the index - - containers._elfDefaultsIndices.push_back(CNV2END((unsigned short)(parameterEntryIndex))); - containers._elfDefaultsIndices.push_back(*arrayDefaultValueIndex); - //increment the default values index by the number of defaultValues slot used by this type - - int typeRegisterCount = getStride(itemType); - *arrayDefaultValueIndex = CNV2END( (unsigned short)((CNV2END((*arrayDefaultValueIndex)))+typeRegisterCount*4)); - - //no handling of the currentDefaultIndex, which is only valid at root. - } - } - } - else if (itemType->_type == CG_STRUCT + 128) - { - //RGL_ASSERT2(arrayResourceIndex == NULL,("struct within array of structures not yet supported")); - unsigned short structureFlag = CGP_STRUCTURE; - parameterEntry->flags |= CNV2END(structureFlag); - - CgStructureType *structureType = (CgStructureType*)itemType; - parameterResources.resize(typeIndex+sizeof(CgParameterStructure)); - CgParameterStructure *parameterStructure = (CgParameterStructure*)(¶meterResources[typeIndex]); - parameterStructure->memberCount = CNV2END((unsigned short)structureType->_elements.size()); - parameterStructure->reserved = CNV2END((unsigned short)0); - - fillStructureItems(containers,structureType,endianness,parameterEntries,parameterResources,stringTable, NULL, NULL); - - if (containers._defaultValuesIndices.size() && structure->_root) - { - if (currentDefaultIndex < (int)(containers._defaultValuesIndices.size()/2) && containers._defaultValuesIndices[currentDefaultIndex*2] == CNV2END((unsigned short)i)) - { - containers._elfDefaultsIndices.push_back(CNV2END((unsigned short)(parameterEntryIndex))); - containers._elfDefaultsIndices.push_back(containers._defaultValuesIndices[currentDefaultIndex*2+1]); - currentDefaultIndex++; - } - } - } - } - //RGL_ASSERT2(!structure->_root || currentDefaultIndex == (int)containers._defaultValuesIndices.size()/2,("error\n")); -} - - -static int getStride(CgBaseType *type) -{ - if (type->_type <128) - { - if (classnames[type->_type-1] == CG_PARAMETERCLASS_MATRIX) - return rows[type->_type-1]; - return 1; - } - - if (type->_type == CG_STRUCT + 128) - { - int i; - CgStructureType *structureType = (CgStructureType *)type; - int res = 0; - int count = (int)structureType->_elements.size(); - - for (i = 0; i < count; i++) - res += getStride(structureType->_elements[i]._type); - return res; - } - - return -9999999; -} - -static int getSizeofSubArray(_CGNVCONTAINERS &containers, int dimensionIndex, int dimensionCount, int endianness) -{ - unsigned char elfEndianness = endianness; //used in the macro CNVEND - int res = 1; - int i; - for ( i=0; i < dimensionCount; i++) - res *= (int)CNV2END(containers._dimensions[dimensionIndex + i]); - return res; -} - - - -unsigned short getFlags(CGenum var, CGenum dir, int no, bool is_referenced, bool is_shared, int paramIndex) -{ - //the following is error prone, use 2 enum array to do the matching instead - //variability - uint16_t flags = 0; - if (var == CG_VARYING) - flags |= CGPV_VARYING; - else if (var == CG_UNIFORM) - flags |= CGPV_UNIFORM; - else if (var == CG_CONSTANT) - flags |= CGPV_CONSTANT; - else if (var == CG_MIXED) - flags |= CGPV_MIXED; - - //direction - if (dir == CG_IN) - flags |= CGPD_IN; - else if (dir == CG_OUT) - flags |= CGPD_OUT; - else if (dir == CG_INOUT) - flags |= CGPD_INOUT; - - //boolean - if (is_referenced) - flags |= CGPF_REFERENCED; - - //is it a global parameter ? - if (no == -1) - flags |= CGPF_GLOBAL; - else if (no == -2) - flags |= CGP_INTERNAL; - else - { - //RGL_ASSERT2(no>=0,("error\n")); - /*if ( no == paramIndex ) //means that a previous parameter already had the same param index, it's an aggregated type - flags |= CGP_AGGREGATED;*/ - paramIndex = no; - } - return flags; -} - -/*============================================================ - CGBIO - ============================================================ */ - -namespace cgc { - namespace bio { - - bin_io* bin_io::instance_ = 0; - - bin_io::bin_io() - { - } - - bin_io::bin_io( const bin_io& ) - { - } - - const bin_io* - bin_io::instance() - { - if (instance_ == 0) - instance_ = new bin_io; - return instance_; - } - - void - bin_io::delete_instance() - { - if (instance_ != 0) - { - free(instance_); - instance_ = 0; - } - } - - const char* - bin_io::error_string( CGBIO_ERROR error ) const - { - switch ( error ) - { - case CGBIO_ERROR_NO_ERROR: - return "No error"; - case CGBIO_ERROR_LOADED: - return "Binary file has been loaded earlier"; - case CGBIO_ERROR_FILEIO: - return "File input output error"; - case CGBIO_ERROR_FORMAT: - return "File format error"; - case CGBIO_ERROR_INDEX: - return "Index is out of range"; - case CGBIO_ERROR_MEMORY: - return "Can't allocate memory"; - case CGBIO_ERROR_RELOC: - return "Relocation error"; - case CGBIO_ERROR_SYMBOL: - return "Symbol error"; - case CGBIO_ERROR_UNKNOWN_TYPE: - return "Uknown type"; - default: - return "Unknown error"; - } - return "Unknown error"; - } - - CGBIO_ERROR - bin_io::new_nvb_reader( nvb_reader** obj ) const - { - CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR; - *obj = new nvb_reader_impl; - if (*obj == 0) - ret = CGBIO_ERROR_MEMORY; - return ret; - } - } // bio namespace -} // cgc namespace - -using std::fill_n; - -/*============================================================ - NVBI IMPLEMENTATION - ============================================================ */ - -namespace cgc { - namespace bio { - - nvb_reader_impl::nvb_reader_impl() - { - ref_count_ = 1; - offset_ = 0; - image_ = 0; - owner_ = false; - loaded_ = false; - endianness_ = host_endianness(); - std::fill_n( (char*)( &header_ ), sizeof( header_ ), '\0' ); - } - - nvb_reader_impl::~nvb_reader_impl() - { - if (image_ != 0) - free(image_); - } - - ptrdiff_t - nvb_reader_impl::reference() const - { - return ++ref_count_; - } - - ptrdiff_t - nvb_reader_impl::release() const - { - ptrdiff_t ret = --ref_count_; - if (ref_count_ == 0) - delete this; - return ret; - } - - CGBIO_ERROR - nvb_reader_impl::loadFromString( const char* source, size_t length) - { - if ( loaded_ ) - return CGBIO_ERROR_LOADED; - - CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR; - while (1) - { - if (length < sizeof( header_ )) - { - ret = CGBIO_ERROR_FORMAT; - break; - } - memcpy(&header_ ,source,sizeof( header_ )); - 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 ) - { - ret = CGBIO_ERROR_FORMAT; - break; - } - } - image_ = (char*)malloc(length * sizeof(char)); - memcpy(image_, source , length); - loaded_ = true; - ret = CGBIO_ERROR_NO_ERROR; - break; - } - return ret; - } - - bool - nvb_reader_impl::is_loaded() const - { - return loaded_; - } - - unsigned char - nvb_reader_impl::endianness() const - { - return endianness_; - } - - CGprofile - nvb_reader_impl::profile() const - { - return (CGprofile) convert_endianness( (unsigned int) header_.profile, endianness() ); - } - - unsigned int - nvb_reader_impl::revision() const - { - return convert_endianness( header_.binaryFormatRevision, endianness() ); - } - - unsigned int - nvb_reader_impl::size() const - { - return convert_endianness( header_.totalSize, endianness() ); - } - - unsigned int - nvb_reader_impl::number_of_params() const - { - return convert_endianness( header_.parameterCount, endianness() ); - } - - unsigned int - nvb_reader_impl::ucode_size() const - { - return convert_endianness( header_.ucodeSize, endianness() ); - } - - const char* - nvb_reader_impl::ucode() const - { - if (image_ == 0 || ucode_size() == 0) - return 0; - return ( image_ + convert_endianness( header_.ucode, endianness() ) ); - } - - const CgBinaryFragmentProgram* - nvb_reader_impl::fragment_program() const - { - if (image_ == 0) - return 0; - return (CgBinaryFragmentProgram*)( &image_[convert_endianness( header_.program, endianness_ )] ); - } - - const CgBinaryVertexProgram* - nvb_reader_impl::vertex_program() const - { - if (image_ == 0) - return 0; - return (CgBinaryVertexProgram*)( &image_[convert_endianness( header_.program, endianness_ )] ); - } - - CGBIO_ERROR - nvb_reader_impl::get_param_name( unsigned int index, const char **name, bool& is_referenced ) const - { - if (index >= number_of_params()) - return CGBIO_ERROR_INDEX; - - if (image_ == 0) - return CGBIO_ERROR_NO_ERROR; - - const CgBinaryParameter* params = (CgBinaryParameter*)( &image_[convert_endianness( header_.parameterArray, endianness_ )] ); - const CgBinaryParameter& pp = params[index]; - is_referenced = convert_endianness( pp.isReferenced, endianness() ) != 0; - CgBinaryStringOffset nm_offset = convert_endianness( pp.name,endianness() ); - if (nm_offset != 0) - *name = &image_[nm_offset]; - else - *name = ""; - return CGBIO_ERROR_NO_ERROR; - } - - CGBIO_ERROR - nvb_reader_impl::get_param( unsigned int index, - CGtype& type, - CGresource& resource, - CGenum& variability, - int& resource_index, - const char ** name, - std::vector& default_value, - std::vector& embedded_constants, - const char ** semantic, - CGenum& direction, - int& paramno, - bool& is_referenced, - bool& is_shared ) const - { - if (index >= number_of_params()) - return CGBIO_ERROR_INDEX; - - if (image_ == 0) - return CGBIO_ERROR_NO_ERROR; - - const CgBinaryParameter* params = (CgBinaryParameter*)( &image_[convert_endianness( header_.parameterArray, endianness_ )] ); - const CgBinaryParameter& pp = params[index]; - type = static_cast( convert_endianness( static_cast( pp.type ), endianness() ) ); - resource = static_cast( convert_endianness( static_cast( pp.res ), endianness() ) ); - variability = static_cast( convert_endianness( static_cast( pp.var ), endianness() ) ); - resource_index = convert_endianness( pp.resIndex, endianness() ); - direction = static_cast( convert_endianness( static_cast( pp.direction ), endianness() ) ); - paramno = convert_endianness( pp.paramno, endianness() ); - is_referenced = convert_endianness( pp.isReferenced, endianness() ) != 0; - is_shared = false; - CgBinaryStringOffset nm_offset = convert_endianness( pp.name, endianness() ); - CgBinaryFloatOffset dv_offset = convert_endianness( pp.defaultValue, endianness() ); - CgBinaryEmbeddedConstantOffset ec_offset = convert_endianness( pp.embeddedConst, endianness() ); - CgBinaryStringOffset sm_offset = convert_endianness( pp.semantic, endianness() ); - if (nm_offset != 0) - *name = &image_[nm_offset]; - else - *name = ""; - - if (sm_offset != 0) - *semantic = &image_[sm_offset]; - else - *semantic = ""; - if (dv_offset != 0) - { - char *vp = &image_[dv_offset]; - for (int ii = 0; ii < 4; ++ii) - { - int tmp; - memcpy(&tmp,vp+4*ii,4); - tmp = convert_endianness(tmp,endianness()); - float tmp2; - memcpy(&tmp2,&tmp,4); - default_value.push_back( tmp2 ); - } - } - if (ec_offset != 0) - { - void *vp = &image_[ec_offset]; - CgBinaryEmbeddedConstant& ec = *(static_cast( vp )); - for (unsigned int ii = 0; ii < convert_endianness( ec.ucodeCount, endianness() ); ++ii) - { - unsigned int offset = convert_endianness( ec.ucodeOffset[ii], endianness() ); - embedded_constants.push_back( offset ); - } - } - return CGBIO_ERROR_NO_ERROR; - } - - - } -} diff --git a/ps3/gcmgl/src/rgl_ps3_raster.cpp b/ps3/gcmgl/src/rgl_ps3_raster.cpp deleted file mode 100644 index 4c5077457d..0000000000 --- a/ps3/gcmgl/src/rgl_ps3_raster.cpp +++ /dev/null @@ -1,2654 +0,0 @@ -#include "rgl.h" - -#include - -#include "include/GmmAlloc.h" -#include "include/rgl-typedefs.h" -#include "include/rgl-inline.h" - -#include -#include -#include - -#include - -#include -#include -#include - -/*============================================================ - MEMORY MANAGER - ============================================================ */ - -#define ENDIAN_32(X, F) ((F) ? endianSwapWord(X) : (X)) - -int _parameterAlloc = 0; -int _ucodeAlloc = 0; - -int rglGetTypeResource( _CGprogram* program, uint16_t typeIndex, int16_t *resourceIndex ); -int rglGetTypeResourceID( _CGprogram* program, uint16_t typeIndex ); -int rglGetTypeResourceRegisterCountVP( _CGprogram* program, int16_t resourceIndex, int resourceCount, uint16_t *resource ); - -static void setAttribConstantIndex (void *data, const void* v, const int ) // index -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - _CGprogram *program = (_CGprogram*)ptr->program; - const CgParameterResource *parameterResource = rglGetParameterResource( program, ptr->parameterEntry ); - GLuint index = parameterResource->resource - CG_ATTR0; - float * f = ( float* ) v; - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - - rglAttribute* attrib = (rglAttribute*)LContext->attribs->attrib + index; - attrib->value[0] = f[0]; - attrib->value[1] = f[1]; - attrib->value[2] = f[2]; - attrib->value[3] = f[3]; - RGLBIT_TRUE( LContext->attribs->DirtyMask, index ); -} - -//here ec has been advanced and is already on top of the embedded constant count -#define swapandsetfp(SIZE, ucodeSize, loadProgramId, loadProgramOffset, ec, v) \ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; \ - rglGcmSetTransferLocation(thisContext, CELL_GCM_LOCATION_LOCAL ); \ - uint16_t count = *( ec++ ); \ - for ( uint32_t offsetIndex = 0; offsetIndex < count; ++offsetIndex ) \ - { \ - void *pointer=NULL; \ - const int paddedSIZE = (SIZE + 1) & ~1; /* even width only */ \ - uint32_t var = gmmIdToOffset( loadProgramId ) + loadProgramOffset + *( ec++ ); \ - rglGcmSetInlineTransferPointer(thisContext, var, paddedSIZE, pointer); \ - float *fp = (float*)pointer; \ - float *src = (float*)v; \ - for (uint32_t j=0; j static void setVectorTypefp( void *dat, const void* v) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)dat; - float *f = ( float* )v; - float *data = ( float* )ptr->pushBufferPointer;/*(float*)ptr->offset*;*/ - for (int i = 0; i < SIZE; ++i ) //TODO: ced: find out if this loop for the get or for the reset in a future use of the same shader or just for the alignment??? - data[i] = f[i]; - _CGprogram *program = ptr->program; - - CgParameterResource *parameterResource = rglGetParameterResource( ptr->program, ptr->parameterEntry ); - uint16_t resource = parameterResource->resource; - uint16_t *ec = ( uint16_t * )( ptr->program->resources ) + resource + 1;//+1 to skip the register - if ( RGL_LIKELY( *ec ) ) - { - swapandsetfp(SIZE, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, data); - } -} - -// matrix uniforms -// note that Cg generated matrices are 1 row per binary param -// storage within the parameter is row major (so register setting is easier) - -//tmp array tentative - -#define ROW_MAJOR 0 -#define COL_MAJOR 1 - -template static void setVectorTypevpIndex (void *data, const void*v, const int index ) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - RGLcontext * LContext = _CurrentContext; - const float *f = ( const float* )v; - float *dst; - if (isIndex) - dst = ( float* )( *(( unsigned int ** )ptr->pushBufferPointer + index ) ); - else - dst = ( float* )ptr->pushBufferPointer; - - for ( int i = 0; i < SIZE; ++ i ) - dst[i] = f[i]; - LContext->needValidate |= RGL_VALIDATE_VERTEX_CONSTANTS; -} - -template static void setVectorTypefpIndex (void *dat, const void *v, const int index) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)dat; - float * f = (float*)v; - float * data = (float*)ptr->pushBufferPointer;/*(float*)ptr->offset*;*/ - for ( int i = 0; i < SIZE; ++i ) //TODO: ced: find out if this loop for the get or for the reset in a future use of the same shader or just for the alignment??? - data[i] = f[i]; - _CGprogram *program = ptr->program; - - const CgParameterResource *parameterResource = rglGetParameterResource( program, ptr->parameterEntry ); - uint16_t resource = parameterResource->resource; - uint16_t *ec = ( uint16_t * )( ptr->program->resources ) + resource + 1; - if (isIndex) - { - int arrayIndex = index; - while ( arrayIndex ) //jump to the right index... this is slow - { - ec += (( *ec ) + 2 );//+1 for the register, +1 for the count, +count for the number of embedded consts - arrayIndex--; - } - } - if ( RGL_LIKELY( *ec ) ) - { - swapandsetfp(SIZE, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, data); - } -} - -//matrices -template static void setMatrixvpIndex (void *data, const void* v, const int index ) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - RGLcontext * LContext = _CurrentContext; - float *f = ( float* )v; - float *dst = ( float* )ptr->pushBufferPointer; - for ( int row = 0; row < ROWS; ++row ) - { - for ( int col = 0; col < COLS; ++col ) - dst[row * 4 + col] = ( ORDER == ROW_MAJOR ) ? f[row * COLS + col] : f[col * ROWS + row]; - } - LContext->needValidate |= RGL_VALIDATE_VERTEX_CONSTANTS; -} - -template static void setMatrixvpIndexArray (void *data, const void* v, const int index ) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - RGLcontext *LContext = (RGLcontext*)_CurrentContext; - float *f = (float*)v; - float *dst = (float*)( *(( unsigned int ** )ptr->pushBufferPointer + index ) ); - for ( int row = 0; row < ROWS; ++row ) - { - for ( int col = 0; col < COLS; ++col ) - dst[row * 4 + col] = ( ORDER == ROW_MAJOR ) ? f[row * COLS + col] : f[col * ROWS + row]; - } - LContext->needValidate |= RGL_VALIDATE_VERTEX_CONSTANTS; -} - -template static void setMatrixfpIndex (void *data, const void* v, const int /*index*/ ) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - float *f = (float*)v; - float *dst = (float*)ptr->pushBufferPointer; - _CGprogram *program = (( CgRuntimeParameter* )ptr )->program; - const CgParameterResource *parameterResource = rglGetParameterResource( program, ptr->parameterEntry ); - uint16_t resource = parameterResource->resource; - uint16_t *ec = ( uint16_t * )program->resources + resource + 1; //+1 to skip the register - for ( long row = 0; row < ROWS; ++row ) - { - for ( long col = 0; col < COLS; ++col ) - dst[row * 4 + col] = ( ORDER == ROW_MAJOR ) ? f[row * COLS + col] : f[col * ROWS + row]; - int count = *ec; - if ( RGL_LIKELY( count ) ) - { - const unsigned int *v = (unsigned int*)dst + row * 4; - swapandsetfp(COLS, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, v); - } - ec += count + 2; //+1 for the register, +1 for the count, + count for the number of embedded consts - } -} - -template static void setMatrixfpIndexArray (void *data, const void* v, const int index ) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - float *f = (float*)v; - float *dst = (float*)ptr->pushBufferPointer; - _CGprogram *program = ptr->program; - const CgParameterResource *parameterResource = rglGetParameterResource( program, ptr->parameterEntry ); - uint16_t resource = parameterResource->resource; - uint16_t *ec = (uint16_t*)program->resources + resource + 1;//+1 to skip the register - int arrayIndex = index * ROWS; - while ( arrayIndex ) //jump to the right index... this is slow - { - uint16_t count = ( *ec ); - ec += ( count + 2 ); //+1 for the register, +1 for the count, +count for the number of embedded consts - arrayIndex--; - } - for ( long row = 0; row < ROWS; ++row ) - { - for ( long col = 0; col < COLS; ++col ) - dst[row * 4 + col] = ( ORDER == ROW_MAJOR ) ? f[row * COLS + col] : f[col * ROWS + row]; - int count = *ec; - if ( RGL_LIKELY( count ) ) - { - const unsigned int *v = ( unsigned int * )dst + row * 4; - swapandsetfp(COLS, (program->header.instructionCount*16), program->loadProgramId, program->loadProgramOffset, ec, v); - } - ec += count + 2;//+1 for the register, +1 for the count, +count for the number of embedded consts - } -} - -static _cgSetArrayIndexFunction setVectorTypeIndex[2][1][2][4] = -{ - { - { - {&setVectorTypevpIndex<1, 0>, &setVectorTypevpIndex<2, 0>, &setVectorTypevpIndex<3, 0>, &setVectorTypevpIndex<4, 0>, }, - {&setVectorTypefpIndex<1, 0>, &setVectorTypefpIndex<2, 0>, &setVectorTypefpIndex<3, 0>, &setVectorTypefpIndex<4, 0>, } - }, - }, - { - { - {&setVectorTypevpIndex<1, 1>, &setVectorTypevpIndex<2, 1>, &setVectorTypevpIndex<3, 1>, &setVectorTypevpIndex<4, 1>, }, - {&setVectorTypefpIndex<1, 1>, &setVectorTypefpIndex<2, 1>, &setVectorTypefpIndex<3, 1>, &setVectorTypefpIndex<4, 1>, } - }, - }, -}; - -static _cgSetArrayIndexFunction setMatrixTypeIndex[2][2][2][4][4][2] = -{ - { - { - { - { - { &setMatrixvpIndex<1, 1, 0>, &setMatrixvpIndex<1, 1, 1>}, - { &setMatrixvpIndex<1, 2, 0>, &setMatrixvpIndex<1, 2, 1>}, - { &setMatrixvpIndex<1, 3, 0>, &setMatrixvpIndex<1, 3, 1>}, - { &setMatrixvpIndex<1, 4, 0>, &setMatrixvpIndex<1, 4, 1>} - }, - { - { &setMatrixvpIndex<2, 1, 0>, &setMatrixvpIndex<2, 1, 1>}, - { &setMatrixvpIndex<2, 2, 0>, &setMatrixvpIndex<2, 2, 1>}, - { &setMatrixvpIndex<2, 3, 0>, &setMatrixvpIndex<2, 3, 1>}, - { &setMatrixvpIndex<2, 4, 0>, &setMatrixvpIndex<2, 4, 1>} - }, - { - { &setMatrixvpIndex<3, 1, 0>, &setMatrixvpIndex<3, 1, 1>}, - { &setMatrixvpIndex<3, 2, 0>, &setMatrixvpIndex<3, 2, 1>}, - { &setMatrixvpIndex<3, 3, 0>, &setMatrixvpIndex<3, 3, 1>}, - { &setMatrixvpIndex<3, 4, 0>, &setMatrixvpIndex<3, 4, 1>} - }, - { - { &setMatrixvpIndex<4, 1, 0>, &setMatrixvpIndex<4, 1, 1>}, - { &setMatrixvpIndex<4, 2, 0>, &setMatrixvpIndex<4, 2, 1>}, - { &setMatrixvpIndex<4, 3, 0>, &setMatrixvpIndex<4, 3, 1>}, - { &setMatrixvpIndex<4, 4, 0>, &setMatrixvpIndex<4, 4, 1>} - }, - }, - { - {{ &setMatrixfpIndex<1, 1, 0>, &setMatrixfpIndex<1, 1, 1>}, { &setMatrixfpIndex<1, 2, 0>, &setMatrixfpIndex<1, 2, 1>}, { &setMatrixfpIndex<1, 3, 0>, &setMatrixfpIndex<1, 3, 1>}, { &setMatrixfpIndex<1, 4, 0>, &setMatrixfpIndex<1, 4, 1>}}, - {{ &setMatrixfpIndex<2, 1, 0>, &setMatrixfpIndex<2, 1, 1>}, { &setMatrixfpIndex<2, 2, 0>, &setMatrixfpIndex<2, 2, 1>}, { &setMatrixfpIndex<2, 3, 0>, &setMatrixfpIndex<2, 3, 1>}, { &setMatrixfpIndex<2, 4, 0>, &setMatrixfpIndex<2, 4, 1>}}, - {{ &setMatrixfpIndex<3, 1, 0>, &setMatrixfpIndex<3, 1, 1>}, { &setMatrixfpIndex<3, 2, 0>, &setMatrixfpIndex<3, 2, 1>}, { &setMatrixfpIndex<3, 3, 0>, &setMatrixfpIndex<3, 3, 1>}, { &setMatrixfpIndex<3, 4, 0>, &setMatrixfpIndex<3, 4, 1>}}, - {{ &setMatrixfpIndex<4, 1, 0>, &setMatrixfpIndex<4, 1, 1>}, { &setMatrixfpIndex<4, 2, 0>, &setMatrixfpIndex<4, 2, 1>}, { &setMatrixfpIndex<4, 3, 0>, &setMatrixfpIndex<4, 3, 1>}, { &setMatrixfpIndex<4, 4, 0>, &setMatrixfpIndex<4, 4, 1>}}, - }, - }, - }, - { - { - { - {{ &setMatrixvpIndexArray<1, 1, 0>, &setMatrixvpIndexArray<1, 1, 1>}, { &setMatrixvpIndexArray<1, 2, 0>, &setMatrixvpIndexArray<1, 2, 1>}, { &setMatrixvpIndexArray<1, 3, 0>, &setMatrixvpIndexArray<1, 3, 1>}, { &setMatrixvpIndexArray<1, 4, 0>, &setMatrixvpIndexArray<1, 4, 1>}}, - {{ &setMatrixvpIndexArray<2, 1, 0>, &setMatrixvpIndexArray<2, 1, 1>}, { &setMatrixvpIndexArray<2, 2, 0>, &setMatrixvpIndexArray<2, 2, 1>}, { &setMatrixvpIndexArray<2, 3, 0>, &setMatrixvpIndexArray<2, 3, 1>}, { &setMatrixvpIndexArray<2, 4, 0>, &setMatrixvpIndexArray<2, 4, 1>}}, - {{ &setMatrixvpIndexArray<3, 1, 0>, &setMatrixvpIndexArray<3, 1, 1>}, { &setMatrixvpIndexArray<3, 2, 0>, &setMatrixvpIndexArray<3, 2, 1>}, { &setMatrixvpIndexArray<3, 3, 0>, &setMatrixvpIndexArray<3, 3, 1>}, { &setMatrixvpIndexArray<3, 4, 0>, &setMatrixvpIndexArray<3, 4, 1>}}, - {{ &setMatrixvpIndexArray<4, 1, 0>, &setMatrixvpIndexArray<4, 1, 1>}, { &setMatrixvpIndexArray<4, 2, 0>, &setMatrixvpIndexArray<4, 2, 1>}, { &setMatrixvpIndexArray<4, 3, 0>, &setMatrixvpIndexArray<4, 3, 1>}, { &setMatrixvpIndexArray<4, 4, 0>, &setMatrixvpIndexArray<4, 4, 1>}}, - }, - { - {{ &setMatrixfpIndexArray<1, 1, 0>, &setMatrixfpIndexArray<1, 1, 1>}, { &setMatrixfpIndexArray<1, 2, 0>, &setMatrixfpIndexArray<1, 2, 1>}, { &setMatrixfpIndexArray<1, 3, 0>, &setMatrixfpIndexArray<1, 3, 1>}, { &setMatrixfpIndexArray<1, 4, 0>, &setMatrixfpIndexArray<1, 4, 1>}}, - {{ &setMatrixfpIndexArray<2, 1, 0>, &setMatrixfpIndexArray<2, 1, 1>}, { &setMatrixfpIndexArray<2, 2, 0>, &setMatrixfpIndexArray<2, 2, 1>}, { &setMatrixfpIndexArray<2, 3, 0>, &setMatrixfpIndexArray<2, 3, 1>}, { &setMatrixfpIndexArray<2, 4, 0>, &setMatrixfpIndexArray<2, 4, 1>}}, - {{ &setMatrixfpIndexArray<3, 1, 0>, &setMatrixfpIndexArray<3, 1, 1>}, { &setMatrixfpIndexArray<3, 2, 0>, &setMatrixfpIndexArray<3, 2, 1>}, { &setMatrixfpIndexArray<3, 3, 0>, &setMatrixfpIndexArray<3, 3, 1>}, { &setMatrixfpIndexArray<3, 4, 0>, &setMatrixfpIndexArray<3, 4, 1>}}, - {{ &setMatrixfpIndexArray<4, 1, 0>, &setMatrixfpIndexArray<4, 1, 1>}, { &setMatrixfpIndexArray<4, 2, 0>, &setMatrixfpIndexArray<4, 2, 1>}, { &setMatrixfpIndexArray<4, 3, 0>, &setMatrixfpIndexArray<4, 3, 1>}, { &setMatrixfpIndexArray<4, 4, 0>, &setMatrixfpIndexArray<4, 4, 1>}}, - }, - }, - } -}; - -static void setSamplerfp (void *data, const void*v, int /* index */) -{ - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - _CGprogram *program = (( CgRuntimeParameter* )ptr )->program; - const CgParameterResource *parameterResource = (const CgParameterResource*)rglGetParameterResource( program, (( CgRuntimeParameter* )ptr )->parameterEntry ); - - // the value of v == NULL when it is called from cgGLEnableTextureParameter - // the value of v == NULL when it is called from cgGLSetTextureParameter - // this may be called by a connected param to propagate its value - // the spec says that the set should not cause the bind - // so only do the bind when the call comes from cgGLEnableTextureParameter - if (v) - *(GLuint*)ptr->pushBufferPointer = *(GLuint*)v; - else - { - rglTextureImageUnit *unit = (rglTextureImageUnit*)(_CurrentContext->TextureImageUnits + ( parameterResource->resource - CG_TEXUNIT0 )); - rglBindTextureInternal( unit, *(GLuint*)ptr->pushBufferPointer, ptr->glType ); - } -} - -static void setSamplervp (void *data, const void*v, int /* index */) -{ - // the value of v == NULL when it is called from cgGLEnableTextureParameter - // the value of v == NULL when it is called from cgGLSetTextureParameter - // this may be called by a connected param to propagate its value - // the spec says that the set should not cause the bind - // so only do the bind when the call comes from cgGLEnableTextureParameter - if (!v) - return; - - CgRuntimeParameter *ptr = (CgRuntimeParameter*)data; - *(GLuint*)ptr->pushBufferPointer = *( GLuint* )v; -} - - -#undef ROW_MAJOR -#undef COL_MAJOR - -#define ROW_MAJOR 0 -#define COL_MAJOR 1 - -//This function creates the push buffer and the related structures -void rglCreatePushBuffer(void *data) -{ - _CGprogram *program = (_CGprogram*)data; - - //first pass to compute the space needed - int bufferSize = 0; - int programPushBufferPointersSize = 0; - int extraStorageInWords = 0; - int offsetCount = 0; - int samplerCount = 0; - int profileIndex = ( program->header.profile == CG_PROFILE_SCE_FP_TYPEB || - program->header.profile == CG_PROFILE_SCE_FP_RSX ) ? FRAGMENT_PROFILE_INDEX : VERTEX_PROFILE_INDEX; - - bool hasSharedParams = false; - int arrayCount = 1; - for ( int i = 0;i < program->rtParametersCount;i++ ) - { - const CgParameterEntry *parameterEntry = program->parametersEntries + i; - - //skip the unrolled arrays and the structures - if (( parameterEntry->flags & CGP_STRUCTURE ) || ( parameterEntry->flags & CGP_UNROLLED ) ) - { - arrayCount = 1; - continue; - } - - if (( parameterEntry->flags & CGPF_REFERENCED ) ) - { - if ( parameterEntry->flags & CGP_ARRAY ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( program, parameterEntry ); - arrayCount = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - continue; - } - if (( parameterEntry->flags & CGPV_MASK ) == CGPV_UNIFORM ) - { - const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); - if ( parameterResource->type >= CG_SAMPLER1D && parameterResource->type <= CG_SAMPLERCUBE ) - { - // store 1 sampler and 1 offset for texture samplers. - offsetCount += arrayCount; - samplerCount += arrayCount; - } - else if ( profileIndex == VERTEX_PROFILE_INDEX ) - { - int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; - if ( parameterEntry->flags & CGP_CONTIGUOUS ) - bufferSize += 3 + 4 * arrayCount * registerStride; - else - { - programPushBufferPointersSize += arrayCount; - int resourceIndex = parameterResource->resource; - int referencedSize = 3 + 4 * registerStride; - int notReferencedSize = 4 * registerStride; - for ( int j = 0;j < arrayCount;j++, resourceIndex += registerStride ) - { - //I use the programPushBuffer pointer so it's valid to have element in an array without any affectation - if ( program->resources[resourceIndex] != 0xffff ) - bufferSize += referencedSize; //referenced: push buffer - else - extraStorageInWords += notReferencedSize; //not referenced , extra storage location - } - } - } - else //profileIndex == FRAGMENT_PROFILE_INDEX - { - int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; - //TODO: check this case - extraStorageInWords += 4 * arrayCount * registerStride; - } - } - } - arrayCount = 1; - } - - bufferSize = rglPad( bufferSize, 4 ); - - //allocate the buffer(s) - unsigned int storageSizeInWords = bufferSize + extraStorageInWords; - if ( storageSizeInWords ) - program->memoryBlock = ( unsigned int* )memalign( 16, storageSizeInWords * 4 ); - else - program->memoryBlock = NULL; - - //TODO: this is tmp - program->samplerCount = samplerCount; - program->samplerValuesLocation = NULL; - program->samplerIndices = NULL; - program->samplerUnits = NULL; - - if ( samplerCount ) - { - program->samplerValuesLocation = ( GLuint* )malloc( samplerCount * sizeof( GLuint ) ); - program->samplerIndices = ( GLuint* )malloc( samplerCount * sizeof( GLuint ) ); - program->samplerUnits = ( GLuint* )malloc( samplerCount * sizeof( GLuint ) ); - } - - GLuint *samplerValuesLocation = program->samplerValuesLocation; - GLuint *samplerIndices = program->samplerIndices; - GLuint *samplerUnits = program->samplerUnits; - - program->constantPushBufferPointers = NULL; - - if ( programPushBufferPointersSize ) - program->constantPushBufferPointers = ( unsigned int** )malloc( programPushBufferPointersSize * 4 ); - - uint32_t *rglGcmCurrent = (uint32_t*)program->memoryBlock; - program->constantPushBuffer = ( bufferSize > 0 ) ? ( unsigned int * )rglGcmCurrent : NULL; - unsigned int **programPushBuffer = program->constantPushBufferPointers; - program->constantPushBufferWordSize = bufferSize; - GLuint *currentStorage = ( GLuint * )( rglGcmCurrent + bufferSize ); - - //second pass to fill the buffer - arrayCount = 1; - const CgParameterEntry *containerEntry = NULL; - - for ( int i = 0;i < program->rtParametersCount;i++ ) - { - CgRuntimeParameter *rtParameter = program->runtimeParameters + i; - const CgParameterEntry *parameterEntry = program->parametersEntries + i; - if ( containerEntry == NULL ) - containerEntry = parameterEntry; - - rtParameter->samplerSetter = _cgIgnoreParamIndex; - - //tentative - rtParameter->setterIndex = _cgIgnoreParamIndex; - rtParameter->setterrIndex = _cgIgnoreParamIndex; - rtParameter->settercIndex = _cgIgnoreParamIndex; - - CGparameter id = ( CGparameter )rglCreateName( &_CurrentContext->cgParameterNameSpace, ( void* )rtParameter ); - if ( !id ) - break; - - rtParameter->id = id; - rtParameter->parameterEntry = parameterEntry; - rtParameter->program = program; - - //skip the unrolled arrays and the structures - if (( parameterEntry->flags & CGP_STRUCTURE ) || ( parameterEntry->flags & CGP_UNROLLED ) ) - { - arrayCount = 1; - containerEntry = NULL; - continue; - } - - if ( parameterEntry->flags & CGPF_REFERENCED ) - { - if ( parameterEntry->flags & CGP_ARRAY ) - { - const CgParameterArray *parameterArray = rglGetParameterArray( program, parameterEntry ); - arrayCount = rglGetSizeofSubArray( parameterArray->dimensions, parameterArray->dimensionCount ); - //continue to the next item - continue; - } - if ((parameterEntry->flags & CGPV_MASK) == CGPV_UNIFORM) - { - //TODO: rtParameter->defaultNormalize = CG_FALSE; - rtParameter->glType = GL_NONE; - //TODO: needed ? rtParameter->flags = 0; - const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); - if ( parameterResource->type >= CG_SAMPLER1D && parameterResource->type <= CG_SAMPLERCUBE ) - { - //TODO - rtParameter->pushBufferPointer = samplerValuesLocation; - // initialize the texture name to zero, used by the setSamplerfp call to rglBindTextureInternal - *samplerValuesLocation = 0; - samplerValuesLocation++; - - // store the texture unit indices. - *samplerIndices = i; - samplerIndices++; - *samplerUnits = parameterResource->resource - CG_TEXUNIT0; - samplerUnits++; - - // XXX the setter is called when validating vertex programs. - // this would cause a CG error. - // the parameters should have a "validate" function instead - if ( profileIndex == VERTEX_PROFILE_INDEX ) - { - rtParameter->setterIndex = _cgIgnoreParamIndex; - rtParameter->samplerSetter = setSamplervp; - } - else - rtParameter->samplerSetter = setSamplerfp; - rtParameter->glType = rglCgGetSamplerGLTypeFromCgType(( CGtype )( parameterResource->type ) ); - } - else - { - if ( profileIndex == VERTEX_PROFILE_INDEX ) - { - int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; - int registerCount = arrayCount * registerStride; - if ( parameterEntry->flags & CGP_CONTIGUOUS ) - { - memset( rglGcmCurrent, 0, 4*( 4*registerCount + 3 ) ); - CellGcmContextData gcmContext, *gcmContext_ptr; - gcmContext.current = (uint32_t*)rglGcmCurrent; - float *v = ( float* )rglGcmCurrent; - gcmContext_ptr = &gcmContext; - rglGcmSetVertexProgramParameterBlock(gcmContext_ptr, parameterResource->resource, registerCount, v); - rglGcmCurrent = (typeof(rglGcmCurrent))gcmContext.current; - - rtParameter->pushBufferPointer = rglGcmCurrent - 4 * registerCount; - } - else - { - rtParameter->pushBufferPointer = programPushBuffer; - int resourceIndex = parameterResource->resource; - for ( int j = 0;j < arrayCount;j++, resourceIndex += registerStride ) - { - //I use the programPushBuffer pointer so it's valid to have element in an array without any affectation - if ( program->resources[resourceIndex] != 0xffff ) - { - memset( rglGcmCurrent, 0, 4*( 4*registerStride + 3 ) ); - CellGcmContextData gcmContext, *gcmContext_ptr; - gcmContext.current = (uint32_t*)rglGcmCurrent; - gcmContext_ptr = &gcmContext; - float *v= (float*)rglGcmCurrent; - rglGcmSetVertexProgramParameterBlock(gcmContext_ptr, program->resources[resourceIndex], registerStride, v); - rglGcmCurrent = (typeof(rglGcmCurrent))gcmContext.current; - *( programPushBuffer++ ) = ( unsigned int* )( rglGcmCurrent - 4 * registerStride ); - } - else - { - //This case is when there is an array item which is not referenced - //we still call tbe setter function, so we have to store the info somewhere... - //and we need to return the value previously set in case of the user asks for a get - *( programPushBuffer++ ) = ( unsigned int* )currentStorage; - currentStorage += 4 * registerStride; - } - } - } - } - else //if (profileIndex == FRAGMENT_PROFILE_INDEX) - { - int registerStride = isMatrix(( CGtype )parameterResource->type ) ? rglGetTypeRowCount(( CGtype )parameterResource->type ) : 1; - int registerCount = arrayCount * registerStride; - rtParameter->pushBufferPointer = currentStorage; - currentStorage += 4 * registerCount; - } - - switch ( parameterResource->type ) - { - case CG_FLOAT: - case CG_FLOAT1: case CG_FLOAT2: case CG_FLOAT3: case CG_FLOAT4: - // if this gets updated, don't forget the halfs below - { - unsigned int floatCount = rglCountFloatsInCgType(( CGtype )parameterResource->type ); - rtParameter->setterIndex = setVectorTypeIndex[( containerEntry->flags&CGP_ARRAY ) ? 1 : 0][0][profileIndex][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: - // if this gets updated, don't forget the halfs below - rtParameter->setterrIndex = setMatrixTypeIndex[( containerEntry->flags&CGP_ARRAY ) ? 1 : 0][0][profileIndex][rglGetTypeRowCount(( CGtype )parameterResource->type ) - 1][rglGetTypeColCount(( CGtype )parameterResource->type ) - 1][ROW_MAJOR]; - rtParameter->settercIndex = setMatrixTypeIndex[( containerEntry->flags&CGP_ARRAY ) ? 1 : 0][0][profileIndex][rglGetTypeRowCount(( CGtype )parameterResource->type ) - 1][rglGetTypeColCount(( CGtype )parameterResource->type ) - 1][COL_MAJOR]; - break; - case CG_SAMPLER1D: case CG_SAMPLER2D: case CG_SAMPLER3D: case CG_SAMPLERRECT: case CG_SAMPLERCUBE: - // A used sampler that does not have a TEXUNIT resource ? - // not sure if we ever go here. - break; - case CGP_SCF_BOOL: - break; - case CG_HALF: - case CG_HALF1: case CG_HALF2: case CG_HALF3: case CG_HALF4: - case CG_INT: - case CG_INT1: case CG_INT2: case CG_INT3: case CG_INT4: - case CG_BOOL: - 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: - { - unsigned int floatCount = rglCountFloatsInCgType(( CGtype )parameterResource->type ); - rtParameter->setterIndex = setVectorTypeIndex[( containerEntry->flags&CGP_ARRAY ) ? 1 : 0][0][profileIndex][floatCount - 1]; - } - 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: - case CG_HALF3x1: case CG_HALF3x2: case CG_HALF3x3: case CG_HALF3x4: - case CG_HALF4x1: case CG_HALF4x2: case CG_HALF4x3: case CG_HALF4x4: - case CG_INT1x1: case CG_INT1x2: case CG_INT1x3: case CG_INT1x4: - case CG_INT2x1: case CG_INT2x2: case CG_INT2x3: case CG_INT2x4: - case CG_INT3x1: case CG_INT3x2: case CG_INT3x3: case CG_INT3x4: - case CG_INT4x1: case CG_INT4x2: case CG_INT4x3: case CG_INT4x4: - case CG_BOOL1x1: case CG_BOOL1x2: case CG_BOOL1x3: case CG_BOOL1x4: - case CG_BOOL2x1: case CG_BOOL2x2: case CG_BOOL2x3: case CG_BOOL2x4: - case CG_BOOL3x1: case CG_BOOL3x2: case CG_BOOL3x3: case CG_BOOL3x4: - case CG_BOOL4x1: case CG_BOOL4x2: case CG_BOOL4x3: case CG_BOOL4x4: - case CG_FIXED1x1: case CG_FIXED1x2: case CG_FIXED1x3: case CG_FIXED1x4: - 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 = setMatrixTypeIndex[( containerEntry->flags&CGP_ARRAY ) ? 1 : 0][0][profileIndex][rglGetTypeRowCount(( CGtype )parameterResource->type ) - 1][rglGetTypeColCount(( CGtype )parameterResource->type ) - 1][ROW_MAJOR]; - rtParameter->settercIndex = setMatrixTypeIndex[( containerEntry->flags&CGP_ARRAY ) ? 1 : 0][0][profileIndex][rglGetTypeRowCount(( CGtype )parameterResource->type ) - 1][rglGetTypeColCount(( CGtype )parameterResource->type ) - 1][COL_MAJOR]; - break; - // addition to be compatible with cgc 2.0 - case CG_STRING: - break; - default: - break; - } - } - } - else if (( parameterEntry->flags & CGPV_MASK ) == CGPV_VARYING ) - { - if (( parameterEntry->flags & CGPD_MASK ) == CGPD_IN && profileIndex == VERTEX_PROFILE_INDEX ) - { - rtParameter->setterIndex = setAttribConstantIndex; - } - } - } - else - { - if (( parameterEntry->flags & CGPV_MASK ) == CGPV_UNIFORM ) - { - if ( parameterEntry->flags & CGP_ARRAY ) - continue; - - const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); - // we silently ignore valid sets on unused parameters. - switch ( parameterResource->type ) - { - case CG_FLOAT: - case CG_FLOAT1: case CG_FLOAT2: case CG_FLOAT3: case CG_FLOAT4: - 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 = _cgIgnoreParamIndex; - rtParameter->settercIndex = _cgIgnoreParamIndex; - break; - case CG_SAMPLER1D: case CG_SAMPLER2D: case CG_SAMPLER3D: case CG_SAMPLERRECT: case CG_SAMPLERCUBE: - rtParameter->samplerSetter = _cgIgnoreParamIndex; - break; - case CGP_SCF_BOOL: - break; - case CG_HALF: - case CG_HALF1: case CG_HALF2: case CG_HALF3: case CG_HALF4: - case CG_INT: - case CG_INT1: case CG_INT2: case CG_INT3: case CG_INT4: - case CG_BOOL: - 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 = _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: - case CG_HALF3x1: case CG_HALF3x2: case CG_HALF3x3: case CG_HALF3x4: - case CG_HALF4x1: case CG_HALF4x2: case CG_HALF4x3: case CG_HALF4x4: - case CG_INT1x1: case CG_INT1x2: case CG_INT1x3: case CG_INT1x4: - case CG_INT2x1: case CG_INT2x2: case CG_INT2x3: case CG_INT2x4: - case CG_INT3x1: case CG_INT3x2: case CG_INT3x3: case CG_INT3x4: - case CG_INT4x1: case CG_INT4x2: case CG_INT4x3: case CG_INT4x4: - case CG_BOOL1x1: case CG_BOOL1x2: case CG_BOOL1x3: case CG_BOOL1x4: - case CG_BOOL2x1: case CG_BOOL2x2: case CG_BOOL2x3: case CG_BOOL2x4: - case CG_BOOL3x1: case CG_BOOL3x2: case CG_BOOL3x3: case CG_BOOL3x4: - case CG_BOOL4x1: case CG_BOOL4x2: case CG_BOOL4x3: case CG_BOOL4x4: - case CG_FIXED1x1: case CG_FIXED1x2: case CG_FIXED1x3: case CG_FIXED1x4: - 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 = _cgIgnoreParamIndex; - rtParameter->settercIndex = _cgIgnoreParamIndex; - break; - // addition to be compatible with cgc 2.0 - case CG_STRING: - break; - default: - break; - } - } - else if (( parameterEntry->flags & CGPV_MASK ) == CGPV_VARYING ) - { - if (( parameterEntry->flags & CGPD_MASK ) == CGPD_IN && profileIndex == VERTEX_PROFILE_INDEX ) - rtParameter->setterIndex = setAttribConstantIndex; - } - } - arrayCount = 1; - containerEntry = NULL; - } - - //add padding - if (bufferSize) - { - CellGcmContextData gcmContext, *thisContext; - int i, nopCount; - - nopCount = ( program->constantPushBuffer + bufferSize ) - ( unsigned int * )rglGcmCurrent; - gcmContext.current = (uint32_t*)rglGcmCurrent; - thisContext = &gcmContext; - - rglGcmSetNopCommand(thisContext, i, nopCount); - rglGcmCurrent = (typeof(rglGcmCurrent))gcmContext.current; - } -} - -/*============================================================ - PLATFORM BUFFER - ============================================================ */ - -static void rglpsAllocateBuffer (void *data) -{ - rglBufferObject *bufferObject = (rglBufferObject*)data; - rglGcmBufferObject *rglBuffer = (rglGcmBufferObject*)bufferObject->platformBufferObject; - - // free current buffer (if any) - rglDeallocateBuffer(bufferObject, rglBuffer); - - // allocate in GPU memory - rglBuffer->pool = RGLGCM_SURFACE_POOL_LINEAR; - rglBuffer->bufferId = gmmAlloc(rglBuffer->bufferSize); - rglBuffer->pitch = 0; - - if ( rglBuffer->bufferId == GMM_ERROR ) - rglBuffer->pool = RGLGCM_SURFACE_POOL_NONE; - - GLuint referenceCount = bufferObject->textureReferences.count; - - if ( referenceCount > 0 ) - { - for ( GLuint i = 0;i < referenceCount;++i ) - { - rglTexture *texture = (rglTexture*)bufferObject->textureReferences.array[i]; - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - gcmTexture->gpuAddressId = rglBuffer->bufferId; - gcmTexture->gpuAddressIdOffset = texture->offset; - texture->revalidate |= RGL_TEXTURE_REVALIDATE_PARAMETERS; - rglTextureTouchFBOs( texture ); - } - _CurrentContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; - } -} - -GLboolean rglpCreateBufferObject (void *data) -{ - rglBufferObject *bufferObject = (rglBufferObject*)data; - rglGcmBufferObject *rglBuffer = (rglGcmBufferObject*)bufferObject->platformBufferObject; - - rglBuffer->pool = RGLGCM_SURFACE_POOL_NONE; - rglBuffer->bufferId = GMM_ERROR; - rglBuffer->mapCount = 0; - rglBuffer->mapAccess = GL_NONE; - - // allocate initial buffer - rglBuffer->bufferSize = rglPad( bufferObject->size, RGL_BUFFER_OBJECT_BLOCK_SIZE ); - rglpsAllocateBuffer( bufferObject ); - - return rglBuffer->bufferId != GMM_ERROR; -} - -void rglPlatformDestroyBufferObject (void *data) -{ - rglBufferObject *bufferObject = (rglBufferObject*)data; - rglGcmBufferObject *rglBuffer = (rglGcmBufferObject*)bufferObject->platformBufferObject; - rglDeallocateBuffer(bufferObject, rglBuffer); -} - -void rglPlatformBufferObjectSetData(void *buf_data, GLintptr offset, GLsizeiptr size, const GLvoid *data, GLboolean tryImmediateCopy) -{ - rglBufferObject *bufferObject = (rglBufferObject*)buf_data; - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - rglGcmBufferObject *rglBuffer = ( rglGcmBufferObject * )bufferObject->platformBufferObject; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - - if ( size == bufferObject->size && tryImmediateCopy ) - memcpy( gmmIdToAddress( rglBuffer->bufferId ) + offset, data, size ); - else if ( size >= bufferObject->size ) - { - // reallocate the buffer - // To avoid waiting for the GPU to finish with the buffer, just - // allocate a whole new one. - rglBuffer->bufferSize = rglPad( size, RGL_BUFFER_OBJECT_BLOCK_SIZE ); - rglpsAllocateBuffer( bufferObject ); - - // copy directly to newly allocated memory - // TODO: For GPU destination, should we copy to system memory and - // pull from GPU? - memcpy( gmmIdToAddress( rglBuffer->bufferId ), data, size ); - } - else - { - if (tryImmediateCopy) - memcpy( gmmIdToAddress( rglBuffer->bufferId ) + offset, data, size ); - else - { - // partial buffer write - // STREAM and DYNAMIC buffers get transfer via a bounce buffer. - // copy via bounce buffer - // try allocating the whole block in the bounce buffer - const char *dat = (const char*)data; - rglGcmSend(thisContext, rglBuffer->bufferId, offset, rglBuffer->pitch, dat, size ); - } - } -} - - -GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data ) -{ - RGLcontext *LContext = (RGLcontext*)_CurrentContext; - GLuint name = 0; - - switch ( target ) - { - case GL_ARRAY_BUFFER: - name = LContext->ArrayBuffer; - break; - case GL_PIXEL_UNPACK_BUFFER_ARB: - name = LContext->PixelUnpackBuffer; - break; - case GL_TEXTURE_REFERENCE_BUFFER_SCE: - name = LContext->TextureBuffer; - break; - default: - rglSetError( GL_INVALID_ENUM ); - return; - } - - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; - rglPlatformBufferObjectSetData( bufferObject, offset, size, data, GL_FALSE ); -} - - -char *rglPlatformBufferObjectMap (void *data, GLenum access) -{ - rglBufferObject *bufferObject = (rglBufferObject*)data; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - rglGcmBufferObject *rglBuffer = (rglGcmBufferObject*)bufferObject->platformBufferObject; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - GLuint ref; - - if (rglBuffer->mapCount++ == 0) - { - if (access == GL_WRITE_ONLY) - { - // replace entire buffer - // To avoid waiting for the GPU to finish using the buffer, - // just allocate a new one. - rglpsAllocateBuffer( bufferObject ); - if ( rglBuffer->pool == RGLGCM_SURFACE_POOL_NONE ) - { - rglSetError( GL_OUT_OF_MEMORY ); - return NULL; - } - } - else - { - unsigned int offset_bytes = 0; - // must wait in order to read - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFinish(fifo, ref, offset_bytes); - } - - rglBuffer->mapAccess = access; - - // count writable mapped buffers - // If any buffers are left mapped when a draw is invoked, we must - // flush the vertex cache in case VBO data has been modified. - if ( rglBuffer->mapAccess != GL_READ_ONLY ) - { - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - ++driver->flushBufferCount; - } - - // only need to pin the first time we map - gmmPinId( rglBuffer->bufferId ); - } - - return gmmIdToAddress( rglBuffer->bufferId ); -} - -GLboolean rglPlatformBufferObjectUnmap (void *data) -{ - rglBufferObject *bufferObject = (rglBufferObject*)data; - rglGcmBufferObject *rglBuffer = (rglGcmBufferObject*)bufferObject->platformBufferObject; - // can't unmap if not mapped - - if ( --rglBuffer->mapCount == 0 ) - { - // count writable mapped buffers - // If any buffers are left mapped when a draw is invoked, we must - // flush the vertex cache in case VBO data has been modified. - if ( rglBuffer->mapAccess != GL_READ_ONLY ) - { - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - --driver->flushBufferCount; - - // make sure we flush for the next draw - driver->invalidateVertexCache = GL_TRUE; - } - - rglBuffer->mapAccess = GL_NONE; - - gmmUnpinId( rglBuffer->bufferId ); - } - - return GL_TRUE; -} - -#ifdef __cplusplus -extern "C" { -#endif - -GLAPI void APIENTRY glBufferSubDataTextureReferenceRA( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data ) -{ - RGLcontext *LContext = (RGLcontext*)_CurrentContext; - GLuint name = LContext->TextureBuffer; - rglBufferObject* bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[name]; - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - rglGcmBufferObject *rglBuffer = ( rglGcmBufferObject * )bufferObject->platformBufferObject; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - - if ( size >= bufferObject->size ) - { - // reallocate the buffer - // To avoid waiting for the GPU to finish with the buffer, just - // allocate a whole new one. - rglBuffer->bufferSize = rglPad( size, RGL_BUFFER_OBJECT_BLOCK_SIZE ); - rglpsAllocateBuffer( bufferObject ); - - // copy directly to newly allocated memory - // TODO: For GPU destination, should we copy to system memory and - // pull from GPU? - memset( gmmIdToAddress(rglBuffer->bufferId), 0, size ); - } - else - { - // partial buffer write - // STREAM and DYNAMIC buffers get transfer via a bounce buffer. - // copy via bounce buffer - GLuint id = gmmAlloc(size); - memset(gmmIdToAddress(id), 0, size); - rglGcmTransferData(thisContext, rglBuffer->bufferId, offset, rglBuffer->pitch, id, 0, size, size, 1); - gmmFree(id); - } -} - -#ifdef __cplusplus -} -#endif - -/*============================================================ - PLATFORM FRAMEBUFFER - ============================================================ */ -static void rglPlatformValidateTextureResources (void *data); - -GLAPI void APIENTRY glClear( GLbitfield mask ) -{ - unsigned int offset_bytes = 0; - RGLcontext* LContext = _CurrentContext; - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmFifo * fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - - if ( LContext->needValidate & RGL_VALIDATE_FRAMEBUFFER ) - { - // set render targets - - RGLdevice *LDevice = _CurrentDevice; - rglGcmDevice *gcmDevice = ( rglGcmDevice * )LDevice->platformDevice; - - // reset buffer data - driver->rtValid = GL_FALSE; - // get buffer parameters - // This may come from a framebuffer_object or the default framebuffer. - // - driver->rt = gcmDevice->rt; - - if (LContext->framebuffer) - { - rglFramebuffer* framebuffer = (rglFramebuffer *)rglGetFramebuffer(LContext, LContext->framebuffer); - - if (framebuffer->needValidate) - { - framebuffer->complete = (rglPlatformFramebufferCheckStatus(framebuffer) == GL_FRAMEBUFFER_COMPLETE_OES); - - if (!framebuffer->complete) - return; - - GLuint width = CELL_GCM_MAX_RT_DIMENSION; - GLuint height = CELL_GCM_MAX_RT_DIMENSION; - - // color - framebuffer->rt.colorBufferCount = 0; - framebuffer->rt.colorFormat = RGLGCM_NONE; - GLuint defaultPitch = 0; - GLuint defaultId = GMM_ERROR; - GLuint defaultIdOffset = 0; - - for ( int i = 0; i < RGLGCM_SETRENDERTARGET_MAXCOUNT; ++i ) - { - // get the texture and face - rglTexture* colorTexture = NULL; - GLuint face = 0; - rglFramebufferGetAttachmentTexture( LContext, &framebuffer->color[i], &colorTexture, &face ); - - if (colorTexture == NULL) - continue; - - rglGcmTexture* nvTexture = ( rglGcmTexture * )colorTexture->platformTexture; - - // make sure texture is resident in a supported layout - // Some restrictions are added if a texture is used as a - // render target: - // - // - no swizzled semifat or fat formats - // - no swizzled smaller than 16x16 - // - no mipmapped cube maps in tiled memory - // - no cube maps with height not a multiple of 16 in tiled - // memory - // - // We may need to reallocate the texture if any of these - // are true. - // - // TODO: Measure time spent here and optimize if indicated. - if ( !colorTexture->isRenderTarget ) - { - colorTexture->isRenderTarget = GL_TRUE; - colorTexture->revalidate |= RGL_TEXTURE_REVALIDATE_LAYOUT; - } - rglPlatformValidateTextureResources( colorTexture ); - colorTexture->image->dataState = RGL_IMAGE_DATASTATE_GPU; - - // set the render target - framebuffer->rt.colorId[i] = nvTexture->gpuAddressId; - framebuffer->rt.colorIdOffset[i] = nvTexture->gpuAddressIdOffset; - framebuffer->rt.colorPitch[i] = nvTexture->gpuLayout.pitch ? nvTexture->gpuLayout.pitch : nvTexture->gpuLayout.pixelBits * nvTexture->gpuLayout.baseWidth / 8; - - width = MIN( width, nvTexture->gpuLayout.baseWidth ); - height = MIN( height, nvTexture->gpuLayout.baseHeight ); - framebuffer->rt.colorFormat = nvTexture->gpuLayout.internalFormat; - framebuffer->rt.colorBufferCount = i + 1; - defaultId = framebuffer->rt.colorId[i]; - defaultIdOffset = framebuffer->rt.colorIdOffset[i]; - defaultPitch = framebuffer->rt.colorPitch[i]; - } - - // framebuffer dimensions are the intersection of attachments - framebuffer->rt.width = width; - framebuffer->rt.height = height; - - framebuffer->rt.yInverted = false; - framebuffer->rt.xOffset = 0; - framebuffer->rt.yOffset = 0; - framebuffer->needValidate = GL_FALSE; - } - - driver->rt = framebuffer->rt; - } - - driver->rtValid = GL_TRUE; - - // update GPU configuration - rglGcmFifoGlSetRenderTarget( &driver->rt ); - - LContext->needValidate &= ~RGL_VALIDATE_FRAMEBUFFER; - LContext->needValidate |= RGL_VALIDATE_VIEWPORT; - } - - if (!driver->rtValid) - return; - - rglGcmSetClearColor(thisContext, 0 ); - rglGcmSetClearSurface(thisContext, CELL_GCM_CLEAR_R | CELL_GCM_CLEAR_G | - CELL_GCM_CLEAR_B | CELL_GCM_CLEAR_A ); - rglGcmSetInvalidateVertexCache(thisContext); - rglGcmFifoFlush(fifo, offset_bytes); -} - -rglFramebuffer* rglCreateFramebuffer (void) -{ - rglFramebuffer *fb = (rglFramebuffer*)calloc(1, sizeof(rglFramebuffer)); - fb->needValidate = GL_TRUE; - memset(&fb->rt, 0, sizeof(fb->rt)); - - return fb; -} - -void rglDestroyFramebuffer (void *data) -{ - rglFramebuffer *framebuffer = (rglFramebuffer*)data; - - if(framebuffer) - free(framebuffer); -} - -GLenum rglPlatformFramebufferCheckStatus (void *data) -{ - rglFramebuffer *framebuffer = (rglFramebuffer*)data; - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - - GLuint nBuffers = 0; // number of attached buffers - int width = 0; - int height = 0; - GLboolean sizeMismatch = GL_FALSE; - - // record attached images - // We have to verify that no image is attached more than once. The - // array is sized for color attachments plus depth and stencil. - rglImage* image[RGL_MAX_COLOR_ATTACHMENTS + 2] = {0}; - - // test colors - GLuint colorFormat = 0; - for ( int i = 0; i < RGL_MAX_COLOR_ATTACHMENTS; ++i ) - { - rglTexture* colorTexture = NULL; - GLuint colorFace = 0; - rglFramebufferGetAttachmentTexture( - LContext, - &framebuffer->color[i], - &colorTexture, - &colorFace ); - // TODO: Complete texture may not be required. - if (colorTexture != NULL) - { - if (colorTexture->referenceBuffer && !colorTexture->isRenderTarget) - return GL_FRAMEBUFFER_UNSUPPORTED_OES; - - // all attachments must have the same dimensions - image[nBuffers] = colorTexture->image; - if (( width && width != image[nBuffers]->width ) || - ( height && height != image[nBuffers]->height ) ) - sizeMismatch = GL_TRUE; - - width = image[nBuffers]->width; - height = image[nBuffers]->height; - - // all color attachments need the same format - if ( colorFormat && colorFormat != image[nBuffers]->internalFormat ) - return GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES; - - colorFormat = image[nBuffers]->internalFormat; - - ++nBuffers; - } - } - - // at least once attachment is required - if ( nBuffers == 0 ) - return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES; - - // verify no image is attached more than once - // This is an n-squared algorithm - n*log(n) is possible but - // probably not necessary (or even faster). - for ( GLuint i = 0; i < nBuffers; ++i ) - for ( GLuint j = i + 1; j < nBuffers; ++j ) - if ( image[i] == image[j] ) - return GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_OES; - - return GL_FRAMEBUFFER_COMPLETE_OES; -} - -/*============================================================ - PLATFORM RASTER - ============================================================ */ - -#define RGL_ATTRIB_BUFFER_ALIGNMENT 16 - -// maximum size for drawing data -#define RGLGCM_MAX_VERTEX_BUFFER_SIZE (2 << 20) -#define RGLGCM_MAX_INDEX_BUFFER_SIZE (1 << 20) - -void rglDumpFifo (char *name); - -#undef RGLGCM_REMAP_MODES - -const uint32_t c_rounded_size_ofrglDrawParams = (sizeof(rglDrawParams)+0x7f)&~0x7f; -static uint8_t s_dparams_buff[ c_rounded_size_ofrglDrawParams ] __attribute__((aligned(128))); - -static void update_state_validation(void) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - - LContext->needValidate &= RGL_VALIDATE_ALL; - - GLuint needValidate = LContext->needValidate; - - if (RGL_UNLIKELY( needValidate & RGL_VALIDATE_TEXTURES_USED)) - { - long unitInUseCount = LContext->BoundFragmentProgram->samplerCount; - const GLuint* unitsInUse = LContext->BoundFragmentProgram->samplerUnits; - for ( long i = 0; i < unitInUseCount; ++i ) - { - long unit = unitsInUse[i]; - rglTexture* texture = LContext->TextureImageUnits[unit].currentTexture; - - if (!texture) - continue; - - // Validate resources of a texture and set it to a unit - - if (RGL_UNLIKELY( texture->revalidate)) - rglPlatformValidateTextureResources(texture); // this updates the isComplete bit. - - GLboolean isCompleteCache = texture->isComplete; - - if (RGL_LIKELY(isCompleteCache)) - { - // Set a texture to a gcm texture unit - - rglGcmTexture *platformTexture = ( rglGcmTexture * )texture->platformTexture; - platformTexture->gcmTexture.offset = gmmIdToOffset(platformTexture->gpuAddressId) + platformTexture->gpuAddressIdOffset; - - // set up the texture unit with the info for the current texture - // bind texture , control 1,3,format and remap - const CellGcmTexture *texture = (const CellGcmTexture*)&platformTexture->gcmTexture; - - rglGcmSetTextureBorder(thisContext, unit, texture, 0x1); - - CellGcmContextData *gcm_context = (CellGcmContextData*)&rglGcmState_i.fifo; - gcm_emit_at(gcm_context->current, 0, ((((8) << (18)) | ((CELL_GCM_NV4097_SET_TEXTURE_OFFSET) + (unit) * 0x20)))); - gcm_emit_at(gcm_context->current, 1, ((platformTexture->gcmTexture.offset))); - gcm_emit_at(gcm_context->current, 2, (((((platformTexture->gcmTexture.location)) + 1) | (((platformTexture->gcmTexture.cubemap)) << 2) | (((0x01)) << 3) | (((platformTexture->gcmTexture.dimension)) << 4) | (((platformTexture->gcmTexture.format)) << 8) | (((platformTexture->gcmTexture.mipmap)) << 16)))); - gcm_emit_at(gcm_context->current, 3, (((platformTexture->gcmMethods.address.wrapS) | ((0) << 4) | ((platformTexture->gcmMethods.address.wrapT) << 8) | ((platformTexture->gcmMethods.address.unsignedRemap) << 12) | ((platformTexture->gcmMethods.address.wrapR) << 16) | ((platformTexture->gcmMethods.address.gamma) << 20) | ((platformTexture->gcmMethods.address.zfunc) << 28)))); - gcm_emit_at(gcm_context->current, 4, ((((0 << 2) | (platformTexture->gcmMethods.control0.maxAniso) << 4) | ((platformTexture->gcmMethods.control0.maxLOD) << 7) | ((platformTexture->gcmMethods.control0.minLOD) << 19) | ((CELL_GCM_TRUE) << 31)))); - gcm_emit_at(gcm_context->current, 5, (platformTexture->gcmTexture.remap)); - gcm_emit_at(gcm_context->current, 6, ((((platformTexture->gcmMethods.filter.bias & 0x1fff)) | ((platformTexture->gcmMethods.filter.conv) << 13) | ((platformTexture->gcmMethods.filter.min) << 16) | ((platformTexture->gcmMethods.filter.mag) << 24)))); - gcm_emit_at(gcm_context->current, 7, (((platformTexture->gcmTexture.height) | ((platformTexture->gcmTexture.width) << 16)))); - gcm_emit_at(gcm_context->current, 8, ((platformTexture->gcmMethods.borderColor))); - gcm_emit_at(gcm_context->current, 9, ((((1) << (18)) | ((CELL_GCM_NV4097_SET_TEXTURE_CONTROL3) + (unit) * 0x04)))); - gcm_emit_at(gcm_context->current, 10, (((platformTexture->gcmTexture.pitch) | ((platformTexture->gcmTexture.depth) << 20)))); - gcm_finish_n_commands(gcm_context->current, 11); - } - else - { - // Validate incomplete texture by remapping - GLuint 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_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO ); - - rglGcmSetTextureControl(thisContext, unit, CELL_GCM_FALSE, 0, 0, 0 ); // disable control 0 - rglGcmSetTextureRemap(thisContext, unit, remap ); // set texture remap only - } - } - } - - if (RGL_UNLIKELY(needValidate & RGL_VALIDATE_VERTEX_PROGRAM)) - { - const _CGprogram *program = (const _CGprogram*)LContext->BoundVertexProgram; - __dcbt(program->ucode); - __dcbt(((uint8_t*)program->ucode)+128); - __dcbt(((uint8_t*)program->ucode)+256); - __dcbt(((uint8_t*)program->ucode)+384); - - CellCgbVertexProgramConfiguration conf, *conf_ptr; - conf.instructionSlot = program->header.vertexProgram.instructionSlot; - conf.instructionCount = program->header.instructionCount; - conf.registerCount = program->header.vertexProgram.registerCount; - conf.attributeInputMask = program->header.attributeInputMask; - - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - GLuint spaceInWords = 7 + 5 * conf.instructionCount; - - // Push a CG program onto the current command buffer - - // make sure there is space for the pushbuffer + any nops we need to add for alignment - if ( fifo->ctx.current + spaceInWords + 1024 > fifo->ctx.end ) - rglOutOfSpaceCallback( fifo, spaceInWords ); - - conf_ptr = &conf; - rglGcmSetVertexProgramLoad(thisContext, conf_ptr, program->ucode ); - rglGcmSetUserClipPlaneControl(thisContext, 0, 0, 0, 0, 0, 0 ); - - rglGcmInterpolantState *s = &rglGcmState_i.state.interpolant; - s->vertexProgramAttribMask = program->header.vertexProgram.attributeOutputMask; - - rglGcmSetVertexAttribOutputMask(thisContext, (( s->vertexProgramAttribMask) & - s->fragmentProgramAttribMask)); - - int count = program->defaultValuesIndexCount; - for ( int i = 0;i < count;i++ ) - { - const CgParameterEntry *parameterEntry = program->parametersEntries + program->defaultValuesIndices[i].entryIndex; - GLboolean cond = (( parameterEntry->flags & CGPF_REFERENCED ) - && ( parameterEntry->flags & CGPV_MASK ) == CGPV_CONSTANT ); - - if (!cond) - continue; - - const float *value = program->defaultValues + - program->defaultValuesIndices[i].defaultValueIndex; - - const CgParameterResource *parameterResource = rglGetParameterResource( program, parameterEntry ); - - GLboolean cond2 = parameterResource->resource != (uint16_t) - 1; - - if (!cond2) - continue; - - switch ( parameterResource->type ) - { - case CG_FLOAT: - case CG_FLOAT1: - case CG_FLOAT2: - case CG_FLOAT3: - case CG_FLOAT4: - case CG_HALF: - case CG_HALF1: - case CG_HALF2: - case CG_HALF3: - case CG_HALF4: - case CG_INT: - case CG_INT1: - case CG_INT2: - case CG_INT3: - case CG_INT4: - case CG_BOOL: - 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: - rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 1, value ); - break; - case CG_FLOAT4x4: - case CG_HALF4x4: - case CG_INT4x4: - case CG_BOOL4x4: - case CG_FIXED4x4: - // set 4 consts - { - GLfloat v2[16]; - v2[0] = value[0]; - v2[1] = value[4]; - v2[2] = value[8]; - v2[3] = value[12]; - v2[4] = value[1]; - v2[5] = value[5]; - v2[6] = value[9]; - v2[7] = value[13]; - v2[8] = value[2]; - v2[9] = value[6]; - v2[10] = value[10]; - v2[11] = value[14]; - v2[12] = value[3]; - v2[13] = value[7]; - v2[14] = value[11]; - v2[15] = value[15]; - const float*v = v2; - rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 4, v); - } - break; - case CG_FLOAT3x3: - case CG_HALF3x3: - case CG_INT3x3: - case CG_BOOL3x3: - case CG_FIXED3x3: - // set 3 consts - { - GLfloat v2[12]; - v2[0] = value[0]; - v2[1] = value[3]; - v2[2] = value[6]; - v2[3] = 0; - v2[4] = value[1]; - v2[5] = value[4]; - v2[6] = value[7]; - v2[7] = 0; - v2[8] = value[2]; - v2[9] = value[5]; - v2[10] = value[8]; - v2[11] = 0; - const float*v = v2; - rglGcmSetVertexProgramParameterBlock(gCellGcmCurrentContext, parameterResource->resource, 3, v); - } - break; - } - } - - // Set all uniforms. - if(!(LContext->needValidate & RGL_VALIDATE_VERTEX_CONSTANTS) && LContext->BoundVertexProgram->parentContext) - needValidate |= RGL_VALIDATE_VERTEX_CONSTANTS; - } - - if (RGL_LIKELY(needValidate & RGL_VALIDATE_VERTEX_CONSTANTS)) - { - _CGprogram *cgprog = LContext->BoundVertexProgram; - rglGcmFifo *fifo = (rglGcmFifo*)&rglGcmState_i.fifo; - GLuint spaceInWords = cgprog->constantPushBufferWordSize + 4 + 32; - - // Push a CG program onto the current command buffer - - // make sure there is space for the pushbuffer + any nops we need to add for alignment - if ( fifo->ctx.current + spaceInWords + 1024 > fifo->ctx.end ) - rglOutOfSpaceCallback( fifo, spaceInWords ); - - // first add nops to get us the next alligned position in the fifo - // [YLIN] Use VMX register to copy - uint32_t padding_in_word = ( ( 0x10-(((uint32_t)rglGcmState_i.fifo.ctx.current)&0xf))&0xf )>>2; - uint32_t padded_size = ( ((cgprog->constantPushBufferWordSize)<<2) + 0xf )&~0xf; - - unsigned i; - rglGcmSetNopCommand(thisContext, i, padding_in_word ); - memcpy(rglGcmState_i.fifo.ctx.current, cgprog->constantPushBuffer, padded_size); - rglGcmState_i.fifo.ctx.current+=cgprog->constantPushBufferWordSize; - } - - if (RGL_UNLIKELY(needValidate & RGL_VALIDATE_FRAGMENT_PROGRAM)) - { - // Set up the current fragment program on hardware - - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - _CGprogram *program = LContext->BoundFragmentProgram; - - // params are set directly in the GPU memory, so there is nothing to be done here. - CellCgbFragmentProgramConfiguration conf, *conf_ptr; - - conf.offset = gmmIdToOffset(program->loadProgramId) + program->loadProgramOffset; - - rglGcmInterpolantState *s = &rglGcmState_i.state.interpolant; - s->fragmentProgramAttribMask |= program->header.attributeInputMask | CELL_GCM_ATTRIB_OUTPUT_MASK_POINTSIZE; - - conf.attributeInputMask = ( s->vertexProgramAttribMask) & - s->fragmentProgramAttribMask; - - conf.texCoordsInputMask = program->header.fragmentProgram.texcoordInputMask; - conf.texCoords2D = program->header.fragmentProgram.texcoord2d; - conf.texCoordsCentroid = program->header.fragmentProgram.texcoordCentroid; - - int fragmentControl = ( 1 << 15 ) | ( 1 << 10 ); - fragmentControl |= program->header.fragmentProgram.flags & CGF_DEPTHREPLACE ? 0xE : 0x0; - fragmentControl |= program->header.fragmentProgram.flags & CGF_OUTPUTFROMH0 ? 0x00 : 0x40; - fragmentControl |= program->header.fragmentProgram.flags & CGF_PIXELKILL ? 0x80 : 0x00; - - conf.fragmentControl = fragmentControl; - conf.registerCount = program->header.fragmentProgram.registerCount < 2 ? 2 : program->header.fragmentProgram.registerCount; - - conf.fragmentControl &= ~CELL_GCM_MASK_SET_SHADER_CONTROL_CONTROL_TXP; - /* TODO - look into this */ - conf.fragmentControl |= 0 << CELL_GCM_SHIFT_SET_SHADER_CONTROL_CONTROL_TXP; - conf_ptr = &conf; - - rglGcmSetFragmentProgramLoad(thisContext, conf_ptr, CELL_GCM_LOCATION_LOCAL); - - bool cullNearFarEnable = (program->header.fragmentProgram.flags & CGF_DEPTHREPLACE ) ? false : true; - rglGcmSetZMinMaxControl(thisContext, cullNearFarEnable, false, false ); - - driver->fpLoadProgramId = program->loadProgramId; - driver->fpLoadProgramOffset = program->loadProgramOffset; - } - - if ( RGL_LIKELY(( needValidate & ~( RGL_VALIDATE_TEXTURES_USED | - RGL_VALIDATE_VERTEX_PROGRAM | - RGL_VALIDATE_VERTEX_CONSTANTS | - RGL_VALIDATE_FRAGMENT_PROGRAM ) ) == 0 ) ) - { - LContext->needValidate = 0; - return; - } - - if ( RGL_UNLIKELY( needValidate & RGL_VALIDATE_VIEWPORT ) ) - { - rglGcmViewportState *v = &rglGcmState_i.state.viewport; - v->x = LContext->ViewPort.X; - v->y = LContext->ViewPort.Y; - v->w = LContext->ViewPort.XSize; - v->h = LContext->ViewPort.YSize; - - rglGcmFifoGlViewport(v, LContext->DepthNear, LContext->DepthFar); - } - - - if (RGL_UNLIKELY(needValidate & RGL_VALIDATE_BLENDING )) - { - if ((LContext->Blending)) - { - rglGcmSetBlendEnable(gCellGcmCurrentContext, LContext->Blending ); - - 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 ); - rglGcmSetBlendColor(gCellGcmCurrentContext, hwColor, hwColor); - } - - rglGcmSetBlendEquation(gCellGcmCurrentContext, LContext->BlendEquationRGB, LContext->BlendEquationAlpha); - rglGcmSetBlendFunc(gCellGcmCurrentContext, LContext->BlendFactorSrcRGB, LContext->BlendFactorDestRGB, - LContext->BlendFactorSrcAlpha, LContext->BlendFactorDestAlpha); - } - } - - LContext->needValidate = 0; -} - -// Fast rendering path called by several glDraw calls: -// glDrawElements, glDrawRangeElements, glDrawArrays -// Slow rendering calls this function also, though it must also perform various -// memory setup operations first -GLAPI void APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmDriver *driver = (rglGcmDriver*)_CurrentDevice->rasterDriver; - - if (RGL_UNLIKELY(!RGLBIT_GET(LContext->attribs->EnabledMask, RGL_ATTRIB_POSITION_INDEX))) - return; - - uint32_t _tmp_clear_loop = c_rounded_size_ofrglDrawParams>>7; - do{ - --_tmp_clear_loop; - __dcbz(s_dparams_buff+(_tmp_clear_loop<<7)); - }while(_tmp_clear_loop); - - rglDrawParams *dparams = (rglDrawParams *)s_dparams_buff; - dparams->mode = mode; - dparams->firstVertex = first; - dparams->vertexCount = count; - - if (LContext->needValidate) - update_state_validation(); - - GLenum indexType = 0; - uint32_t indexCount = 0; - - rglAttributeState *as = (rglAttributeState*)LContext->attribs; - - // are any enabled attributes on the client-side? - const GLuint clientSideMask = as->EnabledMask & ~as->HasVBOMask; - - if (RGL_UNLIKELY(clientSideMask)) - { - // determine transfer buffer requirements for client-side attributes - for ( int i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i ) - { - if (clientSideMask & (1 << i)) - { - rglAttribute* attrib = as->attrib + i; - const GLuint freq = attrib->frequency; - GLuint count = ( (dparams->firstVertex + dparams->vertexCount) + freq - 1 ) / freq; - - const GLuint numBytes = attrib->clientStride * count; - dparams->attribXferOffset[i] = dparams->xferTotalSize; - dparams->attribXferSize[i] = numBytes; - - const GLuint numBytesPadded = rglPad( numBytes, 128 ); - dparams->xferTotalSize += numBytesPadded; - dparams->attribXferTotalSize += numBytesPadded; - } - else - { - dparams->attribXferOffset[i] = 0; - dparams->attribXferSize[i] = 0; - } - } - } - - if (RGL_UNLIKELY(!driver->rtValid)) - return; - - // check for any writable mapped buffers - if (driver->flushBufferCount) - driver->invalidateVertexCache = GL_TRUE; - - GLuint gpuOffset = GMM_ERROR; - - uint32_t totalXfer = 0; - for ( GLuint i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i ) - totalXfer += dparams->attribXferSize[i]; - - // validates attributes for specified draw paramaters - // gpuOffset is pointer to index buffer - - // allocate upload transfer buffer if necessary - // The higher level bounce buffer allocator is used, which means that - // the buffer will automatically be freed after all RGLGCM calls up to - // the next allocation have finished. - void* xferBuffer = NULL; - GLuint xferId = GMM_ERROR; - GLuint VBOId = GMM_ERROR; - if ( RGL_UNLIKELY( dparams->xferTotalSize ) ) - { - xferId = gmmAlloc(dparams->xferTotalSize); - xferBuffer = gmmIdToAddress(xferId); - } - - // which attributes are known to need updating? - // (due to being dirty or enabled client-side arrays) - unsigned int needsUpdateMask = (as->DirtyMask | (as->EnabledMask & ~as->HasVBOMask)); - - // for any remaining attributes that need updating, do it now. - if(needsUpdateMask) - { - for (GLuint i = 0; i < RGL_MAX_VERTEX_ATTRIBS; ++i) - { - // skip this attribute if not needing update - if (!RGLBIT_GET( needsUpdateMask, i)) - continue; - - rglAttribute* attrib = as->attrib + i; - if ( RGLBIT_GET( as->EnabledMask, i ) ) - { - GLsizei stride = attrib->clientStride; - const GLuint freq = attrib->frequency; - - if ( RGL_UNLIKELY( dparams->attribXferSize[i] ) ) - { - // attribute data is client side, need to transfer - - // don't transfer data that is not going to be used, from 0 to first*stride - GLuint offset = ( dparams->firstVertex / freq ) * stride; - - char *b = (char*)xferBuffer + dparams->attribXferOffset[i]; - memcpy(b + offset, (char*)attrib->clientData + offset, - dparams->attribXferSize[i] - offset); - - // draw directly from bounce buffer - gpuOffset = gmmIdToOffset(xferId) + (b - ( char * )xferBuffer); - - } - else - { - // attribute data in VBO, clientData is offset. - // Look up the memory location of a buffer object (VBO, PBO) - rglBufferObject *bufferObject = (rglBufferObject*)_CurrentContext->bufferObjectNameSpace.data[attrib->arrayBuffer]; - VBOId = ((rglGcmBufferObject *)bufferObject->platformBufferObject)->bufferId; - - gpuOffset = gmmIdToOffset(VBOId) + (( const GLubyte* )attrib->clientData - ( const GLubyte* )NULL ); - } - - rglGcmEnum type = (rglGcmEnum)attrib->clientType; - GLint size = attrib->clientSize; - - if (size == 0) - { - /* Disable */ - stride = 0; - attrib->normalized = 0; - type = RGLGCM_FLOAT; - gpuOffset = 0; - } - - // mapping to native types - uint8_t gcmType = 0; - switch ( type ) - { - case RGLGCM_UNSIGNED_BYTE: - if (attrib->normalized) - gcmType = CELL_GCM_VERTEX_UB; - else - gcmType = CELL_GCM_VERTEX_UB256; - break; - - case RGLGCM_SHORT: - gcmType = attrib->normalized ? CELL_GCM_VERTEX_S1 : CELL_GCM_VERTEX_S32K; - break; - - case RGLGCM_FLOAT: - gcmType = CELL_GCM_VERTEX_F; - break; - - case RGLGCM_HALF_FLOAT: - gcmType = CELL_GCM_VERTEX_SF; - break; - - case RGLGCM_CMP: - size = 1; // required for this format - gcmType = CELL_GCM_VERTEX_CMP; - break; - - default: - break; - } - - rglGcmSetVertexDataArray(thisContext, i, freq, stride, size, gcmType, CELL_GCM_LOCATION_LOCAL, gpuOffset ); - } - else - { - // attribute is disabled - rglGcmSetVertexDataArray(thisContext, i, 0, 0, 0, CELL_GCM_VERTEX_F, CELL_GCM_LOCATION_LOCAL, 0); - rglGcmSetVertexData4f(thisContext, i, attrib->value ); - } - } - driver->invalidateVertexCache = GL_TRUE; - } - as->DirtyMask = 0; // all attributes are now clean - - if ( xferId != GMM_ERROR ) - gmmFree( xferId ); - - if ( driver->invalidateVertexCache ) - { - driver->invalidateVertexCache = GL_FALSE; - rglGcmSetInvalidateVertexCache(thisContext); - } - - rglGcmSetUpdateFragmentProgramParameter(gCellGcmCurrentContext, - gmmIdToOffset( driver->fpLoadProgramId ) + driver->fpLoadProgramOffset, - CELL_GCM_LOCATION_LOCAL); - - uint8_t gcmMode = 0; - - switch (dparams->mode) - { - case RGLGCM_POINTS: - gcmMode = CELL_GCM_PRIMITIVE_POINTS; - break; - case RGLGCM_LINES: - gcmMode = CELL_GCM_PRIMITIVE_LINES; - break; - case RGLGCM_LINE_LOOP: - gcmMode = CELL_GCM_PRIMITIVE_LINE_LOOP; - break; - case RGLGCM_LINE_STRIP: - gcmMode = CELL_GCM_PRIMITIVE_LINE_STRIP; - break; - case RGLGCM_TRIANGLES: - gcmMode = CELL_GCM_PRIMITIVE_TRIANGLES; - break; - case RGLGCM_TRIANGLE_STRIP: - gcmMode = CELL_GCM_PRIMITIVE_TRIANGLE_STRIP; - break; - case RGLGCM_TRIANGLE_FAN: - gcmMode = CELL_GCM_PRIMITIVE_TRIANGLE_FAN; - break; - case RGLGCM_QUADS: - gcmMode = CELL_GCM_PRIMITIVE_QUADS; - break; - case RGLGCM_QUAD_STRIP: - gcmMode = CELL_GCM_PRIMITIVE_QUAD_STRIP; - break; - case RGLGCM_POLYGON: - gcmMode = CELL_GCM_PRIMITIVE_POLYGON; - break; - } - - rglGcmSetDrawArrays(thisContext, gcmMode, dparams->firstVertex, dparams->vertexCount ); -} - -/*============================================================ - PLATFORM TEXTURE - ============================================================ */ - -// Calculate required size in bytes for given texture layout -static GLuint rglGetGcmTextureSize (void *data) -{ - GLuint bytesNeeded, faceAlign, width, height; - rglGcmTextureLayout *layout = (rglGcmTextureLayout*)data; - - bytesNeeded = 0; - faceAlign = layout->pitch ? 1 : 128; - - width = MAX(1U, layout->baseWidth ); - height = MAX(1U, layout->baseHeight ); - - if ( !layout->pitch ) - bytesNeeded += layout->pixelBits * width * height / 8; - else - bytesNeeded += height * layout->pitch; - return rglPad( bytesNeeded, faceAlign ); -} - -// Calculate pitch for a texture -// TransferVid2Vid needs 64byte pitch alignment -#define GET_TEXTURE_PITCH(texture) (rglPad(rglGetPixelSize(texture->image->format, texture->image->type) * texture->image->width, 64)) - -// Create a gcm texture by initializing memory to 0 -void rglPlatformCreateTexture (void *data) -{ - rglTexture *texture = (rglTexture*)data; - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - memset( gcmTexture, 0, sizeof( rglGcmTexture ) ); - gcmTexture->gpuAddressId = GMM_ERROR; -} - - -// Free memory pooled by a GCM texture -static void rglPlatformFreeGcmTexture (void *data) -{ - rglTexture *texture = (rglTexture*)data; - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - - if ( gcmTexture->pool == RGLGCM_SURFACE_POOL_LINEAR) - gmmFree( gcmTexture->gpuAddressId ); - - gcmTexture->gpuAddressId = GMM_ERROR; - gcmTexture->gpuAddressIdOffset = 0; - gcmTexture->gpuSize = 0; -} - -// Destroy a texture by freeing a gcm texture and an associated PBO -void rglPlatformDestroyTexture (void *data) -{ - rglTexture *texture = (rglTexture*)data; - - if (!texture->referenceBuffer) - rglPlatformFreeGcmTexture(texture); - - rglTextureTouchFBOs(texture); -} - -// Drop a texture from the GPU memory by detaching it from a PBO -void rglPlatformDropTexture (void *data) -{ - rglTexture *texture = (rglTexture*)data; - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - - if (gcmTexture->pool != RGLGCM_SURFACE_POOL_NONE) - rglPlatformFreeGcmTexture( texture ); - - gcmTexture->pool = RGLGCM_SURFACE_POOL_NONE; - gcmTexture->gpuAddressId = GMM_ERROR; - gcmTexture->gpuAddressIdOffset = 0; - gcmTexture->gpuSize = 0; - texture->revalidate |= RGL_TEXTURE_REVALIDATE_IMAGES; - rglTextureTouchFBOs( texture ); -} - -// Validate texture resources -static void rglPlatformValidateTextureResources (void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglTexture *texture = (rglTexture*)data; - texture->isComplete = GL_TRUE; - - // We may need to reallocate the texture when the parameters are changed - // from non-mipmap to mipmap filtering, even though the images have not - // changed. - // - // NOTE: If we ever support accessing mipmaps from a PBO, this code - // must be changed. As it is, if the texture has a shared PBO and the - // mipmap flag then the slow path (copy back to host) is invoked. - if ( texture->revalidate & RGL_TEXTURE_REVALIDATE_IMAGES || texture->revalidate & RGL_TEXTURE_REVALIDATE_LAYOUT ) - { - // upload images - // 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; - - const rglGcmTextureLayout currentLayout = gcmTexture->gpuLayout; - const GLuint currentSize = gcmTexture->gpuSize; - - rglGcmTextureLayout newLayout; - - // get layout and size compatible with this pool - rglImage *image = (rglImage*)texture->image; - - newLayout.levels = 1; - newLayout.faces = 1; - newLayout.baseWidth = image->width; - newLayout.baseHeight = image->height; - newLayout.baseDepth = 1; - 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(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; - - // host texture requires sync - - // create surface descriptors for image transfer - rglGcmSurface src = { -source: RGLGCM_SURFACE_SOURCE_TEMPORARY, - width: 0, // replaced per image - height: 0, // replaced per image - bpp: pixelBytes, - pitch: 0, // replaced per image - format: layout->internalFormat, - pool: RGLGCM_SURFACE_POOL_LINEAR, // via bounce buffer - dataId: GMM_ERROR, - dataIdOffset:0, - }; - - rglGcmSurface dst = { -source: RGLGCM_SURFACE_SOURCE_TEXTURE, - width: 0, // replaced per image - height: 0, // replaced per image - bpp: pixelBytes, - pitch: layout->pitch, - format: layout->internalFormat, - pool: gcmTexture->pool, - dataId: GMM_ERROR, - dataIdOffset:0, - }; - - // use a bounce buffer to transfer to GPU - GLuint bounceBufferId = GMM_ERROR; - - if ( image->dataState == RGL_IMAGE_DATASTATE_HOST ) - { - bounceBufferId = gmmAlloc(gcmTexture->gpuSize); - - if ( bounceBufferId != GMM_ERROR ) - { - // copy image to bounce buffer - src.dataId = bounceBufferId; - src.dataIdOffset = 0; - - // NPOT DXT - memcpy( gmmIdToAddress( src.dataId ), image->data, image->storageSize ); - } - - // use surface copy functions - src.width = image->width; - src.height = image->height; - src.pitch = pixelBytes * src.width; - - dst.width = src.width; - dst.height = image->height; - dst.dataId = gcmTexture->gpuAddressId; - dst.dataIdOffset = gcmTexture->gpuAddressIdOffset; - - GLuint width = src.width; - GLuint height = src.height; - const GLuint srcPitch = src.pitch ? src.pitch : src.bpp * src.width; - const GLuint dstPitch = dst.pitch ? dst.pitch : dst.bpp * dst.width; - - bool bpp_1_transferdata = src.bpp == 1 && - (!(( width % 2 ) == 0 )); - - if (( srcPitch >= 0x10000 ) || ( dstPitch >= 0x10000 ) || bpp_1_transferdata ) - { - rglGcmTransferData(thisContext, dst.dataId, dst.dataIdOffset, dstPitch, - src.dataId, src.dataIdOffset, srcPitch, - width * src.bpp, height ); - } - else - { - switch ( src.bpp ) - { - case 1: - width /= 2; - src.bpp = 2; - break; - case 8: - case 16: - src.bpp /= 4; - width *= 4; - break; - } - - rglGcmSetTransferImage(thisContext, CELL_GCM_TRANSFER_LOCAL_TO_LOCAL, gmmIdToOffset(dst.dataId) + dst.dataIdOffset, dstPitch, 0, 0, gmmIdToOffset(src.dataId) + src.dataIdOffset, srcPitch, 0, 0, width, height, src.bpp); - } - - // free CPU copy of data - rglImageFreeCPUStorage( image ); - image->dataState |= RGL_IMAGE_DATASTATE_GPU; - } // newer data on host - - if ( bounceBufferId != GMM_ERROR ) - gmmFree( bounceBufferId ); - - rglGcmSetInvalidateTextureCache(thisContext, CELL_GCM_INVALIDATE_TEXTURE ); - } - - // gcmTexture method command - // map RGL internal types to GCM - rglGcmTexture *platformTexture = ( rglGcmTexture * )texture->platformTexture; - rglGcmTextureLayout *layout = &platformTexture->gpuLayout; - - // XXX make sure that REVALIDATE_PARAMETERS is set if the format of the texture changes - // revalidate the texture registers cache just to ensure we are in the correct filtering mode - // based on the internal format. - - // ----------------------------------------------------------------------- - // map the SET_TEXTURE_FILTER method. - platformTexture->gcmMethods.filter.min = rglGcmMapMinTextureFilter(texture->minFilter); - platformTexture->gcmMethods.filter.mag = (texture->magFilter == GL_NEAREST) - ? CELL_GCM_TEXTURE_NEAREST : CELL_GCM_TEXTURE_LINEAR; - platformTexture->gcmMethods.filter.conv = CELL_GCM_TEXTURE_CONVOLUTION_QUINCUNX; - // We don't actually expose this, but still need to set it up properly incase we expose this later - // hw expects a 5.8 twos-complement fixed-point // XXX what is the - .26f ? - platformTexture->gcmMethods.filter.bias = ( GLint )(( texture->lodBias - .26f ) * 256.0f ); - - // ----------------------------------------------------------------------- - // set the SET_TEXTURE_CONTROL0 params - platformTexture->gcmMethods.control0.maxAniso = CELL_GCM_TEXTURE_MAX_ANISO_1; - const GLfloat minLOD = MAX( texture->minLod, 0); - const GLfloat maxLOD = MIN( texture->maxLod, 0 ); - platformTexture->gcmMethods.control0.minLOD = ( GLuint )( MAX( minLOD, 0 ) * 256.0f ); - platformTexture->gcmMethods.control0.maxLOD = ( GLuint )( MIN( maxLOD, 1 ) * 256.0f ); - - // ----------------------------------------------------------------------- - // set the SET_TEXTURE_ADDRESS method params. - platformTexture->gcmMethods.address.wrapS = rglGcmMapWrapMode( texture->wrapS ); - platformTexture->gcmMethods.address.wrapT = rglGcmMapWrapMode( texture->wrapT ); - platformTexture->gcmMethods.address.wrapR = rglGcmMapWrapMode( texture->wrapR ); - platformTexture->gcmMethods.address.unsignedRemap = CELL_GCM_TEXTURE_UNSIGNED_REMAP_NORMAL; - platformTexture->gcmMethods.address.gamma = 0; - - // set border colors - RGLGCM_CALC_COLOR_LE_ARGB8(&(platformTexture->gcmMethods.borderColor), - texture->borderColor.R, texture->borderColor.G, texture->borderColor.B, texture->borderColor.A); - - // ----------------------------------------------------------------------- - // setup the GcmTexture - // format, control1, control3, imagerect; setup for cellGcmSetTexture later - - // map RGL internal types to GCM - // use color format for depth with no compare mode - // This hack is needed because the hardware will not read depth - // textures without performing a compare. The depth value will need to - // be reconstructed in the shader from the color components. - GLuint internalFormat = layout->internalFormat; - - // set the format and remap( control 1) - uint8_t *gcmFormat = (uint8_t*)&platformTexture->gcmTexture.format; - uint32_t *remap = (uint32_t*)&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; -#endif - 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; -#if 0 - 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) - platformTexture->gcmTexture.format += 0x20; // see class doc definitions for SZ_NR vs LN_NR... - - platformTexture->gcmTexture.width = layout->baseWidth; - platformTexture->gcmTexture.height = layout->baseHeight; - platformTexture->gcmTexture.depth = 1; - platformTexture->gcmTexture.pitch = layout->pitch; - platformTexture->gcmTexture.mipmap = 1; - platformTexture->gcmTexture.cubemap = CELL_GCM_FALSE; - platformTexture->gcmTexture.dimension = CELL_GCM_TEXTURE_DIMENSION_2; - platformTexture->gcmTexture.location = CELL_GCM_LOCATION_LOCAL; - - texture->revalidate = 0; -} - -// Choose internal storage type and size, and set it to image, based on given format -GLenum rglPlatformChooseInternalStorage (void *data, GLenum internalFormat ) -{ - GLenum *format, *type; - rglImage *image = (rglImage*)data; - - // see note at bottom concerning storageSize - image->storageSize = 0; - - format = (GLenum*)&image->format; - type = (GLenum*)&image->type; - - // Choose internal format closest to given format - // and extract right format, type - - switch (internalFormat) - { - case GL_ALPHA12: - case GL_ALPHA16: - internalFormat = RGLGCM_ALPHA16; - *format = GL_ALPHA; - *type = GL_UNSIGNED_SHORT; - break; - case GL_ALPHA: - case GL_ALPHA4: - internalFormat = RGLGCM_ALPHA8; - *format = GL_ALPHA; - *type = GL_UNSIGNED_BYTE; - break; - case GL_R3_G3_B2: - case GL_RGB4: - case GL_RGB: - case GL_RGB8: - case RGLGCM_RGBX8: - internalFormat = RGLGCM_RGBX8; - *format = GL_RGBA; - *type = GL_UNSIGNED_INT_8_8_8_8; - break; - case GL_RGBA2: - case GL_RGBA4: - case GL_RGBA8: - case GL_RGBA: - internalFormat = RGLGCM_RGBA8; - *format = GL_RGBA; - *type = GL_UNSIGNED_INT_8_8_8_8; - break; - case GL_RGB5_A1: - internalFormat = RGLGCM_RGB5_A1_SCE; - *format = GL_RGBA; - *type = GL_UNSIGNED_SHORT_1_5_5_5_REV; - break; - case GL_RGB5: - internalFormat = RGLGCM_RGB565_SCE; - *format = GL_RGB; - *type = GL_UNSIGNED_SHORT_5_6_5_REV; - break; - case GL_BGRA: - case RGLGCM_BGRA8: - internalFormat = RGLGCM_BGRA8; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8; - break; - case GL_ARGB_SCE: - internalFormat = RGLGCM_ARGB8; - *format = GL_BGRA; - *type = GL_UNSIGNED_INT_8_8_8_8_REV; - break; - case GL_RGBA32F_ARB: - default: - return GL_INVALID_ENUM; - } - - image->internalFormat = internalFormat; - - // Note that it is critical to get the storageSize value correct because - // this member is used to configure texture loads and unloads. If this - // value is wrong (e.g. contains unnecessary padding) it will corrupt - // the GPU memory layout. - image->storageSize = rglGetPixelSize(image->format, image->type) * image->width * image->height; - - return GL_NO_ERROR; -} - -GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, - GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset ) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - rglImage *image; - - rglTexture *texture = (rglTexture*)rglGetCurrentTexture( LContext->CurrentImageUnit, target ); - rglBufferObject *bufferObject = (rglBufferObject*)LContext->bufferObjectNameSpace.data[LContext->TextureBuffer]; - rglReallocateImages( texture, 0, MAX(baseWidth, baseHeight)); - - image = texture->image; - - image->width = baseWidth; - image->height = baseHeight; - image->depth = 1; - image->alignment = LContext->unpackAlignment; - image->xblk = 0; - image->yblk = 0; - image->xstride = 0; - image->ystride = 0; - image->zstride = 0; - image->format = 0; - image->type = 0; - image->internalFormat = 0; - - const GLenum status = rglPlatformChooseInternalStorage( image, internalFormat ); - (( void )status ); - - image->data = NULL; - image->mallocData = NULL; - image->mallocStorageSize = 0; - image->isSet = GL_TRUE; - image->xstride = rglGetPixelSize( image->format, image->type ); - image->ystride = image->width * image->xstride; - image->zstride = image->height * image->ystride; - image->dataState = RGL_IMAGE_DATASTATE_UNSET; - - texture->maxLevel = 0; - texture->usage = GL_TEXTURE_LINEAR_GPU_SCE; - - // Implementation of texture reference - // Associate bufferObject to texture by assigning buffer's gpu address to the gcm texture - rglGcmTexture *gcmTexture = ( rglGcmTexture * )texture->platformTexture; - - // XXX check pitch restrictions ? - - rglGcmTextureLayout newLayout; - - newLayout.levels = 1; - newLayout.faces = 1; - newLayout.baseWidth = image->width; - newLayout.baseHeight = image->height; - newLayout.baseDepth = 1; - newLayout.internalFormat = ( rglGcmEnum )image->internalFormat; - newLayout.pixelBits = rglPlatformGetBitsPerPixel( newLayout.internalFormat ); - newLayout.pitch = pitch ? pitch : GET_TEXTURE_PITCH(texture); - - texture->isRenderTarget = GL_FALSE; - - if ( gcmTexture->gpuAddressId != GMM_ERROR ) - rglPlatformDestroyTexture( texture ); - - rglGcmBufferObject *gcmBuffer = (rglGcmBufferObject*)&bufferObject->platformBufferObject; - - gcmTexture->gpuLayout = newLayout; - gcmTexture->pool = gcmBuffer->pool; - gcmTexture->gpuAddressId = gcmBuffer->bufferId; - gcmTexture->gpuAddressIdOffset = offset; - gcmTexture->gpuSize = rglGetGcmTextureSize( &newLayout ); - - texture->revalidate &= ~(RGL_TEXTURE_REVALIDATE_LAYOUT | RGL_TEXTURE_REVALIDATE_IMAGES); - texture->revalidate |= RGL_TEXTURE_REVALIDATE_PARAMETERS; - rglTextureTouchFBOs( texture ); - - uint32_t newCapacity = bufferObject->textureReferences.count + 1; - - if (newCapacity > bufferObject->textureReferences.capacity) - { - if ( newCapacity > bufferObject->textureReferences.capacity ) - newCapacity = ( newCapacity > bufferObject->textureReferences.capacity + bufferObject->textureReferences.increment ) ? newCapacity : ( bufferObject->textureReferences.capacity + bufferObject->textureReferences.increment ); - - bufferObject->textureReferences.array = (rglTexture**)realloc((void *)(bufferObject->textureReferences.array), sizeof(rglTexture) * newCapacity); - bufferObject->textureReferences.capacity = newCapacity; - } - new((void *)(bufferObject->textureReferences.array + bufferObject->textureReferences.count))rglTexture((const rglTexture&)texture); - ++bufferObject->textureReferences.count; - - texture->referenceBuffer = bufferObject; - texture->offset = offset; - rglTextureTouchFBOs( texture ); - LContext->needValidate |= RGL_VALIDATE_TEXTURES_USED; -} - -// Set current render target to args -void rglGcmFifoGlSetRenderTarget (const void *data) -{ - CellGcmContextData *thisContext = (CellGcmContextData*)gCellGcmCurrentContext; - rglGcmRenderTarget *rt = (rglGcmRenderTarget*)&rglGcmState_i.renderTarget; - CellGcmSurface *grt = (CellGcmSurface*)&rglGcmState_i.renderTarget.gcmRenderTarget; - const rglGcmRenderTargetEx *args = (const rglGcmRenderTargetEx*)data; - - // GlSetRenderTarget implementation starts here - - // Render target rt's color and depth buffer parameters are updated with args - // Fifo functions are called as required - rt->colorBufferCount = args->colorBufferCount; - - // remember rt for swap and clip related functions - GLuint oldHeight; - GLuint oldyInverted; - - oldyInverted = rt->yInverted; - oldHeight = rt->gcmRenderTarget.height; - - if ( rt->colorFormat != ( GLuint )args->colorFormat ) - { - // ARGB8 and FP16 interpret some registers differently - rglGcmBlendState *blend = &rglGcmState_i.state.blend; - GLuint hwColor; - - rt->colorFormat = args->colorFormat; - - if (rglGcmState_i.renderTarget.colorFormat == RGLGCM_ARGB8) - { - RGLGCM_CALC_COLOR_LE_ARGB8( &hwColor, blend->r, blend->g, blend->b, blend->a ); - rglGcmSetBlendColor(gCellGcmCurrentContext, hwColor, hwColor); - } - } - - GLuint i = 0; - - for ( i = 0; i < args->colorBufferCount; i++ ) - { - // choose context based on top bit of offset - if ( args->colorPitch[i] == 0 ) - { - grt->colorOffset[i] = 0; - grt->colorPitch[i] = 0x200; - grt->colorLocation[i] = CELL_GCM_LOCATION_LOCAL; - } - else - { - if ( args->colorId[i] != GMM_ERROR ) - { - grt->colorLocation[i] = CELL_GCM_LOCATION_LOCAL; - grt->colorOffset[i] = gmmIdToOffset(args->colorId[i]) + args->colorIdOffset[i]; - grt->colorPitch[i] = args->colorPitch[i]; - } - } - } - - // fill in the other render targets that haven't been set - for ( ; i < RGLGCM_SETRENDERTARGET_MAXCOUNT; i++ ) - { - grt->colorOffset[i] = grt->colorOffset[0]; - grt->colorPitch[i] = grt->colorPitch[0]; - grt->colorLocation[i] = grt->colorLocation[0]; - } - - rt->yInverted = args->yInverted; - grt->x = args->xOffset; - grt->y = args->yOffset; - grt->width = args->width; - grt->height = args->height; - - // scissor enabled/viewport and height changed ? obey yInverted - if (( grt->height != oldHeight ) | ( rt->yInverted != oldyInverted ) ) - { - rglGcmViewportState *v = &rglGcmState_i.state.viewport; - rglGcmFifoGlViewport(v, 0.0f, 1.0f); - } - - // Update rt's color and depth format with args - // set the color format - switch ( args->colorFormat ) - { - case RGLGCM_NONE: - case RGLGCM_ARGB8: - // choose a fake format - // but choose a 16-bit format if depth is 16-bit - grt->colorFormat = CELL_GCM_SURFACE_A8R8G8B8; - break; - case RGLGCM_FLOAT_R32: - grt->colorFormat = CELL_GCM_SURFACE_F_X32; - break; - default: - break; - } - - // set the depth format - // choose a fake format - grt->depthFormat = CELL_GCM_SURFACE_Z24S8; - grt->depthLocation = CELL_GCM_LOCATION_LOCAL; - grt->depthOffset = 0; - grt->depthPitch = 64; - - // Update rt's Swizzling parameters with args - - grt->type = CELL_GCM_SURFACE_PITCH; - - // Update rt's color targets - switch ( rt->colorBufferCount ) - { - case 0: - grt->colorTarget = CELL_GCM_SURFACE_TARGET_NONE; - break; - case 1: - grt->colorTarget = CELL_GCM_SURFACE_TARGET_1; - break; - case 2: - grt->colorTarget = CELL_GCM_SURFACE_TARGET_MRT1; - break; - case 3: - grt->colorTarget = CELL_GCM_SURFACE_TARGET_MRT2; - break; - case 4: - grt->colorTarget = CELL_GCM_SURFACE_TARGET_MRT3; - break; - } - - // ensure if either width or height is 1 the other is one as well - if (grt->width == 1) - grt->height = 1; - else if (grt->height == 1) - grt->width = 1; - - uint32_t log2Width = 31 - ({__asm__("cntlzw %0,%1" : "=r" (log2Width) : "r" (grt->width)); log2Width;}); - uint32_t log2Height = 31 - ({__asm__("cntlzw %0,%1" : "=r" (log2Height) : "r" (grt->height)); log2Height;}); - rglGcmSetSurface(thisContext, grt, CELL_GCM_WINDOW_ORIGIN_BOTTOM, CELL_GCM_WINDOW_PIXEL_CENTER_HALF, log2Width, log2Height); -} - -GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ) -{ - RGLcontext* LContext = (RGLcontext*)_CurrentContext; - - switch (pname) - { - case GL_PACK_ALIGNMENT: - LContext->packAlignment = param; - break; - case GL_UNPACK_ALIGNMENT: - LContext->unpackAlignment = param; - break; - } -} - -GLAPI void APIENTRY glGenerateMipmapOES(GLenum target) -{ - (void)target; - /* stub */ -}