blob: 1bb1d313b6383ccb65fa0f912b02a7b3490c43e8 [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 Goeltzenleuchtercc9da542014-08-12 14:12:22 -060031//
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -060032// Copyright (C) 2015 Valve Corporation
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060033//
34// Permission is hereby granted, free of charge, to any person obtaining a
35// copy of this software and associated documentation files (the "Software"),
36// to deal in the Software without restriction, including without limitation
37// the rights to use, copy, modify, merge, publish, distribute, sublicense,
38// and/or sell copies of the Software, and to permit persons to whom the
39// Software is furnished to do so, subject to the following conditions:
40//
41// The above copyright notice and this permission notice shall be included
42// in all copies or substantial portions of the Software.
43//
44// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
47// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
50// DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060051//
52// Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
53// Author: Jon Ashburn <jon@lunarg.com>
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060054
55
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060056// Verify VK driver initialization
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060057
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060058#include <stdlib.h>
59#include <stdio.h>
60#include <stdbool.h>
61#include <string.h>
62
David Pinedo9316d3b2015-11-06 12:54:48 -070063#include <vulkan/vulkan.h>
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060064
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060065#include "vktestbinding.h"
Chia-I Wufe84fe12014-12-29 15:39:23 +080066#include "test_common.h"
Cody Northrop054a4702015-03-17 14:54:35 -060067#include "icd-spv.h"
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060068
Jon Ashburn83a64252015-04-15 11:31:12 -060069#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
70
Tony-LunarGd61e1e52015-05-15 12:42:49 -060071class VkTest : public ::testing::Test {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060072public:
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -060073 void CreateImageTest();
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -060074 void CreateCommandBufferTest();
75 void CreatePipelineTest();
76 void CreateShaderTest();
Chia-I Wu28e06912015-10-31 00:31:16 +080077 void CreateShader(VkShaderModule *pmodule, VkShaderStageFlagBits stage);
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -060078
Chia-I Wuf368b602015-07-03 10:41:20 +080079 VkDevice device() {return m_device->handle();}
Courtney Goeltzenleuchtercc5eb3a2014-08-19 18:35:50 -060080
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060081protected:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060082 VkApplicationInfo app_info;
83 VkInstance inst;
Tony Barbourd1c35722015-04-16 15:59:00 -060084 VkPhysicalDevice objs[16];
Mark Lobodzinski17caf572015-01-29 08:55:56 -060085 uint32_t gpu_count;
Chia-I Wufe84fe12014-12-29 15:39:23 +080086
Mark Lobodzinski17caf572015-01-29 08:55:56 -060087 uint32_t m_device_id;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060088 vk_testing::Device *m_device;
Tony Barbourd1c35722015-04-16 15:59:00 -060089 VkPhysicalDeviceProperties props;
Cody Northropd0802882015-08-03 17:04:53 -060090 std::vector<VkQueueFamilyProperties> queue_props;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -070091 uint32_t graphics_queue_node_index;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060092
93 virtual void SetUp() {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060094 VkResult err;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -070095 int i;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060096
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060097 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -060098 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080099 this->app_info.pApplicationName = "base";
100 this->app_info.applicationVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800101 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600102 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600103 this->app_info.apiVersion = VK_API_VERSION;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600104 VkInstanceCreateInfo inst_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600105 inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600106 inst_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800107 inst_info.pApplicationInfo = &app_info;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800108 inst_info.enabledLayerNameCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600109 inst_info.ppEnabledLayerNames = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800110 inst_info.enabledExtensionNameCount = 0;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600111 inst_info.ppEnabledExtensionNames = NULL;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800112 err = vkCreateInstance(&inst_info, NULL, &inst);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600113 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);
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -0600119 ASSERT_GE(this->gpu_count, (uint32_t) 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
Chia-I Wu999f0482015-07-03 10:32:05 +0800125 props = m_device->phy().properties();
Chia-I Wufe84fe12014-12-29 15:39:23 +0800126
Chia-I Wu999f0482015-07-03 10:32:05 +0800127 queue_props = this->m_device->phy().queue_properties();
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -0700128 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;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800139 vkDestroyInstance(inst, NULL);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600140 }
141};
142
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800143TEST_F(VkTest, AllocateMemory) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600144 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600145 bool pass;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800146 VkMemoryAllocateInfo alloc_info = {};
Tony Barbourd1c35722015-04-16 15:59:00 -0600147 VkDeviceMemory gpu_mem;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600148 uint8_t *pData;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600149
Chia-I Wu00ce5402015-11-10 16:21:09 +0800150 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600151 alloc_info.allocationSize = 1024 * 1024; // 1MB
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600152 alloc_info.memoryTypeIndex = 0;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600153
Tony Barbourcba4ab22015-07-29 14:27:38 -0600154 VkPhysicalDeviceMemoryProperties mem_props;
155 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &mem_props);
156
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600157 pass = m_device->phy().set_memory_type(((1 << mem_props.memoryTypeCount) - 1), &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
158 ASSERT_TRUE(pass);
Tony Barbourcba4ab22015-07-29 14:27:38 -0600159
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800160 err = vkAllocateMemory(device(), &alloc_info, NULL, &gpu_mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600161 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -0600162
Mike Stroyanb050c682015-04-17 12:36:38 -0600163 err = vkMapMemory(device(), gpu_mem, 0, 0, 0, (void **) &pData);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600164 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600165
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600166 memset(pData, 0x55, alloc_info.allocationSize);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600167 EXPECT_EQ(0x55, pData[0]) << "Memory read not same as write";
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600168
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600169 vkUnmapMemory(device(), gpu_mem);
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600170
Chia-I Wuf7458c52015-10-26 21:10:41 +0800171 vkFreeMemory(device(), gpu_mem, NULL);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600172}
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600173
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600174TEST_F(VkTest, Event) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600175 VkEventCreateInfo event_info;
176 VkEvent event;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600177 VkResult err;
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600178
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600179 // typedef struct VkEventCreateInfo_
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600180 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600181 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600182 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600183 // VkFlags flags; // Reserved
184 // } VkEventCreateInfo;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600185 memset(&event_info, 0, sizeof(event_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600186 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600187
Chia-I Wuf7458c52015-10-26 21:10:41 +0800188 err = vkCreateEvent(device(), &event_info, NULL, &event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600189 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600190
Mike Stroyanb050c682015-04-17 12:36:38 -0600191 err = vkResetEvent(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600192 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600193
Mike Stroyanb050c682015-04-17 12:36:38 -0600194 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600195 ASSERT_EQ(VK_EVENT_RESET, err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600196
Mike Stroyanb050c682015-04-17 12:36:38 -0600197 err = vkSetEvent(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600198 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600199
Mike Stroyanb050c682015-04-17 12:36:38 -0600200 err = vkGetEventStatus(device(), event);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600201 ASSERT_EQ(VK_EVENT_SET, err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600202
203 // TODO: Test actual synchronization with command buffer event.
204
205 // All done with event memory, clean up
Chia-I Wuf7458c52015-10-26 21:10:41 +0800206 vkDestroyEvent(device(), event, NULL);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600207}
208
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600209#define MAX_QUERY_SLOTS 10
210
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600211TEST_F(VkTest, Query) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600212 VkQueryPoolCreateInfo query_info;
213 VkQueryPool query_pool;
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800214 size_t query_result_size;
Chia-I Wuccc93a72015-10-26 18:36:20 +0800215 uint8_t *query_result_data;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600216 VkResult err;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600217
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600218 // typedef enum VkQueryType_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600219 // {
Tony Barbourd1c35722015-04-16 15:59:00 -0600220 // VK_QUERY_TYPE_OCCLUSION = 0x00000000,
221 // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001,
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600222
Tony Barbourd1c35722015-04-16 15:59:00 -0600223 // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION,
224 // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600225 // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1),
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600226 // VK_MAX_ENUM(VkQueryType_)
227 // } VkQueryType;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600228
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600229 // typedef struct VkQueryPoolCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600230 // {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600231 // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600232 // const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600233 // VkQueryType queryType;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600234 // uint32_t slots;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600235 // } VkQueryPoolCreateInfo;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600236
237 memset(&query_info, 0, sizeof(query_info));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600238 query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600239 query_info.queryType = VK_QUERY_TYPE_OCCLUSION;
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800240 query_info.entryCount = MAX_QUERY_SLOTS;
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600241
Chia-I Wu9ab61502015-11-06 06:42:02 +0800242 // VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600243 // VkDevice device,
244 // const VkQueryPoolCreateInfo* pCreateInfo,
245 // VkQueryPool* pQueryPool);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600246
Chia-I Wuf7458c52015-10-26 21:10:41 +0800247 err = vkCreateQueryPool(device(), &query_info, NULL, &query_pool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600248 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600249
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600250 // TODO: Test actual synchronization with command buffer event.
251 // TODO: Create command buffer
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600252 // TODO: vkCmdResetQueryPool
253 // TODO: vkCmdBeginQuery
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600254 // TODO: commands
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600255 // TOOD: vkCmdEndQuery
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600256
Chia-I Wuccc93a72015-10-26 18:36:20 +0800257 query_result_size = MAX_QUERY_SLOTS * sizeof(uint64_t);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600258 if (query_result_size > 0) {
Chia-I Wuccc93a72015-10-26 18:36:20 +0800259 query_result_data = new uint8_t [query_result_size];
Mike Stroyanb050c682015-04-17 12:36:38 -0600260 err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS,
Chia-I Wuccc93a72015-10-26 18:36:20 +0800261 query_result_size, query_result_data,
262 sizeof(uint64_t), VK_QUERY_RESULT_64_BIT);
Jon Ashburne3f31082015-10-02 09:35:45 -0700263 //ASSERT_VK_SUCCESS(err); TODO fix once actually submit queries
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600264
265 // TODO: Test Query result data.
266
267 }
268
Chia-I Wuf7458c52015-10-26 21:10:41 +0800269 vkDestroyQueryPool(device(), query_pool, NULL);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600270}
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600271
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600272void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname)
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600273{
Cody Northropd2ad0342015-08-05 11:15:02 -0600274 uint32_t que_idx;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600275 VkQueue queue;
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600276
Cody Northropd0802882015-08-03 17:04:53 -0600277 const VkQueueFamilyProperties props = device->phy().queue_properties()[queue_node_index];
Chia-I Wufe84fe12014-12-29 15:39:23 +0800278 for (que_idx = 0; que_idx < props.queueCount; que_idx++) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500279 // TODO: Need to add support for separate MEMMGR and work queues, including synchronization
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600280 vkGetDeviceQueue(device->handle(), queue_node_index, que_idx, &queue);
Courtney Goeltzenleuchter3dc07f22014-08-14 10:15:09 -0600281 }
282}
283
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600284void VkTest::CreateImageTest()
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600285{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600286 VkResult err;
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600287 bool pass;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600288 VkImage image;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600289 uint32_t w, h, mipCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600290 VkFormat fmt;
291 VkFormatProperties image_fmt;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600292
293 w =512;
294 h = 256;
295 mipCount = 0;
296
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600297 uint32_t _w = w;
298 uint32_t _h = h;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600299 while( ( _w > 0 ) || ( _h > 0 ) )
300 {
301 _w >>= 1;
302 _h >>= 1;
303 mipCount++;
304 }
305
Tony Barbourd1c35722015-04-16 15:59:00 -0600306 fmt = VK_FORMAT_R8G8B8A8_UINT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600307 // TODO: Pick known good format rather than just expect common format
308 /*
309 * XXX: What should happen if given NULL HANDLE for the pData argument?
Tony Barbourd1c35722015-04-16 15:59:00 -0600310 * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600311 * an expectation that pData is a valid pointer.
312 * However, why include a returned size value? That implies that the
313 * amount of data may vary and that doesn't work well for using a
314 * fixed structure.
315 */
316
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600317 vkGetPhysicalDeviceFormatProperties(objs[m_device_id], fmt, &image_fmt);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600318
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600319// typedef struct VkImageCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600320// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600321// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600322// const void* pNext; // Pointer to next structure.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600323// VkImageType imageType;
324// VkFormat format;
325// VkExtent3D extent;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600326// uint32_t mipLevels;
327// uint32_t arraySize;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800328// VkSampleCountFlagBits samples;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600329// VkImageTiling tiling;
330// VkFlags usage; // VkImageUsageFlags
331// VkFlags flags; // VkImageCreateFlags
332// } VkImageCreateInfo;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600333
334
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600335 VkImageCreateInfo imageCreateInfo = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600336 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -0600337 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600338 imageCreateInfo.format = fmt;
Courtney Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600339 imageCreateInfo.arrayLayers = 1;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600340 imageCreateInfo.extent.width = w;
341 imageCreateInfo.extent.height = h;
342 imageCreateInfo.extent.depth = 1;
343 imageCreateInfo.mipLevels = mipCount;
Chia-I Wu5c17c962015-10-31 00:31:16 +0800344 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600345 if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
346 imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;
347 }
348 else if (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
349 imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
350 }
351 else {
352 FAIL() << "Neither Linear nor Optimal allowed for color attachment";
353 }
Cody Northropbb6fdb32015-06-17 08:28:19 -0600354 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
355 VK_IMAGE_USAGE_SAMPLED_BIT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600356
Chia-I Wu9ab61502015-11-06 06:42:02 +0800357// VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600358// VkDevice device,
359// const VkImageCreateInfo* pCreateInfo,
360// VkImage* pImage);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800361 err = vkCreateImage(device(), &imageCreateInfo, NULL, &image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600362 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600363
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600364 // Verify image resources
Chia-I Wu9ab61502015-11-06 06:42:02 +0800365// VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600366// VkImage image,
367// const VkImageSubresource* pSubresource,
Tony Barbour59a47322015-06-24 16:06:58 -0600368// VkSubresourceLayout* pLayout);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369// typedef struct VkSubresourceLayout_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600370// {
Tony Barbourd1c35722015-04-16 15:59:00 -0600371// VkDeviceSize offset; // Specified in bytes
372// VkDeviceSize size; // Specified in bytes
373// VkDeviceSize rowPitch; // Specified in bytes
374// VkDeviceSize depthPitch; // Specified in bytes
Jon Ashburn2b2f90c2015-12-30 14:39:53 -0700375// VkDeviceSize arrayPitch; // Specified in bytes
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600376// } VkSubresourceLayout;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600377
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600378// typedef struct VkImageSubresource_
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600379// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600380// VkImageAspect aspect;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600381// uint32_t mipLevel;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600382// uint32_t arrayLayer;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600383// } VkImageSubresource;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600384
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600385
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600386 if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
387 VkImageSubresource subresource = {};
Chia-I Wu52b07e72015-10-27 19:55:05 +0800388 subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600389 subresource.arrayLayer = 0;
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600390
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600391 _w = w;
392 _h = h;
393 while ((_w > 0) || (_h > 0))
394 {
395 VkSubresourceLayout layout = {};
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600396 vkGetImageSubresourceLayout(device(), image, &subresource, &layout);
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600397
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600398 // TODO: 4 should be replaced with pixel size for given format
399 EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch";
400 _w >>= 1;
401 _h >>= 1;
402
403 subresource.mipLevel++;
404 }
Courtney Goeltzenleuchter7bf0ff82014-08-14 17:40:57 -0600405 }
406
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600407 VkMemoryRequirements mem_req;
Tony Barbourd1c35722015-04-16 15:59:00 -0600408 VkDeviceMemory image_mem;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600409
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600410 vkGetImageMemoryRequirements(device(), image, &mem_req);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600411
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600412 if (mem_req.size) {
413
Chia-I Wu9ab61502015-11-06 06:42:02 +0800414 // VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory(
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600415 // VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800416 // const VkMemoryAllocateInfo* pAllocateInfo,
417 // VkDeviceMemory* pMemory);
418 VkMemoryAllocateInfo mem_info = {};
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600419
Chia-I Wu00ce5402015-11-10 16:21:09 +0800420 mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600421 mem_info.pNext = NULL;
422 mem_info.allocationSize = mem_req.size;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600423 mem_info.memoryTypeIndex = 0;
424
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -0600425 pass = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0);
426 ASSERT_TRUE(pass);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600427
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800428 err = vkAllocateMemory(device(), &mem_info, NULL, &image_mem);
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600429 ASSERT_VK_SUCCESS(err);
430
Tony Barbour67e99152015-07-10 14:10:27 -0600431 err = vkBindImageMemory(device(), image, image_mem, 0);
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600432 ASSERT_VK_SUCCESS(err);
433 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600434
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600435// typedef struct VkImageViewCreateInfo_
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600436// {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600437// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600438// const void* pNext; // Pointer to next structure
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600439// VkImage image;
440// VkImageViewType viewType;
441// VkFormat format;
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800442// VkComponentMapping channels;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600443// VkImageSubresourceRange subresourceRange;
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600444// float minLod;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600445// } VkImageViewCreateInfo;
446 VkImageViewCreateInfo viewInfo = {};
447 VkImageView view;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600448 viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600449 viewInfo.image = image;
Tony Barbourd1c35722015-04-16 15:59:00 -0600450 viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600451 viewInfo.format = fmt;
452
Chia-I Wuab83a0e2015-10-27 19:00:15 +0800453 viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
454 viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
455 viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
456 viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600457
Courtney Goeltzenleuchter4a261892015-09-10 16:38:41 -0600458 viewInfo.subresourceRange.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800459 viewInfo.subresourceRange.layerCount = 1;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600460 viewInfo.subresourceRange.baseMipLevel = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800461 viewInfo.subresourceRange.levelCount = 1;
Courtney Goeltzenleuchterba724512015-09-10 17:58:54 -0600462 viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600463
Chia-I Wu9ab61502015-11-06 06:42:02 +0800464// VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600465// VkDevice device,
466// const VkImageViewCreateInfo* pCreateInfo,
467// VkImageView* pView);
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600468
Chia-I Wuf7458c52015-10-26 21:10:41 +0800469 err = vkCreateImageView(device(), &viewInfo, NULL, &view);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600470 ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed";
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600471
472 // TODO: Test image memory.
473
474 // All done with image memory, clean up
Chia-I Wuf7458c52015-10-26 21:10:41 +0800475 vkDestroyImageView(device(), view, NULL);
476 vkDestroyImage(device(), image, NULL);
Courtney Goeltzenleuchter10642562015-06-22 16:26:54 -0600477
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600478 if (mem_req.size) {
Chia-I Wuf7458c52015-10-26 21:10:41 +0800479 vkFreeMemory(device(), image_mem, NULL);
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600480 }
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600481}
482
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600483TEST_F(VkTest, CreateImage) {
Courtney Goeltzenleuchter794555b2014-08-13 17:55:12 -0600484 CreateImageTest();
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600485}
486
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600487void VkTest::CreateCommandBufferTest()
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600488{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600489 VkResult err;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800490 VkCommandBufferAllocateInfo info = {};
491 VkCommandPool commandPool;
492 VkCommandBuffer commandBuffer;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600493
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800494// typedef struct VkCommandBufferCreateInfo_
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600495// {
Chia-I Wu00ce5402015-11-10 16:21:09 +0800496// VkStructureType sType; // Must be VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600497// const void* pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600498// VK_QUEUE_TYPE queueType;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600499// VkFlags flags;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800500// } VkCommandBufferAllocateInfo;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600501
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800502 VkCommandPoolCreateInfo cmd_pool_info;
503 cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
Cody Northrope62183e2015-07-09 18:08:05 -0600504 cmd_pool_info.pNext = NULL,
505 cmd_pool_info.queueFamilyIndex = graphics_queue_node_index;
506 cmd_pool_info.flags = 0,
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800507 err = vkCreateCommandPool(device(), &cmd_pool_info, NULL, &commandPool);
Cody Northrope62183e2015-07-09 18:08:05 -0600508 ASSERT_VK_SUCCESS(err) << "vkCreateCommandPool failed";
509
Chia-I Wu00ce5402015-11-10 16:21:09 +0800510 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800511 info.commandPool = commandPool;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800512 info.bufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800513 info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
514 err = vkAllocateCommandBuffers(device(), &info, &commandBuffer);
515 ASSERT_VK_SUCCESS(err) << "vkAllocateCommandBuffers failed";
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600516
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800517 vkFreeCommandBuffers(device(), commandPool, 1, &commandBuffer);
518 vkDestroyCommandPool(device(), commandPool, NULL);
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600519}
520
Tony-LunarGd61e1e52015-05-15 12:42:49 -0600521TEST_F(VkTest, TestCommandBuffer) {
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600522 CreateCommandBufferTest();
523}
524
Chia-I Wu28e06912015-10-31 00:31:16 +0800525void VkTest::CreateShader(VkShaderModule *pmodule, VkShaderStageFlagBits stage)
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600526{
Chia-I Wu8094f192015-10-26 19:22:06 +0800527 uint32_t *code;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600528 uint32_t codeSize;
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600529 struct icd_spv_header *pSPV;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600530 VkResult err;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600531
Chia-I Wu8094f192015-10-26 19:22:06 +0800532 codeSize = sizeof(struct icd_spv_header) + sizeof(uint32_t) * 25;
533 code = (uint32_t *) malloc(codeSize);
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600534 ASSERT_TRUE(NULL != code) << "malloc failed!";
535
536 memset(code, 0, codeSize);
537
Cody Northrop3bfd27c2015-03-17 15:55:58 -0600538 // Indicate that this is SPV data.
539 pSPV = (struct icd_spv_header *) code;
540 pSPV->magic = ICD_SPV_MAGIC;
541 pSPV->version = ICD_SPV_VERSION;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600542
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600543 VkShaderModuleCreateInfo moduleCreateInfo;
544 VkShaderModule module;
Courtney Goeltzenleuchter6863ff42014-08-19 13:34:28 -0600545
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600546 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
547 moduleCreateInfo.pNext = NULL;
548 moduleCreateInfo.pCode = code;
549 moduleCreateInfo.codeSize = codeSize;
550 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800551 err = vkCreateShaderModule(device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -0600552 ASSERT_VK_SUCCESS(err);
553
Chia-I Wu28e06912015-10-31 00:31:16 +0800554 *pmodule = module;
Courtney Goeltzenleuchterde3513a2014-08-20 15:26:55 -0600555}
556
Courtney Goeltzenleuchter75011f82014-08-12 09:59:36 -0600557int main(int argc, char **argv) {
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600558 ::testing::InitGoogleTest(&argc, argv);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600559 vk_testing::set_error_callback(test_error_callback);
Courtney Goeltzenleuchtercc9da542014-08-12 14:12:22 -0600560 return RUN_ALL_TESTS();
Courtney Goeltzenleuchter447ed582014-08-11 18:19:35 -0600561}