nbarkhina / N64Wasm

A web based N64 Emulator
https://www.neilb.net/n64wasm/
MIT License
622 stars 132 forks source link

Is it possible to use WebGPU? #58

Open BeezBumba opened 3 months ago

BeezBumba commented 3 months ago

I found an article that talks about the conversion from WebGL to WebGPU. WebGPU is said to have compute shaders and geometry shaders. Geometry shaders are what the emulator needs because, with them, every triangle has a shader that finds the right pixel colors. This explains why there is no color in the images. I posted this in a new issue since the other one was pretty long. Screenshot 2024-06-13 175229 Screenshot 2024-06-13 174826

BeezBumba commented 3 months ago

Sorry I forgot the actual link. https://developer.chrome.com/blog/from-webgl-to-webgpu

BeezBumba commented 3 months ago

The WebGPU using a different shading language than WebGL, but the concepts are fairly the same.

BeezBumba commented 3 months ago

I saw shader_frag and shader_vert files in the code directory. WebGL can't support geometry shaders. so could there have been a shader_geo.hlsl file? That might be easier if it's possible.

nbarkhina commented 3 months ago

those shaders are just used for the emulator overlay menu - "New Game, Save State, etc..." it's not used by the emulator itself

BeezBumba commented 3 months ago

So what is your option on the whole conversion? Do you think it's possible at all?

nbarkhina commented 3 months ago

My knowledge of shaders unfortunately is quite basic - so I would really not know

BeezBumba commented 3 months ago

Its not to much about shaders. It's just the conversion from WebGL to WebGPU.

BeezBumba commented 3 months ago

Well can I ask what spots you changed so the emulator uses webGL?

BeezBumba commented 3 months ago

and the spots where you are using the webgl context

nbarkhina commented 3 months ago

The emulator uses WebGL because that is what emscripten translates to when compiling from OpenGL. See this article -

https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html

Here in the code is where it sets up the OpenGL Context -

https://github.com/nbarkhina/N64Wasm/blob/4aacfded69cdba1c19a07bfe7f3eb13c22252f7f/code/mymain.cpp#L632

So I don't actually use any WebGL commands, it's just straight up OpenGL which the compiler at a lower level turns into WebGL. I'm not sure how you would get it to use something else, the emulator would have to be rewritten to use something other than OpenGL - which in Desktop could use different backends (Vulkan, Direct3D, etc...) but on the web you don't have those options. So don't really think this is possible in my opinion.

BeezBumba commented 2 months ago

Do you know how to disable the emulator emulating lag?

BeezBumba commented 2 months ago

Emulators do that just for the pure accuracy.

nbarkhina commented 2 months ago

I don't believe there is any lag, the main tool for maintaining correct framerate is by syncing to the refresh rate of the monitor. this is done using the emscripten_set_main_loop() function:

https://github.com/nbarkhina/N64Wasm/blob/4aacfded69cdba1c19a07bfe7f3eb13c22252f7f/code/mymain.cpp#L734

you can read about it here

https://emscripten.org/docs/api_reference/emscripten.h.html

one thing you can experiment with is setting the variable doubleSpeed to true here -

https://github.com/nbarkhina/N64Wasm/blob/4aacfded69cdba1c19a07bfe7f3eb13c22252f7f/code/mymain.cpp#L42

that will attempt to run 2 frames for every 1 frame of time, however on slow machines it won't be able to keep up and won't yield any benefit.

BeezBumba commented 2 months ago

I asked this because some games on Ipad are a lot better now with vertex buffer objects. but that update still did something with safari.

BeezBumba commented 1 month ago

new update: the parallel graphics plugin is actually the inaccurate one. I tested it on retroarch and it gave me the same problems.

BeezBumba commented 1 month ago

The parallel one is the only one i could find that was open source.

BeezBumba commented 1 month ago

I found this one on gitlab https://gitlab.com/parallel-launcher/parallel-n64

nbarkhina commented 1 month ago

interesting, ok good to know it wasn't something specific to the web version.

BeezBumba commented 1 month ago

It says it’s used specifically for the parallel launcher and that one works fine. So should you try it?

nbarkhina commented 1 month ago

I used the one that was already built into the parallel core in retroarch. Not sure how this one is different or if it's feasible to integrate it but if I have time I'll take a look

BeezBumba commented 1 month ago

Should I add anything for the new mupen64plus-video-gliden64 plugin code wise? Wondering what this video plugin might offer.

nbarkhina commented 1 month ago

You can try experimenting with if you like, I unfortunately have not had time to look at it been busy with work

nbarkhina commented 1 week ago

I've been working on getting the Rice plugin working - stay tuned I will link to a version you can try and let me know if it fixes the issue.

BeezBumba commented 1 week ago

Nice! can't wait to see that!

nbarkhina commented 1 week ago

ok give this page a try -

https://neilb.net/n64beta/

BeezBumba commented 1 week ago

It works! Screenshot 2024-11-10 195133

BeezBumba commented 1 week ago

the ongoing visual bugs are very minor and not as big so thats good.

BeezBumba commented 6 days ago

can you link the code?

nbarkhina commented 6 days ago

I haven't published the code yet I'm still cleaning it up a bit. I should have it published in a few days and will link you to it as soon as it's available.

nbarkhina commented 5 days ago

ok here is the checkin with the code -

https://github.com/nbarkhina/N64Wasm/commit/3056c89d73efea037aa5653a065ab65947e00149

BeezBumba commented 5 days ago

There is this thing where the whole game covers about 1/4 of the screen it might be a resolution issue? Screenshot 2024-11-12 184744

BeezBumba commented 5 days ago

It might be lines 390 and 391 in RiceConfig.cpp i have to change to global width/height?

screen_width = 640;
   screen_height = 480;
nbarkhina commented 5 days ago

Yes try updating those lines