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