Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input doesn't seem to work #4

Closed
FIM43-Redeye opened this issue Jun 5, 2024 · 22 comments
Closed

Input doesn't seem to work #4

FIM43-Redeye opened this issue Jun 5, 2024 · 22 comments

Comments

@FIM43-Redeye
Copy link

Since this is a very small project, I'm not actually sure how to go ahead and report a bug, What I do know is that BeesNES doesn't seem to take any inputs from my keyboard, and when I do put in new input configs, they stay temporarily (for as long as the program is running) but disappear on restart. Any idea what's up?

@L-Spiro
Copy link
Owner

L-Spiro commented Jun 6, 2024 via email

@FIM43-Redeye
Copy link
Author

So I'm building the source, but I'm unfortunately really not adept in C++ at all- I'm mostly really interested in this project and wanted to have a look, but to be honest, I don't really know where to begin, most of what I do is C#. Would a simple printf work? Should I use one for each function in Input that enumerates controllers? Apologies for my ineptitude.

@L-Spiro
Copy link
Owner

L-Spiro commented Jun 6, 2024 via email

@FIM43-Redeye
Copy link
Author

FIM43-Redeye commented Jun 6, 2024

So, oddly, that line doesn't seem to be called at all when I run it in the debugger. When I breakpoint it, the breakpoint never trips, and nothing prints to the debug window that looks like a product name.

Also, as a side note, I'm getting a 'symbols failed to load for wrap_oal.dll. Failed to find local symbol file wrap_oal.pdb' error too. Nothing big, but I know I installed the OpenAL SDK.

@L-Spiro
Copy link
Owner

L-Spiro commented Jun 7, 2024 via email

@FIM43-Redeye
Copy link
Author

Still nothing, so far. Buttons are useless, but the wrap_oal problem disappeared, so that was probably on my end. Interestingly, when I do hook up a controller, it picks up on it just fine, but then I can't assign inputs with it at all.

@L-Spiro
Copy link
Owner

L-Spiro commented Jul 18, 2024

I wanted to redo the CPU and see if that was an issue.
This is now CPU #3. It’s like the original CPU but refined, sleek, and no hidden bugs outside of what I already know needs to be fixed.
CPU #2 had all kinds of issues and passed very few tests. It might have bee causing input-polling issues.

So try things now.

@FIM43-Redeye
Copy link
Author

FIM43-Redeye commented Oct 2, 2024

Tried now. Unfortunately input is still broken. No preexisting errors, though. Sorry for such a late response.
I did get:

mincore\com\oleaut32\dispatch\ups.cpp(2126)\OLEAUT32.dll!00007FFC880C470C: (caller: 00007FFC880C49FA) ReturnHr(1) tid(c88) 8002801D Library not registered.
onecore\vm\dv\storage\plan9\rdr\dll\util.cpp(99)\p9np.dll!00007FFB8C46F14C: (caller: 00007FFB8C469430) LogHr(1) tid(6c4) C0000034 Msg:[瑎牃慥整楆敬☨敤楶散‬奓䍎剈乏婉ⱅ☠瑡牴扩瑵獥‬椦卯慴畴ⱳ渠汵灬牴‬䥆䕌䅟呔䥒啂䕔也剏䅍ⱌ⠠䥆䕌卟䅈䕒剟䅅⁄⁼䥆䕌卟䅈䕒坟䥒䕔簠䘠䱉彅䡓剁彅䕄䕌䕔Ⱙ䘠䱉彅偏久‬䥆䕌卟乙䡃佒低单䥟彏低䅎䕌呒‬畮汬瑰Ⱳ〠)]

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 3, 2024

regsvr32 oleaut32.dll
Try this to address your error. Run with admin permissions.

image
Does it respond to your keyboard when you configure a controller?

Try running in compatibility mode.

@FIM43-Redeye
Copy link
Author

Registering oleaut32.dll did not seem to help. More concerningly, I can't configure a controller at ALL, and none show up in the input devices list. Running in compatibility mode didn't help either.

Anything I can do on this end to make the code give more information as to what's wrong? This dumbfounds me.

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 3, 2024

Nothing shows in the list yet and those boxes don’t respond to controllers yet.
For now I am only trying to see if your keyboard can at least be recognized.

Input is polled here:
https://github.com/L-Spiro/BeesNES/blob/main/Src/Windows/MainWindow/LSNMainWindow.cpp#L1038
You could add print-outs to see if ::GetAsyncKeyState() returns anything for a key you know to be pressing.

https://github.com/L-Spiro/BeesNES/blob/main/Src/Windows/MainWindow/LSNMainWindow.cpp#L1587
This is where controllers are searched. You can try to follow it in any of the debug builds and check where it fails to gather your controller.
ChatGPT can help you adjust the code so that it finds your controller and then you can tell me what you did if it works.

@FIM43-Redeye
Copy link
Author

FIM43-Redeye commented Oct 3, 2024

Found it!

So the issue is that the controller dialog appears to not have any effect on what keys are actually recognized . The hardcoded keys starting at line 1158 of LSNMainWindow.cpp work fine (though a little futzing was needed to replace VK_OEM_1 with K at lines 1085 and 1159, I assume that key's nice and handy on your keyboard). Aside from that it's a bit crunchy-sounding (significant slowdown on an R9 7940HS), but that's probably my issue to debug and not yours. Though it IS absolutely tapping out one of my cores.

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 3, 2024

My laptop seems much lower-spec than that and it can run at up to 90 FPS.
A lot of work goes into the visuals and audio. How well does Options -> Video Filter -> None work?
It might be a difference in AVX capabilities and I may have chosen bad defaults for my L. Spiro Filter for your AVX support since my own support may vary.

Audio may also be playing a part:
https://github.com/L-Spiro/BeesNES/blob/main/Src/Apu/LSNApu2A0X.h#L187
Try changing that * 3 to * 6 or something.
When you load a ROM, you will see this in Visual Studio: Kernel size: 95.
Change * 3 to something else to lower that number. Increasing it should lower that value but I may be misremembering which part of the equation that is influencing, so it might need to be lowered instead. Check the debug print to confirm.

@FIM43-Redeye
Copy link
Author

My laptop has AVX, AVX2, and AVS-512, but not AVX10. Disabling the filter significantly increases performance, but still doesn't hit stable FPS.
Bumping up that value to 6 did not meaningfully improve performance, but it did push the kernel size to 191. However, I can confirm that the L. Spiro filter runs far worse than with no filter or the Blargg filter. Using it to artificially slow the system down creates a sound best described as the following, where | stands for a good audio sample and - stands for silence:
|---|---|---|---
The slices are extremely small, but there's definitely an audible distance between them. Not sure if that'll help much, but I wanted to report it.

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 3, 2024

Bumping up that value to 6 did not meaningfully improve performance, but it did push the kernel size to 191.

That number is supposed to go down. Higher means worse performance.
Change it to * 1.
The audio buffers are 16 samples long. This will be configurable later but for now I want it to be as close to real-time as possible.
All-in-all this is supposed to run on medium-end hardware even with some settings cranked up, but I am going to just have to get some more hardware for testing on my end.

https://github.com/L-Spiro/BeesNES/blob/main/Src/Audio/LSNAudioBase.h#L142
You can also decrease the output rate by changing both of those 44100’s to something else.

@FIM43-Redeye
Copy link
Author

Even with the kernel shrunk to 31, performance appears similar to what it initially was. I think something different from audio is eating cycles.

What are the specs of your laptop? If it's Intel, that may explain how optimizations that work excellently on it seem to crash and burn on an AMD system. I can try to get access to another Intel system and test it there to see if the performance is linked to manufacturer.

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 3, 2024

I was thinking it is the AMD part too, because your specs are way better than mine:
11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz.
I will need to get an AMD machine unless you are able to find bottlenecks.
Performance might improve once I had GPU support but if “None” filter is still slow then it seems unlikely to be the only issue.
Eating an entire core is by design, but there may be something about that design that just doesn’t play well with AMD.

@FIM43-Redeye
Copy link
Author

FIM43-Redeye commented Oct 3, 2024

I ran the performance profiler- it's a bit clumsy, but here are my results:
Report20241003-1059.zip

From my extremely inexpert analysis, it looks like your code is actually running excellently, and there's some kind of user32.dll external call that's devouring CPU.

@FIM43-Redeye
Copy link
Author

I always hate to doublepost, but I think I found the bottleneck:
https://github.com/L-Spiro/BeesNES/blob/main/Src/LSNLSpiroNes.cpp#L61
This particular line is eating nearly 50% of total CPU through the external call. I can't analyze it any further due to some confusion about missing symbol files.

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 3, 2024

I don’t know how that can be such a problem; it’s just peeking for a new message.
Can you work with Ms. ChatGPT to find some way to make it better on AMD?

@FIM43-Redeye
Copy link
Author

I have embarrassed myself. Turns out I just had to swap it to Release configuration and now it runs smoothly. Swapping PeekMessageW for GetMessageW still uses a very large amount of CPU, if a little less, but I'm not sure how to optimize that - maybe it's just normal and the profiler is just seeing the work that function does.. I think the input issue is solved per earlier.

BeesNES now runs beautifully on my system. I don't know how to strip the FPS limit out, so I can't push it to its limit and see just how well it runs, but it handles full speed like a champ. The filters also run buttery smooth, with no FPS drop on your custom ones. I think the AVX optimization is working well on AMD as well.

Thanks again for making such an amazing program! I genuinely feel privileged for the opportunity to use a sub-cycle NES emulator in real time. Hope I didn't waste too much of your time, and thanks again for all your help.

@L-Spiro
Copy link
Owner

L-Spiro commented Oct 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants