Quake II RTX doxygen  1.0 dev
vk_util.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2018 Christoph Schied
3 Copyright (C) 2019, NVIDIA CORPORATION. All rights reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef __VK_UTIL_H__
21 #define __VK_UTIL_H__
22 
23 #include <vulkan/vulkan.h>
24 
25 char * sgets(char * str, int num, char const ** input);
26 
27 #ifdef VKPT_DEVICE_GROUPS
28 #define VKPT_MAX_GPUS 2
29 #else
30 #define VKPT_MAX_GPUS 1
31 #endif
32 
33 typedef struct BufferResource_s {
34  VkBuffer buffer;
35  VkDeviceMemory memory;
36  size_t size;
37  int is_mapped;
39 
40 VkResult
42  BufferResource_t *buf,
43  VkDeviceSize size,
44  VkBufferUsageFlags usage,
45  VkMemoryPropertyFlags mem_properties);
46 
47 VkResult buffer_destroy(BufferResource_t *buf);
49 void *buffer_map(BufferResource_t *buf);
51 
52 uint32_t get_memory_type(uint32_t mem_req_type_bits, VkMemoryPropertyFlags mem_prop);
53 
54 
55 #define IMAGE_BARRIER(cmd_buf, ...) \
56  do { \
57  VkImageMemoryBarrier img_mem_barrier = { \
58  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, \
59  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
60  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
61  __VA_ARGS__ \
62  }; \
63  vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, \
64  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, \
65  1, &img_mem_barrier); \
66  } while(0)
67 
68 #define BUFFER_BARRIER(cmd_buf, ...) \
69  do { \
70  VkBufferMemoryBarrier buf_mem_barrier = { \
71  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, \
72  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
73  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
74  __VA_ARGS__ \
75  }; \
76  vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, \
77  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 1, &buf_mem_barrier, \
78  0, NULL); \
79  } while(0)
80 
81 
82 #define CREATE_PIPELINE_LAYOUT(dev, layout, ...) \
83  do { \
84  VkPipelineLayoutCreateInfo pipeline_layout_info = { \
85  .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, \
86  __VA_ARGS__ \
87  }; \
88  _VK(vkCreatePipelineLayout(dev, &pipeline_layout_info, NULL, layout)); \
89  } while(0) \
90 
91 const char *qvk_format_to_string(VkFormat format);
92 const char *qvk_result_to_string(VkResult result);
93 
94 // #define VKPT_ENABLE_VALIDATION
95 
96 #ifdef VKPT_ENABLE_VALIDATION
97 #define ATTACH_LABEL_VARIABLE(a, type) \
98  do { \
99  /*Com_Printf("attaching object label 0x%08lx %s\n", (uint64_t) a, #a);*/ \
100  VkDebugMarkerObjectNameInfoEXT name_info = { \
101  .sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT, \
102  .object = (uint64_t) a, \
103  .objectType = VK_DEBUG_REPORT_OBJECT_TYPE_##type##_EXT, \
104  .pObjectName = #a \
105  }; \
106  qvkDebugMarkerSetObjectNameEXT(qvk.device, &name_info); \
107  } while(0)
108 
109 #define ATTACH_LABEL_VARIABLE_NAME(a, type, name) \
110  do { \
111  /*Com_Printf("attaching object label 0x%08lx %s\n", (uint64_t) a, name);*/ \
112  VkDebugMarkerObjectNameInfoEXT name_info = { \
113  .sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT, \
114  .object = (uint64_t) a, \
115  .objectType = VK_DEBUG_REPORT_OBJECT_TYPE_##type##_EXT, \
116  .pObjectName = name, \
117  }; \
118  qvkDebugMarkerSetObjectNameEXT(qvk.device, &name_info); \
119  } while(0)
120 
121 #define BEGIN_CMD_LABEL(cmd_buf, label) \
122  do { \
123  VkDebugUtilsLabelEXT label_info; \
124  label_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; \
125  label_info.pNext = NULL; \
126  label_info.pLabelName = label; \
127  label_info.color[0] = label_info.color[1] = label_info.color[2] = label_info.color[3] = 1.0f; \
128  qvkCmdBeginDebugUtilsLabelEXT(cmd_buf, &label_info); \
129  } while (0)
130 
131 #define END_CMD_LABEL(cmd_buf) \
132  do { \
133  qvkCmdEndDebugUtilsLabelEXT(cmd_buf); \
134  } while (0)
135 
136 #else
137 #define ATTACH_LABEL_VARIABLE(a, type) do{}while(0)
138 #define ATTACH_LABEL_VARIABLE_NAME(a, type, name) do{}while(0)
139 #define BEGIN_CMD_LABEL(cmd_buf, label) do{}while(0)
140 #define END_CMD_LABEL(cmd_buf) do{}while(0)
141 #endif
142 
143 static inline size_t align(size_t x, size_t alignment)
144 {
145  return (x + (alignment - 1)) & ~(alignment - 1);
146 }
147 
148 #ifdef VKPT_IMAGE_DUMPS
149 void save_to_pfm_file(char* prefix, uint64_t frame_counter, uint64_t width, uint64_t height, char* data, uint64_t rowPitch, int32_t type);
150 #endif
151 
152 #endif /*__VK_UTIL_H__*/
height
static int height
Definition: physical_sky.c:39
input
static in_state_t input
Definition: input.c:71
align
static size_t align(size_t x, size_t alignment)
Definition: vk_util.h:143
buffer_unmap
void buffer_unmap(BufferResource_t *buf)
Definition: vk_util.c:159
width
static int width
Definition: physical_sky.c:38
qvk_format_to_string
const char * qvk_format_to_string(VkFormat format)
Definition: vk_util.c:167
BufferResource_s::buffer
VkBuffer buffer
Definition: vk_util.h:34
get_memory_type
uint32_t get_memory_type(uint32_t mem_req_type_bits, VkMemoryPropertyFlags mem_prop)
Definition: vk_util.c:45
buffer_destroy
VkResult buffer_destroy(BufferResource_t *buf)
Definition: vk_util.c:132
sgets
char * sgets(char *str, int num, char const **input)
Definition: vk_util.c:26
BufferResource_s::is_mapped
int is_mapped
Definition: vk_util.h:37
buffer_map
void * buffer_map(BufferResource_t *buf)
Definition: vk_util.c:147
BufferResource_s
Definition: vk_util.h:33
buffer_create
VkResult buffer_create(BufferResource_t *buf, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags mem_properties)
Definition: vk_util.c:57
BufferResource_t
struct BufferResource_s BufferResource_t
BufferResource_s::size
size_t size
Definition: vk_util.h:36
qvk_result_to_string
const char * qvk_result_to_string(VkResult result)
Definition: vk_util.c:439
BufferResource_s::memory
VkDeviceMemory memory
Definition: vk_util.h:35