Pyrogenesis  trunk
Utilities.h
Go to the documentation of this file.
1 /* Copyright (C) 2023 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 "ps/CStr.h"
22 
23 #include <glad/vulkan.h>
24 
25 #define ENSURE_VK_SUCCESS(EXPR) \
26  do \
27  { \
28  const VkResult result = (EXPR); \
29  if (result != VK_SUCCESS) \
30  { \
31  LOGERROR(#EXPR " returned %d instead of VK_SUCCESS", static_cast<int>(result)); \
32  ENSURE(false && #EXPR); \
33  } \
34  } while (0)
35 
36 namespace Renderer
37 {
38 
39 namespace Backend
40 {
41 
42 namespace Vulkan
43 {
44 
45 class CBuffer;
46 class CTexture;
47 
48 namespace Utilities
49 {
50 
51 // https://github.com/KhronosGroup/Vulkan-Docs/wiki/Synchronization-Examples-(Legacy-synchronization-APIs)
52 
53 void SetTextureLayout(
54  VkCommandBuffer commandBuffer, CTexture* texture,
55  const VkImageLayout oldLayout, const VkImageLayout newLayout,
56  const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
57  const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
58 
60  VkCommandBuffer commandBuffer, VkImage image, const uint32_t level, const uint32_t layer,
61  const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
62  const VkImageLayout oldLayout, const VkImageLayout newLayout,
63  const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask,
64  const VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT);
65 
67  VkCommandBuffer commandBuffer, CBuffer* buffer,
68  const uint32_t offset, const uint32_t size,
69  const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
70  const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
71 
73  VkCommandBuffer commandBuffer,
74  const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask,
75  const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
76 
78  VkCommandBuffer commandBuffer,
79  const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask);
80 
81 void SubmitDebugSyncMemoryBarrier(VkCommandBuffer commandBuffer);
82 
83 } // namespace Utilities
84 
85 } // namespace Vulkan
86 
87 } // namespace Backend
88 
89 } // namespace Renderer
90 
91 #endif // INCLUDED_RENDERER_BACKEND_VULKAN_UTILITIES
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:70
void SubmitPipelineBarrier(VkCommandBuffer commandBuffer, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:132
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:39
Represents a texture object.
Definition: TextureManager.h:256
Backend
Definition: Backend.h:27
void SubmitMemoryBarrier(VkCommandBuffer commandBuffer, const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:118
void SubmitDebugSyncMemoryBarrier(VkCommandBuffer commandBuffer)
Definition: Utilities.cpp:141
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
void SubmitBufferMemoryBarrier(VkCommandBuffer commandBuffer, CBuffer *buffer, const uint32_t offset, const uint32_t size, const VkAccessFlags srcAccessMask, const VkAccessFlags dstAccessMask, const VkPipelineStageFlags srcStageMask, const VkPipelineStageFlags dstStageMask)
Definition: Utilities.cpp:97