mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 15:45:19 +00:00
Merge pull request #7963 from fjtrujy/feature/PS2GFXImprovements
Improve manage of VRAM in the GFX and Font Driver for PS2
This commit is contained in:
commit
96b7f9fd9e
@ -33,6 +33,7 @@ typedef struct ps2_video
|
|||||||
GSGLOBAL *gsGlobal;
|
GSGLOBAL *gsGlobal;
|
||||||
GSTEXTURE *menuTexture;
|
GSTEXTURE *menuTexture;
|
||||||
GSTEXTURE *coreTexture;
|
GSTEXTURE *coreTexture;
|
||||||
|
bool clearVRAM;
|
||||||
|
|
||||||
bool menuVisible;
|
bool menuVisible;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
@ -89,8 +90,7 @@ static void deinitTexture(GSTEXTURE *texture) {
|
|||||||
texture->Clut = NULL;
|
texture->Clut = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void color_correction32(uint32_t *buffer, uint32_t dimensions)
|
static void color_correction32(uint32_t *buffer, uint32_t dimensions) {
|
||||||
{
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t x32;
|
uint32_t x32;
|
||||||
for (i = 0; i < dimensions; i++) {
|
for (i = 0; i < dimensions; i++) {
|
||||||
@ -99,8 +99,7 @@ static void color_correction32(uint32_t *buffer, uint32_t dimensions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void color_correction16(uint16_t *buffer, uint32_t dimensions)
|
static void color_correction16(uint16_t *buffer, uint32_t dimensions) {
|
||||||
{
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint16_t x16;
|
uint16_t x16;
|
||||||
for (i = 0; i < dimensions; i++) {
|
for (i = 0; i < dimensions; i++) {
|
||||||
@ -109,35 +108,34 @@ static void color_correction16(uint16_t *buffer, uint32_t dimensions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool texture_need_prepare(GSTEXTURE *texture, int width, int height, int PSM, int filter) {
|
||||||
|
return !texture->Mem || texture->Width != width || texture->Height != height || texture->PSM != PSM;
|
||||||
|
}
|
||||||
|
|
||||||
static void transfer_texture(GSTEXTURE *texture, const void *frame,
|
static void transfer_texture(GSTEXTURE *texture, const void *frame,
|
||||||
int width, int height, bool rgb32, int filter, bool color_correction) {
|
int width, int height, bool rgb32, int filter, bool color_correction) {
|
||||||
|
|
||||||
int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16;
|
int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16;
|
||||||
size_t size = gsKit_texture_size_ee(width, height, PSM);
|
bool changed = texture_need_prepare(texture, width, height, rgb32, PSM);
|
||||||
if ( !texture->Mem ||
|
|
||||||
texture->Width != width ||
|
if (color_correction) {
|
||||||
texture->Height != height ||
|
int pixels = width * height;
|
||||||
texture->PSM != PSM ) {
|
if (rgb32) {
|
||||||
|
uint32_t *buffer = (uint32_t *)frame;
|
||||||
|
color_correction32(buffer, pixels);
|
||||||
|
} else {
|
||||||
|
uint16_t *buffer = (uint16_t *)frame;
|
||||||
|
color_correction16(buffer, pixels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
texture->Width = width;
|
texture->Width = width;
|
||||||
texture->Height = height;
|
texture->Height = height;
|
||||||
texture->PSM = PSM;
|
texture->PSM = PSM;
|
||||||
texture->Filter = filter;
|
texture->Filter = filter;
|
||||||
free(texture->Mem);
|
|
||||||
texture->Mem = memalign(128, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (color_correction) {
|
|
||||||
int pixels = width * height;
|
|
||||||
if (rgb32) {
|
|
||||||
uint32_t *buffer = (uint32_t *)frame;
|
|
||||||
color_correction32(buffer, pixels);
|
|
||||||
} else {
|
|
||||||
uint16_t *buffer = (uint16_t *)frame;
|
|
||||||
color_correction16(buffer, pixels);
|
|
||||||
}
|
}
|
||||||
}
|
texture->Mem = (void *)frame;
|
||||||
|
|
||||||
memcpy(texture->Mem, frame, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) {
|
static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) {
|
||||||
@ -182,6 +180,22 @@ static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition,
|
|||||||
GS_TEXT);
|
GS_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clearVRAMIfNeeded(ps2_video_t *ps2, int width, int height) {
|
||||||
|
int PSM = ps2->rgb32 ? GS_PSM_CT32 : GS_PSM_CT16;
|
||||||
|
bool coreVRAMClear = texture_need_prepare(ps2->coreTexture, width, height, PSM, ps2->core_filter);
|
||||||
|
ps2->clearVRAM = ps2->clearVRAM || coreVRAMClear;
|
||||||
|
if (ps2->clearVRAM) {
|
||||||
|
gsKit_clear(ps2->gsGlobal, GS_BLACK);
|
||||||
|
gsKit_vram_clear(ps2->gsGlobal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void refreshScreen(ps2_video_t *ps2) {
|
||||||
|
gsKit_sync_flip(ps2->gsGlobal);
|
||||||
|
gsKit_queue_exec(ps2->gsGlobal);
|
||||||
|
|
||||||
|
ps2->clearVRAM = false;
|
||||||
|
}
|
||||||
static void *ps2_gfx_init(const video_info_t *video,
|
static void *ps2_gfx_init(const video_info_t *video,
|
||||||
const input_driver_t **input, void **input_data)
|
const input_driver_t **input, void **input_data)
|
||||||
{
|
{
|
||||||
@ -217,12 +231,6 @@ static bool ps2_gfx_frame(void *data, const void *frame,
|
|||||||
unsigned width, unsigned height, uint64_t frame_count,
|
unsigned width, unsigned height, uint64_t frame_count,
|
||||||
unsigned pitch, const char *msg, video_frame_info_t *video_info)
|
unsigned pitch, const char *msg, video_frame_info_t *video_info)
|
||||||
{
|
{
|
||||||
#ifdef DISPLAY_FPS
|
|
||||||
uint32_t diff;
|
|
||||||
static uint64_t currentTick,lastTick;
|
|
||||||
static int frames;
|
|
||||||
static float fps = 0.0;
|
|
||||||
#endif
|
|
||||||
ps2_video_t *ps2 = (ps2_video_t*)data;
|
ps2_video_t *ps2 = (ps2_video_t*)data;
|
||||||
|
|
||||||
if (!width || !height)
|
if (!width || !height)
|
||||||
@ -231,12 +239,14 @@ static bool ps2_gfx_frame(void *data, const void *frame,
|
|||||||
if (frame_count%120==0) {
|
if (frame_count%120==0) {
|
||||||
printf("ps2_gfx_frame %lu\n", frame_count);
|
printf("ps2_gfx_frame %lu\n", frame_count);
|
||||||
}
|
}
|
||||||
gsKit_clear(ps2->gsGlobal, GS_BLACK);
|
|
||||||
gsKit_vram_clear(ps2->gsGlobal);
|
clearVRAMIfNeeded(ps2, width, height);
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, ps2->core_filter, 1);
|
transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, ps2->core_filter, 1);
|
||||||
vram_alloc(ps2->gsGlobal, ps2->coreTexture);
|
if(ps2->clearVRAM) {
|
||||||
|
vram_alloc(ps2->gsGlobal, ps2->coreTexture);
|
||||||
|
}
|
||||||
gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture);
|
gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture);
|
||||||
prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect);
|
prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect);
|
||||||
}
|
}
|
||||||
@ -244,7 +254,9 @@ static bool ps2_gfx_frame(void *data, const void *frame,
|
|||||||
if (ps2->menuVisible) {
|
if (ps2->menuVisible) {
|
||||||
bool texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height;
|
bool texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height;
|
||||||
if (!texture_empty) {
|
if (!texture_empty) {
|
||||||
vram_alloc(ps2->gsGlobal, ps2->menuTexture);
|
if(ps2->clearVRAM) {
|
||||||
|
vram_alloc(ps2->gsGlobal, ps2->menuTexture);
|
||||||
|
}
|
||||||
gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture);
|
gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture);
|
||||||
prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen);
|
prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen);
|
||||||
}
|
}
|
||||||
@ -262,8 +274,7 @@ static bool ps2_gfx_frame(void *data, const void *frame,
|
|||||||
font_driver_render_msg(video_info, NULL, msg, NULL);
|
font_driver_render_msg(video_info, NULL, msg, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gsKit_sync_flip(ps2->gsGlobal);
|
refreshScreen(ps2);
|
||||||
gsKit_queue_exec(ps2->gsGlobal);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -369,8 +380,13 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32,
|
|||||||
unsigned width, unsigned height, float alpha)
|
unsigned width, unsigned height, float alpha)
|
||||||
{
|
{
|
||||||
ps2_video_t *ps2 = (ps2_video_t*)data;
|
ps2_video_t *ps2 = (ps2_video_t*)data;
|
||||||
|
|
||||||
transfer_texture(ps2->menuTexture, frame, width, height, rgb32, ps2->menu_filter, 0);
|
bool color_correction = false;
|
||||||
|
int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16;
|
||||||
|
bool texture_changed = texture_need_prepare(ps2->menuTexture, width, height, rgb32, PSM);
|
||||||
|
|
||||||
|
transfer_texture(ps2->menuTexture, frame, width, height, rgb32, ps2->menu_filter, color_correction);
|
||||||
|
ps2->clearVRAM = texture_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen)
|
static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen)
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
typedef struct ps2_font_info
|
typedef struct ps2_font_info
|
||||||
{
|
{
|
||||||
GSGLOBAL *gsGlobal;
|
ps2_video_t *ps2_video;
|
||||||
GSFONTM *gsFontM;
|
GSFONTM *gsFontM;
|
||||||
} ps2_font_info_t;
|
} ps2_font_info_t;
|
||||||
|
|
||||||
@ -80,11 +80,11 @@ static void *ps2_font_init_font(void *gl_data, const char *font_path,
|
|||||||
float font_size, bool is_threaded)
|
float font_size, bool is_threaded)
|
||||||
{
|
{
|
||||||
ps2_font_info_t *ps2 = (ps2_font_info_t*)calloc(1, sizeof(ps2_font_info_t));
|
ps2_font_info_t *ps2 = (ps2_font_info_t*)calloc(1, sizeof(ps2_font_info_t));
|
||||||
ps2_video_t *ps2_video = (ps2_video_t *)gl_data;
|
ps2->ps2_video = (ps2_video_t *)gl_data;
|
||||||
ps2->gsGlobal = ps2_video->gsGlobal;
|
|
||||||
ps2->gsFontM = gsKit_init_fontm();
|
ps2->gsFontM = gsKit_init_fontm();
|
||||||
|
|
||||||
ps2_prepare_font(ps2->gsGlobal, ps2->gsFontM);
|
ps2_prepare_font(ps2->ps2_video->gsGlobal, ps2->gsFontM);
|
||||||
|
ps2_upload_font(ps2->ps2_video->gsGlobal, ps2->gsFontM);
|
||||||
|
|
||||||
return ps2;
|
return ps2;
|
||||||
}
|
}
|
||||||
@ -105,9 +105,11 @@ static void ps2_font_render_msg(
|
|||||||
|
|
||||||
if (ps2) {
|
if (ps2) {
|
||||||
int x = FONTM_TEXTURE_LEFT_MARGIN;
|
int x = FONTM_TEXTURE_LEFT_MARGIN;
|
||||||
int y = ps2->gsGlobal->Height - FONTM_TEXTURE_BOTTOM_MARGIN;
|
int y = ps2->ps2_video->gsGlobal->Height - FONTM_TEXTURE_BOTTOM_MARGIN;
|
||||||
ps2_upload_font(ps2->gsGlobal, ps2->gsFontM);
|
if (ps2->ps2_video->clearVRAM) {
|
||||||
gsKit_fontm_print_scaled(ps2->gsGlobal, ps2->gsFontM, x, y, FONTM_TEXTURE_ZPOSITION,
|
ps2_upload_font(ps2->ps2_video->gsGlobal, ps2->gsFontM);
|
||||||
|
}
|
||||||
|
gsKit_fontm_print_scaled(ps2->ps2_video->gsGlobal, ps2->gsFontM, x, y, FONTM_TEXTURE_ZPOSITION,
|
||||||
FONTM_TEXTURE_SCALED , FONTM_TEXTURE_COLOR, msg);
|
FONTM_TEXTURE_SCALED , FONTM_TEXTURE_COLOR, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user