error checking or some jazz

This commit is contained in:
Greg Wells
2025-05-27 12:36:13 -04:00
parent f7ff97528d
commit 8cee3c5702
4 changed files with 29 additions and 16 deletions

View File

@@ -1,25 +1,40 @@
#include "metal_presentation_queue.h" #include "metal_presentation_queue.h"
#include "core/surface/metal_surface.h" #include "core/surface/metal_surface.h"
#include "core/devices/metal_output_devices.h" #include "core/devices/metal_output_devices.h"
#include "core/debugger/gryphn_debugger.h"
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo) { gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue, const gnOutputDevice* device, struct gnPresentationQueueInfo_t presentationInfo) {
if (presentationInfo.minImageCount > 3) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("On Metal you cannot have more than 3 images in a presentation queue")
});
return GN_UNSUPPORTED_IMAGE_COUNT;
}
if (presentationInfo.minImageCount < 2) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("On Metal you cannot have less than 2 images in a presentation queue")
});
return GN_UNSUPPORTED_IMAGE_COUNT;
}
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t)); presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
MTLPixelFormat convertedFormat = mtlGryphnFormatToVulkanFormat(presentationInfo.format.format); MTLPixelFormat convertedFormat = mtlGryphnFormatToVulkanFormat(presentationInfo.format.format);
CGColorSpaceRef convertedColorSpace = mtlGryphnColorSpaceToVulkanColorSpace(presentationInfo.format.colorSpace); CGColorSpaceRef convertedColorSpace = mtlGryphnColorSpaceToVulkanColorSpace(presentationInfo.format.colorSpace);
presentationQueue->presentationQueue->textureCount = presentationInfo.ImageCount; presentationQueue->presentationQueue->textureCount = presentationInfo.minImageCount;
presentationQueue->presentationQueue->textures = malloc(sizeof(id<MTLTexture>) * presentationInfo.ImageCount); presentationQueue->presentationQueue->textures = malloc(sizeof(id<MTLTexture>) * presentationInfo.minImageCount);
MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init]; MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
textureDescriptor.pixelFormat = convertedFormat; textureDescriptor.pixelFormat = convertedFormat;
textureDescriptor.width = presentationInfo.ImageSize.x; textureDescriptor.width = presentationInfo.imageSize.x;
textureDescriptor.height = presentationInfo.ImageSize.y; textureDescriptor.height = presentationInfo.imageSize.y;
textureDescriptor.usage = MTLTextureUsageRenderTarget; textureDescriptor.usage = MTLTextureUsageRenderTarget;
textureDescriptor.textureType = MTLTextureType2D; textureDescriptor.textureType = MTLTextureType2D;
for (int i = 0; i < presentationInfo.ImageCount; i++) { for (int i = 0; i < presentationInfo.minImageCount; i++) {
presentationQueue->presentationQueue->textures[i] = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor]; presentationQueue->presentationQueue->textures[i] = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor];
} }

View File

@@ -43,15 +43,15 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presentationQueue,
} }
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkExtent2D extent = { VkExtent2D extent = {
.width = presentationInfo.ImageSize.x, .width = presentationInfo.imageSize.x,
.height = presentationInfo.ImageSize.y .height = presentationInfo.imageSize.y
}; };
VkSwapchainCreateInfoKHR createInfo = {}; VkSwapchainCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.surface = presentationInfo.surface.windowSurface->surface; createInfo.surface = presentationInfo.surface.windowSurface->surface;
createInfo.minImageCount = presentationInfo.ImageCount; createInfo.minImageCount = presentationInfo.minImageCount;
createInfo.imageFormat = details.formats[index].format; createInfo.imageFormat = details.formats[index].format;
createInfo.imageColorSpace = details.formats[index].colorSpace; createInfo.imageColorSpace = details.formats[index].colorSpace;
createInfo.imageExtent = extent; createInfo.imageExtent = extent;

View File

@@ -5,8 +5,8 @@
#include <utils/types/gryphn_image_format.h> #include <utils/types/gryphn_image_format.h>
typedef struct gnPresentationQueueInfo_t { typedef struct gnPresentationQueueInfo_t {
uint32_t ImageCount; uint32_t minImageCount;
struct gnUInt2_t ImageSize; struct gnUInt2_t imageSize;
struct gnWindowSurface_t surface; struct gnWindowSurface_t surface;
struct gnSurfaceFormat_t format; struct gnSurfaceFormat_t format;
enum gnImageSharingMode_e imageSharingMode; enum gnImageSharingMode_e imageSharingMode;
@@ -20,6 +20,7 @@ typedef struct gnPresentationQueue_t {
struct gnPlatformPresentationQueue_t* presentationQueue; struct gnPlatformPresentationQueue_t* presentationQueue;
struct gnOutputDevice_t* outputDevice; struct gnOutputDevice_t* outputDevice;
gnBool valid; gnBool valid;
int imageCount;
} gnPresentationQueue; } gnPresentationQueue;
gnReturnCode gnCreatePresentationQueue(gnPresentationQueue* presentationQueue, struct gnOutputDevice_t* device, struct gnPresentationQueueInfo_t presentationInfo); gnReturnCode gnCreatePresentationQueue(gnPresentationQueue* presentationQueue, struct gnOutputDevice_t* device, struct gnPresentationQueueInfo_t presentationInfo);

View File

@@ -14,21 +14,17 @@ typedef enum gnReturnCode_t {
GN_NO_SUPPORTED_FORMATS, GN_NO_SUPPORTED_FORMATS,
GN_NO_SUPPORTED_PRESENT_MODES, GN_NO_SUPPORTED_PRESENT_MODES,
GN_UNKNOWN_IMAGE_FORMAT, GN_UNKNOWN_IMAGE_FORMAT,
GN_FAILED_TO_CREATE_PRESENTATION_QUEUE GN_FAILED_TO_CREATE_PRESENTATION_QUEUE,
GN_UNSUPPORTED_IMAGE_COUNT
// GN_UNKNOWN_ERROR,
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, // GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
// GN_UNKNOWN_SHADER_MODULE, // GN_UNKNOWN_SHADER_MODULE,
// GN_UNKNOWN_FUNCTION, // GN_UNKNOWN_FUNCTION,
// GN_SHADER_FAILED_TO_COMPILE, // GN_SHADER_FAILED_TO_COMPILE,
// GN_UNSUPPORTED_COLOR_FORMAT,
// GN_UNKNOWN_COLOR_FORMAT, // GN_UNKNOWN_COLOR_FORMAT,
// GN_FUNCTION_NOT_FOUND,
// GN_FAILED_CREATE_GRAPHICS_PIPELINE, // GN_FAILED_CREATE_GRAPHICS_PIPELINE,
// GN_FAILED_CREATE_PRESENTATION_QUEUE,
// GN_FAILED_TO_CREATE_FRAMEBUFFER, // GN_FAILED_TO_CREATE_FRAMEBUFFER,
// GN_FAILED_CREATE_RENDERPASS, // GN_FAILED_CREATE_RENDERPASS,
// GN_FAILED_TO_ATTACH_WINDOW,
// GN_FAILED_TO_CREATE_IMAGE // GN_FAILED_TO_CREATE_IMAGE
} gnReturnCode; } gnReturnCode;
@@ -49,5 +45,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
case GN_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES"; case GN_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES";
case GN_UNKNOWN_IMAGE_FORMAT: return "GN_UNKNOWN_IMAGE_FORMAT"; case GN_UNKNOWN_IMAGE_FORMAT: return "GN_UNKNOWN_IMAGE_FORMAT";
case GN_FAILED_TO_CREATE_PRESENTATION_QUEUE: return "GN_FAILED_TO_CREATE_PRESENTATION_QUEUE"; case GN_FAILED_TO_CREATE_PRESENTATION_QUEUE: return "GN_FAILED_TO_CREATE_PRESENTATION_QUEUE";
case GN_UNSUPPORTED_IMAGE_COUNT: return "GN_UNSUPPORTED_IMAGE_COUNT";
} }
} }