radv/winsys: Distinguish device/host memory errors.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 21 Jun 2020 17:36:16 +0000 (19:36 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 24 Jun 2020 13:00:02 +0000 (13:00 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5578>

src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_radeon_winsys.h
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c
src/amd/vulkan/winsys/null/radv_null_cs.c

index afc90b74f7d375191cab06f6a96ce4133110498b..247029cb70136fc72ec6f13f3ba2f62f2814f974 100644 (file)
@@ -3786,8 +3786,9 @@ VkResult radv_EndCommandBuffer(
        vk_free(&cmd_buffer->pool->alloc, cmd_buffer->state.attachments);
        vk_free(&cmd_buffer->pool->alloc, cmd_buffer->state.subpass_sample_locs);
 
-       if (!cmd_buffer->device->ws->cs_finalize(cmd_buffer->cs))
-               return vk_error(cmd_buffer->device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+       VkResult result = cmd_buffer->device->ws->cs_finalize(cmd_buffer->cs);
+       if (result != VK_SUCCESS)
+               return vk_error(cmd_buffer->device->instance, result);
 
        cmd_buffer->status = RADV_CMD_BUFFER_STATUS_EXECUTABLE;
 
index fc6ec2594b4fd67374abf7ccf8c7055b9132dca3..802dbdb1783417914eb377fa9228bac46a58fef4 100644 (file)
@@ -273,7 +273,7 @@ struct radeon_winsys {
 
        void (*cs_reset)(struct radeon_cmdbuf *cs);
 
-       bool (*cs_finalize)(struct radeon_cmdbuf *cs);
+       VkResult (*cs_finalize)(struct radeon_cmdbuf *cs);
 
        void (*cs_grow)(struct radeon_cmdbuf * cs, size_t min_size);
 
index fca2e53aa8af5d0dda635069e1ed1ae4ec8f0bdd..65b6bb4187d423706ab6bc70deed0e096134eed6 100644 (file)
@@ -57,7 +57,7 @@ struct radv_amdgpu_cs {
        unsigned                    num_old_ib_buffers;
        unsigned                    max_num_old_ib_buffers;
        unsigned                    *ib_size_ptr;
-       bool                        failed;
+       VkResult                    status;
        bool                        is_chained;
 
        int                         buffer_hash_table[1024];
@@ -361,7 +361,7 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
 {
        struct radv_amdgpu_cs *cs = radv_amdgpu_cs(_cs);
 
-       if (cs->failed) {
+       if (cs->status != VK_SUCCESS) {
                cs->base.cdw = 0;
                return;
        }
@@ -381,7 +381,7 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
                                realloc(cs->old_cs_buffers,
                                        (cs->num_old_cs_buffers + 1) * sizeof(*cs->old_cs_buffers));
                        if (!cs->old_cs_buffers) {
-                               cs->failed = true;
+                               cs->status = VK_ERROR_OUT_OF_HOST_MEMORY;
                                cs->base.cdw = 0;
                                return;
                        }
@@ -402,7 +402,7 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
                        if (ib_dws > limit_dws) {
                                fprintf(stderr, "amdgpu: Too high number of "
                                                "dwords to allocate\n");
-                               cs->failed = true;
+                               cs->status = VK_ERROR_OUT_OF_HOST_MEMORY;
                                return;
                        }
                }
@@ -412,7 +412,7 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
                        cs->base.buf = new_buf;
                        cs->base.max_dw = ib_dws;
                } else {
-                       cs->failed = true;
+                       cs->status = VK_ERROR_OUT_OF_HOST_MEMORY;
                        cs->base.cdw = 0;
                }
                return;
@@ -445,7 +445,7 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
 
        if (!cs->ib_buffer) {
                cs->base.cdw = 0;
-               cs->failed = true;
+               cs->status = VK_ERROR_OUT_OF_DEVICE_MEMORY;
                cs->ib_buffer = cs->old_ib_buffers[--cs->num_old_ib_buffers];
        }
 
@@ -453,7 +453,9 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
        if (!cs->ib_mapped) {
                cs->ws->base.buffer_destroy(cs->ib_buffer);
                cs->base.cdw = 0;
-               cs->failed = true;
+
+               /* VK_ERROR_MEMORY_MAP_FAILED is not valid for vkEndCommandBuffer. */
+               cs->status = VK_ERROR_OUT_OF_DEVICE_MEMORY;
                cs->ib_buffer = cs->old_ib_buffers[--cs->num_old_ib_buffers];
        }
 
@@ -472,7 +474,7 @@ static void radv_amdgpu_cs_grow(struct radeon_cmdbuf *_cs, size_t min_size)
 
 }
 
-static bool radv_amdgpu_cs_finalize(struct radeon_cmdbuf *_cs)
+static VkResult radv_amdgpu_cs_finalize(struct radeon_cmdbuf *_cs)
 {
        struct radv_amdgpu_cs *cs = radv_amdgpu_cs(_cs);
 
@@ -485,14 +487,14 @@ static bool radv_amdgpu_cs_finalize(struct radeon_cmdbuf *_cs)
                cs->is_chained = false;
        }
 
-       return !cs->failed;
+       return cs->status;
 }
 
 static void radv_amdgpu_cs_reset(struct radeon_cmdbuf *_cs)
 {
        struct radv_amdgpu_cs *cs = radv_amdgpu_cs(_cs);
        cs->base.cdw = 0;
-       cs->failed = false;
+       cs->status = VK_SUCCESS;
 
        for (unsigned i = 0; i < cs->num_buffers; ++i) {
                unsigned hash = cs->handles[i].bo_handle &
@@ -558,7 +560,7 @@ static void radv_amdgpu_cs_add_buffer_internal(struct radv_amdgpu_cs *cs,
        unsigned hash;
        int index = radv_amdgpu_cs_find_buffer(cs, bo);
 
-       if (index != -1 || cs->failed)
+       if (index != -1 || cs->status != VK_SUCCESS)
                return;
 
        if (cs->num_buffers == cs->max_num_buffers) {
@@ -569,7 +571,7 @@ static void radv_amdgpu_cs_add_buffer_internal(struct radv_amdgpu_cs *cs,
                        cs->max_num_buffers = new_count;
                        cs->handles = new_entries;
                } else {
-                       cs->failed = true;
+                       cs->status = VK_ERROR_OUT_OF_HOST_MEMORY;
                        return;
                }
        }
index f549357e6945abdc366f31c76b5b6d3ff2944eb6..5788cbf92cb2ede843e478981add8bce419dd771 100644 (file)
@@ -78,9 +78,9 @@ radv_null_cs_create(struct radeon_winsys *ws,
        return &cs->base;
 }
 
-static bool radv_null_cs_finalize(struct radeon_cmdbuf *_cs)
+static VkResult radv_null_cs_finalize(struct radeon_cmdbuf *_cs)
 {
-       return true;
+       return VK_SUCCESS;
 }
 
 static void radv_null_cs_destroy(struct radeon_cmdbuf *rcs)