diff --git a/doc/changes/compositor/mr.359.1.md b/doc/changes/compositor/mr.359.1.md new file mode 100644 index 000000000..75c7f7d34 --- /dev/null +++ b/doc/changes/compositor/mr.359.1.md @@ -0,0 +1,2 @@ +swapchain: Give out the oldset image index when a image is acquired. This logic +can be made better, but will work for the good case. diff --git a/src/xrt/compositor/main/comp_compositor.h b/src/xrt/compositor/main/comp_compositor.h index fbd22c4d5..cf3542291 100644 --- a/src/xrt/compositor/main/comp_compositor.h +++ b/src/xrt/compositor/main/comp_compositor.h @@ -13,6 +13,7 @@ #include "xrt/xrt_gfx_vk.h" #include "util/u_threading.h" +#include "util/u_index_fifo.h" #include "main/comp_settings.h" #include "main/comp_window.h" @@ -64,6 +65,12 @@ struct comp_swapchain struct comp_compositor *c; struct comp_swapchain_image images[XRT_MAX_SWAPCHAIN_IMAGES]; + + /*! + * This fifo is used to always give out the oldest image to acquire + * image, this should probably be made even smarter. + */ + struct u_index_fifo fifo; }; enum comp_layer_type diff --git a/src/xrt/compositor/main/comp_swapchain.c b/src/xrt/compositor/main/comp_swapchain.c index 22875b4fd..a19333fc6 100644 --- a/src/xrt/compositor/main/comp_swapchain.c +++ b/src/xrt/compositor/main/comp_swapchain.c @@ -31,8 +31,9 @@ swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) struct comp_swapchain *sc = comp_swapchain(xsc); COMP_SPEW(sc->c, "ACQUIRE_IMAGE"); - *index = 0; - return true; + + // Returns negative on empty fifo. + return u_index_fifo_pop(&sc->fifo, index) >= 0; } static bool @@ -52,6 +53,9 @@ swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) struct comp_swapchain *sc = comp_swapchain(xsc); COMP_SPEW(sc->c, "RELEASE_IMAGE"); + + u_index_fifo_push(&sc->fifo, index); + return true; } @@ -273,6 +277,11 @@ comp_swapchain_create(struct xrt_compositor *xc, } } + // Prime the fifo + for (uint32_t i = 0; i < num_images; i++) { + u_index_fifo_push(&sc->fifo, i); + } + /* *