mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
Cache physical devices in the instance
This commit is contained in:
parent
494f673def
commit
d3b4e4653e
5 changed files with 30 additions and 16 deletions
|
@ -19,7 +19,7 @@ typedef struct qfv_queue_s {
|
|||
struct qfv_instance_s;
|
||||
typedef struct qfv_device_s {
|
||||
VkDevice dev;
|
||||
VkPhysicalDevice physDev;
|
||||
struct qfv_physdev_s *physDev;
|
||||
qfv_devfuncs_t *funcs;
|
||||
qfv_queue_t queue;
|
||||
struct strset_s *enabled_extensions;
|
||||
|
|
|
@ -36,6 +36,11 @@ typedef struct qfv_instfuncs_s {
|
|||
#include "QF/Vulkan/funclist.h"
|
||||
} qfv_instfuncs_t;
|
||||
|
||||
typedef struct qfv_physdev_s {
|
||||
VkPhysicalDevice dev;
|
||||
VkPhysicalDeviceMemoryProperties memory_properties;
|
||||
} qfv_physdev_t;
|
||||
|
||||
typedef struct qfv_instance_s {
|
||||
VkInstance instance;
|
||||
qfv_instfuncs_t *funcs;
|
||||
|
@ -43,6 +48,8 @@ typedef struct qfv_instance_s {
|
|||
int (*extension_enabled) (struct qfv_instance_s *inst,
|
||||
const char *ext);
|
||||
VkDebugUtilsMessengerEXT debug_handle;
|
||||
uint32_t numDevices;
|
||||
qfv_physdev_t *devices;
|
||||
} qfv_instance_t;
|
||||
|
||||
struct vulkan_ctx_s;
|
||||
|
|
|
@ -143,16 +143,10 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions)
|
|||
merge_strings (ext, extensions, 0);
|
||||
|
||||
qfv_instance_t *inst = ctx->instance;
|
||||
VkInstance instance = inst->instance;
|
||||
qfv_instfuncs_t *ifunc = inst->funcs;
|
||||
|
||||
uint32_t numDevices;
|
||||
ifunc->vkEnumeratePhysicalDevices (instance, &numDevices, 0);
|
||||
VkPhysicalDevice *devices = alloca (numDevices * sizeof (*devices));
|
||||
ifunc->vkEnumeratePhysicalDevices (instance, &numDevices, devices);
|
||||
|
||||
for (uint32_t i = 0; i < numDevices; i++) {
|
||||
VkPhysicalDevice physdev = devices[i];
|
||||
for (uint32_t i = 0; i < inst->numDevices; i++) {
|
||||
VkPhysicalDevice physdev = inst->devices[i].dev;
|
||||
/*
|
||||
if (!Vulkan_ExtensionsSupported (phys->extensions, phys->numExtensions,
|
||||
ext)) {
|
||||
|
@ -189,7 +183,7 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions)
|
|||
device->enabled_extensions = new_strset (ext);
|
||||
device->extension_enabled = device_extension_enabled;
|
||||
|
||||
device->physDev = physdev;
|
||||
device->physDev = &inst->devices[i];
|
||||
load_device_funcs (inst, device);
|
||||
device->queue.dev = device->dev;
|
||||
device->queue.funcs = dfunc;
|
||||
|
|
|
@ -256,6 +256,18 @@ QFV_CreateInstance (vulkan_ctx_t *ctx,
|
|||
setup_debug_callback (inst);
|
||||
}
|
||||
|
||||
qfv_instfuncs_t *ifunc = inst->funcs;
|
||||
ifunc->vkEnumeratePhysicalDevices (instance, &inst->numDevices, 0);
|
||||
inst->devices = malloc (inst->numDevices * sizeof (*inst->devices));
|
||||
VkPhysicalDevice *devices = alloca (inst->numDevices * sizeof (*devices));
|
||||
ifunc->vkEnumeratePhysicalDevices (instance, &inst->numDevices, devices);
|
||||
for (uint32_t i = 0; i < inst->numDevices; i++) {
|
||||
VkPhysicalDevice physDev = devices[i];
|
||||
qfv_physdev_t *dev = &inst->devices[i];
|
||||
dev->dev = physDev;
|
||||
ifunc->vkGetPhysicalDeviceMemoryProperties (physDev,
|
||||
&dev->memory_properties);
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,10 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain)
|
|||
qfv_instfuncs_t *ifuncs = ctx->instance->funcs;
|
||||
qfv_devfuncs_t *dfuncs = ctx->device->funcs;
|
||||
qfv_queue_t *queue = &ctx->device->queue;
|
||||
VkPhysicalDevice physDev = ctx->device->physDev->dev;
|
||||
|
||||
VkBool32 supported;
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceSupportKHR (ctx->device->physDev,
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceSupportKHR (physDev,
|
||||
queue->queueFamily,
|
||||
ctx->surface,
|
||||
&supported);
|
||||
|
@ -41,11 +42,11 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain)
|
|||
uint32_t numModes;
|
||||
VkPresentModeKHR *modes;
|
||||
VkPresentModeKHR useMode = VK_PRESENT_MODE_FIFO_KHR;;
|
||||
ifuncs->vkGetPhysicalDeviceSurfacePresentModesKHR (ctx->device->physDev,
|
||||
ifuncs->vkGetPhysicalDeviceSurfacePresentModesKHR (physDev,
|
||||
ctx->surface,
|
||||
&numModes, 0);
|
||||
modes = alloca (numModes * sizeof (VkPresentModeKHR));
|
||||
ifuncs->vkGetPhysicalDeviceSurfacePresentModesKHR (ctx->device->physDev,
|
||||
ifuncs->vkGetPhysicalDeviceSurfacePresentModesKHR (physDev,
|
||||
ctx->surface,
|
||||
&numModes, modes);
|
||||
for (uint32_t i = 0; i < numModes; i++) {
|
||||
|
@ -57,7 +58,7 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain)
|
|||
vulkan_presentation_mode->int_val);
|
||||
|
||||
VkSurfaceCapabilitiesKHR surfCaps;
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceCapabilitiesKHR (ctx->device->physDev,
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceCapabilitiesKHR (physDev,
|
||||
ctx->surface,
|
||||
&surfCaps);
|
||||
uint32_t numImages = surfCaps.minImageCount + 1;
|
||||
|
@ -85,11 +86,11 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain)
|
|||
VkSurfaceTransformFlagBitsKHR surfTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
|
||||
uint32_t numFormats;
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceFormatsKHR (ctx->device->physDev,
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceFormatsKHR (physDev,
|
||||
ctx->surface,
|
||||
&numFormats, 0);
|
||||
VkSurfaceFormatKHR *formats = alloca (numFormats * sizeof (*formats));
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceFormatsKHR (ctx->device->physDev,
|
||||
ifuncs->vkGetPhysicalDeviceSurfaceFormatsKHR (physDev,
|
||||
ctx->surface,
|
||||
&numFormats, formats);
|
||||
VkSurfaceFormatKHR useFormat = {VK_FORMAT_R8G8B8A8_UNORM,
|
||||
|
|
Loading…
Reference in a new issue