get vulkan functions up and running

This commit is contained in:
Gregory Wells
2026-05-25 12:52:56 -04:00
parent 587f3cd224
commit 0eff3c62ee
9 changed files with 66 additions and 17 deletions
@@ -0,0 +1,10 @@
#include "gryphn_swapchain.h"
#include "gryphn_return_code.h"
#include <device/gryphn_device.h>
gnReturnCode gnCreateSwapchain(gnDevice device, gnSwapchainCreateInfo* createInfo, gnSwapchain* swapchain) {
return device->dispatchTable.createSwapchain(device, createInfo, swapchain);
}
gnReturnCode gnDestroySwapchain(gnDevice device, gnSwapchain* swapchain) {
return device->dispatchTable.destroySwapchain(device, swapchain);
}
@@ -0,0 +1,20 @@
#pragma once
#include <gryphn_handle.h>
#include "core/gryphn_format.h"
#include "core/gryphn_present_mode.h"
#include "core/gryphn_vec2d.h"
#include "gryphn_return_code.h"
#include "stdint.h"
typedef struct gnSwapchainCreateInfo {
gnSurface surface;
uint32_t minImageCount;
gnFormat imageFormat;
gnColorSpace imageColorSpace;
gnExtent2D imageExtent;
uint32_t imageArrayLayers;
gnPresentMode presentMode;
} gnSwapchainCreateInfo;
gnReturnCode gnCreateSwapchain(gnDevice device, gnSwapchainCreateInfo* createInfo, gnSwapchain* swapchain);
gnReturnCode gnDestroySwapchain(gnDevice device, gnSwapchain* swapchain);
@@ -1,8 +1,13 @@
#pragma once
#include "gryphn_handle.h"
typedef struct gnSwapchainCreateInfo gnSwapchainCreateInfo;
typedef gnReturnCode (*PFN_gnDestroyDevice)(gnDevice);
typedef gnReturnCode (*PFN_gnCreateSwapchain)(gnDevice, gnSwapchainCreateInfo*, gnSwapchain*);
typedef gnReturnCode (*PFN_gnDestroySwapchain)(gnDevice, gnSwapchain*);
typedef struct gnDeviceDispatchTable {
PFN_gnDestroyDevice destroyDevice;
PFN_gnCreateSwapchain createSwapchain;
PFN_gnDestroySwapchain destroySwapchain;
} gnDeviceDispatchTable;
@@ -0,0 +1,9 @@
#include "../vulkan_functions.h"
#include "gryphn_return_code.h"
gnReturnCode vulkanCreateSwapchain(gnDevice device, gnSwapchainCreateInfo* createInfo, gnSwapchain* swapchain) {
return GN_UNSUPPORTED_BACKEND;
}
gnReturnCode vulkanDestroySwapchain(gnDevice device, gnSwapchain* swapchain) {
return GN_UNSUPPORTED_BACKEND;
}
@@ -64,6 +64,8 @@ gnReturnCode vulkanCreateDevice(gnInstance instance, gnDeviceCreateInfo* info, g
if (strcmp(info->enabledExtensions[i], "GN_EXT_swapchain") == 0) {
extensions[realEnabledExtensionCount] = VK_KHR_SWAPCHAIN_EXTENSION_NAME;
realEnabledExtensionCount++;
device->dispatchTable.createSwapchain = vulkanCreateSwapchain;
device->dispatchTable.destroySwapchain = vulkanDestroySwapchain;
}
}
@@ -15,3 +15,5 @@ gnReturnCode vulkanGetSurfaceCapabilities(gnPhysicalDevice device, gnSurface sur
gnReturnCode vulkanGetSurfaceFormats(gnPhysicalDevice device, gnSurface surface, uint32_t* formatCount, gnSurfaceFormat* formats);
gnReturnCode vulkanGetSurfacePresentModes(gnPhysicalDevice device, gnSurface surface, uint32_t* presentModeCount, gnPresentMode* presentModes);
gnReturnCode vulkanDestroySurface(gnInstance instance, gnSurface* surface);
gnReturnCode vulkanCreateSwapchain(gnDevice device, gnSwapchainCreateInfo* createInfo, gnSwapchain* swapchain);
gnReturnCode vulkanDestroySwapchain(gnDevice device, gnSwapchain* swapchain);
+1
View File
@@ -7,6 +7,7 @@ extern "C" {
#include "GryphnLoader/src/device/gryphn_physical_device.h"
#include "GryphnLoader/src/device/gryphn_device.h"
#include "GryphnLoader/src/ext/instance/surface/gryphn_surface.h"
#include "GryphnLoader/src/ext/device/swapchain/gryphn_swapchain.h"
#ifdef __cplusplus
}
#endif
+17 -17
View File
@@ -23,7 +23,7 @@ gnDevice device;
gnSurface surface;
gnSwapchain swapchain;
int min(int a, int b) {
uint32_t min(uint32_t a, uint32_t b) {
if (a < b) return a;
return b;
}
@@ -129,25 +129,25 @@ gnPresentMode getPresentMode() {
void createSwapchain() {
// gnSurfaceCapabilities capabilites;
// gnGetSurfaceCapabilities(pysicalDevice, surface, &capabilites);
gnSurfaceCapabilities capabilites;
gnGetSurfaceCapabilities(pysicalDevice, surface, &capabilites);
// gnSurfaceFormat chosenFormat = getSurfaceFormat();
// gnPresentMode chosenMode = getPresentMode();
gnSurfaceFormat chosenFormat = getSurfaceFormat();
gnPresentMode chosenMode = getPresentMode();
// int width, height;
// glfwGetWindowSize(window, &width, &height);
int width, height;
glfwGetWindowSize(window, &width, &height);
// gnSwapchainCreateInfo createInfo = {
// .surface = surface,
// .minImageCount = min(capabilites.minImageCount + 1, capabilites.maxImageCount),
// .imageFormat = chosenFormat.format,
// .imageColorSpace = chosenFormat.colorSpace,
// .imageExtent = { width, height },
// .imageArrayLayers = 1,
// .presentMode = chosenMode,
// };
// CHECK(gnCreateSwapchain(device, &createInfo, &swapchain));
gnSwapchainCreateInfo createInfo = {
.surface = surface,
.minImageCount = min(capabilites.minImageCount + 1, capabilites.maxImageCount),
.imageFormat = chosenFormat.format,
.imageColorSpace = chosenFormat.colorSpace,
.imageExtent = { (uint32_t)width, (uint32_t)height },
.imageArrayLayers = 1,
.presentMode = chosenMode,
};
CHECK(gnCreateSwapchain(device, &createInfo, &swapchain));
}
int main() {