From 64a92ef7a26d33ca193a8a9eb5c00e2765a01837 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Sun, 21 Jun 2020 19:36:16 +0200 Subject: [PATCH] radv/winsys: Distinguish device/host memory errors. Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_cmd_buffer.c | 5 ++-- src/amd/vulkan/radv_radeon_winsys.h | 2 +- src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c | 26 ++++++++++--------- src/amd/vulkan/winsys/null/radv_null_cs.c | 4 +-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c index afc90b74f7d..247029cb701 100644 --- a/src/amd/vulkan/radv_cmd_buffer.c +++ b/src/amd/vulkan/radv_cmd_buffer.c @@ -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; diff --git a/src/amd/vulkan/radv_radeon_winsys.h b/src/amd/vulkan/radv_radeon_winsys.h index fc6ec2594b4..802dbdb1783 100644 --- a/src/amd/vulkan/radv_radeon_winsys.h +++ b/src/amd/vulkan/radv_radeon_winsys.h @@ -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); diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c index fca2e53aa8a..65b6bb4187d 100644 --- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c +++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c @@ -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; } } diff --git a/src/amd/vulkan/winsys/null/radv_null_cs.c b/src/amd/vulkan/winsys/null/radv_null_cs.c index f549357e694..5788cbf92cb 100644 --- a/src/amd/vulkan/winsys/null/radv_null_cs.c +++ b/src/amd/vulkan/winsys/null/radv_null_cs.c @@ -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) -- 2.30.2