We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5328

Summary: [PATCH] video: Backport the fast paths for 24/32-bit blitting
Product: SDL Reporter: Cameron Cawley <ccawley2011>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz, sylvain.becker
Version: HG 1.2   
Hardware: All   
OS: All   
Attachments: video: Backport the fast paths for 24/32-bit blitting
test-case for SDL-1.2
compare script
test-case for SDL-1.2
compare script
results file
test-case for SDL-1.2
results file

Description Cameron Cawley 2020-10-24 15:00:43 UTC
Created attachment 4484 [details]
video: Backport the fast paths for 24/32-bit blitting

This backports the optimized blitting code to SDL 1.2. This provides noticeable performance improvements in CSE2, however I haven't done extensive amounts of testing for all of the new paths.
Comment 1 Ozkan Sezer 2020-10-24 15:25:02 UTC
(In reply to Cameron Cawley from comment #0)
> however I haven't done
> extensive amounts of testing for all of the new paths.

If you can do some more testing, I'd wait, say, a week or
something.
Comment 2 Sylvain 2020-10-25 15:50:43 UTC
Hey, if you look at the bug 4503
There is a testcase, an image, and a script to compare.

the testcase load a multi-color image, convert to all format and print some CRC for each step.
if you run it before the patch to have a reference and after: the compare script will tell if it breaks anything and the speed improvements.

(I think there was a few fix to add like ... 
https://hg.libsdl.org/SDL/rev/233b2a61cad1
https://hg.libsdl.org/SDL/rev/dff36de37426 )

maybe the format of SDL 1.2 are different and testcase should be adapted
Comment 3 Ozkan Sezer 2020-11-12 04:21:52 UTC
Has the patch received more testing?
Comment 4 Sylvain 2020-11-13 10:00:22 UTC
Created attachment 4515 [details]
test-case for SDL-1.2

Hello, I tried the test-case from the previous ticket, and there are much more differences that what I remembered of SDL-1.2.

So I ported it to SDL-1.2.
At least, it compiles and runs.

gcc fast_bench.c -Ibuild/include/SDL/ -Lbuild/lib -lSDL -lz -lcrypto


There are TODOs open:

- Need to use IMG_Load (instead of loadBMP) for a .png file, so that the image has an alpha channel for testing.

- Is there blending in SDL-1.2 ?

- Currently it has lots of pixel_format:
  It takes all SDL2 pixel formats and copies them as SDL1 pixel formats.
  Not sure if that are all relevant. ( BPP1 and BPP4 commented out )

It needs to be tested with the SDL-1.2 + patch
Comment 5 Sylvain 2020-11-13 10:04:59 UTC
Created attachment 4516 [details]
compare script

The compare script hasn't changed much. I just updated to python3
(if needed:
- keys = db2.keys()
+ keys = list(db2.keys()) #python3
)

Usage: 

./testcase.out test.png  > ref1.txt
apply the patch
./testcase.out test.png  > ref2.txt

python compare_blitlog.py ref1.txt ref2.txt

The image must be relevant. big enough to mesure the image processing time.
Multi color + alpha so that we have all corner cases.
various size odd/even, pitch padding.
Comment 6 Sylvain 2020-11-13 10:32:57 UTC
After fixing a crash: https://hg.libsdl.org/SDL/rev/0bbdbc7b3ff2 

I've just tested the patch, and all pixel format ARGB2101010 are failing. not sure if this is supported, but at there are not "unsupported()" neither ?

Otherwise, there are improvements as expected: 
like BGRX8888 ->       RGB24 with goes from 15 ms to 3 ms. 
and many others.
Comment 7 Sylvain 2020-11-13 16:42:33 UTC
Created attachment 4517 [details]
test-case for SDL-1.2

Update the test-case to remove ARGB2101010 and use IMG_Load from SDL_image
Comment 8 Sylvain 2020-11-13 16:43:22 UTC
Created attachment 4518 [details]
compare script

Update the script to print the "faster/slower" indication
Comment 9 Sylvain 2020-11-13 16:46:23 UTC
Created attachment 4519 [details]
results file

This my result file if you want to look at.
It shows where there are blit improvements.

(NB: there are a few irrelevant suspicious/slower conversion because blits at two fast in those cases.)
Comment 10 Sylvain 2020-11-14 08:05:52 UTC
Created attachment 4521 [details]
test-case for SDL-1.2

Update the test-case to re-add the SDL_GetPerformanceCounter + some padding/memcheck.
Comment 11 Sylvain 2020-11-14 08:08:24 UTC
Created attachment 4522 [details]
results file

This the results file which show the the speed improvements on 50 conversions.
using the image  "IMG_2476_ColorKey_very_small.png" from bug 4503
Comment 12 Sylvain 2020-11-14 08:13:06 UTC
The results file looks ok to me, 
So I have committed the patch https://hg.libsdl.org/SDL/rev/e901fc96cf25
Comment 13 Ozkan Sezer 2020-11-14 08:25:12 UTC
Sylvain: Thanks for marvelous work testing this!
And thanks Cameron Cawley for the backport patch!

Closing this as fixed.
Comment 14 Ozkan Sezer 2020-11-14 08:26:44 UTC
Closed as fixed.
Comment 15 Cameron Cawley 2020-11-14 22:47:43 UTC
Thanks a lot for sorting this out!