From 7e9937b80fffbc979a0b17764c2b490e23f77373 Mon Sep 17 00:00:00 2001 From: Splendide Imaginarius <119545140+Splendide-Imaginarius@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:21:55 +0000 Subject: [PATCH] Bitmap: short-circuit shader/bilinear interpolation Benchmark shows a speedup from 10.4s to 4.1s. --- src/display/bitmap.cpp | 38 ++++++++------ .../Graphics/Pictures/lime.png | Bin 0 -> 5141 bytes tests/benchmark-bitmap-dup/dup-speed-test.rb | 47 ++++++++++++++++++ 3 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 tests/benchmark-bitmap-dup/Graphics/Pictures/lime.png create mode 100755 tests/benchmark-bitmap-dup/dup-speed-test.rb diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index 62ad9df..cabfd6f 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -737,16 +737,16 @@ Bitmap::Bitmap(const Bitmap &other, int frame) throw e; } - GLMeta::blitBegin(p->gl); + GLMeta::blitBegin(p->gl, false, SameScale); // Blit just the current frame of the other animated bitmap if (!other.isAnimated() || frame == -1) { - GLMeta::blitSource(other.getGLTypes()); + GLMeta::blitSource(other.getGLTypes(), SameScale); } else { auto &frames = other.getFrames(); - GLMeta::blitSource(frames[clamp(frame, 0, (int)frames.size() - 1)]); + GLMeta::blitSource(frames[clamp(frame, 0, (int)frames.size() - 1)], SameScale); } - GLMeta::blitRectangle(rect(), rect(), true); + GLMeta::blitRectangle(rect(), rect()); GLMeta::blitEnd(); } else { @@ -768,9 +768,9 @@ Bitmap::Bitmap(const Bitmap &other, int frame) throw e; } - GLMeta::blitBegin(newframe); - GLMeta::blitSource(sourceframe); - GLMeta::blitRectangle(rect(), rect(), true); + GLMeta::blitBegin(newframe, false, SameScale); + GLMeta::blitSource(sourceframe, SameScale); + GLMeta::blitRectangle(rect(), rect()); GLMeta::blitEnd(); p->animation.frames.push_back(newframe); @@ -806,9 +806,9 @@ Bitmap::Bitmap(TEXFBO &other) // Skip blitting to lores texture, since only the hires one will be displayed. if (p->selfHires == nullptr) { - GLMeta::blitBegin(p->gl); - GLMeta::blitSource(other); - GLMeta::blitRectangle(rect(), rect(), true); + GLMeta::blitBegin(p->gl, false, SameScale); + GLMeta::blitSource(other, SameScale); + GLMeta::blitRectangle(rect(), rect()); GLMeta::blitEnd(); } @@ -1086,10 +1086,16 @@ void Bitmap::stretchBlt(IntRect destRect, SDL_Surface *blitTemp = 0; bool touchesTaintedArea = p->touchesTaintedArea(destRect); bool unpack_subimage = srcSurf && gl.unpack_subimage; - + + const bool scaleIsOne = sourceRect.w == destRect.w && sourceRect.h == destRect.h; + if (scaleIsOne) { + smooth = false; + } + if (!srcSurf && opacity == 255 && !touchesTaintedArea) { /* Fast blit */ + // TODO: Use bitmapSmoothScaling/bitmapSmoothScalingDown configs for this. GLMeta::blitBegin(getGLTypes()); GLMeta::blitSource(source.getGLTypes()); GLMeta::blitRectangle(sourceRect, destRect, smooth); @@ -1227,8 +1233,8 @@ void Bitmap::stretchBlt(IntRect destRect, TEXFBO &gpTex = shState->gpTexFBO(abs(destRect.w), abs(destRect.h)); Vec2i gpTexSize; - GLMeta::blitBegin(gpTex); - GLMeta::blitSource(getGLTypes()); + GLMeta::blitBegin(gpTex, false, SameScale); + GLMeta::blitSource(getGLTypes(), SameScale); GLMeta::blitRectangle(destRect, IntRect(0, 0, abs(destRect.w), abs(destRect.h))); GLMeta::blitEnd(); @@ -2432,9 +2438,9 @@ int Bitmap::addFrame(Bitmap &source, int position) p->surface = 0; } else { - GLMeta::blitBegin(newframe); - GLMeta::blitSource(source.getGLTypes()); - GLMeta::blitRectangle(rect(), rect(), true); + GLMeta::blitBegin(newframe, false, SameScale); + GLMeta::blitSource(source.getGLTypes(), SameScale); + GLMeta::blitRectangle(rect(), rect()); GLMeta::blitEnd(); } diff --git a/tests/benchmark-bitmap-dup/Graphics/Pictures/lime.png b/tests/benchmark-bitmap-dup/Graphics/Pictures/lime.png new file mode 100644 index 0000000000000000000000000000000000000000..d7b672334abf75665b460587a78b5fce4fe58408 GIT binary patch literal 5141 zcmeAS@N?(olHy`uVBq!ia0y~ykOVR%85o&?l-iE7Oh8H@*(1o8fuTx`fuW&=f#DZW zsNn?zL#Y7+!>a@a2CEqi4B`cIb_Lo1CD;OdLR=aCGyMPmKYwpTAW(!c$=lt9@jsL9 zJs^j@#M9T6{RNje3%B%r)j!4z48nDuE{-7;x85FP