Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Utilities.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_UTILITIES
19#define INCLUDED_RENDERER_BACKEND_VULKAN_UTILITIES
20
21#include "lib/debug.h"
22#include "ps/CLogger.h"
23
24#include <cstdint>
25#include <glad/vulkan.h>
26
27namespace Renderer::Backend::Vulkan { class CBuffer; }
28namespace Renderer::Backend::Vulkan { class CTexture; }
29
30#define ENSURE_VK_SUCCESS(EXPR) \
31 do \
32 { \
33 const VkResult result = (EXPR); \
34 if (result != VK_SUCCESS) \
35 { \
36 LOGERROR(#EXPR " returned {} ({}) instead of VK_SUCCESS", static_cast<int>(result), \
37 Utilities::GetVkResultName(result)); \
38 ENSURE(false && #EXPR); \
39 } \
40 } while (0)
41
42#define RETURN_NULLPTR_IF_NOT_VK_SUCCESS(EXPR) \
43 do \
44 { \
45 const VkResult result = (EXPR); \
46 if (result != VK_SUCCESS) \
47 { \
48 LOGERROR(#EXPR " returned {} ({}) instead of VK_SUCCESS ({}:{})", \
49 static_cast<int>(result), Utilities::GetVkResultName(result), __func__, __LINE__); \
50 return nullptr; \
51 } \
52 } while (0)
53
54namespace Renderer
55{
56
57namespace Backend
58{
59
60namespace Vulkan
61{
62
63namespace Utilities
64{
65
66// https://github.com/KhronosGroup/Vulkan-Docs/wiki/Synchronization-Examples-(Legacy-synchronization-APIs)
67
69 VkCommandBuffer commandBuffer, CTexture* texture,
70 const VkImageLayout oldLayout, const VkImageLayout newLayout,
71 const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
72 const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
73
75 VkCommandBuffer commandBuffer, VkImage image, const uint32_t level, const uint32_t layer,
76 const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
77 const VkImageLayout oldLayout, const VkImageLayout newLayout,
78 const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask,
79 const VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT);
80
82 VkCommandBuffer commandBuffer, CBuffer* buffer,
83 const VkDeviceSize offset, const VkDeviceSize size,
84 const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
85 const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
86
88 VkCommandBuffer commandBuffer,
89 const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
90 const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
91
93 VkCommandBuffer commandBuffer,
94 const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
95
96void SubmitDebugSyncMemoryBarrier(VkCommandBuffer commandBuffer);
97
98const char* GetVkResultName(const VkResult result);
99
100} // namespace Utilities
101
102} // namespace Vulkan
103
104} // namespace Backend
105
106} // namespace Renderer
107
108#endif // INCLUDED_RENDERER_BACKEND_VULKAN_UTILITIES
Represents a texture object.
Definition: TextureManager.h:271
void SubmitImageMemoryBarrier(VkCommandBuffer commandBuffer, VkImage image, const uint32_t level, const uint32_t layer, const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask, const VkImageLayout oldLayout, const VkImageLayout newLayout, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask, const VkImageAspectFlags aspectMask)
Definition: Utilities.cpp:68
void SubmitDebugSyncMemoryBarrier(VkCommandBuffer commandBuffer)
Definition: Utilities.cpp:139
void SubmitMemoryBarrier(VkCommandBuffer commandBuffer, const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:116
void SubmitBufferMemoryBarrier(VkCommandBuffer commandBuffer, CBuffer *buffer, const VkDeviceSize offset, const VkDeviceSize size, const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:95
void SubmitPipelineBarrier(VkCommandBuffer commandBuffer, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:130
void SetTextureLayout(VkCommandBuffer commandBuffer, CTexture *texture, const VkImageLayout oldLayout, const VkImageLayout newLayout, const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:37
const char * GetVkResultName(const VkResult result)
Definition: Utilities.cpp:162
Definition: Buffer.cpp:37
Backend
Definition: Backend.h:28
Definition: Canvas2D.h:30