blob: 17d31b06327c59873a716b11a0a8c2889df41ef8 [file] [log] [blame]
Courtney Goeltzenleuchtere099abd2014-08-12 14:09:50 -06001#include "xglgpu.h"
2
3#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
4
5XglGpu::XglGpu(XGL_UINT id, XGL_PHYSICAL_GPU obj)
6{
7 this->id = id;
8 this->gpuObj = obj;
9 this->extension_count = 0;
10 this->heap_count = 0;
11 this->queue_count = 0;
12
13 this->init_gpu();
14 this->init_extensions();
15 this->init_device();
16 this->init_formats();
17}
18
19void XglGpu::init_gpu()
20{
21 int i;
22 XGL_RESULT err;
23 XGL_SIZE size;
24
25 err = xglGetGpuInfo(this->gpuObj,
26 XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES,
27 &size, &this->props);
28 ASSERT_XGL_SUCCESS(err);
29 ASSERT_EQ(size, sizeof(this->props));
30
31 err = xglGetGpuInfo(this->gpuObj,
32 XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE,
33 &size, &this->perf);
34 ASSERT_XGL_SUCCESS(err);
35 ASSERT_EQ(size, sizeof(this->perf));
36
37 /* get queue count */
38 err = xglGetGpuInfo(this->gpuObj,
39 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
40 &size, NULL);
41 ASSERT_XGL_SUCCESS(err);
42 this->queue_count = size / sizeof(this->queue_props[0]);
43 ASSERT_EQ(this->queue_count*sizeof(this->queue_props[0]), size) << "invalid GPU_QUEUE_PROPERTIES size";
44
45 this->queue_props = new XGL_PHYSICAL_GPU_QUEUE_PROPERTIES [this->queue_count];
46 ASSERT_TRUE(NULL != this->queue_props) << "Out of memory";
47
48 err = xglGetGpuInfo(this->gpuObj,
49 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
50 &size, this->queue_props);
51 ASSERT_XGL_SUCCESS(err);
52 ASSERT_EQ(this->queue_count*sizeof(this->queue_props[0]), size) << "invalid GPU_QUEUE_PROPERTIES size";
53
54 /* set up queue requests */
55 // this->queue_reqs = malloc(sizeof(*this->queue_reqs) * this->queue_count);
56 this->queue_reqs = new XGL_DEVICE_QUEUE_CREATE_INFO [this->queue_count];
57 ASSERT_TRUE(NULL != this->queue_reqs) << "Out of memory";
58
59 for (i = 0; i < this->queue_count; i++) {
60 this->queue_reqs[i].queueNodeIndex = i;
61 this->queue_reqs[i].queueCount = this->queue_props[i].queueCount;
62 }
63
64 err = xglGetGpuInfo(this->gpuObj,
65 XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES,
66 &size, &this->memory_props);
67 ASSERT_XGL_SUCCESS(err);
68 ASSERT_EQ(size, sizeof(this->memory_props));
69}
70
71void XglGpu::init_extensions()
72{
73 XGL_RESULT err;
74 XGL_UINT i;
75
76 static const XGL_CHAR *known_extensions[] = {
77 (const XGL_CHAR *) "some_extension",
78 };
79 this->extension_count = 0;
80
81 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
82 err = xglGetExtensionSupport(this->gpuObj, known_extensions[i]);
83 if (!err)
84 this->extension_count++;
85 }
86
87 if (this->extension_count == 0) {
88 return;
89 }
90
91 this->extensions = new const XGL_CHAR *[this->extension_count];
92
93 ASSERT_TRUE(NULL != this->extensions) << "Out of memory";
94
95 this->extension_count = 0;
96 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
97 err = xglGetExtensionSupport(this->gpuObj, known_extensions[i]);
98 if (!err)
99 this->extensions[this->extension_count++] = known_extensions[i];
100 }
101}
102
103void XglGpu::init_device()
104{
105 XGL_DEVICE_CREATE_INFO info = {};
106 XGL_RESULT err;
107 XGL_SIZE size;
108 XGL_UINT i;
109
110 info.sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
111 info.maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE;
112 info.flags = XGL_DEVICE_CREATE_VALIDATION_BIT;
113
114 /* request all queues */
115 info.queueRecordCount = this->queue_count;
116 info.pRequestedQueues = this->queue_reqs;
117
118 /* enable all extensions */
119 info.extensionCount = this->extension_count;
120 info.ppEnabledExtensionNames = this->extensions;
121
122 err = xglCreateDevice(this->gpuObj, &info, &this->devObj);
123 ASSERT_XGL_SUCCESS(err);
124
125 err = xglGetMemoryHeapCount(this->devObj, &this->heap_count);
126 ASSERT_XGL_SUCCESS(err);
127
128 this->heap_props = new XGL_MEMORY_HEAP_PROPERTIES [this->heap_count];
129// malloc(sizeof(dev->heap_props[0]) * dev->heap_count);
130 ASSERT_TRUE(NULL != this->heap_props) << "Out of memory";
131
132 for (i = 0; i < this->heap_count; i++) {
133 err = xglGetMemoryHeapInfo(this->devObj, i,
134 XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES,
135 &size, &this->heap_props[i]);
136 ASSERT_XGL_SUCCESS(err);
137 ASSERT_EQ(size, sizeof(this->heap_props[0]));
138 }
139}
140
141void XglGpu::init_formats()
142{
143 XGL_CHANNEL_FORMAT ch;
144 XGL_NUM_FORMAT num;
145
146 for (int chInt = XGL_CH_FMT_UNDEFINED; chInt < XGL_MAX_CH_FMT; chInt++) {
147 for (int numInt = 0; numInt < XGL_MAX_NUM_FMT; numInt++) {
148 XGL_FORMAT fmt = {};
149 XGL_RESULT err;
150 XGL_SIZE size;
151
152 fmt.channelFormat = static_cast<XGL_CHANNEL_FORMAT>(chInt);
153 fmt.numericFormat = static_cast<XGL_NUM_FORMAT>(numInt);
154
155 err = xglGetFormatInfo(this->devObj, fmt,
156 XGL_INFO_TYPE_FORMAT_PROPERTIES,
157 &size, &this->format_props[ch][num]);
158 if (err) {
159 memset(&this->format_props[ch][num], 0,
160 sizeof(this->format_props[ch][num]));
161 }
162 else if (size != sizeof(this->format_props[ch][num])) {
163 ASSERT_EQ(size, sizeof(this->format_props[ch][num])) << "Incorrect data size";
164 }
165 }
166 }
167}
168