vkQuake2 doxygen  1.0 dev
vk_cmd.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2018-2019 Krzysztof Kondrak
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program 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.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 
21 #include "vk_local.h"
22 
23 VkResult QVk_BeginCommand(const VkCommandBuffer *commandBuffer)
24 {
25  VkCommandBufferBeginInfo cmdInfo = {
26  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
27  .pNext = NULL,
28  .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
29  .pInheritanceInfo = NULL
30  };
31 
32  return vkBeginCommandBuffer(*commandBuffer, &cmdInfo);
33 }
34 
35 void QVk_SubmitCommand(const VkCommandBuffer *commandBuffer, const VkQueue *queue)
36 {
37  VK_VERIFY(vkEndCommandBuffer(*commandBuffer));
38 
39  VkSubmitInfo submitInfo = {
40  .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
41  .pNext = NULL,
42  .waitSemaphoreCount = 0,
43  .pWaitSemaphores = NULL,
44  .pWaitDstStageMask = NULL,
45  .commandBufferCount = 1,
46  .pCommandBuffers = commandBuffer,
47  .signalSemaphoreCount = 0,
48  .pSignalSemaphores = NULL
49  };
50 
51  VkFenceCreateInfo fCreateInfo = {
52  .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
53  .pNext = NULL,
54  .flags = 0
55  };
56 
57  VkFence queueFence;
58  VK_VERIFY(vkCreateFence(vk_device.logical, &fCreateInfo, NULL, &queueFence));
59  VK_VERIFY(vkQueueSubmit(*queue, 1, &submitInfo, queueFence));
60  VK_VERIFY(vkWaitForFences(vk_device.logical, 1, &queueFence, VK_TRUE, UINT64_MAX));
61 
62  vkDestroyFence(vk_device.logical, queueFence, NULL);
63 }
64 
65 VkResult QVk_CreateCommandPool(VkCommandPool *commandPool, uint32_t queueFamilyIndex)
66 {
67  VkCommandPoolCreateInfo cpCreateInfo = {
68  .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
69  .pNext = NULL,
70  // allow the command pool to be explicitly reset without reallocating it manually during recording each frame
71  .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
72  .queueFamilyIndex = queueFamilyIndex
73  };
74 
75  return vkCreateCommandPool(vk_device.logical, &cpCreateInfo, NULL, commandPool);
76 }
77 
78 VkCommandBuffer QVk_CreateCommandBuffer(const VkCommandPool *commandPool, VkCommandBufferLevel level)
79 {
80  VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
81  VkCommandBufferAllocateInfo allocInfo = {
82  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
83  .pNext = NULL,
84  .commandPool = *commandPool,
85  .level = level,
86  .commandBufferCount = 1
87  };
88 
89  VK_VERIFY(vkAllocateCommandBuffers(vk_device.logical, &allocInfo, &commandBuffer));
90  return commandBuffer;
91 }
qvkdevice_t::logical
VkDevice logical
Definition: qvk.h:40
vk_local.h
QVk_CreateCommandPool
VkResult QVk_CreateCommandPool(VkCommandPool *commandPool, uint32_t queueFamilyIndex)
Definition: vk_cmd.c:65
QVk_CreateCommandBuffer
VkCommandBuffer QVk_CreateCommandBuffer(const VkCommandPool *commandPool, VkCommandBufferLevel level)
Definition: vk_cmd.c:78
vk_device
qvkdevice_t vk_device
Definition: vk_common.c:51
QVk_BeginCommand
VkResult QVk_BeginCommand(const VkCommandBuffer *commandBuffer)
Definition: vk_cmd.c:23
NULL
#define NULL
Definition: q_shared.h:67
VK_VERIFY
#define VK_VERIFY(x)
Definition: vk_local.h:59
level
GLint level
Definition: qgl_win.c:116
QVk_SubmitCommand
void QVk_SubmitCommand(const VkCommandBuffer *commandBuffer, const VkQueue *queue)
Definition: vk_cmd.c:35