mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
Remove global vulkan_ctx
While I can't say that I'm happy with the details of vulkan_ctx_t, I am pretty sure I don't want to be limited to having only one.
This commit is contained in:
parent
707bdfc5f2
commit
b3d982bfc3
6 changed files with 36 additions and 31 deletions
|
@ -52,7 +52,7 @@ typedef struct {
|
|||
VkQueueFamilyProperties *queueFamilies;
|
||||
} VulkanPhysDevice_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct VulkanInstance_s {
|
||||
VkInstance instance;
|
||||
VkDebugUtilsMessengerEXT debug_callback;
|
||||
uint32_t numDevices;
|
||||
|
@ -64,7 +64,9 @@ typedef struct {
|
|||
} VulkanInstance_t;
|
||||
|
||||
void Vulkan_Init_Cvars (void);
|
||||
VulkanInstance_t *Vulkan_CreateInstance (const char *appName,
|
||||
struct vulkan_ctx_s;
|
||||
VulkanInstance_t *Vulkan_CreateInstance (struct vulkan_ctx_s *ctx,
|
||||
const char *appName,
|
||||
uint32_t appVersion,
|
||||
const char **layers,
|
||||
const char **extensions);
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
|
||||
#include "QF/Vulkan/cvars.h"
|
||||
|
||||
void Vulkan_Init_Common (void);
|
||||
void Vulkan_Shutdown_Common (void);
|
||||
struct vulkan_ctx_s;
|
||||
void Vulkan_Init_Common (struct vulkan_ctx_s *ctx);
|
||||
void Vulkan_Shutdown_Common (struct vulkan_ctx_s *ctx);
|
||||
|
||||
#endif // __QF_Vulkan_vid_h
|
||||
|
|
|
@ -10,18 +10,18 @@ typedef struct vulkan_ctx_s {
|
|||
void (*load_vulkan) (struct vulkan_ctx_s *ctx);
|
||||
void (*unload_vulkan) (struct vulkan_ctx_s *ctx);
|
||||
|
||||
const char * const *required_extensions;
|
||||
const char **required_extensions;
|
||||
struct vulkan_presentation_s *presentation;
|
||||
int (*get_presentation_support) (struct vulkan_ctx_s *ctx,
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex);
|
||||
VkSurfaceKHR (*create_surface) (struct vulkan_ctx_s *ctx);
|
||||
|
||||
struct VulkanInstance_s *vtx;
|
||||
VkInstance instance;
|
||||
#define EXPORTED_VULKAN_FUNCTION(fname) PFN_##fname fname;
|
||||
#define GLOBAL_LEVEL_VULKAN_FUNCTION(fname) PFN_##fname fname;
|
||||
#include "QF/Vulkan/funclist.h"
|
||||
} vulkan_ctx_t;
|
||||
|
||||
extern vulkan_ctx_t *vulkan_ctx;
|
||||
|
||||
#endif//__vid_vulkan_h
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
#include "vulkan/namehack.h"
|
||||
|
||||
vulkan_ctx_t *vulkan_ctx;
|
||||
static vulkan_ctx_t *vulkan_ctx;
|
||||
|
||||
static vid_model_funcs_t model_funcs = {
|
||||
/* vulkan_Mod_LoadExternalTextures,
|
||||
|
@ -153,7 +153,7 @@ vulkan_vid_render_init (void)
|
|||
vulkan_ctx = vr_data.vid->vid_internal->vulkan_context ();
|
||||
vulkan_ctx->load_vulkan (vulkan_ctx);
|
||||
|
||||
Vulkan_Init_Common ();
|
||||
Vulkan_Init_Common (vulkan_ctx);
|
||||
|
||||
vr_data.vid->vid_internal->set_palette = set_palette;
|
||||
vr_data.vid->vid_internal->choose_visual = vulkan_vid_render_choose_visual;
|
||||
|
@ -166,7 +166,7 @@ vulkan_vid_render_init (void)
|
|||
static void
|
||||
vulkan_vid_render_shutdown (void)
|
||||
{
|
||||
Vulkan_Shutdown_Common ();
|
||||
Vulkan_Shutdown_Common (vulkan_ctx);
|
||||
}
|
||||
|
||||
static general_funcs_t plugin_info_general_funcs = {
|
||||
|
|
|
@ -73,15 +73,15 @@ static const char *device_types[] = {
|
|||
};
|
||||
|
||||
static void
|
||||
get_instance_layers_and_extensions (void)
|
||||
get_instance_layers_and_extensions (vulkan_ctx_t *ctx)
|
||||
{
|
||||
uint32_t i;
|
||||
VkLayerProperties *properties;
|
||||
VkExtensionProperties *extensions;
|
||||
|
||||
vulkan_ctx->vkEnumerateInstanceLayerProperties (&numLayers, 0);
|
||||
ctx->vkEnumerateInstanceLayerProperties (&numLayers, 0);
|
||||
properties = malloc (numLayers * sizeof (VkLayerProperties));
|
||||
vulkan_ctx->vkEnumerateInstanceLayerProperties (&numLayers, properties);
|
||||
ctx->vkEnumerateInstanceLayerProperties (&numLayers, properties);
|
||||
instanceLayerNames = (const char **) malloc ((numLayers + 1)
|
||||
* sizeof (const char **));
|
||||
for (i = 0; i < numLayers; i++) {
|
||||
|
@ -89,9 +89,9 @@ get_instance_layers_and_extensions (void)
|
|||
}
|
||||
instanceLayerNames[i] = 0;
|
||||
|
||||
vulkan_ctx->vkEnumerateInstanceExtensionProperties (0, &numExtensions, 0);
|
||||
ctx->vkEnumerateInstanceExtensionProperties (0, &numExtensions, 0);
|
||||
extensions = malloc (numExtensions * sizeof (VkLayerProperties));
|
||||
vulkan_ctx->vkEnumerateInstanceExtensionProperties (0, &numExtensions,
|
||||
ctx->vkEnumerateInstanceExtensionProperties (0, &numExtensions,
|
||||
extensions);
|
||||
instanceExtensionNames = (const char **) malloc ((numExtensions + 1)
|
||||
* sizeof (const char **));
|
||||
|
@ -277,19 +277,19 @@ setup_debug_callback (VulkanInstance_t *instance)
|
|||
}
|
||||
|
||||
static void
|
||||
load_instance_funcs (VulkanInstance_t *instance)
|
||||
load_instance_funcs (vulkan_ctx_t *ctx)
|
||||
{
|
||||
VulkanInstance_t *vtx = ctx->vtx;
|
||||
VkInstance instance = vtx->instance;
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION(name) \
|
||||
instance->name = (PFN_##name) \
|
||||
vulkan_ctx->vkGetInstanceProcAddr (instance->instance, #name); \
|
||||
if (!instance->name) { \
|
||||
vtx->name = (PFN_##name) ctx->vkGetInstanceProcAddr (instance, #name); \
|
||||
if (!vtx->name) { \
|
||||
Sys_Error ("Couldn't find instance level function %s", #name); \
|
||||
}
|
||||
|
||||
#define INSTANCE_LEVEL_VULKAN_FUNCTION_EXTENSION(name) \
|
||||
instance->name = (PFN_##name) \
|
||||
vulkan_ctx->vkGetInstanceProcAddr (instance->instance, #name); \
|
||||
if (!instance->name) { \
|
||||
vtx->name = (PFN_##name) ctx->vkGetInstanceProcAddr (instance, #name); \
|
||||
if (!vtx->name) { \
|
||||
Sys_Printf ("Couldn't find instance level function %s", #name); \
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,8 @@ load_instance_funcs (VulkanInstance_t *instance)
|
|||
}
|
||||
|
||||
VulkanInstance_t *
|
||||
Vulkan_CreateInstance (const char *appName, uint32_t appVersion,
|
||||
Vulkan_CreateInstance (vulkan_ctx_t *ctx,
|
||||
const char *appName, uint32_t appVersion,
|
||||
const char **layers, const char **extensions)
|
||||
{
|
||||
VkApplicationInfo appInfo = {
|
||||
|
@ -319,7 +320,7 @@ Vulkan_CreateInstance (const char *appName, uint32_t appVersion,
|
|||
VulkanInstance_t *inst;
|
||||
|
||||
if (!instanceLayerProperties) {
|
||||
get_instance_layers_and_extensions ();
|
||||
get_instance_layers_and_extensions (ctx);
|
||||
}
|
||||
|
||||
createInfo.enabledLayerCount = count_strings (layers);
|
||||
|
@ -346,13 +347,14 @@ Vulkan_CreateInstance (const char *appName, uint32_t appVersion,
|
|||
createInfo.ppEnabledLayerNames = lay;
|
||||
createInfo.ppEnabledExtensionNames = ext;
|
||||
|
||||
res = vulkan_ctx->vkCreateInstance (&createInfo, 0, &instance);
|
||||
res = ctx->vkCreateInstance (&createInfo, 0, &instance);
|
||||
if (res != VK_SUCCESS) {
|
||||
Sys_Error ("unable to create vulkan instance\n");
|
||||
}
|
||||
inst = malloc (sizeof(VulkanInstance_t));
|
||||
inst->instance = instance;
|
||||
load_instance_funcs (inst);
|
||||
ctx->vtx = inst;
|
||||
load_instance_funcs (ctx);
|
||||
|
||||
if (vulkan_use_validation->int_val) {
|
||||
setup_debug_callback (inst);
|
||||
|
|
|
@ -168,25 +168,25 @@ create_suitable_device (VulkanInstance_t *instance)
|
|||
int x = 1;
|
||||
|
||||
void
|
||||
Vulkan_Init_Common (void)
|
||||
Vulkan_Init_Common (vulkan_ctx_t *ctx)
|
||||
{
|
||||
Sys_Printf ("Vulkan_Init_Common\n");
|
||||
Vulkan_Init_Cvars ();
|
||||
|
||||
vulkan_instance = Vulkan_CreateInstance (PACKAGE_STRING, 0x000702ff, 0, instance_extensions);//FIXME version
|
||||
vulkan_instance = Vulkan_CreateInstance (ctx, PACKAGE_STRING, 0x000702ff, 0, instance_extensions);//FIXME version
|
||||
vulkan_device = create_suitable_device (vulkan_instance);
|
||||
if (!vulkan_device) {
|
||||
Sys_Error ("no suitable vulkan device found");
|
||||
}
|
||||
// only for now...
|
||||
Sys_Printf ("%p %p\n", vulkan_device->device, vulkan_device->queue);
|
||||
Vulkan_Shutdown_Common ();
|
||||
Vulkan_Shutdown_Common (ctx);
|
||||
if (x)
|
||||
Sys_Quit();
|
||||
}
|
||||
|
||||
void
|
||||
Vulkan_Shutdown_Common (void)
|
||||
Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
|
||||
{
|
||||
if (vulkan_device) {
|
||||
vulkan_device->vkDestroyDevice (vulkan_device->device, 0);
|
||||
|
@ -195,5 +195,5 @@ Vulkan_Shutdown_Common (void)
|
|||
}
|
||||
Vulkan_DestroyInstance (vulkan_instance);
|
||||
vulkan_instance = 0;
|
||||
vulkan_ctx->unload_vulkan (vulkan_ctx);
|
||||
ctx->unload_vulkan (ctx);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue