Fix submit wait stages, support same family for graphics & compute

This commit is contained in:
Brad Davis 2020-01-03 09:25:24 -08:00
parent 055d90ea30
commit 19f80fe423

View file

@ -32,6 +32,7 @@ public:
uint32_t readSet = 0;
uint32_t indexCount;
bool simulateWind = false;
bool specializedComputeQueue = false;
vks::Texture2D textureCloth;
@ -157,6 +158,7 @@ public:
void addGraphicsToComputeBarriers(VkCommandBuffer commandBuffer)
{
if (specializedComputeQueue) {
VkBufferMemoryBarrier bufferBarrier = vks::initializers::bufferMemoryBarrier();
bufferBarrier.srcAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
bufferBarrier.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
@ -177,6 +179,7 @@ public:
static_cast<uint32_t>(bufferBarriers.size()), bufferBarriers.data(),
0, nullptr);
}
}
void addComputeToComputeBarriers(VkCommandBuffer commandBuffer)
{
@ -203,6 +206,7 @@ public:
void addComputeToGraphicsBarriers(VkCommandBuffer commandBuffer)
{
if (specializedComputeQueue) {
VkBufferMemoryBarrier bufferBarrier = vks::initializers::bufferMemoryBarrier();
bufferBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
bufferBarrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
@ -223,6 +227,7 @@ public:
static_cast<uint32_t>(bufferBarriers.size()), bufferBarriers.data(),
0, nullptr);
}
}
void buildCommandBuffers()
{
@ -740,7 +745,7 @@ public:
static bool firstDraw = true;
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
// FIXME find a better way to do this (without using fences, which is much slower)
VkPipelineStageFlags computeWaitDstStageMask = VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
VkPipelineStageFlags computeWaitDstStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
if (!firstDraw) {
computeSubmitInfo.waitSemaphoreCount = 1;
computeSubmitInfo.pWaitSemaphores = &compute.semaphores.ready;
@ -759,7 +764,7 @@ public:
VulkanExampleBase::prepareFrame();
VkPipelineStageFlags waitDstStageMask[2] = {
submitPipelineStages, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
submitPipelineStages, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
};
VkSemaphore waitSemaphores[2] = {
semaphores.presentComplete, compute.semaphores.complete
@ -783,6 +788,12 @@ public:
void prepare()
{
VulkanExampleBase::prepare();
// Make sure the code works properly both with different queues families for graphics and compute and the same queue family
#ifdef DEBUG_FORCE_SHARED_GRAPHICS_COMPUTE_QUEUE
vulkanDevice->queueFamilyIndices.compute = vulkanDevice->queueFamilyIndices.graphics;
#endif
// Check whether the compute queue family is distinct from the graphics queue family
specializedComputeQueue = vulkanDevice->queueFamilyIndices.graphics != vulkanDevice->queueFamilyIndices.compute;
loadAssets();
prepareStorageBuffers();
prepareUniformBuffers();