From 581b9e0b0d178ff662e1d521c2f362f28f84f4bb Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Thu, 23 Feb 2023 16:11:01 +0100 Subject: [PATCH] (RSX) Updates to video driver --- gfx/common/rsx_common.h | 56 ++--- gfx/drivers/rsx_gfx.c | 166 +++++++------- gfx/drivers_font/rsx_font.c | 202 ++++++++++-------- libretro-common/include/defines/ps3_defines.h | 4 + 4 files changed, 237 insertions(+), 191 deletions(-) diff --git a/gfx/common/rsx_common.h b/gfx/common/rsx_common.h index 4bdcd239a4..9c4481b1bb 100644 --- a/gfx/common/rsx_common.h +++ b/gfx/common/rsx_common.h @@ -17,15 +17,18 @@ #ifndef RSX_COMMON_H__ #define RSX_COMMON_H__ -#include -#include -#include - #include #include #include #include + +#ifdef __PSL1GHT__ +#include +#include +#include +#endif + #include "../../driver.h" #include "../../retroarch.h" #include "../video_coord_array.h" @@ -35,7 +38,7 @@ #define RSX_MAX_TEXTURES 4 #define RSX_MAX_SHADERS 2 #define RSX_MAX_VERTICES 4 -#define RSX_MAX_TEXTURE_VERTICES 4096 // Set > 0 for preallocated texture vertices +#define RSX_MAX_TEXTURE_VERTICES 4096 /* Set > 0 for preallocated texture vertices */ #define RSX_MAX_FONT_VERTICES 8192 #define RSX_SHADER_STOCK_BLEND (RSX_MAX_SHADERS - 1) @@ -95,7 +98,8 @@ typedef struct uint32_t offset; } rsxBuffer; -typedef struct { +typedef struct +{ video_viewport_t vp; rsxBuffer buffers[RSX_MAX_BUFFERS]; #if defined(HAVE_MENU_BUFFER) @@ -104,15 +108,6 @@ typedef struct { #endif int currentBuffer, nextBuffer; gcmContextData* context; - u16 width; - u16 height; - u16 menu_width; - u16 menu_height; - bool menu_frame_enable; - bool rgb32; - bool vsync; - u32 depth_pitch; - u32 depth_offset; u32* depth_buffer; #if defined(HAVE_MENU_BUFFER) @@ -120,11 +115,11 @@ typedef struct { #else gcmSurface surface[RSX_MAX_BUFFERS]; #endif - int tex_index; rsx_texture_t texture[RSX_MAX_TEXTURES]; rsx_texture_t menu_texture; rsx_vertex_t *vertices; rsx_vertex_t *texture_vertices; + int tex_index; int vert_idx; int texture_vert_idx; int font_vert_idx; @@ -144,22 +139,33 @@ typedef struct { u32 *fp_buffer[RSX_MAX_SHADERS]; u32 fp_offset[RSX_MAX_SHADERS]; math_matrix_4x4 mvp, mvp_no_rot; - float menu_texture_alpha; - - bool smooth; - unsigned rotation; - bool keep_aspect; - bool should_resize; - bool msg_rendering_enabled; - const shader_backend_t* shader; void* shader_data; void* renderchain_data; void* ctx_data; const gfx_ctx_driver_t* ctx_driver; - bool shared_context_use; video_info_t video_info; + + float menu_texture_alpha; + + unsigned rotation; + + u16 width; + u16 height; + u16 menu_width; + u16 menu_height; + u32 depth_pitch; + u32 depth_offset; + + bool menu_frame_enable; + bool rgb32; + bool vsync; + bool smooth; + bool keep_aspect; + bool should_resize; + bool msg_rendering_enabled; + bool shared_context_use; } rsx_t; #endif diff --git a/gfx/drivers/rsx_gfx.c b/gfx/drivers/rsx_gfx.c index c59e612106..ed0e028d56 100644 --- a/gfx/drivers/rsx_gfx.c +++ b/gfx/drivers/rsx_gfx.c @@ -16,6 +16,10 @@ #include #include #include +#include + +#include +#include #include #include @@ -50,24 +54,19 @@ #include -#include -#include -#include - #define CB_SIZE 0x100000 #define HOST_SIZE (32*1024*1024) +#ifdef __PSL1GHT__ +#include +#include +#include #include -#include -#include -#include -#include #include #include #include #include -#include -#include +#endif #define rsx_context_bind_hw_render(rsx, enable) \ if (rsx->shared_context_use) \ @@ -83,15 +82,19 @@ static void rsx_load_texture_data(rsx_t* rsx, rsx_texture_t *texture, if (!texture->data) { - texture->data = (u32 *)rsxMemalign(128, texture->height * pitch); + texture->data = (u32*)rsxMemalign(128, texture->height * pitch); rsxAddressToOffset(texture->data, &texture->offset); } texbuffer = (u8*)texture->data; memcpy(texbuffer, data, height * pitch); - texture->tex.format = (rgb32 ? GCM_TEXTURE_FORMAT_A8R8G8B8 : - menu ? GCM_TEXTURE_FORMAT_A4R4G4B4 : GCM_TEXTURE_FORMAT_R5G6B5) | GCM_TEXTURE_FORMAT_LIN; + texture->tex.format = (rgb32 + ? GCM_TEXTURE_FORMAT_A8R8G8B8 : + (menu) + ? GCM_TEXTURE_FORMAT_A4R4G4B4 + : GCM_TEXTURE_FORMAT_R5G6B5) + | GCM_TEXTURE_FORMAT_LIN; texture->tex.mipmap = 1; texture->tex.dimension = GCM_TEXTURE_DIMS_2D; texture->tex.cubemap = GCM_FALSE; @@ -300,9 +303,9 @@ task_finder_data_t rsx_tasks_finder_data = {rsx_tasks_finder, NULL}; static int rsx_make_buffer(rsxBuffer * buffer, u16 width, u16 height, int id) { - int depth = sizeof(u32); - int pitch = depth * width; - int size = depth * width * height; + int depth = sizeof(u32); + int pitch = depth * width; + int size = depth * width * height; if (!(buffer->ptr = (uint32_t*)rsxMemalign (64, size))) goto error; @@ -381,8 +384,8 @@ static gcmContextData *rsx_init_screen(rsx_t* gcm) if (!saved_context) { - /* Allocate a 1Mb buffer, alligned to a 1Mb boundary - * to be our shared IO memory with the RSX. */ + /* Allocate a 1MB buffer, alligned to a 1MB boundary + * to be our shared I/O memory with the RSX. */ void *host_addr = memalign(1024*1024, HOST_SIZE); if (!host_addr) @@ -391,7 +394,7 @@ static gcmContextData *rsx_init_screen(rsx_t* gcm) /* Initialise Reality, which sets up the * command buffer and shared I/O memory */ #ifdef NV40TCL_RENDER_ENABLE - /* There was an api breakage on 2020-07-10, let's + /* There was an API breakage on 2020-07-10, let's * workaround this by using one of the new defines */ rsxInit(&context, CB_SIZE, HOST_SIZE, host_addr); #else @@ -486,44 +489,44 @@ static void rsx_init_render_target(rsx_t *rsx, rsxBuffer * buffer, int id) static void rsx_init_vertices(rsx_t *rsx) { - rsx->vertices = (rsx_vertex_t *)rsxMemalign(128, sizeof(rsx_vertex_t) * RSX_MAX_VERTICES); /* vertices for menu and core */ - rsx->vert_idx = 0; + rsx->vertices = (rsx_vertex_t *)rsxMemalign(128, sizeof(rsx_vertex_t) * RSX_MAX_VERTICES); /* vertices for menu and core */ + rsx->vert_idx = 0; - rsx->vertices[0].x = 0.0f; - rsx->vertices[0].y = 0.0f; - rsx->vertices[0].u = 0.0f; - rsx->vertices[0].v = 1.0f; - rsx->vertices[0].r = 1.0f; - rsx->vertices[0].g = 1.0f; - rsx->vertices[0].b = 1.0f; - rsx->vertices[0].a = 1.0f; + rsx->vertices[0].x = 0.0f; + rsx->vertices[0].y = 0.0f; + rsx->vertices[0].u = 0.0f; + rsx->vertices[0].v = 1.0f; + rsx->vertices[0].r = 1.0f; + rsx->vertices[0].g = 1.0f; + rsx->vertices[0].b = 1.0f; + rsx->vertices[0].a = 1.0f; - rsx->vertices[1].x = 1.0f; - rsx->vertices[1].y = 0.0f; - rsx->vertices[1].u = 1.0f; - rsx->vertices[1].v = 1.0f; - rsx->vertices[1].r = 1.0f; - rsx->vertices[1].g = 1.0f; - rsx->vertices[1].b = 1.0f; - rsx->vertices[1].a = 1.0f; + rsx->vertices[1].x = 1.0f; + rsx->vertices[1].y = 0.0f; + rsx->vertices[1].u = 1.0f; + rsx->vertices[1].v = 1.0f; + rsx->vertices[1].r = 1.0f; + rsx->vertices[1].g = 1.0f; + rsx->vertices[1].b = 1.0f; + rsx->vertices[1].a = 1.0f; - rsx->vertices[2].x = 0.0f; - rsx->vertices[2].y = 1.0f; - rsx->vertices[2].u = 0.0f; - rsx->vertices[2].v = 0.0f; - rsx->vertices[2].r = 1.0f; - rsx->vertices[2].g = 1.0f; - rsx->vertices[2].b = 1.0f; - rsx->vertices[2].a = 1.0f; + rsx->vertices[2].x = 0.0f; + rsx->vertices[2].y = 1.0f; + rsx->vertices[2].u = 0.0f; + rsx->vertices[2].v = 0.0f; + rsx->vertices[2].r = 1.0f; + rsx->vertices[2].g = 1.0f; + rsx->vertices[2].b = 1.0f; + rsx->vertices[2].a = 1.0f; - rsx->vertices[3].x = 1.0f; - rsx->vertices[3].y = 1.0f; - rsx->vertices[3].u = 1.0f; - rsx->vertices[3].v = 0.0f; - rsx->vertices[3].r = 1.0f; - rsx->vertices[3].g = 1.0f; - rsx->vertices[3].b = 1.0f; - rsx->vertices[3].a = 1.0f; + rsx->vertices[3].x = 1.0f; + rsx->vertices[3].y = 1.0f; + rsx->vertices[3].u = 1.0f; + rsx->vertices[3].v = 0.0f; + rsx->vertices[3].r = 1.0f; + rsx->vertices[3].g = 1.0f; + rsx->vertices[3].b = 1.0f; + rsx->vertices[3].a = 1.0f; #if RSX_MAX_TEXTURE_VERTICES > 0 /* Using preallocated texture vertices */ @@ -534,18 +537,18 @@ static void rsx_init_vertices(rsx_t *rsx) static void rsx_init_shader(rsx_t *rsx) { - u32 fpsize = 0; - u32 vpsize = 0; + u32 fpsize = 0; + u32 vpsize = 0; rsx->vp_ucode[RSX_SHADER_MENU] = NULL; rsx->fp_ucode[RSX_SHADER_MENU] = NULL; - rsx->vpo[RSX_SHADER_MENU] = (rsxVertexProgram *)modern_opaque_vpo; - rsx->fpo[RSX_SHADER_MENU] = (rsxFragmentProgram *)modern_opaque_fpo; - rsxVertexProgramGetUCode(rsx->vpo[RSX_SHADER_MENU], &rsx->vp_ucode[RSX_SHADER_MENU], &vpsize); + rsx->vpo[RSX_SHADER_MENU] = (rsxVertexProgram*)modern_opaque_vpo; + rsx->fpo[RSX_SHADER_MENU] = (rsxFragmentProgram*)modern_opaque_fpo; + rsxVertexProgramGetUCode( rsx->vpo[RSX_SHADER_MENU], &rsx->vp_ucode[RSX_SHADER_MENU], &vpsize); rsxFragmentProgramGetUCode(rsx->fpo[RSX_SHADER_MENU], &rsx->fp_ucode[RSX_SHADER_MENU], &fpsize); - rsx->fp_buffer[RSX_SHADER_MENU] = (u32 *)rsxMemalign(64, fpsize); + rsx->fp_buffer[RSX_SHADER_MENU] = (u32*)rsxMemalign(64, fpsize); if (!rsx->fp_buffer[RSX_SHADER_MENU]) { - RARCH_LOG("failed to allocate fp_buffer\n"); + RARCH_ERR("failed to allocate fp_buffer\n"); return; } memcpy(rsx->fp_buffer[RSX_SHADER_MENU], rsx->fp_ucode[RSX_SHADER_MENU], fpsize); @@ -565,7 +568,7 @@ static void rsx_init_shader(rsx_t *rsx) rsx->fp_buffer[RSX_SHADER_STOCK_BLEND] = (u32 *)rsxMemalign(64, fpsize); if (!rsx->fp_buffer[RSX_SHADER_STOCK_BLEND]) { - RARCH_LOG("failed to allocate fp_buffer\n"); + RARCH_ERR("failed to allocate fp_buffer\n"); return; } memcpy(rsx->fp_buffer[RSX_SHADER_STOCK_BLEND], rsx->fp_ucode[RSX_SHADER_STOCK_BLEND], fpsize); @@ -582,7 +585,8 @@ static void* rsx_init(const video_info_t* video, input_driver_t** input, void** input_data) { int i; - rsx_t* rsx = malloc(sizeof(rsx_t)); + const gfx_ctx_driver_t* ctx_driver = NULL; + rsx_t* rsx = (rsx_t*)malloc(sizeof(rsx_t)); if (!rsx) return NULL; @@ -590,10 +594,12 @@ static void* rsx_init(const video_info_t* video, memset(rsx, 0, sizeof(rsx_t)); rsx->context = rsx_init_screen(rsx); - const gfx_ctx_driver_t* ctx_driver = rsx_get_context(rsx); - if (!ctx_driver) + if (!(ctx_driver = rsx_get_context(rsx))) + { + free(rsx); return NULL; + } video_context_driver_set((const gfx_ctx_driver_t*)ctx_driver); rsx->ctx_driver = ctx_driver; @@ -875,9 +881,10 @@ static void rsx_blit_buffer( int j, l; for (j = 0; j < width; j++, src++) { + int k; u32 c = *src; - for (int k = 0; k < scale; k++, dst++) - for (int l = 0; l < scale; l++) + for (k = 0; k < scale; k++, dst++) + for (l = 0; l < scale; l++) dst[l * buffer->width] = c; } for (l = 0; l < scale; l++) @@ -886,13 +893,16 @@ static void rsx_blit_buffer( dst += buffer->width * scale - width * scale; src += pitch / 4 - width; } - } else { + } + else + { const uint16_t *src = frame; for (i = 0; i < height; i++) { - for (int j = 0; j < width; j++, src++) + int j, l; + for (j = 0; j < width; j++, src++) { - int k, l; + int k; u16 rgb565 = *src; u8 r = ((rgb565 >> 8) & 0xf8); u8 g = ((rgb565 >> 3) & 0xfc); @@ -902,7 +912,7 @@ static void rsx_blit_buffer( for (l = 0; l < scale; l++) dst[l * buffer->width] = c; } - for (int l = 0; l < scale; l++) + for (l = 0; l < scale; l++) rsx_fill_black(dst + l * buffer->width, dst_end, buffer->width - width * scale); dst += buffer->width * scale - width * scale; @@ -1085,7 +1095,7 @@ static void rsx_draw_menu_vertices(rsx_t* rsx) rsxAddressToOffset(&vertices[rsx->vert_idx].x, &rsx->pos_offset[RSX_SHADER_STOCK_BLEND]); rsxAddressToOffset(&vertices[rsx->vert_idx].u, &rsx->uv_offset[RSX_SHADER_STOCK_BLEND]); rsxAddressToOffset(&vertices[rsx->vert_idx].r, &rsx->col_offset[RSX_SHADER_STOCK_BLEND]); - rsx->vert_idx = end_vert_idx; + rsx->vert_idx = end_vert_idx; rsxBindVertexArrayAttrib(rsx->context, rsx->pos_index[RSX_SHADER_STOCK_BLEND]->index, 0, rsx->pos_offset[RSX_SHADER_STOCK_BLEND], sizeof(rsx_vertex_t), 2, GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); @@ -1116,20 +1126,16 @@ static void rsx_update_screen(rsx_t* gcm) if (gcm->menu_frame_enable) { buffer = &gcm->menuBuffers[gcm->menuBuffer]; - gcm->menuBuffer = (gcm->menuBuffer+1)%RSX_MAX_MENU_BUFFERS; + gcm->menuBuffer = (gcm->menuBuffer + 1) % RSX_MAX_MENU_BUFFERS; gcm->nextBuffer = RSX_MAX_BUFFERS + gcm->menuBuffer; } else +#endif { buffer = &gcm->buffers[gcm->currentBuffer]; - gcm->currentBuffer = (gcm->currentBuffer+1)%RSX_MAX_BUFFERS; + gcm->currentBuffer = (gcm->currentBuffer + 1) % RSX_MAX_BUFFERS; gcm->nextBuffer = gcm->currentBuffer; } -#else - buffer = &gcm->buffers[gcm->currentBuffer]; - gcm->currentBuffer = (gcm->currentBuffer+1)%RSX_MAX_BUFFERS; - gcm->nextBuffer = gcm->currentBuffer; -#endif rsx_flip(gcm->context, buffer->id); if (gcm->vsync) @@ -1182,6 +1188,8 @@ static bool rsx_frame(void* data, const void* frame, gcm->tex_index = ((gcm->tex_index + 1) % RSX_MAX_TEXTURES); rsx_load_texture_data(gcm, &gcm->texture[gcm->tex_index], frame, width, height, pitch, gcm->rgb32, false, gcm->smooth ? TEXTURE_FILTER_LINEAR : TEXTURE_FILTER_NEAREST); + /* TODO/FIXME - pipeline ID being used here is RSX_SHADER_MENU, shouldn't + * this be RSX_SHADER_STOCK_BLEND instead? */ rsx_set_texture(gcm, &gcm->texture[gcm->tex_index]); rsx_draw_vertices(gcm); draw = true; @@ -1193,6 +1201,8 @@ static bool rsx_frame(void* data, const void* frame, menu_driver_frame(menu_is_alive, video_info); if (gcm->menu_texture.data) { + /* TODO/FIXME - pipeline ID being used here is RSX_SHADER_STOCK_BLEND, shouldn't + * this be RSX_SHADER_MENU instead? */ rsx_set_menu_texture(gcm, &gcm->menu_texture); rsx_draw_menu_vertices(gcm); draw = true; diff --git a/gfx/drivers_font/rsx_font.c b/gfx/drivers_font/rsx_font.c index bfa39eb79e..ef3264aba6 100644 --- a/gfx/drivers_font/rsx_font.c +++ b/gfx/drivers_font/rsx_font.c @@ -14,16 +14,18 @@ */ #include +#include + +#ifdef __PSL1GHT__ #include #include #include - -#include - -#include "../common/rsx_common.h" +#endif #include "../font_driver.h" +#include "../common/rsx_common.h" + #include "../../configuration.h" #define RSX_FONT_EMIT(c, vx, vy) \ @@ -43,8 +45,6 @@ typedef struct rsx_t *rsx; rsx_vertex_t *vertices; rsx_texture_t texture; - u32 tex_width; - u32 tex_height; rsxProgramConst *proj_matrix; rsxProgramAttrib *pos_index; rsxProgramAttrib *uv_index; @@ -52,16 +52,18 @@ typedef struct rsxProgramAttrib *tex_unit; rsxVertexProgram* vpo; rsxFragmentProgram* fpo; - u32 fp_offset; - u32 pos_offset; - u32 uv_offset; - u32 col_offset; void *vp_ucode; void *fp_ucode; const font_renderer_driver_t *font_driver; void *font_data; struct font_atlas *atlas; video_font_raster_block_t *block; + u32 tex_width; + u32 tex_height; + u32 fp_offset; + u32 pos_offset; + u32 uv_offset; + u32 col_offset; } rsx_font_t; static void rsx_font_free(void *data, @@ -97,38 +99,44 @@ static void rsx_font_free(void *data, static bool rsx_font_upload_atlas(rsx_font_t *font) { - u8 *texbuffer = (u8 *)font->texture.data; - const u8 *atlas_data = (u8 *)font->atlas->buffer; + u8 *texbuffer = (u8 *)font->texture.data; + const u8 *atlas_data = (u8 *)font->atlas->buffer; memcpy(texbuffer, atlas_data, font->atlas->height * font->atlas->width); - font->texture.tex.format = GCM_TEXTURE_FORMAT_B8 | GCM_TEXTURE_FORMAT_LIN; - font->texture.tex.mipmap = 1; - font->texture.tex.dimension = GCM_TEXTURE_DIMS_2D; - font->texture.tex.cubemap = GCM_FALSE; - font->texture.tex.remap = ((GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_B_SHIFT) | - (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_G_SHIFT) | - (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_R_SHIFT) | - (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_A_SHIFT) | - (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_B_SHIFT) | - (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_G_SHIFT) | - (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_R_SHIFT) | - (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_A_SHIFT)); - font->texture.tex.width = font->tex_width; - font->texture.tex.height = font->tex_height; - font->texture.tex.depth = 1; - font->texture.tex.pitch = font->tex_width; - font->texture.tex.location = GCM_LOCATION_RSX; - font->texture.tex.offset = font->texture.offset; - font->texture.wrap_s = GCM_TEXTURE_CLAMP_TO_EDGE; - font->texture.wrap_t = GCM_TEXTURE_CLAMP_TO_EDGE; - font->texture.min_filter = GCM_TEXTURE_LINEAR; - font->texture.mag_filter = GCM_TEXTURE_LINEAR; + font->texture.tex.format = GCM_TEXTURE_FORMAT_B8 | GCM_TEXTURE_FORMAT_LIN; + font->texture.tex.mipmap = 1; + font->texture.tex.dimension = GCM_TEXTURE_DIMS_2D; + font->texture.tex.cubemap = GCM_FALSE; + font->texture.tex.remap = ( + (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_B_SHIFT) + | (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_G_SHIFT) + | (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_R_SHIFT) + | (GCM_TEXTURE_REMAP_TYPE_REMAP << GCM_TEXTURE_REMAP_TYPE_A_SHIFT) + | (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_B_SHIFT) + | (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_G_SHIFT) + | (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_R_SHIFT) + | (GCM_TEXTURE_REMAP_COLOR_B << GCM_TEXTURE_REMAP_COLOR_A_SHIFT)); + font->texture.tex.width = font->tex_width; + font->texture.tex.height = font->tex_height; + font->texture.tex.depth = 1; + font->texture.tex.pitch = font->tex_width; + font->texture.tex.location = GCM_LOCATION_RSX; + font->texture.tex.offset = font->texture.offset; + font->texture.wrap_s = GCM_TEXTURE_CLAMP_TO_EDGE; + font->texture.wrap_t = GCM_TEXTURE_CLAMP_TO_EDGE; + font->texture.min_filter = GCM_TEXTURE_LINEAR; + font->texture.mag_filter = GCM_TEXTURE_LINEAR; rsxInvalidateTextureCache(font->rsx->context, GCM_INVALIDATE_TEXTURE); rsxLoadTexture(font->rsx->context, font->tex_unit->index, &font->texture.tex); - rsxTextureControl(font->rsx->context, font->tex_unit->index, GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); - rsxTextureFilter(font->rsx->context, font->tex_unit->index, 0, font->texture.min_filter, font->texture.mag_filter, GCM_TEXTURE_CONVOLUTION_QUINCUNX); - rsxTextureWrapMode(font->rsx->context, font->tex_unit->index, font->texture.wrap_s, font->texture.wrap_t, GCM_TEXTURE_CLAMP_TO_EDGE, 0, GCM_TEXTURE_ZFUNC_LESS, 0); + rsxTextureControl(font->rsx->context, font->tex_unit->index, + GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); + rsxTextureFilter(font->rsx->context, font->tex_unit->index, + 0, font->texture.min_filter, + font->texture.mag_filter, GCM_TEXTURE_CONVOLUTION_QUINCUNX); + rsxTextureWrapMode(font->rsx->context, font->tex_unit->index, + font->texture.wrap_s, font->texture.wrap_t, + GCM_TEXTURE_CLAMP_TO_EDGE, 0, GCM_TEXTURE_ZFUNC_LESS, 0); return true; } @@ -137,12 +145,12 @@ static void *rsx_font_init(void *data, const char *font_path, float font_size, bool is_threaded) { - rsx_font_t *font = (rsx_font_t*)calloc(1, sizeof(*font)); + rsx_font_t *font = (rsx_font_t*)calloc(1, sizeof(*font)); if (!font) return NULL; - font->rsx = (rsx_t *)data; + font->rsx = (rsx_t *)data; if (!font_renderer_create_default( &font->font_driver, @@ -154,31 +162,32 @@ static void *rsx_font_init(void *data, if (is_threaded) if ( - font->rsx && - font->rsx->ctx_driver && - font->rsx->ctx_driver->make_current) + font->rsx + && font->rsx->ctx_driver + && font->rsx->ctx_driver->make_current) font->rsx->ctx_driver->make_current(false); - font->atlas = font->font_driver->get_atlas(font->font_data); + font->atlas = font->font_driver->get_atlas(font->font_data); - font->vpo = font->rsx->vpo[RSX_SHADER_STOCK_BLEND]; - font->fpo = font->rsx->fpo[RSX_SHADER_STOCK_BLEND]; - font->fp_ucode = font->rsx->fp_ucode[RSX_SHADER_STOCK_BLEND]; - font->vp_ucode = font->rsx->vp_ucode[RSX_SHADER_STOCK_BLEND]; - font->fp_offset = font->rsx->fp_offset[RSX_SHADER_STOCK_BLEND]; + font->vpo = font->rsx->vpo[RSX_SHADER_STOCK_BLEND]; + font->fpo = font->rsx->fpo[RSX_SHADER_STOCK_BLEND]; + font->fp_ucode = font->rsx->fp_ucode[RSX_SHADER_STOCK_BLEND]; + font->vp_ucode = font->rsx->vp_ucode[RSX_SHADER_STOCK_BLEND]; + font->fp_offset = font->rsx->fp_offset[RSX_SHADER_STOCK_BLEND]; - font->proj_matrix = font->rsx->proj_matrix[RSX_SHADER_STOCK_BLEND]; - font->pos_index = font->rsx->pos_index[RSX_SHADER_STOCK_BLEND]; - font->uv_index = font->rsx->uv_index[RSX_SHADER_STOCK_BLEND]; - font->col_index = font->rsx->col_index[RSX_SHADER_STOCK_BLEND]; - font->tex_unit = font->rsx->tex_unit[RSX_SHADER_STOCK_BLEND]; + font->proj_matrix = font->rsx->proj_matrix[RSX_SHADER_STOCK_BLEND]; + font->pos_index = font->rsx->pos_index[RSX_SHADER_STOCK_BLEND]; + font->uv_index = font->rsx->uv_index[RSX_SHADER_STOCK_BLEND]; + font->col_index = font->rsx->col_index[RSX_SHADER_STOCK_BLEND]; + font->tex_unit = font->rsx->tex_unit[RSX_SHADER_STOCK_BLEND]; - font->vertices = (rsx_vertex_t *)rsxMemalign(128, sizeof(rsx_vertex_t) * RSX_MAX_FONT_VERTICES); + font->vertices = (rsx_vertex_t *)rsxMemalign(128, + sizeof(rsx_vertex_t) * RSX_MAX_FONT_VERTICES); font->rsx->font_vert_idx = 0; - font->tex_width = font->atlas->width; - font->tex_height = font->atlas->height; - font->texture.data = (u32 *)rsxMemalign(128, (font->tex_height * font->tex_width)); + font->tex_width = font->atlas->width; + font->tex_height = font->atlas->height; + font->texture.data = (u32*)rsxMemalign(128, (font->tex_height * font->tex_width)); rsxAddressToOffset(font->texture.data, &font->texture.offset); if (!font->texture.data) @@ -189,7 +198,8 @@ static void *rsx_font_init(void *data, font->atlas->dirty = false; - rsxTextureControl(font->rsx->context, font->tex_unit->index, GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); + rsxTextureControl(font->rsx->context, font->tex_unit->index, + GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); return font; error: @@ -216,7 +226,7 @@ static int rsx_font_get_message_width(void *data, const char *msg, while (msg < msg_end) { const struct font_glyph *glyph; - unsigned code = utf8_walk(&msg); + unsigned code = utf8_walk(&msg); /* Do something smarter here ... */ if (!(glyph = font->font_driver->get_glyph( @@ -233,7 +243,8 @@ static int rsx_font_get_message_width(void *data, const char *msg, static void rsx_font_draw_vertices(rsx_font_t *font, const video_coords_t *coords) { - int i; + int i, end_vert_idx; + rsx_vertex_t *vertices = NULL; const float *vertex = coords->vertex; const float *tex_coord = coords->tex_coord; const float *color = coords->color; @@ -241,16 +252,18 @@ static void rsx_font_draw_vertices(rsx_font_t *font, if (font->atlas->dirty) { rsx_font_upload_atlas(font); - font->atlas->dirty = false; + font->atlas->dirty = false; } - int end_vert_idx = font->rsx->font_vert_idx + coords->vertices; + end_vert_idx = font->rsx->font_vert_idx + coords->vertices; if (end_vert_idx > RSX_MAX_FONT_VERTICES) { - font->rsx->font_vert_idx = 0; - end_vert_idx = font->rsx->font_vert_idx + coords->vertices; + font->rsx->font_vert_idx = 0; + end_vert_idx = font->rsx->font_vert_idx + coords->vertices; } - rsx_vertex_t *vertices = &font->vertices[font->rsx->font_vert_idx]; + + vertices = &font->vertices[font->rsx->font_vert_idx]; + for (i = font->rsx->font_vert_idx; i < end_vert_idx; i++) { vertices[i].x = *vertex++; @@ -262,18 +275,27 @@ static void rsx_font_draw_vertices(rsx_font_t *font, vertices[i].b = *color++; vertices[i].a = *color++; } + rsxAddressToOffset(&vertices[font->rsx->font_vert_idx].x, &font->pos_offset); rsxAddressToOffset(&vertices[font->rsx->font_vert_idx].u, &font->uv_offset); rsxAddressToOffset(&vertices[font->rsx->font_vert_idx].r, &font->col_offset); font->rsx->font_vert_idx = end_vert_idx; - rsxBindVertexArrayAttrib(font->rsx->context, font->pos_index->index, 0, font->pos_offset, sizeof(rsx_vertex_t), 2, GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); - rsxBindVertexArrayAttrib(font->rsx->context, font->uv_index->index, 0, font->uv_offset, sizeof(rsx_vertex_t), 2, GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); - rsxBindVertexArrayAttrib(font->rsx->context, font->col_index->index, 0, font->col_offset, sizeof(rsx_vertex_t), 4, GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); + rsxBindVertexArrayAttrib(font->rsx->context, font->pos_index->index, 0, + font->pos_offset, sizeof(rsx_vertex_t), 2, + GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); + rsxBindVertexArrayAttrib(font->rsx->context, font->uv_index->index, 0, + font->uv_offset, sizeof(rsx_vertex_t), 2, + GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); + rsxBindVertexArrayAttrib(font->rsx->context, font->col_index->index, 0, + font->col_offset, sizeof(rsx_vertex_t), 4, + GCM_VERTEX_DATA_TYPE_F32, GCM_LOCATION_RSX); rsxLoadVertexProgram(font->rsx->context, font->vpo, font->vp_ucode); - rsxSetVertexProgramParameter(font->rsx->context, font->vpo, font->proj_matrix, (float *)&font->rsx->mvp_no_rot); - rsxLoadFragmentProgramLocation(font->rsx->context, font->fpo, font->fp_offset, GCM_LOCATION_RSX); + rsxSetVertexProgramParameter(font->rsx->context, font->vpo, + font->proj_matrix, (float *)&font->rsx->mvp_no_rot); + rsxLoadFragmentProgramLocation(font->rsx->context, font->fpo, + font->fp_offset, GCM_LOCATION_RSX); rsxClearSurface(font->rsx->context, GCM_CLEAR_Z); rsxDrawVertexArray(font->rsx->context, GCM_TYPE_TRIANGLES, 0, coords->vertices); @@ -288,8 +310,8 @@ static void rsx_font_render_line( struct video_coords coords; const struct font_glyph* glyph_q = NULL; float font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK]; - float font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK]; - float font_color[4 * 6 * MAX_MSG_LEN_CHUNK]; + float font_vertex [2 * 6 * MAX_MSG_LEN_CHUNK]; + float font_color [4 * 6 * MAX_MSG_LEN_CHUNK]; rsx_t *rsx = font->rsx; const char* msg_end = msg + msg_len; int x = roundf(pos_x * rsx->vp.width); @@ -304,10 +326,10 @@ static void rsx_font_render_line( switch (text_align) { case TEXT_ALIGN_RIGHT: - x -= rsx_font_get_message_width(font, msg, msg_len, scale); + x -= rsx_font_get_message_width(font, msg, msg_len, scale); break; case TEXT_ALIGN_CENTER: - x -= rsx_font_get_message_width(font, msg, msg_len, scale) / 2.0; + x -= rsx_font_get_message_width(font, msg, msg_len, scale) / 2.0; break; } @@ -373,7 +395,7 @@ static void rsx_font_render_message( /* If font line metrics are not supported just draw as usual */ if (!font->font_driver->get_line_metrics || - !font->font_driver->get_line_metrics(font->font_data, &line_metrics)) + !font->font_driver->get_line_metrics(font->font_data, &line_metrics)) { rsx_font_render_line(font, msg, strlen(msg), scale, color, pos_x, @@ -407,15 +429,17 @@ static void rsx_font_setup_viewport(unsigned width, unsigned height, { video_driver_set_viewport(width, height, full_screen, false); - if (font->rsx) - { - rsxSetBlendEnable(font->rsx->context, GCM_TRUE); - rsxSetBlendFunc(font->rsx->context, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA); - rsxSetBlendEquation(font->rsx->context, GCM_FUNC_ADD, GCM_FUNC_ADD); + if (font->rsx) + { + rsxSetBlendEnable(font->rsx->context, GCM_TRUE); + rsxSetBlendFunc(font->rsx->context, GCM_SRC_ALPHA, + GCM_ONE_MINUS_SRC_ALPHA, GCM_SRC_ALPHA, GCM_ONE_MINUS_SRC_ALPHA); + rsxSetBlendEquation(font->rsx->context, GCM_FUNC_ADD, GCM_FUNC_ADD); - rsxLoadTexture(font->rsx->context, font->tex_unit->index, &font->texture.tex); - rsxTextureControl(font->rsx->context, font->tex_unit->index, GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); - } + rsxLoadTexture(font->rsx->context, font->tex_unit->index, &font->texture.tex); + rsxTextureControl(font->rsx->context, font->tex_unit->index, + GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); + } } static void rsx_font_render_msg( @@ -503,7 +527,7 @@ static void rsx_font_render_msg( rsx_font_render_message(font, msg, scale, color_dark, x + scale * drop_x / font->rsx->vp.width, y + - scale * drop_y / font->rsx->vp.height, text_align); + scale * drop_y / font->rsx->vp.height, text_align); } rsx_font_render_message(font, msg, scale, color, @@ -512,8 +536,9 @@ static void rsx_font_render_msg( if (!font->block) { - /* restore viewport */ - rsxTextureControl(font->rsx->context, font->tex_unit->index, GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); + /* Restore viewport */ + rsxTextureControl(font->rsx->context, font->tex_unit->index, + GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); rsxSetBlendEnable(font->rsx->context, GCM_FALSE); video_driver_set_viewport(width, height, false, true); } @@ -544,8 +569,9 @@ static void rsx_font_flush_block(unsigned width, unsigned height, if (font->rsx) { - /* restore viewport */ - rsxTextureControl(font->rsx->context, font->tex_unit->index, GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); + /* Restore viewport */ + rsxTextureControl(font->rsx->context, font->tex_unit->index, + GCM_TRUE, 0 << 8, 12 << 8, GCM_TEXTURE_MAX_ANISO_1); rsxSetBlendEnable(font->rsx->context, GCM_FALSE); video_driver_set_viewport(width, height, block->fullscreen, true); } diff --git a/libretro-common/include/defines/ps3_defines.h b/libretro-common/include/defines/ps3_defines.h index 8b375bea9e..0a94d27dc1 100644 --- a/libretro-common/include/defines/ps3_defines.h +++ b/libretro-common/include/defines/ps3_defines.h @@ -772,6 +772,10 @@ typedef struct KbData #else #define cellGcmSetTransferImage cellGcmSetTransferImageInline #define celGcmSetInvalidateVertexCache cellGcmSetInvalidateVertexCacheInline +#define rsxInit cellGcmInit +#define rsxInvalidateTextureCache(a, b) cellGcmSetInvalidateVertexCache(a) +#define rsxTextureControl cellGcmSetTextureControlInline +#define rsxSetBlendEnable cellGcmSetBlendEnableInline #endif /*============================================================