blob: b755d768f264e2613344458174a16be869b950bf [file] [log] [blame]
Courtney Goeltzenleuchter447ed582014-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 Goeltzenleuchtercc9da542014-08-12 14:12:22 -060030
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031// VK tests
Courtney Goeltzenleuchtercc9da542014-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060054// Verify VK driver initialization
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060055
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060056#include <stdlib.h>
57#include <stdio.h>
58#include <stdbool.h>
59#include <string.h>
60
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060061#include <vulkan.h>
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060062#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060063
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060064#include "vktestbinding.h"
Chia-I Wufe84fe12014-12-29 15:39:23 +080065#include "test_common.h"
Cody Northrop054a4702015-03-17 14:54:35 -060066#include "icd-spv.h"
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060067
Jon Ashburn83a64252015-04-15 11:31:12 -060068#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
69
Tony-LunarGd61e1e52015-05-15 12:42:49 -060070class VkTest : public ::testing::Test {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060071public:
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -060072 void CreateImageTest();
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -060073 void CreateCommandBufferTest();
74 void CreatePipelineTest();
75 void CreateShaderTest();
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060076 void CreateShader(VkShader *pshader);
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060077
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060078 VkDevice device() {return m_device->obj();}
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060079
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060080protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060081 VkApplicationInfo app_info;
82 VkInstance inst;
Tony Barbourd1c35722015-04-16 15:59:00 -060083 VkPhysicalDevice objs[16];
Mark Lobodzinski17caf572015-01-29 08:55:56 -060084 uint32_t gpu_count;
Chia-I Wufe84fe12014-12-29 15:39:23 +080085
Mark Lobodzinski17caf572015-01-29 08:55:56 -060086 uint32_t m_device_id;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060087 vk_testing::Device *m_device;
Tony Barbourd1c35722015-04-16 15:59:00 -060088 VkPhysicalDeviceProperties props;
89 std::vector<VkPhysicalDeviceQueueProperties> queue_props;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -070090 uint32_t graphics_queue_node_index;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060091
92 virtual void SetUp() {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060093 VkResult err;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -070094 int i;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060095
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060096 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060097 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +080098 this->app_info.pAppName = "base";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060099 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800100 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600101 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600102 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600103 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600104 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600105 inst_info.pNext = NULL;
106 inst_info.pAppInfo = &app_info;
107 inst_info.pAllocCb = NULL;
108 inst_info.extensionCount = 0;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600109 inst_info.pEnabledExtensions = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600110 err = vkCreateInstance(&inst_info, &inst);
111 ASSERT_VK_SUCCESS(err);
Jon Ashburn83a64252015-04-15 11:31:12 -0600112 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL);
113 ASSERT_VK_SUCCESS(err);
114 ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs";
115 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600116 ASSERT_VK_SUCCESS(err);
Jon Ashburnbf843b22014-11-26 11:06:49 -0700117 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600118
Chia-I Wufe84fe12014-12-29 15:39:23 +0800119 m_device_id = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600120 this->m_device = new vk_testing::Device(objs[m_device_id]);
Chia-I Wufe84fe12014-12-29 15:39:23 +0800121 this->m_device->init();
122
123 props = m_device->gpu().properties();
Chia-I Wufe84fe12014-12-29 15:39:23 +0800124
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700125 queue_props = this->m_device->gpu().queue_properties();
126 for (i = 0; i < queue_props.size(); i++) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600127 if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700128 graphics_queue_node_index = i;
129 break;
130 }
131 }
132 ASSERT_LT(i, queue_props.size()) << "Could not find a Queue with Graphics support";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600133 }
134
135 virtual void TearDown() {
Tony Barbourc2f67f52015-06-02 14:55:46 -0600136 delete m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600137 vkDestroyInstance(inst);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600138 }
139};
140
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600141TEST_F(VkTest, AllocMemory) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600142 VkResult err;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600143 VkMemoryAllocInfo alloc_info = {};
Tony Barbourd1c35722015-04-16 15:59:00 -0600144 VkDeviceMemory gpu_mem;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600145 uint8_t *pData;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600146
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600147 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600148 alloc_info.allocationSize = 1024 * 1024; // 1MB
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600149 alloc_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT |
Tony Barbourd1c35722015-04-16 15:59:00 -0600150 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbourf52346d2015-01-16 14:27:35 -0700151
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600152
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600153 // TODO: Try variety of memory priorities
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600154 alloc_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600155
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600156 err = vkAllocMemory(device(), &alloc_info, &gpu_mem);
157 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -0600158
Mike Stroyanb050c682015-04-17 12:36:38 -0600159 err = vkMapMemory(device(), gpu_mem, 0, 0, 0, (void **) &pData);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600160 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600161
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600162 memset(pData, 0x55, alloc_info.allocationSize);
163 EXPECT_EQ(0x55, pData[0]) << "Memory read not same a write";
164
Mike Stroyanb050c682015-04-17 12:36:38 -0600165 err = vkUnmapMemory(device(), gpu_mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600166 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600167
Mike Stroyanb050c682015-04-17 12:36:38 -0600168 err = vkFreeMemory(device(), gpu_mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600169 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600170}
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600171
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600172TEST_F(VkTest, Event) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600173 VkEventCreateInfo event_info;
174 VkEvent event;
175 VkMemoryRequirements mem_req;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600176 size_t data_size;
177 VkDeviceMemory event_mem;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600178 VkResult err;
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600179
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600180 // typedef struct VkEventCreateInfo_
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600181 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600182 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600183 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600184 // VkFlags flags; // Reserved
185 // } VkEventCreateInfo;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600186 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600187 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600188
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189 err = vkCreateEvent(device(), &event_info, &event);
190 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600191
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600192 data_size = sizeof(mem_req);
Mike Stroyanb050c682015-04-17 12:36:38 -0600193 err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600194 &data_size, &mem_req);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600195 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600196
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600197 if (mem_req.size) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600198
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600199 // VkResult VKAPI vkAllocMemory(
200 // VkDevice device,
201 // const VkMemoryAllocInfo* pAllocInfo,
202 // VkDeviceMemory* pMem);
203 VkMemoryAllocInfo mem_info;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600204
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600205 memset(&mem_info, 0, sizeof(mem_info));
206 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
207 mem_info.allocationSize = mem_req.size;
208 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
209 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
210 err = vkAllocMemory(device(), &mem_info, &event_mem);
211 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600212
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600213 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
214 ASSERT_VK_SUCCESS(err);
215 }
Mike Stroyanb050c682015-04-17 12:36:38 -0600216 err = vkResetEvent(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600217 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600218
Mike Stroyanb050c682015-04-17 12:36:38 -0600219 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600220 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600221
Mike Stroyanb050c682015-04-17 12:36:38 -0600222 err = vkSetEvent(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600223 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600224
Mike Stroyanb050c682015-04-17 12:36:38 -0600225 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600226 ASSERT_EQ(VK_EVENT_SET, err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600227
228 // TODO: Test actual synchronization with command buffer event.
229
230 // All done with event memory, clean up
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600231 if (mem_req.size) {
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600232 err = vkFreeMemory(device(), event_mem);
233 ASSERT_VK_SUCCESS(err);
234 }
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600235
Mike Stroyanb050c682015-04-17 12:36:38 -0600236 err = vkDestroyObject(device(), VK_OBJECT_TYPE_EVENT, event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600237 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600238}
239
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600240#define MAX_QUERY_SLOTS 10
241
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600242TEST_F(VkTest, Query) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600243 VkQueryPoolCreateInfo query_info;
244 VkQueryPool query_pool;
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800245 size_t data_size;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600246 VkMemoryRequirements mem_req;
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800247 size_t query_result_size;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600248 uint32_t *query_result_data;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600249 VkDeviceMemory query_mem;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 VkResult err;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600251
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600252 // typedef enum VkQueryType_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600253 // {
Tony Barbourd1c35722015-04-16 15:59:00 -0600254 // VK_QUERY_TYPE_OCCLUSION = 0x00000000,
255 // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600256
Tony Barbourd1c35722015-04-16 15:59:00 -0600257 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION,
258 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600260 // VK_MAX_ENUM(VkQueryType_)
261 // } VkQueryType;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600262
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600263 // typedef struct VkQueryPoolCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600264 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600265 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600266 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600267 // VkQueryType queryType;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600268 // uint32_t slots;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600269 // } VkQueryPoolCreateInfo;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600270
271 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600272 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600273 query_info.queryType = VK_QUERY_TYPE_OCCLUSION;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600274 query_info.slots = MAX_QUERY_SLOTS;
275
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600276 // VkResult VKAPI vkCreateQueryPool(
277 // VkDevice device,
278 // const VkQueryPoolCreateInfo* pCreateInfo,
279 // VkQueryPool* pQueryPool);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600280
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281 err = vkCreateQueryPool(device(), &query_info, &query_pool);
282 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600283
Jon Ashburne494a1a2014-09-25 14:36:58 -0600284 data_size = sizeof(mem_req);
Mike Stroyanb050c682015-04-17 12:36:38 -0600285 err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600286 &data_size, &mem_req);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600287 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600288
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600289 if (mem_req.size) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600290
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600291 // VkResult VKAPI vkAllocMemory(
292 // VkDevice device,
293 // const VkMemoryAllocInfo* pAllocInfo,
294 // VkDeviceMemory* pMem);
295 VkMemoryAllocInfo mem_info;
296
297 memset(&mem_info, 0, sizeof(mem_info));
298 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
299 // TODO: Is a simple multiple all that's needed here?
300 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
301 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
302 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
303 // TODO: Should this be pinned? Or maybe a separate test with pinned.
304 err = vkAllocMemory(device(), &mem_info, &query_mem);
305 ASSERT_VK_SUCCESS(err);
306
307 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, query_mem, 0);
308 ASSERT_VK_SUCCESS(err);
309 }
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600310 // TODO: Test actual synchronization with command buffer event.
311 // TODO: Create command buffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600312 // TODO: vkCmdResetQueryPool
313 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600314 // TODO: commands
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600315 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600316
Mike Stroyanb050c682015-04-17 12:36:38 -0600317 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbourd1c35722015-04-16 15:59:00 -0600318 &query_result_size, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600319 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600320
321 if (query_result_size > 0) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600322 query_result_data = new uint32_t [query_result_size];
Mike Stroyanb050c682015-04-17 12:36:38 -0600323 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbourd1c35722015-04-16 15:59:00 -0600324 &query_result_size, query_result_data, 0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600325 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600326
327 // TODO: Test Query result data.
328
329 }
330
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600331 if (mem_req.size) {
332 // All done with QueryPool memory, clean up
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600333 err = vkFreeMemory(device(), query_mem);
334 ASSERT_VK_SUCCESS(err);
335 }
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600336
Mike Stroyanb050c682015-04-17 12:36:38 -0600337 err = vkDestroyObject(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600338 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600339}
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600340
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600341void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600342{
343 int que_idx;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344 VkResult err;
345 VkQueue queue;
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600346
Tony Barbourd1c35722015-04-16 15:59:00 -0600347 const VkPhysicalDeviceQueueProperties props = device->gpu().queue_properties()[queue_node_index];
Chia-I Wufe84fe12014-12-29 15:39:23 +0800348 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500349 // TODO: Need to add support for separate MEMMGR and work queues, including synchronization
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600350 err = vkGetDeviceQueue(device->obj(), queue_node_index, que_idx, &queue);
351 ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err);
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600352 }
353}
354
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600355void VkTest::CreateImageTest()
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600356{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600357 VkResult err;
358 VkImage image;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600359 uint32_t w, h, mipCount;
360 size_t size;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600361 VkFormat fmt;
362 VkFormatProperties image_fmt;
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800363 size_t data_size;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600364
365 w =512;
366 h = 256;
367 mipCount = 0;
368
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600369 uint32_t _w = w;
370 uint32_t _h = h;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600371 while( ( _w > 0 ) || ( _h > 0 ) )
372 {
373 _w >>= 1;
374 _h >>= 1;
375 mipCount++;
376 }
377
Tony Barbourd1c35722015-04-16 15:59:00 -0600378 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600379 // TODO: Pick known good format rather than just expect common format
380 /*
381 * XXX: What should happen if given NULL HANDLE for the pData argument?
Tony Barbourd1c35722015-04-16 15:59:00 -0600382 * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600383 * an expectation that pData is a valid pointer.
384 * However, why include a returned size value? That implies that the
385 * amount of data may vary and that doesn't work well for using a
386 * fixed structure.
387 */
388
Jon Ashburne494a1a2014-09-25 14:36:58 -0600389 size = sizeof(image_fmt);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600390 err = vkGetFormatInfo(device(), fmt,
Tony Barbourd1c35722015-04-16 15:59:00 -0600391 VK_FORMAT_INFO_TYPE_PROPERTIES,
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600392 &size, &image_fmt);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600393 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600394
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600395// typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600396// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600398// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600399// VkImageType imageType;
400// VkFormat format;
401// VkExtent3D extent;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600402// uint32_t mipLevels;
403// uint32_t arraySize;
404// uint32_t samples;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600405// VkImageTiling tiling;
406// VkFlags usage; // VkImageUsageFlags
407// VkFlags flags; // VkImageCreateFlags
408// } VkImageCreateInfo;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600409
410
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600411 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600412 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600413 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600414 imageCreateInfo.format = fmt;
415 imageCreateInfo.arraySize = 1;
416 imageCreateInfo.extent.width = w;
417 imageCreateInfo.extent.height = h;
418 imageCreateInfo.extent.depth = 1;
419 imageCreateInfo.mipLevels = mipCount;
420 imageCreateInfo.samples = 1;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600421 if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
422 imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
423 }
424 else if (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
425 imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
426 }
427 else {
428 FAIL() << "Neither Linear nor Optimal allowed for color attachment";
429 }
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600430 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600431
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600432// VkResult VKAPI vkCreateImage(
433// VkDevice device,
434// const VkImageCreateInfo* pCreateInfo,
435// VkImage* pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600436 err = vkCreateImage(device(), &imageCreateInfo, &image);
437 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600438
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600439 // Verify image resources
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600440// VkResult VKAPI vkGetImageSubresourceInfo(
441// VkImage image,
442// const VkImageSubresource* pSubresource,
443// VkSubresourceInfoType infoType,
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600444// size_t* pDataSize,
445// void* pData);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600446// typedef struct VkSubresourceLayout_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600447// {
Tony Barbourd1c35722015-04-16 15:59:00 -0600448// VkDeviceSize offset; // Specified in bytes
449// VkDeviceSize size; // Specified in bytes
450// VkDeviceSize rowPitch; // Specified in bytes
451// VkDeviceSize depthPitch; // Specified in bytes
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600452// } VkSubresourceLayout;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600453
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600454// typedef struct VkImageSubresource_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600455// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600456// VkImageAspect aspect;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600457// uint32_t mipLevel;
458// uint32_t arraySlice;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600459// } VkImageSubresource;
460// typedef enum VkSubresourceInfoType_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600461// {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600462// // Info type for vkGetImageSubresourceInfo()
Tony Barbourd1c35722015-04-16 15:59:00 -0600463// VK_SUBRESOURCE_INFO_TYPE_LAYOUT = 0x00000000,
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600464
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600465// VK_MAX_ENUM(VkSubresourceInfoType_)
466// } VkSubresourceInfoType;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600467
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600468 if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
469 VkImageSubresource subresource = {};
470 subresource.aspect = VK_IMAGE_ASPECT_COLOR;
471 subresource.arraySlice = 0;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600472
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600473 _w = w;
474 _h = h;
475 while ((_w > 0) || (_h > 0))
476 {
477 VkSubresourceLayout layout = {};
478 data_size = sizeof(layout);
479 err = vkGetImageSubresourceInfo(device(), image, &subresource, VK_SUBRESOURCE_INFO_TYPE_LAYOUT,
480 &data_size, &layout);
481 ASSERT_VK_SUCCESS(err);
482 ASSERT_EQ(sizeof(VkSubresourceLayout), data_size) << "Invalid structure (VkSubresourceLayout) size";
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600483
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600484 // TODO: 4 should be replaced with pixel size for given format
485 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
486 _w >>= 1;
487 _h >>= 1;
488
489 subresource.mipLevel++;
490 }
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600491 }
492
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600493 VkMemoryRequirements mem_req;
Tony Barbourd1c35722015-04-16 15:59:00 -0600494 VkDeviceMemory image_mem;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600495
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600496 data_size = sizeof(mem_req);
497 err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_IMAGE, image, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS,
498 &data_size, &mem_req);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600499 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600500
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600501 if (mem_req.size) {
502
503 // VkResult VKAPI vkAllocMemory(
504 // VkDevice device,
505 // const VkMemoryAllocInfo* pAllocInfo,
506 // VkDeviceMemory* pMem);
507 VkMemoryAllocInfo mem_info = {};
508
509 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
510 mem_info.pNext = NULL;
511 mem_info.allocationSize = mem_req.size;
512 mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT;
513 mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL;
514 err = vkAllocMemory(device(), &mem_info, &image_mem);
515 ASSERT_VK_SUCCESS(err);
516
517 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_IMAGE, image, image_mem, 0);
518 ASSERT_VK_SUCCESS(err);
519 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600520
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600521// typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600522// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600523// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600524// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600525// VkImage image;
526// VkImageViewType viewType;
527// VkFormat format;
528// VkChannelMapping channels;
529// VkImageSubresourceRange subresourceRange;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600530// float minLod;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600531// } VkImageViewCreateInfo;
532 VkImageViewCreateInfo viewInfo = {};
533 VkImageView view;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600534 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600535 viewInfo.image = image;
Tony Barbourd1c35722015-04-16 15:59:00 -0600536 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600537 viewInfo.format = fmt;
538
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600539 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
540 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
541 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
542 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600543
544 viewInfo.subresourceRange.baseArraySlice = 0;
545 viewInfo.subresourceRange.arraySize = 1;
546 viewInfo.subresourceRange.baseMipLevel = 0;
547 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600548 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600549
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600550// VkResult VKAPI vkCreateImageView(
551// VkDevice device,
552// const VkImageViewCreateInfo* pCreateInfo,
553// VkImageView* pView);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600554
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600555 err = vkCreateImageView(device(), &viewInfo, &view);
556 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600557
558 // TODO: Test image memory.
559
560 // All done with image memory, clean up
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600561 if (mem_req.size) {
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600562 ASSERT_VK_SUCCESS(vkFreeMemory(device(), image_mem));
563 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600564
Tony Barbour51a05ce2015-06-03 11:40:51 -0600565 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_IMAGE_VIEW, view));
Mike Stroyanb050c682015-04-17 12:36:38 -0600566 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_IMAGE, image));
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600567}
568
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600569TEST_F(VkTest, CreateImage) {
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600570 CreateImageTest();
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600571}
572
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600573void VkTest::CreateCommandBufferTest()
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600574{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600575 VkResult err;
576 VkCmdBufferCreateInfo info = {};
577 VkCmdBuffer cmdBuffer;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600578
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600579// typedef struct VkCmdBufferCreateInfo_
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600580// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600581// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600582// const void* pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600583// VK_QUEUE_TYPE queueType;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600584// VkFlags flags;
585// } VkCmdBufferCreateInfo;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600586
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600587 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700588 info.queueNodeIndex = graphics_queue_node_index;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600589 err = vkCreateCommandBuffer(device(), &info, &cmdBuffer);
590 ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed";
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600591
Mike Stroyanb050c682015-04-17 12:36:38 -0600592 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer));
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600593}
594
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600595TEST_F(VkTest, TestCommandBuffer) {
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600596 CreateCommandBufferTest();
597}
598
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600599void VkTest::CreateShader(VkShader *pshader)
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600600{
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600601 void *code;
602 uint32_t codeSize;
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600603 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600604 VkResult err;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600605
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600606 codeSize = sizeof(struct icd_spv_header) + 100;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600607 code = malloc(codeSize);
608 ASSERT_TRUE(NULL != code) << "malloc failed!";
609
610 memset(code, 0, codeSize);
611
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600612 // Indicate that this is SPV data.
613 pSPV = (struct icd_spv_header *) code;
614 pSPV->magic = ICD_SPV_MAGIC;
615 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600616
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600617// typedef struct VkShaderCreateInfo_
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600618// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600619// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600620// const void* pNext; // Pointer to next structure
621// size_t codeSize; // Specified in bytes
622// const void* pCode;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600623// VkFlags flags; // Reserved
624// } VkShaderCreateInfo;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600625
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600626 VkShaderCreateInfo createInfo;
627 VkShader shader;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600628
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600629 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600630 createInfo.pNext = NULL;
631 createInfo.pCode = code;
632 createInfo.codeSize = codeSize;
633 createInfo.flags = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600634 err = vkCreateShader(device(), &createInfo, &shader);
635 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600636
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600637 *pshader = shader;
638}
639
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600640int main(int argc, char **argv) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600641 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600642 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600643 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -0600644}