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