From 260cd1a18b0b4e3c4ddd49332c2a17d049bb37df Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Tue, 3 May 2022 16:00:41 +0200 Subject: [PATCH] radv/radix: handle intentional allocation failures properly This test can intentionally make the alloc callback to return NULL, so we have to handle object creation failures properly. The driver should also avoid memleaks because the test checks that. Fixes crashes with dEQP-VK.api.device_init.create_instance_device_intentional_alloc_fail. Signed-off-by: Samuel Pitoiset Acked-by: Martin Roukala Reviewed-by: Konstantin Seurer Part-of: --- src/amd/vulkan/radix_sort/common/vk/assert.c | 108 ------------------- src/amd/vulkan/radix_sort/common/vk/assert.h | 52 --------- src/amd/vulkan/radix_sort/meson.build | 2 - src/amd/vulkan/radix_sort/radix_sort_vk.c | 33 ++++-- 4 files changed, 27 insertions(+), 168 deletions(-) delete mode 100644 src/amd/vulkan/radix_sort/common/vk/assert.c delete mode 100644 src/amd/vulkan/radix_sort/common/vk/assert.h diff --git a/src/amd/vulkan/radix_sort/common/vk/assert.c b/src/amd/vulkan/radix_sort/common/vk/assert.c deleted file mode 100644 index d5d5d07b454..00000000000 --- a/src/amd/vulkan/radix_sort/common/vk/assert.c +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2019 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// -// -// - -#include -#include - -// -// -// - -#include "assert.h" - -// -// -// - -#define VK_RESULT_TO_STRING(result) \ - case result: \ - return #result - -// -// FIXME -- results and errors -// - -char const * -vk_get_result_string(VkResult const result) -{ - switch (result) - { - // - // Results - // - VK_RESULT_TO_STRING(VK_SUCCESS); - VK_RESULT_TO_STRING(VK_NOT_READY); - VK_RESULT_TO_STRING(VK_TIMEOUT); - VK_RESULT_TO_STRING(VK_EVENT_SET); - VK_RESULT_TO_STRING(VK_EVENT_RESET); - VK_RESULT_TO_STRING(VK_INCOMPLETE); - // - // Errors - // - VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_HOST_MEMORY); - VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_DEVICE_MEMORY); - VK_RESULT_TO_STRING(VK_ERROR_INITIALIZATION_FAILED); - VK_RESULT_TO_STRING(VK_ERROR_DEVICE_LOST); - VK_RESULT_TO_STRING(VK_ERROR_MEMORY_MAP_FAILED); - VK_RESULT_TO_STRING(VK_ERROR_LAYER_NOT_PRESENT); - VK_RESULT_TO_STRING(VK_ERROR_EXTENSION_NOT_PRESENT); - VK_RESULT_TO_STRING(VK_ERROR_FEATURE_NOT_PRESENT); - VK_RESULT_TO_STRING(VK_ERROR_INCOMPATIBLE_DRIVER); - VK_RESULT_TO_STRING(VK_ERROR_TOO_MANY_OBJECTS); - VK_RESULT_TO_STRING(VK_ERROR_FORMAT_NOT_SUPPORTED); - VK_RESULT_TO_STRING(VK_ERROR_FRAGMENTED_POOL); - VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_POOL_MEMORY); - VK_RESULT_TO_STRING(VK_ERROR_INVALID_EXTERNAL_HANDLE); - VK_RESULT_TO_STRING(VK_ERROR_SURFACE_LOST_KHR); - VK_RESULT_TO_STRING(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR); - VK_RESULT_TO_STRING(VK_SUBOPTIMAL_KHR); - VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_DATE_KHR); - VK_RESULT_TO_STRING(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR); - VK_RESULT_TO_STRING(VK_ERROR_VALIDATION_FAILED_EXT); - VK_RESULT_TO_STRING(VK_ERROR_INVALID_SHADER_NV); - VK_RESULT_TO_STRING(VK_ERROR_FRAGMENTATION_EXT); - VK_RESULT_TO_STRING(VK_ERROR_NOT_PERMITTED_EXT); - - // - // Extensions: vk_xyz - // - default: - return "UNKNOWN VULKAN RESULT"; - } -} - -// -// -// - -VkResult -vk_assert(VkResult const result, char const * const file, int const line, bool const is_abort) -{ - if (result != VK_SUCCESS) - { - char const * const vk_result_str = vk_get_result_string(result); - - fprintf(stderr, - "\"%s\", line %d: vk_assert( %d ) = \"%s\"\n", - file, - line, - result, - vk_result_str); - - if (is_abort) - { - abort(); - } - } - - return result; -} - -// -// -// diff --git a/src/amd/vulkan/radix_sort/common/vk/assert.h b/src/amd/vulkan/radix_sort/common/vk/assert.h deleted file mode 100644 index 9d3fe43ed15..00000000000 --- a/src/amd/vulkan/radix_sort/common/vk/assert.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SRC_GRAPHICS_LIB_COMPUTE_COMMON_VK_ASSERT_H_ -#define SRC_GRAPHICS_LIB_COMPUTE_COMMON_VK_ASSERT_H_ - -// -// -// - -#include -#include - -// -// -// - -#ifdef __cplusplus -extern "C" { -#endif - -// -// -// - -char const * -vk_get_result_string(VkResult const result); - -VkResult -vk_assert(VkResult const result, char const * const file, int const line, bool const is_abort); - -// -// clang-format off -// - -#define vk(...) vk_assert((vk##__VA_ARGS__), __FILE__, __LINE__, true); -#define vk_ok(err) vk_assert(err, __FILE__, __LINE__, true); - -// -// clang-format on -// - -#ifdef __cplusplus -} -#endif - -// -// -// - -#endif // SRC_GRAPHICS_LIB_COMPUTE_COMMON_VK_ASSERT_H_ diff --git a/src/amd/vulkan/radix_sort/meson.build b/src/amd/vulkan/radix_sort/meson.build index 46c83847090..34199687f9c 100644 --- a/src/amd/vulkan/radix_sort/meson.build +++ b/src/amd/vulkan/radix_sort/meson.build @@ -21,8 +21,6 @@ subdir('shaders') radix_sort_files = files( - 'common/vk/assert.c', - 'common/vk/assert.h', 'common/vk/barrier.c', 'common/vk/barrier.h', 'common/macros.h', diff --git a/src/amd/vulkan/radix_sort/radix_sort_vk.c b/src/amd/vulkan/radix_sort/radix_sort_vk.c index e8be05979d5..70253884fc4 100644 --- a/src/amd/vulkan/radix_sort/radix_sort_vk.c +++ b/src/amd/vulkan/radix_sort/radix_sort_vk.c @@ -8,7 +8,6 @@ #include "common/macros.h" #include "common/util.h" -#include "common/vk/assert.h" #include "common/vk/barrier.h" #include "radix_sort_vk_devaddr.h" #include "shaders/push.h" @@ -196,7 +195,7 @@ radix_sort_vk_create(VkDevice device, // // Allocate radix_sort_vk // - struct radix_sort_vk * const rs = malloc(sizeof(*rs)); + struct radix_sort_vk * const rs = calloc(1, sizeof(*rs)); // // Save the config for layer @@ -260,7 +259,8 @@ radix_sort_vk_create(VkDevice device, { plci.pPushConstantRanges = pcr + ii; - vk(CreatePipelineLayout(device, &plci, NULL, rs->pipeline_layouts.handles + ii)); + if (vkCreatePipelineLayout(device, &plci, NULL, rs->pipeline_layouts.handles + ii) != VK_SUCCESS) + goto fail_layout; } // @@ -275,14 +275,15 @@ radix_sort_vk_create(VkDevice device, // .pCode = ar_data + ...; }; - VkShaderModule sms[ARRAY_LENGTH_MACRO(rs->pipelines.handles)]; + VkShaderModule sms[ARRAY_LENGTH_MACRO(rs->pipelines.handles)] = {0}; for (uint32_t ii = 0; ii < pipeline_count; ii++) { smci.codeSize = spv_sizes[ii]; smci.pCode = spv[ii]; - vk(CreateShaderModule(device, &smci, ac, sms + ii)); + if (vkCreateShaderModule(device, &smci, ac, sms + ii) != VK_SUCCESS) + goto fail_shader; } // @@ -357,7 +358,8 @@ radix_sort_vk_create(VkDevice device, // // Create the compute pipelines // - vk(CreateComputePipelines(device, pc, pipeline_count, cpcis, ac, rs->pipelines.handles)); + if (vkCreateComputePipelines(device, pc, pipeline_count, cpcis, ac, rs->pipelines.handles) != VK_SUCCESS) + goto fail_pipeline; // // Shader modules can be destroyed now @@ -391,6 +393,25 @@ radix_sort_vk_create(VkDevice device, rs->internal.partitions.offset = rs->internal.histograms.offset + rs->internal.histograms.range; return rs; + +fail_pipeline: + for (uint32_t ii = 0; ii < pipeline_count; ii++) + { + vkDestroyPipeline(device, rs->pipelines.handles[ii], ac); + } +fail_shader: + for (uint32_t ii = 0; ii < pipeline_count; ii++) + { + vkDestroyShaderModule(device, sms[ii], ac); + } +fail_layout: + for (uint32_t ii = 0; ii < pipeline_count; ii++) + { + vkDestroyPipelineLayout(device, rs->pipeline_layouts.handles[ii], ac); + } + + free(rs); + return NULL; } //