Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 1 | // Copyright 2005, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 30 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 31 | // |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 32 | // Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 33 | // |
| 34 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 35 | // copy of this software and associated documentation files (the "Software"), |
| 36 | // to deal in the Software without restriction, including without limitation |
| 37 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 38 | // and/or sell copies of the Software, and to permit persons to whom the |
| 39 | // Software is furnished to do so, subject to the following conditions: |
| 40 | // |
| 41 | // The above copyright notice and this permission notice shall be included |
| 42 | // in all copies or substantial portions of the Software. |
| 43 | // |
| 44 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 45 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 46 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 47 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 48 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 49 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 50 | // DEALINGS IN THE SOFTWARE. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 51 | // |
| 52 | // Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 53 | // Author: Jon Ashburn <jon@lunarg.com> |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 54 | |
| 55 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 56 | // Verify VK driver initialization |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 57 | |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 58 | #include <stdlib.h> |
| 59 | #include <stdio.h> |
| 60 | #include <stdbool.h> |
| 61 | #include <string.h> |
| 62 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 63 | #include <vulkan/vulkan.h> |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 64 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 65 | #include "vktestbinding.h" |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 66 | #include "test_common.h" |
Cody Northrop | 054a470 | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 67 | #include "icd-spv.h" |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 68 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 69 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 70 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 71 | class VkTest : public ::testing::Test { |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 72 | public: |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 73 | void CreateImageTest(); |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 74 | void CreateCommandBufferTest(); |
| 75 | void CreatePipelineTest(); |
| 76 | void CreateShaderTest(); |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 77 | void CreateShader(VkShaderModule *pmodule, VkShaderStageFlagBits stage); |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 78 | |
Chia-I Wu | f368b60 | 2015-07-03 10:41:20 +0800 | [diff] [blame] | 79 | VkDevice device() {return m_device->handle();} |
Courtney Goeltzenleuchter | cc5eb3a | 2014-08-19 18:35:50 -0600 | [diff] [blame] | 80 | |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 81 | protected: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 82 | VkApplicationInfo app_info; |
| 83 | VkInstance inst; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 84 | VkPhysicalDevice objs[16]; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 85 | uint32_t gpu_count; |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 86 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 87 | uint32_t m_device_id; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 88 | vk_testing::Device *m_device; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 89 | VkPhysicalDeviceProperties props; |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 90 | std::vector<VkQueueFamilyProperties> queue_props; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 91 | uint32_t graphics_queue_node_index; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 92 | |
| 93 | virtual void SetUp() { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 94 | VkResult err; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 95 | size_t i; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 96 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 97 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 98 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 99 | this->app_info.pApplicationName = "base"; |
| 100 | this->app_info.applicationVersion = 1; |
Chia-I Wu | f1a5a74 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 101 | this->app_info.pEngineName = "unittest"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 102 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | this->app_info.apiVersion = VK_API_VERSION; |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 104 | VkInstanceCreateInfo inst_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 105 | inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 106 | inst_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 107 | inst_info.pApplicationInfo = &app_info; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 108 | inst_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 109 | inst_info.ppEnabledLayerNames = NULL; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 110 | inst_info.enabledExtensionCount = 0; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 111 | inst_info.ppEnabledExtensionNames = NULL; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 112 | err = vkCreateInstance(&inst_info, NULL, &inst); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 113 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 114 | err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL); |
| 115 | ASSERT_VK_SUCCESS(err); |
| 116 | ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many GPUs"; |
| 117 | err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 119 | ASSERT_GE(this->gpu_count, (uint32_t) 1) << "No GPU available"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 120 | |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 121 | m_device_id = 0; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | this->m_device = new vk_testing::Device(objs[m_device_id]); |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 123 | this->m_device->init(); |
| 124 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 125 | props = m_device->phy().properties(); |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 126 | |
Chia-I Wu | 999f048 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 127 | queue_props = this->m_device->phy().queue_properties(); |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 128 | for (i = 0; i < queue_props.size(); i++) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 129 | if (queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 130 | graphics_queue_node_index = (uint32_t)i; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 131 | break; |
| 132 | } |
| 133 | } |
| 134 | ASSERT_LT(i, queue_props.size()) << "Could not find a Queue with Graphics support"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | virtual void TearDown() { |
Tony Barbour | c2f67f5 | 2015-06-02 14:55:46 -0600 | [diff] [blame] | 138 | delete m_device; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 139 | vkDestroyInstance(inst, NULL); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 140 | } |
| 141 | }; |
| 142 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 143 | TEST_F(VkTest, AllocateMemory) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 144 | VkResult err; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 145 | bool pass; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 146 | VkMemoryAllocateInfo alloc_info = {}; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 147 | VkDeviceMemory gpu_mem; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 148 | uint8_t *pData; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 149 | |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 150 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 151 | alloc_info.allocationSize = 1024 * 1024; // 1MB |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 152 | alloc_info.memoryTypeIndex = 0; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 153 | |
Tony Barbour | cba4ab2 | 2015-07-29 14:27:38 -0600 | [diff] [blame] | 154 | VkPhysicalDeviceMemoryProperties mem_props; |
| 155 | vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &mem_props); |
| 156 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 157 | pass = m_device->phy().set_memory_type(((1 << mem_props.memoryTypeCount) - 1), &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 158 | ASSERT_TRUE(pass); |
Tony Barbour | cba4ab2 | 2015-07-29 14:27:38 -0600 | [diff] [blame] | 159 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 160 | err = vkAllocateMemory(device(), &alloc_info, NULL, &gpu_mem); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 161 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 162 | |
Mark Lobodzinski | f0670cc | 2016-01-05 15:30:41 -0700 | [diff] [blame] | 163 | err = vkMapMemory(device(), gpu_mem, 0, VK_WHOLE_SIZE, 0, (void **) &pData); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 164 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 165 | |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 166 | memset(pData, 0x55, (size_t)alloc_info.allocationSize); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 167 | EXPECT_EQ(0x55, pData[0]) << "Memory read not same as write"; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 168 | |
Mark Lobodzinski | 2141f65 | 2015-09-07 13:59:43 -0600 | [diff] [blame] | 169 | vkUnmapMemory(device(), gpu_mem); |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 170 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 171 | vkFreeMemory(device(), gpu_mem, NULL); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 172 | } |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 173 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 174 | TEST_F(VkTest, Event) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 175 | VkEventCreateInfo event_info; |
| 176 | VkEvent event; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 177 | VkResult err; |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 178 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 179 | // typedef struct VkEventCreateInfo_ |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 180 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 181 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_EVENT_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 182 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 183 | // VkFlags flags; // Reserved |
| 184 | // } VkEventCreateInfo; |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 185 | memset(&event_info, 0, sizeof(event_info)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 186 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 187 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 188 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 189 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 190 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 191 | err = vkResetEvent(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 192 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 193 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 194 | err = vkGetEventStatus(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 195 | ASSERT_EQ(VK_EVENT_RESET, err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 196 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 197 | err = vkSetEvent(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 198 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 199 | |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 200 | err = vkGetEventStatus(device(), event); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 201 | ASSERT_EQ(VK_EVENT_SET, err); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 202 | |
| 203 | // TODO: Test actual synchronization with command buffer event. |
| 204 | |
| 205 | // All done with event memory, clean up |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 206 | vkDestroyEvent(device(), event, NULL); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 207 | } |
| 208 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 209 | 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] | 210 | { |
Cody Northrop | d2ad034 | 2015-08-05 11:15:02 -0600 | [diff] [blame] | 211 | uint32_t que_idx; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 212 | VkQueue queue; |
Courtney Goeltzenleuchter | 3dc07f2 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 213 | |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 214 | const VkQueueFamilyProperties props = device->phy().queue_properties()[queue_node_index]; |
Chia-I Wu | fe84fe1 | 2014-12-29 15:39:23 +0800 | [diff] [blame] | 215 | for (que_idx = 0; que_idx < props.queueCount; que_idx++) { |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 216 | // TODO: Need to add support for separate MEMMGR and work queues, including synchronization |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 217 | vkGetDeviceQueue(device->handle(), queue_node_index, que_idx, &queue); |
Courtney Goeltzenleuchter | 3dc07f2 | 2014-08-14 10:15:09 -0600 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 221 | void VkTest::CreateImageTest() |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 222 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 223 | VkResult err; |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 224 | bool pass; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 225 | VkImage image; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 226 | uint32_t w, h, mipCount; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 227 | VkFormat fmt; |
| 228 | VkFormatProperties image_fmt; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 229 | |
| 230 | w =512; |
| 231 | h = 256; |
| 232 | mipCount = 0; |
| 233 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 234 | uint32_t _w = w; |
| 235 | uint32_t _h = h; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 236 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 237 | { |
| 238 | _w >>= 1; |
| 239 | _h >>= 1; |
| 240 | mipCount++; |
| 241 | } |
| 242 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 243 | fmt = VK_FORMAT_R8G8B8A8_UINT; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 244 | // TODO: Pick known good format rather than just expect common format |
| 245 | /* |
| 246 | * XXX: What should happen if given NULL HANDLE for the pData argument? |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 247 | * 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] | 248 | * an expectation that pData is a valid pointer. |
| 249 | * However, why include a returned size value? That implies that the |
| 250 | * amount of data may vary and that doesn't work well for using a |
| 251 | * fixed structure. |
| 252 | */ |
| 253 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 254 | vkGetPhysicalDeviceFormatProperties(objs[m_device_id], fmt, &image_fmt); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 255 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 256 | // typedef struct VkImageCreateInfo_ |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 257 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 258 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 259 | // const void* pNext; // Pointer to next structure. |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 260 | // VkImageType imageType; |
| 261 | // VkFormat format; |
| 262 | // VkExtent3D extent; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 263 | // uint32_t mipLevels; |
| 264 | // uint32_t arraySize; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 265 | // VkSampleCountFlagBits samples; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 266 | // VkImageTiling tiling; |
| 267 | // VkFlags usage; // VkImageUsageFlags |
| 268 | // VkFlags flags; // VkImageCreateFlags |
| 269 | // } VkImageCreateInfo; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 270 | |
| 271 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 272 | VkImageCreateInfo imageCreateInfo = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 273 | imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 274 | imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 275 | imageCreateInfo.format = fmt; |
Courtney Goeltzenleuchter | 5d2aed4 | 2015-10-21 17:57:31 -0600 | [diff] [blame] | 276 | imageCreateInfo.arrayLayers = 1; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 277 | imageCreateInfo.extent.width = w; |
| 278 | imageCreateInfo.extent.height = h; |
| 279 | imageCreateInfo.extent.depth = 1; |
| 280 | imageCreateInfo.mipLevels = mipCount; |
Chia-I Wu | 5c17c96 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 281 | imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 282 | if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 283 | imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR; |
| 284 | } |
| 285 | else if (image_fmt.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 286 | imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 287 | } |
| 288 | else { |
| 289 | FAIL() << "Neither Linear nor Optimal allowed for color attachment"; |
| 290 | } |
Cody Northrop | bb6fdb3 | 2015-06-17 08:28:19 -0600 | [diff] [blame] | 291 | imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 292 | VK_IMAGE_USAGE_SAMPLED_BIT; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 293 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 294 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 295 | // VkDevice device, |
| 296 | // const VkImageCreateInfo* pCreateInfo, |
| 297 | // VkImage* pImage); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 298 | err = vkCreateImage(device(), &imageCreateInfo, NULL, &image); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 299 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 300 | |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 301 | // Verify image resources |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 302 | // VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 303 | // VkImage image, |
| 304 | // const VkImageSubresource* pSubresource, |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 305 | // VkSubresourceLayout* pLayout); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 306 | // typedef struct VkSubresourceLayout_ |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 307 | // { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 308 | // VkDeviceSize offset; // Specified in bytes |
| 309 | // VkDeviceSize size; // Specified in bytes |
| 310 | // VkDeviceSize rowPitch; // Specified in bytes |
| 311 | // VkDeviceSize depthPitch; // Specified in bytes |
Jon Ashburn | 2b2f90c | 2015-12-30 14:39:53 -0700 | [diff] [blame] | 312 | // VkDeviceSize arrayPitch; // Specified in bytes |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 313 | // } VkSubresourceLayout; |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 314 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 315 | // typedef struct VkImageSubresource_ |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 316 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 317 | // VkImageAspect aspect; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 318 | // uint32_t mipLevel; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 319 | // uint32_t arrayLayer; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 320 | // } VkImageSubresource; |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 321 | |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 322 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 323 | if (image_fmt.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
| 324 | VkImageSubresource subresource = {}; |
Chia-I Wu | 52b07e7 | 2015-10-27 19:55:05 +0800 | [diff] [blame] | 325 | subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 326 | subresource.arrayLayer = 0; |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 327 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 328 | _w = w; |
| 329 | _h = h; |
| 330 | while ((_w > 0) || (_h > 0)) |
| 331 | { |
| 332 | VkSubresourceLayout layout = {}; |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 333 | vkGetImageSubresourceLayout(device(), image, &subresource, &layout); |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 334 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 335 | // TODO: 4 should be replaced with pixel size for given format |
| 336 | EXPECT_LE(_w * 4, layout.rowPitch) << "Pitch does not match expected image pitch"; |
| 337 | _w >>= 1; |
| 338 | _h >>= 1; |
| 339 | |
| 340 | subresource.mipLevel++; |
| 341 | } |
Courtney Goeltzenleuchter | 7bf0ff8 | 2014-08-14 17:40:57 -0600 | [diff] [blame] | 342 | } |
| 343 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 344 | VkMemoryRequirements mem_req; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 345 | VkDeviceMemory image_mem; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 346 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 347 | vkGetImageMemoryRequirements(device(), image, &mem_req); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 348 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 349 | if (mem_req.size) { |
| 350 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 351 | // VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory( |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 352 | // VkDevice device, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 353 | // const VkMemoryAllocateInfo* pAllocateInfo, |
| 354 | // VkDeviceMemory* pMemory); |
| 355 | VkMemoryAllocateInfo mem_info = {}; |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 356 | |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 357 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 358 | mem_info.pNext = NULL; |
| 359 | mem_info.allocationSize = mem_req.size; |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 360 | mem_info.memoryTypeIndex = 0; |
| 361 | |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 362 | pass = m_device->phy().set_memory_type(mem_req.memoryTypeBits, &mem_info, 0); |
| 363 | ASSERT_TRUE(pass); |
Mark Lobodzinski | b3fbcd9 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 364 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 365 | err = vkAllocateMemory(device(), &mem_info, NULL, &image_mem); |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 366 | ASSERT_VK_SUCCESS(err); |
| 367 | |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 368 | err = vkBindImageMemory(device(), image, image_mem, 0); |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 369 | ASSERT_VK_SUCCESS(err); |
| 370 | } |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 371 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 372 | // typedef struct VkImageViewCreateInfo_ |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 373 | // { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 374 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 375 | // const void* pNext; // Pointer to next structure |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 376 | // VkImage image; |
| 377 | // VkImageViewType viewType; |
| 378 | // VkFormat format; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 379 | // VkComponentMapping channels; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 380 | // VkImageSubresourceRange subresourceRange; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 381 | // float minLod; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 382 | // } VkImageViewCreateInfo; |
| 383 | VkImageViewCreateInfo viewInfo = {}; |
| 384 | VkImageView view; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 385 | viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 386 | viewInfo.image = image; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 387 | viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 388 | viewInfo.format = fmt; |
| 389 | |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 390 | viewInfo.components.r = VK_COMPONENT_SWIZZLE_R; |
| 391 | viewInfo.components.g = VK_COMPONENT_SWIZZLE_G; |
| 392 | viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; |
| 393 | viewInfo.components.a = VK_COMPONENT_SWIZZLE_A; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 394 | |
Courtney Goeltzenleuchter | 4a26189 | 2015-09-10 16:38:41 -0600 | [diff] [blame] | 395 | viewInfo.subresourceRange.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 396 | viewInfo.subresourceRange.layerCount = 1; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 397 | viewInfo.subresourceRange.baseMipLevel = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 398 | viewInfo.subresourceRange.levelCount = 1; |
Courtney Goeltzenleuchter | ba72451 | 2015-09-10 17:58:54 -0600 | [diff] [blame] | 399 | viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 400 | |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 401 | // VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 402 | // VkDevice device, |
| 403 | // const VkImageViewCreateInfo* pCreateInfo, |
| 404 | // VkImageView* pView); |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 405 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 406 | err = vkCreateImageView(device(), &viewInfo, NULL, &view); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 407 | ASSERT_VK_SUCCESS(err) << "vkCreateImageView failed"; |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 408 | |
| 409 | // TODO: Test image memory. |
| 410 | |
| 411 | // All done with image memory, clean up |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 412 | vkDestroyImageView(device(), view, NULL); |
| 413 | vkDestroyImage(device(), image, NULL); |
Courtney Goeltzenleuchter | 1064256 | 2015-06-22 16:26:54 -0600 | [diff] [blame] | 414 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 415 | if (mem_req.size) { |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 416 | vkFreeMemory(device(), image_mem, NULL); |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 417 | } |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 418 | } |
| 419 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 420 | TEST_F(VkTest, CreateImage) { |
Courtney Goeltzenleuchter | 794555b | 2014-08-13 17:55:12 -0600 | [diff] [blame] | 421 | CreateImageTest(); |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 422 | } |
| 423 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 424 | void VkTest::CreateCommandBufferTest() |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 425 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 426 | VkResult err; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 427 | VkCommandBufferAllocateInfo info = {}; |
| 428 | VkCommandPool commandPool; |
| 429 | VkCommandBuffer commandBuffer; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 430 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 431 | // typedef struct VkCommandBufferCreateInfo_ |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 432 | // { |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 433 | // VkStructureType sType; // Must be VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 434 | // const void* pNext; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 435 | // VK_QUEUE_TYPE queueType; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 436 | // VkFlags flags; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 437 | // } VkCommandBufferAllocateInfo; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 438 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 439 | VkCommandPoolCreateInfo cmd_pool_info; |
| 440 | cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 441 | cmd_pool_info.pNext = NULL, |
| 442 | cmd_pool_info.queueFamilyIndex = graphics_queue_node_index; |
| 443 | cmd_pool_info.flags = 0, |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 444 | err = vkCreateCommandPool(device(), &cmd_pool_info, NULL, &commandPool); |
Cody Northrop | e62183e | 2015-07-09 18:08:05 -0600 | [diff] [blame] | 445 | ASSERT_VK_SUCCESS(err) << "vkCreateCommandPool failed"; |
| 446 | |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 447 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 448 | info.commandPool = commandPool; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 449 | info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 450 | info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 451 | err = vkAllocateCommandBuffers(device(), &info, &commandBuffer); |
| 452 | ASSERT_VK_SUCCESS(err) << "vkAllocateCommandBuffers failed"; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 453 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 454 | vkFreeCommandBuffers(device(), commandPool, 1, &commandBuffer); |
| 455 | vkDestroyCommandPool(device(), commandPool, NULL); |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 456 | } |
| 457 | |
Tony-LunarG | d61e1e5 | 2015-05-15 12:42:49 -0600 | [diff] [blame] | 458 | TEST_F(VkTest, TestCommandBuffer) { |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 459 | CreateCommandBufferTest(); |
| 460 | } |
| 461 | |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 462 | void VkTest::CreateShader(VkShaderModule *pmodule, VkShaderStageFlagBits stage) |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 463 | { |
Chia-I Wu | 8094f19 | 2015-10-26 19:22:06 +0800 | [diff] [blame] | 464 | uint32_t *code; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 465 | uint32_t codeSize; |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 466 | struct icd_spv_header *pSPV; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 467 | VkResult err; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 468 | |
Chia-I Wu | 8094f19 | 2015-10-26 19:22:06 +0800 | [diff] [blame] | 469 | codeSize = sizeof(struct icd_spv_header) + sizeof(uint32_t) * 25; |
| 470 | code = (uint32_t *) malloc(codeSize); |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 471 | ASSERT_TRUE(NULL != code) << "malloc failed!"; |
| 472 | |
| 473 | memset(code, 0, codeSize); |
| 474 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 475 | // Indicate that this is SPV data. |
| 476 | pSPV = (struct icd_spv_header *) code; |
| 477 | pSPV->magic = ICD_SPV_MAGIC; |
| 478 | pSPV->version = ICD_SPV_VERSION; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 479 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 480 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 481 | VkShaderModule module; |
Courtney Goeltzenleuchter | 6863ff4 | 2014-08-19 13:34:28 -0600 | [diff] [blame] | 482 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 483 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 484 | moduleCreateInfo.pNext = NULL; |
| 485 | moduleCreateInfo.pCode = code; |
| 486 | moduleCreateInfo.codeSize = codeSize; |
| 487 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 488 | err = vkCreateShaderModule(device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 489 | ASSERT_VK_SUCCESS(err); |
| 490 | |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 491 | *pmodule = module; |
Courtney Goeltzenleuchter | de3513a | 2014-08-20 15:26:55 -0600 | [diff] [blame] | 492 | } |
| 493 | |
Courtney Goeltzenleuchter | 75011f8 | 2014-08-12 09:59:36 -0600 | [diff] [blame] | 494 | int main(int argc, char **argv) { |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 495 | ::testing::InitGoogleTest(&argc, argv); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 496 | vk_testing::set_error_callback(test_error_callback); |
Courtney Goeltzenleuchter | cc9da54 | 2014-08-12 14:12:22 -0600 | [diff] [blame] | 497 | return RUN_ALL_TESTS(); |
Courtney Goeltzenleuchter | 447ed58 | 2014-08-11 18:19:35 -0600 | [diff] [blame] | 498 | } |