I implemented copy image to buffer at the end of render pass but my buffer is filled with clearValues[0].color value:
transitionImageLayout(commandBuffer,inputImage, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL );
copyBufferToImage(commandBuffer, inputBuffers, inputImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cfg.width, cfg.height);
transitionImageLayout(commandBuffer,inputImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkRenderPassBeginInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = renderPass; // Your render pass handle
renderPassInfo.framebuffer = frameBuffer; // Your framebuffer handle
renderPassInfo.renderArea.offset = {0, 0};
renderPassInfo.renderArea.extent = extent; // Your swap chain extent
std::array<VkClearValue, 3> clearValues = {};
clearValues[0].color = { 0.2f, 0.3f, 0.4f, 1.0f }; //background color of the image
clearValues[1].color = { 0.6f, 0.65f, 0.4f, 1.0f }; //background color of the image
clearValues[2].depthStencil.depth = 1.0f;
renderPassInfo.pClearValues = clearValues.data();
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
//Bind the first pipeline for the first shader
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,pipelineLayout,
0, 1, &descriptorSets, 0, nullptr);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS,pipelineLayout,
1, 1, &ubodescriptorSet, 0, nullptr);
//Bind vertex buffer
VkBuffer vertexBuffers[] = { vertexBuffer};
VkDeviceSize offsets[] = { 0 };
vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets);
vkCmdDraw(commandBuffer, static_cast<uint32_t>(meshVertices.size()), 1, 0, 0);
vkCmdEndRenderPass(commandBuffer);
transitionImageLayout(commandBuffer,outputImage, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
copyImageToBuffer(commandBuffer, outputBuffers, outputImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cfg.width, cfg.height);
I debugged the output color from the fragment shader by writing the color into a starage buffer and the color is correct:
outColor =texture(inputImage, coords);
//debug
outRGBA[idx]=colorToRGBA(outColor * 255.0f); //ok
So the fragment shader produces correct outColor but the output image is all clearValues[0].color = { 0.2f, 0.3f, 0.4f}
Where should I look for the bug?
Thanks,
Andrei