create vulkan instance
This commit is contained in:
@@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
typedef enum gnReturnCode {
|
typedef enum gnReturnCode {
|
||||||
GN_SUCCESS,
|
GN_SUCCESS,
|
||||||
GN_FAILED_TO_FIND_LIBARY
|
GN_FAILED_TO_FIND_LIBARY,
|
||||||
|
GN_UNSUPPORTED_BACKEND
|
||||||
} gnReturnCode;
|
} gnReturnCode;
|
||||||
|
|||||||
@@ -11,10 +11,15 @@ gnReturnCode gnCreateInstance(gnInstance* newInstance, gnInstanceCreateInfo* cre
|
|||||||
if (createInfo->backend == GN_BACKEND_METAL) {
|
if (createInfo->backend == GN_BACKEND_METAL) {
|
||||||
instance->internalLib = gnLoadLib("bin/gryphn_metal.dylib");
|
instance->internalLib = gnLoadLib("bin/gryphn_metal.dylib");
|
||||||
PFN_initBackend initBackend = (PFN_initBackend)gnLoadLibFunction(&instance->internalLib, "initBackend");
|
PFN_initBackend initBackend = (PFN_initBackend)gnLoadLibFunction(&instance->internalLib, "initBackend");
|
||||||
initBackend(instance, createInfo);
|
return initBackend(instance, createInfo);
|
||||||
|
}
|
||||||
|
if (createInfo->backend == GN_BACKEND_VULKAN) {
|
||||||
|
instance->internalLib = gnLoadLib("bin/gryphn_vulkan.so");
|
||||||
|
PFN_initBackend initBackend = (PFN_initBackend)gnLoadLibFunction(&instance->internalLib, "initBackend");
|
||||||
|
return initBackend(instance, createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_UNSUPPORTED_BACKEND;
|
||||||
}
|
}
|
||||||
gnReturnCode gnDestroyInstance(gnInstance* instance) {
|
gnReturnCode gnDestroyInstance(gnInstance* instance) {
|
||||||
(*instance)->dispatchTable.destroyInstance(*instance);
|
(*instance)->dispatchTable.destroyInstance(*instance);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
#include "gryphn_handle.h"
|
#include "gryphn_handle.h"
|
||||||
#include "vulkan/vulkan.h"
|
#include "vulkan/vulkan.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
uint32_t gnInternalIsApiSupported(gnVersion gryphnVersion) {
|
uint32_t gnInternalIsApiSupported(gnVersion gryphnVersion) {
|
||||||
if (gryphnVersion != gnCreateVersion(1, 0, 0)) return 0;
|
if (gryphnVersion != gnCreateVersion(1, 0, 0)) return 0;
|
||||||
@@ -28,27 +30,63 @@ uint32_t gnInternalIsApiSupported(gnVersion gryphnVersion) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gnReturnCode destroyBackend(gnInstance instance) {
|
gnReturnCode destroyBackend(gnInstance instance) {
|
||||||
// return GN_SUCCESS;
|
vkDestroyInstance(instance->internalData, NULL);
|
||||||
// }
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
// gnReturnCode initBackend(gnInstance instance, gnInstanceCreateInfo* info) {
|
gnReturnCode initBackend(gnInstance instance, gnInstanceCreateInfo* info) {
|
||||||
// instance->dispatchTable.destroyInstance = destroyBackend;
|
VkApplicationInfo applicationInfo = {
|
||||||
// instance->dispatchTable.enumeratePhysicalDevices = metalEnumeratePhysicalDevices;
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
// instance->dispatchTable.getPhysicalDeviceProperties = metalGetPhysicalDeviceProperties;
|
.pNext = NULL,
|
||||||
// instance->dispatchTable.createDevice = metalCreateDevice;
|
.pApplicationName = info->info.applicationName,
|
||||||
|
.applicationVersion = info->info.applicationVersion,
|
||||||
|
.pEngineName = info->info.engineName,
|
||||||
|
.engineVersion = info->info.engineVersion,
|
||||||
|
.apiVersion = VK_API_VERSION_1_0
|
||||||
|
};
|
||||||
|
|
||||||
// for (int i = 0; i < info->enabledExtensionCount; i++) {
|
|
||||||
// if (strcmp(info->enabledExtensions[i], "GN_EXT_surface") == 0) {
|
|
||||||
// instance->dispatchTable.destroySurface = metalDestroySurface;
|
|
||||||
// instance->dispatchTable.getSurfaceCapabilities = metalGetSurfaceCapabilities;
|
|
||||||
// instance->dispatchTable.getSurfaceFormats = metalGetSurfaceFormats;
|
|
||||||
// instance->dispatchTable.getSurfacePresentModes = metalGetSurfacePresentModes;
|
|
||||||
// }
|
|
||||||
// if (strcmp(info->enabledExtensions[i], "GN_EXT_surface_cocoa") == 0) {
|
|
||||||
// instance->dispatchTable.createMetalSurface = metalCreateSurface;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return GN_SUCCESS;
|
const char** extensions = malloc(sizeof(const char*) * info->enabledExtensionCount);
|
||||||
// }
|
int realEnabledExtensionCount = 0;
|
||||||
|
for (int i = 0; i < info->enabledExtensionCount; i++) {
|
||||||
|
// zero supported vulkan extensions right now
|
||||||
|
}
|
||||||
|
VkInstanceCreateInfo createInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||||
|
.pNext = NULL,
|
||||||
|
.flags = 0,
|
||||||
|
.pApplicationInfo = &applicationInfo,
|
||||||
|
.enabledLayerCount = 0,
|
||||||
|
.ppEnabledLayerNames = NULL,
|
||||||
|
.enabledExtensionCount = realEnabledExtensionCount,
|
||||||
|
.ppEnabledExtensionNames = extensions,
|
||||||
|
};
|
||||||
|
|
||||||
|
instance->dispatchTable.destroyInstance = destroyBackend;
|
||||||
|
// instance->dispatchTable.enumeratePhysicalDevices = NULL;
|
||||||
|
// instance->dispatchTable.getPhysicalDeviceProperties = NULL;
|
||||||
|
// instance->dispatchTable.createDevice = NULL;
|
||||||
|
|
||||||
|
// for (int i = 0; i < info->enabledExtensionCount; i++) {
|
||||||
|
// if (strcmp(info->enabledExtensions[i], "GN_EXT_surface") == 0) {
|
||||||
|
// instance->dispatchTable.destroySurface = metalDestroySurface;
|
||||||
|
// instance->dispatchTable.getSurfaceCapabilities = metalGetSurfaceCapabilities;
|
||||||
|
// instance->dispatchTable.getSurfaceFormats = metalGetSurfaceFormats;
|
||||||
|
// instance->dispatchTable.getSurfacePresentModes = metalGetSurfacePresentModes;
|
||||||
|
// }
|
||||||
|
// if (strcmp(info->enabledExtensions[i], "GN_EXT_surface_cocoa") == 0) {
|
||||||
|
// instance->dispatchTable.createMetalSurface = metalCreateSurface;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
VkInstance vulkanInstance;
|
||||||
|
VkResult result = vkCreateInstance(&createInfo, NULL, &vulkanInstance);
|
||||||
|
instance->internalData = vulkanInstance;
|
||||||
|
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
printf("Unknown instance fail mr gregory please diagnose this");
|
||||||
|
return GN_FAILED_TO_FIND_LIBARY;
|
||||||
|
}
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ int main() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
gnDestroySurface(instance, &surface);
|
// gnDestroySurface(instance, &surface);
|
||||||
gnDestroyDevice(&device);
|
// gnDestroyDevice(&device);
|
||||||
gnDestroyInstance(&instance);
|
gnDestroyInstance(&instance);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user