blob: 9c70b98b2632792974358a5eff98eefaed9d0107 [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;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600108 inst_info.layerCount = 0;
109 inst_info.ppEnabledLayerNames = NULL;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600110 inst_info.extensionCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600111 inst_info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600112 err = vkCreateInstance(&inst_info, &inst);
113 ASSERT_VK_SUCCESS(err);
Jon Ashburn83a64252015-04-15 11:31:12 -0600114 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL);
115 ASSERT_VK_SUCCESS(err);
116 ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs";
117 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600118 ASSERT_VK_SUCCESS(err);
Jon Ashburnbf843b22014-11-26 11:06:49 -0700119 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600120
Chia-I Wufe84fe12014-12-29 15:39:23 +0800121 m_device_id = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600122 this->m_device = new vk_testing::Device(objs[m_device_id]);
Chia-I Wufe84fe12014-12-29 15:39:23 +0800123 this->m_device->init();
124
125 props = m_device->gpu().properties();
Chia-I Wufe84fe12014-12-29 15:39:23 +0800126
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700127 queue_props = this->m_device->gpu().queue_properties();
128 for (i = 0; i < queue_props.size(); i++) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600129 if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700130 graphics_queue_node_index = i;
131 break;
132 }
133 }
134 ASSERT_LT(i, queue_props.size()) << "Could not find a Queue with Graphics support";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600135 }
136
137 virtual void TearDown() {
Tony Barbourc2f67f52015-06-02 14:55:46 -0600138 delete m_device;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600139 vkDestroyInstance(inst);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600140 }
141};
142
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600143TEST_F(VkTest, AllocMemory) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600144 VkResult err;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600145 VkMemoryAllocInfo alloc_info = {};
Tony Barbourd1c35722015-04-16 15:59:00 -0600146 VkDeviceMemory gpu_mem;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600147 uint8_t *pData;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600148
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600149 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600150 alloc_info.allocationSize = 1024 * 1024; // 1MB
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600151 alloc_info.memoryTypeIndex = 0;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600152
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600153 err = vkAllocMemory(device(), &alloc_info, &gpu_mem);
154 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -0600155
Mike Stroyanb050c682015-04-17 12:36:38 -0600156 err = vkMapMemory(device(), gpu_mem, 0, 0, 0, (void **) &pData);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600157 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600158
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600159 memset(pData, 0x55, alloc_info.allocationSize);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600160 EXPECT_EQ(0x55, pData[0]) << "Memory read not same as write";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600161
Mike Stroyanb050c682015-04-17 12:36:38 -0600162 err = vkUnmapMemory(device(), gpu_mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600163 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600164
Mike Stroyanb050c682015-04-17 12:36:38 -0600165 err = vkFreeMemory(device(), gpu_mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600166 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600167}
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600168
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600169TEST_F(VkTest, Event) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600170 VkEventCreateInfo event_info;
171 VkEvent event;
172 VkMemoryRequirements mem_req;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600173 VkDeviceMemory event_mem;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600174 VkResult err;
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600175
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600176 // typedef struct VkEventCreateInfo_
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600177 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600178 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600179 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600180 // VkFlags flags; // Reserved
181 // } VkEventCreateInfo;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600182 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600183 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600184
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600185 err = vkCreateEvent(device(), &event_info, &event);
186 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600187
Tony Barbour59a47322015-06-24 16:06:58 -0600188 err = vkGetObjectMemoryRequirements(device(), VK_OBJECT_TYPE_EVENT, event, &mem_req);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600190
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600191 if (mem_req.size) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600192
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600193 // VkResult VKAPI vkAllocMemory(
194 // VkDevice device,
195 // const VkMemoryAllocInfo* pAllocInfo,
196 // VkDeviceMemory* pMem);
197 VkMemoryAllocInfo mem_info;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600198
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600199 memset(&mem_info, 0, sizeof(mem_info));
200 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
201 mem_info.allocationSize = mem_req.size;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600202 mem_info.memoryTypeIndex = 0;
203
204 err = m_device->gpu().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0);
205 ASSERT_VK_SUCCESS(err);
206
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600207 err = vkAllocMemory(device(), &mem_info, &event_mem);
208 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600209
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600210 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0);
211 ASSERT_VK_SUCCESS(err);
212 }
Mike Stroyanb050c682015-04-17 12:36:38 -0600213 err = vkResetEvent(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600214 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600215
Mike Stroyanb050c682015-04-17 12:36:38 -0600216 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600217 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600218
Mike Stroyanb050c682015-04-17 12:36:38 -0600219 err = vkSetEvent(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600220 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600221
Mike Stroyanb050c682015-04-17 12:36:38 -0600222 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600223 ASSERT_EQ(VK_EVENT_SET, err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600224
225 // TODO: Test actual synchronization with command buffer event.
226
227 // All done with event memory, clean up
Courtney Goeltzenleuchter10642562015-06-22 16:26:54 -0600228 err = vkDestroyObject(device(), VK_OBJECT_TYPE_EVENT, event);
229 ASSERT_VK_SUCCESS(err);
230
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}
236
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600237#define MAX_QUERY_SLOTS 10
238
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600239TEST_F(VkTest, Query) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600240 VkQueryPoolCreateInfo query_info;
241 VkQueryPool query_pool;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600242 VkMemoryRequirements mem_req;
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800243 size_t query_result_size;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600244 uint32_t *query_result_data;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600245 VkDeviceMemory query_mem;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600246 VkResult err;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600247
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600248 // typedef enum VkQueryType_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600249 // {
Tony Barbourd1c35722015-04-16 15:59:00 -0600250 // VK_QUERY_TYPE_OCCLUSION = 0x00000000,
251 // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600252
Tony Barbourd1c35722015-04-16 15:59:00 -0600253 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION,
254 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600255 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600256 // VK_MAX_ENUM(VkQueryType_)
257 // } VkQueryType;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600258
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600259 // typedef struct VkQueryPoolCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600260 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600261 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600262 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600263 // VkQueryType queryType;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600264 // uint32_t slots;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600265 // } VkQueryPoolCreateInfo;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600266
267 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600268 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600269 query_info.queryType = VK_QUERY_TYPE_OCCLUSION;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600270 query_info.slots = MAX_QUERY_SLOTS;
271
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600272 // VkResult VKAPI vkCreateQueryPool(
273 // VkDevice device,
274 // const VkQueryPoolCreateInfo* pCreateInfo,
275 // VkQueryPool* pQueryPool);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600276
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600277 err = vkCreateQueryPool(device(), &query_info, &query_pool);
278 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600279
Tony Barbour59a47322015-06-24 16:06:58 -0600280 err = vkGetObjectMemoryRequirements(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, &mem_req);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600282
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600283 if (mem_req.size) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600284
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600285 // VkResult VKAPI vkAllocMemory(
286 // VkDevice device,
287 // const VkMemoryAllocInfo* pAllocInfo,
288 // VkDeviceMemory* pMem);
289 VkMemoryAllocInfo mem_info;
290
291 memset(&mem_info, 0, sizeof(mem_info));
292 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
293 // TODO: Is a simple multiple all that's needed here?
294 mem_info.allocationSize = mem_req.size * MAX_QUERY_SLOTS;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600295 mem_info.memoryTypeIndex = 0;
296
297 err = m_device->gpu().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0);
298 ASSERT_VK_SUCCESS(err);
299
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600300 err = vkAllocMemory(device(), &mem_info, &query_mem);
301 ASSERT_VK_SUCCESS(err);
302
303 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool, query_mem, 0);
304 ASSERT_VK_SUCCESS(err);
305 }
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600306 // TODO: Test actual synchronization with command buffer event.
307 // TODO: Create command buffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600308 // TODO: vkCmdResetQueryPool
309 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600310 // TODO: commands
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600311 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600312
Mike Stroyanb050c682015-04-17 12:36:38 -0600313 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbourd1c35722015-04-16 15:59:00 -0600314 &query_result_size, VK_NULL_HANDLE, 0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600315 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600316
317 if (query_result_size > 0) {
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600318 query_result_data = new uint32_t [query_result_size];
Mike Stroyanb050c682015-04-17 12:36:38 -0600319 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Tony Barbourd1c35722015-04-16 15:59:00 -0600320 &query_result_size, query_result_data, 0);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600321 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600322
323 // TODO: Test Query result data.
324
325 }
326
Courtney Goeltzenleuchter10642562015-06-22 16:26:54 -0600327 err = vkDestroyObject(device(), VK_OBJECT_TYPE_QUERY_POOL, query_pool);
328 ASSERT_VK_SUCCESS(err);
329
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600330 if (mem_req.size) {
331 // All done with QueryPool memory, clean up
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600332 err = vkFreeMemory(device(), query_mem);
333 ASSERT_VK_SUCCESS(err);
334 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600335}
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600336
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600337void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600338{
339 int que_idx;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600340 VkResult err;
341 VkQueue queue;
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600342
Tony Barbourd1c35722015-04-16 15:59:00 -0600343 const VkPhysicalDeviceQueueProperties props = device->gpu().queue_properties()[queue_node_index];
Chia-I Wufe84fe12014-12-29 15:39:23 +0800344 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500345 // TODO: Need to add support for separate MEMMGR and work queues, including synchronization
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600346 err = vkGetDeviceQueue(device->obj(), queue_node_index, que_idx, &queue);
347 ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err);
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600348 }
349}
350
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600351void VkTest::CreateImageTest()
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600352{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult err;
354 VkImage image;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600355 uint32_t w, h, mipCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600356 VkFormat fmt;
357 VkFormatProperties image_fmt;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600358
359 w =512;
360 h = 256;
361 mipCount = 0;
362
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600363 uint32_t _w = w;
364 uint32_t _h = h;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600365 while( ( _w > 0 ) || ( _h > 0 ) )
366 {
367 _w >>= 1;
368 _h >>= 1;
369 mipCount++;
370 }
371
Tony Barbourd1c35722015-04-16 15:59:00 -0600372 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600373 // TODO: Pick known good format rather than just expect common format
374 /*
375 * XXX: What should happen if given NULL HANDLE for the pData argument?
Tony Barbourd1c35722015-04-16 15:59:00 -0600376 * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600377 * an expectation that pData is a valid pointer.
378 * However, why include a returned size value? That implies that the
379 * amount of data may vary and that doesn't work well for using a
380 * fixed structure.
381 */
382
Chris Forbesbc0bb772015-06-21 22:55:02 +1200383 err = vkGetPhysicalDeviceFormatInfo(objs[m_device_id], fmt, &image_fmt);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600384 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600385
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600386// typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600387// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600388// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600389// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600390// VkImageType imageType;
391// VkFormat format;
392// VkExtent3D extent;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600393// uint32_t mipLevels;
394// uint32_t arraySize;
395// uint32_t samples;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600396// VkImageTiling tiling;
397// VkFlags usage; // VkImageUsageFlags
398// VkFlags flags; // VkImageCreateFlags
399// } VkImageCreateInfo;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600400
401
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600402 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600404 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600405 imageCreateInfo.format = fmt;
406 imageCreateInfo.arraySize = 1;
407 imageCreateInfo.extent.width = w;
408 imageCreateInfo.extent.height = h;
409 imageCreateInfo.extent.depth = 1;
410 imageCreateInfo.mipLevels = mipCount;
411 imageCreateInfo.samples = 1;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600412 if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
413 imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
414 }
415 else if (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
416 imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
417 }
418 else {
419 FAIL() << "Neither Linear nor Optimal allowed for color attachment";
420 }
Cody Northropbb6fdb32015-06-17 08:28:19 -0600421 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
422 VK_IMAGE_USAGE_SAMPLED_BIT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600423
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600424// VkResult VKAPI vkCreateImage(
425// VkDevice device,
426// const VkImageCreateInfo* pCreateInfo,
427// VkImage* pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 err = vkCreateImage(device(), &imageCreateInfo, &image);
429 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600430
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600431 // Verify image resources
Tony Barbour59a47322015-06-24 16:06:58 -0600432// VkResult VKAPI vkGetImageSubresourceLayout(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600433// VkImage image,
434// const VkImageSubresource* pSubresource,
Tony Barbour59a47322015-06-24 16:06:58 -0600435// VkSubresourceLayout* pLayout);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600436// typedef struct VkSubresourceLayout_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600437// {
Tony Barbourd1c35722015-04-16 15:59:00 -0600438// VkDeviceSize offset; // Specified in bytes
439// VkDeviceSize size; // Specified in bytes
440// VkDeviceSize rowPitch; // Specified in bytes
441// VkDeviceSize depthPitch; // Specified in bytes
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600442// } VkSubresourceLayout;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600443
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600444// typedef struct VkImageSubresource_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600445// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600446// VkImageAspect aspect;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600447// uint32_t mipLevel;
448// uint32_t arraySlice;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600449// } VkImageSubresource;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600450
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600451
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600452 if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
453 VkImageSubresource subresource = {};
454 subresource.aspect = VK_IMAGE_ASPECT_COLOR;
455 subresource.arraySlice = 0;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600456
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600457 _w = w;
458 _h = h;
459 while ((_w > 0) || (_h > 0))
460 {
461 VkSubresourceLayout layout = {};
Tony Barbour59a47322015-06-24 16:06:58 -0600462 err = vkGetImageSubresourceLayout(device(), image, &subresource, &layout);
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600463 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600464
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600465 // TODO: 4 should be replaced with pixel size for given format
466 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
467 _w >>= 1;
468 _h >>= 1;
469
470 subresource.mipLevel++;
471 }
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600472 }
473
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600474 VkMemoryRequirements mem_req;
Tony Barbourd1c35722015-04-16 15:59:00 -0600475 VkDeviceMemory image_mem;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600476
Tony Barbour59a47322015-06-24 16:06:58 -0600477 err = vkGetObjectMemoryRequirements(device(), VK_OBJECT_TYPE_IMAGE, image, &mem_req);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600478 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600479
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600480 if (mem_req.size) {
481
482 // VkResult VKAPI vkAllocMemory(
483 // VkDevice device,
484 // const VkMemoryAllocInfo* pAllocInfo,
485 // VkDeviceMemory* pMem);
486 VkMemoryAllocInfo mem_info = {};
487
488 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
489 mem_info.pNext = NULL;
490 mem_info.allocationSize = mem_req.size;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600491 mem_info.memoryTypeIndex = 0;
492
493 err = m_device->gpu().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0);
494 ASSERT_VK_SUCCESS(err);
495
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600496 err = vkAllocMemory(device(), &mem_info, &image_mem);
497 ASSERT_VK_SUCCESS(err);
498
499 err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_IMAGE, image, image_mem, 0);
500 ASSERT_VK_SUCCESS(err);
501 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600502
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600503// typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600504// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600505// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600506// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600507// VkImage image;
508// VkImageViewType viewType;
509// VkFormat format;
510// VkChannelMapping channels;
511// VkImageSubresourceRange subresourceRange;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600512// float minLod;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600513// } VkImageViewCreateInfo;
514 VkImageViewCreateInfo viewInfo = {};
515 VkImageView view;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600516 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600517 viewInfo.image = image;
Tony Barbourd1c35722015-04-16 15:59:00 -0600518 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600519 viewInfo.format = fmt;
520
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600521 viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R;
522 viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G;
523 viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B;
524 viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600525
526 viewInfo.subresourceRange.baseArraySlice = 0;
527 viewInfo.subresourceRange.arraySize = 1;
528 viewInfo.subresourceRange.baseMipLevel = 0;
529 viewInfo.subresourceRange.mipLevels = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600530 viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600531
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600532// VkResult VKAPI vkCreateImageView(
533// VkDevice device,
534// const VkImageViewCreateInfo* pCreateInfo,
535// VkImageView* pView);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600536
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600537 err = vkCreateImageView(device(), &viewInfo, &view);
538 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600539
540 // TODO: Test image memory.
541
542 // All done with image memory, clean up
Courtney Goeltzenleuchter10642562015-06-22 16:26:54 -0600543 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_IMAGE_VIEW, view));
544 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_IMAGE, image));
545
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600546 if (mem_req.size) {
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600547 ASSERT_VK_SUCCESS(vkFreeMemory(device(), image_mem));
548 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600549}
550
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600551TEST_F(VkTest, CreateImage) {
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600552 CreateImageTest();
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600553}
554
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600555void VkTest::CreateCommandBufferTest()
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600556{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600557 VkResult err;
558 VkCmdBufferCreateInfo info = {};
559 VkCmdBuffer cmdBuffer;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600560
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600561// typedef struct VkCmdBufferCreateInfo_
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600562// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600563// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600564// const void* pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600565// VK_QUEUE_TYPE queueType;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600566// VkFlags flags;
567// } VkCmdBufferCreateInfo;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600568
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600569 info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700570 info.queueNodeIndex = graphics_queue_node_index;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600571 err = vkCreateCommandBuffer(device(), &info, &cmdBuffer);
572 ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed";
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600573
Mike Stroyanb050c682015-04-17 12:36:38 -0600574 ASSERT_VK_SUCCESS(vkDestroyObject(device(), VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer));
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600575}
576
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600577TEST_F(VkTest, TestCommandBuffer) {
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600578 CreateCommandBufferTest();
579}
580
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600581void VkTest::CreateShader(VkShader *pshader)
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600582{
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600583 void *code;
584 uint32_t codeSize;
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600585 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600586 VkResult err;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600587
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600588 codeSize = sizeof(struct icd_spv_header) + 100;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600589 code = malloc(codeSize);
590 ASSERT_TRUE(NULL != code) << "malloc failed!";
591
592 memset(code, 0, codeSize);
593
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600594 // Indicate that this is SPV data.
595 pSPV = (struct icd_spv_header *) code;
596 pSPV->magic = ICD_SPV_MAGIC;
597 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600598
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600599 VkShaderModuleCreateInfo moduleCreateInfo;
600 VkShaderModule module;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600601 VkShaderCreateInfo createInfo;
602 VkShader shader;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600603
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600604 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
605 moduleCreateInfo.pNext = NULL;
606 moduleCreateInfo.pCode = code;
607 moduleCreateInfo.codeSize = codeSize;
608 moduleCreateInfo.flags = 0;
609 err = vkCreateShaderModule(device(), &moduleCreateInfo, &module);
610 ASSERT_VK_SUCCESS(err);
611
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600612 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600613 createInfo.pNext = NULL;
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600614 createInfo.module = module;
615 createInfo.pName = "main";
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600616 createInfo.flags = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600617 err = vkCreateShader(device(), &createInfo, &shader);
618 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600619
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600620 err = vkDestroyObject(device(), VK_OBJECT_TYPE_SHADER_MODULE, module);
621 ASSERT_VK_SUCCESS(err);
622
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600623 *pshader = shader;
624}
625
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600626int main(int argc, char **argv) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600627 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600628 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600629 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -0600630}