Chia-I Wu | e18ff1b | 2014-08-07 13:38:51 +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 | */ |
| 24 | |
| 25 | #include "dev.h" |
| 26 | #include "mem.h" |
| 27 | #include "query.h" |
| 28 | |
| 29 | static void query_destroy(struct intel_obj *obj) |
| 30 | { |
| 31 | struct intel_query *query = intel_query_from_obj(obj); |
| 32 | |
| 33 | intel_query_destroy(query); |
| 34 | } |
| 35 | |
| 36 | static XGL_RESULT query_get_info(struct intel_base *base, int type, |
| 37 | XGL_SIZE *size, XGL_VOID *data) |
| 38 | { |
| 39 | struct intel_query *query = intel_query_from_base(base); |
| 40 | XGL_RESULT ret = XGL_SUCCESS; |
| 41 | |
| 42 | switch (type) { |
| 43 | case XGL_INFO_TYPE_MEMORY_REQUIREMENTS: |
| 44 | { |
| 45 | XGL_MEMORY_REQUIREMENTS *mem_req = data; |
| 46 | |
| 47 | mem_req->size = query->slot_stride * query->slot_count; |
| 48 | mem_req->alignment = 64; |
| 49 | mem_req->heapCount = 1; |
| 50 | mem_req->heaps[0] = 0; |
| 51 | |
| 52 | *size = sizeof(*mem_req); |
| 53 | } |
| 54 | break; |
| 55 | default: |
| 56 | ret = intel_base_get_info(base, type, size, data); |
| 57 | break; |
| 58 | } |
| 59 | |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | XGL_RESULT intel_query_create(struct intel_dev *dev, |
| 64 | const XGL_QUERY_POOL_CREATE_INFO *info, |
| 65 | struct intel_query **query_ret) |
| 66 | { |
| 67 | struct intel_query *query; |
| 68 | |
| 69 | query = (struct intel_query *) intel_base_create(sizeof(*query), |
| 70 | dev->base.dbg, XGL_DBG_OBJECT_QUERY_POOL, info, 0); |
| 71 | if (!query) |
| 72 | return XGL_ERROR_OUT_OF_MEMORY; |
| 73 | |
| 74 | query->type = info->queryType; |
| 75 | query->slot_count = info->slots; |
| 76 | |
| 77 | switch (info->queryType) { |
| 78 | case XGL_QUERY_OCCLUSION: |
| 79 | query->slot_stride = align(sizeof(uint32_t) * 2, 64); |
| 80 | break; |
| 81 | case XGL_QUERY_PIPELINE_STATISTICS: |
| 82 | query->slot_stride = |
| 83 | align(sizeof(XGL_PIPELINE_STATISTICS_DATA) * 2, 64); |
| 84 | break; |
| 85 | default: |
| 86 | break; |
| 87 | } |
| 88 | |
| 89 | if (!query->slot_stride) { |
| 90 | intel_query_destroy(query); |
| 91 | return XGL_ERROR_INVALID_VALUE; |
| 92 | } |
| 93 | |
| 94 | query->obj.base.get_info = query_get_info; |
| 95 | query->obj.destroy = query_destroy; |
| 96 | |
| 97 | *query_ret = query; |
| 98 | |
| 99 | return XGL_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | void intel_query_destroy(struct intel_query *query) |
| 103 | { |
| 104 | intel_base_destroy(&query->obj.base); |
| 105 | } |
| 106 | |
| 107 | XGL_RESULT intel_query_get_results(struct intel_query *query, |
| 108 | XGL_UINT slot_start, XGL_UINT slot_count, |
| 109 | void *results) |
| 110 | { |
| 111 | const uint8_t *ptr; |
| 112 | XGL_UINT i; |
| 113 | |
| 114 | if (!query->obj.mem) |
| 115 | return XGL_ERROR_MEMORY_NOT_BOUND; |
| 116 | |
| 117 | if (intel_mem_is_busy(query->obj.mem)) |
| 118 | return XGL_NOT_READY; |
| 119 | |
| 120 | ptr = (const uint8_t *) intel_mem_map_sync(query->obj.mem, false); |
| 121 | if (!ptr) |
| 122 | return XGL_ERROR_MEMORY_MAP_FAILED; |
| 123 | |
| 124 | ptr += query->obj.offset + query->slot_stride * slot_start; |
| 125 | |
| 126 | switch (query->type) { |
| 127 | case XGL_QUERY_OCCLUSION: |
| 128 | for (i = 0; i < slot_count; i++) { |
| 129 | const uint32_t *pair = (const uint32_t *) ptr; |
| 130 | |
| 131 | ((uint64_t *) results)[i] = pair[1] - pair[0]; |
| 132 | ptr += query->slot_stride; |
| 133 | } |
| 134 | break; |
| 135 | case XGL_QUERY_PIPELINE_STATISTICS: |
| 136 | for (i = 0; i < slot_count; i++) { |
| 137 | const XGL_UINT count = |
| 138 | sizeof(XGL_PIPELINE_STATISTICS_DATA) / sizeof(uint64_t); |
| 139 | const uint64_t *before = (const uint64_t *) ptr; |
| 140 | const uint64_t *after = (const uint64_t *) ptr + count; |
| 141 | uint64_t *dst = (uint64_t *) |
| 142 | ((XGL_PIPELINE_STATISTICS_DATA *) results + i); |
| 143 | XGL_UINT j; |
| 144 | |
| 145 | for (j = 0; j < count; j++) |
| 146 | dst[j] = after[j] - before[j]; |
| 147 | |
| 148 | ptr += query->slot_stride; |
| 149 | } |
| 150 | break; |
| 151 | default: |
| 152 | assert(0); |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | intel_mem_unmap(query->obj.mem); |
| 157 | |
| 158 | return XGL_SUCCESS; |
| 159 | } |
| 160 | |
| 161 | XGL_RESULT XGLAPI intelCreateQueryPool( |
| 162 | XGL_DEVICE device, |
| 163 | const XGL_QUERY_POOL_CREATE_INFO* pCreateInfo, |
| 164 | XGL_QUERY_POOL* pQueryPool) |
| 165 | { |
| 166 | return XGL_ERROR_UNAVAILABLE; |
| 167 | } |
| 168 | |
| 169 | XGL_RESULT XGLAPI intelGetQueryPoolResults( |
| 170 | XGL_QUERY_POOL queryPool, |
| 171 | XGL_UINT startQuery, |
| 172 | XGL_UINT queryCount, |
| 173 | XGL_SIZE* pDataSize, |
| 174 | XGL_VOID* pData) |
| 175 | { |
| 176 | return XGL_ERROR_UNAVAILABLE; |
| 177 | } |