return; \
} while (0)
-/**
- * A dynamically growable, circular buffer. Elements are added at head and
- * removed from tail. head and tail are free-running uint32_t indices and we
- * only compute the modulo with size when accessing the array. This way,
- * number of bytes in the queue is always head - tail, even in case of
- * wraparound.
- */
-
-struct radv_vector {
- uint32_t head;
- uint32_t tail;
- uint32_t element_size;
- uint32_t size;
- void *data;
-};
-
-int radv_vector_init(struct radv_vector *queue, uint32_t element_size, uint32_t size);
-void *radv_vector_add(struct radv_vector *queue);
-void *radv_vector_remove(struct radv_vector *queue);
-
-static inline int
-radv_vector_length(struct radv_vector *queue)
-{
- return (queue->head - queue->tail) / queue->element_size;
-}
-
-static inline void *
-radv_vector_head(struct radv_vector *vector)
-{
- assert(vector->tail < vector->head);
- return (void *)((char *)vector->data +
- ((vector->head - vector->element_size) &
- (vector->size - 1)));
-}
-
-static inline void *
-radv_vector_tail(struct radv_vector *vector)
-{
- return (void *)((char *)vector->data + (vector->tail & (vector->size - 1)));
-}
-
-static inline void
-radv_vector_finish(struct radv_vector *queue)
-{
- free(queue->data);
-}
-
-#define radv_vector_foreach(elem, queue) \
- static_assert(__builtin_types_compatible_p(__typeof__(queue), struct radv_vector *), ""); \
- for (uint32_t __radv_vector_offset = (queue)->tail; \
- elem = (queue)->data + (__radv_vector_offset & ((queue)->size - 1)), __radv_vector_offset < (queue)->head; \
- __radv_vector_offset += (queue)->element_size)
-
void *radv_resolve_entrypoint(uint32_t index);
void *radv_lookup_entrypoint(const char *name);
return error;
}
-int
-radv_vector_init(struct radv_vector *vector, uint32_t element_size, uint32_t size)
-{
- assert(util_is_power_of_two(size));
- assert(element_size < size && util_is_power_of_two(element_size));
-
- vector->head = 0;
- vector->tail = 0;
- vector->element_size = element_size;
- vector->size = size;
- vector->data = malloc(size);
-
- return vector->data != NULL;
-}
-
-void *
-radv_vector_add(struct radv_vector *vector)
-{
- uint32_t offset, size, split, src_tail, dst_tail;
- void *data;
-
- if (vector->head - vector->tail == vector->size) {
- size = vector->size * 2;
- data = malloc(size);
- if (data == NULL)
- return NULL;
- src_tail = vector->tail & (vector->size - 1);
- dst_tail = vector->tail & (size - 1);
- if (src_tail == 0) {
- /* Since we know that the vector is full, this means that it's
- * linear from start to end so we can do one copy.
- */
- memcpy(data + dst_tail, vector->data, vector->size);
- } else {
- /* In this case, the vector is split into two pieces and we have
- * to do two copies. We have to be careful to make sure each
- * piece goes to the right locations. Thanks to the change in
- * size, it may or may not still wrap around.
- */
- split = align_u32(vector->tail, vector->size);
- assert(vector->tail <= split && split < vector->head);
- memcpy(data + dst_tail, vector->data + src_tail,
- split - vector->tail);
- memcpy(data + (split & (size - 1)), vector->data,
- vector->head - split);
- }
- free(vector->data);
- vector->data = data;
- vector->size = size;
- }
-
- assert(vector->head - vector->tail < vector->size);
-
- offset = vector->head & (vector->size - 1);
- vector->head += vector->element_size;
-
- return vector->data + offset;
-}
-
-void *
-radv_vector_remove(struct radv_vector *vector)
-{
- uint32_t offset;
-
- if (vector->head == vector->tail)
- return NULL;
-
- assert(vector->head - vector->tail <= vector->size);
-
- offset = vector->tail & (vector->size - 1);
- vector->tail += vector->element_size;
-
- return vector->data + offset;
-}
#include "vk_format.h"
#include <util/hash_table.h>
-
+#include <util/u_vector.h>
#define MIN_NUM_IMAGES 2
struct wsi_wl_display {
struct wl_drm * drm;
/* Vector of VkFormats supported */
- struct radv_vector formats;
+ struct u_vector formats;
uint32_t capabilities;
};
{
/* Don't add a format that's already in the list */
VkFormat *f;
- radv_vector_foreach(f, &display->formats)
+ u_vector_foreach(f, &display->formats)
if (*f == format)
return;
if (!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
return;
- f = radv_vector_add(&display->formats);
+ f = u_vector_add(&display->formats);
if (f)
*f = format;
}
static void
wsi_wl_display_destroy(struct wsi_wayland *wsi, struct wsi_wl_display *display)
{
- radv_vector_finish(&display->formats);
+ u_vector_finish(&display->formats);
if (display->drm)
wl_drm_destroy(display->drm);
radv_free(&wsi->physical_device->instance->alloc, display);
display->display = wl_display;
display->physical_device = wsi->physical_device;
- if (!radv_vector_init(&display->formats, sizeof(VkFormat), 8))
+ if (!u_vector_init(&display->formats, sizeof(VkFormat), 8))
goto fail;
struct wl_registry *registry = wl_display_get_registry(wl_display);
struct wsi_wl_display *display =
wsi_wl_get_display(device, surface->display);
- uint32_t count = radv_vector_length(&display->formats);
+ uint32_t count = u_vector_length(&display->formats);
if (pSurfaceFormats == NULL) {
*pSurfaceFormatCount = count;
*pSurfaceFormatCount = count;
VkFormat *f;
- radv_vector_foreach(f, &display->formats) {
+ u_vector_foreach(f, &display->formats) {
*(pSurfaceFormats++) = (VkSurfaceFormatKHR) {
.format = *f,
/* TODO: We should get this from the compositor somehow */