Courtney Goeltzenleuchter | b8e71a8 | 2014-08-07 18:13:51 -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 | #include "common.h" |
| 26 | #include "debug.h" |
| 27 | |
| 28 | #define MAX_QUERY_SLOTS 10 |
| 29 | |
| 30 | int main(int argc, char **argv) |
| 31 | { |
| 32 | static const XGL_APPLICATION_INFO app_info = { |
| 33 | .sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO, |
| 34 | .pNext = NULL, |
| 35 | .pAppName = (const XGL_CHAR *) "xglQuery", |
| 36 | .appVersion = 1, |
| 37 | .pEngineName = (const XGL_CHAR *) "xglQuery", |
| 38 | .engineVersion = 1, |
| 39 | .apiVersion = XGL_MAKE_VERSION(0, 22, 0), |
| 40 | }; |
| 41 | struct app_gpu gpus[MAX_GPUS]; |
| 42 | struct app_gpu *gpu; |
| 43 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 44 | XGL_UINT gpu_count, i, gpu_idx; |
| 45 | XGL_QUERY_POOL_CREATE_INFO query_info; |
| 46 | XGL_QUERY_POOL query_pool; |
| 47 | XGL_UINT data_size; |
| 48 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 49 | XGL_UINT query_result_size; |
| 50 | XGL_UINT *query_result_data; |
| 51 | XGL_RESULT err; |
| 52 | |
| 53 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 54 | MAX_GPUS, &gpu_count, objs); |
| 55 | if (err) |
| 56 | ERR_EXIT(err); |
| 57 | |
| 58 | if (gpu_count <= 0) { |
| 59 | ERR_MSG_EXIT("No GPU avialable"); |
| 60 | } |
| 61 | |
| 62 | for (i = 0; i < gpu_count; i++) { |
| 63 | app_gpu_init(&gpus[i], i, objs[i]); |
| 64 | app_dev_init_queue(&gpus[i].dev, XGL_QUEUE_TYPE_GRAPHICS); |
| 65 | } |
| 66 | |
| 67 | for (gpu_idx = 0; gpu_idx < gpu_count; gpu_idx++) { |
| 68 | |
| 69 | gpu = &gpus[gpu_idx]; |
| 70 | |
| 71 | // typedef enum _XGL_QUERY_TYPE |
| 72 | // { |
| 73 | // XGL_QUERY_OCCLUSION = 0x00000000, |
| 74 | // XGL_QUERY_PIPELINE_STATISTICS = 0x00000001, |
| 75 | |
| 76 | // XGL_QUERY_TYPE_BEGIN_RANGE = XGL_QUERY_OCCLUSION, |
| 77 | // XGL_QUERY_TYPE_END_RANGE = XGL_QUERY_PIPELINE_STATISTICS, |
| 78 | // XGL_NUM_QUERY_TYPE = (XGL_QUERY_TYPE_END_RANGE - XGL_QUERY_TYPE_BEGIN_RANGE + 1), |
| 79 | // XGL_MAX_ENUM(_XGL_QUERY_TYPE) |
| 80 | // } XGL_QUERY_TYPE; |
| 81 | |
| 82 | // typedef struct _XGL_QUERY_POOL_CREATE_INFO |
| 83 | // { |
| 84 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO |
| 85 | // const XGL_VOID* pNext; // Pointer to next structure |
| 86 | // XGL_QUERY_TYPE queryType; |
| 87 | // XGL_UINT slots; |
| 88 | // } XGL_QUERY_POOL_CREATE_INFO; |
| 89 | |
| 90 | memset(&query_info, 0, sizeof(query_info)); |
| 91 | query_info.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 92 | query_info.queryType = XGL_QUERY_OCCLUSION; |
| 93 | query_info.slots = MAX_QUERY_SLOTS; |
| 94 | |
| 95 | // XGL_RESULT XGLAPI xglCreateQueryPool( |
| 96 | // XGL_DEVICE device, |
| 97 | // const XGL_QUERY_POOL_CREATE_INFO* pCreateInfo, |
| 98 | // XGL_QUERY_POOL* pQueryPool); |
| 99 | |
| 100 | err = xglCreateQueryPool(gpu->dev.obj, &query_info, &query_pool); |
| 101 | if (err) |
| 102 | ERR_EXIT(err); |
| 103 | |
| 104 | printf("xglCreateQueryPool: Passed"); |
| 105 | |
| 106 | err = xglGetObjectInfo(query_pool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 107 | &data_size, &mem_req); |
| 108 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 109 | // XGL_DEVICE device, |
| 110 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 111 | // XGL_GPU_MEMORY* pMem); |
| 112 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 113 | XGL_GPU_MEMORY query_mem; |
| 114 | |
| 115 | if (data_size == 0) { |
| 116 | ERR_MSG_EXIT("xglGetObjectInfo (Event): Failed - expect events to require memory"); |
| 117 | } |
| 118 | memset(&mem_info, 0, sizeof(mem_info)); |
| 119 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 120 | // TODO: Is a simple multiple all that's needed here? |
| 121 | mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS; |
| 122 | mem_info.alignment = mem_req.alignment; |
| 123 | mem_info.heapCount = mem_req.heapCount; |
| 124 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 125 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 126 | |
| 127 | // TODO: are the flags right? |
| 128 | // TODO: Should this be pinned? Or maybe a separate test with pinned. |
| 129 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 130 | err = xglAllocMemory(gpu->dev.obj, &mem_info, &query_mem); |
| 131 | if (err) |
| 132 | ERR_EXIT(err); |
| 133 | |
| 134 | printf("xglAllocMemory (QueryPool): Passed\n"); |
| 135 | |
| 136 | err = xglBindObjectMemory(query_pool, query_mem, 0); |
| 137 | if (err) |
| 138 | ERR_EXIT(err); |
| 139 | |
| 140 | printf("xglBindObjectMemory (QueryPool): Passed\n"); |
| 141 | |
| 142 | // TODO: Test actual synchronization with command buffer event. |
| 143 | // TODO: Create command buffer |
| 144 | // TODO: xglCmdResetQueryPool |
| 145 | // TODO: xglCmdBeginQuery |
| 146 | // TODO: commands |
| 147 | // TOOD: xglCmdEndQuery |
| 148 | |
| 149 | err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS, |
| 150 | &query_result_size, XGL_NULL_HANDLE); |
| 151 | if (err) |
| 152 | ERR_EXIT(err); |
| 153 | |
| 154 | printf("xglGetQueryPoolResults: Passed (size = %d)\n", query_result_size); |
| 155 | |
| 156 | if (query_result_size > 0) { |
| 157 | query_result_data = malloc(query_result_size); |
| 158 | err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS, |
| 159 | &query_result_size, query_result_data); |
| 160 | |
| 161 | if (err) |
| 162 | ERR_EXIT(err); |
| 163 | |
| 164 | // TODO: Test Query result data. |
| 165 | |
| 166 | printf("xglGetQueryPoolResults: Passed\n"); |
| 167 | } |
| 168 | |
| 169 | // All done with QueryPool memory, clean up |
| 170 | err = xglBindObjectMemory(query_pool, XGL_NULL_HANDLE, 0); |
| 171 | if (err) |
| 172 | ERR_EXIT(err); |
| 173 | |
| 174 | printf("xglBindObjectMemory (Unbind memory): Passed\n"); |
| 175 | |
| 176 | err = xglDestroyObject(query_pool); |
| 177 | if (err) |
| 178 | ERR_EXIT(err); |
| 179 | |
| 180 | printf("xglDestroyObject (QueryPool): Passed\n"); |
| 181 | } |
| 182 | |
| 183 | for (i = 0; i < gpu_count; i++) |
| 184 | app_gpu_destroy(&gpus[i]); |
| 185 | |
| 186 | return 0; |
| 187 | } |