all repos — mgba @ 97e2cf08ab727dd7a6f47ebd0fe2ba70b8eeb8b5

mGBA Game Boy Advance Emulator

Vita: Avoid uncached memcpy
Vicki Pfau vi@endrift.com
Sun, 19 Jan 2020 22:17:38 -0800
commit

97e2cf08ab727dd7a6f47ebd0fe2ba70b8eeb8b5

parent

f44846cb9a0818af13830a34c0deee830b4451d4

3 files changed, 21 insertions(+), 15 deletions(-)

jump to
M src/platform/psp2/main.csrc/platform/psp2/main.c

@@ -152,7 +152,7 @@ .setup = mPSP2Setup,

.teardown = mPSP2Teardown, .gameLoaded = mPSP2LoadROM, .gameUnloaded = mPSP2UnloadROM, - .prepareForFrame = NULL, + .prepareForFrame = mPSP2Swap, .drawFrame = mPSP2Draw, .drawScreenshot = mPSP2DrawScreenshot, .paused = mPSP2Paused,
M src/platform/psp2/psp2-context.csrc/platform/psp2/psp2-context.c

@@ -51,8 +51,8 @@ SM_MAX

} screenMode; static void* outputBuffer; -static vita2d_texture* tex; -static vita2d_texture* oldTex; +static int currentTex; +static vita2d_texture* tex[4]; static vita2d_texture* screenshot; static Thread audioThread; static bool interframeBlending = false;

@@ -324,12 +324,14 @@ mInputBindAxis(&runner->core->inputMap, PSP2_INPUT, 1, &desc);

unsigned width, height; runner->core->desiredVideoDimensions(runner->core, &width, &height); - tex = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); - oldTex = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); + tex[0] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); + tex[1] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); + tex[2] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); + tex[3] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); + currentTex = 0; screenshot = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR); - outputBuffer = anonymousMemoryMap(256 * toPow2(height) * 4); - runner->core->setVideoBuffer(runner->core, outputBuffer, 256); + runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256); runner->core->setAudioBufferSize(runner->core, PSP2_SAMPLES); rotation.d.sample = _sampleRotation;

@@ -490,8 +492,10 @@

void mPSP2Teardown(struct mGUIRunner* runner) { UNUSED(runner); CircleBufferDeinit(&rumble.history); - vita2d_free_texture(tex); - vita2d_free_texture(oldTex); + vita2d_free_texture(tex[0]); + vita2d_free_texture(tex[1]); + vita2d_free_texture(tex[2]); + vita2d_free_texture(tex[3]); vita2d_free_texture(screenshot); mappedMemoryFree(outputBuffer, 256 * 256 * 4); frameLimiter = true;

@@ -583,17 +587,18 @@ scalex, scaley,

tint); } +void mPSP2Swap(struct mGUIRunner* runner) { + currentTex = (currentTex + 1) & 3; + runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256); +} + void mPSP2Draw(struct mGUIRunner* runner, bool faded) { unsigned width, height; runner->core->desiredVideoDimensions(runner->core, &width, &height); - void* texpixels = vita2d_texture_get_datap(tex); if (interframeBlending) { - void* oldTexpixels = vita2d_texture_get_datap(oldTex); - memcpy(oldTexpixels, texpixels, 256 * height * 4); - _drawTex(oldTex, width, height, faded, false); + _drawTex(tex[(currentTex - 1) & 3], width, height, faded, false); } - memcpy(texpixels, outputBuffer, 256 * height * 4); - _drawTex(tex, width, height, faded, interframeBlending); + _drawTex(tex[currentTex], width, height, faded, interframeBlending); } void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsigned width, unsigned height, bool faded) {
M src/platform/psp2/psp2-context.hsrc/platform/psp2/psp2-context.h

@@ -20,6 +20,7 @@ void mPSP2UnloadROM(struct mGUIRunner* runner);

void mPSP2PrepareForFrame(struct mGUIRunner* runner); void mPSP2Paused(struct mGUIRunner* runner); void mPSP2Unpaused(struct mGUIRunner* runner); +void mPSP2Swap(struct mGUIRunner* runner); void mPSP2Draw(struct mGUIRunner* runner, bool faded); void mPSP2DrawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded); void mPSP2IncrementScreenMode(struct mGUIRunner* runner);