finish vulkan graphics pipelines

This commit is contained in:
Greg Wells
2025-05-28 21:35:23 -04:00
parent b443b5173c
commit c58275353a
4 changed files with 46 additions and 2 deletions

View File

@@ -1,10 +1,12 @@
#include "vulkan_graphics_pipeline.h" #include "vulkan_graphics_pipeline.h"
#include "core/debugger/gryphn_debugger.h" #include "core/debugger/gryphn_debugger.h"
#include "output_device/vulkan_output_devices.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) { VkDynamicState vkGryphnDynamicStateToVulkanDynamicState(enum gnDynamicState_e state) {
switch (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_SCISSOR: return VK_DYNAMIC_STATE_SCISSOR;
case GN_DYNAMIC_STATE_MAX: return VK_DYNAMIC_STATE_MAX_ENUM; 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); free(dynamicStates);
return GN_SUCCESS; return GN_SUCCESS;
} }
@@ -176,4 +206,5 @@ gnReturnCode gnCreateGraphicsPipelineFn(struct gnGraphicsPipeline_t* graphicsPip
void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline) { void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline) {
if (graphicsPipeline->graphicsPipeline->createdPipelineLayout) if (graphicsPipeline->graphicsPipeline->createdPipelineLayout)
vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL); vkDestroyPipelineLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->pipelineLayout, NULL);
vkDestroyPipeline(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->graphicsPipeline, NULL);
} }

View File

@@ -17,4 +17,7 @@ typedef struct gnPlatformGraphicsPipeline_t {
gnBool createdPipelineLayout; gnBool createdPipelineLayout;
VkPipelineLayout pipelineLayout; VkPipelineLayout pipelineLayout;
VkPipeline graphicsPipeline;
} gnPlatformGraphicsPipeline; } gnPlatformGraphicsPipeline;

View File

@@ -1,6 +1,8 @@
#pragma once #pragma once
#include <core/output_device/gryphn_output_device.h> #include <core/output_device/gryphn_output_device.h>
#include <core/pipelines/gryphn_uniform_layout.h> #include <core/pipelines/gryphn_uniform_layout.h>
#include <core/renderpass/gryphn_render_pass_descriptor.h>
#include <core/shader_module/gryphn_shader_module.h>
typedef enum gnDynamicState_e { typedef enum gnDynamicState_e {
GN_DYNAMIC_VIEWPORT, GN_DYNAMIC_VIEWPORT,
@@ -79,6 +81,12 @@ typedef struct gnGraphicsPipelineInfo_t {
struct gnColorBlending_t colorBlending; struct gnColorBlending_t colorBlending;
struct gnUniformLayout_t* uniformLayout; struct gnUniformLayout_t* uniformLayout;
uint32_t subpassIndex;
struct gnRenderPassDescriptor_t* renderPassDescriptor;
uint32_t shaderModuleCount;
struct gnShaderModule_t* shaderModules;
} gnGraphicsPipelineInfo; } gnGraphicsPipelineInfo;
struct gnPlatformGraphicsPipeline_t; struct gnPlatformGraphicsPipeline_t;

View File

@@ -21,7 +21,8 @@ typedef enum gnReturnCode_t {
GN_FAILED_TO_CONVERT_SHADER_CODE, GN_FAILED_TO_CONVERT_SHADER_CODE,
GN_FAILED_TO_FIND_ENTRY_POINT, GN_FAILED_TO_FIND_ENTRY_POINT,
GN_FAILED_TO_CREATE_UNIFORM_LAYOUT, 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_FRAMEBUFFER_ATTACHMENT,
// GN_UNKNOWN_FUNCTION, // 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_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_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_RENDER_PASS: return "GN_FAILED_TO_CREATE_RENDER_PASS";
case GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE: return "GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE";
} }
} }