···122122 render/render_interface.h
123123 render/render_resources.c
124124 render/render_shaders.c
125125+ render/render_sub_alloc.c
125126 render/render_util.c
126127 )
127128 # The aux_vk library needs to be public to include Vulkan.
+99
src/xrt/compositor/render/render_interface.h
···4141 */
42424343/*!
4444+ * The value `minUniformBufferOffsetAlignment` is defined by the Vulkan spec as
4545+ * having a max value of 256. Use this value to safely figure out sizes and
4646+ * alignment of UBO sub-allocation. It is also the max for 'nonCoherentAtomSize`
4747+ * which if we need to do flushing is what we need to align UBOs to.
4848+ *
4949+ * https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceLimits.html
5050+ * https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#limits-minmax
5151+ */
5252+#define RENDER_ALWAYS_SAFE_UBO_ALIGNMENT (256)
5353+5454+/*!
4455 * Max number of layers for layer squasher, can be different from
4556 * @ref COMP_MAX_LAYERS as the render module is separate from the compositor.
4657 */
···226237 */
227238VkResult
228239render_buffer_write(struct vk_bundle *vk, struct render_buffer *buffer, void *data, VkDeviceSize size);
240240+241241+242242+/*
243243+ *
244244+ * Sub-alloc.
245245+ *
246246+ */
247247+248248+/*!
249249+ * Per frame sub-allocation into a buffer, used to reduce the number of UBO
250250+ * objects we need to create. There is no way to free a sub-allocation, this is
251251+ * done implicitly at the end of the frame when @ref render_sub_alloc_tracker is
252252+ * zeroed out.
253253+ *
254254+ * @see render_sub_alloc_tracker
255255+ */
256256+struct render_sub_alloc
257257+{
258258+ /*!
259259+ * The buffer this is allocated from, it's the callers responsibility
260260+ * to keep it alive for as long as the sub-allocation is used.
261261+ */
262262+ VkBuffer buffer;
263263+264264+ //! Size of sub-allocation.
265265+ VkDeviceSize size;
266266+267267+ //! Offset into buffer.
268268+ VkDeviceSize offset;
269269+};
270270+271271+/*!
272272+ * A per frame tracker of sub-allocation out of a buffer, used to reduce the
273273+ * number of UBO objects we need to create. This code is designed with one
274274+ * constraint in mind, that the lifetime of a sub-allocation is only for one
275275+ * frame and is discarded at the end of it, but also alive for the entire frame.
276276+ * This removes the need to free indivudial sub-allocation, or even track them
277277+ * beyond filling the UBO data and descriptor sets.
278278+ *
279279+ * @see render_sub_alloc
280280+ */
281281+struct render_sub_alloc_tracker
282282+{
283283+ /*!
284284+ * The buffer to allocate from, it's the callers responsibility to keep
285285+ * it alive for as long as the sub-allocations are in used.
286286+ */
287287+ VkBuffer buffer;
288288+289289+ //! Start of memory, if buffer was mapped with initialised.
290290+ void *mapped;
291291+292292+ //! Total size of buffer.
293293+ VkDeviceSize total_size;
294294+295295+ //! Currently used memory.
296296+ VkDeviceSize used;
297297+};
298298+299299+/*!
300300+ * Init a @ref render_sub_alloc_tracker struct from a @ref render_buffer, the
301301+ * caller is responsible for keeping @p buffer alive while the sub allocator
302302+ * is being used.
303303+ */
304304+void
305305+render_sub_alloc_tracker_init(struct render_sub_alloc_tracker *rsat, struct render_buffer *buffer);
306306+307307+/*!
308308+ * Allocate enough memory (with constraints of UBOs) of @p size, return the
309309+ * pointer to the mapped memory or null if the buffer wasn't allocated.
310310+ */
311311+XRT_CHECK_RESULT VkResult
312312+render_sub_alloc_ubo_alloc_and_get_ptr(struct vk_bundle *vk,
313313+ struct render_sub_alloc_tracker *rsat,
314314+ VkDeviceSize size,
315315+ void **out_ptr,
316316+ struct render_sub_alloc *out_rsa);
317317+318318+/*!
319319+ * Allocate enough memory (with constraints of UBOs) to hold the memory in @ptr
320320+ * and copy that memory to the buffer using the CPU.
321321+ */
322322+XRT_CHECK_RESULT VkResult
323323+render_sub_alloc_ubo_alloc_and_write(struct vk_bundle *vk,
324324+ struct render_sub_alloc_tracker *rsat,
325325+ const void *ptr,
326326+ VkDeviceSize size,
327327+ struct render_sub_alloc *out_rsa);
229328230329231330/*