blob: 3a62832f6216fddae4a8ae032aa3c943c21d03f9 [file] [log] [blame]
Courtney Goeltzenleuchterac8d1562014-09-01 16:36:49 -06001
2
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06003#include "xgldevice.h"
Courtney Goeltzenleuchterac8d1562014-09-01 16:36:49 -06004#include "xglimage.h"
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06005
6XglDevice::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
15void 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
53void XglDevice::init_formats()
54{
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060055 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 Wu28798b62014-08-27 14:22:38 +080066 &size, &this->format_props[chInt][numInt]);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060067 if (err) {
Chia-I Wu28798b62014-08-27 14:22:38 +080068 memset(&this->format_props[chInt][numInt], 0,
69 sizeof(this->format_props[chInt][numInt]));
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060070 }
Chia-I Wu28798b62014-08-27 14:22:38 +080071 else if (size != sizeof(this->format_props[chInt][numInt])) {
72 ASSERT_EQ(size, sizeof(this->format_props[chInt][numInt])) << "Incorrect data size";
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060073 }
74 }
75 }
76}
77
Courtney Goeltzenleuchterbd3bde42014-08-20 15:26:23 -060078
79void XglDevice::get_device_queue(XGL_QUEUE_TYPE queue_type, XGL_UINT queue_idx)
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060080{
81 XGL_RESULT err;
82
Courtney Goeltzenleuchterbd3bde42014-08-20 15:26:23 -060083 err = xglGetDeviceQueue(this->device(), queue_type, queue_idx, &this->m_queue);
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060084 ASSERT_XGL_SUCCESS(err) << "xglGetDeviceQueue failed";
85}
Courtney Goeltzenleuchterc3102ac2014-08-22 16:27:11 -060086
87XGL_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 Goeltzenleuchterac8d1562014-09-01 16:36:49 -0600117
118void 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}