Vulkan: Pass signal semaphore by value to async thread
Otherwise the signal semaphore is pointing to whatever was passed in
from the main thread. Currently, this is ok because:
- For external semaphores, ensureNoPendingWork is called
- For surfaces, there's a fixed buffer of semaphores
However, an upcoming change passes a semaphore specified on the stack,
and the thread should not be referencing it.
Bug: angleproject:7847
Change-Id: I9a823214bde59b9d7ff23313694c1749a76e6b8e
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4060453
Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Charlie Lao <cclao@google.com>
Reviewed-by: Yuxin Hu <yuxinhu@google.com>
diff --git a/src/libANGLE/renderer/vulkan/CommandProcessor.cpp b/src/libANGLE/renderer/vulkan/CommandProcessor.cpp
index 5e2d53a..81cc0c5 100644
--- a/src/libANGLE/renderer/vulkan/CommandProcessor.cpp
+++ b/src/libANGLE/renderer/vulkan/CommandProcessor.cpp
@@ -26,7 +26,7 @@
const PrimaryCommandBuffer &commandBuffer,
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *signalSemaphore)
+ const VkSemaphore &signalSemaphore)
{
// Verify that the submitInfo has been zero'd out.
ASSERT(submitInfo->signalSemaphoreCount == 0);
@@ -38,10 +38,10 @@
submitInfo->pWaitSemaphores = waitSemaphores.empty() ? nullptr : waitSemaphores.data();
submitInfo->pWaitDstStageMask = waitSemaphoreStageMasks.data();
- if (signalSemaphore)
+ if (signalSemaphore != VK_NULL_HANDLE)
{
submitInfo->signalSemaphoreCount = 1;
- submitInfo->pSignalSemaphores = signalSemaphore->ptr();
+ submitInfo->pSignalSemaphores = &signalSemaphore;
}
}
@@ -153,7 +153,7 @@
mOutsideRenderPassCommandBuffer = nullptr;
mRenderPassCommandBuffer = nullptr;
mRenderPass = nullptr;
- mSemaphore = nullptr;
+ mSemaphore = VK_NULL_HANDLE;
mCommandPools = nullptr;
mOneOffWaitSemaphore = nullptr;
mOneOffWaitSemaphoreStageMask = 0;
@@ -277,7 +277,7 @@
void CommandProcessorTask::initFlushAndQueueSubmit(
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *semaphore,
+ const VkSemaphore semaphore,
bool hasProtectedContent,
egl::ContextPriority priority,
SecondaryCommandPools *commandPools,
@@ -744,7 +744,7 @@
egl::ContextPriority priority,
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *signalSemaphore,
+ const VkSemaphore signalSemaphore,
GarbageList &¤tGarbage,
SecondaryCommandBufferList &&commandBuffersToReset,
SecondaryCommandPools *commandPools,
@@ -1166,7 +1166,7 @@
egl::ContextPriority priority,
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *signalSemaphore,
+ const VkSemaphore signalSemaphore,
GarbageList &¤tGarbage,
SecondaryCommandBufferList &&commandBuffersToReset,
SecondaryCommandPools *commandPools,
@@ -1188,7 +1188,7 @@
// Don't make a submission if there is nothing to submit.
PrimaryCommandBuffer &commandBuffer = getCommandBuffer(hasProtectedContent);
const bool hasAnyPendingCommands = commandBuffer.valid();
- if (hasAnyPendingCommands || signalSemaphore != nullptr || !waitSemaphores.empty())
+ if (hasAnyPendingCommands || signalSemaphore != VK_NULL_HANDLE || !waitSemaphores.empty())
{
if (commandBuffer.valid())
{
diff --git a/src/libANGLE/renderer/vulkan/CommandProcessor.h b/src/libANGLE/renderer/vulkan/CommandProcessor.h
index b65d914..d785721 100644
--- a/src/libANGLE/renderer/vulkan/CommandProcessor.h
+++ b/src/libANGLE/renderer/vulkan/CommandProcessor.h
@@ -101,7 +101,7 @@
void initFlushAndQueueSubmit(const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *semaphore,
+ const VkSemaphore semaphore,
bool hasProtectedContent,
egl::ContextPriority priority,
SecondaryCommandPools *commandPools,
@@ -132,7 +132,7 @@
{
return mWaitSemaphoreStageMasks;
}
- const Semaphore *getSemaphore() { return mSemaphore; }
+ VkSemaphore getSemaphore() { return mSemaphore; }
GarbageList &getGarbage() { return mGarbage; }
SecondaryCommandBufferList &&getCommandBuffersToReset()
{
@@ -169,7 +169,7 @@
// Flush data
std::vector<VkSemaphore> mWaitSemaphores;
std::vector<VkPipelineStageFlags> mWaitSemaphoreStageMasks;
- const Semaphore *mSemaphore;
+ VkSemaphore mSemaphore;
SecondaryCommandPools *mCommandPools;
GarbageList mGarbage;
SecondaryCommandBufferList mCommandBuffersToReset;
@@ -306,7 +306,7 @@
egl::ContextPriority priority,
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *signalSemaphore,
+ const VkSemaphore signalSemaphore,
GarbageList &¤tGarbage,
SecondaryCommandBufferList &&commandBuffersToReset,
SecondaryCommandPools *commandPools,
@@ -377,7 +377,7 @@
egl::ContextPriority priority,
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *signalSemaphore,
+ const VkSemaphore signalSemaphore,
GarbageList &¤tGarbage,
SecondaryCommandBufferList &&commandBuffersToReset,
SecondaryCommandPools *commandPools,
@@ -544,7 +544,7 @@
egl::ContextPriority priority,
const std::vector<VkSemaphore> &waitSemaphores,
const std::vector<VkPipelineStageFlags> &waitSemaphoreStageMasks,
- const Semaphore *signalSemaphore,
+ const VkSemaphore signalSemaphore,
GarbageList &¤tGarbage,
SecondaryCommandBufferList &&commandBuffersToReset,
SecondaryCommandPools *commandPools,
diff --git a/src/libANGLE/renderer/vulkan/RendererVk.cpp b/src/libANGLE/renderer/vulkan/RendererVk.cpp
index 6544cf6..f4b44a7 100644
--- a/src/libANGLE/renderer/vulkan/RendererVk.cpp
+++ b/src/libANGLE/renderer/vulkan/RendererVk.cpp
@@ -4807,13 +4807,16 @@
std::move(mRenderPassCommandBufferRecycler.releaseCommandBuffersToReset()),
};
+ const VkSemaphore signalVkSemaphore =
+ signalSemaphore ? signalSemaphore->getHandle() : VK_NULL_HANDLE;
+
if (isAsyncCommandQueueEnabled())
{
*submitSerialOut = mCommandProcessor.reserveSubmitSerial();
ANGLE_TRY(mCommandProcessor.submitCommands(
context, hasProtectedContent, contextPriority, waitSemaphores, waitSemaphoreStageMasks,
- signalSemaphore, std::move(currentGarbage), std::move(commandBuffersToReset),
+ signalVkSemaphore, std::move(currentGarbage), std::move(commandBuffersToReset),
commandPools, *submitSerialOut));
}
else
@@ -4822,7 +4825,7 @@
ANGLE_TRY(mCommandQueue.submitCommands(
context, hasProtectedContent, contextPriority, waitSemaphores, waitSemaphoreStageMasks,
- signalSemaphore, std::move(currentGarbage), std::move(commandBuffersToReset),
+ signalVkSemaphore, std::move(currentGarbage), std::move(commandBuffersToReset),
commandPools, *submitSerialOut));
}