Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan Tests |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 29 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 30 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 31 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 32 | VkRenderFramework::VkRenderFramework() : |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | m_cmdBuffer( VK_NULL_HANDLE ), |
Tony Barbour | f77fd65 | 2015-04-09 11:07:02 -0600 | [diff] [blame] | 34 | m_renderPass(VK_NULL_HANDLE), |
| 35 | m_framebuffer(VK_NULL_HANDLE), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 36 | m_stateRaster( VK_NULL_HANDLE ), |
| 37 | m_colorBlend( VK_NULL_HANDLE ), |
| 38 | m_stateViewport( VK_NULL_HANDLE ), |
| 39 | m_stateDepthStencil( VK_NULL_HANDLE ), |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 40 | m_width( 256.0 ), // default window width |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 41 | m_height( 256.0 ), // default window height |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 42 | m_render_target_fmt( VK_FORMAT_R8G8B8A8_UNORM ), |
| 43 | m_depth_stencil_fmt( VK_FORMAT_UNDEFINED ), |
Chris Forbes | e182fe0 | 2015-06-15 09:32:35 +1200 | [diff] [blame] | 44 | m_clear_via_load_op( false ), |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 45 | m_depth_clear_color( 1.0 ), |
Courtney Goeltzenleuchter | b6c9aca | 2015-06-08 16:19:37 -0600 | [diff] [blame] | 46 | m_stencil_clear_color( 0 ), |
| 47 | m_depthStencil( NULL ), |
| 48 | m_dbgCreateMsgCallback( VK_NULL_HANDLE ), |
| 49 | m_dbgDestroyMsgCallback( VK_NULL_HANDLE ), |
| 50 | m_globalMsgCallback( VK_NULL_HANDLE ), |
| 51 | m_devMsgCallback( VK_NULL_HANDLE ) |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 52 | { |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 53 | |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 54 | // clear the back buffer to dark grey |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 55 | m_clear_color.f32[0] = 0.25f; |
| 56 | m_clear_color.f32[1] = 0.25f; |
| 57 | m_clear_color.f32[2] = 0.25f; |
| 58 | m_clear_color.f32[3] = 0.0f; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 59 | } |
| 60 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 61 | VkRenderFramework::~VkRenderFramework() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 62 | { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 63 | |
| 64 | } |
| 65 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 66 | void VkRenderFramework::InitFramework() |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 67 | { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 68 | std::vector<const char*> instance_extension_names; |
| 69 | std::vector<const char*> device_extension_names; |
| 70 | InitFramework(instance_extension_names, device_extension_names); |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 71 | } |
| 72 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 73 | void VkRenderFramework::InitFramework( |
| 74 | std::vector<const char *> instance_extension_names, |
| 75 | std::vector<const char *> device_extension_names, |
| 76 | PFN_vkDbgMsgCallback dbgFunction, |
| 77 | void *userData) |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 78 | { |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 79 | VkInstanceCreateInfo instInfo = {}; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 80 | std::vector<VkExtensionProperties> instance_extensions; |
| 81 | std::vector<VkExtensionProperties> device_extensions; |
| 82 | uint32_t extCount = 0; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 83 | VkResult U_ASSERT_ONLY err; |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 84 | err = vkGetGlobalExtensionCount(&extCount); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 85 | assert(!err); |
| 86 | |
| 87 | VkExtensionProperties extProp; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 88 | bool32_t extFound; |
| 89 | |
| 90 | for (uint32_t i = 0; i < instance_extension_names.size(); i++) { |
| 91 | extFound = 0; |
| 92 | for (uint32_t j = 0; j < extCount; j++) { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 93 | err = vkGetGlobalExtensionProperties(j, &extProp); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 94 | assert(!err); |
| 95 | if (!strcmp(instance_extension_names[i], extProp.name)) { |
| 96 | instance_extensions.push_back(extProp); |
| 97 | extFound = 1; |
| 98 | } |
| 99 | } |
| 100 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test"; |
| 101 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 102 | instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; |
Jon Ashburn | b317fad | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 103 | instInfo.pNext = NULL; |
| 104 | instInfo.pAppInfo = &app_info; |
| 105 | instInfo.pAllocCb = NULL; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 106 | instInfo.extensionCount = instance_extensions.size(); |
| 107 | instInfo.pEnabledExtensions = (instance_extensions.size()) ? &instance_extensions[0] : NULL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 108 | err = vkCreateInstance(&instInfo, &this->inst); |
| 109 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 110 | |
Jon Ashburn | 83a6425 | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 111 | err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL); |
| 112 | ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many gpus"; |
| 113 | ASSERT_VK_SUCCESS(err); |
| 114 | err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | bf843b2 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 116 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 117 | if (dbgFunction) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 118 | m_dbgCreateMsgCallback = (PFN_vkDbgCreateMsgCallback) vkGetInstanceProcAddr(this->inst, "vkDbgCreateMsgCallback"); |
| 119 | ASSERT_NE(m_dbgCreateMsgCallback, (PFN_vkDbgCreateMsgCallback) NULL) << "Did not get function pointer for DbgCreateMsgCallback"; |
| 120 | if (m_dbgCreateMsgCallback) { |
| 121 | err = m_dbgCreateMsgCallback(this->inst, |
| 122 | VK_DBG_REPORT_ERROR_BIT | VK_DBG_REPORT_WARN_BIT, |
| 123 | dbgFunction, |
| 124 | userData, |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 125 | &m_globalMsgCallback); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 126 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | 7e46b62 | 2015-06-08 15:16:04 -0600 | [diff] [blame] | 127 | |
| 128 | m_dbgDestroyMsgCallback = (PFN_vkDbgDestroyMsgCallback) vkGetInstanceProcAddr(this->inst, "vkDbgDestroyMsgCallback"); |
| 129 | ASSERT_NE(m_dbgDestroyMsgCallback, (PFN_vkDbgDestroyMsgCallback) NULL) << "Did not get function pointer for DbgDestroyMsgCallback"; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 130 | } |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 131 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 132 | |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 133 | err = vkGetPhysicalDeviceExtensionCount(objs[0], &extCount); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 134 | assert(!err); |
| 135 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 136 | for (uint32_t i = 0; i < device_extension_names.size(); i++) { |
| 137 | extFound = 0; |
| 138 | for (uint32_t j = 0; j < extCount; j++) { |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 139 | err = vkGetPhysicalDeviceExtensionProperties(objs[0], j, &extProp); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 140 | assert(!err); |
| 141 | if (!strcmp(device_extension_names[i], extProp.name)) { |
| 142 | device_extensions.push_back(extProp); |
| 143 | extFound = 1; |
| 144 | } |
| 145 | } |
| 146 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test"; |
| 147 | } |
| 148 | /* TODO: Testing unenabled extension */ |
| 149 | |
| 150 | // PFN_vkDbgSetObjectName obj_name = (PFN_vkDbgSetObjectName) vkGetInstanceProcAddr(this->inst, |
| 151 | // "vkDbgSetObjectName"); |
| 152 | // ASSERT_NE(obj_name, (PFN_vkDbgCreateMsgCallback) NULL) << "Did not get function pointer for DbgCreateMsgCallback"; |
| 153 | // obj_name() |
| 154 | m_device = new VkDeviceObj(0, objs[0], device_extensions); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 155 | |
| 156 | /* Now register callback on device */ |
| 157 | if (0) { |
| 158 | if (m_dbgCreateMsgCallback) { |
| 159 | err = m_dbgCreateMsgCallback(this->inst, |
| 160 | VK_DBG_REPORT_ERROR_BIT | VK_DBG_REPORT_WARN_BIT, |
| 161 | dbgFunction, |
| 162 | userData, |
| 163 | &m_devMsgCallback); |
| 164 | ASSERT_VK_SUCCESS(err); |
| 165 | } |
| 166 | } |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 167 | m_device->get_device_queue(); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 168 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 169 | m_depthStencil = new VkDepthStencilObj(); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 170 | } |
| 171 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 172 | void VkRenderFramework::ShutdownFramework() |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 173 | { |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 174 | if (m_colorBlend) vkDestroyObject(device(), VK_OBJECT_TYPE_DYNAMIC_CB_STATE, m_colorBlend); |
| 175 | if (m_stateDepthStencil) vkDestroyObject(device(), VK_OBJECT_TYPE_DYNAMIC_DS_STATE, m_stateDepthStencil); |
| 176 | if (m_stateRaster) vkDestroyObject(device(), VK_OBJECT_TYPE_DYNAMIC_RS_STATE, m_stateRaster); |
| 177 | if (m_cmdBuffer) vkDestroyObject(device(), VK_OBJECT_TYPE_COMMAND_BUFFER, m_cmdBuffer); |
| 178 | if (m_framebuffer) vkDestroyObject(device(), VK_OBJECT_TYPE_FRAMEBUFFER, m_framebuffer); |
| 179 | if (m_renderPass) vkDestroyObject(device(), VK_OBJECT_TYPE_RENDER_PASS, m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 180 | |
Courtney Goeltzenleuchter | 7e46b62 | 2015-06-08 15:16:04 -0600 | [diff] [blame] | 181 | if (m_globalMsgCallback) m_dbgDestroyMsgCallback(this->inst, m_globalMsgCallback); |
| 182 | if (m_devMsgCallback) m_dbgDestroyMsgCallback(this->inst, m_devMsgCallback); |
| 183 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 184 | if (m_stateViewport) { |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 185 | vkDestroyObject(device(), VK_OBJECT_TYPE_DYNAMIC_VP_STATE, m_stateViewport); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 186 | } |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 187 | while (!m_renderTargets.empty()) { |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 188 | vkDestroyObject(device(), VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW, m_renderTargets.back()->targetView()); |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 189 | vkDestroyObject(device(), VK_OBJECT_TYPE_IMAGE, m_renderTargets.back()->image()); |
| 190 | vkFreeMemory(device(), m_renderTargets.back()->memory()); |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 191 | m_renderTargets.pop_back(); |
| 192 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 193 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 194 | delete m_depthStencil; |
| 195 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 196 | // reset the driver |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 197 | delete m_device; |
Chris Forbes | be2fae6 | 2015-07-07 11:02:22 +1200 | [diff] [blame] | 198 | if (this->inst) vkDestroyInstance(this->inst); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 199 | } |
| 200 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 201 | void VkRenderFramework::InitState() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 202 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 203 | VkResult err; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 204 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 205 | m_render_target_fmt = VK_FORMAT_B8G8R8A8_UNORM; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 206 | |
| 207 | // create a raster state (solid, back-face culling) |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 208 | VkDynamicRsStateCreateInfo raster = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 209 | raster.sType = VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 210 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 211 | err = vkCreateDynamicRasterState( device(), &raster, &m_stateRaster ); |
| 212 | ASSERT_VK_SUCCESS(err); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 213 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 214 | VkDynamicCbStateCreateInfo blend = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 215 | blend.sType = VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO; |
Tony Barbour | d81b888 | 2015-05-15 09:37:57 -0600 | [diff] [blame] | 216 | blend.blendConst[0] = 1.0f; |
| 217 | blend.blendConst[1] = 1.0f; |
| 218 | blend.blendConst[2] = 1.0f; |
| 219 | blend.blendConst[3] = 1.0f; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 220 | err = vkCreateDynamicColorBlendState(device(), &blend, &m_colorBlend); |
| 221 | ASSERT_VK_SUCCESS( err ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 222 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 223 | VkDynamicDsStateCreateInfo depthStencil = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 224 | depthStencil.sType = VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO; |
Mark Lobodzinski | 365feea | 2015-06-12 11:14:17 -0600 | [diff] [blame] | 225 | depthStencil.minDepthBounds = 0.f; |
| 226 | depthStencil.maxDepthBounds = 1.f; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 227 | depthStencil.stencilFrontRef = 0; |
| 228 | depthStencil.stencilBackRef = 0; |
Tony Barbour | d81b888 | 2015-05-15 09:37:57 -0600 | [diff] [blame] | 229 | depthStencil.stencilReadMask = 0xff; |
| 230 | depthStencil.stencilWriteMask = 0xff; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 231 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 232 | err = vkCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
| 233 | ASSERT_VK_SUCCESS( err ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 234 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 235 | VkCmdBufferCreateInfo cmdInfo = {}; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 236 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 237 | cmdInfo.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 238 | cmdInfo.queueNodeIndex = m_device->graphics_queue_node_index_; |
| 239 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 240 | err = vkCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 241 | ASSERT_VK_SUCCESS(err) << "vkCreateCommandBuffer failed"; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 242 | } |
| 243 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 244 | void VkRenderFramework::InitViewport(float width, float height) |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 245 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 246 | VkResult err; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 247 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 248 | VkViewport viewport; |
Chris Forbes | d9be82b | 2015-06-22 17:21:59 +1200 | [diff] [blame] | 249 | VkRect2D scissor; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 250 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 251 | VkDynamicVpStateCreateInfo viewportCreate = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | viewportCreate.sType = VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 253 | viewportCreate.viewportAndScissorCount = 1; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 254 | viewport.originX = 0; |
| 255 | viewport.originY = 0; |
| 256 | viewport.width = 1.f * width; |
| 257 | viewport.height = 1.f * height; |
| 258 | viewport.minDepth = 0.f; |
| 259 | viewport.maxDepth = 1.f; |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 260 | scissor.extent.width = (int32_t) width; |
| 261 | scissor.extent.height = (int32_t) height; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 262 | scissor.offset.x = 0; |
| 263 | scissor.offset.y = 0; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 264 | viewportCreate.pViewports = &viewport; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 265 | viewportCreate.pScissors = &scissor; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 266 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 267 | err = vkCreateDynamicViewportState( device(), &viewportCreate, &m_stateViewport ); |
| 268 | ASSERT_VK_SUCCESS( err ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 269 | m_width = width; |
| 270 | m_height = height; |
| 271 | } |
| 272 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 273 | void VkRenderFramework::InitViewport() |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 274 | { |
| 275 | InitViewport(m_width, m_height); |
| 276 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 277 | void VkRenderFramework::InitRenderTarget() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 278 | { |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 279 | InitRenderTarget(1); |
| 280 | } |
| 281 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 282 | void VkRenderFramework::InitRenderTarget(uint32_t targets) |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 283 | { |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 284 | InitRenderTarget(targets, NULL); |
| 285 | } |
| 286 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 287 | void VkRenderFramework::InitRenderTarget(VkDepthStencilBindInfo *dsBinding) |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 288 | { |
| 289 | InitRenderTarget(1, dsBinding); |
| 290 | } |
| 291 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 292 | void VkRenderFramework::InitRenderTarget(uint32_t targets, VkDepthStencilBindInfo *dsBinding) |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 293 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 294 | std::vector<VkAttachmentLoadOp> load_ops; |
| 295 | std::vector<VkAttachmentStoreOp> store_ops; |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 296 | std::vector<VkClearColorValue> clear_colors; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 297 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 298 | uint32_t i; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 299 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 300 | for (i = 0; i < targets; i++) { |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 301 | VkImageObj *img = new VkImageObj(m_device); |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 302 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 303 | VkFormatProperties props; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 304 | VkResult err; |
| 305 | |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 306 | err = vkGetPhysicalDeviceFormatInfo(m_device->gpu().obj(), m_render_target_fmt, &props); |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 307 | ASSERT_VK_SUCCESS(err); |
| 308 | |
| 309 | if (props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 310 | img->init((uint32_t)m_width, (uint32_t)m_height, m_render_target_fmt, |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 311 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR); |
| 312 | } |
| 313 | else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) { |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 314 | img->init((uint32_t)m_width, (uint32_t)m_height, m_render_target_fmt, |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 315 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL); |
| 316 | } |
| 317 | else { |
| 318 | FAIL() << "Neither Linear nor Optimal allowed for render target"; |
| 319 | } |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 320 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 321 | m_renderTargets.push_back(img); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 322 | m_colorBindings[i].view = img->targetView(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 323 | m_colorBindings[i].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
Chris Forbes | e182fe0 | 2015-06-15 09:32:35 +1200 | [diff] [blame] | 324 | load_ops.push_back(m_clear_via_load_op ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 325 | store_ops.push_back(VK_ATTACHMENT_STORE_OP_STORE); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 326 | clear_colors.push_back(m_clear_color); |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 327 | } |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 328 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 329 | // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 330 | VkFramebufferCreateInfo fb_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 331 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 332 | fb_info.pNext = NULL; |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 333 | fb_info.colorAttachmentCount = m_renderTargets.size(); |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 334 | fb_info.pColorAttachments = m_colorBindings; |
| 335 | fb_info.pDepthStencilAttachment = dsBinding; |
| 336 | fb_info.sampleCount = 1; |
| 337 | fb_info.width = (uint32_t)m_width; |
| 338 | fb_info.height = (uint32_t)m_height; |
| 339 | fb_info.layers = 1; |
| 340 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 341 | vkCreateFramebuffer(device(), &fb_info, &m_framebuffer); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 342 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 343 | VkRenderPassCreateInfo rp_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 344 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 345 | rp_info.renderArea.extent.width = (uint32_t) m_width; |
| 346 | rp_info.renderArea.extent.height = (uint32_t) m_height; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 347 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 348 | rp_info.colorAttachmentCount = m_renderTargets.size(); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 349 | rp_info.pColorFormats = &m_render_target_fmt; |
| 350 | rp_info.pColorLayouts = &m_colorBindings[0].layout; |
| 351 | rp_info.pColorLoadOps = &load_ops[0]; |
| 352 | rp_info.pColorStoreOps = &store_ops[0]; |
| 353 | rp_info.pColorLoadClearValues = &clear_colors[0]; |
| 354 | rp_info.depthStencilFormat = m_depth_stencil_fmt; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 355 | if (dsBinding) { |
| 356 | rp_info.depthStencilLayout = dsBinding->layout; |
| 357 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 358 | rp_info.depthLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 359 | rp_info.depthLoadClearValue = m_depth_clear_color; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 360 | rp_info.depthStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 361 | rp_info.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 362 | rp_info.stencilLoadClearValue = m_stencil_clear_color; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 363 | rp_info.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
Tony Barbour | 51a05ce | 2015-06-03 11:40:51 -0600 | [diff] [blame] | 364 | rp_info.sampleCount = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 365 | vkCreateRenderPass(device(), &rp_info, &m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 366 | } |
| 367 | |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 368 | |
| 369 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 370 | VkDeviceObj::VkDeviceObj(uint32_t id, VkPhysicalDevice obj) : |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 371 | vk_testing::Device(obj), id(id) |
Chia-I Wu | fb1459b | 2014-12-29 15:23:20 +0800 | [diff] [blame] | 372 | { |
| 373 | init(); |
| 374 | |
| 375 | props = gpu().properties(); |
| 376 | queue_props = &gpu().queue_properties()[0]; |
| 377 | } |
| 378 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 379 | VkDeviceObj::VkDeviceObj(uint32_t id, |
| 380 | VkPhysicalDevice obj, |
| 381 | std::vector<VkExtensionProperties> extensions) : |
| 382 | vk_testing::Device(obj), id(id) |
| 383 | { |
| 384 | init(extensions); |
| 385 | |
| 386 | props = gpu().properties(); |
| 387 | queue_props = &gpu().queue_properties()[0]; |
| 388 | } |
| 389 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 390 | void VkDeviceObj::get_device_queue() |
Chia-I Wu | fb1459b | 2014-12-29 15:23:20 +0800 | [diff] [blame] | 391 | { |
| 392 | ASSERT_NE(true, graphics_queues().empty()); |
| 393 | m_queue = graphics_queues()[0]->obj(); |
| 394 | } |
| 395 | |
Tobin Ehlis | 3ab1f87 | 2015-05-27 14:33:27 -0600 | [diff] [blame] | 396 | VkDescriptorSetObj::VkDescriptorSetObj(VkDeviceObj *device) : |
| 397 | m_device(device), m_nextSlot(0) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 398 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 399 | |
| 400 | } |
| 401 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 402 | VkDescriptorSetObj::~VkDescriptorSetObj() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 403 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 404 | delete m_set; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 405 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 406 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 407 | int VkDescriptorSetObj::AppendDummy() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 408 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 409 | /* request a descriptor but do not update it */ |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 410 | VkDescriptorTypeCount tc = {}; |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 411 | tc.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 412 | tc.count = 1; |
| 413 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 414 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 415 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 416 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 417 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 418 | int VkDescriptorSetObj::AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 419 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 420 | VkDescriptorTypeCount tc = {}; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 421 | tc.type = type; |
| 422 | tc.count = 1; |
| 423 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 424 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 425 | m_writes.push_back(vk_testing::Device::write_descriptor_set(vk_testing::DescriptorSet(), |
| 426 | m_nextSlot, 0, type, 1, &constantBuffer.m_descriptorInfo)); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 427 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 428 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 429 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 430 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 431 | int VkDescriptorSetObj::AppendSamplerTexture( VkSamplerObj* sampler, VkTextureObj* texture) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 432 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 433 | VkDescriptorTypeCount tc = {}; |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 434 | tc.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 435 | tc.count = 1; |
| 436 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 437 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 438 | VkDescriptorInfo tmp = texture->m_descriptorInfo; |
Courtney Goeltzenleuchter | f39b3ec | 2015-04-09 11:43:10 -0600 | [diff] [blame] | 439 | tmp.sampler = sampler->obj(); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 440 | m_imageSamplerDescriptors.push_back(tmp); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 441 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 442 | m_writes.push_back(vk_testing::Device::write_descriptor_set(vk_testing::DescriptorSet(), |
| 443 | m_nextSlot, 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, NULL)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 444 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 445 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 446 | } |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 447 | |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 448 | VkPipelineLayout VkDescriptorSetObj::GetPipelineLayout() const |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 449 | { |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 450 | return m_pipeline_layout.obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 453 | VkDescriptorSet VkDescriptorSetObj::GetDescriptorSetHandle() const |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 454 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 455 | return m_set->obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 456 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 457 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 458 | void VkDescriptorSetObj::CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer) |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 459 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 460 | // create VkDescriptorPool |
| 461 | VkDescriptorPoolCreateInfo pool = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 462 | pool.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
Chia-I Wu | 985ba16 | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 463 | pool.count = m_type_counts.size(); |
| 464 | pool.pTypeCount = &m_type_counts[0]; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 465 | init(*m_device, VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, pool); |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 466 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 467 | // create VkDescriptorSetLayout |
| 468 | vector<VkDescriptorSetLayoutBinding> bindings; |
Chia-I Wu | b41393e | 2015-03-26 15:04:41 +0800 | [diff] [blame] | 469 | bindings.resize(m_type_counts.size()); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 470 | for (int i = 0; i < m_type_counts.size(); i++) { |
Chia-I Wu | b41393e | 2015-03-26 15:04:41 +0800 | [diff] [blame] | 471 | bindings[i].descriptorType = m_type_counts[i].type; |
Chia-I Wu | 712bb5d | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 472 | bindings[i].arraySize = m_type_counts[i].count; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 473 | bindings[i].stageFlags = VK_SHADER_STAGE_ALL; |
Chia-I Wu | 0743e83 | 2015-03-27 12:56:09 +0800 | [diff] [blame] | 474 | bindings[i].pImmutableSamplers = NULL; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 475 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 476 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 477 | // create VkDescriptorSetLayout |
| 478 | VkDescriptorSetLayoutCreateInfo layout = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 479 | layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Chia-I Wu | b41393e | 2015-03-26 15:04:41 +0800 | [diff] [blame] | 480 | layout.count = bindings.size(); |
| 481 | layout.pBinding = &bindings[0]; |
| 482 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 483 | m_layout.init(*m_device, layout); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 484 | vector<const vk_testing::DescriptorSetLayout *> layouts; |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 485 | layouts.push_back(&m_layout); |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 486 | |
| 487 | // create VkPipelineLayout |
| 488 | VkPipelineLayoutCreateInfo pipeline_layout = {}; |
| 489 | pipeline_layout.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 490 | pipeline_layout.descriptorSetCount = layouts.size(); |
| 491 | pipeline_layout.pSetLayouts = NULL; |
| 492 | |
| 493 | m_pipeline_layout.init(*m_device, pipeline_layout, layouts); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 494 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 495 | // create VkDescriptorSet |
Mark Lobodzinski | 40f7f40 | 2015-04-16 11:44:05 -0500 | [diff] [blame] | 496 | m_set = alloc_sets(*m_device, VK_DESCRIPTOR_SET_USAGE_STATIC, m_layout); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 497 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 498 | // build the update array |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 499 | size_t imageSamplerCount = 0; |
| 500 | for (std::vector<VkWriteDescriptorSet>::iterator it = m_writes.begin(); |
| 501 | it != m_writes.end(); it++) { |
| 502 | it->destSet = m_set->obj(); |
| 503 | if (it->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) |
| 504 | it->pDescriptors = &m_imageSamplerDescriptors[imageSamplerCount++]; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 505 | } |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 506 | |
| 507 | // do the updates |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 508 | m_device->update_descriptor_sets(m_writes); |
Tony Barbour | 25ef8a6 | 2014-12-03 13:59:18 -0700 | [diff] [blame] | 509 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 510 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 511 | VkImageObj::VkImageObj(VkDeviceObj *dev) |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 512 | { |
| 513 | m_device = dev; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 514 | m_descriptorInfo.imageView = VK_NULL_HANDLE; |
| 515 | m_descriptorInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 516 | } |
| 517 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 518 | void VkImageObj::ImageMemoryBarrier( |
| 519 | VkCommandBufferObj *cmd_buf, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 520 | VkImageAspect aspect, |
| 521 | VkFlags output_mask /*= |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 522 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 523 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 524 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 525 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 526 | VK_MEMORY_OUTPUT_COPY_BIT*/, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 527 | VkFlags input_mask /*= |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 528 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 529 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 530 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 531 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 532 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 533 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 534 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 535 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 536 | VK_MEMORY_INPUT_COPY_BIT*/, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 537 | VkImageLayout image_layout) |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 538 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 539 | const VkImageSubresourceRange subresourceRange = subresource_range(aspect, 0, 1, 0, 1); |
| 540 | VkImageMemoryBarrier barrier; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 541 | barrier = image_memory_barrier(output_mask, input_mask, layout(), image_layout, |
| 542 | subresourceRange); |
| 543 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 544 | VkImageMemoryBarrier *pmemory_barrier = &barrier; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 545 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 546 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
| 547 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 548 | |
| 549 | // write barrier to the command buffer |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 550 | vkCmdPipelineBarrier(cmd_buf->obj(), src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 551 | } |
| 552 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 553 | void VkImageObj::SetLayout(VkCommandBufferObj *cmd_buf, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 554 | VkImageAspect aspect, |
| 555 | VkImageLayout image_layout) |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 556 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 557 | VkFlags output_mask, input_mask; |
| 558 | const VkFlags all_cache_outputs = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 559 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 560 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 561 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 562 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 563 | VK_MEMORY_OUTPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 564 | const VkFlags all_cache_inputs = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 565 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 566 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 567 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 568 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 569 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 570 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 571 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 572 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 573 | VK_MEMORY_INPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 574 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 575 | if (image_layout == m_descriptorInfo.imageLayout) { |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 576 | return; |
| 577 | } |
| 578 | |
| 579 | switch (image_layout) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 580 | case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL: |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 581 | output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT; |
| 582 | input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 583 | break; |
| 584 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 585 | case VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL: |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 586 | output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT; |
| 587 | input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 588 | break; |
| 589 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 590 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 591 | output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT; |
| 592 | input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | default: |
| 596 | output_mask = all_cache_outputs; |
| 597 | input_mask = all_cache_inputs; |
| 598 | break; |
| 599 | } |
| 600 | |
| 601 | ImageMemoryBarrier(cmd_buf, aspect, output_mask, input_mask, image_layout); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 602 | m_descriptorInfo.imageLayout = image_layout; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 603 | } |
| 604 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 605 | void VkImageObj::SetLayout(VkImageAspect aspect, |
| 606 | VkImageLayout image_layout) |
Courtney Goeltzenleuchter | be4f0cd | 2015-04-07 08:57:30 -0600 | [diff] [blame] | 607 | { |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 608 | VkResult U_ASSERT_ONLY err; |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 609 | |
| 610 | if (image_layout == m_descriptorInfo.imageLayout) { |
| 611 | return; |
| 612 | } |
| 613 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 614 | VkCommandBufferObj cmd_buf(m_device); |
Courtney Goeltzenleuchter | be4f0cd | 2015-04-07 08:57:30 -0600 | [diff] [blame] | 615 | |
| 616 | /* Build command buffer to set image layout in the driver */ |
| 617 | err = cmd_buf.BeginCommandBuffer(); |
| 618 | assert(!err); |
| 619 | |
| 620 | SetLayout(&cmd_buf, aspect, image_layout); |
| 621 | |
| 622 | err = cmd_buf.EndCommandBuffer(); |
| 623 | assert(!err); |
| 624 | |
| 625 | cmd_buf.QueueCommandBuffer(); |
| 626 | } |
| 627 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 628 | bool VkImageObj::IsCompatible(VkFlags usage, VkFlags features) |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 629 | { |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 630 | if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) && |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 631 | !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 632 | return false; |
Courtney Goeltzenleuchter | be4f0cd | 2015-04-07 08:57:30 -0600 | [diff] [blame] | 633 | |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 634 | return true; |
| 635 | } |
| 636 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 637 | void VkImageObj::init(uint32_t w, uint32_t h, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 638 | VkFormat fmt, VkFlags usage, |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 639 | VkImageTiling requested_tiling, |
| 640 | VkMemoryPropertyFlags reqs) |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 641 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 642 | uint32_t mipCount; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 643 | VkFormatProperties image_fmt; |
| 644 | VkImageTiling tiling; |
| 645 | VkResult err; |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 646 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 647 | mipCount = 0; |
| 648 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 649 | uint32_t _w = w; |
| 650 | uint32_t _h = h; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 651 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 652 | { |
| 653 | _w >>= 1; |
| 654 | _h >>= 1; |
| 655 | mipCount++; |
| 656 | } |
| 657 | |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 658 | err = vkGetPhysicalDeviceFormatInfo(m_device->gpu().obj(), fmt, &image_fmt); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 659 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 660 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 661 | if (requested_tiling == VK_IMAGE_TILING_LINEAR) { |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 662 | if (IsCompatible(usage, image_fmt.linearTilingFeatures)) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 663 | tiling = VK_IMAGE_TILING_LINEAR; |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 664 | } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 665 | tiling = VK_IMAGE_TILING_OPTIMAL; |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 666 | } else { |
| 667 | ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration"; |
| 668 | } |
| 669 | } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 670 | tiling = VK_IMAGE_TILING_OPTIMAL; |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 671 | } else if (IsCompatible(usage, image_fmt.linearTilingFeatures)) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 672 | tiling = VK_IMAGE_TILING_LINEAR; |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 673 | } else { |
| 674 | ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration"; |
| 675 | } |
| 676 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 677 | VkImageCreateInfo imageCreateInfo = vk_testing::Image::create_info(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 678 | imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 679 | imageCreateInfo.format = fmt; |
| 680 | imageCreateInfo.extent.width = w; |
| 681 | imageCreateInfo.extent.height = h; |
| 682 | imageCreateInfo.mipLevels = mipCount; |
| 683 | imageCreateInfo.tiling = tiling; |
| 684 | |
| 685 | imageCreateInfo.usage = usage; |
| 686 | |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 687 | vk_testing::Image::init(*m_device, imageCreateInfo, reqs); |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 688 | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 689 | if (usage & VK_IMAGE_USAGE_SAMPLED_BIT) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 690 | SetLayout(VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); |
Courtney Goeltzenleuchter | be4f0cd | 2015-04-07 08:57:30 -0600 | [diff] [blame] | 691 | } else { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 692 | SetLayout(VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_GENERAL); |
Courtney Goeltzenleuchter | be4f0cd | 2015-04-07 08:57:30 -0600 | [diff] [blame] | 693 | } |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 694 | } |
| 695 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 696 | VkResult VkImageObj::MapMemory(void** ptr) |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 697 | { |
| 698 | *ptr = map(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 699 | return (*ptr) ? VK_SUCCESS : VK_ERROR_UNKNOWN; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 700 | } |
| 701 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 702 | VkResult VkImageObj::UnmapMemory() |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 703 | { |
| 704 | unmap(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 705 | return VK_SUCCESS; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 706 | } |
| 707 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 708 | VkResult VkImageObj::CopyImage(VkImageObj &src_image) |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 709 | { |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 710 | VkResult U_ASSERT_ONLY err; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 711 | VkCommandBufferObj cmd_buf(m_device); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 712 | VkImageLayout src_image_layout, dest_image_layout; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 713 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 714 | /* Build command buffer to copy staging texture to usable texture */ |
| 715 | err = cmd_buf.BeginCommandBuffer(); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 716 | assert(!err); |
| 717 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 718 | /* TODO: Can we determine image aspect from image object? */ |
| 719 | src_image_layout = src_image.layout(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 720 | src_image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 721 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 722 | dest_image_layout = this->layout(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 723 | this->SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 724 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 725 | VkImageCopy copy_region = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 726 | copy_region.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 727 | copy_region.srcSubresource.arraySlice = 0; |
| 728 | copy_region.srcSubresource.mipLevel = 0; |
| 729 | copy_region.srcOffset.x = 0; |
| 730 | copy_region.srcOffset.y = 0; |
| 731 | copy_region.srcOffset.z = 0; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 732 | copy_region.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 733 | copy_region.destSubresource.arraySlice = 0; |
| 734 | copy_region.destSubresource.mipLevel = 0; |
| 735 | copy_region.destOffset.x = 0; |
| 736 | copy_region.destOffset.y = 0; |
| 737 | copy_region.destOffset.z = 0; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 738 | copy_region.extent = src_image.extent(); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 739 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 740 | vkCmdCopyImage(cmd_buf.obj(), |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 741 | src_image.obj(), src_image.layout(), |
| 742 | obj(), layout(), |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 743 | 1, ©_region); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 744 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 745 | src_image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, src_image_layout); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 746 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 747 | this->SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, dest_image_layout); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 748 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 749 | err = cmd_buf.EndCommandBuffer(); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 750 | assert(!err); |
| 751 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 752 | cmd_buf.QueueCommandBuffer(); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 753 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 754 | return VK_SUCCESS; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 755 | } |
| 756 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 757 | VkTextureObj::VkTextureObj(VkDeviceObj *device, uint32_t *colors) |
| 758 | :VkImageObj(device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 759 | { |
| 760 | m_device = device; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 761 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 762 | uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 }; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 763 | void *data; |
| 764 | int32_t x, y; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 765 | VkImageObj stagingImage(device); |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 766 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 767 | |
Cody Northrop | bb6fdb3 | 2015-06-17 08:28:19 -0600 | [diff] [blame^] | 768 | stagingImage.init(16, 16, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, reqs); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 769 | VkSubresourceLayout layout = stagingImage.subresource_layout(subresource(VK_IMAGE_ASPECT_COLOR, 0, 0)); |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 770 | |
| 771 | if (colors == NULL) |
| 772 | colors = tex_colors; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 773 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 774 | memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 775 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 776 | VkImageViewCreateInfo view = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 777 | view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 778 | view.pNext = NULL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 779 | view.image = VK_NULL_HANDLE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 780 | view.viewType = VK_IMAGE_VIEW_TYPE_2D; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 781 | view.format = tex_format; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 782 | view.channels.r = VK_CHANNEL_SWIZZLE_R; |
| 783 | view.channels.g = VK_CHANNEL_SWIZZLE_G; |
| 784 | view.channels.b = VK_CHANNEL_SWIZZLE_B; |
| 785 | view.channels.a = VK_CHANNEL_SWIZZLE_A; |
| 786 | view.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 787 | view.subresourceRange.baseMipLevel = 0; |
| 788 | view.subresourceRange.mipLevels = 1; |
| 789 | view.subresourceRange.baseArraySlice = 0; |
| 790 | view.subresourceRange.arraySize = 1; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 791 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 792 | /* create image */ |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 793 | init(16, 16, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 794 | |
| 795 | /* create image view */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 796 | view.image = obj(); |
| 797 | m_textureView.init(*m_device, view); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 798 | m_descriptorInfo.imageView = m_textureView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 799 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 800 | data = stagingImage.map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 801 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 802 | for (y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 803 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 804 | for (x = 0; x < extent().width; x++) |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 805 | row[x] = colors[(x & 1) ^ (y & 1)]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 806 | } |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 807 | stagingImage.unmap(); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 808 | VkImageObj::CopyImage(stagingImage); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 809 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 810 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 811 | VkSamplerObj::VkSamplerObj(VkDeviceObj *device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 812 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 813 | m_device = device; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 814 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 815 | VkSamplerCreateInfo samplerCreateInfo; |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 816 | memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 817 | samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 818 | samplerCreateInfo.magFilter = VK_TEX_FILTER_NEAREST; |
| 819 | samplerCreateInfo.minFilter = VK_TEX_FILTER_NEAREST; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 820 | samplerCreateInfo.mipMode = VK_TEX_MIPMAP_MODE_BASE; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 821 | samplerCreateInfo.addressU = VK_TEX_ADDRESS_WRAP; |
| 822 | samplerCreateInfo.addressV = VK_TEX_ADDRESS_WRAP; |
| 823 | samplerCreateInfo.addressW = VK_TEX_ADDRESS_WRAP; |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 824 | samplerCreateInfo.mipLodBias = 0.0; |
Tony Barbour | 7ea6aa2 | 2015-05-22 09:44:58 -0600 | [diff] [blame] | 825 | samplerCreateInfo.maxAnisotropy = 0; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 826 | samplerCreateInfo.compareOp = VK_COMPARE_OP_NEVER; |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 827 | samplerCreateInfo.minLod = 0.0; |
| 828 | samplerCreateInfo.maxLod = 0.0; |
Tony Barbour | 26b17f8 | 2015-06-25 16:56:44 -0600 | [diff] [blame] | 829 | samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 830 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 831 | init(*m_device, samplerCreateInfo); |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 832 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 833 | |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 834 | /* |
| 835 | * Basic ConstantBuffer constructor. Then use create methods to fill in the details. |
| 836 | */ |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 837 | VkConstantBufferObj::VkConstantBufferObj(VkDeviceObj *device) |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 838 | { |
| 839 | m_device = device; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 840 | m_commandBuffer = 0; |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 841 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 842 | memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo)); |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 845 | VkConstantBufferObj::~VkConstantBufferObj() |
Tony Barbour | 044703b | 2015-03-26 12:37:52 -0600 | [diff] [blame] | 846 | { |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 847 | // TODO: Should we call QueueRemoveMemReference for the constant buffer memory here? |
Tony Barbour | 044703b | 2015-03-26 12:37:52 -0600 | [diff] [blame] | 848 | if (m_commandBuffer) { |
| 849 | delete m_commandBuffer; |
| 850 | } |
| 851 | } |
| 852 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 853 | VkConstantBufferObj::VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 854 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 855 | m_device = device; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 856 | m_commandBuffer = 0; |
| 857 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 858 | memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 859 | m_numVertices = constantCount; |
| 860 | m_stride = constantSize; |
| 861 | |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 862 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 863 | const size_t allocationSize = constantCount * constantSize; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 864 | init(*m_device, allocationSize, reqs); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 865 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 866 | void *pData = map(); |
| 867 | memcpy(pData, data, allocationSize); |
| 868 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 869 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 870 | // set up the buffer view for the constant buffer |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 871 | VkBufferViewCreateInfo view_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 872 | view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 873 | view_info.buffer = obj(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 874 | view_info.viewType = VK_BUFFER_VIEW_TYPE_RAW; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 875 | view_info.offset = 0; |
| 876 | view_info.range = allocationSize; |
| 877 | m_bufferView.init(*m_device, view_info); |
| 878 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 879 | this->m_descriptorInfo.bufferView = m_bufferView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 880 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 881 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 882 | void VkConstantBufferObj::Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding) |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 883 | { |
Courtney Goeltzenleuchter | f68ad72 | 2015-04-16 13:38:46 -0600 | [diff] [blame] | 884 | vkCmdBindVertexBuffers(cmdBuffer, binding, 1, &obj(), &offset); |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 888 | void VkConstantBufferObj::BufferMemoryBarrier( |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 889 | VkFlags outputMask /*= |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 890 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 891 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 892 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 893 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 894 | VK_MEMORY_OUTPUT_COPY_BIT*/, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 895 | VkFlags inputMask /*= |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 896 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 897 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 898 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 899 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 900 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 901 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 902 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 903 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 904 | VK_MEMORY_INPUT_COPY_BIT*/) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 905 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 906 | VkResult err = VK_SUCCESS; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 907 | |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 908 | if (!m_commandBuffer) |
| 909 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 910 | m_fence.init(*m_device, vk_testing::Fence::create_info()); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 911 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 912 | m_commandBuffer = new VkCommandBufferObj(m_device); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 913 | } |
| 914 | else |
| 915 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 916 | m_device->wait(m_fence); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 919 | // open the command buffer |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 920 | VkCmdBufferBeginInfo cmd_buf_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 921 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 922 | cmd_buf_info.pNext = NULL; |
| 923 | cmd_buf_info.flags = 0; |
| 924 | |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 925 | err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 926 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 927 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 928 | VkBufferMemoryBarrier memory_barrier = |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 929 | buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 930 | VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 931 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 932 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
| 933 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 934 | |
| 935 | // write barrier to the command buffer |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 936 | m_commandBuffer->PipelineBarrier(src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 937 | |
| 938 | // finish recording the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 939 | err = m_commandBuffer->EndCommandBuffer(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 940 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 941 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 942 | // submit the command buffer to the universal queue |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 943 | VkCmdBuffer bufferArray[1]; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 944 | bufferArray[0] = m_commandBuffer->GetBufferHandle(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 945 | err = vkQueueSubmit( m_device->m_queue, 1, bufferArray, m_fence.obj() ); |
| 946 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 949 | VkIndexBufferObj::VkIndexBufferObj(VkDeviceObj *device) |
| 950 | : VkConstantBufferObj(device) |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 951 | { |
| 952 | |
| 953 | } |
| 954 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 955 | void VkIndexBufferObj::CreateAndInitBuffer(int numIndexes, VkIndexType indexType, const void* data) |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 956 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 957 | VkFormat viewFormat; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 958 | |
| 959 | m_numVertices = numIndexes; |
| 960 | m_indexType = indexType; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 961 | switch (indexType) { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 962 | case VK_INDEX_TYPE_UINT16: |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 963 | m_stride = 2; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 964 | viewFormat = VK_FORMAT_R16_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 965 | break; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 966 | case VK_INDEX_TYPE_UINT32: |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 967 | m_stride = 4; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 968 | viewFormat = VK_FORMAT_R32_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 969 | break; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 970 | default: |
| 971 | assert(!"unknown index type"); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 972 | m_stride = 2; |
| 973 | viewFormat = VK_FORMAT_R16_UINT; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 974 | break; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 977 | const size_t allocationSize = numIndexes * m_stride; |
Tony Barbour | 4c97d7a | 2015-04-22 15:10:33 -0600 | [diff] [blame] | 978 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 979 | init(*m_device, allocationSize, reqs); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 980 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 981 | void *pData = map(); |
| 982 | memcpy(pData, data, allocationSize); |
| 983 | unmap(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 984 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 985 | // set up the buffer view for the constant buffer |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 986 | VkBufferViewCreateInfo view_info = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 987 | view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 988 | view_info.buffer = obj(); |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 989 | view_info.viewType = VK_BUFFER_VIEW_TYPE_FORMATTED; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 990 | view_info.format = viewFormat; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 991 | view_info.offset = 0; |
| 992 | view_info.range = allocationSize; |
| 993 | m_bufferView.init(*m_device, view_info); |
| 994 | |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 995 | this->m_descriptorInfo.bufferView = m_bufferView.obj(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 998 | void VkIndexBufferObj::Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset) |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 999 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1000 | vkCmdBindIndexBuffer(cmdBuffer, obj(), offset, m_indexType); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 1001 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1002 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1003 | VkIndexType VkIndexBufferObj::GetIndexType() |
Tony Barbour | af1f919 | 2014-12-17 10:57:58 -0700 | [diff] [blame] | 1004 | { |
| 1005 | return m_indexType; |
| 1006 | } |
| 1007 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1008 | VkPipelineShaderStageCreateInfo* VkShaderObj::GetStageCreateInfo() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1009 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1010 | VkPipelineShaderStageCreateInfo *stageInfo = (VkPipelineShaderStageCreateInfo*) calloc( 1,sizeof(VkPipelineShaderStageCreateInfo) ); |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1011 | stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1012 | stageInfo->stage = m_stage; |
| 1013 | stageInfo->shader = obj(); |
| 1014 | stageInfo->linkConstBufferCount = 0; |
| 1015 | stageInfo->pLinkConstBufferInfo = VK_NULL_HANDLE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1016 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1017 | return stageInfo; |
| 1018 | } |
| 1019 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1020 | VkShaderObj::VkShaderObj(VkDeviceObj *device, const char * shader_code, VkShaderStage stage, VkRenderFramework *framework) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1021 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1022 | VkResult err = VK_SUCCESS; |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 1023 | std::vector<unsigned int> spv; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1024 | VkShaderCreateInfo createInfo; |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1025 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 1026 | vk_testing::ShaderModule module; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1027 | size_t shader_len; |
| 1028 | |
| 1029 | m_stage = stage; |
| 1030 | m_device = device; |
| 1031 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1032 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 1033 | moduleCreateInfo.pNext = NULL; |
| 1034 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1035 | createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1036 | createInfo.pNext = NULL; |
| 1037 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 1038 | if (framework->m_use_glsl) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1039 | |
| 1040 | shader_len = strlen(shader_code); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1041 | moduleCreateInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 1042 | moduleCreateInfo.pCode = malloc(moduleCreateInfo.codeSize); |
| 1043 | moduleCreateInfo.flags = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1044 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1045 | /* try version 0 first: VkShaderStage followed by GLSL */ |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1046 | ((uint32_t *) moduleCreateInfo.pCode)[0] = ICD_SPV_MAGIC; |
| 1047 | ((uint32_t *) moduleCreateInfo.pCode)[1] = 0; |
| 1048 | ((uint32_t *) moduleCreateInfo.pCode)[2] = stage; |
| 1049 | memcpy(((uint32_t *) moduleCreateInfo.pCode + 3), shader_code, shader_len + 1); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1050 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 1051 | } else { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1052 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 1053 | // Use Reference GLSL to SPV compiler |
| 1054 | framework->GLSLtoSPV(stage, shader_code, spv); |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1055 | moduleCreateInfo.pCode = spv.data(); |
| 1056 | moduleCreateInfo.codeSize = spv.size() * sizeof(unsigned int); |
| 1057 | moduleCreateInfo.flags = 0; |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 1058 | } |
Cody Northrop | 475663c | 2015-04-15 11:19:06 -0600 | [diff] [blame] | 1059 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1060 | err = module.init_try(*m_device, moduleCreateInfo); |
| 1061 | assert(VK_SUCCESS == err); |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 1062 | |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1063 | createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 1064 | createInfo.pNext = NULL; |
| 1065 | createInfo.module = module.obj(); |
| 1066 | createInfo.pName = "main"; |
| 1067 | createInfo.flags = 0; |
| 1068 | |
| 1069 | err = init_try(*m_device, createInfo); |
Cody Northrop | 475663c | 2015-04-15 11:19:06 -0600 | [diff] [blame] | 1070 | assert(VK_SUCCESS == err); |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 1071 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1072 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1073 | VkPipelineObj::VkPipelineObj(VkDeviceObj *device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1074 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1075 | m_device = device; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1076 | |
| 1077 | m_vi_state.pNext = VK_NULL_HANDLE; |
| 1078 | m_vi_state.bindingCount = 0; |
| 1079 | m_vi_state.pVertexBindingDescriptions = VK_NULL_HANDLE; |
| 1080 | m_vi_state.attributeCount = 0; |
| 1081 | m_vi_state.pVertexAttributeDescriptions = VK_NULL_HANDLE; |
| 1082 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1083 | m_vertexBufferCount = 0; |
| 1084 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1085 | m_ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO; |
| 1086 | m_ia_state.pNext = VK_NULL_HANDLE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1087 | m_ia_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1088 | m_ia_state.disableVertexReuse = VK_FALSE; |
| 1089 | m_ia_state.primitiveRestartEnable = VK_FALSE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1090 | m_ia_state.primitiveRestartIndex = 0; |
| 1091 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1092 | m_rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1093 | m_rs_state.pNext = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1094 | m_rs_state.depthClipEnable = VK_FALSE; |
| 1095 | m_rs_state.rasterizerDiscardEnable = VK_FALSE; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1096 | m_rs_state.pointOrigin = VK_COORDINATE_ORIGIN_UPPER_LEFT; |
| 1097 | m_rs_state.provokingVertex = VK_PROVOKING_VERTEX_LAST; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1098 | m_rs_state.fillMode = VK_FILL_MODE_SOLID; |
Courtney Goeltzenleuchter | 43fb2c7 | 2015-04-30 17:44:12 -0600 | [diff] [blame] | 1099 | m_rs_state.cullMode = VK_CULL_MODE_BACK; |
| 1100 | m_rs_state.frontFace = VK_FRONT_FACE_CW; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1101 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1102 | memset(&m_cb_state,0,sizeof(m_cb_state)); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1103 | m_cb_state.sType = VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1104 | m_cb_state.pNext = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1105 | m_cb_state.alphaToCoverageEnable = VK_FALSE; |
| 1106 | m_cb_state.logicOp = VK_LOGIC_OP_COPY; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1107 | |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1108 | m_ms_state.pNext = VK_NULL_HANDLE; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1109 | m_ms_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO; |
| 1110 | m_ms_state.multisampleEnable = VK_FALSE; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1111 | m_ms_state.sampleMask = 1; // Do we have to specify MSAA even just to disable it? |
Tony Barbour | dfd533a | 2015-06-26 10:18:34 -0600 | [diff] [blame] | 1112 | m_ms_state.rasterSamples = 1; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1113 | m_ms_state.minSampleShading = 0; |
| 1114 | m_ms_state.sampleShadingEnable = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1115 | |
Tony Barbour | d81b888 | 2015-05-15 09:37:57 -0600 | [diff] [blame] | 1116 | m_vp_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1117 | m_vp_state.pNext = VK_NULL_HANDLE; |
Tony Barbour | d81b888 | 2015-05-15 09:37:57 -0600 | [diff] [blame] | 1118 | m_vp_state.viewportCount = 1; |
| 1119 | m_vp_state.depthMode = VK_DEPTH_MODE_ZERO_TO_ONE; |
| 1120 | m_vp_state.clipOrigin = VK_COORDINATE_ORIGIN_UPPER_LEFT; |
| 1121 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1122 | m_ds_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1123 | m_ds_state.pNext = VK_NULL_HANDLE, |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1124 | m_ds_state.format = VK_FORMAT_D32_SFLOAT; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1125 | m_ds_state.depthTestEnable = VK_FALSE; |
| 1126 | m_ds_state.depthWriteEnable = VK_FALSE; |
| 1127 | m_ds_state.depthBoundsEnable = VK_FALSE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1128 | m_ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1129 | m_ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP; |
| 1130 | m_ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP; |
| 1131 | m_ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1132 | m_ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1133 | m_ds_state.stencilTestEnable = VK_FALSE; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1134 | m_ds_state.front = m_ds_state.back; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1135 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1136 | VkPipelineCbAttachmentState att = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1137 | att.blendEnable = VK_FALSE; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1138 | att.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1139 | att.channelWriteMask = 0xf; |
| 1140 | AddColorAttachment(0, &att); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1141 | |
| 1142 | }; |
| 1143 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1144 | void VkPipelineObj::AddShader(VkShaderObj* shader) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1145 | { |
| 1146 | m_shaderObjs.push_back(shader); |
| 1147 | } |
| 1148 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1149 | void VkPipelineObj::AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1150 | { |
| 1151 | m_vi_state.pVertexAttributeDescriptions = vi_attrib; |
| 1152 | m_vi_state.attributeCount = count; |
| 1153 | } |
| 1154 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1155 | void VkPipelineObj::AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1156 | { |
| 1157 | m_vi_state.pVertexBindingDescriptions = vi_binding; |
| 1158 | m_vi_state.bindingCount = count; |
| 1159 | } |
| 1160 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1161 | void VkPipelineObj::AddVertexDataBuffer(VkConstantBufferObj* vertexDataBuffer, int binding) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1162 | { |
| 1163 | m_vertexBufferObjs.push_back(vertexDataBuffer); |
| 1164 | m_vertexBufferBindings.push_back(binding); |
| 1165 | m_vertexBufferCount++; |
| 1166 | } |
| 1167 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1168 | void VkPipelineObj::AddColorAttachment(uint32_t binding, const VkPipelineCbAttachmentState *att) |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 1169 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1170 | if (binding+1 > m_colorAttachments.size()) |
| 1171 | { |
| 1172 | m_colorAttachments.resize(binding+1); |
| 1173 | } |
| 1174 | m_colorAttachments[binding] = *att; |
| 1175 | } |
| 1176 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1177 | void VkPipelineObj::SetDepthStencil(VkPipelineDsStateCreateInfo *ds_state) |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1178 | { |
| 1179 | m_ds_state.format = ds_state->format; |
| 1180 | m_ds_state.depthTestEnable = ds_state->depthTestEnable; |
| 1181 | m_ds_state.depthWriteEnable = ds_state->depthWriteEnable; |
| 1182 | m_ds_state.depthBoundsEnable = ds_state->depthBoundsEnable; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1183 | m_ds_state.depthCompareOp = ds_state->depthCompareOp; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1184 | m_ds_state.stencilTestEnable = ds_state->stencilTestEnable; |
| 1185 | m_ds_state.back = ds_state->back; |
| 1186 | m_ds_state.front = ds_state->front; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 1189 | VkResult VkPipelineObj::CreateVKPipeline(VkDescriptorSetObj &descriptorSet) |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1190 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1191 | VkGraphicsPipelineCreateInfo info = {}; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1192 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1193 | VkPipelineShaderStageCreateInfo* shaderCreateInfo; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1194 | |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1195 | info.stageCount = m_shaderObjs.size(); |
| 1196 | info.pStages = new VkPipelineShaderStageCreateInfo[info.stageCount]; |
| 1197 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1198 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 1199 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1200 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(); |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1201 | memcpy((void*)&info.pStages[i], shaderCreateInfo, sizeof(VkPipelineShaderStageCreateInfo)); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 1205 | { |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1206 | m_vi_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 1209 | info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1210 | info.pNext = NULL; |
Mark Lobodzinski | 0fadf5f | 2015-04-17 14:11:39 -0500 | [diff] [blame] | 1211 | info.flags = 0; |
| 1212 | info.layout = descriptorSet.GetPipelineLayout(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1213 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1214 | m_cb_state.attachmentCount = m_colorAttachments.size(); |
| 1215 | m_cb_state.pAttachments = &m_colorAttachments[0]; |
| 1216 | |
Mark Lobodzinski | d5732f3 | 2015-06-23 15:11:57 -0600 | [diff] [blame] | 1217 | info.pTessState = NULL; |
| 1218 | info.pVertexInputState = &m_vi_state; |
| 1219 | info.pIaState = &m_ia_state; |
| 1220 | info.pVpState = &m_vp_state; |
| 1221 | info.pRsState = &m_rs_state; |
| 1222 | info.pMsState = &m_ms_state; |
| 1223 | info.pDsState = &m_ds_state; |
| 1224 | info.pCbState = &m_cb_state; |
| 1225 | |
Chris Forbes | 95292b1 | 2015-05-25 11:13:26 +1200 | [diff] [blame] | 1226 | return init_try(*m_device, info); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1227 | } |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1228 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1229 | vector<VkDeviceMemory> VkMemoryRefManager::mem_refs() const |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1230 | { |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1231 | std::vector<VkDeviceMemory> mems; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1232 | if (this->mem_refs_.size()) { |
| 1233 | mems.reserve(this->mem_refs_.size()); |
| 1234 | for (uint32_t i = 0; i < this->mem_refs_.size(); i++) |
| 1235 | mems.push_back(this->mem_refs_[i]); |
| 1236 | } |
| 1237 | |
| 1238 | return mems; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1241 | VkCommandBufferObj::VkCommandBufferObj(VkDeviceObj *device) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1242 | : vk_testing::CmdBuffer(*device, vk_testing::CmdBuffer::create_info(device->graphics_queue_node_index_)) |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1243 | { |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1244 | m_device = device; |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1245 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1246 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1247 | VkCmdBuffer VkCommandBufferObj::GetBufferHandle() |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1248 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1249 | return obj(); |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1250 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1251 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1252 | VkResult VkCommandBufferObj::BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1253 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1254 | begin(pInfo); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1255 | return VK_SUCCESS; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1258 | VkResult VkCommandBufferObj::BeginCommandBuffer() |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1259 | { |
| 1260 | begin(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1261 | return VK_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1264 | VkResult VkCommandBufferObj::EndCommandBuffer() |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1265 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1266 | end(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1267 | return VK_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1270 | void VkCommandBufferObj::PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, bool32_t byRegion, uint32_t memBarrierCount, const void** ppMemBarriers) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1271 | { |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1272 | vkCmdPipelineBarrier(obj(), src_stages, dest_stages, byRegion, memBarrierCount, ppMemBarriers); |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Chris Forbes | f0796e1 | 2015-06-24 14:34:53 +1200 | [diff] [blame] | 1275 | void VkCommandBufferObj::ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color, |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1276 | VkDepthStencilObj *depthStencilObj) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1277 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1278 | uint32_t i; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1279 | const VkFlags output_mask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1280 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1281 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1282 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1283 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1284 | VK_MEMORY_OUTPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1285 | const VkFlags input_mask = 0; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1286 | |
| 1287 | // whatever we want to do, we do it to the whole buffer |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1288 | VkImageSubresourceRange srRange = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1289 | srRange.aspect = VK_IMAGE_ASPECT_COLOR; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1290 | srRange.baseMipLevel = 0; |
Courtney Goeltzenleuchter | 62b2d43 | 2015-06-04 11:35:43 -0600 | [diff] [blame] | 1291 | srRange.mipLevels = VK_LAST_MIP_LEVEL; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1292 | srRange.baseArraySlice = 0; |
Courtney Goeltzenleuchter | 62b2d43 | 2015-06-04 11:35:43 -0600 | [diff] [blame] | 1293 | srRange.arraySize = VK_LAST_ARRAY_SLICE; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1294 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1295 | VkImageMemoryBarrier memory_barrier = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1296 | memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1297 | memory_barrier.outputMask = output_mask; |
| 1298 | memory_barrier.inputMask = input_mask; |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1299 | memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1300 | memory_barrier.subresourceRange = srRange; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1301 | VkImageMemoryBarrier *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1302 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1303 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
| 1304 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1305 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 1306 | for (i = 0; i < m_renderTargets.size(); i++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1307 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1308 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1309 | vkCmdPipelineBarrier( obj(), src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1310 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1311 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1312 | vkCmdClearColorImage(obj(), |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1313 | m_renderTargets[i]->image(), VK_IMAGE_LAYOUT_GENERAL, |
Courtney Goeltzenleuchter | d7a5cff | 2015-04-23 17:49:22 -0600 | [diff] [blame] | 1314 | &clear_color, 1, &srRange ); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1315 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1318 | if (depthStencilObj) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1319 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1320 | VkImageSubresourceRange dsRange = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1321 | dsRange.aspect = VK_IMAGE_ASPECT_DEPTH; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1322 | dsRange.baseMipLevel = 0; |
Courtney Goeltzenleuchter | 62b2d43 | 2015-06-04 11:35:43 -0600 | [diff] [blame] | 1323 | dsRange.mipLevels = VK_LAST_MIP_LEVEL; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1324 | dsRange.baseArraySlice = 0; |
Courtney Goeltzenleuchter | 62b2d43 | 2015-06-04 11:35:43 -0600 | [diff] [blame] | 1325 | dsRange.arraySize = VK_LAST_ARRAY_SLICE; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1326 | |
| 1327 | // prepare the depth buffer for clear |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1328 | |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1329 | memory_barrier.oldLayout = depthStencilObj->BindInfo()->layout; |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1330 | memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1331 | memory_barrier.image = depthStencilObj->obj(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1332 | memory_barrier.subresourceRange = dsRange; |
| 1333 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1334 | vkCmdPipelineBarrier( obj(), src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1335 | |
Chris Forbes | d9be82b | 2015-06-22 17:21:59 +1200 | [diff] [blame] | 1336 | vkCmdClearDepthStencilImage(obj(), |
| 1337 | depthStencilObj->obj(), VK_IMAGE_LAYOUT_GENERAL, |
| 1338 | depth_clear_color, stencil_clear_color, |
| 1339 | 1, &dsRange); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1340 | |
| 1341 | // prepare depth buffer for rendering |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1342 | memory_barrier.image = depthStencilObj->obj(); |
Mark Lobodzinski | 2b3fa3d | 2015-07-01 15:18:26 -0600 | [diff] [blame] | 1343 | memory_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL; |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1344 | memory_barrier.newLayout = depthStencilObj->BindInfo()->layout; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1345 | memory_barrier.subresourceRange = dsRange; |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1346 | vkCmdPipelineBarrier( obj(), src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1350 | void VkCommandBufferObj::PrepareAttachments() |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1351 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1352 | uint32_t i; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1353 | const VkFlags output_mask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1354 | VK_MEMORY_OUTPUT_HOST_WRITE_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1355 | VK_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1356 | VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1357 | VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1358 | VK_MEMORY_OUTPUT_TRANSFER_BIT; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1359 | const VkFlags input_mask = |
Courtney Goeltzenleuchter | f69f8a2 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 1360 | VK_MEMORY_INPUT_HOST_READ_BIT | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1361 | VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1362 | VK_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1363 | VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1364 | VK_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1365 | VK_MEMORY_INPUT_SHADER_READ_BIT | |
| 1366 | VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1367 | VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
Courtney Goeltzenleuchter | b9776ab | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 1368 | VK_MEMORY_INPUT_TRANSFER_BIT; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1369 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1370 | VkImageSubresourceRange srRange = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1371 | srRange.aspect = VK_IMAGE_ASPECT_COLOR; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1372 | srRange.baseMipLevel = 0; |
Courtney Goeltzenleuchter | 62b2d43 | 2015-06-04 11:35:43 -0600 | [diff] [blame] | 1373 | srRange.mipLevels = VK_LAST_MIP_LEVEL; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1374 | srRange.baseArraySlice = 0; |
Courtney Goeltzenleuchter | 62b2d43 | 2015-06-04 11:35:43 -0600 | [diff] [blame] | 1375 | srRange.arraySize = VK_LAST_ARRAY_SLICE; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1376 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1377 | VkImageMemoryBarrier memory_barrier = {}; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1378 | memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1379 | memory_barrier.outputMask = output_mask; |
| 1380 | memory_barrier.inputMask = input_mask; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1381 | memory_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1382 | memory_barrier.subresourceRange = srRange; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1383 | VkImageMemoryBarrier *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1384 | |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1385 | VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
| 1386 | VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1387 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 1388 | for(i=0; i<m_renderTargets.size(); i++) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1389 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1390 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1391 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
Tony Barbour | 0b2cfb2 | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 1392 | vkCmdPipelineBarrier( obj(), src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1393 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1394 | } |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1397 | void VkCommandBufferObj::BeginRenderPass(VkRenderPass renderpass, VkFramebuffer framebuffer) |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1398 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1399 | VkRenderPassBegin rp_begin = { |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1400 | renderpass, |
| 1401 | framebuffer, |
| 1402 | }; |
| 1403 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1404 | vkCmdBeginRenderPass( obj(), &rp_begin); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1405 | } |
| 1406 | |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 1407 | void VkCommandBufferObj::EndRenderPass() |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1408 | { |
Chia-I Wu | 0b50a1c | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 1409 | vkCmdEndRenderPass(obj()); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1410 | } |
| 1411 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1412 | void VkCommandBufferObj::BindStateObject(VkStateBindPoint stateBindPoint, VkDynamicStateObject stateObject) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1413 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1414 | vkCmdBindDynamicStateObject( obj(), stateBindPoint, stateObject); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1417 | void VkCommandBufferObj::AddRenderTarget(VkImageObj *renderTarget) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1418 | { |
| 1419 | m_renderTargets.push_back(renderTarget); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1422 | void VkCommandBufferObj::DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1423 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1424 | vkCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1427 | void VkCommandBufferObj::Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1428 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1429 | vkCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1432 | void VkCommandBufferObj::QueueCommandBuffer() |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1433 | { |
Tony Barbour | 09b7ac3 | 2015-04-08 10:11:29 -0600 | [diff] [blame] | 1434 | QueueCommandBuffer(NULL); |
| 1435 | } |
| 1436 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1437 | void VkCommandBufferObj::QueueCommandBuffer(VkFence fence) |
Tony Barbour | 09b7ac3 | 2015-04-08 10:11:29 -0600 | [diff] [blame] | 1438 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1439 | VkResult err = VK_SUCCESS; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1440 | |
| 1441 | // submit the command buffer to the universal queue |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1442 | err = vkQueueSubmit( m_device->m_queue, 1, &obj(), fence ); |
| 1443 | ASSERT_VK_SUCCESS( err ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1444 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1445 | err = vkQueueWaitIdle( m_device->m_queue ); |
| 1446 | ASSERT_VK_SUCCESS( err ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1447 | |
| 1448 | // Wait for work to finish before cleaning up. |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1449 | vkDeviceWaitIdle(m_device->device()); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1452 | void VkCommandBufferObj::BindPipeline(VkPipelineObj &pipeline) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1453 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1454 | vkCmdBindPipeline( obj(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.obj() ); |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1455 | } |
| 1456 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1457 | void VkCommandBufferObj::BindDescriptorSet(VkDescriptorSetObj &descriptorSet) |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1458 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1459 | VkDescriptorSet set_obj = descriptorSet.GetDescriptorSetHandle(); |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame] | 1460 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1461 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view) |
Mark Lobodzinski | f2093b6 | 2015-06-15 13:21:21 -0600 | [diff] [blame] | 1462 | vkCmdBindDescriptorSets(obj(), VK_PIPELINE_BIND_POINT_GRAPHICS, descriptorSet.GetPipelineLayout(), |
Cody Northrop | d4c1a50 | 2015-04-16 13:41:56 -0600 | [diff] [blame] | 1463 | 0, 1, &set_obj, 0, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1464 | } |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1465 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1466 | void VkCommandBufferObj::BindIndexBuffer(VkIndexBufferObj *indexBuffer, uint32_t offset) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1467 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1468 | vkCmdBindIndexBuffer(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType()); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1469 | } |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1470 | |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1471 | void VkCommandBufferObj::BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1472 | { |
Courtney Goeltzenleuchter | f68ad72 | 2015-04-16 13:38:46 -0600 | [diff] [blame] | 1473 | vkCmdBindVertexBuffers(obj(), binding, 1, &vertexBuffer->obj(), &offset); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1474 | } |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1475 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1476 | VkDepthStencilObj::VkDepthStencilObj() |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1477 | { |
| 1478 | m_initialized = false; |
| 1479 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1480 | bool VkDepthStencilObj::Initialized() |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1481 | { |
| 1482 | return m_initialized; |
| 1483 | } |
| 1484 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1485 | VkDepthStencilBindInfo* VkDepthStencilObj::BindInfo() |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1486 | { |
| 1487 | return &m_depthStencilBindInfo; |
| 1488 | } |
| 1489 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1490 | void VkDepthStencilObj::Init(VkDeviceObj *device, int32_t width, int32_t height) |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1491 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1492 | VkImageCreateInfo image_info; |
| 1493 | VkDepthStencilViewCreateInfo view_info; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1494 | |
| 1495 | m_device = device; |
| 1496 | m_initialized = true; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1497 | m_depth_stencil_fmt = VK_FORMAT_D16_UNORM; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1498 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1499 | image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1500 | image_info.pNext = NULL; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1501 | image_info.imageType = VK_IMAGE_TYPE_2D; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1502 | image_info.format = m_depth_stencil_fmt; |
| 1503 | image_info.extent.width = width; |
| 1504 | image_info.extent.height = height; |
| 1505 | image_info.extent.depth = 1; |
| 1506 | image_info.mipLevels = 1; |
| 1507 | image_info.arraySize = 1; |
| 1508 | image_info.samples = 1; |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1509 | image_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1510 | image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1511 | image_info.flags = 0; |
| 1512 | init(*m_device, image_info); |
| 1513 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1514 | view_info.sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1515 | view_info.pNext = NULL; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1516 | view_info.image = VK_NULL_HANDLE; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1517 | view_info.mipLevel = 0; |
| 1518 | view_info.baseArraySlice = 0; |
| 1519 | view_info.arraySize = 1; |
| 1520 | view_info.flags = 0; |
| 1521 | view_info.image = obj(); |
| 1522 | m_depthStencilView.init(*m_device, view_info); |
| 1523 | |
| 1524 | m_depthStencilBindInfo.view = m_depthStencilView.obj(); |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1525 | m_depthStencilBindInfo.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1526 | } |