bsnes vsync development thread

Archived bsnes development news, feature requests and bug reports. Forum is now located at http://board.byuu.org/
Locked
tetsuo55
Regular
Posts: 307
Joined: Sat Mar 04, 2006 3:17 pm

bsnes vsync development thread

Post by tetsuo55 »

Hi Byuu,

i don't remember if i mentioned this before.

Media Player classic has long had the problem of Tearing just like Bsnes does. That is until Casimir came along and created a special rendering mode which completely fixes the tearing.

The base problem is the same, the monitor refreshrate is different from the rendered refreshrate.

The fix has someting to do with VMR9 renderless and only works in that mode, not sure if the MPC licence is compatible with Bsnes, or if its even usefull in any way. At least you can take a look.

A bonus to this is that it only works in full-screen mode, but exiting the game would return the emulator to regular windows size!

link: http://mpc-hc.sourceforge.net/AntiTearing.html
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

How much latency does it introduce? Latency isn't an issue when there's no interaction with the source material.
tetsuo55
Regular
Posts: 307
Joined: Sat Mar 04, 2006 3:17 pm

Post by tetsuo55 »

I cannot be sure, there has to be some ofcourse, but i do not notice any lip-sync delay in movies.
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

... because it also delays audio accordingly. -_-

Most media-player tricks cannot be used in timing critical stuff like emulators.
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
byuu

Post by byuu »

Yeah, media players get it easy :P

Thanks for the suggestion anyway.
tetsuo55
Regular
Posts: 307
Joined: Sat Mar 04, 2006 3:17 pm

Post by tetsuo55 »

I read the sourcecode.

According to what i read there is no delay at all.

The code simply uses the following call to fix the tearing:

SetRenderingMode(VMR9Mode_Renderless), as this is "Gaming mode" there is little to no room for any lag

the source is here:
https://mpc-hc.svn.sourceforge.net/svnr ... senter.cpp
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

All I know is that it wasn't too bad on my CRT, but now that I have an LCD, I'm very envious of zsnes vsync. I just ticked the box and the tearing went away, and I noticed no other differences in game speed or audio quality.
byuu

Post by byuu »

Yeah, I have to admit, I was testing Street Racer the other day on the CRT TV, and was just blown away by how much more fun the game was without all the tearing. Sigh ...

Maybe we should make an audio resampler that actually works into a bounty. I'd put money on that. Problem is getting it to work on Linux, that'll be ten times harder, and that's my primary dev platform where I'd want it fixed first. But both video and audio lock up the process waiting for events.
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

This might sound like a stupid question, but since zsnes is open source, how can the way in which they (and others) succeed elude you, blargg, and Nach? Are you doing something fundamentally different that makes typical strategies inapplicable?
FirebrandX
Trooper
Posts: 376
Joined: Tue Apr 19, 2005 11:08 pm
Location: DFW area, TX USA
Contact:

Post by FirebrandX »

byuu wrote: Problem is getting it to work on Linux, that'll be ten times harder, and that's my primary dev platform where I'd want it fixed first. But both video and audio lock up the process waiting for events.
You're getting sleepy... Eyes closing... Very sleepy. You're now asleep and will do exactly as I say...


I command you to put bsnes windows version on first priority. When you awake, you'll have no memory of this post, other than a strong desire to fix screen tearing for Windows bsnes.

You will awake... Now!
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

FitzRoy wrote:This might sound like a stupid question, but since zsnes is open source, how can the way in which they (and others) succeed elude you, blargg, and Nach? Are you doing something fundamentally different that makes typical strategies inapplicable?
Why am I being dragged into this?
Since when have I worked with Video rendering APIs?

I also wouldn't bother blargg for anything other than the theoretical, he's a Mac user (DirectX doesn't exist for Macs).
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

Sorry Nach, I couldn't remember who was working on the problem before.

Byuu, I'd put up $50 myself for the bounty. But I don't know how to describe exactly what you're requiring, if you could. My fear is someone will come up with a solution that comes at a cost you find unacceptable.

Maybe you could have a full-blown write-up of the problem in a new thread and I could link to it from the compatibility list.
Snark
Trooper
Posts: 376
Joined: Tue Oct 31, 2006 7:17 pm

Post by Snark »

FirebrandX wrote:
byuu wrote: Problem is getting it to work on Linux, that'll be ten times harder, and that's my primary dev platform where I'd want it fixed first. But both video and audio lock up the process waiting for events.
You're getting sleepy... Eyes closing... Very sleepy. You're now asleep and will do exactly as I say...


I command you to put bsnes windows version on first priority. When you awake, you'll have no memory of this post, other than a strong desire to fix screen tearing for Windows bsnes.

You will awake... Now!


That's bad etiquette...Even if someone is goofing. If you asked M.A.M.E something similar you would have your request send back to the stone age...or push back 6 months at least...byuu is free to make whatever OS his priority.
I want to fry~~ Sky Hiiiiiiiiigh~
Let's go-o-o-O~ togeda~
Snark
Trooper
Posts: 376
Joined: Tue Oct 31, 2006 7:17 pm

Post by Snark »

Franky wrote:
FitzRoy wrote:Sorry Nach, I couldn't remember who was working on the problem before.

Byuu, I'd put up $50 myself for the bounty. But I don't know how to describe exactly what you're requiring, if you could. My fear is someone will come up with a solution that comes at a cost you find unacceptable.

Maybe you could have a full-blown write-up of the problem in a new thread and I could link to it from the compatibility list.
Seriously man, do you put a bounty on everything?
More seriously, I think the people that are capable or interested in fixing these issues don't care for the money and will do it even without the bounty anyway...That is: chances are there won't be anyone showing up outside those who we already known in the emulation scene..and they're not in emulation for the money,so...

Make it 10 000$ perhaps haha...Then, maybe someone outside the scene will show up. (Yes I'm just joking, point is: I doubt 50 bucks will attract anyone.)

I'm just curious if ANYONE has ever helped and then requested the bounty.
I want to fry~~ Sky Hiiiiiiiiigh~
Let's go-o-o-O~ togeda~
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

Snark wrote: Make it 10 000$ perhaps haha...Then, maybe someone outside the scene will show up. (Yes I'm just joking, point is: I doubt 50 bucks will attract anyone.)

I'm just curious if ANYONE has ever helped and then requested the bounty.
For the record, two people have collected a bounty from me so far. Instead of sitting here and pissing on the amount I'm offering, maybe you'd like to add to it yourself and make it larger? That's sort of the concept behind it, but I'm the only one doing it. Everyone else just repeatedly asks (or commands) that it be fixed.
Snark
Trooper
Posts: 376
Joined: Tue Oct 31, 2006 7:17 pm

Post by Snark »

FitzRoy wrote:
Snark wrote: Make it 10 000$ perhaps haha...Then, maybe someone outside the scene will show up. (Yes I'm just joking, point is: I doubt 50 bucks will attract anyone.)

I'm just curious if ANYONE has ever helped and then requested the bounty.
For the record, two people have collected a bounty from me so far. Instead of sitting here and pissing on the amount I'm offering, maybe you'd like to add to it yourself and make it larger? That's sort of the concept behind it, but I'm the only one doing it. Everyone else just repeatedly asks (or commands) that it be fixed.
I'm not "sitting here and pissing on the amount your offering", I was merely saying I thought it was unlikely to be enough to attract people outside those we already know.

And yes, for MY record, so long as I can do so anonymously I'm willing to add money (the only way I can think of effectively doing this is to just send the cash directly to whatever address though...) I'd chip 20-30$ and if I saw other people actually doing the same I would probably contribute once in while.

Of course, to anyone else that would consider contributing: of course you can never have an absolute 100% guarantee that your donation will actually go to the actual cause itself, but that's true for basically any kind of donation. It always require a minimal of trust (and I do trust the cash will be used as said. Otherwise I wouldn't give in the first place)
Last edited by Snark on Wed Aug 13, 2008 2:17 pm, edited 1 time in total.
I want to fry~~ Sky Hiiiiiiiiigh~
Let's go-o-o-O~ togeda~
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

Cash is only given when it's done, all you're offering is the commitment.
Snark
Trooper
Posts: 376
Joined: Tue Oct 31, 2006 7:17 pm

Post by Snark »

FitzRoy wrote:Cash is only given when it's done, all you're offering is the commitment.
Very well. But let's say tomorrow someone arrives and fix the issue..Then I'd need some way of sending the cash. Anyway, if that happens (someone add a fix and claim the bounty) let us know.
I want to fry~~ Sky Hiiiiiiiiigh~
Let's go-o-o-O~ togeda~
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

If you don't have the cash ready, you don't make the commitment. If you don't have paypal, you don't make the commitment. And there is no bounty yet because nobody has a clue what the conditions are.
DancemasterGlenn
Veteran
Posts: 637
Joined: Sat Apr 21, 2007 8:05 pm

Post by DancemasterGlenn »

FitzRoy wrote:
Snark wrote: Make it 10 000$ perhaps haha...Then, maybe someone outside the scene will show up. (Yes I'm just joking, point is: I doubt 50 bucks will attract anyone.)

I'm just curious if ANYONE has ever helped and then requested the bounty.
For the record, two people have collected a bounty from me so far.
I feel like I remember this happening a while ago, and if I'm remembering correctly, the people involved really didn't care so much about the money. At least one of those times the bounty wasn't even mentioned until you brought it up afterwards. I think it was more the job itself and the fact that whatever was being worked on interested them that brought them to the issues that needed fixing. It seems like every so often you guys get very focused on one particular bug, and then someone finally fixes it, bounty or no.

I've got nothing against the bounty system, but I wouldn't say that it's currently the driving force behind bsnes development. I wish it was more of a driving force... I know that if I could code I'd be going after those bounties. But on the other hand, I'd also be going after those bugs because I respect the project and would like to help byuu out. If the goal is really to attract outside help in fixing these bugs, isn't there a better place than the forums we all frequent in which to talk about these bounties?
I bring the trouble.
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

DancemasterGlenn wrote: I've got nothing against the bounty system, but I wouldn't say that it's currently the driving force behind bsnes development.
lol, who said this?

And I talk about the bounties here insofar as the people who are supposed to contributing to them are aware that they exist. Knowing that something exists is a precondition to contributing to it.
Last edited by FitzRoy on Wed Aug 13, 2008 5:19 pm, edited 1 time in total.
DancemasterGlenn
Veteran
Posts: 637
Joined: Sat Apr 21, 2007 8:05 pm

Post by DancemasterGlenn »

FitzRoy wrote:
DancemasterGlenn wrote: I've got nothing against the bounty system, but I wouldn't say that it's currently the driving force behind bsnes development.
lol, who said this?
LOLZ U CAWT ME. I guess that completely nullifies everything else I said, which is why this is the only part you replied to.
I bring the trouble.
FitzRoy
Veteran
Posts: 861
Joined: Wed Aug 04, 2004 5:43 pm
Location: Sloop

Post by FitzRoy »

Whatever, it's a failed concept on major shit like this. I imagined that enough people begged for it repeatedly despite the issue being known that those same people would be able to translate their desires into cash which, combined, would be incentivizing. But I was wrong. They'll just beg until the end of time. The reason it doesn't get fixed anyway is probably very similar to the icon issue. Windows, sure, cake. But byuu wants a unified solution between windows and linux. Nobody writes decent drivers for linux because no one develops games for it. No one develops games for it because no one uses it. No one uses it because rather than create an official, windows-like distro with which to easily convert familiarized, non-savvy Windows users, they do a million things differently because they're Windows hating separatists, so they clusterfuck themselves with practically unlimited customization.
byuu

Post by byuu »

A tough topic.

I would obviously prefer that everyone help out of goodwill and flowers and kittens and all that, and I would prefer no money exchange hands. But that's not really realistic. So long as money is not handed to me (though I would accept hardware donations), I don't really have any serious reservations. Nor do I mind pitching in if it helps make you guys happy with the software. Just you using it is payment enough for me, basically free QA testing :)

As for the system itself, it's pretty obvious that it's of no use for things like SPC7110 / SFX / SA1. All of that would take weeks of effort, and someone with very highly specialized skills; and even at minimum wage it's way more than we could afford. Luckily neviksti stopped in and took care of SPC7110, free of charge. You're right, people with that level of skill, investing that much time, aren't out for the money. Like neviksti, and like all of us emu devs. We do it because we enjoy it.

Really, it's the quick fixes and one-day things that people go after for money. And that's exactly what happened with the Direct3D fix we got a while back. Three people worked on that, and two accepted the bounty. And now you can resize bsnes' video output without it becoming overly blurry, a win-win. And that cost very little in the end. Me wasting time on stuff like that instead of the core holds back emulation progress.

Video sync with clean audio is one of those things that a lot of people have the ability to implement, just not me. I've followed the advice of countless people explaining it, yet I always manage to screw it up in one way or another. Yet every other emulator seems to pull it off, so it's obviously doable, and has been done, by a lot of people. And who knows, maybe someone will do it for free in the end. Or maybe I'll figure it out first (hahah.)

I will say that bsnes is a bit more unique than other emulators: because of the cothreading system, I can easily run one processor for a really long time with no need to break out and sync the other, so long as they aren't talking to each other. It's kind of a just-in-time for parallelism system. This results in nice speedups that make up for the speed hit of the green thread switching, but it also means that you get very unusual amounts of audio samples per emulated frame.

I tried to compensate for this: the more buffer I used, the worse the latency. The less buffer I used, the more dramatic the resampling to different numbers of samples became. And even with ~200ms latency, you could still audibly detect the block resampling very clearly.

I even tried forcing the CPU and SMP to stay in sync down to the cycle (~10-15% speed hit), and for whatever reason, the samples per frame were still erratic enough that I couldn't keep the resampling from being obvious. I think this was due to the video API blocking the thread for differing lengths of time trying to vsync.

A lot of systems, such as the NES, SMS and GBC (I may be wrong here), generate sound along with the CPU, and there's only one 'clock' involved.

To get this to work, what I really need is a simple class:

Code: Select all

class resampler {
public:
  void input_sample(uint16_t left, uint16_t right);
  bool samples_pending();
  uint32_t read_sample(); //returns (left << 16) + right
  void initialize(unsigned frequency); //also called to reset / flush the buffer
};
That class cannot block the thread or sleep if samples start getting fed too quickly (because the video driver will be blocking to vsync, and two blocking APIs = epic fail for both), but it can poll the system time to get a sense of how fast samples are coming in and going out.

Most likely, this means it would have to send out blank samples when first starting out for a bit to get a "feel" for what it should be doing. I could maybe spool blocks at a time, so that you can keep track of how many input samples you're getting on average, so you know roughly how many you want to use to create the output, and how many to reserve for future use.

Unfortunately, due to the uselessness of a lot of Linux audio APIs, it will have to be agnostic to the underlying sound system. If it needs information like the play cursor position, it will only work on a few sound drivers. Maybe even only DirectSound.
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

Can we adjust the interface a bit, for efficiency/simplicity? Basically, I'm thinking you don't need "samples_pending", just a way to read as many samples as are available into the caller's buffer.

Code: Select all

class Resampler { 
public:
    // Sets output sample rate and removes all samples from buffer
    void set_rate( int sample_rate );
    
    // Writes pair of samples, each 16-bit signed
    void write( int left, int right ); 
    
    // Reads at most n sample pairs to *out and returns number actually written
    int read( uint32_t* out, int n );
};
Locked