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 | { |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 53 | for (int chInt = XGL_CH_FMT_UNDEFINED; chInt < XGL_MAX_CH_FMT; chInt++) { |
| 54 | for (int numInt = 0; numInt < XGL_MAX_NUM_FMT; numInt++) { |
| 55 | XGL_FORMAT fmt = {}; |
| 56 | XGL_RESULT err; |
| 57 | XGL_SIZE size; |
| 58 | |
| 59 | fmt.channelFormat = static_cast<XGL_CHANNEL_FORMAT>(chInt); |
| 60 | fmt.numericFormat = static_cast<XGL_NUM_FORMAT>(numInt); |
| 61 | |
| 62 | err = xglGetFormatInfo(m_xgl_device_object, fmt, |
| 63 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
Chia-I Wu | 28798b6 | 2014-08-27 14:22:38 +0800 | [diff] [blame] | 64 | &size, &this->format_props[chInt][numInt]); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 65 | if (err) { |
Chia-I Wu | 28798b6 | 2014-08-27 14:22:38 +0800 | [diff] [blame] | 66 | memset(&this->format_props[chInt][numInt], 0, |
| 67 | sizeof(this->format_props[chInt][numInt])); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 68 | } |
Chia-I Wu | 28798b6 | 2014-08-27 14:22:38 +0800 | [diff] [blame] | 69 | else if (size != sizeof(this->format_props[chInt][numInt])) { |
| 70 | ASSERT_EQ(size, sizeof(this->format_props[chInt][numInt])) << "Incorrect data size"; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
Courtney Goeltzenleuchter | bd3bde4 | 2014-08-20 15:26:23 -0600 | [diff] [blame] | 76 | |
| 77 | 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] | 78 | { |
| 79 | XGL_RESULT err; |
| 80 | |
Courtney Goeltzenleuchter | bd3bde4 | 2014-08-20 15:26:23 -0600 | [diff] [blame] | 81 | err = xglGetDeviceQueue(this->device(), queue_type, queue_idx, &this->m_queue); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 82 | ASSERT_XGL_SUCCESS(err) << "xglGetDeviceQueue failed"; |
| 83 | } |
Courtney Goeltzenleuchter | c3102ac | 2014-08-22 16:27:11 -0600 | [diff] [blame] | 84 | |
| 85 | XGL_RESULT XglDevice::AllocAndBindGpuMemory(XGL_OBJECT obj, const std::string &objName, XGL_GPU_MEMORY *pMem) |
| 86 | { |
| 87 | XGL_RESULT err; |
| 88 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 89 | XGL_UINT data_size; |
| 90 | err = xglGetObjectInfo(obj, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, &data_size, &mem_req); |
| 91 | if (err != XGL_SUCCESS) return err; |
| 92 | |
| 93 | if (mem_req.size > 0) { |
| 94 | XGL_MEMORY_ALLOC_INFO mem_info = { |
| 95 | XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 96 | XGL_NULL_HANDLE, |
| 97 | mem_req.size, // allocationSize |
| 98 | mem_req.alignment, // alignment |
| 99 | XGL_MEMORY_ALLOC_SHAREABLE_BIT, // XGL_MEMORY_ALLOC_FLAGS |
| 100 | mem_req.heapCount, // heapCount |
| 101 | {0}, // heaps |
| 102 | XGL_MEMORY_PRIORITY_NORMAL // XGL_MEMORY_PRIORITY |
| 103 | }; |
| 104 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 105 | |
| 106 | err = xglAllocMemory(device(), &mem_info, pMem); |
| 107 | if (err != XGL_SUCCESS) return err; |
| 108 | |
| 109 | err = xglBindObjectMemory(obj, *pMem, 0); |
| 110 | if (err != XGL_SUCCESS) return err; |
| 111 | } |
| 112 | |
| 113 | return err; |
| 114 | } |