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