surface handles

This commit is contained in:
Greg Wells
2025-06-03 14:14:49 -04:00
parent d39f598d3c
commit fbc30509c4
21 changed files with 83 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include "stdint.h"
#include <core/output_device/gryphn_output_device.h>
#include <utils/gryphn_error_code.h>
typedef struct gnCommandPoolInfo_t {
uint32_t queueIndex;

View File

@@ -51,8 +51,6 @@ struct gnDebugger_t {
gnInstanceHandle instance;
};
#endif
typedef struct gnDebugger_t* gnDebuggerHandle;
typedef gnDebuggerHandle gnDebugger;
gnReturnCode gnCreateDebugger(gnDebuggerHandle* debugger, const struct gnDebuggerInfo_t info);
void gnDestroyDebugger(gnDebuggerHandle debugger);

View File

@@ -1,6 +1,7 @@
#pragma once
#include "core/renderpass/gryphn_render_pass_descriptor.h"
#include "core/textures/gryphn_texture.h"
#include "utils/math/gryphn_vec2.h"
typedef struct gnFramebufferInfo_t {
struct gnRenderPassDescriptor_t* renderPassDescriptor;

View File

@@ -0,0 +1,9 @@
#pragma once
#define GN_HANDLE(type) \
typedef struct type##_t* type##Handle; \
typedef struct type##_t* type
GN_HANDLE(gnInstance);
GN_HANDLE(gnDebugger);
GN_HANDLE(gnWindowSurface);

View File

@@ -27,7 +27,7 @@ typedef struct gnFunctions_t {
void (*_gnDestroyDebugger)(gnDebuggerHandle debugger);
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
gnBool (*_gnQueueCanPresentToSurface)(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface);
gnBool (*_gnQueueCanPresentToSurface)(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const gnWindowSurfaceHandle windowSurface);
gnReturnCode (*_gnCreateOutputDevoce)(gnOutputDeviceHandle device, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
@@ -37,24 +37,24 @@ typedef struct gnFunctions_t {
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode (*_gnCreateX11WindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateX11WindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_WINDOW_WAYLAND
gnReturnCode (*_gnCreateWaylandWindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateWaylandWindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
#endif
#endif
#ifdef GN_PLATFORM_WIN32
gnReturnCode (*_gnCreateWin32WindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateWin32WindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_PLATFORM_MACOS
gnReturnCode (*_gnCreateMacOSWindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateMacOSWindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
#endif
void (*_gnDestroyWindowSurface)(struct gnWindowSurface_t* windowSurface);
struct gnSurfaceDetails_t (*_gnGetSurfaceDetails)(struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device);
void (*_gnDestroyWindowSurface)(gnWindowSurfaceHandle windowSurface);
struct gnSurfaceDetails_t (*_gnGetSurfaceDetails)(gnWindowSurfaceHandle windowSurface, struct gnPhysicalDevice_t device);
} gnFunctions;
#include "core/presentation_queue/gryphn_presentation_queue.h"

View File

@@ -1,11 +1,11 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include "core/gryphn_rendering_api.h"
#include "core/gryphn_handles.h"
struct gnPlatformInstance_t;
struct gnFunctions_t;
struct gnDynamicLibrary_t;
typedef struct gnDebugger_t* gnDebuggerHandle;
typedef struct gnInstanceInfo_t {
gnString applicationName;
@@ -33,8 +33,6 @@ struct gnInstance_t {
gnDebuggerHandle debugger;
};
#endif
typedef struct gnInstance_t* gnInstanceHandle;
typedef struct gnInstance_t* gnInstance;
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, struct gnInstanceInfo_t info);
void gnInstanceAttachDebugger(gnInstanceHandle istance, gnDebuggerHandle debugger);

View File

@@ -1,5 +1,6 @@
#pragma once
#include <core/output_device/gryphn_physical_output_device.h>
#include <utils/gryphn_error_code.h>
struct gnPlatformOutputDevice_t;
struct gnDeviceFunctions_t;

View File

@@ -1,6 +1,5 @@
#include "gryphn_physical_output_device.h"
#include "core/gryphn_platform_functions.h"
#include "core/window_surface/gryphn_surface.h"
#include "stdio.h"
gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count) {
@@ -11,7 +10,7 @@ gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* coun
return devices;
}
gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface) {
gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
if (queueIndex >= device.queueProperties.queueCount) {
gnDebuggerSetErrorMessage(device.instance->debugger,
(gnMessageData){
@@ -31,7 +30,7 @@ gnBool gnHasGraphicsQueue(const struct gnPhysicalDevice_t device) {
}
return gnFalse;
}
gnBool gnHasPresentQueue(const struct gnPhysicalDevice_t device, struct gnWindowSurface_t windowSurface) {
gnBool gnHasPresentQueue(const struct gnPhysicalDevice_t device, gnWindowSurfaceHandle windowSurface) {
for (int i = 0; i < device.queueProperties.queueCount; i++) {
if (gnQueueCanPresentToSurface(device, i, windowSurface)) {
return gnTrue;
@@ -54,7 +53,7 @@ int gnGetGraphicsQueueIndex(const struct gnPhysicalDevice_t device) {
);
return -1;
}
int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, struct gnWindowSurface_t windowSurface) {
int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, gnWindowSurfaceHandle windowSurface) {
for (int i = 0; i < device.queueProperties.queueCount; i++) {
if (gnQueueCanPresentToSurface(device, i, windowSurface)) {
return i;

View File

@@ -1,8 +1,8 @@
#pragma once
#include "core/instance/gryphn_instance.h"
#include "utils/strings/gryphn_string.h"
#include "core/gryphn_handles.h"
struct gnPlatformPhysicalDevice_t;
struct gnWindowSurface_t;
typedef enum gnDeviceType_e {
GN_DEDICATED_DEVICE, GN_INTEGRATED_DEVICE, GN_EXTERNAL_DEVICE
@@ -44,10 +44,10 @@ typedef struct gnPhysicalDevice_t {
} gnPhysicalDevice;
gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count);
gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface);
gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface);
gnBool gnHasGraphicsQueue(const struct gnPhysicalDevice_t device);
gnBool gnHasPresentQueue(const struct gnPhysicalDevice_t device, struct gnWindowSurface_t windowSurface);
gnBool gnHasPresentQueue(const struct gnPhysicalDevice_t device, gnWindowSurfaceHandle windowSurface);
int gnGetGraphicsQueueIndex(const struct gnPhysicalDevice_t device);
int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, struct gnWindowSurface_t windowSurface);
int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, gnWindowSurfaceHandle windowSurface);

View File

@@ -3,6 +3,7 @@
#include <core/pipelines/gryphn_uniform_layout.h>
#include <core/renderpass/gryphn_render_pass_descriptor.h>
#include <core/shader_module/gryphn_shader_module.h>
#include "utils/math/gryphn_vec2.h"
typedef enum gnDynamicState_e {
GN_DYNAMIC_VIEWPORT,

View File

@@ -8,7 +8,7 @@
typedef struct gnPresentationQueueInfo_t {
uint32_t minImageCount;
struct gnUInt2_t imageSize;
struct gnWindowSurface_t surface;
gnWindowSurfaceHandle surface;
struct gnSurfaceFormat_t format;
enum gnImageSharingMode_e imageSharingMode;
uint32_t queueFamilyCount;

View File

@@ -1,22 +1,22 @@
#include "gryphn_surface.h"
#include "core/gryphn_platform_functions.h"
void gnDestroyWindowSurface(struct gnWindowSurface_t *windowSurface) {
void gnDestroyWindowSurface(gnWindowSurfaceHandle windowSurface) {
windowSurface->instance->functions->_gnDestroyWindowSurface(windowSurface);
}
struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(
struct gnWindowSurface_t windowSurface,
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
uint32_t* formatCount
) {
struct gnSurfaceDetails_t surfaceDetails = windowSurface.instance->functions->_gnGetSurfaceDetails(&windowSurface, device);
struct gnSurfaceDetails_t surfaceDetails = windowSurface->instance->functions->_gnGetSurfaceDetails(windowSurface, device);
*formatCount = surfaceDetails.formatCount;
return surfaceDetails.formats;
}
gnBool gnIsSurfaceFormatSupported(
struct gnWindowSurface_t windowSurface,
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
) {
@@ -31,7 +31,7 @@ gnBool gnIsSurfaceFormatSupported(
}
struct gnSurfaceFormat_t gnGetPreferredSurfaceFormat(
struct gnWindowSurface_t windowSurface,
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
) {
@@ -53,17 +53,17 @@ struct gnSurfaceFormat_t gnGetPreferredSurfaceFormat(
return formats[0];
}
uint32_t gnGetMinImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device) {
struct gnSurfaceDetails_t surfaceDetails = surface.instance->functions->_gnGetSurfaceDetails(&surface, device);
uint32_t gnGetMinImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device) {
struct gnSurfaceDetails_t surfaceDetails = surface->instance->functions->_gnGetSurfaceDetails(surface, device);
return surfaceDetails.minImageCount;
}
uint32_t gnGetMaxImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device) {
struct gnSurfaceDetails_t surfaceDetails = surface.instance->functions->_gnGetSurfaceDetails(&surface, device);
uint32_t gnGetMaxImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device) {
struct gnSurfaceDetails_t surfaceDetails = surface->instance->functions->_gnGetSurfaceDetails(surface, device);
return surfaceDetails.maxImageCount;
}
uint32_t gnGetPreferredImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device) {
struct gnSurfaceDetails_t surfaceDetails = surface.instance->functions->_gnGetSurfaceDetails(&surface, device);
uint32_t gnGetPreferredImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device) {
struct gnSurfaceDetails_t surfaceDetails = surface->instance->functions->_gnGetSurfaceDetails(surface, device);
uint32_t imageCount = surfaceDetails.minImageCount + 1;
if (surfaceDetails.maxImageCount > 0 && imageCount > surfaceDetails.maxImageCount) {

View File

@@ -4,8 +4,6 @@
#include <utils/types/gryphn_image_format.h>
#include "core/output_device/gryphn_physical_output_device.h"
struct gnPlatformWindowSurface_t;
typedef struct gnSurfaceFormat_t {
gnImageFormat format;
gnColorSpace colorSpace;
@@ -18,18 +16,23 @@ typedef struct gnSurfaceDetails_t {
uint32_t minImageCount, maxImageCount;
} gnSufaceDetails;
typedef struct gnWindowSurface_t {
#ifdef GN_REVEAL_IMPL
struct gnWindowSurface_t {
struct gnPlatformWindowSurface_t* windowSurface;
gnInstanceHandle instance;
} gnWindowSurface;
void gnDestroyWindowSurface(struct gnWindowSurface_t* windowSurface);
};
#endif
// typedef struct gnWindowSurface_t* gnWindowSurfaceHandle;
void gnDestroyWindowSurface(gnWindowSurfaceHandle windowSurface);
struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(
struct gnWindowSurface_t windowSurface,
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
uint32_t* formatCount
);
gnBool gnIsSurfaceFormatSupported(
struct gnWindowSurface_t windowSurface,
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
);
@@ -37,10 +40,10 @@ gnBool gnIsSurfaceFormatSupported(
// unless its not supported then it will give you the first supported surface format
// at some point this function will attempt to give you the most simmilar surface format
struct gnSurfaceFormat_t gnGetPreferredSurfaceFormat(
struct gnWindowSurface_t windowSurface,
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
);
uint32_t gnGetMinImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device);
uint32_t gnGetMaxImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device);
uint32_t gnGetPreferredImageCount(struct gnWindowSurface_t surface, struct gnPhysicalDevice_t device);
uint32_t gnGetMinImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device);
uint32_t gnGetMaxImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device);
uint32_t gnGetPreferredImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device);

View File

@@ -4,12 +4,14 @@
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateX11WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo) {
*windowSurface = malloc(sizeof(struct gnWindowSurface_t));
return instance->functions->_gnCreateX11WindowSurface(windowSurface, instance, createInfo);
}
#endif
#ifdef GN_WINDOW_WAYLAND
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateWaylandWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
*windowSurface = malloc(sizeof(struct gnWindowSurface_t));
return instance->functions->_gnCreateWaylandWindowSurface(windowSurface, instance, createInfo);
}
#endif
@@ -17,14 +19,16 @@
#ifdef GN_PLATFORM_WIN32
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateWin32WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo) {
*windowSurface = malloc(sizeof(struct gnWindowSurface_t));
return instance->functions->_gnCreateWin32WindowSurface(windowSurface, instance, createInfo);
}
#endif
#ifdef GN_PLATFORM_MACOS
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
windowSurface->instance = instance;
return instance->functions->_gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
gnReturnCode gnCreateMacOSWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
*windowSurface = malloc(sizeof(struct gnWindowSurface_t));
(*windowSurface)->instance = instance;
return instance->functions->_gnCreateMacOSWindowSurface(*windowSurface, instance, createInfo);
}
#endif

View File

@@ -1,5 +1,7 @@
#pragma once
#include "gryphn_surface.h"
#include <platform/gryphn_platform_include.h>
#include "core/gryphn_handles.h"
#include "utils/gryphn_error_code.h"
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
@@ -8,7 +10,7 @@
Window* window;
} gnX11WindowSurfaceCreateInfo;
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateX11WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_WINDOW_WAYLAND
typedef struct gnWaylandWindowSurfaceInfo_t {
@@ -16,7 +18,7 @@
wl_surface* surface;
} gnWaylandWindowSurfaceInfo;
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateWaylandWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
#endif
#endif
@@ -27,7 +29,7 @@
HINSTANCE* instance;
} gnWin32WindowSurfaceInfo;
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateWin32WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_PLATFORM_MACOS
@@ -35,5 +37,5 @@
CAMetalLayer* layer;
} gnMacOSWindowSurfaceInfo;
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateMacOSWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
#endif