Fix race condition where 'visible' result is checked before job finishes

This commit is contained in:
baldurk 2016-04-24 13:14:48 +02:00
parent 9ac4383c46
commit 34292dd547

View file

@ -432,13 +432,22 @@ public:
updateSecondaryCommandBuffer(inheritanceInfo); updateSecondaryCommandBuffer(inheritanceInfo);
commandBuffers.push_back(secondaryCommandBuffer); commandBuffers.push_back(secondaryCommandBuffer);
// Add a job to the thread's queue for each object to be rendered
for (uint32_t t = 0; t < numThreads; t++) for (uint32_t t = 0; t < numThreads; t++)
{ {
// Add a job to the thread's queue for each object to be rendered
for (uint32_t i = 0; i < numObjectsPerThread; i++) for (uint32_t i = 0; i < numObjectsPerThread; i++)
{ {
threadPool.threads[t]->addJob([=] { threadRenderCode(t, i, inheritanceInfo); }); threadPool.threads[t]->addJob([=] { threadRenderCode(t, i, inheritanceInfo); });
// Only submit if object is within the current view frustum }
}
threadPool.wait();
// Only submit if object is within the current view frustum
for (uint32_t t = 0; t < numThreads; t++)
{
for (uint32_t i = 0; i < numObjectsPerThread; i++)
{
if (threadData[t].objectData[i].visible) if (threadData[t].objectData[i].visible)
{ {
commandBuffers.push_back(threadData[t].commandBuffer[i]); commandBuffers.push_back(threadData[t].commandBuffer[i]);
@ -446,8 +455,6 @@ public:
} }
} }
threadPool.wait();
// Execute render commands from the secondary command buffer // Execute render commands from the secondary command buffer
vkCmdExecuteCommands(primaryCommandBuffer, commandBuffers.size(), commandBuffers.data()); vkCmdExecuteCommands(primaryCommandBuffer, commandBuffers.size(), commandBuffers.data());