blob: ee4e55e02298c271e505777cb896e6e185ae76c8 [file] [log] [blame]
Courtney Goeltzenleuchter62928d12014-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060032//
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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060054// Verify VK driver initialization
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060055
56#include <stdlib.h>
57#include <stdio.h>
58#include <stdbool.h>
59#include <string.h>
60
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060061#include <vulkan.h>
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060062#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060063#include "vktestbinding.h"
Chia-I Wu3b78d312014-12-29 15:39:23 +080064#include "test_common.h"
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060065
Tony Barbour01999182015-04-09 12:58:51 -060066class VkImageTest : public ::testing::Test {
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060067public:
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060068 void CreateImage(uint32_t w, uint32_t h);
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -060069 void DestroyImage();
70
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060071 void CreateImageView(VkImageViewCreateInfo* pCreateInfo,
72 VkImageView* pView);
73 void DestroyImageView(VkImageView imageView);
74 VkDevice device() {return m_device->obj();}
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060075
76protected:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060077 vk_testing::Device *m_device;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060078 VkApplicationInfo app_info;
79 VkPhysicalGpu objs[VK_MAX_PHYSICAL_GPUS];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060080 uint32_t gpu_count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060081 VkInstance inst;
82 VkImage m_image;
83 VkGpuMemory *m_image_mem;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060084 uint32_t m_num_mem;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060085
86 virtual void SetUp() {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060087 VkResult err;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060088
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060089 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060090 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080091 this->app_info.pAppName = "base";
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060092 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080093 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -060094 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060095 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060096 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060097 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -060098 inst_info.pNext = NULL;
99 inst_info.pAppInfo = &app_info;
100 inst_info.pAllocCb = NULL;
101 inst_info.extensionCount = 0;
102 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600103 err = vkCreateInstance(&inst_info, &this->inst);
104 ASSERT_VK_SUCCESS(err);
105 err = vkEnumerateGpus(this->inst, VK_MAX_PHYSICAL_GPUS,
Jon Ashburn670b1762015-01-29 15:48:00 -0700106 &this->gpu_count, objs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600107 ASSERT_VK_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700108 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600109
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110 this->m_device = new vk_testing::Device(objs[0]);
Chia-I Wu3b78d312014-12-29 15:39:23 +0800111 this->m_device->init();
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600112 }
113
114 virtual void TearDown() {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600115 vkDestroyInstance(this->inst);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600116 }
117};
118
119
Tony Barbour01999182015-04-09 12:58:51 -0600120void VkImageTest::CreateImage(uint32_t w, uint32_t h)
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600121{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600122 VkResult err;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600123 uint32_t mipCount;
124 size_t size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600125 VkFormat fmt;
126 VkFormatProperties image_fmt;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600127
128 mipCount = 0;
129
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600130 uint32_t _w = w;
131 uint32_t _h = h;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600132 while( ( _w > 0 ) || ( _h > 0 ) )
133 {
134 _w >>= 1;
135 _h >>= 1;
136 mipCount++;
137 }
138
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139 fmt = VK_FMT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600140 // TODO: Pick known good format rather than just expect common format
141 /*
142 * XXX: What should happen if given NULL HANDLE for the pData argument?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600143 * We're not requesting VK_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600144 * an expectation that pData is a valid pointer.
145 * However, why include a returned size value? That implies that the
146 * amount of data may vary and that doesn't work well for using a
147 * fixed structure.
148 */
Jon Ashburnb8e43892014-09-25 14:36:58 -0600149 size = sizeof(image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600150 err = vkGetFormatInfo(this->device(), fmt,
151 VK_INFO_TYPE_FORMAT_PROPERTIES,
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600152 &size, &image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600154
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600155 // typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600156 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600157 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600158 // const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600159 // VkImageType imageType;
160 // VkFormat format;
161 // VkExtent3D extent;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600162 // uint32_t mipLevels;
163 // uint32_t arraySize;
164 // uint32_t samples;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600165 // VkImageTiling tiling;
166 // VkFlags usage; // VkImageUsageFlags
167 // VkFlags flags; // VkImageCreateFlags
168 // } VkImageCreateInfo;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600169
170
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600171 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600172 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
173 imageCreateInfo.imageType = VK_IMAGE_2D;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600174 imageCreateInfo.format = fmt;
175 imageCreateInfo.arraySize = 1;
176 imageCreateInfo.extent.width = w;
177 imageCreateInfo.extent.height = h;
178 imageCreateInfo.extent.depth = 1;
179 imageCreateInfo.mipLevels = mipCount;
180 imageCreateInfo.samples = 1;
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600181 if (image_fmt.linearTilingFeatures & VK_FORMAT_SAMPLED_IMAGE_BIT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600182 imageCreateInfo.tiling = VK_LINEAR_TILING;
Tony Barbourbb6a4132015-03-31 08:59:00 -0600183 }
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600184 else if (image_fmt.optimalTilingFeatures & VK_FORMAT_SAMPLED_IMAGE_BIT) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600185 imageCreateInfo.tiling = VK_OPTIMAL_TILING;
Tony Barbourbb6a4132015-03-31 08:59:00 -0600186 }
187 else {
188 ASSERT_TRUE(false) << "Cannot find supported tiling format - Exiting";
189 }
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600190
191 // Image usage flags
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192 // VK_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008,
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600193 //typedef enum VkImageUsageFlags_
194 //{
195 // VK_IMAGE_USAGE_GENERAL = 0x00000000, // no special usage
196 // VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT = 0x00000001, // Can be used as a source of transfer operations
197 // VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT = 0x00000002, // Can be used as a destination of transfer operations
198 // VK_IMAGE_USAGE_SAMPLED_BIT = 0x00000004, // Can be sampled from (SAMPLED_IMAGE and COMBINED_IMAGE_SAMPLER descriptor types)
199 // VK_IMAGE_USAGE_STORAGE_BIT = 0x00000008, // Can be used as storage image (STORAGE_IMAGE descriptor type)
200 // VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000010, // Can be used as framebuffer color attachment
201 // VK_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000020, // Can be used as framebuffer depth/stencil attachment
202 // VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT = 0x00000040, // Image data not needed outside of rendering
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600203 // } VkImageUsageFlags;
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600204 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600205
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600206 // VkResult VKAPI vkCreateImage(
207 // VkDevice device,
208 // const VkImageCreateInfo* pCreateInfo,
209 // VkImage* pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600210 err = vkCreateImage(device(), &imageCreateInfo, &m_image);
211 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600212
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600213 VkMemoryRequirements *mem_req;
214 size_t mem_reqs_size = sizeof(VkMemoryRequirements);
215 VkImageMemoryRequirements img_reqs;
216 size_t img_reqs_size = sizeof(VkImageMemoryRequirements);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600217 uint32_t num_allocations = 0;
218 size_t num_alloc_size = sizeof(num_allocations);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600219 VkMemoryAllocImageInfo img_alloc = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600220 img_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO;
Tony Barbour901f3bc2015-04-01 17:10:07 -0600221 img_alloc.pNext = NULL;
222
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600223 VkMemoryAllocInfo mem_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600224 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700225 mem_info.pNext = &img_alloc;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600226
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600227 err = vkGetObjectInfo(m_image, VK_INFO_TYPE_MEMORY_ALLOCATION_COUNT,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700228 &num_alloc_size, &num_allocations);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600229 ASSERT_VK_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700230 ASSERT_EQ(num_alloc_size,sizeof(num_allocations));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600231 mem_req = (VkMemoryRequirements *) malloc(num_allocations * sizeof(VkMemoryRequirements));
232 m_image_mem = (VkGpuMemory *) malloc(num_allocations * sizeof(VkGpuMemory));
Jon Ashburna9ae3832015-01-16 09:37:43 -0700233 m_num_mem = num_allocations;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600234 err = vkGetObjectInfo(m_image,
235 VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Jon Ashburna9ae3832015-01-16 09:37:43 -0700236 &mem_reqs_size, mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600237 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 ASSERT_EQ(mem_reqs_size, num_allocations * sizeof(VkMemoryRequirements));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600239 err = vkGetObjectInfo(m_image,
240 VK_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700241 &img_reqs_size, &img_reqs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600242 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243 ASSERT_EQ(img_reqs_size, sizeof(VkImageMemoryRequirements));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700244 img_alloc.usage = img_reqs.usage;
245 img_alloc.formatClass = img_reqs.formatClass;
246 img_alloc.samples = img_reqs.samples;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700247
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600248 for (uint32_t i = 0; i < num_allocations; i ++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600249 ASSERT_NE(0, mem_req[i].size) << "vkGetObjectInfo (Image): Failed - expect images to require memory";
Jon Ashburna9ae3832015-01-16 09:37:43 -0700250 mem_info.allocationSize = mem_req[i].size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600251 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
252 mem_info.memType = VK_MEMORY_TYPE_IMAGE;
253 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Jon Ashburna9ae3832015-01-16 09:37:43 -0700254
255 /* allocate memory */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256 err = vkAllocMemory(device(), &mem_info, &m_image_mem[i]);
257 ASSERT_VK_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700258
259 /* bind memory */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600260 err = vkBindObjectMemory(m_image, i, m_image_mem[i], 0);
261 ASSERT_VK_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700262 }
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600263}
264
Tony Barbour01999182015-04-09 12:58:51 -0600265void VkImageTest::DestroyImage()
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600266{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600267 VkResult err;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600268 // All done with image memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600269 ASSERT_VK_SUCCESS(vkBindObjectMemory(m_image, 0, VK_NULL_HANDLE, 0));
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600270
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600271 for (uint32_t i = 0 ; i < m_num_mem; i++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 err = vkFreeMemory(m_image_mem[i]);
273 ASSERT_VK_SUCCESS(err);
Jon Ashburna9ae3832015-01-16 09:37:43 -0700274 }
275
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600276
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277 ASSERT_VK_SUCCESS(vkDestroyObject(m_image));
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600278}
279
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600280void VkImageTest::CreateImageView(VkImageViewCreateInfo *pCreateInfo,
281 VkImageView *pView)
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600282{
283 pCreateInfo->image = this->m_image;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600284 ASSERT_VK_SUCCESS(vkCreateImageView(device(), pCreateInfo, pView));
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600285}
286
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600287void VkImageTest::DestroyImageView(VkImageView imageView)
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600288{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600289 ASSERT_VK_SUCCESS(vkDestroyObject(imageView));
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600290}
291
Tony Barbour01999182015-04-09 12:58:51 -0600292TEST_F(VkImageTest, CreateImageViewTest) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600293 VkFormat fmt;
294 VkImageView imageView;
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600295
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600296 fmt = VK_FMT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600297
298 CreateImage(512, 256);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300 // typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600301 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600302 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600303 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600304 // VkImage image;
305 // VkImageViewType viewType;
306 // VkFormat format;
307 // VkChannelMapping channels;
308 // VkImageSubresourceRange subresourceRange;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600309 // float minLod;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 // } VkImageViewCreateInfo;
311 VkImageViewCreateInfo viewInfo = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600312 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
313 viewInfo.viewType = VK_IMAGE_VIEW_2D;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600314 viewInfo.format = fmt;
315
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600316 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
317 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
318 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
319 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600320
321 viewInfo.subresourceRange.baseArraySlice = 0;
322 viewInfo.subresourceRange.arraySize = 1;
323 viewInfo.subresourceRange.baseMipLevel = 0;
324 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600325 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600326
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600327 // VkResult VKAPI vkCreateImageView(
328 // VkDevice device,
329 // const VkImageViewCreateInfo* pCreateInfo,
330 // VkImageView* pView);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600331
Courtney Goeltzenleuchter263e7f52014-08-14 17:41:57 -0600332 CreateImageView(&viewInfo, &imageView);
333
334 DestroyImageView(imageView);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600335}
336
337int main(int argc, char **argv) {
338 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600339 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchter62928d12014-08-13 17:53:57 -0600340 return RUN_ALL_TESTS();
341}