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 4f64ca7..776cc02 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 @@ -1,10 +1,12 @@ #include "vulkan_graphics_pipeline.h" #include "core/debugger/gryphn_debugger.h" #include "output_device/vulkan_output_devices.h" +#include "shader_module/vulkan_shader_module.h" +#include "renderpass/vulkan_render_pass_descriptor.h" VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) { switch (state) { - case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_SCISSOR; + case GN_DYNAMIC_VIEWPORT: return VK_DYNAMIC_STATE_VIEWPORT; case GN_DYNAMIC_SCISSOR: return VK_DYNAMIC_STATE_SCISSOR; case GN_DYNAMIC_STATE_MAX: return VK_DYNAMIC_STATE_MAX_ENUM; @@ -169,6 +171,34 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip }); } + VkPipelineShaderStageCreateInfo* modules = malloc(sizeof(VkPipelineShaderStageCreateInfo) * info.shaderModuleCount); + for (int i = 0; i < info.shaderModuleCount; i++) { + modules[i] = info.shaderModules[i].shaderModule->shaderStageInfo; + } + + VkGraphicsPipelineCreateInfo pipelineInfo = { + .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + .stageCount = info.shaderModuleCount, + .pStages = modules, + .pVertexInputState = &graphicsPipeline->graphicsPipeline->vertexInfo, + .pInputAssemblyState = &graphicsPipeline->graphicsPipeline->inputAssembly, + .pViewportState = &graphicsPipeline->graphicsPipeline->viewportState, + .pRasterizationState = &graphicsPipeline->graphicsPipeline->rasterizer, + .pMultisampleState = &multisampling, + .pDepthStencilState = NULL, + .pColorBlendState = &graphicsPipeline->graphicsPipeline->colorBlending, + .pDynamicState = &graphicsPipeline->graphicsPipeline->dynamicState, + .layout = graphicsPipeline->graphicsPipeline->pipelineLayout, + .renderPass = info.renderPassDescriptor->renderPassDescriptor->renderPass, + .subpass = info.subpassIndex, + .basePipelineHandle = VK_NULL_HANDLE, + .basePipelineIndex = -1 + }; + + 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); return GN_SUCCESS; } @@ -176,4 +206,5 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip 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); } 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 c41fe98..3671f41 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 @@ -17,4 +17,7 @@ typedef struct gnPlatformGraphicsPipeline_t { gnBool createdPipelineLayout; VkPipelineLayout pipelineLayout; + + + VkPipeline graphicsPipeline; } gnPlatformGraphicsPipeline; diff --git a/src/core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h b/src/core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h index d76d625..5086f8f 100644 --- a/src/core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h +++ b/src/core/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h @@ -1,6 +1,8 @@ #pragma once #include #include +#include +#include typedef enum gnDynamicState_e { GN_DYNAMIC_VIEWPORT, @@ -79,6 +81,12 @@ typedef struct gnGraphicsPipelineInfo_t { struct gnColorBlending_t colorBlending; struct gnUniformLayout_t* uniformLayout; + + uint32_t subpassIndex; + struct gnRenderPassDescriptor_t* renderPassDescriptor; + + uint32_t shaderModuleCount; + struct gnShaderModule_t* shaderModules; } gnGraphicsPipelineInfo; struct gnPlatformGraphicsPipeline_t; diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index 4c5e8cf..4583afc 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -21,7 +21,8 @@ typedef enum gnReturnCode_t { GN_FAILED_TO_CONVERT_SHADER_CODE, GN_FAILED_TO_FIND_ENTRY_POINT, GN_FAILED_TO_CREATE_UNIFORM_LAYOUT, - GN_FAILED_TO_CREATE_RENDER_PASS + GN_FAILED_TO_CREATE_RENDER_PASS, + GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE // GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, // GN_UNKNOWN_FUNCTION, @@ -56,5 +57,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_FAILED_TO_FIND_ENTRY_POINT: return "GN_FAILED_TO_FIND_ENTRY_POINT"; case GN_FAILED_TO_CREATE_UNIFORM_LAYOUT: return "GN_FAILED_TO_CREATE_UNIFORM_LAYOUT"; 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"; } }