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/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"
|
|
|
|
|
2020-02-17 11:29:35 +00:00
|
|
|
VkCommandPool
|
2019-07-23 03:28:57 +00:00
|
|
|
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
|
|
|
|
};
|
2020-02-17 11:29:35 +00:00
|
|
|
VkCommandPool pool;
|
|
|
|
dfunc->vkCreateCommandPool (dev, &createInfo, 0, &pool);
|
|
|
|
return pool;
|
2019-07-23 04:05:32 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 13:45:49 +00:00
|
|
|
int
|
2020-02-17 11:29:35 +00:00
|
|
|
QFV_AllocateCommandBuffers (qfv_device_t *device, VkCommandPool pool,
|
2021-01-15 13:45:49 +00:00
|
|
|
int secondary, qfv_cmdbufferset_t *bufferset)
|
2019-07-23 03:28:57 +00:00
|
|
|
{
|
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
|
|
|
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,
|
2021-01-15 13:45:49 +00:00
|
|
|
pool, level, bufferset->size
|
2019-07-23 03:28:57 +00:00
|
|
|
};
|
2021-01-15 13:45:49 +00:00
|
|
|
int ret = dfunc->vkAllocateCommandBuffers (dev, &allocInfo, bufferset->a);
|
|
|
|
return ret == VK_SUCCESS;
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 11:29:35 +00:00
|
|
|
VkSemaphore
|
2019-07-23 03:28:57 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2020-02-17 11:29:35 +00:00
|
|
|
VkSemaphore semaphore;
|
|
|
|
dfunc->vkCreateSemaphore (dev, &createInfo, 0, &semaphore);
|
2019-07-23 03:28:57 +00:00
|
|
|
return semaphore;
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:29:35 +00:00
|
|
|
VkFence
|
2019-07-23 03:28:57 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2020-02-17 11:29:35 +00:00
|
|
|
VkFence fence;
|
|
|
|
dfunc->vkCreateFence (dev, &createInfo, 0, &fence);
|
2019-07-23 03:28:57 +00:00
|
|
|
return fence;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-07-23 03:37:47 +00:00
|
|
|
QFV_QueueSubmit (qfv_queue_t *queue, qfv_semaphoreset_t *waitSemaphores,
|
2020-02-17 11:29:35 +00:00
|
|
|
VkPipelineStageFlags *stages,
|
2019-07-23 03:28:57 +00:00
|
|
|
qfv_cmdbufferset_t *buffers,
|
2020-02-17 11:29:35 +00:00
|
|
|
qfv_semaphoreset_t *signalSemaphores, VkFence fence)
|
2019-07-23 03:28:57 +00:00
|
|
|
{
|
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,
|
2020-02-17 11:29:35 +00:00
|
|
|
waitSemaphores->size, waitSemaphores->a, stages,
|
|
|
|
buffers->size, buffers->a,
|
|
|
|
signalSemaphores->size, signalSemaphores->a
|
2019-07-23 03:28:57 +00:00
|
|
|
};
|
|
|
|
//FIXME multi-batch
|
2020-02-17 11:29:35 +00:00
|
|
|
return dfunc->vkQueueSubmit (queue->queue, 1, &submitInfo, fence)
|
|
|
|
== VK_SUCCESS;
|
2019-07-23 03:28:57 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|