From b1fab45e53ecbb51a3e862e33ca84738ca9683cb Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Sat, 24 May 2025 14:46:26 -0400 Subject: [PATCH] do some more C stuff --- include/gryphn/gryphn_utils.h | 6 +- .../vulkan_presentation_details.c | 14 ++ .../vulkan_presentation_queue.c | 124 ++++++++++++++++++ src/core/gryphn_platform_functions.h | 3 +- src/core/instance/init/gryphn_init.c | 2 +- .../gryphn_device_presentation_details.h | 9 -- .../gryphn_presentation_details.h | 7 - .../gryphn_presentation_queue.c | 5 + .../gryphn_presentation_queue.h | 10 +- 9 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 rendering_api/vulkan/src/presentation_queue/vulkan_presentation_details.c create mode 100644 rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c delete mode 100644 src/core/presentation_queue/gryphn_device_presentation_details.h delete mode 100644 src/core/presentation_queue/gryphn_presentation_details.h diff --git a/include/gryphn/gryphn_utils.h b/include/gryphn/gryphn_utils.h index d9be1c8..baf82e9 100644 --- a/include/gryphn/gryphn_utils.h +++ b/include/gryphn/gryphn_utils.h @@ -1,8 +1,8 @@ #pragma once -// #include +#include #include #include -// #include +#include // #include // #include // #include @@ -10,7 +10,7 @@ // #include // #include -// typedef uint32_t gnUInt; +typedef uint32_t gnUInt; // typedef gnChar gnByte; // typedef unsigned char gnUByte; // typedef int gnInt; diff --git a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_details.c b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_details.c new file mode 100644 index 0000000..554065d --- /dev/null +++ b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_details.c @@ -0,0 +1,14 @@ +// #include "vulkan_swapchain.h" +// #include "core/presentation_queue/gryphn_device_presentation_details.h" +// #include "../output_device/vulkan_output_devices.h" +// #include "../instance/vulkan_instance.h" + +// GN_EXPORT gnDevicePresentationDetails gnGetDevicePresentationDetailsFn(const gnPhysicalOutputDevice& physicalOutputDevice) { +// SwapChainSupportDetails swapChainSupport = querySwapChainSupport(physicalOutputDevice.physicalOutputDevice->instance->instance->window_surface, physicalOutputDevice.physicalOutputDevice->device); + +// gnDevicePresentationDetails presentationDetails = gnDevicePresentationDetails{}; +// presentationDetails.MinimumImageCount = swapChainSupport.capabilities.minImageCount; +// presentationDetails.MaximumImageCount = swapChainSupport.capabilities.maxImageCount; + +// return presentationDetails; +// } diff --git a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c new file mode 100644 index 0000000..7e9973f --- /dev/null +++ b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -0,0 +1,124 @@ +#include "vulkan_presentation_queue.h" + +gnReturnCode gnCreatePresentationQueueFn() { + +} + +// #include "core/presentation_queue/gryphn_presentation_queue.h" +// #include "vulkan_queue_families.h" +// #include "vulkan_swapchain_support.h" +// #include "vulkan_presentation_queue.h" +// #include "../sync_objects/vulkan_sync_semaphore.h" +// #include "../textures/vulkan_texture.h" +// #include "../instance/vulkan_instance.h" + +// GN_EXPORT gnImageFormat gnPresentationQueueGetImageFormatFn(gnPresentationQueue& presentationQueue) { +// return (gnImageFormat)presentationQueue.presentationQueue->swapchainDetails.surfaceFormat.format; +// } + +// GN_EXPORT gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice& device, gnPresentationDetails& details) { +// presentationQueue->presentationQueue = new gnPlatformPresentationQueue(); +// presentationQueue->presentationQueue->outputDevice = const_cast(&device); + +// vulkanSwapchainDetails swapchain_details = vulkanGetSwapchainDetails( +// { (float)details.ImageSize.x, (float)details.ImageSize.y }, +// device.physicalOutputDevice->physicalOutputDevice->instance->instance->window_surface, +// device.physicalOutputDevice->physicalOutputDevice->device +// ); +// presentationQueue->presentationQueue->swapchainDetails = swapchain_details; + +// VkSwapchainCreateInfoKHR createInfo{}; +// createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; +// createInfo.surface = device.physicalOutputDevice->physicalOutputDevice->instance->instance->window_surface; + +// createInfo.minImageCount = details.ImageCount; +// createInfo.imageFormat = swapchain_details.surfaceFormat.format; +// createInfo.imageColorSpace = swapchain_details.surfaceFormat.colorSpace; +// createInfo.imageExtent = swapchain_details.extent; +// createInfo.imageArrayLayers = 1; +// createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + +// details.ImageSize = { swapchain_details.extent.width, swapchain_details.extent.height }; + +// QueueFamilyIndices indices = findQueueFamilies(device.physicalOutputDevice->physicalOutputDevice->instance->instance->window_surface, device.physicalOutputDevice->physicalOutputDevice->device); +// uint32_t queueFamilyIndices[] = {indices.graphicsFamily.value(), indices.presentFamily.value()}; + +// if (indices.graphicsFamily != indices.presentFamily) { +// createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; +// createInfo.queueFamilyIndexCount = 2; +// createInfo.pQueueFamilyIndices = queueFamilyIndices; +// } else { +// createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; +// createInfo.queueFamilyIndexCount = 0; // Optional +// createInfo.pQueueFamilyIndices = nullptr; // Optional +// } + +// createInfo.preTransform = swapchain_details.swapChainSupport.capabilities.currentTransform; +// createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; +// createInfo.presentMode = swapchain_details.presentMode; +// createInfo.clipped = VK_TRUE; +// createInfo.oldSwapchain = VK_NULL_HANDLE; + +// if (vkCreateSwapchainKHR(device.outputDevice->device, &createInfo, nullptr, &presentationQueue->presentationQueue->swapChain) != VK_SUCCESS) { +// gnReturnError(GN_FAILED_CREATE_PRESENTATION_QUEUE, "too lazy to query vulkan why"); +// } + +// std::vector swapChainImages; +// vkGetSwapchainImagesKHR(device.outputDevice->device, presentationQueue->presentationQueue->swapChain, &details.ImageCount, nullptr); +// swapChainImages.resize(details.ImageCount); +// vkGetSwapchainImagesKHR(device.outputDevice->device, presentationQueue->presentationQueue->swapChain, &details.ImageCount, swapChainImages.data()); + +// presentationQueue->valid = true; +// presentationQueue->presentationQueue->device = &device.outputDevice->device; + +// if (gnListLength(presentationQueue->images) < swapChainImages.size()) { +// for (size_t i = gnListLength(presentationQueue->images); i < swapChainImages.size(); i++) { +// gnTexture newImage = gnTexture(); +// newImage.texture = new gnPlatformTexture(); +// gnListAdd(presentationQueue->images, newImage); +// } +// } + +// for (size_t i = 0; i < swapChainImages.size(); i++) { +// VkImageView imageView; +// gnReturnCode code = createImageView(device, swapChainImages[i], swapchain_details.surfaceFormat.format, VK_IMAGE_ASPECT_COLOR_BIT, &imageView); +// presentationQueue->images[i].texture->textureImageView = imageView; +// presentationQueue->images[i].texture->textureImage = swapChainImages[i]; +// presentationQueue->images[i].texture->outputDevice = const_cast(&device); +// presentationQueue->images[i].texture->swapchainImage = true; +// if (code != GN_SUCCESS) return code; +// } + +// return GN_SUCCESS; +// } + +// GN_EXPORT void gnDestroyPresentationQueueFn(gnPresentationQueue& queue) { +// for (size_t i = 0; i < gnListLength(queue.images); i++) +// vkDestroyImageView(*queue.presentationQueue->device, queue.images[i].texture->textureImageView, nullptr); +// vkDestroySwapchainKHR(*queue.presentationQueue->device, queue.presentationQueue->swapChain, nullptr); +// } + +// GN_EXPORT gnReturnCode gnPresentationQueueGetNextImageAsyncFn(gnPresentationQueue& presentationQueue, const gnSyncSemaphore& semaphore, gnUInt* imageIndex) { +// gnUInt nextImageIndex = 0; +// presentationQueue.presentationQueue->result = +// vkAcquireNextImageKHR(*presentationQueue.presentationQueue->device, presentationQueue.presentationQueue->swapChain, UINT64_MAX, semaphore.semaphore->semaphore, VK_NULL_HANDLE, &nextImageIndex); +// *imageIndex = nextImageIndex; + +// if (presentationQueue.presentationQueue->result != VK_SUCCESS) { +// return GN_FAILED; +// } + +// return GN_SUCCESS; +// } + +// GN_EXPORT gnPresentationQueueState gnPresentationQueueGetStateFn(gnPresentationQueue& presentationQueue) { +// if (presentationQueue.presentationQueue->result == VK_ERROR_OUT_OF_DATE_KHR) { +// return GN_OUT_OF_DATE; +// } else if (presentationQueue.presentationQueue->result == VK_SUBOPTIMAL_KHR) { +// return GN_SUBOPTIMAL; +// } +// else if (presentationQueue.presentationQueue->result == VK_SUCCESS) { +// return GN_VALID; +// } +// return GN_VALID; +// } diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index bbf7337..0cabd16 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -44,6 +44,7 @@ typedef struct gnFunctions_t { void (*_gnDestroyWindowSurface)(struct gnWindowSurface_t* windowSurface); } gnFunctions; +#include "core/presentation_queue/gryphn_presentation_queue.h" typedef struct gnDeviceFunctions_t { - + gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo); } gnDeviceFunctions; diff --git a/src/core/instance/init/gryphn_init.c b/src/core/instance/init/gryphn_init.c index f7e05dc..0e554d3 100644 --- a/src/core/instance/init/gryphn_init.c +++ b/src/core/instance/init/gryphn_init.c @@ -68,5 +68,5 @@ void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* funct } void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFunctions_t* functions) { - + gnLoadDLLFunction(lib, functions->_gnCreatePresentationQueue, "gnCreatePresentationQueueFn"); } diff --git a/src/core/presentation_queue/gryphn_device_presentation_details.h b/src/core/presentation_queue/gryphn_device_presentation_details.h deleted file mode 100644 index 8547424..0000000 --- a/src/core/presentation_queue/gryphn_device_presentation_details.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../output_device/gryphn_physical_output_device.h" - -struct gnDevicePresentationDetails { -public: - int MinimumImageCount, MaximumImageCount; -}; - -inline gnDevicePresentationDetails (*gnGetDevicePresentationDetails)(const gnPhysicalOutputDevice& physicalOutputDevice); diff --git a/src/core/presentation_queue/gryphn_presentation_details.h b/src/core/presentation_queue/gryphn_presentation_details.h deleted file mode 100644 index 9a1b1bd..0000000 --- a/src/core/presentation_queue/gryphn_presentation_details.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include - -typedef struct gnPresentationDetails_t { - gnUInt ImageCount; - gnUInt2 ImageSize; -} gnPresentationDetails; diff --git a/src/core/presentation_queue/gryphn_presentation_queue.c b/src/core/presentation_queue/gryphn_presentation_queue.c index 2de9c41..e267ff6 100644 --- a/src/core/presentation_queue/gryphn_presentation_queue.c +++ b/src/core/presentation_queue/gryphn_presentation_queue.c @@ -1,4 +1,9 @@ #include "gryphn_presentation_queue.h" +#include "core/gryphn_platform_functions.h" + +gnReturnCode gnCreatePresentationQueue(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo){ + return device->deviceFunctions->_gnCreatePresentationQueue(presentationQueue, device, presentationInfo); +} // gnTexture* gnGetPresentationQueueImage(gnPresentationQueue& presentationQueue, int index) { // // if (index < gnListLength(presentationQueue.images)) diff --git a/src/core/presentation_queue/gryphn_presentation_queue.h b/src/core/presentation_queue/gryphn_presentation_queue.h index a203972..cc2d40b 100644 --- a/src/core/presentation_queue/gryphn_presentation_queue.h +++ b/src/core/presentation_queue/gryphn_presentation_queue.h @@ -1,12 +1,16 @@ #pragma once #include -#include "gryphn_presentation_details.h" #include "core/output_device/gryphn_output_device.h" -// #include "core/sync_objects/gryphn_sync_semaphore.h" #include "gryphn_present_queue_state.h" +// #include "core/sync_objects/gryphn_sync_semaphore.h" // #include "core/textures/gryphn_texture.h" // #include "gryphn_device_presentation_details.h" +typedef struct gnPresentationQueueInfo_t { + gnUInt ImageCount; + gnUInt2 ImageSize; +} gnPresentationQueueInfo; + struct gnPlatformPresentationQueue_t; typedef struct gnPresentationQueue_t { @@ -18,6 +22,8 @@ typedef struct gnPresentationQueue_t { // gnTexture* gnGetPresentationQueueImage(gnPresentationQueue& presentationQueue, int index); +gnReturnCode gnCreatePresentationQueue(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo); + // inline gnReturnCode (*gnCreatePresentationQueue)(gnPresentationQueue* presentationQueue, const gnOutputDevice& device, gnPresentationDetails& details); // inline void (*gnDestroyPresentationQueue)(gnPresentationQueue& queue); // inline gnImageFormat (*_gnPresentationQueueGetImageFormat)(gnPresentationQueue& presentationQueue);