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