Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 1 | // 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 Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 30 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 31 | // |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 32 | // Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 33 | // |
| 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 Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 51 | // |
| 52 | // Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 53 | // Author: Jon Ashburn <jon@lunarg.com> |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 54 | |
| 55 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 56 | // Verify VK driver initialization |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 57 | |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 58 | #include <stdlib.h> |
| 59 | #include <stdio.h> |
| 60 | #include <stdbool.h> |
| 61 | #include <string.h> |
| 62 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 63 | #include <vulkan/vulkan.h> |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 64 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 65 | #include "vktestbinding.h" |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 66 | #include "test_common.h" |
Cody Northrop | 054a470 | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 67 | #include "icd-spv.h" |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 68 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 69 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 70 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 71 | class VkTest : public ::testing::Test { |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 72 | public: |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 73 | void CreateImageTest(); |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 74 | void CreateCommandBufferTest(); |
| 75 | void CreatePipelineTest(); |
| 76 | void CreateShaderTest(); |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 77 | void CreateShader(VkShaderModule *pmodule, VkShaderStageFlagBits stage); |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 78 | |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 79 | VkDevice device() {return m_device->handle();} |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 80 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 81 | protected: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 82 | VkApplicationInfo app_info; |
| 83 | VkInstance inst; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 84 | VkPhysicalDevice objs[16]; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 85 | uint32_t gpu_count; |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 86 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 87 | uint32_t m_device_id; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 88 | vk_testing::Device *m_device; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 89 | VkPhysicalDeviceProperties props; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 90 | std::vector<VkQueueFamilyProperties> queue_props; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 91 | uint32_t graphics_queue_node_index; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 92 | |
| 93 | virtual void SetUp() { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 94 | VkResult err; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 95 | int i; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 96 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 97 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 98 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 99 | this->app_info.pApplicationName = "base"; |
| 100 | this->app_info.applicationVersion = 1; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 101 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 102 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | this->app_info.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 104 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 105 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 106 | inst_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 107 | inst_info.pApplicationInfo = &app_info; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 108 | inst_info.enabledLayerNameCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 109 | inst_info.ppEnabledLayerNames = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 110 | inst_info.enabledExtensionNameCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 111 | inst_info.ppEnabledExtensionNames = NULL; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 112 | err = vkCreateInstance(&inst_info, NULL, &inst); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 113 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 114 | 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 119 | ASSERT_GE(this->gpu_count, (uint32_t) 1) << "No GPU available"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 120 | |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 121 | m_device_id = 0; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | this->m_device = new vk_testing::Device(objs[m_device_id]); |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 123 | this->m_device->init(); |
| 124 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 125 | props = m_device->phy().properties(); |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 126 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 127 | queue_props = this->m_device->phy().queue_properties(); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 128 | for (i = 0; i < queue_props.size(); i++) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 129 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 130 | 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 Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | virtual void TearDown() { |
Tony Barbour | c2f67f5 | 2015-06-02 14:55:46 -0600 | [diff] [blame] | 138 | delete m_device; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 139 | vkDestroyInstance(inst, NULL); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 140 | } |
| 141 | }; |
| 142 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 143 | TEST_F(VkTest, AllocateMemory) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 144 | VkResult err; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 145 | bool pass; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 146 | VkMemoryAllocateInfo alloc_info = {}; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 147 | VkDeviceMemory gpu_mem; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 148 | uint8_t *pData; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 149 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 150 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 151 | alloc_info.allocationSize = 1024 * 1024; // 1MB |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 152 | alloc_info.memoryTypeIndex = 0; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 153 | |
Tony Barbour | cba4ab2 | 2015-07-29 14:27:38 -0600 | [diff] [blame] | 154 | VkPhysicalDeviceMemoryProperties mem_props; |
| 155 | vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &mem_props); |
| 156 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 157 | 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 Barbour | cba4ab2 | 2015-07-29 14:27:38 -0600 | [diff] [blame] | 159 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 160 | err = vkAllocateMemory(device(), &alloc_info, NULL, &gpu_mem); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 161 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 162 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 163 | err = vkMapMemory(device(), gpu_mem, 0, 0, 0, (void **) &pData); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 164 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 165 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 166 | memset(pData, 0x55, alloc_info.allocationSize); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 167 | EXPECT_EQ(0x55, pData[0]) << "Memory read not same as write"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 168 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 169 | vkUnmapMemory(device(), gpu_mem); |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 170 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 171 | vkFreeMemory(device(), gpu_mem, NULL); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 172 | } |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 173 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 174 | TEST_F(VkTest, Event) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 175 | VkEventCreateInfo event_info; |
| 176 | VkEvent event; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 177 | VkResult err; |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 178 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 179 | // typedef struct VkEventCreateInfo_ |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 180 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 181 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 182 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 183 | // VkFlags flags; // Reserved |
| 184 | // } VkEventCreateInfo; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 185 | memset(&event_info, 0, sizeof(event_info)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 186 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 187 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 188 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 189 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 190 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 191 | err = vkResetEvent(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 193 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 194 | err = vkGetEventStatus(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 195 | ASSERT_EQ(VK_EVENT_RESET, err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 196 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 197 | err = vkSetEvent(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 198 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 199 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 200 | err = vkGetEventStatus(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 201 | ASSERT_EQ(VK_EVENT_SET, err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 202 | |
| 203 | // TODO: Test actual synchronization with command buffer event. |
| 204 | |
| 205 | // All done with event memory, clean up |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 206 | vkDestroyEvent(device(), event, NULL); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 207 | } |
| 208 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 209 | #define MAX_QUERY_SLOTS 10 |
| 210 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 211 | TEST_F(VkTest, Query) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 212 | VkQueryPoolCreateInfo query_info; |
| 213 | VkQueryPool query_pool; |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 214 | size_t query_result_size; |
Chia-I Wu | ccc93a7 | 2015-10-26 18:36:20 +0800 | [diff] [blame] | 215 | uint8_t *query_result_data; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 216 | VkResult err; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 217 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 218 | // typedef enum VkQueryType_ |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 219 | // { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 220 | // VK_QUERY_TYPE_OCCLUSION = 0x00000000, |
| 221 | // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001, |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 222 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 223 | // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION, |
| 224 | // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS, |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 225 | // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1), |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 226 | // VK_MAX_ENUM(VkQueryType_) |
| 227 | // } VkQueryType; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 228 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 229 | // typedef struct VkQueryPoolCreateInfo_ |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 230 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 231 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 232 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 233 | // VkQueryType queryType; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 234 | // uint32_t slots; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 235 | // } VkQueryPoolCreateInfo; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 236 | |
| 237 | memset(&query_info, 0, sizeof(query_info)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 238 | query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 239 | query_info.queryType = VK_QUERY_TYPE_OCCLUSION; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 240 | query_info.entryCount = MAX_QUERY_SLOTS; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 241 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 242 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 243 | // VkDevice device, |
| 244 | // const VkQueryPoolCreateInfo* pCreateInfo, |
| 245 | // VkQueryPool* pQueryPool); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 246 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 247 | err = vkCreateQueryPool(device(), &query_info, NULL, &query_pool); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 248 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 249 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 250 | // TODO: Test actual synchronization with command buffer event. |
| 251 | // TODO: Create command buffer |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | // TODO: vkCmdResetQueryPool |
| 253 | // TODO: vkCmdBeginQuery |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 254 | // TODO: commands |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 255 | // TOOD: vkCmdEndQuery |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 256 | |
Chia-I Wu | ccc93a7 | 2015-10-26 18:36:20 +0800 | [diff] [blame] | 257 | query_result_size = MAX_QUERY_SLOTS * sizeof(uint64_t); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 258 | if (query_result_size > 0) { |
Chia-I Wu | ccc93a7 | 2015-10-26 18:36:20 +0800 | [diff] [blame] | 259 | query_result_data = new uint8_t [query_result_size]; |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 260 | err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS, |
Chia-I Wu | ccc93a7 | 2015-10-26 18:36:20 +0800 | [diff] [blame] | 261 | query_result_size, query_result_data, |
| 262 | sizeof(uint64_t), VK_QUERY_RESULT_64_BIT); |
Jon Ashburn | e3f3108 | 2015-10-02 09:35:45 -0700 | [diff] [blame] | 263 | //ASSERT_VK_SUCCESS(err); TODO fix once actually submit queries |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 264 | |
| 265 | // TODO: Test Query result data. |
| 266 | |
| 267 | } |
| 268 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 269 | vkDestroyQueryPool(device(), query_pool, NULL); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 270 | } |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 271 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 272 | void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname) |
Courtney Goeltzenleuchter | 3dc07f2 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 273 | { |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 274 | uint32_t que_idx; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 275 | VkQueue queue; |
Courtney Goeltzenleuchter | 3dc07f2 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 276 | |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 277 | const VkQueueFamilyProperties props = device->phy().queue_properties()[queue_node_index]; |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 278 | for (que_idx = 0; que_idx < props.queueCount; que_idx++) { |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 279 | // TODO: Need to add support for separate MEMMGR and work queues, including synchronization |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 280 | vkGetDeviceQueue(device->handle(), queue_node_index, que_idx, &queue); |
Courtney Goeltzenleuchter | 3dc07f2 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 284 | void VkTest::CreateImageTest() |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 285 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 286 | VkResult err; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 287 | bool pass; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 288 | VkImage image; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 289 | uint32_t w, h, mipCount; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 290 | VkFormat fmt; |
| 291 | VkFormatProperties image_fmt; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 292 | |
| 293 | w =512; |
| 294 | h = 256; |
| 295 | mipCount = 0; |
| 296 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 297 | uint32_t _w = w; |
| 298 | uint32_t _h = h; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 299 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 300 | { |
| 301 | _w >>= 1; |
| 302 | _h >>= 1; |
| 303 | mipCount++; |
| 304 | } |
| 305 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 306 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 307 | // 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 Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 310 | * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 311 | * 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 Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 317 | vkGetPhysicalDeviceFormatProperties(objs[m_device_id], fmt, &image_fmt); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 318 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 319 | // typedef struct VkImageCreateInfo_ |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 320 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 321 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 322 | // const void* pNext; // Pointer to next structure. |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 323 | // VkImageType imageType; |
| 324 | // VkFormat format; |
| 325 | // VkExtent3D extent; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 326 | // uint32_t mipLevels; |
| 327 | // uint32_t arraySize; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 328 | // VkSampleCountFlagBits samples; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 329 | // VkImageTiling tiling; |
| 330 | // VkFlags usage; // VkImageUsageFlags |
| 331 | // VkFlags flags; // VkImageCreateFlags |
| 332 | // } VkImageCreateInfo; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 333 | |
| 334 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 335 | VkImageCreateInfo imageCreateInfo = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 336 | imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 337 | imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 338 | imageCreateInfo.format = fmt; |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 339 | imageCreateInfo.arrayLayers = 1; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 340 | imageCreateInfo.extent.width = w; |
| 341 | imageCreateInfo.extent.height = h; |
| 342 | imageCreateInfo.extent.depth = 1; |
| 343 | imageCreateInfo.mipLevels = mipCount; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 344 | imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 345 | 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 Northrop | bb6fdb3 | 2015-06-17 08:28:19 -0600 | [diff] [blame] | 354 | imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 355 | VK_IMAGE_USAGE_SAMPLED_BIT; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 356 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 357 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 358 | // VkDevice device, |
| 359 | // const VkImageCreateInfo* pCreateInfo, |
| 360 | // VkImage* pImage); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 361 | err = vkCreateImage(device(), &imageCreateInfo, NULL, &image); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 362 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 363 | |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 364 | // Verify image resources |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 365 | // VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 366 | // VkImage image, |
| 367 | // const VkImageSubresource* pSubresource, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 368 | // VkSubresourceLayout* pLayout); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 369 | // typedef struct VkSubresourceLayout_ |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 370 | // { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 371 | // VkDeviceSize offset; // Specified in bytes |
| 372 | // VkDeviceSize size; // Specified in bytes |
| 373 | // VkDeviceSize rowPitch; // Specified in bytes |
| 374 | // VkDeviceSize depthPitch; // Specified in bytes |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 375 | // } VkSubresourceLayout; |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 376 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 377 | // typedef struct VkImageSubresource_ |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 378 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 379 | // VkImageAspect aspect; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 380 | // uint32_t mipLevel; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 381 | // uint32_t arrayLayer; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 382 | // } VkImageSubresource; |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 383 | |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 384 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 385 | if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 386 | VkImageSubresource subresource = {}; |
Chia-I Wu | 52b07e7 | 2015-10-27 19:55:05 +0800 | [diff] [blame] | 387 | subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 388 | subresource.arrayLayer = 0; |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 389 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 390 | _w = w; |
| 391 | _h = h; |
| 392 | while ((_w > 0) || (_h > 0)) |
| 393 | { |
| 394 | VkSubresourceLayout layout = {}; |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 395 | vkGetImageSubresourceLayout(device(), image, &subresource, &layout); |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 396 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 397 | // TODO: 4 should be replaced with pixel size for given format |
| 398 | EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch"; |
| 399 | _w >>= 1; |
| 400 | _h >>= 1; |
| 401 | |
| 402 | subresource.mipLevel++; |
| 403 | } |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 404 | } |
| 405 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 406 | VkMemoryRequirements mem_req; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 407 | VkDeviceMemory image_mem; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 408 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 409 | vkGetImageMemoryRequirements(device(), image, &mem_req); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 410 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 411 | if (mem_req.size) { |
| 412 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 413 | // VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory( |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 414 | // VkDevice device, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 415 | // const VkMemoryAllocateInfo* pAllocateInfo, |
| 416 | // VkDeviceMemory* pMemory); |
| 417 | VkMemoryAllocateInfo mem_info = {}; |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 418 | |
| 419 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 420 | mem_info.pNext = NULL; |
| 421 | mem_info.allocationSize = mem_req.size; |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 422 | mem_info.memoryTypeIndex = 0; |
| 423 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 424 | pass = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0); |
| 425 | ASSERT_TRUE(pass); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 426 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 427 | err = vkAllocateMemory(device(), &mem_info, NULL, &image_mem); |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 428 | ASSERT_VK_SUCCESS(err); |
| 429 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 430 | err = vkBindImageMemory(device(), image, image_mem, 0); |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 431 | ASSERT_VK_SUCCESS(err); |
| 432 | } |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 433 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 434 | // typedef struct VkImageViewCreateInfo_ |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 435 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 436 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 437 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 438 | // VkImage image; |
| 439 | // VkImageViewType viewType; |
| 440 | // VkFormat format; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 441 | // VkComponentMapping channels; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 442 | // VkImageSubresourceRange subresourceRange; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 443 | // float minLod; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 444 | // } VkImageViewCreateInfo; |
| 445 | VkImageViewCreateInfo viewInfo = {}; |
| 446 | VkImageView view; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 447 | viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 448 | viewInfo.image = image; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 449 | viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 450 | viewInfo.format = fmt; |
| 451 | |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 452 | viewInfo.components.r = VK_COMPONENT_SWIZZLE_R; |
| 453 | viewInfo.components.g = VK_COMPONENT_SWIZZLE_G; |
| 454 | viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; |
| 455 | viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 456 | |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 457 | viewInfo.subresourceRange.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 458 | viewInfo.subresourceRange.layerCount = 1; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 459 | viewInfo.subresourceRange.baseMipLevel = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 460 | viewInfo.subresourceRange.levelCount = 1; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 461 | viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 462 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 463 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 464 | // VkDevice device, |
| 465 | // const VkImageViewCreateInfo* pCreateInfo, |
| 466 | // VkImageView* pView); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 467 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 468 | err = vkCreateImageView(device(), &viewInfo, NULL, &view); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 469 | ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed"; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 470 | |
| 471 | // TODO: Test image memory. |
| 472 | |
| 473 | // All done with image memory, clean up |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 474 | vkDestroyImageView(device(), view, NULL); |
| 475 | vkDestroyImage(device(), image, NULL); |
Courtney Goeltzenleuchter | 1064256 | 2015-06-22 16:26:54 -0600 | [diff] [blame] | 476 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 477 | if (mem_req.size) { |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 478 | vkFreeMemory(device(), image_mem, NULL); |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 479 | } |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 480 | } |
| 481 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 482 | TEST_F(VkTest, CreateImage) { |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 483 | CreateImageTest(); |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 484 | } |
| 485 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 486 | void VkTest::CreateCommandBufferTest() |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 487 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 488 | VkResult err; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 489 | VkCommandBufferAllocateInfo info = {}; |
| 490 | VkCommandPool commandPool; |
| 491 | VkCommandBuffer commandBuffer; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 492 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 493 | // typedef struct VkCommandBufferCreateInfo_ |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 494 | // { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 495 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 496 | // const void* pNext; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 497 | // VK_QUEUE_TYPE queueType; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 498 | // VkFlags flags; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 499 | // } VkCommandBufferAllocateInfo; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 500 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 501 | VkCommandPoolCreateInfo cmd_pool_info; |
| 502 | cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 503 | cmd_pool_info.pNext = NULL, |
| 504 | cmd_pool_info.queueFamilyIndex = graphics_queue_node_index; |
| 505 | cmd_pool_info.flags = 0, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 506 | err = vkCreateCommandPool(device(), &cmd_pool_info, NULL, &commandPool); |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 507 | ASSERT_VK_SUCCESS(err) << "vkCreateCommandPool failed"; |
| 508 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 509 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOC_INFO; |
| 510 | info.commandPool = commandPool; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 511 | info.bufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 512 | info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 513 | err = vkAllocateCommandBuffers(device(), &info, &commandBuffer); |
| 514 | ASSERT_VK_SUCCESS(err) << "vkAllocateCommandBuffers failed"; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 515 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 516 | vkFreeCommandBuffers(device(), commandPool, 1, &commandBuffer); |
| 517 | vkDestroyCommandPool(device(), commandPool, NULL); |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 518 | } |
| 519 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 520 | TEST_F(VkTest, TestCommandBuffer) { |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 521 | CreateCommandBufferTest(); |
| 522 | } |
| 523 | |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 524 | void VkTest::CreateShader(VkShaderModule *pmodule, VkShaderStageFlagBits stage) |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 525 | { |
Chia-I Wu | 8094f19 | 2015-10-26 19:22:06 +0800 | [diff] [blame] | 526 | uint32_t *code; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 527 | uint32_t codeSize; |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 528 | struct icd_spv_header *pSPV; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 529 | VkResult err; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 530 | |
Chia-I Wu | 8094f19 | 2015-10-26 19:22:06 +0800 | [diff] [blame] | 531 | codeSize = sizeof(struct icd_spv_header) + sizeof(uint32_t) * 25; |
| 532 | code = (uint32_t *) malloc(codeSize); |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 533 | ASSERT_TRUE(NULL != code) << "malloc failed!"; |
| 534 | |
| 535 | memset(code, 0, codeSize); |
| 536 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 537 | // Indicate that this is SPV data. |
| 538 | pSPV = (struct icd_spv_header *) code; |
| 539 | pSPV->magic = ICD_SPV_MAGIC; |
| 540 | pSPV->version = ICD_SPV_VERSION; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 541 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 542 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 543 | VkShaderModule module; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 544 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 545 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 546 | moduleCreateInfo.pNext = NULL; |
| 547 | moduleCreateInfo.pCode = code; |
| 548 | moduleCreateInfo.codeSize = codeSize; |
| 549 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 550 | err = vkCreateShaderModule(device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 551 | ASSERT_VK_SUCCESS(err); |
| 552 | |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 553 | *pmodule = module; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 554 | } |
| 555 | |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 556 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 557 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 558 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 559 | return RUN_ALL_TESTS(); |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 560 | } |