1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
** Copyright (c) 2018-2021 Valve Corporation
** Copyright (c) 2018-2021 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
** to deal in the Software without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Software, and to permit persons to whom the
** Software is furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
** DEALINGS IN THE SOFTWARE.
*/
#ifndef GFXRECON_DECODE_VULKAN_OBJECT_MAPPER_BASE_H
#define GFXRECON_DECODE_VULKAN_OBJECT_MAPPER_BASE_H
#include "decode/vulkan_object_info.h"
#include "format/format.h"
#include "util/defines.h"
#include "vulkan/vulkan.h"
#include <cassert>
#include <functional>
#include <unordered_map>
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)
class VulkanObjectInfoTableBase
{
protected:
template <typename T>
void AddObjectInfo(T&& info, std::unordered_map<format::HandleId, T>* map)
{
assert(map != nullptr);
if ((info.capture_id != 0) && (info.handle != VK_NULL_HANDLE))
{
auto result = map->emplace(info.capture_id, std::forward<T>(info));
if (!result.second)
{
// There are two expected cases where a capture ID would already be in the map. The first case is for
// handles that are retrieved, such as VkPhysicalDevice, which can be processed more than once. For
// this case we a have a duplicate info structure with the same ID and handle value, and do not need
// to update the map entry. The existing entry may even contain additional info that would be lost if
// replaced with this newly created, default initialized, info structure. The second case is for
// temporary objects created during the trimmed file state setup. IDs may be reused when creating these
// temporary objects, creating a case where we have a new handle that is not a duplicate of the existing
// map entry. In this case, the map entry needs to be updated with the new object's info.
auto iter = result.first;
if (iter->second.handle != info.handle)
{
iter->second = std::forward<T>(info);
}
}
}
}
// Specialization template for SurfaceKHRInfo.
//
// Currently there is a workaround applied for Android apps that create more than 1 surface. For those apps there is
// a command line option (--surface-index) with which the user can choose which of the surface to use, while the
// rest simply will not be created at all. For those surfaces that are not created we still need the SurfaceKHRInfo
// to be inserted in the map in order to be able to tell the difference whether the surface was not created because
// of the said workaround or the user is passing a VK_NULL_HANDLE as a surface on purpose
// (VK_GOOGLE_surfaceless_query).
//
// Once support for multiple Android surfaces is implemented and the workaround is
// removed, this function should also be removed.
//
// Note: the "dummy" template parameter is here for the sole purpose of working around a gcc issue which does
// not allow full specialization in non-namespace scope (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282)
template <typename dummy>
void AddObjectInfo(SurfaceKHRInfo&& info, std::unordered_map<format::HandleId, SurfaceKHRInfo>* map)
{
assert(map != nullptr);
if (info.capture_id != 0)
{
auto result = map->emplace(info.capture_id, std::forward<SurfaceKHRInfo>(info));
if (!result.second)
{
// There are two expected cases where a capture ID would already be in the map. The first case is for
// handles that are retrieved, such as VkPhysicalDevice, which can be processed more than once. For
// this case we a have a duplicate info structure with the same ID and handle value, and do not need
// to update the map entry. The existing entry may even contain additional info that would be lost if
// replaced with this newly created, default initialized, info structure. The second case is for
// temporary objects created during the trimmed file state setup. IDs may be reused when creating these
// temporary objects, creating a case where we have a new handle that is not a duplicate of the existing
// map entry. In this case, the map entry needs to be updated with the new object's info.
auto iter = result.first;
if (iter->second.handle != info.handle)
{
iter->second = std::forward<SurfaceKHRInfo>(info);
}
}
}
}
template <typename T>
const T* GetObjectInfo(format::HandleId id, const std::unordered_map<format::HandleId, T>* map) const
{
assert(map != nullptr);
const T* object_info = nullptr;
if (id != 0)
{
const auto entry = map->find(id);
if (entry != map->end())
{
object_info = &entry->second;
}
}
return object_info;
}
template <typename T>
T* GetObjectInfo(format::HandleId id, std::unordered_map<format::HandleId, T>* map)
{
assert(map != nullptr);
T* object_info = nullptr;
if (id != 0)
{
auto entry = map->find(id);
if (entry != map->end())
{
object_info = &entry->second;
}
}
return object_info;
}
};
GFXRECON_END_NAMESPACE(decode)
GFXRECON_END_NAMESPACE(gfxrecon)
#endif // GFXRECON_DECODE_VULKAN_OBJECT_MAPPER_BASE_H
|