blob: b8446c5dbada3070486d18d0535195a2248d86f5 [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();
Courtney Goeltzenleuchtere099abd2014-08-12 14:09:50 -060015}
16
17void XglGpu::init_gpu()
18{
19 int i;
20 XGL_RESULT err;
21 XGL_SIZE size;
22
23 err = xglGetGpuInfo(this->gpuObj,
24 XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES,
25 &size, &this->props);
26 ASSERT_XGL_SUCCESS(err);
27 ASSERT_EQ(size, sizeof(this->props));
28
29 err = xglGetGpuInfo(this->gpuObj,
30 XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE,
31 &size, &this->perf);
32 ASSERT_XGL_SUCCESS(err);
33 ASSERT_EQ(size, sizeof(this->perf));
34
35 /* get queue count */
36 err = xglGetGpuInfo(this->gpuObj,
37 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
38 &size, NULL);
39 ASSERT_XGL_SUCCESS(err);
40 this->queue_count = size / sizeof(this->queue_props[0]);
41 ASSERT_EQ(this->queue_count*sizeof(this->queue_props[0]), size) << "invalid GPU_QUEUE_PROPERTIES size";
42
43 this->queue_props = new XGL_PHYSICAL_GPU_QUEUE_PROPERTIES [this->queue_count];
44 ASSERT_TRUE(NULL != this->queue_props) << "Out of memory";
45
46 err = xglGetGpuInfo(this->gpuObj,
47 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
48 &size, this->queue_props);
49 ASSERT_XGL_SUCCESS(err);
50 ASSERT_EQ(this->queue_count*sizeof(this->queue_props[0]), size) << "invalid GPU_QUEUE_PROPERTIES size";
51
52 /* set up queue requests */
53 // this->queue_reqs = malloc(sizeof(*this->queue_reqs) * this->queue_count);
54 this->queue_reqs = new XGL_DEVICE_QUEUE_CREATE_INFO [this->queue_count];
55 ASSERT_TRUE(NULL != this->queue_reqs) << "Out of memory";
56
57 for (i = 0; i < this->queue_count; i++) {
58 this->queue_reqs[i].queueNodeIndex = i;
59 this->queue_reqs[i].queueCount = this->queue_props[i].queueCount;
60 }
61
62 err = xglGetGpuInfo(this->gpuObj,
63 XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES,
64 &size, &this->memory_props);
65 ASSERT_XGL_SUCCESS(err);
66 ASSERT_EQ(size, sizeof(this->memory_props));
67}
68
69void XglGpu::init_extensions()
70{
71 XGL_RESULT err;
72 XGL_UINT i;
73
74 static const XGL_CHAR *known_extensions[] = {
75 (const XGL_CHAR *) "some_extension",
76 };
77 this->extension_count = 0;
78
79 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
80 err = xglGetExtensionSupport(this->gpuObj, known_extensions[i]);
81 if (!err)
82 this->extension_count++;
83 }
84
85 if (this->extension_count == 0) {
86 return;
87 }
88
89 this->extensions = new const XGL_CHAR *[this->extension_count];
90
91 ASSERT_TRUE(NULL != this->extensions) << "Out of memory";
92
93 this->extension_count = 0;
94 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
95 err = xglGetExtensionSupport(this->gpuObj, known_extensions[i]);
96 if (!err)
97 this->extensions[this->extension_count++] = known_extensions[i];
98 }
99}
100