radv/winsys: return a Vulkan error code when binding virtual buffers/images
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 21 Jul 2020 13:55:38 +0000 (15:55 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 22 Jul 2020 15:06:20 +0000 (15:06 +0000)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5872>

src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_radeon_winsys.h
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c

index 8d28be4d92a1424c1dd026aed98f55d55b4c35c5..dd8b2e4b73a4600d6955fc1c23285fe5f156b3a6 100644 (file)
@@ -3936,11 +3936,12 @@ radv_finalize_timelines(struct radv_device *device,
        }
 }
 
-static void
+static VkResult
 radv_sparse_buffer_bind_memory(struct radv_device *device,
                                const VkSparseBufferMemoryBindInfo *bind)
 {
        RADV_FROM_HANDLE(radv_buffer, buffer, bind->buffer);
+       VkResult result;
 
        for (uint32_t i = 0; i < bind->bindCount; ++i) {
                struct radv_device_memory *mem = NULL;
@@ -3948,19 +3949,24 @@ radv_sparse_buffer_bind_memory(struct radv_device *device,
                if (bind->pBinds[i].memory != VK_NULL_HANDLE)
                        mem = radv_device_memory_from_handle(bind->pBinds[i].memory);
 
-               device->ws->buffer_virtual_bind(buffer->bo,
-                                               bind->pBinds[i].resourceOffset,
-                                               bind->pBinds[i].size,
-                                               mem ? mem->bo : NULL,
-                                               bind->pBinds[i].memoryOffset);
+               result = device->ws->buffer_virtual_bind(buffer->bo,
+                                                        bind->pBinds[i].resourceOffset,
+                                                        bind->pBinds[i].size,
+                                                        mem ? mem->bo : NULL,
+                                                        bind->pBinds[i].memoryOffset);
+               if (result != VK_SUCCESS)
+                       return result;
        }
+
+       return VK_SUCCESS;
 }
 
-static void
+static VkResult
 radv_sparse_image_opaque_bind_memory(struct radv_device *device,
                                      const VkSparseImageOpaqueMemoryBindInfo *bind)
 {
        RADV_FROM_HANDLE(radv_image, image, bind->image);
+       VkResult result;
 
        for (uint32_t i = 0; i < bind->bindCount; ++i) {
                struct radv_device_memory *mem = NULL;
@@ -3968,12 +3974,16 @@ radv_sparse_image_opaque_bind_memory(struct radv_device *device,
                if (bind->pBinds[i].memory != VK_NULL_HANDLE)
                        mem = radv_device_memory_from_handle(bind->pBinds[i].memory);
 
-               device->ws->buffer_virtual_bind(image->bo,
-                                               bind->pBinds[i].resourceOffset,
-                                               bind->pBinds[i].size,
-                                               mem ? mem->bo : NULL,
-                                               bind->pBinds[i].memoryOffset);
+               result = device->ws->buffer_virtual_bind(image->bo,
+                                                        bind->pBinds[i].resourceOffset,
+                                                        bind->pBinds[i].size,
+                                                        mem ? mem->bo : NULL,
+                                                        bind->pBinds[i].memoryOffset);
+               if (result != VK_SUCCESS)
+                       return result;
        }
+
+       return VK_SUCCESS;
 }
 
 static VkResult
@@ -4283,13 +4293,17 @@ radv_queue_submit_deferred(struct radv_deferred_queue_submission *submission,
                goto fail;
 
        for (uint32_t i = 0; i < submission->buffer_bind_count; ++i) {
-               radv_sparse_buffer_bind_memory(queue->device,
-                                              submission->buffer_binds + i);
+               result = radv_sparse_buffer_bind_memory(queue->device,
+                                                       submission->buffer_binds + i);
+               if (result != VK_SUCCESS)
+                       goto fail;
        }
 
        for (uint32_t i = 0; i < submission->image_opaque_bind_count; ++i) {
-               radv_sparse_image_opaque_bind_memory(queue->device,
-                                                    submission->image_opaque_binds + i);
+               result = radv_sparse_image_opaque_bind_memory(queue->device,
+                                                             submission->image_opaque_binds + i);
+               if (result != VK_SUCCESS)
+                       goto fail;
        }
 
        if (!submission->cmd_buffer_count) {
index 4830c7bf2bdc1c3c5392b206710625f169e88b5f..ac5555e957d3924dc7b28e740470ef19ef6d70a2 100644 (file)
@@ -255,9 +255,9 @@ struct radeon_winsys {
        void (*buffer_get_metadata)(struct radeon_winsys_bo *bo,
                                    struct radeon_bo_metadata *md);
 
-       void (*buffer_virtual_bind)(struct radeon_winsys_bo *parent,
-                                   uint64_t offset, uint64_t size,
-                                   struct radeon_winsys_bo *bo, uint64_t bo_offset);
+       VkResult (*buffer_virtual_bind)(struct radeon_winsys_bo *parent,
+                                       uint64_t offset, uint64_t size,
+                                       struct radeon_winsys_bo *bo, uint64_t bo_offset);
        VkResult (*ctx_create)(struct radeon_winsys *ws,
                               enum radeon_ctx_priority priority,
                               struct radeon_winsys_ctx **ctx);
index 52b94f2e27ad69d643421904309e8e504804cb5d..496d6cf08db99675e52125fb54aafa029ff60e5a 100644 (file)
@@ -127,7 +127,7 @@ static int bo_comparator(const void *ap, const void *bp) {
        return (a > b) ? 1 : (a < b) ? -1 : 0;
 }
 
-static void
+static VkResult
 radv_amdgpu_winsys_rebuild_bo_list(struct radv_amdgpu_winsys_bo *bo)
 {
        if (bo->bo_capacity < bo->range_count) {
@@ -135,7 +135,7 @@ radv_amdgpu_winsys_rebuild_bo_list(struct radv_amdgpu_winsys_bo *bo)
                struct radv_amdgpu_winsys_bo **bos =
                        realloc(bo->bos, new_count * sizeof(struct radv_amdgpu_winsys_bo *));
                if (!bos)
-                       return;
+                       return VK_ERROR_OUT_OF_HOST_MEMORY;
                bo->bos = bos;
                bo->bo_capacity = new_count;
        }
@@ -153,9 +153,11 @@ radv_amdgpu_winsys_rebuild_bo_list(struct radv_amdgpu_winsys_bo *bo)
                        bo->bos[final_bo_count++] = bo->bos[i];
 
        bo->bo_count = final_bo_count;
+
+       return VK_SUCCESS;
 }
 
-static void
+static VkResult
 radv_amdgpu_winsys_bo_virtual_bind(struct radeon_winsys_bo *_parent,
                                    uint64_t offset, uint64_t size,
                                    struct radeon_winsys_bo *_bo, uint64_t bo_offset)
@@ -165,6 +167,7 @@ radv_amdgpu_winsys_bo_virtual_bind(struct radeon_winsys_bo *_parent,
        int range_count_delta, new_idx;
        int first = 0, last;
        struct radv_amdgpu_map_range new_first, new_last;
+       VkResult result;
 
        assert(parent->is_virtual);
        assert(!bo || !bo->is_virtual);
@@ -176,7 +179,7 @@ radv_amdgpu_winsys_bo_virtual_bind(struct radeon_winsys_bo *_parent,
                        realloc(parent->ranges,
                                range_capacity * sizeof(struct radv_amdgpu_map_range));
                if (!ranges)
-                       return;
+                       return VK_ERROR_OUT_OF_HOST_MEMORY;
                parent->ranges = ranges;
                parent->range_capacity = range_capacity;
        }
@@ -272,7 +275,11 @@ radv_amdgpu_winsys_bo_virtual_bind(struct radeon_winsys_bo *_parent,
 
        parent->range_count += range_count_delta;
 
-       radv_amdgpu_winsys_rebuild_bo_list(parent);
+       result = radv_amdgpu_winsys_rebuild_bo_list(parent);
+       if (result != VK_SUCCESS)
+               return result;
+
+       return VK_SUCCESS;
 }
 
 static void radv_amdgpu_winsys_bo_destroy(struct radeon_winsys_bo *_bo)