nikp123 / xava

X11 Audio Visualizer for ALSA
http://nikp123.github.io/xava
Other
129 stars 14 forks source link

Switch the OpenGL code to use VBOs instead of direct mode #17

Closed nikp123 closed 4 years ago

nikp123 commented 4 years ago

This would not only improve performance, but will actually allow me to use GLSL shaders among other things.

nikp123 commented 4 years ago

This obviously isn't ready yet, it will need some work (and extreme amounts of testing - you can't EVER be sure that it works)

My goal for now:

Also doesn't my project become GLava basically after these mods (except it has windows support)?

make-42 commented 4 years ago

Yes, defining the shader files in the config would be pretty good. In the GLSL code, we need to access X.A.V.A. variables, it would be good if you could pass:

If you have another idea of variables to pass, go ahead. PS: This isn't GLava as it is cross-platform.

make-42 commented 4 years ago

Also while the code works it is less efficient in terms of video card usage

make-42 commented 4 years ago

Didn't build it properly, I'm good now, no shadows though...

nikp123 commented 4 years ago

Did some work on it, I figured out (somewhat) what to do. But there are so many annoying bugs to fix. (fxp. shader compilation failures, as OGL is asyncronous AF). And also the way that I deal with variables is backstabing me. I'm thinking of just making all major variables global, since having 3 different variables with the same name is driving me insane (messy code, i know).....

Will update as I go through on this.

nikp123 commented 4 years ago

But I think the first order of duty is to update the branch to mainline, since the removal of bar limits is causing seg. faults all over the place. Thank GDB for giving me insight about my variable issue.

nikp123 commented 4 years ago

Also your assumption is correct, shaders are expesive (in cycles) as it gets when it comes to code. Any slight change to the shader code can change the temps of the GPU from 40 to 80*C.

But I'm thinking of doing geometry inside of a shader, that'll give more flexibility to the developer/end-user (and possibly reduce the load). Only catch though: it's not EGL friendly.

nikp123 commented 4 years ago

Also those shaders (that you demonstrated) draw every single pixel, unlike real fragment shaders which are ran on every pixel that is occupied by a 2d raster of the final polygon.

nikp123 commented 4 years ago

Can I work around this by using two polygons that just cover the entire screen and use fragment shaders for the final image? (kinda hacky, but may work)

make-42 commented 4 years ago

Yeah, I think having 2 polygons that cover the screen is an idea worth exploring but the frag makers need to have an easy way to map the fragment shader to the screen.

nikp123 commented 4 years ago

update: the two polygon thing is working, I've managed to cram the entire renderer into a fragment shader that runs about 30 lines of code per pixel (not sure if it's bad or not)

comparing with the legacy OGL code it uses 20% more GPU, but it's not so bad as you get the complete flexibility of GLSL

However, uno problemo: GLSL had no way to put a dynamic array as an "uniform" variable up until OGL 4.0 So my workaround was to limit the bars to something absurdly high, such as 10000 bars. I did this because like 70% of all computers I ever used barely go above OGL 3.0, so I've did it like this in order to preserve compatibility.

nikp123 commented 4 years ago

Also the current shader I wrote is about 100 LoC and implements most features (80%) and works with the minimum version tag of 110 = OGL 2.0 minimum, which is ok compatibility IMO.

make-42 commented 4 years ago

Yup, sounds great, +20% GPU should be fine for most people.

nikp123 commented 4 years ago

Review this, and try to find bugs and other things (if you're willing to do so). Anyway I think this is the polishing phase.

Just need to update the windows code as well, and do a bit of testing there before merging.

nikp123 commented 4 years ago

Anyway it wasn't 20% more it was more like triple, my benchmarking was flawed. However I believe I can optimize the shader as the GPU isn't that good at doing logic (for which I rely heavily on) So I believe more reliance on floats should help in any case. Would writing inline code help as well?

Besides it's only 10% of my GPU (when I disable compositing ofc)

Also the conversion between ints and floats is expensive, so maybe it's that.

make-42 commented 4 years ago

Ok, I will test it ASAP, thanks!

make-42 commented 4 years ago

"xava" terminated by signal SIGSEGV (Adress boundary error), basically a segmentation fault...

make-42 commented 4 years ago

Also, shaders do not get copied over by install and it has to regenerate them in Ubuntu 20.04... xava installs to /usr/local/bin/xava

make-42 commented 4 years ago

"xava" terminated by signal SIGSEGV (Adress boundary error), basically a segmentation fault...

Error is in src/config.c line 226, it does: assert(!(fragmentShader&&vertexShader)); So if you check the memory addresses instead it goes a bit further(assert(!(*fragmentShader&&*vertexShader));), so basically one of those vars is null...

nikp123 commented 4 years ago

Both should be non-NULL at that point... I have no idea what might be going on.

nikp123 commented 4 years ago

I mean look at the lines behind... it's just two mallocs!?!

nikp123 commented 4 years ago

Also it doesn't matter if the package is installed in /usror /usr/local as all hardcoded directory paths are generated on compile time, so if CMake built it for a PREFIX=/usr/local, all the functions would be using that.

make-42 commented 4 years ago

Gonna have to rebuild it on another PC to find out what is going on, in the meantime do you have a Windows build?

nikp123 commented 4 years ago

I have to work on it since I've changed the renderer code

make-42 commented 4 years ago

image New system, different error...

make-42 commented 4 years ago

It works but there is no way to make another shader, in the config changing the shader variable does nothing.