move device functions over to loader

This commit is contained in:
Gregory Wells
2025-06-24 13:46:01 -04:00
parent 93921452ba
commit 8d2c58b0e9
32 changed files with 172 additions and 134 deletions

View File

@@ -0,0 +1,7 @@
#include "vulkan_loader.h"
gnDeviceFunctions loadVulkanDeviceFunctions() {
return (gnDeviceFunctions){
NULL
};
}

View File

@@ -4,7 +4,7 @@
#include <output_device/vulkan_output_devices.h>
#include <vulkan_surface/vulkan_surface.h>
gnInstanceFunctions loadVulkanFunctions(gnRenderingAPI api) {
gnInstanceFunctions loadVulkanInstanceFunctions() {
return (gnInstanceFunctions){
._gnCreateInstance = createInstance,
._gnDestroyInstance = destroyInstance,

View File

@@ -1,5 +1,6 @@
#pragma once
#include "loader/src/gryphn_instance_functions.h"
#include "core/src/gryphn_rendering_api.h"
#include "loader/src/gryphn_device_functions.h"
gnInstanceFunctions loadVulkanFunctions(gnRenderingAPI api);
gnInstanceFunctions loadVulkanInstanceFunctions();
gnDeviceFunctions loadVulkanDeviceFunctions();

View File

@@ -1,7 +1,7 @@
#include "vulkan_command_pool.h"
#include "output_device/vulkan_output_devices.h"
gnReturnCode gnCreateCommandPoolFn(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, struct gnCommandPoolInfo_t info) {
gnReturnCode gnCreateCommandPoolFn(struct gnCommandPool_t* commandPool, struct gnOutputDevice_t* device, gnCommandPoolInfo info) {
commandPool->commandPool = malloc(sizeof(gnPlatformCommandPool));
VkCommandPoolCreateInfo poolInfo = {

View File

@@ -8,7 +8,7 @@
#include "uniforms/vulkan_uniform.h"
#include "shader_module/vulkan_shader_module.h"
void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, struct gnRenderPassInfo_t passInfo) {
void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, gnRenderPassInfo passInfo) {
VkClearValue* values = malloc(sizeof(VkClearValue) * passInfo.clearValueCount);
for (int i = 0; i < passInfo.clearValueCount; i++) {
values[i] = (VkClearValue){{{
@@ -51,7 +51,7 @@ void gnCommandSetViewportFn(gnCommandBuffer buffer, gnViewport viewport) {
};
vkCmdSetViewport(buffer->commandBuffer->buffer, 0, 1, &vkViewport);
}
void gnCommandSetScissorFn(gnCommandBuffer buffer, struct gnScissor_t scissor) {
void gnCommandSetScissorFn(gnCommandBuffer buffer, gnScissor scissor) {
VkRect2D vkScissor = {
.extent = { scissor.size.x, scissor.size.y },
.offset = { scissor.position.x, scissor.position.y }

View File

@@ -3,7 +3,7 @@
#include "renderpass/vulkan_render_pass_descriptor.h"
#include "output_device/vulkan_output_devices.h"
gnReturnCode gnCreateFramebufferFn(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t info) {
gnReturnCode gnCreateFramebufferFn(gnFramebuffer framebuffer, gnDevice device, gnFramebufferInfo info) {
framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t));
VkImageView* attachments = malloc(sizeof(VkImageView) * info.attachmentCount);
@@ -28,7 +28,7 @@ gnReturnCode gnCreateFramebufferFn(struct gnFramebuffer_t* framebuffer, struct g
return GN_SUCCESS;
}
void gnDestroyFramebufferFn(struct gnFramebuffer_t* framebuffer) {
void gnDestroyFramebufferFn(gnFramebuffer framebuffer) {
vkDestroyFramebuffer(framebuffer->device->outputDevice->device, framebuffer->framebuffer->framebuffer, NULL);
free(framebuffer->framebuffer);
}

View File

@@ -4,10 +4,7 @@
#include "renderpass/vulkan_render_pass_descriptor.h"
#include "uniforms/vulkan_uniform_layout.h"
#include "stdio.h"
VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) {
VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(gnDynamicState state) {
switch (state) {
case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_VIEWPORT;
case GN_DYNAMIC_SCISSOR: return VK_DYNAMIC_STATE_SCISSOR;
@@ -26,7 +23,7 @@ VkPrimitiveTopology vkGryphnPrimitiveType(gnPrimitiveType primitiveType) {
}
}
VkPolygonMode vkGryphnPolygonMode(enum gnFillMode_e fillMode) {
VkPolygonMode vkGryphnPolygonMode(gnFillMode fillMode) {
switch (fillMode) {
case GN_FILL_MODE_FILL: return VK_POLYGON_MODE_FILL;
case GN_FILL_MODE_LINE: return VK_POLYGON_MODE_LINE;
@@ -34,7 +31,7 @@ VkPolygonMode vkGryphnPolygonMode(enum gnFillMode_e fillMode) {
}
}
VkCullModeFlags vkGryphnCullMode(enum gnCullFace_e face) {
VkCullModeFlags vkGryphnCullMode(gnCullFace face) {
switch (face) {
case GN_CULL_FACE_NONE: return VK_CULL_MODE_NONE;
case GN_CULL_FACE_BACK: return VK_CULL_MODE_BACK_BIT;
@@ -42,7 +39,7 @@ VkCullModeFlags vkGryphnCullMode(enum gnCullFace_e face) {
}
}
VkBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) {
VkBlendFactor vkGryphnBlendFactor(gnBlendFactor factor) {
switch (factor) {
case GN_BLEND_FACTOR_ZERO: return VK_BLEND_FACTOR_ZERO;
case GN_BLEND_FACTOR_ONE: return VK_BLEND_FACTOR_ONE;
@@ -51,7 +48,7 @@ VkBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) {
}
}
VkBlendOp vkGryphnBlendOperation(enum gnBlendOperation_e operation) {
VkBlendOp vkGryphnBlendOperation(gnBlendOperation operation) {
switch(operation) {
case GN_OPERATION_ADD: return VK_BLEND_OP_ADD;
}

View File

@@ -3,7 +3,7 @@
#include "presentation_queue/vulkan_presentation_queue.h"
#include "output_device/vulkan_output_devices.h"
gnReturnCode gnPresentFn(struct gnOutputDevice_t* device, struct gnPresentInfo_t info) {
gnReturnCode gnPresentFn(gnDevice device, gnPresentInfo info) {
VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount);
for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore;

View File

@@ -7,7 +7,7 @@
#include "sync/semaphore/vulkan_semaphore.h"
#include "stdio.h"
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, struct gnPresentationQueueInfo_t presentationInfo) {
gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQueue, const gnDevice device, gnPresentationQueueInfo presentationInfo) {
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
vkSwapchainSupportDetails details = vkGetSwapchainSupport(device->physicalDevice.physicalDevice->device, presentationInfo.surface->windowSurface->surface);

View File

@@ -7,9 +7,7 @@
#include "renderpass/vulkan_render_pass_descriptor.h"
gnReturnCode gnSubmitFn(struct gnOutputDevice_t* device, struct gnSubmitInfo_t info) {
VK_SUBPASS_EXTERNAL;
gnReturnCode gnSubmitFn(gnDevice device, gnSubmitInfo info) {
VkSemaphore* waitSemaphores = malloc(sizeof(VkSemaphore) * info.waitCount);
VkPipelineStageFlags* waitStages = malloc(sizeof(VkPipelineStageFlags) * info.waitCount);
for (int i = 0; i < info.waitCount; i++) waitSemaphores[i] = info.waitSemaphores[i]->semaphore->semaphore;

View File

@@ -1,5 +1,5 @@
#include "gryphn_command_buffer.h"
#include "gryphn_platform_functions.h"
#include "command/command_pool/gryphn_command_pool.h"
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
for (int i = 0; i < count; i++) {

View File

@@ -1,7 +1,6 @@
#include "gryphn_command_pool.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info) {
gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info) {
*commandPool = malloc(sizeof(struct gnCommandPool_t));
(*commandPool)->commandFunctions = device->instance->commandFunctions;

View File

@@ -2,8 +2,9 @@
#include "stdint.h"
#include <utils/gryphn_error_code.h>
#include "gryphn_handles.h"
#include <gryphn_platform_functions.h>
typedef struct gnCommandPoolInfo_t {
typedef struct gnCommandPoolInfo {
uint32_t queueIndex;
} gnCommandPoolInfo;
@@ -15,5 +16,5 @@ struct gnCommandPool_t {
};
#endif
gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, struct gnCommandPoolInfo_t info);
gnReturnCode gnCreateCommandPool(gnCommandPoolHandle* commandPool, gnOutputDeviceHandle device, gnCommandPoolInfo info);
void gnDestroyCommandPool(gnCommandPoolHandle commandPool);

View File

@@ -3,20 +3,20 @@
#include "command/command_pool/gryphn_command_pool.h"
#include "gryphn_platform_functions.h"
void gnCommandBeginRenderPass(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) {
void gnCommandBeginRenderPass(gnCommandBufferHandle buffer, gnRenderPassInfo passInfo) {
buffer->commandPool->commandFunctions->_gnCommandBeginRenderPass(buffer, passInfo);
}
void gnCommandEndRenderPass(struct gnCommandBuffer_t* buffer) {
void gnCommandEndRenderPass(gnCommandBufferHandle buffer) {
buffer->commandPool->commandFunctions->_gnCommandEndRenderPass(buffer);
}
void gnCommandBindGraphicsPipeline(struct gnCommandBuffer_t* buffer, struct gnGraphicsPipeline_t* graphicsPipeline) {
void gnCommandBindGraphicsPipeline(gnCommandBufferHandle buffer, gnGraphicsPipeline graphicsPipeline) {
buffer->commandPool->commandFunctions->_gnCommandBindGraphicsPipeline(buffer, graphicsPipeline);
}
void gnCommandSetViewport(struct gnCommandBuffer_t* buffer, struct gnViewport_t viewport) {
void gnCommandSetViewport(gnCommandBufferHandle buffer, gnViewport viewport) {
buffer->commandPool->commandFunctions->_gnCommandSetViewport(buffer, viewport);
}
void gnCommandSetScissor(struct gnCommandBuffer_t* buffer, struct gnScissor_t scissor) {
void gnCommandSetScissor(gnCommandBufferHandle buffer, gnScissor scissor) {
buffer->commandPool->commandFunctions->_gnCommandSetScissor(buffer, scissor);
}
void gnCommandBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) {
@@ -28,7 +28,7 @@ void gnCommandBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBi
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) {
void gnCommandDraw(gnCommandBufferHandle 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) {

View File

@@ -3,7 +3,7 @@
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
typedef struct gnFramebufferInfo_t {
typedef struct gnFramebufferInfo {
gnRenderPassDescriptorHandle renderPassDescriptor;
uint32_t attachmentCount;
gnTextureHandle* attachments;

View File

@@ -3,74 +3,10 @@
// 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"
#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);

View File

@@ -6,7 +6,13 @@
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceInfo info) {
*instance = malloc(sizeof(struct gnInstance_t));
(*instance)->instanceFunctions = loadInstanceFunctions(info.renderingAPI);
loaderInfo loadInfo = {
.api = info.renderingAPI
};
(*instance)->instanceFunctions = loadInstanceFunctions(loadInfo);
(*instance)->deviceFunctions = loadDeviceFunctions(loadInfo);
(*instance)->debugger = info.debugger;
return (*instance)->instanceFunctions._gnCreateInstance((*instance), info);
}

View File

@@ -4,6 +4,7 @@
#include "utils/gryphn_version.h"
#include "utils/gryphn_error_code.h"
#include "loader/src/gryphn_instance_functions.h"
#include "loader/src/gryphn_device_functions.h"
typedef struct gnInstanceInfo {
gnString applicationName;
@@ -19,12 +20,10 @@ typedef struct gnInstanceInfo {
#ifdef GN_REVEAL_IMPL
struct gnInstance_t {
struct gnPlatformInstance_t* instance;
gnBool valid,
loadDeviceFunctions,
loadCommandFunctions;
gnBool valid;
gnInstanceFunctions instanceFunctions;
struct gnDeviceFunctions_t* deviceFunctions;
gnDeviceFunctions deviceFunctions;
struct gnCommandFunctions_t* commandFunctions;
gnDebuggerHandle debugger;

View File

@@ -1,10 +1,9 @@
#include "gryphn_output_device.h"
#include "instance/gryphn_instance.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreateOutputDevice(gnOutputDeviceHandle* outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) {
*outputDevice = malloc(sizeof(struct gnOutputDevice_t));
(*outputDevice)->deviceFunctions = instance->deviceFunctions;
(*outputDevice)->deviceFunctions = &instance->deviceFunctions;
(*outputDevice)->instance = instance;
(*outputDevice)->physicalDevice = deviceInfo.physicalDevice;

View File

@@ -1,6 +1,7 @@
#pragma once
#include <output_device/gryphn_physical_output_device.h>
#include <utils/gryphn_error_code.h>
#include "loader/src/gryphn_device_functions.h"
typedef struct gnDeviceQueueInfo {
int queueIndex;
@@ -18,7 +19,7 @@ typedef struct gnOutputDeviceInfo {
#ifdef GN_REVEAL_IMPL
struct gnOutputDevice_t {
struct gnPlatformOutputDevice_t* outputDevice;
struct gnDeviceFunctions_t* deviceFunctions;
gnDeviceFunctions* deviceFunctions;
gnOutputDeviceInfo deviceInfo;
gnInstanceHandle instance;
gnPhysicalDevice physicalDevice;

View File

@@ -7,7 +7,7 @@
#include "gryphn_handles.h"
#include "shader_input/gryphn_shader_layout.h"
typedef enum gnDynamicState_e {
typedef enum gnDynamicState {
GN_DYNAMIC_VIEWPORT,
GN_DYNAMIC_SCISSOR,
@@ -16,45 +16,45 @@ typedef enum gnDynamicState_e {
typedef struct gnDynamicStateInfo {
uint32_t dynamicStateCount;
enum gnDynamicState_e* dynamicStates;
gnDynamicState* 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 {
typedef enum gnBlendFactor {
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 {
typedef enum gnBlendOperation {
GN_OPERATION_ADD
} gnBlendOperation;
typedef struct gnViewport_t {
typedef struct gnViewport {
gnVec2 position;
gnVec2 size;
float minDepth;
float maxDepth;
} gnViewport;
typedef struct gnScissor_t {
typedef struct gnScissor {
gnInt2 position;
gnUInt2 size;
} gnScissor;
typedef enum gnFillMode_e {
typedef enum gnFillMode {
GN_FILL_MODE_FILL, GN_FILL_MODE_LINE, GN_FILL_MODE_POINT
} gnFillMode;
typedef enum gnCullFace_e {
typedef enum gnCullFace {
GN_CULL_FACE_NONE, GN_CULL_FACE_BACK, GN_CULL_FACE_FRONT
} gnCullFace;
typedef enum gnCullDirection_e {
typedef enum gnCullDirection {
GN_DIRECTION_CLOCK_WISE, GN_DIRECTION_COUNTER_CLOCK_WISE
} gnCullDirection;
@@ -72,11 +72,11 @@ typedef enum gnStencilOperation {
} gnStencilOperation;
typedef struct gnCullMode_t {
enum gnCullFace_e face;
enum gnCullDirection_e direction;
gnCullFace face;
gnCullDirection direction;
} gnCullMode;
typedef struct gnColorBlending_t {
typedef struct gnColorBlending {
gnBool enable;
gnBlendFactor sourceColorBlendFactor;
gnBlendFactor sourceAlphaBlendFactor;
@@ -100,7 +100,7 @@ typedef struct gnDepthStencilState {
gnStencilState front, back;
} gnDepthStencilState;
typedef struct gnGraphicsPipelineInfo_t {
typedef struct gnGraphicsPipelineInfo {
gnDynamicStateInfo dynamicState;
gnPrimitiveType primitiveType;
gnViewport viewport;

View File

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

View File

@@ -3,7 +3,7 @@
#include "stdint.h"
#include "gryphn_handles.h"
typedef struct gnPresentInfo_t {
typedef struct gnPresentInfo {
uint32_t waitCount;
gnSemaphoreHandle* waitSemaphores;
uint32_t presentationQueueCount;

View File

@@ -1,5 +1,4 @@
#include "gryphn_presentation_queue.h"
#include "gryphn_platform_functions.h"
gnReturnCode gnCreatePresentationQueue(gnPresentationQueueHandle* presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo){
*presentationQueue = malloc(sizeof(struct gnPresentationQueue_t));

View File

@@ -6,7 +6,7 @@
#include <sync/semaphore/gryphn_semaphore.h>
#include "gryphn_handles.h"
typedef struct gnPresentationQueueInfo_t {
typedef struct gnPresentationQueueInfo {
uint32_t minImageCount;
gnUInt2 imageSize;
gnWindowSurfaceHandle surface;
@@ -25,7 +25,7 @@ struct gnPresentationQueue_t {
gnBool valid;
uint32_t imageCount;
gnTextureHandle* images;
struct gnPresentationQueueInfo_t info;
gnPresentationQueueInfo info;
};
#endif

View File

@@ -1,7 +1,7 @@
#include <gryphn_platform_functions.h>
#include "gryphn_shader_module.h"
gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo) {
gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo shaderModuleInfo) {
*module = malloc(sizeof(struct gnShaderModule_t));
(*module)->device = device;
(*module)->info = shaderModuleInfo;

View File

@@ -4,13 +4,13 @@
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
typedef enum gnShaderModuleStage_e {
typedef enum gnShaderModuleStage {
GN_VERTEX_SHADER_MODULE = 0x00000001,
GN_FRAGMENT_SHADER_MODULE = 0x00000002,
GN_ALL_SHADER_MODULE = 0xffffffff
} gnShaderModuleStage;
typedef struct gnShaderModuleInfo_t {
typedef struct gnShaderModuleInfo {
gnShaderModuleStage stage;
uint32_t* code;
uint32_t size;
@@ -25,5 +25,5 @@ struct gnShaderModule_t {
};
#endif
gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo_t shaderModuleInfo);
gnReturnCode gnCreateShaderModule(gnShaderModuleHandle* module, gnOutputDeviceHandle device, struct gnShaderModuleInfo shaderModuleInfo);
void gnDestroyShaderModule(gnShaderModuleHandle module);

View File

@@ -1,5 +1,5 @@
#include "gryphn_submit.h"
#include "gryphn_platform_functions.h"
#include "output_device/gryphn_output_device.h"
gnReturnCode gnSubmit(gnOutputDevice device, gnSubmitInfo info) {
return device->deviceFunctions->_gnSubmit(device, info);

View File

@@ -3,7 +3,7 @@
#include "renderpass/gryphn_render_pass_descriptor.h"
#include "gryphn_handles.h"
typedef struct gnSubmitInfo_t {
typedef struct gnSubmitInfo {
uint32_t waitCount;
gnRenderPassStage* waitStages;
gnSemaphoreHandle* waitSemaphores;

View File

@@ -0,0 +1,70 @@
#pragma once
#include "stdint.h"
#include "stdlib.h"
#include "utils/gryphn_error_code.h"
#include "gryphn_handles.h"
typedef struct gnPresentationQueueInfo gnPresentationQueueInfo;
typedef struct gnShaderModuleInfo gnShaderModuleInfo;
typedef struct gnRenderPassDescriptorInfo gnRenderPassDescriptorInfo;
typedef struct gnGraphicsPipelineInfo gnGraphicsPipelineInfo;
typedef struct gnFramebufferInfo gnFramebufferInfo;
typedef struct gnCommandPoolInfo gnCommandPoolInfo;
typedef struct gnBufferInfo gnBufferInfo;
typedef struct gnUniformAllocationInfo gnUniformAllocationInfo;
typedef struct gnBufferUniformInfo gnBufferUniformInfo;
typedef struct gnImageUniformInfo gnImageUniformInfo;
typedef struct gnTextureInfo gnTextureInfo;
typedef struct gnSubmitInfo gnSubmitInfo;
typedef struct gnPresentInfo gnPresentInfo;
typedef struct gnDeviceFunctions {
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;

View File

@@ -1,9 +1,28 @@
#include "gryphn_loader.h"
#include <apis/vulkan/loader/vulkan_loader.h>
gnInstanceFunctions loadInstanceFunctions(gnRenderingAPI api) {
switch (api) {
gnInstanceFunctions loadInstanceFunctions(loaderInfo info) {
switch (info.api) {
case GN_RENDERINGAPI_NONE: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_VULKAN: return loadVulkanFunctions(api);
case GN_RENDERINGAPI_VULKAN: return loadVulkanInstanceFunctions();
case GN_RENDERINGAPI_SOFTWARE: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_OPENGL: return (gnInstanceFunctions){ NULL };
case GN_RENDERINGAPI_METAL: return (gnInstanceFunctions){ NULL };
}
}
gnDeviceFunctions loadDeviceFunctions(loaderInfo info) {
switch (info.api) {
case GN_RENDERINGAPI_NONE: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_VULKAN: return loadVulkanDeviceFunctions();
case GN_RENDERINGAPI_SOFTWARE: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_OPENGL: return (gnDeviceFunctions){ NULL };
case GN_RENDERINGAPI_METAL: return (gnDeviceFunctions){ NULL };
}
}

View File

@@ -1,5 +1,11 @@
#pragma once
#include "gryphn_rendering_api.h"
#include "gryphn_instance_functions.h"
#include "gryphn_device_functions.h"
gnInstanceFunctions loadInstanceFunctions(gnRenderingAPI api);
typedef struct loaderInfo {
gnRenderingAPI api;
} loaderInfo;
gnInstanceFunctions loadInstanceFunctions(loaderInfo info);
gnDeviceFunctions loadDeviceFunctions(loaderInfo info);