blob: 0ff00afc199dfd3b330738e2633bb97babe7f707 [file] [log] [blame]
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -06001// 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 Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060031//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -060032// Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060033//
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.
51
52
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060053// Verify VK driver initialization
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060054
55#include <stdlib.h>
56#include <stdio.h>
57#include <stdbool.h>
58#include <string.h>
59
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060060#include <vulkan.h>
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060061#include "vktestbinding.h"
Chia-I Wufe84fe12014-12-29 15:39:23 +080062#include "test_common.h"
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060063
Jon Ashburn83a64252015-04-15 11:31:12 -060064#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
65
Tony Barbour6918cd52015-04-09 12:58:51 -060066class VkImageTest : public ::testing::Test {
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060067public:
Mark Lobodzinski17caf572015-01-29 08:55:56 -060068 void CreateImage(uint32_t w, uint32_t h);
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -060069 void DestroyImage();
70
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060071 void CreateImageView(VkImageViewCreateInfo* pCreateInfo,
72 VkImageView* pView);
73 void DestroyImageView(VkImageView imageView);
Chia-I Wuf368b602015-07-03 10:41:20 +080074 VkDevice device() {return m_device->handle();}
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060075
76protected:
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060077 vk_testing::Device *m_device;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060078 VkApplicationInfo app_info;
Tony Barbourd1c35722015-04-16 15:59:00 -060079 VkPhysicalDevice objs[16];
Mark Lobodzinski17caf572015-01-29 08:55:56 -060080 uint32_t gpu_count;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060081 VkInstance inst;
82 VkImage m_image;
Mark Lobodzinski23065352015-05-29 09:32:35 -050083 VkDeviceMemory m_image_mem;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060084
85 virtual void SetUp() {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060086 VkResult err;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060087
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060088 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060089 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080090 this->app_info.pApplicationName = "base";
91 this->app_info.applicationVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +080092 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -060093 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060094 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060095 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060096 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -060097 inst_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080098 inst_info.pApplicationInfo = &app_info;
Chia-I Wud50a7d72015-10-26 20:48:51 +080099 inst_info.enabledLayerNameCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600100 inst_info.ppEnabledLayerNames = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800101 inst_info.enabledExtensionNameCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600102 inst_info.ppEnabledExtensionNames = NULL;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800103 err = vkCreateInstance(&inst_info, NULL, &this->inst);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600104 ASSERT_VK_SUCCESS(err);
Jon Ashburn83a64252015-04-15 11:31:12 -0600105 err = vkEnumeratePhysicalDevices(this->inst, &this->gpu_count, NULL);
106 ASSERT_VK_SUCCESS(err);
107 ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs";
108 err = vkEnumeratePhysicalDevices(this->inst, &this->gpu_count, objs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600109 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -0600110 ASSERT_GE(this->gpu_count, (uint32_t) 1) << "No GPU available";
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600111
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600112 this->m_device = new vk_testing::Device(objs[0]);
Chia-I Wufe84fe12014-12-29 15:39:23 +0800113 this->m_device->init();
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600114 }
115
116 virtual void TearDown() {
Tony Barboure30ca4c2015-07-21 09:10:44 -0600117 delete this->m_device;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800118 vkDestroyInstance(this->inst, NULL);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600119 }
120};
121
122
Tony Barbour6918cd52015-04-09 12:58:51 -0600123void VkImageTest::CreateImage(uint32_t w, uint32_t h)
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600124{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600125 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600126 bool pass;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600127 uint32_t mipCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600128 VkFormat fmt;
129 VkFormatProperties image_fmt;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600130
131 mipCount = 0;
132
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600133 uint32_t _w = w;
134 uint32_t _h = h;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600135 while( ( _w > 0 ) || ( _h > 0 ) )
136 {
137 _w >>= 1;
138 _h >>= 1;
139 mipCount++;
140 }
141
Tony Barbourd1c35722015-04-16 15:59:00 -0600142 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600143 // 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 Barbourd1c35722015-04-16 15:59:00 -0600146 * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600147 * 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 */
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600152 vkGetPhysicalDeviceFormatProperties(this->objs[0], fmt, &image_fmt);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600153
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600154 // typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600155 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600156 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600157 // const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600158 // VkImageType imageType;
159 // VkFormat format;
160 // VkExtent3D extent;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600161 // uint32_t mipLevels;
162 // uint32_t arraySize;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800163 // VkSampleCountFlagBits samples;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600164 // VkImageTiling tiling;
165 // VkFlags usage; // VkImageUsageFlags
166 // VkFlags flags; // VkImageCreateFlags
167 // } VkImageCreateInfo;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600168
169
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600170 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600171 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600172 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600173 imageCreateInfo.format = fmt;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600174 imageCreateInfo.arrayLayers = 1;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600175 imageCreateInfo.extent.width = w;
176 imageCreateInfo.extent.height = h;
177 imageCreateInfo.extent.depth = 1;
178 imageCreateInfo.mipLevels = mipCount;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800179 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
Tony Barbour9f0d6b22015-10-05 12:43:30 -0600180 if ((image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) &&
181 (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
182 {
Tony Barbourd1c35722015-04-16 15:59:00 -0600183 imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
Tony Barboura8bea1d2015-03-31 08:59:00 -0600184 }
Tony Barbour9f0d6b22015-10-05 12:43:30 -0600185 else if ((image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) &&
186 (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
187 {
Tony Barbourd1c35722015-04-16 15:59:00 -0600188 imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barboura8bea1d2015-03-31 08:59:00 -0600189 }
190 else {
191 ASSERT_TRUE(false) << "Cannot find supported tiling format - Exiting";
192 }
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600193
194 // Image usage flags
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600195 // VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000008,
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600196 //typedef enum VkImageUsageFlags_
197 //{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800198 // VK_IMAGE_USAGE_TRANSFER_SRC_BIT = 0x00000001, // Can be used as a source of transfer operations
199 // VK_IMAGE_USAGE_TRANSFER_DST_BIT = 0x00000002, // Can be used as a destination of transfer operations
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600200 // VK_IMAGE_USAGE_SAMPLED_BIT = 0x00000004, // Can be sampled from (SAMPLED_IMAGE and COMBINED_IMAGE_SAMPLER descriptor types)
201 // VK_IMAGE_USAGE_STORAGE_BIT = 0x00000008, // Can be used as storage image (STORAGE_IMAGE descriptor type)
202 // VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000010, // Can be used as framebuffer color attachment
Courtney Goeltzenleuchter660f0ca2015-09-10 14:14:11 -0600203 // VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000020, // Can be used as framebuffer depth/stencil attachment
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600204 // VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT = 0x00000040, // Image data not needed outside of rendering
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600205 // } VkImageUsageFlags;
Cody Northropbb6fdb32015-06-17 08:28:19 -0600206 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
207 VK_IMAGE_USAGE_SAMPLED_BIT;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600208
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600209 // VkResult VKAPI vkCreateImage(
210 // VkDevice device,
211 // const VkImageCreateInfo* pCreateInfo,
212 // VkImage* pImage);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800213 err = vkCreateImage(device(), &imageCreateInfo, NULL, &m_image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600214 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600215
Mark Lobodzinski23065352015-05-29 09:32:35 -0500216 VkMemoryRequirements mem_req;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600217
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800218 VkMemoryAllocateInfo mem_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600219 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mark Lobodzinskie39f6952015-04-16 08:52:00 -0500220 mem_info.pNext = NULL;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600221
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600222 vkGetImageMemoryRequirements(device(), m_image, &mem_req);
Jon Ashburn7e781952015-01-16 09:37:43 -0700223
Tony Barbour59a47322015-06-24 16:06:58 -0600224 ASSERT_NE(0, mem_req.size) << "vkGetObjectMemoryRequirements (Image): Failed - expect images to require memory";
Mark Lobodzinski23065352015-05-29 09:32:35 -0500225 mem_info.allocationSize = mem_req.size;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600226 mem_info.memoryTypeIndex = 0;
227
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600228 pass = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0);
229 ASSERT_TRUE(pass);
Jon Ashburn7e781952015-01-16 09:37:43 -0700230
Mark Lobodzinski23065352015-05-29 09:32:35 -0500231 /* allocate memory */
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800232 err = vkAllocateMemory(device(), &mem_info, NULL, &m_image_mem);
Mark Lobodzinski23065352015-05-29 09:32:35 -0500233 ASSERT_VK_SUCCESS(err);
Jon Ashburn7e781952015-01-16 09:37:43 -0700234
Mark Lobodzinski23065352015-05-29 09:32:35 -0500235 /* bind memory */
Tony Barbour67e99152015-07-10 14:10:27 -0600236 err = vkBindImageMemory(device(), m_image, m_image_mem, 0);
Mark Lobodzinski23065352015-05-29 09:32:35 -0500237 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600238}
239
Tony Barbour6918cd52015-04-09 12:58:51 -0600240void VkImageTest::DestroyImage()
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600241{
Mark Lobodzinski4dacaa72015-09-10 11:43:00 -0600242 // All done with image object and memory, clean up
Chia-I Wuf7458c52015-10-26 21:10:41 +0800243 vkDestroyImage(device(), m_image, NULL);
244 vkFreeMemory(device(), m_image_mem, NULL);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600245}
246
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600247void VkImageTest::CreateImageView(VkImageViewCreateInfo *pCreateInfo,
248 VkImageView *pView)
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600249{
Courtney Goeltzenleuchter65fabb42015-09-24 17:47:18 -0600250 VkResult err;
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600251 pCreateInfo->image = this->m_image;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800252 err = vkCreateImageView(device(), pCreateInfo, NULL, pView);
Courtney Goeltzenleuchter65fabb42015-09-24 17:47:18 -0600253 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600254}
255
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600256void VkImageTest::DestroyImageView(VkImageView imageView)
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600257{
Chia-I Wuf7458c52015-10-26 21:10:41 +0800258 vkDestroyImageView(device(), imageView, NULL);
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600259}
260
Tony Barbour6918cd52015-04-09 12:58:51 -0600261TEST_F(VkImageTest, CreateImageViewTest) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600262 VkFormat fmt;
263 VkImageView imageView;
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600264
Tony Barbourd1c35722015-04-16 15:59:00 -0600265 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600266
267 CreateImage(512, 256);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600268
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600269 // typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600270 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600272 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600273 // VkImage image;
274 // VkImageViewType viewType;
275 // VkFormat format;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800276 // VkComponentMapping channels;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600277 // VkImageSubresourceRange subresourceRange;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600278 // float minLod;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600279 // } VkImageViewCreateInfo;
280 VkImageViewCreateInfo viewInfo = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600282 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600283 viewInfo.format = fmt;
284
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800285 viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
286 viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
287 viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
288 viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600289
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600290 viewInfo.subresourceRange.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800291 viewInfo.subresourceRange.layerCount = 1;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600292 viewInfo.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800293 viewInfo.subresourceRange.levelCount = 1;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600294 viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600295
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600296 // VkResult VKAPI vkCreateImageView(
297 // VkDevice device,
298 // const VkImageViewCreateInfo* pCreateInfo,
299 // VkImageView* pView);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600300
Courtney Goeltzenleuchter80ea59a2014-08-14 17:41:57 -0600301 CreateImageView(&viewInfo, &imageView);
302
303 DestroyImageView(imageView);
Tony Barboure30ca4c2015-07-21 09:10:44 -0600304 DestroyImage();
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600305}
306
307int main(int argc, char **argv) {
308 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600309 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchter3470bdf2014-08-13 17:53:57 -0600310 return RUN_ALL_TESTS();
311}