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