2019-07-06 05:42:53 +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"
|
2019-07-10 15:58:14 +00:00
|
|
|
#include "QF/mathlib.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#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"
|
2019-07-12 04:15:25 +00:00
|
|
|
#include "QF/Vulkan/device.h"
|
|
|
|
#include "QF/Vulkan/instance.h"
|
2019-07-12 05:09:12 +00:00
|
|
|
#include "QF/Vulkan/swapchain.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "d_iface.h"
|
|
|
|
#include "r_internal.h"
|
2019-07-08 16:00:47 +00:00
|
|
|
#include "vid_vulkan.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2019-07-09 07:33:44 +00:00
|
|
|
#include "util.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2019-07-12 04:15:25 +00:00
|
|
|
cvar_t *vulkan_presentation_mode;
|
2019-07-10 15:58:14 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_presentation_mode_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
if (!strcmp (var->string, "immediate")) {
|
|
|
|
var->int_val = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
|
|
|
} else if (!strcmp (var->string, "fifo")) {
|
|
|
|
var->int_val = VK_PRESENT_MODE_FIFO_KHR;
|
|
|
|
} else if (!strcmp (var->string, "relaxed")) {
|
|
|
|
var->int_val = VK_PRESENT_MODE_FIFO_RELAXED_KHR;
|
|
|
|
} else if (!strcmp (var->string, "mailbox")) {
|
|
|
|
var->int_val = VK_PRESENT_MODE_MAILBOX_KHR;
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("Invalid presentation mode, using fifo\n");
|
|
|
|
var->int_val = VK_PRESENT_MODE_FIFO_KHR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 04:15:25 +00:00
|
|
|
static void
|
|
|
|
Vulkan_Init_Cvars (void)
|
2019-07-06 05:42:53 +00:00
|
|
|
{
|
|
|
|
vulkan_use_validation = Cvar_Get ("vulkan_use_validation", "1", CVAR_NONE,
|
|
|
|
0,
|
|
|
|
"enable LunarG Standard Validation "
|
|
|
|
"Layer if available (requires instance "
|
|
|
|
"restart).");
|
2019-07-10 15:58:14 +00:00
|
|
|
// FIXME implement fallback choices (instead of just fifo)
|
|
|
|
vulkan_presentation_mode = Cvar_Get ("vulkan_presentation_mode", "mailbox",
|
|
|
|
CVAR_NONE, vulkan_presentation_mode_f,
|
|
|
|
"desired presentation mode (may fall "
|
|
|
|
"back to fifo).");
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 16:28:05 +00:00
|
|
|
static const char *instance_extensions[] = {
|
2019-07-07 07:27:55 +00:00
|
|
|
VK_KHR_SURFACE_EXTENSION_NAME,
|
2019-07-06 05:42:53 +00:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2019-07-06 16:28:05 +00:00
|
|
|
static const char *device_extensions[] = {
|
2019-07-09 07:33:44 +00:00
|
|
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
2019-07-06 16:28:05 +00:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2019-07-09 07:33:44 +00:00
|
|
|
void
|
|
|
|
Vulkan_Init_Common (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
Sys_Printf ("Vulkan_Init_Common\n");
|
|
|
|
Vulkan_Init_Cvars ();
|
|
|
|
|
2019-07-12 04:15:25 +00:00
|
|
|
ctx->instance = QFV_CreateInstance (ctx, PACKAGE_STRING, 0x000702ff, 0, instance_extensions);//FIXME version
|
2019-07-09 07:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
|
2019-07-06 16:28:05 +00:00
|
|
|
{
|
2019-07-12 16:14:21 +00:00
|
|
|
if (ctx->swapchain) {
|
|
|
|
QFV_DestroySwapchain (ctx->swapchain);
|
|
|
|
}
|
2019-07-12 16:20:02 +00:00
|
|
|
ctx->instance->funcs->vkDestroySurfaceKHR (ctx->instance->instance,
|
|
|
|
ctx->surface, 0);
|
2019-07-12 16:14:21 +00:00
|
|
|
if (ctx->device) {
|
|
|
|
QFV_DestroyDevice (ctx->device);
|
|
|
|
}
|
|
|
|
if (ctx->instance) {
|
|
|
|
QFV_DestroyInstance (ctx->instance);
|
|
|
|
}
|
2019-07-12 04:15:25 +00:00
|
|
|
ctx->instance = 0;
|
2019-07-09 07:33:44 +00:00
|
|
|
ctx->unload_vulkan (ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_CreateDevice (vulkan_ctx_t *ctx)
|
|
|
|
{
|
2019-07-12 04:15:25 +00:00
|
|
|
ctx->device = QFV_CreateDevice (ctx, device_extensions);
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
2019-07-10 15:58:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_CreateSwapchain (vulkan_ctx_t *ctx)
|
|
|
|
{
|
2019-07-12 05:09:12 +00:00
|
|
|
VkSwapchainKHR old_swapchain = 0;
|
|
|
|
if (ctx->swapchain) {
|
|
|
|
old_swapchain = ctx->swapchain->swapchain;
|
|
|
|
free (ctx->swapchain);
|
|
|
|
}
|
|
|
|
ctx->swapchain = QFV_CreateSwapchain (ctx, old_swapchain);
|
|
|
|
if (ctx->swapchain->swapchain == old_swapchain) {
|
|
|
|
ctx->device->funcs->vkDestroySwapchainKHR (ctx->device->dev,
|
|
|
|
old_swapchain, 0);
|
|
|
|
}
|
2019-07-10 15:58:14 +00:00
|
|
|
}
|