From 062022f2e4bc3024553db897e3984d1a16b28239 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Sun, 1 Apr 2018 13:57:13 -0700 Subject: [PATCH] anv: Implement aux-map allocator interface This interface allows the aux-map code in the intel/common library to allocate and free buffers. Reworks: * free gen_buffer in gen_aux_map_buffer_free. (Rafael) Signed-off-by: Jordan Justen Reviewed-by: Lionel Landwerlin --- src/intel/vulkan/anv_device.c | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 2bd3093bce8..9f7dc9aaaeb 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -43,6 +43,7 @@ #include "util/xmlpool.h" #include "git_sha1.h" #include "vk_util.h" +#include "common/gen_buffer_alloc.h" #include "common/gen_defines.h" #include "compiler/glsl_types.h" @@ -2390,6 +2391,47 @@ decode_get_bo(void *v_batch, bool ppgtt, uint64_t address) return (struct gen_batch_decode_bo) { }; } +struct gen_aux_map_buffer { + struct gen_buffer base; + struct anv_state state; +}; + +static struct gen_buffer * +gen_aux_map_buffer_alloc(void *driver_ctx, uint32_t size) +{ + struct gen_aux_map_buffer *buf = malloc(sizeof(struct gen_aux_map_buffer)); + if (!buf) + return NULL; + + struct anv_device *device = (struct anv_device*)driver_ctx; + assert(device->instance->physicalDevice.supports_48bit_addresses && + device->instance->physicalDevice.use_softpin); + + struct anv_state_pool *pool = &device->dynamic_state_pool; + buf->state = anv_state_pool_alloc(pool, size, size); + + buf->base.gpu = pool->block_pool.bo->offset + buf->state.offset; + buf->base.gpu_end = buf->base.gpu + buf->state.alloc_size; + buf->base.map = buf->state.map; + buf->base.driver_bo = &buf->state; + return &buf->base; +} + +static void +gen_aux_map_buffer_free(void *driver_ctx, struct gen_buffer *buffer) +{ + struct gen_aux_map_buffer *buf = (struct gen_aux_map_buffer*)buffer; + struct anv_device *device = (struct anv_device*)driver_ctx; + struct anv_state_pool *pool = &device->dynamic_state_pool; + anv_state_pool_free(pool, buf->state); + free(buf); +} + +static struct gen_mapped_pinned_buffer_alloc aux_map_allocator = { + .alloc = gen_aux_map_buffer_alloc, + .free = gen_aux_map_buffer_free, +}; + VkResult anv_CreateDevice( VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, -- 2.30.2