Courtney Goeltzenleuchter | 7087dde | 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 | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 30 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | // VK tests |
Courtney Goeltzenleuchter | ed56abc | 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 | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 54 | // Verify VK driver initialization |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 55 | |
Courtney Goeltzenleuchter | 7087dde | 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 | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 61 | #include <vulkan.h> |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 62 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 63 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 64 | #include "vktestbinding.h" |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 65 | #include "test_common.h" |
Cody Northrop | d4e020a | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 66 | #include "icd-spv.h" |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 67 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 68 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 69 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 70 | class VkTest : public ::testing::Test { |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 71 | public: |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 72 | void CreateImageTest(); |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 73 | void CreateCommandBufferTest(); |
| 74 | void CreatePipelineTest(); |
| 75 | void CreateShaderTest(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 76 | void CreateShader(VkShader *pshader); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 77 | |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 78 | VkDevice device() {return m_device->handle();} |
Courtney Goeltzenleuchter | b85c581 | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 79 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 80 | protected: |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 81 | VkApplicationInfo app_info; |
| 82 | VkInstance inst; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 83 | VkPhysicalDevice objs[16]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 84 | uint32_t gpu_count; |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 85 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 86 | uint32_t m_device_id; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 87 | vk_testing::Device *m_device; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 88 | VkPhysicalDeviceProperties props; |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 89 | std::vector<VkQueueFamilyProperties> queue_props; |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 90 | uint32_t graphics_queue_node_index; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 91 | |
| 92 | virtual void SetUp() { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 93 | VkResult err; |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 94 | int i; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 95 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 96 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 97 | this->app_info.pNext = NULL; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 98 | this->app_info.pAppName = "base"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 99 | this->app_info.appVersion = 1; |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 100 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 101 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 102 | this->app_info.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 103 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 105 | inst_info.pNext = NULL; |
| 106 | inst_info.pAppInfo = &app_info; |
| 107 | inst_info.pAllocCb = NULL; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 108 | inst_info.layerCount = 0; |
| 109 | inst_info.ppEnabledLayerNames = NULL; |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 110 | inst_info.extensionCount = 0; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 111 | inst_info.ppEnabledExtensionNames = NULL; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 112 | err = vkCreateInstance(&inst_info, &inst); |
| 113 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 07b309a | 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 | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 19733c9 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 119 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 120 | |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 121 | m_device_id = 0; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | this->m_device = new vk_testing::Device(objs[m_device_id]); |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 123 | this->m_device->init(); |
| 124 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 125 | props = m_device->phy().properties(); |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 126 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 127 | queue_props = this->m_device->phy().queue_properties(); |
Courtney Goeltzenleuchter | f316806 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 128 | for (i = 0; i < queue_props.size(); i++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 129 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
Courtney Goeltzenleuchter | f316806 | 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 | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | virtual void TearDown() { |
Tony Barbour | 900ae86 | 2015-06-02 14:55:46 -0600 | [diff] [blame] | 138 | delete m_device; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 139 | vkDestroyInstance(inst); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 140 | } |
| 141 | }; |
| 142 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 143 | TEST_F(VkTest, AllocMemory) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 144 | VkResult err; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 145 | VkMemoryAllocInfo alloc_info = {}; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 146 | VkDeviceMemory gpu_mem; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 147 | uint8_t *pData; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 148 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 149 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 150 | alloc_info.allocationSize = 1024 * 1024; // 1MB |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 151 | alloc_info.memoryTypeIndex = 0; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 152 | |
Tony Barbour | 08baf96 | 2015-07-29 14:27:38 -0600 | [diff] [blame] | 153 | VkPhysicalDeviceMemoryProperties mem_props; |
| 154 | vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &mem_props); |
| 155 | |
| 156 | err = m_device->phy().set_memory_type(((1 << mem_props.memoryTypeCount) - 1), &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 157 | ASSERT_VK_SUCCESS(err); |
| 158 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 159 | err = vkAllocMemory(device(), &alloc_info, &gpu_mem); |
| 160 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 161 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 162 | err = vkMapMemory(device(), gpu_mem, 0, 0, 0, (void **) &pData); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 163 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 164 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 165 | memset(pData, 0x55, alloc_info.allocationSize); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 166 | EXPECT_EQ(0x55, pData[0]) << "Memory read not same as write"; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 167 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 168 | err = vkUnmapMemory(device(), gpu_mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 169 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 170 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 171 | err = vkFreeMemory(device(), gpu_mem); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 172 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 173 | } |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 174 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 175 | TEST_F(VkTest, Event) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 176 | VkEventCreateInfo event_info; |
| 177 | VkEvent event; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 178 | VkResult err; |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 179 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 180 | // typedef struct VkEventCreateInfo_ |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 181 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 182 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 183 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 184 | // VkFlags flags; // Reserved |
| 185 | // } VkEventCreateInfo; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 186 | memset(&event_info, 0, sizeof(event_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 187 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 188 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 189 | err = vkCreateEvent(device(), &event_info, &event); |
| 190 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 191 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 192 | err = vkResetEvent(device(), event); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 193 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 194 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 195 | err = vkGetEventStatus(device(), event); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 196 | ASSERT_EQ(VK_EVENT_RESET, err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 197 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 198 | err = vkSetEvent(device(), event); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 199 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 200 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 201 | err = vkGetEventStatus(device(), event); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 202 | ASSERT_EQ(VK_EVENT_SET, err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 203 | |
| 204 | // TODO: Test actual synchronization with command buffer event. |
| 205 | |
| 206 | // All done with event memory, clean up |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 207 | err = vkDestroyEvent(device(), event); |
Courtney Goeltzenleuchter | 0e168bb | 2015-06-22 16:26:54 -0600 | [diff] [blame] | 208 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 209 | } |
| 210 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 211 | #define MAX_QUERY_SLOTS 10 |
| 212 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 213 | TEST_F(VkTest, Query) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 214 | VkQueryPoolCreateInfo query_info; |
| 215 | VkQueryPool query_pool; |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 216 | size_t query_result_size; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 217 | uint32_t *query_result_data; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 218 | VkResult err; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 219 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 220 | // typedef enum VkQueryType_ |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 221 | // { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 222 | // VK_QUERY_TYPE_OCCLUSION = 0x00000000, |
| 223 | // VK_QUERY_TYPE_PIPELINE_STATISTICS = 0x00000001, |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 224 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 225 | // VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION, |
| 226 | // VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 227 | // VK_NUM_QUERY_TYPE = (VK_QUERY_TYPE_END_RANGE - VK_QUERY_TYPE_BEGIN_RANGE + 1), |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 228 | // VK_MAX_ENUM(VkQueryType_) |
| 229 | // } VkQueryType; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 230 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 231 | // typedef struct VkQueryPoolCreateInfo_ |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 232 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 233 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 234 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 235 | // VkQueryType queryType; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 236 | // uint32_t slots; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 237 | // } VkQueryPoolCreateInfo; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 238 | |
| 239 | memset(&query_info, 0, sizeof(query_info)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 240 | query_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 241 | query_info.queryType = VK_QUERY_TYPE_OCCLUSION; |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 242 | query_info.slots = MAX_QUERY_SLOTS; |
| 243 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 244 | // VkResult VKAPI vkCreateQueryPool( |
| 245 | // VkDevice device, |
| 246 | // const VkQueryPoolCreateInfo* pCreateInfo, |
| 247 | // VkQueryPool* pQueryPool); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 248 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 249 | err = vkCreateQueryPool(device(), &query_info, &query_pool); |
| 250 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 251 | |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 252 | // TODO: Test actual synchronization with command buffer event. |
| 253 | // TODO: Create command buffer |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 254 | // TODO: vkCmdResetQueryPool |
| 255 | // TODO: vkCmdBeginQuery |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 256 | // TODO: commands |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 257 | // TOOD: vkCmdEndQuery |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 258 | |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 259 | err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 260 | &query_result_size, VK_NULL_HANDLE, 0); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 261 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 262 | |
| 263 | if (query_result_size > 0) { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 264 | query_result_data = new uint32_t [query_result_size]; |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 265 | err = vkGetQueryPoolResults(device(), query_pool, 0, MAX_QUERY_SLOTS, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 266 | &query_result_size, query_result_data, 0); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 267 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 268 | |
| 269 | // TODO: Test Query result data. |
| 270 | |
| 271 | } |
| 272 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 273 | err = vkDestroyQueryPool(device(), query_pool); |
Courtney Goeltzenleuchter | 0e168bb | 2015-06-22 16:26:54 -0600 | [diff] [blame] | 274 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 275 | } |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 277 | void getQueue(vk_testing::Device *device, uint32_t queue_node_index, const char *qname) |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 278 | { |
Cody Northrop | 1684adb | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 279 | uint32_t que_idx; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 280 | VkResult err; |
| 281 | VkQueue queue; |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 282 | |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 283 | const VkQueueFamilyProperties props = device->phy().queue_properties()[queue_node_index]; |
Chia-I Wu | 3b78d31 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 284 | for (que_idx = 0; que_idx < props.queueCount; que_idx++) { |
Mark Lobodzinski | cf26e07 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 285 | // TODO: Need to add support for separate MEMMGR and work queues, including synchronization |
Chia-I Wu | a263629 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 286 | err = vkGetDeviceQueue(device->handle(), queue_node_index, que_idx, &queue); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 287 | ASSERT_EQ(VK_SUCCESS, err) << "vkGetDeviceQueue: " << qname << " queue #" << que_idx << ": Failed with error: " << vk_result_string(err); |
Courtney Goeltzenleuchter | cc32aa9 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 291 | void VkTest::CreateImageTest() |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 292 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 293 | VkResult err; |
| 294 | VkImage image; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 295 | uint32_t w, h, mipCount; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 296 | VkFormat fmt; |
| 297 | VkFormatProperties image_fmt; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 298 | |
| 299 | w =512; |
| 300 | h = 256; |
| 301 | mipCount = 0; |
| 302 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 303 | uint32_t _w = w; |
| 304 | uint32_t _h = h; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 305 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 306 | { |
| 307 | _w >>= 1; |
| 308 | _h >>= 1; |
| 309 | mipCount++; |
| 310 | } |
| 311 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 312 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 313 | // TODO: Pick known good format rather than just expect common format |
| 314 | /* |
| 315 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 316 | * We're not requesting VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS so there is |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 317 | * an expectation that pData is a valid pointer. |
| 318 | * However, why include a returned size value? That implies that the |
| 319 | * amount of data may vary and that doesn't work well for using a |
| 320 | * fixed structure. |
| 321 | */ |
| 322 | |
Courtney Goeltzenleuchter | 4da96aa | 2015-07-12 12:52:09 -0600 | [diff] [blame] | 323 | err = vkGetPhysicalDeviceFormatProperties(objs[m_device_id], fmt, &image_fmt); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 324 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 325 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 326 | // typedef struct VkImageCreateInfo_ |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 327 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 328 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 329 | // const void* pNext; // Pointer to next structure. |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 330 | // VkImageType imageType; |
| 331 | // VkFormat format; |
| 332 | // VkExtent3D extent; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 333 | // uint32_t mipLevels; |
| 334 | // uint32_t arraySize; |
| 335 | // uint32_t samples; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 336 | // VkImageTiling tiling; |
| 337 | // VkFlags usage; // VkImageUsageFlags |
| 338 | // VkFlags flags; // VkImageCreateFlags |
| 339 | // } VkImageCreateInfo; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 340 | |
| 341 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 342 | VkImageCreateInfo imageCreateInfo = {}; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 343 | imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 344 | imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 345 | imageCreateInfo.format = fmt; |
| 346 | imageCreateInfo.arraySize = 1; |
| 347 | imageCreateInfo.extent.width = w; |
| 348 | imageCreateInfo.extent.height = h; |
| 349 | imageCreateInfo.extent.depth = 1; |
| 350 | imageCreateInfo.mipLevels = mipCount; |
| 351 | imageCreateInfo.samples = 1; |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 352 | if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 353 | imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR; |
| 354 | } |
| 355 | else if (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 356 | imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 357 | } |
| 358 | else { |
| 359 | FAIL() << "Neither Linear nor Optimal allowed for color attachment"; |
| 360 | } |
Cody Northrop | d0d701b | 2015-06-17 08:28:19 -0600 | [diff] [blame] | 361 | imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 362 | VK_IMAGE_USAGE_SAMPLED_BIT; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 363 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 364 | // VkResult VKAPI vkCreateImage( |
| 365 | // VkDevice device, |
| 366 | // const VkImageCreateInfo* pCreateInfo, |
| 367 | // VkImage* pImage); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 368 | err = vkCreateImage(device(), &imageCreateInfo, &image); |
| 369 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 370 | |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 371 | // Verify image resources |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 372 | // VkResult VKAPI vkGetImageSubresourceLayout( |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 373 | // VkImage image, |
| 374 | // const VkImageSubresource* pSubresource, |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 375 | // VkSubresourceLayout* pLayout); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 376 | // typedef struct VkSubresourceLayout_ |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 377 | // { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 378 | // VkDeviceSize offset; // Specified in bytes |
| 379 | // VkDeviceSize size; // Specified in bytes |
| 380 | // VkDeviceSize rowPitch; // Specified in bytes |
| 381 | // VkDeviceSize depthPitch; // Specified in bytes |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 382 | // } VkSubresourceLayout; |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 383 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 384 | // typedef struct VkImageSubresource_ |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 385 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 386 | // VkImageAspect aspect; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 387 | // uint32_t mipLevel; |
| 388 | // uint32_t arraySlice; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 389 | // } VkImageSubresource; |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 390 | |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 391 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 392 | if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 393 | VkImageSubresource subresource = {}; |
| 394 | subresource.aspect = VK_IMAGE_ASPECT_COLOR; |
| 395 | subresource.arraySlice = 0; |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 396 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 397 | _w = w; |
| 398 | _h = h; |
| 399 | while ((_w > 0) || (_h > 0)) |
| 400 | { |
| 401 | VkSubresourceLayout layout = {}; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 402 | err = vkGetImageSubresourceLayout(device(), image, &subresource, &layout); |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 403 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 404 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 405 | // TODO: 4 should be replaced with pixel size for given format |
| 406 | EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch"; |
| 407 | _w >>= 1; |
| 408 | _h >>= 1; |
| 409 | |
| 410 | subresource.mipLevel++; |
| 411 | } |
Courtney Goeltzenleuchter | ac3b73a | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 412 | } |
| 413 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 414 | VkMemoryRequirements mem_req; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 415 | VkDeviceMemory image_mem; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 416 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 417 | err = vkGetImageMemoryRequirements(device(), image, &mem_req); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 418 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 419 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 420 | if (mem_req.size) { |
| 421 | |
| 422 | // VkResult VKAPI vkAllocMemory( |
| 423 | // VkDevice device, |
| 424 | // const VkMemoryAllocInfo* pAllocInfo, |
| 425 | // VkDeviceMemory* pMem); |
| 426 | VkMemoryAllocInfo mem_info = {}; |
| 427 | |
| 428 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 429 | mem_info.pNext = NULL; |
| 430 | mem_info.allocationSize = mem_req.size; |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 431 | mem_info.memoryTypeIndex = 0; |
| 432 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 433 | err = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 434 | ASSERT_VK_SUCCESS(err); |
| 435 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 436 | err = vkAllocMemory(device(), &mem_info, &image_mem); |
| 437 | ASSERT_VK_SUCCESS(err); |
| 438 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 439 | err = vkBindImageMemory(device(), image, image_mem, 0); |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 440 | ASSERT_VK_SUCCESS(err); |
| 441 | } |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 442 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 443 | // typedef struct VkImageViewCreateInfo_ |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 444 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 445 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 446 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 447 | // VkImage image; |
| 448 | // VkImageViewType viewType; |
| 449 | // VkFormat format; |
| 450 | // VkChannelMapping channels; |
| 451 | // VkImageSubresourceRange subresourceRange; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 452 | // float minLod; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 453 | // } VkImageViewCreateInfo; |
| 454 | VkImageViewCreateInfo viewInfo = {}; |
| 455 | VkImageView view; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 456 | viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 457 | viewInfo.image = image; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 458 | viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 459 | viewInfo.format = fmt; |
| 460 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 461 | viewInfo.channels.r = VK_CHANNEL_SWIZZLE_R; |
| 462 | viewInfo.channels.g = VK_CHANNEL_SWIZZLE_G; |
| 463 | viewInfo.channels.b = VK_CHANNEL_SWIZZLE_B; |
| 464 | viewInfo.channels.a = VK_CHANNEL_SWIZZLE_A; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 465 | |
| 466 | viewInfo.subresourceRange.baseArraySlice = 0; |
| 467 | viewInfo.subresourceRange.arraySize = 1; |
| 468 | viewInfo.subresourceRange.baseMipLevel = 0; |
| 469 | viewInfo.subresourceRange.mipLevels = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 470 | viewInfo.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 471 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 472 | // VkResult VKAPI vkCreateImageView( |
| 473 | // VkDevice device, |
| 474 | // const VkImageViewCreateInfo* pCreateInfo, |
| 475 | // VkImageView* pView); |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 476 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 477 | err = vkCreateImageView(device(), &viewInfo, &view); |
| 478 | ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed"; |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 479 | |
| 480 | // TODO: Test image memory. |
| 481 | |
| 482 | // All done with image memory, clean up |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 483 | ASSERT_VK_SUCCESS(vkDestroyImageView(device(), view)); |
| 484 | ASSERT_VK_SUCCESS(vkDestroyImage(device(), image)); |
Courtney Goeltzenleuchter | 0e168bb | 2015-06-22 16:26:54 -0600 | [diff] [blame] | 485 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 486 | if (mem_req.size) { |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 487 | ASSERT_VK_SUCCESS(vkFreeMemory(device(), image_mem)); |
| 488 | } |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 489 | } |
| 490 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 491 | TEST_F(VkTest, CreateImage) { |
Courtney Goeltzenleuchter | 9c3aad0 | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 492 | CreateImageTest(); |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 493 | } |
| 494 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 495 | void VkTest::CreateCommandBufferTest() |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 496 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 497 | VkResult err; |
| 498 | VkCmdBufferCreateInfo info = {}; |
Cody Northrop | f02f9f8 | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 499 | VkCmdPool cmdPool; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 500 | VkCmdBuffer cmdBuffer; |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 501 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 502 | // typedef struct VkCmdBufferCreateInfo_ |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 503 | // { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 504 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 505 | // const void* pNext; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 506 | // VK_QUEUE_TYPE queueType; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 507 | // VkFlags flags; |
| 508 | // } VkCmdBufferCreateInfo; |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 509 | |
Cody Northrop | f02f9f8 | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 510 | VkCmdPoolCreateInfo cmd_pool_info; |
| 511 | cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO, |
| 512 | cmd_pool_info.pNext = NULL, |
| 513 | cmd_pool_info.queueFamilyIndex = graphics_queue_node_index; |
| 514 | cmd_pool_info.flags = 0, |
| 515 | err = vkCreateCommandPool(device(), &cmd_pool_info, &cmdPool); |
| 516 | ASSERT_VK_SUCCESS(err) << "vkCreateCommandPool failed"; |
| 517 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 518 | info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
Cody Northrop | f02f9f8 | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 519 | info.cmdPool = cmdPool; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 520 | err = vkCreateCommandBuffer(device(), &info, &cmdBuffer); |
| 521 | ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed"; |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 522 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 523 | ASSERT_VK_SUCCESS(vkDestroyCommandBuffer(device(), cmdBuffer)); |
Cody Northrop | f02f9f8 | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 524 | ASSERT_VK_SUCCESS(vkDestroyCommandPool(device(), cmdPool)); |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 525 | } |
| 526 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 527 | TEST_F(VkTest, TestCommandBuffer) { |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 528 | CreateCommandBufferTest(); |
| 529 | } |
| 530 | |
Tony-LunarG | e4fe315 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 531 | void VkTest::CreateShader(VkShader *pshader) |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 532 | { |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 533 | void *code; |
| 534 | uint32_t codeSize; |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 535 | struct icd_spv_header *pSPV; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 536 | VkResult err; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 537 | |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 538 | codeSize = sizeof(struct icd_spv_header) + 100; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 539 | code = malloc(codeSize); |
| 540 | ASSERT_TRUE(NULL != code) << "malloc failed!"; |
| 541 | |
| 542 | memset(code, 0, codeSize); |
| 543 | |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 544 | // Indicate that this is SPV data. |
| 545 | pSPV = (struct icd_spv_header *) code; |
| 546 | pSPV->magic = ICD_SPV_MAGIC; |
| 547 | pSPV->version = ICD_SPV_VERSION; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 548 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 549 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 550 | VkShaderModule module; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 551 | VkShaderCreateInfo createInfo; |
| 552 | VkShader shader; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 553 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 554 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 555 | moduleCreateInfo.pNext = NULL; |
| 556 | moduleCreateInfo.pCode = code; |
| 557 | moduleCreateInfo.codeSize = codeSize; |
| 558 | moduleCreateInfo.flags = 0; |
| 559 | err = vkCreateShaderModule(device(), &moduleCreateInfo, &module); |
| 560 | ASSERT_VK_SUCCESS(err); |
| 561 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 562 | createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 563 | createInfo.pNext = NULL; |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 564 | createInfo.module = module; |
| 565 | createInfo.pName = "main"; |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 566 | createInfo.flags = 0; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 567 | err = vkCreateShader(device(), &createInfo, &shader); |
| 568 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | a693ed2 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 569 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 570 | err = vkDestroyShaderModule(device(), module); |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 571 | ASSERT_VK_SUCCESS(err); |
| 572 | |
Courtney Goeltzenleuchter | 0842df7 | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 573 | *pshader = shader; |
| 574 | } |
| 575 | |
Courtney Goeltzenleuchter | 6b814b3 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 576 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 577 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 578 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | ed56abc | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 579 | return RUN_ALL_TESTS(); |
Courtney Goeltzenleuchter | 7087dde | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 580 | } |