(RGL PS3) Slim down headers

This commit is contained in:
twinaphex 2013-11-07 19:11:25 +01:00
parent 7b9b87c284
commit ab0d1a2e65
11 changed files with 224 additions and 307 deletions

View File

@ -1,17 +1,6 @@
#ifndef _CGC_CGBIO_CGBDEFS_HPP #ifndef _CGC_CGBIO_CGBDEFS_HPP
#define _CGC_CGBIO_CGBDEFS_HPP #define _CGC_CGBIO_CGBDEFS_HPP
// Platform depended definitions:
typedef unsigned int Elf32_Addr;
typedef unsigned short Elf32_Half;
typedef short Elf32_Shalf;
typedef unsigned int Elf32_Off;
typedef signed int Elf32_Sword;
typedef unsigned int Elf32_Word;
typedef unsigned short Elf64_Half;
typedef short Elf64_Shalf;
/////////////////////// ///////////////////////
// ELF Header Constants // ELF Header Constants
@ -248,21 +237,24 @@ typedef short Elf64_Shalf;
#define R_RSX_FLOAT4 1 #define R_RSX_FLOAT4 1
/* Note header in a PT_NOTE section */ /* Note header in a PT_NOTE section */
struct Elf32_Note { struct Elf32_Note
Elf32_Word n_namesz; /* Name size */ {
Elf32_Word n_descsz; /* Content size */ unsigned int n_namesz; /* Name size */
Elf32_Word n_type; /* Content type */ unsigned int n_descsz; /* Content size */
unsigned int n_type; /* Content type */
}; };
// Relocation entries // Relocation entries
// Dynamic structure // Dynamic structure
struct Elf32_Dyn { struct Elf32_Dyn
Elf32_Sword d_tag; {
union { signed int d_tag;
Elf32_Word d_val; union
Elf32_Addr d_ptr; {
unsigned int d_val;
unsigned int d_ptr;
} d_un; } d_un;
}; };

View File

@ -1,9 +0,0 @@
LIBRARY cgbu
EXPORTS
;?CreateCGBI@CGBIO@@QBE?AW4CGBIO_Err@@PAPAVCGBI@@@Z
;?instance@CGBIO@@SAPBV1@XZ
;?get_revision@CGBIImpl@@UBEHXZ
get_revision
instance
CreateCGBI

View File

@ -5,55 +5,57 @@
* format. * format.
*/ */
#if !defined(CGC_CGBIO_CGBIO_HPP) #ifndef CGC_CGBIO_CGBIO_HPP
#define CGC_CGBIO_CGBIO_HPP 1 #define CGC_CGBIO_CGBIO_HPP
#include "cgbdefs.hpp" #include "cgbdefs.hpp"
#include <string> #include <string>
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
};
namespace cgc { } // bio namespace
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 } // cgc namespace
#include "nvbi.hpp" #include "nvbi.hpp"
namespace cgc { namespace cgc
namespace bio { {
namespace bio
{
class bin_io
{
public:
static const bin_io* instance();
static void delete_instance();
class bin_io CGBIO_ERROR new_nvb_reader( nvb_reader** obj ) const;
{
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;
const char *error_string( CGBIO_ERROR error ) const; private:
bin_io();
bin_io( const bin_io& );
private: static bin_io* instance_;
bin_io(); }; // bin_io
bin_io( const bin_io& );
static bin_io* instance_; } // bio namespace
}; // bin_io
} // bio namespace
} // cgc namespace } // cgc namespace
#endif // CGC_CGBIO_CGBIO_HPP #endif // CGC_CGBIO_CGBIO_HPP

View File

@ -2,20 +2,21 @@
#define CGBTYPES_HEADER #define CGBTYPES_HEADER
// parameter structure // parameter structure
typedef struct _Elf32_cgParameter { typedef struct _Elf32_cgParameter
uint32_t cgp_name; // index of name in strtab {
uint32_t cgp_semantic; // index of semantic string in strtab uint32_t cgp_name; // index of name in strtab
uint16_t cgp_default; // index of default data in const //Reduced to half uint32_t cgp_semantic; // index of semantic string in strtab
uint16_t cgp_reloc; // index of reloc indices in rel uint16_t cgp_default; // index of default data in const //Reduced to half
uint16_t cgp_resource; // index of hardware resource assigned uint16_t cgp_reloc; // index of reloc indices in rel
uint16_t cgp_resource_index; // index of hardware resource assigned uint16_t cgp_resource; // index of hardware resource assigned
unsigned char cgp_type; uint16_t cgp_resource_index; // index of hardware resource assigned
uint16_t cgp_info; unsigned char cgp_type;
unsigned char unused; uint16_t cgp_info;
unsigned char unused;
} Elf32_cgParameter; //20 bytes } Elf32_cgParameter; //20 bytes
#define CGF_OUTPUTFROMH0 0x01 #define CGF_OUTPUTFROMH0 0x01
#define CGF_DEPTHREPLACE 0x02 #define CGF_DEPTHREPLACE 0x02
#define CGF_PIXELKILL 0x04 #define CGF_PIXELKILL 0x04
#endif #endif

View File

@ -1,102 +1,62 @@
#if !defined(CGC_CGBIO_CGBUTILS_HPP) #ifndef CGC_CGBIO_CGBUTILS_HPP
#define CGC_CGBIO_CGBUTILS_HPP 1 #define CGC_CGBIO_CGBUTILS_HPP
#include "cgbdefs.hpp" #include "cgbdefs.hpp"
namespace cgc { #define ELF32_ST_BIND(idx) ( idx >> 4 )
namespace bio { #define ELF32_ST_TYPE(idx) ( idx & 0xf )
#define ELF32_ST_INFO(b, t) (( b << 4 ) + ( t & 0xf ))
#define ELF32_ST_VISIBILITY(o) ( o & 0x3 )
typedef enum { namespace cgc
CGBIODATANONE = ELFDATANONE,
CGBIODATALSB = ELFDATA2LSB,
CGBIODATAMSB = ELFDATA2MSB
} HOST_ENDIANNESS; // endianness
inline HOST_ENDIANNESS
host_endianness()
{ {
const int ii = 1; namespace bio
const char* cp = (const char*) &ii; {
return ( 1 == cp[0] ) ? CGBIODATALSB : CGBIODATAMSB; typedef enum
} {
CGBIODATANONE = ELFDATANONE,
CGBIODATALSB = ELFDATA2LSB,
CGBIODATAMSB = ELFDATA2MSB
} HOST_ENDIANNESS; // endianness
template< typename T > inline T inline HOST_ENDIANNESS host_endianness(void)
convert_endianness( const T value, unsigned char endianness ) {
{ const int ii = 1;
if ( host_endianness() == endianness ) const char* cp = (const char*) &ii;
{ return ( cp[0] == 1 ) ? CGBIODATALSB : CGBIODATAMSB;
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;
}
template< typename T > inline T template< typename T > inline T convert_endianness( const T value, unsigned char endianness )
ELF32_ST_BIND( const T idx ) {
{ if ( host_endianness() == endianness )
return ( idx >> 4 ); return value;
}
template< typename T > inline T if ( sizeof( T ) == 1 )
ELF32_ST_TYPE( const T idx ) return value;
{
return ( idx & 0xf );
}
template< typename T > inline T if ( sizeof( T ) == 2 )
ELF32_ST_INFO( const T b, const T t ) return ( ((value & 0x00FF) << 8) | ((value & 0xFF00) >> 8) );
{
return ( ( b << 4 ) + ( t & 0xf ) );
}
template< typename T > inline T if ( sizeof( T ) == 4 )
ELF32_ST_VISIBILITY( const T o ) return ( ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8)
{ | ((value & 0x00FF0000) >> 8) | ((value & 0xFF000000) >> 24) );
return ( o & 0x3 );
}
// these are not used in our relocations, will be replaced by the ones if ( sizeof( T ) == 8 )
// we design, will be defined as templates. {
#ifndef ELF32_R_SYM T result = value;
#define ELF32_R_SYM(i) ((i)>>8) for ( int ii = 0; ii < 4; ++ii )
#endif {
char ch = *( (( char* ) &result) + ii );
*( (( char* ) &result) + ii ) = *( (( char* ) &result) + (7 - ii) );
*( (( char* ) &result) + (7 - ii) ) = ch;
}
return result;
}
#ifndef ELF32_R_TYPE // exception
#define ELF32_R_TYPE(i) ((unsigned char)(i)) return value;
#endif }
} // bio namespace
#ifndef ELF32_R_INFO
#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t))
#endif
} // bio namespace
} // cgc namespace } // cgc namespace

View File

@ -1,5 +0,0 @@
#ifndef CGNV2ELF_VERSION
#define CGNV2ELF_VERSION 6365
#define CGNV2ELF_PRODUCT_STRING "SCE cgnv2elf"
#define CGNV2ELF_VERSION_NOTE_TYPE 0
#endif

View File

@ -7,8 +7,6 @@
#define CNV2END(val) convert_endianness((val), elfEndianness) #define CNV2END(val) convert_endianness((val), elfEndianness)
#define ENDSWAP(val) convert_endianness((val), (host_endianness() == 1) ? 2 : 1) #define ENDSWAP(val) convert_endianness((val), (host_endianness() == 1) ? 2 : 1)
int convertNvToElfFromFile(const char *sourceFile, int endianness, int constTableOffset, void **binaryShader, int *size,
std::vector<char> &stringTable, std::vector<float> &defaultValues);
int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize, int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize,
std::vector<char> &stringTable, std::vector<float> &defaultValues); std::vector<char> &stringTable, std::vector<float> &defaultValues);

View File

@ -1,5 +1,5 @@
#if !defined(CGC_CGBIO_NVBI_HPP) #ifndef CGC_CGBIO_NVBI_HPP
#define CGC_CGBIO_NVBI_HPP 1 #define CGC_CGBIO_NVBI_HPP
#include "cgbdefs.hpp" #include "cgbdefs.hpp"
@ -11,82 +11,73 @@
#include <Cg/cg.h> #include <Cg/cg.h>
#include <Cg/cgBinary.h> #include <Cg/cgBinary.h>
namespace cgc
{
namespace bio
{
class nvb_reader
{
public:
virtual ~nvb_reader() {}
namespace cgc { virtual ptrdiff_t
namespace bio { reference() const = 0;
class nvb_reader { virtual ptrdiff_t
public: release() const = 0;
virtual ~nvb_reader() {}
virtual ptrdiff_t
reference() const = 0;
virtual ptrdiff_t virtual CGBIO_ERROR
release() const = 0; loadFromString( const char* source, size_t length ) = 0;
#ifndef __CELLOS_LV2__ virtual bool
virtual CGBIO_ERROR is_loaded() const = 0;
load( std::istream* stream, int start, bool owner = false ) = 0;
virtual CGBIO_ERROR
load( const char *filename ) = 0;
#endif
virtual CGBIO_ERROR virtual unsigned char
loadFromString( const char* source, size_t length ) = 0; endianness() const = 0;
virtual bool virtual CGprofile
is_loaded() const = 0; profile() const = 0;
virtual unsigned char virtual unsigned int
endianness() const = 0; revision() const = 0;
virtual CGprofile virtual unsigned int
profile() const = 0; size() const = 0;
virtual unsigned int virtual unsigned int
revision() const = 0; number_of_params() const = 0;
virtual unsigned int virtual unsigned int
size() const = 0; ucode_size() const = 0;
virtual unsigned int
number_of_params() const = 0;
virtual unsigned int virtual const char*
ucode_size() const = 0; ucode() const = 0;
virtual const char* virtual const CgBinaryFragmentProgram*
ucode() const = 0; fragment_program() const = 0;
virtual const CgBinaryFragmentProgram* virtual const CgBinaryVertexProgram*
fragment_program() const = 0; vertex_program() const = 0;
virtual const CgBinaryVertexProgram* virtual CGBIO_ERROR
vertex_program() const = 0; get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char** semantic,
CGenum& direction,
int& paramno,
bool& is_referenced,
bool& is_shared ) const = 0;
virtual CGBIO_ERROR virtual CGBIO_ERROR get_param_name( unsigned int index, const char** name, bool& is_referenced) const = 0;
get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char** name,
std::vector<float>& default_value,
std::vector<unsigned int>& 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
}; // nvb_reader
} // bio namespace
} // cgc namespace } // cgc namespace
#endif // CGC_CGBIO_NVBI_HPP #endif // CGC_CGBIO_NVBI_HPP

View File

@ -1,7 +1,6 @@
#if !defined(CGC_CGBIO_NVBIIMPL_HPP) #ifndef CGC_CGBIO_NVBIIMPL_HPP
#define CGC_CGBIO_NVBIIMPL_HPP 1 #define CGC_CGBIO_NVBIIMPL_HPP
#include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstddef> #include <cstddef>
@ -11,93 +10,86 @@
#include "cgbio.hpp" #include "cgbio.hpp"
namespace cgc { namespace cgc
namespace bio {
class nvb_reader_impl : public nvb_reader
{ {
public: namespace bio
nvb_reader_impl(); {
class nvb_reader_impl : public nvb_reader
{
public:
nvb_reader_impl();
virtual virtual
~nvb_reader_impl(); ~nvb_reader_impl();
virtual ptrdiff_t virtual ptrdiff_t
reference() const; reference() const;
virtual ptrdiff_t virtual ptrdiff_t
release() const; release() const;
#ifndef __CELLOS_LV2__ virtual CGBIO_ERROR
virtual CGBIO_ERROR loadFromString( const char* source, size_t length);
load( std::istream* stream, int start ,bool owner = false);
virtual CGBIO_ERROR virtual bool
load( const char* filename ); is_loaded() const;
#endif
virtual CGBIO_ERROR
loadFromString( const char* source, size_t length);
virtual bool
is_loaded() const;
virtual unsigned char virtual unsigned char
endianness() const; endianness() const;
virtual CGprofile virtual CGprofile
profile() const; profile() const;
virtual unsigned int virtual unsigned int
revision() const; revision() const;
virtual unsigned int virtual unsigned int
size() const; size() const;
virtual unsigned int
number_of_params() const;
virtual unsigned int virtual unsigned int
ucode_size() const; number_of_params() const;
virtual const char* virtual unsigned int
ucode() const; ucode_size() const;
virtual const CgBinaryFragmentProgram* virtual const char*
fragment_program() const; ucode() const;
virtual const CgBinaryVertexProgram* virtual const CgBinaryFragmentProgram*
vertex_program() const; fragment_program() const;
virtual CGBIO_ERROR virtual const CgBinaryVertexProgram*
get_param( unsigned int index, vertex_program() const;
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char ** name,
std::vector<float>& default_value,
std::vector<unsigned int>& 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; virtual CGBIO_ERROR
get_param( unsigned int index,
CGtype& type,
CGresource& resource,
CGenum& variability,
int& resource_index,
const char ** name,
std::vector<float>& default_value,
std::vector<unsigned int>& embedded_constants,
const char ** semantic,
CGenum& direction,
int& paramno,
bool& is_referenced,
bool& is_shared ) const;
private: virtual CGBIO_ERROR get_param_name( unsigned int index, const char ** name , bool& is_referenced) const;
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 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 } // cgc namespace
#endif // CGC_CGBIO_NVBIIMPL_HPP #endif // CGC_CGBIO_NVBIIMPL_HPP

View File

@ -1,10 +1,6 @@
#ifndef ELF_H #ifndef ELF_H
#define ELF_H #define ELF_H
/*
* Data Representation
*/
/* /*
* ELF header * ELF header
*/ */

View File

@ -41,7 +41,6 @@
#include "cg/cgbtypes.h" #include "cg/cgbtypes.h"
#include "cg/cgnv2rt.h" #include "cg/cgnv2rt.h"
#include "cg/cgnv2elfversion.h"
#include "cg/cgbio.hpp" #include "cg/cgbio.hpp"
#include "cg/nvbiimpl.hpp" #include "cg/nvbiimpl.hpp"