blob: a0c44d1b2879fb560238adb7091c5760528b0b52 [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];
148 size_t layer_count;
149 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600176 err = vkEnumerateLayers(objs[0], 16, 256, &layer_count, (char * const *) layers, NULL);
177 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
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600210 err = vkMapMemory(gpu_mem, 0, (void **) &pData);
211 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
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600216 err = vkUnmapMemory(gpu_mem);
217 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600218
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 err = vkFreeMemory(gpu_mem);
220 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
Tony Barbour8205d902015-04-16 15:59:00 -0600242 err = vkGetObjectInfo(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 Lobodzinskicf26e072015-04-16 11:44:05 -0500263 VkQueue queue = m_device->graphics_queues()[0]->obj();
264 err = vkQueueBindObjectMemory(queue, event, 0, event_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600265 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600266
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600267 err = vkResetEvent(event);
268 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600269
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600270 err = vkGetEventStatus(event);
271 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600272
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 err = vkSetEvent(event);
274 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600275
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600276 err = vkGetEventStatus(event);
277 ASSERT_EQ(VK_EVENT_SET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600278
279 // TODO: Test actual synchronization with command buffer event.
280
281 // All done with event memory, clean up
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500282 err = vkQueueBindObjectMemory(queue, event, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600283 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600284
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600285 err = vkDestroyObject(event);
286 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600287}
288
289TEST_F(XglTest, Fence) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600290 VkResult err;
291 VkFenceCreateInfo fence_info;
292 VkFence fence;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600293
294 memset(&fence_info, 0, sizeof(fence_info));
295
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296 // typedef struct VkFenceCreateInfo_
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600297 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600298 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600299 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300 // VkFlags flags; // Reserved
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600301 fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600302
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600303 err = vkCreateFence(device(), &fence_info, &fence);
304 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600305
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600306 err = vkGetFenceStatus(fence);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600307 // We've not submitted this fence on a command buffer so should get
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600308 // VK_ERROR_UNAVAILABLE
309 EXPECT_EQ(VK_ERROR_UNAVAILABLE, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600310
311 // Test glxWaitForFences
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600312 // VkResult VKAPI vkWaitForFences(
313 // VkDevice device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600314 // uint32_t fenceCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315 // const VkFence* pFences,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600316 // bool32_t waitAll,
317 // uint64_t timeout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600318 err = vkWaitForFences(device(), 1, &fence, VK_TRUE, 0);
319 EXPECT_EQ(VK_ERROR_UNAVAILABLE, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600320
321 // TODO: Attached to command buffer and test GetFenceStatus
322 // TODO: Add some commands and submit the command buffer
323
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600324 err = vkDestroyObject(fence);
325 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600326
327}
328
329#define MAX_QUERY_SLOTS 10
330
331TEST_F(XglTest, Query) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332 VkQueryPoolCreateInfo query_info;
333 VkQueryPool query_pool;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800334 size_t data_size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600335 VkMemoryRequirements mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800336 size_t query_result_size;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600337 uint32_t *query_result_data;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600338 VkResult err;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600339
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600340 // typedef enum VkQueryType_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600341 // {
Tony Barbour8205d902015-04-16 15:59:00 -0600342 // VK_QUERY_TYPE_OCCLUSION = 0x00000000,
343 // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600344
Tony Barbour8205d902015-04-16 15:59:00 -0600345 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION,
346 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600347 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600348 // VK_MAX_ENUM(VkQueryType_)
349 // } VkQueryType;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600350
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600351 // typedef struct VkQueryPoolCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600352 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600353 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600354 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600355 // VkQueryType queryType;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600356 // uint32_t slots;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600357 // } VkQueryPoolCreateInfo;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600358
359 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600360 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
Tony Barbour8205d902015-04-16 15:59:00 -0600361 query_info.queryType = VK_QUERY_TYPE_OCCLUSION;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600362 query_info.slots = MAX_QUERY_SLOTS;
363
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600364 // VkResult VKAPI vkCreateQueryPool(
365 // VkDevice device,
366 // const VkQueryPoolCreateInfo* pCreateInfo,
367 // VkQueryPool* pQueryPool);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600368
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600369 err = vkCreateQueryPool(device(), &query_info, &query_pool);
370 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600371
Jon Ashburnb8e43892014-09-25 14:36:58 -0600372 data_size = sizeof(mem_req);
Tony Barbour8205d902015-04-16 15:59:00 -0600373 err = vkGetObjectInfo(query_pool, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600374 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600375 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600376 ASSERT_NE(0, data_size) << "Invalid data_size";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600377
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600378 // VkResult VKAPI vkAllocMemory(
379 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600380 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600381 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600382 VkMemoryAllocInfo mem_info;
Tony Barbour8205d902015-04-16 15:59:00 -0600383 VkDeviceMemory query_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600384
385 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600386 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600387 // TODO: Is a simple multiple all that's needed here?
388 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600389 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600391 // TODO: Should this be pinned? Or maybe a separate test with pinned.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600392 err = vkAllocMemory(device(), &mem_info, &query_mem);
393 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600394
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500395 VkQueue queue = m_device->graphics_queues()[0]->obj();
396 err = vkQueueBindObjectMemory(queue, query_pool, 0, query_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600397 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600398
399 // TODO: Test actual synchronization with command buffer event.
400 // TODO: Create command buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600401 // TODO: vkCmdResetQueryPool
402 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600403 // TODO: commands
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600404 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600405
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406 err = vkGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbour8205d902015-04-16 15:59:00 -0600407 &query_result_size, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600408 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600409
410 if (query_result_size > 0) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600411 query_result_data = new uint32_t [query_result_size];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412 err = vkGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbour8205d902015-04-16 15:59:00 -0600413 &query_result_size, query_result_data, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600414 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600415
416 // TODO: Test Query result data.
417
418 }
419
420 // All done with QueryPool memory, clean up
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500421 err = vkQueueBindObjectMemory(queue, query_pool, 0, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600423
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600424 err = vkDestroyObject(query_pool);
425 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600426}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600427
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600429{
430 int que_idx;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600431 VkResult err;
432 VkQueue queue;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600433
Tony Barbour8205d902015-04-16 15:59:00 -0600434 const VkPhysicalDeviceQueueProperties props = device->gpu().queue_properties()[queue_node_index];
Chia-I Wu3b78d312014-12-29 15:39:23 +0800435 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500436 // TODO: Need to add support for separate MEMMGR and work queues, including synchronization
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600437 err = vkGetDeviceQueue(device->obj(), queue_node_index, que_idx, &queue);
438 ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600439 }
440}
441
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700442
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600443void print_queue_info(vk_testing::Device *device, uint32_t queue_node_index)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600444{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600445 uint32_t que_idx;
Tony Barbour8205d902015-04-16 15:59:00 -0600446 VkPhysicalDeviceQueueProperties queue_props;
447 VkPhysicalDeviceProperties props;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600448
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700449 props = device->gpu().properties();
450 queue_props = device->gpu().queue_properties()[queue_node_index];
Tony Barbour8205d902015-04-16 15:59:00 -0600451 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 -0600452
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600453// VkResult VKAPI vkGetDeviceQueue(
454// VkDevice device,
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700455// uint32_t queueNodeIndex,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600456// uint32_t queueIndex,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600457// VkQueue* pQueue);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600458 /*
459 * queue handles are retrieved from the device by calling
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600460 * vkGetDeviceQueue() with a queue node index and a requested logical
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700461 * queue ID. The queue node index is the index into the array of
Tony Barbour8205d902015-04-16 15:59:00 -0600462 * VkPhysicalDeviceQueueProperties returned by GetPhysicalDeviceInfo. Each
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600463 * queue node index has different attributes specified by the VkQueueFlags property.
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700464 * The logical queue ID is a sequential number starting from zero
465 * and referencing up to the number of queues supported of that node index
466 * at device creation.
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600467 */
468
Chia-I Wu3b78d312014-12-29 15:39:23 +0800469 for (que_idx = 0; que_idx < queue_props.queueCount; que_idx++) {
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600470
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600471// typedef enum VkQueueFlags_
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600472// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473// VK_QUEUE_GRAPHICS_BIT = 0x00000001, // Queue supports graphics operations
474// VK_QUEUE_COMPUTE_BIT = 0x00000002, // Queue supports compute operations
475// VK_QUEUE_DMA_BIT = 0x00000004, // Queue supports DMA operations
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500476// VK_QUEUE_MEMMGR_BIT = 0x00000008, // Queue supports MEMMGR operations
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477// VK_QUEUE_EXTENDED_BIT = 0x80000000 // Extended queue
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600478// } VkQueueFlags;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600479
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480 if (queue_props.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700481 getQueue(device, queue_node_index, "Graphics");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600482 }
483
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600484 if (queue_props.queueFlags & VK_QUEUE_COMPUTE_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700485 getQueue(device, queue_node_index, "Compute");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600486 }
487
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600488 if (queue_props.queueFlags & VK_QUEUE_DMA_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700489 getQueue(device, queue_node_index, "DMA");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600490 }
491
492 // TODO: What do we do about EXTENDED_BIT?
493
494 /* Guide: pg 34:
495 * The queue objects cannot be destroyed explicitly by an application
496 * and are automatically destroyed when the associated device is destroyed.
497 * Once the device is destroyed, attempting to use a queue results in
498 * undefined behavior.
499 */
500 }
501}
502
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700503TEST_F(XglTest, Queue)
504{
505 uint32_t i;
506
507 for (i = 0; i < m_device->gpu().queue_properties().size(); i++) {
508 print_queue_info(m_device, i);
509 }
510}
511
512
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600513void XglTest::CreateImageTest()
514{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600515 VkResult err;
516 VkImage image;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600517 uint32_t w, h, mipCount;
518 size_t size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600519 VkFormat fmt;
520 VkFormatProperties image_fmt;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800521 size_t data_size;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600522
523 w =512;
524 h = 256;
525 mipCount = 0;
526
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600527 uint32_t _w = w;
528 uint32_t _h = h;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600529 while( ( _w > 0 ) || ( _h > 0 ) )
530 {
531 _w >>= 1;
532 _h >>= 1;
533 mipCount++;
534 }
535
Tony Barbour8205d902015-04-16 15:59:00 -0600536 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600537 // TODO: Pick known good format rather than just expect common format
538 /*
539 * XXX: What should happen if given NULL HANDLE for the pData argument?
Tony Barbour8205d902015-04-16 15:59:00 -0600540 * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600541 * an expectation that pData is a valid pointer.
542 * However, why include a returned size value? That implies that the
543 * amount of data may vary and that doesn't work well for using a
544 * fixed structure.
545 */
546
Jon Ashburnb8e43892014-09-25 14:36:58 -0600547 size = sizeof(image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600548 err = vkGetFormatInfo(device(), fmt,
Tony Barbour8205d902015-04-16 15:59:00 -0600549 VK_FORMAT_INFO_TYPE_PROPERTIES,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600550 &size, &image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600551 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600552
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600553// typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600554// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600555// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600556// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600557// VkImageType imageType;
558// VkFormat format;
559// VkExtent3D extent;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600560// uint32_t mipLevels;
561// uint32_t arraySize;
562// uint32_t samples;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600563// VkImageTiling tiling;
564// VkFlags usage; // VkImageUsageFlags
565// VkFlags flags; // VkImageCreateFlags
566// } VkImageCreateInfo;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600567
568
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600569 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600570 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbour8205d902015-04-16 15:59:00 -0600571 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600572 imageCreateInfo.format = fmt;
573 imageCreateInfo.arraySize = 1;
574 imageCreateInfo.extent.width = w;
575 imageCreateInfo.extent.height = h;
576 imageCreateInfo.extent.depth = 1;
577 imageCreateInfo.mipLevels = mipCount;
578 imageCreateInfo.samples = 1;
Tony Barbour8205d902015-04-16 15:59:00 -0600579 imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600580
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600581 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600582
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600583// VkResult VKAPI vkCreateImage(
584// VkDevice device,
585// const VkImageCreateInfo* pCreateInfo,
586// VkImage* pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600587 err = vkCreateImage(device(), &imageCreateInfo, &image);
588 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600589
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600590 // Verify image resources
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600591// VkResult VKAPI vkGetImageSubresourceInfo(
592// VkImage image,
593// const VkImageSubresource* pSubresource,
594// VkSubresourceInfoType infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600595// size_t* pDataSize,
596// void* pData);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600597// typedef struct VkSubresourceLayout_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600598// {
Tony Barbour8205d902015-04-16 15:59:00 -0600599// VkDeviceSize offset; // Specified in bytes
600// VkDeviceSize size; // Specified in bytes
601// VkDeviceSize rowPitch; // Specified in bytes
602// VkDeviceSize depthPitch; // Specified in bytes
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600603// } VkSubresourceLayout;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600605// typedef struct VkImageSubresource_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600606// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600607// VkImageAspect aspect;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600608// uint32_t mipLevel;
609// uint32_t arraySlice;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600610// } VkImageSubresource;
611// typedef enum VkSubresourceInfoType_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600612// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600613// // Info type for vkGetImageSubresourceInfo()
Tony Barbour8205d902015-04-16 15:59:00 -0600614// VK_SUBRESOURCE_INFO_TYPE_LAYOUT = 0x00000000,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600615
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600616// VK_MAX_ENUM(VkSubresourceInfoType_)
617// } VkSubresourceInfoType;
618 VkImageSubresource subresource = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600619 subresource.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600620 subresource.arraySlice = 0;
621
622 _w = w;
623 _h = h;
624 while( ( _w > 0 ) || ( _h > 0 ) )
625 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626 VkSubresourceLayout layout = {};
Jon Ashburnb8e43892014-09-25 14:36:58 -0600627 data_size = sizeof(layout);
Tony Barbour8205d902015-04-16 15:59:00 -0600628 err = vkGetImageSubresourceInfo(image, &subresource, VK_SUBRESOURCE_INFO_TYPE_LAYOUT,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600629 &data_size, &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600630 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600631 ASSERT_EQ(sizeof(VkSubresourceLayout), data_size) << "Invalid structure (VkSubresourceLayout) size";
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600632
633 // TODO: 4 should be replaced with pixel size for given format
634 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
635 _w >>= 1;
636 _h >>= 1;
637
638 subresource.mipLevel++;
639 }
640
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600641 VkMemoryRequirements mem_req;
Jon Ashburnb8e43892014-09-25 14:36:58 -0600642 data_size = sizeof(mem_req);
Tony Barbour8205d902015-04-16 15:59:00 -0600643 err = vkGetObjectInfo(image, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600644 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600645 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600646 ASSERT_EQ(data_size, sizeof(mem_req));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600647 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect images to require memory";
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600648 // VkResult VKAPI vkAllocMemory(
649 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600650 // const VkMemoryAllocInfo* pAllocInfo,
Tony Barbour8205d902015-04-16 15:59:00 -0600651 // VkDeviceMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600652 VkMemoryAllocInfo mem_info = {};
Tony Barbour8205d902015-04-16 15:59:00 -0600653 VkDeviceMemory image_mem;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600654
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600655 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500656 mem_info.pNext = NULL;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600657 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600658 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
660 err = vkAllocMemory(device(), &mem_info, &image_mem);
661 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600662
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500663 VkQueue queue = m_device->graphics_queues()[0]->obj();
664 err = vkQueueBindObjectMemory(queue, image, 0, image_mem, 0);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600666
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600667// typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600668// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600669// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600670// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600671// VkImage image;
672// VkImageViewType viewType;
673// VkFormat format;
674// VkChannelMapping channels;
675// VkImageSubresourceRange subresourceRange;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600676// float minLod;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600677// } VkImageViewCreateInfo;
678 VkImageViewCreateInfo viewInfo = {};
679 VkImageView view;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600681 viewInfo.image = image;
Tony Barbour8205d902015-04-16 15:59:00 -0600682 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600683 viewInfo.format = fmt;
684
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
686 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
687 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
688 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600689
690 viewInfo.subresourceRange.baseArraySlice = 0;
691 viewInfo.subresourceRange.arraySize = 1;
692 viewInfo.subresourceRange.baseMipLevel = 0;
693 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600694 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600695
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600696// VkResult VKAPI vkCreateImageView(
697// VkDevice device,
698// const VkImageViewCreateInfo* pCreateInfo,
699// VkImageView* pView);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600700
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600701 err = vkCreateImageView(device(), &viewInfo, &view);
702 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600703
704 // TODO: Test image memory.
705
706 // All done with image memory, clean up
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500707 ASSERT_VK_SUCCESS(vkQueueBindObjectMemory(queue, image, 0, VK_NULL_HANDLE, 0));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600708
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600709 ASSERT_VK_SUCCESS(vkFreeMemory(image_mem));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600710
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600711 ASSERT_VK_SUCCESS(vkDestroyObject(image));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600712}
713
714TEST_F(XglTest, CreateImage) {
715 CreateImageTest();
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600716}
717
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600718void XglTest::CreateCommandBufferTest()
719{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600720 VkResult err;
721 VkCmdBufferCreateInfo info = {};
722 VkCmdBuffer cmdBuffer;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724// typedef struct VkCmdBufferCreateInfo_
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600725// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600727// const void* pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600728// VK_QUEUE_TYPE queueType;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600729// VkFlags flags;
730// } VkCmdBufferCreateInfo;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600731
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600732 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700733 info.queueNodeIndex = graphics_queue_node_index;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600734 err = vkCreateCommandBuffer(device(), &info, &cmdBuffer);
735 ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed";
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600736
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600737 ASSERT_VK_SUCCESS(vkDestroyObject(cmdBuffer));
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600738}
739
740TEST_F(XglTest, TestComandBuffer) {
741 CreateCommandBufferTest();
742}
743
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600744void XglTest::CreateShader(VkShader *pshader)
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600745{
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600746 void *code;
747 uint32_t codeSize;
Cody Northropacfb0492015-03-17 15:55:58 -0600748 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600749 VkResult err;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600750
Cody Northropacfb0492015-03-17 15:55:58 -0600751 codeSize = sizeof(struct icd_spv_header) + 100;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600752 code = malloc(codeSize);
753 ASSERT_TRUE(NULL != code) << "malloc failed!";
754
755 memset(code, 0, codeSize);
756
Cody Northropacfb0492015-03-17 15:55:58 -0600757 // Indicate that this is SPV data.
758 pSPV = (struct icd_spv_header *) code;
759 pSPV->magic = ICD_SPV_MAGIC;
760 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600761
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600762// typedef struct VkShaderCreateInfo_
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600763// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600765// const void* pNext; // Pointer to next structure
766// size_t codeSize; // Specified in bytes
767// const void* pCode;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600768// VkFlags flags; // Reserved
769// } VkShaderCreateInfo;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600770
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600771 VkShaderCreateInfo createInfo;
772 VkShader shader;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600773
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600774 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600775 createInfo.pNext = NULL;
776 createInfo.pCode = code;
777 createInfo.codeSize = codeSize;
778 createInfo.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600779 err = vkCreateShader(device(), &createInfo, &shader);
780 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600781
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600782 *pshader = shader;
783}
784
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600785int main(int argc, char **argv) {
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600786 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600787 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600788 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600789}