Commit aafcb504 by Courtney Goeltzenleuchter Committed by Commit Bot

Vulkan: Add ensureSubmission to queueSubmitOneOff

Some callers of queueSubmitOneOff require that the command being queued to have been sent to the GPU. The new ensureSubmission parameter indicates that behavior and when running with threaded worker will wait for the worker queue to empty before returning. Bug: b/170312581 Change-Id: Ib620fb37f4b9b4431451ccbd10807c0dff1842af Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2579041Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
parent b1f094eb
...@@ -432,7 +432,7 @@ angle::Result CommandProcessor::processTask(CommandProcessorTask *task) ...@@ -432,7 +432,7 @@ angle::Result CommandProcessor::processTask(CommandProcessorTask *task)
ANGLE_TRY(mCommandQueue.queueSubmitOneOff( ANGLE_TRY(mCommandQueue.queueSubmitOneOff(
this, task->getPriority(), task->getOneOffCommandBufferVk(), task->getOneOffFence(), this, task->getPriority(), task->getOneOffCommandBufferVk(), task->getOneOffFence(),
task->getQueueSerial())); SubmitPolicy::EnsureSubmitted, task->getQueueSerial()));
ANGLE_TRY(mCommandQueue.checkCompletedCommands(this)); ANGLE_TRY(mCommandQueue.checkCompletedCommands(this));
break; break;
} }
...@@ -652,6 +652,7 @@ angle::Result CommandProcessor::queueSubmitOneOff(Context *context, ...@@ -652,6 +652,7 @@ angle::Result CommandProcessor::queueSubmitOneOff(Context *context,
egl::ContextPriority contextPriority, egl::ContextPriority contextPriority,
VkCommandBuffer commandBufferHandle, VkCommandBuffer commandBufferHandle,
const Fence *fence, const Fence *fence,
SubmitPolicy submitPolicy,
Serial submitQueueSerial) Serial submitQueueSerial)
{ {
ANGLE_TRY(checkAndPopPendingError(context)); ANGLE_TRY(checkAndPopPendingError(context));
...@@ -659,6 +660,12 @@ angle::Result CommandProcessor::queueSubmitOneOff(Context *context, ...@@ -659,6 +660,12 @@ angle::Result CommandProcessor::queueSubmitOneOff(Context *context,
CommandProcessorTask task; CommandProcessorTask task;
task.initOneOffQueueSubmit(commandBufferHandle, contextPriority, fence, submitQueueSerial); task.initOneOffQueueSubmit(commandBufferHandle, contextPriority, fence, submitQueueSerial);
queueCommand(std::move(task)); queueCommand(std::move(task));
if (submitPolicy == SubmitPolicy::EnsureSubmitted)
{
// Caller has synchronization requirement to have work in GPU pipe when returning from this
// function.
ANGLE_TRY(waitForWorkComplete(context));
}
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1091,6 +1098,7 @@ angle::Result CommandQueue::queueSubmitOneOff(Context *context, ...@@ -1091,6 +1098,7 @@ angle::Result CommandQueue::queueSubmitOneOff(Context *context,
egl::ContextPriority contextPriority, egl::ContextPriority contextPriority,
VkCommandBuffer commandBufferHandle, VkCommandBuffer commandBufferHandle,
const Fence *fence, const Fence *fence,
SubmitPolicy submitPolicy,
Serial submitQueueSerial) Serial submitQueueSerial)
{ {
VkSubmitInfo submitInfo = {}; VkSubmitInfo submitInfo = {};
......
...@@ -27,6 +27,12 @@ class CommandProcessor; ...@@ -27,6 +27,12 @@ class CommandProcessor;
namespace vk namespace vk
{ {
enum class SubmitPolicy
{
AllowDeferred,
EnsureSubmitted,
};
class FenceRecycler class FenceRecycler
{ {
public: public:
...@@ -201,6 +207,7 @@ class CommandQueueInterface : angle::NonCopyable ...@@ -201,6 +207,7 @@ class CommandQueueInterface : angle::NonCopyable
egl::ContextPriority contextPriority, egl::ContextPriority contextPriority,
VkCommandBuffer commandBufferHandle, VkCommandBuffer commandBufferHandle,
const Fence *fence, const Fence *fence,
SubmitPolicy submitPolicy,
Serial submitQueueSerial) = 0; Serial submitQueueSerial) = 0;
virtual VkResult queuePresent(egl::ContextPriority contextPriority, virtual VkResult queuePresent(egl::ContextPriority contextPriority,
const VkPresentInfoKHR &presentInfo) = 0; const VkPresentInfoKHR &presentInfo) = 0;
...@@ -255,6 +262,7 @@ class CommandQueue final : public CommandQueueInterface ...@@ -255,6 +262,7 @@ class CommandQueue final : public CommandQueueInterface
egl::ContextPriority contextPriority, egl::ContextPriority contextPriority,
VkCommandBuffer commandBufferHandle, VkCommandBuffer commandBufferHandle,
const Fence *fence, const Fence *fence,
SubmitPolicy submitPolicy,
Serial submitQueueSerial) override; Serial submitQueueSerial) override;
VkResult queuePresent(egl::ContextPriority contextPriority, VkResult queuePresent(egl::ContextPriority contextPriority,
...@@ -363,6 +371,7 @@ class CommandProcessor : public Context, public CommandQueueInterface ...@@ -363,6 +371,7 @@ class CommandProcessor : public Context, public CommandQueueInterface
egl::ContextPriority contextPriority, egl::ContextPriority contextPriority,
VkCommandBuffer commandBufferHandle, VkCommandBuffer commandBufferHandle,
const Fence *fence, const Fence *fence,
SubmitPolicy submitPolicy,
Serial submitQueueSerial) override; Serial submitQueueSerial) override;
VkResult queuePresent(egl::ContextPriority contextPriority, VkResult queuePresent(egl::ContextPriority contextPriority,
const VkPresentInfoKHR &presentInfo) override; const VkPresentInfoKHR &presentInfo) override;
......
...@@ -1695,8 +1695,11 @@ angle::Result ContextVk::synchronizeCpuGpuTime() ...@@ -1695,8 +1695,11 @@ angle::Result ContextVk::synchronizeCpuGpuTime()
ANGLE_VK_TRY(this, commandBuffer.end()); ANGLE_VK_TRY(this, commandBuffer.end());
Serial throwAwaySerial; Serial throwAwaySerial;
// vkEvent's are externally synchronized, therefore need work to be submitted before calling
// vkGetEventStatus
ANGLE_TRY(mRenderer->queueSubmitOneOff(this, std::move(commandBuffer), mContextPriority, ANGLE_TRY(mRenderer->queueSubmitOneOff(this, std::move(commandBuffer), mContextPriority,
nullptr, &throwAwaySerial)); nullptr, vk::SubmitPolicy::EnsureSubmitted,
&throwAwaySerial));
scratchResourceUseList.releaseResourceUsesAndUpdateSerials(throwAwaySerial); scratchResourceUseList.releaseResourceUsesAndUpdateSerials(throwAwaySerial);
// Wait for GPU to be ready. This is a short busy wait. // Wait for GPU to be ready. This is a short busy wait.
...@@ -4375,7 +4378,8 @@ angle::Result ContextVk::getTimestamp(uint64_t *timestampOut) ...@@ -4375,7 +4378,8 @@ angle::Result ContextVk::getTimestamp(uint64_t *timestampOut)
Serial throwAwaySerial; Serial throwAwaySerial;
ANGLE_TRY(mRenderer->queueSubmitOneOff(this, std::move(commandBuffer), mContextPriority, ANGLE_TRY(mRenderer->queueSubmitOneOff(this, std::move(commandBuffer), mContextPriority,
&fence.get(), &throwAwaySerial)); &fence.get(), vk::SubmitPolicy::EnsureSubmitted,
&throwAwaySerial));
// Wait for the submission to finish. Given no semaphores, there is hope that it would execute // Wait for the submission to finish. Given no semaphores, there is hope that it would execute
// in parallel with what's already running on the GPU. // in parallel with what's already running on the GPU.
......
...@@ -2293,6 +2293,7 @@ angle::Result RendererVk::queueSubmitOneOff(vk::Context *context, ...@@ -2293,6 +2293,7 @@ angle::Result RendererVk::queueSubmitOneOff(vk::Context *context,
vk::PrimaryCommandBuffer &&primary, vk::PrimaryCommandBuffer &&primary,
egl::ContextPriority priority, egl::ContextPriority priority,
const vk::Fence *fence, const vk::Fence *fence,
vk::SubmitPolicy submitPolicy,
Serial *serialOut) Serial *serialOut)
{ {
ANGLE_TRACE_EVENT0("gpu.angle", "RendererVk::queueSubmitOneOff"); ANGLE_TRACE_EVENT0("gpu.angle", "RendererVk::queueSubmitOneOff");
...@@ -2304,13 +2305,13 @@ angle::Result RendererVk::queueSubmitOneOff(vk::Context *context, ...@@ -2304,13 +2305,13 @@ angle::Result RendererVk::queueSubmitOneOff(vk::Context *context,
{ {
submitQueueSerial = mCommandProcessor.reserveSubmitSerial(); submitQueueSerial = mCommandProcessor.reserveSubmitSerial();
ANGLE_TRY(mCommandProcessor.queueSubmitOneOff(context, priority, primary.getHandle(), fence, ANGLE_TRY(mCommandProcessor.queueSubmitOneOff(context, priority, primary.getHandle(), fence,
submitQueueSerial)); submitPolicy, submitQueueSerial));
} }
else else
{ {
submitQueueSerial = mCommandQueue.reserveSubmitSerial(); submitQueueSerial = mCommandQueue.reserveSubmitSerial();
ANGLE_TRY(mCommandQueue.queueSubmitOneOff(context, priority, primary.getHandle(), fence, ANGLE_TRY(mCommandQueue.queueSubmitOneOff(context, priority, primary.getHandle(), fence,
submitQueueSerial)); submitPolicy, submitQueueSerial));
} }
*serialOut = submitQueueSerial; *serialOut = submitQueueSerial;
......
...@@ -209,6 +209,7 @@ class RendererVk : angle::NonCopyable ...@@ -209,6 +209,7 @@ class RendererVk : angle::NonCopyable
vk::PrimaryCommandBuffer &&primary, vk::PrimaryCommandBuffer &&primary,
egl::ContextPriority priority, egl::ContextPriority priority,
const vk::Fence *fence, const vk::Fence *fence,
vk::SubmitPolicy submitPolicy,
Serial *serialOut); Serial *serialOut);
template <typename... ArgsT> template <typename... ArgsT>
......
...@@ -205,8 +205,13 @@ angle::Result SyncHelperNativeFence::initializeWithFd(ContextVk *contextVk, int ...@@ -205,8 +205,13 @@ angle::Result SyncHelperNativeFence::initializeWithFd(ContextVk *contextVk, int
retain(&contextVk->getResourceUseList()); retain(&contextVk->getResourceUseList());
Serial serialOut; Serial serialOut;
// exportFd is exporting VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR type handle which
// obeys copy semantics. This means that the fence must already be signaled or the work to
// signal in the graphics pipeline at the time we export the fd. Thus we need to
// ensureSubmission here.
ANGLE_TRY(renderer->queueSubmitOneOff(contextVk, vk::PrimaryCommandBuffer(), ANGLE_TRY(renderer->queueSubmitOneOff(contextVk, vk::PrimaryCommandBuffer(),
contextVk->getPriority(), &fence.get(), &serialOut)); contextVk->getPriority(), &fence.get(),
vk::SubmitPolicy::EnsureSubmitted, &serialOut));
VkFenceGetFdInfoKHR fenceGetFdInfo = {}; VkFenceGetFdInfoKHR fenceGetFdInfo = {};
fenceGetFdInfo.sType = VK_STRUCTURE_TYPE_FENCE_GET_FD_INFO_KHR; fenceGetFdInfo.sType = VK_STRUCTURE_TYPE_FENCE_GET_FD_INFO_KHR;
...@@ -219,7 +224,7 @@ angle::Result SyncHelperNativeFence::initializeWithFd(ContextVk *contextVk, int ...@@ -219,7 +224,7 @@ angle::Result SyncHelperNativeFence::initializeWithFd(ContextVk *contextVk, int
// descriptor from the application to the Vulkan implementation. The application must not // descriptor from the application to the Vulkan implementation. The application must not
// perform any operations on the file descriptor after a successful import. // perform any operations on the file descriptor after a successful import.
// Make a dup of importFenceFd before tranfering ownership to created fence. // Make a dup of importFenceFd before transferring ownership to created fence.
mNativeFenceFd = dup(importFenceFd); mNativeFenceFd = dup(importFenceFd);
// Import FD - after creating fence. // Import FD - after creating fence.
......
...@@ -3226,7 +3226,8 @@ angle::Result BufferHelper::initializeNonZeroMemory(Context *context, VkDeviceSi ...@@ -3226,7 +3226,8 @@ angle::Result BufferHelper::initializeNonZeroMemory(Context *context, VkDeviceSi
Serial serial; Serial serial;
ANGLE_TRY(renderer->queueSubmitOneOff(context, std::move(commandBuffer), ANGLE_TRY(renderer->queueSubmitOneOff(context, std::move(commandBuffer),
egl::ContextPriority::Medium, nullptr, &serial)); egl::ContextPriority::Medium, nullptr,
vk::SubmitPolicy::AllowDeferred, &serial));
stagingBuffer.collectGarbage(renderer, serial); stagingBuffer.collectGarbage(renderer, serial);
mUse.updateSerialOneOff(serial); mUse.updateSerialOneOff(serial);
...@@ -3764,7 +3765,8 @@ angle::Result ImageHelper::initializeNonZeroMemory(Context *context, VkDeviceSiz ...@@ -3764,7 +3765,8 @@ angle::Result ImageHelper::initializeNonZeroMemory(Context *context, VkDeviceSiz
Serial serial; Serial serial;
ANGLE_TRY(renderer->queueSubmitOneOff(context, std::move(commandBuffer), ANGLE_TRY(renderer->queueSubmitOneOff(context, std::move(commandBuffer),
egl::ContextPriority::Medium, nullptr, &serial)); egl::ContextPriority::Medium, nullptr,
vk::SubmitPolicy::AllowDeferred, &serial));
if (isCompressedFormat) if (isCompressedFormat)
{ {
......
...@@ -479,14 +479,4 @@ TEST_P(EGLSyncTest, AndroidNativeFence_withFences) ...@@ -479,14 +479,4 @@ TEST_P(EGLSyncTest, AndroidNativeFence_withFences)
EXPECT_EGL_TRUE(eglDestroySyncKHR(display, syncWithGeneratedFD)); EXPECT_EGL_TRUE(eglDestroySyncKHR(display, syncWithGeneratedFD));
} }
ANGLE_INSTANTIATE_TEST(EGLSyncTest, ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(EGLSyncTest);
ES2_D3D9(),
ES2_D3D11(),
ES2_METAL(),
ES3_D3D11(),
ES2_OPENGL(),
ES3_OPENGL(),
ES2_OPENGLES(),
ES3_OPENGLES(),
ES2_VULKAN(),
ES3_VULKAN());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment