Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 1 | // XGL 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 | #include <iostream> |
| 24 | #include <string.h> // memset(), memcmp() |
| 25 | #include "xgltestbinding.h" |
| 26 | |
| 27 | namespace { |
| 28 | |
| 29 | #define DERIVED_OBJECT_INIT(create_func, ...) \ |
| 30 | do { \ |
| 31 | obj_type obj; \ |
| 32 | if (EXPECT(create_func(__VA_ARGS__, &obj) == XGL_SUCCESS)) \ |
| 33 | base_type::init(obj); \ |
| 34 | } while (0) |
| 35 | |
| 36 | #define STRINGIFY(x) #x |
| 37 | #define EXPECT(expr) ((expr) ? true : expect_failure(STRINGIFY(expr), __FILE__, __LINE__, __FUNCTION__)) |
| 38 | |
| 39 | xgl_testing::ErrorCallback error_callback; |
| 40 | |
| 41 | bool expect_failure(const char *expr, const char *file, unsigned int line, const char *function) |
| 42 | { |
| 43 | if (error_callback) { |
| 44 | error_callback(expr, file, line, function); |
| 45 | } else { |
| 46 | std::cerr << file << ":" << line << ": " << function << |
| 47 | ": Expectation `" << expr << "' failed.\n"; |
| 48 | } |
| 49 | |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | template<class T, class S> |
| 54 | std::vector<T> make_objects(const std::vector<S> &v) |
| 55 | { |
| 56 | std::vector<T> objs; |
| 57 | objs.reserve(v.size()); |
| 58 | for (typename std::vector<S>::const_iterator it = v.begin(); it != v.end(); it++) |
| 59 | objs.push_back((*it)->obj()); |
| 60 | return objs; |
| 61 | } |
| 62 | |
| 63 | template<typename T> |
| 64 | std::vector<T> get_info(XGL_PHYSICAL_GPU gpu, XGL_PHYSICAL_GPU_INFO_TYPE type, size_t min_elems) |
| 65 | { |
| 66 | std::vector<T> info; |
Jon Ashburn | f7e282a | 2015-01-22 13:33:15 -0700 | [diff] [blame] | 67 | size_t size = sizeof(T); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 68 | if (EXPECT(xglGetGpuInfo(gpu, type, &size, NULL) == XGL_SUCCESS && size % sizeof(T) == 0)) { |
| 69 | info.resize(size / sizeof(T)); |
| 70 | if (!EXPECT(xglGetGpuInfo(gpu, type, &size, &info[0]) == XGL_SUCCESS && size == info.size() * sizeof(T))) |
| 71 | info.clear(); |
| 72 | } |
| 73 | |
| 74 | if (info.size() < min_elems) |
| 75 | info.resize(min_elems); |
| 76 | |
| 77 | return info; |
| 78 | } |
| 79 | |
| 80 | template<typename T> |
| 81 | std::vector<T> get_info(XGL_BASE_OBJECT obj, XGL_OBJECT_INFO_TYPE type, size_t min_elems) |
| 82 | { |
| 83 | std::vector<T> info; |
Jon Ashburn | f7e282a | 2015-01-22 13:33:15 -0700 | [diff] [blame] | 84 | size_t size = sizeof(T); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 85 | if (EXPECT(xglGetObjectInfo(obj, type, &size, NULL) == XGL_SUCCESS && size % sizeof(T) == 0)) { |
| 86 | info.resize(size / sizeof(T)); |
| 87 | if (!EXPECT(xglGetObjectInfo(obj, type, &size, &info[0]) == XGL_SUCCESS && size == info.size() * sizeof(T))) |
| 88 | info.clear(); |
| 89 | } |
| 90 | |
| 91 | if (info.size() < min_elems) |
| 92 | info.resize(min_elems); |
| 93 | |
| 94 | return info; |
| 95 | } |
| 96 | |
| 97 | } // namespace |
| 98 | |
| 99 | namespace xgl_testing { |
| 100 | |
| 101 | void set_error_callback(ErrorCallback callback) |
| 102 | { |
| 103 | error_callback = callback; |
| 104 | } |
| 105 | |
| 106 | XGL_PHYSICAL_GPU_PROPERTIES PhysicalGpu::properties() const |
| 107 | { |
| 108 | return get_info<XGL_PHYSICAL_GPU_PROPERTIES>(gpu_, XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, 1)[0]; |
| 109 | } |
| 110 | |
| 111 | XGL_PHYSICAL_GPU_PERFORMANCE PhysicalGpu::performance() const |
| 112 | { |
| 113 | return get_info<XGL_PHYSICAL_GPU_PERFORMANCE>(gpu_, XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE, 1)[0]; |
| 114 | } |
| 115 | |
| 116 | std::vector<XGL_PHYSICAL_GPU_QUEUE_PROPERTIES> PhysicalGpu::queue_properties() const |
| 117 | { |
| 118 | return get_info<XGL_PHYSICAL_GPU_QUEUE_PROPERTIES>(gpu_, XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, 0); |
| 119 | } |
| 120 | |
| 121 | XGL_PHYSICAL_GPU_MEMORY_PROPERTIES PhysicalGpu::memory_properties() const |
| 122 | { |
| 123 | return get_info<XGL_PHYSICAL_GPU_MEMORY_PROPERTIES>(gpu_, XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES, 1)[0]; |
| 124 | } |
| 125 | |
| 126 | std::vector<const char *> PhysicalGpu::layers(std::vector<char> &buf) const |
| 127 | { |
| 128 | const size_t max_layer_count = 16; |
| 129 | const size_t max_string_size = 256; |
| 130 | |
| 131 | buf.resize(max_layer_count * max_string_size); |
| 132 | |
| 133 | std::vector<const char *> layers; |
| 134 | layers.reserve(max_layer_count); |
| 135 | for (size_t i = 0; i < max_layer_count; i++) |
| 136 | layers.push_back(&buf[0] + max_string_size * i); |
| 137 | |
| 138 | char * const *out = const_cast<char * const *>(&layers[0]); |
| 139 | size_t count; |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 140 | if (!EXPECT(xglEnumerateLayers(gpu_, max_layer_count, max_string_size, &count, out, NULL) == XGL_SUCCESS)) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 141 | count = 0; |
| 142 | layers.resize(count); |
| 143 | |
| 144 | return layers; |
| 145 | } |
| 146 | |
| 147 | std::vector<const char *> PhysicalGpu::extensions() const |
| 148 | { |
| 149 | static const char *known_exts[] = { |
| 150 | "XGL_WSI_X11", |
| 151 | }; |
| 152 | |
| 153 | std::vector<const char *> exts; |
| 154 | for (int i = 0; i < sizeof(known_exts) / sizeof(known_exts[0]); i++) { |
| 155 | XGL_RESULT err = xglGetExtensionSupport(gpu_, known_exts[i]); |
| 156 | if (err == XGL_SUCCESS) |
| 157 | exts.push_back(known_exts[i]); |
| 158 | } |
| 159 | |
| 160 | return exts; |
| 161 | } |
| 162 | |
| 163 | XGL_GPU_COMPATIBILITY_INFO PhysicalGpu::compatibility(const PhysicalGpu &other) const |
| 164 | { |
| 165 | XGL_GPU_COMPATIBILITY_INFO data; |
| 166 | if (!EXPECT(xglGetMultiGpuCompatibility(gpu_, other.gpu_, &data) == XGL_SUCCESS)) |
| 167 | memset(&data, 0, sizeof(data)); |
| 168 | |
| 169 | return data; |
| 170 | } |
| 171 | |
| 172 | void BaseObject::init(XGL_BASE_OBJECT obj, bool own) |
| 173 | { |
| 174 | EXPECT(!initialized()); |
| 175 | reinit(obj, own); |
| 176 | } |
| 177 | |
| 178 | void BaseObject::reinit(XGL_BASE_OBJECT obj, bool own) |
| 179 | { |
| 180 | obj_ = obj; |
| 181 | own_obj_ = own; |
| 182 | } |
| 183 | |
| 184 | uint32_t BaseObject::memory_allocation_count() const |
| 185 | { |
| 186 | return memory_requirements().size(); |
| 187 | } |
| 188 | |
| 189 | std::vector<XGL_MEMORY_REQUIREMENTS> BaseObject::memory_requirements() const |
| 190 | { |
| 191 | std::vector<XGL_MEMORY_REQUIREMENTS> info = |
| 192 | get_info<XGL_MEMORY_REQUIREMENTS>(obj_, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, 0); |
| 193 | if (info.size() == 1 && !info[0].size) |
| 194 | info.clear(); |
| 195 | |
| 196 | return info; |
| 197 | } |
| 198 | |
| 199 | void Object::init(XGL_OBJECT obj, bool own) |
| 200 | { |
| 201 | BaseObject::init(obj, own); |
| 202 | mem_alloc_count_ = memory_allocation_count(); |
| 203 | } |
| 204 | |
| 205 | void Object::reinit(XGL_OBJECT obj, bool own) |
| 206 | { |
| 207 | cleanup(); |
| 208 | BaseObject::reinit(obj, own); |
| 209 | mem_alloc_count_ = memory_allocation_count(); |
| 210 | } |
| 211 | |
| 212 | void Object::cleanup() |
| 213 | { |
| 214 | if (!initialized()) |
| 215 | return; |
| 216 | |
| 217 | unbind_memory(); |
| 218 | |
| 219 | if (internal_mems_) { |
| 220 | delete[] internal_mems_; |
| 221 | internal_mems_ = NULL; |
| 222 | primary_mem_ = NULL; |
| 223 | } |
| 224 | |
| 225 | mem_alloc_count_ = 0; |
| 226 | |
| 227 | if (own()) |
| 228 | EXPECT(xglDestroyObject(obj()) == XGL_SUCCESS); |
| 229 | } |
| 230 | |
| 231 | void Object::bind_memory(uint32_t alloc_idx, const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 232 | { |
| 233 | EXPECT(!alloc_idx && xglBindObjectMemory(obj(), mem.obj(), mem_offset) == XGL_SUCCESS); |
| 234 | } |
| 235 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 236 | void Object::bind_memory(uint32_t alloc_idx, XGL_GPU_SIZE offset, XGL_GPU_SIZE size, |
| 237 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 238 | { |
| 239 | EXPECT(!alloc_idx && xglBindObjectMemoryRange(obj(), offset, size, mem.obj(), mem_offset) == XGL_SUCCESS); |
| 240 | } |
| 241 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 242 | void Object::unbind_memory(uint32_t alloc_idx) |
| 243 | { |
| 244 | EXPECT(!alloc_idx && xglBindObjectMemory(obj(), XGL_NULL_HANDLE, 0) == XGL_SUCCESS); |
| 245 | } |
| 246 | |
| 247 | void Object::unbind_memory() |
| 248 | { |
| 249 | for (uint32_t i = 0; i < mem_alloc_count_; i++) |
| 250 | unbind_memory(i); |
| 251 | } |
| 252 | |
| 253 | void Object::alloc_memory(const Device &dev, bool for_linear_img) |
| 254 | { |
| 255 | if (!EXPECT(!internal_mems_) || !mem_alloc_count_) |
| 256 | return; |
| 257 | |
| 258 | internal_mems_ = new GpuMemory[mem_alloc_count_]; |
| 259 | |
| 260 | const std::vector<XGL_MEMORY_REQUIREMENTS> mem_reqs = memory_requirements(); |
| 261 | for (int i = 0; i < mem_reqs.size(); i++) { |
| 262 | XGL_MEMORY_ALLOC_INFO info = GpuMemory::alloc_info(mem_reqs[i]); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 263 | std::vector<uint32_t> heap_ids; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 264 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 265 | // prefer CPU visible heaps |
| 266 | std::vector<uint32_t> non_visible_heaps; |
| 267 | info.heapCount = 0; |
| 268 | for (uint32_t j = 0; j < mem_reqs[i].heapCount; j++) { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 269 | const uint32_t heap = mem_reqs[i].pHeaps[j]; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 270 | const XGL_MEMORY_HEAP_PROPERTIES &props = dev.heap_properties()[heap]; |
| 271 | |
| 272 | if (props.flags & XGL_MEMORY_HEAP_CPU_VISIBLE_BIT) |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 273 | heap_ids.push_back(heap); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 274 | else |
| 275 | non_visible_heaps.push_back(heap); |
| 276 | } |
| 277 | for (std::vector<uint32_t>::const_iterator it = non_visible_heaps.begin(); it != non_visible_heaps.end(); it++) |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 278 | heap_ids.push_back(*it); |
| 279 | |
| 280 | info.heapCount = heap_ids.size(); |
| 281 | info.pHeaps = &heap_ids[0]; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 282 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 283 | primary_mem_ = &internal_mems_[i]; |
| 284 | |
| 285 | internal_mems_[i].init(dev, info); |
| 286 | bind_memory(i, internal_mems_[i], 0); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | void Object::alloc_memory(const std::vector<XGL_GPU_MEMORY> &mems) |
| 291 | { |
| 292 | if (!EXPECT(!internal_mems_) || !mem_alloc_count_) |
| 293 | return; |
| 294 | |
| 295 | internal_mems_ = new GpuMemory[mem_alloc_count_]; |
| 296 | |
| 297 | const std::vector<XGL_MEMORY_REQUIREMENTS> mem_reqs = memory_requirements(); |
| 298 | if (!EXPECT(mem_reqs.size() == mems.size())) |
| 299 | return; |
| 300 | |
| 301 | for (int i = 0; i < mem_reqs.size(); i++) { |
| 302 | primary_mem_ = &internal_mems_[i]; |
| 303 | |
| 304 | internal_mems_[i].init(mems[i]); |
| 305 | bind_memory(i, internal_mems_[i], 0); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | std::vector<XGL_GPU_MEMORY> Object::memories() const |
| 310 | { |
| 311 | std::vector<XGL_GPU_MEMORY> mems; |
| 312 | if (internal_mems_) { |
| 313 | mems.reserve(mem_alloc_count_); |
| 314 | for (uint32_t i = 0; i < mem_alloc_count_; i++) |
| 315 | mems.push_back(internal_mems_[i].obj()); |
| 316 | } |
| 317 | |
| 318 | return mems; |
| 319 | } |
| 320 | |
| 321 | Device::~Device() |
| 322 | { |
| 323 | if (!initialized()) |
| 324 | return; |
| 325 | |
| 326 | for (int i = 0; i < QUEUE_COUNT; i++) { |
| 327 | for (std::vector<Queue *>::iterator it = queues_[i].begin(); it != queues_[i].end(); it++) |
| 328 | delete *it; |
| 329 | queues_[i].clear(); |
| 330 | } |
| 331 | |
| 332 | EXPECT(xglDestroyDevice(obj()) == XGL_SUCCESS); |
| 333 | } |
| 334 | |
Chia-I Wu | 510c999 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 335 | void Device::init(bool enable_layers) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 336 | { |
| 337 | // request all queues |
| 338 | const std::vector<XGL_PHYSICAL_GPU_QUEUE_PROPERTIES> queue_props = gpu_.queue_properties(); |
| 339 | std::vector<XGL_DEVICE_QUEUE_CREATE_INFO> queue_info; |
| 340 | queue_info.reserve(queue_props.size()); |
| 341 | for (int i = 0; i < queue_props.size(); i++) { |
| 342 | XGL_DEVICE_QUEUE_CREATE_INFO qi = {}; |
| 343 | qi.queueNodeIndex = i; |
| 344 | qi.queueCount = queue_props[i].queueCount; |
| 345 | queue_info.push_back(qi); |
| 346 | } |
| 347 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 348 | XGL_LAYER_CREATE_INFO layer_info = {}; |
| 349 | layer_info.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO; |
Chia-I Wu | 510c999 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 350 | |
| 351 | std::vector<const char *> layers; |
| 352 | std::vector<char> layer_buf; |
| 353 | // request all layers |
| 354 | if (enable_layers) { |
| 355 | layers = gpu_.layers(layer_buf); |
| 356 | layer_info.layerCount = layers.size(); |
| 357 | layer_info.ppActiveLayerNames = &layers[0]; |
| 358 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 359 | |
| 360 | const std::vector<const char *> exts = gpu_.extensions(); |
| 361 | |
| 362 | XGL_DEVICE_CREATE_INFO dev_info = {}; |
| 363 | dev_info.sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
Jon Ashburn | f7e282a | 2015-01-22 13:33:15 -0700 | [diff] [blame] | 364 | dev_info.pNext = (enable_layers) ? static_cast<void *>(&layer_info) : NULL; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 365 | dev_info.queueRecordCount = queue_info.size(); |
| 366 | dev_info.pRequestedQueues = &queue_info[0]; |
| 367 | dev_info.extensionCount = exts.size(); |
| 368 | dev_info.ppEnabledExtensionNames = &exts[0]; |
| 369 | dev_info.maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE; |
| 370 | dev_info.flags = XGL_DEVICE_CREATE_VALIDATION_BIT; |
| 371 | |
| 372 | init(dev_info); |
| 373 | } |
| 374 | |
| 375 | void Device::init(const XGL_DEVICE_CREATE_INFO &info) |
| 376 | { |
| 377 | DERIVED_OBJECT_INIT(xglCreateDevice, gpu_.obj(), &info); |
| 378 | |
| 379 | init_queues(); |
| 380 | init_heap_props(); |
| 381 | init_formats(); |
| 382 | } |
| 383 | |
| 384 | void Device::init_queues() |
| 385 | { |
| 386 | const struct { |
| 387 | QueueIndex index; |
| 388 | XGL_QUEUE_TYPE type; |
| 389 | } queue_mapping[] = { |
| 390 | { GRAPHICS, XGL_QUEUE_TYPE_GRAPHICS }, |
| 391 | { COMPUTE, XGL_QUEUE_TYPE_COMPUTE }, |
| 392 | { DMA, XGL_QUEUE_TYPE_DMA }, |
| 393 | }; |
| 394 | |
| 395 | for (int i = 0; i < QUEUE_COUNT; i++) { |
| 396 | uint32_t idx = 0; |
| 397 | |
| 398 | while (true) { |
| 399 | XGL_QUEUE queue; |
| 400 | XGL_RESULT err = xglGetDeviceQueue(obj(), queue_mapping[i].type, idx++, &queue); |
| 401 | if (err != XGL_SUCCESS) |
| 402 | break; |
| 403 | queues_[queue_mapping[i].index].push_back(new Queue(queue)); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty()); |
| 408 | } |
| 409 | |
| 410 | void Device::init_heap_props() |
| 411 | { |
| 412 | uint32_t count; |
| 413 | if (!EXPECT(xglGetMemoryHeapCount(obj(), &count) == XGL_SUCCESS && count)) |
| 414 | return; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 415 | |
| 416 | heap_props_.reserve(count); |
| 417 | for (uint32_t i = 0; i < count; i++) { |
| 418 | const XGL_MEMORY_HEAP_INFO_TYPE type = XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES; |
| 419 | XGL_MEMORY_HEAP_PROPERTIES props; |
| 420 | XGL_SIZE size = sizeof(props); |
| 421 | if (EXPECT(xglGetMemoryHeapInfo(obj(), i, type, &size, &props) == XGL_SUCCESS && size == sizeof(props))) |
| 422 | heap_props_.push_back(props); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | void Device::init_formats() |
| 427 | { |
| 428 | for (int ch = XGL_CH_FMT_UNDEFINED; ch <= XGL_MAX_CH_FMT; ch++) { |
| 429 | for (int num = XGL_NUM_FMT_UNDEFINED; num <= XGL_MAX_NUM_FMT; num++) { |
| 430 | const XGL_FORMAT fmt = { static_cast<XGL_CHANNEL_FORMAT>(ch), |
| 431 | static_cast<XGL_NUM_FORMAT>(num) }; |
| 432 | const XGL_FORMAT_PROPERTIES props = format_properties(fmt); |
| 433 | |
| 434 | if (props.linearTilingFeatures) { |
| 435 | const Format tmp = { fmt, XGL_LINEAR_TILING, props.linearTilingFeatures }; |
| 436 | formats_.push_back(tmp); |
| 437 | } |
| 438 | |
| 439 | if (props.optimalTilingFeatures) { |
| 440 | const Format tmp = { fmt, XGL_OPTIMAL_TILING, props.optimalTilingFeatures }; |
| 441 | formats_.push_back(tmp); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | EXPECT(!formats_.empty()); |
| 447 | } |
| 448 | |
| 449 | XGL_FORMAT_PROPERTIES Device::format_properties(XGL_FORMAT format) |
| 450 | { |
| 451 | const XGL_FORMAT_INFO_TYPE type = XGL_INFO_TYPE_FORMAT_PROPERTIES; |
| 452 | XGL_FORMAT_PROPERTIES data; |
| 453 | size_t size = sizeof(data); |
| 454 | if (!EXPECT(xglGetFormatInfo(obj(), format, type, &size, &data) == XGL_SUCCESS && size == sizeof(data))) |
| 455 | memset(&data, 0, sizeof(data)); |
| 456 | |
| 457 | return data; |
| 458 | } |
| 459 | |
| 460 | void Device::wait() |
| 461 | { |
| 462 | EXPECT(xglDeviceWaitIdle(obj()) == XGL_SUCCESS); |
| 463 | } |
| 464 | |
| 465 | XGL_RESULT Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout) |
| 466 | { |
| 467 | const std::vector<XGL_FENCE> fence_objs = make_objects<XGL_FENCE>(fences); |
| 468 | XGL_RESULT err = xglWaitForFences(obj(), fence_objs.size(), &fence_objs[0], wait_all, timeout); |
| 469 | EXPECT(err == XGL_SUCCESS || err == XGL_TIMEOUT); |
| 470 | |
| 471 | return err; |
| 472 | } |
| 473 | |
| 474 | void Queue::submit(const std::vector<const CmdBuffer *> &cmds, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence) |
| 475 | { |
| 476 | const std::vector<XGL_CMD_BUFFER> cmd_objs = make_objects<XGL_CMD_BUFFER>(cmds); |
| 477 | EXPECT(xglQueueSubmit(obj(), cmd_objs.size(), &cmd_objs[0], mem_refs.size(), &mem_refs[0], fence.obj()) == XGL_SUCCESS); |
| 478 | } |
| 479 | |
| 480 | void Queue::submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence) |
| 481 | { |
| 482 | submit(std::vector<const CmdBuffer*>(1, &cmd), mem_refs, fence); |
| 483 | } |
| 484 | |
| 485 | void Queue::submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs) |
| 486 | { |
| 487 | Fence fence; |
| 488 | submit(cmd, mem_refs, fence); |
| 489 | } |
| 490 | |
| 491 | void Queue::set_global_mem_references(const std::vector<XGL_MEMORY_REF> &mem_refs) |
| 492 | { |
| 493 | EXPECT(xglQueueSetGlobalMemReferences(obj(), mem_refs.size(), &mem_refs[0]) == XGL_SUCCESS); |
| 494 | } |
| 495 | |
| 496 | void Queue::wait() |
| 497 | { |
| 498 | EXPECT(xglQueueWaitIdle(obj()) == XGL_SUCCESS); |
| 499 | } |
| 500 | |
| 501 | void Queue::signal_semaphore(QueueSemaphore &sem) |
| 502 | { |
| 503 | EXPECT(xglSignalQueueSemaphore(obj(), sem.obj()) == XGL_SUCCESS); |
| 504 | } |
| 505 | |
| 506 | void Queue::wait_semaphore(QueueSemaphore &sem) |
| 507 | { |
| 508 | EXPECT(xglWaitQueueSemaphore(obj(), sem.obj()) == XGL_SUCCESS); |
| 509 | } |
| 510 | |
| 511 | GpuMemory::~GpuMemory() |
| 512 | { |
| 513 | if (initialized() && own()) |
| 514 | EXPECT(xglFreeMemory(obj()) == XGL_SUCCESS); |
| 515 | } |
| 516 | |
| 517 | void GpuMemory::init(const Device &dev, const XGL_MEMORY_ALLOC_INFO &info) |
| 518 | { |
| 519 | DERIVED_OBJECT_INIT(xglAllocMemory, dev.obj(), &info); |
| 520 | } |
| 521 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 522 | void GpuMemory::init(const Device &dev, size_t size, const void *data) |
| 523 | { |
| 524 | DERIVED_OBJECT_INIT(xglPinSystemMemory, dev.obj(), data, size); |
| 525 | } |
| 526 | |
| 527 | void GpuMemory::init(const Device &dev, const XGL_MEMORY_OPEN_INFO &info) |
| 528 | { |
| 529 | DERIVED_OBJECT_INIT(xglOpenSharedMemory, dev.obj(), &info); |
| 530 | } |
| 531 | |
| 532 | void GpuMemory::init(const Device &dev, const XGL_PEER_MEMORY_OPEN_INFO &info) |
| 533 | { |
| 534 | DERIVED_OBJECT_INIT(xglOpenPeerMemory, dev.obj(), &info); |
| 535 | } |
| 536 | |
| 537 | void GpuMemory::set_priority(XGL_MEMORY_PRIORITY priority) |
| 538 | { |
| 539 | EXPECT(xglSetMemoryPriority(obj(), priority) == XGL_SUCCESS); |
| 540 | } |
| 541 | |
| 542 | const void *GpuMemory::map(XGL_FLAGS flags) const |
| 543 | { |
| 544 | void *data; |
| 545 | if (!EXPECT(xglMapMemory(obj(), flags, &data) == XGL_SUCCESS)) |
| 546 | data = NULL; |
| 547 | |
| 548 | return data; |
| 549 | } |
| 550 | |
| 551 | void *GpuMemory::map(XGL_FLAGS flags) |
| 552 | { |
| 553 | void *data; |
| 554 | if (!EXPECT(xglMapMemory(obj(), flags, &data) == XGL_SUCCESS)) |
| 555 | data = NULL; |
| 556 | |
| 557 | return data; |
| 558 | } |
| 559 | |
| 560 | void GpuMemory::unmap() const |
| 561 | { |
| 562 | EXPECT(xglUnmapMemory(obj()) == XGL_SUCCESS); |
| 563 | } |
| 564 | |
| 565 | void Fence::init(const Device &dev, const XGL_FENCE_CREATE_INFO &info) |
| 566 | { |
| 567 | DERIVED_OBJECT_INIT(xglCreateFence, dev.obj(), &info); |
| 568 | alloc_memory(dev); |
| 569 | } |
| 570 | |
| 571 | void QueueSemaphore::init(const Device &dev, const XGL_QUEUE_SEMAPHORE_CREATE_INFO &info) |
| 572 | { |
| 573 | DERIVED_OBJECT_INIT(xglCreateQueueSemaphore, dev.obj(), &info); |
| 574 | alloc_memory(dev); |
| 575 | } |
| 576 | |
| 577 | void QueueSemaphore::init(const Device &dev, const XGL_QUEUE_SEMAPHORE_OPEN_INFO &info) |
| 578 | { |
| 579 | DERIVED_OBJECT_INIT(xglOpenSharedQueueSemaphore, dev.obj(), &info); |
| 580 | } |
| 581 | |
| 582 | void Event::init(const Device &dev, const XGL_EVENT_CREATE_INFO &info) |
| 583 | { |
| 584 | DERIVED_OBJECT_INIT(xglCreateEvent, dev.obj(), &info); |
| 585 | alloc_memory(dev); |
| 586 | } |
| 587 | |
| 588 | void Event::set() |
| 589 | { |
| 590 | EXPECT(xglSetEvent(obj()) == XGL_SUCCESS); |
| 591 | } |
| 592 | |
| 593 | void Event::reset() |
| 594 | { |
| 595 | EXPECT(xglResetEvent(obj()) == XGL_SUCCESS); |
| 596 | } |
| 597 | |
| 598 | void QueryPool::init(const Device &dev, const XGL_QUERY_POOL_CREATE_INFO &info) |
| 599 | { |
| 600 | DERIVED_OBJECT_INIT(xglCreateQueryPool, dev.obj(), &info); |
| 601 | alloc_memory(dev); |
| 602 | } |
| 603 | |
| 604 | XGL_RESULT QueryPool::results(uint32_t start, uint32_t count, size_t size, void *data) |
| 605 | { |
| 606 | size_t tmp = size; |
| 607 | XGL_RESULT err = xglGetQueryPoolResults(obj(), start, count, &tmp, data); |
| 608 | if (err == XGL_SUCCESS) { |
| 609 | if (!EXPECT(tmp == size)) |
| 610 | memset(data, 0, size); |
| 611 | } else { |
| 612 | EXPECT(err == XGL_NOT_READY); |
| 613 | } |
| 614 | |
| 615 | return err; |
| 616 | } |
| 617 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 618 | void Buffer::init(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) |
| 619 | { |
| 620 | init_no_mem(dev, info); |
| 621 | alloc_memory(dev); |
| 622 | } |
| 623 | |
| 624 | void Buffer::init_no_mem(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) |
| 625 | { |
| 626 | DERIVED_OBJECT_INIT(xglCreateBuffer, dev.obj(), &info); |
| 627 | create_info_ = info; |
| 628 | } |
| 629 | |
| 630 | void BufferView::init(const Device &dev, const XGL_BUFFER_VIEW_CREATE_INFO &info) |
| 631 | { |
| 632 | DERIVED_OBJECT_INIT(xglCreateBufferView, dev.obj(), &info); |
| 633 | alloc_memory(dev); |
| 634 | } |
| 635 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 636 | void Image::init(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 637 | { |
| 638 | init_no_mem(dev, info); |
| 639 | alloc_memory(dev, info.tiling == XGL_LINEAR_TILING); |
| 640 | } |
| 641 | |
| 642 | void Image::init_no_mem(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 643 | { |
| 644 | DERIVED_OBJECT_INIT(xglCreateImage, dev.obj(), &info); |
| 645 | init_info(dev, info); |
| 646 | } |
| 647 | |
| 648 | void Image::init(const Device &dev, const XGL_PEER_IMAGE_OPEN_INFO &info, const XGL_IMAGE_CREATE_INFO &original_info) |
| 649 | { |
| 650 | XGL_IMAGE img; |
| 651 | XGL_GPU_MEMORY mem; |
| 652 | EXPECT(xglOpenPeerImage(dev.obj(), &info, &img, &mem) == XGL_SUCCESS); |
| 653 | Object::init(img); |
| 654 | |
| 655 | init_info(dev, original_info); |
| 656 | alloc_memory(std::vector<XGL_GPU_MEMORY>(1, mem)); |
| 657 | } |
| 658 | |
| 659 | void Image::init_info(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 660 | { |
| 661 | create_info_ = info; |
| 662 | |
| 663 | for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) { |
| 664 | if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) { |
| 665 | format_features_ = it->features; |
| 666 | break; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 671 | void Image::bind_memory(uint32_t alloc_idx, const XGL_IMAGE_MEMORY_BIND_INFO &info, |
| 672 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 673 | { |
| 674 | EXPECT(!alloc_idx && xglBindImageMemoryRange(obj(), &info, mem.obj(), mem_offset) == XGL_SUCCESS); |
| 675 | } |
| 676 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 677 | XGL_SUBRESOURCE_LAYOUT Image::subresource_layout(const XGL_IMAGE_SUBRESOURCE &subres) const |
| 678 | { |
| 679 | const XGL_SUBRESOURCE_INFO_TYPE type = XGL_INFO_TYPE_SUBRESOURCE_LAYOUT; |
| 680 | XGL_SUBRESOURCE_LAYOUT data; |
| 681 | size_t size = sizeof(data); |
| 682 | if (!EXPECT(xglGetImageSubresourceInfo(obj(), &subres, type, &size, &data) == XGL_SUCCESS && size == sizeof(data))) |
| 683 | memset(&data, 0, sizeof(data)); |
| 684 | |
| 685 | return data; |
| 686 | } |
| 687 | |
| 688 | bool Image::transparent() const |
| 689 | { |
| 690 | return (create_info_.tiling == XGL_LINEAR_TILING && |
| 691 | create_info_.samples == 1 && |
| 692 | !(create_info_.usage & (XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 693 | XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT))); |
| 694 | } |
| 695 | |
| 696 | void ImageView::init(const Device &dev, const XGL_IMAGE_VIEW_CREATE_INFO &info) |
| 697 | { |
| 698 | DERIVED_OBJECT_INIT(xglCreateImageView, dev.obj(), &info); |
| 699 | alloc_memory(dev); |
| 700 | } |
| 701 | |
| 702 | void ColorAttachmentView::init(const Device &dev, const XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO &info) |
| 703 | { |
| 704 | DERIVED_OBJECT_INIT(xglCreateColorAttachmentView, dev.obj(), &info); |
| 705 | alloc_memory(dev); |
| 706 | } |
| 707 | |
| 708 | void DepthStencilView::init(const Device &dev, const XGL_DEPTH_STENCIL_VIEW_CREATE_INFO &info) |
| 709 | { |
| 710 | DERIVED_OBJECT_INIT(xglCreateDepthStencilView, dev.obj(), &info); |
| 711 | alloc_memory(dev); |
| 712 | } |
| 713 | |
| 714 | void Shader::init(const Device &dev, const XGL_SHADER_CREATE_INFO &info) |
| 715 | { |
| 716 | DERIVED_OBJECT_INIT(xglCreateShader, dev.obj(), &info); |
| 717 | } |
| 718 | |
| 719 | XGL_RESULT Shader::init_try(const Device &dev, const XGL_SHADER_CREATE_INFO &info) |
| 720 | { |
| 721 | XGL_SHADER sh; |
| 722 | XGL_RESULT err = xglCreateShader(dev.obj(), &info, &sh); |
| 723 | if (err == XGL_SUCCESS) |
| 724 | Object::init(sh); |
| 725 | |
| 726 | return err; |
| 727 | } |
| 728 | |
| 729 | void Pipeline::init(const Device &dev, const XGL_GRAPHICS_PIPELINE_CREATE_INFO &info) |
| 730 | { |
| 731 | DERIVED_OBJECT_INIT(xglCreateGraphicsPipeline, dev.obj(), &info); |
| 732 | alloc_memory(dev); |
| 733 | } |
| 734 | |
| 735 | void Pipeline::init(const Device &dev, const XGL_COMPUTE_PIPELINE_CREATE_INFO &info) |
| 736 | { |
| 737 | DERIVED_OBJECT_INIT(xglCreateComputePipeline, dev.obj(), &info); |
| 738 | alloc_memory(dev); |
| 739 | } |
| 740 | |
| 741 | void Pipeline::init(const Device&dev, size_t size, const void *data) |
| 742 | { |
| 743 | DERIVED_OBJECT_INIT(xglLoadPipeline, dev.obj(), size, data); |
| 744 | alloc_memory(dev); |
| 745 | } |
| 746 | |
| 747 | size_t Pipeline::store(size_t size, void *data) |
| 748 | { |
| 749 | if (!EXPECT(xglStorePipeline(obj(), &size, data) == XGL_SUCCESS)) |
| 750 | size = 0; |
| 751 | |
| 752 | return size; |
| 753 | } |
| 754 | |
| 755 | void PipelineDelta::init(const Device &dev, const Pipeline &p1, const Pipeline &p2) |
| 756 | { |
| 757 | DERIVED_OBJECT_INIT(xglCreatePipelineDelta, dev.obj(), p1.obj(), p2.obj()); |
| 758 | alloc_memory(dev); |
| 759 | } |
| 760 | |
| 761 | void Sampler::init(const Device &dev, const XGL_SAMPLER_CREATE_INFO &info) |
| 762 | { |
| 763 | DERIVED_OBJECT_INIT(xglCreateSampler, dev.obj(), &info); |
| 764 | alloc_memory(dev); |
| 765 | } |
| 766 | |
| 767 | void DescriptorSet::init(const Device &dev, const XGL_DESCRIPTOR_SET_CREATE_INFO &info) |
| 768 | { |
| 769 | DERIVED_OBJECT_INIT(xglCreateDescriptorSet, dev.obj(), &info); |
| 770 | info_ = info; |
| 771 | } |
| 772 | |
| 773 | void DescriptorSet::attach(uint32_t start_slot, const std::vector<const Sampler *> &samplers) |
| 774 | { |
| 775 | const std::vector<XGL_SAMPLER> sampler_objs = make_objects<XGL_SAMPLER>(samplers); |
| 776 | xglAttachSamplerDescriptors(obj(), start_slot, sampler_objs.size(), &sampler_objs[0]); |
| 777 | } |
| 778 | |
| 779 | void DescriptorSet::attach(uint32_t start_slot, const std::vector<XGL_IMAGE_VIEW_ATTACH_INFO> &img_views) |
| 780 | { |
| 781 | xglAttachImageViewDescriptors(obj(), start_slot, img_views.size(), &img_views[0]); |
| 782 | } |
| 783 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 784 | void DescriptorSet::attach(uint32_t start_slot, const std::vector<XGL_BUFFER_VIEW_ATTACH_INFO> &buf_views) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 785 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 786 | xglAttachBufferViewDescriptors(obj(), start_slot, buf_views.size(), &buf_views[0]); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | void DescriptorSet::attach(uint32_t start_slot, const std::vector<XGL_DESCRIPTOR_SET_ATTACH_INFO> &sets) |
| 790 | { |
| 791 | xglAttachNestedDescriptors(obj(), start_slot, sets.size(), &sets[0]); |
| 792 | } |
| 793 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 794 | void DynamicVpStateObject::init(const Device &dev, const XGL_DYNAMIC_VP_STATE_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 795 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 796 | DERIVED_OBJECT_INIT(xglCreateDynamicViewportState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 797 | alloc_memory(dev); |
| 798 | } |
| 799 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 800 | void DynamicRsStateObject::init(const Device &dev, const XGL_DYNAMIC_RS_STATE_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 801 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 802 | DERIVED_OBJECT_INIT(xglCreateDynamicRasterState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 803 | alloc_memory(dev); |
| 804 | } |
| 805 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 806 | void DynamicCbStateObject::init(const Device &dev, const XGL_DYNAMIC_CB_STATE_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 807 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 808 | DERIVED_OBJECT_INIT(xglCreateDynamicColorBlendState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 809 | alloc_memory(dev); |
| 810 | } |
| 811 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 812 | void DynamicDsStateObject::init(const Device &dev, const XGL_DYNAMIC_DS_STATE_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 813 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame^] | 814 | DERIVED_OBJECT_INIT(xglCreateDynamicDepthStencilState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 815 | alloc_memory(dev); |
| 816 | } |
| 817 | |
| 818 | void CmdBuffer::init(const Device &dev, const XGL_CMD_BUFFER_CREATE_INFO &info) |
| 819 | { |
| 820 | DERIVED_OBJECT_INIT(xglCreateCommandBuffer, dev.obj(), &info); |
| 821 | } |
| 822 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 823 | void CmdBuffer::begin(const XGL_CMD_BUFFER_BEGIN_INFO *info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 824 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 825 | EXPECT(xglBeginCommandBuffer(obj(), info) == XGL_SUCCESS); |
| 826 | } |
| 827 | |
| 828 | void CmdBuffer::begin(XGL_RENDER_PASS renderpass_obj) |
| 829 | { |
| 830 | XGL_CMD_BUFFER_BEGIN_INFO info = {}; |
| 831 | XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO graphics_cmd_buf_info = { |
| 832 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO, |
| 833 | .pNext = NULL, |
| 834 | .renderPass = renderpass_obj, |
| 835 | .operation = XGL_RENDER_PASS_OPERATION_BEGIN_AND_END, |
| 836 | }; |
| 837 | info.flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 838 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 839 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 840 | info.pNext = &graphics_cmd_buf_info; |
| 841 | |
| 842 | begin(&info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | void CmdBuffer::begin() |
| 846 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 847 | XGL_CMD_BUFFER_BEGIN_INFO info = {}; |
| 848 | info.flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 849 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 850 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 851 | |
| 852 | begin(&info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | void CmdBuffer::end() |
| 856 | { |
| 857 | EXPECT(xglEndCommandBuffer(obj()) == XGL_SUCCESS); |
| 858 | } |
| 859 | |
| 860 | void CmdBuffer::reset() |
| 861 | { |
| 862 | EXPECT(xglResetCommandBuffer(obj()) == XGL_SUCCESS); |
| 863 | } |
| 864 | |
| 865 | }; // namespace xgl_testing |