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
Triple buffering for metal - sokol_gfx.h #888
Comments
Currently the only way to change SG_NUM_INFLIGHT_FRAMES is to patch the sokol header, I did it this way because that value unfortunately leaks into the public API (for instance here: Line 2291 in d4ac122
This public API 'leakage' is also why it must be a comptime constant and can't be provided in sg_desc at startup. If you decide to make this a preprocessor define which can be provided from the outside, you'll need to make sure that all places which include the header (not just the implementation) see the same define (so it should probably be provided on the compiler command line by the build system instead of relying on a Also make sure to check that this change doesn't increase frame latency. Apart from that, as far as I can see the sokol_gfx.h 'frame management' code is identical with that Apple example code (except that Currently I don't want to make this change in the 'official' header though, because I don't like this 'NUM_INFLIGHT_FRAMES' constant in the first place. A "proper" fix would be to have a (PS: if you're 'workload' comfortably fits into the 8.333ms frame budget (for 120Hz), triple buffering shouldn't be needed, because then the CPU side always has enough wiggle room to provide the next frame in time before the next presentation needs to happen, and TBH I don't quite understand from that article why 3 buffers would be needed (instead of just 2) to prevent the GPU and CPU from trampling on each others feet (the GPU will read one buffer, while the CPU writes the next, and since the CPU is usually ready before the next vsync, the buffer that was just written by the CPU will already be ready at the start of the next frame for the GPU to read). ...but anyway, if you see any advantages with |
Apple recommends triple buffering dynamic content in metal. Should
SG_NUM_INFLIGHT_FRAMES
be set to 3 when the metal backend is chosen, or should sokol allow#define SG_NUM_INFLIGHT_FRAMES 3
to to be declared before the header is imported?The text was updated successfully, but these errors were encountered: