Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | // VK tests |
| 2 | // |
| 3 | // Copyright (C) 2014 LunarG, Inc. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | // copy of this software and associated documentation files (the "Software"), |
| 7 | // to deal in the Software without restriction, including without limitation |
| 8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | // and/or sell copies of the Software, and to permit persons to whom the |
| 10 | // Software is furnished to do so, subject to the following conditions: |
| 11 | // |
| 12 | // The above copyright notice and this permission notice shall be included |
| 13 | // in all copies or substantial portions of the Software. |
| 14 | // |
| 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | // DEALINGS IN THE SOFTWARE. |
| 22 | |
| 23 | #ifndef VKTESTBINDING_H |
| 24 | #define VKTESTBINDING_H |
| 25 | |
| 26 | #include <vector> |
| 27 | |
| 28 | #include "vulkan.h" |
| 29 | |
| 30 | namespace vk_testing { |
| 31 | |
| 32 | typedef void (*ErrorCallback)(const char *expr, const char *file, unsigned int line, const char *function); |
| 33 | void set_error_callback(ErrorCallback callback); |
| 34 | |
| 35 | class PhysicalGpu; |
| 36 | class BaseObject; |
| 37 | class Object; |
| 38 | class DynamicStateObject; |
| 39 | class Device; |
| 40 | class Queue; |
| 41 | class GpuMemory; |
| 42 | class Fence; |
| 43 | class Semaphore; |
| 44 | class Event; |
| 45 | class QueryPool; |
| 46 | class Buffer; |
| 47 | class BufferView; |
| 48 | class Image; |
| 49 | class ImageView; |
| 50 | class ColorAttachmentView; |
| 51 | class DepthStencilView; |
| 52 | class Shader; |
| 53 | class Pipeline; |
| 54 | class PipelineDelta; |
| 55 | class Sampler; |
| 56 | class DescriptorSetLayout; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 57 | class PipelineLayout; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 58 | class DescriptorSetPool; |
| 59 | class DescriptorSet; |
| 60 | class DynamicVpStateObject; |
| 61 | class DynamicRsStateObject; |
| 62 | class DynamicMsaaStateObject; |
| 63 | class DynamicCbStateObject; |
| 64 | class DynamicDsStateObject; |
| 65 | class CmdBuffer; |
| 66 | |
| 67 | class PhysicalGpu { |
| 68 | public: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 69 | explicit PhysicalGpu(VkPhysicalDevice gpu) : gpu_(gpu) {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 70 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 71 | const VkPhysicalDevice &obj() const { return gpu_; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 72 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 73 | // vkGetPhysicalDeviceInfo() |
| 74 | VkPhysicalDeviceProperties properties() const; |
| 75 | VkPhysicalDevicePerformance performance() const; |
| 76 | VkPhysicalDeviceMemoryProperties memory_properties() const; |
| 77 | std::vector<VkPhysicalDeviceQueueProperties> queue_properties() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 78 | |
| 79 | // vkGetProcAddr() |
| 80 | void *get_proc(const char *name) const { return vkGetProcAddr(gpu_, name); } |
| 81 | |
Tobin Ehlis | 3dd031b | 2015-04-16 10:13:25 -0600 | [diff] [blame] | 82 | // vkGetGlobalExtensionInfo() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 83 | std::vector<const char *> extensions() const; |
| 84 | |
| 85 | // vkEnumerateLayers() |
| 86 | std::vector<const char *> layers(std::vector<char> &buf) const; |
| 87 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 88 | // vkGetMultiDeviceCompatibility() |
| 89 | VkPhysicalDeviceCompatibilityInfo compatibility(const PhysicalGpu &other) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 90 | |
| 91 | private: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 92 | VkPhysicalDevice gpu_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | class BaseObject { |
| 96 | public: |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 97 | const VkObject &obj() const { return obj_; } |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 98 | VkObjectType type() const { return object_type_; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 99 | bool initialized() const { return (obj_ != VK_NULL_HANDLE); } |
| 100 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 101 | protected: |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 102 | explicit BaseObject() : |
| 103 | object_type_((VkObjectType) 0), obj_(VK_NULL_HANDLE), own_obj_(false){} |
| 104 | explicit BaseObject(VkObject obj, VkObjectType object_type) : |
| 105 | object_type_(object_type), obj_(obj), own_obj_(false){} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 106 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 107 | void init(VkObject obj, VkObjectType object_type, bool own); |
| 108 | void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 109 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 110 | void reinit(VkObject obj, VkObjectType object_type, bool own); |
| 111 | void reinit(VkObject obj, VkObjectType object_type) { reinit(obj, object_type, true); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 112 | |
| 113 | bool own() const { return own_obj_; } |
| 114 | |
| 115 | private: |
| 116 | // base objects are non-copyable |
| 117 | BaseObject(const BaseObject &); |
| 118 | BaseObject &operator=(const BaseObject &); |
| 119 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 120 | VkObjectType object_type_; |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 121 | VkObject obj_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | bool own_obj_; |
| 123 | }; |
| 124 | |
| 125 | class Object : public BaseObject { |
| 126 | public: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 127 | const VkObject &obj() const { return reinterpret_cast<const VkObject &>(BaseObject::obj()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 128 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 129 | // vkGetObjectInfo() |
| 130 | uint32_t memory_allocation_count() const; |
| 131 | std::vector<VkMemoryRequirements> memory_requirements() const; |
| 132 | |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 133 | // vkBindObjectMemory() |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 134 | void bind_memory(const GpuMemory &mem, VkDeviceSize mem_offset); |
Courtney Goeltzenleuchter | 30a3945 | 2015-04-22 10:02:41 -0600 | [diff] [blame] | 135 | void unbind_memory(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 136 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 137 | // Unless an object is initialized with init_no_mem(), memories are |
Courtney Goeltzenleuchter | b66f5fd | 2015-05-01 17:56:13 -0600 | [diff] [blame] | 138 | // automatically allocated and bound. These methods can be used to |
| 139 | // map/unmap the primary memory. |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 140 | std::vector<VkDeviceMemory> memories() const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 141 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 142 | const void *map(VkFlags flags) const; |
| 143 | void *map(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 144 | const void *map() const { return map(0); } |
| 145 | void *map() { return map(0); } |
| 146 | |
| 147 | void unmap() const; |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 148 | const Device* dev_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 149 | |
| 150 | protected: |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 151 | explicit Object() : |
| 152 | mem_alloc_count_(0), internal_mems_(NULL), |
| 153 | primary_mem_(NULL), bound(false) {} |
| 154 | explicit Object(const Device &dev, VkObject obj, VkObjectType object_type) : |
| 155 | dev_(&dev), |
| 156 | mem_alloc_count_(0), internal_mems_(NULL), |
Chris Forbes | 94ba49d | 2015-05-25 11:13:03 +1200 | [diff] [blame^] | 157 | primary_mem_(NULL), bound(false) { init(obj, object_type); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 158 | ~Object() { cleanup(); } |
| 159 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 160 | void init(VkObject obj, VkObjectType object_type, bool own); |
| 161 | void init(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 162 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 163 | void reinit(VkObject obj, VkObjectType object_type, bool own); |
| 164 | void reinit(VkObject obj, VkObjectType object_type) { init(obj, object_type, true); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 165 | |
| 166 | // allocate and bind internal memories |
Courtney Goeltzenleuchter | 30a3945 | 2015-04-22 10:02:41 -0600 | [diff] [blame] | 167 | void alloc_memory(); |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 168 | void alloc_memory(VkMemoryPropertyFlags &reqs); |
Courtney Goeltzenleuchter | 30a3945 | 2015-04-22 10:02:41 -0600 | [diff] [blame] | 169 | void alloc_memory(const std::vector<VkDeviceMemory> &mems); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 170 | |
| 171 | private: |
| 172 | void cleanup(); |
| 173 | |
| 174 | uint32_t mem_alloc_count_; |
| 175 | GpuMemory *internal_mems_; |
| 176 | GpuMemory *primary_mem_; |
Tony Barbour | 44bb3ab | 2015-04-09 16:00:18 -0600 | [diff] [blame] | 177 | bool bound; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | class DynamicStateObject : public Object { |
| 181 | public: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 182 | const VkDynamicStateObject &obj() const { return reinterpret_cast<const VkDynamicStateObject &>(Object::obj()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 183 | |
| 184 | protected: |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 185 | explicit DynamicStateObject() : Object() {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 186 | }; |
| 187 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 188 | template<typename T, class C, VkObjectType V> |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 189 | class DerivedObject : public C { |
| 190 | public: |
| 191 | const T &obj() const { return reinterpret_cast<const T &>(C::obj()); } |
| 192 | |
| 193 | protected: |
| 194 | typedef T obj_type; |
| 195 | typedef C base_type; |
| 196 | |
| 197 | explicit DerivedObject() {} |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 198 | explicit DerivedObject(T obj) : C(obj, V) {} |
| 199 | explicit DerivedObject(const Device &dev, T obj) : C(dev, obj, V) {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 200 | }; |
| 201 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 202 | class Device : public DerivedObject<VkDevice, BaseObject, VK_OBJECT_TYPE_DEVICE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 203 | public: |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 204 | explicit Device(VkPhysicalDevice gpu) : gpu_(gpu) {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 205 | ~Device(); |
| 206 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 207 | VkDevice device() const { return obj(); } |
| 208 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 209 | // vkCreateDevice() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 210 | void init(const VkDeviceCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 211 | void init(bool enable_layers); // all queues, all extensions, etc |
| 212 | void init() { init(false); }; |
| 213 | |
| 214 | const PhysicalGpu &gpu() const { return gpu_; } |
| 215 | |
| 216 | // vkGetDeviceQueue() |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 217 | const std::vector<Queue *> &graphics_queues() const { return queues_[GRAPHICS]; } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 218 | const std::vector<Queue *> &compute_queues() { return queues_[COMPUTE]; } |
| 219 | const std::vector<Queue *> &dma_queues() { return queues_[DMA]; } |
| 220 | uint32_t graphics_queue_node_index_; |
| 221 | |
| 222 | struct Format { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 223 | VkFormat format; |
| 224 | VkImageTiling tiling; |
| 225 | VkFlags features; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 226 | }; |
| 227 | // vkGetFormatInfo() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 228 | VkFormatProperties format_properties(VkFormat format); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 229 | const std::vector<Format> &formats() const { return formats_; } |
| 230 | |
| 231 | // vkDeviceWaitIdle() |
| 232 | void wait(); |
| 233 | |
| 234 | // vkWaitForFences() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 235 | VkResult wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout); |
| 236 | 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] | 237 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 238 | // vkUpdateDescriptorSets() |
| 239 | VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes, const std::vector<VkCopyDescriptorSet> &copies); |
| 240 | VkResult update_descriptor_sets(const std::vector<VkWriteDescriptorSet> &writes) { return update_descriptor_sets(writes, std::vector<VkCopyDescriptorSet>()); } |
| 241 | |
| 242 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 243 | VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors); |
| 244 | static VkWriteDescriptorSet write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 245 | VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors); |
| 246 | |
| 247 | static VkCopyDescriptorSet copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element, |
| 248 | const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element, |
| 249 | uint32_t count); |
| 250 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 251 | private: |
| 252 | enum QueueIndex { |
| 253 | GRAPHICS, |
| 254 | COMPUTE, |
| 255 | DMA, |
| 256 | QUEUE_COUNT, |
| 257 | }; |
| 258 | |
| 259 | void init_queues(); |
| 260 | void init_formats(); |
| 261 | |
| 262 | PhysicalGpu gpu_; |
| 263 | |
| 264 | std::vector<Queue *> queues_[QUEUE_COUNT]; |
| 265 | std::vector<Format> formats_; |
| 266 | }; |
| 267 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 268 | class Queue : public DerivedObject<VkQueue, BaseObject, VK_OBJECT_TYPE_QUEUE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 269 | public: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 270 | explicit Queue(VkQueue queue) : DerivedObject(queue) {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 271 | |
| 272 | // vkQueueSubmit() |
| 273 | void submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence); |
| 274 | void submit(const CmdBuffer &cmd, Fence &fence); |
| 275 | void submit(const CmdBuffer &cmd); |
| 276 | |
Courtney Goeltzenleuchter | f68ad72 | 2015-04-16 13:38:46 -0600 | [diff] [blame] | 277 | // vkQueueAddMemReferences() |
| 278 | // vkQueueRemoveMemReferences() |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 279 | void add_mem_references(const std::vector<VkDeviceMemory> &mem_refs); |
| 280 | void remove_mem_references(const std::vector<VkDeviceMemory> &mem_refs); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 281 | |
| 282 | // vkQueueWaitIdle() |
| 283 | void wait(); |
| 284 | |
| 285 | // vkQueueSignalSemaphore() |
| 286 | // vkQueueWaitSemaphore() |
| 287 | void signal_semaphore(Semaphore &sem); |
| 288 | void wait_semaphore(Semaphore &sem); |
| 289 | }; |
| 290 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 291 | /* Note: This needs to be BaseObject so that we don't try to destroy |
| 292 | * the object when the object is device memory. |
| 293 | */ |
| 294 | class GpuMemory : public DerivedObject<VkDeviceMemory, BaseObject, VK_OBJECT_TYPE_DEVICE_MEMORY> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 295 | public: |
| 296 | ~GpuMemory(); |
| 297 | |
| 298 | // vkAllocMemory() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 299 | void init(const Device &dev, const VkMemoryAllocInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 300 | // vkPinSystemMemory() |
| 301 | void init(const Device &dev, size_t size, const void *data); |
| 302 | // vkOpenSharedMemory() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 303 | void init(const Device &dev, const VkMemoryOpenInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 304 | // vkOpenPeerMemory() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 305 | void init(const Device &dev, const VkPeerMemoryOpenInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 306 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 307 | void init(const Device &dev, VkDeviceMemory mem); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | |
| 309 | // vkSetMemoryPriority() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 310 | void set_priority(VkMemoryPriority priority); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 311 | |
| 312 | // vkMapMemory() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 313 | const void *map(VkFlags flags) const; |
| 314 | void *map(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 315 | const void *map() const { return map(0); } |
| 316 | void *map() { return map(0); } |
| 317 | |
| 318 | // vkUnmapMemory() |
| 319 | void unmap() const; |
| 320 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 321 | static VkMemoryAllocInfo alloc_info(const VkMemoryRequirements &reqs, |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 322 | const VkMemoryAllocInfo *next_info); |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 323 | private: |
| 324 | const Device* dev_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 325 | }; |
| 326 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 327 | class Fence : public DerivedObject<VkFence, Object, VK_OBJECT_TYPE_FENCE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | public: |
| 329 | // vkCreateFence() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 330 | void init(const Device &dev, const VkFenceCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | |
| 332 | // vkGetFenceStatus() |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 333 | VkResult status() const { return vkGetFenceStatus(dev_->obj(), obj()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 334 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 335 | static VkFenceCreateInfo create_info(VkFenceCreateFlags flags); |
| 336 | static VkFenceCreateInfo create_info(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 337 | }; |
| 338 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 339 | class Semaphore : public DerivedObject<VkSemaphore, Object, VK_OBJECT_TYPE_SEMAPHORE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 340 | public: |
| 341 | // vkCreateSemaphore() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 342 | void init(const Device &dev, const VkSemaphoreCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 343 | // vkOpenSharedSemaphore() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 344 | void init(const Device &dev, const VkSemaphoreOpenInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 345 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 346 | static VkSemaphoreCreateInfo create_info(uint32_t init_count, VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 347 | }; |
| 348 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 349 | class Event : public DerivedObject<VkEvent, Object, VK_OBJECT_TYPE_EVENT> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 350 | public: |
| 351 | // vkCreateEvent() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 352 | void init(const Device &dev, const VkEventCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 353 | |
| 354 | // vkGetEventStatus() |
| 355 | // vkSetEvent() |
| 356 | // vkResetEvent() |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 357 | VkResult status() const { return vkGetEventStatus(dev_->obj(), obj()); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 358 | void set(); |
| 359 | void reset(); |
| 360 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 361 | static VkEventCreateInfo create_info(VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 362 | }; |
| 363 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 364 | class QueryPool : public DerivedObject<VkQueryPool, Object, VK_OBJECT_TYPE_QUERY_POOL> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | public: |
| 366 | // vkCreateQueryPool() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 367 | void init(const Device &dev, const VkQueryPoolCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 368 | |
| 369 | // vkGetQueryPoolResults() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 370 | VkResult results(uint32_t start, uint32_t count, size_t size, void *data); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 371 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 372 | static VkQueryPoolCreateInfo create_info(VkQueryType type, uint32_t slot_count); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 373 | }; |
| 374 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 375 | class Buffer : public DerivedObject<VkBuffer, Object, VK_OBJECT_TYPE_BUFFER> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 376 | public: |
| 377 | explicit Buffer() {} |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 378 | explicit Buffer(const Device &dev, const VkBufferCreateInfo &info) { init(dev, info); } |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 379 | explicit Buffer(const Device &dev, VkDeviceSize size) { init(dev, size); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 380 | |
| 381 | // vkCreateBuffer() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 382 | void init(const Device &dev, const VkBufferCreateInfo &info); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 383 | void init(const Device &dev, VkDeviceSize size) { init(dev, create_info(size, 0)); } |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 384 | void init(const Device &dev, VkDeviceSize size, VkMemoryPropertyFlags &reqs) { init(dev, create_info(size, 0), reqs); } |
| 385 | void init(const Device &dev, const VkBufferCreateInfo &info, VkMemoryPropertyFlags &reqs); |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 386 | void init_no_mem(const Device &dev, const VkBufferCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 387 | |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 388 | // vkQueueBindSparseBufferMemory() |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 389 | void bind_memory(VkDeviceSize offset, VkDeviceSize size, |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 390 | const GpuMemory &mem, VkDeviceSize mem_offset); |
| 391 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 392 | static VkBufferCreateInfo create_info(VkDeviceSize size, VkFlags usage); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 393 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 394 | VkBufferMemoryBarrier buffer_memory_barrier(VkFlags output_mask, VkFlags input_mask, |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 395 | VkDeviceSize offset, VkDeviceSize size) const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 396 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 397 | VkBufferMemoryBarrier barrier = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 398 | barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 399 | barrier.buffer = obj(); |
| 400 | barrier.outputMask = output_mask; |
| 401 | barrier.inputMask = input_mask; |
| 402 | barrier.offset = offset; |
| 403 | barrier.size = size; |
| 404 | return barrier; |
| 405 | } |
| 406 | private: |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 407 | VkBufferCreateInfo create_info_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 408 | }; |
| 409 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 410 | class BufferView : public DerivedObject<VkBufferView, Object, VK_OBJECT_TYPE_BUFFER_VIEW> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 411 | public: |
| 412 | // vkCreateBufferView() |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 413 | void init(const Device &dev, const VkBufferViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 414 | }; |
| 415 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 416 | class Image : public DerivedObject<VkImage, Object, VK_OBJECT_TYPE_IMAGE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 417 | public: |
| 418 | explicit Image() : format_features_(0) {} |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 419 | explicit Image(const Device &dev, const VkImageCreateInfo &info) : format_features_(0) { init(dev, info); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 420 | |
| 421 | // vkCreateImage() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 422 | void init(const Device &dev, const VkImageCreateInfo &info); |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 423 | void init(const Device &dev, const VkImageCreateInfo &info, VkMemoryPropertyFlags &reqs); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 424 | void init_no_mem(const Device &dev, const VkImageCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 425 | // vkOpenPeerImage() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 426 | void init(const Device &dev, const VkPeerImageOpenInfo &info, const VkImageCreateInfo &original_info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 427 | |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 428 | // vkQueueBindSparseImageMemory() |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 429 | void bind_memory(const Device &dev, const VkImageMemoryBindInfo &info, |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 430 | const GpuMemory &mem, VkDeviceSize mem_offset); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 431 | |
| 432 | // vkGetImageSubresourceInfo() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 433 | VkSubresourceLayout subresource_layout(const VkImageSubresource &subres) const; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 434 | |
| 435 | bool transparent() const; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 436 | bool copyable() const { return (format_features_ & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 437 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 438 | VkImageSubresourceRange subresource_range(VkImageAspect aspect) const { return subresource_range(create_info_, aspect); } |
| 439 | VkExtent3D extent() const { return create_info_.extent; } |
| 440 | VkExtent3D extent(uint32_t mip_level) const { return extent(create_info_.extent, mip_level); } |
| 441 | VkFormat format() const {return create_info_.format;} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 442 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 443 | VkImageMemoryBarrier image_memory_barrier(VkFlags output_mask, VkFlags input_mask, |
| 444 | VkImageLayout old_layout, |
| 445 | VkImageLayout new_layout, |
| 446 | const VkImageSubresourceRange &range) const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 447 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 448 | VkImageMemoryBarrier barrier = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 449 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 450 | barrier.outputMask = output_mask; |
| 451 | barrier.inputMask = input_mask; |
| 452 | barrier.oldLayout = old_layout; |
| 453 | barrier.newLayout = new_layout; |
| 454 | barrier.image = obj(); |
| 455 | barrier.subresourceRange = range; |
| 456 | return barrier; |
| 457 | } |
| 458 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 459 | static VkImageCreateInfo create_info(); |
| 460 | static VkImageSubresource subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice); |
| 461 | static VkImageSubresource subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice); |
| 462 | static VkImageSubresourceRange subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 463 | uint32_t base_array_slice, uint32_t array_size); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 464 | static VkImageSubresourceRange subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect); |
| 465 | static VkImageSubresourceRange subresource_range(const VkImageSubresource &subres); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 466 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 467 | static VkExtent2D extent(int32_t width, int32_t height); |
| 468 | static VkExtent2D extent(const VkExtent2D &extent, uint32_t mip_level); |
| 469 | static VkExtent2D extent(const VkExtent3D &extent); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 470 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 471 | static VkExtent3D extent(int32_t width, int32_t height, int32_t depth); |
| 472 | static VkExtent3D extent(const VkExtent3D &extent, uint32_t mip_level); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 473 | |
| 474 | private: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 475 | void init_info(const Device &dev, const VkImageCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 476 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 477 | VkImageCreateInfo create_info_; |
| 478 | VkFlags format_features_; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 479 | }; |
| 480 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 481 | class ImageView : public DerivedObject<VkImageView, Object, VK_OBJECT_TYPE_IMAGE_VIEW> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 482 | public: |
| 483 | // vkCreateImageView() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 484 | void init(const Device &dev, const VkImageViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 485 | }; |
| 486 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 487 | class ColorAttachmentView : public DerivedObject<VkColorAttachmentView, Object, VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 488 | public: |
| 489 | // vkCreateColorAttachmentView() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 490 | void init(const Device &dev, const VkColorAttachmentViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 491 | }; |
| 492 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 493 | class DepthStencilView : public DerivedObject<VkDepthStencilView, Object, VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 494 | public: |
| 495 | // vkCreateDepthStencilView() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 496 | void init(const Device &dev, const VkDepthStencilViewCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 497 | }; |
| 498 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 499 | class Shader : public DerivedObject<VkShader, Object, VK_OBJECT_TYPE_SHADER> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 500 | public: |
| 501 | // vkCreateShader() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 502 | void init(const Device &dev, const VkShaderCreateInfo &info); |
| 503 | VkResult init_try(const Device &dev, const VkShaderCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 504 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 505 | static VkShaderCreateInfo create_info(size_t code_size, const void *code, VkFlags flags); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 506 | }; |
| 507 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 508 | class Pipeline : public DerivedObject<VkPipeline, Object, VK_OBJECT_TYPE_PIPELINE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 509 | public: |
| 510 | // vkCreateGraphicsPipeline() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 511 | void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 512 | // vkCreateGraphicsPipelineDerivative() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 513 | void init(const Device &dev, const VkGraphicsPipelineCreateInfo &info, const VkPipeline basePipeline); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 514 | // vkCreateComputePipeline() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 515 | void init(const Device &dev, const VkComputePipelineCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 516 | // vkLoadPipeline() |
| 517 | void init(const Device&dev, size_t size, const void *data); |
| 518 | // vkLoadPipelineDerivative() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 519 | 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] | 520 | |
| 521 | // vkStorePipeline() |
| 522 | size_t store(size_t size, void *data); |
| 523 | }; |
| 524 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 525 | class Sampler : public DerivedObject<VkSampler, Object, VK_OBJECT_TYPE_SAMPLER> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 526 | public: |
| 527 | // vkCreateSampler() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 528 | void init(const Device &dev, const VkSamplerCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 529 | }; |
| 530 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 531 | class DescriptorSetLayout : public DerivedObject<VkDescriptorSetLayout, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 532 | public: |
| 533 | // vkCreateDescriptorSetLayout() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 534 | void init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 535 | }; |
| 536 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 537 | class PipelineLayout : public DerivedObject<VkPipelineLayout, Object, VK_OBJECT_TYPE_PIPELINE_LAYOUT> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 538 | public: |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 539 | // vCreatePipelineLayout() |
| 540 | void init(const Device &dev, VkPipelineLayoutCreateInfo &info, const std::vector<const DescriptorSetLayout *> &layouts); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 541 | }; |
| 542 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 543 | class DescriptorPool : public DerivedObject<VkDescriptorPool, Object, VK_OBJECT_TYPE_DESCRIPTOR_POOL> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 544 | public: |
| 545 | // vkCreateDescriptorPool() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 546 | void init(const Device &dev, VkDescriptorPoolUsage usage, |
| 547 | uint32_t max_sets, const VkDescriptorPoolCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 548 | |
| 549 | // vkResetDescriptorPool() |
| 550 | void reset(); |
| 551 | |
| 552 | // vkAllocDescriptorSets() |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 553 | std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts); |
| 554 | std::vector<DescriptorSet *> alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count); |
| 555 | DescriptorSet *alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 556 | |
| 557 | // vkClearDescriptorSets() |
| 558 | void clear_sets(const std::vector<DescriptorSet *> &sets); |
| 559 | void clear_sets(DescriptorSet &set) { clear_sets(std::vector<DescriptorSet *>(1, &set)); } |
| 560 | }; |
| 561 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 562 | class DescriptorSet : public DerivedObject<VkDescriptorSet, Object, VK_OBJECT_TYPE_DESCRIPTOR_SET> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 563 | public: |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 564 | explicit DescriptorSet() : DerivedObject() {} |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 565 | explicit DescriptorSet(const Device &dev, VkDescriptorSet set) : DerivedObject(dev, set) {} |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 566 | }; |
| 567 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 568 | class DynamicVpStateObject : public DerivedObject<VkDynamicVpState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_VP_STATE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 569 | public: |
| 570 | // vkCreateDynamicViewportState() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 571 | void init(const Device &dev, const VkDynamicVpStateCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 572 | }; |
| 573 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 574 | class DynamicRsStateObject : public DerivedObject<VkDynamicRsState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_RS_STATE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 575 | public: |
| 576 | // vkCreateDynamicRasterState() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 577 | void init(const Device &dev, const VkDynamicRsStateCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 578 | }; |
| 579 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 580 | class DynamicCbStateObject : public DerivedObject<VkDynamicCbState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_CB_STATE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 581 | public: |
| 582 | // vkCreateDynamicColorBlendState() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 583 | void init(const Device &dev, const VkDynamicCbStateCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 584 | }; |
| 585 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 586 | class DynamicDsStateObject : public DerivedObject<VkDynamicDsState, DynamicStateObject, VK_OBJECT_TYPE_DYNAMIC_DS_STATE> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 587 | public: |
| 588 | // vkCreateDynamicDepthStencilState() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 589 | void init(const Device &dev, const VkDynamicDsStateCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 590 | }; |
| 591 | |
Courtney Goeltzenleuchter | 992fb4f | 2015-04-19 19:07:33 -0600 | [diff] [blame] | 592 | class CmdBuffer : public DerivedObject<VkCmdBuffer, Object, VK_OBJECT_TYPE_COMMAND_BUFFER> { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 593 | public: |
| 594 | explicit CmdBuffer() {} |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 595 | explicit CmdBuffer(const Device &dev, const VkCmdBufferCreateInfo &info) { init(dev, info); } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 596 | |
| 597 | // vkCreateCommandBuffer() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 598 | void init(const Device &dev, const VkCmdBufferCreateInfo &info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 599 | |
| 600 | // vkBeginCommandBuffer() |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 601 | void begin(const VkCmdBufferBeginInfo *info); |
| 602 | void begin(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 603 | void begin(); |
| 604 | |
| 605 | // vkEndCommandBuffer() |
| 606 | // vkResetCommandBuffer() |
| 607 | void end(); |
| 608 | void reset(); |
| 609 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 610 | static VkCmdBufferCreateInfo create_info(uint32_t queueNodeIndex); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 611 | }; |
| 612 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 613 | inline const void *Object::map(VkFlags flags) const |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 614 | { |
| 615 | return (primary_mem_) ? primary_mem_->map(flags) : NULL; |
| 616 | } |
| 617 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 618 | inline void *Object::map(VkFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 619 | { |
| 620 | return (primary_mem_) ? primary_mem_->map(flags) : NULL; |
| 621 | } |
| 622 | |
| 623 | inline void Object::unmap() const |
| 624 | { |
| 625 | if (primary_mem_) |
| 626 | primary_mem_->unmap(); |
| 627 | } |
| 628 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 629 | inline VkMemoryAllocInfo GpuMemory::alloc_info(const VkMemoryRequirements &reqs, |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 630 | const VkMemoryAllocInfo *next_info) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 631 | { |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 632 | VkMemoryAllocInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 633 | info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 634 | if (next_info != NULL) |
| 635 | info.pNext = (void *) next_info; |
| 636 | |
| 637 | info.allocationSize = reqs.size; |
Jeremy Hayes | 38ce2b1 | 2015-04-15 14:17:56 -0600 | [diff] [blame] | 638 | info.memProps = reqs.memPropsRequired; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 639 | info.memPriority = VK_MEMORY_PRIORITY_NORMAL; |
| 640 | return info; |
| 641 | } |
| 642 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 643 | inline VkBufferCreateInfo Buffer::create_info(VkDeviceSize size, VkFlags usage) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 644 | { |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 645 | VkBufferCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 646 | info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 647 | info.size = size; |
| 648 | info.usage = usage; |
| 649 | return info; |
| 650 | } |
| 651 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 652 | inline VkFenceCreateInfo Fence::create_info(VkFenceCreateFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 653 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 654 | VkFenceCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 655 | info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 656 | info.flags = flags; |
| 657 | return info; |
| 658 | } |
| 659 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 660 | inline VkFenceCreateInfo Fence::create_info() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 661 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 662 | VkFenceCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 663 | info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 664 | return info; |
| 665 | } |
| 666 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 667 | inline VkSemaphoreCreateInfo Semaphore::create_info(uint32_t init_count, VkFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 668 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 669 | VkSemaphoreCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 670 | info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 671 | info.initialCount = init_count; |
| 672 | info.flags = flags; |
| 673 | return info; |
| 674 | } |
| 675 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 676 | inline VkEventCreateInfo Event::create_info(VkFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 677 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 678 | VkEventCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 679 | info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 680 | info.flags = flags; |
| 681 | return info; |
| 682 | } |
| 683 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 684 | inline VkQueryPoolCreateInfo QueryPool::create_info(VkQueryType type, uint32_t slot_count) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 685 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 686 | VkQueryPoolCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 687 | info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 688 | info.queryType = type; |
| 689 | info.slots = slot_count; |
| 690 | return info; |
| 691 | } |
| 692 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 693 | inline VkImageCreateInfo Image::create_info() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 694 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 695 | VkImageCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 696 | info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 697 | info.extent.width = 1; |
| 698 | info.extent.height = 1; |
| 699 | info.extent.depth = 1; |
| 700 | info.mipLevels = 1; |
| 701 | info.arraySize = 1; |
| 702 | info.samples = 1; |
| 703 | return info; |
| 704 | } |
| 705 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 706 | inline VkImageSubresource Image::subresource(VkImageAspect aspect, uint32_t mip_level, uint32_t array_slice) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 707 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 708 | VkImageSubresource subres = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 709 | subres.aspect = aspect; |
| 710 | subres.mipLevel = mip_level; |
| 711 | subres.arraySlice = array_slice; |
| 712 | return subres; |
| 713 | } |
| 714 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 715 | inline VkImageSubresource Image::subresource(const VkImageSubresourceRange &range, uint32_t mip_level, uint32_t array_slice) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 716 | { |
| 717 | return subresource(range.aspect, range.baseMipLevel + mip_level, range.baseArraySlice + array_slice); |
| 718 | } |
| 719 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 720 | inline VkImageSubresourceRange Image::subresource_range(VkImageAspect aspect, uint32_t base_mip_level, uint32_t mip_levels, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 721 | uint32_t base_array_slice, uint32_t array_size) |
| 722 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 723 | VkImageSubresourceRange range = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 724 | range.aspect = aspect; |
| 725 | range.baseMipLevel = base_mip_level; |
| 726 | range.mipLevels = mip_levels; |
| 727 | range.baseArraySlice = base_array_slice; |
| 728 | range.arraySize = array_size; |
| 729 | return range; |
| 730 | } |
| 731 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 732 | inline VkImageSubresourceRange Image::subresource_range(const VkImageCreateInfo &info, VkImageAspect aspect) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 733 | { |
| 734 | return subresource_range(aspect, 0, info.mipLevels, 0, info.arraySize); |
| 735 | } |
| 736 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 737 | inline VkImageSubresourceRange Image::subresource_range(const VkImageSubresource &subres) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 738 | { |
| 739 | return subresource_range(subres.aspect, subres.mipLevel, 1, subres.arraySlice, 1); |
| 740 | } |
| 741 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 742 | inline VkExtent2D Image::extent(int32_t width, int32_t height) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 743 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 744 | VkExtent2D extent = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 745 | extent.width = width; |
| 746 | extent.height = height; |
| 747 | return extent; |
| 748 | } |
| 749 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 750 | inline VkExtent2D Image::extent(const VkExtent2D &extent, uint32_t mip_level) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 751 | { |
| 752 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 753 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 754 | return Image::extent(width, height); |
| 755 | } |
| 756 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 757 | inline VkExtent2D Image::extent(const VkExtent3D &extent) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 758 | { |
| 759 | return Image::extent(extent.width, extent.height); |
| 760 | } |
| 761 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 762 | inline VkExtent3D Image::extent(int32_t width, int32_t height, int32_t depth) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 763 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 764 | VkExtent3D extent = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 765 | extent.width = width; |
| 766 | extent.height = height; |
| 767 | extent.depth = depth; |
| 768 | return extent; |
| 769 | } |
| 770 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 771 | inline VkExtent3D Image::extent(const VkExtent3D &extent, uint32_t mip_level) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 772 | { |
| 773 | const int32_t width = (extent.width >> mip_level) ? extent.width >> mip_level : 1; |
| 774 | const int32_t height = (extent.height >> mip_level) ? extent.height >> mip_level : 1; |
| 775 | const int32_t depth = (extent.depth >> mip_level) ? extent.depth >> mip_level : 1; |
| 776 | return Image::extent(width, height, depth); |
| 777 | } |
| 778 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 779 | inline VkShaderCreateInfo Shader::create_info(size_t code_size, const void *code, VkFlags flags) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 780 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 781 | VkShaderCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 782 | info.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 783 | info.codeSize = code_size; |
| 784 | info.pCode = code; |
| 785 | info.flags = flags; |
| 786 | return info; |
| 787 | } |
| 788 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 789 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 790 | VkDescriptorType type, uint32_t count, const VkDescriptorInfo *descriptors) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 791 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 792 | VkWriteDescriptorSet write = {}; |
| 793 | write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 794 | write.destSet = set.obj(); |
| 795 | write.destBinding = binding; |
| 796 | write.destArrayElement = array_element; |
| 797 | write.count = count; |
| 798 | write.descriptorType = type; |
| 799 | write.pDescriptors = descriptors; |
| 800 | return write; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 801 | } |
| 802 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 803 | inline VkWriteDescriptorSet Device::write_descriptor_set(const DescriptorSet &set, uint32_t binding, uint32_t array_element, |
| 804 | VkDescriptorType type, const std::vector<VkDescriptorInfo> &descriptors) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 805 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 806 | return write_descriptor_set(set, binding, array_element, type, descriptors.size(), &descriptors[0]); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 807 | } |
| 808 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 809 | inline VkCopyDescriptorSet Device::copy_descriptor_set(const DescriptorSet &src_set, uint32_t src_binding, uint32_t src_array_element, |
| 810 | const DescriptorSet &dst_set, uint32_t dst_binding, uint32_t dst_array_element, |
| 811 | uint32_t count) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 812 | { |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 813 | VkCopyDescriptorSet copy = {}; |
| 814 | copy.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 815 | copy.srcSet = src_set.obj(); |
| 816 | copy.srcBinding = src_binding; |
| 817 | copy.srcArrayElement = src_array_element; |
| 818 | copy.destSet = dst_set.obj(); |
| 819 | copy.destBinding = dst_binding; |
| 820 | copy.destArrayElement = dst_array_element; |
| 821 | copy.count = count; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 822 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 823 | return copy; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 824 | } |
| 825 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 826 | inline VkCmdBufferCreateInfo CmdBuffer::create_info(uint32_t queueNodeIndex) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 827 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 828 | VkCmdBufferCreateInfo info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 829 | info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 830 | info.queueNodeIndex = queueNodeIndex; |
| 831 | return info; |
| 832 | } |
| 833 | |
| 834 | }; // namespace vk_testing |
| 835 | |
| 836 | #endif // VKTESTBINDING_H |