Snes9x with xBRZ scaler support

This is for people involved in the developement of Snes9x, or SNES emulators in general.
BUG REPORTS BELONG IN TECH SUPPORT/BUG TRACKING!
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Snes9x with xBRZ scaler support

Post by Zenju »

Hi,

just as the title says, this is Snes9x with support for the xBRZ software scaler.
xBRZ is intended as a replacement for HQx and was added as a new scaler for selection in Snes9x's display settings.

Image

For a short comparison between xBRZ and other software scalers, see here:
http://www.vogons.org/viewtopic.php?t=34125

The source is also included, so if there's interest to add xBRZ to the official Snes9x release, the code is here for study.

Binary:
http://www.file-upload.net/download-893 ... Z.zip.html

Source:
http://www.file-upload.net/download-893 ... e.zip.html

Best regards, Zenju
Ryan
Grand Poobah
Posts: 670
Joined: Sat May 15, 2004 4:28 am
Location: Austin, TX

Re: Snes9x with xBRZ scaler support

Post by Ryan »

Moved your topic to what I feel is a more appropriate forum for this type of thing. :)
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Re: Snes9x with xBRZ scaler support

Post by OV2 »

Hi Zenju,

thank you for taking the time to add this to snes9x. However I can only include it in the official releases (if there ever is another ;)) if you allow an exception for s9x, since its license is not compatible with the GPL.

I'm not a huge fan of adding the TBB dependency, but I could add it as optional behind a define.
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

allow an exception for s9x
Sure, no problem :) Just let me know when time to implement draws near, and I'll add it to the official sources just like for HqMAME.

Code: Select all

if there ever is another
I truly hope so... but currently I have nothing to complain about 1.53 so far, and it supports all the features that I need. Actually I came from Zsnes and finally switched to Snes9x because I couldn't get Zsnes to compile due to it's assembly heritage. Snes9x OTOH was a breeze to get to compile. Of all the xBRZ implementations in various emulators that I've done, Snes9x was by far the easiest one. That was very nice.

Code: Select all

not a huge fan of adding the TBB dependency
On equal grounds, 4xBRZ and HQ4x show pretty much the same performance numbers. Howver xBRZ as it is right now only supports ARGB input and output. So for Snes9x I had to add two additional conversion steps from and to RGB565. Running all these things multithreaded is a huge perf improvement on my quad-core system. Single-threaded Snes9x has one core busy at about 80% - and emulation seems a little bit choppy sometimes. With TBB I have 4 cores running at only 24% each - emulation with xBRZ is smooth as butter. Since xBRZ is particularily designed to take full advantage of modern CPUs it would be a waste not to use multithreading for the scaling. Whether TBB as a dependency should be added to Snes9x is a different question however. For HqMame I provided xBRZ via a dll which internally uses TBB so that the core MAME source can be oblivious of this implementation detail.
psychic5
Snes9x White Belt
Posts: 3
Joined: Thu May 29, 2014 8:21 pm

Re: Snes9x with xBRZ scaler support

Post by psychic5 »

Hi,

Thank you for adding 4xbrz, best filter available in snes9x at the moment! Do you plan to add 2xbr (my favorite) and 3xbrz too?

Thanks again,

Psychic5
WalMartCartPusher
Snes9x White Belt
Posts: 32
Joined: Thu May 02, 2013 2:33 pm

Re: Snes9x with xBRZ scaler support

Post by WalMartCartPusher »

I am a tad late to the party...but I have been extensively testing the XBRZ filter...So far...I have not detected any grey lines other filters have made with DKC2 and the lines that even XBR leaves behind are gone....While this filter might not make it into the next version...I'd love to start experimenting on mixing XBRZ with different shaders via .cgp files.....So that being said...do you think you could possibly turn the filter into a .cg shader file as a shader and share the code on this thread?
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

WalMartCartPusher wrote:do you think you could possibly turn the filter into a .cg shader file as a shader and share the code on this thread?
I don't have experience programming cg shaders, but I guess it would be quite a challenge. xBRZ has been written from scratch in C++ and takes advantage of a lot of C++ features which don't have a direct representation in the shader language. That's unlike xBR which AFAIK was written in shader language first and then ported to C.
Aaron6537
Snes9x White Belt
Posts: 3
Joined: Thu Jun 05, 2014 9:58 am

Re: Snes9x with xBRZ scaler support

Post by Aaron6537 »

I just created an account to say... Thank you so much for this! :D I've been waiting for months for someone to add xBRZ to ANY snes emulator. If I knew how to code I would have added it myself when I discovered xBRZ months ago.

I do have a problem though. I can't use it! :( I have a 2.5ghz dual core processor that's not quite fast enough to run 4xBRZ. I don't know how difficult it would be to add 2xBRZ and 3xBRZ, but I;m sure a lot of others, including myself, would greatly appreciate it. I think I might be able to use 3xBRZ smoothly, but not sure.

If you could do this for the emulator community. It would be greatly appreciated.

If I wasn't dirt poor. I'd even pay you some money to do it.
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

Aaron6537 wrote:how difficult it would be to add 2xBRZ and 3xBRZ
Actually, easy :) I've added 2xBRZ and 3xBRZ:

Snes9x-1.53-xBRZ-2014-06-05.zip
Snes9x-1.53-xBRZ-2014-06-05-source.zip
psychic5
Snes9x White Belt
Posts: 3
Joined: Thu May 29, 2014 8:21 pm

Re: Snes9x with xBRZ scaler support

Post by psychic5 »

Thank you!

I really appreciate!
Aaron6537
Snes9x White Belt
Posts: 3
Joined: Thu Jun 05, 2014 9:58 am

Re: Snes9x with xBRZ scaler support

Post by Aaron6537 »

Oh my god! Thank you! Thank you! Thank you so much! Your awesome. I'm testing it right now. Not having very good results unfortunately. :(

Not sure what to do. Except for frame skipping. Automatic skipping one frame jumps the FPS from 42 up to 60.
It works perfectly for me with Kega Fusion 3.63 and xBRZ plugins made by milo1012. Maybe Snes9x uses more CPU than Kega Fusion.

Here's his plugins and source if your interested in checking it out. Look at the comments for his xBRZ url.
http://www.emucr.com/2013/04/kega-fusio ... 30427.html
Latest xBRZ plugins and source from his comment.
http://en.file-upload.net/download-8825 ... 1.zip.html

Not sure how you do it but maybe milo1012's version is much faster than the version you added. Maybe you can use his source to create faster and multithreaded versions.
Just trying to help you improve it to run on older computers. Thanks for letting me see what DKC and Mario looked like.
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

The kega version of xBRZ claims to be 2-8 % faster than the original code, so it's probably the differences between kega and snes9x that explain perf. Technically the kega xBRZ code does pretty much the same thing, except for needlessly giving up on encapsulation by undoing function calls that the compiler inlines easily, littering the code with magic numbers and removing some dead code that was never used anyway. Reading a book on modern C++ programming principles would not have hurt here [/end of rant] ;)
Aaron6537
Snes9x White Belt
Posts: 3
Joined: Thu Jun 05, 2014 9:58 am

Re: Snes9x with xBRZ scaler support

Post by Aaron6537 »

Ummm..... Lol. I only have a vague idea of what your talking about there but what I can say is I just updated my Kega xBRZ plugin and can now use the 3xBRZ multithreaded version instead of the 2xBRZ multithreaded version. The Snes9x xBRZ I can't even use 2xBRZ without adding 1 frame skip to it.

Maybe there is something to this Kega xBRZ plugin or do you reallly think Kega and Snes9x itself is what makes the speed difference?

By the way, I think my brain draws the line when it comes to coding. It's never gonna happen. Tried C# video tutorials once. Watched about 10 training videos. My brain stopped right after learning a little bit about operations, iterations, expressions, arrays, and statements. :oops:
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Re: Snes9x with xBRZ scaler support

Post by OV2 »

I've finally had time last weekend and added xbrz: snes9x_testbuild_24062014.zip

I rolled my on threaded implementation to remove the TBB dependency and also had to make some small modifications to the xbrz code to keep VS2008 compatibility. Hope that's ok (commit).
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

OV2 wrote:I've finally had time last weekend and added xBRZ.
It's looking good! I've done a very quick review of the code and have two remarks:

Code: Select all

num_xbrz_threads = sysinfo.dwNumberOfProcessors * 2;
I think the "*2" should be removed. On my machine this creates 8 threads, but I only have 4 CPU cores with no hyperthreading capability. But even with hyperthreading this seems like oversubscription.

Code: Select all

stretchImage32To16
Ideally this scaling should be executed as a bilinear filter on the graphics card. This would get rid of additional artifacts that are introduced by the simple nearest neighbor stretching algorithm. But I don't know if this is already possible in Snes9x.
psychic5
Snes9x White Belt
Posts: 3
Joined: Thu May 29, 2014 8:21 pm

Re: Snes9x with xBRZ scaler support

Post by psychic5 »

OV2 wrote:I've finally had time last weekend and added xbrz: snes9x_testbuild_24062014.zip

I rolled my on threaded implementation to remove the TBB dependency and also had to make some small modifications to the xbrz code to keep VS2008 compatibility. Hope that's ok (commit).
Can you add 2xbrz and 3xbrz too, as they are missing in your compile?
You can find Zenju's source with 2xbrz and 3xbrz above.

Thanks!
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Re: Snes9x with xBRZ scaler support

Post by OV2 »

Here is a version with 2x/3x: snes9x_testbuild_25062014.zip
Zenju wrote:I think the "*2" should be removed. On my machine this creates 8 threads, but I only have 4 CPU cores with no hyperthreading capability. But even with hyperthreading this seems like oversubscription.
I think I did that to get closer to your task granularity, but I guess you're right since this is CPU-bound.
Zenju wrote:

Code: Select all

stretchImage32To16
Ideally this scaling should be executed as a bilinear filter on the graphics card. This would get rid of additional artifacts that are introduced by the simple nearest neighbor stretching algorithm. But I don't know if this is already possible in Snes9x.
Usually there should be no streching, only the 32to16 conversion, unless it's a high res game. It would be nice to simply switch to 32bit textures for xbrz, but the current design doesn't support that.
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

I think I did that to get closer to your task granularity, but I guess you're right since this is CPU-bound.
The best multithreaded solution would be of course to have a task scheduler (like Intel TBB - hopefully this will be a standard C++ library maybe with C++17) and chop everything into tiny little pieces. In the absence of that using twice the number of threads than cores could be seen as a compromise. Anyway, I did a quick performance comparison between 4 and 8 threads on my 4 core machine and couldn't find any noticible perf difference.
Usually there should be no streching, only the 32to16 conversion
Okay, it seems there is a second nearest neighbor stretching happening when "Display Settings -> General ->Stretch Image" is checked. It would be great if this step could be done as biliinear filter: at least for xBRZ this introduces quite a number of artifacts. Compare stretched vs unstretched 4xBRZ:
Image
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Re: Snes9x with xBRZ scaler support

Post by OV2 »

That's what the "Bilinear Filtering" option in display settings should do.
Zenju
Snes9x White Belt
Posts: 16
Joined: Mon May 19, 2014 4:46 pm

Re: Snes9x with xBRZ scaler support

Post by Zenju »

OV2 wrote:That's what the "Bilinear Filtering" option in display settings should do.
lol, for some reason I didn't expect a user option for "bilinear filtering", and so didn't look for one. TIL
Post Reply