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