diff --git a/rendering_api/metal/src/core/pipelines/graphics_pipeline/metal_graphics_pipeline.m b/rendering_api/metal/src/core/pipelines/graphics_pipeline/metal_graphics_pipeline.m index 2b4479d..af98c30 100644 --- a/rendering_api/metal/src/core/pipelines/graphics_pipeline/metal_graphics_pipeline.m +++ b/rendering_api/metal/src/core/pipelines/graphics_pipeline/metal_graphics_pipeline.m @@ -23,8 +23,20 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip graphicsPipeline->graphicsPipeline = malloc(sizeof(struct gnPlatformGraphicsPipeline_t)); MTLRenderPipelineDescriptor* descriptor = [[MTLRenderPipelineDescriptor alloc] init]; - for (int i = 0; i < info.renderPassDescriptor->info.attachmentCount; i++) { - [descriptor.colorAttachments objectAtIndexedSubscript:i].pixelFormat = mtlGryphnFormatToVulkanFormat(info.renderPassDescriptor->info.attachmentInfos[i].format); + if (info.subpassIndex >= info.renderPassDescriptor->info.subpassCount) { + gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){ + .message = gnCreateString("Subpass index is larger then the subpass count in render pass descriptor") + }); + return GN_UNKNOWN_SUBPASS; + } + + struct gnSubpassInfo_t subpass = info.renderPassDescriptor->info.subpassInfos[info.subpassIndex]; + + for (uint32_t i = 0; i < subpass.colorAttachmentCount; i++) { + gnSubpassAttachmentInfo subpassAtt = subpass.colorAttachments[i]; + + gnRenderPassAttachmentInfo attInfo = info.renderPassDescriptor->info.attachmentInfos[subpassAtt.index]; + descriptor.colorAttachments[i].pixelFormat = mtlGryphnFormatToVulkanFormat(attInfo.format); if (info.colorBlending.enable == gnTrue) { [descriptor.colorAttachments objectAtIndexedSubscript:i].blendingEnabled = YES; [descriptor.colorAttachments objectAtIndexedSubscript:i].rgbBlendOperation = vkGryphnBlendOperation(info.colorBlending.colorBlendOperation); diff --git a/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c b/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c index 776cc02..6452846 100644 --- a/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c +++ b/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.c @@ -207,4 +207,6 @@ void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline) if (graphicsPipeline->graphicsPipeline->createdPipelineLayout) vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL); vkDestroyPipeline(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->graphicsPipeline, NULL); + + free(graphicsPipeline->graphicsPipeline); } diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index 23d99e7..df07224 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -23,7 +23,8 @@ typedef enum gnReturnCode_t { GN_FAILED_TO_CREATE_UNIFORM_LAYOUT, GN_FAILED_TO_CREATE_RENDER_PASS, GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE, - GN_UNSUPPORTED_SHADER_MODULE + GN_UNSUPPORTED_SHADER_MODULE, + GN_UNKNOWN_SUBPASS } gnReturnCode; typedef gnReturnCode gnErrorCode; @@ -52,5 +53,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_FAILED_TO_CREATE_RENDER_PASS: return "GN_FAILED_TO_CREATE_RENDER_PASS"; case GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE: return "GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE"; case GN_UNSUPPORTED_SHADER_MODULE: return "GN_UNSUPPORTED_SHADER_MODULE"; + case GN_UNKNOWN_SUBPASS: return "GN_UNKNOWN_SUBPASS"; } }