Update computeshader.cpp
There is a logical error that cause the first frame render error. Since the graphic rendering need to sample the compute shader 's output image, so the compute command need to run before the graphic rendering. If not, the graphic rendering will sample the gabage data (computer's output image) for the first frame and present on the display screen.This issue can be easy to be reproduced when the GPU device has a lower performance.
This commit is contained in:
parent
ab2d4060d2
commit
fb4187a916
1 changed files with 20 additions and 21 deletions
|
|
@ -490,6 +490,13 @@ public:
|
||||||
// Semaphore for compute & graphics sync
|
// Semaphore for compute & graphics sync
|
||||||
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
|
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
|
||||||
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &graphics.semaphore));
|
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &graphics.semaphore));
|
||||||
|
|
||||||
|
// Signal the semaphore
|
||||||
|
VkSubmitInfo submitInfo = vks::initializers::submitInfo();
|
||||||
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
|
submitInfo.pSignalSemaphores = &graphics.semaphore;
|
||||||
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||||
|
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareCompute()
|
void prepareCompute()
|
||||||
|
|
@ -559,13 +566,6 @@ public:
|
||||||
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
|
VkSemaphoreCreateInfo semaphoreCreateInfo = vks::initializers::semaphoreCreateInfo();
|
||||||
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &compute.semaphore));
|
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &compute.semaphore));
|
||||||
|
|
||||||
// Signal the semaphore
|
|
||||||
VkSubmitInfo submitInfo = vks::initializers::submitInfo();
|
|
||||||
submitInfo.signalSemaphoreCount = 1;
|
|
||||||
submitInfo.pSignalSemaphores = &compute.semaphore;
|
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
|
||||||
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
|
|
||||||
|
|
||||||
// Build a single command buffer containing the compute dispatch commands
|
// Build a single command buffer containing the compute dispatch commands
|
||||||
buildComputeCommandBuffer();
|
buildComputeCommandBuffer();
|
||||||
}
|
}
|
||||||
|
|
@ -595,6 +595,19 @@ public:
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
|
// Wait for rendering finished
|
||||||
|
VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
||||||
|
|
||||||
|
// Submit compute commands
|
||||||
|
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
|
||||||
|
computeSubmitInfo.commandBufferCount = 1;
|
||||||
|
computeSubmitInfo.pCommandBuffers = &compute.commandBuffer;
|
||||||
|
computeSubmitInfo.waitSemaphoreCount = 1;
|
||||||
|
computeSubmitInfo.pWaitSemaphores = &graphics.semaphore;
|
||||||
|
computeSubmitInfo.pWaitDstStageMask = &waitStageMask;
|
||||||
|
computeSubmitInfo.signalSemaphoreCount = 1;
|
||||||
|
computeSubmitInfo.pSignalSemaphores = &compute.semaphore;
|
||||||
|
VK_CHECK_RESULT(vkQueueSubmit(compute.queue, 1, &computeSubmitInfo, VK_NULL_HANDLE));
|
||||||
VulkanExampleBase::prepareFrame();
|
VulkanExampleBase::prepareFrame();
|
||||||
|
|
||||||
VkPipelineStageFlags graphicsWaitStageMasks[] = { VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
|
VkPipelineStageFlags graphicsWaitStageMasks[] = { VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
|
||||||
|
|
@ -612,20 +625,6 @@ public:
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
|
||||||
|
|
||||||
VulkanExampleBase::submitFrame();
|
VulkanExampleBase::submitFrame();
|
||||||
|
|
||||||
// Wait for rendering finished
|
|
||||||
VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
|
||||||
|
|
||||||
// Submit compute commands
|
|
||||||
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
|
|
||||||
computeSubmitInfo.commandBufferCount = 1;
|
|
||||||
computeSubmitInfo.pCommandBuffers = &compute.commandBuffer;
|
|
||||||
computeSubmitInfo.waitSemaphoreCount = 1;
|
|
||||||
computeSubmitInfo.pWaitSemaphores = &graphics.semaphore;
|
|
||||||
computeSubmitInfo.pWaitDstStageMask = &waitStageMask;
|
|
||||||
computeSubmitInfo.signalSemaphoreCount = 1;
|
|
||||||
computeSubmitInfo.pSignalSemaphores = &compute.semaphore;
|
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(compute.queue, 1, &computeSubmitInfo, VK_NULL_HANDLE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepare()
|
void prepare()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue