mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-12 18:51:15 +00:00
run clang-format
This commit is contained in:
parent
13c269eacf
commit
3e47c9a779
@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
#include <psp2/kernel/clib.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
#include <psp2/types.h>
|
||||
|
||||
void* patcher_host_alloc(void* user_data, unsigned int size);
|
||||
@ -16,3 +14,6 @@ void vita_mem_vertex_usse_free(SceUID uid);
|
||||
void* vita_mem_fragment_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset);
|
||||
void vita_mem_fragment_usse_free(SceUID uid);
|
||||
|
||||
bool cdram_allocator_create();
|
||||
void* cdram_alloc(size_t size, size_t align);
|
||||
void cdram_free(void* ptr);
|
||||
|
||||
@ -9,31 +9,18 @@
|
||||
#ifndef INCBIN_HDR
|
||||
#define INCBIN_HDR
|
||||
#include <limits.h>
|
||||
#if defined(__AVX512BW__) || \
|
||||
defined(__AVX512CD__) || \
|
||||
defined(__AVX512DQ__) || \
|
||||
defined(__AVX512ER__) || \
|
||||
defined(__AVX512PF__) || \
|
||||
defined(__AVX512VL__) || \
|
||||
defined(__AVX512F__)
|
||||
# define INCBIN_ALIGNMENT_INDEX 6
|
||||
#elif defined(__AVX__) || \
|
||||
defined(__AVX2__)
|
||||
# define INCBIN_ALIGNMENT_INDEX 5
|
||||
#elif defined(__SSE__) || \
|
||||
defined(__SSE2__) || \
|
||||
defined(__SSE3__) || \
|
||||
defined(__SSSE3__) || \
|
||||
defined(__SSE4_1__) || \
|
||||
defined(__SSE4_2__) || \
|
||||
defined(__neon__) || \
|
||||
defined(__ARM_NEON) || \
|
||||
defined(__ALTIVEC__)
|
||||
# define INCBIN_ALIGNMENT_INDEX 4
|
||||
#if defined(__AVX512BW__) || defined(__AVX512CD__) || defined(__AVX512DQ__) || defined(__AVX512ER__) || \
|
||||
defined(__AVX512PF__) || defined(__AVX512VL__) || defined(__AVX512F__)
|
||||
#define INCBIN_ALIGNMENT_INDEX 6
|
||||
#elif defined(__AVX__) || defined(__AVX2__)
|
||||
#define INCBIN_ALIGNMENT_INDEX 5
|
||||
#elif defined(__SSE__) || defined(__SSE2__) || defined(__SSE3__) || defined(__SSSE3__) || defined(__SSE4_1__) || \
|
||||
defined(__SSE4_2__) || defined(__neon__) || defined(__ARM_NEON) || defined(__ALTIVEC__)
|
||||
#define INCBIN_ALIGNMENT_INDEX 4
|
||||
#elif ULONG_MAX != 0xffffffffu
|
||||
# define INCBIN_ALIGNMENT_INDEX 3
|
||||
# else
|
||||
# define INCBIN_ALIGNMENT_INDEX 2
|
||||
#define INCBIN_ALIGNMENT_INDEX 3
|
||||
#else
|
||||
#define INCBIN_ALIGNMENT_INDEX 2
|
||||
#endif
|
||||
|
||||
/* Lookup table of (1 << n) where `n' is `INCBIN_ALIGNMENT_INDEX' */
|
||||
@ -46,94 +33,84 @@
|
||||
#define INCBIN_ALIGN_SHIFT_6 64
|
||||
|
||||
/* Actual alignment value */
|
||||
#define INCBIN_ALIGNMENT \
|
||||
INCBIN_CONCATENATE( \
|
||||
INCBIN_CONCATENATE(INCBIN_ALIGN_SHIFT, _), \
|
||||
INCBIN_ALIGNMENT_INDEX)
|
||||
#define INCBIN_ALIGNMENT INCBIN_CONCATENATE(INCBIN_CONCATENATE(INCBIN_ALIGN_SHIFT, _), INCBIN_ALIGNMENT_INDEX)
|
||||
|
||||
/* Stringize */
|
||||
#define INCBIN_STR(X) \
|
||||
#X
|
||||
#define INCBIN_STRINGIZE(X) \
|
||||
INCBIN_STR(X)
|
||||
#define INCBIN_STR(X) #X
|
||||
#define INCBIN_STRINGIZE(X) INCBIN_STR(X)
|
||||
/* Concatenate */
|
||||
#define INCBIN_CAT(X, Y) \
|
||||
X ## Y
|
||||
#define INCBIN_CONCATENATE(X, Y) \
|
||||
INCBIN_CAT(X, Y)
|
||||
#define INCBIN_CAT(X, Y) X##Y
|
||||
#define INCBIN_CONCATENATE(X, Y) INCBIN_CAT(X, Y)
|
||||
/* Deferred macro expansion */
|
||||
#define INCBIN_EVAL(X) \
|
||||
X
|
||||
#define INCBIN_INVOKE(N, ...) \
|
||||
INCBIN_EVAL(N(__VA_ARGS__))
|
||||
#define INCBIN_EVAL(X) X
|
||||
#define INCBIN_INVOKE(N, ...) INCBIN_EVAL(N(__VA_ARGS__))
|
||||
/* Variable argument count for overloading by arity */
|
||||
#define INCBIN_VA_ARG_COUNTER(_1, _2, _3, N, ...) N
|
||||
#define INCBIN_VA_ARGC(...) INCBIN_VA_ARG_COUNTER(__VA_ARGS__, 3, 2, 1, 0)
|
||||
|
||||
/* Green Hills uses a different directive for including binary data */
|
||||
#if defined(__ghs__)
|
||||
# if (__ghs_asm == 2)
|
||||
# define INCBIN_MACRO ".file"
|
||||
#if (__ghs_asm == 2)
|
||||
#define INCBIN_MACRO ".file"
|
||||
/* Or consider the ".myrawdata" entry in the ld file */
|
||||
# else
|
||||
# define INCBIN_MACRO "\tINCBIN"
|
||||
# endif
|
||||
#else
|
||||
# define INCBIN_MACRO ".incbin"
|
||||
#define INCBIN_MACRO "\tINCBIN"
|
||||
#endif
|
||||
#else
|
||||
#define INCBIN_MACRO ".incbin"
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
# define INCBIN_ALIGN \
|
||||
__attribute__((aligned(INCBIN_ALIGNMENT)))
|
||||
#define INCBIN_ALIGN __attribute__((aligned(INCBIN_ALIGNMENT)))
|
||||
#else
|
||||
# define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT))
|
||||
#define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT))
|
||||
#endif
|
||||
|
||||
#if defined(__arm__) || /* GNU C and RealView */ \
|
||||
defined(__arm) || /* Diab */ \
|
||||
defined(_ARM) /* ImageCraft */
|
||||
# define INCBIN_ARM
|
||||
#if defined(__arm__) || /* GNU C and RealView */ \
|
||||
defined(__arm) || /* Diab */ \
|
||||
defined(_ARM) /* ImageCraft */
|
||||
#define INCBIN_ARM
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
/* Utilize .balign where supported */
|
||||
# define INCBIN_ALIGN_HOST ".balign " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
|
||||
# define INCBIN_ALIGN_BYTE ".balign 1\n"
|
||||
#define INCBIN_ALIGN_HOST ".balign " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
|
||||
#define INCBIN_ALIGN_BYTE ".balign 1\n"
|
||||
#elif defined(INCBIN_ARM)
|
||||
/*
|
||||
* On arm assemblers, the alignment value is calculated as (1 << n) where `n' is
|
||||
* the shift count. This is the value passed to `.align'
|
||||
*/
|
||||
# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT_INDEX) "\n"
|
||||
# define INCBIN_ALIGN_BYTE ".align 0\n"
|
||||
#define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT_INDEX) "\n"
|
||||
#define INCBIN_ALIGN_BYTE ".align 0\n"
|
||||
#else
|
||||
/* We assume other inline assembler's treat `.align' as `.balign' */
|
||||
# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
|
||||
# define INCBIN_ALIGN_BYTE ".align 1\n"
|
||||
#define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
|
||||
#define INCBIN_ALIGN_BYTE ".align 1\n"
|
||||
#endif
|
||||
|
||||
/* INCBIN_CONST is used by incbin.c generated files */
|
||||
#if defined(__cplusplus)
|
||||
# define INCBIN_EXTERNAL extern "C"
|
||||
# define INCBIN_CONST extern const
|
||||
#define INCBIN_EXTERNAL extern "C"
|
||||
#define INCBIN_CONST extern const
|
||||
#else
|
||||
# define INCBIN_EXTERNAL extern
|
||||
# define INCBIN_CONST const
|
||||
#define INCBIN_EXTERNAL extern
|
||||
#define INCBIN_CONST const
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Optionally override the linker section into which size and data is
|
||||
* emitted.
|
||||
*
|
||||
*
|
||||
* @warning If you use this facility, you might have to deal with
|
||||
* platform-specific linker output section naming on your own.
|
||||
*/
|
||||
#if !defined(INCBIN_OUTPUT_SECTION)
|
||||
# if defined(__APPLE__)
|
||||
# define INCBIN_OUTPUT_SECTION ".const_data"
|
||||
# else
|
||||
# define INCBIN_OUTPUT_SECTION ".rodata"
|
||||
# endif
|
||||
#if defined(__APPLE__)
|
||||
#define INCBIN_OUTPUT_SECTION ".const_data"
|
||||
#else
|
||||
#define INCBIN_OUTPUT_SECTION ".rodata"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -143,7 +120,7 @@
|
||||
* platform-specific linker output section naming on your own.
|
||||
*/
|
||||
#if !defined(INCBIN_OUTPUT_DATA_SECTION)
|
||||
# define INCBIN_OUTPUT_DATA_SECTION INCBIN_OUTPUT_SECTION
|
||||
#define INCBIN_OUTPUT_DATA_SECTION INCBIN_OUTPUT_SECTION
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -151,51 +128,52 @@
|
||||
*
|
||||
* @warning If you use this facility, you might have to deal with
|
||||
* platform-specific linker output section naming on your own.
|
||||
*
|
||||
*
|
||||
* @note This is useful for Harvard architectures where program memory cannot
|
||||
* be directly read from the program without special instructions. With this you
|
||||
* can chose to put the size variable in RAM rather than ROM.
|
||||
*/
|
||||
#if !defined(INCBIN_OUTPUT_SIZE_SECTION)
|
||||
# define INCBIN_OUTPUT_SIZE_SECTION INCBIN_OUTPUT_SECTION
|
||||
#define INCBIN_OUTPUT_SIZE_SECTION INCBIN_OUTPUT_SECTION
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <TargetConditionals.h>
|
||||
# if defined(TARGET_OS_IPHONE) && !defined(INCBIN_SILENCE_BITCODE_WARNING)
|
||||
# warning "incbin is incompatible with bitcode. Using the library will break upload to App Store if you have bitcode enabled. Add `#define INCBIN_SILENCE_BITCODE_WARNING` before including this header to silence this warning."
|
||||
# endif
|
||||
#include <TargetConditionals.h>
|
||||
#if defined(TARGET_OS_IPHONE) && !defined(INCBIN_SILENCE_BITCODE_WARNING)
|
||||
#warning \
|
||||
"incbin is incompatible with bitcode. Using the library will break upload to App Store if you have bitcode enabled. Add `#define INCBIN_SILENCE_BITCODE_WARNING` before including this header to silence this warning."
|
||||
#endif
|
||||
/* The directives are different for Apple branded compilers */
|
||||
# define INCBIN_SECTION INCBIN_OUTPUT_SECTION "\n"
|
||||
# define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
|
||||
# define INCBIN_INT ".long "
|
||||
# define INCBIN_MANGLE "_"
|
||||
# define INCBIN_BYTE ".byte "
|
||||
# define INCBIN_TYPE(...)
|
||||
#define INCBIN_SECTION INCBIN_OUTPUT_SECTION "\n"
|
||||
#define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
|
||||
#define INCBIN_INT ".long "
|
||||
#define INCBIN_MANGLE "_"
|
||||
#define INCBIN_BYTE ".byte "
|
||||
#define INCBIN_TYPE(...)
|
||||
#else
|
||||
# define INCBIN_SECTION ".section " INCBIN_OUTPUT_SECTION "\n"
|
||||
# define INCBIN_GLOBAL(NAME) ".global " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
|
||||
# if defined(__ghs__)
|
||||
# define INCBIN_INT ".word "
|
||||
# else
|
||||
# define INCBIN_INT ".int "
|
||||
# endif
|
||||
# if defined(__USER_LABEL_PREFIX__)
|
||||
# define INCBIN_MANGLE INCBIN_STRINGIZE(__USER_LABEL_PREFIX__)
|
||||
# else
|
||||
# define INCBIN_MANGLE ""
|
||||
# endif
|
||||
# if defined(INCBIN_ARM)
|
||||
#define INCBIN_SECTION ".section " INCBIN_OUTPUT_SECTION "\n"
|
||||
#define INCBIN_GLOBAL(NAME) ".global " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
|
||||
#if defined(__ghs__)
|
||||
#define INCBIN_INT ".word "
|
||||
#else
|
||||
#define INCBIN_INT ".int "
|
||||
#endif
|
||||
#if defined(__USER_LABEL_PREFIX__)
|
||||
#define INCBIN_MANGLE INCBIN_STRINGIZE(__USER_LABEL_PREFIX__)
|
||||
#else
|
||||
#define INCBIN_MANGLE ""
|
||||
#endif
|
||||
#if defined(INCBIN_ARM)
|
||||
/* On arm assemblers, `@' is used as a line comment token */
|
||||
# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", %object\n"
|
||||
# elif defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__)
|
||||
#define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", %object\n"
|
||||
#elif defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__)
|
||||
/* Mingw and Cygwin don't support this directive either */
|
||||
# define INCBIN_TYPE(NAME)
|
||||
# else
|
||||
#define INCBIN_TYPE(NAME)
|
||||
#else
|
||||
/* It's safe to use `@' on other architectures */
|
||||
# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", @object\n"
|
||||
# endif
|
||||
# define INCBIN_BYTE ".byte "
|
||||
#define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", @object\n"
|
||||
#endif
|
||||
#define INCBIN_BYTE ".byte "
|
||||
#endif
|
||||
|
||||
/* List of style types used for symbol names */
|
||||
@ -219,7 +197,7 @@
|
||||
* @endcode
|
||||
*/
|
||||
#if !defined(INCBIN_PREFIX)
|
||||
# define INCBIN_PREFIX g
|
||||
#define INCBIN_PREFIX g
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -243,7 +221,7 @@
|
||||
* @endcode
|
||||
*/
|
||||
#if !defined(INCBIN_STYLE)
|
||||
# define INCBIN_STYLE INCBIN_STYLE_CAMEL
|
||||
#define INCBIN_STYLE INCBIN_STYLE_CAMEL
|
||||
#endif
|
||||
|
||||
/* Style lookup tables */
|
||||
@ -255,35 +233,17 @@
|
||||
#define INCBIN_STYLE_1_SIZE _size
|
||||
|
||||
/* Style lookup: returning identifier */
|
||||
#define INCBIN_STYLE_IDENT(TYPE) \
|
||||
INCBIN_CONCATENATE( \
|
||||
INCBIN_STYLE_, \
|
||||
INCBIN_CONCATENATE( \
|
||||
INCBIN_EVAL(INCBIN_STYLE), \
|
||||
INCBIN_CONCATENATE(_, TYPE)))
|
||||
#define INCBIN_STYLE_IDENT(TYPE) \
|
||||
INCBIN_CONCATENATE(INCBIN_STYLE_, INCBIN_CONCATENATE(INCBIN_EVAL(INCBIN_STYLE), INCBIN_CONCATENATE(_, TYPE)))
|
||||
|
||||
/* Style lookup: returning string literal */
|
||||
#define INCBIN_STYLE_STRING(TYPE) \
|
||||
INCBIN_STRINGIZE( \
|
||||
INCBIN_STYLE_IDENT(TYPE)) \
|
||||
#define INCBIN_STYLE_STRING(TYPE) INCBIN_STRINGIZE(INCBIN_STYLE_IDENT(TYPE))
|
||||
|
||||
/* Generate the global labels by indirectly invoking the macro with our style
|
||||
* type and concatenating the name against them. */
|
||||
#define INCBIN_GLOBAL_LABELS(NAME, TYPE) \
|
||||
INCBIN_INVOKE( \
|
||||
INCBIN_GLOBAL, \
|
||||
INCBIN_CONCATENATE( \
|
||||
NAME, \
|
||||
INCBIN_INVOKE( \
|
||||
INCBIN_STYLE_IDENT, \
|
||||
TYPE))) \
|
||||
INCBIN_INVOKE( \
|
||||
INCBIN_TYPE, \
|
||||
INCBIN_CONCATENATE( \
|
||||
NAME, \
|
||||
INCBIN_INVOKE( \
|
||||
INCBIN_STYLE_IDENT, \
|
||||
TYPE)))
|
||||
#define INCBIN_GLOBAL_LABELS(NAME, TYPE) \
|
||||
INCBIN_INVOKE(INCBIN_GLOBAL, INCBIN_CONCATENATE(NAME, INCBIN_INVOKE(INCBIN_STYLE_IDENT, TYPE))) \
|
||||
INCBIN_INVOKE(INCBIN_TYPE, INCBIN_CONCATENATE(NAME, INCBIN_INVOKE(INCBIN_STYLE_IDENT, TYPE)))
|
||||
|
||||
/**
|
||||
* @brief Externally reference binary data included in another translation unit.
|
||||
@ -305,34 +265,30 @@
|
||||
* // extern const unsigned char *const <prefix>Foo<end>;
|
||||
* // extern const unsigned int <prefix>Foo<size>;
|
||||
* @endcode
|
||||
*
|
||||
*
|
||||
* You may specify a custom optional data type as well as the first argument.
|
||||
* @code
|
||||
* INCBIN_EXTERN(custom_type, Foo);
|
||||
*
|
||||
*
|
||||
* // Now you have the following symbols:
|
||||
* // extern const custom_type <prefix>Foo<data>[];
|
||||
* // extern const custom_type *const <prefix>Foo<end>;
|
||||
* // extern const unsigned int <prefix>Foo<size>;
|
||||
* @endcode
|
||||
*/
|
||||
#define INCBIN_EXTERN(...) \
|
||||
INCBIN_CONCATENATE(INCBIN_EXTERN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define INCBIN_EXTERN_1(NAME, ...) \
|
||||
INCBIN_EXTERN_2(unsigned char, NAME)
|
||||
#define INCBIN_EXTERN_2(TYPE, NAME) \
|
||||
INCBIN_EXTERNAL const INCBIN_ALIGN TYPE \
|
||||
INCBIN_CONCATENATE( \
|
||||
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||
INCBIN_STYLE_IDENT(DATA))[]; \
|
||||
INCBIN_EXTERNAL const INCBIN_ALIGN TYPE *const \
|
||||
INCBIN_CONCATENATE( \
|
||||
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||
INCBIN_STYLE_IDENT(END)); \
|
||||
INCBIN_EXTERNAL const unsigned int \
|
||||
INCBIN_CONCATENATE( \
|
||||
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||
INCBIN_STYLE_IDENT(SIZE))
|
||||
#define INCBIN_EXTERN(...) INCBIN_CONCATENATE(INCBIN_EXTERN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define INCBIN_EXTERN_1(NAME, ...) INCBIN_EXTERN_2(unsigned char, NAME)
|
||||
#define INCBIN_EXTERN_2(TYPE, NAME) \
|
||||
INCBIN_EXTERNAL const INCBIN_ALIGN TYPE \
|
||||
INCBIN_CONCATENATE(INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), INCBIN_STYLE_IDENT(DATA))[]; \
|
||||
INCBIN_EXTERNAL const INCBIN_ALIGN TYPE* const INCBIN_CONCATENATE( \
|
||||
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||
INCBIN_STYLE_IDENT(END) \
|
||||
); \
|
||||
INCBIN_EXTERNAL const unsigned int INCBIN_CONCATENATE( \
|
||||
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
|
||||
INCBIN_STYLE_IDENT(SIZE) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @brief Externally reference textual data included in another translation unit.
|
||||
@ -354,8 +310,7 @@
|
||||
* // extern const unsigned int <prefix>Foo<size>;
|
||||
* @endcode
|
||||
*/
|
||||
#define INCTXT_EXTERN(NAME) \
|
||||
INCBIN_EXTERN_2(char, NAME)
|
||||
#define INCTXT_EXTERN(NAME) INCBIN_EXTERN_2(char, NAME)
|
||||
|
||||
/**
|
||||
* @brief Include a binary file into the current translation unit.
|
||||
@ -378,7 +333,7 @@
|
||||
* // const unsigned char *const <prefix>Icon<end>;
|
||||
* // const unsigned int <prefix>Icon<size>;
|
||||
* @endcode
|
||||
*
|
||||
*
|
||||
* You may specify a custom optional data type as well as the first argument.
|
||||
* These macros are specialized by arity.
|
||||
* @code
|
||||
@ -397,46 +352,34 @@
|
||||
* please @see INCBIN_EXTERN.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
# define INCBIN(NAME, FILENAME) \
|
||||
INCBIN_EXTERN(NAME)
|
||||
#define INCBIN(NAME, FILENAME) INCBIN_EXTERN(NAME)
|
||||
#else
|
||||
# define INCBIN(...) \
|
||||
INCBIN_CONCATENATE(INCBIN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__)
|
||||
# if defined(__GNUC__)
|
||||
# define INCBIN_1(...) _Pragma("GCC error \"Single argument INCBIN not allowed\"")
|
||||
# elif defined(__clang__)
|
||||
# define INCBIN_1(...) _Pragma("clang error \"Single argument INCBIN not allowed\"")
|
||||
# else
|
||||
# define INCBIN_1(...) /* Cannot do anything here */
|
||||
# endif
|
||||
# define INCBIN_2(NAME, FILENAME) \
|
||||
INCBIN_3(unsigned char, NAME, FILENAME)
|
||||
# define INCBIN_3(TYPE, NAME, FILENAME) INCBIN_COMMON(TYPE, NAME, FILENAME, /* No terminator for binary data */)
|
||||
# define INCBIN_COMMON(TYPE, NAME, FILENAME, TERMINATOR) \
|
||||
__asm__(INCBIN_SECTION \
|
||||
INCBIN_GLOBAL_LABELS(NAME, DATA) \
|
||||
INCBIN_ALIGN_HOST \
|
||||
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) ":\n" \
|
||||
INCBIN_MACRO " \"" FILENAME "\"\n" \
|
||||
TERMINATOR \
|
||||
INCBIN_GLOBAL_LABELS(NAME, END) \
|
||||
INCBIN_ALIGN_BYTE \
|
||||
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) ":\n" \
|
||||
INCBIN_BYTE "1\n" \
|
||||
INCBIN_GLOBAL_LABELS(NAME, SIZE) \
|
||||
INCBIN_ALIGN_HOST \
|
||||
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(SIZE) ":\n" \
|
||||
INCBIN_INT INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) " - " \
|
||||
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) "\n" \
|
||||
INCBIN_ALIGN_HOST \
|
||||
".text\n" \
|
||||
); \
|
||||
INCBIN_EXTERN(TYPE, NAME)
|
||||
#define INCBIN(...) INCBIN_CONCATENATE(INCBIN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__)
|
||||
#if defined(__GNUC__)
|
||||
#define INCBIN_1(...) _Pragma("GCC error \"Single argument INCBIN not allowed\"")
|
||||
#elif defined(__clang__)
|
||||
#define INCBIN_1(...) _Pragma("clang error \"Single argument INCBIN not allowed\"")
|
||||
#else
|
||||
#define INCBIN_1(...) /* Cannot do anything here */
|
||||
#endif
|
||||
#define INCBIN_2(NAME, FILENAME) INCBIN_3(unsigned char, NAME, FILENAME)
|
||||
#define INCBIN_3(TYPE, NAME, FILENAME) INCBIN_COMMON(TYPE, NAME, FILENAME, /* No terminator for binary data */)
|
||||
#define INCBIN_COMMON(TYPE, NAME, FILENAME, TERMINATOR) \
|
||||
__asm__(INCBIN_SECTION INCBIN_GLOBAL_LABELS(NAME, DATA) \
|
||||
INCBIN_ALIGN_HOST INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA \
|
||||
) ":\n" INCBIN_MACRO " \"" FILENAME "\"\n" TERMINATOR INCBIN_GLOBAL_LABELS(NAME, END) \
|
||||
INCBIN_ALIGN_BYTE INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END \
|
||||
) ":\n" INCBIN_BYTE "1\n" INCBIN_GLOBAL_LABELS(NAME, SIZE) \
|
||||
INCBIN_ALIGN_HOST INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(SIZE \
|
||||
) ":\n" INCBIN_INT INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END \
|
||||
) " - " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA \
|
||||
) "\n" INCBIN_ALIGN_HOST ".text\n"); \
|
||||
INCBIN_EXTERN(TYPE, NAME)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Include a textual file into the current translation unit.
|
||||
*
|
||||
*
|
||||
* This behaves the same as INCBIN except it produces char compatible arrays
|
||||
* and implicitly adds a null-terminator byte, thus the size of data included
|
||||
* by this is one byte larger than that of INCBIN.
|
||||
@ -466,11 +409,9 @@
|
||||
* please @see INCBIN_EXTERN.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
# define INCTXT(NAME, FILENAME) \
|
||||
INCBIN_EXTERN(NAME)
|
||||
#define INCTXT(NAME, FILENAME) INCBIN_EXTERN(NAME)
|
||||
#else
|
||||
# define INCTXT(NAME, FILENAME) \
|
||||
INCBIN_COMMON(char, NAME, FILENAME, INCBIN_BYTE "0\n")
|
||||
#define INCTXT(NAME, FILENAME) INCBIN_COMMON(char, NAME, FILENAME, INCBIN_BYTE "0\n")
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
#include "gxm_memory.h"
|
||||
|
||||
#include "tlsf.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
#include <psp2/gxm.h>
|
||||
#include <psp2/kernel/clib.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
|
||||
#define CDRAM_POOL_SIZE 64 * 1024 * 1024
|
||||
|
||||
static SceUID cdramAllocatorUID = -1;
|
||||
static tlsf_t cdramAllocator = nullptr;
|
||||
int inuse_mem = 0;
|
||||
|
||||
void* patcher_host_alloc(void* user_data, unsigned int size)
|
||||
{
|
||||
@ -114,3 +122,53 @@ void vita_mem_fragment_usse_free(SceUID uid)
|
||||
sceGxmUnmapFragmentUsseMemory(mem);
|
||||
sceKernelFreeMemBlock(uid);
|
||||
}
|
||||
|
||||
bool cdram_allocator_create()
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sceKernelAllocMemBlock("gpu_cdram_pool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, CDRAM_POOL_SIZE, NULL);
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("sceKernelAllocMemBlock failed: %08x\n", ret);
|
||||
return false;
|
||||
}
|
||||
cdramAllocatorUID = ret;
|
||||
|
||||
void* mem;
|
||||
ret = sceKernelGetMemBlockBase(cdramAllocatorUID, &mem);
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("sceKernelGetMemBlockBase failed: %08x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = sceGxmMapMemory(
|
||||
mem,
|
||||
CDRAM_POOL_SIZE,
|
||||
(SceGxmMemoryAttribFlags) (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE)
|
||||
);
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("sceGxmMapMemory failed: %08x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
cdramAllocator = SDL_malloc(tlsf_size());
|
||||
tlsf_create(cdramAllocator);
|
||||
tlsf_add_pool(cdramAllocator, mem, CDRAM_POOL_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
void* cdram_alloc(size_t size, size_t align)
|
||||
{
|
||||
DEBUG_ONLY_PRINTF("cdram_alloc(%d, %d) inuse=%d ", size, align, inuse_mem);
|
||||
void* ptr = tlsf_memalign(cdramAllocator, align, size);
|
||||
DEBUG_ONLY_PRINTF("ptr=%p\n", ptr);
|
||||
inuse_mem += tlsf_block_size(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void cdram_free(void* ptr)
|
||||
{
|
||||
inuse_mem -= tlsf_block_size(ptr);
|
||||
DEBUG_ONLY_PRINTF("cdram_free(%p)\n", ptr);
|
||||
tlsf_free(cdramAllocator, ptr);
|
||||
}
|
||||
|
||||
@ -3,10 +3,11 @@
|
||||
#include <psp2/razor_capture.h>
|
||||
#include <psp2/razor_hud.h>
|
||||
|
||||
extern "C" {
|
||||
extern int sceRazorGpuCaptureSetTrigger(int frames, const char* path);
|
||||
extern "C"
|
||||
{
|
||||
extern int sceRazorGpuCaptureSetTrigger(int frames, const char* path);
|
||||
|
||||
extern int sceRazorGpuTraceTrigger();
|
||||
extern int sceRazorGpuTraceSetFilename(const char* filename, int counter);
|
||||
extern int sceRazorHudSetDisplayEnabled(bool enable);
|
||||
extern int sceRazorGpuTraceTrigger();
|
||||
extern int sceRazorGpuTraceSetFilename(const char* filename, int counter);
|
||||
extern int sceRazorHudSetDisplayEnabled(bool enable);
|
||||
}
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
#include "d3drmrenderer_gxm.h"
|
||||
#include "gxm_memory.h"
|
||||
#include "meshutils.h"
|
||||
#include "utils.h"
|
||||
#include "razor.h"
|
||||
#include "tlsf.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <algorithm>
|
||||
#include <psp2/display.h>
|
||||
#include <psp2/gxm.h>
|
||||
#include <psp2/kernel/modulemgr.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
#include <psp2/types.h>
|
||||
#include <string>
|
||||
#define INCBIN_PREFIX _inc_
|
||||
@ -27,9 +28,6 @@ bool gxm_initialized = false;
|
||||
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
|
||||
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
|
||||
|
||||
#define CDRAM_POOL_SIZE 64*1024*1024
|
||||
|
||||
|
||||
INCBIN(main_vert_gxp, "shaders/main.vert.gxp");
|
||||
INCBIN(main_frag_gxp, "shaders/main.frag.gxp");
|
||||
INCBIN(color_frag_gxp, "shaders/color.frag.gxp");
|
||||
@ -60,7 +58,6 @@ static const SceGxmBlendInfo blendInfoTransparent = {
|
||||
.alphaDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
};
|
||||
|
||||
|
||||
static GXMRendererContext gxm_renderer_context;
|
||||
|
||||
static void display_callback(const void* callback_data)
|
||||
@ -84,13 +81,13 @@ static void display_callback(const void* callback_data)
|
||||
static int load_skprx(const char* name)
|
||||
{
|
||||
int modid = taiLoadKernelModule(name, 0, nullptr);
|
||||
if(modid < 0) {
|
||||
if (modid < 0) {
|
||||
sceClibPrintf("%s load: 0x%08x\n", name, modid);
|
||||
return modid;
|
||||
}
|
||||
int status;
|
||||
int ret = taiStartKernelModule(modid, 0, nullptr, 0, nullptr, &status);
|
||||
if(ret < 0) {
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("%s start: 0x%08x\n", name, ret);
|
||||
}
|
||||
return ret;
|
||||
@ -99,34 +96,34 @@ static int load_skprx(const char* name)
|
||||
static int load_suprx(const char* name)
|
||||
{
|
||||
int modid = _sceKernelLoadModule(name, 0, nullptr);
|
||||
if(modid < 0) {
|
||||
if (modid < 0) {
|
||||
sceClibPrintf("%s load: 0x%08x\n", name, modid);
|
||||
return modid;
|
||||
}
|
||||
int status;
|
||||
int ret = sceKernelStartModule(modid, 0, nullptr, 0, nullptr, &status);
|
||||
if(ret < 0) {
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("%s start: 0x%08x\n", name, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const bool extra_debug = false;
|
||||
static const bool extra_debug = false;
|
||||
|
||||
static void load_razor()
|
||||
{
|
||||
if(load_suprx("app0:librazorcapture_es4.suprx") >= 0) {
|
||||
if (load_suprx("app0:librazorcapture_es4.suprx") >= 0) {
|
||||
with_razor = true;
|
||||
}
|
||||
|
||||
if(extra_debug) {
|
||||
if (extra_debug) {
|
||||
load_skprx("ux0:app/LEGO00001/syslibtrace.skprx");
|
||||
load_skprx("ux0:app/LEGO00001/pamgr.skprx");
|
||||
|
||||
if(load_suprx("app0:libperf.suprx") >= 0) {
|
||||
if (load_suprx("app0:libperf.suprx") >= 0) {
|
||||
}
|
||||
|
||||
if(load_suprx("app0:librazorhud_es4.suprx") >= 0) {
|
||||
if (load_suprx("app0:librazorhud_es4.suprx") >= 0) {
|
||||
with_razor_hud = true;
|
||||
}
|
||||
}
|
||||
@ -135,7 +132,7 @@ static void load_razor()
|
||||
sceRazorGpuCaptureEnableSalvage("ux0:data/gpu_crash.sgx");
|
||||
}
|
||||
|
||||
if(with_razor_hud) {
|
||||
if (with_razor_hud) {
|
||||
sceRazorGpuTraceSetFilename("ux0:data/gpu_trace", 3);
|
||||
}
|
||||
}
|
||||
@ -165,62 +162,6 @@ bool gxm_init()
|
||||
return true;
|
||||
}
|
||||
|
||||
static SceUID cdramAllocatorUID = -1;
|
||||
static tlsf_t cdramAllocator = nullptr;
|
||||
|
||||
bool cdram_allocator_create() {
|
||||
int ret;
|
||||
|
||||
ret = sceKernelAllocMemBlock(
|
||||
"gpu_cdram_pool",
|
||||
SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
|
||||
CDRAM_POOL_SIZE,
|
||||
NULL
|
||||
);
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("sceKernelAllocMemBlock failed: %08x\n", ret);
|
||||
return false;
|
||||
}
|
||||
cdramAllocatorUID = ret;
|
||||
|
||||
void* mem;
|
||||
ret = sceKernelGetMemBlockBase(cdramAllocatorUID, &mem);
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("sceKernelGetMemBlockBase failed: %08x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = sceGxmMapMemory(
|
||||
mem,
|
||||
CDRAM_POOL_SIZE,
|
||||
(SceGxmMemoryAttribFlags) (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE)
|
||||
);
|
||||
if (ret < 0) {
|
||||
sceClibPrintf("sceGxmMapMemory failed: %08x\n", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
cdramAllocator = SDL_malloc(tlsf_size());
|
||||
tlsf_create(cdramAllocator);
|
||||
tlsf_add_pool(cdramAllocator, mem, CDRAM_POOL_SIZE);
|
||||
return true;
|
||||
}
|
||||
|
||||
int inuse_mem = 0;
|
||||
inline void* cdram_alloc(size_t size, size_t align) {
|
||||
sceClibPrintf("cdram_alloc(%d, %d) inuse=%d ", size, align, inuse_mem);
|
||||
void* ptr = tlsf_memalign(cdramAllocator, align, size);
|
||||
sceClibPrintf("ptr=%p\n", ptr);
|
||||
inuse_mem += tlsf_block_size(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void cdram_free(void* ptr) {
|
||||
inuse_mem -= tlsf_block_size(ptr);
|
||||
sceClibPrintf("cdram_free(%p)\n", ptr);
|
||||
tlsf_free(cdramAllocator, ptr);
|
||||
}
|
||||
|
||||
static bool create_gxm_context()
|
||||
{
|
||||
GXMRendererContext* data = &gxm_renderer_context;
|
||||
@ -407,7 +348,7 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height)
|
||||
return;
|
||||
}
|
||||
|
||||
if(!cdram_allocator_create()) {
|
||||
if (!cdram_allocator_create()) {
|
||||
sceClibPrintf("failed to create cdram allocator");
|
||||
return;
|
||||
}
|
||||
@ -551,15 +492,15 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height)
|
||||
vertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
|
||||
|
||||
if (SCE_ERR(
|
||||
sceGxmShaderPatcherCreateVertexProgram,
|
||||
this->shaderPatcher,
|
||||
this->mainVertexProgramId,
|
||||
vertexAttributes,
|
||||
3,
|
||||
vertexStreams,
|
||||
1,
|
||||
&this->mainVertexProgram
|
||||
)) {
|
||||
sceGxmShaderPatcherCreateVertexProgram,
|
||||
this->shaderPatcher,
|
||||
this->mainVertexProgramId,
|
||||
vertexAttributes,
|
||||
3,
|
||||
vertexStreams,
|
||||
1,
|
||||
&this->mainVertexProgram
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -635,7 +576,6 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height)
|
||||
// clear uniforms
|
||||
this->colorShader_uColor = sceGxmProgramFindParameterByName(colorFragmentProgramGxp, "uColor"); // vec4
|
||||
|
||||
|
||||
for (int i = 0; i < GXM_FRAGMENT_BUFFER_COUNT; i++) {
|
||||
this->lights[i] = static_cast<GXMSceneLightUniform*>(cdram_alloc(sizeof(GXMSceneLightUniform), 4));
|
||||
}
|
||||
@ -649,13 +589,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height)
|
||||
this->quadIndices[3] = 3;
|
||||
|
||||
volatile uint32_t* notificationMem = sceGxmGetNotificationRegion();
|
||||
for(uint32_t i = 0; i < GXM_FRAGMENT_BUFFER_COUNT; i++) {
|
||||
for (uint32_t i = 0; i < GXM_FRAGMENT_BUFFER_COUNT; i++) {
|
||||
this->fragmentNotifications[i].address = notificationMem++;
|
||||
this->fragmentNotifications[i].value = 0;
|
||||
}
|
||||
this->currentFragmentBufferIndex = 0;
|
||||
|
||||
for(uint32_t i = 0; i < GXM_VERTEX_BUFFER_COUNT; i++) {
|
||||
for (uint32_t i = 0; i < GXM_VERTEX_BUFFER_COUNT; i++) {
|
||||
this->vertexNotifications[i].address = notificationMem++;
|
||||
this->vertexNotifications[i].value = 0;
|
||||
}
|
||||
@ -663,10 +603,10 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height)
|
||||
|
||||
int count;
|
||||
auto ids = SDL_GetGamepads(&count);
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
auto id = ids[i];
|
||||
auto gamepad = SDL_OpenGamepad(id);
|
||||
if(gamepad != nullptr) {
|
||||
if (gamepad != nullptr) {
|
||||
this->gamepad = gamepad;
|
||||
break;
|
||||
}
|
||||
@ -734,90 +674,84 @@ static void convertTextureMetadata(
|
||||
SDL_Surface* surface,
|
||||
bool* supportedFormat,
|
||||
SceGxmTextureFormat* gxmTextureFormat,
|
||||
size_t* textureSize, // size in bytes
|
||||
size_t* textureSize, // size in bytes
|
||||
size_t* textureAlignment, // alignment in bytes
|
||||
size_t* textureStride, // stride in bytes
|
||||
size_t* paletteOffset // offset from textureData in bytes
|
||||
size_t* textureStride, // stride in bytes
|
||||
size_t* paletteOffset // offset from textureData in bytes
|
||||
)
|
||||
{
|
||||
int bytesPerPixel;
|
||||
size_t extraDataSize = 0;
|
||||
switch (surface->format) {
|
||||
case SDL_PIXELFORMAT_INDEX8: {
|
||||
*supportedFormat = true;
|
||||
*gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_P8_ABGR;
|
||||
int pixelsSize = surface->w * surface->h;
|
||||
int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT);
|
||||
extraDataSize = alignBytes + 256 * 4;
|
||||
*textureAlignment = SCE_GXM_PALETTE_ALIGNMENT;
|
||||
*paletteOffset = pixelsSize + alignBytes;
|
||||
bytesPerPixel = 1;
|
||||
break;
|
||||
}
|
||||
case SDL_PIXELFORMAT_ABGR8888: {
|
||||
*supportedFormat = true;
|
||||
*gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR;
|
||||
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
||||
bytesPerPixel = 4;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
*supportedFormat = false;
|
||||
*gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR;
|
||||
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
||||
bytesPerPixel = 4;
|
||||
break;
|
||||
}
|
||||
case SDL_PIXELFORMAT_INDEX8: {
|
||||
*supportedFormat = true;
|
||||
*gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_P8_ABGR;
|
||||
int pixelsSize = surface->w * surface->h;
|
||||
int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT);
|
||||
extraDataSize = alignBytes + 256 * 4;
|
||||
*textureAlignment = SCE_GXM_PALETTE_ALIGNMENT;
|
||||
*paletteOffset = pixelsSize + alignBytes;
|
||||
bytesPerPixel = 1;
|
||||
break;
|
||||
}
|
||||
*textureStride = ALIGN(surface->w, 8)*bytesPerPixel;
|
||||
*textureSize = (*textureStride)*surface->h+extraDataSize;
|
||||
case SDL_PIXELFORMAT_ABGR8888: {
|
||||
*supportedFormat = true;
|
||||
*gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR;
|
||||
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
||||
bytesPerPixel = 4;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
*supportedFormat = false;
|
||||
*gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR;
|
||||
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
||||
bytesPerPixel = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*textureStride = ALIGN(surface->w, 8) * bytesPerPixel;
|
||||
*textureSize = (*textureStride) * surface->h + extraDataSize;
|
||||
}
|
||||
|
||||
void copySurfaceToGxm(DirectDrawSurfaceImpl* surface, uint8_t* textureData, size_t dstStride, size_t dstSize)
|
||||
{
|
||||
SDL_Surface* src = surface->m_surface;
|
||||
switch(src->format) {
|
||||
case SDL_PIXELFORMAT_ABGR8888: {
|
||||
for(int y = 0; y < src->h; y++) {
|
||||
uint8_t* srcRow = (uint8_t*)src->pixels + (y*src->pitch);
|
||||
uint8_t* dstRow = textureData + (y*dstStride);
|
||||
size_t rowSize = src->w*4;
|
||||
if((dstRow - textureData)+rowSize > dstSize) {
|
||||
sceClibPrintf("buffer overrun!!! size=%d y=%d rowSize=%d\n", dstSize, y, rowSize);
|
||||
}
|
||||
memcpy(dstRow, srcRow, rowSize);
|
||||
}
|
||||
break;
|
||||
switch (src->format) {
|
||||
case SDL_PIXELFORMAT_ABGR8888: {
|
||||
for (int y = 0; y < src->h; y++) {
|
||||
uint8_t* srcRow = (uint8_t*) src->pixels + (y * src->pitch);
|
||||
uint8_t* dstRow = textureData + (y * dstStride);
|
||||
size_t rowSize = src->w * 4;
|
||||
memcpy(dstRow, srcRow, rowSize);
|
||||
}
|
||||
case SDL_PIXELFORMAT_INDEX8: {
|
||||
LPDIRECTDRAWPALETTE _palette;
|
||||
surface->GetPalette(&_palette);
|
||||
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
|
||||
|
||||
// copy pixels
|
||||
for(int y = 0; y < src->h; y++) {
|
||||
void* srcRow = static_cast<uint8_t*>(src->pixels) + (y*src->pitch);
|
||||
void* dstRow = static_cast<uint8_t*>(textureData) + (y*dstStride);
|
||||
memcpy(dstRow, srcRow, src->w);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_PIXELFORMAT_INDEX8: {
|
||||
LPDIRECTDRAWPALETTE _palette;
|
||||
surface->GetPalette(&_palette);
|
||||
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
|
||||
|
||||
int pixelsSize = src->w * src->h;
|
||||
int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT);
|
||||
uint8_t* paletteData = textureData + pixelsSize + alignBytes;
|
||||
memcpy(paletteData, palette->m_palette->colors, 256 * 4);
|
||||
if((paletteData-textureData) + 256*4 > dstSize) {
|
||||
sceClibPrintf("buffer overrun!!! textureData=%p paletteData=%p size=%d\n", textureData, paletteData, dstSize);
|
||||
}
|
||||
palette->Release();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sceClibPrintf("unsupported format %d\n", SDL_GetPixelFormatName(src->format));
|
||||
SDL_Surface* dst = SDL_CreateSurfaceFrom(src->w, src->h, SDL_PIXELFORMAT_ABGR8888, textureData, src->w*4);
|
||||
SDL_BlitSurface(src, nullptr, dst, nullptr);
|
||||
SDL_DestroySurface(dst);
|
||||
break;
|
||||
// copy pixels
|
||||
for (int y = 0; y < src->h; y++) {
|
||||
void* srcRow = static_cast<uint8_t*>(src->pixels) + (y * src->pitch);
|
||||
void* dstRow = static_cast<uint8_t*>(textureData) + (y * dstStride);
|
||||
memcpy(dstRow, srcRow, src->w);
|
||||
}
|
||||
|
||||
int pixelsSize = src->w * src->h;
|
||||
int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT);
|
||||
uint8_t* paletteData = textureData + pixelsSize + alignBytes;
|
||||
memcpy(paletteData, palette->m_palette->colors, 256 * 4);
|
||||
palette->Release();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
DEBUG_ONLY_PRINTF("unsupported format %d\n", SDL_GetPixelFormatName(src->format));
|
||||
SDL_Surface* dst = SDL_CreateSurfaceFrom(src->w, src->h, SDL_PIXELFORMAT_ABGR8888, textureData, src->w * 4);
|
||||
SDL_BlitSurface(src, nullptr, dst, nullptr);
|
||||
SDL_DestroySurface(dst);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -825,7 +759,7 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
||||
{
|
||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||
|
||||
|
||||
bool supportedFormat;
|
||||
SceGxmTextureFormat gxmTextureFormat;
|
||||
size_t textureSize;
|
||||
@ -846,7 +780,7 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
||||
&paletteOffset
|
||||
);
|
||||
|
||||
if(!supportedFormat) {
|
||||
if (!supportedFormat) {
|
||||
return NO_TEXTURE_ID;
|
||||
}
|
||||
|
||||
@ -855,14 +789,15 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
||||
if (tex.texture == texture) {
|
||||
if (tex.version != texture->m_version) {
|
||||
void* textureData = sceGxmTextureGetData(&tex.gxmTexture);
|
||||
copySurfaceToGxm(surface, (uint8_t*)textureData, textureStride, textureSize);
|
||||
copySurfaceToGxm(surface, (uint8_t*) textureData, textureStride, textureSize);
|
||||
tex.version = texture->m_version;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
sceClibPrintf("Create Texture %s w=%d h=%d s=%d size=%d align=%d\n",
|
||||
DEBUG_ONLY_PRINTF(
|
||||
"Create Texture %s w=%d h=%d s=%d size=%d align=%d\n",
|
||||
SDL_GetPixelFormatName(surface->m_surface->format),
|
||||
textureWidth,
|
||||
textureHeight,
|
||||
@ -873,24 +808,16 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
||||
|
||||
// allocate gpu memory
|
||||
void* textureData = cdram_alloc(textureSize, textureAlignment);
|
||||
copySurfaceToGxm(surface, (uint8_t*)textureData, textureStride, textureSize);
|
||||
copySurfaceToGxm(surface, (uint8_t*) textureData, textureStride, textureSize);
|
||||
|
||||
SceGxmTexture gxmTexture;
|
||||
SCE_ERR(
|
||||
sceGxmTextureInitLinear,
|
||||
&gxmTexture,
|
||||
textureData,
|
||||
gxmTextureFormat,
|
||||
textureWidth,
|
||||
textureHeight,
|
||||
0
|
||||
);
|
||||
SCE_ERR(sceGxmTextureInitLinear, &gxmTexture, textureData, gxmTextureFormat, textureWidth, textureHeight, 0);
|
||||
sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
||||
sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
||||
sceGxmTextureSetUAddrMode(&gxmTexture, SCE_GXM_TEXTURE_ADDR_REPEAT);
|
||||
sceGxmTextureSetVAddrMode(&gxmTexture, SCE_GXM_TEXTURE_ADDR_REPEAT);
|
||||
if (gxmTextureFormat == SCE_GXM_TEXTURE_FORMAT_P8_ABGR) {
|
||||
sceGxmTextureSetPalette(&gxmTexture, (uint8_t*)textureData + paletteOffset);
|
||||
sceGxmTextureSetPalette(&gxmTexture, (uint8_t*) textureData + paletteOffset);
|
||||
}
|
||||
|
||||
for (Uint32 i = 0; i < m_textures.size(); ++i) {
|
||||
@ -1044,30 +971,31 @@ void GXMRenderer::StartScene()
|
||||
bool dpad_right = SDL_GetGamepadButton(this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_RIGHT);
|
||||
|
||||
// hud display
|
||||
if(with_razor_hud && dpad_up != this->button_dpad_up) {
|
||||
if (with_razor_hud && dpad_up != this->button_dpad_up) {
|
||||
this->button_dpad_up = dpad_up;
|
||||
if(dpad_up) {
|
||||
if (dpad_up) {
|
||||
sceRazorHudSetDisplayEnabled(razor_display_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
// capture frame
|
||||
if(with_razor && dpad_down != this->button_dpad_down) {
|
||||
if (with_razor && dpad_down != this->button_dpad_down) {
|
||||
this->button_dpad_down = dpad_down;
|
||||
if(dpad_down) {
|
||||
if (dpad_down) {
|
||||
sceRazorGpuCaptureSetTriggerNextFrame("ux0:/data/capture.sgx");
|
||||
SDL_Log("trigger razor");
|
||||
}
|
||||
}
|
||||
|
||||
// toggle live
|
||||
if(with_razor_hud && dpad_left != this->button_dpad_left) {
|
||||
if (with_razor_hud && dpad_left != this->button_dpad_left) {
|
||||
this->button_dpad_left = dpad_left;
|
||||
if(dpad_left) {
|
||||
if(razor_live_started) {
|
||||
if (dpad_left) {
|
||||
if (razor_live_started) {
|
||||
sceRazorGpuLiveStop();
|
||||
razor_live_started = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sceRazorGpuLiveStart();
|
||||
razor_live_started = true;
|
||||
}
|
||||
@ -1075,9 +1003,9 @@ void GXMRenderer::StartScene()
|
||||
}
|
||||
|
||||
// trigger trace
|
||||
if(with_razor_hud && dpad_right != this->button_dpad_right) {
|
||||
if (with_razor_hud && dpad_right != this->button_dpad_right) {
|
||||
this->button_dpad_right = dpad_right;
|
||||
if(dpad_right) {
|
||||
if (dpad_right) {
|
||||
sceRazorGpuTraceTrigger();
|
||||
}
|
||||
}
|
||||
@ -1099,7 +1027,6 @@ void GXMRenderer::StartScene()
|
||||
sceGxmNotificationWait(&this->fragmentNotifications[this->currentFragmentBufferIndex]);
|
||||
}
|
||||
|
||||
|
||||
HRESULT GXMRenderer::BeginFrame()
|
||||
{
|
||||
this->transparencyEnabled = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user