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