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