blob: 158a23da6d63dbc699b31b959be3d413a478c88c [file] [log] [blame]
Courtney Goeltzenleuchterb202efc2014-08-06 16:11:26 -06001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include "common.h"
26
27void app_dev_init_formats(struct app_dev *dev)
28{
29 XGL_CHANNEL_FORMAT ch;
30 XGL_NUM_FORMAT num;
31
32 for (ch = 0; ch < XGL_MAX_CH_FMT; ch++) {
33 for (num = 0; num < XGL_MAX_NUM_FMT; num++) {
34 const XGL_FORMAT fmt = {
35 .channelFormat = ch,
36 .numericFormat = num,
37 };
38 XGL_RESULT err;
39 XGL_SIZE size;
40
41 err = xglGetFormatInfo(dev->obj, fmt,
42 XGL_INFO_TYPE_FORMAT_PROPERTIES,
43 &size, &dev->format_props[ch][num]);
44 if (err) {
45 memset(&dev->format_props[ch][num], 0,
46 sizeof(dev->format_props[ch][num]));
47 }
48 else if (size != sizeof(dev->format_props[ch][num])) {
49 ERR_EXIT(XGL_ERROR_UNKNOWN);
50 }
51 }
52 }
53}
54
55void app_dev_init(struct app_dev *dev, struct app_gpu *gpu)
56{
57 XGL_DEVICE_CREATE_INFO info = {
58 .sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
59 .pNext = NULL,
60 .queueRecordCount = 0,
61 .pRequestedQueues = NULL,
62 .extensionCount = 0,
63 .ppEnabledExtensionNames = NULL,
64 .maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE,
65 .flags = XGL_DEVICE_CREATE_VALIDATION_BIT,
66 };
67 XGL_RESULT err;
68 XGL_SIZE size;
69 XGL_UINT i;
70
71 /* XXX how to request queues? */
72
73 /* enable all extensions */
74 info.extensionCount = gpu->extension_count;
75 info.ppEnabledExtensionNames = gpu->extensions;
76
77 dev->gpu = gpu;
78 err = xglCreateDevice(gpu->obj, &info, &dev->obj);
79 if (err)
80 ERR_EXIT(err);
81
82 err = xglGetMemoryHeapCount(dev->obj, &dev->heap_count);
83 if (err)
84 ERR_EXIT(err);
85
86 dev->heap_props =
87 malloc(sizeof(dev->heap_props[0]) * dev->heap_count);
88 if (!dev->heap_props)
89 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
90
91 for (i = 0; i < dev->heap_count; i++) {
92 err = xglGetMemoryHeapInfo(dev->obj, i,
93 XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES,
94 &size, &dev->heap_props[i]);
95 if (err || size != sizeof(dev->heap_props[0]))
96 ERR_EXIT(err);
97 }
98}
99
100void app_dev_destroy(struct app_dev *dev)
101{
102 free(dev->heap_props);
103 xglDestroyDevice(dev->obj);
104}
105
106void app_gpu_init_extensions(struct app_gpu *gpu)
107{
108 XGL_RESULT err;
109 XGL_UINT i;
110
111 static const XGL_CHAR *known_extensions[] = {
112 (const XGL_CHAR *) "some_extension",
113 };
114
115 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
116 err = xglGetExtensionSupport(gpu->obj, known_extensions[i]);
117 if (!err)
118 gpu->extension_count++;
119 }
120
121 gpu->extensions =
122 malloc(sizeof(gpu->extensions[0]) * gpu->extension_count);
123 if (!gpu->extensions)
124 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
125
126 gpu->extension_count = 0;
127 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
128 err = xglGetExtensionSupport(gpu->obj, known_extensions[i]);
129 if (!err)
130 gpu->extensions[gpu->extension_count++] = known_extensions[i];
131 }
132}
133
134void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj)
135{
136 XGL_SIZE size;
137 XGL_RESULT err;
138 int i;
139
140 memset(gpu, 0, sizeof(*gpu));
141
142 gpu->id = id;
143 gpu->obj = obj;
144
145 err = xglGetGpuInfo(gpu->obj,
146 XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES,
147 &size, &gpu->props);
148 if (err || size != sizeof(gpu->props))
149 ERR_EXIT(err);
150
151 err = xglGetGpuInfo(gpu->obj,
152 XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE,
153 &size, &gpu->perf);
154 if (err || size != sizeof(gpu->perf))
155 ERR_EXIT(err);
156
157 /* get queue count */
158 err = xglGetGpuInfo(gpu->obj,
159 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
160 &size, NULL);
161 if (err || size % sizeof(gpu->queue_props[0]))
162 ERR_EXIT(err);
163 gpu->queue_count = size / sizeof(gpu->queue_props[0]);
164
165 gpu->queue_props =
166 malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
167 if (!gpu->queue_props)
168 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
169 err = xglGetGpuInfo(gpu->obj,
170 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
171 &size, gpu->queue_props);
172 if (err || size != sizeof(gpu->queue_props[0]) * gpu->queue_count)
173 ERR_EXIT(err);
174
175 err = xglGetGpuInfo(gpu->obj,
176 XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES,
177 &size, &gpu->memory_props);
178 if (err || size != sizeof(gpu->memory_props))
179 ERR_EXIT(err);
180
181 app_gpu_init_extensions(gpu);
182 app_dev_init(&gpu->dev, gpu);
183 app_dev_init_formats(&gpu->dev);
184}
185
186void app_gpu_destroy(struct app_gpu *gpu)
187{
188 app_dev_destroy(&gpu->dev);
189 free(gpu->extensions);
190}
191