(RGL PS3) Cleanups - we don't need string/enum reporting

This commit is contained in:
twinaphex 2013-03-29 18:58:29 +01:00
parent 292bc36b43
commit 76ddce84a3
9 changed files with 123 additions and 390 deletions

View File

@ -21,8 +21,6 @@ INCDIRS = -I. -Ips3/rgl/include
RGL_DIR = ps3/rgl/src
PPU_SRCS = $(RGL_DIR)/Utils/NameSpace.cpp \
$(RGL_DIR)/Utils/TexNameSpace.cpp \
$(RGL_DIR)/Utils/EnumMap.cpp \
$(RGL_DIR)/libelf/readelf.cpp \
$(RGL_DIR)/ps3/rgl_ps3_raster.cpp \
$(RGL_DIR)/ps3/rgl_ps3.cpp

View File

@ -1212,8 +1212,10 @@ bool gl_cg_init(const char *path)
RARCH_ERR("Invalid profile type\n");
return false;
}
#ifndef HAVE_RGL
RARCH_LOG("[Cg]: Vertex profile: %s\n", cgGetProfileString(cgVProf));
RARCH_LOG("[Cg]: Fragment profile: %s\n", cgGetProfileString(cgFProf));
#endif
cgGLSetOptimalOptions(cgFProf);
cgGLSetOptimalOptions(cgVProf);
cgGLEnableProfile(cgFProf);

View File

@ -275,7 +275,7 @@ 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 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;

View File

@ -1,29 +0,0 @@
#ifndef _RGL_REPORT_INTERNAL_H
#define _RGL_REPORT_INTERNAL_H
#include "../export/RGL/rgl.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
GLenum e;
const char *s;
} RGLenumMap;
const char *rglMapLookupEnum(const void *data, unsigned int count, GLenum e);
GLenum rglMapLookupString(const void *data, unsigned int count, const char *s);
#define _RGL_MAP_LOOKUP_ENUM(MAP,ENUM) rglMapLookupEnum(MAP,sizeof(MAP)/sizeof(MAP[0]),ENUM)
#define _RGL_MAP_LOOKUP_STRING(MAP,STRING) rglMapLookupString(MAP,sizeof(MAP)/sizeof(MAP[0]),STRING)
const char *rglGetGLEnumName(GLenum e);
const char *rglGetGLErrorName(GLenum e);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -4,7 +4,6 @@
#include "../export/RGL/rgl.h"
#include "Types.h"
#include "Utils.h"
#include "ReportInternal.h"
#ifndef OS_VERSION_NUMERIC
#define OS_VERSION_NUMERIC 0x160

View File

@ -1,27 +0,0 @@
#include "../../include/export/RGL/rgl.h"
#include "../../include/RGL/private.h"
#include <string.h>
const char *rglMapLookupEnum(const void *data, unsigned int count, GLenum e )
{
const RGLenumMap *map = (const RGLenumMap*)data;
for (GLuint i = 0; i < count; ++i)
if (map[i].e == e)
return map[i].s;
return NULL;
}
GLenum rglMapLookupString(const void *data, unsigned int count, const char *s )
{
const RGLenumMap *map = (const RGLenumMap*)data;
if (s != NULL)
for (GLuint i = 0;i < count;++i)
if ( strcmp( map[i].s, s) == 0)
return map[i].e;
return -1U;
}

View File

@ -5,6 +5,9 @@
#include <string.h>
#define NAME_INCREMENT 4
#define CAPACITY_INCREMENT 16
void rglInitNameSpace(void *data)
{
rglNameSpace *name = (rglNameSpace*)data;
@ -25,8 +28,6 @@ void rglFreeNameSpace(void *data)
name->firstFree = NULL;
}
static const int NAME_INCREMENT = 4;
unsigned int rglCreateName(void *data, void* object)
{
rglNameSpace *name = (rglNameSpace*)data;
@ -79,7 +80,7 @@ unsigned int rglCreateName(void *data, void* object)
unsigned int rglIsName (void *data, unsigned int name )
{
rglNameSpace *ns = (rglNameSpace*)data;
// there should always be a namesepace
// there should always be a namespace
// 0 is never valid.
if (RGL_UNLIKELY(name == 0))
return 0;
@ -114,3 +115,117 @@ void rglEraseName(void *data, unsigned int name )
ns->firstFree = ns->data + name;
}
}
// Initialize texture namespace ns with creation and destruction functions
void rglTexNameSpaceInit(void *data, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy)
{
rglTexNameSpace *ns = (rglTexNameSpace*)data;
ns->capacity = CAPACITY_INCREMENT;
ns->data = (void **)malloc( ns->capacity * sizeof( void* ) );
memset( ns->data, 0, ns->capacity*sizeof( void* ) );
ns->create = create;
ns->destroy = destroy;
}
// Free texture namespace ns
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
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 );
else return GL_FALSE;
}
// Generate new n names in namespace ns
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;
}
}

View File

@ -1,121 +0,0 @@
#include <string.h>
#include "../../include/export/RGL/rgl.h"
#include "../../include/RGL/Types.h"
#include "../../include/RGL/Utils.h"
#include "../../include/RGL/private.h"
static const unsigned int capacityIncr = 16;
// Initialize texture namespace ns with creation and destruction functions
void rglTexNameSpaceInit(void *data, rglTexNameSpaceCreateFunction create, rglTexNameSpaceDestroyFunction destroy)
{
rglTexNameSpace *ns = (rglTexNameSpace*)data;
ns->capacity = capacityIncr;
ns->data = (void **)malloc( ns->capacity * sizeof( void* ) );
memset( ns->data, 0, ns->capacity*sizeof( void* ) );
ns->create = create;
ns->destroy = destroy;
}
// Free texture namespace ns
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
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 + capacityIncr ? name + 1 : ns->capacity + capacityIncr;
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 );
else return GL_FALSE;
}
// Generate new n names in namespace ns
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;
}
}

View File

@ -1709,53 +1709,6 @@ static const RGLcgTypeMapType RGLcgTypeMap[] =
{ CGtype( 0 ), "", CG_PARAMETERCLASS_UNKNOWN }
};
static const RGLenumMap RGLcgResourceMap[] =
{
#define CG_BINDLOCATION_MACRO(name,enum_name,compiler_name,enum_int,addressable,param_type) \
{ enum_name, compiler_name },
#include <Cg/cg_bindlocations.h>
{ CG_UNDEFINED, "undefined" },
{ 0, "" }
};
static const RGLenumMap RGLcgEnumMap[] =
{
#define CG_ENUM_MACRO(enum_name, enum_val) \
{ enum_val, #enum_name },
#include <Cg/cg_enums.h>
{ 0, "" }
};
static const RGLcgProfileMapType RGLcgProfileMap[] =
{
{( CGprofile )6144, "CG_PROFILE_START", 1 },
{( CGprofile )6145, "unknown", 1 },
#define CG_PROFILE_MACRO(name, compiler_id, compiler_id_caps, compiler_opt,int_id,vertex_profile) \
{CG_PROFILE_ ## compiler_id_caps, compiler_opt, vertex_profile},
//#include <Cg/cgRGL_profiles.h>
#include <Cg/cg_profiles.h>
{( CGprofile )0, "", 0 }
};
static const RGLenumMap RGLcgErrorMap[] =
{
#define CG_ERROR_MACRO(code, enum_name, message) \
{ enum_name, message },
#include <Cg/cg_errors.h>
{ 0, "" }
};
// templated map lookup functions ---------
@ -1858,75 +1811,9 @@ CG_API CGbool cgIsInterfaceType( CGtype type )
return CG_FALSE;
}
// Resource Functions -----------------------
CG_API const char* cgGetResourceString( CGresource resource )
{
return _RGL_MAP_LOOKUP_ENUM( RGLcgResourceMap, resource );
}
CG_API CGresource cgGetResource( const char* resource_string )
{
GLenum r = _RGL_MAP_LOOKUP_STRING( RGLcgResourceMap, resource_string );
return ( r == -1U ) ? CG_UNDEFINED : ( CGresource )r;
}
// Enum Functions ----------------------------
CG_API const char* cgGetEnumString( CGenum en )
{
return _RGL_MAP_LOOKUP_ENUM( RGLcgEnumMap, en );
}
CG_API CGenum cgGetEnum( const char* enum_string )
{
if ( !enum_string ) { rglCgRaiseError( CG_INVALID_PARAMETER_ERROR ); return CG_UNKNOWN; }
GLenum r = _RGL_MAP_LOOKUP_STRING( RGLcgEnumMap, enum_string );
return ( r == -1U ) ? CG_UNKNOWN : ( CGenum )r;
}
// Profile functions -------------------------
// profiles are the only tokens not stored in a RGLenumMap. Instead
// they use a RGLcgProfileMap which contains extra information about
// whether the profile is a vertex or a fragment program.
CG_API const char* cgGetProfileString( CGprofile profile )
{
const size_t arraysize = sizeof( RGLcgProfileMap ) / sizeof( RGLcgProfileMapType );
unsigned int i = 0;
while ( i < arraysize )
{
if ( profile == RGLcgProfileMap[i].id )
{
// id found.
return RGLcgProfileMap[i].string;
}
++i;
}
// id not found, return an empty string
return "";
}
CG_API CGprofile cgGetProfile( const char* profile_string )
{
size_t arraysize = sizeof( RGLcgProfileMap ) / sizeof( RGLcgProfileMapType );
unsigned int i = 0;
while ( i < arraysize )
{
if (strcmp( RGLcgProfileMap[i].string, profile_string) == 0)
return RGLcgProfileMap[i].id; // string found.
++i;
}
// string not found, return fail code.
return CG_PROFILE_UNKNOWN;
}
// ErrorFunctions ----------------------------
CG_API CGerror cgGetError( void )
{
@ -1937,16 +1824,7 @@ CG_API CGerror cgGetError( void )
CG_API const char* cgGetErrorString( CGerror error )
{
return _RGL_MAP_LOOKUP_ENUM( RGLcgErrorMap, error );
}
CG_API const char* cgGetLastErrorString( CGerror* error )
{
// return both the error id and string.
*error = _CurrentContext->RGLcgLastError;
_CurrentContext->RGLcgLastError = CG_NO_ERROR;
const char * result = _RGL_MAP_LOOKUP_ENUM( RGLcgErrorMap, *error );
return result;
return "cgGetErrorString not implemented.\n";
}
CG_API void cgSetErrorCallback( CGerrorCallbackFunc func )
@ -1976,31 +1854,6 @@ CG_API const char* cgGetString( CGenum sname )
return NULL;
}
CG_API CGdomain cgGetProfileDomain( CGprofile profile )
{
const size_t arraysize = sizeof( RGLcgProfileMap ) / sizeof( RGLcgProfileMapType );
unsigned int i = 0;
while ( i < arraysize )
{
if ( profile == RGLcgProfileMap[i].id )
{
// id found, check whether this is a vertex or fragment program
if ( RGLcgProfileMap[i].is_vertex_program )
return CG_VERTEX_DOMAIN;
else
return CG_FRAGMENT_DOMAIN;
}
++i;
}
// id not found, return an unknown domain
rglCgRaiseError( CG_UNKNOWN_PROFILE_ERROR );
return CG_UNKNOWN_DOMAIN;
}
CG_API CGparameterclass cgGetTypeClass( CGtype type )
{
const RGLcgTypeMapType *ptr = rglLookupEnum( RGLcgTypeMap, type );
@ -3717,7 +3570,7 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx,
{
if ( _cgRTCgcCompileProgramHook )
{
_cgRTCgcCompileProgramHook( program, cgGetProfileString( profile ), entry, args, &compiled_program );
_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 );
@ -4292,63 +4145,6 @@ CG_API CGbool cgIsProgramCompiled( CGprogram program )
return CG_TRUE;
}
CG_API const char* cgGetProgramString( CGprogram prog, CGenum pname )
{
// check the program input
if ( !CG_IS_PROGRAM( prog ) )
{
rglCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR );
return NULL;
}
//hack to counter change of defines for program_type at r5294
// previously CG_PROGRAM_FILENAME was defined the same as CG_COLUMN_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 ( pname == CG_COLUMN_MAJOR )
pname = CG_PROGRAM_FILENAME;
switch ( pname )
{
case CG_PROGRAM_SOURCE:
// the original Cg source program is returned
// all programs in our API are pre-compiled and come without source.
return NULL;
case CG_PROGRAM_ENTRY:
// the main entry point for the program is returned
// TODO *********** return the name of the entry point
return NULL;
case CG_PROGRAM_PROFILE:
// the profile for the program is returned
{
const char *result = cgGetProfileString(( CGprofile )_cgGetProgPtr( prog )->header.profile );
return result;
}
case CG_COMPILED_PROGRAM:
// the string for the object program is returned
return NULL;
case CG_PROGRAM_FILENAME:
// TODO ***************
// Return the filename of the source ELF this program came from
return ( char* )_cgGetProgPtr( prog )->platformProgram;
case CG_BINARY:
// TODO ***************
// Create a whole new function for handling binaries - return charand length.
// we'll return an image pointer for now...
return ( char* )_cgGetProgPtr( prog )->platformProgram;
default:
rglCgRaiseError( CG_INVALID_ENUMERANT_ERROR );
}
return NULL;
}
CG_API void CGENTRY cgSetLastListing( CGhandle handle, const char *listing )
{
return;