2021-01-19 16:25:54 +00:00
|
|
|
/*
|
|
|
|
vulkan_main.c
|
|
|
|
|
|
|
|
Vulkan rendering
|
|
|
|
|
|
|
|
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2021/1/19
|
|
|
|
|
|
|
|
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_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include "strings.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/image.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2021-01-26 11:58:24 +00:00
|
|
|
#include "QF/Vulkan/qf_alias.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_bsp.h"
|
2022-05-31 01:41:19 +00:00
|
|
|
#include "QF/Vulkan/qf_compose.h"
|
2022-05-07 01:08:46 +00:00
|
|
|
#include "QF/Vulkan/qf_iqm.h"
|
2021-03-03 09:14:16 +00:00
|
|
|
#include "QF/Vulkan/qf_lighting.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_lightmap.h"
|
|
|
|
#include "QF/Vulkan/qf_main.h"
|
2022-05-31 01:41:19 +00:00
|
|
|
#include "QF/Vulkan/qf_matrices.h"
|
2022-11-25 02:07:08 +00:00
|
|
|
#include "QF/Vulkan/qf_output.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_particles.h"
|
2022-05-30 03:10:00 +00:00
|
|
|
#include "QF/Vulkan/qf_renderpass.h"
|
2022-05-25 04:29:11 +00:00
|
|
|
#include "QF/Vulkan/qf_scene.h"
|
2021-12-14 16:22:05 +00:00
|
|
|
#include "QF/Vulkan/qf_sprite.h"
|
2022-11-30 18:00:47 +00:00
|
|
|
#include "QF/Vulkan/qf_translucent.h"
|
2022-05-31 01:41:19 +00:00
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
|
|
|
#include "QF/Vulkan/swapchain.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
|
|
|
|
#include "mod_internal.h"
|
|
|
|
#include "r_internal.h"
|
|
|
|
#include "vid_vulkan.h"
|
|
|
|
|
2022-03-17 08:50:38 +00:00
|
|
|
void
|
|
|
|
Vulkan_RenderEntities (entqueue_t *queue, qfv_renderframe_t *rFrame)
|
2021-01-19 16:25:54 +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 (!r_drawentities)
|
2021-01-19 16:25:54 +00:00
|
|
|
return;
|
2022-10-27 02:11:38 +00:00
|
|
|
//FIXME need a better way (components? but HasComponent isn't free)
|
|
|
|
int vmod = Entity_Valid (vr_data.view_model);
|
2021-01-19 16:25:54 +00:00
|
|
|
#define RE_LOOP(type_name, Type) \
|
|
|
|
do { \
|
2021-01-27 07:16:28 +00:00
|
|
|
int begun = 0; \
|
2022-03-17 08:50:38 +00:00
|
|
|
for (size_t i = 0; i < queue->ent_queues[mod_##type_name].size; \
|
2022-03-04 16:48:10 +00:00
|
|
|
i++) { \
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
entity_t ent = queue->ent_queues[mod_##type_name].a[i]; \
|
2021-01-19 16:25:54 +00:00
|
|
|
if (!begun) { \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_##Type##Begin (rFrame); \
|
2021-01-19 16:25:54 +00:00
|
|
|
begun = 1; \
|
|
|
|
} \
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
/* FIXME hack the depth range to prevent view model */\
|
2021-07-25 05:03:25 +00:00
|
|
|
/* from poking into walls */\
|
2022-10-27 02:11:38 +00:00
|
|
|
if (vmod && ent.id == vr_data.view_model.id) { \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_AliasDepthRange (rFrame, 0, 0.3); \
|
2021-07-25 05:03:25 +00:00
|
|
|
} \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_Draw##Type (ent, rFrame); \
|
2021-07-25 05:03:25 +00:00
|
|
|
/* unhack in case the view_model is not the last */\
|
2022-10-27 02:11:38 +00:00
|
|
|
if (vmod && ent.id == vr_data.view_model.id) { \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_AliasDepthRange (rFrame, 0, 1); \
|
2021-07-25 05:03:25 +00:00
|
|
|
} \
|
2021-01-19 16:25:54 +00:00
|
|
|
} \
|
|
|
|
if (begun) \
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_##Type##End (rFrame); \
|
2021-01-19 16:25:54 +00:00
|
|
|
} while (0)
|
|
|
|
|
2021-01-26 11:58:24 +00:00
|
|
|
RE_LOOP (alias, Alias);
|
2022-05-07 01:08:46 +00:00
|
|
|
RE_LOOP (iqm, IQM);
|
2021-12-14 16:22:05 +00:00
|
|
|
RE_LOOP (sprite, Sprite);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-25 05:03:25 +00:00
|
|
|
Vulkan_DrawViewModel (vulkan_ctx_t *ctx)
|
2021-01-19 16:25:54 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
entity_t ent = vr_data.view_model;
|
2022-10-27 03:53:01 +00:00
|
|
|
if (!Entity_Valid (ent)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-25 03:53:30 +00:00
|
|
|
renderer_t *renderer = Ent_GetComponent (ent.id, scene_renderer, ent.reg);
|
2021-01-19 16:25:54 +00:00
|
|
|
if (vr_data.inhibit_viewmodel
|
[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
|
|
|
|| !r_drawviewmodel
|
|
|
|
|| !r_drawentities
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
|| !renderer->model)
|
2021-01-19 16:25:54 +00:00
|
|
|
return;
|
|
|
|
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
EntQueue_AddEntity (r_ent_queue, ent, renderer->model->type);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_RenderView (qfv_renderframe_t *rFrame)
|
2021-01-19 16:25:54 +00:00
|
|
|
{
|
2021-12-02 12:58:29 +00:00
|
|
|
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
|
2021-01-19 16:25:54 +00:00
|
|
|
|
2022-03-14 06:27:43 +00:00
|
|
|
if (!r_refdef.worldmodel) {
|
2021-12-02 09:30:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_DrawWorld (rFrame);
|
|
|
|
Vulkan_DrawSky (rFrame);
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
if (Entity_Valid (vr_data.view_model)) {
|
2022-04-25 22:22:45 +00:00
|
|
|
Vulkan_DrawViewModel (ctx);
|
|
|
|
}
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_DrawWaterSurfaces (rFrame);
|
2022-11-28 01:21:20 +00:00
|
|
|
Vulkan_DrawParticles (rFrame);
|
2021-12-17 06:52:17 +00:00
|
|
|
Vulkan_Bsp_Flush (ctx);
|
2022-05-31 01:49:40 +00:00
|
|
|
Vulkan_RenderEntities (r_ent_queue, rFrame);
|
2022-05-25 04:29:11 +00:00
|
|
|
Vulkan_Scene_Flush (ctx);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-05-05 05:41:46 +00:00
|
|
|
Vulkan_NewScene (scene_t *scene, vulkan_ctx_t *ctx)
|
2021-01-19 16:25:54 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
d_lightstylevalue[i] = 264; // normal light value
|
|
|
|
}
|
|
|
|
|
2022-05-05 05:41:46 +00:00
|
|
|
r_refdef.worldmodel = scene->worldmodel;
|
2021-01-19 16:25:54 +00:00
|
|
|
|
|
|
|
// Force a vis update
|
2022-05-22 07:31:24 +00:00
|
|
|
R_MarkLeaves (0, 0, 0, 0);
|
2021-01-19 16:25:54 +00:00
|
|
|
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2022-05-05 05:41:46 +00:00
|
|
|
Vulkan_RegisterTextures (scene->models, scene->num_models, ctx);
|
|
|
|
//Vulkan_BuildLightmaps (scene->models, scene->num_models, ctx);
|
|
|
|
Vulkan_BuildDisplayLists (scene->models, scene->num_models, ctx);
|
2022-05-05 05:58:47 +00:00
|
|
|
Vulkan_LoadLights (scene, ctx);
|
2021-01-19 16:25:54 +00:00
|
|
|
}
|
2022-05-31 01:41:19 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
main_draw (qfv_renderframe_t *rFrame)
|
|
|
|
{
|
|
|
|
Vulkan_Matrix_Draw (rFrame);
|
|
|
|
Vulkan_RenderView (rFrame);
|
|
|
|
Vulkan_Lighting_Draw (rFrame);
|
|
|
|
Vulkan_Compose_Draw (rFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_Main_CreateRenderPasses (vulkan_ctx_t *ctx)
|
|
|
|
{
|
2022-11-26 13:23:59 +00:00
|
|
|
__auto_type rp = QFV_RenderPass_New (ctx, "deferred", main_draw);
|
|
|
|
rp->output = (qfv_output_t) {
|
|
|
|
.extent = ctx->swapchain->extent,
|
|
|
|
.frames = ctx->swapchain->numImages,
|
|
|
|
};
|
|
|
|
QFV_RenderPass_CreateAttachments (rp);
|
|
|
|
QFV_RenderPass_CreateRenderPass (rp);
|
|
|
|
QFV_RenderPass_CreateFramebuffer (rp);
|
2022-05-31 01:41:19 +00:00
|
|
|
rp->order = QFV_rp_main;
|
|
|
|
DARRAY_APPEND (&ctx->renderPasses, rp);
|
2022-11-26 13:23:59 +00:00
|
|
|
|
|
|
|
Vulkan_Output_SetInput (ctx, rp->output.view);
|
2022-11-30 18:00:47 +00:00
|
|
|
Vulkan_Translucent_CreateBuffers (ctx, rp->output.extent);
|
2022-05-31 01:41:19 +00:00
|
|
|
}
|