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

GL performance optimization #1171

Open
mikesmullin opened this issue Dec 24, 2024 · 1 comment
Open

GL performance optimization #1171

mikesmullin opened this issue Dec 24, 2024 · 1 comment

Comments

@mikesmullin
Copy link

This is more for users of Sokol. You probably already know, but glGetError() is causes slowdown.

OpenGL operates as a client-server model where commands are issued on the CPU and executed asynchronously on the GPU. When you call glGetError(), it forces a synchronization point between the CPU and GPU. The CPU has to wait for all previous OpenGL commands to be processed and their results made available, potentially stalling the pipeline.

If glGetError() is called frequently, such as once per OpenGL command or per frame, the accumulated cost can become significant, especially if it forces the pipeline to synchronize multiple times per frame.

So if you're not actively debugging (say, during a performance test, or in a production build) you may want to disable the many calls to this function throughout sokol_gfx.h.

In my case I disable the macro, before including any Sokol headers.

#define _SG_GL_CHECK_ERROR() {} // performance optimization, when not debugging

In my case, I measured sg_begin_pass(). Before disabling macro = taking 16ms per frame. After = <1ms per frame.
Important if you want to maintain >=60fps.

@floooh
Copy link
Owner

floooh commented Dec 24, 2024

Note though that those GL errors checks are only active in debug mode since it is wrapped in a C assert().

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