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

@@ -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;