mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 15:45:19 +00:00
(GX2) Cleanups
This commit is contained in:
parent
afd3df7523
commit
b8951de6fd
@ -79,12 +79,148 @@ static const wiiu_render_mode_t gx2_render_mode_map[] =
|
||||
{1920, 1080, GX2_TV_RENDER_MODE_WIDE_1080P} /* GX2_TV_SCAN_MODE_1080P */
|
||||
};
|
||||
|
||||
/*
|
||||
* FORWARD DECLARATIONS
|
||||
*/
|
||||
static void gx2_free_shader_preset(wiiu_video_t *wiiu)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->passes; i++)
|
||||
{
|
||||
gfd_free(wiiu->pass[i].gfd);
|
||||
MEM2_free(wiiu->pass[i].vs_ubos[0]);
|
||||
MEM2_free(wiiu->pass[i].vs_ubos[1]);
|
||||
MEM2_free(wiiu->pass[i].ps_ubos[0]);
|
||||
MEM2_free(wiiu->pass[i].ps_ubos[1]);
|
||||
if (wiiu->pass[i].mem1)
|
||||
MEM1_free(wiiu->pass[i].texture.surface.image);
|
||||
else
|
||||
MEM2_free(wiiu->pass[i].texture.surface.image);
|
||||
}
|
||||
|
||||
memset(wiiu->pass, 0, sizeof(wiiu->pass));
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->luts; i++)
|
||||
{
|
||||
MEM2_free(wiiu->luts[i].surface.image);
|
||||
wiiu->luts[i].surface.image = NULL;
|
||||
}
|
||||
|
||||
free(wiiu->shader_preset);
|
||||
wiiu->shader_preset = NULL;
|
||||
}
|
||||
|
||||
static bool gx2_set_shader(void *data,
|
||||
enum rarch_shader_type type, const char *path);
|
||||
enum rarch_shader_type type, const char *path)
|
||||
{
|
||||
unsigned i;
|
||||
wiiu_video_t *wiiu = (wiiu_video_t *)data;
|
||||
|
||||
if (!wiiu)
|
||||
return false;
|
||||
|
||||
GX2DrawDone();
|
||||
if (wiiu->shader_preset)
|
||||
gx2_free_shader_preset(wiiu);
|
||||
|
||||
if (!string_is_empty(path))
|
||||
{
|
||||
if (type != RARCH_SHADER_SLANG)
|
||||
{
|
||||
RARCH_WARN("[GX2] Only Slang shaders are supported. Falling back to stock.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
wiiu->shader_preset = calloc(1, sizeof(*wiiu->shader_preset));
|
||||
|
||||
if (!video_shader_load_preset_into_shader(path, wiiu->shader_preset))
|
||||
{
|
||||
free(wiiu->shader_preset);
|
||||
wiiu->shader_preset = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->passes; i++)
|
||||
{
|
||||
unsigned j;
|
||||
char *ptr;
|
||||
char gfdpath[PATH_MAX_LENGTH];
|
||||
struct video_shader_pass *pass = &wiiu->shader_preset->pass[i];
|
||||
|
||||
strlcpy(gfdpath, pass->source.path, sizeof(gfdpath));
|
||||
|
||||
if (!(ptr = strrchr(gfdpath, '.')))
|
||||
ptr = gfdpath + strlen(gfdpath);
|
||||
|
||||
*ptr++ = '.';
|
||||
*ptr++ = 'g';
|
||||
*ptr++ = 's';
|
||||
*ptr++ = 'h';
|
||||
*ptr++ = '\0';
|
||||
|
||||
wiiu->pass[i].gfd = gfd_open(gfdpath);
|
||||
|
||||
if (!wiiu->pass[i].gfd)
|
||||
{
|
||||
if (wiiu->shader_preset)
|
||||
gx2_free_shader_preset(wiiu);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->vs->uniformBlockCount; j++)
|
||||
{
|
||||
wiiu->pass[i].vs_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->vs->uniformBlocks[j].size,
|
||||
GX2_UNIFORM_BLOCK_ALIGNMENT);
|
||||
memset(wiiu->pass[i].vs_ubos[j], 0, wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].vs_ubos[j],
|
||||
wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
|
||||
}
|
||||
|
||||
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->ps->uniformBlockCount; j++)
|
||||
{
|
||||
wiiu->pass[i].ps_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->ps->uniformBlocks[j].size,
|
||||
GX2_UNIFORM_BLOCK_ALIGNMENT);
|
||||
memset(wiiu->pass[i].ps_ubos[j], 0, wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].ps_ubos[j],
|
||||
wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->luts; i++)
|
||||
{
|
||||
struct texture_image image = {};
|
||||
|
||||
if (image_texture_load(&image, wiiu->shader_preset->lut[i].path))
|
||||
{
|
||||
unsigned j;
|
||||
|
||||
wiiu->luts[i].surface.width = image.width;
|
||||
wiiu->luts[i].surface.height = image.height;
|
||||
wiiu->luts[i].surface.depth = 1;
|
||||
wiiu->luts[i].surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
|
||||
wiiu->luts[i].surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
|
||||
wiiu->luts[i].viewNumSlices = 1;
|
||||
|
||||
wiiu->luts[i].surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
wiiu->luts[i].compMap = GX2_COMP_SEL(_G, _B, _A, _R);
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&wiiu->luts[i].surface);
|
||||
GX2InitTextureRegs(&wiiu->luts[i]);
|
||||
wiiu->luts[i].surface.image = MEM2_alloc(wiiu->luts[i].surface.imageSize,
|
||||
wiiu->luts[i].surface.alignment);
|
||||
|
||||
for (j = 0; (j < image.height) && (j < wiiu->luts[i].surface.height); j++)
|
||||
memcpy((uint32_t *)wiiu->luts[i].surface.image + (j * wiiu->luts[i].surface.pitch),
|
||||
image.pixels + (j * image.width), image.width * sizeof(image.pixels));
|
||||
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->luts[i].surface.image,
|
||||
wiiu->luts[i].surface.imageSize);
|
||||
|
||||
image_texture_free(&image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* DISPLAY DRIVER
|
||||
@ -555,7 +691,9 @@ static void gx2_font_render_line(
|
||||
if (!count)
|
||||
return;
|
||||
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.v + wiiu->vertex_cache.current, count * sizeof(wiiu->vertex_cache.v));
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER,
|
||||
wiiu->vertex_cache.v + wiiu->vertex_cache.current,
|
||||
count * sizeof(wiiu->vertex_cache.v));
|
||||
|
||||
if (font->atlas->dirty)
|
||||
{
|
||||
@ -933,7 +1071,7 @@ static void *gx2_init(const video_info_t *video,
|
||||
memset(&wiiu->color_buffer, 0, sizeof(GX2ColorBuffer));
|
||||
|
||||
wiiu->color_buffer.surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
|
||||
if (wiiu->render_mode.height != 480 && prefer_drc)
|
||||
if (prefer_drc && (wiiu->render_mode.height != 480))
|
||||
{
|
||||
wiiu->color_buffer.surface.width = 1708;
|
||||
wiiu->color_buffer.surface.height = 960;
|
||||
@ -952,13 +1090,14 @@ static void *gx2_init(const video_info_t *video,
|
||||
GX2CalcSurfaceSizeAndAlignment(&wiiu->color_buffer.surface);
|
||||
GX2InitColorBufferRegs(&wiiu->color_buffer);
|
||||
|
||||
wiiu->color_buffer.surface.image = MEM1_alloc(wiiu->color_buffer.surface.imageSize,
|
||||
wiiu->color_buffer.surface.image = MEM1_alloc(
|
||||
wiiu->color_buffer.surface.imageSize,
|
||||
wiiu->color_buffer.surface.alignment);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU, wiiu->color_buffer.surface.image,
|
||||
wiiu->color_buffer.surface.imageSize);
|
||||
|
||||
wiiu->ctx_state = (GX2ContextState *)MEM2_alloc(sizeof(GX2ContextState),
|
||||
GX2_CONTEXT_STATE_ALIGNMENT);
|
||||
wiiu->ctx_state = (GX2ContextState *)MEM2_alloc(
|
||||
sizeof(GX2ContextState), GX2_CONTEXT_STATE_ALIGNMENT);
|
||||
GX2SetupContextStateEx(wiiu->ctx_state, GX2_TRUE);
|
||||
|
||||
GX2SetContextState(wiiu->ctx_state);
|
||||
@ -1027,7 +1166,8 @@ static void *gx2_init(const video_info_t *video,
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->menu.texture.surface.image,
|
||||
wiiu->menu.texture.surface.imageSize);
|
||||
|
||||
wiiu->v = MEM2_alloc(4 * sizeof(*wiiu->v), GX2_VERTEX_BUFFER_ALIGNMENT);
|
||||
wiiu->v = MEM2_alloc(
|
||||
4 * sizeof(*wiiu->v), GX2_VERTEX_BUFFER_ALIGNMENT);
|
||||
|
||||
wiiu->v[0].pos.x = 0.0f;
|
||||
wiiu->v[0].pos.y = 0.0f;
|
||||
@ -1344,36 +1484,6 @@ static void gx2_get_overlay_interface(void *data,
|
||||
}
|
||||
#endif
|
||||
|
||||
static void wiiu_free_shader_preset(wiiu_video_t *wiiu)
|
||||
{
|
||||
unsigned i;
|
||||
if (!wiiu->shader_preset)
|
||||
return;
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->passes; i++)
|
||||
{
|
||||
gfd_free(wiiu->pass[i].gfd);
|
||||
MEM2_free(wiiu->pass[i].vs_ubos[0]);
|
||||
MEM2_free(wiiu->pass[i].vs_ubos[1]);
|
||||
MEM2_free(wiiu->pass[i].ps_ubos[0]);
|
||||
MEM2_free(wiiu->pass[i].ps_ubos[1]);
|
||||
if (wiiu->pass[i].mem1)
|
||||
MEM1_free(wiiu->pass[i].texture.surface.image);
|
||||
else
|
||||
MEM2_free(wiiu->pass[i].texture.surface.image);
|
||||
}
|
||||
|
||||
memset(wiiu->pass, 0, sizeof(wiiu->pass));
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->luts; i++)
|
||||
{
|
||||
MEM2_free(wiiu->luts[i].surface.image);
|
||||
wiiu->luts[i].surface.image = NULL;
|
||||
}
|
||||
|
||||
free(wiiu->shader_preset);
|
||||
wiiu->shader_preset = NULL;
|
||||
}
|
||||
|
||||
static void gx2_free(void *data)
|
||||
{
|
||||
@ -1406,7 +1516,8 @@ static void gx2_free(void *data)
|
||||
GX2DestroyShader(&snow_simple_shader);
|
||||
GX2DestroyShader(&snowflake_shader);
|
||||
|
||||
wiiu_free_shader_preset(wiiu);
|
||||
if (wiiu->shader_preset)
|
||||
gx2_free_shader_preset(wiiu);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
gx2_free_overlay(wiiu);
|
||||
@ -1574,7 +1685,8 @@ static bool wiiu_init_frame_textures(wiiu_video_t *wiiu, unsigned width, unsigne
|
||||
{
|
||||
/* Failed to allocate Render target memory from MEM2. Falling
|
||||
* back to stock... */
|
||||
wiiu_free_shader_preset(wiiu);
|
||||
if (wiiu->shader_preset)
|
||||
gx2_free_shader_preset(wiiu);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -2123,118 +2235,6 @@ static bool gx2_alive(void *data) { return true; }
|
||||
static bool gx2_focus(void *data) { return true; }
|
||||
static bool gx2_suppress_screensaver(void *a, bool b) { return false; }
|
||||
|
||||
static bool gx2_set_shader(void *data,
|
||||
enum rarch_shader_type type, const char *path)
|
||||
{
|
||||
unsigned i;
|
||||
wiiu_video_t *wiiu = (wiiu_video_t *)data;
|
||||
|
||||
if (!wiiu)
|
||||
return false;
|
||||
|
||||
GX2DrawDone();
|
||||
wiiu_free_shader_preset(wiiu);
|
||||
|
||||
if (!string_is_empty(path))
|
||||
{
|
||||
if (type != RARCH_SHADER_SLANG)
|
||||
{
|
||||
RARCH_WARN("[GX2] Only Slang shaders are supported. Falling back to stock.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
wiiu->shader_preset = calloc(1, sizeof(*wiiu->shader_preset));
|
||||
|
||||
if (!video_shader_load_preset_into_shader(path, wiiu->shader_preset))
|
||||
{
|
||||
free(wiiu->shader_preset);
|
||||
wiiu->shader_preset = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->passes; i++)
|
||||
{
|
||||
unsigned j;
|
||||
char *ptr;
|
||||
char gfdpath[PATH_MAX_LENGTH];
|
||||
struct video_shader_pass *pass = &wiiu->shader_preset->pass[i];
|
||||
|
||||
strlcpy(gfdpath, pass->source.path, sizeof(gfdpath));
|
||||
|
||||
if (!(ptr = strrchr(gfdpath, '.')))
|
||||
ptr = gfdpath + strlen(gfdpath);
|
||||
|
||||
*ptr++ = '.';
|
||||
*ptr++ = 'g';
|
||||
*ptr++ = 's';
|
||||
*ptr++ = 'h';
|
||||
*ptr++ = '\0';
|
||||
|
||||
wiiu->pass[i].gfd = gfd_open(gfdpath);
|
||||
|
||||
if (!wiiu->pass[i].gfd)
|
||||
{
|
||||
wiiu_free_shader_preset(wiiu);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->vs->uniformBlockCount; j++)
|
||||
{
|
||||
wiiu->pass[i].vs_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->vs->uniformBlocks[j].size,
|
||||
GX2_UNIFORM_BLOCK_ALIGNMENT);
|
||||
memset(wiiu->pass[i].vs_ubos[j], 0, wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].vs_ubos[j],
|
||||
wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
|
||||
}
|
||||
|
||||
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->ps->uniformBlockCount; j++)
|
||||
{
|
||||
wiiu->pass[i].ps_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->ps->uniformBlocks[j].size,
|
||||
GX2_UNIFORM_BLOCK_ALIGNMENT);
|
||||
memset(wiiu->pass[i].ps_ubos[j], 0, wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].ps_ubos[j],
|
||||
wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < wiiu->shader_preset->luts; i++)
|
||||
{
|
||||
struct texture_image image = {};
|
||||
|
||||
if (image_texture_load(&image, wiiu->shader_preset->lut[i].path))
|
||||
{
|
||||
unsigned j;
|
||||
|
||||
wiiu->luts[i].surface.width = image.width;
|
||||
wiiu->luts[i].surface.height = image.height;
|
||||
wiiu->luts[i].surface.depth = 1;
|
||||
wiiu->luts[i].surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
|
||||
wiiu->luts[i].surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
|
||||
wiiu->luts[i].viewNumSlices = 1;
|
||||
|
||||
wiiu->luts[i].surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
wiiu->luts[i].compMap = GX2_COMP_SEL(_G, _B, _A, _R);
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&wiiu->luts[i].surface);
|
||||
GX2InitTextureRegs(&wiiu->luts[i]);
|
||||
wiiu->luts[i].surface.image = MEM2_alloc(wiiu->luts[i].surface.imageSize,
|
||||
wiiu->luts[i].surface.alignment);
|
||||
|
||||
for (j = 0; (j < image.height) && (j < wiiu->luts[i].surface.height); j++)
|
||||
memcpy((uint32_t *)wiiu->luts[i].surface.image + (j * wiiu->luts[i].surface.pitch),
|
||||
image.pixels + (j * image.width), image.width * sizeof(image.pixels));
|
||||
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->luts[i].surface.image,
|
||||
wiiu->luts[i].surface.imageSize);
|
||||
|
||||
image_texture_free(&image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct video_shader *gx2_get_current_shader(void *data)
|
||||
{
|
||||
wiiu_video_t *wiiu = (wiiu_video_t *)data;
|
||||
|
Loading…
x
Reference in New Issue
Block a user