summaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2016-10-14 12:59:55 +1000
committerDave Airlie <airlied@redhat.com>2016-10-19 09:05:25 +1000
commitf5daaba0fdd842bf04ede903aea3e63d10a27c6e (patch)
tree12f18b4158e66560cf13f0e4130507a3c052b5bc /src/amd/vulkan
parent8df014c01a41012a983bd0be164600ab50300e5c (diff)
downloadexternal_mesa3d-f5daaba0fdd842bf04ede903aea3e63d10a27c6e.zip
external_mesa3d-f5daaba0fdd842bf04ede903aea3e63d10a27c6e.tar.gz
external_mesa3d-f5daaba0fdd842bf04ede903aea3e63d10a27c6e.tar.bz2
radv: make use of shared vector helper.
This removes the vector code from radv in favour of sharing code with anv. Acked-by: Jason Ekstrand <jason@jlekstrand.net> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'src/amd/vulkan')
-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 6db8c7a..1f5af62 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 bf7abd4..8c7a948 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 739e0e3..a1978bc 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 */