Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vita: Fix flickering when using frameskip #1822

Merged
merged 1 commit into from Aug 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/platform/psp2/psp2-context.c
Expand Up @@ -52,7 +52,7 @@ static enum ScreenMode {

static void* outputBuffer;
static int currentTex;
static vita2d_texture* tex[4];
static vita2d_texture* tex[2];
static vita2d_texture* screenshot;
static Thread audioThread;
static bool interframeBlending = false;
Expand Down Expand Up @@ -326,8 +326,6 @@ void mPSP2Setup(struct mGUIRunner* runner) {
runner->core->desiredVideoDimensions(runner->core, &width, &height);
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);

Expand Down Expand Up @@ -494,8 +492,6 @@ void mPSP2Teardown(struct mGUIRunner* runner) {
CircleBufferDeinit(&rumble.history);
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;
Expand Down Expand Up @@ -588,15 +584,27 @@ void _drawTex(vita2d_texture* t, unsigned width, unsigned height, bool faded, bo
}

void mPSP2Swap(struct mGUIRunner* runner) {
currentTex = (currentTex + 1) & 3;
runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256);
bool frameAvailable;
if (runner->core->platform(runner->core) == PLATFORM_GBA) {
struct GBA* gba = runner->core->board;
frameAvailable = gba->video.frameskipCounter <= 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach. However, I don't like the idea of having to cast to a specific core to grab the frameskip counter. It's not generic, and I want to reduce the number of things peering into the cores, not increase. Not sure if there's a better approach however.

} else if (runner->core->platform(runner->core) == PLATFORM_GB) {
struct GB* gb = runner->core->board;
frameAvailable = gb->video.frameskipCounter <= 0;
} else {
frameAvailable = false;
}
if (frameAvailable) {
currentTex = !currentTex;
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);
if (interframeBlending) {
_drawTex(tex[(currentTex - 1) & 3], width, height, faded, false);
_drawTex(tex[!currentTex], width, height, faded, false);
}
_drawTex(tex[currentTex], width, height, faded, interframeBlending);
}
Expand Down