radv: start fixing up queue allocate for multiple queues
authorDave Airlie <airlied@redhat.com>
Wed, 30 Nov 2016 04:30:06 +0000 (04:30 +0000)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 18 Dec 2016 19:52:15 +0000 (20:52 +0100)
v2: Fix error handling  and zero init the device (Bas)

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_private.h

index c1438feb85200569b71b6902d83ae91b8c3b204b..0cac5bc989311e1742a92001ab02abb13442c5c4 100644 (file)
@@ -619,10 +619,13 @@ void radv_GetPhysicalDeviceMemoryProperties(
 }
 
 static void
-radv_queue_init(struct radv_device *device, struct radv_queue *queue)
+radv_queue_init(struct radv_device *device, struct radv_queue *queue,
+               int queue_family_index, int idx)
 {
        queue->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
        queue->device = device;
+       queue->queue_family_index = queue_family_index;
+       queue->queue_idx = idx;
 }
 
 static void
@@ -659,6 +662,8 @@ VkResult radv_CreateDevice(
        if (!device)
                return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       memset(device, 0, sizeof(*device));
+
        device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
        device->instance = physical_device->instance;
        device->shader_stats_dump = false;
@@ -669,18 +674,33 @@ VkResult radv_CreateDevice(
        else
                device->alloc = physical_device->instance->alloc;
 
+       for (unsigned i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
+               const VkDeviceQueueCreateInfo *queue_create = &pCreateInfo->pQueueCreateInfos[i];
+               uint32_t qfi = queue_create->queueFamilyIndex;
+
+               device->queues[qfi] = vk_alloc(&device->alloc,
+                                              queue_create->queueCount * sizeof(struct radv_queue), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+               if (!device->queues[qfi]) {
+                       result = VK_ERROR_OUT_OF_HOST_MEMORY;
+                       goto fail;
+               }
+
+               device->queue_count[qfi] = queue_create->queueCount;
+
+               for (unsigned q = 0; q < queue_create->queueCount; q++)
+                       radv_queue_init(device, &device->queues[qfi][q], qfi, q);
+       }
+
        device->hw_ctx = device->ws->ctx_create(device->ws);
        if (!device->hw_ctx) {
                result = VK_ERROR_OUT_OF_HOST_MEMORY;
-               goto fail_free;
+               goto fail;
        }
 
-       radv_queue_init(device, &device->queue);
-
        result = radv_device_init_meta(device);
        if (result != VK_SUCCESS) {
                device->ws->ctx_destroy(device->hw_ctx);
-               goto fail_free;
+               goto fail;
        }
        device->allow_fast_clears = env_var_as_boolean("RADV_FAST_CLEARS", false);
        device->allow_dcc = !env_var_as_boolean("RADV_DCC_DISABLE", false);
@@ -697,7 +717,14 @@ VkResult radv_CreateDevice(
        device->ws->cs_finalize(device->empty_cs);
        *pDevice = radv_device_to_handle(device);
        return VK_SUCCESS;
-fail_free:
+
+fail:
+       for (unsigned i = 0; i < RADV_MAX_QUEUE_FAMILIES; i++) {
+               for (unsigned q = 0; q < device->queue_count[i]; q++)
+                       radv_queue_finish(&device->queues[i][q]);
+               if (device->queue_count[i])
+                       vk_free(&device->alloc, device->queues[i]);
+       }
        vk_free(&device->alloc, device);
        return result;
 }
@@ -709,7 +736,12 @@ void radv_DestroyDevice(
        RADV_FROM_HANDLE(radv_device, device, _device);
 
        device->ws->ctx_destroy(device->hw_ctx);
-       radv_queue_finish(&device->queue);
+       for (unsigned i = 0; i < RADV_MAX_QUEUE_FAMILIES; i++) {
+               for (unsigned q = 0; q < device->queue_count[i]; q++)
+                       radv_queue_finish(&device->queues[i][q]);
+               if (device->queue_count[i])
+                       vk_free(&device->alloc, device->queues[i]);
+       }
        radv_device_finish_meta(device);
 
        vk_free(&device->alloc, device);
@@ -783,15 +815,13 @@ VkResult radv_EnumerateDeviceLayerProperties(
 
 void radv_GetDeviceQueue(
        VkDevice                                    _device,
-       uint32_t                                    queueNodeIndex,
+       uint32_t                                    queueFamilyIndex,
        uint32_t                                    queueIndex,
        VkQueue*                                    pQueue)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
 
-       assert(queueIndex == 0);
-
-       *pQueue = radv_queue_to_handle(&device->queue);
+       *pQueue = radv_queue_to_handle(&device->queues[queueFamilyIndex][queueIndex]);
 }
 
 VkResult radv_QueueSubmit(
index 3d4b111d25a0afcb543ee428840130b24ee1b4ee..aa5b477c19263f88d0819aa55d28f4badd0e5201 100644 (file)
@@ -434,12 +434,18 @@ struct radv_meta_state {
        } buffer;
 };
 
+/* queue types */
+#define RADV_QUEUE_GENERAL 0
+#define RADV_QUEUE_COMPUTE 1
+#define RADV_QUEUE_TRANSFER 2
+
+#define RADV_MAX_QUEUE_FAMILIES 3
+
 struct radv_queue {
        VK_LOADER_DATA                              _loader_data;
-
        struct radv_device *                         device;
-
-       struct radv_state_pool *                     pool;
+       int queue_family_index;
+       int queue_idx;
 };
 
 struct radv_device {
@@ -452,7 +458,9 @@ struct radv_device {
        struct radeon_winsys_ctx *hw_ctx;
 
        struct radv_meta_state                       meta_state;
-       struct radv_queue                            queue;
+
+       struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
+       int queue_count[RADV_MAX_QUEUE_FAMILIES];
        struct radeon_winsys_cs *empty_cs;
 
        bool allow_fast_clears;