Skip to content

Commit

Permalink
PipelineConfigInfo self references Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blurrypiano committed Feb 2, 2021
1 parent 8a7a151 commit a867ab3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
7 changes: 5 additions & 2 deletions littleVulkanEngine/tutorial/first_app.cpp
Expand Up @@ -37,8 +37,11 @@ void FirstApp::createPipelineLayout() {
}

void FirstApp::createPipeline() {
auto pipelineConfig =
LvePipeline::defaultPipelineConfigInfo(lveSwapChain.width(), lveSwapChain.height());
PipelineConfigInfo pipelineConfig{};
LvePipeline::defaultPipelineConfigInfo(
pipelineConfig,
lveSwapChain.width(),
lveSwapChain.height());
pipelineConfig.renderPass = lveSwapChain.getRenderPass();
pipelineConfig.pipelineLayout = pipelineLayout;
lvePipeline = std::make_unique<LvePipeline>(
Expand Down
22 changes: 9 additions & 13 deletions littleVulkanEngine/tutorial/lve_pipeline.cpp
Expand Up @@ -80,20 +80,13 @@ void LvePipeline::createGraphicsPipeline(
vertexInputInfo.pVertexAttributeDescriptions = nullptr;
vertexInputInfo.pVertexBindingDescriptions = nullptr;

VkPipelineViewportStateCreateInfo viewportInfo{};
viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportInfo.viewportCount = 1;
viewportInfo.pViewports = &configInfo.viewport;
viewportInfo.scissorCount = 1;
viewportInfo.pScissors = &configInfo.scissor;

VkGraphicsPipelineCreateInfo pipelineInfo{};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.stageCount = 2;
pipelineInfo.pStages = shaderStages;
pipelineInfo.pVertexInputState = &vertexInputInfo;
pipelineInfo.pInputAssemblyState = &configInfo.inputAssemblyInfo;
pipelineInfo.pViewportState = &viewportInfo;
pipelineInfo.pViewportState = &configInfo.viewportInfo;
pipelineInfo.pRasterizationState = &configInfo.rasterizationInfo;
pipelineInfo.pMultisampleState = &configInfo.multisampleInfo;
pipelineInfo.pColorBlendState = &configInfo.colorBlendInfo;
Expand Down Expand Up @@ -133,9 +126,8 @@ void LvePipeline::bind(VkCommandBuffer commandBuffer) {
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
}

PipelineConfigInfo LvePipeline::defaultPipelineConfigInfo(uint32_t width, uint32_t height) {
PipelineConfigInfo configInfo{};

void LvePipeline::defaultPipelineConfigInfo(
PipelineConfigInfo& configInfo, uint32_t width, uint32_t height) {
configInfo.inputAssemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
configInfo.inputAssemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
configInfo.inputAssemblyInfo.primitiveRestartEnable = VK_FALSE;
Expand All @@ -150,6 +142,12 @@ PipelineConfigInfo LvePipeline::defaultPipelineConfigInfo(uint32_t width, uint32
configInfo.scissor.offset = {0, 0};
configInfo.scissor.extent = {width, height};

configInfo.viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
configInfo.viewportInfo.viewportCount = 1;
configInfo.viewportInfo.pViewports = &configInfo.viewport;
configInfo.viewportInfo.scissorCount = 1;
configInfo.viewportInfo.pScissors = &configInfo.scissor;

configInfo.rasterizationInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
configInfo.rasterizationInfo.depthClampEnable = VK_FALSE;
configInfo.rasterizationInfo.rasterizerDiscardEnable = VK_FALSE;
Expand Down Expand Up @@ -201,8 +199,6 @@ PipelineConfigInfo LvePipeline::defaultPipelineConfigInfo(uint32_t width, uint32
configInfo.depthStencilInfo.stencilTestEnable = VK_FALSE;
configInfo.depthStencilInfo.front = {}; // Optional
configInfo.depthStencilInfo.back = {}; // Optional

return configInfo;
}

} // namespace lve
7 changes: 6 additions & 1 deletion littleVulkanEngine/tutorial/lve_pipeline.hpp
Expand Up @@ -9,8 +9,12 @@
namespace lve {

struct PipelineConfigInfo {
PipelineConfigInfo(const PipelineConfigInfo&) = delete;

This comment has been minimized.

Copy link
@blurrypiano

blurrypiano Sep 11, 2021

Author Owner

should also declare default constructor
PipelineConfigInfo() = default;

PipelineConfigInfo& operator=(const PipelineConfigInfo&) = delete;

VkViewport viewport;
VkRect2D scissor;
VkPipelineViewportStateCreateInfo viewportInfo;
VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo;
VkPipelineRasterizationStateCreateInfo rasterizationInfo;
VkPipelineMultisampleStateCreateInfo multisampleInfo;
Expand All @@ -36,7 +40,8 @@ class LvePipeline {

void bind(VkCommandBuffer commandBuffer);

static PipelineConfigInfo defaultPipelineConfigInfo(uint32_t width, uint32_t height);
static void defaultPipelineConfigInfo(
PipelineConfigInfo& configInfo, uint32_t width, uint32_t height);

private:
static std::vector<char> readFile(const std::string& filepath);
Expand Down

1 comment on commit a867ab3

@maross3
Copy link

@maross3 maross3 commented on a867ab3 Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeming to have issues with the above fix.

Exception thrown: read access violation.
**this** was 0x238.

Doesn't reach the runtime error at:

		if (vkCreateGraphicsPipelines(appDevice.device(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS) {
			throw std::runtime_error("Failed to create graphics pipeline");
		}

I have been through the files multiple times, and I am not sure there is any difference

Please sign in to comment.