Lets say, for a rendering setup, that we have a renderer that can be either double or triple buffered, and this buffering can be changed dynamically, at runtime. So, at any time, it's 2 or 3 frames in flight (FIF).
Frame resources, like buffers, are duplicated to match the FIF-count. Buffers are created large enough to hold (frame-data-size * FIF-count), and reading/writing into those buffers are offsetted accordingly.
For the purpose of offsetting into buffers, is it good enough to use a monotonic clycling index which would go like so:
double buffer: 0, 1, 0, 1, 0, 1, ...
triple buffer: 0, 1, 2, 0, 1, 2, ...
Then, if a change is made to the FIF-count a runtime, we first WaitIdle() on the GPU, and then reset this index to 0.
Is this a safe way of offsetting into buffers, such that we don't trample on data still being used by the GPU?
I'm particularly unsure how this may play with a triple-buffer setup with a swapchain mailbox present-mode.