blob: 9de9dfc1838dbdde3ea0da441a504ddbfc63d5ae [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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060074 void CreateShader(VK_SHADER *pshader);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -060075
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060076 VK_DEVICE device() {return m_device->obj();}
Courtney Goeltzenleuchterb85c5812014-08-19 18:35:50 -060077
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -060078protected:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060079 VK_APPLICATION_INFO app_info;
80 VK_INSTANCE inst;
81 VK_PHYSICAL_GPU 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;
86 VK_PHYSICAL_GPU_PROPERTIES props;
87 std::vector<VK_PHYSICAL_GPU_QUEUE_PROPERTIES> 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060091 VK_RESULT 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;
101 VK_INSTANCE_CREATE_INFO inst_info = {};
102 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) {
137 VK_APPLICATION_INFO app_info = {};
138 VK_INSTANCE inst;
139 VK_PHYSICAL_GPU objs[VK_MAX_PHYSICAL_GPUS];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600140 uint32_t gpu_count;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600141 VK_RESULT err;
142 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600146 VK_INSTANCE_CREATE_INFO inst_info = {};
147 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600186 VK_RESULT err;
187 VK_MEMORY_ALLOC_INFO alloc_info = {};
188 VK_GPU_MEMORY 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;
195 alloc_info.memType = VK_MEMORY_TYPE_OTHER;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700196
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600197
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600198 // TODO: Try variety of memory priorities
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600199 alloc_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600200
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600201 err = vkAllocMemory(device(), &alloc_info, &gpu_mem);
202 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600203
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600204 err = vkMapMemory(gpu_mem, 0, (void **) &pData);
205 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600206
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600207 memset(pData, 0x55, alloc_info.allocationSize);
208 EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write";
209
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600210 err = vkUnmapMemory(gpu_mem);
211 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600212
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600213 err = vkFreeMemory(gpu_mem);
214 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600215}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600216
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600217TEST_F(XglTest, Event) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600218 VK_EVENT_CREATE_INFO event_info;
219 VK_EVENT event;
220 VK_MEMORY_REQUIREMENTS mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800221 size_t data_size = sizeof(mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 VK_RESULT err;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600223
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600224 // typedef struct _VK_EVENT_CREATE_INFO
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600225 // {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600226 // VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600227 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600228 // VK_FLAGS flags; // Reserved
229 // } VK_EVENT_CREATE_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600230 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600231 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600232
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600233 err = vkCreateEvent(device(), &event_info, &event);
234 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600235
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600236 err = vkGetObjectInfo(event, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600237 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600238 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600239
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600240 // VK_RESULT VKAPI vkAllocMemory(
241 // VK_DEVICE device,
242 // const VK_MEMORY_ALLOC_INFO* pAllocInfo,
243 // VK_GPU_MEMORY* pMem);
244 VK_MEMORY_ALLOC_INFO mem_info;
245 VK_GPU_MEMORY event_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600246
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600247 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600248
249 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600251 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600252 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
253 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
254 mem_info.memType = VK_MEMORY_TYPE_OTHER;
255 err = vkAllocMemory(device(), &mem_info, &event_mem);
256 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600257
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600258 err = vkBindObjectMemory(event, 0, event_mem, 0);
259 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600260
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600261 err = vkResetEvent(event);
262 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600263
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600264 err = vkGetEventStatus(event);
265 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600266
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600267 err = vkSetEvent(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_SET, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600272
273 // TODO: Test actual synchronization with command buffer event.
274
275 // All done with event memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600276 err = vkBindObjectMemory(event, 0, VK_NULL_HANDLE, 0);
277 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600278
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279 err = vkDestroyObject(event);
280 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600281}
282
283TEST_F(XglTest, Fence) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600284 VK_RESULT err;
285 VK_FENCE_CREATE_INFO fence_info;
286 VK_FENCE fence;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600287
288 memset(&fence_info, 0, sizeof(fence_info));
289
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600290 // typedef struct _VK_FENCE_CREATE_INFO
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600291 // {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600292 // VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600293 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 // VK_FLAGS flags; // Reserved
295 fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600296
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600297 err = vkCreateFence(device(), &fence_info, &fence);
298 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600299
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600300 err = vkGetFenceStatus(fence);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600301 // We've not submitted this fence on a command buffer so should get
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600302 // VK_ERROR_UNAVAILABLE
303 EXPECT_EQ(VK_ERROR_UNAVAILABLE, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600304
305 // Test glxWaitForFences
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600306 // VK_RESULT VKAPI vkWaitForFences(
307 // VK_DEVICE device,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600308 // uint32_t fenceCount,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600309 // const VK_FENCE* pFences,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600310 // bool32_t waitAll,
311 // uint64_t timeout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600312 err = vkWaitForFences(device(), 1, &fence, VK_TRUE, 0);
313 EXPECT_EQ(VK_ERROR_UNAVAILABLE, err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600314
315 // TODO: Attached to command buffer and test GetFenceStatus
316 // TODO: Add some commands and submit the command buffer
317
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600318 err = vkDestroyObject(fence);
319 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600320
321}
322
323#define MAX_QUERY_SLOTS 10
324
325TEST_F(XglTest, Query) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600326 VK_QUERY_POOL_CREATE_INFO query_info;
327 VK_QUERY_POOL query_pool;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800328 size_t data_size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600329 VK_MEMORY_REQUIREMENTS mem_req;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800330 size_t query_result_size;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600331 uint32_t *query_result_data;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600332 VK_RESULT err;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600333
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600334 // typedef enum _VK_QUERY_TYPE
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600335 // {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600336 // VK_QUERY_OCCLUSION = 0x00000000,
337 // VK_QUERY_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600338
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600339 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_OCCLUSION,
340 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_PIPELINE_STATISTICS,
341 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
342 // VK_MAX_ENUM(_VK_QUERY_TYPE)
343 // } VK_QUERY_TYPE;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600344
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345 // typedef struct _VK_QUERY_POOL_CREATE_INFO
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600346 // {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600347 // VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600348 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600349 // VK_QUERY_TYPE queryType;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 // uint32_t slots;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600351 // } VK_QUERY_POOL_CREATE_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600352
353 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600354 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
355 query_info.queryType = VK_QUERY_OCCLUSION;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600356 query_info.slots = MAX_QUERY_SLOTS;
357
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600358 // VK_RESULT VKAPI vkCreateQueryPool(
359 // VK_DEVICE device,
360 // const VK_QUERY_POOL_CREATE_INFO* pCreateInfo,
361 // VK_QUERY_POOL* pQueryPool);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600362
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600363 err = vkCreateQueryPool(device(), &query_info, &query_pool);
364 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600365
Jon Ashburnb8e43892014-09-25 14:36:58 -0600366 data_size = sizeof(mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600367 err = vkGetObjectInfo(query_pool, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600368 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600369 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600370 ASSERT_NE(0, data_size) << "Invalid data_size";
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600371
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600372 // VK_RESULT VKAPI vkAllocMemory(
373 // VK_DEVICE device,
374 // const VK_MEMORY_ALLOC_INFO* pAllocInfo,
375 // VK_GPU_MEMORY* pMem);
376 VK_MEMORY_ALLOC_INFO mem_info;
377 VK_GPU_MEMORY query_mem;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600378
379 memset(&mem_info, 0, sizeof(mem_info));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600380 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600381 // TODO: Is a simple multiple all that's needed here?
382 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600383 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
384 mem_info.memType = VK_MEMORY_TYPE_OTHER;
385 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600386 // TODO: Should this be pinned? Or maybe a separate test with pinned.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387 err = vkAllocMemory(device(), &mem_info, &query_mem);
388 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600389
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390 err = vkBindObjectMemory(query_pool, 0, query_mem, 0);
391 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600392
393 // TODO: Test actual synchronization with command buffer event.
394 // TODO: Create command buffer
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395 // TODO: vkCmdResetQueryPool
396 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600397 // TODO: commands
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600399
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600400 err = vkGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
401 &query_result_size, VK_NULL_HANDLE);
402 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600403
404 if (query_result_size > 0) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600405 query_result_data = new uint32_t [query_result_size];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406 err = vkGetQueryPoolResults(query_pool, 0, MAX_QUERY_SLOTS,
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600407 &query_result_size, query_result_data);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600408 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600409
410 // TODO: Test Query result data.
411
412 }
413
414 // All done with QueryPool memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415 err = vkBindObjectMemory(query_pool, 0, VK_NULL_HANDLE, 0);
416 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600417
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 err = vkDestroyObject(query_pool);
419 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600420}
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600421
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600423{
424 int que_idx;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 VK_RESULT err;
426 VK_QUEUE queue;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600427
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428 const VK_PHYSICAL_GPU_QUEUE_PROPERTIES props = device->gpu().queue_properties()[queue_node_index];
Chia-I Wu3b78d312014-12-29 15:39:23 +0800429 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 err = vkGetDeviceQueue(device->obj(), queue_node_index, que_idx, &queue);
431 ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600432 }
433}
434
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700435
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600436void print_queue_info(vk_testing::Device *device, uint32_t queue_node_index)
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600437{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600438 uint32_t que_idx;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600439 VK_PHYSICAL_GPU_QUEUE_PROPERTIES queue_props;
440 VK_PHYSICAL_GPU_PROPERTIES props;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600441
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700442 props = device->gpu().properties();
443 queue_props = device->gpu().queue_properties()[queue_node_index];
444 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 -0600445
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600446// VK_RESULT VKAPI vkGetDeviceQueue(
447// VK_DEVICE device,
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700448// uint32_t queueNodeIndex,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600449// uint32_t queueIndex,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450// VK_QUEUE* pQueue);
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600451 /*
452 * queue handles are retrieved from the device by calling
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600453 * vkGetDeviceQueue() with a queue node index and a requested logical
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700454 * queue ID. The queue node index is the index into the array of
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600455 * VK_PHYSICAL_GPU_QUEUE_PROPERTIES returned by GetGpuInfo. Each
456 * queue node index has different attributes specified by the VK_QUEUE_FLAGS property.
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700457 * The logical queue ID is a sequential number starting from zero
458 * and referencing up to the number of queues supported of that node index
459 * at device creation.
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600460 */
461
Chia-I Wu3b78d312014-12-29 15:39:23 +0800462 for (que_idx = 0; que_idx < queue_props.queueCount; que_idx++) {
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600463
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600464// typedef enum _VK_QUEUE_FLAGS
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600465// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600466// VK_QUEUE_GRAPHICS_BIT = 0x00000001, // Queue supports graphics operations
467// VK_QUEUE_COMPUTE_BIT = 0x00000002, // Queue supports compute operations
468// VK_QUEUE_DMA_BIT = 0x00000004, // Queue supports DMA operations
469// VK_QUEUE_EXTENDED_BIT = 0x80000000 // Extended queue
470// } VK_QUEUE_FLAGS;
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600471
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472 if (queue_props.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700473 getQueue(device, queue_node_index, "Graphics");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600474 }
475
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600476 if (queue_props.queueFlags & VK_QUEUE_COMPUTE_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700477 getQueue(device, queue_node_index, "Compute");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600478 }
479
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480 if (queue_props.queueFlags & VK_QUEUE_DMA_BIT) {
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700481 getQueue(device, queue_node_index, "DMA");
Courtney Goeltzenleuchtercc32aa92014-08-14 10:15:09 -0600482 }
483
484 // TODO: What do we do about EXTENDED_BIT?
485
486 /* Guide: pg 34:
487 * The queue objects cannot be destroyed explicitly by an application
488 * and are automatically destroyed when the associated device is destroyed.
489 * Once the device is destroyed, attempting to use a queue results in
490 * undefined behavior.
491 */
492 }
493}
494
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700495TEST_F(XglTest, Queue)
496{
497 uint32_t i;
498
499 for (i = 0; i < m_device->gpu().queue_properties().size(); i++) {
500 print_queue_info(m_device, i);
501 }
502}
503
504
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600505void XglTest::CreateImageTest()
506{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600507 VK_RESULT err;
508 VK_IMAGE image;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600509 uint32_t w, h, mipCount;
510 size_t size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600511 VK_FORMAT fmt;
512 VK_FORMAT_PROPERTIES image_fmt;
Chia-I Wu54ed0792014-12-27 14:14:50 +0800513 size_t data_size;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600514
515 w =512;
516 h = 256;
517 mipCount = 0;
518
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600519 uint32_t _w = w;
520 uint32_t _h = h;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600521 while( ( _w > 0 ) || ( _h > 0 ) )
522 {
523 _w >>= 1;
524 _h >>= 1;
525 mipCount++;
526 }
527
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600528 fmt = VK_FMT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600529 // TODO: Pick known good format rather than just expect common format
530 /*
531 * XXX: What should happen if given NULL HANDLE for the pData argument?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600532 * We're not requesting VK_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600533 * an expectation that pData is a valid pointer.
534 * However, why include a returned size value? That implies that the
535 * amount of data may vary and that doesn't work well for using a
536 * fixed structure.
537 */
538
Jon Ashburnb8e43892014-09-25 14:36:58 -0600539 size = sizeof(image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600540 err = vkGetFormatInfo(device(), fmt,
541 VK_INFO_TYPE_FORMAT_PROPERTIES,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600542 &size, &image_fmt);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600543 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600544
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600545// typedef struct _VK_IMAGE_CREATE_INFO
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600546// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547// VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600548// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600549// VK_IMAGE_TYPE imageType;
550// VK_FORMAT format;
551// VK_EXTENT3D extent;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600552// uint32_t mipLevels;
553// uint32_t arraySize;
554// uint32_t samples;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600555// VK_IMAGE_TILING tiling;
556// VK_FLAGS usage; // VK_IMAGE_USAGE_FLAGS
557// VK_FLAGS flags; // VK_IMAGE_CREATE_FLAGS
558// } VK_IMAGE_CREATE_INFO;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600559
560
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600561 VK_IMAGE_CREATE_INFO imageCreateInfo = {};
562 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
563 imageCreateInfo.imageType = VK_IMAGE_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600564 imageCreateInfo.format = fmt;
565 imageCreateInfo.arraySize = 1;
566 imageCreateInfo.extent.width = w;
567 imageCreateInfo.extent.height = h;
568 imageCreateInfo.extent.depth = 1;
569 imageCreateInfo.mipLevels = mipCount;
570 imageCreateInfo.samples = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600571 imageCreateInfo.tiling = VK_LINEAR_TILING;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600572
573// Image usage flags
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600574// typedef enum _VK_IMAGE_USAGE_FLAGS
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600575// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576// VK_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001,
577// VK_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002,
578// VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004,
579// VK_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008,
580// } VK_IMAGE_USAGE_FLAGS;
581 imageCreateInfo.usage = VK_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600582
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600583// VK_RESULT VKAPI vkCreateImage(
584// VK_DEVICE device,
585// const VK_IMAGE_CREATE_INFO* pCreateInfo,
586// VK_IMAGE* pImage);
587 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600591// VK_RESULT VKAPI vkGetImageSubresourceInfo(
592// VK_IMAGE image,
593// const VK_IMAGE_SUBRESOURCE* pSubresource,
594// VK_SUBRESOURCE_INFO_TYPE infoType,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600595// size_t* pDataSize,
596// void* pData);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600597// typedef struct _VK_SUBRESOURCE_LAYOUT
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600598// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600599// VK_GPU_SIZE offset; // Specified in bytes
600// VK_GPU_SIZE size; // Specified in bytes
601// VK_GPU_SIZE rowPitch; // Specified in bytes
602// VK_GPU_SIZE depthPitch; // Specified in bytes
603// } VK_SUBRESOURCE_LAYOUT;
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600604
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600605// typedef struct _VK_IMAGE_SUBRESOURCE
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600606// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607// VK_IMAGE_ASPECT aspect;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600608// uint32_t mipLevel;
609// uint32_t arraySlice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600610// } VK_IMAGE_SUBRESOURCE;
611// typedef enum _VK_SUBRESOURCE_INFO_TYPE
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600612// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600613// // Info type for vkGetImageSubresourceInfo()
614// VK_INFO_TYPE_SUBRESOURCE_LAYOUT = 0x00000000,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600615
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600616// VK_MAX_ENUM(_VK_SUBRESOURCE_INFO_TYPE)
617// } VK_SUBRESOURCE_INFO_TYPE;
618 VK_IMAGE_SUBRESOURCE subresource = {};
619 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600626 VK_SUBRESOURCE_LAYOUT layout = {};
Jon Ashburnb8e43892014-09-25 14:36:58 -0600627 data_size = sizeof(layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600628 err = vkGetImageSubresourceInfo(image, &subresource, VK_INFO_TYPE_SUBRESOURCE_LAYOUT,
Courtney Goeltzenleuchterac3b73a2014-08-14 17:40:57 -0600629 &data_size, &layout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600630 ASSERT_VK_SUCCESS(err);
631 ASSERT_EQ(sizeof(VK_SUBRESOURCE_LAYOUT), data_size) << "Invalid structure (VK_SUBRESOURCE_LAYOUT) 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600641 VK_MEMORY_ALLOC_IMAGE_INFO img_alloc = {
642 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO,
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700643 .pNext = NULL,
644
645 };
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600646 VK_MEMORY_REQUIREMENTS mem_req;
647 VK_IMAGE_MEMORY_REQUIREMENTS img_reqs;
648 size_t img_reqs_size = sizeof(VK_IMAGE_MEMORY_REQUIREMENTS);
Jon Ashburnb8e43892014-09-25 14:36:58 -0600649 data_size = sizeof(mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600650 err = vkGetObjectInfo(image, VK_INFO_TYPE_MEMORY_REQUIREMENTS,
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600651 &data_size, &mem_req);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600652 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600653 ASSERT_EQ(data_size, sizeof(mem_req));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600654 ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect images to require memory";
655 err = vkGetObjectInfo(image, VK_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS,
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700656 &img_reqs_size, &img_reqs);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600657 ASSERT_VK_SUCCESS(err);
658 ASSERT_EQ(img_reqs_size, sizeof(VK_IMAGE_MEMORY_REQUIREMENTS));
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700659 img_alloc.usage = img_reqs.usage;
660 img_alloc.formatClass = img_reqs.formatClass;
661 img_alloc.samples = img_reqs.samples;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600662 // VK_RESULT VKAPI vkAllocMemory(
663 // VK_DEVICE device,
664 // const VK_MEMORY_ALLOC_INFO* pAllocInfo,
665 // VK_GPU_MEMORY* pMem);
666 VK_MEMORY_ALLOC_INFO mem_info = {};
667 VK_GPU_MEMORY image_mem;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600668
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600669 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Jon Ashburnc6ae13d2015-01-19 15:00:26 -0700670 mem_info.pNext = &img_alloc;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600671 mem_info.allocationSize = mem_req.size;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600672 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
673 mem_info.memType = VK_MEMORY_TYPE_IMAGE;
674 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
675 err = vkAllocMemory(device(), &mem_info, &image_mem);
676 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600677
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678 err = vkBindObjectMemory(image, 0, image_mem, 0);
679 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600680
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600681// typedef struct _VK_IMAGE_VIEW_CREATE_INFO
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600682// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600683// VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600684// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685// VK_IMAGE image;
686// VK_IMAGE_VIEW_TYPE viewType;
687// VK_FORMAT format;
688// VK_CHANNEL_MAPPING channels;
689// VK_IMAGE_SUBRESOURCE_RANGE subresourceRange;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600690// float minLod;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600691// } VK_IMAGE_VIEW_CREATE_INFO;
692 VK_IMAGE_VIEW_CREATE_INFO viewInfo = {};
693 VK_IMAGE_VIEW view;
694 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600695 viewInfo.image = image;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600696 viewInfo.viewType = VK_IMAGE_VIEW_2D;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600697 viewInfo.format = fmt;
698
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600699 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
700 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
701 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
702 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600703
704 viewInfo.subresourceRange.baseArraySlice = 0;
705 viewInfo.subresourceRange.arraySize = 1;
706 viewInfo.subresourceRange.baseMipLevel = 0;
707 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600708 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600709
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600710// VK_RESULT VKAPI vkCreateImageView(
711// VK_DEVICE device,
712// const VK_IMAGE_VIEW_CREATE_INFO* pCreateInfo,
713// VK_IMAGE_VIEW* pView);
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600714
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600715 err = vkCreateImageView(device(), &viewInfo, &view);
716 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600717
718 // TODO: Test image memory.
719
720 // All done with image memory, clean up
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600721 ASSERT_VK_SUCCESS(vkBindObjectMemory(image, 0, VK_NULL_HANDLE, 0));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600722
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 ASSERT_VK_SUCCESS(vkFreeMemory(image_mem));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600724
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600725 ASSERT_VK_SUCCESS(vkDestroyObject(image));
Courtney Goeltzenleuchter9c3aad02014-08-13 17:55:12 -0600726}
727
728TEST_F(XglTest, CreateImage) {
729 CreateImageTest();
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600730}
731
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600732void XglTest::CreateCommandBufferTest()
733{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600734 VK_RESULT err;
735 VK_CMD_BUFFER_CREATE_INFO info = {};
736 VK_CMD_BUFFER cmdBuffer;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600737
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600738// typedef struct _VK_CMD_BUFFER_CREATE_INFO
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600739// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600740// VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600741// const void* pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742// VK_QUEUE_TYPE queueType;
743// VK_FLAGS flags;
744// } VK_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600745
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600746 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -0700747 info.queueNodeIndex = graphics_queue_node_index;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600748 err = vkCreateCommandBuffer(device(), &info, &cmdBuffer);
749 ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed";
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600750
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600751 ASSERT_VK_SUCCESS(vkDestroyObject(cmdBuffer));
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600752}
753
754TEST_F(XglTest, TestComandBuffer) {
755 CreateCommandBufferTest();
756}
757
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758void XglTest::CreateShader(VK_SHADER *pshader)
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600759{
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600760 void *code;
761 uint32_t codeSize;
Cody Northropacfb0492015-03-17 15:55:58 -0600762 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600763 VK_RESULT err;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600764
Cody Northropacfb0492015-03-17 15:55:58 -0600765 codeSize = sizeof(struct icd_spv_header) + 100;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600766 code = malloc(codeSize);
767 ASSERT_TRUE(NULL != code) << "malloc failed!";
768
769 memset(code, 0, codeSize);
770
Cody Northropacfb0492015-03-17 15:55:58 -0600771 // Indicate that this is SPV data.
772 pSPV = (struct icd_spv_header *) code;
773 pSPV->magic = ICD_SPV_MAGIC;
774 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600775
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600776// typedef struct _VK_SHADER_CREATE_INFO
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600777// {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600778// VK_STRUCTURE_TYPE sType; // Must be VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600779// const void* pNext; // Pointer to next structure
780// size_t codeSize; // Specified in bytes
781// const void* pCode;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600782// VK_FLAGS flags; // Reserved
783// } VK_SHADER_CREATE_INFO;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600784
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600785 VK_SHADER_CREATE_INFO createInfo;
786 VK_SHADER shader;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600787
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600788 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600789 createInfo.pNext = NULL;
790 createInfo.pCode = code;
791 createInfo.codeSize = codeSize;
792 createInfo.flags = 0;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793 err = vkCreateShader(device(), &createInfo, &shader);
794 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtera693ed22014-08-19 13:34:28 -0600795
Courtney Goeltzenleuchter0842df72014-08-20 15:26:55 -0600796 *pshader = shader;
797}
798
Courtney Goeltzenleuchter6b814b32014-08-12 09:59:36 -0600799int main(int argc, char **argv) {
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600800 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600801 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtered56abc2014-08-12 14:12:22 -0600802 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter7087dde2014-08-11 18:19:35 -0600803}