338 lines
8.7 KiB
C
Raw Normal View History

2018-12-28 01:27:13 +01:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2018 - M4xw
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
2020-06-20 14:05:20 -07:00
#include <string/stdstring.h>
#include <compat/strl.h>
2020-06-20 14:05:20 -07:00
#include <piglet.h>
#include <orbis/libkernel.h>
#include <EGL/egl.h>
2018-12-28 01:27:13 +01:00
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
2020-07-20 18:22:33 +02:00
#ifdef HAVE_EGL
#include "../common/egl_common.h"
#endif
2023-05-31 22:46:34 +02:00
#include "../common/orbis_defines.h"
2018-12-28 01:27:13 +01:00
#include "../../frontend/frontend_driver.h"
#include "../../configuration.h"
2020-06-20 14:05:20 -07:00
#include <defines/ps4_defines.h>
2018-12-28 01:27:13 +01:00
2020-07-17 16:46:00 +02:00
/* TODO/FIXME - static globals */
2018-12-28 01:27:13 +01:00
static enum gfx_ctx_api ctx_orbis_api = GFX_CTX_OPENGL_API;
2020-07-17 16:34:11 +02:00
/* TODO/FIXME - global reference */
2018-12-28 01:27:13 +01:00
extern bool platform_orbis_has_focus;
2020-06-20 14:05:20 -07:00
extern SceKernelModule s_piglet_module;
2018-12-28 01:27:13 +01:00
void orbis_ctx_destroy(void *data)
{
2020-07-14 16:37:02 +02:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
2018-12-28 01:27:13 +01:00
2020-07-14 16:37:02 +02:00
if (ctx_orbis)
{
2018-12-28 01:27:13 +01:00
#ifdef HAVE_EGL
2020-07-14 16:37:02 +02:00
egl_destroy(&ctx_orbis->egl);
2018-12-28 01:27:13 +01:00
#endif
2020-07-14 16:37:02 +02:00
ctx_orbis->resize = false;
free(ctx_orbis);
}
2018-12-28 01:27:13 +01:00
}
static void orbis_ctx_get_video_size(void *data,
2020-07-14 16:37:02 +02:00
unsigned *width, unsigned *height)
2018-12-28 01:27:13 +01:00
{
2020-06-20 14:05:20 -07:00
orbis_ctx_data_t
2020-07-14 16:37:02 +02:00
*ctx_orbis = (orbis_ctx_data_t *)data;
2018-12-28 01:27:13 +01:00
2020-07-14 16:37:02 +02:00
*width = ATTR_ORBISGL_WIDTH;
*height = ATTR_ORBISGL_HEIGHT;
2018-12-28 01:27:13 +01:00
}
2020-03-07 00:39:06 +01:00
static void *orbis_ctx_init(void *video_driver)
2018-12-28 01:27:13 +01:00
{
2022-05-22 20:29:53 +02:00
#if defined(HAVE_OOSDK)
const char *shdr_cache_dir;
#endif
2018-12-28 01:27:13 +01:00
#ifdef HAVE_EGL
2022-05-22 20:29:53 +02:00
int ret;
EGLint n;
EGLint major, minor;
static const EGLint attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, 0,
2020-06-20 14:05:20 -07:00
#if defined(HAVE_OPENGLES3)
2022-05-22 20:29:53 +02:00
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
2020-06-20 14:05:20 -07:00
#else
2022-05-22 20:29:53 +02:00
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
2020-06-20 14:05:20 -07:00
#endif
2022-05-22 20:29:53 +02:00
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE};
2018-12-28 01:27:13 +01:00
#endif
2023-02-21 09:49:46 +01:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)
2022-05-22 20:29:53 +02:00
calloc(1, sizeof(*ctx_orbis));
2018-12-28 01:27:13 +01:00
2022-05-22 20:29:53 +02:00
if (!ctx_orbis)
return NULL;
2018-12-28 01:27:13 +01:00
#ifdef HAVE_EGL
memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config));
2020-07-14 16:37:02 +02:00
2023-02-21 09:49:46 +01:00
ctx_orbis->pgl_config.size = sizeof(ctx_orbis->pgl_config);
ctx_orbis->pgl_config.flags =
SCE_PGL_FLAGS_USE_COMPOSITE_EXT
| SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY
| 0x60;
ctx_orbis->pgl_config.processOrder = 1;
ctx_orbis->pgl_config.systemSharedMemorySize = 0x1000000;
ctx_orbis->pgl_config.videoSharedMemorySize = 0x3000000;
ctx_orbis->pgl_config.maxMappedFlexibleMemory = 0xFFFFFFFF;
ctx_orbis->pgl_config.drawCommandBufferSize = 0x100000;
ctx_orbis->pgl_config.lcueResourceBufferSize = 0x1000000;
ctx_orbis->pgl_config.dbgPosCmd_0x40 = ATTR_ORBISGL_WIDTH;
ctx_orbis->pgl_config.dbgPosCmd_0x44 = ATTR_ORBISGL_HEIGHT;
ctx_orbis->pgl_config.dbgPosCmd_0x48 = 0;
ctx_orbis->pgl_config.dbgPosCmd_0x4C = 0;
ctx_orbis->pgl_config.unk_0x5C = 2;
if (!(ret = scePigletSetConfigurationVSH(&ctx_orbis->pgl_config)))
2022-05-22 20:29:53 +02:00
goto error;
2018-12-28 01:27:13 +01:00
2020-06-20 14:05:20 -07:00
#if defined(HAVE_OOSDK)
2022-05-22 20:29:53 +02:00
memset(&ctx_orbis->shdr_cache_config, 0, sizeof(ctx_orbis->shdr_cache_config));
shdr_cache_dir = "/data/retroarch/temp/";
2022-05-22 20:29:53 +02:00
ctx_orbis->shdr_cache_config.ver = 0x00010064;
snprintf(ctx_orbis->shdr_cache_config.cache_dir,
strlen(shdr_cache_dir) + 1, "%s",
shdr_cache_dir);
if (!(ret =
scePigletSetShaderCacheConfiguration(&ctx_orbis->shdr_cache_config)))
goto error;
2020-06-20 14:05:20 -07:00
#endif
2022-05-22 20:29:53 +02:00
if (!egl_init_context(&ctx_orbis->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
&major, &minor, &n, attribs, NULL))
{
egl_report_error();
goto error;
}
2018-12-28 01:27:13 +01:00
#endif
2022-05-22 20:29:53 +02:00
return ctx_orbis;
2018-12-28 01:27:13 +01:00
error:
2022-05-22 20:29:53 +02:00
orbis_ctx_destroy(video_driver);
return NULL;
2018-12-28 01:27:13 +01:00
}
static void orbis_ctx_check_window(void *data, bool *quit,
2020-03-06 20:29:15 +01:00
bool *resize, unsigned *width, unsigned *height)
2018-12-28 01:27:13 +01:00
{
unsigned new_width, new_height;
orbis_ctx_get_video_size(data, &new_width, &new_height);
if (new_width != *width || new_height != *height)
{
2020-07-14 16:37:02 +02:00
*width = new_width;
2018-12-28 01:27:13 +01:00
*height = new_height;
*resize = true;
}
2023-02-21 09:49:46 +01:00
*quit = (bool)false;
2018-12-28 01:27:13 +01:00
}
static bool orbis_ctx_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
2018-12-28 01:27:13 +01:00
{
/* Create an EGL rendering context */
2020-06-20 14:05:20 -07:00
static const EGLint
2020-07-14 16:37:02 +02:00
contextAttributeList[] =
2018-12-28 01:27:13 +01:00
{
2020-06-20 14:05:20 -07:00
#if defined(HAVE_OPENGLES3)
EGL_CONTEXT_CLIENT_VERSION, 3, // GLES3
#else
EGL_CONTEXT_CLIENT_VERSION, 2, // GLES2
#endif
2018-12-28 01:27:13 +01:00
EGL_NONE};
2020-07-14 16:37:02 +02:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
2018-12-28 01:27:13 +01:00
2020-07-14 16:37:02 +02:00
ctx_orbis->width = ATTR_ORBISGL_WIDTH;
ctx_orbis->height = ATTR_ORBISGL_HEIGHT;
2018-12-28 01:27:13 +01:00
2020-07-14 16:37:02 +02:00
ctx_orbis->native_window.width = ctx_orbis->width;
2018-12-28 01:27:13 +01:00
ctx_orbis->native_window.height = ctx_orbis->height;
ctx_orbis->refresh_rate = 60;
#ifdef HAVE_EGL
if (!egl_create_context(&ctx_orbis->egl, contextAttributeList))
goto error;
if (!egl_create_surface(&ctx_orbis->egl, &ctx_orbis->native_window))
goto error;
#endif
return true;
error:
#ifdef HAVE_EGL
egl_report_error();
#endif
2018-12-28 01:27:13 +01:00
orbis_ctx_destroy(data);
return false;
}
static void orbis_ctx_input_driver(void *data,
const char *name,
input_driver_t **input, void **input_data)
2018-12-28 01:27:13 +01:00
{
*input = NULL;
2018-12-28 01:27:13 +01:00
*input_data = NULL;
}
2023-02-21 09:49:46 +01:00
static enum gfx_ctx_api orbis_ctx_get_api(void *data) { return ctx_orbis_api; }
2018-12-28 01:27:13 +01:00
static bool orbis_ctx_bind_api(void *data,
2020-01-04 15:09:42 +01:00
enum gfx_ctx_api api, unsigned major, unsigned minor)
2018-12-28 01:27:13 +01:00
{
ctx_orbis_api = api;
#ifdef HAVE_EGL
2018-12-30 00:11:53 +01:00
if (api == GFX_CTX_OPENGL_ES_API)
2020-01-04 15:09:42 +01:00
if (egl_bind_api(EGL_OPENGL_ES_API))
2018-12-28 01:27:13 +01:00
return true;
#endif
2018-12-28 01:27:13 +01:00
return false;
}
2020-07-14 16:37:02 +02:00
static bool orbis_ctx_has_focus(void *data) { return true; }
2018-12-28 01:27:13 +01:00
2020-07-14 16:37:02 +02:00
static bool orbis_ctx_suppress_screensaver(void *data, bool enable) { return false; }
2018-12-28 01:27:13 +01:00
static void orbis_ctx_set_swap_interval(void *data,
2020-07-14 16:37:02 +02:00
int swap_interval)
2018-12-28 01:27:13 +01:00
{
#ifdef HAVE_EGL
2020-07-14 16:37:02 +02:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
egl_set_swap_interval(&ctx_orbis->egl, 0);
2018-12-28 01:27:13 +01:00
#endif
}
static void orbis_ctx_swap_buffers(void *data)
2018-12-28 01:27:13 +01:00
{
#ifdef HAVE_EGL
2020-07-14 16:37:02 +02:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
egl_swap_buffers(&ctx_orbis->egl);
2018-12-28 01:27:13 +01:00
#endif
}
2020-06-20 14:05:20 -07:00
static gfx_ctx_proc_t orbis_ctx_get_proc_address(const char *symbol)
{
2023-02-21 09:49:46 +01:00
gfx_ctx_proc_t ptr_sym = NULL;
2020-06-20 14:05:20 -07:00
#ifdef HAVE_EGL
2023-02-21 09:49:46 +01:00
ptr_sym = egl_get_proc_address(symbol);
2020-06-20 14:05:20 -07:00
#endif
2023-02-21 09:49:46 +01:00
if (!ptr_sym && s_piglet_module > 0)
sceKernelDlsym(s_piglet_module, symbol, (void **)&ptr_sym);
return ptr_sym;
2020-06-20 14:05:20 -07:00
}
2023-02-21 09:49:46 +01:00
2018-12-28 01:27:13 +01:00
static void orbis_ctx_bind_hw_render(void *data, bool enable)
{
#ifdef HAVE_EGL
2023-02-21 09:49:46 +01:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
2020-07-14 16:37:02 +02:00
egl_bind_hw_render(&ctx_orbis->egl, enable);
2018-12-28 01:27:13 +01:00
#endif
}
static uint32_t orbis_ctx_get_flags(void *data)
{
uint32_t flags = 0;
2018-12-28 01:27:13 +01:00
if (string_is_equal(video_driver_get_ident(), "glcore"))
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
#endif
}
else
{
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
}
return flags;
2018-12-28 01:27:13 +01:00
}
2020-07-14 16:37:02 +02:00
static void orbis_ctx_set_flags(void *data, uint32_t flags) { }
2018-12-28 01:27:13 +01:00
static float orbis_ctx_get_refresh_rate(void *data)
{
2020-07-14 16:37:02 +02:00
orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data;
return ctx_orbis->refresh_rate;
2018-12-28 01:27:13 +01:00
}
const gfx_ctx_driver_t orbis_ctx = {
orbis_ctx_init,
orbis_ctx_destroy,
orbis_ctx_get_api,
orbis_ctx_bind_api,
orbis_ctx_set_swap_interval,
orbis_ctx_set_video_mode,
orbis_ctx_get_video_size,
orbis_ctx_get_refresh_rate,
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
NULL, /* get_metrics */
NULL,
NULL, /* update_title */
2018-12-28 01:27:13 +01:00
orbis_ctx_check_window,
NULL, /* set_resize */
orbis_ctx_has_focus,
orbis_ctx_suppress_screensaver,
false, /* has_windowed */
2018-12-28 01:27:13 +01:00
orbis_ctx_swap_buffers,
orbis_ctx_input_driver,
#ifdef HAVE_EGL
egl_get_proc_address,
#else
NULL,
#endif
2018-12-28 01:27:13 +01:00
NULL,
NULL,
NULL,
2020-07-20 18:22:33 +02:00
"egl_orbis",
2018-12-28 01:27:13 +01:00
orbis_ctx_get_flags,
orbis_ctx_set_flags,
orbis_ctx_bind_hw_render,
NULL,
NULL};