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 <samuel.pitoiset@gmail.com>
Acked-by: Martin Roukala <martin.roukala@mupuf.org>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16298>
This commit is contained in:
Samuel Pitoiset 2022-05-03 16:00:41 +02:00 committed by Marge Bot
parent 428929cf1f
commit 260cd1a18b
4 changed files with 27 additions and 168 deletions

View file

@ -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 <stdio.h>
#include <stdlib.h>
//
//
//
#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;
}
//
//
//

View file

@ -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 <stdbool.h>
#include <vulkan/vulkan.h>
//
//
//
#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_

View file

@ -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',

View file

@ -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;
}
//