blob: 8339de05493991b3f6577c33e816502f451a1ece [file] [log] [blame]
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -06001#include "xgldevice.h"
2
3XglDevice::XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj) :
4 m_flags(0),
5 XglGpu(id, obj)
6{
7 init_device();
8 init_formats();
9}
10
11
12void XglDevice::init_device()
13{
14 XGL_DEVICE_CREATE_INFO info = {};
15 XGL_RESULT err;
16 XGL_SIZE size;
17 XGL_UINT i;
18
19 info.sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
20 info.maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE;
21 info.flags = XGL_DEVICE_CREATE_VALIDATION_BIT;
22
23 /* request all queues */
24 info.queueRecordCount = this->queue_count;
25 info.pRequestedQueues = this->queue_reqs;
26
27 /* enable all extensions */
28 info.extensionCount = this->extension_count;
29 info.ppEnabledExtensionNames = this->extensions;
30
31 err = xglCreateDevice(this->gpuObj, &info, &m_xgl_device_object);
32 ASSERT_XGL_SUCCESS(err);
33
34 err = xglGetMemoryHeapCount(m_xgl_device_object, &this->heap_count);
35 ASSERT_XGL_SUCCESS(err);
36 ASSERT_GE(1, this->heap_count) << "No memory heaps available";
37
38 this->heap_props = new XGL_MEMORY_HEAP_PROPERTIES [this->heap_count];
39 ASSERT_TRUE(NULL != this->heap_props) << "Out of memory";
40
41 for (i = 0; i < this->heap_count; i++) {
42 err = xglGetMemoryHeapInfo(m_xgl_device_object, i,
43 XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES,
44 &size, &this->heap_props[i]);
45 ASSERT_XGL_SUCCESS(err);
46 ASSERT_EQ(size, sizeof(this->heap_props[0])) << "Invalid heap property size";
47 }
48}
49
50void XglDevice::init_formats()
51{
52 XGL_CHANNEL_FORMAT ch;
53 XGL_NUM_FORMAT num;
54
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,
66 &size, &this->format_props[ch][num]);
67 if (err) {
68 memset(&this->format_props[ch][num], 0,
69 sizeof(this->format_props[ch][num]));
70 }
71 else if (size != sizeof(this->format_props[ch][num])) {
72 ASSERT_EQ(size, sizeof(this->format_props[ch][num])) << "Incorrect data size";
73 }
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}