get image count and preferred surface format

This commit is contained in:
Greg Wells
2025-05-24 18:41:13 -04:00
parent a3f1201062
commit 339b2c75e0
15 changed files with 214 additions and 82 deletions

View File

@@ -6,7 +6,6 @@
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){
@@ -15,7 +14,6 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue,
);
return GN_NO_SUPPORTED_FORMATS;
}
if (details.presentModeCount == 0) {
gnDebuggerSetErrorMessage(device->instance->debugger,
(gnMessageData){
@@ -25,6 +23,28 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue,
return GN_NO_SUPPORTED_PRESENT_MODES;
}
int index = -1;
VkFormat convertedFormat = vkGryphnFormatToVulkanFormat(presentationInfo.format.format);
VkColorSpaceKHR convertedColorSpace = vkGryphnColorSpaceToVulkanColorSpace(presentationInfo.format.colorSpace);
for (int i = 0; i < details.formatCount; i++) {
if (details.formats[i].format == convertedFormat && details.formats[i].colorSpace == convertedColorSpace) {
index = i;
break;
}
}
if (index == -1) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("Unsupported color format passed to Gryphn")
});
return GN_UNKNOWN_IMAGE_FORMAT;
}
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkExtent2D extent = {
.width = presentationInfo.ImageSize.x,
.height = presentationInfo.ImageSize.y
};
return GN_SUCCESS;
}

View File

@@ -59,11 +59,8 @@ void gnDestroyWindowSurfaceFn(struct gnWindowSurface_t* windowSurface) {
vkDestroySurfaceKHR(windowSurface->instance->instance->vk_instance, windowSurface->windowSurface->surface, NULL);
}
struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormatsFn(
struct gnWindowSurface_t* windowSurface,
struct gnPhysicalDevice_t device,
uint32_t* formatCount
struct gnSurfaceFormat_t* vkGetSurfaceFormats(
struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device, uint32_t* formatCount
) {
struct gnSurfaceFormat_t* formats = NULL;
@@ -88,3 +85,34 @@ struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormatsFn(
return formats;
}
struct gnSurfaceDetails_t gnGetSurfaceDetailsFn(
// struct gnWindowSurface_t* windowSurface,
// struct gnPhysicalDevice_t device,
// uint32_t* formatCount
struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device
) {
struct gnSurfaceDetails_t surfaceDetails;
surfaceDetails.formats = vkGetSurfaceFormats(windowSurface, device, &surfaceDetails.formatCount);
VkSurfaceCapabilitiesKHR details;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device.physicalDevice->device, windowSurface->windowSurface->surface, &details);
surfaceDetails.minImageCount = details.minImageCount;
surfaceDetails.maxImageCount = details.maxImageCount;
return surfaceDetails;
}
VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format) {
switch (format) {
case GN_FORMAT_BGRA8_SRGB: { return VK_FORMAT_B8G8R8A8_SRGB; }
default: return VK_FORMAT_UNDEFINED;
}
}
VkColorSpaceKHR vkGryphnColorSpaceToVulkanColorSpace(gnColorSpace colorSpace) {
switch (colorSpace) {
case GN_COLOR_SPACE_SRGB_NONLINEAR: { return VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; }
}
}

View File

@@ -5,3 +5,6 @@
typedef struct gnPlatformWindowSurface_t {
VkSurfaceKHR surface;
} gnPlatformWindowSurface;
VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format);
VkColorSpaceKHR vkGryphnColorSpaceToVulkanColorSpace(gnColorSpace colorSpace);

View File

@@ -1,5 +1,6 @@
#ifdef GN_PLATFORM_MACOS
#include "vulkan_surface.h"
#include "core/window_surface/gryphn_surface_create_functions.h"
#include "../instance/vulkan_instance.h"
#include <AppKit/AppKit.h>
#include <vulkan/vulkan_metal.h>