Monado OpenXR Runtime
vk_mini_helpers.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Super small defines that makes writing Vulkan code smaller.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_vk
8 */
9
10#pragma once
11
12#include "vk/vk_helpers.h"
13
14
15/*!
16 * Calls `vkDestroy##TYPE` on @p THING if it is not @p VK_NULL_HANDLE, sets it
17 * to @p VK_NULL_HANDLE afterwards. The implicit argument @p vk will be used to
18 * look up the function, and @p vk->device will be used as the device.
19 *
20 * @param TYPE The type of the thing to be destroyed.
21 * @param THING Object to be destroyed.
22 *
23 * @ingroup aux_vk
24 */
25#define D(TYPE, THING) \
26 if (THING != VK_NULL_HANDLE) { \
27 vk->vkDestroy##TYPE(vk->device, THING, NULL); \
28 THING = VK_NULL_HANDLE; \
29 }
30
31/*!
32 * Calls `vkFree##TYPE` on @p THING` if it is not @p VK_NULL_HANDLE, sets it to
33 * @p VK_NULL_HANDLE afterwards. The implicit argument @p vk will be used to
34 * look up the function, and @p vk->device will be used as the device.
35 *
36 * @param TYPE The type of the thing to be freed.
37 * @param THING Object to be freed.
38 *
39 * @ingroup aux_vk
40 */
41#define DF(TYPE, THING) \
42 if (THING != VK_NULL_HANDLE) { \
43 vk->vkFree##TYPE(vk->device, THING, NULL); \
44 THING = VK_NULL_HANDLE; \
45 }
Common Vulkan code header.