Skip to content

Commit af3372c

Browse files
committed
Swizzle just static textures
1 parent 67adbe8 commit af3372c

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

src/render/psp/SDL_render_psp.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,10 @@ static inline int unswizzle(PSP_Texture *psp_tex)
330330
return 1;
331331
}
332332

333-
static inline void prepareTextureForUpload(PSP_Texture *psp_tex)
333+
static inline void prepareTextureForUpload(SDL_Texture *texture)
334334
{
335-
if (psp_tex->swizzled)
335+
PSP_Texture *psp_tex = (PSP_Texture *)texture->driverdata;
336+
if (texture->access != SDL_TEXTUREACCESS_STATIC || psp_tex->swizzled )
336337
return;
337338

338339
psp_tex->swizzledData = vramalloc(psp_tex->swizzledSize);
@@ -348,9 +349,11 @@ static inline void prepareTextureForUpload(PSP_Texture *psp_tex)
348349
sceKernelDcacheWritebackRange(psp_tex->swizzledData, psp_tex->swizzledSize);
349350
}
350351

351-
static inline void prepareTextureForDownload(PSP_Texture *psp_tex)
352+
static inline void prepareTextureForDownload(SDL_Texture *texture)
352353
{
353-
if (!psp_tex->swizzled)
354+
PSP_Texture *psp_tex = (PSP_Texture *)texture->driverdata;
355+
356+
if (texture->access != SDL_TEXTUREACCESS_STATIC || !psp_tex->swizzled)
354357
return;
355358

356359
psp_tex->data = SDL_malloc(psp_tex->size);
@@ -389,13 +392,21 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
389392
psp_tex->swizzledPitch = psp_tex->swizzledWidth * SDL_BYTESPERPIXEL(texture->format);
390393
psp_tex->size = getMemorySize(psp_tex->width, psp_tex->height, psp_tex->format);
391394
psp_tex->swizzledSize = getMemorySize(psp_tex->swizzledWidth, psp_tex->swizzledHeight, psp_tex->format);
392-
psp_tex->data = SDL_calloc(1, psp_tex->size);
393-
psp_tex->swizzled = GU_FALSE;
394395

395-
if (!psp_tex->data) {
396-
SDL_free(psp_tex);
397-
return SDL_OutOfMemory();
396+
if (texture->access != SDL_TEXTUREACCESS_STATIC) {
397+
psp_tex->data = vramalloc(psp_tex->size);
398+
if (!psp_tex->data) {
399+
vfree(psp_tex);
400+
return SDL_OutOfMemory();
401+
}
402+
} else {
403+
psp_tex->data = SDL_calloc(1, psp_tex->size);
404+
if (!psp_tex->data) {
405+
SDL_free(psp_tex);
406+
return SDL_OutOfMemory();
407+
}
398408
}
409+
psp_tex->swizzled = GU_FALSE;
399410

400411
texture->driverdata = psp_tex;
401412

@@ -408,7 +419,7 @@ static int PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
408419
PSP_Texture *psp_tex = (PSP_Texture *)texture->driverdata;
409420

410421
// How a pointer to the texture data is returned it need to be unswizzled before it can be used
411-
prepareTextureForDownload(psp_tex);
422+
prepareTextureForDownload(texture);
412423

413424
*pixels =
414425
(void *)((Uint8 *)psp_tex->data + rect->y * psp_tex->width * SDL_BYTESPERPIXEL(texture->format) +
@@ -741,6 +752,7 @@ static inline int PSP_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd
741752
static inline int PSP_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd)
742753
{
743754
PSP_RenderData *data = (PSP_RenderData *)renderer->driverdata;
755+
SDL_Texture *texture = cmd->data.draw.texture;
744756
const size_t count = cmd->data.draw.count;
745757
PSP_BlendInfo blendInfo = {
746758
.mode = cmd->data.draw.blend,
@@ -749,12 +761,13 @@ static inline int PSP_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL
749761

750762
PSP_SetBlendMode(data, blendInfo);
751763

752-
if (cmd->data.draw.texture) {
764+
if (texture) {
753765
uint32_t tbw, twp;
754766
const VertTCV *verts = (VertTCV *)(vertices + cmd->data.draw.first);
755-
PSP_Texture *psp_tex = (PSP_Texture *)cmd->data.draw.texture->driverdata;
767+
768+
PSP_Texture *psp_tex = (PSP_Texture *)texture->driverdata;
756769

757-
prepareTextureForUpload(psp_tex);
770+
prepareTextureForUpload(texture);
758771

759772
tbw = psp_tex->swizzled ? psp_tex->swizzledWidth : psp_tex->width;
760773
twp = psp_tex->swizzled ? psp_tex->swizzledData : psp_tex->data;
@@ -826,7 +839,8 @@ static inline int PSP_RenderCopy(SDL_Renderer *renderer, void *vertices, SDL_Ren
826839
{
827840
uint32_t tbw, twp;
828841
PSP_RenderData *data = (PSP_RenderData *)renderer->driverdata;
829-
PSP_Texture *psp_tex = (PSP_Texture *)cmd->data.draw.texture->driverdata;
842+
SDL_Texture *texture = cmd->data.draw.texture;
843+
PSP_Texture *psp_tex = (PSP_Texture *)texture->driverdata;
830844
const size_t count = cmd->data.draw.count;
831845
const VertTV *verts = (VertTV *)(vertices + cmd->data.draw.first);
832846
const PSP_BlendInfo blendInfo = {
@@ -836,7 +850,7 @@ static inline int PSP_RenderCopy(SDL_Renderer *renderer, void *vertices, SDL_Ren
836850

837851
PSP_SetBlendMode(data, blendInfo);
838852

839-
prepareTextureForUpload(psp_tex);
853+
prepareTextureForUpload(texture);
840854

841855
tbw = psp_tex->swizzled ? psp_tex->textureWidth : psp_tex->width;
842856
twp = psp_tex->swizzled ? psp_tex->swizzledData : psp_tex->data;
@@ -965,7 +979,11 @@ static void PSP_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
965979
}
966980

967981
vfree(psp_tex->swizzledData);
968-
SDL_free(psp_tex->data);
982+
if (texture->access != SDL_TEXTUREACCESS_STATIC) {
983+
vfree(psp_tex->data);
984+
} else {
985+
SDL_free(psp_tex->data);
986+
}
969987
SDL_free(psp_tex);
970988
texture->driverdata = NULL;
971989
}

0 commit comments

Comments
 (0)