a/vk: Add mini defines helpers

This commit is contained in:
Jakob Bornecrantz 2023-09-30 14:36:38 +01:00
parent 0fb3e9a943
commit 42080b068c
2 changed files with 46 additions and 0 deletions

View file

@ -19,6 +19,7 @@ add_library(
vk_image_allocator.h
vk_image_readback_to_xf_pool.c
vk_image_readback_to_xf_pool.h
vk_mini_helpers.h
vk_print.c
vk_state_creators.c
vk_surface_info.c

View file

@ -0,0 +1,45 @@
// Copyright 2019-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Super small defines that makes writing Vulkan code smaller.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @ingroup aux_vk
*/
#pragma once
#include "vk/vk_helpers.h"
/*!
* Calls `vkDestroy##TYPE` on @p THING if it is not @p VK_NULL_HANDLE, sets it
* to @p VK_NULL_HANDLE afterwards. The implicit argument @p vk will be used to
* look up the function, and @p vk->device will be used as the device.
*
* @param TYPE The type of the thing to be destroyed.
* @param THING Object to be destroyed.
*
* @ingroup aux_vk
*/
#define D(TYPE, THING) \
if (THING != VK_NULL_HANDLE) { \
vk->vkDestroy##TYPE(vk->device, THING, NULL); \
THING = VK_NULL_HANDLE; \
}
/*!
* Calls `vkFree##TYPE` on @p THING` if it is not @p VK_NULL_HANDLE, sets it to
* @p VK_NULL_HANDLE afterwards. The implicit argument @p vk will be used to
* look up the function, and @p vk->device will be used as the device.
*
* @param TYPE The type of the thing to be freed.
* @param THING Object to be freed.
*
* @ingroup aux_vk
*/
#define DF(TYPE, THING) \
if (THING != VK_NULL_HANDLE) { \
vk->vkFree##TYPE(vk->device, THING, NULL); \
THING = VK_NULL_HANDLE; \
}