RAIIfy vulkan

This commit is contained in:
Guillaume Meunier
2024-01-07 11:45:07 +01:00
parent 54fe51b21f
commit cf14f9bd8b
44 changed files with 2711 additions and 2793 deletions
-63
View File
@@ -18,66 +18,3 @@
*/
#include "pipeline.h"
#include "vk.h"
vk::pipeline::pipeline(VkDevice device, vk::pipeline::graphics_info & create_info, const VkPipelineLayout layout) :
device(device)
{
for (VkPipelineShaderStageCreateInfo & i: create_info.shader_stages)
{
i.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
}
create_info.InputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
create_info.RasterizationState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
create_info.MultisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
create_info.DepthStencilState.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
create_info.ColorBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
VkPipelineVertexInputStateCreateInfo VertexInputState{
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.vertexBindingDescriptionCount = (uint32_t)create_info.vertex_input_bindings.size(),
.pVertexBindingDescriptions = create_info.vertex_input_bindings.data(),
.vertexAttributeDescriptionCount = (uint32_t)create_info.vertex_input_attributes.size(),
.pVertexAttributeDescriptions = create_info.vertex_input_attributes.data(),
};
VkPipelineDynamicStateCreateInfo DynamicState{
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.dynamicStateCount = (uint32_t)create_info.dynamic_states.size(),
.pDynamicStates = create_info.dynamic_states.data()};
VkPipelineViewportStateCreateInfo ViewportState{
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
.viewportCount = (uint32_t)create_info.viewports.size(),
.pViewports = create_info.viewports.data(),
.scissorCount = (uint32_t)create_info.scissors.size(),
.pScissors = create_info.scissors.data(),
};
VkGraphicsPipelineCreateInfo info{};
info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
info.stageCount = create_info.shader_stages.size();
info.pStages = create_info.shader_stages.data();
info.pVertexInputState = &VertexInputState;
info.pInputAssemblyState = &create_info.InputAssemblyState;
info.pViewportState = &ViewportState;
info.pRasterizationState = &create_info.RasterizationState;
info.pMultisampleState = &create_info.MultisampleState;
info.pColorBlendState = &create_info.ColorBlendState;
info.layout = layout;
info.renderPass = create_info.renderPass;
info.subpass = create_info.subpass;
if (DynamicState.dynamicStateCount > 0)
info.pDynamicState = &DynamicState;
CHECK_VK(vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &info, nullptr, &id));
}
vk::pipeline::~pipeline()
{
if (device)
vkDestroyPipeline(device, id, nullptr);
}