load instance functions

This commit is contained in:
Gregory Wells
2025-06-24 13:29:37 -04:00
parent 2f2baf4586
commit 93921452ba
9 changed files with 61 additions and 11 deletions

View File

@@ -1,8 +1,40 @@
#include "vulkan_loader.h"
#include "instance/vulkan_instance.h"
#include <instance/vulkan_instance.h>
#include <output_device/vulkan_physical_device.h>
#include <output_device/vulkan_output_devices.h>
#include <vulkan_surface/vulkan_surface.h>
gnInstanceFunctions loadVulkanFunctions(gnRenderingAPI api) {
return (gnInstanceFunctions){
._gnCreateInstance = createInstance
._gnCreateInstance = createInstance,
._gnDestroyInstance = destroyInstance,
._gnGetPhysicalDevices = getPhysicalDevices,
._gnQueueCanPresentToSurface = queueCanPresentToSurface,
._gnCreateOutputDevice = createOutputDevice,
._gnDestroyOutputDevice = destroyOutputDevice,
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
._gnCreateX11WindowSurface = createX11WindowSurface,
#endif
#ifdef GN_WINDOW_WAYLAND
._gnCreateWaylandWindowSurface
#endif
#endif
#ifdef GN_PLATFORM_WIN32
._gnCreateWin32WindowSurface
#endif
#ifdef GN_PLATFORM_MACOS
._gnCreateMacOSWindowSurface
#endif
._gnDestroyWindowSurface = destroyWindowSurface,
._gnGetSurfaceDetails = getSurfaceDetails
};
}

View File

@@ -129,7 +129,7 @@ gnReturnCode createInstance(gnInstanceHandle instance, gnInstanceInfo instanceIn
return GN_SUCCESS;
}
void gnDestroyInstanceFn(gnInstanceHandle instance) {
void destroyInstance(gnInstanceHandle instance) {
instance->valid = gnFalse;
vkDestroyInstance(instance->instance->vk_instance, NULL);
}

View File

@@ -8,3 +8,4 @@ typedef struct gnPlatformInstance_t {
} gnPlatformInstance;
gnReturnCode createInstance(gnInstanceHandle instance, gnInstanceInfo instanceInfo);
void destroyInstance(gnInstanceHandle instance);

View File

@@ -5,7 +5,7 @@
#include "instance/gryphn_instance.h"
#include "commands/command_buffer/vulkan_command_buffer.h"
gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
VkDeviceQueueCreateInfo* queueCreateInfos = malloc(sizeof(VkDeviceQueueCreateInfo) * deviceInfo.queueInfoCount);
@@ -90,11 +90,11 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanc
return GN_SUCCESS;
}
void gnWaitForDeviceFn(const gnOutputDeviceHandle device) {
void waitForDevice(const gnOutputDeviceHandle device) {
vkDeviceWaitIdle(device->outputDevice->device);
}
void gnDestroyOutputDeviceFn(gnOutputDeviceHandle device) {
void destroyOutputDevice(gnOutputDeviceHandle device) {
vkDestroyCommandPool(device->outputDevice->device, device->outputDevice->transferCommandPool, NULL);
vkDestroyDevice(device->outputDevice->device, NULL);
free(device->outputDevice);

View File

@@ -15,3 +15,8 @@ typedef struct gnPlatformOutputDevice_t {
VkCommandBuffer gnBeginVulkanTransferOperation(gnDevice device);
void gnEndVulkanTransferOperation(gnDevice device, VkCommandBuffer commandBuffer);
gnReturnCode createOutputDevice(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo);
void waitForDevice(const gnOutputDeviceHandle device);
void destroyOutputDevice(gnOutputDeviceHandle device);

View File

@@ -3,7 +3,7 @@
#include <output_device/vulkan_device_extensions.h>
#include <vulkan_surface/vulkan_surface.h>
gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* deviceCount) {
gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* deviceCount) {
vkEnumeratePhysicalDevices(instance->instance->vk_instance, deviceCount, NULL);
if (deviceCount == 0)
return NULL;
@@ -49,7 +49,7 @@ gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* de
return outputDevices;
}
gnBool gnQueueCanPresentToSurfaceFn(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
gnBool queueCanPresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
VkBool32 supportsPresent = VK_FALSE;
vkGetPhysicalDeviceSurfaceSupportKHR(device.physicalDevice->device, queueIndex, windowSurface->windowSurface->surface, &supportsPresent);
if (supportsPresent)

View File

@@ -5,3 +5,6 @@
typedef struct gnPlatformPhysicalDevice_t {
VkPhysicalDevice device;
} gnPlatformPhysicalDevice;
gnPhysicalDevice* getPhysicalDevices(gnInstanceHandle instance, uint32_t* deviceCount);
gnBool queueCanPresentToSurface(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface);

View File

@@ -9,7 +9,7 @@
#ifdef GN_WINDOW_X11
#include <vulkan/vulkan_xlib.h>
#include <X11/Xlib.h>
gnReturnCode gnCreateX11WindowSurfaceFn(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo) {
gnReturnCode createX11WindowSurface(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo) {
windowSurface->windowSurface = malloc(sizeof(struct gnPlatformWindowSurface_t));
VkXlibSurfaceCreateInfoKHR info = {};
info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
@@ -57,7 +57,7 @@ gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface,
#endif
void gnDestroyWindowSurfaceFn(struct gnWindowSurface_t* windowSurface) {
void destroyWindowSurface(struct gnWindowSurface_t* windowSurface) {
vkDestroySurfaceKHR(windowSurface->instance->instance->vk_instance, windowSurface->windowSurface->surface, NULL);
}
@@ -88,7 +88,7 @@ gnSurfaceFormat* vkGetSurfaceFormats(
return formats;
}
gnSurfaceDetails gnGetSurfaceDetailsFn(
gnSurfaceDetails getSurfaceDetails(
gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device
) {
gnSurfaceDetails surfaceDetails;

View File

@@ -8,3 +8,12 @@ typedef struct gnPlatformWindowSurface_t {
VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format);
VkColorSpaceKHR vkGryphnColorSpaceToVulkanColorSpace(gnColorSpace colorSpace);
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode createX11WindowSurface(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo);
#endif
#endif
gnSurfaceDetails getSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device);
void destroyWindowSurface(gnWindowSurface windowSurface);