| 1 |
/* |
| 2 |
* Copyright (c) 2025 The Khronos Group Inc. |
| 3 |
* Copyright (c) 2025 Valve Corporation |
| 4 |
* Copyright (c) 2025 LunarG, Inc. |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and/or associated documentation files (the "Materials"), to |
| 8 |
* deal in the Materials without restriction, including without limitation the |
| 9 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 |
* sell copies of the Materials, and to permit persons to whom the Materials are |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice(s) and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Materials. |
| 15 |
* |
| 16 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 |
* |
| 20 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 21 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 22 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 23 |
* USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#pragma once |
| 28 |
|
| 29 |
#include <vulkan/vk_icd.h> |
| 30 |
|
| 31 |
#include "test_defines.h" |
| 32 |
|
| 33 |
template <typename T> |
| 34 |
struct FRAMEWORK_EXPORT DispatchableHandle { |
| 35 |
DispatchableHandle() { |
| 36 |
auto ptr_handle = new VK_LOADER_DATA; |
| 37 |
set_loader_magic_value(ptr_handle); |
| 38 |
handle = reinterpret_cast<T>(ptr_handle); |
| 39 |
} |
| 40 |
~DispatchableHandle() { |
| 41 |
if (handle) { |
| 42 |
delete reinterpret_cast<VK_LOADER_DATA*>(handle); |
| 43 |
} |
| 44 |
handle = nullptr; |
| 45 |
} |
| 46 |
DispatchableHandle(DispatchableHandle const&) = delete; |
| 47 |
DispatchableHandle& operator=(DispatchableHandle const&) = delete; |
| 48 |
DispatchableHandle(DispatchableHandle&& other) noexcept : handle(other.handle) { other.handle = nullptr; } |
| 49 |
DispatchableHandle& operator=(DispatchableHandle&& other) noexcept { |
| 50 |
if (handle) { |
| 51 |
delete reinterpret_cast<VK_LOADER_DATA*>(handle); |
| 52 |
} |
| 53 |
handle = other.handle; |
| 54 |
other.handle = nullptr; |
| 55 |
return *this; |
| 56 |
} |
| 57 |
bool operator==(T base_handle) { return base_handle == handle; } |
| 58 |
bool operator!=(T base_handle) { return base_handle != handle; } |
| 59 |
|
| 60 |
T handle = nullptr; |
| 61 |
}; |