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 | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 31 | // |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 32 | // Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 33 | // |
| 34 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 35 | // copy of this software and associated documentation files (the "Software"), |
| 36 | // to deal in the Software without restriction, including without limitation |
| 37 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 38 | // and/or sell copies of the Software, and to permit persons to whom the |
| 39 | // Software is furnished to do so, subject to the following conditions: |
| 40 | // |
| 41 | // The above copyright notice and this permission notice shall be included |
| 42 | // in all copies or substantial portions of the Software. |
| 43 | // |
| 44 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 45 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 46 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 47 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 48 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 49 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 50 | // DEALINGS IN THE SOFTWARE. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 51 | // |
| 52 | // Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 53 | // Author: Jon Ashburn <jon@lunarg.com> |
| 54 | // Author: Tony Barbour <tony@LunarG.com> |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 55 | |
| 56 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 57 | // Verify VK driver initialization |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 58 | |
| 59 | #include <stdlib.h> |
| 60 | #include <stdio.h> |
| 61 | #include <stdbool.h> |
| 62 | #include <string.h> |
| 63 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 64 | #include <vulkan/vulkan.h> |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 65 | #include "vktestbinding.h" |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 66 | #include "test_common.h" |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 67 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 68 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 69 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 70 | class VkImageTest : public ::testing::Test { |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 71 | public: |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 72 | void CreateImage(uint32_t w, uint32_t h); |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 73 | void DestroyImage(); |
| 74 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 75 | void CreateImageView(VkImageViewCreateInfo* pCreateInfo, |
| 76 | VkImageView* pView); |
| 77 | void DestroyImageView(VkImageView imageView); |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 78 | VkDevice device() {return m_device->handle();} |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 79 | |
| 80 | protected: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 81 | vk_testing::Device *m_device; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 82 | VkApplicationInfo app_info; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 83 | VkPhysicalDevice objs[16]; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 84 | uint32_t gpu_count; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 85 | VkInstance inst; |
| 86 | VkImage m_image; |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 87 | VkDeviceMemory m_image_mem; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 88 | |
| 89 | virtual void SetUp() { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 90 | VkResult err; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 91 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 92 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 93 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 94 | this->app_info.pApplicationName = "base"; |
| 95 | this->app_info.applicationVersion = 1; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 96 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 97 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 98 | this->app_info.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 99 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 100 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 101 | inst_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 102 | inst_info.pApplicationInfo = &app_info; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 103 | inst_info.enabledLayerNameCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 104 | inst_info.ppEnabledLayerNames = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 105 | inst_info.enabledExtensionNameCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 106 | inst_info.ppEnabledExtensionNames = NULL; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 107 | err = vkCreateInstance(&inst_info, NULL, &this->inst); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 108 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 109 | err = vkEnumeratePhysicalDevices(this->inst, &this->gpu_count, NULL); |
| 110 | ASSERT_VK_SUCCESS(err); |
| 111 | ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs"; |
| 112 | err = vkEnumeratePhysicalDevices(this->inst, &this->gpu_count, objs); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 113 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 114 | ASSERT_GE(this->gpu_count, (uint32_t) 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 115 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 116 | this->m_device = new vk_testing::Device(objs[0]); |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 117 | this->m_device->init(); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | virtual void TearDown() { |
Tony Barbour | e30ca4c | 2015-07-21 09:10:44 -0600 | [diff] [blame] | 121 | delete this->m_device; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 122 | vkDestroyInstance(this->inst, NULL); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 123 | } |
| 124 | }; |
| 125 | |
| 126 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 127 | void VkImageTest::CreateImage(uint32_t w, uint32_t h) |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 128 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 129 | VkResult err; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 130 | bool pass; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 131 | uint32_t mipCount; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 132 | VkFormat fmt; |
| 133 | VkFormatProperties image_fmt; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 134 | |
| 135 | mipCount = 0; |
| 136 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 137 | uint32_t _w = w; |
| 138 | uint32_t _h = h; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 139 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 140 | { |
| 141 | _w >>= 1; |
| 142 | _h >>= 1; |
| 143 | mipCount++; |
| 144 | } |
| 145 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 146 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 147 | // TODO: Pick known good format rather than just expect common format |
| 148 | /* |
| 149 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 150 | * 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] | 151 | * an expectation that pData is a valid pointer. |
| 152 | * However, why include a returned size value? That implies that the |
| 153 | * amount of data may vary and that doesn't work well for using a |
| 154 | * fixed structure. |
| 155 | */ |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 156 | vkGetPhysicalDeviceFormatProperties(this->objs[0], fmt, &image_fmt); |
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; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 167 | // VkSampleCountFlagBits 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; |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 178 | imageCreateInfo.arrayLayers = 1; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 179 | imageCreateInfo.extent.width = w; |
| 180 | imageCreateInfo.extent.height = h; |
| 181 | imageCreateInfo.extent.depth = 1; |
| 182 | imageCreateInfo.mipLevels = mipCount; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 183 | imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
Tony Barbour | 9f0d6b2 | 2015-10-05 12:43:30 -0600 | [diff] [blame] | 184 | if ((image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && |
| 185 | (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) |
| 186 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 187 | imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR; |
Tony Barbour | a8bea1d | 2015-03-31 08:59:00 -0600 | [diff] [blame] | 188 | } |
Tony Barbour | 9f0d6b2 | 2015-10-05 12:43:30 -0600 | [diff] [blame] | 189 | else if ((image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) && |
| 190 | (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) |
| 191 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 192 | imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; |
Tony Barbour | a8bea1d | 2015-03-31 08:59:00 -0600 | [diff] [blame] | 193 | } |
| 194 | else { |
| 195 | ASSERT_TRUE(false) << "Cannot find supported tiling format - Exiting"; |
| 196 | } |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 197 | |
| 198 | // Image usage flags |
Courtney Goeltzenleuchter | 660f0ca | 2015-09-10 14:14:11 -0600 | [diff] [blame] | 199 | // VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000008, |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 200 | //typedef enum VkImageUsageFlags_ |
| 201 | //{ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 202 | // VK_IMAGE_USAGE_TRANSFER_SRC_BIT = 0x00000001, // Can be used as a source of transfer operations |
| 203 | // VK_IMAGE_USAGE_TRANSFER_DST_BIT = 0x00000002, // Can be used as a destination of transfer operations |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 204 | // VK_IMAGE_USAGE_SAMPLED_BIT = 0x00000004, // Can be sampled from (SAMPLED_IMAGE and COMBINED_IMAGE_SAMPLER descriptor types) |
| 205 | // VK_IMAGE_USAGE_STORAGE_BIT = 0x00000008, // Can be used as storage image (STORAGE_IMAGE descriptor type) |
| 206 | // VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000010, // Can be used as framebuffer color attachment |
Courtney Goeltzenleuchter | 660f0ca | 2015-09-10 14:14:11 -0600 | [diff] [blame] | 207 | // VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000020, // Can be used as framebuffer depth/stencil attachment |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 208 | // 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] | 209 | // } VkImageUsageFlags; |
Cody Northrop | bb6fdb3 | 2015-06-17 08:28:19 -0600 | [diff] [blame] | 210 | imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 211 | VK_IMAGE_USAGE_SAMPLED_BIT; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 212 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 213 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 214 | // VkDevice device, |
| 215 | // const VkImageCreateInfo* pCreateInfo, |
| 216 | // VkImage* pImage); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 217 | err = vkCreateImage(device(), &imageCreateInfo, NULL, &m_image); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 218 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 219 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 220 | VkMemoryRequirements mem_req; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 221 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 222 | VkMemoryAllocateInfo mem_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 223 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Mark Lobodzinski | e39f695 | 2015-04-16 08:52:00 -0500 | [diff] [blame] | 224 | mem_info.pNext = NULL; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 225 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 226 | vkGetImageMemoryRequirements(device(), m_image, &mem_req); |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 227 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 228 | ASSERT_NE(0, mem_req.size) << "vkGetObjectMemoryRequirements (Image): Failed - expect images to require memory"; |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 229 | mem_info.allocationSize = mem_req.size; |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 230 | mem_info.memoryTypeIndex = 0; |
| 231 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 232 | pass = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0); |
| 233 | ASSERT_TRUE(pass); |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 234 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 235 | /* allocate memory */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 236 | err = vkAllocateMemory(device(), &mem_info, NULL, &m_image_mem); |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 237 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 7e78195 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 238 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 239 | /* bind memory */ |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 240 | err = vkBindImageMemory(device(), m_image, m_image_mem, 0); |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 241 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 242 | } |
| 243 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 244 | void VkImageTest::DestroyImage() |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 245 | { |
Mark Lobodzinski | 4dacaa7 | 2015-09-10 11:43:00 -0600 | [diff] [blame] | 246 | // All done with image object and memory, clean up |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 247 | vkDestroyImage(device(), m_image, NULL); |
| 248 | vkFreeMemory(device(), m_image_mem, NULL); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 249 | } |
| 250 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 251 | void VkImageTest::CreateImageView(VkImageViewCreateInfo *pCreateInfo, |
| 252 | VkImageView *pView) |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 253 | { |
Courtney Goeltzenleuchter | 65fabb4 | 2015-09-24 17:47:18 -0600 | [diff] [blame] | 254 | VkResult err; |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 255 | pCreateInfo->image = this->m_image; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 256 | err = vkCreateImageView(device(), pCreateInfo, NULL, pView); |
Courtney Goeltzenleuchter | 65fabb4 | 2015-09-24 17:47:18 -0600 | [diff] [blame] | 257 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 258 | } |
| 259 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 260 | void VkImageTest::DestroyImageView(VkImageView imageView) |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 261 | { |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 262 | vkDestroyImageView(device(), imageView, NULL); |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 263 | } |
| 264 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 265 | TEST_F(VkImageTest, CreateImageViewTest) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 266 | VkFormat fmt; |
| 267 | VkImageView imageView; |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 268 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 269 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 270 | |
| 271 | CreateImage(512, 256); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 272 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 273 | // typedef struct VkImageViewCreateInfo_ |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 274 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 275 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 276 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 277 | // VkImage image; |
| 278 | // VkImageViewType viewType; |
| 279 | // VkFormat format; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 280 | // VkComponentMapping channels; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 281 | // VkImageSubresourceRange subresourceRange; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 282 | // float minLod; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 283 | // } VkImageViewCreateInfo; |
| 284 | VkImageViewCreateInfo viewInfo = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 285 | viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 286 | viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 287 | viewInfo.format = fmt; |
| 288 | |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 289 | viewInfo.components.r = VK_COMPONENT_SWIZZLE_R; |
| 290 | viewInfo.components.g = VK_COMPONENT_SWIZZLE_G; |
| 291 | viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; |
| 292 | viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 294 | viewInfo.subresourceRange.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 295 | viewInfo.subresourceRange.layerCount = 1; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 296 | viewInfo.subresourceRange.baseMipLevel = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 297 | viewInfo.subresourceRange.levelCount = 1; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 298 | viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 299 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 300 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 301 | // VkDevice device, |
| 302 | // const VkImageViewCreateInfo* pCreateInfo, |
| 303 | // VkImageView* pView); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 304 | |
Courtney Goeltzenleuchter | 80ea59a | 2014-08-14 17:41:57 -0600 | [diff] [blame] | 305 | CreateImageView(&viewInfo, &imageView); |
| 306 | |
| 307 | DestroyImageView(imageView); |
Tony Barbour | e30ca4c | 2015-07-21 09:10:44 -0600 | [diff] [blame] | 308 | DestroyImage(); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | int main(int argc, char **argv) { |
| 312 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 313 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | 3470bdf | 2014-08-13 17:53:57 -0600 | [diff] [blame] | 314 | return RUN_ALL_TESTS(); |
| 315 | } |