2019-07-23 03:28:57 +00:00
|
|
|
/*
|
|
|
|
vid_common_vulkan.c
|
|
|
|
|
|
|
|
Common Vulkan video driver functions
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2019 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_MATH_H
|
|
|
|
# include <math.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/mathlib.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
|
|
|
#include "QF/vid.h"
|
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
2020-02-10 06:07:35 +00:00
|
|
|
#include "QF/Vulkan/buffer.h"//FIXME should QFV_CmdPipelineBarrier be here?
|
2020-02-10 09:18:37 +00:00
|
|
|
#include "QF/Vulkan/image.h"//FIXME should QFV_CmdPipelineBarrier be here?
|
2020-02-12 09:55:51 +00:00
|
|
|
#include "QF/Vulkan/renderpass.h"//FIXME should QFV_CmdPipelineBarrier be here?
|
2020-02-12 19:21:35 +00:00
|
|
|
#include "QF/Vulkan/pipeline.h"//FIXME should QFV_CmdPipelineBarrier be here?
|
2019-07-23 03:28:57 +00:00
|
|
|
#include "QF/Vulkan/command.h"
|
|
|
|
#include "QF/Vulkan/device.h"
|
|
|
|
#include "QF/Vulkan/instance.h"
|
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "d_iface.h"
|
|
|
|
#include "r_internal.h"
|
|
|
|
#include "vid_vulkan.h"
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
qfv_cmdpool_t *
|
|
|
|
QFV_CreateCommandPool (qfv_device_t *device, uint32_t queueFamily,
|
|
|
|
int transient, int reset)
|
|
|
|
{
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
uint32_t flags = 0;
|
|
|
|
if (transient) {
|
|
|
|
flags |= VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
|
|
|
|
}
|
|
|
|
if (reset) {
|
|
|
|
flags |= VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
|
|
|
}
|
|
|
|
VkCommandPoolCreateInfo createInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 0,
|
|
|
|
flags,
|
|
|
|
queueFamily
|
|
|
|
};
|
|
|
|
qfv_cmdpool_t *cmdpool = malloc (sizeof (*cmdpool));
|
|
|
|
dfunc->vkCreateCommandPool (dev, &createInfo, 0, &cmdpool->cmdpool);
|
2020-02-07 02:45:05 +00:00
|
|
|
cmdpool->device = device;
|
2019-07-23 03:28:57 +00:00
|
|
|
return cmdpool;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFV_ResetCommandPool (qfv_cmdpool_t *pool, int release)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = pool->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 03:28:57 +00:00
|
|
|
VkCommandPool cmdpool = pool->cmdpool;
|
|
|
|
VkCommandPoolResetFlags release_flag = 0;
|
|
|
|
|
|
|
|
if (release) {
|
|
|
|
release_flag = VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dfunc->vkResetCommandPool (dev, cmdpool, release_flag) == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-07-23 04:05:32 +00:00
|
|
|
void
|
|
|
|
QFV_DestroyCommandPool (qfv_cmdpool_t *pool)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = pool->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 04:05:32 +00:00
|
|
|
|
|
|
|
dfunc->vkDestroyCommandPool (dev, pool->cmdpool, 0);
|
|
|
|
free (pool);
|
|
|
|
}
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
qfv_cmdbufferset_t *
|
2019-07-23 03:28:57 +00:00
|
|
|
QFV_AllocateCommandBuffers (qfv_cmdpool_t *pool, int secondary, int count)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = pool->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 03:28:57 +00:00
|
|
|
uint32_t level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
|
|
if (secondary) {
|
|
|
|
level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
|
|
|
|
}
|
|
|
|
VkCommandBufferAllocateInfo allocInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, 0,
|
|
|
|
pool->cmdpool, level, count
|
|
|
|
};
|
2020-02-16 13:43:57 +00:00
|
|
|
qfv_cmdbufferset_t *cmdbufferset;
|
|
|
|
cmdbufferset = malloc (sizeof (qfv_cmdbufferset_t)
|
|
|
|
+ count * sizeof (qfv_buffer_t *)
|
|
|
|
+ count * sizeof (qfv_buffer_t)
|
|
|
|
+ count * sizeof (VkCommandBuffer));
|
|
|
|
cmdbufferset->buffers = (qfv_cmdbuffer_t **) (cmdbufferset + 1);
|
|
|
|
cmdbufferset->vkBuffers = (VkCommandBuffer *) (cmdbufferset->buffers
|
|
|
|
+ count);
|
2020-02-16 15:10:59 +00:00
|
|
|
qfv_cmdbuffer_t *buffer = (qfv_cmdbuffer_t *) (cmdbufferset->vkBuffers
|
|
|
|
+ count);
|
2020-02-16 13:43:57 +00:00
|
|
|
cmdbufferset->cmdpool = pool->cmdpool;
|
|
|
|
cmdbufferset->numBuffers = count;
|
|
|
|
dfunc->vkAllocateCommandBuffers (dev, &allocInfo, cmdbufferset->vkBuffers);
|
2019-07-23 03:28:57 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2020-02-16 15:10:59 +00:00
|
|
|
buffer->device = device;
|
|
|
|
buffer->buffer = &cmdbufferset->vkBuffers[i];
|
|
|
|
cmdbufferset->buffers[i] = buffer++;
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
2020-02-16 13:43:57 +00:00
|
|
|
return cmdbufferset;
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
void QFV_FreeCommandBuffers (qfv_cmdbufferset_t *bufferset)
|
2019-07-23 03:28:57 +00:00
|
|
|
{
|
2020-02-16 13:43:57 +00:00
|
|
|
qfv_device_t *device = bufferset->device;
|
2020-02-07 02:45:05 +00:00
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 04:05:32 +00:00
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkFreeCommandBuffers (dev, bufferset->cmdpool,
|
|
|
|
bufferset->numBuffers,
|
|
|
|
bufferset->vkBuffers);
|
|
|
|
free (bufferset);
|
2019-07-23 04:05:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-23 03:28:57 +00:00
|
|
|
int
|
|
|
|
QFV_BeginCommandBuffer (qfv_cmdbuffer_t *buffer, int oneTime, int rpContinue,
|
|
|
|
int simultaneous,
|
|
|
|
VkCommandBufferInheritanceInfo *inheritanceInfo)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = buffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2020-02-16 13:43:57 +00:00
|
|
|
VkCommandBuffer buff = *buffer->buffer;
|
2019-07-23 03:28:57 +00:00
|
|
|
VkCommandBufferUsageFlags usage = 0;
|
|
|
|
|
|
|
|
if (oneTime) {
|
|
|
|
usage |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
|
|
|
}
|
|
|
|
if (rpContinue) {
|
|
|
|
usage |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
|
|
|
|
}
|
|
|
|
if (simultaneous) {
|
|
|
|
usage |= VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkCommandBufferBeginInfo beginInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 0,
|
|
|
|
usage,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
return dfunc->vkBeginCommandBuffer (buff, &beginInfo) == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFV_EndCommandBuffer (qfv_cmdbuffer_t *buffer)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = buffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2020-02-16 13:43:57 +00:00
|
|
|
VkCommandBuffer buff = *buffer->buffer;
|
2019-07-23 03:28:57 +00:00
|
|
|
|
|
|
|
return dfunc->vkEndCommandBuffer (buff) == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFV_ResetCommandBuffer (qfv_cmdbuffer_t *buffer, int release)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = buffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2020-02-16 13:43:57 +00:00
|
|
|
VkCommandBuffer buff = *buffer->buffer;
|
2019-07-23 03:28:57 +00:00
|
|
|
VkCommandBufferResetFlags release_flag = 0;
|
|
|
|
|
|
|
|
if (release) {
|
|
|
|
release_flag = VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dfunc->vkResetCommandBuffer (buff, release_flag) == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
qfv_semaphore_t *
|
|
|
|
QFV_CreateSemaphore (qfv_device_t *device)
|
|
|
|
{
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
VkSemaphoreCreateInfo createInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, 0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
qfv_semaphore_t *semaphore = malloc (sizeof (*semaphore));
|
2020-02-07 02:45:05 +00:00
|
|
|
semaphore->device = device;
|
2019-07-23 03:28:57 +00:00
|
|
|
|
|
|
|
dfunc->vkCreateSemaphore (dev, &createInfo, 0, &semaphore->semaphore);
|
|
|
|
return semaphore;
|
|
|
|
}
|
|
|
|
|
|
|
|
qfv_semaphoreset_t *
|
|
|
|
QFV_CreateSemaphoreSet (qfv_semaphore_t **semaphores, int numSemaphores)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = semaphores[0]->device;
|
2019-07-23 03:28:57 +00:00
|
|
|
qfv_semaphoreset_t *semaphoreset;
|
|
|
|
semaphoreset = calloc (1, sizeof (*semaphoreset)
|
2020-02-16 15:10:32 +00:00
|
|
|
+ sizeof (qfv_semaphore_t *) * numSemaphores
|
2019-07-23 03:28:57 +00:00
|
|
|
+ sizeof (VkSemaphore) * numSemaphores
|
|
|
|
+ sizeof (VkPipelineStageFlags) * numSemaphores);
|
|
|
|
|
2020-02-07 02:45:05 +00:00
|
|
|
semaphoreset->device = device;
|
2020-02-16 15:10:32 +00:00
|
|
|
semaphoreset->vkSemaphores = (VkSemaphore *) (semaphoreset + 1);
|
2019-07-23 03:28:57 +00:00
|
|
|
semaphoreset->stages = (VkPipelineStageFlags *)
|
2020-02-16 15:10:32 +00:00
|
|
|
&semaphoreset->vkSemaphores[numSemaphores];
|
|
|
|
semaphoreset->semaphores = (qfv_semaphore_t **) (semaphoreset->stages
|
|
|
|
+ numSemaphores);
|
2019-07-23 03:28:57 +00:00
|
|
|
semaphoreset->numSemaphores = numSemaphores;
|
|
|
|
|
2020-02-16 15:10:32 +00:00
|
|
|
if (semaphores) {
|
|
|
|
for (int i = 0; i < numSemaphores; i++) {
|
|
|
|
semaphoreset->semaphores[i] = semaphores[i];
|
|
|
|
semaphoreset->vkSemaphores[i] = semaphores[i]->semaphore;
|
|
|
|
}
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
|
|
|
return semaphoreset;
|
|
|
|
}
|
|
|
|
|
2019-07-23 04:05:32 +00:00
|
|
|
void
|
|
|
|
QFV_DestroySemaphore (qfv_semaphore_t *semaphore)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = semaphore->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 04:05:32 +00:00
|
|
|
|
|
|
|
dfunc->vkDestroySemaphore (dev, semaphore->semaphore, 0);
|
|
|
|
free (semaphore);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QFV_DestroySemaphoreSet (qfv_semaphoreset_t *semaphores)
|
|
|
|
{
|
|
|
|
free (semaphores);
|
|
|
|
}
|
|
|
|
|
2019-07-23 03:28:57 +00:00
|
|
|
qfv_fence_t *
|
|
|
|
QFV_CreateFence (qfv_device_t *device, int signaled)
|
|
|
|
{
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
VkFenceCreateInfo createInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, 0,
|
|
|
|
signaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
qfv_fence_t *fence = malloc (sizeof (*fence));
|
2020-02-07 02:45:05 +00:00
|
|
|
fence->device = device;
|
2019-07-23 03:28:57 +00:00
|
|
|
|
|
|
|
dfunc->vkCreateFence (dev, &createInfo, 0, &fence->fence);
|
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
|
|
|
qfv_fenceset_t *
|
|
|
|
QFV_CreateFenceSet (qfv_fence_t **fences, int numFences)
|
|
|
|
{
|
|
|
|
qfv_fenceset_t *fenceset = malloc (sizeof (*fenceset)
|
2020-02-16 13:43:57 +00:00
|
|
|
+ sizeof (qfv_fence_t) * numFences
|
2019-07-23 03:28:57 +00:00
|
|
|
+ sizeof (VkFence) * numFences);
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
fenceset->fences = (qfv_fence_t **) (fenceset + 1);
|
|
|
|
fenceset->vkFences = (VkFence *) (fenceset->fences + numFences);
|
2019-07-23 03:28:57 +00:00
|
|
|
fenceset->numFences = numFences;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
if (fences) {
|
|
|
|
fenceset->device = fences[0]->device;
|
|
|
|
for (int i = 0; i < numFences; i++) {
|
|
|
|
fenceset->fences[i] = fences[i];
|
|
|
|
fenceset->vkFences[i] = fences[i]->fence;
|
|
|
|
}
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
|
|
|
return fenceset;
|
|
|
|
}
|
|
|
|
|
2019-07-23 04:05:32 +00:00
|
|
|
void
|
|
|
|
QFV_DestroyFence (qfv_fence_t *fence)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = fence->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 04:05:32 +00:00
|
|
|
|
|
|
|
dfunc->vkDestroyFence (dev, fence->fence, 0);
|
|
|
|
free (fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-16 13:43:57 +00:00
|
|
|
QFV_DestroyFenceSet (qfv_fenceset_t *fenceset)
|
2019-07-23 04:05:32 +00:00
|
|
|
{
|
2020-02-16 13:43:57 +00:00
|
|
|
free (fenceset);
|
2019-07-23 04:05:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-23 03:28:57 +00:00
|
|
|
int
|
2020-02-16 13:43:57 +00:00
|
|
|
QFV_WaitForFences (qfv_fenceset_t *fenceset, int all, uint64_t timeout)
|
2019-07-23 03:28:57 +00:00
|
|
|
{
|
2020-02-16 13:43:57 +00:00
|
|
|
qfv_device_t *device = fenceset->device;
|
2020-02-07 02:45:05 +00:00
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 03:28:57 +00:00
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
VkResult res = dfunc->vkWaitForFences (dev, fenceset->numFences,
|
|
|
|
fenceset->vkFences, all, timeout);
|
2019-07-23 03:28:57 +00:00
|
|
|
return res == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-16 13:43:57 +00:00
|
|
|
QFV_WaitForFence (qfv_fence_t *fence, uint64_t timeout)
|
2019-07-23 03:28:57 +00:00
|
|
|
{
|
2020-02-16 13:43:57 +00:00
|
|
|
qfv_device_t *device = fence->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
VkResult res = dfunc->vkWaitForFences (dev, 1, &fence->fence, 1, timeout);
|
|
|
|
return res == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFV_ResetFences (qfv_fenceset_t *fenceset)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = fenceset->device;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
return dfunc->vkResetFences (dev, fenceset->numFences,
|
|
|
|
fenceset->vkFences) == VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QFV_ResetFence (qfv_fence_t *fence)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = fence->device;
|
2020-02-07 02:45:05 +00:00
|
|
|
VkDevice dev = device->dev;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 03:28:57 +00:00
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
return dfunc->vkResetFences (dev, 1, &fence->fence) == VK_SUCCESS;
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-07-23 03:37:47 +00:00
|
|
|
QFV_QueueSubmit (qfv_queue_t *queue, qfv_semaphoreset_t *waitSemaphores,
|
2019-07-23 03:28:57 +00:00
|
|
|
qfv_cmdbufferset_t *buffers,
|
|
|
|
qfv_semaphoreset_t *signalSemaphores, qfv_fence_t *fence)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = queue->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 03:28:57 +00:00
|
|
|
VkSubmitInfo submitInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_SUBMIT_INFO, 0,
|
|
|
|
waitSemaphores->numSemaphores,
|
2020-02-16 15:10:32 +00:00
|
|
|
waitSemaphores->vkSemaphores, waitSemaphores->stages,
|
2020-02-16 13:43:57 +00:00
|
|
|
buffers->numBuffers, buffers->vkBuffers,
|
2019-07-23 03:28:57 +00:00
|
|
|
signalSemaphores->numSemaphores,
|
2020-02-16 15:10:32 +00:00
|
|
|
signalSemaphores->vkSemaphores
|
2019-07-23 03:28:57 +00:00
|
|
|
};
|
|
|
|
//FIXME multi-batch
|
2019-07-23 03:37:47 +00:00
|
|
|
return dfunc->vkQueueSubmit (queue->queue, 1, &submitInfo,
|
2019-07-23 03:28:57 +00:00
|
|
|
fence->fence) == VK_SUCCESS;
|
|
|
|
}
|
2019-07-23 04:05:32 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
QFV_QueueWaitIdle (qfv_queue_t *queue)
|
|
|
|
{
|
2020-02-07 02:45:05 +00:00
|
|
|
qfv_device_t *device = queue->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2019-07-23 04:05:32 +00:00
|
|
|
return dfunc->vkQueueWaitIdle (queue->queue) == VK_SUCCESS;
|
|
|
|
}
|
2020-02-10 06:07:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdPipelineBarrier (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
VkPipelineStageFlags srcStageMask,
|
|
|
|
VkPipelineStageFlags dstStageMask,
|
|
|
|
VkDependencyFlags dependencyFlags,
|
|
|
|
struct qfv_memorybarrierset_s *memBarrierSet,
|
|
|
|
qfv_bufferbarrierset_t *buffBarrierSet,
|
2020-02-10 09:18:37 +00:00
|
|
|
qfv_imagebarrierset_t *imgBarrierSet)
|
2020-02-10 06:07:35 +00:00
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
uint32_t numMemBarriers = 0;
|
|
|
|
VkMemoryBarrier *memBarriers = 0;
|
|
|
|
uint32_t numBuffBarriers = 0;
|
|
|
|
VkBufferMemoryBarrier *buffBarriers = 0;
|
|
|
|
uint32_t numImgBarriers = 0;
|
|
|
|
VkImageMemoryBarrier *imgBarriers = 0;
|
|
|
|
|
|
|
|
if (buffBarrierSet) {
|
|
|
|
numBuffBarriers = buffBarrierSet->numBarriers;
|
|
|
|
buffBarriers = buffBarrierSet->barriers;
|
|
|
|
}
|
2020-02-10 09:18:37 +00:00
|
|
|
if (imgBarrierSet) {
|
|
|
|
numImgBarriers = imgBarrierSet->numBarriers;
|
|
|
|
imgBarriers = imgBarrierSet->barriers;
|
|
|
|
}
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdPipelineBarrier (*cmdBuffer->buffer,
|
|
|
|
srcStageMask, dstStageMask, dependencyFlags,
|
|
|
|
numMemBarriers, memBarriers,
|
|
|
|
numBuffBarriers, buffBarriers,
|
|
|
|
numImgBarriers, imgBarriers);
|
2020-02-10 06:07:35 +00:00
|
|
|
}
|
2020-02-10 11:42:19 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdCopyBuffer (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
struct qfv_buffer_s *src, struct qfv_buffer_s *dst,
|
|
|
|
VkBufferCopy *regions, uint32_t numRegions)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdCopyBuffer (*cmdBuffer->buffer, src->buffer, dst->buffer,
|
2020-02-10 11:42:19 +00:00
|
|
|
numRegions, regions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdCopyBufferToImage (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
struct qfv_buffer_s *src,
|
|
|
|
struct qfv_image_s *dst,
|
|
|
|
VkImageLayout layout,
|
|
|
|
VkBufferImageCopy *regions, uint32_t numRegions)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdCopyBufferToImage (*cmdBuffer->buffer, src->buffer, dst->image,
|
2020-02-10 11:42:19 +00:00
|
|
|
layout, numRegions, regions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdCopyImageToBuffer (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
struct qfv_image_s *src,
|
|
|
|
VkImageLayout layout,
|
|
|
|
struct qfv_buffer_s *dst,
|
|
|
|
VkBufferImageCopy *regions, uint32_t numRegions)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdCopyImageToBuffer (*cmdBuffer->buffer, src->image, layout,
|
2020-02-10 11:42:19 +00:00
|
|
|
dst->buffer, numRegions, regions);
|
|
|
|
}
|
2020-02-12 09:55:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdBeginRenderPass (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
qfv_renderpass_t *renderPass,
|
|
|
|
qfv_framebuffer_t *framebuffer,
|
|
|
|
VkRect2D renderArea,
|
|
|
|
uint32_t numClearValues,
|
|
|
|
VkClearValue *clearValues,
|
|
|
|
VkSubpassContents subpassContents)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
VkRenderPassBeginInfo beginInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, 0,
|
|
|
|
renderPass->renderPass, framebuffer->framebuffer, renderArea,
|
|
|
|
numClearValues, clearValues,
|
|
|
|
};
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdBeginRenderPass (*cmdBuffer->buffer, &beginInfo,
|
2020-02-12 09:55:51 +00:00
|
|
|
subpassContents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdNextSubpass (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
VkSubpassContents subpassContents)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdNextSubpass (*cmdBuffer->buffer, subpassContents);
|
2020-02-12 09:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdEndRenderPass (qfv_cmdbuffer_t *cmdBuffer)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdEndRenderPass (*cmdBuffer->buffer);
|
2020-02-12 09:55:51 +00:00
|
|
|
}
|
2020-02-12 19:21:35 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
QFV_CmdBindPipeline (qfv_cmdbuffer_t *cmdBuffer,
|
|
|
|
VkPipelineBindPoint bindPoint,
|
|
|
|
qfv_pipeline_t *pipeline)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = cmdBuffer->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2020-02-16 13:43:57 +00:00
|
|
|
dfunc->vkCmdBindPipeline (*cmdBuffer->buffer, bindPoint,
|
|
|
|
pipeline->pipeline);
|
2020-02-12 19:21:35 +00:00
|
|
|
}
|