Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -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 | |
| 30 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | // VK tests |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 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 | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 54 | // Verify VK driver initialization |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 55 | |
| 56 | #include <stdlib.h> |
| 57 | #include <stdio.h> |
| 58 | #include <stdbool.h> |
| 59 | #include <string.h> |
| 60 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 61 | #include <vulkan.h> |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 62 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | #include "vktestbinding.h" |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 64 | #include "test_common.h" |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 65 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame^] | 66 | class VkImageTest : public ::testing::Test { |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 67 | public: |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 68 | void CreateImage(uint32_t w, uint32_t h); |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 69 | void DestroyImage(); |
| 70 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 71 | void CreateImageView(VK_IMAGE_VIEW_CREATE_INFO* pCreateInfo, |
| 72 | VK_IMAGE_VIEW* pView); |
| 73 | void DestroyImageView(VK_IMAGE_VIEW imageView); |
| 74 | VK_DEVICE device() {return m_device->obj();} |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 75 | |
| 76 | protected: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 77 | vk_testing::Device *m_device; |
| 78 | VK_APPLICATION_INFO app_info; |
| 79 | VK_PHYSICAL_GPU objs[VK_MAX_PHYSICAL_GPUS]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 80 | uint32_t gpu_count; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 81 | VK_INSTANCE inst; |
| 82 | VK_IMAGE m_image; |
| 83 | VK_GPU_MEMORY *m_image_mem; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 84 | uint32_t m_num_mem; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 85 | |
| 86 | virtual void SetUp() { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 87 | VK_RESULT err; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 88 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 89 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 90 | this->app_info.pNext = NULL; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 91 | this->app_info.pAppName = "base"; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 92 | this->app_info.appVersion = 1; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 93 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 94 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 95 | this->app_info.apiVersion = VK_API_VERSION; |
| 96 | VK_INSTANCE_CREATE_INFO inst_info = {}; |
| 97 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 98 | inst_info.pNext = NULL; |
| 99 | inst_info.pAppInfo = &app_info; |
| 100 | inst_info.pAllocCb = NULL; |
| 101 | inst_info.extensionCount = 0; |
| 102 | inst_info.ppEnabledExtensionNames = NULL; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | err = vkCreateInstance(&inst_info, &this->inst); |
| 104 | ASSERT_VK_SUCCESS(err); |
| 105 | err = vkEnumerateGpus(this->inst, VK_MAX_PHYSICAL_GPUS, |
Jon Ashburn | 670b176 | 2015-01-29 15:48:00 -0700 | [diff] [blame] | 106 | &this->gpu_count, objs); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 107 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 108 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 109 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 110 | this->m_device = new vk_testing::Device(objs[0]); |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 111 | this->m_device->init(); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | virtual void TearDown() { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | vkDestroyInstance(this->inst); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 116 | } |
| 117 | }; |
| 118 | |
| 119 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame^] | 120 | void VkImageTest::CreateImage(uint32_t w, uint32_t h) |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 121 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | VK_RESULT err; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 123 | uint32_t mipCount; |
| 124 | size_t size; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 125 | VK_FORMAT fmt; |
| 126 | VK_FORMAT_PROPERTIES image_fmt; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 127 | |
| 128 | mipCount = 0; |
| 129 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 130 | uint32_t _w = w; |
| 131 | uint32_t _h = h; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 132 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 133 | { |
| 134 | _w >>= 1; |
| 135 | _h >>= 1; |
| 136 | mipCount++; |
| 137 | } |
| 138 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 139 | fmt = VK_FMT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 140 | // TODO: Pick known good format rather than just expect common format |
| 141 | /* |
| 142 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 143 | * We're not requesting VK_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 144 | * an expectation that pData is a valid pointer. |
| 145 | * However, why include a returned size value? That implies that the |
| 146 | * amount of data may vary and that doesn't work well for using a |
| 147 | * fixed structure. |
| 148 | */ |
Jon Ashburn | b8e4389 | 2014-09-25 14:36:58 -0600 | [diff] [blame] | 149 | size = sizeof(image_fmt); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 150 | err = vkGetFormatInfo(this->device(), fmt, |
| 151 | VK_INFO_TYPE_FORMAT_PROPERTIES, |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 152 | &size, &image_fmt); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 153 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 154 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 155 | // typedef struct _VK_IMAGE_CREATE_INFO |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 156 | // { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 157 | // VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 158 | // const void* pNext; // Pointer to next structure. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 159 | // VK_IMAGE_TYPE imageType; |
| 160 | // VK_FORMAT format; |
| 161 | // VK_EXTENT3D extent; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 162 | // uint32_t mipLevels; |
| 163 | // uint32_t arraySize; |
| 164 | // uint32_t samples; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 165 | // VK_IMAGE_TILING tiling; |
| 166 | // VK_FLAGS usage; // VK_IMAGE_USAGE_FLAGS |
| 167 | // VK_FLAGS flags; // VK_IMAGE_CREATE_FLAGS |
| 168 | // } VK_IMAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 169 | |
| 170 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 171 | VK_IMAGE_CREATE_INFO imageCreateInfo = {}; |
| 172 | imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 173 | imageCreateInfo.imageType = VK_IMAGE_2D; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 174 | imageCreateInfo.format = fmt; |
| 175 | imageCreateInfo.arraySize = 1; |
| 176 | imageCreateInfo.extent.width = w; |
| 177 | imageCreateInfo.extent.height = h; |
| 178 | imageCreateInfo.extent.depth = 1; |
| 179 | imageCreateInfo.mipLevels = mipCount; |
| 180 | imageCreateInfo.samples = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 181 | if (image_fmt.linearTilingFeatures & VK_FORMAT_IMAGE_SHADER_READ_BIT) { |
| 182 | imageCreateInfo.tiling = VK_LINEAR_TILING; |
Tony Barbour | bb6a413 | 2015-03-31 08:59:00 -0600 | [diff] [blame] | 183 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 184 | else if (image_fmt.optimalTilingFeatures & VK_FORMAT_IMAGE_SHADER_READ_BIT) { |
| 185 | imageCreateInfo.tiling = VK_OPTIMAL_TILING; |
Tony Barbour | bb6a413 | 2015-03-31 08:59:00 -0600 | [diff] [blame] | 186 | } |
| 187 | else { |
| 188 | ASSERT_TRUE(false) << "Cannot find supported tiling format - Exiting"; |
| 189 | } |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 190 | |
| 191 | // Image usage flags |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | // typedef enum _VK_IMAGE_USAGE_FLAGS |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 193 | // { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 194 | // VK_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001, |
| 195 | // VK_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002, |
| 196 | // VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004, |
| 197 | // VK_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008, |
| 198 | // } VK_IMAGE_USAGE_FLAGS; |
| 199 | imageCreateInfo.usage = VK_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 200 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 201 | // VK_RESULT VKAPI vkCreateImage( |
| 202 | // VK_DEVICE device, |
| 203 | // const VK_IMAGE_CREATE_INFO* pCreateInfo, |
| 204 | // VK_IMAGE* pImage); |
| 205 | err = vkCreateImage(device(), &imageCreateInfo, &m_image); |
| 206 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 207 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 208 | VK_MEMORY_REQUIREMENTS *mem_req; |
| 209 | size_t mem_reqs_size = sizeof(VK_MEMORY_REQUIREMENTS); |
| 210 | VK_IMAGE_MEMORY_REQUIREMENTS img_reqs; |
| 211 | size_t img_reqs_size = sizeof(VK_IMAGE_MEMORY_REQUIREMENTS); |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 212 | uint32_t num_allocations = 0; |
| 213 | size_t num_alloc_size = sizeof(num_allocations); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 214 | VK_MEMORY_ALLOC_IMAGE_INFO img_alloc = {}; |
| 215 | img_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO; |
Tony Barbour | 901f3bc | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 216 | img_alloc.pNext = NULL; |
| 217 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 218 | VK_MEMORY_ALLOC_INFO mem_info = {}; |
| 219 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 220 | mem_info.pNext = &img_alloc; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 221 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 222 | err = vkGetObjectInfo(m_image, VK_INFO_TYPE_MEMORY_ALLOCATION_COUNT, |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 223 | &num_alloc_size, &num_allocations); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 224 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 225 | ASSERT_EQ(num_alloc_size,sizeof(num_allocations)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 226 | mem_req = (VK_MEMORY_REQUIREMENTS *) malloc(num_allocations * sizeof(VK_MEMORY_REQUIREMENTS)); |
| 227 | m_image_mem = (VK_GPU_MEMORY *) malloc(num_allocations * sizeof(VK_GPU_MEMORY)); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 228 | m_num_mem = num_allocations; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 229 | err = vkGetObjectInfo(m_image, |
| 230 | VK_INFO_TYPE_MEMORY_REQUIREMENTS, |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 231 | &mem_reqs_size, mem_req); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 232 | ASSERT_VK_SUCCESS(err); |
| 233 | ASSERT_EQ(mem_reqs_size, num_allocations * sizeof(VK_MEMORY_REQUIREMENTS)); |
| 234 | err = vkGetObjectInfo(m_image, |
| 235 | VK_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS, |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 236 | &img_reqs_size, &img_reqs); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 237 | ASSERT_VK_SUCCESS(err); |
| 238 | ASSERT_EQ(img_reqs_size, sizeof(VK_IMAGE_MEMORY_REQUIREMENTS)); |
Jon Ashburn | c6ae13d | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 239 | img_alloc.usage = img_reqs.usage; |
| 240 | img_alloc.formatClass = img_reqs.formatClass; |
| 241 | img_alloc.samples = img_reqs.samples; |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 242 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 243 | for (uint32_t i = 0; i < num_allocations; i ++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 244 | ASSERT_NE(0, mem_req[i].size) << "vkGetObjectInfo (Image): Failed - expect images to require memory"; |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 245 | mem_info.allocationSize = mem_req[i].size; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 246 | mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT; |
| 247 | mem_info.memType = VK_MEMORY_TYPE_IMAGE; |
| 248 | mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL; |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 249 | |
| 250 | /* allocate memory */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 251 | err = vkAllocMemory(device(), &mem_info, &m_image_mem[i]); |
| 252 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 253 | |
| 254 | /* bind memory */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 255 | err = vkBindObjectMemory(m_image, i, m_image_mem[i], 0); |
| 256 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 257 | } |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 258 | } |
| 259 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame^] | 260 | void VkImageTest::DestroyImage() |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 261 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 262 | VK_RESULT err; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 263 | // All done with image memory, clean up |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 264 | ASSERT_VK_SUCCESS(vkBindObjectMemory(m_image, 0, VK_NULL_HANDLE, 0)); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 265 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 266 | for (uint32_t i = 0 ; i < m_num_mem; i++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 267 | err = vkFreeMemory(m_image_mem[i]); |
| 268 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 271 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 272 | ASSERT_VK_SUCCESS(vkDestroyObject(m_image)); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 273 | } |
| 274 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame^] | 275 | void VkImageTest::CreateImageView(VK_IMAGE_VIEW_CREATE_INFO *pCreateInfo, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 276 | VK_IMAGE_VIEW *pView) |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 277 | { |
| 278 | pCreateInfo->image = this->m_image; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 279 | ASSERT_VK_SUCCESS(vkCreateImageView(device(), pCreateInfo, pView)); |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 280 | } |
| 281 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame^] | 282 | void VkImageTest::DestroyImageView(VK_IMAGE_VIEW imageView) |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 283 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 284 | ASSERT_VK_SUCCESS(vkDestroyObject(imageView)); |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 285 | } |
| 286 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame^] | 287 | TEST_F(VkImageTest, CreateImageViewTest) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 288 | VK_FORMAT fmt; |
| 289 | VK_IMAGE_VIEW imageView; |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 290 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 291 | fmt = VK_FMT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 292 | |
| 293 | CreateImage(512, 256); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 294 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 295 | // typedef struct _VK_IMAGE_VIEW_CREATE_INFO |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 296 | // { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 297 | // VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 298 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 299 | // VK_IMAGE image; |
| 300 | // VK_IMAGE_VIEW_TYPE viewType; |
| 301 | // VK_FORMAT format; |
| 302 | // VK_CHANNEL_MAPPING channels; |
| 303 | // VK_IMAGE_SUBRESOURCE_RANGE subresourceRange; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 304 | // float minLod; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 305 | // } VK_IMAGE_VIEW_CREATE_INFO; |
| 306 | VK_IMAGE_VIEW_CREATE_INFO viewInfo = {}; |
| 307 | viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 308 | viewInfo.viewType = VK_IMAGE_VIEW_2D; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 309 | viewInfo.format = fmt; |
| 310 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 311 | viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R; |
| 312 | viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G; |
| 313 | viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B; |
| 314 | viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 315 | |
| 316 | viewInfo.subresourceRange.baseArraySlice = 0; |
| 317 | viewInfo.subresourceRange.arraySize = 1; |
| 318 | viewInfo.subresourceRange.baseMipLevel = 0; |
| 319 | viewInfo.subresourceRange.mipLevels = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 320 | viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 321 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 322 | // VK_RESULT VKAPI vkCreateImageView( |
| 323 | // VK_DEVICE device, |
| 324 | // const VK_IMAGE_VIEW_CREATE_INFO* pCreateInfo, |
| 325 | // VK_IMAGE_VIEW* pView); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 326 | |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 327 | CreateImageView(&viewInfo, &imageView); |
| 328 | |
| 329 | DestroyImageView(imageView); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | int main(int argc, char **argv) { |
| 333 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 334 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 335 | return RUN_ALL_TESTS(); |
| 336 | } |