diff --git a/rendering_api/vulkan/src/instance/vulkan_instance.c b/rendering_api/vulkan/src/instance/vulkan_instance.c index 8b17d52..26c2b3f 100644 --- a/rendering_api/vulkan/src/instance/vulkan_instance.c +++ b/rendering_api/vulkan/src/instance/vulkan_instance.c @@ -7,50 +7,47 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback( VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) { - printf("Created instance: %s\n", pCallbackData->pMessage); + gnMessageSeverity severity; + gnMessageType type; + gnMessageData data = { + .message = gnCreateString(pCallbackData->pMessage) + }; - // gnMessageSeverity severity; - // gnMessageType type; - // gnMessageData data = { - // .message = gnCreateString(pCallbackData->pMessage) - // }; + switch (messageSeverity) { + default: break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: severity = GN_MESSAGE_VERBOSE; break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: severity = GN_MESSAGE_INFO; break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: severity = GN_MESSAGE_WARNING; break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: severity = GN_MESSAGE_ERROR; break; + } - // switch (messageSeverity) { - // default: break; - // case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: severity = GN_MESSAGE_VERBOSE; break; - // case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: severity = GN_MESSAGE_INFO; break; - // case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: severity = GN_MESSAGE_WARNING; break; - // case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: severity = GN_MESSAGE_ERROR; break; - // } + switch (messageType) { + default: break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT: type = GN_DEBUG_MESSAGE_GENERAL; break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT: type = GN_DEBUG_MESSAGE_VALIDATION; break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT: type = GN_DEBUG_MESSAGE_PERFORMANCE; break; + } - // switch (messageType) { - // default: break; - // case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT: type = GN_DEBUG_MESSAGE_GENERAL; break; - // case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT: type = GN_DEBUG_MESSAGE_VALIDATION; break; - // case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT: type = GN_DEBUG_MESSAGE_PERFORMANCE; break; - // } + gnInstanceHandle instance = (gnInstanceHandle)pUserData; - // gnInstanceHandle instance = (gnInstanceHandle)pUserData; + if (instance->debugger) { + instance->debugger->info.callback( + severity, type, data, instance->debugger->info.userData + ); + } else { + instance->instance->instanceMessageCount++; + if (instance->instance->instanceMessageCount == 1) + instance->instance->instanceMessages = malloc(sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount); + else + instance->instance->instanceMessages = realloc(instance->instance->instanceMessages, sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount); - // if (instance->debugger) { - // instance->debugger->info.callback( - // severity, type, data, instance->debugger->info.userData - // ); - // } else { - // instance->instance->instanceMessageCount++; - // if (instance->instance->instanceMessageCount == 1) { - // instance->instance->instanceMessages = malloc(sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount); - // } - // else { - // instance->instance->instanceMessages = realloc(instance->instance->instanceMessages, sizeof(struct gnInstanceMessage) * instance->instance->instanceMessageCount); - // } - // instance->instance->instanceMessages[instance->instance->instanceMessageCount - 1] = (struct gnInstanceMessage){ - // .data = data, - // .severity = severity, - // .type = type - // }; - // } + instance->instance->instanceMessages[instance->instance->instanceMessageCount - 1] = (struct gnInstanceMessage){ + .data = data, + .severity = severity, + .type = type + }; + } return VK_FALSE; } diff --git a/rendering_api/vulkan/src/output_device/vulkan_output_device.c b/rendering_api/vulkan/src/output_device/vulkan_output_device.c index ada25ef..9fde611 100644 --- a/rendering_api/vulkan/src/output_device/vulkan_output_device.c +++ b/rendering_api/vulkan/src/output_device/vulkan_output_device.c @@ -76,9 +76,11 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanc .queueFamilyIndex = transferQueueIndex }; - if (vkCreateCommandPool(outputDevice->outputDevice->device, &poolInfo, NULL, &outputDevice->outputDevice->transferCommandPool) != VK_SUCCESS) { + if (vkCreateCommandPool(outputDevice->outputDevice->device, &poolInfo, NULL, &outputDevice->outputDevice->transferCommandPool) != VK_SUCCESS) return GN_FAILED_TO_CREATE_COMMAND_POOL; - } + + free(queueCreateInfos); + free(queueFamilies); return GN_SUCCESS; } 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 03d624c..ccade0e 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 @@ -4,6 +4,9 @@ #include "renderpass/vulkan_render_pass_descriptor.h" #include "uniforms/vulkan_uniform_layout.h" +#include "stdio.h" + + VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) { switch (state) { case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_VIEWPORT; @@ -63,37 +66,35 @@ VkFormat vkGryphnVertexFormat(gnVertexFormat format) { gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnDevice device, gnGraphicsPipelineInfo info) { graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline)); - for (int i = 0; i < GN_DYNAMIC_STATE_MAX; i++) graphicsPipeline->graphicsPipeline->isDynamic[i] = gnFalse; - VkDynamicState* dynamicStates = malloc(sizeof(VkDynamicState) * info.dynamicState.dynamicStateCount); + graphicsPipeline->graphicsPipeline->dynamicStates = malloc(sizeof(VkDynamicState) * info.dynamicState.dynamicStateCount); for (int i = 0; i < info.dynamicState.dynamicStateCount; i++) { graphicsPipeline->graphicsPipeline->isDynamic[info.dynamicState.dynamicStates[i]] = gnTrue; - dynamicStates[i] = vkGryphnDynamicStateToVulkanDynamicState(info.dynamicState.dynamicStates[i]); + graphicsPipeline->graphicsPipeline->dynamicStates[i] = vkGryphnDynamicStateToVulkanDynamicState(info.dynamicState.dynamicStates[i]); } graphicsPipeline->graphicsPipeline->dynamicState = (VkPipelineDynamicStateCreateInfo){ .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .dynamicStateCount = info.dynamicState.dynamicStateCount, - .pDynamicStates = dynamicStates + .pDynamicStates = graphicsPipeline->graphicsPipeline->dynamicStates }; int vertexAttributeCount = 0; - VkVertexInputAttributeDescription* attributeDescriptions = NULL; - VkVertexInputBindingDescription* bindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * info.shaderInputLayout.bufferCount); + graphicsPipeline->graphicsPipeline->bindingDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * info.shaderInputLayout.bufferCount); for (int i = 0; i < info.shaderInputLayout.bufferCount; i++) { - bindingDescriptions[i].binding = info.shaderInputLayout.bufferAttributes[i].binding; - bindingDescriptions[i].stride = info.shaderInputLayout.bufferAttributes[i].size; - bindingDescriptions[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + graphicsPipeline->graphicsPipeline->bindingDescriptions[i].binding = info.shaderInputLayout.bufferAttributes[i].binding; + graphicsPipeline->graphicsPipeline->bindingDescriptions[i].stride = info.shaderInputLayout.bufferAttributes[i].size; + graphicsPipeline->graphicsPipeline->bindingDescriptions[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; vertexAttributeCount += info.shaderInputLayout.bufferAttributes[i].attributeCount; } - attributeDescriptions = malloc(sizeof(VkVertexInputBindingDescription) * vertexAttributeCount); + graphicsPipeline->graphicsPipeline->attributeDescriptions = malloc(sizeof(VkVertexInputAttributeDescription) * vertexAttributeCount); for (int i = 0, j = 0; j < info.shaderInputLayout.bufferCount; j++) { for (int k = 0; k < info.shaderInputLayout.bufferAttributes[j].attributeCount; k++) { - attributeDescriptions[i].binding = j; - attributeDescriptions[i].location = info.shaderInputLayout.bufferAttributes[j].attributes[k].location; - attributeDescriptions[i].offset = info.shaderInputLayout.bufferAttributes[j].attributes[k].offset; - attributeDescriptions[i].format = vkGryphnVertexFormat(info.shaderInputLayout.bufferAttributes[j].attributes[k].format); + graphicsPipeline->graphicsPipeline->attributeDescriptions[i].binding = j; + graphicsPipeline->graphicsPipeline->attributeDescriptions[i].location = info.shaderInputLayout.bufferAttributes[j].attributes[k].location; + graphicsPipeline->graphicsPipeline->attributeDescriptions[i].offset = info.shaderInputLayout.bufferAttributes[j].attributes[k].offset; + graphicsPipeline->graphicsPipeline->attributeDescriptions[i].format = vkGryphnVertexFormat(info.shaderInputLayout.bufferAttributes[j].attributes[k].format); i++; } } @@ -101,9 +102,9 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD graphicsPipeline->graphicsPipeline->vertexInfo = (VkPipelineVertexInputStateCreateInfo){ .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, .vertexBindingDescriptionCount = info.shaderInputLayout.bufferCount, - .pVertexBindingDescriptions = bindingDescriptions, + .pVertexBindingDescriptions = graphicsPipeline->graphicsPipeline->bindingDescriptions, .vertexAttributeDescriptionCount = vertexAttributeCount, - .pVertexAttributeDescriptions = attributeDescriptions + .pVertexAttributeDescriptions = graphicsPipeline->graphicsPipeline->attributeDescriptions }; graphicsPipeline->graphicsPipeline->inputAssembly = (VkPipelineInputAssemblyStateCreateInfo){ @@ -191,19 +192,18 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD pipelineLayoutInfo.pPushConstantRanges = NULL }; - if (vkCreatePipelineLayout(device->outputDevice->device, &pipelineLayoutInfo, NULL, &graphicsPipeline->graphicsPipeline->pipelineLayout) != VK_SUCCESS) { + if (vkCreatePipelineLayout(device->outputDevice->device, &pipelineLayoutInfo, NULL, &graphicsPipeline->graphicsPipeline->pipelineLayout) != VK_SUCCESS) return GN_FAILED_TO_CREATE_UNIFORM_LAYOUT; - } - VkPipelineShaderStageCreateInfo* modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount); + graphicsPipeline->graphicsPipeline->modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount); for (int i = 0; i < info.shaderModuleCount; i++) { - modules[i] = info.shaderModules[i]->shaderModule->shaderStageInfo; + graphicsPipeline->graphicsPipeline->modules[i] = info.shaderModules[i]->shaderModule->shaderStageInfo; } VkGraphicsPipelineCreateInfo pipelineInfo = { .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .stageCount = info.shaderModuleCount, - .pStages = modules, + .pStages = graphicsPipeline->graphicsPipeline->modules, .pVertexInputState = &graphicsPipeline->graphicsPipeline->vertexInfo, .pInputAssemblyState = &graphicsPipeline->graphicsPipeline->inputAssembly, .pViewportState = &graphicsPipeline->graphicsPipeline->viewportState, @@ -219,21 +219,21 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD .basePipelineIndex = -1, }; - if (vkCreateGraphicsPipelines(device->outputDevice->device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &graphicsPipeline->graphicsPipeline->graphicsPipeline) != VK_SUCCESS) { + if (vkCreateGraphicsPipelines(device->outputDevice->device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &graphicsPipeline->graphicsPipeline->graphicsPipeline) != VK_SUCCESS) return GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE; - } - free(dynamicStates); - free(bindingDescriptions); - free(attributeDescriptions); return GN_SUCCESS; } void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline) { + free(graphicsPipeline->graphicsPipeline->dynamicStates); + free(graphicsPipeline->graphicsPipeline->bindingDescriptions); + free(graphicsPipeline->graphicsPipeline->attributeDescriptions); for (int i = 0; i < graphicsPipeline->graphicsPipeline->setCount; i++) vkDestroyDescriptorSetLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->sets[i], NULL); - vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL); - vkDestroyPipeline(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->graphicsPipeline, NULL); + free(graphicsPipeline->graphicsPipeline->modules); + vkDestroyPipeline(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->graphicsPipeline, NULL); + vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL); free(graphicsPipeline->graphicsPipeline); } diff --git a/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.h b/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.h index dee5fa5..e937fda 100644 --- a/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.h +++ b/rendering_api/vulkan/src/pipelines/graphics_pipeline/vulkan_graphics_pipeline.h @@ -22,4 +22,12 @@ typedef struct gnPlatformGraphicsPipeline_t { VkPipeline graphicsPipeline; + + + + // memory that needs to be freeed + VkDynamicState* dynamicStates; + VkVertexInputBindingDescription* bindingDescriptions; + VkVertexInputAttributeDescription* attributeDescriptions; + VkPipelineShaderStageCreateInfo* modules; } gnPlatformGraphicsPipeline; diff --git a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c index 87e5d00..c6ad87a 100644 --- a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c +++ b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.c @@ -102,9 +102,8 @@ gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueueHandle presentationQ presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t)); presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture)); imageViewCreateInfo.image = presentationQueue->presentationQueue->swapChainImages[i]; - if (vkCreateImageView(device->outputDevice->device, &imageViewCreateInfo, NULL, &presentationQueue->presentationQueue->swapChainImageViews[i]) != VK_SUCCESS) { + if (vkCreateImageView(device->outputDevice->device, &imageViewCreateInfo, NULL, &presentationQueue->presentationQueue->swapChainImageViews[i]) != VK_SUCCESS) return GN_FAILED_TO_CREATE_IMAGE_VIEW; - } presentationQueue->images[i]->texture->image = presentationQueue->presentationQueue->swapChainImages[i]; presentationQueue->images[i]->texture->imageView = presentationQueue->presentationQueue->swapChainImageViews[i]; @@ -129,4 +128,7 @@ void gnDestroyPresentationQueueFn(gnPresentationQueueHandle queue) { for (int i = 0; i < queue->imageCount; i++) vkDestroyImageView(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChainImageViews[i], NULL); vkDestroySwapchainKHR(queue->outputDevice->outputDevice->device, queue->presentationQueue->swapChain, NULL); + free(queue->presentationQueue->swapChainImageViews); + free(queue->presentationQueue->swapChainImages); + free(queue->presentationQueue); } diff --git a/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.c b/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.c index 9128347..593acc8 100644 --- a/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.c +++ b/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.c @@ -30,24 +30,26 @@ VkImageLayout vkGryphnImageLayout(gnImageLayout layout) { gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass, struct gnOutputDevice_t* device, struct gnRenderPassDescriptorInfo_t info) { renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor)); - VkAttachmentDescription* attachments = malloc(sizeof(VkAttachmentDescription) * info.attachmentCount); + renderPass->renderPassDescriptor->attachmentCount = info.attachmentCount; + renderPass->renderPassDescriptor->attachments = malloc(sizeof(VkAttachmentDescription) * info.attachmentCount); for (int i = 0; i < info.attachmentCount; i++) { - attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format); - attachments[i].flags = 0; - attachments[i].samples = VK_SAMPLE_COUNT_1_BIT; + renderPass->renderPassDescriptor->attachments[i].format = vkGryphnFormatToVulkanFormat(info.attachmentInfos[i].format); + renderPass->renderPassDescriptor->attachments[i].flags = 0; + renderPass->renderPassDescriptor->attachments[i].samples = VK_SAMPLE_COUNT_1_BIT; - attachments[i].loadOp = vkGryphnLoadOperation(info.attachmentInfos[i].loadOperation); - attachments[i].storeOp = vkGryphnStoreOperation(info.attachmentInfos[i].storeOperation); + renderPass->renderPassDescriptor->attachments[i].loadOp = vkGryphnLoadOperation(info.attachmentInfos[i].loadOperation); + renderPass->renderPassDescriptor->attachments[i].storeOp = vkGryphnStoreOperation(info.attachmentInfos[i].storeOperation); - attachments[i].stencilLoadOp = vkGryphnLoadOperation(info.attachmentInfos[i].stencilLoadOperation); - attachments[i].stencilStoreOp = vkGryphnStoreOperation(info.attachmentInfos[i].stencilStoreOperation); + renderPass->renderPassDescriptor->attachments[i].stencilLoadOp = vkGryphnLoadOperation(info.attachmentInfos[i].stencilLoadOperation); + renderPass->renderPassDescriptor->attachments[i].stencilStoreOp = vkGryphnStoreOperation(info.attachmentInfos[i].stencilStoreOperation); - attachments[i].initialLayout = vkGryphnImageLayout(info.attachmentInfos[i].initialLayout); - attachments[i].finalLayout = vkGryphnImageLayout(info.attachmentInfos[i].finalLayout); + renderPass->renderPassDescriptor->attachments[i].initialLayout = vkGryphnImageLayout(info.attachmentInfos[i].initialLayout); + renderPass->renderPassDescriptor->attachments[i].finalLayout = vkGryphnImageLayout(info.attachmentInfos[i].finalLayout); } - VkSubpassDescription* subpasses = malloc(sizeof(VkSubpassDescription) * info.subpassCount); - VkAttachmentReference** colorAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount); + renderPass->renderPassDescriptor->subpassCount = info.subpassCount; + renderPass->renderPassDescriptor->subpasses = malloc(sizeof(VkSubpassDescription) * info.subpassCount); + renderPass->renderPassDescriptor->colorAttachments = malloc(sizeof(VkAttachmentReference*) * info.subpassCount); VkAttachmentReference ref = { .attachment = 0, @@ -55,27 +57,27 @@ gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* ren }; for (int i = 0; i < info.subpassCount; i++) { - colorAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount); + renderPass->renderPassDescriptor->colorAttachments[i] = malloc(sizeof(VkAttachmentReference) * info.subpassInfos[i].colorAttachmentCount); for (int c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) { - colorAttachments[i][c] = (VkAttachmentReference){ + renderPass->renderPassDescriptor->colorAttachments[i][c] = (VkAttachmentReference){ .attachment = info.subpassInfos[i].colorAttachments[c].index, .layout = vkGryphnImageLayout(info.subpassInfos[i].colorAttachments[c].imageLayout) }; } - subpasses[i] = (VkSubpassDescription){ + renderPass->renderPassDescriptor->subpasses[i] = (VkSubpassDescription){ .flags = 0, .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, .colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount, - .pColorAttachments = colorAttachments[i] + .pColorAttachments = renderPass->renderPassDescriptor->colorAttachments[i] }; } - VkSubpassDependency* dependencies = malloc(sizeof(VkSubpassDependency) * info.dependencyCount); + renderPass->renderPassDescriptor->dependencies = malloc(sizeof(VkSubpassDependency) * info.dependencyCount); for (int i = 0; i < info.dependencyCount; i++) { - dependencies[i] = (VkSubpassDependency) { + renderPass->renderPassDescriptor->dependencies[i] = (VkSubpassDependency) { .srcSubpass = (info.dependencies[i].source == GN_SUBPASS_EXTERNAL) ? VK_SUBPASS_EXTERNAL : info.dependencies[i].source, .dstSubpass = (info.dependencies[i].destination == GN_SUBPASS_EXTERNAL) ? VK_SUBPASS_EXTERNAL : info.dependencies[i].destination, .srcStageMask = info.dependencies[i].soruceStageMask, @@ -90,24 +92,25 @@ gnReturnCode gnCreateRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* ren .pNext = NULL, .flags = 0, .attachmentCount = info.attachmentCount, - .pAttachments = attachments, + .pAttachments = renderPass->renderPassDescriptor->attachments, .subpassCount = info.subpassCount, - .pSubpasses = subpasses, + .pSubpasses = renderPass->renderPassDescriptor->subpasses, .dependencyCount = info.dependencyCount, - .pDependencies = dependencies, + .pDependencies = renderPass->renderPassDescriptor->dependencies, }; if (vkCreateRenderPass(device->outputDevice->device, &renderPassInfo, NULL, &renderPass->renderPassDescriptor->renderPass) != VK_SUCCESS) return GN_FAILED_TO_CREATE_RENDER_PASS; - free(attachments); - free(subpasses); - free(dependencies); - return GN_SUCCESS; } -void gnDestroyRenderPassDescriptorFn(struct gnRenderPassDescriptor_t* renderPass) { +void gnDestroyRenderPassDescriptorFn(gnRenderPassDescriptor renderPass) { vkDestroyRenderPass(renderPass->device->outputDevice->device, renderPass->renderPassDescriptor->renderPass, NULL); + + + free(renderPass->renderPassDescriptor->attachments); + free(renderPass->renderPassDescriptor->subpasses); + free(renderPass->renderPassDescriptor->dependencies); } diff --git a/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.h b/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.h index e65edbd..e82595a 100644 --- a/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.h +++ b/rendering_api/vulkan/src/renderpass/vulkan_render_pass_descriptor.h @@ -4,4 +4,13 @@ typedef struct gnPlatformRenderPassDescriptor_t { VkRenderPass renderPass; + + uint32_t attachmentCount; + VkAttachmentDescription* attachments; + + uint32_t subpassCount; + VkSubpassDescription* subpasses; + VkSubpassDependency* dependencies; + + VkAttachmentReference** colorAttachments; } gnPlatformRenderPassDescriptor; diff --git a/src/core/command/command_buffer/gryphn_command_buffer.c b/src/core/command/command_buffer/gryphn_command_buffer.c index 0206440..3a1713d 100644 --- a/src/core/command/command_buffer/gryphn_command_buffer.c +++ b/src/core/command/command_buffer/gryphn_command_buffer.c @@ -1,13 +1,11 @@ #include "gryphn_command_buffer.h" #include "core/gryphn_platform_functions.h" -#include "stdio.h" gnReturnCode gnCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) { for (int i = 0; i < count; i++) { buffers[i] = malloc(sizeof(struct gnCommandBuffer_t)); buffers[i]->commandPool = commandPool; } - printf("Created the graphics pipeline: %p\n", commandPool->commandFunctions->_gnCommandBindGraphicsPipeline); return commandPool->commandFunctions->_gnCommandPoolAllocateCommandBuffers(buffers, count, commandPool); } diff --git a/src/core/debugger/gryphn_debugger.c b/src/core/debugger/gryphn_debugger.c index dca6536..233bb1d 100644 --- a/src/core/debugger/gryphn_debugger.c +++ b/src/core/debugger/gryphn_debugger.c @@ -7,5 +7,5 @@ gnReturnCode gnCreateDebugger(gnDebuggerHandle* debugger, const struct gnDebugge return GN_SUCCESS; } void gnDestroyDebugger(gnDebuggerHandle debugger) { - free(debugger); + // free(debugger); } diff --git a/src/core/instance/gryphn_instance.c b/src/core/instance/gryphn_instance.c index 4402e3f..4e64af5 100644 --- a/src/core/instance/gryphn_instance.c +++ b/src/core/instance/gryphn_instance.c @@ -6,9 +6,9 @@ #include "stdio.h" gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, struct gnInstanceInfo_t info) { - *instanceHandlePtr = malloc(sizeof(struct gnInstance_t)); gnInstanceHandle instance = *instanceHandlePtr; + instance->debugger = NULL; if (!gnIsAPISupported(info.renderingAPI)) return GN_UNSUPPORTED_RENDERING_API; instance->loadDeviceFunctions = gnFalse; @@ -22,8 +22,6 @@ gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, struct gnInst return instance->functions->_gnCreateInstance(instance, info); } void gnInstanceAttachDebugger(gnInstanceHandle instance, struct gnDebugger_t *debugger) { - - if (instance->debugger != NULL) { gnDebuggerSetErrorMessage(debugger, (gnMessageData){ .message = gnCreateString("Debugger already attached to instance") @@ -39,15 +37,11 @@ void gnInstanceAttachDebugger(gnInstanceHandle instance, struct gnDebugger_t *de } } -#include "stdio.h" void gnDestroyInstance(gnInstanceHandle instance) { - if (instance->debugger) { - instance->functions->_gnDestroyDebugger(instance->debugger); - } + if (instance->debugger) instance->functions->_gnDestroyDebugger(instance->debugger); instance->functions->_gnDestroyInstance(instance); } void gnInstanceReleaseDebugger(gnInstanceHandle instance) { instance->debugger = NULL; - free(instance); }