vulkan swapchain support
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <core/debugger/gryphn_debugger.h>
|
#include <core/debugger/gryphn_debugger.h>
|
||||||
#include <core/output_device/gryphn_physical_output_device.h>
|
#include <core/output_device/gryphn_physical_output_device.h>
|
||||||
#include <core/window_surface/gryphn_surface.h>
|
#include <core/window_surface/gryphn_surface.h>
|
||||||
|
#include <core/presentation_queue/gryphn_presentation_queue.h>
|
||||||
|
|
||||||
// #pragma once
|
// #pragma once
|
||||||
|
|
||||||
|
@@ -1,14 +0,0 @@
|
|||||||
// #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;
|
|
||||||
// }
|
|
@@ -1,14 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
@@ -1,7 +1,31 @@
|
|||||||
#include "vulkan_presentation_queue.h"
|
#include "vulkan_presentation_queue.h"
|
||||||
|
#include "vulkan_swapchain_support.h"
|
||||||
|
#include <output_device/vulkan_physical_device.h>
|
||||||
|
#include "vulkan_surface/vulkan_surface.h"
|
||||||
|
#include "core/debugger/gryphn_debugger.h"
|
||||||
|
|
||||||
gnReturnCode gnCreatePresentationQueueFn() {
|
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo) {
|
||||||
|
vkSwapchainSupportDetails details = vkGetSwapchainSupport(device->physicalDevice.physicalDevice->device, presentationInfo.surface.windowSurface->surface);
|
||||||
|
|
||||||
|
if (details.formatCount == 0) {
|
||||||
|
gnDebuggerSetErrorMessage(device->instance->debugger,
|
||||||
|
(gnMessageData){
|
||||||
|
.message = gnCreateString("Format count for presentation queue is zero")
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return GN_NO_SUPPORTED_FORMATS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details.presentModeCount == 0) {
|
||||||
|
gnDebuggerSetErrorMessage(device->instance->debugger,
|
||||||
|
(gnMessageData){
|
||||||
|
.message = gnCreateString("Present mode count for presentation queue is zero")
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return GN_NO_SUPPORTED_PRESENT_MODES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #include "core/presentation_queue/gryphn_presentation_queue.h"
|
// #include "core/presentation_queue/gryphn_presentation_queue.h"
|
||||||
|
@@ -1,99 +0,0 @@
|
|||||||
// #pragma once
|
|
||||||
// #include <vulkan/vulkan.h>
|
|
||||||
// #include <gryphn/gryphn_utils.h>
|
|
||||||
// #include <cstdint> // Necessary for uint32_t
|
|
||||||
// #include <limits> // Necessary for std::numeric_limits
|
|
||||||
// #include <algorithm> // Necessary for std::clamp
|
|
||||||
// #include "vector"
|
|
||||||
// #include "set"
|
|
||||||
// #include <iostream>
|
|
||||||
|
|
||||||
// const std::vector<const char*> deviceExtensions = {
|
|
||||||
// VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
|
||||||
// "VK_KHR_portability_subset"
|
|
||||||
// };
|
|
||||||
|
|
||||||
// static VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {
|
|
||||||
// for (const auto& availableFormat : availableFormats) {
|
|
||||||
// if (availableFormat.format == VK_FORMAT_B8G8R8A8_SRGB && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
|
|
||||||
// return availableFormat;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return availableFormats[0];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes) {
|
|
||||||
// for (const auto& availablePresentMode : availablePresentModes) {
|
|
||||||
// if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
|
|
||||||
// return availablePresentMode;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return VK_PRESENT_MODE_FIFO_KHR;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static VkExtent2D chooseSwapExtent(gnVec2 size, const VkSurfaceCapabilitiesKHR& capabilities) {
|
|
||||||
// if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max()) {
|
|
||||||
// return capabilities.currentExtent;
|
|
||||||
// } else {
|
|
||||||
// // int width, height;
|
|
||||||
// // glfwGetFramebufferSize(window, &width, &height);
|
|
||||||
|
|
||||||
// VkExtent2D actualExtent = {
|
|
||||||
// static_cast<uint32_t>(size.x),
|
|
||||||
// static_cast<uint32_t>(size.y)
|
|
||||||
// };
|
|
||||||
|
|
||||||
// actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
|
||||||
// actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
|
||||||
|
|
||||||
// return actualExtent;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static bool checkDeviceExtensionSupport(std::vector<const char*> deviceExtensions, const VkPhysicalDevice& device) {
|
|
||||||
// uint32_t extensionCount;
|
|
||||||
// vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
|
|
||||||
|
|
||||||
// std::vector<VkExtensionProperties> availableExtensions(extensionCount);
|
|
||||||
// vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data());
|
|
||||||
|
|
||||||
// std::set<std::string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());
|
|
||||||
|
|
||||||
// for (const auto& extension : availableExtensions) {
|
|
||||||
// requiredExtensions.erase(extension.extensionName);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return requiredExtensions.empty();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// struct SwapChainSupportDetails {
|
|
||||||
// VkSurfaceCapabilitiesKHR capabilities;
|
|
||||||
// std::vector<VkSurfaceFormatKHR> formats;
|
|
||||||
// std::vector<VkPresentModeKHR> presentModes;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// static SwapChainSupportDetails querySwapChainSupport(const VkSurfaceKHR& surface, const VkPhysicalDevice& device) {
|
|
||||||
// SwapChainSupportDetails details;
|
|
||||||
|
|
||||||
// vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);
|
|
||||||
|
|
||||||
// uint32_t formatCount;
|
|
||||||
// vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
|
||||||
|
|
||||||
// if (formatCount != 0) {
|
|
||||||
// details.formats.resize(formatCount);
|
|
||||||
// vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uint32_t presentModeCount;
|
|
||||||
// vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
|
|
||||||
|
|
||||||
// if (presentModeCount != 0) {
|
|
||||||
// details.presentModes.resize(presentModeCount);
|
|
||||||
// vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return details;
|
|
||||||
// }
|
|
@@ -0,0 +1,23 @@
|
|||||||
|
#include "vulkan_swapchain_support.h"
|
||||||
|
|
||||||
|
struct vkSwapchainSupportDetails_t vkGetSwapchainSupport(
|
||||||
|
const VkPhysicalDevice device,
|
||||||
|
const VkSurfaceKHR surface
|
||||||
|
) {
|
||||||
|
struct vkSwapchainSupportDetails_t details;
|
||||||
|
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);
|
||||||
|
|
||||||
|
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &details.formatCount, NULL);
|
||||||
|
if (details.formatCount > 0) {
|
||||||
|
details.formats = malloc(sizeof(VkSurfaceFormatKHR) * details.formatCount);
|
||||||
|
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &details.formatCount, details.formats);
|
||||||
|
}
|
||||||
|
|
||||||
|
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &details.presentModeCount, NULL);
|
||||||
|
if (details.presentModeCount > 0) {
|
||||||
|
details.presentModes = malloc(sizeof(VkPresentModeKHR) * details.presentModeCount);
|
||||||
|
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &details.presentModeCount, details.presentModes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return details;
|
||||||
|
}
|
@@ -1,24 +1,17 @@
|
|||||||
// #pragma once
|
#pragma once
|
||||||
// #include "vulkan/vulkan.h"
|
#include <vulkan/vulkan.h>
|
||||||
// #include "vulkan_swapchain.h"
|
#include <output_device/vulkan_output_devices.h>
|
||||||
// #include "../output_device/vulkan_output_devices.h"
|
|
||||||
|
|
||||||
// struct vulkanSwapchainDetails {
|
typedef struct vkSwapchainSupportDetails_t {
|
||||||
// VkSurfaceFormatKHR surfaceFormat;
|
VkSurfaceCapabilitiesKHR capabilities;
|
||||||
// VkPresentModeKHR presentMode;
|
uint32_t formatCount;
|
||||||
// VkExtent2D extent;
|
VkSurfaceFormatKHR* formats;
|
||||||
|
|
||||||
// SwapChainSupportDetails swapChainSupport;
|
uint32_t presentModeCount;
|
||||||
// };
|
VkPresentModeKHR* presentModes;
|
||||||
|
} vkSwapchainSupportDetails;
|
||||||
|
|
||||||
// static vulkanSwapchainDetails vulkanGetSwapchainDetails(gnVec2 size, const VkSurfaceKHR& surface, const VkPhysicalDevice& physicalDevice) {
|
struct vkSwapchainSupportDetails_t vkGetSwapchainSupport(
|
||||||
// SwapChainSupportDetails swapChainSupport = querySwapChainSupport(surface, physicalDevice);
|
const VkPhysicalDevice device,
|
||||||
|
const VkSurfaceKHR surface
|
||||||
// VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats);
|
);
|
||||||
// VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes);
|
|
||||||
// VkExtent2D extent = chooseSwapExtent(size, swapChainSupport.capabilities);
|
|
||||||
|
|
||||||
// return {
|
|
||||||
// surfaceFormat, presentMode, extent, swapChainSupport
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
@@ -13,12 +13,3 @@ gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const
|
|||||||
void gnDestroyDebugger(gnDebugger* debugger) {
|
void gnDestroyDebugger(gnDebugger* debugger) {
|
||||||
debugger->instance->functions->_gnDestroyDebugger(debugger);
|
debugger->instance->functions->_gnDestroyDebugger(debugger);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDebuggerSetErrorMessage(gnDebugger* debugger, gnMessageData data) {
|
|
||||||
debugger->info.callback(
|
|
||||||
GN_MESSAGE_ERROR,
|
|
||||||
GN_DEBUG_MESSAGE_VALIDATION,
|
|
||||||
data,
|
|
||||||
debugger->info.userData
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
@@ -53,4 +53,11 @@ typedef struct gnDebugger_t {
|
|||||||
gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info);
|
gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info);
|
||||||
void gnDestroyDebugger(gnDebugger* debugger);
|
void gnDestroyDebugger(gnDebugger* debugger);
|
||||||
|
|
||||||
void gnDebuggerSetErrorMessage(gnDebugger* debugger, gnMessageData data);
|
static void gnDebuggerSetErrorMessage(gnDebugger* debugger, gnMessageData data) {
|
||||||
|
debugger->info.callback(
|
||||||
|
GN_MESSAGE_ERROR,
|
||||||
|
GN_DEBUG_MESSAGE_VALIDATION,
|
||||||
|
data,
|
||||||
|
debugger->info.userData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@@ -7,7 +7,7 @@ gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstance* inst
|
|||||||
outputDevice->deviceFunctions = malloc(sizeof(gnDeviceFunctions));
|
outputDevice->deviceFunctions = malloc(sizeof(gnDeviceFunctions));
|
||||||
gnLoadDeviceFunctions(instance->dynamicLib, outputDevice->deviceFunctions);
|
gnLoadDeviceFunctions(instance->dynamicLib, outputDevice->deviceFunctions);
|
||||||
outputDevice->instance = instance;
|
outputDevice->instance = instance;
|
||||||
// outputDevice->physicalDevice = (gnPhysicalDevice*)(&deviceInfo.physicalDevice);
|
outputDevice->physicalDevice = deviceInfo.physicalDevice;
|
||||||
return instance->functions->_gnCreateOutputDevoce(outputDevice, instance, deviceInfo);
|
return instance->functions->_gnCreateOutputDevoce(outputDevice, instance, deviceInfo);
|
||||||
}
|
}
|
||||||
void gnDestroyOutputDevice(gnOutputDevice* device) {
|
void gnDestroyOutputDevice(gnOutputDevice* device) {
|
||||||
|
@@ -21,7 +21,7 @@ typedef struct gnOutputDevice_t {
|
|||||||
struct gnPlatformOutputDevice_t* outputDevice;
|
struct gnPlatformOutputDevice_t* outputDevice;
|
||||||
struct gnDeviceFunctions_t* deviceFunctions;
|
struct gnDeviceFunctions_t* deviceFunctions;
|
||||||
gnInstance* instance;
|
gnInstance* instance;
|
||||||
// gnPhysicalDevice* physicalDevice;
|
gnPhysicalDevice physicalDevice;
|
||||||
} gnOutputDevice;
|
} gnOutputDevice;
|
||||||
|
|
||||||
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstance* instance, struct gnOutputDeviceInfo_t deviceInfo);
|
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstance* instance, struct gnOutputDeviceInfo_t deviceInfo);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <gryphn/gryphn_utils.h>
|
#include <gryphn/gryphn_utils.h>
|
||||||
#include "core/output_device/gryphn_output_device.h"
|
#include "core/output_device/gryphn_output_device.h"
|
||||||
#include "gryphn_present_queue_state.h"
|
#include <core/window_surface/gryphn_surface.h>
|
||||||
// #include "core/sync_objects/gryphn_sync_semaphore.h"
|
// #include "core/sync_objects/gryphn_sync_semaphore.h"
|
||||||
// #include "core/textures/gryphn_texture.h"
|
// #include "core/textures/gryphn_texture.h"
|
||||||
// #include "gryphn_device_presentation_details.h"
|
// #include "gryphn_device_presentation_details.h"
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
typedef struct gnPresentationQueueInfo_t {
|
typedef struct gnPresentationQueueInfo_t {
|
||||||
gnUInt ImageCount;
|
gnUInt ImageCount;
|
||||||
gnUInt2 ImageSize;
|
gnUInt2 ImageSize;
|
||||||
|
struct gnWindowSurface_t surface;
|
||||||
} gnPresentationQueueInfo;
|
} gnPresentationQueueInfo;
|
||||||
|
|
||||||
struct gnPlatformPresentationQueue_t;
|
struct gnPlatformPresentationQueue_t;
|
||||||
|
@@ -10,7 +10,9 @@ typedef enum gnReturnCode_t {
|
|||||||
GN_FAILED_TO_CREATE_DEVICE,
|
GN_FAILED_TO_CREATE_DEVICE,
|
||||||
GN_FAILED_TO_ATTACH_WINDOW,
|
GN_FAILED_TO_ATTACH_WINDOW,
|
||||||
GN_INVALID_INSTANCE,
|
GN_INVALID_INSTANCE,
|
||||||
GN_DEBUGGER_EXISTS
|
GN_DEBUGGER_EXISTS,
|
||||||
|
GN_NO_SUPPORTED_FORMATS,
|
||||||
|
GN_NO_SUPPORTED_PRESENT_MODES
|
||||||
|
|
||||||
// GN_UNKNOWN_ERROR,
|
// GN_UNKNOWN_ERROR,
|
||||||
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
|
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
|
||||||
@@ -41,5 +43,7 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
|
|||||||
case GN_FAILED_TO_CREATE_DEVICE: return "GN_FAILED_TO_CREATE_DEVICE";
|
case GN_FAILED_TO_CREATE_DEVICE: return "GN_FAILED_TO_CREATE_DEVICE";
|
||||||
case GN_INVALID_INSTANCE: return "GN_INVALID_INSTANCE";
|
case GN_INVALID_INSTANCE: return "GN_INVALID_INSTANCE";
|
||||||
case GN_DEBUGGER_EXISTS: return "GN_DEBUGGER_EXISTS";
|
case GN_DEBUGGER_EXISTS: return "GN_DEBUGGER_EXISTS";
|
||||||
|
case GN_NO_SUPPORTED_FORMATS: return "GN_NO_SUPPORTED_FORMATS";
|
||||||
|
case GN_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user