Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <string.h> |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 28 | #include <assert.h> |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 29 | |
| 30 | #include <xgl.h> |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 31 | |
| 32 | #define ERR(err) printf("%s:%d: failed with %s\n", \ |
| 33 | __FILE__, __LINE__, xgl_result_string(err)); |
| 34 | |
| 35 | #define ERR_EXIT(err) do { ERR(err); exit(-1); } while (0) |
| 36 | |
| 37 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 38 | |
| 39 | #define MAX_GPUS 8 |
| 40 | |
| 41 | #define MAX_QUEUE_TYPES 5 |
| 42 | |
| 43 | struct app_gpu; |
| 44 | |
| 45 | struct app_dev { |
| 46 | struct app_gpu *gpu; /* point back to the GPU */ |
| 47 | |
| 48 | XGL_DEVICE obj; |
| 49 | |
| 50 | XGL_UINT heap_count; |
| 51 | XGL_MEMORY_HEAP_PROPERTIES *heap_props; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 52 | |
| 53 | XGL_FORMAT_PROPERTIES format_props[XGL_MAX_CH_FMT][XGL_MAX_NUM_FMT]; |
| 54 | }; |
| 55 | |
| 56 | struct app_gpu { |
| 57 | XGL_UINT id; |
| 58 | XGL_PHYSICAL_GPU obj; |
| 59 | |
| 60 | XGL_PHYSICAL_GPU_PROPERTIES props; |
| 61 | XGL_PHYSICAL_GPU_PERFORMANCE perf; |
| 62 | |
| 63 | XGL_UINT queue_count; |
| 64 | XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *queue_props; |
| 65 | XGL_DEVICE_QUEUE_CREATE_INFO *queue_reqs; |
| 66 | |
| 67 | XGL_PHYSICAL_GPU_MEMORY_PROPERTIES memory_props; |
| 68 | |
| 69 | XGL_UINT extension_count; |
| 70 | const XGL_CHAR **extensions; |
| 71 | |
| 72 | struct app_dev dev; |
| 73 | }; |
| 74 | |
| 75 | static const char *xgl_result_string(XGL_RESULT err) |
| 76 | { |
| 77 | switch (err) { |
| 78 | #define STR(r) case r: return #r |
| 79 | STR(XGL_SUCCESS); |
| 80 | STR(XGL_UNSUPPORTED); |
| 81 | STR(XGL_NOT_READY); |
| 82 | STR(XGL_TIMEOUT); |
| 83 | STR(XGL_EVENT_SET); |
| 84 | STR(XGL_EVENT_RESET); |
| 85 | STR(XGL_ERROR_UNKNOWN); |
| 86 | STR(XGL_ERROR_UNAVAILABLE); |
| 87 | STR(XGL_ERROR_INITIALIZATION_FAILED); |
| 88 | STR(XGL_ERROR_OUT_OF_MEMORY); |
| 89 | STR(XGL_ERROR_OUT_OF_GPU_MEMORY); |
| 90 | STR(XGL_ERROR_DEVICE_ALREADY_CREATED); |
| 91 | STR(XGL_ERROR_DEVICE_LOST); |
| 92 | STR(XGL_ERROR_INVALID_POINTER); |
| 93 | STR(XGL_ERROR_INVALID_VALUE); |
| 94 | STR(XGL_ERROR_INVALID_HANDLE); |
| 95 | STR(XGL_ERROR_INVALID_ORDINAL); |
| 96 | STR(XGL_ERROR_INVALID_MEMORY_SIZE); |
| 97 | STR(XGL_ERROR_INVALID_EXTENSION); |
| 98 | STR(XGL_ERROR_INVALID_FLAGS); |
| 99 | STR(XGL_ERROR_INVALID_ALIGNMENT); |
| 100 | STR(XGL_ERROR_INVALID_FORMAT); |
| 101 | STR(XGL_ERROR_INVALID_IMAGE); |
| 102 | STR(XGL_ERROR_INVALID_DESCRIPTOR_SET_DATA); |
| 103 | STR(XGL_ERROR_INVALID_QUEUE_TYPE); |
| 104 | STR(XGL_ERROR_INVALID_OBJECT_TYPE); |
| 105 | STR(XGL_ERROR_UNSUPPORTED_SHADER_IL_VERSION); |
| 106 | STR(XGL_ERROR_BAD_SHADER_CODE); |
| 107 | STR(XGL_ERROR_BAD_PIPELINE_DATA); |
| 108 | STR(XGL_ERROR_TOO_MANY_MEMORY_REFERENCES); |
| 109 | STR(XGL_ERROR_NOT_MAPPABLE); |
| 110 | STR(XGL_ERROR_MEMORY_MAP_FAILED); |
| 111 | STR(XGL_ERROR_MEMORY_UNMAP_FAILED); |
| 112 | STR(XGL_ERROR_INCOMPATIBLE_DEVICE); |
| 113 | STR(XGL_ERROR_INCOMPATIBLE_DRIVER); |
| 114 | STR(XGL_ERROR_INCOMPLETE_COMMAND_BUFFER); |
| 115 | STR(XGL_ERROR_BUILDING_COMMAND_BUFFER); |
| 116 | STR(XGL_ERROR_MEMORY_NOT_BOUND); |
| 117 | STR(XGL_ERROR_INCOMPATIBLE_QUEUE); |
| 118 | STR(XGL_ERROR_NOT_SHAREABLE); |
| 119 | #undef STR |
| 120 | default: return "UNKNOWN_RESULT"; |
| 121 | } |
| 122 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 123 | |
| 124 | static const char *xgl_gpu_type_string(XGL_PHYSICAL_GPU_TYPE type) |
| 125 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 126 | switch (type) { |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 127 | #define STR(r) case XGL_GPU_TYPE_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 128 | STR(OTHER); |
| 129 | STR(INTEGRATED); |
| 130 | STR(DISCRETE); |
| 131 | STR(VIRTUAL); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 132 | #undef STR |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 133 | default: return "UNKNOWN_GPU"; |
| 134 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static const char *xgl_heap_type_string(XGL_HEAP_MEMORY_TYPE type) |
| 138 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 139 | switch (type) { |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 140 | #define STR(r) case XGL_HEAP_MEMORY_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 141 | STR(OTHER); |
| 142 | STR(LOCAL); |
| 143 | STR(REMOTE); |
| 144 | STR(EMBEDDED); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 145 | #undef STR |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 146 | default: return "UNKNOWN_HEAP"; |
| 147 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static const char *xgl_channel_format_string(XGL_CHANNEL_FORMAT ch) |
| 151 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 152 | switch (ch) { |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 153 | #define STR(r) case XGL_CH_FMT_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 154 | STR(UNDEFINED); |
| 155 | STR(R4G4); |
| 156 | STR(R4G4B4A4); |
| 157 | STR(R5G6B5); |
| 158 | STR(B5G6R5); |
| 159 | STR(R5G5B5A1); |
| 160 | STR(R8); |
| 161 | STR(R8G8); |
| 162 | STR(R8G8B8A8); |
| 163 | STR(B8G8R8A8); |
| 164 | STR(R10G11B11); |
| 165 | STR(R11G11B10); |
| 166 | STR(R10G10B10A2); |
| 167 | STR(R16); |
| 168 | STR(R16G16); |
| 169 | STR(R16G16B16A16); |
| 170 | STR(R32); |
| 171 | STR(R32G32); |
| 172 | STR(R32G32B32); |
| 173 | STR(R32G32B32A32); |
| 174 | STR(R16G8); |
| 175 | STR(R32G8); |
| 176 | STR(R9G9B9E5); |
| 177 | STR(BC1); |
| 178 | STR(BC2); |
| 179 | STR(BC3); |
| 180 | STR(BC4); |
| 181 | STR(BC5); |
| 182 | STR(BC6U); |
| 183 | STR(BC6S); |
| 184 | STR(BC7); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 185 | #undef STR |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 186 | default: return "UNKNOWN_CH"; |
| 187 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static const char *xgl_numeric_format_string(XGL_NUM_FORMAT num) |
| 191 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 192 | switch (num) { |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 193 | #define STR(r) case XGL_NUM_FMT_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 194 | STR(UNDEFINED); |
| 195 | STR(UNORM); |
| 196 | STR(SNORM); |
| 197 | STR(UINT); |
| 198 | STR(SINT); |
| 199 | STR(FLOAT); |
| 200 | STR(SRGB); |
| 201 | STR(DS); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 202 | #undef STR |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 203 | default: return "UNKNOWN_NUM"; |
| 204 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 207 | static void app_dev_init_formats(struct app_dev *dev) |
| 208 | { |
| 209 | XGL_CHANNEL_FORMAT ch; |
| 210 | XGL_NUM_FORMAT num; |
| 211 | |
| 212 | for (ch = 0; ch < XGL_MAX_CH_FMT; ch++) { |
| 213 | for (num = 0; num < XGL_MAX_NUM_FMT; num++) { |
| 214 | const XGL_FORMAT fmt = { |
| 215 | .channelFormat = ch, |
| 216 | .numericFormat = num, |
| 217 | }; |
| 218 | XGL_RESULT err; |
| 219 | XGL_SIZE size = sizeof(dev->format_props[ch][num]); |
| 220 | |
| 221 | err = xglGetFormatInfo(dev->obj, fmt, |
| 222 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 223 | &size, &dev->format_props[ch][num]); |
| 224 | if (err) { |
| 225 | memset(&dev->format_props[ch][num], 0, |
| 226 | sizeof(dev->format_props[ch][num])); |
| 227 | } |
| 228 | else if (size != sizeof(dev->format_props[ch][num])) { |
| 229 | ERR_EXIT(XGL_ERROR_UNKNOWN); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu) |
| 236 | { |
| 237 | XGL_DEVICE_CREATE_INFO info = { |
| 238 | .sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO, |
| 239 | .pNext = NULL, |
| 240 | .queueRecordCount = 0, |
| 241 | .pRequestedQueues = NULL, |
| 242 | .extensionCount = 0, |
| 243 | .ppEnabledExtensionNames = NULL, |
| 244 | .maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE, |
| 245 | .flags = XGL_DEVICE_CREATE_VALIDATION_BIT, |
| 246 | }; |
| 247 | XGL_RESULT err; |
| 248 | XGL_SIZE size; |
| 249 | XGL_UINT i; |
| 250 | |
| 251 | /* request all queues */ |
| 252 | info.queueRecordCount = gpu->queue_count; |
| 253 | info.pRequestedQueues = gpu->queue_reqs; |
| 254 | |
| 255 | /* enable all extensions */ |
| 256 | info.extensionCount = gpu->extension_count; |
| 257 | info.ppEnabledExtensionNames = gpu->extensions; |
| 258 | dev->gpu = gpu; |
| 259 | err = xglCreateDevice(gpu->obj, &info, &dev->obj); |
| 260 | if (err) |
| 261 | ERR_EXIT(err); |
| 262 | |
| 263 | err = xglGetMemoryHeapCount(dev->obj, &dev->heap_count); |
| 264 | if (err) |
| 265 | ERR_EXIT(err); |
| 266 | |
| 267 | dev->heap_props = |
| 268 | malloc(sizeof(dev->heap_props[0]) * dev->heap_count); |
| 269 | if (!dev->heap_props) |
| 270 | ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY); |
| 271 | |
| 272 | for (i = 0; i < dev->heap_count; i++) { |
| 273 | size = sizeof(dev->heap_props[0]); |
| 274 | err = xglGetMemoryHeapInfo(dev->obj, i, |
| 275 | XGL_INFO_TYPE_MEMORY_HEAP_PROPERTIES, |
| 276 | &size, &dev->heap_props[i]); |
| 277 | if (err || size != sizeof(dev->heap_props[0])) |
| 278 | ERR_EXIT(err); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | static void app_dev_destroy(struct app_dev *dev) |
| 283 | { |
| 284 | free(dev->heap_props); |
| 285 | xglDestroyDevice(dev->obj); |
| 286 | } |
| 287 | |
| 288 | static void app_gpu_init_extensions(struct app_gpu *gpu) |
| 289 | { |
| 290 | XGL_RESULT err; |
| 291 | XGL_UINT i; |
| 292 | |
| 293 | static const XGL_CHAR *known_extensions[] = { |
| 294 | (const XGL_CHAR *) "XGL_WSI_X11", |
| 295 | }; |
| 296 | |
| 297 | for (i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
| 298 | err = xglGetExtensionSupport(gpu->obj, known_extensions[i]); |
| 299 | if (!err) |
| 300 | gpu->extension_count++; |
| 301 | } |
| 302 | |
| 303 | gpu->extensions = |
| 304 | malloc(sizeof(gpu->extensions[0]) * gpu->extension_count); |
| 305 | if (!gpu->extensions) |
| 306 | ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY); |
| 307 | |
| 308 | gpu->extension_count = 0; |
| 309 | for (i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
| 310 | err = xglGetExtensionSupport(gpu->obj, known_extensions[i]); |
| 311 | if (!err) |
| 312 | gpu->extensions[gpu->extension_count++] = known_extensions[i]; |
| 313 | } |
| 314 | } |
| 315 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 316 | static void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj) |
| 317 | { |
| 318 | XGL_SIZE size; |
| 319 | XGL_RESULT err; |
| 320 | int i; |
| 321 | |
| 322 | memset(gpu, 0, sizeof(*gpu)); |
| 323 | |
| 324 | gpu->id = id; |
| 325 | gpu->obj = obj; |
| 326 | size = sizeof(gpu->props); |
| 327 | err = xglGetGpuInfo(gpu->obj, |
| 328 | XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, |
| 329 | &size, &gpu->props); |
| 330 | if (err || size != sizeof(gpu->props)) |
| 331 | ERR_EXIT(err); |
| 332 | |
| 333 | size = sizeof(gpu->perf); |
| 334 | err = xglGetGpuInfo(gpu->obj, |
| 335 | XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE, |
| 336 | &size, &gpu->perf); |
| 337 | if (err || size != sizeof(gpu->perf)) |
| 338 | ERR_EXIT(err); |
| 339 | |
| 340 | /* get queue count */ |
| 341 | err = xglGetGpuInfo(gpu->obj, |
| 342 | XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, |
| 343 | &size, NULL); |
| 344 | if (err || size % sizeof(gpu->queue_props[0])) |
| 345 | ERR_EXIT(err); |
| 346 | gpu->queue_count = size / sizeof(gpu->queue_props[0]); |
| 347 | |
| 348 | gpu->queue_props = |
| 349 | malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count); |
| 350 | size = sizeof(gpu->queue_props[0]) * gpu->queue_count; |
| 351 | if (!gpu->queue_props) |
| 352 | ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY); |
| 353 | err = xglGetGpuInfo(gpu->obj, |
| 354 | XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, |
| 355 | &size, gpu->queue_props); |
| 356 | if (err || size != sizeof(gpu->queue_props[0]) * gpu->queue_count) |
| 357 | ERR_EXIT(err); |
| 358 | |
| 359 | /* set up queue requests */ |
| 360 | size = sizeof(*gpu->queue_reqs) * gpu->queue_count; |
| 361 | gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count); |
| 362 | if (!gpu->queue_reqs) |
| 363 | ERR_EXIT(XGL_ERROR_OUT_OF_MEMORY); |
| 364 | for (i = 0; i < gpu->queue_count; i++) { |
| 365 | gpu->queue_reqs[i].queueNodeIndex = i; |
| 366 | gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount; |
| 367 | } |
| 368 | |
| 369 | size = sizeof(gpu->memory_props); |
| 370 | err = xglGetGpuInfo(gpu->obj, |
| 371 | XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES, |
| 372 | &size, &gpu->memory_props); |
| 373 | if (err || size != sizeof(gpu->memory_props)) |
| 374 | ERR_EXIT(err); |
| 375 | |
| 376 | app_gpu_init_extensions(gpu); |
| 377 | app_dev_init(&gpu->dev, gpu); |
| 378 | app_dev_init_formats(&gpu->dev); |
| 379 | } |
| 380 | |
| 381 | static void app_gpu_destroy(struct app_gpu *gpu) |
| 382 | { |
| 383 | app_dev_destroy(&gpu->dev); |
| 384 | free(gpu->extensions); |
| 385 | free(gpu->queue_reqs); |
| 386 | free(gpu->queue_props); |
| 387 | } |
| 388 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 389 | static void app_dev_dump_format_props(const struct app_dev *dev, XGL_CHANNEL_FORMAT ch, XGL_NUM_FORMAT num) |
| 390 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 391 | const XGL_FORMAT_PROPERTIES *props = &dev->format_props[ch][num]; |
| 392 | struct { |
| 393 | const char *name; |
| 394 | XGL_FLAGS flags; |
| 395 | } tilings[2]; |
| 396 | XGL_UINT i; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 397 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 398 | if (!props->linearTilingFeatures && !props->optimalTilingFeatures) |
| 399 | return; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 400 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 401 | tilings[0].name = "linear"; |
| 402 | tilings[0].flags = props->linearTilingFeatures; |
| 403 | tilings[1].name = "optimal"; |
| 404 | tilings[1].flags = props->optimalTilingFeatures; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 405 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 406 | printf("FORMAT_%s_%s\n", xgl_channel_format_string(ch), |
| 407 | xgl_numeric_format_string(num)); |
| 408 | for (i = 0; i < ARRAY_SIZE(tilings); i++) { |
| 409 | if (!tilings[i].flags) |
| 410 | continue; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 411 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 412 | printf("\t%s tiling image =%s%s%s\n", tilings[i].name, |
| 413 | (tilings[i].flags & XGL_FORMAT_IMAGE_SHADER_READ_BIT) ? " read" : "", |
| 414 | (tilings[i].flags & XGL_FORMAT_IMAGE_SHADER_WRITE_BIT) ? " write" : "", |
| 415 | (tilings[i].flags & XGL_FORMAT_IMAGE_COPY_BIT) ? " copy" : ""); |
| 416 | printf("\t%s tiling memory =%s\n", tilings[i].name, |
| 417 | (tilings[i].flags & XGL_FORMAT_MEMORY_SHADER_ACCESS_BIT) ? " access" : ""); |
| 418 | printf("\t%s tiling attachment =%s%s%s%s%s\n", tilings[i].name, |
| 419 | (tilings[i].flags & XGL_FORMAT_COLOR_ATTACHMENT_WRITE_BIT) ? " color" : "", |
| 420 | (tilings[i].flags & XGL_FORMAT_COLOR_ATTACHMENT_BLEND_BIT) ? " blend" : "", |
| 421 | (tilings[i].flags & XGL_FORMAT_DEPTH_ATTACHMENT_BIT) ? " depth" : "", |
| 422 | (tilings[i].flags & XGL_FORMAT_STENCIL_ATTACHMENT_BIT) ? " stencil" : "", |
| 423 | (tilings[i].flags & XGL_FORMAT_MSAA_ATTACHMENT_BIT) ? " msaa" : ""); |
| 424 | printf("\t%s tiling conversion = %u\n", tilings[i].name, |
| 425 | (bool) (tilings[i].flags & XGL_FORMAT_CONVERSION_BIT)); |
| 426 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static void app_dev_dump_heap_props(const struct app_dev *dev, XGL_UINT id) |
| 430 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 431 | const XGL_MEMORY_HEAP_PROPERTIES *props = &dev->heap_props[id]; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 432 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 433 | printf("XGL_MEMORY_HEAP_PROPERTIES[%u]\n", id); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame^] | 434 | printf("\tstructSize = %zu\n", props->structSize); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 435 | printf("\theapMemoryType = %s\n", xgl_heap_type_string(props->heapMemoryType)); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame^] | 436 | printf("\theapSize = %zu\n", props->heapSize); |
| 437 | printf("\tpagesSize = %zu\n", props->pageSize); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 438 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 439 | printf("\tflags =%s%s%s%s%s%s\n", |
| 440 | (props->flags & XGL_MEMORY_HEAP_CPU_VISIBLE_BIT) ? " visible" : "", |
| 441 | (props->flags & XGL_MEMORY_HEAP_CPU_GPU_COHERENT_BIT) ? " coherent" : "", |
| 442 | (props->flags & XGL_MEMORY_HEAP_CPU_UNCACHED_BIT) ? " uc" : "", |
| 443 | (props->flags & XGL_MEMORY_HEAP_CPU_WRITE_COMBINED_BIT) ? " wc" : "", |
| 444 | (props->flags & XGL_MEMORY_HEAP_HOLDS_PINNED_BIT) ? " pinnable" : "", |
| 445 | (props->flags & XGL_MEMORY_HEAP_SHAREABLE_BIT) ? " shareable" : ""); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 446 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 447 | printf("\tgpuReadPerfRating = %f\n", props->gpuReadPerfRating); |
| 448 | printf("\tgpuWritePerfRating = %f\n", props->gpuWritePerfRating); |
| 449 | printf("\tcpuReadPerfRating = %f\n", props->cpuReadPerfRating); |
| 450 | printf("\tcpuWritePerfRating = %f\n", props->cpuWritePerfRating); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void |
| 454 | app_dev_dump(const struct app_dev *dev) |
| 455 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 456 | XGL_CHANNEL_FORMAT ch; |
| 457 | XGL_NUM_FORMAT num; |
| 458 | XGL_UINT i; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 459 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 460 | for (i = 0; i < dev->heap_count; i++) { |
| 461 | app_dev_dump_heap_props(dev, i); |
| 462 | printf("\n"); |
| 463 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 464 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 465 | for (ch = 0; ch < XGL_MAX_CH_FMT; ch++) { |
| 466 | for (num = 0; num < XGL_MAX_NUM_FMT; num++) |
| 467 | app_dev_dump_format_props(dev, ch, num); |
| 468 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | static void app_gpu_dump_multi_compat(const struct app_gpu *gpu, const struct app_gpu *other, |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 472 | const XGL_GPU_COMPATIBILITY_INFO *info) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 473 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 474 | printf("XGL_GPU_COMPATIBILITY_INFO[GPU%d]\n", other->id); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 475 | |
| 476 | #define TEST(info, b) printf(#b " = %u\n", (bool) (info->compatibilityFlags & XGL_GPU_COMPAT_ ##b## _BIT)) |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 477 | TEST(info, ASIC_FEATURES); |
| 478 | TEST(info, IQ_MATCH); |
| 479 | TEST(info, PEER_TRANSFER); |
| 480 | TEST(info, SHARED_MEMORY); |
| 481 | TEST(info, SHARED_SYNC); |
| 482 | TEST(info, SHARED_GPU0_DISPLAY); |
| 483 | TEST(info, SHARED_GPU1_DISPLAY); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 484 | #undef TEST |
| 485 | } |
| 486 | |
Courtney Goeltzenleuchter | d183e71 | 2014-08-06 16:12:02 -0600 | [diff] [blame] | 487 | static void app_gpu_multi_compat(struct app_gpu *gpus, XGL_UINT gpu_count) |
| 488 | { |
| 489 | XGL_RESULT err; |
| 490 | XGL_UINT i, j; |
| 491 | |
| 492 | for (i = 0; i < gpu_count; i++) { |
| 493 | for (j = 0; j < gpu_count; j++) { |
| 494 | XGL_GPU_COMPATIBILITY_INFO info; |
| 495 | |
| 496 | if (i == j) |
| 497 | continue; |
| 498 | |
| 499 | err = xglGetMultiGpuCompatibility(gpus[i].obj, |
| 500 | gpus[j].obj, &info); |
| 501 | if (err) |
| 502 | ERR_EXIT(err); |
| 503 | |
| 504 | app_gpu_dump_multi_compat(&gpus[i], &gpus[j], &info); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 509 | static void app_gpu_dump_props(const struct app_gpu *gpu) |
| 510 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 511 | const XGL_PHYSICAL_GPU_PROPERTIES *props = &gpu->props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 512 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 513 | printf("XGL_PHYSICAL_GPU_PROPERTIES\n"); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame^] | 514 | printf("\tstructSize = %zu\n", props->structSize); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 515 | printf("\tapiVersion = %u\n", props->apiVersion); |
| 516 | printf("\tdriverVersion = %u\n", props->driverVersion); |
| 517 | printf("\tvendorId = 0x%04x\n", props->vendorId); |
| 518 | printf("\tdeviceId = 0x%04x\n", props->deviceId); |
| 519 | printf("\tgpuType = %s\n", xgl_gpu_type_string(props->gpuType)); |
| 520 | printf("\tgpuName = %s\n", props->gpuName); |
| 521 | printf("\tmaxMemRefsPerSubmission = %u\n", props->maxMemRefsPerSubmission); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame^] | 522 | printf("\tvirtualMemPageSize = %zu\n", props->virtualMemPageSize); |
| 523 | printf("\tmaxInlineMemoryUpdateSize = %zu\n", props->maxInlineMemoryUpdateSize); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 524 | printf("\tmaxBoundDescriptorSets = %u\n", props->maxBoundDescriptorSets); |
| 525 | printf("\tmaxThreadGroupSize = %u\n", props->maxThreadGroupSize); |
| 526 | printf("\ttimestampFrequency = %lu\n", props->timestampFrequency); |
| 527 | printf("\tmultiColorAttachmentClears = %u\n", props->multiColorAttachmentClears); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static void app_gpu_dump_perf(const struct app_gpu *gpu) |
| 531 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 532 | const XGL_PHYSICAL_GPU_PERFORMANCE *perf = &gpu->perf; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 533 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 534 | printf("XGL_PHYSICAL_GPU_PERFORMANCE\n"); |
| 535 | printf("\tmaxGpuClock = %f\n", perf->maxGpuClock); |
| 536 | printf("\taluPerClock = %f\n", perf->aluPerClock); |
| 537 | printf("\ttexPerClock = %f\n", perf->texPerClock); |
| 538 | printf("\tprimsPerClock = %f\n", perf->primsPerClock); |
| 539 | printf("\tpixelsPerClock = %f\n", perf->pixelsPerClock); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 540 | } |
| 541 | |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 542 | static void app_gpu_dump_extensions(const struct app_gpu *gpu) |
| 543 | { |
| 544 | int i; |
| 545 | printf("Extensions"); |
| 546 | printf("\tcount = %d\n", gpu->extension_count); |
| 547 | printf("\t"); |
| 548 | for (i=0; i< gpu->extension_count; i++) { |
| 549 | if (i>0) |
| 550 | printf(", "); // separator between extension names |
| 551 | printf("%s", gpu->extensions[i]); |
| 552 | } |
| 553 | printf("\n"); |
| 554 | } |
| 555 | |
Chia-I Wu | f5c46f4 | 2014-08-05 15:33:40 +0800 | [diff] [blame] | 556 | static void app_gpu_dump_queue_props(const struct app_gpu *gpu, XGL_UINT id) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 557 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 558 | const XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *props = &gpu->queue_props[id]; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 559 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 560 | printf("XGL_PHYSICAL_GPU_QUEUE_PROPERTIES[%d]\n", id); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame^] | 561 | printf("\tstructSize = %zu\n", props->structSize); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 562 | printf("\tqueueFlags = %c%c%c%c\n", |
| 563 | (props->queueFlags & XGL_QUEUE_GRAPHICS_BIT) ? 'G' : '.', |
| 564 | (props->queueFlags & XGL_QUEUE_COMPUTE_BIT) ? 'C' : '.', |
| 565 | (props->queueFlags & XGL_QUEUE_DMA_BIT) ? 'D' : '.', |
| 566 | (props->queueFlags & XGL_QUEUE_EXTENDED_BIT) ? 'X' : '.'); |
| 567 | printf("\tqueueCount = %u\n", props->queueCount); |
| 568 | printf("\tmaxAtomicCounters = %u\n", props->maxAtomicCounters); |
| 569 | printf("\tsupportsTimestamps = %u\n", props->supportsTimestamps); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void app_gpu_dump_memory_props(const struct app_gpu *gpu) |
| 573 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 574 | const XGL_PHYSICAL_GPU_MEMORY_PROPERTIES *props = &gpu->memory_props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 575 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 576 | printf("XGL_PHYSICAL_GPU_MEMORY_PROPERTIES\n"); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame^] | 577 | printf("\tstructSize = %zu\n", props->structSize); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 578 | printf("\tsupportsMigration = %u\n", props->supportsMigration); |
| 579 | printf("\tsupportsVirtualMemoryRemapping = %u\n", props->supportsVirtualMemoryRemapping); |
| 580 | printf("\tsupportsPinning = %u\n", props->supportsPinning); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static void app_gpu_dump(const struct app_gpu *gpu) |
| 584 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 585 | XGL_UINT i; |
Chia-I Wu | f5c46f4 | 2014-08-05 15:33:40 +0800 | [diff] [blame] | 586 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 587 | printf("GPU%u\n", gpu->id); |
| 588 | app_gpu_dump_props(gpu); |
| 589 | printf("\n"); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 590 | app_gpu_dump_extensions(gpu); |
| 591 | printf("\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 592 | app_gpu_dump_perf(gpu); |
| 593 | printf("\n"); |
| 594 | for (i = 0; i < gpu->queue_count; i++) { |
| 595 | app_gpu_dump_queue_props(gpu, i); |
| 596 | printf("\n"); |
| 597 | } |
| 598 | app_gpu_dump_memory_props(gpu); |
| 599 | printf("\n"); |
| 600 | app_dev_dump(&gpu->dev); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 601 | } |
| 602 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 603 | int main(int argc, char **argv) |
| 604 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 605 | static const XGL_APPLICATION_INFO app_info = { |
| 606 | .sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO, |
| 607 | .pNext = NULL, |
| 608 | .pAppName = (const XGL_CHAR *) "xglinfo", |
| 609 | .appVersion = 1, |
| 610 | .pEngineName = (const XGL_CHAR *) "xglinfo", |
| 611 | .engineVersion = 1, |
| 612 | .apiVersion = XGL_MAKE_VERSION(0, 22, 0), |
| 613 | }; |
| 614 | struct app_gpu gpus[MAX_GPUS]; |
| 615 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 616 | XGL_UINT gpu_count, i; |
| 617 | XGL_RESULT err; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 618 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 619 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 620 | MAX_GPUS, &gpu_count, objs); |
| 621 | if (err) |
| 622 | ERR_EXIT(err); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 623 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 624 | for (i = 0; i < gpu_count; i++) { |
| 625 | app_gpu_init(&gpus[i], i, objs[i]); |
| 626 | app_gpu_dump(&gpus[i]); |
| 627 | printf("\n\n"); |
| 628 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 629 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 630 | app_gpu_multi_compat(gpus, gpu_count); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 631 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 632 | for (i = 0; i < gpu_count; i++) |
| 633 | app_gpu_destroy(&gpus[i]); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 634 | |
Chia-I Wu | 0b9a737 | 2014-08-06 12:09:19 +0800 | [diff] [blame] | 635 | xglInitAndEnumerateGpus(&app_info, NULL, 0, &gpu_count, NULL); |
| 636 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 637 | return 0; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 638 | } |