Courtney Goeltzenleuchter | c3102ac | 2014-08-22 16:27:11 -0600 | [diff] [blame^] | 1 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 2 | #include "xgldevice.h" |
| 3 | |
| 4 | XglDevice::XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj) : |
| 5 | m_flags(0), |
| 6 | XglGpu(id, obj) |
| 7 | { |
| 8 | init_device(); |
| 9 | init_formats(); |
| 10 | } |
| 11 | |
| 12 | |
| 13 | void XglDevice::init_device() |
| 14 | { |
| 15 | XGL_DEVICE_CREATE_INFO info = {}; |
| 16 | XGL_RESULT err; |
| 17 | XGL_SIZE size; |
| 18 | XGL_UINT i; |
| 19 | |
| 20 | info.sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO, |
| 21 | info.maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE; |
| 22 | info.flags = XGL_DEVICE_CREATE_VALIDATION_BIT; |
| 23 | |
| 24 | /* request all queues */ |
| 25 | info.queueRecordCount = this->queue_count; |
| 26 | info.pRequestedQueues = this->queue_reqs; |
| 27 | |
| 28 | /* enable all extensions */ |
| 29 | info.extensionCount = this->extension_count; |
| 30 | info.ppEnabledExtensionNames = this->extensions; |
| 31 | |
| 32 | err = xglCreateDevice(this->gpuObj, &info, &m_xgl_device_object); |
| 33 | ASSERT_XGL_SUCCESS(err); |
| 34 | |
| 35 | err = xglGetMemoryHeapCount(m_xgl_device_object, &this->heap_count); |
| 36 | ASSERT_XGL_SUCCESS(err); |
| 37 | ASSERT_GE(1, this->heap_count) << "No memory heaps available"; |
| 38 | |
| 39 | this->heap_props = new XGL_MEMORY_HEAP_PROPERTIES [this->heap_count]; |
| 40 | ASSERT_TRUE(NULL != this->heap_props) << "Out of memory"; |
| 41 | |
| 42 | for (i = 0; i < this->heap_count; i++) { |
| 43 | err = xglGetMemoryHeapInfo(m_xgl_device_object, i, |
| 44 | XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES, |
| 45 | &size, &this->heap_props[i]); |
| 46 | ASSERT_XGL_SUCCESS(err); |
| 47 | ASSERT_EQ(size, sizeof(this->heap_props[0])) << "Invalid heap property size"; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void XglDevice::init_formats() |
| 52 | { |
| 53 | XGL_CHANNEL_FORMAT ch; |
| 54 | XGL_NUM_FORMAT num; |
| 55 | |
| 56 | for (int chInt = XGL_CH_FMT_UNDEFINED; chInt < XGL_MAX_CH_FMT; chInt++) { |
| 57 | for (int numInt = 0; numInt < XGL_MAX_NUM_FMT; numInt++) { |
| 58 | XGL_FORMAT fmt = {}; |
| 59 | XGL_RESULT err; |
| 60 | XGL_SIZE size; |
| 61 | |
| 62 | fmt.channelFormat = static_cast<XGL_CHANNEL_FORMAT>(chInt); |
| 63 | fmt.numericFormat = static_cast<XGL_NUM_FORMAT>(numInt); |
| 64 | |
| 65 | err = xglGetFormatInfo(m_xgl_device_object, fmt, |
| 66 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 67 | &size, &this->format_props[ch][num]); |
| 68 | if (err) { |
| 69 | memset(&this->format_props[ch][num], 0, |
| 70 | sizeof(this->format_props[ch][num])); |
| 71 | } |
| 72 | else if (size != sizeof(this->format_props[ch][num])) { |
| 73 | ASSERT_EQ(size, sizeof(this->format_props[ch][num])) << "Incorrect data size"; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
Courtney Goeltzenleuchter | bd3bde4 | 2014-08-20 15:26:23 -0600 | [diff] [blame] | 79 | |
| 80 | void XglDevice::get_device_queue(XGL_QUEUE_TYPE queue_type, XGL_UINT queue_idx) |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 81 | { |
| 82 | XGL_RESULT err; |
| 83 | |
Courtney Goeltzenleuchter | bd3bde4 | 2014-08-20 15:26:23 -0600 | [diff] [blame] | 84 | err = xglGetDeviceQueue(this->device(), queue_type, queue_idx, &this->m_queue); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 85 | ASSERT_XGL_SUCCESS(err) << "xglGetDeviceQueue failed"; |
| 86 | } |
Courtney Goeltzenleuchter | c3102ac | 2014-08-22 16:27:11 -0600 | [diff] [blame^] | 87 | |
| 88 | XGL_RESULT XglDevice::AllocAndBindGpuMemory(XGL_OBJECT obj, const std::string &objName, XGL_GPU_MEMORY *pMem) |
| 89 | { |
| 90 | XGL_RESULT err; |
| 91 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 92 | XGL_UINT data_size; |
| 93 | err = xglGetObjectInfo(obj, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, &data_size, &mem_req); |
| 94 | if (err != XGL_SUCCESS) return err; |
| 95 | |
| 96 | if (mem_req.size > 0) { |
| 97 | XGL_MEMORY_ALLOC_INFO mem_info = { |
| 98 | XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 99 | XGL_NULL_HANDLE, |
| 100 | mem_req.size, // allocationSize |
| 101 | mem_req.alignment, // alignment |
| 102 | XGL_MEMORY_ALLOC_SHAREABLE_BIT, // XGL_MEMORY_ALLOC_FLAGS |
| 103 | mem_req.heapCount, // heapCount |
| 104 | {0}, // heaps |
| 105 | XGL_MEMORY_PRIORITY_NORMAL // XGL_MEMORY_PRIORITY |
| 106 | }; |
| 107 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 108 | |
| 109 | err = xglAllocMemory(device(), &mem_info, pMem); |
| 110 | if (err != XGL_SUCCESS) return err; |
| 111 | |
| 112 | err = xglBindObjectMemory(obj, *pMem, 0); |
| 113 | if (err != XGL_SUCCESS) return err; |
| 114 | } |
| 115 | |
| 116 | return err; |
| 117 | } |