Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [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 | */ |
| 24 | |
| 25 | #ifndef COMMON_H |
| 26 | #define COMMON_H |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> |
| 30 | #include <stdbool.h> |
| 31 | #include <string.h> |
Courtney Goeltzenleuchter | 0a787c6 | 2014-08-07 15:07:34 -0600 | [diff] [blame] | 32 | #include <assert.h> |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 33 | |
| 34 | #include <xgl.h> |
| 35 | |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 36 | #define ASSERT_XGL_SUCCESS(err) ASSERT_EQ(XGL_SUCCESS, err) << xgl_result_string(err) |
| 37 | |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 38 | #ifdef __cplusplus |
| 39 | extern "C" |
| 40 | { |
| 41 | #endif // __cplusplus |
| 42 | |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 43 | #define ERR(err) printf("%s:%d: failed with %s\n", \ |
| 44 | __FILE__, __LINE__, xgl_result_string(err)); |
| 45 | |
| 46 | #define ERR_EXIT(err) do { ERR(err); exit(-1); } while (0) |
| 47 | |
| 48 | #define ERR_MSG(msg) printf("%s:%d: failed with %s\n", \ |
| 49 | __FILE__, __LINE__, msg); |
| 50 | |
| 51 | #define ERR_MSG_EXIT(err) do { ERR_MSG(err); exit(-1); } while (0) |
| 52 | |
| 53 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 54 | |
| 55 | #define MAX_GPUS 8 |
| 56 | |
Courtney Goeltzenleuchter | 0a787c6 | 2014-08-07 15:07:34 -0600 | [diff] [blame] | 57 | #define MAX_QUEUE_TYPES 5 |
| 58 | |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 59 | struct app_dev { |
| 60 | struct app_gpu *gpu; /* point back to the GPU */ |
| 61 | |
| 62 | XGL_DEVICE obj; |
| 63 | |
| 64 | XGL_UINT heap_count; |
| 65 | XGL_MEMORY_HEAP_PROPERTIES *heap_props; |
Courtney Goeltzenleuchter | 0a787c6 | 2014-08-07 15:07:34 -0600 | [diff] [blame] | 66 | XGL_QUEUE queues[MAX_QUEUE_TYPES]; |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 67 | |
| 68 | XGL_FORMAT_PROPERTIES format_props[XGL_MAX_CH_FMT][XGL_MAX_NUM_FMT]; |
| 69 | }; |
| 70 | |
| 71 | struct app_gpu { |
| 72 | XGL_UINT id; |
| 73 | XGL_PHYSICAL_GPU obj; |
| 74 | |
| 75 | XGL_PHYSICAL_GPU_PROPERTIES props; |
| 76 | XGL_PHYSICAL_GPU_PERFORMANCE perf; |
| 77 | |
| 78 | XGL_UINT queue_count; |
| 79 | XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *queue_props; |
Courtney Goeltzenleuchter | d183e71 | 2014-08-06 16:12:02 -0600 | [diff] [blame] | 80 | XGL_DEVICE_QUEUE_CREATE_INFO *queue_reqs; |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 81 | |
| 82 | XGL_PHYSICAL_GPU_MEMORY_PROPERTIES memory_props; |
| 83 | |
| 84 | XGL_UINT extension_count; |
| 85 | const XGL_CHAR **extensions; |
| 86 | |
| 87 | struct app_dev dev; |
| 88 | }; |
| 89 | |
| 90 | static const char *xgl_result_string(XGL_RESULT err) |
| 91 | { |
| 92 | switch (err) { |
| 93 | #define STR(r) case r: return #r |
| 94 | STR(XGL_SUCCESS); |
| 95 | STR(XGL_UNSUPPORTED); |
| 96 | STR(XGL_NOT_READY); |
| 97 | STR(XGL_TIMEOUT); |
| 98 | STR(XGL_EVENT_SET); |
| 99 | STR(XGL_EVENT_RESET); |
| 100 | STR(XGL_ERROR_UNKNOWN); |
| 101 | STR(XGL_ERROR_UNAVAILABLE); |
| 102 | STR(XGL_ERROR_INITIALIZATION_FAILED); |
| 103 | STR(XGL_ERROR_OUT_OF_MEMORY); |
| 104 | STR(XGL_ERROR_OUT_OF_GPU_MEMORY); |
| 105 | STR(XGL_ERROR_DEVICE_ALREADY_CREATED); |
| 106 | STR(XGL_ERROR_DEVICE_LOST); |
| 107 | STR(XGL_ERROR_INVALID_POINTER); |
| 108 | STR(XGL_ERROR_INVALID_VALUE); |
| 109 | STR(XGL_ERROR_INVALID_HANDLE); |
| 110 | STR(XGL_ERROR_INVALID_ORDINAL); |
| 111 | STR(XGL_ERROR_INVALID_MEMORY_SIZE); |
| 112 | STR(XGL_ERROR_INVALID_EXTENSION); |
| 113 | STR(XGL_ERROR_INVALID_FLAGS); |
| 114 | STR(XGL_ERROR_INVALID_ALIGNMENT); |
| 115 | STR(XGL_ERROR_INVALID_FORMAT); |
| 116 | STR(XGL_ERROR_INVALID_IMAGE); |
| 117 | STR(XGL_ERROR_INVALID_DESCRIPTOR_SET_DATA); |
| 118 | STR(XGL_ERROR_INVALID_QUEUE_TYPE); |
| 119 | STR(XGL_ERROR_INVALID_OBJECT_TYPE); |
| 120 | STR(XGL_ERROR_UNSUPPORTED_SHADER_IL_VERSION); |
| 121 | STR(XGL_ERROR_BAD_SHADER_CODE); |
| 122 | STR(XGL_ERROR_BAD_PIPELINE_DATA); |
| 123 | STR(XGL_ERROR_TOO_MANY_MEMORY_REFERENCES); |
| 124 | STR(XGL_ERROR_NOT_MAPPABLE); |
| 125 | STR(XGL_ERROR_MEMORY_MAP_FAILED); |
| 126 | STR(XGL_ERROR_MEMORY_UNMAP_FAILED); |
| 127 | STR(XGL_ERROR_INCOMPATIBLE_DEVICE); |
| 128 | STR(XGL_ERROR_INCOMPATIBLE_DRIVER); |
| 129 | STR(XGL_ERROR_INCOMPLETE_COMMAND_BUFFER); |
| 130 | STR(XGL_ERROR_BUILDING_COMMAND_BUFFER); |
| 131 | STR(XGL_ERROR_MEMORY_NOT_BOUND); |
| 132 | STR(XGL_ERROR_INCOMPATIBLE_QUEUE); |
| 133 | STR(XGL_ERROR_NOT_SHAREABLE); |
| 134 | #undef STR |
| 135 | default: return "UNKNOWN_RESULT"; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void app_dev_init_formats(struct app_dev *dev); |
| 140 | void app_dev_init(struct app_dev *dev, struct app_gpu *gpu); |
| 141 | void app_dev_destroy(struct app_dev *dev); |
| 142 | void app_gpu_init_extensions(struct app_gpu *gpu); |
| 143 | void app_gpu_init(struct app_gpu *gpu, XGL_UINT id, XGL_PHYSICAL_GPU obj); |
| 144 | void app_gpu_destroy(struct app_gpu *gpu); |
Courtney Goeltzenleuchter | 0a787c6 | 2014-08-07 15:07:34 -0600 | [diff] [blame] | 145 | void app_dev_init_queue(struct app_dev *dev, XGL_QUEUE_TYPE qtype); |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 146 | |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 147 | #ifdef __cplusplus |
| 148 | } // extern "C" |
| 149 | #endif // __cplusplus |
| 150 | |
Courtney Goeltzenleuchter | b202efc | 2014-08-06 16:11:26 -0600 | [diff] [blame] | 151 | #endif // COMMON_H |