From ba2980b6615f9041733d2571904a8d9f87153279 Mon Sep 17 00:00:00 2001 From: rw-r-r-0644 Date: Mon, 18 Mar 2019 23:11:18 +0100 Subject: [PATCH] render/wiiu: Allocate normal textures from MEM2 MEM1 fills up very quickly and soon runs out of space for apps with many textures --- src/render/wiiu/SDL_render_wiiu.c | 1 + src/render/wiiu/SDL_render_wiiu.h | 3 +++ src/render/wiiu/SDL_rtexture_wiiu.c | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/render/wiiu/SDL_render_wiiu.c b/src/render/wiiu/SDL_render_wiiu.c index 156c50a6f7..a49afb0d29 100644 --- a/src/render/wiiu/SDL_render_wiiu.c +++ b/src/render/wiiu/SDL_render_wiiu.c @@ -124,6 +124,7 @@ void WIIU_SDL_CreateWindowTex(SDL_Renderer * renderer, SDL_Window * window) data->windowTex = (SDL_Texture) { .format = SDL_PIXELFORMAT_RGBA8888, .r = 255, .g = 255, .b = 255, .a = 255, + .driverdata = WIIU_TEXTURE_MEM1_MAGIC, }; SDL_GetWindowSize(window, &data->windowTex.w, &data->windowTex.h); diff --git a/src/render/wiiu/SDL_render_wiiu.h b/src/render/wiiu/SDL_render_wiiu.h index 05f216bcd2..68f9ff9101 100644 --- a/src/render/wiiu/SDL_render_wiiu.h +++ b/src/render/wiiu/SDL_render_wiiu.h @@ -101,6 +101,9 @@ struct WIIU_TextureData int isRendering; }; +/* Ask texture driver to allocate texture's memory from MEM1 */ +#define WIIU_TEXTURE_MEM1_MAGIC (void *)0xCAFE0001 + /* SDL_render API implementation */ SDL_Renderer *WIIU_SDL_CreateRenderer(SDL_Window * window, Uint32 flags); void WIIU_SDL_WindowEvent(SDL_Renderer * renderer, diff --git a/src/render/wiiu/SDL_rtexture_wiiu.c b/src/render/wiiu/SDL_rtexture_wiiu.c index e06a719217..7aae30b0d7 100644 --- a/src/render/wiiu/SDL_rtexture_wiiu.c +++ b/src/render/wiiu/SDL_rtexture_wiiu.c @@ -38,8 +38,9 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { - WIIUPixFmt gx2_fmt; BOOL res; + WIIUPixFmt gx2_fmt; + GX2RResourceFlags surface_flags; WIIU_TextureData *tdata = (WIIU_TextureData *) SDL_calloc(1, sizeof(*tdata)); if (!tdata) { return SDL_OutOfMemory(); @@ -74,12 +75,19 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) tdata->cbuf.viewNumSlices = 1; GX2InitColorBufferRegs(&tdata->cbuf); + /* Texture's surface flags */ + surface_flags = GX2R_RESOURCE_BIND_TEXTURE | GX2R_RESOURCE_BIND_COLOR_BUFFER | + GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_CPU_READ | + GX2R_RESOURCE_USAGE_GPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ; + + /* Allocate normal textures from MEM2 */ + if (texture->driverdata != WIIU_TEXTURE_MEM1_MAGIC) + surface_flags |= GX2R_RESOURCE_USAGE_FORCE_MEM2; + /* Allocate the texture's surface */ res = GX2RCreateSurface( &tdata->texture.surface, - GX2R_RESOURCE_BIND_TEXTURE | GX2R_RESOURCE_BIND_COLOR_BUFFER | - GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_CPU_READ | - GX2R_RESOURCE_USAGE_GPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ + surface_flags ); if (!res) { SDL_free(tdata);