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