blob: 2054a1660ce91d4488fca8ce41d1cd3e3df0afb4 [file] [log] [blame]
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -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
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060030
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -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 Goeltzenleuchtered56abc2014-08-12 14:12:22 -060055
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060056#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 Goeltzenleuchtered56abc2014-08-12 14:12:22 -060062#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060063
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060064#include "vktestbinding.h"
Chia-I Wu3b78d312014-12-29 15:39:23 +080065#include "test_common.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060066#include "icd-spv.h"
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060067
Jon Ashburn07b309a2015-04-15 11:31:12 -060068#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
69
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060070class XglTest : public ::testing::Test {
71public:
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -060072 void CreateImageTest();
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -060073 void CreateCommandBufferTest();
74 void CreatePipelineTest();
75 void CreateShaderTest();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060076 void CreateShader(VkShader *pshader);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060077
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060078 VkDevice device() {return m_device->obj();}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060079
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060080protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060081 VkApplicationInfo app_info;
82 VkInstance inst;
Tony Barbour8205d902015-04-16 15:59:00 -060083 VkPhysicalDevice objs[16];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060084 uint32_t gpu_count;
Chia-I Wu3b78d312014-12-29 15:39:23 +080085
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060086 uint32_t m_device_id;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060087 vk_testing::Device *m_device;
Tony Barbour8205d902015-04-16 15:59:00 -060088 VkPhysicalDeviceProperties props;
89 std::vector<VkPhysicalDeviceQueueProperties> queue_props;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -070090 uint32_t graphics_queue_node_index;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060091
92 virtual void SetUp() {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060093 VkResult err;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -070094 int i;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060095
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060097 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080098 this->app_info.pAppName = "base";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060099 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800100 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600101 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600103 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600104 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -0600105 inst_info.pNext = NULL;
106 inst_info.pAppInfo = &app_info;
107 inst_info.pAllocCb = NULL;
108 inst_info.extensionCount = 0;
109 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110 err = vkCreateInstance(&inst_info, &inst);
111 ASSERT_VK_SUCCESS(err);
Jon Ashburn07b309a2015-04-15 11:31:12 -0600112 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL);
113 ASSERT_VK_SUCCESS(err);
114 ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs";
115 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600116 ASSERT_VK_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700117 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600118
Chia-I Wu3b78d312014-12-29 15:39:23 +0800119 m_device_id = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600120 this->m_device = new vk_testing::Device(objs[m_device_id]);
Chia-I Wu3b78d312014-12-29 15:39:23 +0800121 this->m_device->init();
122
123 props = m_device->gpu().properties();
Chia-I Wu3b78d312014-12-29 15:39:23 +0800124
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700125 queue_props = this->m_device->gpu().queue_properties();
126 for (i = 0; i < queue_props.size(); i++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600127 if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700128 graphics_queue_node_index = i;
129 break;
130 }
131 }
132 ASSERT_LT(i, queue_props.size()) << "Could not find a Queue with Graphics support";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600133 }
134
135 virtual void TearDown() {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136 vkDestroyInstance(inst);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600137 }
138};
139
Tony Barbour8205d902015-04-16 15:59:00 -0600140TEST(Initialization, vkEnumeratePhysicalDevices) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 VkApplicationInfo app_info = {};
142 VkInstance inst;
Tony Barbour8205d902015-04-16 15:59:00 -0600143 VkPhysicalDevice objs[16];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600144 uint32_t gpu_count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600145 VkResult err;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600146 vk_testing::PhysicalGpu *gpu;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600147 char *layers[16];
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600148 size_t layer_count = 16; /* accept 16 layer names to be returned */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600149 char layer_buf[16][256];
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600150 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600151 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -0600152 inst_info.pNext = NULL;
153 inst_info.pAppInfo = &app_info;
154 inst_info.pAllocCb = NULL;
155 inst_info.extensionCount = 0;
156 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600157 app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600158 app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800159 app_info.pAppName = "base";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600160 app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800161 app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600162 app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600163 app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600164
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600165 err = vkCreateInstance(&inst_info, &inst);
166 ASSERT_VK_SUCCESS(err);
Jon Ashburn07b309a2015-04-15 11:31:12 -0600167 err = vkEnumeratePhysicalDevices(inst, &gpu_count, NULL);
168 ASSERT_VK_SUCCESS(err);
169 ASSERT_LE(gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs";
170 err = vkEnumeratePhysicalDevices(inst, &gpu_count, objs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 ASSERT_VK_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700172 ASSERT_GE(gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600173
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600174 for (int i = 0; i < 16; i++)
175 layers[i] = &layer_buf[i][0];
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -0600176 err = vkEnumerateLayers(objs[0], 256, &layer_count, (char * const *) layers, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600177 ASSERT_VK_SUCCESS(err);
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600178 for (int i = 0; i < layer_count; i++) {
179 printf("Enumerated layers: %s ", layers[i]);
180 }
181 printf("\n");
182
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600183 // TODO: Iterate over all GPUs
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600184 gpu = new vk_testing::PhysicalGpu(objs[0]);
Chia-I Wub7cf4452014-12-16 00:04:02 +0800185 delete gpu;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600186
187 // TODO: Verify destroy functions
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600188 err = vkDestroyInstance(inst);
189 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600190}
191
192TEST_F(XglTest, AllocMemory) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600193 VkResult err;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600194 VkMemoryAllocInfo alloc_info = {};
Tony Barbour8205d902015-04-16 15:59:00 -0600195 VkDeviceMemory gpu_mem;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600196 uint8_t *pData;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600197
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600199 alloc_info.allocationSize = 1024 * 1024; // 1MB
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600200 alloc_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT |
Tony Barbour8205d902015-04-16 15:59:00 -0600201 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700202
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600203
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600204 // TODO: Try variety of memory priorities
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600205 alloc_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600206
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600207 err = vkAllocMemory(device(), &alloc_info, &gpu_mem);
208 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600209
Mike Stroyan230e6252015-04-17 12:36:38 -0600210 err = vkMapMemory(device(), gpu_mem, 0, 0, 0, (void **) &pData);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600212
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600213 memset(pData, 0x55, alloc_info.allocationSize);
214 EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write";
215
Mike Stroyan230e6252015-04-17 12:36:38 -0600216 err = vkUnmapMemory(device(), gpu_mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600217 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600218
Mike Stroyan230e6252015-04-17 12:36:38 -0600219 err = vkFreeMemory(device(), gpu_mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600220 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600221}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600222
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600223TEST_F(XglTest, Event) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600224 VkEventCreateInfo event_info;
225 VkEvent event;
226 VkMemoryRequirements mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800227 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228 VkResult err;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600230 // typedef struct VkEventCreateInfo_
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600231 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600232 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600233 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600234 // VkFlags flags; // Reserved
235 // } VkEventCreateInfo;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600236 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600237 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600238
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600239 err = vkCreateEvent(device(), &event_info, &event);
240 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600241
Mike Stroyan230e6252015-04-17 12:36:38 -0600242 err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600243 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600244 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600245
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600246 // VkResult VKAPI vkAllocMemory(
247 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600248 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600249 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600250 VkMemoryAllocInfo mem_info;
Tony Barbour8205d902015-04-16 15:59:00 -0600251 VkDeviceMemory event_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600252
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600253 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600254
255 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600257 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600258 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
259 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600260 err = vkAllocMemory(device(), &mem_info, &event_mem);
261 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600262
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500263 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, 0, event_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600264 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600265
Mike Stroyan230e6252015-04-17 12:36:38 -0600266 err = vkResetEvent(device(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600267 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600268
Mike Stroyan230e6252015-04-17 12:36:38 -0600269 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600270 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600271
Mike Stroyan230e6252015-04-17 12:36:38 -0600272 err = vkSetEvent(device(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600274
Mike Stroyan230e6252015-04-17 12:36:38 -0600275 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600276 ASSERT_EQ(VK_EVENT_SET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600277
278 // TODO: Test actual synchronization with command buffer event.
279
280 // All done with event memory, clean up
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500281 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600282 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600283
Mike Stroyan230e6252015-04-17 12:36:38 -0600284 err = vkDestroyObject(device(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600285 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600286}
287
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600288#define MAX_QUERY_SLOTS 10
289
290TEST_F(XglTest, Query) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600291 VkQueryPoolCreateInfo query_info;
292 VkQueryPool query_pool;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800293 size_t data_size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600294 VkMemoryRequirements mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800295 size_t query_result_size;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600296 uint32_t *query_result_data;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600297 VkResult err;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600298
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600299 // typedef enum VkQueryType_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600300 // {
Tony Barbour8205d902015-04-16 15:59:00 -0600301 // VK_QUERY_TYPE_OCCLUSION = 0x00000000,
302 // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600303
Tony Barbour8205d902015-04-16 15:59:00 -0600304 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION,
305 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600306 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307 // VK_MAX_ENUM(VkQueryType_)
308 // } VkQueryType;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600309
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600310 // typedef struct VkQueryPoolCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600311 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600312 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600313 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600314 // VkQueryType queryType;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600315 // uint32_t slots;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600316 // } VkQueryPoolCreateInfo;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600317
318 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600319 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
Tony Barbour8205d902015-04-16 15:59:00 -0600320 query_info.queryType = VK_QUERY_TYPE_OCCLUSION;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600321 query_info.slots = MAX_QUERY_SLOTS;
322
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600323 // VkResult VKAPI vkCreateQueryPool(
324 // VkDevice device,
325 // const VkQueryPoolCreateInfo* pCreateInfo,
326 // VkQueryPool* pQueryPool);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600327
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600328 err = vkCreateQueryPool(device(), &query_info, &query_pool);
329 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600330
Jon Ashburnb8e43892014-09-25 14:36:58 -0600331 data_size = sizeof(mem_req);
Mike Stroyan230e6252015-04-17 12:36:38 -0600332 err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600333 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600334 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600335 ASSERT_NE(0, data_size) << "Invalid data_size";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600336
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600337 // VkResult VKAPI vkAllocMemory(
338 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600339 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600340 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600341 VkMemoryAllocInfo mem_info;
Tony Barbour8205d902015-04-16 15:59:00 -0600342 VkDeviceMemory query_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600343
344 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600346 // TODO: Is a simple multiple all that's needed here?
347 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600348 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600350 // TODO: Should this be pinned? Or maybe a separate test with pinned.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 err = vkAllocMemory(device(), &mem_info, &query_mem);
352 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600353
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500354 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, 0, query_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600355 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600356
357 // TODO: Test actual synchronization with command buffer event.
358 // TODO: Create command buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600359 // TODO: vkCmdResetQueryPool
360 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600361 // TODO: commands
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600362 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600363
Mike Stroyan230e6252015-04-17 12:36:38 -0600364 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbour8205d902015-04-16 15:59:00 -0600365 &query_result_size, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600367
368 if (query_result_size > 0) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600369 query_result_data = new uint32_t [query_result_size];
Mike Stroyan230e6252015-04-17 12:36:38 -0600370 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbour8205d902015-04-16 15:59:00 -0600371 &query_result_size, query_result_data, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600372 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600373
374 // TODO: Test Query result data.
375
376 }
377
378 // All done with QueryPool memory, clean up
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500379 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600380 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600381
Mike Stroyan230e6252015-04-17 12:36:38 -0600382 err = vkDestroyObject(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600383 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600384}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600385
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600386void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600387{
388 int que_idx;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600389 VkResult err;
390 VkQueue queue;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600391
Tony Barbour8205d902015-04-16 15:59:00 -0600392 const VkPhysicalDeviceQueueProperties props = device->gpu().queue_properties()[queue_node_index];
Chia-I Wu3b78d312014-12-29 15:39:23 +0800393 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500394 // TODO: Need to add support for separate MEMMGR and work queues, including synchronization
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395 err = vkGetDeviceQueue(device->obj(), queue_node_index, que_idx, &queue);
396 ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600397 }
398}
399
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700400
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600401void print_queue_info(vk_testing::Device *device, uint32_t queue_node_index)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600402{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600403 uint32_t que_idx;
Tony Barbour8205d902015-04-16 15:59:00 -0600404 VkPhysicalDeviceQueueProperties queue_props;
405 VkPhysicalDeviceProperties props;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600406
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700407 props = device->gpu().properties();
408 queue_props = device->gpu().queue_properties()[queue_node_index];
Tony Barbour8205d902015-04-16 15:59:00 -0600409 ASSERT_NE(0, queue_props.queueCount) << "No Queues available at Node Index #" << queue_node_index << " GPU: " << props.deviceName;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600410
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411// VkResult VKAPI vkGetDeviceQueue(
412// VkDevice device,
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700413// uint32_t queueNodeIndex,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600414// uint32_t queueIndex,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600415// VkQueue* pQueue);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600416 /*
417 * queue handles are retrieved from the device by calling
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 * vkGetDeviceQueue() with a queue node index and a requested logical
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700419 * queue ID. The queue node index is the index into the array of
Tony Barbour8205d902015-04-16 15:59:00 -0600420 * VkPhysicalDeviceQueueProperties returned by GetPhysicalDeviceInfo. Each
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600421 * queue node index has different attributes specified by the VkQueueFlags property.
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700422 * The logical queue ID is a sequential number starting from zero
423 * and referencing up to the number of queues supported of that node index
424 * at device creation.
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600425 */
426
Chia-I Wu3b78d312014-12-29 15:39:23 +0800427 for (que_idx = 0; que_idx < queue_props.queueCount; que_idx++) {
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600428
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600429// typedef enum VkQueueFlags_
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600430// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600431// VK_QUEUE_GRAPHICS_BIT = 0x00000001, // Queue supports graphics operations
432// VK_QUEUE_COMPUTE_BIT = 0x00000002, // Queue supports compute operations
433// VK_QUEUE_DMA_BIT = 0x00000004, // Queue supports DMA operations
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500434// VK_QUEUE_SPARSE_MEMMGR_BIT = 0x00000008, // Queue supports sparse resource memory management operations
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600435// VK_QUEUE_EXTENDED_BIT = 0x80000000 // Extended queue
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600436// } VkQueueFlags;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600437
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600438 if (queue_props.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700439 getQueue(device, queue_node_index, "Graphics");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600440 }
441
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600442 if (queue_props.queueFlags & VK_QUEUE_COMPUTE_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700443 getQueue(device, queue_node_index, "Compute");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600444 }
445
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600446 if (queue_props.queueFlags & VK_QUEUE_DMA_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700447 getQueue(device, queue_node_index, "DMA");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600448 }
449
450 // TODO: What do we do about EXTENDED_BIT?
451
452 /* Guide: pg 34:
453 * The queue objects cannot be destroyed explicitly by an application
454 * and are automatically destroyed when the associated device is destroyed.
455 * Once the device is destroyed, attempting to use a queue results in
456 * undefined behavior.
457 */
458 }
459}
460
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700461TEST_F(XglTest, Queue)
462{
463 uint32_t i;
464
465 for (i = 0; i < m_device->gpu().queue_properties().size(); i++) {
466 print_queue_info(m_device, i);
467 }
468}
469
470
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600471void XglTest::CreateImageTest()
472{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600473 VkResult err;
474 VkImage image;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600475 uint32_t w, h, mipCount;
476 size_t size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600477 VkFormat fmt;
478 VkFormatProperties image_fmt;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800479 size_t data_size;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600480
481 w =512;
482 h = 256;
483 mipCount = 0;
484
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600485 uint32_t _w = w;
486 uint32_t _h = h;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600487 while( ( _w > 0 ) || ( _h > 0 ) )
488 {
489 _w >>= 1;
490 _h >>= 1;
491 mipCount++;
492 }
493
Tony Barbour8205d902015-04-16 15:59:00 -0600494 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600495 // TODO: Pick known good format rather than just expect common format
496 /*
497 * XXX: What should happen if given NULL HANDLE for the pData argument?
Tony Barbour8205d902015-04-16 15:59:00 -0600498 * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600499 * an expectation that pData is a valid pointer.
500 * However, why include a returned size value? That implies that the
501 * amount of data may vary and that doesn't work well for using a
502 * fixed structure.
503 */
504
Jon Ashburnb8e43892014-09-25 14:36:58 -0600505 size = sizeof(image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600506 err = vkGetFormatInfo(device(), fmt,
Tony Barbour8205d902015-04-16 15:59:00 -0600507 VK_FORMAT_INFO_TYPE_PROPERTIES,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600508 &size, &image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600509 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600510
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600511// typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600512// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600513// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600514// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600515// VkImageType imageType;
516// VkFormat format;
517// VkExtent3D extent;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600518// uint32_t mipLevels;
519// uint32_t arraySize;
520// uint32_t samples;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600521// VkImageTiling tiling;
522// VkFlags usage; // VkImageUsageFlags
523// VkFlags flags; // VkImageCreateFlags
524// } VkImageCreateInfo;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600525
526
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600527 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600528 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbour8205d902015-04-16 15:59:00 -0600529 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600530 imageCreateInfo.format = fmt;
531 imageCreateInfo.arraySize = 1;
532 imageCreateInfo.extent.width = w;
533 imageCreateInfo.extent.height = h;
534 imageCreateInfo.extent.depth = 1;
535 imageCreateInfo.mipLevels = mipCount;
536 imageCreateInfo.samples = 1;
Tony Barbour8205d902015-04-16 15:59:00 -0600537 imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600538
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600539 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600540
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600541// VkResult VKAPI vkCreateImage(
542// VkDevice device,
543// const VkImageCreateInfo* pCreateInfo,
544// VkImage* pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600545 err = vkCreateImage(device(), &imageCreateInfo, &image);
546 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600547
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600548 // Verify image resources
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600549// VkResult VKAPI vkGetImageSubresourceInfo(
550// VkImage image,
551// const VkImageSubresource* pSubresource,
552// VkSubresourceInfoType infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600553// size_t* pDataSize,
554// void* pData);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600555// typedef struct VkSubresourceLayout_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600556// {
Tony Barbour8205d902015-04-16 15:59:00 -0600557// VkDeviceSize offset; // Specified in bytes
558// VkDeviceSize size; // Specified in bytes
559// VkDeviceSize rowPitch; // Specified in bytes
560// VkDeviceSize depthPitch; // Specified in bytes
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600561// } VkSubresourceLayout;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600562
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600563// typedef struct VkImageSubresource_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600564// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600565// VkImageAspect aspect;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600566// uint32_t mipLevel;
567// uint32_t arraySlice;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600568// } VkImageSubresource;
569// typedef enum VkSubresourceInfoType_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600570// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600571// // Info type for vkGetImageSubresourceInfo()
Tony Barbour8205d902015-04-16 15:59:00 -0600572// VK_SUBRESOURCE_INFO_TYPE_LAYOUT = 0x00000000,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600573
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600574// VK_MAX_ENUM(VkSubresourceInfoType_)
575// } VkSubresourceInfoType;
576 VkImageSubresource subresource = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600577 subresource.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600578 subresource.arraySlice = 0;
579
580 _w = w;
581 _h = h;
582 while( ( _w > 0 ) || ( _h > 0 ) )
583 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600584 VkSubresourceLayout layout = {};
Jon Ashburnb8e43892014-09-25 14:36:58 -0600585 data_size = sizeof(layout);
Mike Stroyan230e6252015-04-17 12:36:38 -0600586 err = vkGetImageSubresourceInfo(device(), image, &subresource, VK_SUBRESOURCE_INFO_TYPE_LAYOUT,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600587 &data_size, &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600588 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600589 ASSERT_EQ(sizeof(VkSubresourceLayout), data_size) << "Invalid structure (VkSubresourceLayout) size";
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600590
591 // TODO: 4 should be replaced with pixel size for given format
592 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
593 _w >>= 1;
594 _h >>= 1;
595
596 subresource.mipLevel++;
597 }
598
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600599 VkMemoryRequirements mem_req;
Jon Ashburnb8e43892014-09-25 14:36:58 -0600600 data_size = sizeof(mem_req);
Mike Stroyan230e6252015-04-17 12:36:38 -0600601 err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_IMAGE, image, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600602 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600603 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600604 ASSERT_EQ(data_size, sizeof(mem_req));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600605 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect images to require memory";
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600606 // VkResult VKAPI vkAllocMemory(
607 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600608 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600609 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600610 VkMemoryAllocInfo mem_info = {};
Tony Barbour8205d902015-04-16 15:59:00 -0600611 VkDeviceMemory image_mem;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600612
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600613 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500614 mem_info.pNext = NULL;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600615 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600616 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600617 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
618 err = vkAllocMemory(device(), &mem_info, &image_mem);
619 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600620
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500621 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_IMAGE, image, 0, image_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600623
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624// typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600625// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600627// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600628// VkImage image;
629// VkImageViewType viewType;
630// VkFormat format;
631// VkChannelMapping channels;
632// VkImageSubresourceRange subresourceRange;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600633// float minLod;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600634// } VkImageViewCreateInfo;
635 VkImageViewCreateInfo viewInfo = {};
636 VkImageView view;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600637 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600638 viewInfo.image = image;
Tony Barbour8205d902015-04-16 15:59:00 -0600639 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600640 viewInfo.format = fmt;
641
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600642 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
643 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
644 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
645 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600646
647 viewInfo.subresourceRange.baseArraySlice = 0;
648 viewInfo.subresourceRange.arraySize = 1;
649 viewInfo.subresourceRange.baseMipLevel = 0;
650 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600651 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600652
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600653// VkResult VKAPI vkCreateImageView(
654// VkDevice device,
655// const VkImageViewCreateInfo* pCreateInfo,
656// VkImageView* pView);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600657
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600658 err = vkCreateImageView(device(), &viewInfo, &view);
659 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600660
661 // TODO: Test image memory.
662
663 // All done with image memory, clean up
Mark Lobodzinskifb9f5642015-05-11 17:21:15 -0500664 ASSERT_VK_SUCCESS(vkBindObjectMemory(device(), VK_OBJECT_TYPE_IMAGE, image, 0, VK_NULL_HANDLE, 0));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600665
Mike Stroyan230e6252015-04-17 12:36:38 -0600666 ASSERT_VK_SUCCESS(vkFreeMemory(device(), image_mem));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600667
Mike Stroyan230e6252015-04-17 12:36:38 -0600668 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_IMAGE, image));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600669}
670
671TEST_F(XglTest, CreateImage) {
672 CreateImageTest();
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600673}
674
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600675void XglTest::CreateCommandBufferTest()
676{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600677 VkResult err;
678 VkCmdBufferCreateInfo info = {};
679 VkCmdBuffer cmdBuffer;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600680
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600681// typedef struct VkCmdBufferCreateInfo_
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600682// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600683// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600684// const void* pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685// VK_QUEUE_TYPE queueType;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600686// VkFlags flags;
687// } VkCmdBufferCreateInfo;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600688
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600689 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700690 info.queueNodeIndex = graphics_queue_node_index;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600691 err = vkCreateCommandBuffer(device(), &info, &cmdBuffer);
692 ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed";
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600693
Mike Stroyan230e6252015-04-17 12:36:38 -0600694 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer));
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600695}
696
697TEST_F(XglTest, TestComandBuffer) {
698 CreateCommandBufferTest();
699}
700
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600701void XglTest::CreateShader(VkShader *pshader)
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600702{
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600703 void *code;
704 uint32_t codeSize;
Cody Northropacfb0492015-03-17 15:55:58 -0600705 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600706 VkResult err;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600707
Cody Northropacfb0492015-03-17 15:55:58 -0600708 codeSize = sizeof(struct icd_spv_header) + 100;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600709 code = malloc(codeSize);
710 ASSERT_TRUE(NULL != code) << "malloc failed!";
711
712 memset(code, 0, codeSize);
713
Cody Northropacfb0492015-03-17 15:55:58 -0600714 // Indicate that this is SPV data.
715 pSPV = (struct icd_spv_header *) code;
716 pSPV->magic = ICD_SPV_MAGIC;
717 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600718
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600719// typedef struct VkShaderCreateInfo_
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600720// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600721// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600722// const void* pNext; // Pointer to next structure
723// size_t codeSize; // Specified in bytes
724// const void* pCode;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600725// VkFlags flags; // Reserved
726// } VkShaderCreateInfo;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600727
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600728 VkShaderCreateInfo createInfo;
729 VkShader shader;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600730
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600731 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600732 createInfo.pNext = NULL;
733 createInfo.pCode = code;
734 createInfo.codeSize = codeSize;
735 createInfo.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600736 err = vkCreateShader(device(), &createInfo, &shader);
737 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600738
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600739 *pshader = shader;
740}
741
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600742int main(int argc, char **argv) {
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600743 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600744 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600745 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600746}