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 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 66 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 67 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 68 | class VkImageTest : public ::testing::Test { |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 69 | public: |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 70 | void CreateImage(uint32_t w, uint32_t h); |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 71 | void DestroyImage(); |
| 72 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 73 | void CreateImageView(VkImageViewCreateInfo* pCreateInfo, |
| 74 | VkImageView* pView); |
| 75 | void DestroyImageView(VkImageView imageView); |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 76 | VkDevice device() {return m_device->handle();} |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 77 | |
| 78 | protected: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 79 | vk_testing::Device *m_device; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 80 | VkApplicationInfo app_info; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 81 | VkPhysicalDevice objs[16]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 82 | uint32_t gpu_count; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 83 | VkInstance inst; |
| 84 | VkImage m_image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 85 | VkDeviceMemory m_image_mem; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 86 | |
| 87 | virtual void SetUp() { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 88 | VkResult err; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 89 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 90 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 91 | this->app_info.pNext = NULL; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 92 | this->app_info.pAppName = "base"; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 93 | this->app_info.appVersion = 1; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 94 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 95 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 96 | this->app_info.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 97 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 99 | inst_info.pNext = NULL; |
| 100 | inst_info.pAppInfo = &app_info; |
| 101 | inst_info.pAllocCb = NULL; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 102 | inst_info.layerCount = 0; |
| 103 | inst_info.ppEnabledLayerNames = NULL; |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 104 | inst_info.extensionCount = 0; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 105 | inst_info.ppEnabledExtensionNames = NULL; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 106 | err = vkCreateInstance(&inst_info, &this->inst); |
| 107 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 108 | err = vkEnumeratePhysicalDevices(this->inst, &this->gpu_count, NULL); |
| 109 | ASSERT_VK_SUCCESS(err); |
| 110 | ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs"; |
| 111 | err = vkEnumeratePhysicalDevices(this->inst, &this->gpu_count, objs); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 112 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 113 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 114 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | this->m_device = new vk_testing::Device(objs[0]); |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 116 | this->m_device->init(); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | virtual void TearDown() { |
Tony Barbour | 52bbc2b | 2015-07-21 09:10:44 -0600 | [diff] [blame] | 120 | delete this->m_device; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | vkDestroyInstance(this->inst); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 122 | } |
| 123 | }; |
| 124 | |
| 125 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 126 | void VkImageTest::CreateImage(uint32_t w, uint32_t h) |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 127 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 128 | VkResult err; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 129 | uint32_t mipCount; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 130 | VkFormat fmt; |
| 131 | VkFormatProperties image_fmt; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 132 | |
| 133 | mipCount = 0; |
| 134 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 135 | uint32_t _w = w; |
| 136 | uint32_t _h = h; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 137 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 138 | { |
| 139 | _w >>= 1; |
| 140 | _h >>= 1; |
| 141 | mipCount++; |
| 142 | } |
| 143 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 144 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 145 | // TODO: Pick known good format rather than just expect common format |
| 146 | /* |
| 147 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 148 | * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 149 | * an expectation that pData is a valid pointer. |
| 150 | * However, why include a returned size value? That implies that the |
| 151 | * amount of data may vary and that doesn't work well for using a |
| 152 | * fixed structure. |
| 153 | */ |
Courtney Goeltzenleuchter | 4da96aa | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 154 | err = vkGetPhysicalDeviceFormatProperties(this->objs[0], fmt, &image_fmt); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 155 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 156 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 157 | // typedef struct VkImageCreateInfo_ |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 158 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 159 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 160 | // const void* pNext; // Pointer to next structure. |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 161 | // VkImageType imageType; |
| 162 | // VkFormat format; |
| 163 | // VkExtent3D extent; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 164 | // uint32_t mipLevels; |
| 165 | // uint32_t arraySize; |
| 166 | // uint32_t samples; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 167 | // VkImageTiling tiling; |
| 168 | // VkFlags usage; // VkImageUsageFlags |
| 169 | // VkFlags flags; // VkImageCreateFlags |
| 170 | // } VkImageCreateInfo; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 171 | |
| 172 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 173 | VkImageCreateInfo imageCreateInfo = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 174 | imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 175 | imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 176 | imageCreateInfo.format = fmt; |
| 177 | imageCreateInfo.arraySize = 1; |
| 178 | imageCreateInfo.extent.width = w; |
| 179 | imageCreateInfo.extent.height = h; |
| 180 | imageCreateInfo.extent.depth = 1; |
| 181 | imageCreateInfo.mipLevels = mipCount; |
| 182 | imageCreateInfo.samples = 1; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 183 | if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { |
| 184 | imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR; |
Tony Barbour | bb6a413 | 2015-03-31 08:59:00 -0600 | [diff] [blame] | 185 | } |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 186 | else if (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) { |
| 187 | imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; |
Tony Barbour | bb6a413 | 2015-03-31 08:59:00 -0600 | [diff] [blame] | 188 | } |
| 189 | else { |
| 190 | ASSERT_TRUE(false) << "Cannot find supported tiling format - Exiting"; |
| 191 | } |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 192 | |
| 193 | // Image usage flags |
Courtney Goeltzenleuchter | c3b8eea | 2015-09-10 14:14:11 -0600 | [diff] [blame^] | 194 | // VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000008, |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 195 | //typedef enum VkImageUsageFlags_ |
| 196 | //{ |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 197 | // VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT = 0x00000001, // Can be used as a source of transfer operations |
| 198 | // VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT = 0x00000002, // Can be used as a destination of transfer operations |
| 199 | // VK_IMAGE_USAGE_SAMPLED_BIT = 0x00000004, // Can be sampled from (SAMPLED_IMAGE and COMBINED_IMAGE_SAMPLER descriptor types) |
| 200 | // VK_IMAGE_USAGE_STORAGE_BIT = 0x00000008, // Can be used as storage image (STORAGE_IMAGE descriptor type) |
| 201 | // VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000010, // Can be used as framebuffer color attachment |
Courtney Goeltzenleuchter | c3b8eea | 2015-09-10 14:14:11 -0600 | [diff] [blame^] | 202 | // VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000020, // Can be used as framebuffer depth/stencil attachment |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 203 | // VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT = 0x00000040, // Image data not needed outside of rendering |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 204 | // } VkImageUsageFlags; |
Cody Northrop | d0d701b | 2015-06-17 08:28:19 -0600 | [diff] [blame] | 205 | imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 206 | VK_IMAGE_USAGE_SAMPLED_BIT; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 207 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 208 | // VkResult VKAPI vkCreateImage( |
| 209 | // VkDevice device, |
| 210 | // const VkImageCreateInfo* pCreateInfo, |
| 211 | // VkImage* pImage); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 212 | err = vkCreateImage(device(), &imageCreateInfo, &m_image); |
| 213 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 214 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 215 | VkMemoryRequirements mem_req; |
Tony Barbour | 901f3bc | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 216 | |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 217 | VkMemoryAllocInfo mem_info = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 218 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Mark Lobodzinski | 97dcd04 | 2015-04-16 08:52:00 -0500 | [diff] [blame] | 219 | mem_info.pNext = NULL; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 220 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 221 | err = vkGetImageMemoryRequirements(device(), m_image, &mem_req); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 222 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 223 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 224 | ASSERT_NE(0, mem_req.size) << "vkGetObjectMemoryRequirements (Image): Failed - expect images to require memory"; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 225 | mem_info.allocationSize = mem_req.size; |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 226 | mem_info.memoryTypeIndex = 0; |
| 227 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 228 | err = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 229 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 230 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 231 | /* allocate memory */ |
| 232 | err = vkAllocMemory(device(), &mem_info, &m_image_mem); |
| 233 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | a9ae383 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 234 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 235 | /* bind memory */ |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 236 | err = vkBindImageMemory(device(), m_image, m_image_mem, 0); |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 237 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 238 | } |
| 239 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 240 | void VkImageTest::DestroyImage() |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 241 | { |
Mark Lobodzinski | 9212253 | 2015-09-10 11:43:00 -0600 | [diff] [blame] | 242 | // All done with image object and memory, clean up |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 243 | vkDestroyImage(device(), m_image); |
Mark Lobodzinski | 9212253 | 2015-09-10 11:43:00 -0600 | [diff] [blame] | 244 | vkFreeMemory(device(), m_image_mem); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 245 | } |
| 246 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 247 | void VkImageTest::CreateImageView(VkImageViewCreateInfo *pCreateInfo, |
| 248 | VkImageView *pView) |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 249 | { |
| 250 | pCreateInfo->image = this->m_image; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 251 | ASSERT_VK_SUCCESS(vkCreateImageView(device(), pCreateInfo, pView)); |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 252 | } |
| 253 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 254 | void VkImageTest::DestroyImageView(VkImageView imageView) |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 255 | { |
Mark Lobodzinski | 67b42b7 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 256 | vkDestroyImageView(device(), imageView); |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 257 | } |
| 258 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 259 | TEST_F(VkImageTest, CreateImageViewTest) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 260 | VkFormat fmt; |
| 261 | VkImageView imageView; |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 262 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 263 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 264 | |
| 265 | CreateImage(512, 256); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 266 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 267 | // typedef struct VkImageViewCreateInfo_ |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 268 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 269 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 270 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 271 | // VkImage image; |
| 272 | // VkImageViewType viewType; |
| 273 | // VkFormat format; |
| 274 | // VkChannelMapping channels; |
| 275 | // VkImageSubresourceRange subresourceRange; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 276 | // float minLod; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 277 | // } VkImageViewCreateInfo; |
| 278 | VkImageViewCreateInfo viewInfo = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 279 | viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 280 | viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 281 | viewInfo.format = fmt; |
| 282 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 283 | viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R; |
| 284 | viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G; |
| 285 | viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B; |
| 286 | viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 287 | |
| 288 | viewInfo.subresourceRange.baseArraySlice = 0; |
| 289 | viewInfo.subresourceRange.arraySize = 1; |
| 290 | viewInfo.subresourceRange.baseMipLevel = 0; |
| 291 | viewInfo.subresourceRange.mipLevels = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 292 | viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR; |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 294 | // VkResult VKAPI vkCreateImageView( |
| 295 | // VkDevice device, |
| 296 | // const VkImageViewCreateInfo* pCreateInfo, |
| 297 | // VkImageView* pView); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 298 | |
Courtney Goeltzenleuchter | 263e7f5 | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 299 | CreateImageView(&viewInfo, &imageView); |
| 300 | |
| 301 | DestroyImageView(imageView); |
Tony Barbour | 52bbc2b | 2015-07-21 09:10:44 -0600 | [diff] [blame] | 302 | DestroyImage(); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | int main(int argc, char **argv) { |
| 306 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 307 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | 62928d1 | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 308 | return RUN_ALL_TESTS(); |
| 309 | } |