2019-07-06 05:42:53 +00:00
|
|
|
/*
|
|
|
|
vid_common_vulkan.c
|
|
|
|
|
|
|
|
Common Vulkan video driver functions
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-12-21 09:38:31 +00:00
|
|
|
#include "QF/cexpr.h"
|
|
|
|
#include "QF/cmem.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/dstring.h"
|
2021-01-05 08:48:00 +00:00
|
|
|
#include "QF/hash.h"
|
2019-07-10 15:58:14 +00:00
|
|
|
#include "QF/mathlib.h"
|
2021-03-21 07:13:03 +00:00
|
|
|
#include "QF/plist.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"
|
2021-12-08 06:28:21 +00:00
|
|
|
#include "QF/Vulkan/qf_matrices.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
2021-01-10 16:24:15 +00:00
|
|
|
#include "QF/Vulkan/barrier.h"
|
2021-01-12 02:27:41 +00:00
|
|
|
#include "QF/Vulkan/buffer.h"
|
2021-03-24 10:20:53 +00:00
|
|
|
#include "QF/Vulkan/capture.h"
|
2021-01-31 10:58:55 +00:00
|
|
|
#include "QF/Vulkan/debug.h"
|
2021-01-04 08:36:11 +00:00
|
|
|
#include "QF/Vulkan/descriptor.h"
|
2019-07-12 04:15:25 +00:00
|
|
|
#include "QF/Vulkan/device.h"
|
2020-02-18 08:18:37 +00:00
|
|
|
#include "QF/Vulkan/command.h"
|
2019-07-12 04:15:25 +00:00
|
|
|
#include "QF/Vulkan/instance.h"
|
2020-02-18 05:28:28 +00:00
|
|
|
#include "QF/Vulkan/image.h"
|
2021-01-05 14:54:22 +00:00
|
|
|
#include "QF/Vulkan/pipeline.h"
|
2020-02-18 08:18:37 +00:00
|
|
|
#include "QF/Vulkan/renderpass.h"
|
2020-12-23 16:36:17 +00:00
|
|
|
#include "QF/Vulkan/shader.h"
|
2021-01-10 16:24:15 +00:00
|
|
|
#include "QF/Vulkan/staging.h"
|
2019-07-12 05:09:12 +00:00
|
|
|
#include "QF/Vulkan/swapchain.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
#include "QF/Vulkan/qf_alias.h"
|
|
|
|
#include "QF/Vulkan/qf_bsp.h"
|
|
|
|
#include "QF/Vulkan/qf_compose.h"
|
|
|
|
#include "QF/Vulkan/qf_draw.h"
|
|
|
|
#include "QF/Vulkan/qf_lighting.h"
|
|
|
|
#include "QF/Vulkan/qf_main.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"
|
2020-12-21 09:38:31 +00:00
|
|
|
#include "vkparse.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
#include "libs/video/renderer/vulkan/vkparse.hinc"
|
|
|
|
|
2020-07-16 06:42:49 +00:00
|
|
|
static const char quakeforge_pipeline[] =
|
|
|
|
#include "libs/video/renderer/vulkan/qfpipeline.plc"
|
|
|
|
;
|
|
|
|
|
2021-02-14 02:35:06 +00:00
|
|
|
static const char quakeforge_renderpass[] =
|
|
|
|
#include "libs/video/renderer/vulkan/deferred.plc"
|
|
|
|
;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int vulkan_frame_count;
|
|
|
|
static cvar_t vulkan_frame_count_cvar = {
|
|
|
|
.name = "vulkan_frame_count",
|
|
|
|
.description =
|
|
|
|
"Number of frames to render in the background. More frames can "
|
|
|
|
"increase performance, but at the cost of latency. The default of 3 is"
|
|
|
|
" recommended.",
|
|
|
|
.default_value = "3",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vulkan_frame_count },
|
|
|
|
};
|
|
|
|
int vulkan_presentation_mode;
|
|
|
|
static cvar_t vulkan_presentation_mode_cvar = {
|
|
|
|
.name = "vulkan_presentation_mode",
|
|
|
|
.description =
|
|
|
|
"desired presentation mode (may fall back to fifo).",
|
|
|
|
.default_value = "mailbox",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = {
|
|
|
|
.type = &VkPresentModeKHR_type,
|
|
|
|
.value = &vulkan_presentation_mode,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
int msaaSamples;
|
|
|
|
static cvar_t msaaSamples_cvar = {
|
|
|
|
.name = "msaaSamples",
|
|
|
|
.description =
|
|
|
|
"desired MSAA sample size.",
|
|
|
|
.default_value = "VK_SAMPLE_COUNT_1_BIT",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &VkSampleCountFlagBits_type, .value = &msaaSamples },
|
|
|
|
};
|
|
|
|
static exprenum_t validation_enum;
|
|
|
|
static exprtype_t validation_type = {
|
|
|
|
.name = "vulkan_use_validation",
|
|
|
|
.size = sizeof (int),
|
|
|
|
.binops = cexpr_flag_binops,
|
|
|
|
.unops = cexpr_flag_unops,
|
|
|
|
.data = &validation_enum,
|
|
|
|
.get_string = cexpr_flags_get_string,
|
|
|
|
};
|
2021-11-29 04:43:07 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static int validation_values[] = {
|
|
|
|
0,
|
|
|
|
VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT,
|
|
|
|
};
|
|
|
|
static exprsym_t validation_symbols[] = {
|
|
|
|
{"none", &validation_type, validation_values + 0},
|
|
|
|
{"all", &validation_type, validation_values + 1},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
static exprtab_t validation_symtab = {
|
|
|
|
validation_symbols,
|
|
|
|
};
|
|
|
|
static exprenum_t validation_enum = {
|
|
|
|
&validation_type,
|
|
|
|
&validation_symtab,
|
|
|
|
};
|
|
|
|
static cvar_t vulkan_use_validation_cvar = {
|
|
|
|
.name = "vulkan_use_validation",
|
|
|
|
.description =
|
|
|
|
"enable KRONOS Validation Layer if available (requires instance "
|
|
|
|
"restart).",
|
|
|
|
.default_value = "error|warning",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &validation_type, .value = &vulkan_use_validation },
|
|
|
|
};
|
2021-11-29 04:43:07 +00:00
|
|
|
|
2019-07-10 15:58:14 +00:00
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
vulkan_frame_count_f (void *data, const cvar_t *cvar)
|
2019-07-10 15:58:14 +00:00
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (vulkan_frame_count < 1) {
|
|
|
|
Sys_Printf ("Invalid frame count: %d. Setting to 1\n",
|
|
|
|
vulkan_frame_count);
|
|
|
|
vulkan_frame_count = 1;
|
2019-07-10 15:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 04:44:10 +00:00
|
|
|
static void
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Vulkan_Init_Cvars (void)
|
2021-11-29 04:44:10 +00:00
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int num_syms = 0;
|
|
|
|
for (exprsym_t *sym = VkDebugUtilsMessageSeverityFlagBitsEXT_symbols;
|
|
|
|
sym->name; sym++, num_syms++) {
|
2021-11-29 04:44:10 +00:00
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
for (exprsym_t *sym = validation_symbols; sym->name; sym++, num_syms++) {
|
2021-02-05 02:06:18 +00:00
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
validation_symtab.symbols = calloc (num_syms + 1, sizeof (exprsym_t));
|
|
|
|
num_syms = 0;
|
|
|
|
for (exprsym_t *sym = VkDebugUtilsMessageSeverityFlagBitsEXT_symbols;
|
|
|
|
sym->name; sym++, num_syms++) {
|
|
|
|
validation_symtab.symbols[num_syms] = *sym;
|
|
|
|
validation_symtab.symbols[num_syms].type = &validation_type;
|
|
|
|
}
|
|
|
|
for (exprsym_t *sym = validation_symbols; sym->name; sym++, num_syms++) {
|
|
|
|
validation_symtab.symbols[num_syms] = *sym;
|
|
|
|
}
|
|
|
|
Cvar_Register (&vulkan_use_validation_cvar, 0, 0);
|
2019-07-10 15:58:14 +00:00
|
|
|
// FIXME implement fallback choices (instead of just fifo)
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&vulkan_presentation_mode_cvar, 0, 0);
|
|
|
|
Cvar_Register (&vulkan_frame_count_cvar, vulkan_frame_count_f, 0);
|
|
|
|
Cvar_Register (&msaaSamples_cvar, 0, 0);
|
2021-01-12 02:27:41 +00:00
|
|
|
R_Init_Cvars ();
|
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,
|
2021-01-21 03:39:08 +00:00
|
|
|
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_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)
|
|
|
|
{
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan, "Vulkan_Init_Common\n");
|
2021-02-14 02:35:06 +00:00
|
|
|
|
2021-01-05 10:55:17 +00:00
|
|
|
QFV_InitParse (ctx);
|
2019-07-09 07:33:44 +00:00
|
|
|
Vulkan_Init_Cvars ();
|
2021-03-23 04:04:22 +00:00
|
|
|
ctx->instance = QFV_CreateInstance (ctx, PACKAGE_STRING, 0x000702ff, 0,
|
|
|
|
instance_extensions);//FIXME version
|
2021-12-19 00:14:11 +00:00
|
|
|
DARRAY_INIT (&ctx->renderPasses, 4);
|
2019-07-09 07:33:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 08:48:00 +00:00
|
|
|
static void
|
|
|
|
clear_table (hashtab_t **table)
|
|
|
|
{
|
|
|
|
if (*table) {
|
2021-01-05 10:55:17 +00:00
|
|
|
hashtab_t *tab = *table;
|
2021-01-05 08:48:00 +00:00
|
|
|
*table = 0;
|
2021-01-05 10:55:17 +00:00
|
|
|
Hash_DelTable (tab);
|
2021-01-05 08:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 07:33:44 +00:00
|
|
|
void
|
|
|
|
Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
|
2019-07-06 16:28:05 +00:00
|
|
|
{
|
2021-03-21 10:56:17 +00:00
|
|
|
PL_Free (ctx->pipelineDef);
|
2021-03-24 10:20:53 +00:00
|
|
|
if (ctx->capture) {
|
|
|
|
QFV_DestroyCapture (ctx->capture);
|
|
|
|
}
|
2021-02-05 01:22:32 +00:00
|
|
|
if (ctx->frames.size) {
|
2021-02-14 02:35:06 +00:00
|
|
|
Vulkan_DestroyFrames (ctx);
|
2020-02-18 08:18:37 +00:00
|
|
|
}
|
2019-07-12 16:14:21 +00:00
|
|
|
if (ctx->swapchain) {
|
|
|
|
QFV_DestroySwapchain (ctx->swapchain);
|
|
|
|
}
|
2021-01-16 05:37:16 +00:00
|
|
|
QFV_DestroyStagingBuffer (ctx->staging);
|
2021-01-05 10:55:17 +00:00
|
|
|
ctx->instance->funcs->vkDestroySurfaceKHR (ctx->instance->instance,
|
|
|
|
ctx->surface, 0);
|
2021-01-05 08:48:00 +00:00
|
|
|
clear_table (&ctx->pipelineLayouts);
|
|
|
|
clear_table (&ctx->setLayouts);
|
|
|
|
clear_table (&ctx->shaderModules);
|
2021-01-10 06:50:24 +00:00
|
|
|
clear_table (&ctx->descriptorPools);
|
|
|
|
clear_table (&ctx->samplers);
|
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);
|
2021-02-14 02:35:06 +00:00
|
|
|
|
|
|
|
//FIXME msaa and deferred rendering...
|
|
|
|
//also, location
|
|
|
|
ctx->msaaSamples = 1;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
/*ctx->msaaSamples = min ((VkSampleCountFlagBits) msaaSamples,
|
2021-02-14 02:35:06 +00:00
|
|
|
QFV_GetMaxSampleCount (device->physDev));
|
|
|
|
if (ctx->msaaSamples > 1) {
|
|
|
|
name = "renderpass_msaa";
|
|
|
|
}*/
|
2019-07-06 05:42:53 +00:00
|
|
|
}
|
2019-07-10 15:58:14 +00:00
|
|
|
|
2021-01-10 16:24:15 +00:00
|
|
|
void
|
|
|
|
Vulkan_CreateStagingBuffers (vulkan_ctx_t *ctx)
|
|
|
|
{
|
2021-08-02 06:12:29 +00:00
|
|
|
// FIXME configurable?
|
2021-01-31 10:58:55 +00:00
|
|
|
ctx->staging = QFV_CreateStagingBuffer (ctx->device, "vulkan_ctx",
|
2021-08-02 06:12:29 +00:00
|
|
|
32*1024*1024, ctx->cmdpool);
|
2021-01-10 16:24:15 +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);
|
2021-03-24 03:04:09 +00:00
|
|
|
if (old_swapchain && ctx->swapchain->swapchain != old_swapchain) {
|
2019-07-12 05:09:12 +00:00
|
|
|
ctx->device->funcs->vkDestroySwapchainKHR (ctx->device->dev,
|
|
|
|
old_swapchain, 0);
|
|
|
|
}
|
2019-07-10 15:58:14 +00:00
|
|
|
}
|
2020-02-18 05:28:28 +00:00
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
static plitem_t *
|
|
|
|
qfv_load_pipeline (vulkan_ctx_t *ctx, const char *name)
|
2020-07-16 06:42:49 +00:00
|
|
|
{
|
2021-01-05 08:45:02 +00:00
|
|
|
if (!ctx->pipelineDef) {
|
2021-02-09 00:57:07 +00:00
|
|
|
ctx->pipelineDef = PL_GetPropertyList (quakeforge_pipeline,
|
|
|
|
&ctx->hashlinks);
|
2020-12-23 16:36:17 +00:00
|
|
|
}
|
2021-02-04 08:03:49 +00:00
|
|
|
|
|
|
|
plitem_t *item = ctx->pipelineDef;
|
|
|
|
if (!item || !(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading %s\n", name);
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found %s def\n", name);
|
2021-02-04 08:03:49 +00:00
|
|
|
}
|
|
|
|
return item;
|
2020-07-16 06:42:49 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 02:35:06 +00:00
|
|
|
static plitem_t *
|
2021-12-02 12:58:29 +00:00
|
|
|
qfv_load_renderpass (vulkan_ctx_t *ctx, qfv_renderpass_t *rp, const char *name)
|
2020-02-18 05:28:28 +00:00
|
|
|
{
|
2021-12-02 12:58:29 +00:00
|
|
|
if (!rp->renderpassDef) {
|
|
|
|
rp->renderpassDef = PL_GetPropertyList (quakeforge_renderpass,
|
|
|
|
&ctx->hashlinks);
|
2021-02-02 15:08:33 +00:00
|
|
|
}
|
2020-07-16 06:42:49 +00:00
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
plitem_t *item = rp->renderpassDef;
|
2021-02-14 02:35:06 +00:00
|
|
|
if (!item || !(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading %s\n", name);
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found %s def\n", name);
|
2020-07-16 06:42:49 +00:00
|
|
|
}
|
2021-02-14 02:35:06 +00:00
|
|
|
return item;
|
|
|
|
}
|
2020-02-18 05:28:28 +00:00
|
|
|
|
2021-02-14 02:35:06 +00:00
|
|
|
static size_t
|
|
|
|
get_image_size (VkImage image, qfv_device_t *device)
|
|
|
|
{
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
size_t size;
|
|
|
|
size_t align;
|
|
|
|
|
|
|
|
VkMemoryRequirements requirements;
|
|
|
|
dfunc->vkGetImageMemoryRequirements (device->dev, image, &requirements);
|
|
|
|
size = requirements.size;
|
|
|
|
align = requirements.alignment - 1;
|
|
|
|
size = (size + align) & ~(align);
|
|
|
|
return size;
|
2020-02-18 05:28:28 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
static void
|
|
|
|
renderpass_draw (qfv_renderframe_t *rFrame)
|
|
|
|
{
|
2021-12-08 06:28:21 +00:00
|
|
|
Vulkan_Matrix_Draw (rFrame);
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_RenderView (rFrame);
|
2022-03-07 14:32:44 +00:00
|
|
|
Vulkan_FlushText (rFrame);//FIXME delayed by a frame?
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_Lighting_Draw (rFrame);
|
|
|
|
Vulkan_Compose_Draw (rFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_attachements (vulkan_ctx_t *ctx, qfv_renderpass_t *rp)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
|
|
|
|
plitem_t *item = qfv_load_renderpass (ctx, rp, "images");
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
__auto_type images = QFV_ParseImageSet (ctx, item, rp->renderpassDef);
|
|
|
|
rp->attachment_images = images;
|
|
|
|
size_t memSize = 0;
|
|
|
|
for (size_t i = 0; i < images->size; i++) {
|
|
|
|
memSize += get_image_size (images->a[i], device);
|
|
|
|
}
|
|
|
|
VkDeviceMemory mem;
|
|
|
|
mem = QFV_AllocImageMemory (device, images->a[0],
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
|
|
|
memSize, 0);
|
|
|
|
rp->attachmentMemory = mem;
|
|
|
|
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DEVICE_MEMORY,
|
|
|
|
mem, "memory:framebuffers");
|
|
|
|
size_t offset = 0;
|
|
|
|
for (size_t i = 0; i < images->size; i++) {
|
|
|
|
QFV_BindImageMemory (device, images->a[i], mem, offset);
|
|
|
|
offset += get_image_size (images->a[i], device);
|
|
|
|
}
|
|
|
|
|
|
|
|
item = qfv_load_renderpass (ctx, rp, "imageViews");
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
__auto_type views = QFV_ParseImageViewSet (ctx, item, rp->renderpassDef);
|
|
|
|
rp->attachment_views = views;
|
|
|
|
|
|
|
|
item = qfv_load_renderpass (ctx, rp, "framebuffer");
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rp->framebuffers = QFV_AllocFrameBuffers (ctx->swapchain->numImages,
|
|
|
|
malloc);
|
|
|
|
for (size_t i = 0; i < rp->framebuffers->size; i++) {
|
2022-04-02 02:42:36 +00:00
|
|
|
ctx->output = (qfv_output_t) {
|
|
|
|
.extent = ctx->swapchain->extent,
|
|
|
|
.view = ctx->swapchain->imageViews->a[i],
|
|
|
|
.format = ctx->swapchain->format,
|
|
|
|
};
|
2021-12-02 12:58:29 +00:00
|
|
|
rp->framebuffers->a[i] = QFV_ParseFramebuffer (ctx, item,
|
|
|
|
rp->renderpassDef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_renderframe (vulkan_ctx_t *ctx, qfv_renderpass_t *rp,
|
|
|
|
qfv_renderframe_t *rFrame)
|
|
|
|
{
|
|
|
|
rFrame->subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS;
|
|
|
|
rFrame->vulkan_ctx = ctx;
|
|
|
|
rFrame->renderpass = rp;
|
|
|
|
rFrame->subpassCount = QFV_NumPasses;
|
|
|
|
rFrame->subpassCmdSets = malloc (QFV_NumPasses
|
|
|
|
* sizeof (qfv_cmdbufferset_t));
|
|
|
|
for (int j = 0; j < QFV_NumPasses; j++) {
|
|
|
|
DARRAY_INIT (&rFrame->subpassCmdSets[j], 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 05:28:28 +00:00
|
|
|
void
|
2021-02-14 02:35:06 +00:00
|
|
|
Vulkan_CreateRenderPass (vulkan_ctx_t *ctx)
|
2020-02-18 05:28:28 +00:00
|
|
|
{
|
2021-02-14 02:35:06 +00:00
|
|
|
const char *name = "renderpass";//FIXME
|
2021-12-02 12:58:29 +00:00
|
|
|
plitem_t *item;
|
|
|
|
|
|
|
|
qfv_renderpass_t *rp = calloc (1, sizeof (qfv_renderpass_t));
|
2020-02-18 05:28:28 +00:00
|
|
|
|
2021-02-23 05:37:48 +00:00
|
|
|
hashtab_t *tab = ctx->renderpasses;
|
|
|
|
const char *path;
|
|
|
|
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".%s", name);
|
|
|
|
__auto_type renderpass = (VkRenderPass) QFV_GetHandle (tab, path);
|
|
|
|
if (renderpass) {
|
2021-12-02 12:58:29 +00:00
|
|
|
rp->renderpass = renderpass;
|
|
|
|
} else {
|
2022-04-02 02:42:36 +00:00
|
|
|
ctx->output = (qfv_output_t) {
|
|
|
|
.extent = ctx->swapchain->extent,
|
|
|
|
.view = ctx->swapchain->imageViews->a[0],
|
|
|
|
.format = ctx->swapchain->format,
|
|
|
|
};
|
2021-12-02 12:58:29 +00:00
|
|
|
item = qfv_load_renderpass (ctx, rp, name);
|
|
|
|
rp->renderpass = QFV_ParseRenderPass (ctx, item, rp->renderpassDef);
|
|
|
|
QFV_AddHandle (tab, path, (uint64_t) rp->renderpass);
|
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_RENDER_PASS,
|
|
|
|
rp->renderpass, va (ctx->va_ctx, "renderpass:%s",
|
|
|
|
name));
|
2021-02-23 05:37:48 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
DARRAY_INIT (&rp->frames, 4);
|
|
|
|
DARRAY_RESIZE (&rp->frames, ctx->frames.size);
|
|
|
|
for (size_t i = 0; i < rp->frames.size; i++) {
|
|
|
|
init_renderframe (ctx, rp, &rp->frames.a[i]);
|
|
|
|
}
|
2020-02-18 08:18:37 +00:00
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
create_attachements (ctx, rp);
|
|
|
|
|
|
|
|
item = qfv_load_renderpass (ctx, rp, "clearValues");
|
|
|
|
rp->clearValues = QFV_ParseClearValues (ctx, item, rp->renderpassDef);
|
|
|
|
|
|
|
|
rp->draw = renderpass_draw;
|
|
|
|
|
|
|
|
DARRAY_APPEND (&ctx->renderPasses, rp);
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
static float quad_vertices[] = {
|
|
|
|
-1, -1, 0, 1,
|
|
|
|
-1, 1, 0, 1,
|
|
|
|
1, -1, 0, 1,
|
|
|
|
1, 1, 0, 1,
|
|
|
|
};
|
|
|
|
ctx->quad_buffer = QFV_CreateBuffer (device, sizeof (quad_vertices),
|
|
|
|
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
|
|
|
ctx->quad_memory = QFV_AllocBufferMemory (device, ctx->quad_buffer,
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
|
|
|
0, 0);
|
|
|
|
QFV_BindBufferMemory (device, ctx->quad_buffer, ctx->quad_memory, 0);
|
|
|
|
|
|
|
|
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
|
|
|
float *verts = QFV_PacketExtend (packet, sizeof (quad_vertices));
|
|
|
|
memcpy (verts, quad_vertices, sizeof (quad_vertices));
|
|
|
|
|
2021-04-24 06:47:31 +00:00
|
|
|
qfv_bufferbarrier_t bb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
|
|
|
bb.barrier.buffer = ctx->quad_buffer;
|
|
|
|
bb.barrier.size = sizeof (quad_vertices);
|
|
|
|
dfunc->vkCmdPipelineBarrier (packet->cmd, bb.srcStages, bb.dstStages,
|
|
|
|
0, 0, 0, 1, &bb.barrier, 0, 0);
|
2021-02-24 10:58:31 +00:00
|
|
|
VkBufferCopy copy_region[] = {
|
|
|
|
{ packet->offset, 0, sizeof (quad_vertices) },
|
|
|
|
};
|
|
|
|
dfunc->vkCmdCopyBuffer (packet->cmd, ctx->staging->buffer,
|
|
|
|
ctx->quad_buffer, 1, ©_region[0]);
|
2021-04-24 06:47:31 +00:00
|
|
|
bb = bufferBarriers[qfv_BB_TransferWrite_to_VertexAttrRead];
|
|
|
|
bb.barrier.buffer = ctx->quad_buffer;
|
|
|
|
bb.barrier.size = sizeof (quad_vertices);
|
|
|
|
dfunc->vkCmdPipelineBarrier (packet->cmd, bb.srcStages, bb.dstStages,
|
|
|
|
0, 0, 0, 1, &bb.barrier, 0, 0);
|
2021-02-24 10:58:31 +00:00
|
|
|
QFV_PacketSubmit (packet);
|
2021-02-14 02:35:06 +00:00
|
|
|
}
|
2020-02-18 05:28:28 +00:00
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
static void
|
|
|
|
destroy_attachments (vulkan_ctx_t *ctx, qfv_renderpass_t *rp)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < rp->attachment_views->size; i++) {
|
|
|
|
dfunc->vkDestroyImageView (device->dev, rp->attachment_views->a[i], 0);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < rp->attachment_images->size; i++) {
|
|
|
|
dfunc->vkDestroyImage (device->dev, rp->attachment_images->a[i], 0);
|
|
|
|
}
|
|
|
|
dfunc->vkFreeMemory (device->dev, rp->attachmentMemory, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_renderframes (vulkan_ctx_t *ctx, qfv_renderpass_t *rp)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < rp->frames.size; i++) {
|
|
|
|
__auto_type rFrame = &rp->frames.a[i];
|
|
|
|
for (int j = 0; j < rFrame->subpassCount; j++) {
|
|
|
|
DARRAY_CLEAR (&rFrame->subpassCmdSets[j]);
|
|
|
|
}
|
|
|
|
free (rFrame->subpassCmdSets);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_framebuffers (vulkan_ctx_t *ctx, qfv_renderpass_t *rp)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < rp->framebuffers->size; i++) {
|
|
|
|
dfunc->vkDestroyFramebuffer (device->dev, rp->framebuffers->a[i], 0);
|
|
|
|
}
|
|
|
|
free (rp->framebuffers);
|
|
|
|
}
|
|
|
|
|
2021-02-14 02:35:06 +00:00
|
|
|
void
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_DestroyRenderPasses (vulkan_ctx_t *ctx)
|
2021-02-14 02:35:06 +00:00
|
|
|
{
|
2021-02-24 07:27:56 +00:00
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
for (size_t i = 0; i < ctx->renderPasses.size; i++) {
|
|
|
|
__auto_type rp = ctx->renderPasses.a[i];
|
|
|
|
|
|
|
|
PL_Free (rp->renderpassDef);
|
|
|
|
|
|
|
|
destroy_attachments (ctx, rp);
|
|
|
|
dfunc->vkDestroyRenderPass (device->dev, rp->renderpass, 0);
|
|
|
|
destroy_renderframes (ctx, rp);
|
|
|
|
destroy_framebuffers (ctx, rp);
|
|
|
|
|
|
|
|
free (rp);
|
|
|
|
}
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
dfunc->vkFreeMemory (device->dev, ctx->quad_memory, 0);
|
|
|
|
dfunc->vkDestroyBuffer (device->dev, ctx->quad_buffer, 0);
|
2020-02-18 05:28:28 +00:00
|
|
|
}
|
2020-02-18 08:18:37 +00:00
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
VkPipeline
|
2021-12-16 14:00:17 +00:00
|
|
|
Vulkan_CreateComputePipeline (vulkan_ctx_t *ctx, const char *name)
|
2020-12-23 16:36:17 +00:00
|
|
|
{
|
2021-02-04 08:03:49 +00:00
|
|
|
plitem_t *item = qfv_load_pipeline (ctx, "pipelines");
|
2021-01-10 06:52:27 +00:00
|
|
|
if (!(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading pipeline %s\n", name);
|
|
|
|
return 0;
|
2021-01-05 14:42:30 +00:00
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline def %s\n", name);
|
2021-01-05 14:42:30 +00:00
|
|
|
}
|
2021-12-16 14:00:17 +00:00
|
|
|
VkPipeline pipeline = QFV_ParseComputePipeline (ctx, item,
|
|
|
|
ctx->pipelineDef);
|
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE, pipeline,
|
|
|
|
va (ctx->va_ctx, "pipeline:%s", name));
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPipeline
|
|
|
|
Vulkan_CreateGraphicsPipeline (vulkan_ctx_t *ctx, const char *name)
|
|
|
|
{
|
|
|
|
plitem_t *item = qfv_load_pipeline (ctx, "pipelines");
|
|
|
|
if (!(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading pipeline %s\n", name);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline def %s\n", name);
|
|
|
|
}
|
|
|
|
VkPipeline pipeline = QFV_ParseGraphicsPipeline (ctx, item,
|
|
|
|
ctx->pipelineDef);
|
2021-01-31 10:58:55 +00:00
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE, pipeline,
|
|
|
|
va (ctx->va_ctx, "pipeline:%s", name));
|
|
|
|
return pipeline;
|
2020-12-23 16:36:17 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
VkDescriptorPool
|
|
|
|
Vulkan_CreateDescriptorPool (vulkan_ctx_t *ctx, const char *name)
|
|
|
|
{
|
2021-02-04 11:40:28 +00:00
|
|
|
hashtab_t *tab = ctx->descriptorPools;
|
|
|
|
const char *path;
|
|
|
|
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".descriptorPools.%s", name);
|
|
|
|
__auto_type pool = (VkDescriptorPool) QFV_GetHandle (tab, path);
|
|
|
|
if (pool) {
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
plitem_t *item = qfv_load_pipeline (ctx, "descriptorPools");
|
|
|
|
if (!(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading descriptor pool %s\n", name);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found descriptor pool def %s\n",
|
2021-03-23 04:04:22 +00:00
|
|
|
name);
|
2021-02-04 08:03:49 +00:00
|
|
|
}
|
2021-02-14 02:35:06 +00:00
|
|
|
pool = QFV_ParseDescriptorPool (ctx, item, ctx->pipelineDef);
|
2021-02-04 11:40:28 +00:00
|
|
|
QFV_AddHandle (tab, path, (uint64_t) pool);
|
2021-02-04 08:03:49 +00:00
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool,
|
|
|
|
va (ctx->va_ctx, "descriptor_pool:%s", name));
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPipelineLayout
|
|
|
|
Vulkan_CreatePipelineLayout (vulkan_ctx_t *ctx, const char *name)
|
|
|
|
{
|
2021-02-04 11:40:28 +00:00
|
|
|
hashtab_t *tab = ctx->pipelineLayouts;
|
|
|
|
const char *path;
|
|
|
|
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".pipelineLayouts.%s", name);
|
|
|
|
__auto_type layout = (VkPipelineLayout) QFV_GetHandle (tab, path);
|
|
|
|
if (layout) {
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
plitem_t *item = qfv_load_pipeline (ctx, "pipelineLayouts");
|
|
|
|
if (!(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading pipeline layout %s\n", name);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found pipeline layout def %s\n",
|
2021-03-23 04:04:22 +00:00
|
|
|
name);
|
2021-02-04 08:03:49 +00:00
|
|
|
}
|
2021-02-14 02:35:06 +00:00
|
|
|
layout = QFV_ParsePipelineLayout (ctx, item, ctx->pipelineDef);
|
2021-02-04 11:40:28 +00:00
|
|
|
QFV_AddHandle (tab, path, (uint64_t) layout);
|
2021-02-04 08:03:49 +00:00
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_PIPELINE_LAYOUT, layout,
|
|
|
|
va (ctx->va_ctx, "pipeline_layout:%s", name));
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkSampler
|
|
|
|
Vulkan_CreateSampler (vulkan_ctx_t *ctx, const char *name)
|
|
|
|
{
|
2021-02-04 11:40:28 +00:00
|
|
|
hashtab_t *tab = ctx->samplers;
|
|
|
|
const char *path;
|
|
|
|
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".samplers.%s", name);
|
|
|
|
__auto_type sampler = (VkSampler) QFV_GetHandle (tab, path);
|
|
|
|
if (sampler) {
|
|
|
|
return sampler;
|
|
|
|
}
|
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
plitem_t *item = qfv_load_pipeline (ctx, "samplers");
|
|
|
|
if (!(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading sampler %s\n", name);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found sampler def %s\n", name);
|
2021-02-04 08:03:49 +00:00
|
|
|
}
|
2021-02-14 02:35:06 +00:00
|
|
|
sampler = QFV_ParseSampler (ctx, item, ctx->pipelineDef);
|
2021-02-04 11:40:28 +00:00
|
|
|
QFV_AddHandle (tab, path, (uint64_t) sampler);
|
2021-02-04 08:03:49 +00:00
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_SAMPLER, sampler,
|
|
|
|
va (ctx->va_ctx, "sampler:%s", name));
|
|
|
|
return sampler;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkDescriptorSetLayout
|
|
|
|
Vulkan_CreateDescriptorSetLayout(vulkan_ctx_t *ctx, const char *name)
|
|
|
|
{
|
2021-02-04 11:40:28 +00:00
|
|
|
hashtab_t *tab = ctx->setLayouts;
|
|
|
|
const char *path;
|
|
|
|
path = va (ctx->va_ctx, "$"QFV_PROPERTIES".setLayouts.%s", name);
|
|
|
|
__auto_type set = (VkDescriptorSetLayout) QFV_GetHandle (tab, path);
|
|
|
|
if (set) {
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2021-02-04 08:03:49 +00:00
|
|
|
plitem_t *item = qfv_load_pipeline (ctx, "setLayouts");
|
|
|
|
if (!(item = PL_ObjectForKey (item, name))) {
|
|
|
|
Sys_Printf ("error loading descriptor set %s\n", name);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan_parse, "Found descriptor set def %s\n",
|
2021-03-23 04:04:22 +00:00
|
|
|
name);
|
2021-02-04 08:03:49 +00:00
|
|
|
}
|
2021-02-14 02:35:06 +00:00
|
|
|
set = QFV_ParseDescriptorSetLayout (ctx, item, ctx->pipelineDef);
|
2021-02-04 11:40:28 +00:00
|
|
|
QFV_AddHandle (tab, path, (uint64_t) set);
|
2021-02-04 08:03:49 +00:00
|
|
|
QFV_duSetObjectName (ctx->device, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT,
|
|
|
|
set, va (ctx->va_ctx, "descriptor_set:%s", name));
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:18:37 +00:00
|
|
|
void
|
2021-02-14 02:35:06 +00:00
|
|
|
Vulkan_CreateFrames (vulkan_ctx_t *ctx)
|
2020-02-18 08:18:37 +00:00
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
VkCommandPool cmdpool = ctx->cmdpool;
|
|
|
|
|
2021-02-05 01:22:32 +00:00
|
|
|
if (!ctx->frames.grow) {
|
|
|
|
DARRAY_INIT (&ctx->frames, 4);
|
2020-02-18 08:18:37 +00:00
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
DARRAY_RESIZE (&ctx->frames, vulkan_frame_count);
|
2020-02-18 08:18:37 +00:00
|
|
|
|
2021-02-05 01:22:32 +00:00
|
|
|
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (ctx->frames.size,
|
2021-01-15 13:45:49 +00:00
|
|
|
alloca);
|
|
|
|
QFV_AllocateCommandBuffers (device, cmdpool, 0, cmdBuffers);
|
2020-02-18 08:18:37 +00:00
|
|
|
|
2021-02-05 01:22:32 +00:00
|
|
|
for (size_t i = 0; i < ctx->frames.size; i++) {
|
|
|
|
__auto_type frame = &ctx->frames.a[i];
|
2021-01-16 12:24:42 +00:00
|
|
|
frame->framebuffer = 0;
|
2020-02-18 08:18:37 +00:00
|
|
|
frame->fence = QFV_CreateFence (device, 1);
|
|
|
|
frame->imageAvailableSemaphore = QFV_CreateSemaphore (device);
|
|
|
|
frame->renderDoneSemaphore = QFV_CreateSemaphore (device);
|
|
|
|
frame->cmdBuffer = cmdBuffers->a[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 10:20:53 +00:00
|
|
|
void
|
|
|
|
Vulkan_CreateCapture (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
ctx->capture = QFV_CreateCapture (ctx->device, ctx->frames.size,
|
|
|
|
ctx->swapchain, ctx->cmdpool);
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:18:37 +00:00
|
|
|
void
|
2021-02-14 02:35:06 +00:00
|
|
|
Vulkan_DestroyFrames (vulkan_ctx_t *ctx)
|
2020-02-18 08:18:37 +00:00
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *df = device->funcs;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
|
2021-02-05 01:22:32 +00:00
|
|
|
for (size_t i = 0; i < ctx->frames.size; i++) {
|
|
|
|
__auto_type frame = &ctx->frames.a[i];
|
2020-02-18 08:18:37 +00:00
|
|
|
df->vkDestroyFence (dev, frame->fence, 0);
|
|
|
|
df->vkDestroySemaphore (dev, frame->imageAvailableSemaphore, 0);
|
|
|
|
df->vkDestroySemaphore (dev, frame->renderDoneSemaphore, 0);
|
2021-11-30 12:56:57 +00:00
|
|
|
frame->framebuffer = 0;
|
2020-02-18 08:18:37 +00:00
|
|
|
}
|
2020-02-18 08:48:22 +00:00
|
|
|
|
2021-02-05 01:22:32 +00:00
|
|
|
DARRAY_CLEAR (&ctx->frames);
|
2021-02-14 02:35:06 +00:00
|
|
|
}
|