blob: 67b5beecb7891c999b09250f75006a1b3ef80a0f [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
Courtney Goeltzenleuchterd183e712014-08-06 16:12:02 -060071 /* request all queues */
72 info.queueRecordCount = gpu->queue_count;
73 info.pRequestedQueues = gpu->queue_reqs;
Courtney Goeltzenleuchterb202efc2014-08-06 16:11:26 -060074
75 /* enable all extensions */
76 info.extensionCount = gpu->extension_count;
77 info.ppEnabledExtensionNames = gpu->extensions;
78
79 dev->gpu = gpu;
80 err = xglCreateDevice(gpu->obj, &info, &dev->obj);
81 if (err)
82 ERR_EXIT(err);
83
84 err = xglGetMemoryHeapCount(dev->obj, &dev->heap_count);
85 if (err)
86 ERR_EXIT(err);
87
88 dev->heap_props =
89 malloc(sizeof(dev->heap_props[0]) * dev->heap_count);
90 if (!dev->heap_props)
91 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
92
93 for (i = 0; i < dev->heap_count; i++) {
94 err = xglGetMemoryHeapInfo(dev->obj, i,
95 XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES,
96 &size, &dev->heap_props[i]);
97 if (err || size != sizeof(dev->heap_props[0]))
98 ERR_EXIT(err);
99 }
100}
101
102void app_dev_destroy(struct app_dev *dev)
103{
104 free(dev->heap_props);
105 xglDestroyDevice(dev->obj);
106}
107
108void app_gpu_init_extensions(struct app_gpu *gpu)
109{
110 XGL_RESULT err;
111 XGL_UINT i;
112
113 static const XGL_CHAR *known_extensions[] = {
114 (const XGL_CHAR *) "some_extension",
115 };
116
117 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
118 err = xglGetExtensionSupport(gpu->obj, known_extensions[i]);
119 if (!err)
120 gpu->extension_count++;
121 }
122
123 gpu->extensions =
124 malloc(sizeof(gpu->extensions[0]) * gpu->extension_count);
125 if (!gpu->extensions)
126 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
127
128 gpu->extension_count = 0;
129 for (i = 0; i < ARRAY_SIZE(known_extensions); i++) {
130 err = xglGetExtensionSupport(gpu->obj, known_extensions[i]);
131 if (!err)
132 gpu->extensions[gpu->extension_count++] = known_extensions[i];
133 }
134}
135
136void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj)
137{
138 XGL_SIZE size;
139 XGL_RESULT err;
140 int i;
141
142 memset(gpu, 0, sizeof(*gpu));
143
144 gpu->id = id;
145 gpu->obj = obj;
146
147 err = xglGetGpuInfo(gpu->obj,
148 XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES,
149 &size, &gpu->props);
150 if (err || size != sizeof(gpu->props))
151 ERR_EXIT(err);
152
153 err = xglGetGpuInfo(gpu->obj,
154 XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE,
155 &size, &gpu->perf);
156 if (err || size != sizeof(gpu->perf))
157 ERR_EXIT(err);
158
159 /* get queue count */
160 err = xglGetGpuInfo(gpu->obj,
161 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
162 &size, NULL);
163 if (err || size % sizeof(gpu->queue_props[0]))
164 ERR_EXIT(err);
165 gpu->queue_count = size / sizeof(gpu->queue_props[0]);
166
167 gpu->queue_props =
168 malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
169 if (!gpu->queue_props)
170 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
171 err = xglGetGpuInfo(gpu->obj,
172 XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES,
173 &size, gpu->queue_props);
174 if (err || size != sizeof(gpu->queue_props[0]) * gpu->queue_count)
175 ERR_EXIT(err);
176
Courtney Goeltzenleuchterd183e712014-08-06 16:12:02 -0600177 /* set up queue requests */
178 gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count);
179 if (!gpu->queue_reqs)
180 ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY);
181 for (i = 0; i < gpu->queue_count; i++) {
182 gpu->queue_reqs[i].queueNodeIndex = i;
183 gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount;
184 }
185
Courtney Goeltzenleuchterb202efc2014-08-06 16:11:26 -0600186 err = xglGetGpuInfo(gpu->obj,
187 XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES,
188 &size, &gpu->memory_props);
189 if (err || size != sizeof(gpu->memory_props))
190 ERR_EXIT(err);
191
192 app_gpu_init_extensions(gpu);
193 app_dev_init(&gpu->dev, gpu);
194 app_dev_init_formats(&gpu->dev);
195}
196
197void app_gpu_destroy(struct app_gpu *gpu)
198{
199 app_dev_destroy(&gpu->dev);
200 free(gpu->extensions);
Courtney Goeltzenleuchterd183e712014-08-06 16:12:02 -0600201 free(gpu->queue_reqs);
202 free(gpu->queue_props);
Courtney Goeltzenleuchterb202efc2014-08-06 16:11:26 -0600203}
204