Chia-I Wu | 82bff27 | 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 | 23bd382 | 2015-02-11 09:36:41 -0700 | [diff] [blame] | 67 | size_t size; |
Chia-I Wu | 82bff27 | 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 | 23bd382 | 2015-02-11 09:36:41 -0700 | [diff] [blame] | 84 | size_t size; |
Chia-I Wu | 82bff27 | 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 | 953a169 | 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 | 82bff27 | 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 | a9ae383 | 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 | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | std::vector<XGL_MEMORY_REQUIREMENTS> BaseObject::memory_requirements() const |
| 190 | { |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 191 | XGL_RESULT err; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 192 | uint32_t num_allocations = 0; |
| 193 | size_t num_alloc_size = sizeof(num_allocations); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 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 | 82bff27 | 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 | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 199 | EXPECT(info.size() == num_allocations); |
Chia-I Wu | 82bff27 | 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 | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 240 | EXPECT(xglBindObjectMemory(obj(), alloc_idx, mem.obj(), mem_offset) == XGL_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 241 | } |
| 242 | |
Chia-I Wu | 714df45 | 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 | ed62b41 | 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 | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 249 | void Object::unbind_memory(uint32_t alloc_idx) |
| 250 | { |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 251 | EXPECT(xglBindObjectMemory(obj(), alloc_idx, XGL_NULL_HANDLE, 0) == XGL_SUCCESS); |
Chia-I Wu | 82bff27 | 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 | |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 260 | void Object::alloc_memory(const Device &dev, bool for_buf, bool for_img) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 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(); |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 268 | std::vector<XGL_IMAGE_MEMORY_REQUIREMENTS> img_reqs; |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 269 | std::vector<XGL_BUFFER_MEMORY_REQUIREMENTS> buf_reqs; |
| 270 | XGL_MEMORY_ALLOC_IMAGE_INFO img_info; |
| 271 | XGL_MEMORY_ALLOC_BUFFER_INFO buf_info; |
| 272 | XGL_MEMORY_ALLOC_INFO info, *next_info = NULL; |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 273 | |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 274 | if (for_img) { |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 275 | img_reqs = get_info<XGL_IMAGE_MEMORY_REQUIREMENTS>(obj(), |
| 276 | XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS, 0); |
| 277 | EXPECT(img_reqs.size() == 1); |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 278 | next_info = (XGL_MEMORY_ALLOC_INFO *) &img_info; |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 279 | img_info.pNext = NULL; |
| 280 | img_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO; |
| 281 | img_info.usage = img_reqs[0].usage; |
| 282 | img_info.formatClass = img_reqs[0].formatClass; |
| 283 | img_info.samples = img_reqs[0].samples; |
| 284 | } |
| 285 | |
| 286 | |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 287 | if (for_buf) { |
| 288 | buf_reqs = get_info<XGL_BUFFER_MEMORY_REQUIREMENTS>(obj(), |
| 289 | XGL_INFO_TYPE_BUFFER_MEMORY_REQUIREMENTS, 0); |
| 290 | if (for_img) |
| 291 | img_info.pNext = &buf_info; |
| 292 | else |
| 293 | next_info = (XGL_MEMORY_ALLOC_INFO *) &buf_info; |
| 294 | buf_info.pNext = NULL; |
| 295 | buf_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO; |
| 296 | buf_info.usage = buf_reqs[0].usage; |
| 297 | } |
| 298 | |
| 299 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 300 | for (int i = 0; i < mem_reqs.size(); i++) { |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 301 | info = GpuMemory::alloc_info(mem_reqs[i], next_info); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 302 | |
Jon Ashburn | 661c329 | 2015-01-22 11:40:11 -0700 | [diff] [blame] | 303 | switch (info.memType) { |
| 304 | case XGL_MEMORY_TYPE_BUFFER: |
| 305 | EXPECT(for_buf); |
| 306 | info.memProps |= XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT; |
| 307 | primary_mem_ = &internal_mems_[i]; |
| 308 | break; |
| 309 | case XGL_MEMORY_TYPE_IMAGE: |
| 310 | EXPECT(for_img); |
| 311 | primary_mem_ = &internal_mems_[i]; |
| 312 | break; |
| 313 | default: |
| 314 | break; |
| 315 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 316 | |
| 317 | internal_mems_[i].init(dev, info); |
| 318 | bind_memory(i, internal_mems_[i], 0); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | void Object::alloc_memory(const std::vector<XGL_GPU_MEMORY> &mems) |
| 323 | { |
| 324 | if (!EXPECT(!internal_mems_) || !mem_alloc_count_) |
| 325 | return; |
| 326 | |
| 327 | internal_mems_ = new GpuMemory[mem_alloc_count_]; |
| 328 | |
| 329 | const std::vector<XGL_MEMORY_REQUIREMENTS> mem_reqs = memory_requirements(); |
| 330 | if (!EXPECT(mem_reqs.size() == mems.size())) |
| 331 | return; |
| 332 | |
| 333 | for (int i = 0; i < mem_reqs.size(); i++) { |
| 334 | primary_mem_ = &internal_mems_[i]; |
| 335 | |
| 336 | internal_mems_[i].init(mems[i]); |
| 337 | bind_memory(i, internal_mems_[i], 0); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | std::vector<XGL_GPU_MEMORY> Object::memories() const |
| 342 | { |
| 343 | std::vector<XGL_GPU_MEMORY> mems; |
| 344 | if (internal_mems_) { |
| 345 | mems.reserve(mem_alloc_count_); |
| 346 | for (uint32_t i = 0; i < mem_alloc_count_; i++) |
| 347 | mems.push_back(internal_mems_[i].obj()); |
| 348 | } |
| 349 | |
| 350 | return mems; |
| 351 | } |
| 352 | |
| 353 | Device::~Device() |
| 354 | { |
| 355 | if (!initialized()) |
| 356 | return; |
| 357 | |
| 358 | for (int i = 0; i < QUEUE_COUNT; i++) { |
| 359 | for (std::vector<Queue *>::iterator it = queues_[i].begin(); it != queues_[i].end(); it++) |
| 360 | delete *it; |
| 361 | queues_[i].clear(); |
| 362 | } |
| 363 | |
| 364 | EXPECT(xglDestroyDevice(obj()) == XGL_SUCCESS); |
| 365 | } |
| 366 | |
Chia-I Wu | 6c09922 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 367 | void Device::init(bool enable_layers) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 368 | { |
| 369 | // request all queues |
| 370 | const std::vector<XGL_PHYSICAL_GPU_QUEUE_PROPERTIES> queue_props = gpu_.queue_properties(); |
| 371 | std::vector<XGL_DEVICE_QUEUE_CREATE_INFO> queue_info; |
| 372 | queue_info.reserve(queue_props.size()); |
| 373 | for (int i = 0; i < queue_props.size(); i++) { |
| 374 | XGL_DEVICE_QUEUE_CREATE_INFO qi = {}; |
| 375 | qi.queueNodeIndex = i; |
| 376 | qi.queueCount = queue_props[i].queueCount; |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 377 | if (queue_props[i].queueFlags & XGL_QUEUE_GRAPHICS_BIT) { |
| 378 | graphics_queue_node_index_ = i; |
| 379 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 380 | queue_info.push_back(qi); |
| 381 | } |
| 382 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 383 | XGL_LAYER_CREATE_INFO layer_info = {}; |
| 384 | layer_info.sType = XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO; |
Chia-I Wu | 6c09922 | 2015-01-06 10:40:45 +0800 | [diff] [blame] | 385 | |
| 386 | std::vector<const char *> layers; |
| 387 | std::vector<char> layer_buf; |
| 388 | // request all layers |
| 389 | if (enable_layers) { |
| 390 | layers = gpu_.layers(layer_buf); |
| 391 | layer_info.layerCount = layers.size(); |
| 392 | layer_info.ppActiveLayerNames = &layers[0]; |
| 393 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 394 | |
| 395 | const std::vector<const char *> exts = gpu_.extensions(); |
| 396 | |
| 397 | XGL_DEVICE_CREATE_INFO dev_info = {}; |
| 398 | dev_info.sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
Jon Ashburn | ca93058 | 2015-01-22 13:33:15 -0700 | [diff] [blame] | 399 | dev_info.pNext = (enable_layers) ? static_cast<void *>(&layer_info) : NULL; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 400 | dev_info.queueRecordCount = queue_info.size(); |
| 401 | dev_info.pRequestedQueues = &queue_info[0]; |
| 402 | dev_info.extensionCount = exts.size(); |
| 403 | dev_info.ppEnabledExtensionNames = &exts[0]; |
| 404 | dev_info.maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE; |
| 405 | dev_info.flags = XGL_DEVICE_CREATE_VALIDATION_BIT; |
| 406 | |
| 407 | init(dev_info); |
| 408 | } |
| 409 | |
| 410 | void Device::init(const XGL_DEVICE_CREATE_INFO &info) |
| 411 | { |
| 412 | DERIVED_OBJECT_INIT(xglCreateDevice, gpu_.obj(), &info); |
| 413 | |
| 414 | init_queues(); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 415 | init_formats(); |
| 416 | } |
| 417 | |
| 418 | void Device::init_queues() |
| 419 | { |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 420 | XGL_RESULT err; |
| 421 | size_t data_size; |
| 422 | uint32_t queue_node_count; |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 423 | |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 424 | err = xglGetGpuInfo(gpu_.obj(), XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, |
| 425 | &data_size, NULL); |
| 426 | EXPECT(err == XGL_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 427 | |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 428 | queue_node_count = data_size / sizeof(XGL_PHYSICAL_GPU_QUEUE_PROPERTIES); |
| 429 | EXPECT(queue_node_count >= 1); |
| 430 | |
| 431 | XGL_PHYSICAL_GPU_QUEUE_PROPERTIES queue_props[queue_node_count]; |
| 432 | |
| 433 | err = xglGetGpuInfo(gpu_.obj(), XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, |
| 434 | &data_size, queue_props); |
| 435 | EXPECT(err == XGL_SUCCESS); |
| 436 | |
| 437 | for (int i = 0; i < queue_node_count; i++) { |
| 438 | XGL_QUEUE queue; |
| 439 | |
| 440 | for (int j = 0; j < queue_props[i].queueCount; j++) { |
| 441 | err = xglGetDeviceQueue(obj(), i, j, &queue); |
| 442 | EXPECT(err == XGL_SUCCESS); |
| 443 | |
| 444 | if (queue_props[i].queueFlags & XGL_QUEUE_GRAPHICS_BIT) { |
| 445 | queues_[GRAPHICS].push_back(new Queue(queue)); |
| 446 | } |
| 447 | |
| 448 | if (queue_props[i].queueFlags & XGL_QUEUE_COMPUTE_BIT) { |
| 449 | queues_[COMPUTE].push_back(new Queue(queue)); |
| 450 | } |
| 451 | |
| 452 | if (queue_props[i].queueFlags & XGL_QUEUE_DMA_BIT) { |
| 453 | queues_[DMA].push_back(new Queue(queue)); |
| 454 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | EXPECT(!queues_[GRAPHICS].empty() || !queues_[COMPUTE].empty()); |
| 459 | } |
| 460 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 461 | void Device::init_formats() |
| 462 | { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 463 | for (int f = XGL_FMT_BEGIN_RANGE; f <= XGL_FMT_END_RANGE; f++) { |
| 464 | const XGL_FORMAT fmt = static_cast<XGL_FORMAT>(f); |
| 465 | const XGL_FORMAT_PROPERTIES props = format_properties(fmt); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 466 | |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 467 | if (props.linearTilingFeatures) { |
| 468 | const Format tmp = { fmt, XGL_LINEAR_TILING, props.linearTilingFeatures }; |
| 469 | formats_.push_back(tmp); |
| 470 | } |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 471 | |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 472 | if (props.optimalTilingFeatures) { |
| 473 | const Format tmp = { fmt, XGL_OPTIMAL_TILING, props.optimalTilingFeatures }; |
| 474 | formats_.push_back(tmp); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | EXPECT(!formats_.empty()); |
| 479 | } |
| 480 | |
| 481 | XGL_FORMAT_PROPERTIES Device::format_properties(XGL_FORMAT format) |
| 482 | { |
| 483 | const XGL_FORMAT_INFO_TYPE type = XGL_INFO_TYPE_FORMAT_PROPERTIES; |
| 484 | XGL_FORMAT_PROPERTIES data; |
| 485 | size_t size = sizeof(data); |
| 486 | if (!EXPECT(xglGetFormatInfo(obj(), format, type, &size, &data) == XGL_SUCCESS && size == sizeof(data))) |
| 487 | memset(&data, 0, sizeof(data)); |
| 488 | |
| 489 | return data; |
| 490 | } |
| 491 | |
| 492 | void Device::wait() |
| 493 | { |
| 494 | EXPECT(xglDeviceWaitIdle(obj()) == XGL_SUCCESS); |
| 495 | } |
| 496 | |
| 497 | XGL_RESULT Device::wait(const std::vector<const Fence *> &fences, bool wait_all, uint64_t timeout) |
| 498 | { |
| 499 | const std::vector<XGL_FENCE> fence_objs = make_objects<XGL_FENCE>(fences); |
| 500 | XGL_RESULT err = xglWaitForFences(obj(), fence_objs.size(), &fence_objs[0], wait_all, timeout); |
| 501 | EXPECT(err == XGL_SUCCESS || err == XGL_TIMEOUT); |
| 502 | |
| 503 | return err; |
| 504 | } |
| 505 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 506 | void Device::begin_descriptor_pool_update(XGL_DESCRIPTOR_UPDATE_MODE mode) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 507 | { |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 508 | EXPECT(xglBeginDescriptorPoolUpdate(obj(), mode) == XGL_SUCCESS); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 509 | } |
| 510 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 511 | void Device::end_descriptor_pool_update(CmdBuffer &cmd) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 512 | { |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 513 | EXPECT(xglEndDescriptorPoolUpdate(obj(), cmd.obj()) == XGL_SUCCESS); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 514 | } |
| 515 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 516 | void Queue::submit(const std::vector<const CmdBuffer *> &cmds, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence) |
| 517 | { |
| 518 | const std::vector<XGL_CMD_BUFFER> cmd_objs = make_objects<XGL_CMD_BUFFER>(cmds); |
| 519 | EXPECT(xglQueueSubmit(obj(), cmd_objs.size(), &cmd_objs[0], mem_refs.size(), &mem_refs[0], fence.obj()) == XGL_SUCCESS); |
| 520 | } |
| 521 | |
| 522 | void Queue::submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs, Fence &fence) |
| 523 | { |
| 524 | submit(std::vector<const CmdBuffer*>(1, &cmd), mem_refs, fence); |
| 525 | } |
| 526 | |
| 527 | void Queue::submit(const CmdBuffer &cmd, const std::vector<XGL_MEMORY_REF> &mem_refs) |
| 528 | { |
| 529 | Fence fence; |
| 530 | submit(cmd, mem_refs, fence); |
| 531 | } |
| 532 | |
| 533 | void Queue::set_global_mem_references(const std::vector<XGL_MEMORY_REF> &mem_refs) |
| 534 | { |
| 535 | EXPECT(xglQueueSetGlobalMemReferences(obj(), mem_refs.size(), &mem_refs[0]) == XGL_SUCCESS); |
| 536 | } |
| 537 | |
| 538 | void Queue::wait() |
| 539 | { |
| 540 | EXPECT(xglQueueWaitIdle(obj()) == XGL_SUCCESS); |
| 541 | } |
| 542 | |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 543 | void Queue::signal_semaphore(Semaphore &sem) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 544 | { |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 545 | EXPECT(xglQueueSignalSemaphore(obj(), sem.obj()) == XGL_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 546 | } |
| 547 | |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 548 | void Queue::wait_semaphore(Semaphore &sem) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 549 | { |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 550 | EXPECT(xglQueueWaitSemaphore(obj(), sem.obj()) == XGL_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | GpuMemory::~GpuMemory() |
| 554 | { |
| 555 | if (initialized() && own()) |
| 556 | EXPECT(xglFreeMemory(obj()) == XGL_SUCCESS); |
| 557 | } |
| 558 | |
| 559 | void GpuMemory::init(const Device &dev, const XGL_MEMORY_ALLOC_INFO &info) |
| 560 | { |
| 561 | DERIVED_OBJECT_INIT(xglAllocMemory, dev.obj(), &info); |
| 562 | } |
| 563 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 564 | void GpuMemory::init(const Device &dev, size_t size, const void *data) |
| 565 | { |
| 566 | DERIVED_OBJECT_INIT(xglPinSystemMemory, dev.obj(), data, size); |
| 567 | } |
| 568 | |
| 569 | void GpuMemory::init(const Device &dev, const XGL_MEMORY_OPEN_INFO &info) |
| 570 | { |
| 571 | DERIVED_OBJECT_INIT(xglOpenSharedMemory, dev.obj(), &info); |
| 572 | } |
| 573 | |
| 574 | void GpuMemory::init(const Device &dev, const XGL_PEER_MEMORY_OPEN_INFO &info) |
| 575 | { |
| 576 | DERIVED_OBJECT_INIT(xglOpenPeerMemory, dev.obj(), &info); |
| 577 | } |
| 578 | |
| 579 | void GpuMemory::set_priority(XGL_MEMORY_PRIORITY priority) |
| 580 | { |
| 581 | EXPECT(xglSetMemoryPriority(obj(), priority) == XGL_SUCCESS); |
| 582 | } |
| 583 | |
| 584 | const void *GpuMemory::map(XGL_FLAGS flags) const |
| 585 | { |
| 586 | void *data; |
| 587 | if (!EXPECT(xglMapMemory(obj(), flags, &data) == XGL_SUCCESS)) |
| 588 | data = NULL; |
| 589 | |
| 590 | return data; |
| 591 | } |
| 592 | |
| 593 | void *GpuMemory::map(XGL_FLAGS flags) |
| 594 | { |
| 595 | void *data; |
| 596 | if (!EXPECT(xglMapMemory(obj(), flags, &data) == XGL_SUCCESS)) |
| 597 | data = NULL; |
| 598 | |
| 599 | return data; |
| 600 | } |
| 601 | |
| 602 | void GpuMemory::unmap() const |
| 603 | { |
| 604 | EXPECT(xglUnmapMemory(obj()) == XGL_SUCCESS); |
| 605 | } |
| 606 | |
| 607 | void Fence::init(const Device &dev, const XGL_FENCE_CREATE_INFO &info) |
| 608 | { |
| 609 | DERIVED_OBJECT_INIT(xglCreateFence, dev.obj(), &info); |
| 610 | alloc_memory(dev); |
| 611 | } |
| 612 | |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 613 | void Semaphore::init(const Device &dev, const XGL_SEMAPHORE_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 614 | { |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 615 | DERIVED_OBJECT_INIT(xglCreateSemaphore, dev.obj(), &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 616 | alloc_memory(dev); |
| 617 | } |
| 618 | |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 619 | void Semaphore::init(const Device &dev, const XGL_SEMAPHORE_OPEN_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 620 | { |
Courtney Goeltzenleuchter | 0d2efef | 2015-03-25 17:14:29 -0600 | [diff] [blame] | 621 | DERIVED_OBJECT_INIT(xglOpenSharedSemaphore, dev.obj(), &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void Event::init(const Device &dev, const XGL_EVENT_CREATE_INFO &info) |
| 625 | { |
| 626 | DERIVED_OBJECT_INIT(xglCreateEvent, dev.obj(), &info); |
| 627 | alloc_memory(dev); |
| 628 | } |
| 629 | |
| 630 | void Event::set() |
| 631 | { |
| 632 | EXPECT(xglSetEvent(obj()) == XGL_SUCCESS); |
| 633 | } |
| 634 | |
| 635 | void Event::reset() |
| 636 | { |
| 637 | EXPECT(xglResetEvent(obj()) == XGL_SUCCESS); |
| 638 | } |
| 639 | |
| 640 | void QueryPool::init(const Device &dev, const XGL_QUERY_POOL_CREATE_INFO &info) |
| 641 | { |
| 642 | DERIVED_OBJECT_INIT(xglCreateQueryPool, dev.obj(), &info); |
| 643 | alloc_memory(dev); |
| 644 | } |
| 645 | |
| 646 | XGL_RESULT QueryPool::results(uint32_t start, uint32_t count, size_t size, void *data) |
| 647 | { |
| 648 | size_t tmp = size; |
| 649 | XGL_RESULT err = xglGetQueryPoolResults(obj(), start, count, &tmp, data); |
| 650 | if (err == XGL_SUCCESS) { |
| 651 | if (!EXPECT(tmp == size)) |
| 652 | memset(data, 0, size); |
| 653 | } else { |
| 654 | EXPECT(err == XGL_NOT_READY); |
| 655 | } |
| 656 | |
| 657 | return err; |
| 658 | } |
| 659 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 660 | void Buffer::init(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) |
| 661 | { |
| 662 | init_no_mem(dev, info); |
Jon Ashburn | 5567c81 | 2015-01-20 08:50:12 -0700 | [diff] [blame] | 663 | alloc_memory(dev, true, false); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | void Buffer::init_no_mem(const Device &dev, const XGL_BUFFER_CREATE_INFO &info) |
| 667 | { |
| 668 | DERIVED_OBJECT_INIT(xglCreateBuffer, dev.obj(), &info); |
| 669 | create_info_ = info; |
| 670 | } |
| 671 | |
| 672 | void BufferView::init(const Device &dev, const XGL_BUFFER_VIEW_CREATE_INFO &info) |
| 673 | { |
| 674 | DERIVED_OBJECT_INIT(xglCreateBufferView, dev.obj(), &info); |
| 675 | alloc_memory(dev); |
| 676 | } |
| 677 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 678 | void Image::init(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 679 | { |
| 680 | init_no_mem(dev, info); |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 681 | alloc_memory(dev, info.tiling == XGL_LINEAR_TILING, true); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | void Image::init_no_mem(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 685 | { |
| 686 | DERIVED_OBJECT_INIT(xglCreateImage, dev.obj(), &info); |
| 687 | init_info(dev, info); |
| 688 | } |
| 689 | |
| 690 | void Image::init(const Device &dev, const XGL_PEER_IMAGE_OPEN_INFO &info, const XGL_IMAGE_CREATE_INFO &original_info) |
| 691 | { |
| 692 | XGL_IMAGE img; |
| 693 | XGL_GPU_MEMORY mem; |
| 694 | EXPECT(xglOpenPeerImage(dev.obj(), &info, &img, &mem) == XGL_SUCCESS); |
| 695 | Object::init(img); |
| 696 | |
| 697 | init_info(dev, original_info); |
| 698 | alloc_memory(std::vector<XGL_GPU_MEMORY>(1, mem)); |
| 699 | } |
| 700 | |
| 701 | void Image::init_info(const Device &dev, const XGL_IMAGE_CREATE_INFO &info) |
| 702 | { |
| 703 | create_info_ = info; |
| 704 | |
| 705 | for (std::vector<Device::Format>::const_iterator it = dev.formats().begin(); it != dev.formats().end(); it++) { |
| 706 | if (memcmp(&it->format, &create_info_.format, sizeof(it->format)) == 0 && it->tiling == create_info_.tiling) { |
| 707 | format_features_ = it->features; |
| 708 | break; |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 713 | void Image::bind_memory(uint32_t alloc_idx, const XGL_IMAGE_MEMORY_BIND_INFO &info, |
| 714 | const GpuMemory &mem, XGL_GPU_SIZE mem_offset) |
| 715 | { |
Jon Ashburn | ed62b41 | 2015-01-15 10:39:19 -0700 | [diff] [blame] | 716 | EXPECT(!alloc_idx && xglBindImageMemoryRange(obj(), 0, &info, mem.obj(), mem_offset) == XGL_SUCCESS); |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 717 | } |
| 718 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 719 | XGL_SUBRESOURCE_LAYOUT Image::subresource_layout(const XGL_IMAGE_SUBRESOURCE &subres) const |
| 720 | { |
| 721 | const XGL_SUBRESOURCE_INFO_TYPE type = XGL_INFO_TYPE_SUBRESOURCE_LAYOUT; |
| 722 | XGL_SUBRESOURCE_LAYOUT data; |
| 723 | size_t size = sizeof(data); |
| 724 | if (!EXPECT(xglGetImageSubresourceInfo(obj(), &subres, type, &size, &data) == XGL_SUCCESS && size == sizeof(data))) |
| 725 | memset(&data, 0, sizeof(data)); |
| 726 | |
| 727 | return data; |
| 728 | } |
| 729 | |
| 730 | bool Image::transparent() const |
| 731 | { |
| 732 | return (create_info_.tiling == XGL_LINEAR_TILING && |
| 733 | create_info_.samples == 1 && |
| 734 | !(create_info_.usage & (XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 735 | XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT))); |
| 736 | } |
| 737 | |
| 738 | void ImageView::init(const Device &dev, const XGL_IMAGE_VIEW_CREATE_INFO &info) |
| 739 | { |
| 740 | DERIVED_OBJECT_INIT(xglCreateImageView, dev.obj(), &info); |
| 741 | alloc_memory(dev); |
| 742 | } |
| 743 | |
| 744 | void ColorAttachmentView::init(const Device &dev, const XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO &info) |
| 745 | { |
| 746 | DERIVED_OBJECT_INIT(xglCreateColorAttachmentView, dev.obj(), &info); |
| 747 | alloc_memory(dev); |
| 748 | } |
| 749 | |
| 750 | void DepthStencilView::init(const Device &dev, const XGL_DEPTH_STENCIL_VIEW_CREATE_INFO &info) |
| 751 | { |
| 752 | DERIVED_OBJECT_INIT(xglCreateDepthStencilView, dev.obj(), &info); |
| 753 | alloc_memory(dev); |
| 754 | } |
| 755 | |
| 756 | void Shader::init(const Device &dev, const XGL_SHADER_CREATE_INFO &info) |
| 757 | { |
| 758 | DERIVED_OBJECT_INIT(xglCreateShader, dev.obj(), &info); |
| 759 | } |
| 760 | |
| 761 | XGL_RESULT Shader::init_try(const Device &dev, const XGL_SHADER_CREATE_INFO &info) |
| 762 | { |
| 763 | XGL_SHADER sh; |
| 764 | XGL_RESULT err = xglCreateShader(dev.obj(), &info, &sh); |
| 765 | if (err == XGL_SUCCESS) |
| 766 | Object::init(sh); |
| 767 | |
| 768 | return err; |
| 769 | } |
| 770 | |
| 771 | void Pipeline::init(const Device &dev, const XGL_GRAPHICS_PIPELINE_CREATE_INFO &info) |
| 772 | { |
| 773 | DERIVED_OBJECT_INIT(xglCreateGraphicsPipeline, dev.obj(), &info); |
| 774 | alloc_memory(dev); |
| 775 | } |
| 776 | |
Courtney Goeltzenleuchter | 32876a1 | 2015-03-25 15:37:49 -0600 | [diff] [blame] | 777 | void Pipeline::init( |
| 778 | const Device &dev, |
| 779 | const XGL_GRAPHICS_PIPELINE_CREATE_INFO &info, |
| 780 | const XGL_PIPELINE basePipeline) |
| 781 | { |
| 782 | DERIVED_OBJECT_INIT(xglCreateGraphicsPipelineDerivative, dev.obj(), &info, basePipeline); |
| 783 | alloc_memory(dev); |
| 784 | } |
| 785 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 786 | void Pipeline::init(const Device &dev, const XGL_COMPUTE_PIPELINE_CREATE_INFO &info) |
| 787 | { |
| 788 | DERIVED_OBJECT_INIT(xglCreateComputePipeline, dev.obj(), &info); |
| 789 | alloc_memory(dev); |
| 790 | } |
| 791 | |
| 792 | void Pipeline::init(const Device&dev, size_t size, const void *data) |
| 793 | { |
| 794 | DERIVED_OBJECT_INIT(xglLoadPipeline, dev.obj(), size, data); |
| 795 | alloc_memory(dev); |
| 796 | } |
| 797 | |
Courtney Goeltzenleuchter | 32876a1 | 2015-03-25 15:37:49 -0600 | [diff] [blame] | 798 | void Pipeline::init( |
| 799 | const Device&dev, |
| 800 | size_t size, |
| 801 | const void *data, |
| 802 | const XGL_PIPELINE basePipeline) |
| 803 | { |
| 804 | DERIVED_OBJECT_INIT(xglLoadPipelineDerivative, dev.obj(), size, data, basePipeline); |
| 805 | alloc_memory(dev); |
| 806 | } |
| 807 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 808 | size_t Pipeline::store(size_t size, void *data) |
| 809 | { |
| 810 | if (!EXPECT(xglStorePipeline(obj(), &size, data) == XGL_SUCCESS)) |
| 811 | size = 0; |
| 812 | |
| 813 | return size; |
| 814 | } |
| 815 | |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 816 | void Sampler::init(const Device &dev, const XGL_SAMPLER_CREATE_INFO &info) |
| 817 | { |
| 818 | DERIVED_OBJECT_INIT(xglCreateSampler, dev.obj(), &info); |
| 819 | alloc_memory(dev); |
| 820 | } |
| 821 | |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 822 | void DescriptorSetLayout::init(const Device &dev, XGL_FLAGS stage_mask, |
| 823 | const std::vector<uint32_t> &bind_points, |
| 824 | const DescriptorSetLayout &prior_layout, |
| 825 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 826 | { |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 827 | DERIVED_OBJECT_INIT(xglCreateDescriptorSetLayout, dev.obj(), stage_mask, |
| 828 | &bind_points[0], prior_layout.obj(), &info); |
| 829 | alloc_memory(dev); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 830 | } |
| 831 | |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 832 | void DescriptorSetLayout::init(const Device &dev, uint32_t bind_point, |
| 833 | const DescriptorSetLayout &prior_layout, |
| 834 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 835 | { |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 836 | init(dev, XGL_SHADER_STAGE_FLAGS_ALL, std::vector<uint32_t>(1, bind_point), prior_layout, info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 837 | } |
| 838 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 839 | void DescriptorPool::init(const Device &dev, XGL_DESCRIPTOR_POOL_USAGE usage, |
| 840 | uint32_t max_sets, const XGL_DESCRIPTOR_POOL_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 841 | { |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 842 | DERIVED_OBJECT_INIT(xglCreateDescriptorPool, dev.obj(), usage, max_sets, &info); |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 843 | alloc_memory(dev); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 844 | } |
| 845 | |
Chia-I Wu | dee9561 | 2015-03-26 15:23:52 +0800 | [diff] [blame^] | 846 | void DescriptorPool::reset() |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 847 | { |
Chia-I Wu | dee9561 | 2015-03-26 15:23:52 +0800 | [diff] [blame^] | 848 | EXPECT(xglResetDescriptorPool(obj()) == XGL_SUCCESS); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 849 | } |
| 850 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 851 | std::vector<DescriptorSet *> DescriptorPool::alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const std::vector<const DescriptorSetLayout *> &layouts) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 852 | { |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 853 | const std::vector<XGL_DESCRIPTOR_SET_LAYOUT> layout_objs = make_objects<XGL_DESCRIPTOR_SET_LAYOUT>(layouts); |
| 854 | |
| 855 | std::vector<XGL_DESCRIPTOR_SET> set_objs; |
| 856 | set_objs.resize(layout_objs.size()); |
| 857 | |
| 858 | uint32_t set_count; |
| 859 | XGL_RESULT err = xglAllocDescriptorSets(obj(), usage, layout_objs.size(), &layout_objs[0], &set_objs[0], &set_count); |
| 860 | if (err == XGL_SUCCESS) |
| 861 | EXPECT(set_count == set_objs.size()); |
| 862 | set_objs.resize(set_count); |
| 863 | |
| 864 | std::vector<DescriptorSet *> sets; |
| 865 | sets.reserve(set_count); |
| 866 | for (std::vector<XGL_DESCRIPTOR_SET>::const_iterator it = set_objs.begin(); it != set_objs.end(); it++) { |
| 867 | // do descriptor sets need memories bound? |
| 868 | sets.push_back(new DescriptorSet(*it)); |
| 869 | } |
| 870 | |
| 871 | return sets; |
| 872 | } |
| 873 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 874 | std::vector<DescriptorSet *> DescriptorPool::alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const DescriptorSetLayout &layout, uint32_t count) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 875 | { |
| 876 | return alloc_sets(usage, std::vector<const DescriptorSetLayout *>(count, &layout)); |
| 877 | } |
| 878 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 879 | DescriptorSet *DescriptorPool::alloc_sets(XGL_DESCRIPTOR_SET_USAGE usage, const DescriptorSetLayout &layout) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 880 | { |
| 881 | std::vector<DescriptorSet *> set = alloc_sets(usage, layout, 1); |
| 882 | return (set.empty()) ? NULL : set[0]; |
| 883 | } |
| 884 | |
Chia-I Wu | 8d24b3b | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 885 | void DescriptorPool::clear_sets(const std::vector<DescriptorSet *> &sets) |
Chia-I Wu | f838506 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 886 | { |
| 887 | const std::vector<XGL_DESCRIPTOR_SET> set_objs = make_objects<XGL_DESCRIPTOR_SET>(sets); |
| 888 | xglClearDescriptorSets(obj(), set_objs.size(), &set_objs[0]); |
| 889 | } |
| 890 | |
| 891 | void DescriptorSet::update(const void *update_chain) |
| 892 | { |
| 893 | xglUpdateDescriptors(obj(), update_chain); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 894 | } |
| 895 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 896 | void DynamicVpStateObject::init(const Device &dev, const XGL_DYNAMIC_VP_STATE_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 897 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 898 | DERIVED_OBJECT_INIT(xglCreateDynamicViewportState, dev.obj(), &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 899 | alloc_memory(dev); |
| 900 | } |
| 901 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 902 | void DynamicRsStateObject::init(const Device &dev, const XGL_DYNAMIC_RS_STATE_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 903 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 904 | DERIVED_OBJECT_INIT(xglCreateDynamicRasterState, dev.obj(), &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 905 | alloc_memory(dev); |
| 906 | } |
| 907 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 908 | void DynamicCbStateObject::init(const Device &dev, const XGL_DYNAMIC_CB_STATE_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 909 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 910 | DERIVED_OBJECT_INIT(xglCreateDynamicColorBlendState, dev.obj(), &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 911 | alloc_memory(dev); |
| 912 | } |
| 913 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 914 | void DynamicDsStateObject::init(const Device &dev, const XGL_DYNAMIC_DS_STATE_CREATE_INFO &info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 915 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 916 | DERIVED_OBJECT_INIT(xglCreateDynamicDepthStencilState, dev.obj(), &info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 917 | alloc_memory(dev); |
| 918 | } |
| 919 | |
| 920 | void CmdBuffer::init(const Device &dev, const XGL_CMD_BUFFER_CREATE_INFO &info) |
| 921 | { |
| 922 | DERIVED_OBJECT_INIT(xglCreateCommandBuffer, dev.obj(), &info); |
| 923 | } |
| 924 | |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 925 | void CmdBuffer::begin(const XGL_CMD_BUFFER_BEGIN_INFO *info) |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 926 | { |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 927 | EXPECT(xglBeginCommandBuffer(obj(), info) == XGL_SUCCESS); |
| 928 | } |
| 929 | |
Courtney Goeltzenleuchter | e3b0f3a | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 930 | void CmdBuffer::begin(XGL_RENDER_PASS renderpass_obj, XGL_FRAMEBUFFER framebuffer_obj) |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 931 | { |
| 932 | XGL_CMD_BUFFER_BEGIN_INFO info = {}; |
Tony Barbour | 901f3bc | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 933 | XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO graphics_cmd_buf_info = {}; |
| 934 | graphics_cmd_buf_info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO; |
| 935 | graphics_cmd_buf_info.pNext = NULL; |
Courtney Goeltzenleuchter | e3b0f3a | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 936 | graphics_cmd_buf_info.renderPassContinue.renderPass = renderpass_obj; |
| 937 | graphics_cmd_buf_info.renderPassContinue.framebuffer = framebuffer_obj; |
Tony Barbour | 901f3bc | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 938 | |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 939 | info.flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 940 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 941 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 942 | info.pNext = &graphics_cmd_buf_info; |
| 943 | |
| 944 | begin(&info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | void CmdBuffer::begin() |
| 948 | { |
Jeremy Hayes | e0c3b22 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 949 | XGL_CMD_BUFFER_BEGIN_INFO info = {}; |
| 950 | info.flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 951 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 952 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 953 | |
| 954 | begin(&info); |
Chia-I Wu | 82bff27 | 2014-12-27 14:12:52 +0800 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | void CmdBuffer::end() |
| 958 | { |
| 959 | EXPECT(xglEndCommandBuffer(obj()) == XGL_SUCCESS); |
| 960 | } |
| 961 | |
| 962 | void CmdBuffer::reset() |
| 963 | { |
| 964 | EXPECT(xglResetCommandBuffer(obj()) == XGL_SUCCESS); |
| 965 | } |
| 966 | |
| 967 | }; // namespace xgl_testing |