aboutsummaryrefslogtreecommitdiff
path: root/layers/unique_objects.cpp
diff options
context:
space:
mode:
authorChris Forbes <chrisforbes@google.com>2017-05-02 17:35:26 -0700
committerChris Forbes <chrisf@ijw.co.nz>2017-05-03 11:38:06 -0700
commitad9cf068c0ecb4775ce49ca64da502c3169df684 (patch)
tree87183db398254b9a458441b7e49e4a9312535c9c /layers/unique_objects.cpp
parenta8901efd8e753d01bc5763dba3405d2e4485a5c7 (diff)
downloadusermoji-ad9cf068c0ecb4775ce49ca64da502c3169df684.tar.xz
layers: Write helpers for UO Unwrap+WrapNew operations
Allows us to concentrate all the ID generation and cast insanity in one place.
Diffstat (limited to 'layers/unique_objects.cpp')
-rw-r--r--layers/unique_objects.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/layers/unique_objects.cpp b/layers/unique_objects.cpp
index 6cb9a1c0..5287b790 100644
--- a/layers/unique_objects.cpp
+++ b/layers/unique_objects.cpp
@@ -316,6 +316,23 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance in
return disp_table->GetPhysicalDeviceProcAddr(instance, funcName);
}
+/* Unwrap a handle. */
+// must hold lock!
+template<typename HandleType, typename MapType>
+static HandleType Unwrap(MapType *layer_data, HandleType wrappedHandle) {
+ // TODO: don't use operator[] here.
+ return (HandleType)layer_data->unique_id_mapping[reinterpret_cast<uint64_t const &>(wrappedHandle)];
+}
+
+/* Wrap a newly created handle with a new unique ID, and return the new ID. */
+// must hold lock!
+template<typename HandleType, typename MapType>
+static HandleType WrapNew(MapType *layer_data, HandleType newlyCreatedHandle) {
+ auto unique_id = global_unique_id++;
+ layer_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t const &>(newlyCreatedHandle);
+ return (HandleType)unique_id;
+}
+
VKAPI_ATTR VkResult VKAPI_CALL CreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
const VkComputePipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) {