From e43b731f39cbb562aac75d4b7c387b7742709d15 Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Sat, 12 Jul 2025 15:00:19 -0400 Subject: [PATCH] some housekeeping --- README.md | 7 ++++++- .../pipelines/graphics_pipeline/metal_graphics_pipeline.m | 3 +-- .../apis/metal/src/shader_module/metal_shader_module.m | 8 -------- projects/apis/metal/src/texture/metal_texture.m | 3 +-- .../src/presentation_queue/vulkan_presentation_queue.c | 3 --- projects/apis/vulkan/src/sync/fence/vulkan_fence.c | 1 + projects/core/src/gryphn_handles.h | 2 ++ projects/core/src/instance/gryphn_instance.c | 1 - projects/platform/platform_macos/gryphn_platform_macos.m | 1 + 9 files changed, 12 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 29195db..548d90b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ Gryphn works to abstract away platform API functions (Vulkan, Metal, D3D11/D3D12 - buffers store GPU data so that it can be used in shaders
- Textures: - Store image data so that it can be sampled in shaders
+# Extentions +- GN_EXT_SYNCHRONIZATION + - allows sync primatives (fence, semaphore) and sync functions (gnPresentationQueueGetImageAsync, gnSubmitSync, gnPresentSync)
+ - Supported APIs
+ - Vulkan
+ - Metal* (metal support is buggy, fences are nonatomic so they cannot be used across multible threads)
# Validation Gryphn its an interesting API to work with so ive attempted to put together a somewhat comprehensive set of validation tools that will tell you what you (or I) am doing wrong. Gryphn currently has support for 2 validation layers but I plan to support more in the future
@@ -61,7 +67,6 @@ Gryphn validation layers are meant to be more specific so there are certain ones - APIs like OpenGL dont support the full capabilities of vulkan so things like synchronization I currently am planning to move synchronization primatives to be an extension. Planned extensions:
- - GN_EXT_SYNCHRONIZATION, my only problem with this extension is that I might be able to fake support for things like semaphores in OpenGL, im not 100% sure yet
- GN_EXT_COMPUTE, while compute pipelines might be a vulkan standard they are not an OpenGL standard so this does need to be an exension

- I will add more exensions as Gryphn grows in complexity, my current biggest task is going to be moving synchronization primatives over into extension land and not a core part of the Gryphn standard. My biggest problem with exentensions is that I don't want them to be something like, this feature is only supported on Vulkan which I think removes part of the reason for my making this project. #### Standardization 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 96aba06..f5cb12c 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 @@ -103,8 +103,7 @@ gnReturnCode createMetalGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gn MTLDepthStencilDescriptor* depthStencilDesc = [[MTLDepthStencilDescriptor alloc] init]; depthStencilDesc.depthWriteEnabled = info.depthStencil.depthWriteEnable; - depthStencilDesc.depthCompareFunction = MTLCompareFunctionLess; - + depthStencilDesc.depthCompareFunction = mtlGrypnCompareOperation(info.depthStencil.operation); graphicsPipeline->graphicsPipeline->depthState = [device->outputDevice->device newDepthStencilStateWithDescriptor:depthStencilDesc]; [descriptor setVertexDescriptor:vertexDescriptor]; 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 c987cc0..8831637 100644 --- a/projects/apis/metal/src/shader_module/metal_shader_module.m +++ b/projects/apis/metal/src/shader_module/metal_shader_module.m @@ -31,14 +31,6 @@ gnReturnCode createMetalShaderModule(gnShaderModule module, gnDevice device, gnS spvc_compiler_create_shader_resources(compiler, &resources); - spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_SHADER_RECORD_BUFFER, &list, &count); - for (int i = 0; i < count; i++) { - uint32_t set = spvc_compiler_get_decoration(compiler, list[i].id, SpvDecorationDescriptorSet), - binding = spvc_compiler_get_decoration(compiler, list[i].id, SpvDecorationBinding), - mslBinding = spvc_compiler_msl_get_automatic_resource_binding(compiler, list[i].id); - printf("%s: set %ui, binding %ui, mslBinding %ui\n", list[i].name, set, binding, mslBinding); - } - spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, &list, &count); // [[buffer(0)]] is reserved for stage_in, [[buffer(1)]] is reserved for push_constant uint32_t currentBufferBinding = 2, currentTextureBinding = 0; diff --git a/projects/apis/metal/src/texture/metal_texture.m b/projects/apis/metal/src/texture/metal_texture.m index 5adc9d5..e1f411d 100644 --- a/projects/apis/metal/src/texture/metal_texture.m +++ b/projects/apis/metal/src/texture/metal_texture.m @@ -46,7 +46,7 @@ gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnText void metalTextureData(gnTextureHandle texture, void* pixelData) { MTLRegion region = { { 0, 0, 0 }, - {texture->info.extent.width, texture->info.extent.width, texture->info.extent.depth} + {texture->info.extent.width, texture->info.extent.height, texture->info.extent.depth} }; NSUInteger bytesPerRow = 4 * texture->info.extent.width; // TODO: fix this should not be set to 4 @@ -54,7 +54,6 @@ void metalTextureData(gnTextureHandle texture, void* pixelData) { mipmapLevel:0 withBytes:pixelData bytesPerRow:bytesPerRow]; - } void metalDestroyTexture(gnTexture texture) { diff --git a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c index ac35337..0338ee3 100644 --- a/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c +++ b/projects/apis/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -87,12 +87,9 @@ gnReturnCode getVulkanPresentQueueImage(gnPresentationQueueHandle presentationQu presentationQueue->outputDevice->outputDevice->device, presentationQueue->presentationQueue->swapChain, UINT64_MAX, VK_NULL_HANDLE, presentationQueue->outputDevice->outputDevice->barrierFence, imageIndex); - if (result == VK_ERROR_OUT_OF_DATE_KHR) return GN_OUT_OF_DATE_PRESENTATION_QUEUE; if (result == VK_SUBOPTIMAL_KHR) return GN_SUBOPTIMAL_PRESENTATION_QUEUE; - vkWaitForFences(presentationQueue->outputDevice->outputDevice->device, 1, &presentationQueue->outputDevice->outputDevice->barrierFence, VK_TRUE, UINT64_MAX); - return GN_SUCCESS; } diff --git a/projects/apis/vulkan/src/sync/fence/vulkan_fence.c b/projects/apis/vulkan/src/sync/fence/vulkan_fence.c index 1978f56..a02bc9a 100644 --- a/projects/apis/vulkan/src/sync/fence/vulkan_fence.c +++ b/projects/apis/vulkan/src/sync/fence/vulkan_fence.c @@ -6,6 +6,7 @@ gnReturnCode createFence(gnFence fence, gnDevice device) { VkFenceCreateInfo fenceInfo = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO }; + if (vkCreateFence(device->outputDevice->device, &fenceInfo, NULL, &fence->fence->fence) != VK_SUCCESS) return GN_FAILED_TO_CREATE_FENCE; return GN_SUCCESS; diff --git a/projects/core/src/gryphn_handles.h b/projects/core/src/gryphn_handles.h index f8ee424..ec375e6 100644 --- a/projects/core/src/gryphn_handles.h +++ b/projects/core/src/gryphn_handles.h @@ -1,5 +1,7 @@ #pragma once +#define GN_NULL_HANDLE 0 + #define GN_HANDLE(type) \ typedef struct type##_t* type##Handle; \ typedef struct type##_t* type diff --git a/projects/core/src/instance/gryphn_instance.c b/projects/core/src/instance/gryphn_instance.c index fa83072..19b061f 100644 --- a/projects/core/src/instance/gryphn_instance.c +++ b/projects/core/src/instance/gryphn_instance.c @@ -9,7 +9,6 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instance, gnInstanceInfo info) { *instance = malloc(sizeof(struct gnInstance_t)); (*instance)->layers = loaderLayerArrayListCreate(); - loaderLayerArrayListAdd(&(*instance)->layers, loadLayer((loaderInfo){ .api = info.renderingAPI, .layerToLoad = api_layer diff --git a/projects/platform/platform_macos/gryphn_platform_macos.m b/projects/platform/platform_macos/gryphn_platform_macos.m index 8865700..2019db2 100644 --- a/projects/platform/platform_macos/gryphn_platform_macos.m +++ b/projects/platform/platform_macos/gryphn_platform_macos.m @@ -27,6 +27,7 @@ CAMetalLayer* gnCreateCAMetalLayer(NSWindow* window) { [layer setFramebufferOnly:YES]; [view setLayer:layer]; [view setWantsLayer:YES]; + // [layer setDisplaySyncEnabled:NO]; CGSize viewSize = view.bounds.size; CGFloat scale = window.screen.backingScaleFactor; layer.pixelFormat = MTLPixelFormatBGRA8Unorm;