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