summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/amd/vulkan/radv_private.h53
-rw-r--r--src/amd/vulkan/radv_util.c74
-rw-r--r--src/amd/vulkan/radv_wsi_wayland.c16
3 files changed, 8 insertions, 135 deletions
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 6db8c7acfe3..1f5af622e1d 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -238,59 +238,6 @@ void radv_abortfv(const char *format, va_list va) radv_noreturn;
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);
diff --git a/src/amd/vulkan/radv_util.c b/src/amd/vulkan/radv_util.c
index bf7abd49d1d..8c7a948bc95 100644
--- a/src/amd/vulkan/radv_util.c
+++ b/src/amd/vulkan/radv_util.c
@@ -128,77 +128,3 @@ __vk_errorf(VkResult error, const char *file, int line, const char *format, ...)
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;
-}
diff --git a/src/amd/vulkan/radv_wsi_wayland.c b/src/amd/vulkan/radv_wsi_wayland.c
index 739e0e32580..a1978bc5b43 100644
--- a/src/amd/vulkan/radv_wsi_wayland.c
+++ b/src/amd/vulkan/radv_wsi_wayland.c
@@ -30,7 +30,7 @@
#include "vk_format.h"
#include <util/hash_table.h>
-
+#include <util/u_vector.h>
#define MIN_NUM_IMAGES 2
struct wsi_wl_display {
@@ -39,7 +39,7 @@ struct wsi_wl_display {
struct wl_drm * drm;
/* Vector of VkFormats supported */
- struct radv_vector formats;
+ struct u_vector formats;
uint32_t capabilities;
};
@@ -59,7 +59,7 @@ wsi_wl_display_add_vk_format(struct wsi_wl_display *display, VkFormat format)
{
/* 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;
@@ -70,7 +70,7 @@ wsi_wl_display_add_vk_format(struct wsi_wl_display *display, VkFormat format)
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;
}
@@ -228,7 +228,7 @@ static const struct wl_registry_listener registry_listener = {
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);
@@ -248,7 +248,7 @@ wsi_wl_display_create(struct wsi_wayland *wsi, struct wl_display *wl_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);
@@ -381,7 +381,7 @@ wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface,
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;
@@ -392,7 +392,7 @@ wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface,
*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 */