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