Commit e63efe29 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #13275 from wzw-intel:thread_safe

parents c6daa4aa 4e652830
......@@ -33,6 +33,7 @@ extern VkPhysicalDevice kPhysicalDevice;
extern VkDevice kDevice;
extern VkQueue kQueue;
extern VkCommandPool kCmdPool;
extern cv::Mutex kContextMtx;
enum ShapeIdx
{
......
......@@ -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());
......
......@@ -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);
}
......
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