get the metal backend to compile (does not load)

This commit is contained in:
Greg Wells
2025-06-25 10:46:07 -04:00
parent 4306646c6e
commit 2c9e2260f4
39 changed files with 235 additions and 117 deletions

View File

@@ -13,8 +13,9 @@ if (UNIX AND NOT APPLE)
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl) target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl)
endif() endif()
if (APPLE) 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/) add_subdirectory(projects/apis/vulkan/)
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl) add_subdirectory(projects/apis/metal/)
target_link_libraries(Gryphn INTERFACE GryphnVulkanImpl GryphnMetalImpl)
endif() endif()
target_link_libraries(Gryphn INTERFACE GryphnCore GryphnLoader GryphnPlatform) target_link_libraries(Gryphn INTERFACE GryphnCore GryphnLoader GryphnPlatform)

View File

@@ -7,10 +7,11 @@ file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS
) )
add_library(GryphnMetalImpl STATIC ${SOURCE_FILES}) add_library(GryphnMetalImpl STATIC ${SOURCE_FILES})
target_include_directories(GryphnMetalImpl PUBLIC target_include_directories(GryphnMetalImpl PUBLIC
${CMAKE_SOURCE_DIR}/gryphn/include/ ${CMAKE_CURRENT_SOURCE_DIR}/../../core/src/
${CMAKE_SOURCE_DIR}/gryphn/src/ ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/
${CMAKE_SOURCE_DIR}/gryphn/src/utils/ ${CMAKE_CURRENT_SOURCE_DIR}/../../
src/ ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
${CMAKE_CURRENT_SOURCE_DIR}/src/
depends/SPIRV-Cross/ depends/SPIRV-Cross/
) )
add_compile_definitions(GN_REVEAL_IMPL) add_compile_definitions(GN_REVEAL_IMPL)

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
#include "metal_buffer.h" #include "metal_buffer.h"
#include "core/buffers/gryphn_buffer.h" #include "buffers/gryphn_buffer.h"
#include "core/output_device/gryphn_output_device.h" #include "output_device/gryphn_output_device.h"
#include "core/devices/metal_output_devices.h" #include "devices/metal_output_devices.h"
gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) { gnReturnCode gnCreateBufferFn(gnBufferHandle buffer, gnOutputDeviceHandle device, gnBufferInfo info) {
buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t)); buffer->buffer = malloc(sizeof(struct gnPlatformBuffer_t));

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "core/command/command_buffer/gryphn_command_buffer.h" #include "command/command_buffer/gryphn_command_buffer.h"
#include "core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" #include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
#import <Metal/MTLCommandBuffer.h> #import <Metal/MTLCommandBuffer.h>
#import <Metal/MTLCommandEncoder.h> #import <Metal/MTLCommandEncoder.h>

View File

@@ -1,5 +1,5 @@
#include "metal_command_buffer.h" #include "metal_command_buffer.h"
#include "core/commands/command_pool/metal_command_pool.h" #include "commands/command_pool/metal_command_pool.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) { gnReturnCode gnCommandPoolAllocateCommandBuffersFn(gnCommandBufferHandle* commandBuffers, uint32_t count, struct gnCommandPool_t* pool) {

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#import <Metal/Metal.h> #import <Metal/Metal.h>
#include "core/command/command_pool/gryphn_command_pool.h" #include "command/command_pool/gryphn_command_pool.h"
typedef struct gnPlatformCommandPool_t { typedef struct gnPlatformCommandPool_t {
id<MTLCommandQueue> commandQueue; id<MTLCommandQueue> commandQueue;

View File

@@ -1,7 +1,7 @@
#include "metal_command_pool.h" #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 = malloc(sizeof(struct gnPlatformCommandPool_t));
commandPool->commandPool->commandQueue = [device->outputDevice->device newCommandQueue]; commandPool->commandPool->commandQueue = [device->outputDevice->device newCommandQueue];

View File

@@ -1,12 +1,12 @@
#include "core/command/commands/gryphn_command.h" #include "command/commands/gryphn_command.h"
#include "core/framebuffers/metal_framebuffer.h" #include "framebuffers/metal_framebuffer.h"
#include "core/commands/command_buffer/metal_command_buffer.h" #include "commands/command_buffer/metal_command_buffer.h"
#include "core/pipelines/graphics_pipeline/metal_graphics_pipeline.h" #include "pipelines/graphics_pipeline/metal_graphics_pipeline.h"
#include "core/buffer/metal_buffer.h" #include "buffer/metal_buffer.h"
#include "core/uniforms/metal_uniform.h" #include "uniforms/metal_uniform.h"
#import <Metal/MTLRenderCommandEncoder.h> #import <Metal/MTLRenderCommandEncoder.h>
void gnCommandBeginRenderPassFn(struct gnCommandBuffer_t* buffer, struct gnRenderPassInfo_t passInfo) { void gnCommandBeginRenderPassFn(struct gnCommandBuffer_t* buffer, gnRenderPassInfo passInfo) {
int currentColorAttachment = 0; int currentColorAttachment = 0;
for (int i = 0; i < passInfo.clearValueCount; i++) { for (int i = 0; i < passInfo.clearValueCount; i++) {
gnBool wasDepthStencil = gnFalse; gnBool wasDepthStencil = gnFalse;
@@ -60,12 +60,12 @@ void gnCommandBindGraphicsPipelineFn(struct gnCommandBuffer_t* buffer, struct gn
buffer->commandBuffer->boundGraphcisPipeline = graphicsPipeline; 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}; MTLViewport vp = {(double)viewport.position.x, (double)viewport.position.y, (double)viewport.size.x, (double)viewport.size.y, viewport.minDepth, viewport.maxDepth};
id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder; id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder;
[encoder setViewport:vp]; [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 }; MTLScissorRect scissorRect = { scissor.position.x, scissor.position.y, scissor.size.x, scissor.size.y };
id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder; id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder;
[encoder setScissorRect:scissorRect]; [encoder setScissorRect:scissorRect];
@@ -116,12 +116,14 @@ void gnCommandDrawIndexedFn(gnCommandBufferHandle buffer, gnIndexType type, int
void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) { void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set) {
id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder; id<MTLRenderCommandEncoder> encoder = (id<MTLRenderCommandEncoder>)buffer->commandBuffer->encoder;
if (uniform->uniform->type == GN_UNIFORM_BUFFER_DESCRIPTOR) { for (int i = 0; i < uniform->uniform->bindingCount; i++) {
gnBufferUniformInfo info = *(gnBufferUniformInfo*)uniform->uniform->data; if (uniform->uniform->bindings[i].type == GN_UNIFORM_BUFFER_DESCRIPTOR) {
gnBufferUniformInfo info = *(gnBufferUniformInfo*)uniform->uniform->bindings[i].data;
[encoder setVertexBuffer:info.buffer->buffer->buffer [encoder setVertexBuffer:info.buffer->buffer->buffer
offset:info.offset offset:info.offset
atIndex:(info.binding + 1) atIndex:(info.binding + 1)
]; ];
} }
}
} }

View File

@@ -1,7 +1,7 @@
#include <core/debugger/gryphn_debugger.h> #include <debugger/gryphn_debugger.h>
// these do nothing because I am too lazy to write a debugger for metal at this point in time // 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; return GN_SUCCESS;
} }
void gnDestroyDebuggerFn(gnDebuggerHandle instance) { void gnDestroyDebuggerFn(gnDebuggerHandle instance) {

View File

@@ -1,11 +1,11 @@
#include <core/output_device/gryphn_physical_output_device.h> #include <output_device/gryphn_physical_output_device.h>
#include <Metal/Metal.h> #include <Metal/Metal.h>
#include "metal_output_devices.h" #include "metal_output_devices.h"
#include "core/instance/metal_instance.h" #include "instance/metal_instance.h"
#include "core/instance/gryphn_instance.h" #include "instance/gryphn_instance.h"
#include <core/debugger/gryphn_debugger.h> #include <debugger/gryphn_debugger.h>
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 = malloc(sizeof(gnPlatformOutputDevice));
outputDevice->outputDevice->device = deviceInfo.physicalDevice.physicalDevice->device.retain; outputDevice->outputDevice->device = deviceInfo.physicalDevice.physicalDevice->device.retain;
outputDevice->outputDevice->transferQueue = outputDevice->outputDevice->device.newCommandQueue; outputDevice->outputDevice->transferQueue = outputDevice->outputDevice->device.newCommandQueue;

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "core/instance/gryphn_instance.h" #include "instance/gryphn_instance.h"
#include "core/output_device/gryphn_output_device.h" #include "output_device/gryphn_output_device.h"
#include <Metal/Metal.h> #include <Metal/Metal.h>
#include <MetalKit/MetalKit.h> #include <MetalKit/MetalKit.h>

View File

@@ -1,7 +1,7 @@
#include <core/output_device/gryphn_physical_output_device.h> #include <output_device/gryphn_physical_output_device.h>
#include <Metal/Metal.h> #include <Metal/Metal.h>
#include "metal_output_devices.h" #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) { gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* deviceCount) {
NSArray *devices = MTLCopyAllDevices(); NSArray *devices = MTLCopyAllDevices();
@@ -34,6 +34,6 @@ gnPhysicalDevice* gnGetPhysicalDevicesFn(gnInstanceHandle instance, uint32_t* de
return devicesList; 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 return gnTrue; // I belive that a window should always be able to present to a surface in metal
} }

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/framebuffer/gryphn_framebuffer.h" #include "framebuffer/gryphn_framebuffer.h"
#include "utils/gryphn_bool.h" #include "utils/gryphn_bool.h"
#include "utils/gryphn_image_format.h" #include "utils/gryphn_image_format.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>

View File

@@ -1,8 +1,9 @@
#include "metal_framebuffer.h" #include "metal_framebuffer.h"
#include "core/debugger/gryphn_debugger.h" #include "debugger/gryphn_debugger.h"
#include "core/texture/metal_texture.h" #include "texture/metal_texture.h"
#include "core/renderpass/gryphn_render_pass_descriptor.h" #include "renderpass/gryphn_render_pass_descriptor.h"
#include "core/instance/gryphn_instance.h" #include "instance/gryphn_instance.h"
#include "output_device/gryphn_output_device.h"
gnBool isDepthFormat(gnImageFormat format) { gnBool isDepthFormat(gnImageFormat format) {
return gnFalse; return gnFalse;
@@ -12,7 +13,7 @@ gnBool isStencilFormat(gnImageFormat format) {
return gnFalse; return gnFalse;
} }
MTLLoadAction mtlGryphnLoadOperation(enum gnLoadOperation_e loadOperation) { MTLLoadAction mtlGryphnLoadOperation(gnLoadOperation loadOperation) {
switch(loadOperation) { switch(loadOperation) {
case GN_LOAD_OPERATION_LOAD: return MTLLoadActionLoad; case GN_LOAD_OPERATION_LOAD: return MTLLoadActionLoad;
case GN_LOAD_OPERATION_CLEAR: return MTLLoadActionClear; 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) { switch (storeOperation) {
case GN_STORE_OPERATION_STORE: return MTLStoreActionStore; case GN_STORE_OPERATION_STORE: return MTLStoreActionStore;
case GN_STORE_OPERATION_DONT_CARE: return MTLStoreActionDontCare; 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)); framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t));
if (info.attachmentCount != info.renderPassDescriptor->info.attachmentCount) { if (info.attachmentCount != info.renderPassDescriptor->info.attachmentCount) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){ gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h" #include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
typedef struct gnPlatformGraphicsPipeline_t { typedef struct gnPlatformGraphicsPipeline_t {

View File

@@ -1,10 +1,10 @@
#include "metal_graphics_pipeline.h" #include "metal_graphics_pipeline.h"
#include "core/devices/metal_output_devices.h" #include "devices/metal_output_devices.h"
#include "core/debugger/gryphn_debugger.h" #include "debugger/gryphn_debugger.h"
#include "core/shader_module/metal_shader_module.h" #include "shader_module/metal_shader_module.h"
#include "core/surface/metal_surface.h" #include "surface/metal_surface.h"
MTLBlendFactor vkGryphnBlendFactor(enum gnBlendFactor_e factor) { MTLBlendFactor vkGryphnBlendFactor(gnBlendFactor factor) {
switch (factor) { switch (factor) {
case GN_BLEND_FACTOR_ZERO: return MTLBlendFactorZero; case GN_BLEND_FACTOR_ZERO: return MTLBlendFactorZero;
case GN_BLEND_FACTOR_ONE: return MTLBlendFactorOne; 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) { switch(operation) {
case GN_OPERATION_ADD: return MTLBlendOperationAdd; 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)); graphicsPipeline->graphicsPipeline = malloc(sizeof(struct gnPlatformGraphicsPipeline_t));
MTLRenderPipelineDescriptor* descriptor = [[MTLRenderPipelineDescriptor alloc] init]; MTLRenderPipelineDescriptor* descriptor = [[MTLRenderPipelineDescriptor alloc] init];

View File

@@ -1,14 +1,14 @@
#include "core/present/gryphn_present.h" #include "present/gryphn_present.h"
#include "core/instance/metal_instance.h" #include "instance/metal_instance.h"
#include "core/surface/metal_surface.h" #include "surface/metal_surface.h"
#include "core/devices/metal_output_devices.h" #include "devices/metal_output_devices.h"
#include "core/sync/semaphore/metal_semaphore.h" #include "sync/semaphore/metal_semaphore.h"
#include "core/presentation_queue/metal_presentation_queue.h" #include "presentation_queue/metal_presentation_queue.h"
#include "core/debugger/gryphn_debugger.h" #include "debugger/gryphn_debugger.h"
#include "core/texture/metal_texture.h" #include "texture/metal_texture.h"
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
gnReturnCode gnPresentFn(gnOutputDeviceHandle device, struct gnPresentInfo_t info) { gnReturnCode gnPresentFn(gnOutputDeviceHandle device, gnPresentInfo info) {
for (int i = 0; i < info.waitCount; i++) { for (int i = 0; i < info.waitCount; i++) {
while (!info.waitSemaphores[i]->semaphore->eventTriggered) {} while (!info.waitSemaphores[i]->semaphore->eventTriggered) {}
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#import <Metal/Metal.h> #import <Metal/Metal.h>
#include "core/presentation_queue/gryphn_presentation_queue.h" #include "presentation_queue/gryphn_presentation_queue.h"
typedef struct gnPlatformPresentationQueue_t { typedef struct gnPlatformPresentationQueue_t {
int textureCount; int textureCount;

View File

@@ -1,11 +1,11 @@
#include "metal_presentation_queue.h" #include "metal_presentation_queue.h"
#include "core/surface/metal_surface.h" #include "surface/metal_surface.h"
#include "core/devices/metal_output_devices.h" #include "devices/metal_output_devices.h"
#include "core/debugger/gryphn_debugger.h" #include "debugger/gryphn_debugger.h"
#include "core/texture/metal_texture.h" #include "texture/metal_texture.h"
#include "core/sync/semaphore/metal_semaphore.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) { if (presentationInfo.minImageCount > 3) {
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){ gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString("On Metal you cannot have more than 3 images in a presentation queue") .message = gnCreateString("On Metal you cannot have more than 3 images in a presentation queue")

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/renderpass/gryphn_render_pass_descriptor.h" #include "renderpass/gryphn_render_pass_descriptor.h"
#import <Metal/MTLRenderPass.h> #import <Metal/MTLRenderPass.h>
typedef struct gnPlatformRenderPassDescriptor_t { typedef struct gnPlatformRenderPassDescriptor_t {

View File

@@ -1,6 +1,6 @@
#include "metal_render_pass.h" #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 = malloc(sizeof(gnPlatformRenderPassDescriptor));
renderPass->renderPassDescriptor->passDescriptor = [[MTLRenderPassDescriptor alloc] init]; renderPass->renderPassDescriptor->passDescriptor = [[MTLRenderPassDescriptor alloc] init];

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/shader_module/gryphn_shader_module.h" #include "shader_module/gryphn_shader_module.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
typedef struct gnPlatformShaderModule_t { typedef struct gnPlatformShaderModule_t {

View File

@@ -1,7 +1,7 @@
#include "metal_shader_module.h" #include "metal_shader_module.h"
#include "spirv_cross_c.h" #include "spirv_cross_c.h"
#include "core/debugger/gryphn_debugger.h" #include "debugger/gryphn_debugger.h"
#include "core/devices/metal_output_devices.h" #include "devices/metal_output_devices.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <Metal/Metal.h> #import <Metal/Metal.h>
@@ -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)); module->shaderModule = malloc(sizeof(struct gnPlatformShaderModule_t));
spvc_context context = NULL; spvc_context context = NULL;

View File

@@ -1,10 +1,11 @@
#include "core/submit/gryphn_submit.h" #include "submit/gryphn_submit.h"
#include "core/sync/semaphore/metal_semaphore.h" #include "sync/semaphore/metal_semaphore.h"
#include "core/commands/command_buffer/metal_command_buffer.h" #include "commands/command_buffer/metal_command_buffer.h"
#include "core/debugger/gryphn_debugger.h" #include "debugger/gryphn_debugger.h"
#include "core/commands/command_pool/metal_command_pool.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++) { for (int i = 0; i < info.waitCount; i++) {
while (!info.waitSemaphores[i]->semaphore->eventTriggered) {} while (!info.waitSemaphores[i]->semaphore->eventTriggered) {}
} }

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/window_surface/gryphn_surface.h" #include "window_surface/gryphn_surface.h"
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
typedef struct gnPlatformWindowSurface_t { typedef struct gnPlatformWindowSurface_t {

View File

@@ -1,5 +1,5 @@
#include "metal_surface.h" #include "metal_surface.h"
#include "core/window_surface/gryphn_surface_create_functions.h" #include "window_surface/gryphn_surface_create_functions.h"
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@@ -8,7 +8,7 @@
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
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 = malloc(sizeof(gnPlatformWindowSurface));
windowSurface->windowSurface->layer = createInfo.layer; windowSurface->windowSurface->layer = createInfo.layer;
return GN_SUCCESS; return GN_SUCCESS;
@@ -18,12 +18,12 @@ void gnDestroyWindowSurfaceFn(struct gnWindowSurface_t *windowSurface) {
free(windowSurface->windowSurface); free(windowSurface->windowSurface);
} }
struct gnSurfaceDetails_t gnGetSurfaceDetailsFn( gnSurfaceDetails gnGetSurfaceDetailsFn(
struct gnWindowSurface_t* windowSurface, struct gnPhysicalDevice_t device gnWindowSurface windowSurface, gnPhysicalDevice device
) { ) {
struct gnSurfaceDetails_t surfaceDetails; gnSurfaceDetails surfaceDetails;
surfaceDetails.formatCount = 1; 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.minImageCount = 2;
surfaceDetails.maxImageCount = 3; surfaceDetails.maxImageCount = 3;
return surfaceDetails; return surfaceDetails;

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/sync/fence/gryphn_fence.h" #include "sync/fence/gryphn_fence.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <Metal/MTLEvent.h> #import <Metal/MTLEvent.h>

View File

@@ -1,5 +1,5 @@
#include "metal_fence.h" #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) { gnReturnCode gnCreateFenceFn(struct gnFence_t* fence, struct gnOutputDevice_t* device) {
// fence->fence = malloc(sizeof(gnPlatformFence)); // fence->fence = malloc(sizeof(gnPlatformFence));

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/sync/semaphore/gryphn_semaphore.h" #include "sync/semaphore/gryphn_semaphore.h"
#import <Metal/MTLEvent.h> #import <Metal/MTLEvent.h>
typedef struct gnPlatformSemaphore_t { typedef struct gnPlatformSemaphore_t {

View File

@@ -1,13 +1,13 @@
#include "metal_semaphore.h" #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 = malloc(sizeof(gnPlatformSemaphore));
semaphore->semaphore->event = [device->outputDevice->device newEvent]; semaphore->semaphore->event = [device->outputDevice->device newEvent];
return GN_SUCCESS; return GN_SUCCESS;
} }
void gnDestroySemaphoreFn(struct gnSemaphore_t* semaphore) { void gnDestroySemaphoreFn(gnSemaphore semaphore) {
[semaphore->semaphore->event release]; [semaphore->semaphore->event release];
free(semaphore->semaphore); free(semaphore->semaphore);
} }

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "core/textures/gryphn_texture.h" #include "textures/gryphn_texture.h"
#import <Metal/MTLTexture.h> #import <Metal/MTLTexture.h>
typedef struct gnPlatformTexture_t { typedef struct gnPlatformTexture_t {

View File

@@ -1,7 +1,12 @@
#include <core/uniforms/gryphn_uniform.h> #include <uniforms/gryphn_uniform.h>
#include "metal_uniform.h" #include "metal_uniform.h"
void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) { void gnUpdateBufferUniformFn(gnUniform uniform, gnBufferUniformInfo* info) {
uniform->uniform->data = malloc(sizeof(gnBufferUniformInfo)); for (int i = 0; i < uniform->uniform->bindingCount; i++) {
memcpy(uniform->uniform->data, info, sizeof(gnBufferUniformInfo)); 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;
}
}
} }

View File

@@ -1,8 +1,14 @@
#pragma once #pragma once
#include "core/uniforms/gryphn_uniform.h" #include "uniforms/gryphn_uniform.h"
#include <core/uniforms/gryphn_uniform_pool.h> #include <uniforms/gryphn_uniform_pool.h>
typedef struct metalUniformBinding {
gnUniformType type;
uint32_t binding;
void* data;
} metalUniformBinding;
typedef struct gnPlatformUniform_t { typedef struct gnPlatformUniform_t {
gnUniformType type; uint32_t bindingCount;
void* data; metalUniformBinding* bindings;
} gnPlatformUniform; } gnPlatformUniform;

View File

@@ -1,17 +1,21 @@
#include <core/uniforms/gryphn_uniform_pool.h> #include <uniforms/gryphn_uniform_pool.h>
#include <core/uniforms/gryphn_uniform.h> #include <uniforms/gryphn_uniform.h>
#include "metal_uniform.h" #include "metal_uniform.h"
gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) { gnReturnCode gnCreateUniformPoolFn(gnUniformPool pool, gnDeviceHandle device) {
return GN_SUCCESS; return GN_SUCCESS;
} }
gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformLayout layout) { gnUniform* gnUniformPoolAllocateUniformsFn(gnUniformPool pool, const gnUniformAllocationInfo allocInfo) {
gnUniform* uniforms = malloc(sizeof(gnUniform) * layout.uniformBindingCount); gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount);
for (int i = 0; i < layout.uniformBindingCount; i++) { for (int i = 0; i < allocInfo.setCount; i++) {
uniforms[i] = malloc(sizeof(struct gnUniform_t)); uniforms[i] = malloc(sizeof(struct gnUniform_t));
uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t)); uniforms[i]->uniform = malloc(sizeof(gnPlatformUniform));
uniforms[i]->uniform->type = layout.uniformBindings[i].type; 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; return uniforms;
} }

View File

@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <core/uniforms/gryphn_uniform_pool.h> #include <uniforms/gryphn_uniform_pool.h>
struct gnPlatformUniformPool_t { typedef struct gnPlatformUniformPool_t {} gnPlatformUniformPool;
};