Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2016, 2020-2022 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016, 2020-2022 Valve Corporation |
| 4 | * Copyright (c) 2015-2016, 2020-2022 LunarG, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 19 | * Author: Cody Northrop <cody@lunarg.com> |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 20 | * Author: John Zulauf <jzulauf@lunarg.com> |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 21 | */ |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 22 | |
| 23 | #ifndef VKTESTBINDING_H |
| 24 | #define VKTESTBINDING_H |
| 25 | |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 26 | #include <algorithm> |
Petr Kraus | c3aee2e | 2019-09-06 00:26:06 +0200 | [diff] [blame] | 27 | #include <cassert> |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 28 | #include <iterator> |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 29 | #include <memory> |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 30 | #include <vector> |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | c7a5fcf | 2019-09-27 14:09:58 -0600 | [diff] [blame] | 32 | #include "lvt_function_pointers.h" |
Petr Kraus | c3aee2e | 2019-09-06 00:26:06 +0200 | [diff] [blame] | 33 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 34 | |
| 35 | namespace vk_testing { |
| 36 | |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 37 | template <class Dst, class Src> |
| 38 | std::vector<Dst> MakeVkHandles(const std::vector<Src> &v) { |
| 39 | std::vector<Dst> handles; |
| 40 | handles.reserve(v.size()); |
| 41 | std::transform(v.begin(), v.end(), std::back_inserter(handles), [](const Src &o) { return o.handle(); }); |
| 42 | return handles; |
| 43 | } |
| 44 | |
| 45 | template <class Dst, class Src> |
| 46 | std::vector<Dst> MakeVkHandles(const std::vector<Src *> &v) { |
| 47 | std::vector<Dst> handles; |
| 48 | handles.reserve(v.size()); |
Nathaniel Cesario | c19c8b7 | 2022-03-10 23:01:21 -0700 | [diff] [blame] | 49 | std::transform(v.begin(), v.end(), std::back_inserter(handles), |
| 50 | [](const Src *o) { return (o) ? o->handle() : VK_NULL_HANDLE; }); |
Petr Kraus | 858bacd | 2017-12-01 23:10:08 +0100 | [diff] [blame] | 51 | return handles; |
| 52 | } |
| 53 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 54 | typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 55 | void set_error_callback(ErrorCallback callback); |
| 56 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 57 | class PhysicalDevice; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 58 | class Device; |
| 59 | class Queue; |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 60 | class DeviceMemory; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 61 | class Fence; |
| 62 | class Semaphore; |
| 63 | class Event; |
| 64 | class QueryPool; |
| 65 | class Buffer; |
| 66 | class BufferView; |
| 67 | class Image; |
| 68 | class ImageView; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 69 | class DepthStencilView; |
| 70 | class Shader; |
| 71 | class Pipeline; |
| 72 | class PipelineDelta; |
| 73 | class Sampler; |
| 74 | class DescriptorSetLayout; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 75 | class PipelineLayout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 76 | class DescriptorSetPool; |
| 77 | class DescriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 78 | class CommandBuffer; |
| 79 | class CommandPool; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 80 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 81 | std::vector<VkLayerProperties> GetGlobalLayers(); |
| 82 | std::vector<VkExtensionProperties> GetGlobalExtensions(); |
| 83 | std::vector<VkExtensionProperties> GetGlobalExtensions(const char *pLayerName); |
| 84 | |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 85 | namespace internal { |
| 86 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 87 | template <typename T> |
| 88 | class Handle { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 89 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 90 | const T &handle() const noexcept { return handle_; } |
| 91 | bool initialized() const noexcept { return (handle_ != T{}); } |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 92 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 93 | protected: |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 94 | typedef T handle_type; |
| 95 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 96 | explicit Handle() noexcept : handle_{} {} |
| 97 | explicit Handle(T handle) noexcept : handle_(handle) {} |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 98 | |
Petr Kraus | b3d2c82 | 2017-12-01 23:09:19 +0100 | [diff] [blame] | 99 | // handles are non-copyable |
| 100 | Handle(const Handle &) = delete; |
| 101 | Handle &operator=(const Handle &) = delete; |
| 102 | |
| 103 | // handles can be moved out |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 104 | Handle(Handle &&src) noexcept : handle_{src.handle_} { src.handle_ = {}; } |
| 105 | Handle &operator=(Handle &&src) noexcept { |
Petr Kraus | b3d2c82 | 2017-12-01 23:09:19 +0100 | [diff] [blame] | 106 | handle_ = src.handle_; |
| 107 | src.handle_ = {}; |
| 108 | return *this; |
| 109 | } |
| 110 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 111 | void init(T handle) noexcept { |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 112 | assert(!initialized()); |
| 113 | handle_ = handle; |
| 114 | } |
| 115 | |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 116 | protected: |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 117 | T handle_; |
| 118 | }; |
| 119 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 120 | template <typename T> |
| 121 | class NonDispHandle : public Handle<T> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 122 | protected: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 123 | explicit NonDispHandle() noexcept : Handle<T>(), dev_handle_(VK_NULL_HANDLE) {} |
| 124 | explicit NonDispHandle(VkDevice dev, T handle) noexcept : Handle<T>(handle), dev_handle_(dev) {} |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 125 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 126 | NonDispHandle(NonDispHandle &&src) noexcept : Handle<T>(std::move(src)) { |
Mike Schuchardt | 0bc8e7a | 2018-01-02 14:39:51 -0700 | [diff] [blame] | 127 | dev_handle_ = src.dev_handle_; |
| 128 | src.dev_handle_ = VK_NULL_HANDLE; |
| 129 | } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 130 | NonDispHandle &operator=(NonDispHandle &&src) noexcept { |
Mike Schuchardt | 0bc8e7a | 2018-01-02 14:39:51 -0700 | [diff] [blame] | 131 | Handle<T>::operator=(std::move(src)); |
| 132 | dev_handle_ = src.dev_handle_; |
| 133 | src.dev_handle_ = VK_NULL_HANDLE; |
| 134 | return *this; |
| 135 | } |
Petr Kraus | b3d2c82 | 2017-12-01 23:09:19 +0100 | [diff] [blame] | 136 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 137 | const VkDevice &device() const noexcept { return dev_handle_; } |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 138 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 139 | void init(VkDevice dev, T handle) noexcept { |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 140 | assert(!Handle<T>::initialized() && dev_handle_ == VK_NULL_HANDLE); |
| 141 | Handle<T>::init(handle); |
| 142 | dev_handle_ = dev; |
| 143 | } |
| 144 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 145 | private: |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 146 | VkDevice dev_handle_; |
| 147 | }; |
| 148 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 149 | } // namespace internal |
Chia-I Wu | b0ed7d4 | 2015-07-03 10:13:26 +0800 | [diff] [blame] | 150 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 151 | class PhysicalDevice : public internal::Handle<VkPhysicalDevice> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 152 | public: |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 153 | explicit PhysicalDevice(VkPhysicalDevice phy) : Handle(phy) { |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 154 | memory_properties_ = memory_properties(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 155 | device_properties_ = properties(); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 156 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 157 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 158 | VkPhysicalDeviceProperties properties() const; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 159 | VkPhysicalDeviceMemoryProperties memory_properties() const; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 160 | std::vector<VkQueueFamilyProperties> queue_properties() const; |
Chris Forbes | f9cfe18 | 2016-04-04 17:22:42 +1200 | [diff] [blame] | 161 | VkPhysicalDeviceFeatures features() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 162 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 163 | bool set_memory_type(const uint32_t type_bits, VkMemoryAllocateInfo *info, const VkMemoryPropertyFlags properties, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | const VkMemoryPropertyFlags forbid = 0) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 165 | |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 166 | // vkEnumerateDeviceExtensionProperties() |
Petr Kraus | 43bba7b | 2020-04-02 19:55:31 +0200 | [diff] [blame] | 167 | std::vector<VkExtensionProperties> extensions(const char *pLayerName = nullptr) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 168 | |
| 169 | // vkEnumerateLayers() |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 170 | std::vector<VkLayerProperties> layers() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 171 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 172 | private: |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 173 | void add_extension_dependencies(uint32_t dependency_count, VkExtensionProperties *depencency_props, |
| 174 | std::vector<VkExtensionProperties> &ext_list); |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 175 | |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 176 | VkPhysicalDeviceMemoryProperties memory_properties_; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 177 | |
| 178 | VkPhysicalDeviceProperties device_properties_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 179 | }; |
| 180 | |
John Zulauf | 01da3ee | 2017-10-18 18:13:37 -0600 | [diff] [blame] | 181 | class QueueCreateInfoArray { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 182 | private: |
John Zulauf | 01da3ee | 2017-10-18 18:13:37 -0600 | [diff] [blame] | 183 | std::vector<VkDeviceQueueCreateInfo> queue_info_; |
| 184 | std::vector<std::vector<float>> queue_priorities_; |
| 185 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 186 | public: |
John Zulauf | 01da3ee | 2017-10-18 18:13:37 -0600 | [diff] [blame] | 187 | QueueCreateInfoArray(const std::vector<VkQueueFamilyProperties> &queue_props); |
| 188 | size_t size() const { return queue_info_.size(); } |
| 189 | const VkDeviceQueueCreateInfo *data() const { return queue_info_.data(); } |
| 190 | }; |
| 191 | |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 192 | class Device : public internal::Handle<VkDevice> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 193 | public: |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 194 | explicit Device(VkPhysicalDevice phy) : phy_(phy) {} |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 195 | ~Device() noexcept; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 196 | |
| 197 | // vkCreateDevice() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 198 | void init(const VkDeviceCreateInfo &info); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 199 | void init(std::vector<const char *> &extensions, VkPhysicalDeviceFeatures *features = nullptr, |
Tony-LunarG | 58c59b4 | 2019-01-03 13:19:11 -0700 | [diff] [blame] | 200 | void *create_device_pnext = nullptr); // all queues, all extensions, etc |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 201 | void init() { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 202 | std::vector<const char *> extensions; |
Tony Barbour | 4c70d10 | 2016-08-08 16:06:56 -0600 | [diff] [blame] | 203 | init(extensions); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 204 | }; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 205 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 206 | const PhysicalDevice &phy() const { return phy_; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 207 | |
Petr Kraus | b9659a0 | 2017-12-11 01:17:46 +0100 | [diff] [blame] | 208 | std::vector<const char *> GetEnabledExtensions() { return enabled_extensions_; } |
Cort Stratton | 72f89aa | 2018-05-27 10:40:27 -0700 | [diff] [blame] | 209 | bool IsEnabledExtension(const char *extension); |
Petr Kraus | b9659a0 | 2017-12-11 01:17:46 +0100 | [diff] [blame] | 210 | |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 211 | // vkGetDeviceProcAddr() |
Mark Lobodzinski | c7a5fcf | 2019-09-27 14:09:58 -0600 | [diff] [blame] | 212 | PFN_vkVoidFunction get_proc(const char *name) const { return vk::GetDeviceProcAddr(handle(), name); } |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 213 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 214 | // vkGetDeviceQueue() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 215 | const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 216 | const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; } |
| 217 | const std::vector<Queue *> &dma_queues() { return queues_[DMA]; } |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 218 | |
| 219 | typedef std::vector<std::unique_ptr<Queue>> QueueFamilyQueues; |
| 220 | typedef std::vector<QueueFamilyQueues> QueueFamilies; |
| 221 | const QueueFamilyQueues &queue_family_queues(uint32_t queue_family) const; |
| 222 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 223 | uint32_t graphics_queue_node_index_; |
| 224 | |
| 225 | struct Format { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 226 | VkFormat format; |
| 227 | VkImageTiling tiling; |
| 228 | VkFlags features; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 229 | }; |
| 230 | // vkGetFormatInfo() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 231 | VkFormatProperties format_properties(VkFormat format); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 232 | const std::vector<Format> &formats() const { return formats_; } |
| 233 | |
| 234 | // vkDeviceWaitIdle() |
| 235 | void wait(); |
| 236 | |
| 237 | // vkWaitForFences() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 238 | VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout); |
| 239 | VkResult wait(const Fence &fence) { return wait(std::vector<const Fence *>(1, &fence), true, (uint64_t)-1); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 240 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 241 | // vkUpdateDescriptorSets() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 242 | void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies); |
| 243 | void update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { |
| 244 | return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 245 | } |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 246 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 247 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 248 | VkDescriptorType type, uint32_t count, |
| 249 | const VkDescriptorImageInfo *image_info); |
| 250 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 251 | VkDescriptorType type, uint32_t count, |
| 252 | const VkDescriptorBufferInfo *buffer_info); |
| 253 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 254 | VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views); |
| 255 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 256 | VkDescriptorType type, const std::vector<VkDescriptorImageInfo> &image_info); |
| 257 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 258 | VkDescriptorType type, const std::vector<VkDescriptorBufferInfo> &buffer_info); |
| 259 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 260 | VkDescriptorType type, const std::vector<VkBufferView> &buffer_views); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 261 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 262 | static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element, |
| 263 | const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element, |
| 264 | uint32_t count); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 265 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 266 | private: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 267 | enum QueueIndex { |
| 268 | GRAPHICS, |
| 269 | COMPUTE, |
| 270 | DMA, |
| 271 | QUEUE_COUNT, |
| 272 | }; |
| 273 | |
Jeremy Gebben | c7af14b | 2021-10-22 11:16:48 -0600 | [diff] [blame] | 274 | void init_queues(const VkDeviceCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 275 | void init_formats(); |
| 276 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 277 | PhysicalDevice phy_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 278 | |
Petr Kraus | b9659a0 | 2017-12-11 01:17:46 +0100 | [diff] [blame] | 279 | std::vector<const char *> enabled_extensions_; |
| 280 | |
John Zulauf | 5abdf12 | 2018-03-27 10:12:37 -0600 | [diff] [blame] | 281 | QueueFamilies queue_families_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 282 | std::vector<Queue *> queues_[QUEUE_COUNT]; |
| 283 | std::vector<Format> formats_; |
| 284 | }; |
| 285 | |
Chia-I Wu | df12ffd | 2015-07-03 10:53:18 +0800 | [diff] [blame] | 286 | class Queue : public internal::Handle<VkQueue> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 287 | public: |
John Zulauf | bd0a45c | 2022-05-25 15:17:14 -0600 | [diff] [blame] | 288 | explicit Queue(VkQueue queue, uint32_t index) : Handle(queue) { family_index_ = index; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 289 | |
| 290 | // vkQueueSubmit() |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 291 | VkResult submit(const std::vector<const CommandBuffer *> &cmds, const Fence &fence, bool expect_success = true); |
| 292 | VkResult submit(const CommandBuffer &cmd, const Fence &fence, bool expect_success = true); |
| 293 | VkResult submit(const CommandBuffer &cmd, bool expect_success = true); |
sjfricke | a143ec2 | 2022-08-02 21:46:04 +0900 | [diff] [blame] | 294 | // vkQueueSubmit2() |
| 295 | VkResult submit2(const std::vector<const CommandBuffer *> &cmds, const Fence &fence, bool expect_success = true); |
| 296 | VkResult submit2(const CommandBuffer &cmd, const Fence &fence, bool expect_success = true); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 297 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 298 | // vkQueueWaitIdle() |
John Zulauf | 7109547 | 2018-03-26 14:45:12 -0600 | [diff] [blame] | 299 | VkResult wait(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 300 | |
John Zulauf | 6df2d5c | 2022-05-28 13:02:21 -0600 | [diff] [blame] | 301 | uint32_t get_family_index() const { return family_index_; } |
Tony Barbour | fb21ea3 | 2015-07-23 10:35:30 -0600 | [diff] [blame] | 302 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 303 | private: |
John Zulauf | bd0a45c | 2022-05-25 15:17:14 -0600 | [diff] [blame] | 304 | uint32_t family_index_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 305 | }; |
| 306 | |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 307 | class DeviceMemory : public internal::NonDispHandle<VkDeviceMemory> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 308 | public: |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 309 | DeviceMemory() = default; |
| 310 | DeviceMemory(const Device &dev, const VkMemoryAllocateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 311 | ~DeviceMemory() noexcept; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 312 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 313 | // vkAllocateMemory() |
| 314 | void init(const Device &dev, const VkMemoryAllocateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 315 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 316 | // vkMapMemory() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 317 | const void *map(VkFlags flags) const; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 318 | void *map(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 319 | const void *map() const { return map(0); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 320 | void *map() { return map(0); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 321 | |
| 322 | // vkUnmapMemory() |
| 323 | void unmap() const; |
| 324 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 325 | static VkMemoryAllocateInfo alloc_info(VkDeviceSize size, uint32_t memory_type_index); |
Mike Schuchardt | 8cacbb0 | 2017-10-26 14:06:38 -0600 | [diff] [blame] | 326 | static VkMemoryAllocateInfo get_resource_alloc_info(const vk_testing::Device &dev, const VkMemoryRequirements &reqs, |
| 327 | VkMemoryPropertyFlags mem_props); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | }; |
| 329 | |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 330 | class Fence : public internal::NonDispHandle<VkFence> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 331 | public: |
Jeremy Gebben | acaac9f | 2022-09-16 12:14:21 -0600 | [diff] [blame] | 332 | #ifdef _WIN32 |
| 333 | using ExternalHandle = HANDLE; |
| 334 | #else |
| 335 | using ExternalHandle = int; |
| 336 | #endif |
| 337 | |
paul-lunarg | de56bc1 | 2022-06-27 18:57:48 +0200 | [diff] [blame] | 338 | Fence() = default; |
| 339 | Fence(const Device &dev, const VkFenceCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 340 | ~Fence() noexcept; |
paul-lunarg | de56bc1 | 2022-06-27 18:57:48 +0200 | [diff] [blame] | 341 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 342 | // vkCreateFence() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 343 | void init(const Device &dev, const VkFenceCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 344 | |
| 345 | // vkGetFenceStatus() |
Mark Lobodzinski | c7a5fcf | 2019-09-27 14:09:58 -0600 | [diff] [blame] | 346 | VkResult status() const { return vk::GetFenceStatus(device(), handle()); } |
Petr Kraus | 70fc465 | 2020-04-25 20:10:49 +0200 | [diff] [blame] | 347 | VkResult wait(uint64_t timeout) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 348 | |
Jeremy Gebben | acaac9f | 2022-09-16 12:14:21 -0600 | [diff] [blame] | 349 | VkResult reset(); |
| 350 | |
| 351 | VkResult export_handle(ExternalHandle &handle, VkExternalFenceHandleTypeFlagBits handle_type); |
| 352 | VkResult import_handle(ExternalHandle handle, VkExternalFenceHandleTypeFlagBits handle_type, VkFenceImportFlags flags = 0); |
| 353 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 354 | static VkFenceCreateInfo create_info(VkFenceCreateFlags flags); |
| 355 | static VkFenceCreateInfo create_info(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 356 | }; |
| 357 | |
Chia-I Wu | 6b1c248 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 358 | class Semaphore : public internal::NonDispHandle<VkSemaphore> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 359 | public: |
Jeremy Gebben | acaac9f | 2022-09-16 12:14:21 -0600 | [diff] [blame] | 360 | #ifdef _WIN32 |
| 361 | using ExternalHandle = HANDLE; |
| 362 | #else |
| 363 | using ExternalHandle = int; |
| 364 | #endif |
| 365 | |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 366 | Semaphore() = default; |
Nathaniel Cesario | 13da77b | 2022-07-15 14:51:12 -0600 | [diff] [blame] | 367 | Semaphore(const Device &dev) { init(dev, LvlInitStruct<VkSemaphoreCreateInfo>()); } |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 368 | Semaphore(const Device &dev, const VkSemaphoreCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 369 | ~Semaphore() noexcept; |
Chia-I Wu | 6b1c248 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 370 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 371 | // vkCreateSemaphore() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 372 | void init(const Device &dev, const VkSemaphoreCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 373 | |
Jeremy Gebben | acaac9f | 2022-09-16 12:14:21 -0600 | [diff] [blame] | 374 | VkResult export_handle(ExternalHandle &ext_handle, VkExternalSemaphoreHandleTypeFlagBits handle_type); |
| 375 | VkResult import_handle(ExternalHandle ext_handle, VkExternalSemaphoreHandleTypeFlagBits handle_type, |
| 376 | VkSemaphoreImportFlags flags = 0); |
| 377 | |
Tony Barbour | af892a1 | 2015-06-26 12:56:09 -0600 | [diff] [blame] | 378 | static VkSemaphoreCreateInfo create_info(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 379 | }; |
| 380 | |
Chia-I Wu | c5c9799 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 381 | class Event : public internal::NonDispHandle<VkEvent> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 382 | public: |
Nathaniel Cesario | 079b1b9 | 2022-07-06 15:56:26 -0600 | [diff] [blame] | 383 | Event() = default; |
Nathaniel Cesario | 13da77b | 2022-07-15 14:51:12 -0600 | [diff] [blame] | 384 | Event(const Device &dev) { init(dev, LvlInitStruct<VkEventCreateInfo>()); } |
Nathaniel Cesario | 079b1b9 | 2022-07-06 15:56:26 -0600 | [diff] [blame] | 385 | Event(const Device &dev, const VkEventCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 386 | ~Event() noexcept; |
Chia-I Wu | c5c9799 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 387 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 388 | // vkCreateEvent() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 389 | void init(const Device &dev, const VkEventCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 390 | |
| 391 | // vkGetEventStatus() |
| 392 | // vkSetEvent() |
| 393 | // vkResetEvent() |
Mark Lobodzinski | c7a5fcf | 2019-09-27 14:09:58 -0600 | [diff] [blame] | 394 | VkResult status() const { return vk::GetEventStatus(device(), handle()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 395 | void set(); |
John Zulauf | 7701931 | 2020-12-15 09:04:32 -0700 | [diff] [blame] | 396 | void cmd_set(const CommandBuffer &cmd, VkPipelineStageFlags stage_mask); |
| 397 | void cmd_reset(const CommandBuffer &cmd, VkPipelineStageFlags stage_mask); |
John Zulauf | b66ee05 | 2022-06-10 16:52:28 -0600 | [diff] [blame] | 398 | void cmd_wait(const CommandBuffer &cmd, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask, |
| 399 | const std::vector<VkMemoryBarrier> &memory_barriers, const std::vector<VkBufferMemoryBarrier> &buffer_barriers, |
| 400 | const std::vector<VkImageMemoryBarrier> &image_barriers); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 401 | void reset(); |
| 402 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 403 | static VkEventCreateInfo create_info(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 404 | }; |
| 405 | |
Chia-I Wu | 1b7d476 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 406 | class QueryPool : public internal::NonDispHandle<VkQueryPool> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 407 | public: |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 408 | QueryPool() = default; |
| 409 | QueryPool(const Device &dev, const VkQueryPoolCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 410 | ~QueryPool() noexcept; |
Chia-I Wu | 1b7d476 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 411 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 412 | // vkCreateQueryPool() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 413 | void init(const Device &dev, const VkQueryPoolCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 414 | |
| 415 | // vkGetQueryPoolResults() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 416 | VkResult results(uint32_t first, uint32_t count, size_t size, void *data, size_t stride); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 417 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 418 | static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 419 | }; |
| 420 | |
Nathaniel Cesario | 079b1b9 | 2022-07-06 15:56:26 -0600 | [diff] [blame] | 421 | struct NoMemT {}; |
| 422 | static constexpr NoMemT no_mem{}; |
| 423 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 424 | class Buffer : public internal::NonDispHandle<VkBuffer> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 425 | public: |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 426 | explicit Buffer() : NonDispHandle() {} |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 427 | explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); } |
Nathaniel Cesario | 079b1b9 | 2022-07-06 15:56:26 -0600 | [diff] [blame] | 428 | explicit Buffer(const Device &dev, const VkBufferCreateInfo &info, NoMemT) { init_no_mem(dev, info); } |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 429 | explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 430 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 431 | ~Buffer() noexcept; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 432 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 433 | // vkCreateBuffer() |
Tony-LunarG | c7cd9b3 | 2022-07-12 14:25:39 -0600 | [diff] [blame] | 434 | void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags mem_props, void *alloc_info_pnext = nullptr); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 435 | void init(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info, 0); } |
unknown | 11b2e80 | 2019-06-03 11:47:40 -0600 | [diff] [blame] | 436 | void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props, |
Jason Macnak | aabfa9b | 2019-07-17 15:20:22 -0700 | [diff] [blame] | 437 | VkBufferUsageFlags usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, const std::vector<uint32_t> &queue_families = {}) { |
| 438 | init(dev, create_info(size, usage, &queue_families), mem_props); |
unknown | 11b2e80 | 2019-06-03 11:47:40 -0600 | [diff] [blame] | 439 | } |
Tony-LunarG | c7cd9b3 | 2022-07-12 14:25:39 -0600 | [diff] [blame] | 440 | void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags mem_props, VkBufferUsageFlags usage, |
| 441 | void *alloc_info_pnext) { |
| 442 | init(dev, create_info(size, usage), mem_props, alloc_info_pnext); |
| 443 | } |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 444 | void init(const Device &dev, VkDeviceSize size) { init(dev, size, 0); } |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 445 | void init_as_src(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs, |
| 446 | const std::vector<uint32_t> *queue_families = nullptr) { |
| 447 | init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, queue_families), reqs); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 448 | } |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 449 | void init_as_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs, |
| 450 | const std::vector<uint32_t> *queue_families = nullptr) { |
| 451 | init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_DST_BIT, queue_families), reqs); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 452 | } |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 453 | void init_as_src_and_dst(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs, |
unknown | 11b2e80 | 2019-06-03 11:47:40 -0600 | [diff] [blame] | 454 | const std::vector<uint32_t> *queue_families = nullptr, bool memory = true) { |
| 455 | if (memory) |
| 456 | init(dev, create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, queue_families), reqs); |
| 457 | else |
| 458 | init_no_mem(dev, |
| 459 | create_info(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, queue_families)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 460 | } |
Tony-LunarG | edde675 | 2020-08-28 13:41:30 -0600 | [diff] [blame] | 461 | void init_as_storage(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs, |
| 462 | const std::vector<uint32_t> *queue_families = nullptr) { |
| 463 | init(dev, create_info(size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, queue_families), reqs); |
| 464 | } |
| 465 | |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 466 | void init_no_mem(const Device &dev, const VkBufferCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 467 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 468 | // get the internal memory |
| 469 | const DeviceMemory &memory() const { return internal_mem_; } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 470 | DeviceMemory &memory() { return internal_mem_; } |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 471 | |
| 472 | // vkGetObjectMemoryRequirements() |
| 473 | VkMemoryRequirements memory_requirements() const; |
| 474 | |
| 475 | // vkBindObjectMemory() |
| 476 | void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset); |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 477 | // Bind to internal_mem_ reference |
| 478 | void bind_memory(const Device &dev, VkMemoryPropertyFlags mem_props, VkDeviceSize mem_offset); |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 479 | |
John Zulauf | 065ca13 | 2018-02-20 12:19:28 -0700 | [diff] [blame] | 480 | const VkBufferCreateInfo &create_info() const { return create_info_; } |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 481 | static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage, const std::vector<uint32_t> *queue_families = nullptr); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 482 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 483 | VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkDeviceSize offset, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 484 | VkDeviceSize size) const { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 485 | VkBufferMemoryBarrier barrier = LvlInitStruct<VkBufferMemoryBarrier>(); |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 486 | barrier.buffer = handle(); |
Chia-I Wu | a459420 | 2015-10-27 19:54:37 +0800 | [diff] [blame] | 487 | barrier.srcAccessMask = output_mask; |
| 488 | barrier.dstAccessMask = input_mask; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 489 | barrier.offset = offset; |
| 490 | barrier.size = size; |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 491 | if (create_info_.sharingMode == VK_SHARING_MODE_CONCURRENT) { |
| 492 | barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 493 | barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 494 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 495 | return barrier; |
| 496 | } |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 497 | |
Jeremy Gebben | 1db6edc | 2021-02-17 15:28:40 -0700 | [diff] [blame] | 498 | VkBufferMemoryBarrier2KHR buffer_memory_barrier(VkPipelineStageFlags2KHR src_stage, VkPipelineStageFlags2KHR dst_stage, |
| 499 | VkAccessFlags2KHR src_access, VkAccessFlags2KHR dst_access, VkDeviceSize offset, |
| 500 | VkDeviceSize size) const { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 501 | VkBufferMemoryBarrier2KHR barrier = LvlInitStruct<VkBufferMemoryBarrier2KHR>(); |
Jeremy Gebben | 1db6edc | 2021-02-17 15:28:40 -0700 | [diff] [blame] | 502 | barrier.buffer = handle(); |
| 503 | barrier.srcStageMask = src_stage; |
| 504 | barrier.dstStageMask = dst_stage; |
| 505 | barrier.srcAccessMask = src_access; |
| 506 | barrier.dstAccessMask = dst_access; |
| 507 | barrier.offset = offset; |
| 508 | barrier.size = size; |
| 509 | if (create_info_.sharingMode == VK_SHARING_MODE_CONCURRENT) { |
| 510 | barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 511 | barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 512 | } |
| 513 | return barrier; |
| 514 | } |
| 515 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 516 | private: |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 517 | VkBufferCreateInfo create_info_; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 518 | |
| 519 | DeviceMemory internal_mem_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 520 | }; |
| 521 | |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 522 | class BufferView : public internal::NonDispHandle<VkBufferView> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 523 | public: |
Nathaniel Cesario | cabaf44 | 2022-07-21 14:57:41 -0600 | [diff] [blame] | 524 | BufferView() = default; |
| 525 | BufferView(const Device &dev, const VkBufferViewCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 526 | ~BufferView() noexcept; |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 527 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 528 | // vkCreateBufferView() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 529 | void init(const Device &dev, const VkBufferViewCreateInfo &info); |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 530 | static VkBufferViewCreateInfo createInfo(VkBuffer buffer, VkFormat format, VkDeviceSize offset = 0, |
| 531 | VkDeviceSize range = VK_WHOLE_SIZE); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 532 | }; |
| 533 | |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 534 | inline VkBufferViewCreateInfo BufferView::createInfo(VkBuffer buffer, VkFormat format, VkDeviceSize offset, VkDeviceSize range) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 535 | VkBufferViewCreateInfo info = LvlInitStruct<VkBufferViewCreateInfo>(); |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 536 | info.flags = VkFlags(0); |
| 537 | info.buffer = buffer; |
| 538 | info.format = format; |
| 539 | info.offset = offset; |
| 540 | info.range = range; |
| 541 | return info; |
| 542 | } |
| 543 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 544 | class Image : public internal::NonDispHandle<VkImage> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 545 | public: |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 546 | explicit Image() : NonDispHandle(), format_features_(0) {} |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 547 | explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); } |
Nathaniel Cesario | 079b1b9 | 2022-07-06 15:56:26 -0600 | [diff] [blame] | 548 | explicit Image(const Device &dev, const VkImageCreateInfo &info, NoMemT) : format_features_(0) { init_no_mem(dev, info); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 549 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 550 | ~Image() noexcept; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 551 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 552 | // vkCreateImage() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 553 | void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags mem_props); |
| 554 | void init(const Device &dev, const VkImageCreateInfo &info) { init(dev, info, 0); } |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 555 | void init_no_mem(const Device &dev, const VkImageCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 556 | |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 557 | // get the internal memory |
| 558 | const DeviceMemory &memory() const { return internal_mem_; } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 559 | DeviceMemory &memory() { return internal_mem_; } |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 560 | |
| 561 | // vkGetObjectMemoryRequirements() |
| 562 | VkMemoryRequirements memory_requirements() const; |
| 563 | |
| 564 | // vkBindObjectMemory() |
| 565 | void bind_memory(const DeviceMemory &mem, VkDeviceSize mem_offset); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 566 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 567 | // vkGetImageSubresourceLayout() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 568 | VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const; |
| 569 | VkSubresourceLayout subresource_layout(const VkImageSubresourceLayers &subres) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 570 | |
| 571 | bool transparent() const; |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 572 | bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 573 | |
John Zulauf | 5e01c4a | 2022-07-25 18:00:18 -0600 | [diff] [blame] | 574 | VkImageAspectFlags aspect_mask() const { return aspect_mask(create_info_.format); } |
| 575 | |
| 576 | VkImageSubresourceRange subresource_range() const { return subresource_range(create_info_, aspect_mask()); } |
John Zulauf | 567887d | 2019-04-16 09:04:57 -0600 | [diff] [blame] | 577 | VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect) const { return subresource_range(create_info_, aspect); } |
John Zulauf | 5e01c4a | 2022-07-25 18:00:18 -0600 | [diff] [blame] | 578 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 579 | VkExtent3D extent() const { return create_info_.extent; } |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 580 | VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 581 | VkFormat format() const { return create_info_.format; } |
Mike Weiblen | e6e0117 | 2017-03-07 22:18:40 -0700 | [diff] [blame] | 582 | VkImageUsageFlags usage() const { return create_info_.usage; } |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 583 | VkSharingMode sharing_mode() const { return create_info_.sharingMode; } |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 584 | VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask, VkImageLayout old_layout, |
unknown | 11b2e80 | 2019-06-03 11:47:40 -0600 | [diff] [blame] | 585 | VkImageLayout new_layout, const VkImageSubresourceRange &range, |
| 586 | uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, |
| 587 | uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED) const { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 588 | VkImageMemoryBarrier barrier = LvlInitStruct<VkImageMemoryBarrier>(); |
Chia-I Wu | a459420 | 2015-10-27 19:54:37 +0800 | [diff] [blame] | 589 | barrier.srcAccessMask = output_mask; |
| 590 | barrier.dstAccessMask = input_mask; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 591 | barrier.oldLayout = old_layout; |
| 592 | barrier.newLayout = new_layout; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 593 | barrier.image = handle(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 594 | barrier.subresourceRange = range; |
unknown | 11b2e80 | 2019-06-03 11:47:40 -0600 | [diff] [blame] | 595 | barrier.srcQueueFamilyIndex = srcQueueFamilyIndex; |
| 596 | barrier.dstQueueFamilyIndex = dstQueueFamilyIndex; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 597 | return barrier; |
| 598 | } |
| 599 | |
Jeremy Gebben | 1db6edc | 2021-02-17 15:28:40 -0700 | [diff] [blame] | 600 | VkImageMemoryBarrier2KHR image_memory_barrier(VkPipelineStageFlags2KHR src_stage, VkPipelineStageFlags2KHR dst_stage, |
| 601 | VkAccessFlags2KHR src_access, VkAccessFlags2KHR dst_access, |
| 602 | VkImageLayout old_layout, VkImageLayout new_layout, |
| 603 | const VkImageSubresourceRange &range, |
| 604 | uint32_t srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, |
| 605 | uint32_t dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED) const { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 606 | VkImageMemoryBarrier2KHR barrier = LvlInitStruct<VkImageMemoryBarrier2KHR>(); |
Jeremy Gebben | 1db6edc | 2021-02-17 15:28:40 -0700 | [diff] [blame] | 607 | barrier.srcStageMask = src_stage; |
| 608 | barrier.dstStageMask = dst_stage; |
| 609 | barrier.srcAccessMask = src_access; |
| 610 | barrier.dstAccessMask = dst_access; |
| 611 | barrier.oldLayout = old_layout; |
| 612 | barrier.newLayout = new_layout; |
| 613 | barrier.image = handle(); |
| 614 | barrier.subresourceRange = range; |
| 615 | barrier.srcQueueFamilyIndex = srcQueueFamilyIndex; |
| 616 | barrier.dstQueueFamilyIndex = dstQueueFamilyIndex; |
| 617 | return barrier; |
| 618 | } |
| 619 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 620 | static VkImageCreateInfo create_info(); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 621 | static VkImageSubresource subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer); |
| 622 | static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer); |
| 623 | static VkImageSubresourceLayers subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 624 | uint32_t array_size); |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 625 | static VkImageSubresourceLayers subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, |
| 626 | uint32_t array_size); |
| 627 | static VkImageSubresourceRange subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, uint32_t mip_levels, |
| 628 | uint32_t base_array_layer, uint32_t num_layers); |
| 629 | static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask); |
| 630 | static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 631 | |
John Zulauf | 5e01c4a | 2022-07-25 18:00:18 -0600 | [diff] [blame] | 632 | static VkImageAspectFlags aspect_mask(VkFormat format); |
| 633 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 634 | static VkExtent2D extent(int32_t width, int32_t height); |
| 635 | static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level); |
| 636 | static VkExtent2D extent(const VkExtent3D &extent); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 637 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 638 | static VkExtent3D extent(int32_t width, int32_t height, int32_t depth); |
| 639 | static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 640 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 641 | private: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 642 | void init_info(const Device &dev, const VkImageCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 643 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 644 | VkImageCreateInfo create_info_; |
| 645 | VkFlags format_features_; |
Chia-I Wu | 681d7a0 | 2015-07-03 13:44:34 +0800 | [diff] [blame] | 646 | |
| 647 | DeviceMemory internal_mem_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 648 | }; |
| 649 | |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 650 | class ImageView : public internal::NonDispHandle<VkImageView> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 651 | public: |
Nathaniel Cesario | 2bb759a | 2021-10-28 18:16:54 -0600 | [diff] [blame] | 652 | explicit ImageView() = default; |
| 653 | explicit ImageView(const Device &dev, const VkImageViewCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 654 | ~ImageView() noexcept; |
Chia-I Wu | 3158bf3 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 655 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 656 | // vkCreateImageView() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 657 | void init(const Device &dev, const VkImageViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 658 | }; |
| 659 | |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 660 | class AccelerationStructure : public internal::NonDispHandle<VkAccelerationStructureNV> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 661 | public: |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 662 | explicit AccelerationStructure(const Device &dev, const VkAccelerationStructureCreateInfoNV &info, bool init_memory = true) { |
| 663 | init(dev, info, init_memory); |
| 664 | } |
| 665 | ~AccelerationStructure(); |
| 666 | |
| 667 | // vkCreateAccelerationStructureNV |
| 668 | void init(const Device &dev, const VkAccelerationStructureCreateInfoNV &info, bool init_memory = true); |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 669 | // vkGetAccelerationStructureMemoryRequirementsNV() |
sourav parmar | bb9d8f8 | 2020-07-17 13:01:41 -0700 | [diff] [blame] | 670 | VkMemoryRequirements2 memory_requirements() const; |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 671 | VkMemoryRequirements2 build_scratch_memory_requirements() const; |
| 672 | |
Jason Macnak | e4b41ca | 2019-07-11 11:05:31 -0700 | [diff] [blame] | 673 | uint64_t opaque_handle() const { return opaque_handle_; } |
| 674 | |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 675 | const VkAccelerationStructureInfoNV &info() const { return info_; } |
| 676 | |
| 677 | const VkDevice &dev() const { return device(); } |
| 678 | |
Tony-LunarG | 2c0a972 | 2022-07-13 15:17:17 -0600 | [diff] [blame] | 679 | void create_scratch_buffer(const Device &dev, Buffer *buffer, VkBufferCreateInfo *pCreateInfo = NULL, |
| 680 | bool buffer_device_address = false); |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 681 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 682 | private: |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 683 | VkAccelerationStructureInfoNV info_; |
| 684 | DeviceMemory memory_; |
Jason Macnak | e4b41ca | 2019-07-11 11:05:31 -0700 | [diff] [blame] | 685 | uint64_t opaque_handle_; |
sourav parmar | bb9d8f8 | 2020-07-17 13:01:41 -0700 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | class AccelerationStructureKHR : public internal::NonDispHandle<VkAccelerationStructureKHR> { |
| 689 | public: |
| 690 | explicit AccelerationStructureKHR(const Device &dev, const VkAccelerationStructureCreateInfoKHR &info, |
| 691 | bool init_memory = true) { |
| 692 | init(dev, info, init_memory); |
| 693 | } |
| 694 | ~AccelerationStructureKHR(); |
| 695 | // vkCreateAccelerationStructureNV |
| 696 | void init(const Device &dev, const VkAccelerationStructureCreateInfoKHR &info, bool init_memory = true); |
| 697 | uint64_t opaque_handle() const { return opaque_handle_; } |
| 698 | |
| 699 | const VkAccelerationStructureCreateInfoKHR &info() const { return info_; } |
| 700 | |
| 701 | const VkDevice &dev() const { return device(); } |
| 702 | |
Tony-LunarG | 2c0a972 | 2022-07-13 15:17:17 -0600 | [diff] [blame] | 703 | void create_scratch_buffer(const Device &dev, Buffer *buffer, VkBufferCreateInfo *pCreateInfo = NULL, |
| 704 | bool buffer_device_address = false); |
sourav parmar | bb9d8f8 | 2020-07-17 13:01:41 -0700 | [diff] [blame] | 705 | |
| 706 | private: |
| 707 | VkAccelerationStructureCreateInfoKHR info_; |
| 708 | DeviceMemory memory_; |
| 709 | uint64_t opaque_handle_; |
Jason Macnak | d218cba | 2019-07-09 15:47:02 -0700 | [diff] [blame] | 710 | }; |
| 711 | |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 712 | class ShaderModule : public internal::NonDispHandle<VkShaderModule> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 713 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 714 | ~ShaderModule() noexcept; |
Chia-I Wu | 4d0c792 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 715 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 716 | // vkCreateShaderModule() |
| 717 | void init(const Device &dev, const VkShaderModuleCreateInfo &info); |
| 718 | VkResult init_try(const Device &dev, const VkShaderModuleCreateInfo &info); |
| 719 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 720 | static VkShaderModuleCreateInfo create_info(size_t code_size, const uint32_t *code, VkFlags flags); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 721 | }; |
| 722 | |
Chia-I Wu | 2ff72fd | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 723 | class Pipeline : public internal::NonDispHandle<VkPipeline> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 724 | public: |
Nathaniel Cesario | c8c11c1 | 2022-02-16 17:23:50 -0700 | [diff] [blame] | 725 | Pipeline() = default; |
| 726 | Pipeline(const Device &dev, const VkGraphicsPipelineCreateInfo &info) { init(dev, info); } |
| 727 | Pipeline(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline) { |
| 728 | init(dev, info, basePipeline); |
| 729 | } |
| 730 | Pipeline(const Device &dev, const VkComputePipelineCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 731 | ~Pipeline() noexcept; |
Chia-I Wu | 2ff72fd | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 732 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 733 | // vkCreateGraphicsPipeline() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 734 | void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 735 | // vkCreateGraphicsPipelineDerivative() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 736 | void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 737 | // vkCreateComputePipeline() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 738 | void init(const Device &dev, const VkComputePipelineCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 739 | // vkLoadPipeline() |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 740 | void init(const Device &dev, size_t size, const void *data); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 741 | // vkLoadPipelineDerivative() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 742 | void init(const Device &dev, size_t size, const void *data, VkPipeline basePipeline); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 743 | |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 744 | // vkCreateGraphicsPipeline with error return |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 745 | VkResult init_try(const Device &dev, const VkGraphicsPipelineCreateInfo &info); |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 746 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 747 | // vkStorePipeline() |
| 748 | size_t store(size_t size, void *data); |
| 749 | }; |
| 750 | |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 751 | class PipelineLayout : public internal::NonDispHandle<VkPipelineLayout> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 752 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 753 | PipelineLayout() noexcept : NonDispHandle() {} |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 754 | PipelineLayout(const Device &dev, VkPipelineLayoutCreateInfo &info, |
| 755 | const std::vector<const DescriptorSetLayout *> &layouts = {}) { |
Nathaniel Cesario | c19c8b7 | 2022-03-10 23:01:21 -0700 | [diff] [blame] | 756 | init(dev, info, layouts); |
| 757 | } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 758 | ~PipelineLayout() noexcept; |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 759 | |
Mike Schuchardt | 0bc8e7a | 2018-01-02 14:39:51 -0700 | [diff] [blame] | 760 | // Move constructor for Visual Studio 2013 |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 761 | PipelineLayout(PipelineLayout &&src) noexcept : NonDispHandle(std::move(src)){}; |
Mike Schuchardt | 0bc8e7a | 2018-01-02 14:39:51 -0700 | [diff] [blame] | 762 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 763 | PipelineLayout &operator=(PipelineLayout &&src) noexcept { |
Petr Kraus | 65ccc88 | 2017-12-03 15:36:03 +0100 | [diff] [blame] | 764 | this->~PipelineLayout(); |
| 765 | this->NonDispHandle::operator=(std::move(src)); |
| 766 | return *this; |
| 767 | }; |
| 768 | |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 769 | // vCreatePipelineLayout() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 770 | void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts); |
Chia-I Wu | fd46e7d | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 771 | }; |
| 772 | |
Chia-I Wu | 8c721c6 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 773 | class Sampler : public internal::NonDispHandle<VkSampler> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 774 | public: |
Nathaniel Cesario | 5ce41fe | 2022-06-07 13:37:08 -0600 | [diff] [blame] | 775 | Sampler() = default; |
| 776 | Sampler(const Device &dev, const VkSamplerCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 777 | ~Sampler() noexcept; |
Chia-I Wu | 8c721c6 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 778 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 779 | // vkCreateSampler() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 780 | void init(const Device &dev, const VkSamplerCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 781 | }; |
| 782 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 783 | class DescriptorSetLayout : public internal::NonDispHandle<VkDescriptorSetLayout> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 784 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 785 | DescriptorSetLayout() noexcept : NonDispHandle(){}; |
Nathaniel Cesario | c19c8b7 | 2022-03-10 23:01:21 -0700 | [diff] [blame] | 786 | DescriptorSetLayout(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 787 | ~DescriptorSetLayout() noexcept; |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 788 | |
Mike Schuchardt | 0bc8e7a | 2018-01-02 14:39:51 -0700 | [diff] [blame] | 789 | // Move constructor for Visual Studio 2013 |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 790 | DescriptorSetLayout(DescriptorSetLayout &&src) noexcept : NonDispHandle(std::move(src)){}; |
Mike Schuchardt | 0bc8e7a | 2018-01-02 14:39:51 -0700 | [diff] [blame] | 791 | |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 792 | DescriptorSetLayout &operator=(DescriptorSetLayout &&src) noexcept { |
Petr Kraus | 32ea608 | 2017-12-02 01:02:59 +0100 | [diff] [blame] | 793 | this->~DescriptorSetLayout(); |
| 794 | this->NonDispHandle::operator=(std::move(src)); |
| 795 | return *this; |
| 796 | } |
| 797 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 798 | // vkCreateDescriptorSetLayout() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 799 | void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 800 | }; |
| 801 | |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 802 | class DescriptorPool : public internal::NonDispHandle<VkDescriptorPool> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 803 | public: |
Nathaniel Cesario | 079b1b9 | 2022-07-06 15:56:26 -0600 | [diff] [blame] | 804 | DescriptorPool() = default; |
| 805 | DescriptorPool(const Device &dev, const VkDescriptorPoolCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 806 | ~DescriptorPool() noexcept; |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 807 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 808 | // Descriptor sets allocated from this pool will need access to the original |
| 809 | // object |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 810 | VkDescriptorPool GetObj() { return pool_; } |
| 811 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 812 | // vkCreateDescriptorPool() |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 813 | void init(const Device &dev, const VkDescriptorPoolCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 814 | |
| 815 | // vkResetDescriptorPool() |
| 816 | void reset(); |
| 817 | |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 818 | // vkFreeDescriptorSet() |
| 819 | void setDynamicUsage(bool isDynamic) { dynamic_usage_ = isDynamic; } |
| 820 | bool getDynamicUsage() { return dynamic_usage_; } |
| 821 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 822 | // vkAllocateDescriptorSets() |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 823 | std::vector<DescriptorSet *> alloc_sets(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts); |
| 824 | std::vector<DescriptorSet *> alloc_sets(const Device &dev, const DescriptorSetLayout &layout, uint32_t count); |
| 825 | DescriptorSet *alloc_sets(const Device &dev, const DescriptorSetLayout &layout); |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 826 | |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 827 | template <typename PoolSizes> |
| 828 | static VkDescriptorPoolCreateInfo create_info(VkDescriptorPoolCreateFlags flags, uint32_t max_sets, |
| 829 | const PoolSizes &pool_sizes); |
| 830 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 831 | private: |
Cody Northrop | cdc72a4 | 2015-10-08 11:39:25 -0600 | [diff] [blame] | 832 | VkDescriptorPool pool_; |
| 833 | |
| 834 | // Track whether this pool's usage is VK_DESCRIPTOR_POOL_USAGE_DYNAMIC |
| 835 | bool dynamic_usage_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 836 | }; |
| 837 | |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 838 | template <typename PoolSizes> |
| 839 | inline VkDescriptorPoolCreateInfo DescriptorPool::create_info(VkDescriptorPoolCreateFlags flags, uint32_t max_sets, |
| 840 | const PoolSizes &pool_sizes) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 841 | VkDescriptorPoolCreateInfo info = LvlInitStruct<VkDescriptorPoolCreateInfo>(); |
John Zulauf | cde9d7d | 2018-01-18 16:53:07 -0700 | [diff] [blame] | 842 | info.flags = flags; |
| 843 | info.maxSets = max_sets; |
| 844 | info.poolSizeCount = pool_sizes.size(); |
| 845 | info.pPoolSizes = (info.poolSizeCount) ? pool_sizes.data() : nullptr; |
| 846 | return info; |
| 847 | } |
| 848 | |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 849 | class DescriptorSet : public internal::NonDispHandle<VkDescriptorSet> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 850 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 851 | ~DescriptorSet() noexcept; |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 852 | |
| 853 | explicit DescriptorSet() : NonDispHandle() {} |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 854 | explicit DescriptorSet(const Device &dev, DescriptorPool *pool, VkDescriptorSet set) : NonDispHandle(dev.handle(), set) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 855 | containing_pool_ = pool; |
| 856 | } |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 857 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 858 | private: |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 859 | DescriptorPool *containing_pool_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 860 | }; |
| 861 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 862 | class CommandPool : public internal::NonDispHandle<VkCommandPool> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 863 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 864 | ~CommandPool() noexcept; |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 865 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 866 | explicit CommandPool() : NonDispHandle() {} |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 867 | explicit CommandPool(const Device &dev, const VkCommandPoolCreateInfo &info) { init(dev, info); } |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 868 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 869 | void init(const Device &dev, const VkCommandPoolCreateInfo &info); |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 870 | |
Mike Schuchardt | 06304c2 | 2017-03-01 17:09:09 -0700 | [diff] [blame] | 871 | static VkCommandPoolCreateInfo create_info(uint32_t queue_family_index, VkCommandPoolCreateFlags flags); |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 872 | }; |
| 873 | |
Mike Schuchardt | 06304c2 | 2017-03-01 17:09:09 -0700 | [diff] [blame] | 874 | inline VkCommandPoolCreateInfo CommandPool::create_info(uint32_t queue_family_index, VkCommandPoolCreateFlags flags) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 875 | VkCommandPoolCreateInfo info = LvlInitStruct<VkCommandPoolCreateInfo>(); |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 876 | info.queueFamilyIndex = queue_family_index; |
Mike Schuchardt | 06304c2 | 2017-03-01 17:09:09 -0700 | [diff] [blame] | 877 | info.flags = flags; |
Courtney Goeltzenleuchter | ee5d80b | 2015-07-10 19:50:17 -0600 | [diff] [blame] | 878 | return info; |
| 879 | } |
| 880 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 881 | class CommandBuffer : public internal::Handle<VkCommandBuffer> { |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 882 | public: |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 883 | ~CommandBuffer() noexcept; |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 884 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 885 | explicit CommandBuffer() : Handle() {} |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 886 | explicit CommandBuffer(const Device &dev, const VkCommandBufferAllocateInfo &info) { init(dev, info); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 887 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 888 | // vkAllocateCommandBuffers() |
| 889 | void init(const Device &dev, const VkCommandBufferAllocateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 890 | |
| 891 | // vkBeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 892 | void begin(const VkCommandBufferBeginInfo *info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 893 | void begin(); |
| 894 | |
| 895 | // vkEndCommandBuffer() |
| 896 | // vkResetCommandBuffer() |
| 897 | void end(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 898 | void reset(VkCommandBufferResetFlags flags); |
| 899 | void reset() { reset(VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 900 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 901 | static VkCommandBufferAllocateInfo create_info(VkCommandPool const &pool); |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 902 | |
Petr Kraus | 4ed81e3 | 2019-09-02 23:41:19 +0200 | [diff] [blame] | 903 | private: |
Chia-I Wu | be2b917 | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 904 | VkDevice dev_handle_; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 905 | VkCommandPool cmd_pool_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 906 | }; |
| 907 | |
Jeremy Gebben | 76d2de3 | 2021-08-13 13:26:59 -0600 | [diff] [blame] | 908 | class RenderPass : public internal::NonDispHandle<VkRenderPass> { |
| 909 | public: |
Nathaniel Cesario | b3f17dc | 2021-08-17 12:52:22 -0600 | [diff] [blame] | 910 | RenderPass() = default; |
| 911 | RenderPass(const Device &dev, const VkRenderPassCreateInfo &info) { init(dev, info); } |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 912 | RenderPass(const Device &dev, const VkRenderPassCreateInfo2 &info, bool khr = false) { init(dev, info, khr); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 913 | ~RenderPass() noexcept; |
Jeremy Gebben | 76d2de3 | 2021-08-13 13:26:59 -0600 | [diff] [blame] | 914 | |
| 915 | // vkCreateRenderPass() |
| 916 | void init(const Device &dev, const VkRenderPassCreateInfo &info); |
ziga-lunarg | 2fd0e8f | 2022-05-09 20:59:11 +0200 | [diff] [blame] | 917 | // vkCreateRenderPass2() |
Nathaniel Cesario | 0d50bcf | 2022-06-21 10:30:04 -0600 | [diff] [blame] | 918 | void init(const Device &dev, const VkRenderPassCreateInfo2 &info, bool khr = false); |
Jeremy Gebben | 76d2de3 | 2021-08-13 13:26:59 -0600 | [diff] [blame] | 919 | }; |
| 920 | |
| 921 | |
| 922 | class Framebuffer : public internal::NonDispHandle<VkFramebuffer> { |
| 923 | public: |
Nathaniel Cesario | b3f17dc | 2021-08-17 12:52:22 -0600 | [diff] [blame] | 924 | Framebuffer() = default; |
| 925 | Framebuffer(const Device &dev, const VkFramebufferCreateInfo &info) { init(dev, info); } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 926 | ~Framebuffer() noexcept; |
Jeremy Gebben | 76d2de3 | 2021-08-13 13:26:59 -0600 | [diff] [blame] | 927 | |
| 928 | // vkCreateFramebuffer() |
| 929 | void init(const Device &dev, const VkFramebufferCreateInfo &info); |
| 930 | }; |
| 931 | |
paul-lunarg | b645413 | 2022-07-13 10:00:39 -0600 | [diff] [blame] | 932 | class SamplerYcbcrConversion : public internal::NonDispHandle<VkSamplerYcbcrConversion> { |
| 933 | public: |
| 934 | SamplerYcbcrConversion() = default; |
| 935 | SamplerYcbcrConversion(const Device &dev, VkFormat format, bool khr) : khr_(khr) { |
| 936 | init(dev, DefaultConversionInfo(format), khr); |
| 937 | } |
| 938 | SamplerYcbcrConversion(const Device &dev, const VkSamplerYcbcrConversionCreateInfo &info, bool khr) : khr_(khr) { |
| 939 | init(dev, info, khr); |
| 940 | } |
Jeremy Gebben | a4fc674 | 2022-09-15 14:57:30 -0600 | [diff] [blame] | 941 | ~SamplerYcbcrConversion() noexcept; |
paul-lunarg | b645413 | 2022-07-13 10:00:39 -0600 | [diff] [blame] | 942 | |
| 943 | void init(const Device &dev, const VkSamplerYcbcrConversionCreateInfo &info, bool khr); |
| 944 | VkSamplerYcbcrConversionInfo ConversionInfo(); |
| 945 | |
| 946 | static VkSamplerYcbcrConversionCreateInfo DefaultConversionInfo(VkFormat format); |
| 947 | |
| 948 | bool khr_ = false; |
| 949 | }; |
| 950 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 951 | inline VkMemoryAllocateInfo DeviceMemory::alloc_info(VkDeviceSize size, uint32_t memory_type_index) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 952 | VkMemoryAllocateInfo info = LvlInitStruct<VkMemoryAllocateInfo>(); |
Chia-I Wu | f8f074f | 2015-07-03 10:58:57 +0800 | [diff] [blame] | 953 | info.allocationSize = size; |
| 954 | info.memoryTypeIndex = memory_type_index; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 955 | return info; |
| 956 | } |
| 957 | |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 958 | inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage, const std::vector<uint32_t> *queue_families) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 959 | VkBufferCreateInfo info = LvlInitStruct<VkBufferCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 960 | info.size = size; |
| 961 | info.usage = usage; |
John Zulauf | 3d92b72 | 2018-01-16 11:15:15 -0700 | [diff] [blame] | 962 | |
| 963 | if (queue_families && queue_families->size() > 1) { |
| 964 | info.sharingMode = VK_SHARING_MODE_CONCURRENT; |
| 965 | info.queueFamilyIndexCount = static_cast<uint32_t>(queue_families->size()); |
| 966 | info.pQueueFamilyIndices = queue_families->data(); |
| 967 | } |
| 968 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 969 | return info; |
| 970 | } |
| 971 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 972 | inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 973 | VkFenceCreateInfo info = LvlInitStruct<VkFenceCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 974 | info.flags = flags; |
| 975 | return info; |
| 976 | } |
| 977 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 978 | inline VkFenceCreateInfo Fence::create_info() { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 979 | VkFenceCreateInfo info = LvlInitStruct<VkFenceCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 980 | return info; |
| 981 | } |
| 982 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 983 | inline VkSemaphoreCreateInfo Semaphore::create_info(VkFlags flags) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 984 | VkSemaphoreCreateInfo info = LvlInitStruct<VkSemaphoreCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 985 | info.flags = flags; |
| 986 | return info; |
| 987 | } |
| 988 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 989 | inline VkEventCreateInfo Event::create_info(VkFlags flags) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 990 | VkEventCreateInfo info = LvlInitStruct<VkEventCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 991 | info.flags = flags; |
| 992 | return info; |
| 993 | } |
| 994 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 995 | inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 996 | VkQueryPoolCreateInfo info = LvlInitStruct<VkQueryPoolCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 997 | info.queryType = type; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 998 | info.queryCount = slot_count; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 999 | return info; |
| 1000 | } |
| 1001 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1002 | inline VkImageCreateInfo Image::create_info() { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1003 | VkImageCreateInfo info = LvlInitStruct<VkImageCreateInfo>(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1004 | info.extent.width = 1; |
| 1005 | info.extent.height = 1; |
| 1006 | info.extent.depth = 1; |
| 1007 | info.mipLevels = 1; |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 1008 | info.arrayLayers = 1; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 1009 | info.samples = VK_SAMPLE_COUNT_1_BIT; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1010 | return info; |
| 1011 | } |
| 1012 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1013 | inline VkImageSubresource Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1014 | VkImageSubresource subres = {}; |
Karl Schultz | 0ab73f8 | 2016-03-29 12:41:24 -0600 | [diff] [blame] | 1015 | if (aspect == 0) { |
Nathaniel Cesario | 7e35129 | 2022-05-12 14:47:07 -0600 | [diff] [blame] | 1016 | assert(false && "Invalid VkImageAspectFlags"); |
Karl Schultz | 0ab73f8 | 2016-03-29 12:41:24 -0600 | [diff] [blame] | 1017 | } |
Chia-I Wu | 52b07e7 | 2015-10-27 19:55:05 +0800 | [diff] [blame] | 1018 | subres.aspectMask = aspect; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1019 | subres.mipLevel = mip_level; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 1020 | subres.arrayLayer = array_layer; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1021 | return subres; |
| 1022 | } |
| 1023 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1024 | inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer) { |
| 1025 | return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1026 | } |
| 1027 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1028 | inline VkImageSubresourceLayers Image::subresource(VkImageAspectFlags aspect, uint32_t mip_level, uint32_t array_layer, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1029 | uint32_t array_size) { |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 1030 | VkImageSubresourceLayers subres = {}; |
Karl Schultz | 0ab73f8 | 2016-03-29 12:41:24 -0600 | [diff] [blame] | 1031 | switch (aspect) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1032 | case VK_IMAGE_ASPECT_COLOR_BIT: |
| 1033 | case VK_IMAGE_ASPECT_DEPTH_BIT: |
| 1034 | case VK_IMAGE_ASPECT_STENCIL_BIT: |
| 1035 | case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT: |
| 1036 | /* valid */ |
| 1037 | break; |
| 1038 | default: |
Nathaniel Cesario | 7e35129 | 2022-05-12 14:47:07 -0600 | [diff] [blame] | 1039 | assert(false && "Invalid VkImageAspectFlags"); |
Karl Schultz | 0ab73f8 | 2016-03-29 12:41:24 -0600 | [diff] [blame] | 1040 | } |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 1041 | subres.aspectMask = aspect; |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 1042 | subres.mipLevel = mip_level; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 1043 | subres.baseArrayLayer = array_layer; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1044 | subres.layerCount = array_size; |
Courtney Goeltzenleuchter | 01ee1ca | 2015-09-10 16:41:13 -0600 | [diff] [blame] | 1045 | return subres; |
| 1046 | } |
| 1047 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1048 | inline VkImageSubresourceLayers Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_layer, |
| 1049 | uint32_t array_size) { |
| 1050 | return subresource(range.aspectMask, range.baseMipLevel + mip_level, range.baseArrayLayer + array_layer, array_size); |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 1051 | } |
| 1052 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1053 | inline VkImageSubresourceRange Image::subresource_range(VkImageAspectFlags aspect_mask, uint32_t base_mip_level, |
| 1054 | uint32_t mip_levels, uint32_t base_array_layer, uint32_t num_layers) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1055 | VkImageSubresourceRange range = {}; |
Karl Schultz | 0ab73f8 | 2016-03-29 12:41:24 -0600 | [diff] [blame] | 1056 | if (aspect_mask == 0) { |
Nathaniel Cesario | 7e35129 | 2022-05-12 14:47:07 -0600 | [diff] [blame] | 1057 | assert(false && "Invalid VkImageAspectFlags"); |
Karl Schultz | 0ab73f8 | 2016-03-29 12:41:24 -0600 | [diff] [blame] | 1058 | } |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 1059 | range.aspectMask = aspect_mask; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1060 | range.baseMipLevel = base_mip_level; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1061 | range.levelCount = mip_levels; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 1062 | range.baseArrayLayer = base_array_layer; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1063 | range.layerCount = num_layers; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1064 | return range; |
| 1065 | } |
| 1066 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1067 | inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspectFlags aspect_mask) { |
| 1068 | return subresource_range(aspect_mask, 0, info.mipLevels, 0, info.arrayLayers); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1069 | } |
| 1070 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1071 | inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres) { |
| 1072 | return subresource_range(subres.aspectMask, subres.mipLevel, 1, subres.arrayLayer, 1); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1073 | } |
| 1074 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1075 | inline VkExtent2D Image::extent(int32_t width, int32_t height) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1076 | VkExtent2D extent = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1077 | extent.width = width; |
| 1078 | extent.height = height; |
| 1079 | return extent; |
| 1080 | } |
| 1081 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1082 | inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1083 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 1084 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1085 | return Image::extent(width, height); |
| 1086 | } |
| 1087 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1088 | inline VkExtent2D Image::extent(const VkExtent3D &extent) { return Image::extent(extent.width, extent.height); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1089 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1090 | inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1091 | VkExtent3D extent = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1092 | extent.width = width; |
| 1093 | extent.height = height; |
| 1094 | extent.depth = depth; |
| 1095 | return extent; |
| 1096 | } |
| 1097 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1098 | inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level) { |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1099 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 1100 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 1101 | const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1102 | return Image::extent(width, height, depth); |
| 1103 | } |
| 1104 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1105 | inline VkShaderModuleCreateInfo ShaderModule::create_info(size_t code_size, const uint32_t *code, VkFlags flags) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1106 | VkShaderModuleCreateInfo info = LvlInitStruct<VkShaderModuleCreateInfo>(); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1107 | info.codeSize = code_size; |
| 1108 | info.pCode = code; |
| 1109 | info.flags = flags; |
| 1110 | return info; |
| 1111 | } |
| 1112 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1113 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 1114 | VkDescriptorType type, uint32_t count, |
| 1115 | const VkDescriptorImageInfo *image_info) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1116 | VkWriteDescriptorSet write = LvlInitStruct<VkWriteDescriptorSet>(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1117 | write.dstSet = set.handle(); |
| 1118 | write.dstBinding = binding; |
| 1119 | write.dstArrayElement = array_element; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1120 | write.descriptorCount = count; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1121 | write.descriptorType = type; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 1122 | write.pImageInfo = image_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1123 | return write; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1124 | } |
| 1125 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1126 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 1127 | VkDescriptorType type, uint32_t count, |
| 1128 | const VkDescriptorBufferInfo *buffer_info) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1129 | VkWriteDescriptorSet write = LvlInitStruct<VkWriteDescriptorSet>(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1130 | write.dstSet = set.handle(); |
| 1131 | write.dstBinding = binding; |
| 1132 | write.dstArrayElement = array_element; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1133 | write.descriptorCount = count; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 1134 | write.descriptorType = type; |
| 1135 | write.pBufferInfo = buffer_info; |
| 1136 | return write; |
| 1137 | } |
| 1138 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1139 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 1140 | VkDescriptorType type, uint32_t count, const VkBufferView *buffer_views) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1141 | VkWriteDescriptorSet write = LvlInitStruct<VkWriteDescriptorSet>(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1142 | write.dstSet = set.handle(); |
| 1143 | write.dstBinding = binding; |
| 1144 | write.dstArrayElement = array_element; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1145 | write.descriptorCount = count; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 1146 | write.descriptorType = type; |
| 1147 | write.pTexelBufferView = buffer_views; |
| 1148 | return write; |
| 1149 | } |
| 1150 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1151 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 1152 | VkDescriptorType type, |
| 1153 | const std::vector<VkDescriptorImageInfo> &image_info) { |
| 1154 | return write_descriptor_set(set, binding, array_element, type, image_info.size(), &image_info[0]); |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 1155 | } |
| 1156 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1157 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 1158 | VkDescriptorType type, |
| 1159 | const std::vector<VkDescriptorBufferInfo> &buffer_info) { |
| 1160 | return write_descriptor_set(set, binding, array_element, type, buffer_info.size(), &buffer_info[0]); |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 1161 | } |
| 1162 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1163 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 1164 | VkDescriptorType type, const std::vector<VkBufferView> &buffer_views) { |
| 1165 | return write_descriptor_set(set, binding, array_element, type, buffer_views.size(), &buffer_views[0]); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1166 | } |
| 1167 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1168 | inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, |
| 1169 | uint32_t src_array_element, const DescriptorSet &dst_set, |
| 1170 | uint32_t dst_binding, uint32_t dst_array_element, uint32_t count) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1171 | VkCopyDescriptorSet copy = LvlInitStruct<VkCopyDescriptorSet>(); |
Chia-I Wu | afdfd7f | 2015-07-03 11:49:42 +0800 | [diff] [blame] | 1172 | copy.srcSet = src_set.handle(); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1173 | copy.srcBinding = src_binding; |
| 1174 | copy.srcArrayElement = src_array_element; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1175 | copy.dstSet = dst_set.handle(); |
| 1176 | copy.dstBinding = dst_binding; |
| 1177 | copy.dstArrayElement = dst_array_element; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1178 | copy.descriptorCount = count; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1179 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1180 | return copy; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1181 | } |
| 1182 | |
Mark Lobodzinski | 722841d | 2016-09-07 16:34:56 -0600 | [diff] [blame] | 1183 | inline VkCommandBufferAllocateInfo CommandBuffer::create_info(VkCommandPool const &pool) { |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 1184 | VkCommandBufferAllocateInfo info = LvlInitStruct<VkCommandBufferAllocateInfo>(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1185 | info.commandPool = pool; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1186 | info.commandBufferCount = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1187 | return info; |
| 1188 | } |
| 1189 | |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1190 | } // namespace vk_testing |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1191 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1192 | #endif // VKTESTBINDING_H |