layers: Make unique object IDs unique cross-device and cross-instance
authorMark Lobodzinski <mark@lunarg.com>
Thu, 28 Apr 2016 22:36:58 +0000 (16:36 -0600)
committerTobin Ehlis <tobine@google.com>
Mon, 2 May 2016 16:47:15 +0000 (10:47 -0600)
Change-Id: Ic45e21bd3137dc0474c59f0f4cf9331f070dac20

layers/unique_objects.h
vk-layer-generate.py

index e285450..e32970d 100644 (file)
 #include "vk_safe_struct.h"
 #include "vk_layer_utils.h"
 
+// All increments must be guarded by global_lock
+static uint64_t global_unique_id = 1;
+
 struct layer_data {
     bool wsi_enabled;
-    uint64_t unique_id; // All increments are guarded by global_lock
     std::unordered_map<uint64_t, uint64_t> unique_id_mapping; // Map uniqueID to actual object handle
     VkPhysicalDevice gpu;
 
-    layer_data() : wsi_enabled(false), unique_id(1), gpu(VK_NULL_HANDLE){};
+    layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){};
 };
 
 struct instExts {
@@ -268,7 +270,7 @@ VkResult explicit_CreateComputePipelines(VkDevice device, VkPipelineCache pipeli
         uint64_t unique_id = 0;
         std::lock_guard<std::mutex> lock(global_lock);
         for (uint32_t i = 0; i < createInfoCount; ++i) {
-            unique_id = my_device_data->unique_id++;
+            unique_id = global_unique_id++;
             my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pPipelines[i]);
             pPipelines[i] = reinterpret_cast<VkPipeline &>(unique_id);
         }
@@ -329,7 +331,7 @@ VkResult explicit_CreateGraphicsPipelines(VkDevice device, VkPipelineCache pipel
         uint64_t unique_id = 0;
         std::lock_guard<std::mutex> lock(global_lock);
         for (uint32_t i = 0; i < createInfoCount; ++i) {
-            unique_id = my_device_data->unique_id++;
+            unique_id = global_unique_id++;
             my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pPipelines[i]);
             pPipelines[i] = reinterpret_cast<VkPipeline &>(unique_id);
         }
@@ -359,7 +361,7 @@ VkResult explicit_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInf
         delete local_pCreateInfo;
     if (VK_SUCCESS == result) {
         std::lock_guard<std::mutex> lock(global_lock);
-        uint64_t unique_id = my_map_data->unique_id++;
+        uint64_t unique_id =global_unique_id++;
         my_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*pSwapchain);
         *pSwapchain = reinterpret_cast<VkSwapchainKHR &>(unique_id);
     }
@@ -383,7 +385,7 @@ VkResult explicit_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchai
             uint64_t unique_id = 0;
             std::lock_guard<std::mutex> lock(global_lock);
             for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
-                unique_id = my_device_data->unique_id++;
+                unique_id = global_unique_id++;
                 my_device_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(pSwapchainImages[i]);
                 pSwapchainImages[i] = reinterpret_cast<VkImage &>(unique_id);
             }
index 467e602..1c7cf24 100755 (executable)
@@ -1628,14 +1628,14 @@ class UniqueObjectsSubcommand(Subcommand):
                     local_name = '%ss' % (local_name) # add 's' to end for vector of many
                     post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, custom_create_dict[obj_name])
                     indent += '    '
-                    post_call_txt += '%suint64_t unique_id = my_map_data->unique_id++;\n' % (indent)
+                    post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent)
                     post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(%s[i]);\n' % (indent, obj_name)
                     post_call_txt += '%s%s[i] = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type)
                     indent = indent[4:]
                     post_call_txt += '%s}\n' % (indent)
                 else:
                     post_call_txt += '%s\n' % (self.lineinfo.get())
-                    post_call_txt += '%suint64_t unique_id = my_map_data->unique_id++;\n' % (indent)
+                    post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent)
                     post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*%s);\n' % (indent, obj_name)
                     post_call_txt += '%s*%s = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type)
                 indent = indent[4:]