diff --git a/CHANGES b/CHANGES index dafa39d3c..eb7f0c29f 100644 --- a/CHANGES +++ b/CHANGES @@ -63,6 +63,7 @@ Misc: - GBA, GB: ROM is now unloaded if a patch is applied - Util: Add 8-bit PNG write support - Qt: Rename "Resample video" option to "Bilinear filtering" + - GBA Video: Optimize when BLD* registers are written frequently 0.5.2: (2016-12-31) Bugfixes: diff --git a/include/mgba/internal/gba/renderers/video-software.h b/include/mgba/internal/gba/renderers/video-software.h index ba9db50f7..853a6f335 100644 --- a/include/mgba/internal/gba/renderers/video-software.h +++ b/include/mgba/internal/gba/renderers/video-software.h @@ -126,6 +126,7 @@ struct GBAVideoSoftwareRenderer { unsigned target1Bd; unsigned target2Obj; unsigned target2Bd; + bool blendDirty; enum BlendEffect blendEffect; color_t normalPalette[512]; color_t variantPalette[512]; diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 3e04be736..2c20a475a 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -97,6 +97,7 @@ static void GBAVideoSoftwareRendererReset(struct GBAVideoRenderer* renderer) { LOAD_16(entry, i, softwareRenderer->d.palette); GBAVideoSoftwareRendererWritePalette(renderer, i, entry); } + softwareRenderer->blendDirty = false; _updatePalettes(softwareRenderer); softwareRenderer->blda = 0; @@ -261,11 +262,14 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender value &= 0x1F1F; break; case REG_BLDY: - softwareRenderer->bldy = value & 0x1F; - if (softwareRenderer->bldy > 0x10) { - softwareRenderer->bldy = 0x10; + value &= 0x1F; + if (value > 0x10) { + value = 0x10; + } + if (softwareRenderer->bldy != value) { + softwareRenderer->bldy = value; + softwareRenderer->blendDirty = true; } - _updatePalettes(softwareRenderer); break; case REG_WIN0H: softwareRenderer->winN[0].h.end = value; @@ -515,6 +519,10 @@ static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* render } GBAVideoSoftwareRendererUpdateDISPCNT(softwareRenderer); + if (softwareRenderer->blendDirty) { + _updatePalettes(softwareRenderer); + softwareRenderer->blendDirty = false; + } int w; x = 0; @@ -702,7 +710,7 @@ static void GBAVideoSoftwareRendererWriteBLDCNT(struct GBAVideoSoftwareRenderer* renderer->target2Bd = GBARegisterBLDCNTGetTarget2Bd(value); if (oldEffect != renderer->blendEffect) { - _updatePalettes(renderer); + renderer->blendDirty = true; } }