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 | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 64 | #include "xgldevice.h" |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 65 | #include "icd-bil.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: |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 69 | void CreateImageTest(); |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 70 | void CreateCommandBufferTest(); |
| 71 | void CreatePipelineTest(); |
| 72 | void CreateShaderTest(); |
| 73 | void CreateShader(XGL_SHADER *pshader); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 74 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 75 | XGL_DEVICE device() {return m_device->device();} |
| 76 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 77 | protected: |
| 78 | XGL_APPLICATION_INFO app_info; |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 79 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 80 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 81 | XglDevice *m_device; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 82 | |
| 83 | virtual void SetUp() { |
| 84 | XGL_RESULT err; |
| 85 | |
| 86 | this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 87 | this->app_info.pNext = NULL; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 88 | this->app_info.pAppName = "base"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 89 | this->app_info.appVersion = 1; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 90 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 91 | this->app_info.engineVersion = 1; |
| 92 | this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
| 93 | |
| 94 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
| 95 | MAX_GPUS, &this->gpu_count, objs); |
| 96 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 97 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 98 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 99 | this->m_device = new XglDevice(0, objs[0]); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | virtual void TearDown() { |
| 103 | xglInitAndEnumerateGpus(&this->app_info, NULL, 0, &gpu_count, NULL); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | TEST(Initialization, xglInitAndEnumerateGpus) { |
| 108 | XGL_APPLICATION_INFO app_info = {}; |
| 109 | XGL_PHYSICAL_GPU objs[MAX_GPUS]; |
| 110 | XGL_UINT gpu_count; |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 111 | XGL_RESULT err; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 112 | XglGpu *gpu; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 113 | XGL_CHAR *layers[16]; |
| 114 | XGL_SIZE layer_count; |
| 115 | XGL_CHAR layer_buf[16][256]; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 116 | |
| 117 | app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO; |
| 118 | app_info.pNext = NULL; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 119 | app_info.pAppName = "base"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 120 | app_info.appVersion = 1; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 121 | app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 122 | app_info.engineVersion = 1; |
| 123 | app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 124 | |
| 125 | err = xglInitAndEnumerateGpus(&app_info, NULL, |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 126 | MAX_GPUS, &gpu_count, objs); |
| 127 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 128 | ASSERT_GE(gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 129 | |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 130 | for (int i = 0; i < 16; i++) |
| 131 | layers[i] = &layer_buf[i][0]; |
Jon Ashburn | 6847c2b | 2014-11-25 12:56:49 -0700 | [diff] [blame] | 132 | err = xglEnumerateLayers(objs[0], 16, 256, (XGL_CHAR * const *) layers, &layer_count, NULL); |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 133 | ASSERT_XGL_SUCCESS(err); |
| 134 | for (int i = 0; i < layer_count; i++) { |
| 135 | printf("Enumerated layers: %s ", layers[i]); |
| 136 | } |
| 137 | printf("\n"); |
| 138 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 139 | // TODO: Iterate over all GPUs |
| 140 | gpu = new XglGpu(0, objs[0]); |
Chia-I Wu | b7cf445 | 2014-12-16 00:04:02 +0800 | [diff] [blame] | 141 | delete gpu; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 142 | |
| 143 | // TODO: Verify destroy functions |
| 144 | } |
| 145 | |
| 146 | TEST_F(XglTest, AllocMemory) { |
| 147 | XGL_RESULT err; |
| 148 | XGL_MEMORY_ALLOC_INFO alloc_info = {}; |
| 149 | XGL_GPU_MEMORY gpu_mem; |
| 150 | XGL_UINT8 *pData; |
| 151 | |
| 152 | alloc_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 153 | alloc_info.allocationSize = 1024 * 1024; // 1MB |
| 154 | alloc_info.alignment = 0; |
| 155 | alloc_info.heapCount = 1; |
| 156 | alloc_info.heaps[0] = 0; // TODO: Reference other heaps |
| 157 | |
| 158 | // TODO: Pick heap properties indicated by heap info |
| 159 | alloc_info.flags = XGL_MEMORY_HEAP_CPU_VISIBLE_BIT; |
| 160 | |
| 161 | // TODO: Try variety of memory priorities |
| 162 | alloc_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 163 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 164 | err = xglAllocMemory(device(), &alloc_info, &gpu_mem); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 165 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 166 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 167 | err = xglMapMemory(gpu_mem, 0, (XGL_VOID **) &pData); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 168 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 169 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 170 | memset(pData, 0x55, alloc_info.allocationSize); |
| 171 | EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write"; |
| 172 | |
| 173 | err = xglUnmapMemory(gpu_mem); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 174 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 175 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 176 | err = xglFreeMemory(gpu_mem); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 177 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 178 | } |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 179 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 180 | TEST_F(XglTest, Event) { |
| 181 | XGL_EVENT_CREATE_INFO event_info; |
| 182 | XGL_EVENT event; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 183 | XGL_MEMORY_REQUIREMENTS mem_req; |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 184 | size_t data_size = sizeof(mem_req); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 185 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 186 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 187 | // typedef struct _XGL_EVENT_CREATE_INFO |
| 188 | // { |
| 189 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO |
| 190 | // const XGL_VOID* pNext; // Pointer to next structure |
| 191 | // XGL_FLAGS flags; // Reserved |
| 192 | // } XGL_EVENT_CREATE_INFO; |
| 193 | memset(&event_info, 0, sizeof(event_info)); |
| 194 | event_info.sType = XGL_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 195 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 196 | err = xglCreateEvent(device(), &event_info, &event); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 197 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 198 | |
| 199 | err = xglGetObjectInfo(event, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 200 | &data_size, &mem_req); |
| 201 | ASSERT_XGL_SUCCESS(err); |
| 202 | |
| 203 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 204 | // XGL_DEVICE device, |
| 205 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 206 | // XGL_GPU_MEMORY* pMem); |
| 207 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 208 | XGL_GPU_MEMORY event_mem; |
| 209 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 210 | 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] | 211 | |
| 212 | memset(&mem_info, 0, sizeof(mem_info)); |
| 213 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 214 | mem_info.allocationSize = mem_req.size; |
| 215 | mem_info.alignment = mem_req.alignment; |
| 216 | mem_info.heapCount = mem_req.heapCount; |
| 217 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 218 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 219 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 220 | err = xglAllocMemory(device(), &mem_info, &event_mem); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 221 | ASSERT_XGL_SUCCESS(err); |
| 222 | |
| 223 | err = xglBindObjectMemory(event, event_mem, 0); |
| 224 | ASSERT_XGL_SUCCESS(err); |
| 225 | |
| 226 | err = xglResetEvent(event); |
| 227 | ASSERT_XGL_SUCCESS(err); |
| 228 | |
| 229 | err = xglGetEventStatus(event); |
| 230 | ASSERT_EQ(XGL_EVENT_RESET, err); |
| 231 | |
| 232 | err = xglSetEvent(event); |
| 233 | ASSERT_XGL_SUCCESS(err); |
| 234 | |
| 235 | err = xglGetEventStatus(event); |
| 236 | ASSERT_EQ(XGL_EVENT_SET, err); |
| 237 | |
| 238 | // TODO: Test actual synchronization with command buffer event. |
| 239 | |
| 240 | // All done with event memory, clean up |
| 241 | err = xglBindObjectMemory(event, XGL_NULL_HANDLE, 0); |
| 242 | ASSERT_XGL_SUCCESS(err); |
| 243 | |
| 244 | err = xglDestroyObject(event); |
| 245 | ASSERT_XGL_SUCCESS(err); |
| 246 | } |
| 247 | |
| 248 | TEST_F(XglTest, Fence) { |
| 249 | XGL_RESULT err; |
| 250 | XGL_FENCE_CREATE_INFO fence_info; |
| 251 | XGL_FENCE fence; |
| 252 | |
| 253 | memset(&fence_info, 0, sizeof(fence_info)); |
| 254 | |
| 255 | // typedef struct _XGL_FENCE_CREATE_INFO |
| 256 | // { |
| 257 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO |
| 258 | // const XGL_VOID* pNext; // Pointer to next structure |
| 259 | // XGL_FLAGS flags; // Reserved |
| 260 | fence_info.sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 261 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 262 | err = xglCreateFence(device(), &fence_info, &fence); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 263 | ASSERT_XGL_SUCCESS(err); |
| 264 | |
| 265 | err = xglGetFenceStatus(fence); |
| 266 | // We've not submitted this fence on a command buffer so should get |
| 267 | // XGL_ERROR_UNAVAILABLE |
| 268 | EXPECT_EQ(XGL_ERROR_UNAVAILABLE, err); |
| 269 | |
| 270 | // Test glxWaitForFences |
| 271 | // XGL_RESULT XGLAPI xglWaitForFences( |
| 272 | // XGL_DEVICE device, |
| 273 | // XGL_UINT fenceCount, |
| 274 | // const XGL_FENCE* pFences, |
| 275 | // XGL_BOOL waitAll, |
| 276 | // XGL_UINT64 timeout); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 277 | err = xglWaitForFences(device(), 1, &fence, XGL_TRUE, 0); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 278 | EXPECT_EQ(XGL_ERROR_UNAVAILABLE, err); |
| 279 | |
| 280 | // TODO: Attached to command buffer and test GetFenceStatus |
| 281 | // TODO: Add some commands and submit the command buffer |
| 282 | |
| 283 | err = xglDestroyObject(fence); |
| 284 | ASSERT_XGL_SUCCESS(err); |
| 285 | |
| 286 | } |
| 287 | |
| 288 | #define MAX_QUERY_SLOTS 10 |
| 289 | |
| 290 | TEST_F(XglTest, Query) { |
| 291 | XGL_QUERY_POOL_CREATE_INFO query_info; |
| 292 | XGL_QUERY_POOL query_pool; |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 293 | size_t data_size; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 294 | XGL_MEMORY_REQUIREMENTS mem_req; |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 295 | size_t query_result_size; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 296 | XGL_UINT *query_result_data; |
| 297 | XGL_RESULT err; |
| 298 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 299 | // typedef enum _XGL_QUERY_TYPE |
| 300 | // { |
| 301 | // XGL_QUERY_OCCLUSION = 0x00000000, |
| 302 | // XGL_QUERY_PIPELINE_STATISTICS = 0x00000001, |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 303 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 304 | // XGL_QUERY_TYPE_BEGIN_RANGE = XGL_QUERY_OCCLUSION, |
| 305 | // XGL_QUERY_TYPE_END_RANGE = XGL_QUERY_PIPELINE_STATISTICS, |
| 306 | // XGL_NUM_QUERY_TYPE = (XGL_QUERY_TYPE_END_RANGE - XGL_QUERY_TYPE_BEGIN_RANGE + 1), |
| 307 | // XGL_MAX_ENUM(_XGL_QUERY_TYPE) |
| 308 | // } XGL_QUERY_TYPE; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 309 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 310 | // typedef struct _XGL_QUERY_POOL_CREATE_INFO |
| 311 | // { |
| 312 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO |
| 313 | // const XGL_VOID* pNext; // Pointer to next structure |
| 314 | // XGL_QUERY_TYPE queryType; |
| 315 | // XGL_UINT slots; |
| 316 | // } XGL_QUERY_POOL_CREATE_INFO; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 317 | |
| 318 | memset(&query_info, 0, sizeof(query_info)); |
| 319 | query_info.sType = XGL_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 320 | query_info.queryType = XGL_QUERY_OCCLUSION; |
| 321 | query_info.slots = MAX_QUERY_SLOTS; |
| 322 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 323 | // XGL_RESULT XGLAPI xglCreateQueryPool( |
| 324 | // XGL_DEVICE device, |
| 325 | // const XGL_QUERY_POOL_CREATE_INFO* pCreateInfo, |
| 326 | // XGL_QUERY_POOL* pQueryPool); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 327 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 328 | err = xglCreateQueryPool(device(), &query_info, &query_pool); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 329 | ASSERT_XGL_SUCCESS(err); |
| 330 | |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 331 | data_size = sizeof(mem_req); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 332 | err = xglGetObjectInfo(query_pool, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 333 | &data_size, &mem_req); |
| 334 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 335 | ASSERT_NE(0, data_size) << "Invalid data_size"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 336 | |
| 337 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 338 | // XGL_DEVICE device, |
| 339 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 340 | // XGL_GPU_MEMORY* pMem); |
| 341 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 342 | XGL_GPU_MEMORY query_mem; |
| 343 | |
| 344 | memset(&mem_info, 0, sizeof(mem_info)); |
| 345 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 346 | // TODO: Is a simple multiple all that's needed here? |
| 347 | mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS; |
| 348 | mem_info.alignment = mem_req.alignment; |
| 349 | mem_info.heapCount = mem_req.heapCount; |
| 350 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 351 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 352 | |
| 353 | // TODO: are the flags right? |
| 354 | // TODO: Should this be pinned? Or maybe a separate test with pinned. |
| 355 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 356 | err = xglAllocMemory(device(), &mem_info, &query_mem); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 357 | ASSERT_XGL_SUCCESS(err); |
| 358 | |
| 359 | err = xglBindObjectMemory(query_pool, query_mem, 0); |
| 360 | ASSERT_XGL_SUCCESS(err); |
| 361 | |
| 362 | // TODO: Test actual synchronization with command buffer event. |
| 363 | // TODO: Create command buffer |
| 364 | // TODO: xglCmdResetQueryPool |
| 365 | // TODO: xglCmdBeginQuery |
| 366 | // TODO: commands |
| 367 | // TOOD: xglCmdEndQuery |
| 368 | |
| 369 | err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS, |
| 370 | &query_result_size, XGL_NULL_HANDLE); |
| 371 | ASSERT_XGL_SUCCESS(err); |
| 372 | |
| 373 | if (query_result_size > 0) { |
| 374 | query_result_data = new XGL_UINT [query_result_size]; |
| 375 | err = xglGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS, |
| 376 | &query_result_size, query_result_data); |
| 377 | ASSERT_XGL_SUCCESS(err); |
| 378 | |
| 379 | // TODO: Test Query result data. |
| 380 | |
| 381 | } |
| 382 | |
| 383 | // All done with QueryPool memory, clean up |
| 384 | err = xglBindObjectMemory(query_pool, XGL_NULL_HANDLE, 0); |
| 385 | ASSERT_XGL_SUCCESS(err); |
| 386 | |
| 387 | err = xglDestroyObject(query_pool); |
| 388 | ASSERT_XGL_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 389 | } |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 390 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 391 | void getQueue(XglDevice *device, XGL_QUEUE_TYPE qtype, const char *qname) |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 392 | { |
| 393 | int que_idx; |
| 394 | XGL_RESULT err; |
| 395 | XGL_QUEUE queue; |
| 396 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 397 | for (que_idx = 0; que_idx < device->queue_props->queueCount; que_idx++) { |
| 398 | err = xglGetDeviceQueue(device->device(), qtype, que_idx, &queue); |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 399 | ASSERT_EQ(XGL_SUCCESS, err) << "xglGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << xgl_result_string(err); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | TEST_F(XglTest, Queue) |
| 404 | { |
| 405 | XGL_UINT que_idx; |
| 406 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 407 | ASSERT_NE(0, m_device->queue_props->queueCount) << "No heaps available for GPU #" << m_device->id << ": " << m_device->props.gpuName; |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 408 | |
| 409 | // XGL_RESULT XGLAPI xglGetDeviceQueue( |
| 410 | // XGL_DEVICE device, |
| 411 | // XGL_QUEUE_TYPE queueType, |
| 412 | // XGL_UINT queueIndex, |
| 413 | // XGL_QUEUE* pQueue); |
| 414 | /* |
| 415 | * queue handles are retrieved from the device by calling |
| 416 | * xglGetDeviceQueue() with a queue type and a requested logical |
| 417 | * queue ID. The logical queue ID is a sequential number starting |
| 418 | * from zero and referencing up to the number of queues requested |
| 419 | * at device creation. Each queue type has its own sequence of IDs |
| 420 | * starting at zero. |
| 421 | */ |
| 422 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 423 | for (que_idx = 0; que_idx < m_device->queue_props->queueCount; que_idx++) { |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 424 | |
| 425 | // typedef enum _XGL_QUEUE_FLAGS |
| 426 | // { |
| 427 | // XGL_QUEUE_GRAPHICS_BIT = 0x00000001, // Queue supports graphics operations |
| 428 | // XGL_QUEUE_COMPUTE_BIT = 0x00000002, // Queue supports compute operations |
| 429 | // XGL_QUEUE_DMA_BIT = 0x00000004, // Queue supports DMA operations |
| 430 | // XGL_QUEUE_EXTENDED_BIT = 0x80000000 // Extended queue |
| 431 | // } XGL_QUEUE_FLAGS; |
| 432 | |
| 433 | // typedef enum _XGL_QUEUE_TYPE |
| 434 | // { |
| 435 | // XGL_QUEUE_TYPE_GRAPHICS = 0x1, |
| 436 | // XGL_QUEUE_TYPE_COMPUTE = 0x2, |
| 437 | // XGL_QUEUE_TYPE_DMA = 0x3, |
| 438 | // XGL_MAX_ENUM(_XGL_QUEUE_TYPE) |
| 439 | // } XGL_QUEUE_TYPE; |
| 440 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 441 | if (m_device->queue_props->queueFlags & XGL_QUEUE_GRAPHICS_BIT) { |
| 442 | getQueue(m_device, XGL_QUEUE_TYPE_GRAPHICS, "Graphics"); |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 443 | } |
| 444 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 445 | if (m_device->queue_props->queueFlags & XGL_QUEUE_COMPUTE_BIT) { |
| 446 | getQueue(m_device, XGL_QUEUE_TYPE_GRAPHICS, "Compute"); |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 447 | } |
| 448 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 449 | if (m_device->queue_props->queueFlags & XGL_QUEUE_DMA_BIT) { |
| 450 | getQueue(m_device, XGL_QUEUE_TYPE_GRAPHICS, "DMA"); |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | // TODO: What do we do about EXTENDED_BIT? |
| 454 | |
| 455 | /* Guide: pg 34: |
| 456 | * The queue objects cannot be destroyed explicitly by an application |
| 457 | * and are automatically destroyed when the associated device is destroyed. |
| 458 | * Once the device is destroyed, attempting to use a queue results in |
| 459 | * undefined behavior. |
| 460 | */ |
| 461 | } |
| 462 | } |
| 463 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 464 | void XglTest::CreateImageTest() |
| 465 | { |
| 466 | XGL_RESULT err; |
| 467 | XGL_IMAGE image; |
| 468 | XGL_UINT w, h, mipCount; |
| 469 | XGL_SIZE size; |
| 470 | XGL_FORMAT fmt; |
| 471 | XGL_FORMAT_PROPERTIES image_fmt; |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 472 | size_t data_size; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 473 | |
| 474 | w =512; |
| 475 | h = 256; |
| 476 | mipCount = 0; |
| 477 | |
| 478 | XGL_UINT _w = w; |
| 479 | XGL_UINT _h = h; |
| 480 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 481 | { |
| 482 | _w >>= 1; |
| 483 | _h >>= 1; |
| 484 | mipCount++; |
| 485 | } |
| 486 | |
| 487 | fmt.channelFormat = XGL_CH_FMT_R8G8B8A8; |
| 488 | fmt.numericFormat = XGL_NUM_FMT_UINT; |
| 489 | // TODO: Pick known good format rather than just expect common format |
| 490 | /* |
| 491 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
| 492 | * We're not requesting XGL_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
| 493 | * an expectation that pData is a valid pointer. |
| 494 | * However, why include a returned size value? That implies that the |
| 495 | * amount of data may vary and that doesn't work well for using a |
| 496 | * fixed structure. |
| 497 | */ |
| 498 | |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 499 | size = sizeof(image_fmt); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 500 | err = xglGetFormatInfo(device(), fmt, |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 501 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 502 | &size, &image_fmt); |
| 503 | ASSERT_XGL_SUCCESS(err); |
| 504 | |
| 505 | // typedef struct _XGL_IMAGE_CREATE_INFO |
| 506 | // { |
| 507 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
| 508 | // const XGL_VOID* pNext; // Pointer to next structure. |
| 509 | // XGL_IMAGE_TYPE imageType; |
| 510 | // XGL_FORMAT format; |
| 511 | // XGL_EXTENT3D extent; |
| 512 | // XGL_UINT mipLevels; |
| 513 | // XGL_UINT arraySize; |
| 514 | // XGL_UINT samples; |
| 515 | // XGL_IMAGE_TILING tiling; |
| 516 | // XGL_FLAGS usage; // XGL_IMAGE_USAGE_FLAGS |
| 517 | // XGL_FLAGS flags; // XGL_IMAGE_CREATE_FLAGS |
| 518 | // } XGL_IMAGE_CREATE_INFO; |
| 519 | |
| 520 | |
| 521 | XGL_IMAGE_CREATE_INFO imageCreateInfo = {}; |
| 522 | imageCreateInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 523 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 524 | imageCreateInfo.format = fmt; |
| 525 | imageCreateInfo.arraySize = 1; |
| 526 | imageCreateInfo.extent.width = w; |
| 527 | imageCreateInfo.extent.height = h; |
| 528 | imageCreateInfo.extent.depth = 1; |
| 529 | imageCreateInfo.mipLevels = mipCount; |
| 530 | imageCreateInfo.samples = 1; |
| 531 | imageCreateInfo.tiling = XGL_LINEAR_TILING; |
| 532 | |
| 533 | // Image usage flags |
| 534 | // typedef enum _XGL_IMAGE_USAGE_FLAGS |
| 535 | // { |
| 536 | // XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001, |
| 537 | // XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002, |
| 538 | // XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004, |
| 539 | // XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008, |
| 540 | // } XGL_IMAGE_USAGE_FLAGS; |
| 541 | imageCreateInfo.usage = XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 542 | |
| 543 | // XGL_RESULT XGLAPI xglCreateImage( |
| 544 | // XGL_DEVICE device, |
| 545 | // const XGL_IMAGE_CREATE_INFO* pCreateInfo, |
| 546 | // XGL_IMAGE* pImage); |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 547 | err = xglCreateImage(device(), &imageCreateInfo, &image); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 548 | ASSERT_XGL_SUCCESS(err); |
| 549 | |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 550 | // Verify image resources |
| 551 | // XGL_RESULT XGLAPI xglGetImageSubresourceInfo( |
| 552 | // XGL_IMAGE image, |
| 553 | // const XGL_IMAGE_SUBRESOURCE* pSubresource, |
| 554 | // XGL_SUBRESOURCE_INFO_TYPE infoType, |
| 555 | // XGL_SIZE* pDataSize, |
| 556 | // XGL_VOID* pData); |
| 557 | // typedef struct _XGL_SUBRESOURCE_LAYOUT |
| 558 | // { |
| 559 | // XGL_GPU_SIZE offset; // Specified in bytes |
| 560 | // XGL_GPU_SIZE size; // Specified in bytes |
| 561 | // XGL_GPU_SIZE rowPitch; // Specified in bytes |
| 562 | // XGL_GPU_SIZE depthPitch; // Specified in bytes |
| 563 | // } XGL_SUBRESOURCE_LAYOUT; |
| 564 | |
| 565 | // typedef struct _XGL_IMAGE_SUBRESOURCE |
| 566 | // { |
| 567 | // XGL_IMAGE_ASPECT aspect; |
| 568 | // XGL_UINT mipLevel; |
| 569 | // XGL_UINT arraySlice; |
| 570 | // } XGL_IMAGE_SUBRESOURCE; |
| 571 | // typedef enum _XGL_SUBRESOURCE_INFO_TYPE |
| 572 | // { |
| 573 | // // Info type for xglGetImageSubresourceInfo() |
| 574 | // XGL_INFO_TYPE_SUBRESOURCE_LAYOUT = 0x00000000, |
| 575 | |
| 576 | // XGL_MAX_ENUM(_XGL_SUBRESOURCE_INFO_TYPE) |
| 577 | // } XGL_SUBRESOURCE_INFO_TYPE; |
| 578 | XGL_IMAGE_SUBRESOURCE subresource = {}; |
| 579 | subresource.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 580 | subresource.arraySlice = 0; |
| 581 | |
| 582 | _w = w; |
| 583 | _h = h; |
| 584 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 585 | { |
| 586 | XGL_SUBRESOURCE_LAYOUT layout = {}; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 587 | data_size = sizeof(layout); |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 588 | err = xglGetImageSubresourceInfo(image, &subresource, XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, |
| 589 | &data_size, &layout); |
| 590 | ASSERT_XGL_SUCCESS(err); |
| 591 | ASSERT_EQ(sizeof(XGL_SUBRESOURCE_LAYOUT), data_size) << "Invalid structure (XGL_SUBRESOURCE_LAYOUT) size"; |
| 592 | |
| 593 | // TODO: 4 should be replaced with pixel size for given format |
| 594 | EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch"; |
| 595 | _w >>= 1; |
| 596 | _h >>= 1; |
| 597 | |
| 598 | subresource.mipLevel++; |
| 599 | } |
| 600 | |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 601 | XGL_MEMORY_REQUIREMENTS mem_req; |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 602 | data_size = sizeof(mem_req); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 603 | err = xglGetObjectInfo(image, XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 604 | &data_size, &mem_req); |
| 605 | ASSERT_XGL_SUCCESS(err); |
| 606 | ASSERT_EQ(data_size, sizeof(mem_req)); |
| 607 | ASSERT_NE(0, mem_req.size) << "xglGetObjectInfo (Event): Failed - expect images to require memory"; |
| 608 | |
| 609 | // XGL_RESULT XGLAPI xglAllocMemory( |
| 610 | // XGL_DEVICE device, |
| 611 | // const XGL_MEMORY_ALLOC_INFO* pAllocInfo, |
| 612 | // XGL_GPU_MEMORY* pMem); |
| 613 | XGL_MEMORY_ALLOC_INFO mem_info; |
| 614 | XGL_GPU_MEMORY image_mem; |
| 615 | |
| 616 | memset(&mem_info, 0, sizeof(mem_info)); |
| 617 | mem_info.sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 618 | mem_info.allocationSize = mem_req.size; |
| 619 | mem_info.alignment = mem_req.alignment; |
| 620 | mem_info.heapCount = mem_req.heapCount; |
| 621 | memcpy(mem_info.heaps, mem_req.heaps, sizeof(XGL_UINT)*XGL_MAX_MEMORY_HEAPS); |
| 622 | mem_info.memPriority = XGL_MEMORY_PRIORITY_NORMAL; |
| 623 | mem_info.flags = XGL_MEMORY_ALLOC_SHAREABLE_BIT; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 624 | err = xglAllocMemory(device(), &mem_info, &image_mem); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 625 | ASSERT_XGL_SUCCESS(err); |
| 626 | |
| 627 | err = xglBindObjectMemory(image, image_mem, 0); |
| 628 | ASSERT_XGL_SUCCESS(err); |
| 629 | |
| 630 | // typedef struct _XGL_IMAGE_VIEW_CREATE_INFO |
| 631 | // { |
| 632 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
| 633 | // const XGL_VOID* pNext; // Pointer to next structure |
| 634 | // XGL_IMAGE image; |
| 635 | // XGL_IMAGE_VIEW_TYPE viewType; |
| 636 | // XGL_FORMAT format; |
| 637 | // XGL_CHANNEL_MAPPING channels; |
| 638 | // XGL_IMAGE_SUBRESOURCE_RANGE subresourceRange; |
| 639 | // XGL_FLOAT minLod; |
| 640 | // } XGL_IMAGE_VIEW_CREATE_INFO; |
| 641 | XGL_IMAGE_VIEW_CREATE_INFO viewInfo = {}; |
| 642 | XGL_IMAGE_VIEW view; |
| 643 | viewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 644 | viewInfo.image = image; |
| 645 | viewInfo.viewType = XGL_IMAGE_VIEW_2D; |
| 646 | viewInfo.format = fmt; |
| 647 | |
| 648 | viewInfo.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 649 | viewInfo.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 650 | viewInfo.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 651 | viewInfo.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 652 | |
| 653 | viewInfo.subresourceRange.baseArraySlice = 0; |
| 654 | viewInfo.subresourceRange.arraySize = 1; |
| 655 | viewInfo.subresourceRange.baseMipLevel = 0; |
| 656 | viewInfo.subresourceRange.mipLevels = 1; |
| 657 | viewInfo.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 658 | |
| 659 | // XGL_RESULT XGLAPI xglCreateImageView( |
| 660 | // XGL_DEVICE device, |
| 661 | // const XGL_IMAGE_VIEW_CREATE_INFO* pCreateInfo, |
| 662 | // XGL_IMAGE_VIEW* pView); |
| 663 | |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 664 | err = xglCreateImageView(device(), &viewInfo, &view); |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 665 | ASSERT_XGL_SUCCESS(err) << "xglCreateImageView failed"; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 666 | |
| 667 | // TODO: Test image memory. |
| 668 | |
| 669 | // All done with image memory, clean up |
| 670 | ASSERT_XGL_SUCCESS(xglBindObjectMemory(image, XGL_NULL_HANDLE, 0)); |
| 671 | |
| 672 | ASSERT_XGL_SUCCESS(xglFreeMemory(image_mem)); |
| 673 | |
| 674 | ASSERT_XGL_SUCCESS(xglDestroyObject(image)); |
| 675 | } |
| 676 | |
| 677 | TEST_F(XglTest, CreateImage) { |
| 678 | CreateImageTest(); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 679 | } |
| 680 | |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 681 | void XglTest::CreateCommandBufferTest() |
| 682 | { |
| 683 | XGL_RESULT err; |
| 684 | XGL_CMD_BUFFER_CREATE_INFO info = {}; |
| 685 | XGL_CMD_BUFFER cmdBuffer; |
| 686 | |
| 687 | // typedef struct _XGL_CMD_BUFFER_CREATE_INFO |
| 688 | // { |
| 689 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO |
| 690 | // const XGL_VOID* pNext; |
| 691 | // XGL_QUEUE_TYPE queueType; |
| 692 | // XGL_FLAGS flags; |
| 693 | // } XGL_CMD_BUFFER_CREATE_INFO; |
| 694 | |
| 695 | info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 696 | info.queueType = XGL_QUEUE_TYPE_GRAPHICS; |
| 697 | err = xglCreateCommandBuffer(device(), &info, &cmdBuffer); |
| 698 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 699 | |
| 700 | ASSERT_XGL_SUCCESS(xglDestroyObject(cmdBuffer)); |
| 701 | } |
| 702 | |
| 703 | TEST_F(XglTest, TestComandBuffer) { |
| 704 | CreateCommandBufferTest(); |
| 705 | } |
| 706 | |
| 707 | void XglTest::CreateShader(XGL_SHADER *pshader) |
| 708 | { |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 709 | void *code; |
| 710 | uint32_t codeSize; |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 711 | struct icd_bil_header *pBIL; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 712 | XGL_RESULT err; |
| 713 | |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 714 | codeSize = sizeof(struct icd_bil_header) + 100; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 715 | code = malloc(codeSize); |
| 716 | ASSERT_TRUE(NULL != code) << "malloc failed!"; |
| 717 | |
| 718 | memset(code, 0, codeSize); |
| 719 | |
| 720 | // Indicate that this is BIL data. |
Chia-I Wu | 4115c89 | 2014-08-28 11:56:29 +0800 | [diff] [blame] | 721 | pBIL = (struct icd_bil_header *) code; |
| 722 | pBIL->magic = ICD_BIL_MAGIC; |
| 723 | pBIL->version = ICD_BIL_VERSION; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 724 | |
| 725 | // typedef struct _XGL_SHADER_CREATE_INFO |
| 726 | // { |
| 727 | // XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO |
| 728 | // const XGL_VOID* pNext; // Pointer to next structure |
| 729 | // XGL_SIZE codeSize; // Specified in bytes |
| 730 | // const XGL_VOID* pCode; |
| 731 | // XGL_FLAGS flags; // Reserved |
| 732 | // } XGL_SHADER_CREATE_INFO; |
| 733 | |
| 734 | XGL_SHADER_CREATE_INFO createInfo; |
| 735 | XGL_SHADER shader; |
| 736 | |
| 737 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 738 | createInfo.pNext = NULL; |
| 739 | createInfo.pCode = code; |
| 740 | createInfo.codeSize = codeSize; |
| 741 | createInfo.flags = 0; |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 742 | err = xglCreateShader(device(), &createInfo, &shader); |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 743 | ASSERT_XGL_SUCCESS(err); |
| 744 | |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 745 | *pshader = shader; |
| 746 | } |
| 747 | |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 748 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 749 | ::testing::InitGoogleTest(&argc, argv); |
Chia-I Wu | 1c9869e | 2014-12-28 14:27:28 +0800 | [diff] [blame^] | 750 | xgl_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 751 | return RUN_ALL_TESTS(); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 752 | } |