With NVIDIA GT 740M on Windows I’m only seeing rendering which goes into swapchain image #0.
I’m trying to find a good way to use swapchain for CAD-like scenarios. Rendering is performed not in a loop frame after frame but only if something is changed.
My code is here: Bitbucket See ‘example’ folder for MSVC 2015 project.
Pre-built windows binary can be downloaded from here: Bitbucket | Git solution for teams using Jira
I create VK_PRESENT_MODE_FIFO_KHR swapchain with 2 images, basic vsync mode.
In this demo app frame is re-rendered on each left mouse button click. Each time with a different color, color and swapchain image are logged to console.
And on my NVIDIA GT 740M with 368.22 and 368.39 drivers on Win10 x64 I have 2 problems with this code:
-
Only rendering into swapchain image #0 is visible. Looks like vkQueuePresentKHR with image #1 is ignored by driver.
-
If window is left without updates for some time (around 30 seconds) index buffer (in device local memory) gets corrupted: Bitbucket | Git solution for teams using Jira
Also, I’ve tried to modify Gears example by Sascha Willems https://github.com/SaschaWillems/Vulkan/blob/master/gears/gears.cpp to set clear color to red for frames which go into #1 and #2 swapchain images. If all frames are shown this should result in flickering background. But for me it still solid dark background from image #0.
Here is modified buildCommandBuffers function from Gears example (my change is marked by ///):
void buildCommandBuffers()
{
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
VkClearValue clearValues[2];
clearValues[0].color = defaultClearColor;
clearValues[1].depthStencil = { 1.0f, 0 };
VkRenderPassBeginInfo renderPassBeginInfo = vkTools::initializers::renderPassBeginInfo();
renderPassBeginInfo.renderPass = renderPass;
renderPassBeginInfo.renderArea.offset.x = 0;
renderPassBeginInfo.renderArea.offset.y = 0;
renderPassBeginInfo.renderArea.extent.width = width;
renderPassBeginInfo.renderArea.extent.height = height;
renderPassBeginInfo.clearValueCount = 2;
renderPassBeginInfo.pClearValues = clearValues;
for (int32_t i = 0; i < drawCmdBuffers.size(); ++i)
{
/// red background for images other than 0
if( i != 0 )
clearValues[0].color = { 1.f, 0.f, 0.f, 1.f };
///
renderPassBeginInfo.framebuffer = frameBuffers[i];
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
VkViewport viewport = vkTools::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);
VkRect2D scissor = vkTools::initializers::rect2D(width, height, 0, 0);
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
for (auto& gear : gears)
{
gear->draw(drawCmdBuffers[i], pipelineLayout);
}
vkCmdEndRenderPass(drawCmdBuffers[i]);
VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i]));
}
}