blob: 6c3a055e6cc759c6d9a05783bfb96a1e10cd9856 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
Mike Stroyan3712d5c2015-04-02 11:59:05 -06004 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07005 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and/or associated documentation files (the "Materials"), to
7 * deal in the Materials without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Materials, and to permit persons to whom the Materials
10 * are furnished to do so, subject to the following conditions:
Mike Stroyan3712d5c2015-04-02 11:59:05 -060011 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070012 * The above copyright notice(s) and this permission notice shall be included
13 * in all copies or substantial portions of the Materials.
Mike Stroyan3712d5c2015-04-02 11:59:05 -060014 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070015 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Mike Stroyan3712d5c2015-04-02 11:59:05 -060016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 *
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
22 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 *
24 * Author: Cody Northrop <cody@lunarg.com>
25 * Author: Mike Stroyan <mike@LunarG.com>
Mike Stroyan3712d5c2015-04-02 11:59:05 -060026 */
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070027
Mike Stroyan313f7e62015-08-10 16:42:53 -060028#ifndef THREADING_H
29#define THREADING_H
Jeremy Hayesb350beb2016-04-12 13:48:52 -060030#include <condition_variable>
31#include <mutex>
Mike Stroyan845bdc42015-11-02 15:30:20 -070032#include <vector>
Mike Stroyan313f7e62015-08-10 16:42:53 -060033#include "vk_layer_config.h"
34#include "vk_layer_logging.h"
Mike Stroyan3712d5c2015-04-02 11:59:05 -060035
Jon Ashburn5484e0c2016-03-08 17:48:44 -070036#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined(_M_IA64) || \
37 defined(__aarch64__) || defined(__powerpc64__)
Mike Stroyan31c50c82016-01-29 15:09:04 -070038// If pointers are 64-bit, then there can be separate counters for each
39// NONDISPATCHABLE_HANDLE type. Otherwise they are all typedef uint64_t.
40#define DISTINCT_NONDISPATCHABLE_HANDLES
41#endif
42
Mike Stroyan3712d5c2015-04-02 11:59:05 -060043// Draw State ERROR codes
Jon Ashburn5484e0c2016-03-08 17:48:44 -070044typedef enum _THREADING_CHECKER_ERROR {
45 THREADING_CHECKER_NONE, // Used for INFO & other non-error messages
46 THREADING_CHECKER_MULTIPLE_THREADS, // Object used simultaneously by multiple threads
47 THREADING_CHECKER_SINGLE_THREAD_REUSE, // Object used simultaneously by recursion in single thread
Mike Stroyan3712d5c2015-04-02 11:59:05 -060048} THREADING_CHECKER_ERROR;
49
Mike Stroyan845bdc42015-11-02 15:30:20 -070050struct object_use_data {
51 loader_platform_thread_id thread;
52 int reader_count;
53 int writer_count;
54};
55
56struct layer_data;
Mike Stroyan845bdc42015-11-02 15:30:20 -070057
Jeremy Hayesb350beb2016-04-12 13:48:52 -060058static std::mutex global_lock;
59static std::condition_variable global_condition;
Mike Stroyan845bdc42015-11-02 15:30:20 -070060
61template <typename T> class counter {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070062 public:
Mike Stroyan845bdc42015-11-02 15:30:20 -070063 const char *typeName;
64 VkDebugReportObjectTypeEXT objectType;
Mike Stroyan1a080012016-01-29 15:33:21 -070065 std::unordered_map<T, object_use_data> uses;
Jon Ashburn5484e0c2016-03-08 17:48:44 -070066 void startWrite(debug_report_data *report_data, T object) {
Dustin Graves080069b2016-04-05 13:48:15 -060067 bool skipCall = false;
Mike Stroyan845bdc42015-11-02 15:30:20 -070068 loader_platform_thread_id tid = loader_platform_get_thread_id();
Jeremy Hayesb350beb2016-04-12 13:48:52 -060069 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -070070 if (uses.find(object) == uses.end()) {
71 // There is no current use of the object. Record writer thread.
72 struct object_use_data *use_data = &uses[object];
73 use_data->reader_count = 0;
74 use_data->writer_count = 1;
75 use_data->thread = tid;
76 } else {
77 struct object_use_data *use_data = &uses[object];
78 if (use_data->reader_count == 0) {
79 // There are no readers. Two writers just collided.
80 if (use_data->thread != tid) {
Dustin Graves37bef952016-02-05 16:06:21 -070081 skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object),
Jon Ashburn5484e0c2016-03-08 17:48:44 -070082 /*location*/ 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",
83 "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld",
84 typeName, use_data->thread, tid);
Mike Stroyan845bdc42015-11-02 15:30:20 -070085 if (skipCall) {
86 // Wait for thread-safe access to object instead of skipping call.
87 while (uses.find(object) != uses.end()) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -060088 global_condition.wait(lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -070089 }
90 // There is now no current use of the object. Record writer thread.
91 struct object_use_data *use_data = &uses[object];
Jon Ashburn5484e0c2016-03-08 17:48:44 -070092 use_data->thread = tid;
Mike Stroyan845bdc42015-11-02 15:30:20 -070093 use_data->reader_count = 0;
94 use_data->writer_count = 1;
95 } else {
96 // Continue with an unsafe use of the object.
Jon Ashburn5484e0c2016-03-08 17:48:44 -070097 use_data->thread = tid;
Mike Stroyan845bdc42015-11-02 15:30:20 -070098 use_data->writer_count += 1;
99 }
100 } else {
Mike Stroyanc8774502016-02-05 09:11:32 -0700101 // This is either safe multiple use in one call, or recursive use.
Mike Stroyan845bdc42015-11-02 15:30:20 -0700102 // There is no way to make recursion safe. Just forge ahead.
103 use_data->writer_count += 1;
104 }
105 } else {
106 // There are readers. This writer collided with them.
107 if (use_data->thread != tid) {
Dustin Graves37bef952016-02-05 16:06:21 -0700108 skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object),
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700109 /*location*/ 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",
110 "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld",
111 typeName, use_data->thread, tid);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700112 if (skipCall) {
113 // Wait for thread-safe access to object instead of skipping call.
114 while (uses.find(object) != uses.end()) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600115 global_condition.wait(lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700116 }
117 // There is now no current use of the object. Record writer thread.
118 struct object_use_data *use_data = &uses[object];
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700119 use_data->thread = tid;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700120 use_data->reader_count = 0;
121 use_data->writer_count = 1;
122 } else {
123 // Continue with an unsafe use of the object.
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700124 use_data->thread = tid;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700125 use_data->writer_count += 1;
126 }
127 } else {
Mike Stroyanc8774502016-02-05 09:11:32 -0700128 // This is either safe multiple use in one call, or recursive use.
Mike Stroyan845bdc42015-11-02 15:30:20 -0700129 // There is no way to make recursion safe. Just forge ahead.
130 use_data->writer_count += 1;
131 }
132 }
133 }
Mike Stroyan845bdc42015-11-02 15:30:20 -0700134 }
135
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700136 void finishWrite(T object) {
Mike Stroyan845bdc42015-11-02 15:30:20 -0700137 // Object is no longer in use
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600138 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700139 uses[object].writer_count -= 1;
140 if ((uses[object].reader_count == 0) && (uses[object].writer_count == 0)) {
141 uses.erase(object);
142 }
143 // Notify any waiting threads that this object may be safe to use
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600144 lock.unlock();
145 global_condition.notify_all();
Mike Stroyan845bdc42015-11-02 15:30:20 -0700146 }
147
148 void startRead(debug_report_data *report_data, T object) {
Dustin Graves080069b2016-04-05 13:48:15 -0600149 bool skipCall = false;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700150 loader_platform_thread_id tid = loader_platform_get_thread_id();
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600151 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700152 if (uses.find(object) == uses.end()) {
153 // There is no current use of the object. Record reader count
154 struct object_use_data *use_data = &uses[object];
155 use_data->reader_count = 1;
156 use_data->writer_count = 0;
157 use_data->thread = tid;
Mike Stroyanc8774502016-02-05 09:11:32 -0700158 } else if (uses[object].writer_count > 0 && uses[object].thread != tid) {
Mike Stroyan845bdc42015-11-02 15:30:20 -0700159 // There is a writer of the object.
Dustin Graves37bef952016-02-05 16:06:21 -0700160 skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object),
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700161 /*location*/ 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",
162 "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld", typeName,
163 uses[object].thread, tid);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700164 if (skipCall) {
165 // Wait for thread-safe access to object instead of skipping call.
166 while (uses.find(object) != uses.end()) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600167 global_condition.wait(lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700168 }
169 // There is no current use of the object. Record reader count
170 struct object_use_data *use_data = &uses[object];
171 use_data->reader_count = 1;
172 use_data->writer_count = 0;
173 use_data->thread = tid;
174 } else {
175 uses[object].reader_count += 1;
176 }
177 } else {
178 // There are other readers of the object. Increase reader count
179 uses[object].reader_count += 1;
180 }
Mike Stroyan845bdc42015-11-02 15:30:20 -0700181 }
182 void finishRead(T object) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600183 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700184 uses[object].reader_count -= 1;
185 if ((uses[object].reader_count == 0) && (uses[object].writer_count == 0)) {
186 uses.erase(object);
187 }
188 // Notify and waiting threads that this object may be safe to use
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600189 lock.unlock();
190 global_condition.notify_all();
Mike Stroyan845bdc42015-11-02 15:30:20 -0700191 }
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700192 counter(const char *name = "", VkDebugReportObjectTypeEXT type = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT) {
Mike Stroyan845bdc42015-11-02 15:30:20 -0700193 typeName = name;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700194 objectType = type;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700195 }
196};
197
Cody Northrop55443ef2015-09-28 15:09:32 -0600198struct layer_data {
Mike Stroyan313f7e62015-08-10 16:42:53 -0600199 debug_report_data *report_data;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700200 std::vector<VkDebugReportCallbackEXT> logging_callback;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700201 VkLayerDispatchTable *device_dispatch_table;
202 VkLayerInstanceDispatchTable *instance_dispatch_table;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700203 counter<VkCommandBuffer> c_VkCommandBuffer;
204 counter<VkDevice> c_VkDevice;
205 counter<VkInstance> c_VkInstance;
206 counter<VkQueue> c_VkQueue;
Mike Stroyan31c50c82016-01-29 15:09:04 -0700207#ifdef DISTINCT_NONDISPATCHABLE_HANDLES
Mike Stroyan845bdc42015-11-02 15:30:20 -0700208 counter<VkBuffer> c_VkBuffer;
209 counter<VkBufferView> c_VkBufferView;
210 counter<VkCommandPool> c_VkCommandPool;
211 counter<VkDescriptorPool> c_VkDescriptorPool;
212 counter<VkDescriptorSet> c_VkDescriptorSet;
213 counter<VkDescriptorSetLayout> c_VkDescriptorSetLayout;
214 counter<VkDeviceMemory> c_VkDeviceMemory;
215 counter<VkEvent> c_VkEvent;
216 counter<VkFence> c_VkFence;
217 counter<VkFramebuffer> c_VkFramebuffer;
218 counter<VkImage> c_VkImage;
219 counter<VkImageView> c_VkImageView;
220 counter<VkPipeline> c_VkPipeline;
221 counter<VkPipelineCache> c_VkPipelineCache;
222 counter<VkPipelineLayout> c_VkPipelineLayout;
223 counter<VkQueryPool> c_VkQueryPool;
224 counter<VkRenderPass> c_VkRenderPass;
225 counter<VkSampler> c_VkSampler;
226 counter<VkSemaphore> c_VkSemaphore;
227 counter<VkShaderModule> c_VkShaderModule;
228 counter<VkDebugReportCallbackEXT> c_VkDebugReportCallbackEXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700229#else // DISTINCT_NONDISPATCHABLE_HANDLES
Mike Stroyan31c50c82016-01-29 15:09:04 -0700230 counter<uint64_t> c_uint64_t;
231#endif // DISTINCT_NONDISPATCHABLE_HANDLES
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700232 layer_data()
233 : report_data(nullptr), c_VkCommandBuffer("VkCommandBuffer", VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT),
234 c_VkDevice("VkDevice", VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT),
235 c_VkInstance("VkInstance", VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT),
236 c_VkQueue("VkQueue", VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT),
Mike Stroyan31c50c82016-01-29 15:09:04 -0700237#ifdef DISTINCT_NONDISPATCHABLE_HANDLES
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700238 c_VkBuffer("VkBuffer", VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT),
239 c_VkBufferView("VkBufferView", VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT),
240 c_VkCommandPool("VkCommandPool", VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT),
241 c_VkDescriptorPool("VkDescriptorPool", VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT),
242 c_VkDescriptorSet("VkDescriptorSet", VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT),
243 c_VkDescriptorSetLayout("VkDescriptorSetLayout", VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT),
244 c_VkDeviceMemory("VkDeviceMemory", VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT),
245 c_VkEvent("VkEvent", VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT), c_VkFence("VkFence", VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT),
246 c_VkFramebuffer("VkFramebuffer", VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT),
247 c_VkImage("VkImage", VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT),
248 c_VkImageView("VkImageView", VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT),
249 c_VkPipeline("VkPipeline", VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT),
250 c_VkPipelineCache("VkPipelineCache", VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT),
251 c_VkPipelineLayout("VkPipelineLayout", VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT),
252 c_VkQueryPool("VkQueryPool", VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT),
253 c_VkRenderPass("VkRenderPass", VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT),
254 c_VkSampler("VkSampler", VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT),
255 c_VkSemaphore("VkSemaphore", VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT),
256 c_VkShaderModule("VkShaderModule", VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT),
257 c_VkDebugReportCallbackEXT("VkDebugReportCallbackEXT", VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT)
258#else // DISTINCT_NONDISPATCHABLE_HANDLES
259 c_uint64_t("NON_DISPATCHABLE_HANDLE", VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT)
Mike Stroyan31c50c82016-01-29 15:09:04 -0700260#endif // DISTINCT_NONDISPATCHABLE_HANDLES
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700261 {};
Cody Northrop55443ef2015-09-28 15:09:32 -0600262};
Mike Stroyan313f7e62015-08-10 16:42:53 -0600263
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700264#define WRAPPER(type) \
265 static void startWriteObject(struct layer_data *my_data, type object) { \
266 my_data->c_##type.startWrite(my_data->report_data, object); \
267 } \
268 static void finishWriteObject(struct layer_data *my_data, type object) { my_data->c_##type.finishWrite(object); } \
269 static void startReadObject(struct layer_data *my_data, type object) { \
270 my_data->c_##type.startRead(my_data->report_data, object); \
271 } \
272 static void finishReadObject(struct layer_data *my_data, type object) { my_data->c_##type.finishRead(object); }
Mike Stroyan313f7e62015-08-10 16:42:53 -0600273
Mike Stroyan845bdc42015-11-02 15:30:20 -0700274WRAPPER(VkDevice)
275WRAPPER(VkInstance)
276WRAPPER(VkQueue)
Mike Stroyan31c50c82016-01-29 15:09:04 -0700277#ifdef DISTINCT_NONDISPATCHABLE_HANDLES
Mike Stroyan845bdc42015-11-02 15:30:20 -0700278WRAPPER(VkBuffer)
279WRAPPER(VkBufferView)
280WRAPPER(VkCommandPool)
281WRAPPER(VkDescriptorPool)
282WRAPPER(VkDescriptorSet)
283WRAPPER(VkDescriptorSetLayout)
284WRAPPER(VkDeviceMemory)
285WRAPPER(VkEvent)
286WRAPPER(VkFence)
287WRAPPER(VkFramebuffer)
288WRAPPER(VkImage)
289WRAPPER(VkImageView)
290WRAPPER(VkPipeline)
291WRAPPER(VkPipelineCache)
292WRAPPER(VkPipelineLayout)
293WRAPPER(VkQueryPool)
294WRAPPER(VkRenderPass)
295WRAPPER(VkSampler)
296WRAPPER(VkSemaphore)
297WRAPPER(VkShaderModule)
298WRAPPER(VkDebugReportCallbackEXT)
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700299#else // DISTINCT_NONDISPATCHABLE_HANDLES
Mike Stroyan31c50c82016-01-29 15:09:04 -0700300WRAPPER(uint64_t)
301#endif // DISTINCT_NONDISPATCHABLE_HANDLES
Mike Stroyan845bdc42015-11-02 15:30:20 -0700302
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700303static std::unordered_map<void *, layer_data *> layer_data_map;
Mike Stroyan845bdc42015-11-02 15:30:20 -0700304static std::unordered_map<VkCommandBuffer, VkCommandPool> command_pool_map;
305
306// VkCommandBuffer needs check for implicit use of command pool
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700307static void startWriteObject(struct layer_data *my_data, VkCommandBuffer object, bool lockPool = true) {
Mike Stroyan845bdc42015-11-02 15:30:20 -0700308 if (lockPool) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600309 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700310 VkCommandPool pool = command_pool_map[object];
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600311 lock.unlock();
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700312 startWriteObject(my_data, pool);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700313 }
314 my_data->c_VkCommandBuffer.startWrite(my_data->report_data, object);
315}
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700316static void finishWriteObject(struct layer_data *my_data, VkCommandBuffer object, bool lockPool = true) {
Mike Stroyan845bdc42015-11-02 15:30:20 -0700317 my_data->c_VkCommandBuffer.finishWrite(object);
318 if (lockPool) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600319 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700320 VkCommandPool pool = command_pool_map[object];
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600321 lock.unlock();
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700322 finishWriteObject(my_data, pool);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700323 }
324}
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700325static void startReadObject(struct layer_data *my_data, VkCommandBuffer object) {
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600326 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700327 VkCommandPool pool = command_pool_map[object];
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600328 lock.unlock();
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700329 startReadObject(my_data, pool);
Mike Stroyan845bdc42015-11-02 15:30:20 -0700330 my_data->c_VkCommandBuffer.startRead(my_data->report_data, object);
331}
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700332static void finishReadObject(struct layer_data *my_data, VkCommandBuffer object) {
Mike Stroyan845bdc42015-11-02 15:30:20 -0700333 my_data->c_VkCommandBuffer.finishRead(object);
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600334 std::unique_lock<std::mutex> lock(global_lock);
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700335 VkCommandPool pool = command_pool_map[object];
Jeremy Hayesb350beb2016-04-12 13:48:52 -0600336 lock.unlock();
Mike Stroyanae8e8a72016-02-08 10:27:55 -0700337 finishReadObject(my_data, pool);
Mike Stroyan313f7e62015-08-10 16:42:53 -0600338}
339#endif // THREADING_H