blob: 5599446c29c6cc930854cbdbee2ec7a818475f26 [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
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060068class XglTest : public ::testing::Test {
69public:
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -060070 void CreateImageTest();
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -060071 void CreateCommandBufferTest();
72 void CreatePipelineTest();
73 void CreateShaderTest();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060074 void CreateShader(VkShader *pshader);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060075
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060076 VkDevice device() {return m_device->obj();}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060077
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060078protected:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060079 VkApplicationInfo app_info;
80 VkInstance inst;
81 VkPhysicalGpu objs[VK_MAX_PHYSICAL_GPUS];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060082 uint32_t gpu_count;
Chia-I Wu3b78d312014-12-29 15:39:23 +080083
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060084 uint32_t m_device_id;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060085 vk_testing::Device *m_device;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060086 VkPhysicalGpuProperties props;
87 std::vector<VkPhysicalGpuQueueProperties> queue_props;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -070088 uint32_t graphics_queue_node_index;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060089
90 virtual void SetUp() {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060091 VkResult err;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -070092 int i;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060093
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060094 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060095 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080096 this->app_info.pAppName = "base";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060097 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080098 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060099 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600100 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600101 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600102 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -0600103 inst_info.pNext = NULL;
104 inst_info.pAppInfo = &app_info;
105 inst_info.pAllocCb = NULL;
106 inst_info.extensionCount = 0;
107 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 err = vkCreateInstance(&inst_info, &inst);
109 ASSERT_VK_SUCCESS(err);
110 err = vkEnumerateGpus(inst, VK_MAX_PHYSICAL_GPUS, &this->gpu_count,
Jon Ashburn670b1762015-01-29 15:48:00 -0700111 objs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 ASSERT_VK_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700113 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600114
Chia-I Wu3b78d312014-12-29 15:39:23 +0800115 m_device_id = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600116 this->m_device = new vk_testing::Device(objs[m_device_id]);
Chia-I Wu3b78d312014-12-29 15:39:23 +0800117 this->m_device->init();
118
119 props = m_device->gpu().properties();
Chia-I Wu3b78d312014-12-29 15:39:23 +0800120
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700121 queue_props = this->m_device->gpu().queue_properties();
122 for (i = 0; i < queue_props.size(); i++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600123 if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700124 graphics_queue_node_index = i;
125 break;
126 }
127 }
128 ASSERT_LT(i, queue_props.size()) << "Could not find a Queue with Graphics support";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600129 }
130
131 virtual void TearDown() {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600132 vkDestroyInstance(inst);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600133 }
134};
135
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600136TEST(Initialization, vkEnumerateGpus) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 VkApplicationInfo app_info = {};
138 VkInstance inst;
139 VkPhysicalGpu objs[VK_MAX_PHYSICAL_GPUS];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600140 uint32_t gpu_count;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 VkResult err;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142 vk_testing::PhysicalGpu *gpu;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600143 char *layers[16];
144 size_t layer_count;
145 char layer_buf[16][256];
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600146 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600147 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburn29669a42015-04-04 14:52:07 -0600148 inst_info.pNext = NULL;
149 inst_info.pAppInfo = &app_info;
150 inst_info.pAllocCb = NULL;
151 inst_info.extensionCount = 0;
152 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600153 app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600154 app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800155 app_info.pAppName = "base";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600156 app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800157 app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600158 app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600159 app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600160
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600161 err = vkCreateInstance(&inst_info, &inst);
162 ASSERT_VK_SUCCESS(err);
163 err = vkEnumerateGpus(inst, VK_MAX_PHYSICAL_GPUS, &gpu_count, objs);
164 ASSERT_VK_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700165 ASSERT_GE(gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600166
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600167 for (int i = 0; i < 16; i++)
168 layers[i] = &layer_buf[i][0];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600169 err = vkEnumerateLayers(objs[0], 16, 256, &layer_count, (char * const *) layers, NULL);
170 ASSERT_VK_SUCCESS(err);
Jon Ashburn96f28fc2014-10-15 15:30:23 -0600171 for (int i = 0; i < layer_count; i++) {
172 printf("Enumerated layers: %s ", layers[i]);
173 }
174 printf("\n");
175
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600176 // TODO: Iterate over all GPUs
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600177 gpu = new vk_testing::PhysicalGpu(objs[0]);
Chia-I Wub7cf4452014-12-16 00:04:02 +0800178 delete gpu;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600179
180 // TODO: Verify destroy functions
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600181 err = vkDestroyInstance(inst);
182 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600183}
184
185TEST_F(XglTest, AllocMemory) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600186 VkResult err;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600187 VkMemoryAllocInfo alloc_info = {};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600188 VkGpuMemory gpu_mem;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600189 uint8_t *pData;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600190
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600191 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600192 alloc_info.allocationSize = 1024 * 1024; // 1MB
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600193 alloc_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT |
194 VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700195
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600196
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600197 // TODO: Try variety of memory priorities
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198 alloc_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600199
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600200 err = vkAllocMemory(device(), &alloc_info, &gpu_mem);
201 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600202
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600203 err = vkMapMemory(gpu_mem, 0, (void **) &pData);
204 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600205
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600206 memset(pData, 0x55, alloc_info.allocationSize);
207 EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write";
208
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600209 err = vkUnmapMemory(gpu_mem);
210 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600211
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600212 err = vkFreeMemory(gpu_mem);
213 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600214}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600215
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600216TEST_F(XglTest, Event) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600217 VkEventCreateInfo event_info;
218 VkEvent event;
219 VkMemoryRequirements mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800220 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600221 VkResult err;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600223 // typedef struct VkEventCreateInfo_
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600224 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600226 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600227 // VkFlags flags; // Reserved
228 // } VkEventCreateInfo;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600229 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600230 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600231
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600232 err = vkCreateEvent(device(), &event_info, &event);
233 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600234
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600235 err = vkGetObjectInfo(event, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600236 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600237 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600238
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239 // VkResult VKAPI vkAllocMemory(
240 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600241 // const VkMemoryAllocInfo* pAllocInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 // VkGpuMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600243 VkMemoryAllocInfo mem_info;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600244 VkGpuMemory event_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600245
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600246 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600247
248 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600249 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600250 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600251 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
252 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600253 err = vkAllocMemory(device(), &mem_info, &event_mem);
254 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600255
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256 err = vkBindObjectMemory(event, 0, event_mem, 0);
257 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600258
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600259 err = vkResetEvent(event);
260 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600261
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600262 err = vkGetEventStatus(event);
263 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600264
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600265 err = vkSetEvent(event);
266 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600267
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600268 err = vkGetEventStatus(event);
269 ASSERT_EQ(VK_EVENT_SET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600270
271 // TODO: Test actual synchronization with command buffer event.
272
273 // All done with event memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600274 err = vkBindObjectMemory(event, 0, VK_NULL_HANDLE, 0);
275 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600276
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600277 err = vkDestroyObject(event);
278 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600279}
280
281TEST_F(XglTest, Fence) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600282 VkResult err;
283 VkFenceCreateInfo fence_info;
284 VkFence fence;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600285
286 memset(&fence_info, 0, sizeof(fence_info));
287
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600288 // typedef struct VkFenceCreateInfo_
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600289 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600290 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600291 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292 // VkFlags flags; // Reserved
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600293 fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600294
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600295 err = vkCreateFence(device(), &fence_info, &fence);
296 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600297
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600298 err = vkGetFenceStatus(fence);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600299 // We've not submitted this fence on a command buffer so should get
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600300 // VK_ERROR_UNAVAILABLE
301 EXPECT_EQ(VK_ERROR_UNAVAILABLE, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600302
303 // Test glxWaitForFences
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600304 // VkResult VKAPI vkWaitForFences(
305 // VkDevice device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600306 // uint32_t fenceCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307 // const VkFence* pFences,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600308 // bool32_t waitAll,
309 // uint64_t timeout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600310 err = vkWaitForFences(device(), 1, &fence, VK_TRUE, 0);
311 EXPECT_EQ(VK_ERROR_UNAVAILABLE, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600312
313 // TODO: Attached to command buffer and test GetFenceStatus
314 // TODO: Add some commands and submit the command buffer
315
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600316 err = vkDestroyObject(fence);
317 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600318
319}
320
321#define MAX_QUERY_SLOTS 10
322
323TEST_F(XglTest, Query) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600324 VkQueryPoolCreateInfo query_info;
325 VkQueryPool query_pool;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800326 size_t data_size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600327 VkMemoryRequirements mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800328 size_t query_result_size;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600329 uint32_t *query_result_data;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600330 VkResult err;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600331
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332 // typedef enum VkQueryType_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600333 // {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600334 // VK_QUERY_OCCLUSION = 0x00000000,
335 // VK_QUERY_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600336
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600337 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_OCCLUSION,
338 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_PIPELINE_STATISTICS,
339 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600340 // VK_MAX_ENUM(VkQueryType_)
341 // } VkQueryType;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600343 // typedef struct VkQueryPoolCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600344 // {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600345 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600346 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600347 // VkQueryType queryType;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600348 // uint32_t slots;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600349 // } VkQueryPoolCreateInfo;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600350
351 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600352 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
353 query_info.queryType = VK_QUERY_OCCLUSION;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600354 query_info.slots = MAX_QUERY_SLOTS;
355
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600356 // VkResult VKAPI vkCreateQueryPool(
357 // VkDevice device,
358 // const VkQueryPoolCreateInfo* pCreateInfo,
359 // VkQueryPool* pQueryPool);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600360
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600361 err = vkCreateQueryPool(device(), &query_info, &query_pool);
362 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600363
Jon Ashburnb8e43892014-09-25 14:36:58 -0600364 data_size = sizeof(mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 err = vkGetObjectInfo(query_pool, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600366 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600367 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600368 ASSERT_NE(0, data_size) << "Invalid data_size";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600369
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600370 // VkResult VKAPI vkAllocMemory(
371 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600372 // const VkMemoryAllocInfo* pAllocInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600373 // VkGpuMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600374 VkMemoryAllocInfo mem_info;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600375 VkGpuMemory query_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600376
377 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600379 // TODO: Is a simple multiple all that's needed here?
380 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600381 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600383 // TODO: Should this be pinned? Or maybe a separate test with pinned.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600384 err = vkAllocMemory(device(), &mem_info, &query_mem);
385 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600386
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387 err = vkBindObjectMemory(query_pool, 0, query_mem, 0);
388 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600389
390 // TODO: Test actual synchronization with command buffer event.
391 // TODO: Create command buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600392 // TODO: vkCmdResetQueryPool
393 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600394 // TODO: commands
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600396
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600397 err = vkGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
398 &query_result_size, VK_NULL_HANDLE);
399 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600400
401 if (query_result_size > 0) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600402 query_result_data = new uint32_t [query_result_size];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600403 err = vkGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600404 &query_result_size, query_result_data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600405 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600406
407 // TODO: Test Query result data.
408
409 }
410
411 // All done with QueryPool memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412 err = vkBindObjectMemory(query_pool, 0, VK_NULL_HANDLE, 0);
413 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600414
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415 err = vkDestroyObject(query_pool);
416 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600417}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600418
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600419void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600420{
421 int que_idx;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600422 VkResult err;
423 VkQueue queue;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600424
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600425 const VkPhysicalGpuQueueProperties props = device->gpu().queue_properties()[queue_node_index];
Chia-I Wu3b78d312014-12-29 15:39:23 +0800426 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600427 err = vkGetDeviceQueue(device->obj(), queue_node_index, que_idx, &queue);
428 ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600429 }
430}
431
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700432
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600433void print_queue_info(vk_testing::Device *device, uint32_t queue_node_index)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600434{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600435 uint32_t que_idx;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600436 VkPhysicalGpuQueueProperties queue_props;
437 VkPhysicalGpuProperties props;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600438
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700439 props = device->gpu().properties();
440 queue_props = device->gpu().queue_properties()[queue_node_index];
441 ASSERT_NE(0, queue_props.queueCount) << "No Queues available at Node Index #" << queue_node_index << " GPU: " << props.gpuName;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443// VkResult VKAPI vkGetDeviceQueue(
444// VkDevice device,
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700445// uint32_t queueNodeIndex,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600446// uint32_t queueIndex,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600447// VkQueue* pQueue);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600448 /*
449 * queue handles are retrieved from the device by calling
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450 * vkGetDeviceQueue() with a queue node index and a requested logical
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700451 * queue ID. The queue node index is the index into the array of
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600452 * VkPhysicalGpuQueueProperties returned by GetGpuInfo. Each
453 * queue node index has different attributes specified by the VkQueueFlags property.
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700454 * The logical queue ID is a sequential number starting from zero
455 * and referencing up to the number of queues supported of that node index
456 * at device creation.
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600457 */
458
Chia-I Wu3b78d312014-12-29 15:39:23 +0800459 for (que_idx = 0; que_idx < queue_props.queueCount; que_idx++) {
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600460
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600461// typedef enum VkQueueFlags_
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600462// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600463// VK_QUEUE_GRAPHICS_BIT = 0x00000001, // Queue supports graphics operations
464// VK_QUEUE_COMPUTE_BIT = 0x00000002, // Queue supports compute operations
465// VK_QUEUE_DMA_BIT = 0x00000004, // Queue supports DMA operations
466// VK_QUEUE_EXTENDED_BIT = 0x80000000 // Extended queue
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600467// } VkQueueFlags;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600468
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600469 if (queue_props.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700470 getQueue(device, queue_node_index, "Graphics");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600471 }
472
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473 if (queue_props.queueFlags & VK_QUEUE_COMPUTE_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700474 getQueue(device, queue_node_index, "Compute");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600475 }
476
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477 if (queue_props.queueFlags & VK_QUEUE_DMA_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700478 getQueue(device, queue_node_index, "DMA");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600479 }
480
481 // TODO: What do we do about EXTENDED_BIT?
482
483 /* Guide: pg 34:
484 * The queue objects cannot be destroyed explicitly by an application
485 * and are automatically destroyed when the associated device is destroyed.
486 * Once the device is destroyed, attempting to use a queue results in
487 * undefined behavior.
488 */
489 }
490}
491
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700492TEST_F(XglTest, Queue)
493{
494 uint32_t i;
495
496 for (i = 0; i < m_device->gpu().queue_properties().size(); i++) {
497 print_queue_info(m_device, i);
498 }
499}
500
501
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600502void XglTest::CreateImageTest()
503{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600504 VkResult err;
505 VkImage image;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600506 uint32_t w, h, mipCount;
507 size_t size;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600508 VkFormat fmt;
509 VkFormatProperties image_fmt;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800510 size_t data_size;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600511
512 w =512;
513 h = 256;
514 mipCount = 0;
515
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600516 uint32_t _w = w;
517 uint32_t _h = h;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600518 while( ( _w > 0 ) || ( _h > 0 ) )
519 {
520 _w >>= 1;
521 _h >>= 1;
522 mipCount++;
523 }
524
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600525 fmt = VK_FMT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600526 // TODO: Pick known good format rather than just expect common format
527 /*
528 * XXX: What should happen if given NULL HANDLE for the pData argument?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600529 * We're not requesting VK_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600530 * an expectation that pData is a valid pointer.
531 * However, why include a returned size value? That implies that the
532 * amount of data may vary and that doesn't work well for using a
533 * fixed structure.
534 */
535
Jon Ashburnb8e43892014-09-25 14:36:58 -0600536 size = sizeof(image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600537 err = vkGetFormatInfo(device(), fmt,
538 VK_INFO_TYPE_FORMAT_PROPERTIES,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600539 &size, &image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600541
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600542// typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600543// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600544// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600545// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600546// VkImageType imageType;
547// VkFormat format;
548// VkExtent3D extent;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600549// uint32_t mipLevels;
550// uint32_t arraySize;
551// uint32_t samples;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600552// VkImageTiling tiling;
553// VkFlags usage; // VkImageUsageFlags
554// VkFlags flags; // VkImageCreateFlags
555// } VkImageCreateInfo;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600556
557
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600558 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600559 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
560 imageCreateInfo.imageType = VK_IMAGE_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600561 imageCreateInfo.format = fmt;
562 imageCreateInfo.arraySize = 1;
563 imageCreateInfo.extent.width = w;
564 imageCreateInfo.extent.height = h;
565 imageCreateInfo.extent.depth = 1;
566 imageCreateInfo.mipLevels = mipCount;
567 imageCreateInfo.samples = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600568 imageCreateInfo.tiling = VK_LINEAR_TILING;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600569
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600570 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600571
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600572// VkResult VKAPI vkCreateImage(
573// VkDevice device,
574// const VkImageCreateInfo* pCreateInfo,
575// VkImage* pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576 err = vkCreateImage(device(), &imageCreateInfo, &image);
577 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600578
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600579 // Verify image resources
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600580// VkResult VKAPI vkGetImageSubresourceInfo(
581// VkImage image,
582// const VkImageSubresource* pSubresource,
583// VkSubresourceInfoType infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600584// size_t* pDataSize,
585// void* pData);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600586// typedef struct VkSubresourceLayout_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600587// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600588// VkGpuSize offset; // Specified in bytes
589// VkGpuSize size; // Specified in bytes
590// VkGpuSize rowPitch; // Specified in bytes
591// VkGpuSize depthPitch; // Specified in bytes
592// } VkSubresourceLayout;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600593
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600594// typedef struct VkImageSubresource_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600595// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600596// VkImageAspect aspect;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600597// uint32_t mipLevel;
598// uint32_t arraySlice;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600599// } VkImageSubresource;
600// typedef enum VkSubresourceInfoType_
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600601// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600602// // Info type for vkGetImageSubresourceInfo()
603// VK_INFO_TYPE_SUBRESOURCE_LAYOUT = 0x00000000,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600605// VK_MAX_ENUM(VkSubresourceInfoType_)
606// } VkSubresourceInfoType;
607 VkImageSubresource subresource = {};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600608 subresource.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600609 subresource.arraySlice = 0;
610
611 _w = w;
612 _h = h;
613 while( ( _w > 0 ) || ( _h > 0 ) )
614 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600615 VkSubresourceLayout layout = {};
Jon Ashburnb8e43892014-09-25 14:36:58 -0600616 data_size = sizeof(layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600617 err = vkGetImageSubresourceInfo(image, &subresource, VK_INFO_TYPE_SUBRESOURCE_LAYOUT,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600618 &data_size, &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600619 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600620 ASSERT_EQ(sizeof(VkSubresourceLayout), data_size) << "Invalid structure (VkSubresourceLayout) size";
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600621
622 // TODO: 4 should be replaced with pixel size for given format
623 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
624 _w >>= 1;
625 _h >>= 1;
626
627 subresource.mipLevel++;
628 }
629
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600630 VkMemoryRequirements mem_req;
Jon Ashburnb8e43892014-09-25 14:36:58 -0600631 data_size = sizeof(mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600632 err = vkGetObjectInfo(image, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600633 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600634 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600635 ASSERT_EQ(data_size, sizeof(mem_req));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600636 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect images to require memory";
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600637 // VkResult VKAPI vkAllocMemory(
638 // VkDevice device,
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600639 // const VkMemoryAllocInfo* pAllocInfo,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600640 // VkGpuMemory* pMem);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600641 VkMemoryAllocInfo mem_info = {};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600642 VkGpuMemory image_mem;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600643
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600644 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Mark Lobodzinski97dcd042015-04-16 08:52:00 -0500645 mem_info.pNext = NULL;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600646 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600647 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
649 err = vkAllocMemory(device(), &mem_info, &image_mem);
650 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600651
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600652 err = vkBindObjectMemory(image, 0, image_mem, 0);
653 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600654
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600655// typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600656// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600657// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600658// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600659// VkImage image;
660// VkImageViewType viewType;
661// VkFormat format;
662// VkChannelMapping channels;
663// VkImageSubresourceRange subresourceRange;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600664// float minLod;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600665// } VkImageViewCreateInfo;
666 VkImageViewCreateInfo viewInfo = {};
667 VkImageView view;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600668 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600669 viewInfo.image = image;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600670 viewInfo.viewType = VK_IMAGE_VIEW_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600671 viewInfo.format = fmt;
672
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600673 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
674 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
675 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
676 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600677
678 viewInfo.subresourceRange.baseArraySlice = 0;
679 viewInfo.subresourceRange.arraySize = 1;
680 viewInfo.subresourceRange.baseMipLevel = 0;
681 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600682 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600683
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600684// VkResult VKAPI vkCreateImageView(
685// VkDevice device,
686// const VkImageViewCreateInfo* pCreateInfo,
687// VkImageView* pView);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600688
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600689 err = vkCreateImageView(device(), &viewInfo, &view);
690 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600691
692 // TODO: Test image memory.
693
694 // All done with image memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600695 ASSERT_VK_SUCCESS(vkBindObjectMemory(image, 0, VK_NULL_HANDLE, 0));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600696
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600697 ASSERT_VK_SUCCESS(vkFreeMemory(image_mem));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600698
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600699 ASSERT_VK_SUCCESS(vkDestroyObject(image));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600700}
701
702TEST_F(XglTest, CreateImage) {
703 CreateImageTest();
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600704}
705
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600706void XglTest::CreateCommandBufferTest()
707{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600708 VkResult err;
709 VkCmdBufferCreateInfo info = {};
710 VkCmdBuffer cmdBuffer;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600711
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600712// typedef struct VkCmdBufferCreateInfo_
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600713// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600714// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600715// const void* pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600716// VK_QUEUE_TYPE queueType;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600717// VkFlags flags;
718// } VkCmdBufferCreateInfo;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600719
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600720 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700721 info.queueNodeIndex = graphics_queue_node_index;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600722 err = vkCreateCommandBuffer(device(), &info, &cmdBuffer);
723 ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed";
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600724
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600725 ASSERT_VK_SUCCESS(vkDestroyObject(cmdBuffer));
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600726}
727
728TEST_F(XglTest, TestComandBuffer) {
729 CreateCommandBufferTest();
730}
731
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732void XglTest::CreateShader(VkShader *pshader)
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600733{
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600734 void *code;
735 uint32_t codeSize;
Cody Northropacfb0492015-03-17 15:55:58 -0600736 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600737 VkResult err;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600738
Cody Northropacfb0492015-03-17 15:55:58 -0600739 codeSize = sizeof(struct icd_spv_header) + 100;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600740 code = malloc(codeSize);
741 ASSERT_TRUE(NULL != code) << "malloc failed!";
742
743 memset(code, 0, codeSize);
744
Cody Northropacfb0492015-03-17 15:55:58 -0600745 // Indicate that this is SPV data.
746 pSPV = (struct icd_spv_header *) code;
747 pSPV->magic = ICD_SPV_MAGIC;
748 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600749
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600750// typedef struct VkShaderCreateInfo_
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600751// {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600752// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600753// const void* pNext; // Pointer to next structure
754// size_t codeSize; // Specified in bytes
755// const void* pCode;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600756// VkFlags flags; // Reserved
757// } VkShaderCreateInfo;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600758
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600759 VkShaderCreateInfo createInfo;
760 VkShader shader;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600761
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600762 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600763 createInfo.pNext = NULL;
764 createInfo.pCode = code;
765 createInfo.codeSize = codeSize;
766 createInfo.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600767 err = vkCreateShader(device(), &createInfo, &shader);
768 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600769
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600770 *pshader = shader;
771}
772
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600773int main(int argc, char **argv) {
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600774 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600776 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600777}