Compare commits
7 Commits
e8e54c0c0d
...
f39024c045
| Author | SHA1 | Date | |
|---|---|---|---|
| f39024c045 | |||
| b0c36a6bea | |||
| ebaf4fde0a | |||
| 9387e8afd9 | |||
| c51c05fb08 | |||
| 55889a32d4 | |||
| 7a952fcb19 |
@@ -1,5 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
project(ChemistryRenderingApp LANGUAGES C CXX)
|
project(ChemistryRenderingApp LANGUAGES C CXX)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
add_executable(ChemistryRenderingApp main.mm)
|
add_executable(ChemistryRenderingApp main.mm)
|
||||||
target_link_libraries(ChemistryRenderingApp PRIVATE
|
target_link_libraries(ChemistryRenderingApp PRIVATE
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ typedef struct gnApplicationInfo {
|
|||||||
const char* applicationName;
|
const char* applicationName;
|
||||||
gnVersion applicationVersion;
|
gnVersion applicationVersion;
|
||||||
const char* engineName;
|
const char* engineName;
|
||||||
gnVersion enginnVersion;
|
gnVersion engineVersion;
|
||||||
} gnApplicationInfo;
|
} gnApplicationInfo;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "instance/gryphn_instance.h"
|
#include "instance/gryphn_instance.h"
|
||||||
#include "gryphn_handle.h"
|
#include "gryphn_handle.h"
|
||||||
#include "vulkan/vulkan.h"
|
#include "stdlib.h"
|
||||||
|
#include <vulkan/vulkan_core.h>
|
||||||
|
#include "vulkan_functions.h"
|
||||||
|
|
||||||
|
gnReturnCode vulkanCodeToGryphnCode(VkResult result) {
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
printf("Unknown instance fail mr gregory please diagnose this: %u", result);
|
||||||
|
return GN_FAILED_TO_FIND_LIBARY;
|
||||||
|
}
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
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 +38,58 @@ 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 = vulkanEnumeratePhysicalDevices;
|
||||||
|
instance->dispatchTable.getPhysicalDeviceProperties = vulkanGetPhysicalDeviceProperties;
|
||||||
|
instance->dispatchTable.createDevice = vulkanCreateDevice;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
return vulkanCodeToGryphnCode(result);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
#include "stdlib.h"
|
||||||
|
#include "gryphn_return_code.h"
|
||||||
|
#include "vulkan_functions.h"
|
||||||
|
#include "vulkan_helpers.h"
|
||||||
|
#include "instance/gryphn_instance.h"
|
||||||
|
#include "device/gryphn_physical_device.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
|
gnPhysicalDeviceType vulkanDeviceTypeToGryphnDeviceType(VkPhysicalDeviceType type) {
|
||||||
|
switch (type) {
|
||||||
|
case VK_PHYSICAL_DEVICE_TYPE_OTHER: return GN_PHYSICAL_DEVICE_TYPE_OTHER;
|
||||||
|
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: return GN_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
|
||||||
|
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: return GN_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
|
||||||
|
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: return GN_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
|
||||||
|
case VK_PHYSICAL_DEVICE_TYPE_CPU: return GN_PHYSICAL_DEVICE_TYPE_CPU;
|
||||||
|
case VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM: return GN_PHYSICAL_DEVICE_TYPE_OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gnReturnCode vulkanEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices) {
|
||||||
|
if (devices == NULL) {
|
||||||
|
vkEnumeratePhysicalDevices(instance->internalData, deviceCount, NULL);
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPhysicalDevice* vulkanDevices = malloc(sizeof(VkPhysicalDevice) * (*deviceCount));
|
||||||
|
VkResult result = vkEnumeratePhysicalDevices(instance->internalData, deviceCount, vulkanDevices);
|
||||||
|
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
free(vulkanDevices);
|
||||||
|
return vulkanCodeToGryphnCode(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < *deviceCount; i++) {
|
||||||
|
devices[i] = malloc(sizeof(gnPhysicalDevice_t));
|
||||||
|
devices[i]->instance = instance;
|
||||||
|
devices[i]->internalData = vulkanDevices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
free(vulkanDevices);
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
gnReturnCode vulkanGetPhysicalDeviceProperties(gnPhysicalDevice device, gnPhysicalDeviceProperties* properties) {
|
||||||
|
VkPhysicalDeviceProperties deviceProperties;
|
||||||
|
vkGetPhysicalDeviceProperties(device->internalData, &deviceProperties);
|
||||||
|
|
||||||
|
*properties = (gnPhysicalDeviceProperties){
|
||||||
|
.apiVersion = deviceProperties.apiVersion,
|
||||||
|
.vendorID = deviceProperties.vendorID,
|
||||||
|
.deviceID = deviceProperties.deviceID,
|
||||||
|
.deviceType = vulkanDeviceTypeToGryphnDeviceType(deviceProperties.deviceType),
|
||||||
|
};
|
||||||
|
strcpy(properties->deviceName, deviceProperties.deviceName);
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
gnReturnCode vulkanCreateDevice(gnInstance instance, gnDeviceCreateInfo* info, gnDevice device) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPhysicalDeviceFeatures deviceFeatures = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
VkDeviceCreateInfo createInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
|
.pNext = NULL,
|
||||||
|
.flags = 0,
|
||||||
|
.queueCreateInfoCount = 0,
|
||||||
|
.pQueueCreateInfos = NULL,
|
||||||
|
.enabledExtensionCount = realEnabledExtensionCount,
|
||||||
|
.ppEnabledExtensionNames = extensions,
|
||||||
|
.pEnabledFeatures = &deviceFeatures,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkDevice vulkanDevice;
|
||||||
|
VkResult result = vkCreateDevice(info->physicalDevice->internalData, &createInfo, NULL, &vulkanDevice);
|
||||||
|
device->internalData = vulkanDevice;
|
||||||
|
|
||||||
|
device->dispatchTable.destroyDevice = vulkanDestroyDevice;
|
||||||
|
|
||||||
|
return vulkanCodeToGryphnCode(result);
|
||||||
|
}
|
||||||
|
gnReturnCode vulkanDestroyDevice(gnDevice device) {
|
||||||
|
vkDestroyDevice(device->internalData, NULL);
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "gryphn_handle.h"
|
||||||
|
#include "gryphn_return_code.h"
|
||||||
|
#include "device/gryphn_physical_device.h"
|
||||||
|
#include "device/gryphn_device.h"
|
||||||
|
|
||||||
|
gnReturnCode vulkanEnumeratePhysicalDevices(gnInstance instance, uint32_t* deviceCount, gnPhysicalDevice* devices);
|
||||||
|
gnReturnCode vulkanGetPhysicalDeviceProperties(gnPhysicalDevice device, gnPhysicalDeviceProperties* properties);
|
||||||
|
gnReturnCode vulkanCreateDevice(gnInstance instance, gnDeviceCreateInfo* createInfo, gnDevice device);
|
||||||
|
gnReturnCode vulkanDestroyDevice(gnDevice device);
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "gryphn_return_code.h"
|
||||||
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
|
gnReturnCode vulkanCodeToGryphnCode(VkResult result);
|
||||||
@@ -32,7 +32,7 @@ void createInstance() {
|
|||||||
CHECK(gnGetAvaliableBackends(version, &backendCount, backends));
|
CHECK(gnGetAvaliableBackends(version, &backendCount, backends));
|
||||||
const char* extensions[2] = {
|
const char* extensions[2] = {
|
||||||
"GN_EXT_surface",
|
"GN_EXT_surface",
|
||||||
"GN_EXT_surface_cocoa"
|
"GN_EXT_surface_xlib"
|
||||||
};
|
};
|
||||||
|
|
||||||
gnInstanceCreateInfo createInfo = {
|
gnInstanceCreateInfo createInfo = {
|
||||||
@@ -41,7 +41,7 @@ void createInstance() {
|
|||||||
.applicationName = "Chemistry Rendering App",
|
.applicationName = "Chemistry Rendering App",
|
||||||
.applicationVersion = gnCreateVersion(0, 0, 1),
|
.applicationVersion = gnCreateVersion(0, 0, 1),
|
||||||
.engineName = "Chemistry Rendering Engine",
|
.engineName = "Chemistry Rendering Engine",
|
||||||
.enginnVersion = gnCreateVersion(0, 0, 1)
|
.engineVersion = gnCreateVersion(0, 0, 1)
|
||||||
},
|
},
|
||||||
.enabledValidationLayerCount = 0,
|
.enabledValidationLayerCount = 0,
|
||||||
.enabledValidationLayers = nullptr,
|
.enabledValidationLayers = nullptr,
|
||||||
@@ -66,7 +66,6 @@ void createDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pysicalDevice = devices[0];
|
pysicalDevice = devices[0];
|
||||||
|
|
||||||
const char* extensions[1] = {
|
const char* extensions[1] = {
|
||||||
"GN_EXT_swapchain"
|
"GN_EXT_swapchain"
|
||||||
};
|
};
|
||||||
@@ -115,7 +114,7 @@ int main() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
createInstance();
|
createInstance();
|
||||||
// createDevice();
|
createDevice();
|
||||||
// createSurface();
|
// createSurface();
|
||||||
// createSwapchain();
|
// createSwapchain();
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
@@ -126,7 +125,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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ void createInstance() {
|
|||||||
.applicationName = "Chemistry Rendering App",
|
.applicationName = "Chemistry Rendering App",
|
||||||
.applicationVersion = gnCreateVersion(0, 0, 1),
|
.applicationVersion = gnCreateVersion(0, 0, 1),
|
||||||
.engineName = "Chemistry Rendering Engine",
|
.engineName = "Chemistry Rendering Engine",
|
||||||
.enginnVersion = gnCreateVersion(0, 0, 1)
|
.engineVersion = gnCreateVersion(0, 0, 1)
|
||||||
},
|
},
|
||||||
.enabledValidationLayerCount = 0,
|
.enabledValidationLayerCount = 0,
|
||||||
.enabledValidationLayers = nullptr,
|
.enabledValidationLayers = nullptr,
|
||||||
|
|||||||
Reference in New Issue
Block a user