Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 1 | // Copyright 2005, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 30 | |
| 31 | // XGL tests |
| 32 | // |
| 33 | // Copyright (C) 2014 LunarG, Inc. |
| 34 | // |
| 35 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 36 | // copy of this software and associated documentation files (the "Software"), |
| 37 | // to deal in the Software without restriction, including without limitation |
| 38 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 39 | // and/or sell copies of the Software, and to permit persons to whom the |
| 40 | // Software is furnished to do so, subject to the following conditions: |
| 41 | // |
| 42 | // The above copyright notice and this permission notice shall be included |
| 43 | // in all copies or substantial portions of the Software. |
| 44 | // |
| 45 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 46 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 47 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 48 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 49 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 50 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 51 | // DEALINGS IN THE SOFTWARE. |
| 52 | |
| 53 | |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 54 | // Verify XGL driver initialization |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 55 | |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 56 | #include <stdlib.h> |
| 57 | #include <stdio.h> |
| 58 | #include <stdbool.h> |
| 59 | #include <string.h> |
| 60 | |
| 61 | #include <xgl.h> |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 62 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 63 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 64 | // #include "gtest/gtest.h" |
| 65 | #include "xglgpu.h" |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 66 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 67 | class XglTest : public ::testing::Test { |
| 68 | public: |
| 69 | XglGpu *gpu; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 70 | void CreateImageTest(); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 71 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 72 | protected: |
| 73 | XGL_APPLICATION_INFO app_info; |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 74 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 75 | XGL_UINT gpu_count; |
| 76 | |
| 77 | virtual void SetUp() { |
| 78 | XGL_RESULT err; |
| 79 | |
| 80 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 81 | this->app_info.pNext = NULL; |
| 82 | this->app_info.pAppName = (const XGL_CHAR *) "base"; |
| 83 | this->app_info.appVersion = 1; |
| 84 | this->app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 85 | this->app_info.engineVersion = 1; |
| 86 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 87 | |
| 88 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 89 | MAX_GPUS, &this->gpu_count, objs); |
| 90 | ASSERT_XGL_SUCCESS(err); |
| 91 | ASSERT_GE(1, this->gpu_count) << "No GPU available"; |
| 92 | |
| 93 | this->gpu = new XglGpu(0, objs[0]); |
| 94 | } |
| 95 | |
| 96 | virtual void TearDown() { |
| 97 | xglInitAndEnumerateGpus(&this->app_info, NULL, 0, &gpu_count, NULL); |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | TEST(Initialization, xglInitAndEnumerateGpus) { |
| 102 | XGL_APPLICATION_INFO app_info = {}; |
| 103 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 104 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 105 | XGL_RESULT err; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 106 | XglGpu *gpu; |
| 107 | |
| 108 | app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 109 | app_info.pNext = NULL; |
| 110 | app_info.pAppName = (const XGL_CHAR *) "base"; |
| 111 | app_info.appVersion = 1; |
| 112 | app_info.pEngineName = (const XGL_CHAR *) "unittest"; |
| 113 | app_info.engineVersion = 1; |
| 114 | app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 115 | |
| 116 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 117 | MAX_GPUS, &gpu_count, objs); |
| 118 | ASSERT_XGL_SUCCESS(err); |
| 119 | ASSERT_GE(1, gpu_count) << "No GPU available"; |
| 120 | |
| 121 | // TODO: Iterate over all GPUs |
| 122 | gpu = new XglGpu(0, objs[0]); |
| 123 | |
| 124 | // TODO: Verify destroy functions |
| 125 | } |
| 126 | |
| 127 | TEST_F(XglTest, AllocMemory) { |
| 128 | XGL_RESULT err; |
| 129 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 130 | XGL_GPU_MEMORY gpu_mem; |
| 131 | XGL_UINT8 *pData; |
| 132 | |
| 133 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 134 | alloc_info.allocationSize = 1024 * 1024; // 1MB |
| 135 | alloc_info.alignment = 0; |
| 136 | alloc_info.heapCount = 1; |
| 137 | alloc_info.heaps[0] = 0; // TODO: Reference other heaps |
| 138 | |
| 139 | // TODO: Pick heap properties indicated by heap info |
| 140 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 141 | |
| 142 | // TODO: Try variety of memory priorities |
| 143 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 144 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 145 | err = xglAllocMemory(this->gpu->device(), &alloc_info, &gpu_mem); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 146 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 147 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 148 | err = xglMapMemory(gpu_mem, 0, (XGL_VOID **) &pData); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 149 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 150 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 151 | memset(pData, 0x55, alloc_info.allocationSize); |
| 152 | EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write"; |
| 153 | |
| 154 | err = xglUnmapMemory(gpu_mem); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 155 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 156 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 157 | err = xglFreeMemory(gpu_mem); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 158 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 159 | } |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 160 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 161 | TEST_F(XglTest, Event) { |
| 162 | XGL_EVENT_CREATE_INFO event_info; |
| 163 | XGL_EVENT event; |
| 164 | XGL_UINT data_size; |
| 165 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 166 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 167 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 168 | // typedef struct _XGL_EVENT_CREATE_INFO |
| 169 | // { |
| 170 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO |
| 171 | // const XGL_VOID* pNext; // Pointer to next structure |
| 172 | // XGL_FLAGS flags; // Reserved |
| 173 | // } XGL_EVENT_CREATE_INFO; |
| 174 | memset(&event_info, 0, sizeof(event_info)); |
| 175 | event_info.sType = XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 176 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 177 | err = xglCreateEvent(this->gpu->device(), &event_info, &event); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 178 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 179 | |
| 180 | err = xglGetObjectInfo(event, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 181 | &data_size, &mem_req); |
| 182 | ASSERT_XGL_SUCCESS(err); |
| 183 | |
| 184 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 185 | // XGL_DEVICE device, |
| 186 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 187 | // XGL_GPU_MEMORY* pMem); |
| 188 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 189 | XGL_GPU_MEMORY event_mem; |
| 190 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 191 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect events to require memory"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 192 | |
| 193 | memset(&mem_info, 0, sizeof(mem_info)); |
| 194 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 195 | mem_info.allocationSize = mem_req.size; |
| 196 | mem_info.alignment = mem_req.alignment; |
| 197 | mem_info.heapCount = mem_req.heapCount; |
| 198 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 199 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 200 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 201 | err = xglAllocMemory(this->gpu->device(), &mem_info, &event_mem); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 202 | ASSERT_XGL_SUCCESS(err); |
| 203 | |
| 204 | err = xglBindObjectMemory(event, event_mem, 0); |
| 205 | ASSERT_XGL_SUCCESS(err); |
| 206 | |
| 207 | err = xglResetEvent(event); |
| 208 | ASSERT_XGL_SUCCESS(err); |
| 209 | |
| 210 | err = xglGetEventStatus(event); |
| 211 | ASSERT_EQ(XGL_EVENT_RESET, err); |
| 212 | |
| 213 | err = xglSetEvent(event); |
| 214 | ASSERT_XGL_SUCCESS(err); |
| 215 | |
| 216 | err = xglGetEventStatus(event); |
| 217 | ASSERT_EQ(XGL_EVENT_SET, err); |
| 218 | |
| 219 | // TODO: Test actual synchronization with command buffer event. |
| 220 | |
| 221 | // All done with event memory, clean up |
| 222 | err = xglBindObjectMemory(event, XGL_NULL_HANDLE, 0); |
| 223 | ASSERT_XGL_SUCCESS(err); |
| 224 | |
| 225 | err = xglDestroyObject(event); |
| 226 | ASSERT_XGL_SUCCESS(err); |
| 227 | } |
| 228 | |
| 229 | TEST_F(XglTest, Fence) { |
| 230 | XGL_RESULT err; |
| 231 | XGL_FENCE_CREATE_INFO fence_info; |
| 232 | XGL_FENCE fence; |
| 233 | |
| 234 | memset(&fence_info, 0, sizeof(fence_info)); |
| 235 | |
| 236 | // typedef struct _XGL_FENCE_CREATE_INFO |
| 237 | // { |
| 238 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO |
| 239 | // const XGL_VOID* pNext; // Pointer to next structure |
| 240 | // XGL_FLAGS flags; // Reserved |
| 241 | fence_info.sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 242 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 243 | err = xglCreateFence(this->gpu->device(), &fence_info, &fence); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 244 | ASSERT_XGL_SUCCESS(err); |
| 245 | |
| 246 | err = xglGetFenceStatus(fence); |
| 247 | // We've not submitted this fence on a command buffer so should get |
| 248 | // XGL_ERROR_UNAVAILABLE |
| 249 | EXPECT_EQ(XGL_ERROR_UNAVAILABLE, err); |
| 250 | |
| 251 | // Test glxWaitForFences |
| 252 | // XGL_RESULT XGLAPI xglWaitForFences( |
| 253 | // XGL_DEVICE device, |
| 254 | // XGL_UINT fenceCount, |
| 255 | // const XGL_FENCE* pFences, |
| 256 | // XGL_BOOL waitAll, |
| 257 | // XGL_UINT64 timeout); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 258 | err = xglWaitForFences(this->gpu->device(), 1, &fence, XGL_TRUE, 0); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 259 | EXPECT_EQ(XGL_ERROR_UNAVAILABLE, err); |
| 260 | |
| 261 | // TODO: Attached to command buffer and test GetFenceStatus |
| 262 | // TODO: Add some commands and submit the command buffer |
| 263 | |
| 264 | err = xglDestroyObject(fence); |
| 265 | ASSERT_XGL_SUCCESS(err); |
| 266 | |
| 267 | } |
| 268 | |
| 269 | #define MAX_QUERY_SLOTS 10 |
| 270 | |
| 271 | TEST_F(XglTest, Query) { |
| 272 | XGL_QUERY_POOL_CREATE_INFO query_info; |
| 273 | XGL_QUERY_POOL query_pool; |
| 274 | XGL_UINT data_size; |
| 275 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 276 | XGL_UINT query_result_size; |
| 277 | XGL_UINT *query_result_data; |
| 278 | XGL_RESULT err; |
| 279 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 280 | // typedef enum _XGL_QUERY_TYPE |
| 281 | // { |
| 282 | // XGL_QUERY_OCCLUSION = 0x00000000, |
| 283 | // XGL_QUERY_PIPELINE_STATISTICS = 0x00000001, |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 284 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 285 | // XGL_QUERY_TYPE_BEGIN_RANGE = XGL_QUERY_OCCLUSION, |
| 286 | // XGL_QUERY_TYPE_END_RANGE = XGL_QUERY_PIPELINE_STATISTICS, |
| 287 | // XGL_NUM_QUERY_TYPE = (XGL_QUERY_TYPE_END_RANGE - XGL_QUERY_TYPE_BEGIN_RANGE + 1), |
| 288 | // XGL_MAX_ENUM(_XGL_QUERY_TYPE) |
| 289 | // } XGL_QUERY_TYPE; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 290 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 291 | // typedef struct _XGL_QUERY_POOL_CREATE_INFO |
| 292 | // { |
| 293 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO |
| 294 | // const XGL_VOID* pNext; // Pointer to next structure |
| 295 | // XGL_QUERY_TYPE queryType; |
| 296 | // XGL_UINT slots; |
| 297 | // } XGL_QUERY_POOL_CREATE_INFO; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 298 | |
| 299 | memset(&query_info, 0, sizeof(query_info)); |
| 300 | query_info.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 301 | query_info.queryType = XGL_QUERY_OCCLUSION; |
| 302 | query_info.slots = MAX_QUERY_SLOTS; |
| 303 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 304 | // XGL_RESULT XGLAPI xglCreateQueryPool( |
| 305 | // XGL_DEVICE device, |
| 306 | // const XGL_QUERY_POOL_CREATE_INFO* pCreateInfo, |
| 307 | // XGL_QUERY_POOL* pQueryPool); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 308 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 309 | err = xglCreateQueryPool(this->gpu->device(), &query_info, &query_pool); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 310 | ASSERT_XGL_SUCCESS(err); |
| 311 | |
| 312 | err = xglGetObjectInfo(query_pool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 313 | &data_size, &mem_req); |
| 314 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 315 | ASSERT_NE(0, data_size) << "Invalid data_size"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 316 | |
| 317 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 318 | // XGL_DEVICE device, |
| 319 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 320 | // XGL_GPU_MEMORY* pMem); |
| 321 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 322 | XGL_GPU_MEMORY query_mem; |
| 323 | |
| 324 | memset(&mem_info, 0, sizeof(mem_info)); |
| 325 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 326 | // TODO: Is a simple multiple all that's needed here? |
| 327 | mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS; |
| 328 | mem_info.alignment = mem_req.alignment; |
| 329 | mem_info.heapCount = mem_req.heapCount; |
| 330 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 331 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 332 | |
| 333 | // TODO: are the flags right? |
| 334 | // TODO: Should this be pinned? Or maybe a separate test with pinned. |
| 335 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 336 | err = xglAllocMemory(this->gpu->device(), &mem_info, &query_mem); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 337 | ASSERT_XGL_SUCCESS(err); |
| 338 | |
| 339 | err = xglBindObjectMemory(query_pool, query_mem, 0); |
| 340 | ASSERT_XGL_SUCCESS(err); |
| 341 | |
| 342 | // TODO: Test actual synchronization with command buffer event. |
| 343 | // TODO: Create command buffer |
| 344 | // TODO: xglCmdResetQueryPool |
| 345 | // TODO: xglCmdBeginQuery |
| 346 | // TODO: commands |
| 347 | // TOOD: xglCmdEndQuery |
| 348 | |
| 349 | err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS, |
| 350 | &query_result_size, XGL_NULL_HANDLE); |
| 351 | ASSERT_XGL_SUCCESS(err); |
| 352 | |
| 353 | if (query_result_size > 0) { |
| 354 | query_result_data = new XGL_UINT [query_result_size]; |
| 355 | err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS, |
| 356 | &query_result_size, query_result_data); |
| 357 | ASSERT_XGL_SUCCESS(err); |
| 358 | |
| 359 | // TODO: Test Query result data. |
| 360 | |
| 361 | } |
| 362 | |
| 363 | // All done with QueryPool memory, clean up |
| 364 | err = xglBindObjectMemory(query_pool, XGL_NULL_HANDLE, 0); |
| 365 | ASSERT_XGL_SUCCESS(err); |
| 366 | |
| 367 | err = xglDestroyObject(query_pool); |
| 368 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 369 | } |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 370 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame^] | 371 | void XglTest::CreateImageTest() |
| 372 | { |
| 373 | XGL_RESULT err; |
| 374 | XGL_IMAGE image; |
| 375 | XGL_UINT w, h, mipCount; |
| 376 | XGL_SIZE size; |
| 377 | XGL_FORMAT fmt; |
| 378 | XGL_FORMAT_PROPERTIES image_fmt; |
| 379 | |
| 380 | w =512; |
| 381 | h = 256; |
| 382 | mipCount = 0; |
| 383 | |
| 384 | XGL_UINT _w = w; |
| 385 | XGL_UINT _h = h; |
| 386 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 387 | { |
| 388 | _w >>= 1; |
| 389 | _h >>= 1; |
| 390 | mipCount++; |
| 391 | } |
| 392 | |
| 393 | fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 394 | fmt.numericFormat = XGL_NUM_FMT_UINT; |
| 395 | // TODO: Pick known good format rather than just expect common format |
| 396 | /* |
| 397 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
| 398 | * We're not requesting XGL_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
| 399 | * an expectation that pData is a valid pointer. |
| 400 | * However, why include a returned size value? That implies that the |
| 401 | * amount of data may vary and that doesn't work well for using a |
| 402 | * fixed structure. |
| 403 | */ |
| 404 | |
| 405 | err = xglGetFormatInfo(this->gpu->device(), fmt, |
| 406 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 407 | &size, &image_fmt); |
| 408 | ASSERT_XGL_SUCCESS(err); |
| 409 | |
| 410 | // typedef struct _XGL_IMAGE_CREATE_INFO |
| 411 | // { |
| 412 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
| 413 | // const XGL_VOID* pNext; // Pointer to next structure. |
| 414 | // XGL_IMAGE_TYPE imageType; |
| 415 | // XGL_FORMAT format; |
| 416 | // XGL_EXTENT3D extent; |
| 417 | // XGL_UINT mipLevels; |
| 418 | // XGL_UINT arraySize; |
| 419 | // XGL_UINT samples; |
| 420 | // XGL_IMAGE_TILING tiling; |
| 421 | // XGL_FLAGS usage; // XGL_IMAGE_USAGE_FLAGS |
| 422 | // XGL_FLAGS flags; // XGL_IMAGE_CREATE_FLAGS |
| 423 | // } XGL_IMAGE_CREATE_INFO; |
| 424 | |
| 425 | |
| 426 | XGL_IMAGE_CREATE_INFO imageCreateInfo = {}; |
| 427 | imageCreateInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 428 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 429 | imageCreateInfo.format = fmt; |
| 430 | imageCreateInfo.arraySize = 1; |
| 431 | imageCreateInfo.extent.width = w; |
| 432 | imageCreateInfo.extent.height = h; |
| 433 | imageCreateInfo.extent.depth = 1; |
| 434 | imageCreateInfo.mipLevels = mipCount; |
| 435 | imageCreateInfo.samples = 1; |
| 436 | imageCreateInfo.tiling = XGL_LINEAR_TILING; |
| 437 | |
| 438 | // Image usage flags |
| 439 | // typedef enum _XGL_IMAGE_USAGE_FLAGS |
| 440 | // { |
| 441 | // XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001, |
| 442 | // XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002, |
| 443 | // XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004, |
| 444 | // XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008, |
| 445 | // } XGL_IMAGE_USAGE_FLAGS; |
| 446 | imageCreateInfo.usage = XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 447 | |
| 448 | // XGL_RESULT XGLAPI xglCreateImage( |
| 449 | // XGL_DEVICE device, |
| 450 | // const XGL_IMAGE_CREATE_INFO* pCreateInfo, |
| 451 | // XGL_IMAGE* pImage); |
| 452 | err = xglCreateImage(this->gpu->device(), &imageCreateInfo, &image); |
| 453 | ASSERT_XGL_SUCCESS(err); |
| 454 | |
| 455 | XGL_MEMORY_REQUIREMENTS mem_req; |
| 456 | XGL_UINT data_size; |
| 457 | err = xglGetObjectInfo(image, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 458 | &data_size, &mem_req); |
| 459 | ASSERT_XGL_SUCCESS(err); |
| 460 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 461 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect images to require memory"; |
| 462 | |
| 463 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 464 | // XGL_DEVICE device, |
| 465 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 466 | // XGL_GPU_MEMORY* pMem); |
| 467 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 468 | XGL_GPU_MEMORY image_mem; |
| 469 | |
| 470 | memset(&mem_info, 0, sizeof(mem_info)); |
| 471 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 472 | mem_info.allocationSize = mem_req.size; |
| 473 | mem_info.alignment = mem_req.alignment; |
| 474 | mem_info.heapCount = mem_req.heapCount; |
| 475 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 476 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 477 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
| 478 | err = xglAllocMemory(this->gpu->device(), &mem_info, &image_mem); |
| 479 | ASSERT_XGL_SUCCESS(err); |
| 480 | |
| 481 | err = xglBindObjectMemory(image, image_mem, 0); |
| 482 | ASSERT_XGL_SUCCESS(err); |
| 483 | |
| 484 | // typedef struct _XGL_IMAGE_VIEW_CREATE_INFO |
| 485 | // { |
| 486 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
| 487 | // const XGL_VOID* pNext; // Pointer to next structure |
| 488 | // XGL_IMAGE image; |
| 489 | // XGL_IMAGE_VIEW_TYPE viewType; |
| 490 | // XGL_FORMAT format; |
| 491 | // XGL_CHANNEL_MAPPING channels; |
| 492 | // XGL_IMAGE_SUBRESOURCE_RANGE subresourceRange; |
| 493 | // XGL_FLOAT minLod; |
| 494 | // } XGL_IMAGE_VIEW_CREATE_INFO; |
| 495 | XGL_IMAGE_VIEW_CREATE_INFO viewInfo = {}; |
| 496 | XGL_IMAGE_VIEW view; |
| 497 | viewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 498 | viewInfo.image = image; |
| 499 | viewInfo.viewType = XGL_IMAGE_VIEW_2D; |
| 500 | viewInfo.format = fmt; |
| 501 | |
| 502 | viewInfo.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 503 | viewInfo.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 504 | viewInfo.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 505 | viewInfo.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 506 | |
| 507 | viewInfo.subresourceRange.baseArraySlice = 0; |
| 508 | viewInfo.subresourceRange.arraySize = 1; |
| 509 | viewInfo.subresourceRange.baseMipLevel = 0; |
| 510 | viewInfo.subresourceRange.mipLevels = 1; |
| 511 | viewInfo.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 512 | |
| 513 | // XGL_RESULT XGLAPI xglCreateImageView( |
| 514 | // XGL_DEVICE device, |
| 515 | // const XGL_IMAGE_VIEW_CREATE_INFO* pCreateInfo, |
| 516 | // XGL_IMAGE_VIEW* pView); |
| 517 | |
| 518 | err = xglCreateImageView(gpu->device(), &viewInfo, &view); |
| 519 | ASSERT_XGL_SUCCESS(err); |
| 520 | |
| 521 | // TODO: Test image memory. |
| 522 | |
| 523 | // All done with image memory, clean up |
| 524 | ASSERT_XGL_SUCCESS(xglBindObjectMemory(image, XGL_NULL_HANDLE, 0)); |
| 525 | |
| 526 | ASSERT_XGL_SUCCESS(xglFreeMemory(image_mem)); |
| 527 | |
| 528 | ASSERT_XGL_SUCCESS(xglDestroyObject(image)); |
| 529 | } |
| 530 | |
| 531 | TEST_F(XglTest, CreateImage) { |
| 532 | CreateImageTest(); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 536 | ::testing::InitGoogleTest(&argc, argv); |
| 537 | return RUN_ALL_TESTS(); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 538 | } |