From 2c9e2260f439b266930e08d4ac2fc5ff63c5fd78 Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Wed, 25 Jun 2025 10:46:07 -0400 Subject: [PATCH] get the metal backend to compile (does not load) --- CMakeLists.txt | 5 +- projects/apis/metal/CMakeLists.txt | 9 ++-- .../apis/metal/loader/metal_command_loader.c | 22 ++++++++ .../apis/metal/loader/metal_device_loader.c | 53 +++++++++++++++++++ .../apis/metal/loader/metal_instance_loader.c | 15 ++++++ projects/apis/metal/loader/metal_loader.h | 8 +++ projects/apis/metal/src/buffer/metal_buffer.m | 6 +-- .../command_buffer/metal_command_buffer.h | 4 +- .../command_buffer/metal_command_buffer.m | 2 +- .../command_pool/metal_command_pool.h | 2 +- .../command_pool/metal_command_pool.m | 4 +- .../src/commands/commands/metal_commands.m | 32 +++++------ .../apis/metal/src/debugger/metal_debugger.m | 4 +- .../metal/src/devices/metal_output_device.m | 10 ++-- .../metal/src/devices/metal_output_devices.h | 4 +- .../metal/src/devices/metal_physical_device.m | 6 +-- .../src/framebuffers/metal_framebuffer.h | 2 +- .../src/framebuffers/metal_framebuffer.m | 15 +++--- .../metal_graphics_pipeline.h | 2 +- .../metal_graphics_pipeline.m | 14 ++--- .../apis/metal/src/present/metal_present.m | 18 +++---- .../metal_presentation_queue.h | 2 +- .../metal_presentation_queue.m | 12 ++--- .../metal/src/renderpass/metal_render_pass.h | 2 +- .../metal/src/renderpass/metal_render_pass.m | 2 +- .../src/shader_module/metal_shader_module.h | 2 +- .../src/shader_module/metal_shader_module.m | 6 +-- projects/apis/metal/src/submit/metal_submit.m | 13 ++--- .../apis/metal/src/surface/metal_surface.h | 2 +- .../apis/metal/src/surface/metal_surface.m | 12 ++--- .../apis/metal/src/sync/fence/metal_fence.h | 2 +- .../apis/metal/src/sync/fence/metal_fence.m | 2 +- .../src/sync/semaphore/metal_semaphore.h | 2 +- .../src/sync/semaphore/metal_semaphore.m | 6 +-- .../apis/metal/src/texture/metal_texture.h | 2 +- .../apis/metal/src/uniforms/metal_uniform.c | 11 ++-- .../apis/metal/src/uniforms/metal_uniform.h | 14 +++-- .../metal/src/uniforms/metal_uniform_pool.c | 18 ++++--- .../metal/src/uniforms/metal_uniform_pool.h | 5 +- 39 files changed, 235 insertions(+), 117 deletions(-) create mode 100644 projects/apis/metal/loader/metal_command_loader.c create mode 100644 projects/apis/metal/loader/metal_device_loader.c create mode 100644 projects/apis/metal/loader/metal_instance_loader.c create mode 100644 projects/apis/metal/loader/metal_loader.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c637a91..6bdb76b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,9 @@ if (UNIX AND NOT APPLE) target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl) endif() if (APPLE) - add_compile_definitions(GN_PLATFORM_MACOS) + add_compile_definitions(GN_PLATFORM_MACOS GN_API_VULKAN GN_API_METAL) add_subdirectory(projects/apis/vulkan/) - target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl) + add_subdirectory(projects/apis/metal/) + target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl GryphnMetalImpl) endif() target_link_libraries(Gryphn INTERFACE GryphnCore GryphnLoader GryphnPlatform) diff --git a/projects/apis/metal/CMakeLists.txt b/projects/apis/metal/CMakeLists.txt index dceaf16..e41f303 100644 --- a/projects/apis/metal/CMakeLists.txt +++ b/projects/apis/metal/CMakeLists.txt @@ -7,10 +7,11 @@ file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS ) add_library(GryphnMetalImpl STATIC ${SOURCE_FILES}) target_include_directories(GryphnMetalImpl PUBLIC - ${CMAKE_SOURCE_DIR}/gryphn/include/ - ${CMAKE_SOURCE_DIR}/gryphn/src/ - ${CMAKE_SOURCE_DIR}/gryphn/src/utils/ - src/ + ${CMAKE_CURRENT_SOURCE_DIR}/../../core/src/ + ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/ + ${CMAKE_CURRENT_SOURCE_DIR}/../../ + ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/ + ${CMAKE_CURRENT_SOURCE_DIR}/src/ depends/SPIRV-Cross/ ) add_compile_definitions(GN_REVEAL_IMPL) diff --git a/projects/apis/metal/loader/metal_command_loader.c b/projects/apis/metal/loader/metal_command_loader.c new file mode 100644 index 0000000..c6548e0 --- /dev/null +++ b/projects/apis/metal/loader/metal_command_loader.c @@ -0,0 +1,22 @@ +#include "metal_loader.h" + +gnCommandFunctions loadMetalCommandFunctions() { + return (gnCommandFunctions){ + ._gnCommandPoolAllocateCommandBuffers = NULL, + ._gnBeginCommandBuffer = NULL, + ._gnResetCommandBuffer = NULL, + ._gnEndCommandBuffer = NULL, + + ._gnCommandBeginRenderPass = NULL, + ._gnCommandEndRenderPass = NULL, + ._gnCommandBindGraphicsPipeline = NULL, + ._gnCommandSetViewport = NULL, + ._gnCommandSetScissor = NULL, + ._gnCommandBindUniform = NULL, + ._gnCommandPushConstant = NULL, + + ._gnCommandBindBuffer = NULL, + ._gnCommandDraw = NULL, + ._gnCommandDrawIndexed = NULL, + }; +} diff --git a/projects/apis/metal/loader/metal_device_loader.c b/projects/apis/metal/loader/metal_device_loader.c new file mode 100644 index 0000000..5ca513d --- /dev/null +++ b/projects/apis/metal/loader/metal_device_loader.c @@ -0,0 +1,53 @@ +#include "metal_loader.h" + +gnDeviceFunctions loadMetalDeviceFunctions() { + return (gnDeviceFunctions){ + ._gnCreatePresentationQueue = NULL, + ._gnPresentationQueueGetImage = NULL, + ._gnDestroyPresentationQueue = NULL, + + ._gnCreateShaderModule = NULL, + ._gnDestroyShaderModule = NULL, + + ._gnCreateRenderPassDescriptor = NULL, + ._gnDestroyRenderPassDescriptor = NULL, + + ._gnCreateGraphicsPipeline = NULL, + ._gnDestroyGraphicsPipeline = NULL, + + ._gnCreateFramebuffer = NULL, + ._gnDestroyFramebuffer = NULL, + + ._gnCreateCommandPool = NULL, + ._gnDestroyCommandPool = NULL, + + ._gnCreateSemaphore = NULL, + ._gnDestroySemaphore = NULL, + + ._gnCreateBuffer = NULL, + ._gnBufferData = NULL, + ._gnMapBuffer = NULL, + ._gnDestroyBuffer = NULL, + + ._gnCreateUniformPool = NULL, + ._gnUniformPoolAllocateUniforms = NULL, + ._gnDestroyUniformPool = NULL, + + ._gnUpdateBufferUniform = NULL, + ._gnUpdateImageUniform = NULL, + + ._gnCreateTexture = NULL, + ._gnTextureData = NULL, + ._gnDestroyTexture = NULL, + + ._gnCreateFence = NULL, + ._gnWaitForFence = NULL, + ._gnResetFence = NULL, + ._gnDestroyFence = NULL, + + ._gnSubmit = NULL, + ._gnPresent = NULL, + + ._gnWaitForDevice = NULL + }; +} diff --git a/projects/apis/metal/loader/metal_instance_loader.c b/projects/apis/metal/loader/metal_instance_loader.c new file mode 100644 index 0000000..a156710 --- /dev/null +++ b/projects/apis/metal/loader/metal_instance_loader.c @@ -0,0 +1,15 @@ +#include "metal_loader.h" + +gnInstanceFunctions loadMetalInstanceFunctions() { + return (gnInstanceFunctions){ + ._gnCreateInstance = NULL, + ._gnDestroyInstance = NULL, + ._gnGetPhysicalDevices = NULL, + ._gnQueueCanPresentToSurface = NULL, + ._gnCreateOutputDevice = NULL, + ._gnDestroyOutputDevice = NULL, + ._gnCreateMacOSWindowSurface = NULL, + ._gnDestroyWindowSurface = NULL, + ._gnGetSurfaceDetails = NULL + }; +} diff --git a/projects/apis/metal/loader/metal_loader.h b/projects/apis/metal/loader/metal_loader.h new file mode 100644 index 0000000..a4bd81f --- /dev/null +++ b/projects/apis/metal/loader/metal_loader.h @@ -0,0 +1,8 @@ +#pragma once +#include "loader/src/gryphn_instance_functions.h" +#include "loader/src/gryphn_device_functions.h" +#include "loader/src/gryphn_command_functions.h" + +gnInstanceFunctions loadMetalInstanceFunctions(); +gnDeviceFunctions loadMetalDeviceFunctions(); +gnCommandFunctions loadMetalCommandFunctions(); diff --git a/projects/apis/metal/src/buffer/metal_buffer.m b/projects/apis/metal/src/buffer/metal_buffer.m index 4f9e068..e9f7802 100644 --- a/projects/apis/metal/src/buffer/metal_buffer.m +++ b/projects/apis/metal/src/buffer/metal_buffer.m @@ -1,7 +1,7 @@ #include "metal_buffer.h" -#include "core/buffers/gryphn_buffer.h" -#include "core/output_device/gryphn_output_device.h" -#include "core/devices/metal_output_devices.h" +#include "buffers/gryphn_buffer.h" +#include "output_device/gryphn_output_device.h" +#include "devices/metal_output_devices.h" gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) { buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t)); diff --git a/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.h b/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.h index f0335a0..30aaaec 100644 --- a/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.h +++ b/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.h @@ -1,6 +1,6 @@ #pragma once -#include "core/command/command_buffer/gryphn_command_buffer.h" -#include "core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" +#include "command/command_buffer/gryphn_command_buffer.h" +#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" #import #import diff --git a/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.m b/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.m index 9e82171..1a12c73 100644 --- a/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.m +++ b/projects/apis/metal/src/commands/command_buffer/metal_command_buffer.m @@ -1,5 +1,5 @@ #include "metal_command_buffer.h" -#include "core/commands/command_pool/metal_command_pool.h" +#include "commands/command_pool/metal_command_pool.h" #import gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { diff --git a/projects/apis/metal/src/commands/command_pool/metal_command_pool.h b/projects/apis/metal/src/commands/command_pool/metal_command_pool.h index 626a7d8..f0f2e40 100644 --- a/projects/apis/metal/src/commands/command_pool/metal_command_pool.h +++ b/projects/apis/metal/src/commands/command_pool/metal_command_pool.h @@ -1,6 +1,6 @@ #pragma once #import -#include "core/command/command_pool/gryphn_command_pool.h" +#include "command/command_pool/gryphn_command_pool.h" typedef struct gnPlatformCommandPool_t { id commandQueue; diff --git a/projects/apis/metal/src/commands/command_pool/metal_command_pool.m b/projects/apis/metal/src/commands/command_pool/metal_command_pool.m index c95ec74..75879c2 100644 --- a/projects/apis/metal/src/commands/command_pool/metal_command_pool.m +++ b/projects/apis/metal/src/commands/command_pool/metal_command_pool.m @@ -1,7 +1,7 @@ #include "metal_command_pool.h" -#include "core/devices/metal_output_devices.h" +#include "devices/metal_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(struct gnPlatformCommandPool_t)); commandPool->commandPool->commandQueue = [device->outputDevice->device newCommandQueue]; diff --git a/projects/apis/metal/src/commands/commands/metal_commands.m b/projects/apis/metal/src/commands/commands/metal_commands.m index b4be150..c293ffe 100644 --- a/projects/apis/metal/src/commands/commands/metal_commands.m +++ b/projects/apis/metal/src/commands/commands/metal_commands.m @@ -1,12 +1,12 @@ -#include "core/command/commands/gryphn_command.h" -#include "core/framebuffers/metal_framebuffer.h" -#include "core/commands/command_buffer/metal_command_buffer.h" -#include "core/pipelines/graphics_pipeline/metal_graphics_pipeline.h" -#include "core/buffer/metal_buffer.h" -#include "core/uniforms/metal_uniform.h" +#include "command/commands/gryphn_command.h" +#include "framebuffers/metal_framebuffer.h" +#include "commands/command_buffer/metal_command_buffer.h" +#include "pipelines/graphics_pipeline/metal_graphics_pipeline.h" +#include "buffer/metal_buffer.h" +#include "uniforms/metal_uniform.h" #import -void gnCommandBeginRenderPassFn(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) { +void gnCommandBeginRenderPassFn(struct gnCommandBuffer_t* buffer, gnRenderPassInfo passInfo) { int currentColorAttachment = 0; for (int i = 0; i < passInfo.clearValueCount; i++) { gnBool wasDepthStencil = gnFalse; @@ -60,12 +60,12 @@ void gnCommandBindGraphicsPipelineFn(struct gnCommandBuffer_t* buffer, struct gn buffer->commandBuffer->boundGraphcisPipeline = graphicsPipeline; } -void gnCommandSetViewportFn(struct gnCommandBuffer_t* buffer, struct gnViewport_t viewport) { +void gnCommandSetViewportFn(struct gnCommandBuffer_t* buffer, gnViewport viewport) { MTLViewport vp = {(double)viewport.position.x, (double)viewport.position.y, (double)viewport.size.x, (double)viewport.size.y, viewport.minDepth, viewport.maxDepth}; id encoder = (id)buffer->commandBuffer->encoder; [encoder setViewport:vp]; } -void gnCommandSetScissorFn(struct gnCommandBuffer_t* buffer, struct gnScissor_t scissor) { +void gnCommandSetScissorFn(struct gnCommandBuffer_t* buffer, gnScissor scissor) { MTLScissorRect scissorRect = { scissor.position.x, scissor.position.y, scissor.size.x, scissor.size.y }; id encoder = (id)buffer->commandBuffer->encoder; [encoder setScissorRect:scissorRect]; @@ -116,12 +116,14 @@ void gnCommandDrawIndexedFn(gnCommandBufferHandle buffer, gnIndexType type, int void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) { id encoder = (id)buffer->commandBuffer->encoder; - if (uniform->uniform->type == GN_UNIFORM_BUFFER_DESCRIPTOR) { - gnBufferUniformInfo info = *(gnBufferUniformInfo*)uniform->uniform->data; + for (int i = 0; i < uniform->uniform->bindingCount; i++) { + if (uniform->uniform->bindings[i].type == GN_UNIFORM_BUFFER_DESCRIPTOR) { + gnBufferUniformInfo info = *(gnBufferUniformInfo*)uniform->uniform->bindings[i].data; - [encoder setVertexBuffer:info.buffer->buffer->buffer - offset:info.offset - atIndex:(info.binding + 1) - ]; + [encoder setVertexBuffer:info.buffer->buffer->buffer + offset:info.offset + atIndex:(info.binding + 1) + ]; + } } } diff --git a/projects/apis/metal/src/debugger/metal_debugger.m b/projects/apis/metal/src/debugger/metal_debugger.m index eec1f25..e8830f3 100644 --- a/projects/apis/metal/src/debugger/metal_debugger.m +++ b/projects/apis/metal/src/debugger/metal_debugger.m @@ -1,7 +1,7 @@ -#include +#include // these do nothing because I am too lazy to write a debugger for metal at this point in time -gnReturnCode gnCreateDebuggerFn(gnDebuggerHandle debugger, gnInstanceHandle instance, const struct gnDebuggerInfo_t info) { +gnReturnCode gnCreateDebuggerFn(gnDebuggerHandle debugger, gnInstanceHandle instance, const gnDebuggerInfo info) { return GN_SUCCESS; } void gnDestroyDebuggerFn(gnDebuggerHandle instance) { diff --git a/projects/apis/metal/src/devices/metal_output_device.m b/projects/apis/metal/src/devices/metal_output_device.m index 421333c..1031c65 100644 --- a/projects/apis/metal/src/devices/metal_output_device.m +++ b/projects/apis/metal/src/devices/metal_output_device.m @@ -1,11 +1,11 @@ -#include +#include #include #include "metal_output_devices.h" -#include "core/instance/metal_instance.h" -#include "core/instance/gryphn_instance.h" -#include +#include "instance/metal_instance.h" +#include "instance/gryphn_instance.h" +#include -gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) { +gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanceHandle instance, gnOutputDeviceInfo deviceInfo) { outputDevice->outputDevice = malloc(sizeof(gnPlatformOutputDevice)); outputDevice->outputDevice->device = deviceInfo.physicalDevice.physicalDevice->device.retain; outputDevice->outputDevice->transferQueue = outputDevice->outputDevice->device.newCommandQueue; diff --git a/projects/apis/metal/src/devices/metal_output_devices.h b/projects/apis/metal/src/devices/metal_output_devices.h index 4348b92..ed291db 100644 --- a/projects/apis/metal/src/devices/metal_output_devices.h +++ b/projects/apis/metal/src/devices/metal_output_devices.h @@ -1,6 +1,6 @@ #pragma once -#include "core/instance/gryphn_instance.h" -#include "core/output_device/gryphn_output_device.h" +#include "instance/gryphn_instance.h" +#include "output_device/gryphn_output_device.h" #include #include diff --git a/projects/apis/metal/src/devices/metal_physical_device.m b/projects/apis/metal/src/devices/metal_physical_device.m index 4cf8640..404de5d 100644 --- a/projects/apis/metal/src/devices/metal_physical_device.m +++ b/projects/apis/metal/src/devices/metal_physical_device.m @@ -1,7 +1,7 @@ -#include +#include #include #include "metal_output_devices.h" -#include "core/window_surface/gryphn_surface.h" +#include "window_surface/gryphn_surface.h" gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* deviceCount) { NSArray *devices = MTLCopyAllDevices(); @@ -34,6 +34,6 @@ gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* de return devicesList; } -gnBool gnQueueCanPresentToSurfaceFn(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface) { +gnBool gnQueueCanPresentToSurfaceFn(const gnPhysicalDevice device, uint32_t queueIndex, gnWindowSurface windowSurface) { return gnTrue; // I belive that a window should always be able to present to a surface in metal } diff --git a/projects/apis/metal/src/framebuffers/metal_framebuffer.h b/projects/apis/metal/src/framebuffers/metal_framebuffer.h index d4278e1..725b03d 100644 --- a/projects/apis/metal/src/framebuffers/metal_framebuffer.h +++ b/projects/apis/metal/src/framebuffers/metal_framebuffer.h @@ -1,5 +1,5 @@ #pragma once -#include "core/framebuffer/gryphn_framebuffer.h" +#include "framebuffer/gryphn_framebuffer.h" #include "utils/gryphn_bool.h" #include "utils/gryphn_image_format.h" #import diff --git a/projects/apis/metal/src/framebuffers/metal_framebuffer.m b/projects/apis/metal/src/framebuffers/metal_framebuffer.m index 711eb67..2586c80 100644 --- a/projects/apis/metal/src/framebuffers/metal_framebuffer.m +++ b/projects/apis/metal/src/framebuffers/metal_framebuffer.m @@ -1,8 +1,9 @@ #include "metal_framebuffer.h" -#include "core/debugger/gryphn_debugger.h" -#include "core/texture/metal_texture.h" -#include "core/renderpass/gryphn_render_pass_descriptor.h" -#include "core/instance/gryphn_instance.h" +#include "debugger/gryphn_debugger.h" +#include "texture/metal_texture.h" +#include "renderpass/gryphn_render_pass_descriptor.h" +#include "instance/gryphn_instance.h" +#include "output_device/gryphn_output_device.h" gnBool isDepthFormat(gnImageFormat format) { return gnFalse; @@ -12,7 +13,7 @@ gnBool isStencilFormat(gnImageFormat format) { return gnFalse; } -MTLLoadAction mtlGryphnLoadOperation(enum gnLoadOperation_e loadOperation) { +MTLLoadAction mtlGryphnLoadOperation(gnLoadOperation loadOperation) { switch(loadOperation) { case GN_LOAD_OPERATION_LOAD: return MTLLoadActionLoad; case GN_LOAD_OPERATION_CLEAR: return MTLLoadActionClear; @@ -20,14 +21,14 @@ MTLLoadAction mtlGryphnLoadOperation(enum gnLoadOperation_e loadOperation) { } } -MTLStoreAction mtlGryphnStoreOperation(enum gnStoreOperation_e storeOperation) { +MTLStoreAction mtlGryphnStoreOperation(gnStoreOperation storeOperation) { switch (storeOperation) { case GN_STORE_OPERATION_STORE: return MTLStoreActionStore; case GN_STORE_OPERATION_DONT_CARE: return MTLStoreActionDontCare; } } -gnReturnCode gnCreateFramebufferFn(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t info) { +gnReturnCode gnCreateFramebufferFn(gnFramebuffer framebuffer, gnOutputDevice device, gnFramebufferInfo info) { framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t)); if (info.attachmentCount != info.renderPassDescriptor->info.attachmentCount) { gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){ diff --git a/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.h b/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.h index 5032b23..4593839 100644 --- a/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.h +++ b/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.h @@ -1,5 +1,5 @@ #pragma once -#include "core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" +#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" #import typedef struct gnPlatformGraphicsPipeline_t { diff --git a/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.m b/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.m index 0b34bc3..97f6d43 100644 --- a/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.m +++ b/projects/apis/metal/src/pipelines/graphics_pipeline/metal_graphics_pipeline.m @@ -1,10 +1,10 @@ #include "metal_graphics_pipeline.h" -#include "core/devices/metal_output_devices.h" -#include "core/debugger/gryphn_debugger.h" -#include "core/shader_module/metal_shader_module.h" -#include "core/surface/metal_surface.h" +#include "devices/metal_output_devices.h" +#include "debugger/gryphn_debugger.h" +#include "shader_module/metal_shader_module.h" +#include "surface/metal_surface.h" -MTLBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) { +MTLBlendFactor vkGryphnBlendFactor(gnBlendFactor factor) { switch (factor) { case GN_BLEND_FACTOR_ZERO: return MTLBlendFactorZero; case GN_BLEND_FACTOR_ONE: return MTLBlendFactorOne; @@ -13,7 +13,7 @@ MTLBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) { } } -MTLBlendOperation vkGryphnBlendOperation(enum gnBlendOperation_e operation) { +MTLBlendOperation vkGryphnBlendOperation(gnBlendOperation operation) { switch(operation) { case GN_OPERATION_ADD: return MTLBlendOperationAdd; } @@ -26,7 +26,7 @@ MTLVertexFormat mtlGryphnVertexFormat(gnVertexFormat format) { } } -gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t info) { +gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) { graphicsPipeline->graphicsPipeline = malloc(sizeof(struct gnPlatformGraphicsPipeline_t)); MTLRenderPipelineDescriptor* descriptor = [[MTLRenderPipelineDescriptor alloc] init]; diff --git a/projects/apis/metal/src/present/metal_present.m b/projects/apis/metal/src/present/metal_present.m index 247589b..845ebda 100644 --- a/projects/apis/metal/src/present/metal_present.m +++ b/projects/apis/metal/src/present/metal_present.m @@ -1,14 +1,14 @@ -#include "core/present/gryphn_present.h" -#include "core/instance/metal_instance.h" -#include "core/surface/metal_surface.h" -#include "core/devices/metal_output_devices.h" -#include "core/sync/semaphore/metal_semaphore.h" -#include "core/presentation_queue/metal_presentation_queue.h" -#include "core/debugger/gryphn_debugger.h" -#include "core/texture/metal_texture.h" +#include "present/gryphn_present.h" +#include "instance/metal_instance.h" +#include "surface/metal_surface.h" +#include "devices/metal_output_devices.h" +#include "sync/semaphore/metal_semaphore.h" +#include "presentation_queue/metal_presentation_queue.h" +#include "debugger/gryphn_debugger.h" +#include "texture/metal_texture.h" #import -gnReturnCode gnPresentFn(gnOutputDeviceHandle device, struct gnPresentInfo_t info) { +gnReturnCode gnPresentFn(gnOutputDeviceHandle device, gnPresentInfo info) { for (int i = 0; i < info.waitCount; i++) { while (!info.waitSemaphores[i]->semaphore->eventTriggered) {} } diff --git a/projects/apis/metal/src/presentation_queue/metal_presentation_queue.h b/projects/apis/metal/src/presentation_queue/metal_presentation_queue.h index 87855af..ca1e084 100644 --- a/projects/apis/metal/src/presentation_queue/metal_presentation_queue.h +++ b/projects/apis/metal/src/presentation_queue/metal_presentation_queue.h @@ -1,6 +1,6 @@ #pragma once #import -#include "core/presentation_queue/gryphn_presentation_queue.h" +#include "presentation_queue/gryphn_presentation_queue.h" typedef struct gnPlatformPresentationQueue_t { int textureCount; diff --git a/projects/apis/metal/src/presentation_queue/metal_presentation_queue.m b/projects/apis/metal/src/presentation_queue/metal_presentation_queue.m index f880309..14fc7b9 100644 --- a/projects/apis/metal/src/presentation_queue/metal_presentation_queue.m +++ b/projects/apis/metal/src/presentation_queue/metal_presentation_queue.m @@ -1,11 +1,11 @@ #include "metal_presentation_queue.h" -#include "core/surface/metal_surface.h" -#include "core/devices/metal_output_devices.h" -#include "core/debugger/gryphn_debugger.h" -#include "core/texture/metal_texture.h" -#include "core/sync/semaphore/metal_semaphore.h" +#include "surface/metal_surface.h" +#include "devices/metal_output_devices.h" +#include "debugger/gryphn_debugger.h" +#include "texture/metal_texture.h" +#include "sync/semaphore/metal_semaphore.h" -gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, struct gnPresentationQueueInfo_t presentationInfo) { +gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQueue, const gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo) { if (presentationInfo.minImageCount > 3) { gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){ .message = gnCreateString("On Metal you cannot have more than 3 images in a presentation queue") diff --git a/projects/apis/metal/src/renderpass/metal_render_pass.h b/projects/apis/metal/src/renderpass/metal_render_pass.h index 45e5fe7..82619d4 100644 --- a/projects/apis/metal/src/renderpass/metal_render_pass.h +++ b/projects/apis/metal/src/renderpass/metal_render_pass.h @@ -1,5 +1,5 @@ #pragma once -#include "core/renderpass/gryphn_render_pass_descriptor.h" +#include "renderpass/gryphn_render_pass_descriptor.h" #import typedef struct gnPlatformRenderPassDescriptor_t { diff --git a/projects/apis/metal/src/renderpass/metal_render_pass.m b/projects/apis/metal/src/renderpass/metal_render_pass.m index d327747..dc5e265 100644 --- a/projects/apis/metal/src/renderpass/metal_render_pass.m +++ b/projects/apis/metal/src/renderpass/metal_render_pass.m @@ -1,6 +1,6 @@ #include "metal_render_pass.h" -gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info) { +gnReturnCode gnCreateRenderPassDescriptorFn(gnRenderPassDescriptor renderPass, gnOutputDevice device, gnRenderPassDescriptorInfo info) { renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor)); renderPass->renderPassDescriptor->passDescriptor = [[MTLRenderPassDescriptor alloc] init]; diff --git a/projects/apis/metal/src/shader_module/metal_shader_module.h b/projects/apis/metal/src/shader_module/metal_shader_module.h index 20691b7..127781f 100644 --- a/projects/apis/metal/src/shader_module/metal_shader_module.h +++ b/projects/apis/metal/src/shader_module/metal_shader_module.h @@ -1,5 +1,5 @@ #pragma once -#include "core/shader_module/gryphn_shader_module.h" +#include "shader_module/gryphn_shader_module.h" #import typedef struct gnPlatformShaderModule_t { diff --git a/projects/apis/metal/src/shader_module/metal_shader_module.m b/projects/apis/metal/src/shader_module/metal_shader_module.m index 3afd686..b6329c8 100644 --- a/projects/apis/metal/src/shader_module/metal_shader_module.m +++ b/projects/apis/metal/src/shader_module/metal_shader_module.m @@ -1,7 +1,7 @@ #include "metal_shader_module.h" #include "spirv_cross_c.h" -#include "core/debugger/gryphn_debugger.h" -#include "core/devices/metal_output_devices.h" +#include "debugger/gryphn_debugger.h" +#include "devices/metal_output_devices.h" #import #import @@ -12,7 +12,7 @@ void mtlSpirVErrorCallback(void *userdata, const char *error) { }); } -gnReturnCode gnCreateShaderModuleFn(struct gnShaderModule_t *module, struct gnOutputDevice_t *device, struct gnShaderModuleInfo_t shaderModuleInfo) { +gnReturnCode gnCreateShaderModuleFn(gnShaderModule module, gnOutputDevice device, gnShaderModuleInfo shaderModuleInfo) { module->shaderModule = malloc(sizeof(struct gnPlatformShaderModule_t)); spvc_context context = NULL; diff --git a/projects/apis/metal/src/submit/metal_submit.m b/projects/apis/metal/src/submit/metal_submit.m index 7eaddd8..926558e 100644 --- a/projects/apis/metal/src/submit/metal_submit.m +++ b/projects/apis/metal/src/submit/metal_submit.m @@ -1,10 +1,11 @@ -#include "core/submit/gryphn_submit.h" -#include "core/sync/semaphore/metal_semaphore.h" -#include "core/commands/command_buffer/metal_command_buffer.h" -#include "core/debugger/gryphn_debugger.h" -#include "core/commands/command_pool/metal_command_pool.h" +#include "submit/gryphn_submit.h" +#include "sync/semaphore/metal_semaphore.h" +#include "commands/command_buffer/metal_command_buffer.h" +#include "debugger/gryphn_debugger.h" +#include "commands/command_pool/metal_command_pool.h" +#include "sync/fence/gryphn_fence.h" -gnReturnCode gnSubmitFn(struct gnOutputDevice_t* device, struct gnSubmitInfo_t info) { +gnReturnCode gnSubmitFn(gnDevice* device, gnSubmitInfo info) { for (int i = 0; i < info.waitCount; i++) { while (!info.waitSemaphores[i]->semaphore->eventTriggered) {} } diff --git a/projects/apis/metal/src/surface/metal_surface.h b/projects/apis/metal/src/surface/metal_surface.h index cfaa274..fc83e8a 100644 --- a/projects/apis/metal/src/surface/metal_surface.h +++ b/projects/apis/metal/src/surface/metal_surface.h @@ -1,5 +1,5 @@ #pragma once -#include "core/window_surface/gryphn_surface.h" +#include "window_surface/gryphn_surface.h" #import typedef struct gnPlatformWindowSurface_t { diff --git a/projects/apis/metal/src/surface/metal_surface.m b/projects/apis/metal/src/surface/metal_surface.m index 477e024..6a0a428 100644 --- a/projects/apis/metal/src/surface/metal_surface.m +++ b/projects/apis/metal/src/surface/metal_surface.m @@ -1,5 +1,5 @@ #include "metal_surface.h" -#include "core/window_surface/gryphn_surface_create_functions.h" +#include "window_surface/gryphn_surface_create_functions.h" #import #import @@ -8,7 +8,7 @@ #import #import -gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo) { +gnReturnCode gnCreateMacOSWindowSurfaceFn(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, gnMacOSWindowSurfaceInfo createInfo) { windowSurface->windowSurface = malloc(sizeof(gnPlatformWindowSurface)); windowSurface->windowSurface->layer = createInfo.layer; return GN_SUCCESS; @@ -18,12 +18,12 @@ void gnDestroyWindowSurfaceFn(struct gnWindowSurface_t *windowSurface) { free(windowSurface->windowSurface); } -struct gnSurfaceDetails_t gnGetSurfaceDetailsFn( - struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device +gnSurfaceDetails gnGetSurfaceDetailsFn( + gnWindowSurface windowSurface, gnPhysicalDevice device ) { - struct gnSurfaceDetails_t surfaceDetails; + gnSurfaceDetails surfaceDetails; surfaceDetails.formatCount = 1; - surfaceDetails.formats = (struct gnSurfaceFormat_t[1]){ { GN_FORMAT_BGRA8_SRGB, GN_COLOR_SPACE_SRGB_NONLINEAR } }; + surfaceDetails.formats = (gnSurfaceFormat[]){ { GN_FORMAT_BGRA8_SRGB, GN_COLOR_SPACE_SRGB_NONLINEAR } }; surfaceDetails.minImageCount = 2; surfaceDetails.maxImageCount = 3; return surfaceDetails; diff --git a/projects/apis/metal/src/sync/fence/metal_fence.h b/projects/apis/metal/src/sync/fence/metal_fence.h index 28b5a0c..e695a28 100644 --- a/projects/apis/metal/src/sync/fence/metal_fence.h +++ b/projects/apis/metal/src/sync/fence/metal_fence.h @@ -1,5 +1,5 @@ #pragma once -#include "core/sync/fence/gryphn_fence.h" +#include "sync/fence/gryphn_fence.h" #import #import diff --git a/projects/apis/metal/src/sync/fence/metal_fence.m b/projects/apis/metal/src/sync/fence/metal_fence.m index 8c2f389..1c7a0ba 100644 --- a/projects/apis/metal/src/sync/fence/metal_fence.m +++ b/projects/apis/metal/src/sync/fence/metal_fence.m @@ -1,5 +1,5 @@ #include "metal_fence.h" -#include "core/devices/metal_output_devices.h" +#include "devices/metal_output_devices.h" gnReturnCode gnCreateFenceFn(struct gnFence_t* fence, struct gnOutputDevice_t* device) { // fence->fence = malloc(sizeof(gnPlatformFence)); diff --git a/projects/apis/metal/src/sync/semaphore/metal_semaphore.h b/projects/apis/metal/src/sync/semaphore/metal_semaphore.h index f3477d8..7f7dc59 100644 --- a/projects/apis/metal/src/sync/semaphore/metal_semaphore.h +++ b/projects/apis/metal/src/sync/semaphore/metal_semaphore.h @@ -1,5 +1,5 @@ #pragma once -#include "core/sync/semaphore/gryphn_semaphore.h" +#include "sync/semaphore/gryphn_semaphore.h" #import typedef struct gnPlatformSemaphore_t { diff --git a/projects/apis/metal/src/sync/semaphore/metal_semaphore.m b/projects/apis/metal/src/sync/semaphore/metal_semaphore.m index 342e73a..a032827 100644 --- a/projects/apis/metal/src/sync/semaphore/metal_semaphore.m +++ b/projects/apis/metal/src/sync/semaphore/metal_semaphore.m @@ -1,13 +1,13 @@ #include "metal_semaphore.h" -#include "core/devices/metal_output_devices.h" +#include "devices/metal_output_devices.h" -gnReturnCode gnCreateSemaphoreFn(struct gnSemaphore_t* semaphore, struct gnOutputDevice_t* device) { +gnReturnCode gnCreateSemaphoreFn(gnSemaphore semaphore, gnOutputDevice device) { semaphore->semaphore = malloc(sizeof(gnPlatformSemaphore)); semaphore->semaphore->event = [device->outputDevice->device newEvent]; return GN_SUCCESS; } -void gnDestroySemaphoreFn(struct gnSemaphore_t* semaphore) { +void gnDestroySemaphoreFn(gnSemaphore semaphore) { [semaphore->semaphore->event release]; free(semaphore->semaphore); } diff --git a/projects/apis/metal/src/texture/metal_texture.h b/projects/apis/metal/src/texture/metal_texture.h index 5ec174a..d4b392f 100644 --- a/projects/apis/metal/src/texture/metal_texture.h +++ b/projects/apis/metal/src/texture/metal_texture.h @@ -1,5 +1,5 @@ #pragma once -#include "core/textures/gryphn_texture.h" +#include "textures/gryphn_texture.h" #import typedef struct gnPlatformTexture_t { diff --git a/projects/apis/metal/src/uniforms/metal_uniform.c b/projects/apis/metal/src/uniforms/metal_uniform.c index 4251241..8609dd3 100644 --- a/projects/apis/metal/src/uniforms/metal_uniform.c +++ b/projects/apis/metal/src/uniforms/metal_uniform.c @@ -1,7 +1,12 @@ -#include +#include #include "metal_uniform.h" void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) { - uniform->uniform->data = malloc(sizeof(gnBufferUniformInfo)); - memcpy(uniform->uniform->data, info, sizeof(gnBufferUniformInfo)); + for (int i = 0; i < uniform->uniform->bindingCount; i++) { + if (uniform->uniform->bindings[i].binding == info->binding) { + uniform->uniform->bindings[i].data = malloc(sizeof(gnBufferUniformInfo)); + memcpy(uniform->uniform->bindings[i].data, info, sizeof(gnBufferUniformInfo)); + break; + } + } } diff --git a/projects/apis/metal/src/uniforms/metal_uniform.h b/projects/apis/metal/src/uniforms/metal_uniform.h index 4c01c36..fd44d4a 100644 --- a/projects/apis/metal/src/uniforms/metal_uniform.h +++ b/projects/apis/metal/src/uniforms/metal_uniform.h @@ -1,8 +1,14 @@ #pragma once -#include "core/uniforms/gryphn_uniform.h" -#include +#include "uniforms/gryphn_uniform.h" +#include + +typedef struct metalUniformBinding { + gnUniformType type; + uint32_t binding; + void* data; +} metalUniformBinding; typedef struct gnPlatformUniform_t { - gnUniformType type; - void* data; + uint32_t bindingCount; + metalUniformBinding* bindings; } gnPlatformUniform; diff --git a/projects/apis/metal/src/uniforms/metal_uniform_pool.c b/projects/apis/metal/src/uniforms/metal_uniform_pool.c index 172c924..db93ad8 100644 --- a/projects/apis/metal/src/uniforms/metal_uniform_pool.c +++ b/projects/apis/metal/src/uniforms/metal_uniform_pool.c @@ -1,17 +1,21 @@ -#include -#include +#include +#include #include "metal_uniform.h" gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) { return GN_SUCCESS; } -gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformLayout layout) { - gnUniform* uniforms = malloc(sizeof(gnUniform) * layout.uniformBindingCount); - for (int i = 0; i < layout.uniformBindingCount; i++) { +gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformAllocationInfo allocInfo) { + gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount); + for (int i = 0; i < allocInfo.setCount; i++) { uniforms[i] = malloc(sizeof(struct gnUniform_t)); - uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t)); - uniforms[i]->uniform->type = layout.uniformBindings[i].type; + uniforms[i]->uniform = malloc(sizeof(gnPlatformUniform)); + uniforms[i]->uniform->bindings = malloc(sizeof(metalUniformBinding) * allocInfo.sets[i].uniformBindingCount); + for (int c = 0; c < allocInfo.sets[i].uniformBindingCount; c++) { + uniforms[i]->uniform->bindings[c].type = allocInfo.sets[i].uniformBindings[c].type; + uniforms[i]->uniform->bindings[c].binding = allocInfo.sets[i].uniformBindings[c].binding; + } } return uniforms; } diff --git a/projects/apis/metal/src/uniforms/metal_uniform_pool.h b/projects/apis/metal/src/uniforms/metal_uniform_pool.h index d145a50..a514b90 100644 --- a/projects/apis/metal/src/uniforms/metal_uniform_pool.h +++ b/projects/apis/metal/src/uniforms/metal_uniform_pool.h @@ -1,6 +1,5 @@ #pragma once #include -#include +#include -struct gnPlatformUniformPool_t { -}; +typedef struct gnPlatformUniformPool_t {} gnPlatformUniformPool;