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 | { |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame^] | 186 | return get_info<uint32_t>(obj_, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, 1)[0]; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | std::vector<XGL_MEMORY_REQUIREMENTS> BaseObject::memory_requirements() const |
| 190 | { |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame^] | 191 | XGL_RESULT err; |
| 192 | XGL_UINT num_allocations = 0; |
| 193 | XGL_SIZE num_alloc_size = sizeof(num_allocations); |
| 194 | err = xglGetObjectInfo(obj_, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, |
| 195 | &num_alloc_size, &num_allocations); |
| 196 | EXPECT(err == XGL_SUCCESS && num_alloc_size == sizeof(num_allocations)); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 197 | std::vector<XGL_MEMORY_REQUIREMENTS> info = |
| 198 | get_info<XGL_MEMORY_REQUIREMENTS>(obj_, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, 0); |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame^] | 199 | EXPECT(info.size() == num_allocations); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 200 | if (info.size() == 1 && !info[0].size) |
| 201 | info.clear(); |
| 202 | |
| 203 | return info; |
| 204 | } |
| 205 | |
| 206 | void Object::init(XGL_OBJECT obj, bool own) |
| 207 | { |
| 208 | BaseObject::init(obj, own); |
| 209 | mem_alloc_count_ = memory_allocation_count(); |
| 210 | } |
| 211 | |
| 212 | void Object::reinit(XGL_OBJECT obj, bool own) |
| 213 | { |
| 214 | cleanup(); |
| 215 | BaseObject::reinit(obj, own); |
| 216 | mem_alloc_count_ = memory_allocation_count(); |
| 217 | } |
| 218 | |
| 219 | void Object::cleanup() |
| 220 | { |
| 221 | if (!initialized()) |
| 222 | return; |
| 223 | |
| 224 | unbind_memory(); |
| 225 | |
| 226 | if (internal_mems_) { |
| 227 | delete[] internal_mems_; |
| 228 | internal_mems_ = NULL; |
| 229 | primary_mem_ = NULL; |
| 230 | } |
| 231 | |
| 232 | mem_alloc_count_ = 0; |
| 233 | |
| 234 | if (own()) |
| 235 | EXPECT(xglDestroyObject(obj()) == XGL_SUCCESS); |
| 236 | } |
| 237 | |
| 238 | void Object::bind_memory(uint32_t alloc_idx, const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 239 | { |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame^] | 240 | EXPECT(xglBindObjectMemory(obj(), alloc_idx, mem.obj(), mem_offset) == XGL_SUCCESS); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 241 | } |
| 242 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 243 | void Object::bind_memory(uint32_t alloc_idx, XGL_GPU_SIZE offset, XGL_GPU_SIZE size, |
| 244 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 245 | { |
Jon Ashburn | 9b6eae5 | 2015-01-15 10:39:19 -0700 | [diff] [blame] | 246 | EXPECT(!alloc_idx && xglBindObjectMemoryRange(obj(), 0, offset, size, mem.obj(), mem_offset) == XGL_SUCCESS); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 249 | void Object::unbind_memory(uint32_t alloc_idx) |
| 250 | { |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame^] | 251 | EXPECT(xglBindObjectMemory(obj(), alloc_idx, XGL_NULL_HANDLE, 0) == XGL_SUCCESS); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void Object::unbind_memory() |
| 255 | { |
| 256 | for (uint32_t i = 0; i < mem_alloc_count_; i++) |
| 257 | unbind_memory(i); |
| 258 | } |
| 259 | |
| 260 | void Object::alloc_memory(const Device &dev, bool for_linear_img) |
| 261 | { |
| 262 | if (!EXPECT(!internal_mems_) || !mem_alloc_count_) |
| 263 | return; |
| 264 | |
| 265 | internal_mems_ = new GpuMemory[mem_alloc_count_]; |
| 266 | |
| 267 | const std::vector<XGL_MEMORY_REQUIREMENTS> mem_reqs = memory_requirements(); |
| 268 | for (int i = 0; i < mem_reqs.size(); i++) { |
| 269 | XGL_MEMORY_ALLOC_INFO info = GpuMemory::alloc_info(mem_reqs[i]); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 270 | std::vector<uint32_t> heap_ids; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 271 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 272 | info.heapCount = 0; |
| 273 | for (uint32_t j = 0; j < mem_reqs[i].heapCount; j++) { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 274 | const uint32_t heap = mem_reqs[i].pHeaps[j]; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 275 | |
Jon Ashburn | 86b36ac | 2015-01-14 09:58:23 -0700 | [diff] [blame] | 276 | heap_ids.push_back(heap); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 277 | } |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 278 | |
| 279 | info.heapCount = heap_ids.size(); |
| 280 | info.pHeaps = &heap_ids[0]; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 281 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 282 | primary_mem_ = &internal_mems_[i]; |
| 283 | |
| 284 | internal_mems_[i].init(dev, info); |
| 285 | bind_memory(i, internal_mems_[i], 0); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void Object::alloc_memory(const std::vector<XGL_GPU_MEMORY> &mems) |
| 290 | { |
| 291 | if (!EXPECT(!internal_mems_) || !mem_alloc_count_) |
| 292 | return; |
| 293 | |
| 294 | internal_mems_ = new GpuMemory[mem_alloc_count_]; |
| 295 | |
| 296 | const std::vector<XGL_MEMORY_REQUIREMENTS> mem_reqs = memory_requirements(); |
| 297 | 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]); |
| 304 | bind_memory(i, internal_mems_[i], 0); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | std::vector<XGL_GPU_MEMORY> Object::memories() const |
| 309 | { |
| 310 | std::vector<XGL_GPU_MEMORY> mems; |
| 311 | 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 | |
| 320 | Device::~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 | |
| 331 | EXPECT(xglDestroyDevice(obj()) == XGL_SUCCESS); |
| 332 | } |
| 333 | |
Chia-I Wu | 510c999 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 334 | void Device::init(bool enable_layers) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 335 | { |
| 336 | // request all queues |
| 337 | const std::vector<XGL_PHYSICAL_GPU_QUEUE_PROPERTIES> queue_props = gpu_.queue_properties(); |
| 338 | std::vector<XGL_DEVICE_QUEUE_CREATE_INFO> queue_info; |
| 339 | queue_info.reserve(queue_props.size()); |
| 340 | for (int i = 0; i < queue_props.size(); i++) { |
| 341 | XGL_DEVICE_QUEUE_CREATE_INFO qi = {}; |
| 342 | qi.queueNodeIndex = i; |
| 343 | qi.queueCount = queue_props[i].queueCount; |
| 344 | queue_info.push_back(qi); |
| 345 | } |
| 346 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 347 | XGL_LAYER_CREATE_INFO layer_info = {}; |
| 348 | layer_info.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO; |
Chia-I Wu | 510c999 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 349 | |
| 350 | std::vector<const char *> layers; |
| 351 | std::vector<char> layer_buf; |
| 352 | // request all layers |
| 353 | if (enable_layers) { |
| 354 | layers = gpu_.layers(layer_buf); |
| 355 | layer_info.layerCount = layers.size(); |
| 356 | layer_info.ppActiveLayerNames = &layers[0]; |
| 357 | } |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 358 | |
| 359 | const std::vector<const char *> exts = gpu_.extensions(); |
| 360 | |
| 361 | XGL_DEVICE_CREATE_INFO dev_info = {}; |
| 362 | dev_info.sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
Jon Ashburn | f7e282a | 2015-01-22 13:33:15 -0700 | [diff] [blame] | 363 | dev_info.pNext = (enable_layers) ? static_cast<void *>(&layer_info) : NULL; |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 364 | dev_info.queueRecordCount = queue_info.size(); |
| 365 | dev_info.pRequestedQueues = &queue_info[0]; |
| 366 | dev_info.extensionCount = exts.size(); |
| 367 | dev_info.ppEnabledExtensionNames = &exts[0]; |
| 368 | dev_info.maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE; |
| 369 | dev_info.flags = XGL_DEVICE_CREATE_VALIDATION_BIT; |
| 370 | |
| 371 | init(dev_info); |
| 372 | } |
| 373 | |
| 374 | void Device::init(const XGL_DEVICE_CREATE_INFO &info) |
| 375 | { |
| 376 | DERIVED_OBJECT_INIT(xglCreateDevice, gpu_.obj(), &info); |
| 377 | |
| 378 | init_queues(); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 379 | init_formats(); |
| 380 | } |
| 381 | |
| 382 | void Device::init_queues() |
| 383 | { |
| 384 | const struct { |
| 385 | QueueIndex index; |
| 386 | XGL_QUEUE_TYPE type; |
| 387 | } queue_mapping[] = { |
| 388 | { GRAPHICS, XGL_QUEUE_TYPE_GRAPHICS }, |
| 389 | { COMPUTE, XGL_QUEUE_TYPE_COMPUTE }, |
| 390 | { DMA, XGL_QUEUE_TYPE_DMA }, |
| 391 | }; |
| 392 | |
| 393 | for (int i = 0; i < QUEUE_COUNT; i++) { |
| 394 | uint32_t idx = 0; |
| 395 | |
| 396 | while (true) { |
| 397 | XGL_QUEUE queue; |
| 398 | XGL_RESULT err = xglGetDeviceQueue(obj(), queue_mapping[i].type, idx++, &queue); |
| 399 | if (err != XGL_SUCCESS) |
| 400 | break; |
| 401 | queues_[queue_mapping[i].index].push_back(new Queue(queue)); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty()); |
| 406 | } |
| 407 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 408 | void Device::init_formats() |
| 409 | { |
| 410 | for (int ch = XGL_CH_FMT_UNDEFINED; ch <= XGL_MAX_CH_FMT; ch++) { |
| 411 | for (int num = XGL_NUM_FMT_UNDEFINED; num <= XGL_MAX_NUM_FMT; num++) { |
| 412 | const XGL_FORMAT fmt = { static_cast<XGL_CHANNEL_FORMAT>(ch), |
| 413 | static_cast<XGL_NUM_FORMAT>(num) }; |
| 414 | const XGL_FORMAT_PROPERTIES props = format_properties(fmt); |
| 415 | |
| 416 | if (props.linearTilingFeatures) { |
| 417 | const Format tmp = { fmt, XGL_LINEAR_TILING, props.linearTilingFeatures }; |
| 418 | formats_.push_back(tmp); |
| 419 | } |
| 420 | |
| 421 | if (props.optimalTilingFeatures) { |
| 422 | const Format tmp = { fmt, XGL_OPTIMAL_TILING, props.optimalTilingFeatures }; |
| 423 | formats_.push_back(tmp); |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | EXPECT(!formats_.empty()); |
| 429 | } |
| 430 | |
| 431 | XGL_FORMAT_PROPERTIES Device::format_properties(XGL_FORMAT format) |
| 432 | { |
| 433 | const XGL_FORMAT_INFO_TYPE type = XGL_INFO_TYPE_FORMAT_PROPERTIES; |
| 434 | XGL_FORMAT_PROPERTIES data; |
| 435 | size_t size = sizeof(data); |
| 436 | if (!EXPECT(xglGetFormatInfo(obj(), format, type, &size, &data) == XGL_SUCCESS && size == sizeof(data))) |
| 437 | memset(&data, 0, sizeof(data)); |
| 438 | |
| 439 | return data; |
| 440 | } |
| 441 | |
| 442 | void Device::wait() |
| 443 | { |
| 444 | EXPECT(xglDeviceWaitIdle(obj()) == XGL_SUCCESS); |
| 445 | } |
| 446 | |
| 447 | XGL_RESULT Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout) |
| 448 | { |
| 449 | const std::vector<XGL_FENCE> fence_objs = make_objects<XGL_FENCE>(fences); |
| 450 | XGL_RESULT err = xglWaitForFences(obj(), fence_objs.size(), &fence_objs[0], wait_all, timeout); |
| 451 | EXPECT(err == XGL_SUCCESS || err == XGL_TIMEOUT); |
| 452 | |
| 453 | return err; |
| 454 | } |
| 455 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 456 | void Device::begin_descriptor_region_update(XGL_DESCRIPTOR_UPDATE_MODE mode) |
| 457 | { |
| 458 | EXPECT(xglBeginDescriptorRegionUpdate(obj(), mode) == XGL_SUCCESS); |
| 459 | } |
| 460 | |
| 461 | void Device::end_descriptor_region_update(CmdBuffer &cmd) |
| 462 | { |
| 463 | EXPECT(xglEndDescriptorRegionUpdate(obj(), cmd.obj()) == XGL_SUCCESS); |
| 464 | } |
| 465 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 466 | void Queue::submit(const std::vector<const CmdBuffer *> &cmds, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence) |
| 467 | { |
| 468 | const std::vector<XGL_CMD_BUFFER> cmd_objs = make_objects<XGL_CMD_BUFFER>(cmds); |
| 469 | EXPECT(xglQueueSubmit(obj(), cmd_objs.size(), &cmd_objs[0], mem_refs.size(), &mem_refs[0], fence.obj()) == XGL_SUCCESS); |
| 470 | } |
| 471 | |
| 472 | void Queue::submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence) |
| 473 | { |
| 474 | submit(std::vector<const CmdBuffer*>(1, &cmd), mem_refs, fence); |
| 475 | } |
| 476 | |
| 477 | void Queue::submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs) |
| 478 | { |
| 479 | Fence fence; |
| 480 | submit(cmd, mem_refs, fence); |
| 481 | } |
| 482 | |
| 483 | void Queue::set_global_mem_references(const std::vector<XGL_MEMORY_REF> &mem_refs) |
| 484 | { |
| 485 | EXPECT(xglQueueSetGlobalMemReferences(obj(), mem_refs.size(), &mem_refs[0]) == XGL_SUCCESS); |
| 486 | } |
| 487 | |
| 488 | void Queue::wait() |
| 489 | { |
| 490 | EXPECT(xglQueueWaitIdle(obj()) == XGL_SUCCESS); |
| 491 | } |
| 492 | |
| 493 | void Queue::signal_semaphore(QueueSemaphore &sem) |
| 494 | { |
| 495 | EXPECT(xglSignalQueueSemaphore(obj(), sem.obj()) == XGL_SUCCESS); |
| 496 | } |
| 497 | |
| 498 | void Queue::wait_semaphore(QueueSemaphore &sem) |
| 499 | { |
| 500 | EXPECT(xglWaitQueueSemaphore(obj(), sem.obj()) == XGL_SUCCESS); |
| 501 | } |
| 502 | |
| 503 | GpuMemory::~GpuMemory() |
| 504 | { |
| 505 | if (initialized() && own()) |
| 506 | EXPECT(xglFreeMemory(obj()) == XGL_SUCCESS); |
| 507 | } |
| 508 | |
| 509 | void GpuMemory::init(const Device &dev, const XGL_MEMORY_ALLOC_INFO &info) |
| 510 | { |
| 511 | DERIVED_OBJECT_INIT(xglAllocMemory, dev.obj(), &info); |
| 512 | } |
| 513 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 514 | void GpuMemory::init(const Device &dev, size_t size, const void *data) |
| 515 | { |
| 516 | DERIVED_OBJECT_INIT(xglPinSystemMemory, dev.obj(), data, size); |
| 517 | } |
| 518 | |
| 519 | void GpuMemory::init(const Device &dev, const XGL_MEMORY_OPEN_INFO &info) |
| 520 | { |
| 521 | DERIVED_OBJECT_INIT(xglOpenSharedMemory, dev.obj(), &info); |
| 522 | } |
| 523 | |
| 524 | void GpuMemory::init(const Device &dev, const XGL_PEER_MEMORY_OPEN_INFO &info) |
| 525 | { |
| 526 | DERIVED_OBJECT_INIT(xglOpenPeerMemory, dev.obj(), &info); |
| 527 | } |
| 528 | |
| 529 | void GpuMemory::set_priority(XGL_MEMORY_PRIORITY priority) |
| 530 | { |
| 531 | EXPECT(xglSetMemoryPriority(obj(), priority) == XGL_SUCCESS); |
| 532 | } |
| 533 | |
| 534 | const void *GpuMemory::map(XGL_FLAGS flags) const |
| 535 | { |
| 536 | void *data; |
| 537 | if (!EXPECT(xglMapMemory(obj(), flags, &data) == XGL_SUCCESS)) |
| 538 | data = NULL; |
| 539 | |
| 540 | return data; |
| 541 | } |
| 542 | |
| 543 | void *GpuMemory::map(XGL_FLAGS flags) |
| 544 | { |
| 545 | void *data; |
| 546 | if (!EXPECT(xglMapMemory(obj(), flags, &data) == XGL_SUCCESS)) |
| 547 | data = NULL; |
| 548 | |
| 549 | return data; |
| 550 | } |
| 551 | |
| 552 | void GpuMemory::unmap() const |
| 553 | { |
| 554 | EXPECT(xglUnmapMemory(obj()) == XGL_SUCCESS); |
| 555 | } |
| 556 | |
| 557 | void Fence::init(const Device &dev, const XGL_FENCE_CREATE_INFO &info) |
| 558 | { |
| 559 | DERIVED_OBJECT_INIT(xglCreateFence, dev.obj(), &info); |
| 560 | alloc_memory(dev); |
| 561 | } |
| 562 | |
| 563 | void QueueSemaphore::init(const Device &dev, const XGL_QUEUE_SEMAPHORE_CREATE_INFO &info) |
| 564 | { |
| 565 | DERIVED_OBJECT_INIT(xglCreateQueueSemaphore, dev.obj(), &info); |
| 566 | alloc_memory(dev); |
| 567 | } |
| 568 | |
| 569 | void QueueSemaphore::init(const Device &dev, const XGL_QUEUE_SEMAPHORE_OPEN_INFO &info) |
| 570 | { |
| 571 | DERIVED_OBJECT_INIT(xglOpenSharedQueueSemaphore, dev.obj(), &info); |
| 572 | } |
| 573 | |
| 574 | void Event::init(const Device &dev, const XGL_EVENT_CREATE_INFO &info) |
| 575 | { |
| 576 | DERIVED_OBJECT_INIT(xglCreateEvent, dev.obj(), &info); |
| 577 | alloc_memory(dev); |
| 578 | } |
| 579 | |
| 580 | void Event::set() |
| 581 | { |
| 582 | EXPECT(xglSetEvent(obj()) == XGL_SUCCESS); |
| 583 | } |
| 584 | |
| 585 | void Event::reset() |
| 586 | { |
| 587 | EXPECT(xglResetEvent(obj()) == XGL_SUCCESS); |
| 588 | } |
| 589 | |
| 590 | void QueryPool::init(const Device &dev, const XGL_QUERY_POOL_CREATE_INFO &info) |
| 591 | { |
| 592 | DERIVED_OBJECT_INIT(xglCreateQueryPool, dev.obj(), &info); |
| 593 | alloc_memory(dev); |
| 594 | } |
| 595 | |
| 596 | XGL_RESULT QueryPool::results(uint32_t start, uint32_t count, size_t size, void *data) |
| 597 | { |
| 598 | size_t tmp = size; |
| 599 | XGL_RESULT err = xglGetQueryPoolResults(obj(), start, count, &tmp, data); |
| 600 | if (err == XGL_SUCCESS) { |
| 601 | if (!EXPECT(tmp == size)) |
| 602 | memset(data, 0, size); |
| 603 | } else { |
| 604 | EXPECT(err == XGL_NOT_READY); |
| 605 | } |
| 606 | |
| 607 | return err; |
| 608 | } |
| 609 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 610 | void Buffer::init(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) |
| 611 | { |
| 612 | init_no_mem(dev, info); |
| 613 | alloc_memory(dev); |
| 614 | } |
| 615 | |
| 616 | void Buffer::init_no_mem(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) |
| 617 | { |
| 618 | DERIVED_OBJECT_INIT(xglCreateBuffer, dev.obj(), &info); |
| 619 | create_info_ = info; |
| 620 | } |
| 621 | |
| 622 | void BufferView::init(const Device &dev, const XGL_BUFFER_VIEW_CREATE_INFO &info) |
| 623 | { |
| 624 | DERIVED_OBJECT_INIT(xglCreateBufferView, dev.obj(), &info); |
| 625 | alloc_memory(dev); |
| 626 | } |
| 627 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 628 | void Image::init(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 629 | { |
| 630 | init_no_mem(dev, info); |
| 631 | alloc_memory(dev, info.tiling == XGL_LINEAR_TILING); |
| 632 | } |
| 633 | |
| 634 | void Image::init_no_mem(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 635 | { |
| 636 | DERIVED_OBJECT_INIT(xglCreateImage, dev.obj(), &info); |
| 637 | init_info(dev, info); |
| 638 | } |
| 639 | |
| 640 | void Image::init(const Device &dev, const XGL_PEER_IMAGE_OPEN_INFO &info, const XGL_IMAGE_CREATE_INFO &original_info) |
| 641 | { |
| 642 | XGL_IMAGE img; |
| 643 | XGL_GPU_MEMORY mem; |
| 644 | EXPECT(xglOpenPeerImage(dev.obj(), &info, &img, &mem) == XGL_SUCCESS); |
| 645 | Object::init(img); |
| 646 | |
| 647 | init_info(dev, original_info); |
| 648 | alloc_memory(std::vector<XGL_GPU_MEMORY>(1, mem)); |
| 649 | } |
| 650 | |
| 651 | void Image::init_info(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 652 | { |
| 653 | create_info_ = info; |
| 654 | |
| 655 | for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) { |
| 656 | if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) { |
| 657 | format_features_ = it->features; |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 663 | void Image::bind_memory(uint32_t alloc_idx, const XGL_IMAGE_MEMORY_BIND_INFO &info, |
| 664 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 665 | { |
Jon Ashburn | 9b6eae5 | 2015-01-15 10:39:19 -0700 | [diff] [blame] | 666 | EXPECT(!alloc_idx && xglBindImageMemoryRange(obj(), 0, &info, mem.obj(), mem_offset) == XGL_SUCCESS); |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 667 | } |
| 668 | |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 669 | XGL_SUBRESOURCE_LAYOUT Image::subresource_layout(const XGL_IMAGE_SUBRESOURCE &subres) const |
| 670 | { |
| 671 | const XGL_SUBRESOURCE_INFO_TYPE type = XGL_INFO_TYPE_SUBRESOURCE_LAYOUT; |
| 672 | XGL_SUBRESOURCE_LAYOUT data; |
| 673 | size_t size = sizeof(data); |
| 674 | if (!EXPECT(xglGetImageSubresourceInfo(obj(), &subres, type, &size, &data) == XGL_SUCCESS && size == sizeof(data))) |
| 675 | memset(&data, 0, sizeof(data)); |
| 676 | |
| 677 | return data; |
| 678 | } |
| 679 | |
| 680 | bool Image::transparent() const |
| 681 | { |
| 682 | return (create_info_.tiling == XGL_LINEAR_TILING && |
| 683 | create_info_.samples == 1 && |
| 684 | !(create_info_.usage & (XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 685 | XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT))); |
| 686 | } |
| 687 | |
| 688 | void ImageView::init(const Device &dev, const XGL_IMAGE_VIEW_CREATE_INFO &info) |
| 689 | { |
| 690 | DERIVED_OBJECT_INIT(xglCreateImageView, dev.obj(), &info); |
| 691 | alloc_memory(dev); |
| 692 | } |
| 693 | |
| 694 | void ColorAttachmentView::init(const Device &dev, const XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO &info) |
| 695 | { |
| 696 | DERIVED_OBJECT_INIT(xglCreateColorAttachmentView, dev.obj(), &info); |
| 697 | alloc_memory(dev); |
| 698 | } |
| 699 | |
| 700 | void DepthStencilView::init(const Device &dev, const XGL_DEPTH_STENCIL_VIEW_CREATE_INFO &info) |
| 701 | { |
| 702 | DERIVED_OBJECT_INIT(xglCreateDepthStencilView, dev.obj(), &info); |
| 703 | alloc_memory(dev); |
| 704 | } |
| 705 | |
| 706 | void Shader::init(const Device &dev, const XGL_SHADER_CREATE_INFO &info) |
| 707 | { |
| 708 | DERIVED_OBJECT_INIT(xglCreateShader, dev.obj(), &info); |
| 709 | } |
| 710 | |
| 711 | XGL_RESULT Shader::init_try(const Device &dev, const XGL_SHADER_CREATE_INFO &info) |
| 712 | { |
| 713 | XGL_SHADER sh; |
| 714 | XGL_RESULT err = xglCreateShader(dev.obj(), &info, &sh); |
| 715 | if (err == XGL_SUCCESS) |
| 716 | Object::init(sh); |
| 717 | |
| 718 | return err; |
| 719 | } |
| 720 | |
| 721 | void Pipeline::init(const Device &dev, const XGL_GRAPHICS_PIPELINE_CREATE_INFO &info) |
| 722 | { |
| 723 | DERIVED_OBJECT_INIT(xglCreateGraphicsPipeline, dev.obj(), &info); |
| 724 | alloc_memory(dev); |
| 725 | } |
| 726 | |
| 727 | void Pipeline::init(const Device &dev, const XGL_COMPUTE_PIPELINE_CREATE_INFO &info) |
| 728 | { |
| 729 | DERIVED_OBJECT_INIT(xglCreateComputePipeline, dev.obj(), &info); |
| 730 | alloc_memory(dev); |
| 731 | } |
| 732 | |
| 733 | void Pipeline::init(const Device&dev, size_t size, const void *data) |
| 734 | { |
| 735 | DERIVED_OBJECT_INIT(xglLoadPipeline, dev.obj(), size, data); |
| 736 | alloc_memory(dev); |
| 737 | } |
| 738 | |
| 739 | size_t Pipeline::store(size_t size, void *data) |
| 740 | { |
| 741 | if (!EXPECT(xglStorePipeline(obj(), &size, data) == XGL_SUCCESS)) |
| 742 | size = 0; |
| 743 | |
| 744 | return size; |
| 745 | } |
| 746 | |
| 747 | void PipelineDelta::init(const Device &dev, const Pipeline &p1, const Pipeline &p2) |
| 748 | { |
| 749 | DERIVED_OBJECT_INIT(xglCreatePipelineDelta, dev.obj(), p1.obj(), p2.obj()); |
| 750 | alloc_memory(dev); |
| 751 | } |
| 752 | |
| 753 | void Sampler::init(const Device &dev, const XGL_SAMPLER_CREATE_INFO &info) |
| 754 | { |
| 755 | DERIVED_OBJECT_INIT(xglCreateSampler, dev.obj(), &info); |
| 756 | alloc_memory(dev); |
| 757 | } |
| 758 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 759 | void DescriptorSetLayout::init(const Device &dev, XGL_FLAGS stage_mask, |
| 760 | const std::vector<uint32_t> &bind_points, |
| 761 | const DescriptorSetLayout &prior_layout, |
| 762 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 763 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 764 | DERIVED_OBJECT_INIT(xglCreateDescriptorSetLayout, dev.obj(), stage_mask, |
| 765 | &bind_points[0], prior_layout.obj(), &info); |
| 766 | alloc_memory(dev); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 767 | } |
| 768 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 769 | void DescriptorSetLayout::init(const Device &dev, uint32_t bind_point, |
| 770 | const DescriptorSetLayout &prior_layout, |
| 771 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 772 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 773 | init(dev, XGL_SHADER_STAGE_FLAGS_ALL, std::vector<uint32_t>(1, bind_point), prior_layout, info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 774 | } |
| 775 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 776 | void DescriptorRegion::init(const Device &dev, XGL_DESCRIPTOR_REGION_USAGE usage, |
| 777 | uint32_t max_sets, const XGL_DESCRIPTOR_REGION_CREATE_INFO &info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 778 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 779 | DERIVED_OBJECT_INIT(xglCreateDescriptorRegion, dev.obj(), usage, max_sets, &info); |
| 780 | alloc_memory(dev); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 781 | } |
| 782 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 783 | void DescriptorRegion::clear() |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 784 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 785 | EXPECT(xglClearDescriptorRegion(obj()) == XGL_SUCCESS); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 786 | } |
| 787 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 788 | std::vector<DescriptorSet *> DescriptorRegion::alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const std::vector<const DescriptorSetLayout *> &layouts) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 789 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 790 | const std::vector<XGL_DESCRIPTOR_SET_LAYOUT> layout_objs = make_objects<XGL_DESCRIPTOR_SET_LAYOUT>(layouts); |
| 791 | |
| 792 | std::vector<XGL_DESCRIPTOR_SET> set_objs; |
| 793 | set_objs.resize(layout_objs.size()); |
| 794 | |
| 795 | uint32_t set_count; |
| 796 | XGL_RESULT err = xglAllocDescriptorSets(obj(), usage, layout_objs.size(), &layout_objs[0], &set_objs[0], &set_count); |
| 797 | if (err == XGL_SUCCESS) |
| 798 | EXPECT(set_count == set_objs.size()); |
| 799 | set_objs.resize(set_count); |
| 800 | |
| 801 | std::vector<DescriptorSet *> sets; |
| 802 | sets.reserve(set_count); |
| 803 | for (std::vector<XGL_DESCRIPTOR_SET>::const_iterator it = set_objs.begin(); it != set_objs.end(); it++) { |
| 804 | // do descriptor sets need memories bound? |
| 805 | sets.push_back(new DescriptorSet(*it)); |
| 806 | } |
| 807 | |
| 808 | return sets; |
| 809 | } |
| 810 | |
| 811 | std::vector<DescriptorSet *> DescriptorRegion::alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const DescriptorSetLayout &layout, uint32_t count) |
| 812 | { |
| 813 | return alloc_sets(usage, std::vector<const DescriptorSetLayout *>(count, &layout)); |
| 814 | } |
| 815 | |
| 816 | DescriptorSet *DescriptorRegion::alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const DescriptorSetLayout &layout) |
| 817 | { |
| 818 | std::vector<DescriptorSet *> set = alloc_sets(usage, layout, 1); |
| 819 | return (set.empty()) ? NULL : set[0]; |
| 820 | } |
| 821 | |
| 822 | void DescriptorRegion::clear_sets(const std::vector<DescriptorSet *> &sets) |
| 823 | { |
| 824 | const std::vector<XGL_DESCRIPTOR_SET> set_objs = make_objects<XGL_DESCRIPTOR_SET>(sets); |
| 825 | xglClearDescriptorSets(obj(), set_objs.size(), &set_objs[0]); |
| 826 | } |
| 827 | |
| 828 | void DescriptorSet::update(const void *update_chain) |
| 829 | { |
| 830 | xglUpdateDescriptors(obj(), update_chain); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 831 | } |
| 832 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 833 | 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] | 834 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 835 | DERIVED_OBJECT_INIT(xglCreateDynamicViewportState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 836 | alloc_memory(dev); |
| 837 | } |
| 838 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 839 | 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] | 840 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 841 | DERIVED_OBJECT_INIT(xglCreateDynamicRasterState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 842 | alloc_memory(dev); |
| 843 | } |
| 844 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 845 | 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] | 846 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 847 | DERIVED_OBJECT_INIT(xglCreateDynamicColorBlendState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 848 | alloc_memory(dev); |
| 849 | } |
| 850 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 851 | 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] | 852 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 853 | DERIVED_OBJECT_INIT(xglCreateDynamicDepthStencilState, dev.obj(), &info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 854 | alloc_memory(dev); |
| 855 | } |
| 856 | |
| 857 | void CmdBuffer::init(const Device &dev, const XGL_CMD_BUFFER_CREATE_INFO &info) |
| 858 | { |
| 859 | DERIVED_OBJECT_INIT(xglCreateCommandBuffer, dev.obj(), &info); |
| 860 | } |
| 861 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 862 | void CmdBuffer::begin(const XGL_CMD_BUFFER_BEGIN_INFO *info) |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 863 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 864 | EXPECT(xglBeginCommandBuffer(obj(), info) == XGL_SUCCESS); |
| 865 | } |
| 866 | |
| 867 | void CmdBuffer::begin(XGL_RENDER_PASS renderpass_obj) |
| 868 | { |
| 869 | XGL_CMD_BUFFER_BEGIN_INFO info = {}; |
| 870 | XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO graphics_cmd_buf_info = { |
| 871 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO, |
| 872 | .pNext = NULL, |
| 873 | .renderPass = renderpass_obj, |
| 874 | .operation = XGL_RENDER_PASS_OPERATION_BEGIN_AND_END, |
| 875 | }; |
| 876 | info.flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 877 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 878 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 879 | info.pNext = &graphics_cmd_buf_info; |
| 880 | |
| 881 | begin(&info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | void CmdBuffer::begin() |
| 885 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 886 | XGL_CMD_BUFFER_BEGIN_INFO info = {}; |
| 887 | info.flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 888 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 889 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 890 | |
| 891 | begin(&info); |
Chia-I Wu | f1e2e99 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | void CmdBuffer::end() |
| 895 | { |
| 896 | EXPECT(xglEndCommandBuffer(obj()) == XGL_SUCCESS); |
| 897 | } |
| 898 | |
| 899 | void CmdBuffer::reset() |
| 900 | { |
| 901 | EXPECT(xglResetCommandBuffer(obj()) == XGL_SUCCESS); |
| 902 | } |
| 903 | |
| 904 | }; // namespace xgl_testing |