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