rename to projects (DOES NOT COMPILE)

This commit is contained in:
Gregory Wells
2025-06-24 12:04:16 -04:00
parent 7a80d0fd61
commit d66f470a52
148 changed files with 2 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
#include "gryphn_buffer.h"
#include "output_device/gryphn_output_device.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info) {
*buffer = malloc(sizeof(struct gnBuffer_t));
(*buffer)->device = device;
(*buffer)->info = info;
return device->deviceFunctions->_gnCreateBuffer(*buffer, device, info);
}
void gnBufferData(gnBufferHandle buffer, size_t dataSize, void* data) {
buffer->device->deviceFunctions->_gnBufferData(buffer, dataSize, data);
}
void* gnMapBuffer(gnBufferHandle buffer) {
if (buffer->info.usage == GN_STATIC_DRAW) return NULL;
return buffer->device->deviceFunctions->_gnMapBuffer(buffer);
}
void gnDestroyBuffer(gnBufferHandle buffer) {
buffer->device->deviceFunctions->_gnDestroyBuffer(buffer);
}

View File

@@ -0,0 +1,41 @@
#pragma once
#include "stdlib.h"
#include "utils/gryphn_error_code.h"
#include "utils/lists/gryphn_array_list.h"
#include <gryphn_handles.h>
typedef enum gnIndexType {
GN_UINT16, GN_UINT32
} gnIndexType;
typedef enum gnBufferType {
GN_VERTEX_BUFFER = 0x00000001,
GN_INDEX_BUFFER = 0x00000002,
GN_UNIFORM_BUFFER = 0x00000004
} gnBufferType;
typedef enum gnBufferUsage {
GN_STATIC_DRAW, GN_DYNAMIC_DRAW
} gnBufferUsage; // i love that OpenGL does this so im stealing it
typedef struct gnBufferInfo {
size_t size;
gnBufferType type;
gnBufferUsage usage;
} gnBufferInfo;
#ifdef GN_REVEAL_IMPL
struct gnBuffer_t {
struct gnPlatformBuffer_t* buffer;
gnDeviceHandle device;
gnBufferInfo info;
};
#endif
typedef void* gnBufferMemory;
GN_ARRAY_LIST(gnBuffer);
GN_ARRAY_LIST(gnBufferMemory);
gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info);
void gnBufferData(gnBufferHandle buffer, size_t dataSize, gnBufferMemory data);
gnBufferMemory gnMapBuffer(gnBufferHandle buffer);
void gnDestroyBuffer(gnBufferHandle buffer);

View File

@@ -0,0 +1,30 @@
#include "gryphn_command_buffer.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
for (int i = 0; i < count; i++) {
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));
buffers[i]->commandPool = commandPool;
}
return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool);
}
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool) {
for (int i = 0; i < count; i++) {
buffers.data[i] = malloc(sizeof(struct gnCommandBuffer_t));
buffers.data[i]->commandPool = commandPool;
}
return gnCommandPoolAllocateCommandBuffersFromPointer(buffers.data, count, commandPool);
}
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer) {
commandBuffer->commandPool->commandFunctions->_gnResetCommandBuffer(commandBuffer);
}
gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer) {
return commandBuffer->commandPool->commandFunctions->_gnBeginCommandBuffer(commandBuffer);
}
gnReturnCode gnEndCommandBuffer(gnCommandBufferHandle commandBuffer) {
return commandBuffer->commandPool->commandFunctions->_gnEndCommandBuffer(commandBuffer);
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "stdint.h"
#include "utils/gryphn_error_code.h"
#include "utils/lists/gryphn_array_list.h"
#include "gryphn_handles.h"
#ifdef GN_REVEAL_IMPL
struct gnCommandBuffer_t {
struct gnPlatformCommandBuffer_t* commandBuffer;
gnCommandPoolHandle commandPool;
};
#endif
GN_ARRAY_LIST(gnCommandBuffer);
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool);
// will reserve the space for ${count} number of elements
gnReturnCode gnCommandPoolAllocateCommandBuffersFromList(gnCommandBufferArrayList buffers, uint32_t count, gnCommandPoolHandle commandPool);
#define gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool) \
_Generic((buffers), \
gnCommandBufferArrayList: gnCommandPoolAllocateCommandBuffersFromList, \
default: gnCommandPoolAllocateCommandBuffersFromPointer \
)(buffers, count, commandPool)
void gnResetCommandBuffer(gnCommandBufferHandle commandBuffer);
gnReturnCode gnBeginCommandBuffer(gnCommandBufferHandle commandBuffer);
gnReturnCode gnEndCommandBuffer(gnCommandBufferHandle commandBuffer);

View File

@@ -0,0 +1,20 @@
#include "gryphn_command_pool.h"
#include "gryphn_platform_functions.h"
#include "instance/init/gryphn_init.h"
gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info) {
*commandPool = malloc(sizeof(struct gnCommandPool_t));
if (!device->instance->loadCommandFunctions) {
device->instance->commandFunctions = malloc(sizeof(struct gnCommandFunctions_t));
gnLoadCommandFunctions(device->instance->dynamicLib, device->instance->commandFunctions);
device->instance->loadCommandFunctions = gnTrue;
}
(*commandPool)->commandFunctions = device->instance->commandFunctions;
(*commandPool)->device = device;
return device->deviceFunctions->_gnCreateCommandPool((*commandPool), device, info);
}
void gnDestroyCommandPool(gnCommandPoolHandle commandPool) {
commandPool->device->deviceFunctions->_gnDestroyCommandPool(commandPool);
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include "stdint.h"
#include <utils/gryphn_error_code.h>
#include "gryphn_handles.h"
typedef struct gnCommandPoolInfo_t {
uint32_t queueIndex;
} gnCommandPoolInfo;
#ifdef GN_REVEAL_IMPL
struct gnCommandPool_t {
struct gnPlatformCommandPool_t* commandPool;
struct gnCommandFunctions_t* commandFunctions;
struct gnOutputDevice_t* device;
};
#endif
gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info);
void gnDestroyCommandPool(gnCommandPoolHandle commandPool);

View File

@@ -0,0 +1,36 @@
#include "gryphn_command.h"
#include "command/command_buffer/gryphn_command_buffer.h"
#include "command/command_pool/gryphn_command_pool.h"
#include "gryphn_platform_functions.h"
void gnCommandBeginRenderPass(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) {
buffer->commandPool->commandFunctions->_gnCommandBeginRenderPass(buffer, passInfo);
}
void gnCommandEndRenderPass(struct gnCommandBuffer_t* buffer) {
buffer->commandPool->commandFunctions->_gnCommandEndRenderPass(buffer);
}
void gnCommandBindGraphicsPipeline(struct gnCommandBuffer_t* buffer, struct gnGraphicsPipeline_t* graphicsPipeline) {
buffer->commandPool->commandFunctions->_gnCommandBindGraphicsPipeline(buffer, graphicsPipeline);
}
void gnCommandSetViewport(struct gnCommandBuffer_t* buffer, struct gnViewport_t viewport) {
buffer->commandPool->commandFunctions->_gnCommandSetViewport(buffer, viewport);
}
void gnCommandSetScissor(struct gnCommandBuffer_t* buffer, struct gnScissor_t scissor) {
buffer->commandPool->commandFunctions->_gnCommandSetScissor(buffer, scissor);
}
void gnCommandBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) {
buffer->commandPool->commandFunctions->_gnCommandBindUniform(buffer, uniform, set);
}
void gnCommandBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type) {
buffer->commandPool->commandFunctions->_gnCommandBindBuffer(buffer, bufferToBind, type);
}
void gnCommandPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) {
buffer->commandPool->commandFunctions->_gnCommandPushConstant(buffer, layout, data);
}
void gnCommandDraw(struct gnCommandBuffer_t* buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance) {
buffer->commandPool->commandFunctions->_gnCommandDraw(buffer, vertexCount, firstVertex, instanceCount, firstInstance);
}
void gnCommandDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance) {
buffer->commandPool->commandFunctions->_gnCommandDrawIndexed(buffer, type, indexCount, firstIndex, vertexOffset, instanceCount, firstInstance);
}

View File

@@ -0,0 +1,18 @@
#include "gryphn_handles.h"
#include "renderpass/gryphn_render_pass.h"
void gnCommandBeginRenderPass(gnCommandBufferHandle buffer, gnRenderPassInfo passInfo);
void gnCommandEndRenderPass(gnCommandBufferHandle buffer);
#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
void gnCommandBindGraphicsPipeline(gnCommandBufferHandle buffer, gnGraphicsPipelineHandle graphicsPipeline);
void gnCommandSetViewport(gnCommandBufferHandle buffer, gnViewport viewport);
void gnCommandSetScissor(gnCommandBufferHandle buffer, gnScissor scissor);
void gnCommandBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set);
void gnCommandPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);
#include "buffers/gryphn_buffer.h"
void gnCommandBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type);
void gnCommandDraw(gnCommandBufferHandle buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance);
void gnCommandDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance);

View File

@@ -0,0 +1,9 @@
#include "gryphn_debugger.h"
#include <gryphn_platform_functions.h>
gnReturnCode gnCreateDebugger(gnDebuggerHandle* debugger, const gnDebuggerInfo info) {
*debugger = malloc(sizeof(struct gnDebugger_t));
(*debugger)->info = info;
return GN_SUCCESS;
}
void gnDestroyDebugger(gnDebuggerHandle debugger) {}

View File

@@ -0,0 +1,66 @@
#pragma once
#include "stdint.h"
#include "utils/gryphn_string.h"
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
struct gnPlatformDebugger_t;
typedef enum gnMessageSeverity_e {
GN_MESSAGE_VERBOSE = 0x00000001,
GN_MESSAGE_INFO = 0x00000002,
GN_MESSAGE_WARNING = 0x00000004,
GN_MESSAGE_ERROR = 0x00000008,
} gnMessageSeverity;
typedef enum gnMessageType_e {
GN_DEBUG_MESSAGE_GENERAL = 0x00000001,
GN_DEBUG_MESSAGE_VALIDATION = 0x00000002,
GN_DEBUG_MESSAGE_PERFORMANCE = 0x00000004,
} gnMessageType;
typedef struct gnMessageData {
gnString message;
} gnMessageData;
typedef gnBool (*gnDebuggerCallback)(
gnMessageSeverity messageSeverity,
gnMessageType messageType,
gnMessageData messageData,
void* userData);
typedef enum gnDebuggerLayer {
GN_DEBUGGER_LAYER_PLATFORM, // enable platform (vulkan validation) layers
GN_DEBUGGER_LAYER_FUNCTIONS // enable the checks on every function
} gnDebuggerLayer;
typedef struct gnDebuggerInfo {
gnDebuggerCallback callback;
void* userData;
uint32_t layerCount;
gnDebuggerLayer* layers;
} gnDebuggerInfo;
#ifdef GN_REVEAL_IMPL
struct gnDebugger_t {
gnDebuggerInfo info;
};
#endif
gnReturnCode gnCreateDebugger(gnDebuggerHandle* debugger, const gnDebuggerInfo info);
void gnDestroyDebugger(gnDebuggerHandle debugger);
#ifdef GN_REVEAL_IMPL
static void gnDebuggerSetErrorMessage(gnDebuggerHandle debugger, gnMessageData data) {
if (debugger == NULL) return;
debugger->info.callback(
GN_MESSAGE_ERROR,
GN_DEBUG_MESSAGE_VALIDATION,
data,
debugger->info.userData
);
}
#endif

View File

@@ -0,0 +1,12 @@
#include "gryphn_framebuffer.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateFramebuffer(gnFramebuffer* framebuffer, gnOutputDeviceHandle device, gnFramebufferInfo framebufferInfo) {
*framebuffer = malloc(sizeof(struct gnFramebuffer_t));
(*framebuffer)->device = device;
return device->deviceFunctions->_gnCreateFramebuffer(*framebuffer, device, framebufferInfo);
}
void gnDestroyFramebuffer(gnFramebuffer framebuffer) {
framebuffer->device->deviceFunctions->_gnDestroyFramebuffer(framebuffer);
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "utils/math/gryphn_vec2.h"
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
typedef struct gnFramebufferInfo_t {
gnRenderPassDescriptorHandle renderPassDescriptor;
uint32_t attachmentCount;
gnTextureHandle* attachments;
gnUInt2 size;
} gnFramebufferInfo;
#ifdef GN_REVEAL_IMPL
struct gnFramebuffer_t {
struct gnPlatformFramebuffer_t* framebuffer;
gnOutputDeviceHandle device;
};
#endif
gnReturnCode gnCreateFramebuffer(gnFramebuffer* framebuffer, gnOutputDeviceHandle device, gnFramebufferInfo framebufferInfo);
void gnDestroyFramebuffer(gnFramebuffer framebuffer);

View File

@@ -0,0 +1,28 @@
#pragma once
#define GN_HANDLE(type) \
typedef struct type##_t* type##Handle; \
typedef struct type##_t* type
#define GN_HANDLE_ALIAS(handle, alias) \
typedef struct handle##_t* alias##Handle; \
typedef struct handle##_t* alias
GN_HANDLE(gnInstance);
GN_HANDLE(gnDebugger);
GN_HANDLE(gnWindowSurface);
GN_HANDLE(gnPresentationQueue);
GN_HANDLE(gnTexture);
GN_HANDLE(gnRenderPassDescriptor);
GN_HANDLE(gnOutputDevice);
GN_HANDLE_ALIAS(gnOutputDevice, gnDevice);
GN_HANDLE(gnShaderModule);
GN_HANDLE(gnGraphicsPipeline);
GN_HANDLE(gnCommandPool);
GN_HANDLE(gnCommandBuffer);
GN_HANDLE(gnSemaphore);
GN_HANDLE(gnFence);
GN_HANDLE(gnFramebuffer);
GN_HANDLE(gnBuffer);
GN_HANDLE(gnUniformPool);
GN_HANDLE(gnUniform);

View File

@@ -0,0 +1,126 @@
#pragma once
// theoretically you could have multible gryphn instances running in one application,
// why I dont know
#include "instance/gryphn_instance.h"
#include <debugger/gryphn_debugger.h>
#include "output_device/gryphn_physical_output_device.h"
#include "output_device/gryphn_output_device.h"
#include "window_surface/gryphn_surface.h"
#include <window_surface/gryphn_surface_create_functions.h>
#include "shader_module/gryphn_shader_module.h"
#include "renderpass/gryphn_render_pass_descriptor.h"
#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
#include "framebuffer/gryphn_framebuffer.h"
#include "command/command_pool/gryphn_command_pool.h"
#include "renderpass/gryphn_render_pass.h"
#include "submit/gryphn_submit.h"
#include "present/gryphn_present.h"
#include "buffers/gryphn_buffer.h"
#include "uniforms/gryphn_uniform.h"
#include "textures/gryphn_texture.h"
#include "uniforms/gryphn_uniform_pool.h"
typedef struct gnInstanceFunctions {
gnReturnCode (*_gnCreateInstance)(gnInstanceHandle instance, gnInstanceInfo info);
void (*_gnDestroyInstance)(gnInstanceHandle instance);
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
gnBool (*_gnQueueCanPresentToSurface)(const gnPhysicalDevice device, uint32_t queueIndex, const gnWindowSurfaceHandle windowSurface);
gnReturnCode (*_gnCreateOutputDevice)(gnOutputDeviceHandle device, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void (*_gnDestroyOutputDevice)(gnOutputDeviceHandle device);
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode (*_gnCreateX11WindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo);
#endif
#ifdef GN_WINDOW_WAYLAND
gnReturnCode (*_gnCreateWaylandWindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
#endif
#endif
#ifdef GN_PLATFORM_WIN32
gnReturnCode (*_gnCreateWin32WindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_PLATFORM_MACOS
gnReturnCode (*_gnCreateMacOSWindowSurface)(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
#endif
void (*_gnDestroyWindowSurface)(gnWindowSurfaceHandle windowSurface);
gnSurfaceDetails (*_gnGetSurfaceDetails)(gnWindowSurfaceHandle windowSurface, struct gnPhysicalDevice_t device);
} gnInstanceFunctions;
#include "presentation_queue/gryphn_presentation_queue.h"
typedef struct gnDeviceFunctions_t {
gnReturnCode (*_gnCreatePresentationQueue)(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo);
gnReturnCode (*_gnPresentationQueueGetImage)(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex);
void (*_gnDestroyPresentationQueue)(gnPresentationQueueHandle presentationQueue);
gnReturnCode (*_gnCreateShaderModule)(gnShaderModuleHandle module, gnOutputDeviceHandle device, gnShaderModuleInfo shaderModuleInfo);
void (*_gnDestroyShaderModule)(gnShaderModuleHandle module);
gnReturnCode (*_gnCreateRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass, gnOutputDeviceHandle device, gnRenderPassDescriptorInfo info);
void (*_gnDestroyRenderPassDescriptor)(gnRenderPassDescriptorHandle renderPass);
gnReturnCode (*_gnCreateGraphicsPipeline)(gnGraphicsPipelineHandle pipeline, gnOutputDeviceHandle device, gnGraphicsPipelineInfo pipelineInfo);
void (*_gnDestroyGraphicsPipeline)(gnGraphicsPipelineHandle pipeline);
gnReturnCode (*_gnCreateFramebuffer)(gnFramebuffer framebuffer, gnOutputDeviceHandle device, gnFramebufferInfo framebufferInfo);
void (*_gnDestroyFramebuffer)(gnFramebuffer framebuffer);
gnReturnCode (*_gnCreateCommandPool)(gnCommandPoolHandle commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info);
void (*_gnDestroyCommandPool)(gnCommandPoolHandle commandPool);
gnReturnCode (*_gnCreateSemaphore)(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device);
void (*_gnDestroySemaphore)(gnSemaphoreHandle semaphore);
gnReturnCode (*_gnCreateBuffer)(gnBufferHandle buffer, gnDeviceHandle device, gnBufferInfo info);
void (*_gnBufferData)(gnBufferHandle buffer, size_t size, void* data);
void* (*_gnMapBuffer)(gnBufferHandle buffer);
void (*_gnDestroyBuffer)(gnBufferHandle buffer);
gnReturnCode (*_gnCreateUniformPool)(gnUniformPool pool, gnDeviceHandle device);
gnUniform* (*_gnUniformPoolAllocateUniforms)(gnUniformPool pool, gnUniformAllocationInfo allocInfo);
void (*_gnDestroyUniformPool)(gnUniformPool pool);
void (*_gnUpdateBufferUniform)(gnUniform uniform, gnBufferUniformInfo* bufferInfo);
void (*_gnUpdateImageUniform)(gnUniform uniform, gnImageUniformInfo* imageInfo);
gnReturnCode (*_gnCreateTexture)(gnTexture texture, gnDevice device, const gnTextureInfo info);
void (*_gnTextureData)(gnTextureHandle texture, void* pixelData);
void (*_gnDestroyTexture)(gnTexture texture);
gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device);
void (*_gnSignalFence)(gnFenceHandle fence);
void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout);
void (*_gnResetFence)(gnFenceHandle fence);
void (*_gnDestroyFence)(gnFenceHandle fence);
gnReturnCode (*_gnSubmit)(gnOutputDeviceHandle device, gnSubmitInfo submit);
gnReturnCode (*_gnPresent)(gnOutputDeviceHandle device, gnPresentInfo info);
void (*_gnWaitForDevice)(gnOutputDeviceHandle device);
} gnDeviceFunctions;
typedef struct gnCommandFunctions_t {
gnReturnCode (*_gnCommandPoolAllocateCommandBuffers)(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);
gnReturnCode (*_gnBeginCommandBuffer)(gnCommandBufferHandle commandBuffer);
void (*_gnResetCommandBuffer)(gnCommandBufferHandle commandBuffer);
gnReturnCode (*_gnEndCommandBuffer)(gnCommandBufferHandle commandBuffer);
void (*_gnCommandBeginRenderPass)(gnCommandBufferHandle buffer, gnRenderPassInfo passInfo);
void (*_gnCommandEndRenderPass)(gnCommandBufferHandle buffer);
void (*_gnCommandBindGraphicsPipeline)(gnCommandBufferHandle buffer, gnGraphicsPipelineHandle graphicsPipeline);
void (*_gnCommandSetViewport)(gnCommandBufferHandle buffer, gnViewport viewport);
void (*_gnCommandSetScissor)(gnCommandBufferHandle buffer, gnScissor scissor);
void (*_gnCommandBindUniform)(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set);
void (*_gnCommandPushConstant)(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);
void (*_gnCommandBindBuffer)(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type);
void (*_gnCommandDraw)(gnCommandBufferHandle buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance);
void (*_gnCommandDrawIndexed)(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance);
} gnCommandFunctions;

View File

@@ -0,0 +1,25 @@
#pragma once
#include "utils/gryphn_string.h"
typedef enum gnRenderingAPI_t {
GN_RENDERINGAPI_NONE, // idk why im putting this
GN_RENDERINGAPI_SOFTWARE, // i kinda wanna write a software renderer
GN_RENDERINGAPI_OPENGL,
GN_RENDERINGAPI_VULKAN,
GN_RENDERINGAPI_DIRECTX11, GN_RENDERINGAPI_DIRECTX12,
GN_RENDERINGAPI_METAL
} gnRenderingAPI;
static gnString gnRenderingAPIName(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return gnCreateString("GN_RENDERINGAPI_NONE");
case GN_RENDERINGAPI_SOFTWARE: return gnCreateString("GN_RENDERINGAPI_SOFTWARE");
case GN_RENDERINGAPI_OPENGL: return gnCreateString("GN_RENDERINGAPI_OPENGL");
case GN_RENDERINGAPI_VULKAN: return gnCreateString("GN_RENDERINGAPI_VULKAN");
case GN_RENDERINGAPI_DIRECTX11: return gnCreateString("GN_RENDERINGAPI_DIRECTX11");
case GN_RENDERINGAPI_DIRECTX12: return gnCreateString("GN_RENDERINGAPI_DIRECTX12");
case GN_RENDERINGAPI_METAL: return gnCreateString("GN_RENDERINGAPI_METAL");
}
return gnCreateString("GN_INVALID_API");
}

View File

@@ -0,0 +1,8 @@
#pragma once
#include <gryphn/gryphn_utils.h>
typedef enum gnFeature {
GN_DYNAMIC_STATES, GN_SYNC_OBJECTS
} gnFeature;
inline gnBool (*gnAPISupports)(gnFeature feature);

View File

@@ -0,0 +1,26 @@
#include "gryphn_instance.h"
#include <gryphn_platform_functions.h>
#include "instance/gryphn_instance.h"
#include "gryphn_handles.h"
gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, gnInstanceInfo info) {
// *instanceHandlePtr = malloc(sizeof(struct gnInstance_t));
// gnInstanceHandle instance = *instanceHandlePtr;
// if (!gnIsAPISupported(info.renderingAPI)) return GN_UNSUPPORTED_RENDERING_API;
// instance->loadDeviceFunctions = gnFalse;
// instance->dynamicLib = gnLoadRenderingDLL(info.renderingAPI);
// if (instance->dynamicLib == NULL) return GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY;
// instance->functions = gnLoadFunctions(instance);
// if (info.debugger)
// instance->debugger = info.debugger;
// instance->loadCommandFunctions = gnFalse;
// instance->loadDeviceFunctions = gnFalse;
// return instance->functions->_gnCreateInstance(instance, info);
return GN_SUCCESS;
}
void gnDestroyInstance(gnInstanceHandle instance) {
instance->functions->_gnDestroyInstance(instance);
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include "gryphn_rendering_api.h"
#include "gryphn_handles.h"
typedef struct gnInstanceFunctions gnInstanceFunctions;
typedef struct gnInstanceInfo_t {
gnString applicationName;
gnVersion applicationVersion;
gnString engineName;
gnVersion engineVersion;
gnRenderingAPI renderingAPI;
gnDebuggerHandle debugger;
} gnInstanceInfo;
#ifdef GN_REVEAL_IMPL
struct gnInstance_t {
struct gnPlatformInstance_t* instance;
gnBool valid,
loadDeviceFunctions,
loadCommandFunctions;
struct gnDynamicLibrary_t* dynamicLib;
gnInstanceFunctions *functions, *unvalidatedFunctions;
struct gnDeviceFunctions_t* deviceFunctions;
struct gnCommandFunctions_t* commandFunctions;
gnDebuggerHandle debugger;
};
#endif
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, struct gnInstanceInfo_t info);
void gnDestroyInstance(gnInstanceHandle instance);

View File

@@ -0,0 +1,14 @@
#pragma once
#include "utils/gryphn_string.h"
#include "utils/gryphn_bool.h"
typedef struct gnDynamicLibrary_t {
void* dllPtr;
gnBool isValid;
} gnDynamicLibrary;
struct gnDynamicLibrary_t* gnLoadDynamicLibrary(const gnString path);
void gnUnloadDynamicLibrary(struct gnDynamicLibrary_t* dll);
void* gnLoadFunctionPtr(struct gnDynamicLibrary_t* dll, const char* name);
#define gnLoadDLLFunction(dll, function, name) function = (typeof(function))gnLoadFunctionPtr(dll, name)

View File

@@ -0,0 +1,127 @@
// #undef GN_UTILS_CPP
#include "gryphn_init.h"
#include <platform/gryphn_platform_include.h>
#include "gryphn_dynamic_library.h"
// #include <dlfcn.h>
#include "stdbool.h"
#include "stdio.h"
gnBool gnIsAPISupported(gnRenderingAPI api) {
int renderingAPICount = 0;
gnRenderingAPI* supportedRenderingAPIS = gnGetSupportedRenderingAPIs(&renderingAPICount);
for (int i = 0; i < renderingAPICount; i++) if (supportedRenderingAPIS[i] == api) return true;
return false;
}
struct gnDynamicLibrary_t* gnLoadRenderingDLL(gnRenderingAPI renderingAPI) {
gnString libName = gnCreateEmptyString();
switch (renderingAPI) {
case GN_RENDERINGAPI_NONE: return NULL;
case GN_RENDERINGAPI_SOFTWARE: return NULL;
case GN_RENDERINGAPI_OPENGL: return NULL;
case GN_RENDERINGAPI_VULKAN: {
if (!gnIsAPISupported(GN_RENDERINGAPI_VULKAN)) return NULL;
libName = gnCreateString("GryphnVulkanImpl");
break;
}
case GN_RENDERINGAPI_DIRECTX11: return NULL;
case GN_RENDERINGAPI_DIRECTX12: return NULL;
case GN_RENDERINGAPI_METAL: {
if (!gnIsAPISupported(GN_RENDERINGAPI_METAL)) return NULL;
libName = gnCreateString("GryphnMetalImpl");
break;
}
}
return gnLoadDynamicLibrary(gnCombineStrings(gnCreateString("gryphn/rendering_apis/"), libName));
}
gnInstanceFunctions* gnLoadFunctions(gnInstanceHandle instance) {
gnInstanceFunctions* functions = malloc(sizeof(gnInstanceFunctions));
gnLoadDLLFunction(instance->dynamicLib, functions->_gnCreateInstance, "gnCreateInstanceFn");
gnLoadDLLFunction(instance->dynamicLib, functions->_gnDestroyInstance, "gnDestroyInstanceFn");
gnLoadDLLFunction(instance->dynamicLib, functions->_gnGetPhysicalDevices, "gnGetPhysicalDevicesFn");
gnLoadDLLFunction(instance->dynamicLib, functions->_gnQueueCanPresentToSurface, "gnQueueCanPresentToSurfaceFn");
gnLoadDLLFunction(instance->dynamicLib, functions->_gnCreateOutputDevice, "gnCreateOutputDeviceFn");
gnLoadDLLFunction(instance->dynamicLib, functions->_gnDestroyOutputDevice, "gnDestroyOutputDeviceFn");
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnLoadDLLFunction(instance->dynamicLib, functions->_gnCreateX11WindowSurface, "gnCreateX11WindowSurfaceFn");
#endif
#ifdef GN_WINDOW_WAYLAND
gnLoadDLLFunction(instance->dynamicLib, functions->_gnCreateWaylandWindowSurface, "gnCreateWaylandWindowSurfaceFn");
#endif
#endif
#ifdef GN_PLATFORM_WIN32
gnLoadDLLFunction(instance->dynamicLib, functions->_gnCreateWin32WindowSurface, "gnCreateWin32WindowSurfaceFn");
#endif
#ifdef GN_PLATFORM_MACOS
gnLoadDLLFunction(instance->dynamicLib, functions->_gnCreateMacOSWindowSurface, "gnCreateMacOSWindowSurfaceFn");
#endif
gnLoadDLLFunction(instance->dynamicLib, functions->_gnDestroyWindowSurface, "gnDestroyWindowSurfaceFn");
gnLoadDLLFunction(instance->dynamicLib, functions->_gnGetSurfaceDetails, "gnGetSurfaceDetailsFn");
return functions;
}
void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFunctions_t* functions) {
gnLoadDLLFunction(lib, functions->_gnCreatePresentationQueue, "gnCreatePresentationQueueFn");
gnLoadDLLFunction(lib, functions->_gnPresentationQueueGetImage, "gnPresentationQueueGetImageFn");
gnLoadDLLFunction(lib, functions->_gnDestroyPresentationQueue, "gnDestroyPresentationQueueFn");
gnLoadDLLFunction(lib, functions->_gnCreateShaderModule, "gnCreateShaderModuleFn");
gnLoadDLLFunction(lib, functions->_gnDestroyShaderModule, "gnDestroyShaderModuleFn");
gnLoadDLLFunction(lib, functions->_gnCreateRenderPassDescriptor, "gnCreateRenderPassDescriptorFn");
gnLoadDLLFunction(lib, functions->_gnDestroyRenderPassDescriptor, "gnDestroyRenderPassDescriptorFn");
gnLoadDLLFunction(lib, functions->_gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn");
gnLoadDLLFunction(lib, functions->_gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn");
gnLoadDLLFunction(lib, functions->_gnCreateFramebuffer, "gnCreateFramebufferFn");
gnLoadDLLFunction(lib, functions->_gnDestroyFramebuffer, "gnDestroyFramebufferFn");
gnLoadDLLFunction(lib, functions->_gnCreateCommandPool, "gnCreateCommandPoolFn");
gnLoadDLLFunction(lib, functions->_gnDestroyCommandPool, "gnDestroyCommandPoolFn");
gnLoadDLLFunction(lib, functions->_gnCreateSemaphore, "gnCreateSemaphoreFn");
gnLoadDLLFunction(lib, functions->_gnDestroySemaphore, "gnDestroySemaphoreFn");
gnLoadDLLFunction(lib, functions->_gnCreateBuffer, "gnCreateBufferFn");
gnLoadDLLFunction(lib, functions->_gnBufferData, "gnBufferDataFn");
gnLoadDLLFunction(lib, functions->_gnMapBuffer, "gnMapBufferFn");
gnLoadDLLFunction(lib, functions->_gnDestroyBuffer, "gnDestroyBufferFn");
gnLoadDLLFunction(lib, functions->_gnCreateUniformPool, "gnCreateUniformPoolFn");
gnLoadDLLFunction(lib, functions->_gnUniformPoolAllocateUniforms, "gnUniformPoolAllocateUniformsFn");
gnLoadDLLFunction(lib, functions->_gnDestroyUniformPool, "gnDestroyUniformPoolFn");
gnLoadDLLFunction(lib, functions->_gnUpdateBufferUniform, "gnUpdateBufferUniformFn");
gnLoadDLLFunction(lib, functions->_gnUpdateImageUniform, "gnUpdateImageUniformFn");
gnLoadDLLFunction(lib, functions->_gnCreateTexture, "gnCreateTextureFn");
gnLoadDLLFunction(lib, functions->_gnTextureData, "gnTextureDataFn");
gnLoadDLLFunction(lib, functions->_gnDestroyTexture, "gnDestroyTextureFn");
gnLoadDLLFunction(lib, functions->_gnCreateFence, "gnCreateFenceFn");
gnLoadDLLFunction(lib, functions->_gnSignalFence, "gnSignalFenceFn");
gnLoadDLLFunction(lib, functions->_gnWaitForFence, "gnWaitForFenceFn");
gnLoadDLLFunction(lib, functions->_gnResetFence, "gnResetFenceFn");
gnLoadDLLFunction(lib, functions->_gnDestroyFence, "gnDestroyFenceFn");
gnLoadDLLFunction(lib, functions->_gnSubmit, "gnSubmitFn");
gnLoadDLLFunction(lib, functions->_gnPresent, "gnPresentFn");
gnLoadDLLFunction(lib, functions->_gnWaitForDevice, "gnWaitForDeviceFn");
}
void gnLoadCommandFunctions(struct gnDynamicLibrary_t* lib, struct gnCommandFunctions_t* functions) {
gnLoadDLLFunction(lib, functions->_gnCommandPoolAllocateCommandBuffers, "gnCommandPoolAllocateCommandBuffersFn");
gnLoadDLLFunction(lib, functions->_gnBeginCommandBuffer, "gnBeginCommandBufferFn");
gnLoadDLLFunction(lib, functions->_gnResetCommandBuffer, "gnResetCommandBufferFn");
gnLoadDLLFunction(lib, functions->_gnEndCommandBuffer, "gnEndCommandBufferFn");
gnLoadDLLFunction(lib, functions->_gnCommandBeginRenderPass, "gnCommandBeginRenderPassFn");
gnLoadDLLFunction(lib, functions->_gnCommandEndRenderPass, "gnCommandEndRenderPassFn");
gnLoadDLLFunction(lib, functions->_gnCommandBindGraphicsPipeline, "gnCommandBindGraphicsPipelineFn");
gnLoadDLLFunction(lib, functions->_gnCommandSetViewport, "gnCommandSetViewportFn");
gnLoadDLLFunction(lib, functions->_gnCommandSetScissor, "gnCommandSetScissorFn");
gnLoadDLLFunction(lib, functions->_gnCommandBindUniform, "gnCommandBindUniformFn");
gnLoadDLLFunction(lib, functions->_gnCommandBindBuffer, "gnCommandBindBufferFn");
gnLoadDLLFunction(lib, functions->_gnCommandPushConstant, "gnCommandPushConstantFn");
gnLoadDLLFunction(lib, functions->_gnCommandDraw, "gnCommandDrawFn");
gnLoadDLLFunction(lib, functions->_gnCommandDrawIndexed, "gnCommandDrawIndexedFn");
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include <gryphn_rendering_api.h>
#include "gryphn_platform_functions.h"
// #include "utils/gryphn_error_code.h"
gnBool gnIsAPISupported(gnRenderingAPI RenderingAPI);
struct gnDynamicLibrary_t* gnLoadRenderingDLL(gnRenderingAPI RenderingAPI);
gnInstanceFunctions* gnLoadFunctions(gnInstance instance);
void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFunctions_t* functions);
void gnLoadCommandFunctions(struct gnDynamicLibrary_t* lib, struct gnCommandFunctions_t* function);

View File

@@ -0,0 +1,29 @@
#include "gryphn_output_device.h"
#include "instance/gryphn_instance.h"
#include "gryphn_platform_functions.h"
#include "instance/init/gryphn_init.h"
#include "utils/gryphn_bool.h"
gnReturnCode gnCreateOutputDevice(gnOutputDeviceHandle* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
*outputDevice = malloc(sizeof(struct gnOutputDevice_t));
if (instance->loadDeviceFunctions == gnFalse) {
instance->deviceFunctions = malloc(sizeof(struct gnDeviceFunctions_t));
gnLoadDeviceFunctions(instance->dynamicLib, instance->deviceFunctions);
instance->loadDeviceFunctions = gnTrue;
}
(*outputDevice)->deviceFunctions = instance->deviceFunctions;
(*outputDevice)->instance = instance;
(*outputDevice)->physicalDevice = deviceInfo.physicalDevice;
(*outputDevice)->deviceInfo = deviceInfo;
return instance->functions->_gnCreateOutputDevice(*outputDevice, instance, deviceInfo);
}
void gnWaitForDevice(gnOutputDeviceHandle device) {
device->deviceFunctions->_gnWaitForDevice(device);
}
void gnDestroyOutputDevice(gnOutputDeviceHandle device) {
device->instance->functions->_gnDestroyOutputDevice(device);
free(device);
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include <output_device/gryphn_physical_output_device.h>
#include <utils/gryphn_error_code.h>
struct gnPlatformOutputDevice_t;
struct gnDeviceFunctions_t;
typedef struct gnDeviceQueueInfo_t {
int queueIndex;
int queueCount;
// float* queuePriority;
} gnDeviceQueueInfo;
typedef struct gnOutputDeviceInfo_t {
uint32_t queueInfoCount;
struct gnDeviceQueueInfo_t* queueInfos;
struct gnPhysicalDeviceFeatures_t enabledFeatures;
struct gnPhysicalDevice_t physicalDevice;
} gnOutputDeviceInfo;
#ifdef GN_REVEAL_IMPL
struct gnOutputDevice_t {
struct gnPlatformOutputDevice_t* outputDevice;
struct gnDeviceFunctions_t* deviceFunctions;
struct gnOutputDeviceInfo_t deviceInfo;
gnInstanceHandle instance;
gnPhysicalDevice physicalDevice;
};
#endif
gnReturnCode gnCreateOutputDevice(gnOutputDeviceHandle* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void gnWaitForDevice(gnOutputDeviceHandle device);
void gnDestroyOutputDevice(gnOutputDeviceHandle device);

View File

@@ -0,0 +1,68 @@
#include "gryphn_physical_output_device.h"
#include "gryphn_platform_functions.h"
gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count) {
gnPhysicalDevice* devices = instance->functions->_gnGetPhysicalDevices(instance, count);
for (int i = 0; i < *count; i++) {
devices[i].instance = instance;
}
return devices;
}
gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, gnWindowSurfaceHandle windowSurface) {
// if (queueIndex >= device.queueProperties.queueCount) {
// gnDebuggerSetErrorMessage(device.instance->debugger,
// (gnMessageData){
// .message = gnCreateString("gnQueueCanPresentToSurface queue index passed in is large then queueProperties.queueCount")
// }
// );
// return gnFalse;
// }
return device.instance->functions->_gnQueueCanPresentToSurface(device, queueIndex, windowSurface);
}
gnBool gnHasGraphicsQueue(const struct gnPhysicalDevice_t device) {
for (int i = 0; i < device.queueProperties.queueCount; i++) {
if (device.queueProperties.queueProperties[i].queueType & GN_QUEUE_GRAPHICS) {
return gnTrue;
}
}
return gnFalse;
}
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;
}
}
return gnFalse;
}
int gnGetGraphicsQueueIndex(const struct gnPhysicalDevice_t device) {
for (int i = 0; i < device.queueProperties.queueCount; i++) {
if (device.queueProperties.queueProperties[i].queueType & GN_QUEUE_GRAPHICS) {
return i;
break;
}
}
// gnDebuggerSetErrorMessage(device.instance->debugger,
// (gnMessageData){
// .message = gnCreateString("gnGetGraphicsQueueIndex failed no queue that support graphics on this device")
// }
// );
return -1;
}
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;
break;
}
}
// gnDebuggerSetErrorMessage(device.instance->debugger,
// (gnMessageData){
// .message = gnCreateString("gnGetPresentQueueIndex failed no queue that support presenting to this window surface")
// }
// );
return -1;
}

View File

@@ -0,0 +1,54 @@
#pragma once
#include "stdint.h"
#include "utils/gryphn_string.h"
#include "gryphn_handles.h"
struct gnPlatformPhysicalDevice_t;
typedef enum gnDeviceType_e {
GN_DEDICATED_DEVICE, GN_INTEGRATED_DEVICE, GN_EXTERNAL_DEVICE
} gnDeviceType;
typedef struct gnPhysicalDeviceProperties_t {
gnString name;
gnDeviceType deviceType;
} gnPhysicalDeviceProperties;
typedef struct gnPhysicalDeviceFeatures_t {
gnBool supportsGeometryShader;
} gnPhysicalDeviceFeatures;
typedef enum gnQueueTypeFlags_e {
GN_QUEUE_GRAPHICS = 0x00000001,
GN_QUEUE_COMPUTE = 0x00000002,
GN_QUEUE_TRANSFER = 0x00000004,
GN_QUEUE_SPARSE_BINDING = 0x00000008
} gnQueueTypeFlags;
typedef struct gnQueueProperties_t {
uint32_t queueCount;
enum gnQueueTypeFlags_e queueType;
} gnQueueProperties;
typedef struct gnPhysicalDeviceQueueProperties_t {
uint32_t queueCount;
struct gnQueueProperties_t* queueProperties;
} gnPhysicalDeviceQueueProperties;
typedef struct gnPhysicalDevice_t {
struct gnPlatformPhysicalDevice_t* physicalDevice;
struct gnPhysicalDeviceProperties_t properties;
struct gnPhysicalDeviceFeatures_t features;
struct gnPhysicalDeviceQueueProperties_t queueProperties;
gnInstanceHandle instance;
} gnPhysicalDevice;
gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count);
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, gnWindowSurfaceHandle windowSurface);
int gnGetGraphicsQueueIndex(const struct gnPhysicalDevice_t device);
int gnGetPresentQueueIndex(const struct gnPhysicalDevice_t device, gnWindowSurfaceHandle windowSurface);

View File

@@ -0,0 +1,13 @@
#include "gryphn_graphics_pipeline.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) {
*graphicsPipeline = malloc(sizeof(struct gnGraphicsPipeline_t));
(*graphicsPipeline)->device = device;
(*graphicsPipeline)->info = info;
return device->deviceFunctions->_gnCreateGraphicsPipeline(*graphicsPipeline, device, info);
}
void gnDestroyGraphicsPipeline(gnGraphicsPipelineHandle graphicsPipeline) {
graphicsPipeline->device->deviceFunctions->_gnDestroyGraphicsPipeline(graphicsPipeline);
}

View File

@@ -0,0 +1,132 @@
#pragma once
#include <output_device/gryphn_output_device.h>
#include <uniforms/gryphn_uniform_layout.h>
#include <renderpass/gryphn_render_pass_descriptor.h>
#include <shader_module/gryphn_shader_module.h>
#include "utils/math/gryphn_vec2.h"
#include "gryphn_handles.h"
#include "shader_input/gryphn_shader_layout.h"
typedef enum gnDynamicState_e {
GN_DYNAMIC_VIEWPORT,
GN_DYNAMIC_SCISSOR,
GN_DYNAMIC_STATE_MAX
} gnDynamicState;
typedef struct gnDynamicStateInfo {
uint32_t dynamicStateCount;
enum gnDynamicState_e* dynamicStates;
} gnDynamicStateInfo;
typedef enum gnPrimitiveType {
GN_PRIMITIVE_POINTS, GN_PRIMITIVE_LINES, GN_PRIMITIVE_LINE_STRIP, GN_PRIMITIVE_TRIANGLES, GN_PRIMITIVE_TRIANGLE_STRIP
} gnPrimitiveType;
typedef enum gnBlendFactor_e {
GN_BLEND_FACTOR_ZERO,
GN_BLEND_FACTOR_ONE,
GN_BLEND_FACTOR_SRC_ALPHA,
GN_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
} gnBlendFactor;
typedef enum gnBlendOperation_e {
GN_OPERATION_ADD
} gnBlendOperation;
typedef struct gnViewport_t {
gnVec2 position;
gnVec2 size;
float minDepth;
float maxDepth;
} gnViewport;
typedef struct gnScissor_t {
gnInt2 position;
gnUInt2 size;
} gnScissor;
typedef enum gnFillMode_e {
GN_FILL_MODE_FILL, GN_FILL_MODE_LINE, GN_FILL_MODE_POINT
} gnFillMode;
typedef enum gnCullFace_e {
GN_CULL_FACE_NONE, GN_CULL_FACE_BACK, GN_CULL_FACE_FRONT
} gnCullFace;
typedef enum gnCullDirection_e {
GN_DIRECTION_CLOCK_WISE, GN_DIRECTION_COUNTER_CLOCK_WISE
} gnCullDirection;
typedef enum gnCompareOperation {
GN_COMPARE_NEVER, GN_COMPARE_LESS, GN_COMPARE_EQUAL,
GN_COMPARE_LESS_OR_EQUAL, GN_COMPARE_GREATER, GN_COMPARE_NOT_EQUAL,
GN_COMPARE_GREATER_OR_EQUAL, GN_COMPARE_ALWAYS
} gnCompareOperation;
typedef enum gnStencilOperation {
GN_STENCIL_KEEP, GN_STENCIL_ZERO, GN_STENCIL_REPLACE,
GN_STENCIL_INCREMENT_AND_CLAMP, GN_STENCIL_DECREMENT_AND_CLAMP,
GN_STENCIL_INVERT, GN_STENCIL_INCREMENT_AND_WRAP,
GN_STENCIL_DECREMENT_AND_WRAP,
} gnStencilOperation;
typedef struct gnCullMode_t {
enum gnCullFace_e face;
enum gnCullDirection_e direction;
} gnCullMode;
typedef struct gnColorBlending_t {
gnBool enable;
gnBlendFactor sourceColorBlendFactor;
gnBlendFactor sourceAlphaBlendFactor;
gnBlendFactor destinationColorBlendFactor;
gnBlendFactor destinationAlphaBlendFactor;
gnBlendOperation colorBlendOperation;
gnBlendOperation alphaBlendOperation;
} gnColorBlending;
typedef struct gnStencilState {
gnStencilOperation failOperation, passOperation, depthFailOperation;
gnCompareOperation compareOperation;
uint32_t compareMask, writeMask, reference;
} gnStencilState;
typedef struct gnDepthStencilState {
gnBool depthTestEnable, depthWriteEnable;
gnCompareOperation operation;
gnBool stencilTestEnable;
gnStencilState front, back;
} gnDepthStencilState;
typedef struct gnGraphicsPipelineInfo_t {
gnDynamicStateInfo dynamicState;
gnPrimitiveType primitiveType;
gnViewport viewport;
gnScissor scissor;
gnFillMode fillMode;
gnCullMode cullMode;
gnColorBlending colorBlending;
gnDepthStencilState depthStencil;
uint32_t subpassIndex;
gnRenderPassDescriptorHandle renderPassDescriptor;
uint32_t shaderModuleCount;
gnShaderModuleHandle* shaderModules;
gnShaderInputLayout shaderInputLayout;
gnUniformLayout uniformLayout;
} gnGraphicsPipelineInfo;
#ifdef GN_REVEAL_IMPL
struct gnGraphicsPipeline_t {
struct gnPlatformGraphicsPipeline_t* graphicsPipeline;
gnOutputDeviceHandle device;
gnGraphicsPipelineInfo info;
};
#endif
gnReturnCode gnCreateGraphicsPipeline(gnGraphicsPipelineHandle* graphicsPipeline, gnOutputDeviceHandle device, gnGraphicsPipelineInfo info);
void gnDestroyGraphicsPipeline(gnGraphicsPipelineHandle graphicsPipeline);

View File

@@ -0,0 +1,6 @@
#include "gryphn_platform_functions.h"
#include "gryphn_present.h"
gnReturnCode gnPresent(gnOutputDeviceHandle device, gnPresentInfo info) {
return device->deviceFunctions->_gnPresent(device, info);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "utils/gryphn_error_code.h"
#include "stdint.h"
#include "gryphn_handles.h"
typedef struct gnPresentInfo_t {
uint32_t waitCount;
gnSemaphoreHandle* waitSemaphores;
uint32_t presentationQueueCount;
gnPresentationQueueHandle* presentationQueues;
uint32_t* imageIndices;
uint32_t queueIndex;
} gnPresentInfo;
gnReturnCode gnPresent(gnOutputDeviceHandle device, gnPresentInfo info);

View File

@@ -0,0 +1,21 @@
#include "gryphn_presentation_queue.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreatePresentationQueue(gnPresentationQueueHandle* presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo){
*presentationQueue = malloc(sizeof(struct gnPresentationQueue_t));
(*presentationQueue)->outputDevice = device;
(*presentationQueue)->info = presentationInfo;
return device->deviceFunctions->_gnCreatePresentationQueue(*presentationQueue, device, presentationInfo);
}
gnReturnCode gnPresentationQueueGetImage(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex) {
return presentationQueue->outputDevice->deviceFunctions->_gnPresentationQueueGetImage(presentationQueue, timeout, semaphore, imageIndex);
}
uint32_t gnGetPresentationQueueImageCount(gnPresentationQueueHandle presentationQueue) { return presentationQueue->imageCount; }
gnTextureHandle gnGetPresentationQueueImage(gnPresentationQueueHandle presentationQueue, uint32_t index) {
return presentationQueue->images[index];
}
void gnDestroyPresentationQueue(gnPresentationQueueHandle presentationQueue) {
presentationQueue->outputDevice->deviceFunctions->_gnDestroyPresentationQueue(presentationQueue);
free(presentationQueue);
}

View File

@@ -0,0 +1,36 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include <utils/gryphn_image_format.h>
#include <output_device/gryphn_output_device.h>
#include <window_surface/gryphn_surface.h>
#include <sync/semaphore/gryphn_semaphore.h>
#include "gryphn_handles.h"
typedef struct gnPresentationQueueInfo_t {
uint32_t minImageCount;
gnUInt2 imageSize;
gnWindowSurfaceHandle surface;
gnSurfaceFormat format;
gnImageSharingMode imageSharingMode;
uint32_t queueFamilyCount;
uint32_t* queueFamilies;
} gnPresentationQueueInfo;
struct gnPlatformPresentationQueue_t;
#ifdef GN_REVEAL_IMPL
struct gnPresentationQueue_t {
struct gnPlatformPresentationQueue_t* presentationQueue;
gnOutputDeviceHandle outputDevice;
gnBool valid;
uint32_t imageCount;
gnTextureHandle* images;
struct gnPresentationQueueInfo_t info;
};
#endif
gnReturnCode gnCreatePresentationQueue(gnPresentationQueueHandle* presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo);
gnReturnCode gnPresentationQueueGetImage(gnPresentationQueueHandle presentationQueue, uint64_t timeout, gnSemaphoreHandle semaphore, uint32_t* imageIndex);
uint32_t gnGetPresentationQueueImageCount(gnPresentationQueueHandle presentationQueue);
gnTextureHandle gnGetPresentationQueueImage(gnPresentationQueueHandle presentationQueue, uint32_t index);
void gnDestroyPresentationQueue(gnPresentationQueueHandle presentationQueue);

View File

@@ -0,0 +1,13 @@
#pragma once
#include "utils/gryphn_color.h"
#include "utils/math/gryphn_vec2.h"
#include "gryphn_handles.h"
typedef struct gnRenderPassInfo_t {
gnRenderPassDescriptorHandle renderPassDescriptor;
gnFramebuffer framebuffer;
gnUInt2 offset;
gnUInt2 size;
uint32_t clearValueCount;
gnClearValue* clearValues;
} gnRenderPassInfo;

View File

@@ -0,0 +1,13 @@
#include "gryphn_render_pass_descriptor.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateRenderPassDescriptor(gnRenderPassDescriptorHandle* renderPass, gnOutputDeviceHandle device, gnRenderPassDescriptorInfo info) {
*renderPass = malloc(sizeof(struct gnRenderPassDescriptor_t));
(*renderPass)->device = device;
(*renderPass)->info = info;
return device->deviceFunctions->_gnCreateRenderPassDescriptor(*renderPass, device, info);
}
void gnDestroyRenderPassDescriptor(gnRenderPassDescriptorHandle renderPass) {
renderPass->device->deviceFunctions->_gnDestroyRenderPassDescriptor(renderPass);
}

View File

@@ -0,0 +1,80 @@
#pragma once
#include "stdint.h"
#include "utils/gryphn_image_format.h"
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
typedef enum gnRenderPassStage {
GN_COLOR_ATTACHMENT_OUTPUT = 1,
GN_EARLY_FRAGMENT_TEST = 2
} gnRenderPassStage; // I stole these from vulkan to make that conversion easier
typedef enum gnRenderPassAccess {
GN_COLOR_ATTACHMENT_WRITE = 1,
GN_DEPTH_STENCIL_WRITE = 2
} gnRenderPassAccess;
typedef enum gnLoadOperation_e {
GN_LOAD_OPERATION_LOAD, GN_LOAD_OPERATION_CLEAR, GN_LOAD_OPERATION_DONT_CARE
} gnLoadOperation;
typedef enum gnStoreOperation_e {
GN_STORE_OPERATION_STORE, GN_STORE_OPERATION_DONT_CARE
} gnStoreOperation;
typedef struct gnRenderPassAttachmentInfo_t {
gnImageFormat format;
gnLoadOperation loadOperation;
gnStoreOperation storeOperation;
gnLoadOperation stencilLoadOperation;
gnStoreOperation stencilStoreOperation;
gnImageLayout initialLayout;
gnImageLayout finalLayout;
} gnRenderPassAttachmentInfo;
typedef struct gnSubpassAttachmentInfo_t {
uint32_t index;
gnImageLayout imageLayout;
} gnSubpassAttachmentInfo;
typedef struct gnSubpassInfo_t {
uint32_t colorAttachmentCount;
gnSubpassAttachmentInfo* colorAttachments;
gnSubpassAttachmentInfo* depthAttachment;
} gnSubpassInfo;
#define GN_SUBPASS_EXTERNAL -1
typedef struct gnSubpassDependencyInfo_t {
int source, destination;
gnRenderPassStage soruceStageMask;
gnRenderPassAccess sourceAccessMask;
gnRenderPassStage destinationStageMask;
gnRenderPassAccess destinationAccessMask;
} gnSubpassDependencyInfo;
typedef struct gnRenderPassDescriptorInfo {
uint32_t attachmentCount;
gnRenderPassAttachmentInfo* attachmentInfos;
uint32_t subpassCount;
gnSubpassInfo* subpassInfos;
uint32_t dependencyCount;
gnSubpassDependencyInfo* dependencies;
} gnRenderPassDescriptorInfo;
#ifdef GN_REVEAL_IMPL
struct gnRenderPassDescriptor_t {
struct gnPlatformRenderPassDescriptor_t* renderPassDescriptor;
gnRenderPassDescriptorInfo info;
gnDeviceHandle device;
};
#endif
gnReturnCode gnCreateRenderPassDescriptor(gnRenderPassDescriptorHandle* renderPass, gnOutputDeviceHandle device, gnRenderPassDescriptorInfo info);
void gnDestroyRenderPassDescriptor(gnRenderPassDescriptorHandle renderPass);

View File

@@ -0,0 +1,25 @@
#pragma once
#include "stdint.h"
#include "stdlib.h"
typedef enum gnVertexFormat {
GN_FLOAT2, GN_FLOAT3
} gnVertexFormat;
typedef struct gnVertexAttribute {
uint32_t location;
gnVertexFormat format;
size_t offset;
} gnVertexAttribute;
typedef struct gnBufferAttribute {
uint32_t binding;
size_t size;
uint32_t attributeCount;
gnVertexAttribute* attributes;
} gnBufferAttribute;
typedef struct gnShaderInputLayout {
uint32_t bufferCount;
gnBufferAttribute* bufferAttributes;
} gnShaderInputLayout;

View File

@@ -0,0 +1,13 @@
#include <gryphn_platform_functions.h>
#include "gryphn_shader_module.h"
gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo) {
*module = malloc(sizeof(struct gnShaderModule_t));
(*module)->device = device;
(*module)->info = shaderModuleInfo;
return device->deviceFunctions->_gnCreateShaderModule(*module, device, shaderModuleInfo);
}
void gnDestroyShaderModule(gnShaderModuleHandle module) {
module->device->deviceFunctions->_gnDestroyShaderModule(module);
}

View File

@@ -0,0 +1,29 @@
#pragma once
#include "stdint.h"
#include "utils/gryphn_string.h"
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
typedef enum gnShaderModuleStage_e {
GN_VERTEX_SHADER_MODULE = 0x00000001,
GN_FRAGMENT_SHADER_MODULE = 0x00000002,
GN_ALL_SHADER_MODULE = 0xffffffff
} gnShaderModuleStage;
typedef struct gnShaderModuleInfo_t {
gnShaderModuleStage stage;
uint32_t* code;
uint32_t size;
gnString entryPoint;
} gnShaderModuleInfo;
#ifdef GN_REVEAL_IMPL
struct gnShaderModule_t {
struct gnPlatformShaderModule_t* shaderModule;
gnShaderModuleInfo info;
gnOutputDeviceHandle device;
};
#endif
gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo);
void gnDestroyShaderModule(gnShaderModuleHandle module);

View File

@@ -0,0 +1,6 @@
#include "gryphn_submit.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnSubmit(gnOutputDevice device, gnSubmitInfo info) {
return device->deviceFunctions->_gnSubmit(device, info);
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include "stdint.h"
#include "renderpass/gryphn_render_pass_descriptor.h"
#include "gryphn_handles.h"
typedef struct gnSubmitInfo_t {
uint32_t waitCount;
gnRenderPassStage* waitStages;
gnSemaphoreHandle* waitSemaphores;
uint32_t signalCount;
gnSemaphoreHandle* signalSemaphores;
uint32_t commandBufferCount;
gnCommandBufferHandle* commandBuffers;
uint32_t queueIndex;
gnFenceHandle fence;
} gnSubmitInfo;
gnReturnCode gnSubmit(gnOutputDevice device, gnSubmitInfo info);

View File

@@ -0,0 +1,24 @@
#include "gryphn_fence.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateFence(gnFenceHandle* fence, struct gnOutputDevice_t* device) {
*fence = malloc(sizeof(struct gnFence_t));
(*fence)->device = device;
(*fence)->signaled = gnFalse;
return device->deviceFunctions->_gnCreateFence(*fence, device);
}
void gnSignalFence(gnFenceHandle fence) {
fence->signaled = gnTrue;
// fence->device->deviceFunctions->_gnSignalFence(fence);
}
void gnWaitForFence(gnFenceHandle fence, uint64_t timeout) {
if (fence->signaled == gnTrue) return;
fence->device->deviceFunctions->_gnWaitForFence(fence, timeout);
}
void gnResetFence(gnFenceHandle fence) {
fence->signaled = gnFalse;
fence->device->deviceFunctions->_gnResetFence(fence);
}
void gnDestroyFence(gnFenceHandle fence) {
fence->device->deviceFunctions->_gnDestroyFence(fence);
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "stdint.h"
#include <utils/gryphn_bool.h>
#include "utils/gryphn_error_code.h"
#include "utils/lists/gryphn_array_list.h"
#include "gryphn_handles.h"
#ifdef GN_REVEAL_IMPL
struct gnFence_t {
struct gnPlatformFence_t* fence;
gnOutputDeviceHandle device;
gnBool signaled;
};
#endif
GN_ARRAY_LIST(gnFence);
gnReturnCode gnCreateFence(gnFenceHandle* fence, gnOutputDeviceHandle device);
void gnSignalFence(gnFenceHandle fence);
void gnWaitForFence(gnFenceHandle fence, uint64_t timeout);
void gnResetFence(gnFenceHandle fence);
void gnDestroyFence(gnFenceHandle fence);

View File

@@ -0,0 +1,11 @@
#include "gryphn_semaphore.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateSemaphore(gnSemaphore* semaphore, struct gnOutputDevice_t* device) {
*semaphore = malloc(sizeof(struct gnSemaphore_t));
(*semaphore)->device = device;
return device->deviceFunctions->_gnCreateSemaphore((*semaphore), device);
}
void gnDestroySemaphore(struct gnSemaphore_t* semaphore) {
semaphore->device->deviceFunctions->_gnDestroySemaphore(semaphore);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "utils/gryphn_error_code.h"
#include "utils/lists/gryphn_array_list.h"
#include "gryphn_handles.h"
#ifdef GN_REVEAL_IMPL
struct gnSemaphore_t {
struct gnPlatformSemaphore_t* semaphore;
gnOutputDeviceHandle device;
};
#endif
GN_ARRAY_LIST(gnSemaphore);
gnReturnCode gnCreateSemaphore(gnSemaphore* semaphore, struct gnOutputDevice_t* device);
void gnDestroySemaphore(gnSemaphore semaphore);

View File

@@ -0,0 +1,16 @@
#include "gryphn_texture.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateTexture(gnTexture* texture, gnDevice device, const gnTextureInfo info) {
*texture = malloc(sizeof(struct gnTexture_t));
(*texture)->device = device;
(*texture)->info = info;
return device->deviceFunctions->_gnCreateTexture(*texture, device, info);
}
void gnTextureData(gnTextureHandle texture, void* pixelData) {
texture->device->deviceFunctions->_gnTextureData(texture, pixelData);
}
void gnDestroyTexture(gnTexture texture) {
texture->device->deviceFunctions->_gnDestroyTexture(texture);
}

View File

@@ -0,0 +1,38 @@
#pragma once
#include "stdint.h"
#include "utils/gryphn_image_format.h"
#include "utils/gryphn_error_code.h"
#include <gryphn_handles.h>
typedef enum gnTextureType {
GN_TEXTURE_2D
} gnTextureType;
typedef enum gnTextureFilter {
GN_FILTER_LINEAR, GN_FILTER_NEAREST
} gnTextureFilter;
typedef enum gnTextureWrap {
GN_REPEAT, GN_MIRRORED_REPEAT, GN_CLAMP_TO_EDGE, GN_CLAMP_TO_BORDER
} gnTextureWrap;
typedef struct gnTextureInfo {
uint32_t width;
uint32_t height;
gnTextureType type;
gnImageFormat format;
gnTextureFilter minFilter, magFilter;
gnTextureWrap wrapU, wrapV, wrapW;
} gnTextureInfo;
#ifdef GN_REVEAL_IMPL
struct gnTexture_t {
struct gnPlatformTexture_t* texture;
gnDeviceHandle device;
gnTextureInfo info;
};
#endif
gnReturnCode gnCreateTexture(gnTexture* texture, gnDevice device, const gnTextureInfo info);
void gnTextureData(gnTextureHandle texture, void* pixelData);
void gnDestroyTexture(gnTexture texture);

View File

@@ -0,0 +1,12 @@
#include "gryphn_uniform.h"
#include "gryphn_uniform_pool.h"
#include "output_device/gryphn_output_device.h"
#include "gryphn_platform_functions.h"
void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo) {
uniform->pool->device->deviceFunctions->_gnUpdateBufferUniform(uniform, &bufferInfo);
}
void gnUpdateImageUniform(gnUniform uniform, gnImageUniformInfo imageInfo) {
uniform->pool->device->deviceFunctions->_gnUpdateImageUniform(uniform, &imageInfo);
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "stdint.h"
#include "stdlib.h"
#include "utils/lists/gryphn_array_list.h"
#include "gryphn_handles.h"
typedef struct gnBufferUniformInfo {
uint32_t binding;
gnBuffer buffer;
size_t offset;
size_t size;
} gnBufferUniformInfo;
typedef struct gnImageUniformInfo {
uint32_t binding;
gnTexture texture;
} gnImageUniformInfo;
#ifdef GN_REVEAL_IMPL
struct gnUniform_t {
struct gnPlatformUniform_t* uniform;
gnUniformPool pool;
};
#endif
GN_ARRAY_LIST(gnUniform)
void gnUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo bufferInfo);
void gnUpdateImageUniform(gnUniform uniform, gnImageUniformInfo imageInfo);

View File

@@ -0,0 +1,33 @@
#pragma once
#include "stdint.h"
#include "shader_module/gryphn_shader_module.h"
typedef enum gnUniformType {
GN_UNIFORM_BUFFER_DESCRIPTOR,
GN_IMAGE_DESCRIPTOR,
GN_UNIFORM_TYPE_MAX
} gnUniformType;
typedef struct gnUniformBinding {
uint32_t binding;
gnUniformType type;
gnShaderModuleStage stage;
} gnUniformBinding;
typedef struct gnUniformSet {
uint32_t uniformBindingCount;
gnUniformBinding* uniformBindings;
} gnUniformSet;
typedef struct gnPushConstantLayout {
gnShaderModuleStage stage;
size_t size;
size_t offset;
} gnPushConstantLayout;
typedef struct gnUniformLayout {
uint32_t setCount;
gnUniformSet* sets;
uint32_t pushConstantCount;
gnPushConstantLayout* pushConstants;
} gnUniformLayout;

View File

@@ -0,0 +1,27 @@
#include "gryphn_uniform_pool.h"
#include "output_device/gryphn_output_device.h"
#include "gryphn_platform_functions.h"
#include "gryphn_uniform.h"
#include "stdlib.h"
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device) {
*pool = malloc(sizeof(struct gnUniformPool_t));
(*pool)->device = device;
return device->deviceFunctions->_gnCreateUniformPool(*pool, device);
}
// you own this memory now
gnUniformArrayList gnUniformPoolAllocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInfo) {
gnUniform* uniforms = pool->device->deviceFunctions->_gnUniformPoolAllocateUniforms(pool, allocInfo);
for (int i = 0; i < allocInfo.setCount; i++)
uniforms[i]->pool = pool;
gnUniformArrayList list = gnUniformArrayListCreate();
gnUniformArrayListResize(&list, allocInfo.setCount);
for (int i = 0; i < allocInfo.setCount; i++) list.data[i] = uniforms[i];
return list;
}
void gnDestroyUniformPool(gnUniformPool pool) {
pool->device->deviceFunctions->_gnDestroyUniformPool(pool);
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "utils/gryphn_error_code.h"
#include "uniforms/gryphn_uniform_layout.h"
#include "uniforms/gryphn_uniform.h"
#include "gryphn_handles.h"
#ifdef GN_REVEAL_IMPL
struct gnUniformPool_t {
struct gnPlatformUniformPool_t* uniformPool;
gnDeviceHandle device;
};
#endif
typedef struct gnUniformAllocationInfo {
const uint32_t setCount;
const gnUniformSet* sets;
} gnUniformAllocationInfo;
gnReturnCode gnCreateUniformPool(gnUniformPool* pool, gnDeviceHandle device);
gnUniformArrayList gnUniformPoolAllocateUniforms(gnUniformPool pool, gnUniformAllocationInfo allocInfo);
void gnDestroyUniformPool(gnUniformPool pool);

View File

@@ -0,0 +1,75 @@
#include "gryphn_surface.h"
#include "gryphn_platform_functions.h"
void gnDestroyWindowSurface(gnWindowSurfaceHandle windowSurface) {
windowSurface->instance->functions->_gnDestroyWindowSurface(windowSurface);
}
struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
uint32_t* formatCount
) {
gnSurfaceDetails surfaceDetails = windowSurface->instance->functions->_gnGetSurfaceDetails(windowSurface, device);
*formatCount = surfaceDetails.formatCount;
return surfaceDetails.formats;
}
gnBool gnIsSurfaceFormatSupported(
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
) {
uint32_t formatCount = 0;
gnSurfaceFormat* formats = gnGetSupportedSurfaceFormats(windowSurface, device, &formatCount);
for (int i = 0; i < formatCount; i++) {
if (formats[i].format == format.format && formats[i].colorSpace == format.colorSpace) {
return gnTrue;
}
}
return gnFalse;
}
struct gnSurfaceFormat_t gnGetPreferredSurfaceFormat(
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
) {
uint32_t formatCount = 0;
gnSurfaceFormat* formats = gnGetSupportedSurfaceFormats(windowSurface, device, &formatCount);
for (int i = 0; i < formatCount; i++) {
if (formats[i].format == format.format && formats[i].colorSpace == format.colorSpace) {
return formats[i];
}
}
// will attempt to give you a simmilar format that either matches the Image format and the Color space
for (int i = 0; i < formatCount; i++) {
if (formats[i].format == format.format || formats[i].colorSpace == format.colorSpace) {
return formats[i];
}
}
return formats[0];
}
uint32_t gnGetMinImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device) {
gnSurfaceDetails surfaceDetails = surface->instance->functions->_gnGetSurfaceDetails(surface, device);
return surfaceDetails.minImageCount;
}
uint32_t gnGetMaxImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device) {
gnSurfaceDetails surfaceDetails = surface->instance->functions->_gnGetSurfaceDetails(surface, device);
return surfaceDetails.maxImageCount;
}
uint32_t gnGetPreferredImageCount(gnWindowSurfaceHandle surface, struct gnPhysicalDevice_t device) {
gnSurfaceDetails surfaceDetails = surface->instance->functions->_gnGetSurfaceDetails(surface, device);
uint32_t imageCount = surfaceDetails.minImageCount + 1;
if (surfaceDetails.maxImageCount > 0 && imageCount > surfaceDetails.maxImageCount) {
imageCount = surfaceDetails.maxImageCount;
}
return imageCount;
}
gnSurfaceDetails gnGetSurfaceDetails(gnWindowSurfaceHandle surface, gnPhysicalDevice device) { return surface->instance->functions->_gnGetSurfaceDetails(surface, device); }

View File

@@ -0,0 +1,53 @@
#pragma once
#include <platform/gryphn_platform_include.h>
#include <utils/gryphn_image_format.h>
#include <instance/gryphn_instance.h>
#include "output_device/gryphn_physical_output_device.h"
typedef struct gnSurfaceFormat_t {
gnImageFormat format;
gnColorSpace colorSpace;
} gnSurfaceFormat;
typedef struct gnSurfaceDetails {
uint32_t formatCount;
struct gnSurfaceFormat_t* formats;
uint32_t minImageCount, maxImageCount;
gnUInt2 minImageSize, maxImageSize, currentSize;
} gnSurfaceDetails;
#ifdef GN_REVEAL_IMPL
struct gnWindowSurface_t {
struct gnPlatformWindowSurface_t* windowSurface;
gnInstanceHandle instance;
};
#endif
// typedef struct gnWindowSurface_t* gnWindowSurfaceHandle;
void gnDestroyWindowSurface(gnWindowSurfaceHandle windowSurface);
struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
uint32_t* formatCount
);
gnBool gnIsSurfaceFormatSupported(
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
);
// this function will give you you're preferred surface format
// 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(
gnWindowSurfaceHandle windowSurface,
struct gnPhysicalDevice_t device,
struct gnSurfaceFormat_t format
);
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);
gnSurfaceDetails gnGetSurfaceDetails(gnWindowSurfaceHandle surface, gnPhysicalDevice device);

View File

@@ -0,0 +1,35 @@
#include "gryphn_surface_create_functions.h"
#include "instance/gryphn_instance.h"
#include "gryphn_platform_functions.h"
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode gnCreateX11WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo) {
*windowSurface = malloc(sizeof(struct gnWindowSurface_t));
(*windowSurface)->instance = instance;
return instance->functions->_gnCreateX11WindowSurface(*windowSurface, instance, createInfo);
}
#endif
#ifdef GN_WINDOW_WAYLAND
gnReturnCode gnCreateWaylandWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
*windowSurface = malloc(sizeof(struct gnWindowSurface_t));
return instance->functions->_gnCreateWaylandWindowSurface(windowSurface, instance, createInfo);
}
#endif
#endif
#ifdef GN_PLATFORM_WIN32
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(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

@@ -0,0 +1,45 @@
#pragma once
#ifndef GN_WINDOW_X11
#define GN_WINDOW_X11
#endif
#include <platform/gryphn_platform_include.h>
#include <gryphn_handles.h>
#include <utils/gryphn_error_code.h>
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
typedef struct gnX11WindowSurfaceInfo {
Display* display;
Window window;
} gnX11WindowSurfaceInfo;
gnReturnCode gnCreateX11WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo);
#endif
#ifdef GN_WINDOW_WAYLAND
typedef struct gnWaylandWindowSurfaceInfo_t {
wl_display* display;
wl_surface* surface;
} gnWaylandWindowSurfaceInfo;
gnReturnCode gnCreateWaylandWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
#endif
#endif
#ifdef GN_PLATFORM_WIN32
typedef struct gnWin32WindowSurfaceInfo_t {
HWND* window;
HINSTANCE* instance;
} gnWin32WindowSurfaceInfo;
gnReturnCode gnCreateWin32WindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_PLATFORM_MACOS
typedef struct gnMacOSWindowSurfaceInfo_t {
CAMetalLayer* layer;
} gnMacOSWindowSurfaceInfo;
gnReturnCode gnCreateMacOSWindowSurface(gnWindowSurfaceHandle* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
#endif