1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #13275 from wzw-intel:thread_safe

This commit is contained in:
Alexander Alekhin
2018-11-26 09:15:09 +00:00
3 changed files with 8 additions and 2 deletions
+1
View File
@@ -33,6 +33,7 @@ extern VkPhysicalDevice kPhysicalDevice;
extern VkDevice kDevice;
extern VkQueue kQueue;
extern VkCommandPool kCmdPool;
extern cv::Mutex kContextMtx;
enum ShapeIdx
{
+2 -1
View File
@@ -25,6 +25,7 @@ VkDebugReportCallbackEXT kDebugReportCallback;
uint32_t kQueueFamilyIndex;
std::vector<const char *> kEnabledLayers;
std::map<std::string, std::vector<uint32_t>> kShaders;
cv::Mutex kContextMtx;
static uint32_t getComputeQueueFamilyIndex()
{
@@ -86,7 +87,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallbackFn(
// internally used
void createContext()
{
cv::AutoLock lock(getInitializationMutex());
cv::AutoLock lock(kContextMtx);
if (!kCtx)
{
kCtx.reset(new Context());
+5 -1
View File
@@ -150,6 +150,7 @@ void OpBase::recordCommandBuffer(void* push_constants, size_t push_constants_siz
VkCommandBufferBeginInfo beginInfo = {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
cv::AutoLock lock(kContextMtx);
VK_CHECK_RESULT(vkBeginCommandBuffer(cmd_buffer_, &beginInfo));
if (push_constants)
vkCmdPushConstants(cmd_buffer_, pipeline_layout_,
@@ -176,7 +177,10 @@ void OpBase::runCommandBuffer()
fence_create_info_.flags = 0;
VK_CHECK_RESULT(vkCreateFence(device_, &fence_create_info_, NULL, &fence));
VK_CHECK_RESULT(vkQueueSubmit(kQueue, 1, &submit_info, fence));
{
cv::AutoLock lock(kContextMtx);
VK_CHECK_RESULT(vkQueueSubmit(kQueue, 1, &submit_info, fence));
}
VK_CHECK_RESULT(vkWaitForFences(device_, 1, &fence, VK_TRUE, 100000000000));
vkDestroyFence(device_, fence, NULL);
}