-
Notifications
You must be signed in to change notification settings - Fork 578
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
Adds CRC calculation to draw command buffer #724
base: master
Are you sure you want to change the base?
Conversation
Adding a rolling CRC caluclation based off the commands going into the draw buffer allows for really quick and cheap difference detection. That is, for an application to know if it needs to nk_convert and paint the screen again. All that needs to be done now, is to store the previous CRC value and compare that to the latest value to determine if you should draw or not.
this is a stepping stone to going to a full Makefile build system. All src files can be provided in the make and sent to build.py with minimal issues now that we don't have to build a comma separated list.
Nice addition! But... :) I would prefer this is conditionally included with a define (aka NK_DRAW_BUFFER_CRC) because it induces some static memory for the crc table and additional computation on each draw command push, a waist for those not using this optimization. Then a minor version bump will be needed. |
@riri |
Here seems to be the perfect place to discuss about it. Others can join if they have their own idea about it. My argument is that by default, Nuklear does not keep track of what was rendered, and we should stay on that line. Dunno, maybe I'm a bit conservative :) |
This update still keeps with that ethos. Nuklear isn't tracking anything between separate computationally, the CRC is a lookup operation and a XOR arithmetic operation. super fast. super cheap. This is a very common technique used in resource constrained embedded systems everywhere. So common, that most processors have SIMD or AVX or dedicated hardware to support it. I will concede that a 256 element array of 32 bit integers is a little bit large (1KB). but even in embedded systems with memory constraints, if you can't find 1KB of space, then you problem went wrong somewhere else. (makes me wonder how large the draw buffer gets). Also, I am sure that the compiler would optimize a lot of this out, especially if the developer never calls the function to retain the CRC value. I would be happy to do some performance checks on this if you are concerned. |
also. let me know if I am coming off as too combative. I can get passionate sometimes. Ultimately, this is your project, not mine. I will concede to your will because I believe in this project and want to be a respected contributor. I respect your opinions and comments even if I push back strongly. I really do love this project. It is the best gui framework that I have come across for C and I really do want to see it excel. I share your opinion on being conservative; which is why i enjoy this single header, render backend agnostic approach. I work in embedded systems and have chosen this project for most gui work because of how small and efficient it is. I can really tailor this thing into many memory constrained and processor constrained spaces. Which is actually the inspiration for this update. I really don't want to run With the CRC approach, we take advantage of the fact that the frame work already loops through the buffer (to fill it with draw calls in the first place). Then we just add a single basic |
Disabled by default seems most appropriate, as not every usage of Nuklear requires validation of the draw buffer. Two other considerations...
|
The CRC Table definition should be guarded by the |
but you are right, this is not thread safe and i will make the update to move it. |
i am trying to update to use the |
i found that you |
Nothing wrong with being passionate, I'm actually in the same vein, but with different output.
Yes Nuklear is meant to be used anywhere, even where dynamic allocation is not available, so a memory buffer (which can be initialized either dynamically or statically) is used for all the things that cannot be determined in advance. draw commands are inverted in that buffer, but it's transparent to the user if using default allocation. |
Version number bumped (i think i did it right). PR should be good to go. |
Also a huge documentation update for CRC.
PR is not good. Turns out that I don't understand how to work with the buffer system |
I am asking for some help in figuring out a couple of bugs. When I try to run an example, I get Seg fault because the CRC read function gets ran at the end of all of the draw calls.... but the Note: I was testing in the sdl_renderer demo. |
okay. i have figured out some of it. it turns out that |
I think I have it figured out. All window command buffers are "finished" upon nk_end being called. Which means they are no longer available for use in any direct manner. However their list of draw calls just gets appended to the context's "global" draw buffer so that the NK Convert can just run on one long array regardless of how many buffers or windiws or popups got created. I think the proper fix for this would be to have the CTX store the CRC value, then update that on NK_finish_buffer |
CRC calculations appear to be updating pretty well. however for panels that get drawn before others, there seems to be no change in CRC for small updates on hover, like highlighting an object as you mouse over it. Note that the CRC does change with highlights in the last panel that is rendered. More investigation is required.
i got the CRCs mostly working again. i had to add CRC into the context, then update that as the |
Isn't it because redraw becomes too cheap with only one loop? If I remember well, hovered status is marked but drawn in next loop (I remember a similar thing with combobox dropdown on a different approach, running next loop only on platform events) |
Oh. Interesting. I guess that makes sense. It would be the same draw call, just a different parameter. So I will have to CRC more than just the pointer... I need to learn more |
Adding a rolling CRC caluclation based off the commands going into the draw buffer allows for really quick and cheap difference detection. That is, for an application to know if it needs to nk_convert and paint the screen again. All that needs to be done now, is to store the previous CRC value and compare that to the latest value to determine if you should draw or not.