Commit 84fce18c by Jamie Madill Committed by Commit Bot

Vulkan: Give CommandQueue an abstract interface.

This gives CommandQueue and CommandProcessor the exact same interface. This also moves the worker thread to be owned by CommandProcessor. Bug: b/172704839 Change-Id: Ife439bcf52d923e01a6a2166e0caaffce14fd086 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2537235 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 59bddcfb
...@@ -527,9 +527,6 @@ void ContextVk::onDestroy(const gl::Context *context) ...@@ -527,9 +527,6 @@ void ContextVk::onDestroy(const gl::Context *context)
mShaderLibrary.destroy(device); mShaderLibrary.destroy(device);
mGpuEventQueryPool.destroy(device); mGpuEventQueryPool.destroy(device);
mCommandPool.destroy(device); mCommandPool.destroy(device);
// This will clean up any outstanding buffer allocations
(void)mRenderer->clearAllGarbage(this);
} }
angle::Result ContextVk::getIncompleteTexture(const gl::Context *context, angle::Result ContextVk::getIncompleteTexture(const gl::Context *context,
...@@ -1842,13 +1839,12 @@ void ContextVk::flushGpuEvents(double nextSyncGpuTimestampS, double nextSyncCpuT ...@@ -1842,13 +1839,12 @@ void ContextVk::flushGpuEvents(double nextSyncGpuTimestampS, double nextSyncCpuT
void ContextVk::clearAllGarbage() void ContextVk::clearAllGarbage()
{ {
ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::finishAllWork"); ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::clearAllGarbage");
for (vk::GarbageObject &garbage : mCurrentGarbage) for (vk::GarbageObject &garbage : mCurrentGarbage)
{ {
garbage.destroy(mRenderer); garbage.destroy(mRenderer);
} }
mCurrentGarbage.clear(); mCurrentGarbage.clear();
mRenderer->clearAllGarbage(this);
} }
void ContextVk::handleDeviceLost() void ContextVk::handleDeviceLost()
...@@ -3035,7 +3031,7 @@ angle::Result ContextVk::onUnMakeCurrent(const gl::Context *context) ...@@ -3035,7 +3031,7 @@ angle::Result ContextVk::onUnMakeCurrent(const gl::Context *context)
if (mRenderer->getFeatures().asyncCommandQueue.enabled) if (mRenderer->getFeatures().asyncCommandQueue.enabled)
{ {
ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::onUnMakeCurrent"); ANGLE_TRACE_EVENT0("gpu.angle", "ContextVk::onUnMakeCurrent");
mRenderer->finishAllWork(this); ANGLE_TRY(mRenderer->finishAllWork(this));
} }
mCurrentWindowSurface = nullptr; mCurrentWindowSurface = nullptr;
return angle::Result::Continue; return angle::Result::Continue;
......
...@@ -260,10 +260,10 @@ void DisplayVk::handleError(VkResult result, ...@@ -260,10 +260,10 @@ void DisplayVk::handleError(VkResult result,
{ {
ASSERT(result != VK_SUCCESS); ASSERT(result != VK_SUCCESS);
mSavedError.mErrorCode = result; mSavedError.errorCode = result;
mSavedError.mFile = file; mSavedError.file = file;
mSavedError.mFunction = function; mSavedError.function = function;
mSavedError.mLine = line; mSavedError.line = line;
if (result == VK_ERROR_DEVICE_LOST) if (result == VK_ERROR_DEVICE_LOST)
{ {
...@@ -277,10 +277,9 @@ void DisplayVk::handleError(VkResult result, ...@@ -277,10 +277,9 @@ void DisplayVk::handleError(VkResult result,
egl::Error DisplayVk::getEGLError(EGLint errorCode) egl::Error DisplayVk::getEGLError(EGLint errorCode)
{ {
std::stringstream errorStream; std::stringstream errorStream;
errorStream << "Internal Vulkan error (" << mSavedError.mErrorCode errorStream << "Internal Vulkan error (" << mSavedError.errorCode
<< "): " << VulkanResultString(mSavedError.mErrorCode) << ", in " << "): " << VulkanResultString(mSavedError.errorCode) << ", in " << mSavedError.file
<< mSavedError.mFile << ", " << mSavedError.mFunction << ":" << mSavedError.mLine << ", " << mSavedError.function << ":" << mSavedError.line << ".";
<< ".";
std::string errorString = errorStream.str(); std::string errorString = errorStream.str();
return egl::Error(errorCode, 0, std::move(errorString)); return egl::Error(errorCode, 0, std::move(errorString));
......
...@@ -190,7 +190,7 @@ angle::Result QueryVk::getResult(const gl::Context *context, bool wait) ...@@ -190,7 +190,7 @@ angle::Result QueryVk::getResult(const gl::Context *context, bool wait)
if (renderer->getFeatures().asyncCommandQueue.enabled) if (renderer->getFeatures().asyncCommandQueue.enabled)
{ {
// TODO: https://issuetracker.google.com/170312581 - For now just stalling here // TODO: https://issuetracker.google.com/170312581 - For now just stalling here
renderer->waitForCommandProcessorIdle(contextVk); ANGLE_TRY(renderer->waitForCommandProcessorIdle(contextVk));
} }
ASSERT(!mQueryHelperTimeElapsedBegin.hasPendingWork(contextVk)); ASSERT(!mQueryHelperTimeElapsedBegin.hasPendingWork(contextVk));
......
...@@ -281,21 +281,20 @@ class RendererVk : angle::NonCopyable ...@@ -281,21 +281,20 @@ class RendererVk : angle::NonCopyable
SamplerYcbcrConversionCache &getYuvConversionCache() { return mYuvConversionCache; } SamplerYcbcrConversionCache &getYuvConversionCache() { return mYuvConversionCache; }
vk::ActiveHandleCounter &getActiveHandleCounts() { return mActiveHandleCounts; } vk::ActiveHandleCounter &getActiveHandleCounts() { return mActiveHandleCounts; }
// Queue commands to worker thread for processing // TODO(jmadill): Remove. b/172704839
void queueCommand(vk::Context *context, vk::CommandProcessorTask *command) angle::Result waitForCommandProcessorIdle(vk::Context *context)
{ {
mCommandProcessor.queueCommand(context, command); ASSERT(getFeatures().asyncCommandQueue.enabled);
return mCommandProcessor.waitForWorkComplete(context);
} }
bool hasPendingError() const { return mCommandProcessor.hasPendingError(); }
vk::Error getAndClearPendingError() { return mCommandProcessor.getAndClearPendingError(); } // TODO(jmadill): Remove. b/172704839
void waitForCommandProcessorIdle(vk::Context *context) angle::Result finishAllWork(vk::Context *context)
{ {
ASSERT(getFeatures().asyncCommandQueue.enabled); ASSERT(getFeatures().asyncCommandQueue.enabled);
mCommandProcessor.waitForWorkComplete(context); return mCommandProcessor.finishAllWork(context);
} }
void finishAllWork(vk::Context *context) { mCommandProcessor.finishAllWork(context); }
bool getEnableValidationLayers() const { return mEnableValidationLayers; } bool getEnableValidationLayers() const { return mEnableValidationLayers; }
vk::ResourceSerialFactory &getResourceSerialFactory() { return mResourceSerialFactory; } vk::ResourceSerialFactory &getResourceSerialFactory() { return mResourceSerialFactory; }
...@@ -315,7 +314,6 @@ class RendererVk : angle::NonCopyable ...@@ -315,7 +314,6 @@ class RendererVk : angle::NonCopyable
vk::GarbageList &&currentGarbage, vk::GarbageList &&currentGarbage,
vk::CommandPool *commandPool); vk::CommandPool *commandPool);
void clearAllGarbage(vk::Context *context);
void handleDeviceLost(); void handleDeviceLost();
angle::Result finishToSerial(vk::Context *context, Serial serial); angle::Result finishToSerial(vk::Context *context, Serial serial);
angle::Result waitForSerialWithUserTimeout(vk::Context *context, angle::Result waitForSerialWithUserTimeout(vk::Context *context,
...@@ -357,12 +355,6 @@ class RendererVk : angle::NonCopyable ...@@ -357,12 +355,6 @@ class RendererVk : angle::NonCopyable
template <VkFormatFeatureFlags VkFormatProperties::*features> template <VkFormatFeatureFlags VkFormatProperties::*features>
bool hasFormatFeatureBits(VkFormat format, const VkFormatFeatureFlags featureBits) const; bool hasFormatFeatureBits(VkFormat format, const VkFormatFeatureFlags featureBits) const;
// Sync any errors from the command processor
void commandProcessorSyncErrors(vk::Context *context);
// Sync any error from worker thread and queue up next command for processing
void commandProcessorSyncErrorsAndQueueCommand(vk::Context *context,
vk::CommandProcessorTask *command);
egl::Display *mDisplay; egl::Display *mDisplay;
mutable bool mCapsInitialized; mutable bool mCapsInitialized;
...@@ -456,9 +448,8 @@ class RendererVk : angle::NonCopyable ...@@ -456,9 +448,8 @@ class RendererVk : angle::NonCopyable
std::mutex mCommandBufferHelperFreeListMutex; std::mutex mCommandBufferHelperFreeListMutex;
std::vector<vk::CommandBufferHelper *> mCommandBufferHelperFreeList; std::vector<vk::CommandBufferHelper *> mCommandBufferHelperFreeList;
// Command Processor Thread // Async Command Queue
vk::CommandProcessor mCommandProcessor; vk::CommandProcessor mCommandProcessor;
std::thread mCommandProcessorThread;
// mNextSubmitFence is the fence that's going to be signaled at the next submission. This is // mNextSubmitFence is the fence that's going to be signaled at the next submission. This is
// used to support SyncVk objects, which may outlive the context (as EGLSync objects). // used to support SyncVk objects, which may outlive the context (as EGLSync objects).
vk::Shared<vk::Fence> mNextSubmitFence; vk::Shared<vk::Fence> mNextSubmitFence;
......
...@@ -37,7 +37,7 @@ void SyncHelper::releaseToRenderer(RendererVk *renderer) ...@@ -37,7 +37,7 @@ void SyncHelper::releaseToRenderer(RendererVk *renderer)
if (renderer->getFeatures().asyncCommandQueue.enabled) if (renderer->getFeatures().asyncCommandQueue.enabled)
{ {
ANGLE_TRACE_EVENT0("gpu.angle", "SyncHelper::releaseToRenderer"); ANGLE_TRACE_EVENT0("gpu.angle", "SyncHelper::releaseToRenderer");
renderer->waitForCommandProcessorIdle(nullptr); (void)renderer->waitForCommandProcessorIdle(nullptr);
} }
} }
...@@ -272,7 +272,7 @@ angle::Result SyncHelperNativeFence::clientWait(Context *context, ...@@ -272,7 +272,7 @@ angle::Result SyncHelperNativeFence::clientWait(Context *context,
if (contextVk->getRenderer()->getFeatures().asyncCommandQueue.enabled) if (contextVk->getRenderer()->getFeatures().asyncCommandQueue.enabled)
{ {
ANGLE_TRACE_EVENT0("gpu.angle", "SyncHelperNativeFence::clientWait"); ANGLE_TRACE_EVENT0("gpu.angle", "SyncHelperNativeFence::clientWait");
contextVk->getRenderer()->waitForCommandProcessorIdle(contextVk); ANGLE_TRY(contextVk->getRenderer()->waitForCommandProcessorIdle(contextVk));
} }
// Wait for mFenceWithFd to be signaled. // Wait for mFenceWithFd to be signaled.
......
...@@ -156,10 +156,10 @@ void AddToPNextChain(VulkanStruct1 *chainStart, VulkanStruct2 *ptr) ...@@ -156,10 +156,10 @@ void AddToPNextChain(VulkanStruct1 *chainStart, VulkanStruct2 *ptr)
struct Error struct Error
{ {
VkResult mErrorCode; VkResult errorCode;
const char *mFile; const char *file;
const char *mFunction; const char *function;
unsigned int mLine; uint32_t line;
}; };
// Abstracts error handling. Implemented by both ContextVk for GL and DisplayVk for EGL errors. // Abstracts error handling. Implemented by both ContextVk for GL and DisplayVk for EGL errors.
......
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