blob: 1287e7aeb77dfe6521a0104d6893d5d3b1a301d6 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001// VK tests
Chia-I Wu82bff272014-12-27 14:12:52 +08002//
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#include <iostream>
24#include <string.h> // memset(), memcmp()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060025#include "vktestbinding.h"
Chia-I Wu82bff272014-12-27 14:12:52 +080026
27namespace {
Chia-I Wu82bff272014-12-27 14:12:52 +080028#define DERIVED_OBJECT_INIT(create_func, ...) \
29 do { \
30 obj_type obj; \
Mark Lobodzinskicf26e072015-04-16 11:44:05 -050031 if (EXPECT(create_func(__VA_ARGS__, &obj) == VK_SUCCESS)) \
Chia-I Wu82bff272014-12-27 14:12:52 +080032 base_type::init(obj); \
33 } while (0)
34
35#define STRINGIFY(x) #x
36#define EXPECT(expr) ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, __FUNCTION__))
Mark Lobodzinskicf26e072015-04-16 11:44:05 -050037#define DEV_INIT(device) dev_ = &device;
38
39
Chia-I Wu82bff272014-12-27 14:12:52 +080040
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060041vk_testing::ErrorCallback error_callback;
Chia-I Wu82bff272014-12-27 14:12:52 +080042
43bool expect_failure(const char *expr, const char *file, unsigned int line, const char *function)
44{
45 if (error_callback) {
46 error_callback(expr, file, line, function);
47 } else {
48 std::cerr << file << ":" << line << ": " << function <<
49 ": Expectation `" << expr << "' failed.\n";
50 }
51
52 return false;
53}
54
55template<class T, class S>
56std::vector<T> make_objects(const std::vector<S> &v)
57{
58 std::vector<T> objs;
59 objs.reserve(v.size());
60 for (typename std::vector<S>::const_iterator it = v.begin(); it != v.end(); it++)
61 objs.push_back((*it)->obj());
62 return objs;
63}
64
65template<typename T>
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060066std::vector<T> get_info(VkPhysicalGpu gpu, VkPhysicalGpuInfoType type, size_t min_elems)
Chia-I Wu82bff272014-12-27 14:12:52 +080067{
68 std::vector<T> info;
Jon Ashburn23bd3822015-02-11 09:36:41 -070069 size_t size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060070 if (EXPECT(vkGetGpuInfo(gpu, type, &size, NULL) == VK_SUCCESS && size % sizeof(T) == 0)) {
Chia-I Wu82bff272014-12-27 14:12:52 +080071 info.resize(size / sizeof(T));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060072 if (!EXPECT(vkGetGpuInfo(gpu, type, &size, &info[0]) == VK_SUCCESS && size == info.size() * sizeof(T)))
Chia-I Wu82bff272014-12-27 14:12:52 +080073 info.clear();
74 }
75
76 if (info.size() < min_elems)
77 info.resize(min_elems);
78
79 return info;
80}
81
82template<typename T>
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060083std::vector<T> get_info(VkBaseObject obj, VkObjectInfoType type, size_t min_elems)
Chia-I Wu82bff272014-12-27 14:12:52 +080084{
85 std::vector<T> info;
Jon Ashburn23bd3822015-02-11 09:36:41 -070086 size_t size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060087 if (EXPECT(vkGetObjectInfo(obj, type, &size, NULL) == VK_SUCCESS && size % sizeof(T) == 0)) {
Chia-I Wu82bff272014-12-27 14:12:52 +080088 info.resize(size / sizeof(T));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060089 if (!EXPECT(vkGetObjectInfo(obj, type, &size, &info[0]) == VK_SUCCESS && size == info.size() * sizeof(T)))
Chia-I Wu82bff272014-12-27 14:12:52 +080090 info.clear();
91 }
92
93 if (info.size() < min_elems)
94 info.resize(min_elems);
95
96 return info;
97}
98
99} // namespace
100
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600101namespace vk_testing {
Chia-I Wu82bff272014-12-27 14:12:52 +0800102
103void set_error_callback(ErrorCallback callback)
104{
105 error_callback = callback;
106}
107
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600108VkPhysicalGpuProperties PhysicalGpu::properties() const
Chia-I Wu82bff272014-12-27 14:12:52 +0800109{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600110 return get_info<VkPhysicalGpuProperties>(gpu_, VK_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, 1)[0];
Chia-I Wu82bff272014-12-27 14:12:52 +0800111}
112
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600113VkPhysicalGpuPerformance PhysicalGpu::performance() const
Chia-I Wu82bff272014-12-27 14:12:52 +0800114{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600115 return get_info<VkPhysicalGpuPerformance>(gpu_, VK_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE, 1)[0];
Chia-I Wu82bff272014-12-27 14:12:52 +0800116}
117
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600118std::vector<VkPhysicalGpuQueueProperties> PhysicalGpu::queue_properties() const
Chia-I Wu82bff272014-12-27 14:12:52 +0800119{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600120 return get_info<VkPhysicalGpuQueueProperties>(gpu_, VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, 0);
Chia-I Wu82bff272014-12-27 14:12:52 +0800121}
122
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600123VkPhysicalGpuMemoryProperties PhysicalGpu::memory_properties() const
Chia-I Wu82bff272014-12-27 14:12:52 +0800124{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600125 return get_info<VkPhysicalGpuMemoryProperties>(gpu_, VK_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES, 1)[0];
Chia-I Wu82bff272014-12-27 14:12:52 +0800126}
127
128std::vector<const char *> PhysicalGpu::layers(std::vector<char> &buf) const
129{
130 const size_t max_layer_count = 16;
131 const size_t max_string_size = 256;
132
133 buf.resize(max_layer_count * max_string_size);
134
135 std::vector<const char *> layers;
136 layers.reserve(max_layer_count);
137 for (size_t i = 0; i < max_layer_count; i++)
138 layers.push_back(&buf[0] + max_string_size * i);
139
140 char * const *out = const_cast<char * const *>(&layers[0]);
141 size_t count;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142 if (!EXPECT(vkEnumerateLayers(gpu_, max_layer_count, max_string_size, &count, out, NULL) == VK_SUCCESS))
Chia-I Wu82bff272014-12-27 14:12:52 +0800143 count = 0;
144 layers.resize(count);
145
146 return layers;
147}
148
149std::vector<const char *> PhysicalGpu::extensions() const
150{
Tobin Ehlisf6cc4e72015-04-16 10:13:25 -0600151 // TODO : Should fill this out using GetGlobalExtensionInfo to query count
152 // Then fill in extensions based on that count
Chia-I Wu82bff272014-12-27 14:12:52 +0800153 static const char *known_exts[] = {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600154 "VK_WSI_X11",
Chia-I Wu82bff272014-12-27 14:12:52 +0800155 };
156
157 std::vector<const char *> exts;
158 for (int i = 0; i < sizeof(known_exts) / sizeof(known_exts[0]); i++) {
Tobin Ehlisf6cc4e72015-04-16 10:13:25 -0600159// VkResult err = vkGetExtensionSupport(gpu_, known_exts[i]);
160// if (err == VK_SUCCESS)
161 exts.push_back(known_exts[i]);
Chia-I Wu82bff272014-12-27 14:12:52 +0800162 }
163
164 return exts;
165}
166
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600167VkGpuCompatibilityInfo PhysicalGpu::compatibility(const PhysicalGpu &other) const
Chia-I Wu82bff272014-12-27 14:12:52 +0800168{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600169 VkGpuCompatibilityInfo data;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600170 if (!EXPECT(vkGetMultiGpuCompatibility(gpu_, other.gpu_, &data) == VK_SUCCESS))
Chia-I Wu82bff272014-12-27 14:12:52 +0800171 memset(&data, 0, sizeof(data));
172
173 return data;
174}
175
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600176void BaseObject::init(VkBaseObject obj, bool own)
Chia-I Wu82bff272014-12-27 14:12:52 +0800177{
178 EXPECT(!initialized());
179 reinit(obj, own);
180}
181
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600182void BaseObject::reinit(VkBaseObject obj, bool own)
Chia-I Wu82bff272014-12-27 14:12:52 +0800183{
184 obj_ = obj;
185 own_obj_ = own;
186}
187
188uint32_t BaseObject::memory_allocation_count() const
189{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190 return get_info<uint32_t>(obj_, VK_INFO_TYPE_MEMORY_ALLOCATION_COUNT, 1)[0];
Chia-I Wu82bff272014-12-27 14:12:52 +0800191}
192
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600193std::vector<VkMemoryRequirements> BaseObject::memory_requirements() const
Chia-I Wu82bff272014-12-27 14:12:52 +0800194{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600195 VkResult err;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600196 uint32_t num_allocations = 0;
197 size_t num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 err = vkGetObjectInfo(obj_, VK_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700199 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600200 EXPECT(err == VK_SUCCESS && num_alloc_size == sizeof(num_allocations));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600201 std::vector<VkMemoryRequirements> info =
202 get_info<VkMemoryRequirements>(obj_, VK_INFO_TYPE_MEMORY_REQUIREMENTS, 0);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700203 EXPECT(info.size() == num_allocations);
Chia-I Wu82bff272014-12-27 14:12:52 +0800204 if (info.size() == 1 && !info[0].size)
205 info.clear();
206
207 return info;
208}
209
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210void Object::init(VkObject obj, bool own)
Chia-I Wu82bff272014-12-27 14:12:52 +0800211{
212 BaseObject::init(obj, own);
213 mem_alloc_count_ = memory_allocation_count();
214}
215
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600216void Object::reinit(VkObject obj, bool own)
Chia-I Wu82bff272014-12-27 14:12:52 +0800217{
218 cleanup();
219 BaseObject::reinit(obj, own);
220 mem_alloc_count_ = memory_allocation_count();
221}
222
223void Object::cleanup()
224{
225 if (!initialized())
226 return;
227
Tony Barbour2b5fb342015-04-09 16:00:18 -0600228 if(bound) {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500229 unbind_memory(*dev_);
Tony Barbour2b5fb342015-04-09 16:00:18 -0600230 }
Chia-I Wu82bff272014-12-27 14:12:52 +0800231
232 if (internal_mems_) {
233 delete[] internal_mems_;
234 internal_mems_ = NULL;
235 primary_mem_ = NULL;
236 }
237
238 mem_alloc_count_ = 0;
239
240 if (own())
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600241 EXPECT(vkDestroyObject(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800242}
243
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500244void Object::bind_memory(const Device &dev, uint32_t alloc_idx, const GpuMemory &mem, VkGpuSize mem_offset)
Chia-I Wu82bff272014-12-27 14:12:52 +0800245{
Tony Barbour2b5fb342015-04-09 16:00:18 -0600246 bound = true;
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500247 VkQueue queue = dev.graphics_queues()[0]->obj();
248 EXPECT(vkQueueBindObjectMemory(queue, obj(), alloc_idx, mem.obj(), mem_offset) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800249}
250
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500251void Object::bind_memory(const Device &dev, uint32_t alloc_idx, VkGpuSize offset, VkGpuSize size,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600252 const GpuMemory &mem, VkGpuSize mem_offset)
Chia-I Wu714df452015-01-01 07:55:04 +0800253{
Tony Barbour2b5fb342015-04-09 16:00:18 -0600254 bound = true;
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500255 VkQueue queue = dev.graphics_queues()[0]->obj();
256 EXPECT(!alloc_idx && vkQueueBindObjectMemoryRange(queue, obj(), 0, offset, size, mem.obj(), mem_offset) == VK_SUCCESS);
Chia-I Wu714df452015-01-01 07:55:04 +0800257}
258
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500259void Object::unbind_memory(const Device &dev, uint32_t alloc_idx)
Chia-I Wu82bff272014-12-27 14:12:52 +0800260{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500261 VkQueue queue = dev.graphics_queues()[0]->obj();
262 EXPECT(vkQueueBindObjectMemory(queue, obj(), alloc_idx, VK_NULL_HANDLE, 0) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800263}
264
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500265void Object::unbind_memory(const Device &dev)
Chia-I Wu82bff272014-12-27 14:12:52 +0800266{
267 for (uint32_t i = 0; i < mem_alloc_count_; i++)
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500268 unbind_memory(dev, i);
Chia-I Wu82bff272014-12-27 14:12:52 +0800269}
270
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500271void Object::alloc_memory(const Device &dev)
Chia-I Wu82bff272014-12-27 14:12:52 +0800272{
273 if (!EXPECT(!internal_mems_) || !mem_alloc_count_)
274 return;
275
276 internal_mems_ = new GpuMemory[mem_alloc_count_];
277
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 const std::vector<VkMemoryRequirements> mem_reqs = memory_requirements();
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600279 VkMemoryAllocInfo info, *next_info = NULL;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700280
Chia-I Wu82bff272014-12-27 14:12:52 +0800281 for (int i = 0; i < mem_reqs.size(); i++) {
Jon Ashburn5567c812015-01-20 08:50:12 -0700282 info = GpuMemory::alloc_info(mem_reqs[i], next_info);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500283 primary_mem_ = &internal_mems_[i];
Chia-I Wu82bff272014-12-27 14:12:52 +0800284 internal_mems_[i].init(dev, info);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500285 bind_memory(dev, i, internal_mems_[i], 0);
Chia-I Wu82bff272014-12-27 14:12:52 +0800286 }
287}
288
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500289void Object::alloc_memory(const Device &dev, const std::vector<VkGpuMemory> &mems)
Chia-I Wu82bff272014-12-27 14:12:52 +0800290{
291 if (!EXPECT(!internal_mems_) || !mem_alloc_count_)
292 return;
293
294 internal_mems_ = new GpuMemory[mem_alloc_count_];
295
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296 const std::vector<VkMemoryRequirements> mem_reqs = memory_requirements();
Chia-I Wu82bff272014-12-27 14:12:52 +0800297 if (!EXPECT(mem_reqs.size() == mems.size()))
298 return;
299
300 for (int i = 0; i < mem_reqs.size(); i++) {
301 primary_mem_ = &internal_mems_[i];
302
303 internal_mems_[i].init(mems[i]);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500304 bind_memory(dev, i, internal_mems_[i], 0);
Chia-I Wu82bff272014-12-27 14:12:52 +0800305 }
306}
307
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600308std::vector<VkGpuMemory> Object::memories() const
Chia-I Wu82bff272014-12-27 14:12:52 +0800309{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 std::vector<VkGpuMemory> mems;
Chia-I Wu82bff272014-12-27 14:12:52 +0800311 if (internal_mems_) {
312 mems.reserve(mem_alloc_count_);
313 for (uint32_t i = 0; i < mem_alloc_count_; i++)
314 mems.push_back(internal_mems_[i].obj());
315 }
316
317 return mems;
318}
319
320Device::~Device()
321{
322 if (!initialized())
323 return;
324
325 for (int i = 0; i < QUEUE_COUNT; i++) {
326 for (std::vector<Queue *>::iterator it = queues_[i].begin(); it != queues_[i].end(); it++)
327 delete *it;
328 queues_[i].clear();
329 }
330
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600331 EXPECT(vkDestroyDevice(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800332}
333
Chia-I Wu6c099222015-01-06 10:40:45 +0800334void Device::init(bool enable_layers)
Chia-I Wu82bff272014-12-27 14:12:52 +0800335{
336 // request all queues
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600337 const std::vector<VkPhysicalGpuQueueProperties> queue_props = gpu_.queue_properties();
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600338 std::vector<VkDeviceQueueCreateInfo> queue_info;
Chia-I Wu82bff272014-12-27 14:12:52 +0800339 queue_info.reserve(queue_props.size());
340 for (int i = 0; i < queue_props.size(); i++) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600341 VkDeviceQueueCreateInfo qi = {};
Chia-I Wu82bff272014-12-27 14:12:52 +0800342 qi.queueNodeIndex = i;
343 qi.queueCount = queue_props[i].queueCount;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600344 if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700345 graphics_queue_node_index_ = i;
346 }
Chia-I Wu82bff272014-12-27 14:12:52 +0800347 queue_info.push_back(qi);
348 }
349
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600350 VkLayerCreateInfo layer_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 layer_info.sType = VK_STRUCTURE_TYPE_LAYER_CREATE_INFO;
Chia-I Wu6c099222015-01-06 10:40:45 +0800352
353 std::vector<const char *> layers;
354 std::vector<char> layer_buf;
355 // request all layers
356 if (enable_layers) {
357 layers = gpu_.layers(layer_buf);
358 layer_info.layerCount = layers.size();
359 layer_info.ppActiveLayerNames = &layers[0];
360 }
Chia-I Wu82bff272014-12-27 14:12:52 +0800361
362 const std::vector<const char *> exts = gpu_.extensions();
363
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600364 VkDeviceCreateInfo dev_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
Jon Ashburnca930582015-01-22 13:33:15 -0700366 dev_info.pNext = (enable_layers) ? static_cast<void *>(&layer_info) : NULL;
Chia-I Wu82bff272014-12-27 14:12:52 +0800367 dev_info.queueRecordCount = queue_info.size();
368 dev_info.pRequestedQueues = &queue_info[0];
369 dev_info.extensionCount = exts.size();
370 dev_info.ppEnabledExtensionNames = &exts[0];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600371 dev_info.flags = VK_DEVICE_CREATE_VALIDATION_BIT;
Chia-I Wu82bff272014-12-27 14:12:52 +0800372
373 init(dev_info);
374}
375
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600376void Device::init(const VkDeviceCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800377{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 DERIVED_OBJECT_INIT(vkCreateDevice, gpu_.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800379
380 init_queues();
Chia-I Wu82bff272014-12-27 14:12:52 +0800381 init_formats();
382}
383
384void Device::init_queues()
385{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600386 VkResult err;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700387 size_t data_size;
388 uint32_t queue_node_count;
Chia-I Wu82bff272014-12-27 14:12:52 +0800389
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390 err = vkGetGpuInfo(gpu_.obj(), VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700391 &data_size, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600392 EXPECT(err == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800393
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600394 queue_node_count = data_size / sizeof(VkPhysicalGpuQueueProperties);
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700395 EXPECT(queue_node_count >= 1);
396
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600397 VkPhysicalGpuQueueProperties queue_props[queue_node_count];
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700398
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600399 err = vkGetGpuInfo(gpu_.obj(), VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700400 &data_size, queue_props);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600401 EXPECT(err == VK_SUCCESS);
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700402
403 for (int i = 0; i < queue_node_count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600404 VkQueue queue;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700405
406 for (int j = 0; j < queue_props[i].queueCount; j++) {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500407 // TODO: Need to add support for separate MEMMGR and work queues, including synchronization
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600408 err = vkGetDeviceQueue(obj(), i, j, &queue);
409 EXPECT(err == VK_SUCCESS);
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700410
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600411 if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700412 queues_[GRAPHICS].push_back(new Queue(queue));
413 }
414
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415 if (queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700416 queues_[COMPUTE].push_back(new Queue(queue));
417 }
418
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419 if (queue_props[i].queueFlags & VK_QUEUE_DMA_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700420 queues_[DMA].push_back(new Queue(queue));
421 }
Chia-I Wu82bff272014-12-27 14:12:52 +0800422 }
423 }
424
425 EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty());
426}
427
Chia-I Wu82bff272014-12-27 14:12:52 +0800428void Device::init_formats()
429{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 for (int f = VK_FMT_BEGIN_RANGE; f <= VK_FMT_END_RANGE; f++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600431 const VkFormat fmt = static_cast<VkFormat>(f);
432 const VkFormatProperties props = format_properties(fmt);
Chia-I Wu82bff272014-12-27 14:12:52 +0800433
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700434 if (props.linearTilingFeatures) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600435 const Format tmp = { fmt, VK_LINEAR_TILING, props.linearTilingFeatures };
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700436 formats_.push_back(tmp);
437 }
Chia-I Wu82bff272014-12-27 14:12:52 +0800438
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700439 if (props.optimalTilingFeatures) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600440 const Format tmp = { fmt, VK_OPTIMAL_TILING, props.optimalTilingFeatures };
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700441 formats_.push_back(tmp);
Chia-I Wu82bff272014-12-27 14:12:52 +0800442 }
443 }
444
445 EXPECT(!formats_.empty());
446}
447
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600448VkFormatProperties Device::format_properties(VkFormat format)
Chia-I Wu82bff272014-12-27 14:12:52 +0800449{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600450 const VkFormatInfoType type = VK_INFO_TYPE_FORMAT_PROPERTIES;
451 VkFormatProperties data;
Chia-I Wu82bff272014-12-27 14:12:52 +0800452 size_t size = sizeof(data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600453 if (!EXPECT(vkGetFormatInfo(obj(), format, type, &size, &data) == VK_SUCCESS && size == sizeof(data)))
Chia-I Wu82bff272014-12-27 14:12:52 +0800454 memset(&data, 0, sizeof(data));
455
456 return data;
457}
458
459void Device::wait()
460{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600461 EXPECT(vkDeviceWaitIdle(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800462}
463
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600464VkResult Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout)
Chia-I Wu82bff272014-12-27 14:12:52 +0800465{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466 const std::vector<VkFence> fence_objs = make_objects<VkFence>(fences);
467 VkResult err = vkWaitForFences(obj(), fence_objs.size(), &fence_objs[0], wait_all, timeout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600468 EXPECT(err == VK_SUCCESS || err == VK_TIMEOUT);
Chia-I Wu82bff272014-12-27 14:12:52 +0800469
470 return err;
471}
472
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600473void Device::begin_descriptor_pool_update(VkDescriptorUpdateMode mode)
Chia-I Wuf8385062015-01-04 16:27:24 +0800474{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600475 EXPECT(vkBeginDescriptorPoolUpdate(obj(), mode) == VK_SUCCESS);
Chia-I Wuf8385062015-01-04 16:27:24 +0800476}
477
Chia-I Wu8d24b3b2015-03-26 13:14:16 +0800478void Device::end_descriptor_pool_update(CmdBuffer &cmd)
Chia-I Wuf8385062015-01-04 16:27:24 +0800479{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480 EXPECT(vkEndDescriptorPoolUpdate(obj(), cmd.obj()) == VK_SUCCESS);
Chia-I Wuf8385062015-01-04 16:27:24 +0800481}
482
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600483void Queue::submit(const std::vector<const CmdBuffer *> &cmds, Fence &fence)
Chia-I Wu82bff272014-12-27 14:12:52 +0800484{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485 const std::vector<VkCmdBuffer> cmd_objs = make_objects<VkCmdBuffer>(cmds);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600486 EXPECT(vkQueueSubmit(obj(), cmd_objs.size(), &cmd_objs[0], fence.obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800487}
488
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600489void Queue::submit(const CmdBuffer &cmd, Fence &fence)
Chia-I Wu82bff272014-12-27 14:12:52 +0800490{
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600491 submit(std::vector<const CmdBuffer*>(1, &cmd), fence);
Chia-I Wu82bff272014-12-27 14:12:52 +0800492}
493
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600494void Queue::submit(const CmdBuffer &cmd)
Chia-I Wu82bff272014-12-27 14:12:52 +0800495{
496 Fence fence;
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600497 submit(cmd, fence);
Chia-I Wu82bff272014-12-27 14:12:52 +0800498}
499
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600500void Queue::add_mem_references(const std::vector<VkGpuMemory> &mem_refs)
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600501{
502 for (int i = 0; i < mem_refs.size(); i++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600503 EXPECT(vkQueueAddMemReference(obj(), mem_refs[i]) == VK_SUCCESS);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600504 }
505}
506
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600507void Queue::remove_mem_references(const std::vector<VkGpuMemory> &mem_refs)
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600508{
509 for (int i = 0; i < mem_refs.size(); i++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600510 EXPECT(vkQueueRemoveMemReference(obj(), mem_refs[i]) == VK_SUCCESS);
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600511 }
512}
Chia-I Wu82bff272014-12-27 14:12:52 +0800513
514void Queue::wait()
515{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600516 EXPECT(vkQueueWaitIdle(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800517}
518
Courtney Goeltzenleuchter0d2efef2015-03-25 17:14:29 -0600519void Queue::signal_semaphore(Semaphore &sem)
Chia-I Wu82bff272014-12-27 14:12:52 +0800520{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600521 EXPECT(vkQueueSignalSemaphore(obj(), sem.obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800522}
523
Courtney Goeltzenleuchter0d2efef2015-03-25 17:14:29 -0600524void Queue::wait_semaphore(Semaphore &sem)
Chia-I Wu82bff272014-12-27 14:12:52 +0800525{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600526 EXPECT(vkQueueWaitSemaphore(obj(), sem.obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800527}
528
529GpuMemory::~GpuMemory()
530{
531 if (initialized() && own())
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600532 EXPECT(vkFreeMemory(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800533}
534
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600535void GpuMemory::init(const Device &dev, const VkMemoryAllocInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800536{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600537 DERIVED_OBJECT_INIT(vkAllocMemory, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800538}
539
Chia-I Wu82bff272014-12-27 14:12:52 +0800540void GpuMemory::init(const Device &dev, size_t size, const void *data)
541{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600542 DERIVED_OBJECT_INIT(vkPinSystemMemory, dev.obj(), data, size);
Chia-I Wu82bff272014-12-27 14:12:52 +0800543}
544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600545void GpuMemory::init(const Device &dev, const VkMemoryOpenInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800546{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547 DERIVED_OBJECT_INIT(vkOpenSharedMemory, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800548}
549
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600550void GpuMemory::init(const Device &dev, const VkPeerMemoryOpenInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800551{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600552 DERIVED_OBJECT_INIT(vkOpenPeerMemory, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800553}
554
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600555void GpuMemory::set_priority(VkMemoryPriority priority)
Chia-I Wu82bff272014-12-27 14:12:52 +0800556{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600557 EXPECT(vkSetMemoryPriority(obj(), priority) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800558}
559
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600560const void *GpuMemory::map(VkFlags flags) const
Chia-I Wu82bff272014-12-27 14:12:52 +0800561{
562 void *data;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600563 if (!EXPECT(vkMapMemory(obj(), flags, &data) == VK_SUCCESS))
Chia-I Wu82bff272014-12-27 14:12:52 +0800564 data = NULL;
565
566 return data;
567}
568
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600569void *GpuMemory::map(VkFlags flags)
Chia-I Wu82bff272014-12-27 14:12:52 +0800570{
571 void *data;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600572 if (!EXPECT(vkMapMemory(obj(), flags, &data) == VK_SUCCESS))
Chia-I Wu82bff272014-12-27 14:12:52 +0800573 data = NULL;
574
575 return data;
576}
577
578void GpuMemory::unmap() const
579{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600580 EXPECT(vkUnmapMemory(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800581}
582
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600583void Fence::init(const Device &dev, const VkFenceCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800584{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600585 DERIVED_OBJECT_INIT(vkCreateFence, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800586 alloc_memory(dev);
587}
588
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600589void Semaphore::init(const Device &dev, const VkSemaphoreCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800590{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500591 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600592 DERIVED_OBJECT_INIT(vkCreateSemaphore, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800593 alloc_memory(dev);
594}
595
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600596void Semaphore::init(const Device &dev, const VkSemaphoreOpenInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800597{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500598 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600599 DERIVED_OBJECT_INIT(vkOpenSharedSemaphore, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800600}
601
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600602void Event::init(const Device &dev, const VkEventCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800603{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500604 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600605 DERIVED_OBJECT_INIT(vkCreateEvent, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800606 alloc_memory(dev);
607}
608
609void Event::set()
610{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600611 EXPECT(vkSetEvent(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800612}
613
614void Event::reset()
615{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600616 EXPECT(vkResetEvent(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800617}
618
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600619void QueryPool::init(const Device &dev, const VkQueryPoolCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800620{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500621 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 DERIVED_OBJECT_INIT(vkCreateQueryPool, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800623 alloc_memory(dev);
624}
625
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626VkResult QueryPool::results(uint32_t start, uint32_t count, size_t size, void *data)
Chia-I Wu82bff272014-12-27 14:12:52 +0800627{
628 size_t tmp = size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600629 VkResult err = vkGetQueryPoolResults(obj(), start, count, &tmp, data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600630 if (err == VK_SUCCESS) {
Chia-I Wu82bff272014-12-27 14:12:52 +0800631 if (!EXPECT(tmp == size))
632 memset(data, 0, size);
633 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600634 EXPECT(err == VK_NOT_READY);
Chia-I Wu82bff272014-12-27 14:12:52 +0800635 }
636
637 return err;
638}
639
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600640void Buffer::init(const Device &dev, const VkBufferCreateInfo &info)
Chia-I Wu714df452015-01-01 07:55:04 +0800641{
642 init_no_mem(dev, info);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500643 alloc_memory(dev);
Chia-I Wu714df452015-01-01 07:55:04 +0800644}
645
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600646void Buffer::init_no_mem(const Device &dev, const VkBufferCreateInfo &info)
Chia-I Wu714df452015-01-01 07:55:04 +0800647{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500648 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600649 DERIVED_OBJECT_INIT(vkCreateBuffer, dev.obj(), &info);
Chia-I Wu714df452015-01-01 07:55:04 +0800650 create_info_ = info;
651}
652
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600653void BufferView::init(const Device &dev, const VkBufferViewCreateInfo &info)
Chia-I Wu714df452015-01-01 07:55:04 +0800654{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600655 DERIVED_OBJECT_INIT(vkCreateBufferView, dev.obj(), &info);
Chia-I Wu714df452015-01-01 07:55:04 +0800656 alloc_memory(dev);
657}
658
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600659void Image::init(const Device &dev, const VkImageCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800660{
661 init_no_mem(dev, info);
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500662 alloc_memory(dev);
Chia-I Wu82bff272014-12-27 14:12:52 +0800663}
664
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600665void Image::init_no_mem(const Device &dev, const VkImageCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800666{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500667 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600668 DERIVED_OBJECT_INIT(vkCreateImage, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800669 init_info(dev, info);
670}
671
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600672void Image::init(const Device &dev, const VkPeerImageOpenInfo &info, const VkImageCreateInfo &original_info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800673{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600674 VkImage img;
675 VkGpuMemory mem;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600676 EXPECT(vkOpenPeerImage(dev.obj(), &info, &img, &mem) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800677 Object::init(img);
678
679 init_info(dev, original_info);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500680 alloc_memory(dev, std::vector<VkGpuMemory>(1, mem));
Chia-I Wu82bff272014-12-27 14:12:52 +0800681}
682
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600683void Image::init_info(const Device &dev, const VkImageCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800684{
685 create_info_ = info;
686
687 for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) {
688 if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) {
689 format_features_ = it->features;
690 break;
691 }
692 }
693}
694
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500695void Image::bind_memory(const Device &dev, uint32_t alloc_idx, const VkImageMemoryBindInfo &info,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600696 const GpuMemory &mem, VkGpuSize mem_offset)
Chia-I Wu714df452015-01-01 07:55:04 +0800697{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500698 VkQueue queue = dev.graphics_queues()[0]->obj();
699 EXPECT(!alloc_idx && vkQueueBindImageMemoryRange(queue, obj(), 0, &info, mem.obj(), mem_offset) == VK_SUCCESS);
Chia-I Wu714df452015-01-01 07:55:04 +0800700}
701
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600702VkSubresourceLayout Image::subresource_layout(const VkImageSubresource &subres) const
Chia-I Wu82bff272014-12-27 14:12:52 +0800703{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600704 const VkSubresourceInfoType type = VK_INFO_TYPE_SUBRESOURCE_LAYOUT;
705 VkSubresourceLayout data;
Chia-I Wu82bff272014-12-27 14:12:52 +0800706 size_t size = sizeof(data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600707 if (!EXPECT(vkGetImageSubresourceInfo(obj(), &subres, type, &size, &data) == VK_SUCCESS && size == sizeof(data)))
Chia-I Wu82bff272014-12-27 14:12:52 +0800708 memset(&data, 0, sizeof(data));
709
710 return data;
711}
712
713bool Image::transparent() const
714{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600715 return (create_info_.tiling == VK_LINEAR_TILING &&
Chia-I Wu82bff272014-12-27 14:12:52 +0800716 create_info_.samples == 1 &&
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600717 !(create_info_.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
718 VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)));
Chia-I Wu82bff272014-12-27 14:12:52 +0800719}
720
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600721void ImageView::init(const Device &dev, const VkImageViewCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800722{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 DERIVED_OBJECT_INIT(vkCreateImageView, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800724 alloc_memory(dev);
725}
726
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600727void ColorAttachmentView::init(const Device &dev, const VkColorAttachmentViewCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800728{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600729 DERIVED_OBJECT_INIT(vkCreateColorAttachmentView, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800730 alloc_memory(dev);
731}
732
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600733void DepthStencilView::init(const Device &dev, const VkDepthStencilViewCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800734{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600735 DERIVED_OBJECT_INIT(vkCreateDepthStencilView, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800736 alloc_memory(dev);
737}
738
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600739void Shader::init(const Device &dev, const VkShaderCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800740{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500741 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742 DERIVED_OBJECT_INIT(vkCreateShader, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800743}
744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600745VkResult Shader::init_try(const Device &dev, const VkShaderCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800746{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747 VkShader sh;
748 VkResult err = vkCreateShader(dev.obj(), &info, &sh);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600749 if (err == VK_SUCCESS)
Chia-I Wu82bff272014-12-27 14:12:52 +0800750 Object::init(sh);
751
752 return err;
753}
754
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600755void Pipeline::init(const Device &dev, const VkGraphicsPipelineCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800756{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500757 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758 DERIVED_OBJECT_INIT(vkCreateGraphicsPipeline, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800759 alloc_memory(dev);
760}
761
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -0600762void Pipeline::init(
763 const Device &dev,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764 const VkGraphicsPipelineCreateInfo &info,
765 const VkPipeline basePipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -0600766{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500767 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600768 DERIVED_OBJECT_INIT(vkCreateGraphicsPipelineDerivative, dev.obj(), &info, basePipeline);
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -0600769 alloc_memory(dev);
770}
771
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600772void Pipeline::init(const Device &dev, const VkComputePipelineCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800773{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500774 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775 DERIVED_OBJECT_INIT(vkCreateComputePipeline, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800776 alloc_memory(dev);
777}
778
779void Pipeline::init(const Device&dev, size_t size, const void *data)
780{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500781 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600782 DERIVED_OBJECT_INIT(vkLoadPipeline, dev.obj(), size, data);
Chia-I Wu82bff272014-12-27 14:12:52 +0800783 alloc_memory(dev);
784}
785
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -0600786void Pipeline::init(
787 const Device&dev,
788 size_t size,
789 const void *data,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600790 const VkPipeline basePipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -0600791{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500792 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793 DERIVED_OBJECT_INIT(vkLoadPipelineDerivative, dev.obj(), size, data, basePipeline);
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -0600794 alloc_memory(dev);
795}
796
Chia-I Wu82bff272014-12-27 14:12:52 +0800797size_t Pipeline::store(size_t size, void *data)
798{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600799 if (!EXPECT(vkStorePipeline(obj(), &size, data) == VK_SUCCESS))
Chia-I Wu82bff272014-12-27 14:12:52 +0800800 size = 0;
801
802 return size;
803}
804
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600805void Sampler::init(const Device &dev, const VkSamplerCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800806{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500807 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600808 DERIVED_OBJECT_INIT(vkCreateSampler, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800809 alloc_memory(dev);
810}
811
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600812void DescriptorSetLayout::init(const Device &dev, const VkDescriptorSetLayoutCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800813{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500814 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600815 DERIVED_OBJECT_INIT(vkCreateDescriptorSetLayout, dev.obj(), &info);
Chia-I Wuf8385062015-01-04 16:27:24 +0800816 alloc_memory(dev);
Chia-I Wu82bff272014-12-27 14:12:52 +0800817}
818
Chia-I Wu7732cb22015-03-26 15:27:55 +0800819void DescriptorSetLayoutChain::init(const Device &dev, const std::vector<const DescriptorSetLayout *> &layouts)
Chia-I Wu82bff272014-12-27 14:12:52 +0800820{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500821 DEV_INIT(dev);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600822 const std::vector<VkDescriptorSetLayout> layout_objs = make_objects<VkDescriptorSetLayout>(layouts);
Chia-I Wu7732cb22015-03-26 15:27:55 +0800823
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600824 DERIVED_OBJECT_INIT(vkCreateDescriptorSetLayoutChain, dev.obj(), layout_objs.size(), &layout_objs[0]);
Chia-I Wu7732cb22015-03-26 15:27:55 +0800825 alloc_memory(dev);
Chia-I Wu82bff272014-12-27 14:12:52 +0800826}
827
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600828void DescriptorPool::init(const Device &dev, VkDescriptorPoolUsage usage,
829 uint32_t max_sets, const VkDescriptorPoolCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800830{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500831 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600832 DERIVED_OBJECT_INIT(vkCreateDescriptorPool, dev.obj(), usage, max_sets, &info);
Chia-I Wuf8385062015-01-04 16:27:24 +0800833 alloc_memory(dev);
Chia-I Wu82bff272014-12-27 14:12:52 +0800834}
835
Chia-I Wudee95612015-03-26 15:23:52 +0800836void DescriptorPool::reset()
Chia-I Wu82bff272014-12-27 14:12:52 +0800837{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600838 EXPECT(vkResetDescriptorPool(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800839}
840
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500841std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const std::vector<const DescriptorSetLayout *> &layouts)
Chia-I Wu82bff272014-12-27 14:12:52 +0800842{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600843 const std::vector<VkDescriptorSetLayout> layout_objs = make_objects<VkDescriptorSetLayout>(layouts);
Chia-I Wuf8385062015-01-04 16:27:24 +0800844
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600845 std::vector<VkDescriptorSet> set_objs;
Chia-I Wuf8385062015-01-04 16:27:24 +0800846 set_objs.resize(layout_objs.size());
847
848 uint32_t set_count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600849 VkResult err = vkAllocDescriptorSets(obj(), usage, layout_objs.size(), &layout_objs[0], &set_objs[0], &set_count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600850 if (err == VK_SUCCESS)
Chia-I Wuf8385062015-01-04 16:27:24 +0800851 EXPECT(set_count == set_objs.size());
852 set_objs.resize(set_count);
853
854 std::vector<DescriptorSet *> sets;
855 sets.reserve(set_count);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600856 for (std::vector<VkDescriptorSet>::const_iterator it = set_objs.begin(); it != set_objs.end(); it++) {
Chia-I Wuf8385062015-01-04 16:27:24 +0800857 // do descriptor sets need memories bound?
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500858 DescriptorSet *descriptorSet = new DescriptorSet(*it);
859 descriptorSet->dev_ = &dev;
860 sets.push_back(descriptorSet);
Chia-I Wuf8385062015-01-04 16:27:24 +0800861 }
Chia-I Wuf8385062015-01-04 16:27:24 +0800862 return sets;
863}
864
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500865std::vector<DescriptorSet *> DescriptorPool::alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout, uint32_t count)
Chia-I Wuf8385062015-01-04 16:27:24 +0800866{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500867 return alloc_sets(dev, usage, std::vector<const DescriptorSetLayout *>(count, &layout));
Chia-I Wuf8385062015-01-04 16:27:24 +0800868}
869
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500870DescriptorSet *DescriptorPool::alloc_sets(const Device &dev, VkDescriptorSetUsage usage, const DescriptorSetLayout &layout)
Chia-I Wuf8385062015-01-04 16:27:24 +0800871{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500872 std::vector<DescriptorSet *> set = alloc_sets(dev, usage, layout, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +0800873 return (set.empty()) ? NULL : set[0];
874}
875
Chia-I Wu8d24b3b2015-03-26 13:14:16 +0800876void DescriptorPool::clear_sets(const std::vector<DescriptorSet *> &sets)
Chia-I Wuf8385062015-01-04 16:27:24 +0800877{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600878 const std::vector<VkDescriptorSet> set_objs = make_objects<VkDescriptorSet>(sets);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 vkClearDescriptorSets(obj(), set_objs.size(), &set_objs[0]);
Chia-I Wuf8385062015-01-04 16:27:24 +0800880}
881
Chia-I Wu7732cb22015-03-26 15:27:55 +0800882void DescriptorSet::update(const std::vector<const void *> &update_array)
Chia-I Wuf8385062015-01-04 16:27:24 +0800883{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600884 vkUpdateDescriptors(obj(), update_array.size(), const_cast<const void **>(&update_array[0]));
Chia-I Wu82bff272014-12-27 14:12:52 +0800885}
886
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600887void DynamicVpStateObject::init(const Device &dev, const VkDynamicVpStateCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800888{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600889 DERIVED_OBJECT_INIT(vkCreateDynamicViewportState, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800890 alloc_memory(dev);
891}
892
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600893void DynamicRsStateObject::init(const Device &dev, const VkDynamicRsStateCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800894{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600895 DERIVED_OBJECT_INIT(vkCreateDynamicRasterState, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800896 alloc_memory(dev);
897}
898
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600899void DynamicCbStateObject::init(const Device &dev, const VkDynamicCbStateCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800900{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600901 DERIVED_OBJECT_INIT(vkCreateDynamicColorBlendState, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800902 alloc_memory(dev);
903}
904
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600905void DynamicDsStateObject::init(const Device &dev, const VkDynamicDsStateCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800906{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600907 DERIVED_OBJECT_INIT(vkCreateDynamicDepthStencilState, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800908 alloc_memory(dev);
909}
910
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600911void CmdBuffer::init(const Device &dev, const VkCmdBufferCreateInfo &info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800912{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500913 DEV_INIT(dev);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600914 DERIVED_OBJECT_INIT(vkCreateCommandBuffer, dev.obj(), &info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800915}
916
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600917void CmdBuffer::begin(const VkCmdBufferBeginInfo *info)
Chia-I Wu82bff272014-12-27 14:12:52 +0800918{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600919 EXPECT(vkBeginCommandBuffer(obj(), info) == VK_SUCCESS);
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700920}
921
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600922void CmdBuffer::begin(VkRenderPass renderpass_obj, VkFramebuffer framebuffer_obj)
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700923{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600924 VkCmdBufferBeginInfo info = {};
925 VkCmdBufferGraphicsBeginInfo graphics_cmd_buf_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600926 graphics_cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO;
Tony Barbour901f3bc2015-04-01 17:10:07 -0600927 graphics_cmd_buf_info.pNext = NULL;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600928 graphics_cmd_buf_info.renderPassContinue.renderPass = renderpass_obj;
929 graphics_cmd_buf_info.renderPassContinue.framebuffer = framebuffer_obj;
Tony Barbour901f3bc2015-04-01 17:10:07 -0600930
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600931 info.flags = VK_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT |
932 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
933 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700934 info.pNext = &graphics_cmd_buf_info;
935
936 begin(&info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800937}
938
939void CmdBuffer::begin()
940{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600941 VkCmdBufferBeginInfo info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600942 info.flags = VK_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT |
943 VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
944 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700945
946 begin(&info);
Chia-I Wu82bff272014-12-27 14:12:52 +0800947}
948
949void CmdBuffer::end()
950{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600951 EXPECT(vkEndCommandBuffer(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800952}
953
954void CmdBuffer::reset()
955{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600956 EXPECT(vkResetCommandBuffer(obj()) == VK_SUCCESS);
Chia-I Wu82bff272014-12-27 14:12:52 +0800957}
958
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600959}; // namespace vk_testing