Skip to content

Commit

Permalink
render/wiiu: Allocate normal textures from MEM2
Browse files Browse the repository at this point in the history
MEM1 fills up very quickly and soon runs out of space for apps with many textures
  • Loading branch information
rw-r-r-0644 committed Mar 18, 2019
1 parent 16c1ea9 commit ba2980b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/render/wiiu/SDL_render_wiiu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/render/wiiu/SDL_render_wiiu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions src/render/wiiu/SDL_rtexture_wiiu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ba2980b

Please sign in to comment.