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