2019-07-06 05:42:53 +00:00
|
|
|
/*
|
|
|
|
vid_render_vulkan.c
|
|
|
|
|
|
|
|
Vulkan version of the renderer
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-02-16 13:45:27 +00:00
|
|
|
#include <stdlib.h>
|
2022-05-31 01:56:00 +00:00
|
|
|
#include <string.h>
|
2020-02-16 13:45:27 +00:00
|
|
|
|
2021-11-29 04:40:56 +00:00
|
|
|
#include "QF/cvar.h"
|
2020-02-17 11:29:35 +00:00
|
|
|
#include "QF/darray.h"
|
2021-03-24 10:20:53 +00:00
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/quakefs.h"
|
2019-07-09 07:33:44 +00:00
|
|
|
#include "QF/sys.h"
|
2021-03-24 10:20:53 +00:00
|
|
|
#include "QF/va.h"
|
2019-07-09 07:33:44 +00:00
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/plugin/general.h"
|
|
|
|
#include "QF/plugin/vid_render.h"
|
|
|
|
|
2021-01-25 15:55:45 +00:00
|
|
|
#include "QF/Vulkan/qf_alias.h"
|
2021-01-19 16:25:54 +00:00
|
|
|
#include "QF/Vulkan/qf_bsp.h"
|
2021-02-24 10:58:31 +00:00
|
|
|
#include "QF/Vulkan/qf_compose.h"
|
2021-01-10 06:52:27 +00:00
|
|
|
#include "QF/Vulkan/qf_draw.h"
|
2022-05-04 05:07:27 +00:00
|
|
|
#include "QF/Vulkan/qf_iqm.h"
|
2021-02-24 10:58:31 +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"
|
2021-12-08 06:28:21 +00:00
|
|
|
#include "QF/Vulkan/qf_matrices.h"
|
2022-11-22 08:47:36 +00:00
|
|
|
#include "QF/Vulkan/qf_output.h"
|
2022-11-15 00:26:17 +00:00
|
|
|
#include "QF/Vulkan/qf_palette.h"
|
2021-01-18 03:46:06 +00:00
|
|
|
#include "QF/Vulkan/qf_particles.h"
|
2023-07-21 02:59:25 +00:00
|
|
|
#include "QF/Vulkan/qf_planes.h"
|
2022-05-24 15:17:57 +00:00
|
|
|
#include "QF/Vulkan/qf_scene.h"
|
2021-12-14 01:02:35 +00:00
|
|
|
#include "QF/Vulkan/qf_sprite.h"
|
2021-01-20 06:11:50 +00:00
|
|
|
#include "QF/Vulkan/qf_texture.h"
|
2022-11-30 18:00:47 +00:00
|
|
|
#include "QF/Vulkan/qf_translucent.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "QF/Vulkan/qf_vid.h"
|
2021-03-24 10:20:53 +00:00
|
|
|
#include "QF/Vulkan/capture.h"
|
2020-02-16 13:45:27 +00:00
|
|
|
#include "QF/Vulkan/command.h"
|
2022-05-07 03:38:31 +00:00
|
|
|
#include "QF/Vulkan/debug.h"
|
2019-07-12 04:15:25 +00:00
|
|
|
#include "QF/Vulkan/device.h"
|
2020-02-17 11:29:35 +00:00
|
|
|
#include "QF/Vulkan/image.h"
|
2019-07-12 04:15:25 +00:00
|
|
|
#include "QF/Vulkan/instance.h"
|
2022-03-30 05:55:32 +00:00
|
|
|
#include "QF/Vulkan/projection.h"
|
2023-02-10 02:04:11 +00:00
|
|
|
#include "QF/Vulkan/render.h"
|
2022-05-13 01:19:08 +00:00
|
|
|
#include "QF/Vulkan/staging.h"
|
2019-07-12 04:15:25 +00:00
|
|
|
#include "QF/Vulkan/swapchain.h"
|
2023-07-13 06:21:53 +00:00
|
|
|
#include "QF/ui/imui.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2022-05-05 05:41:46 +00:00
|
|
|
#include "QF/scene/scene.h"
|
2022-03-04 16:48:10 +00:00
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
#include "mod_internal.h"
|
|
|
|
#include "r_internal.h"
|
2019-07-08 04:40:29 +00:00
|
|
|
#include "vid_internal.h"
|
2019-07-08 16:00:47 +00:00
|
|
|
#include "vid_vulkan.h"
|
2022-11-24 14:44:07 +00:00
|
|
|
#include "vulkan/vkparse.h"
|
2019-07-06 05:42:53 +00:00
|
|
|
|
2019-07-09 02:54:23 +00:00
|
|
|
static vulkan_ctx_t *vulkan_ctx;
|
2019-07-08 16:00:47 +00:00
|
|
|
|
2021-12-19 05:47:25 +00:00
|
|
|
static struct psystem_s *
|
|
|
|
vulkan_ParticleSystem (void)
|
|
|
|
{
|
|
|
|
return Vulkan_ParticleSystem (vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2019-07-10 04:16:46 +00:00
|
|
|
static void
|
|
|
|
vulkan_R_Init (void)
|
|
|
|
{
|
2023-02-13 08:45:36 +00:00
|
|
|
QFV_Render_Init (vulkan_ctx);
|
|
|
|
|
2021-01-10 16:24:15 +00:00
|
|
|
Vulkan_CreateStagingBuffers (vulkan_ctx);
|
2022-09-26 00:52:14 +00:00
|
|
|
Vulkan_Texture_Init (vulkan_ctx);
|
|
|
|
|
|
|
|
Vulkan_CreateSwapchain (vulkan_ctx);
|
2022-11-22 08:47:36 +00:00
|
|
|
|
2023-06-25 12:01:34 +00:00
|
|
|
QFV_Capture_Init (vulkan_ctx);
|
2022-11-22 08:47:36 +00:00
|
|
|
Vulkan_Output_Init (vulkan_ctx);
|
2021-12-02 12:58:29 +00:00
|
|
|
|
2021-12-08 06:28:21 +00:00
|
|
|
Vulkan_Matrix_Init (vulkan_ctx);
|
2022-05-24 15:17:57 +00:00
|
|
|
Vulkan_Scene_Init (vulkan_ctx);
|
2021-01-26 11:58:24 +00:00
|
|
|
Vulkan_Alias_Init (vulkan_ctx);
|
2021-01-19 16:25:54 +00:00
|
|
|
Vulkan_Bsp_Init (vulkan_ctx);
|
2022-05-07 01:08:46 +00:00
|
|
|
Vulkan_IQM_Init (vulkan_ctx);
|
2021-12-16 14:17:01 +00:00
|
|
|
Vulkan_Particles_Init (vulkan_ctx);
|
2023-07-21 02:59:25 +00:00
|
|
|
Vulkan_Planes_Init (vulkan_ctx);
|
2021-12-14 16:22:05 +00:00
|
|
|
Vulkan_Sprite_Init (vulkan_ctx);
|
2021-01-10 06:52:27 +00:00
|
|
|
Vulkan_Draw_Init (vulkan_ctx);
|
2021-02-24 10:58:31 +00:00
|
|
|
Vulkan_Lighting_Init (vulkan_ctx);
|
2022-11-30 18:00:47 +00:00
|
|
|
Vulkan_Translucent_Init (vulkan_ctx);
|
2021-02-24 10:58:31 +00:00
|
|
|
Vulkan_Compose_Init (vulkan_ctx);
|
2021-12-02 12:58:29 +00:00
|
|
|
|
2023-06-25 14:33:47 +00:00
|
|
|
QFV_LoadRenderInfo (vulkan_ctx, "main_def");
|
|
|
|
QFV_LoadSamplerInfo (vulkan_ctx, "smp_quake");
|
2023-02-19 03:53:02 +00:00
|
|
|
QFV_BuildRender (vulkan_ctx);
|
2023-02-13 15:55:22 +00:00
|
|
|
|
2023-06-24 12:42:46 +00:00
|
|
|
Vulkan_Texture_Setup (vulkan_ctx);
|
|
|
|
Vulkan_Palette_Init (vulkan_ctx, vid.palette);
|
2023-06-25 14:33:47 +00:00
|
|
|
Vulkan_Alias_Setup (vulkan_ctx);
|
2023-06-24 12:42:46 +00:00
|
|
|
Vulkan_Bsp_Setup (vulkan_ctx);
|
2023-06-25 14:33:47 +00:00
|
|
|
Vulkan_IQM_Setup (vulkan_ctx);
|
2023-06-24 12:42:46 +00:00
|
|
|
Vulkan_Matrix_Setup (vulkan_ctx);
|
|
|
|
Vulkan_Scene_Setup (vulkan_ctx);
|
2023-06-25 14:33:47 +00:00
|
|
|
Vulkan_Sprite_Setup (vulkan_ctx);
|
2023-06-24 12:42:46 +00:00
|
|
|
Vulkan_Output_Setup (vulkan_ctx);
|
|
|
|
Vulkan_Compose_Setup (vulkan_ctx);
|
|
|
|
Vulkan_Draw_Setup (vulkan_ctx);
|
|
|
|
Vulkan_Particles_Setup (vulkan_ctx);
|
2023-07-21 02:59:25 +00:00
|
|
|
Vulkan_Planes_Setup (vulkan_ctx);
|
2023-06-24 12:42:46 +00:00
|
|
|
Vulkan_Translucent_Setup (vulkan_ctx);
|
|
|
|
Vulkan_Lighting_Setup (vulkan_ctx);
|
|
|
|
|
2021-03-19 13:53:23 +00:00
|
|
|
Skin_Init ();
|
2020-02-18 08:18:37 +00:00
|
|
|
|
2021-01-12 02:27:41 +00:00
|
|
|
SCR_Init ();
|
2020-02-16 13:45:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 03:46:06 +00:00
|
|
|
static void
|
|
|
|
vulkan_R_ClearState (void)
|
|
|
|
{
|
2022-05-31 01:56:00 +00:00
|
|
|
QFV_DeviceWaitIdle (vulkan_ctx->device);
|
2023-06-22 11:27:55 +00:00
|
|
|
//FIXME clear scene correctly
|
2022-03-14 06:27:43 +00:00
|
|
|
r_refdef.worldmodel = 0;
|
2023-06-22 11:27:55 +00:00
|
|
|
EntQueue_Clear (r_ent_queue);
|
2021-01-19 16:25:54 +00:00
|
|
|
R_ClearDlights ();
|
2021-12-19 04:08:39 +00:00
|
|
|
R_ClearParticles ();
|
2022-05-07 03:12:02 +00:00
|
|
|
Vulkan_LoadLights (0, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_R_LoadSkys (const char *skyname)
|
|
|
|
{
|
2021-03-25 06:54:34 +00:00
|
|
|
Vulkan_LoadSkys (skyname, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-05-05 05:41:46 +00:00
|
|
|
vulkan_R_NewScene (scene_t *scene)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2022-05-05 05:41:46 +00:00
|
|
|
Vulkan_NewScene (scene, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-11 01:59:27 +00:00
|
|
|
vulkan_R_LineGraph (int x, int y, int *h_vals, int count, int height)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2022-11-10 12:19:01 +00:00
|
|
|
Vulkan_LineGraph (x, y, h_vals, count, height, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
2022-09-15 05:24:33 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_CharBuffer (int x, int y, draw_charbuffer_t *buffer)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_CharBuffer (x, y, buffer, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2022-11-13 13:23:56 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_SetScale (int scale)
|
|
|
|
{
|
|
|
|
vulkan_ctx->twod_scale = max (1, scale);
|
|
|
|
}
|
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_Character (int x, int y, unsigned ch)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Character (x, y, ch, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_String (int x, int y, const char *str)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_String (x, y, str, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_nString (int x, int y, const char *str, int count)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_nString (x, y, str, count, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_AltString (int x, int y, const char *str)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_AltString (x, y, str, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_ConsoleBackground (int lines, byte alpha)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_ConsoleBackground (lines, alpha, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_Crosshair (void)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Crosshair (vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_CrosshairAt (int ch, int x, int y)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_CrosshairAt (ch, x, y, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_TileClear (int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_TileClear (x, y, w, h, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_Fill (int x, int y, int w, int h, int c)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Fill (x, y, w, h, c, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2022-05-28 09:14:26 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_Line (int x0, int y0, int x1, int y1, int c)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Line (x0, y0, x1, y1, c, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_TextBox (int x, int y, int width, int lines, byte alpha)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_TextBox (x, y, width, lines, alpha, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_FadeScreen (void)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_FadeScreen (vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_BlendScreen (quat_t color)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_BlendScreen (color, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2020-02-16 13:45:27 +00:00
|
|
|
static qpic_t *
|
2023-06-13 09:06:11 +00:00
|
|
|
vulkan_Draw_CachePic (const char *path, bool alpha)
|
2020-02-16 13:45:27 +00:00
|
|
|
{
|
2021-01-10 06:52:27 +00:00
|
|
|
return Vulkan_Draw_CachePic (path, alpha, vulkan_ctx);
|
2020-02-16 13:45:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_UncachePic (const char *path)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_UncachePic (path, vulkan_ctx);
|
|
|
|
}
|
2020-02-16 13:45:27 +00:00
|
|
|
|
|
|
|
static qpic_t *
|
|
|
|
vulkan_Draw_MakePic (int width, int height, const byte *data)
|
|
|
|
{
|
2021-01-10 06:52:27 +00:00
|
|
|
return Vulkan_Draw_MakePic (width, height, data, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_DestroyPic (qpic_t *pic)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_DestroyPic (pic, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static qpic_t *
|
|
|
|
vulkan_Draw_PicFromWad (const char *name)
|
|
|
|
{
|
|
|
|
return Vulkan_Draw_PicFromWad (name, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_Pic (int x, int y, qpic_t *pic)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Pic (x, y, pic, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2023-01-17 02:33:47 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_FitPic (int x, int y, int width, int height, qpic_t *pic)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_FitPic (x, y, width, height, pic, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2021-01-10 06:52:27 +00:00
|
|
|
static void
|
|
|
|
vulkan_Draw_Picf (float x, float y, qpic_t *pic)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_Picf (x, y, pic, vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height)
|
|
|
|
{
|
|
|
|
Vulkan_Draw_SubPic (x, y, pic, srcx, srcy, width, height, vulkan_ctx);
|
2019-07-10 04:16:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-02 23:58:27 +00:00
|
|
|
static int
|
2022-12-07 06:11:08 +00:00
|
|
|
vulkan_Draw_AddFont (struct font_s *font)
|
2022-08-31 10:23:30 +00:00
|
|
|
{
|
2022-10-02 23:58:27 +00:00
|
|
|
return Vulkan_Draw_AddFont (font, vulkan_ctx);
|
2022-08-31 10:23:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 02:38:09 +00:00
|
|
|
static void
|
2022-12-10 09:55:08 +00:00
|
|
|
vulkan_Draw_Glyph (int x, int y, int fontid, int glyphid, int c)
|
2022-09-02 02:38:09 +00:00
|
|
|
{
|
2022-12-10 09:55:08 +00:00
|
|
|
Vulkan_Draw_Glyph (x, y, fontid, glyphid, c, vulkan_ctx);
|
2022-09-02 02:38:09 +00:00
|
|
|
}
|
2022-03-07 14:32:44 +00:00
|
|
|
|
|
|
|
static void
|
2022-03-15 06:42:43 +00:00
|
|
|
vulkan_set_2d (int scaled)
|
2022-03-07 14:32:44 +00:00
|
|
|
{
|
2022-03-30 05:55:32 +00:00
|
|
|
//FIXME this should not be done every frame
|
|
|
|
__auto_type mctx = vulkan_ctx->matrix_context;
|
|
|
|
__auto_type mat = &mctx->matrices;
|
2022-11-13 13:23:56 +00:00
|
|
|
int scale = vulkan_ctx->twod_scale;
|
2022-03-30 05:55:32 +00:00
|
|
|
|
2022-11-19 16:17:09 +00:00
|
|
|
float left = 0;
|
|
|
|
float top = 0;
|
2022-11-13 13:23:56 +00:00
|
|
|
float right = left + vid.width / scale;
|
|
|
|
float bottom = top + vid.height / scale;
|
2022-09-28 13:24:22 +00:00
|
|
|
QFV_Orthographic (mat->Projection2d, left, right, top, bottom, 0, 99999);
|
2022-11-22 08:47:36 +00:00
|
|
|
mat->ScreenSize = (vec2f_t) { 1.0 / vid.width, 1.0 / vid.height };
|
2022-03-30 05:55:32 +00:00
|
|
|
mctx->dirty = mctx->frames.size;
|
2022-03-07 14:32:44 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 02:33:49 +00:00
|
|
|
static void
|
2023-07-11 02:41:14 +00:00
|
|
|
vulkan_UpdateScreen (SCR_Func *scr_funcs)
|
2023-01-19 02:33:49 +00:00
|
|
|
{
|
2023-06-21 14:31:08 +00:00
|
|
|
vulkan_set_2d (1);//FIXME
|
2023-06-23 09:07:40 +00:00
|
|
|
Vulkan_SetScrFuncs (scr_funcs, vulkan_ctx);
|
2023-06-15 06:17:39 +00:00
|
|
|
QFV_RunRenderJob (vulkan_ctx);
|
2023-01-19 02:33:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 05:55:32 +00:00
|
|
|
static void
|
|
|
|
vulkan_set_fov (float x, float y)
|
|
|
|
{
|
|
|
|
if (!vulkan_ctx || !vulkan_ctx->matrix_context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
__auto_type mctx = vulkan_ctx->matrix_context;
|
|
|
|
__auto_type mat = &mctx->matrices;
|
|
|
|
|
|
|
|
QFV_PerspectiveTan (mat->Projection3d, x, y);
|
|
|
|
|
|
|
|
mctx->dirty = mctx->frames.size;
|
|
|
|
}
|
2022-03-31 10:07:15 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_capture_screen (capfunc_t callback, void *data)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2023-06-25 12:01:34 +00:00
|
|
|
QFV_Capture_Screen (vulkan_ctx, callback, data);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 06:21:53 +00:00
|
|
|
static void
|
|
|
|
vulkan_debug_ui (struct imui_ctx_s *imui_ctx)
|
|
|
|
{
|
|
|
|
#define IMUI_context imui_ctx
|
|
|
|
UI_ExtendPanel ("Renderer##menu") {
|
2023-07-13 14:16:26 +00:00
|
|
|
QFV_Render_Menu (vulkan_ctx, imui_ctx);
|
2023-07-13 06:21:53 +00:00
|
|
|
}
|
|
|
|
#undef IMUI_context
|
2023-07-13 14:16:26 +00:00
|
|
|
QFV_Render_UI (vulkan_ctx, imui_ctx);
|
2023-07-13 06:21:53 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 03:46:06 +00:00
|
|
|
static void
|
2021-02-01 05:39:00 +00:00
|
|
|
vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2021-02-01 05:39:00 +00:00
|
|
|
Vulkan_Mod_LoadLighting (mod, bsp, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-01 05:39:00 +00:00
|
|
|
vulkan_Mod_SubdivideSurface (model_t *mod, msurface_t *fa)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-01 05:39:00 +00:00
|
|
|
vulkan_Mod_ProcessTexture (model_t *mod, texture_t *tx)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2021-02-01 05:39:00 +00:00
|
|
|
Vulkan_Mod_ProcessTexture (mod, tx, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-01 12:11:45 +00:00
|
|
|
vulkan_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx,
|
2021-01-18 03:46:06 +00:00
|
|
|
void *_m, int _s, int extra)
|
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
Vulkan_Mod_MakeAliasModelDisplayLists (alias_ctx, _m, _s, extra,
|
|
|
|
vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
static void
|
|
|
|
vulkan_Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
Vulkan_Mod_LoadAllSkins (alias_ctx, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-01 12:11:45 +00:00
|
|
|
vulkan_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
Vulkan_Mod_FinalizeAliasModel (alias_ctx, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-02-01 12:11:45 +00:00
|
|
|
vulkan_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Mod_IQMFinish (model_t *mod)
|
|
|
|
{
|
2022-05-04 05:07:27 +00:00
|
|
|
Vulkan_Mod_IQMFinish (mod, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-12-13 23:36:19 +00:00
|
|
|
vulkan_Mod_SpriteLoadFrames (mod_sprite_ctx_t *sprite_ctx)
|
2021-01-18 03:46:06 +00:00
|
|
|
{
|
2021-12-14 01:02:35 +00:00
|
|
|
Vulkan_Mod_SpriteLoadFrames (sprite_ctx, vulkan_ctx);
|
2021-01-18 03:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Skin_SetupSkin (struct skin_s *skin, int cmap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Skin_ProcessTranslation (int cmap, const byte *translation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_Skin_InitTranslations (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-26 06:43:17 +00:00
|
|
|
static void
|
2021-07-10 15:09:41 +00:00
|
|
|
set_palette (void *data, const byte *palette)
|
2021-06-26 06:43:17 +00:00
|
|
|
{
|
2022-11-15 00:26:17 +00:00
|
|
|
if (vulkan_ctx->palette_context) {
|
|
|
|
Vulkan_Palette_Update (vulkan_ctx, palette);
|
|
|
|
}
|
2021-06-26 06:43:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-10 15:09:41 +00:00
|
|
|
vulkan_vid_render_choose_visual (void *data)
|
2021-06-26 06:43:17 +00:00
|
|
|
{
|
|
|
|
Vulkan_CreateDevice (vulkan_ctx);
|
2021-11-29 04:40:56 +00:00
|
|
|
if (!vulkan_ctx->device) {
|
|
|
|
Sys_Error ("Unable to create Vulkan device.%s",
|
[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_use_validation ? ""
|
2021-11-29 04:40:56 +00:00
|
|
|
: "\nSet vulkan_use_validation for details");
|
|
|
|
}
|
2021-06-26 06:43:17 +00:00
|
|
|
vulkan_ctx->choose_visual (vulkan_ctx);
|
|
|
|
vulkan_ctx->cmdpool = QFV_CreateCommandPool (vulkan_ctx->device,
|
|
|
|
vulkan_ctx->device->queue.queueFamily,
|
|
|
|
0, 1);
|
|
|
|
Sys_MaskPrintf (SYS_vulkan, "vk choose visual %p %p %d %#zx\n",
|
|
|
|
vulkan_ctx->device->dev, vulkan_ctx->device->queue.queue,
|
|
|
|
vulkan_ctx->device->queue.queueFamily,
|
|
|
|
(size_t) vulkan_ctx->cmdpool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-07-10 15:09:41 +00:00
|
|
|
vulkan_vid_render_create_context (void *data)
|
2021-06-26 06:43:17 +00:00
|
|
|
{
|
|
|
|
vulkan_ctx->create_window (vulkan_ctx);
|
|
|
|
vulkan_ctx->surface = vulkan_ctx->create_surface (vulkan_ctx);
|
2022-05-31 02:05:12 +00:00
|
|
|
Sys_MaskPrintf (SYS_vulkan, "vk create context: surface:%#zx\n",
|
2021-06-26 06:43:17 +00:00
|
|
|
(size_t) vulkan_ctx->surface);
|
|
|
|
}
|
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
static vid_model_funcs_t model_funcs = {
|
2022-09-25 01:18:06 +00:00
|
|
|
.texture_render_size = sizeof (vulktex_t) + 2 * sizeof (qfv_tex_t),
|
|
|
|
|
|
|
|
.Mod_LoadLighting = vulkan_Mod_LoadLighting,
|
|
|
|
.Mod_SubdivideSurface = vulkan_Mod_SubdivideSurface,
|
|
|
|
.Mod_ProcessTexture = vulkan_Mod_ProcessTexture,
|
|
|
|
|
|
|
|
.Mod_LoadIQM = Mod_LoadIQM,
|
|
|
|
.Mod_LoadAliasModel = Mod_LoadAliasModel,
|
|
|
|
.Mod_LoadSpriteModel = Mod_LoadSpriteModel,
|
|
|
|
|
|
|
|
.Mod_MakeAliasModelDisplayLists = vulkan_Mod_MakeAliasModelDisplayLists,
|
|
|
|
.Mod_LoadAllSkins = vulkan_Mod_LoadAllSkins,
|
|
|
|
.Mod_FinalizeAliasModel = vulkan_Mod_FinalizeAliasModel,
|
|
|
|
.Mod_LoadExternalSkins = vulkan_Mod_LoadExternalSkins,
|
|
|
|
.Mod_IQMFinish = vulkan_Mod_IQMFinish,
|
|
|
|
.alias_cache = 0,
|
|
|
|
.Mod_SpriteLoadFrames = vulkan_Mod_SpriteLoadFrames,
|
|
|
|
|
|
|
|
.Skin_Free = Skin_Free,
|
|
|
|
.Skin_SetColormap = Skin_SetColormap,
|
|
|
|
.Skin_SetSkin = Skin_SetSkin,
|
|
|
|
.Skin_SetupSkin = vulkan_Skin_SetupSkin,
|
|
|
|
.Skin_SetTranslation = Skin_SetTranslation,
|
|
|
|
.Skin_ProcessTranslation = vulkan_Skin_ProcessTranslation,
|
|
|
|
.Skin_InitTranslations = vulkan_Skin_InitTranslations,
|
2019-07-06 05:42:53 +00:00
|
|
|
};
|
|
|
|
|
2021-06-26 06:43:17 +00:00
|
|
|
static void
|
|
|
|
vulkan_vid_render_init (void)
|
|
|
|
{
|
|
|
|
if (!vr_data.vid->vid_internal->vulkan_context) {
|
|
|
|
Sys_Error ("Sorry, Vulkan not supported by this program.");
|
|
|
|
}
|
2023-03-06 12:15:15 +00:00
|
|
|
vid_internal_t *vi = vr_data.vid->vid_internal;
|
|
|
|
vulkan_ctx = vi->vulkan_context (vi);
|
2021-06-26 06:43:17 +00:00
|
|
|
vulkan_ctx->load_vulkan (vulkan_ctx);
|
|
|
|
|
|
|
|
Vulkan_Init_Common (vulkan_ctx);
|
|
|
|
|
2023-03-06 12:15:15 +00:00
|
|
|
vi->set_palette = set_palette;
|
|
|
|
vi->choose_visual = vulkan_vid_render_choose_visual;
|
|
|
|
vi->create_context = vulkan_vid_render_create_context;
|
2021-06-26 06:43:17 +00:00
|
|
|
|
|
|
|
vr_funcs = &vulkan_vid_render_funcs;
|
|
|
|
m_funcs = &model_funcs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vulkan_vid_render_shutdown (void)
|
|
|
|
{
|
2021-11-29 04:40:56 +00:00
|
|
|
if (!vulkan_ctx || !vulkan_ctx->device) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-26 06:43:17 +00:00
|
|
|
qfv_device_t *device = vulkan_ctx->device;
|
|
|
|
qfv_devfuncs_t *df = device->funcs;
|
|
|
|
VkDevice dev = device->dev;
|
|
|
|
QFV_DeviceWaitIdle (device);
|
2021-12-02 12:58:29 +00:00
|
|
|
|
2023-03-05 09:19:54 +00:00
|
|
|
SCR_Shutdown ();
|
2023-03-06 12:04:00 +00:00
|
|
|
Mod_ClearAll ();
|
2022-05-07 01:08:46 +00:00
|
|
|
|
2021-06-26 06:43:17 +00:00
|
|
|
Vulkan_Compose_Shutdown (vulkan_ctx);
|
2022-11-30 18:00:47 +00:00
|
|
|
Vulkan_Translucent_Shutdown (vulkan_ctx);
|
2021-06-26 06:43:17 +00:00
|
|
|
Vulkan_Lighting_Shutdown (vulkan_ctx);
|
|
|
|
Vulkan_Draw_Shutdown (vulkan_ctx);
|
2021-12-14 16:22:05 +00:00
|
|
|
Vulkan_Sprite_Shutdown (vulkan_ctx);
|
2023-07-21 02:59:25 +00:00
|
|
|
Vulkan_Planes_Shutdown (vulkan_ctx);
|
2021-12-16 14:17:01 +00:00
|
|
|
Vulkan_Particles_Shutdown (vulkan_ctx);
|
2022-05-07 01:08:46 +00:00
|
|
|
Vulkan_IQM_Shutdown (vulkan_ctx);
|
2021-06-26 06:43:17 +00:00
|
|
|
Vulkan_Bsp_Shutdown (vulkan_ctx);
|
|
|
|
Vulkan_Alias_Shutdown (vulkan_ctx);
|
2022-05-24 15:17:57 +00:00
|
|
|
Vulkan_Scene_Shutdown (vulkan_ctx);
|
2021-12-08 06:28:21 +00:00
|
|
|
Vulkan_Matrix_Shutdown (vulkan_ctx);
|
2021-12-02 12:58:29 +00:00
|
|
|
|
2023-06-25 12:01:34 +00:00
|
|
|
QFV_Capture_Shutdown (vulkan_ctx);
|
2022-11-22 08:47:36 +00:00
|
|
|
Vulkan_Output_Shutdown (vulkan_ctx);
|
2022-11-22 04:30:29 +00:00
|
|
|
|
2022-11-15 00:26:17 +00:00
|
|
|
Vulkan_Palette_Shutdown (vulkan_ctx);
|
2021-06-26 06:43:17 +00:00
|
|
|
Vulkan_Texture_Shutdown (vulkan_ctx);
|
2022-05-13 01:19:08 +00:00
|
|
|
|
2023-02-19 03:53:02 +00:00
|
|
|
QFV_Render_Shutdown (vulkan_ctx);
|
|
|
|
|
2022-05-13 01:19:08 +00:00
|
|
|
QFV_DestroyStagingBuffer (vulkan_ctx->staging);
|
|
|
|
df->vkDestroyCommandPool (dev, vulkan_ctx->cmdpool, 0);
|
|
|
|
|
2021-06-26 06:43:17 +00:00
|
|
|
Vulkan_Shutdown_Common (vulkan_ctx);
|
|
|
|
}
|
|
|
|
|
2019-07-06 05:42:53 +00:00
|
|
|
vid_render_funcs_t vulkan_vid_render_funcs = {
|
2022-09-25 01:18:06 +00:00
|
|
|
.init = vulkan_vid_render_init,
|
|
|
|
|
2023-01-19 02:33:49 +00:00
|
|
|
.UpdateScreen = vulkan_UpdateScreen,
|
2023-01-18 15:09:41 +00:00
|
|
|
|
2022-09-25 01:18:06 +00:00
|
|
|
.Draw_CharBuffer = vulkan_Draw_CharBuffer,
|
2022-11-13 13:23:56 +00:00
|
|
|
.Draw_SetScale = vulkan_Draw_SetScale,
|
2022-09-25 01:18:06 +00:00
|
|
|
.Draw_Character = vulkan_Draw_Character,
|
|
|
|
.Draw_String = vulkan_Draw_String,
|
|
|
|
.Draw_nString = vulkan_Draw_nString,
|
|
|
|
.Draw_AltString = vulkan_Draw_AltString,
|
|
|
|
.Draw_ConsoleBackground = vulkan_Draw_ConsoleBackground,
|
|
|
|
.Draw_Crosshair = vulkan_Draw_Crosshair,
|
|
|
|
.Draw_CrosshairAt = vulkan_Draw_CrosshairAt,
|
|
|
|
.Draw_TileClear = vulkan_Draw_TileClear,
|
|
|
|
.Draw_Fill = vulkan_Draw_Fill,
|
|
|
|
.Draw_Line = vulkan_Draw_Line,
|
|
|
|
.Draw_TextBox = vulkan_Draw_TextBox,
|
|
|
|
.Draw_FadeScreen = vulkan_Draw_FadeScreen,
|
|
|
|
.Draw_BlendScreen = vulkan_Draw_BlendScreen,
|
|
|
|
.Draw_CachePic = vulkan_Draw_CachePic,
|
|
|
|
.Draw_UncachePic = vulkan_Draw_UncachePic,
|
|
|
|
.Draw_MakePic = vulkan_Draw_MakePic,
|
|
|
|
.Draw_DestroyPic = vulkan_Draw_DestroyPic,
|
|
|
|
.Draw_PicFromWad = vulkan_Draw_PicFromWad,
|
|
|
|
.Draw_Pic = vulkan_Draw_Pic,
|
2023-01-17 02:33:47 +00:00
|
|
|
.Draw_FitPic = vulkan_Draw_FitPic,
|
2022-09-25 01:18:06 +00:00
|
|
|
.Draw_Picf = vulkan_Draw_Picf,
|
|
|
|
.Draw_SubPic = vulkan_Draw_SubPic,
|
|
|
|
.Draw_AddFont = vulkan_Draw_AddFont,
|
2022-12-10 09:55:08 +00:00
|
|
|
.Draw_Glyph = vulkan_Draw_Glyph,
|
2022-09-25 01:18:06 +00:00
|
|
|
|
|
|
|
.ParticleSystem = vulkan_ParticleSystem,
|
|
|
|
.R_Init = vulkan_R_Init,
|
|
|
|
.R_ClearState = vulkan_R_ClearState,
|
|
|
|
.R_LoadSkys = vulkan_R_LoadSkys,
|
|
|
|
.R_NewScene = vulkan_R_NewScene,
|
|
|
|
.R_LineGraph = vulkan_R_LineGraph,
|
2023-01-19 03:58:02 +00:00
|
|
|
|
2022-09-25 01:18:06 +00:00
|
|
|
.set_fov = vulkan_set_fov,
|
|
|
|
|
|
|
|
.capture_screen = vulkan_capture_screen,
|
|
|
|
|
2023-07-13 06:21:53 +00:00
|
|
|
.debug_ui = vulkan_debug_ui,
|
|
|
|
|
2022-09-25 01:18:06 +00:00
|
|
|
.model_funcs = &model_funcs
|
2019-07-06 05:42:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
2021-06-26 06:43:17 +00:00
|
|
|
.shutdown = vulkan_vid_render_shutdown,
|
2019-07-06 05:42:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static general_data_t plugin_info_general_data;
|
|
|
|
|
|
|
|
static plugin_funcs_t plugin_info_funcs = {
|
2021-06-26 06:43:17 +00:00
|
|
|
.general = &plugin_info_general_funcs,
|
|
|
|
.vid_render = &vulkan_vid_render_funcs,
|
2019-07-06 05:42:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_data_t plugin_info_data = {
|
2021-06-26 06:43:17 +00:00
|
|
|
.general = &plugin_info_general_data,
|
|
|
|
.vid_render = &vid_render_data,
|
2019-07-06 05:42:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_t plugin_info = {
|
2019-07-07 05:57:56 +00:00
|
|
|
qfp_vid_render,
|
2019-07-06 05:42:53 +00:00
|
|
|
0,
|
|
|
|
QFPLUGIN_VERSION,
|
|
|
|
"0.1",
|
2019-07-07 05:59:20 +00:00
|
|
|
"Vulkan Renderer",
|
2022-05-04 05:39:47 +00:00
|
|
|
"Copyright (C) 2019 Bill Currie <bill@taniwha.org>\n"
|
2019-07-06 05:42:53 +00:00
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors",
|
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
|
|
|
|
|
|
|
PLUGIN_INFO(vid_render, vulkan)
|
|
|
|
{
|
|
|
|
return &plugin_info;
|
|
|
|
}
|