blob: d601b8c0ab9fd048bc8ff218176b00a1b32090fc [file] [log] [blame]
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -06001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan Tests
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -06003 *
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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tony Barbour6a3faf02015-07-23 10:36:18 -060029#include <vk_wsi_swapchain.h>
30#include <vk_wsi_device_swapchain.h>
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060031
Jon Ashburn83a64252015-04-15 11:31:12 -060032#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
Tony Barbour6a3faf02015-07-23 10:36:18 -060033#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 Ashburn83a64252015-04-15 11:31:12 -060038
Tony Barbour6918cd52015-04-09 12:58:51 -060039VkRenderFramework::VkRenderFramework() :
Tony Barbourfe3351b2015-07-28 10:17:20 -060040 m_cmdBuffer(),
Tony Barbourf77fd652015-04-09 11:07:02 -060041 m_renderPass(VK_NULL_HANDLE),
42 m_framebuffer(VK_NULL_HANDLE),
Cody Northrop12365112015-08-17 11:10:49 -060043 m_stateRasterLine( VK_NULL_HANDLE ),
44 m_stateRasterDepthBias( VK_NULL_HANDLE ),
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060045 m_colorBlend( VK_NULL_HANDLE ),
46 m_stateViewport( VK_NULL_HANDLE ),
47 m_stateDepthStencil( VK_NULL_HANDLE ),
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060048 m_width( 256.0 ), // default window width
Courtney Goeltzenleuchter679bbfa2015-03-05 17:26:38 -070049 m_height( 256.0 ), // default window height
Tony Barbourd1c35722015-04-16 15:59:00 -060050 m_render_target_fmt( VK_FORMAT_R8G8B8A8_UNORM ),
51 m_depth_stencil_fmt( VK_FORMAT_UNDEFINED ),
Tony Barbour71bd4b32015-07-21 17:00:26 -060052 m_clear_via_load_op( true ),
Courtney Goeltzenleuchter679bbfa2015-03-05 17:26:38 -070053 m_depth_clear_color( 1.0 ),
Courtney Goeltzenleuchterb6c9aca2015-06-08 16:19:37 -060054 m_stencil_clear_color( 0 ),
55 m_depthStencil( NULL ),
56 m_dbgCreateMsgCallback( VK_NULL_HANDLE ),
57 m_dbgDestroyMsgCallback( VK_NULL_HANDLE ),
58 m_globalMsgCallback( VK_NULL_HANDLE ),
59 m_devMsgCallback( VK_NULL_HANDLE )
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060060{
Tony Barbour1c45ce02015-03-27 17:03:18 -060061
Chia-I Wu08accc62015-07-07 11:50:03 +080062 memset(&m_renderPassBeginInfo, 0, sizeof(m_renderPassBeginInfo));
63 m_renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
64
Courtney Goeltzenleuchter679bbfa2015-03-05 17:26:38 -070065 // clear the back buffer to dark grey
Chris Forbesf0796e12015-06-24 14:34:53 +120066 m_clear_color.f32[0] = 0.25f;
67 m_clear_color.f32[1] = 0.25f;
68 m_clear_color.f32[2] = 0.25f;
69 m_clear_color.f32[3] = 0.0f;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060070}
71
Tony Barbour6918cd52015-04-09 12:58:51 -060072VkRenderFramework::~VkRenderFramework()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060073{
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060074
75}
76
Tony Barbour6918cd52015-04-09 12:58:51 -060077void VkRenderFramework::InitFramework()
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060078{
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060079 std::vector<const char*> instance_layer_names;
80 std::vector<const char*> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060081 std::vector<const char*> instance_extension_names;
82 std::vector<const char*> device_extension_names;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060083 InitFramework(
84 instance_layer_names, device_layer_names,
85 instance_extension_names, device_extension_names);
Tony Barbour3fdff9e2015-04-23 12:55:36 -060086}
87
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060088void VkRenderFramework::InitFramework(
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060089 std::vector<const char *> instance_layer_names,
90 std::vector<const char *> device_layer_names,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060091 std::vector<const char *> instance_extension_names,
92 std::vector<const char *> device_extension_names,
93 PFN_vkDbgMsgCallback dbgFunction,
94 void *userData)
Tony Barbour3fdff9e2015-04-23 12:55:36 -060095{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060096 VkInstanceCreateInfo instInfo = {};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060097 std::vector<VkExtensionProperties> instance_extensions;
98 std::vector<VkExtensionProperties> device_extensions;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060099 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600100
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600101 /* TODO: Verify requested extensions are available */
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600102
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600103 instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600104 instInfo.pNext = NULL;
105 instInfo.pAppInfo = &app_info;
106 instInfo.pAllocCb = NULL;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600107 instInfo.layerCount = instance_layer_names.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600108 instInfo.ppEnabledLayerNames = instance_layer_names.data();
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600109 instInfo.extensionCount = instance_extension_names.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600110 instInfo.ppEnabledExtensionNames = instance_extension_names.data();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600111 err = vkCreateInstance(&instInfo, &this->inst);
112 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600113
Jon Ashburn83a64252015-04-15 11:31:12 -0600114 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL);
115 ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many gpus";
116 ASSERT_VK_SUCCESS(err);
117 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600118 ASSERT_VK_SUCCESS(err);
Jon Ashburnbf843b22014-11-26 11:06:49 -0700119 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Tony Barbour15524c32015-04-29 17:34:29 -0600120 if (dbgFunction) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600121 m_dbgCreateMsgCallback = (PFN_vkDbgCreateMsgCallback) vkGetInstanceProcAddr(this->inst, "vkDbgCreateMsgCallback");
122 ASSERT_NE(m_dbgCreateMsgCallback, (PFN_vkDbgCreateMsgCallback) NULL) << "Did not get function pointer for DbgCreateMsgCallback";
123 if (m_dbgCreateMsgCallback) {
124 err = m_dbgCreateMsgCallback(this->inst,
125 VK_DBG_REPORT_ERROR_BIT | VK_DBG_REPORT_WARN_BIT,
126 dbgFunction,
127 userData,
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600128 &m_globalMsgCallback);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600129 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter7e46b622015-06-08 15:16:04 -0600130
131 m_dbgDestroyMsgCallback = (PFN_vkDbgDestroyMsgCallback) vkGetInstanceProcAddr(this->inst, "vkDbgDestroyMsgCallback");
132 ASSERT_NE(m_dbgDestroyMsgCallback, (PFN_vkDbgDestroyMsgCallback) NULL) << "Did not get function pointer for DbgDestroyMsgCallback";
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600133 }
Tony Barbour15524c32015-04-29 17:34:29 -0600134 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600135
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600136 /* TODO: Verify requested physical device extensions are available */
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600137 m_device = new VkDeviceObj(0, objs[0], device_layer_names, device_extension_names);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600138
139 /* Now register callback on device */
140 if (0) {
141 if (m_dbgCreateMsgCallback) {
142 err = m_dbgCreateMsgCallback(this->inst,
143 VK_DBG_REPORT_ERROR_BIT | VK_DBG_REPORT_WARN_BIT,
144 dbgFunction,
145 userData,
146 &m_devMsgCallback);
147 ASSERT_VK_SUCCESS(err);
148 }
149 }
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600150 m_device->get_device_queue();
Tony Barbour1c45ce02015-03-27 17:03:18 -0600151
Tony Barbour6918cd52015-04-09 12:58:51 -0600152 m_depthStencil = new VkDepthStencilObj();
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600153}
154
Tony Barbour6918cd52015-04-09 12:58:51 -0600155void VkRenderFramework::ShutdownFramework()
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600156{
Tony Barbour67e99152015-07-10 14:10:27 -0600157 if (m_colorBlend) vkDestroyDynamicColorBlendState(device(), m_colorBlend);
158 if (m_stateDepthStencil) vkDestroyDynamicDepthStencilState(device(), m_stateDepthStencil);
Cody Northrop12365112015-08-17 11:10:49 -0600159 if (m_stateRasterLine) vkDestroyDynamicRasterLineState(device(), m_stateRasterLine);
160 if (m_stateRasterDepthBias) vkDestroyDynamicRasterDepthBiasState(device(), m_stateRasterDepthBias);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600161 if (m_cmdBuffer)
162 delete m_cmdBuffer;
Cody Northrope62183e2015-07-09 18:08:05 -0600163 if (m_cmdPool) vkDestroyCommandPool(device(), m_cmdPool);
Tony Barbour67e99152015-07-10 14:10:27 -0600164 if (m_framebuffer) vkDestroyFramebuffer(device(), m_framebuffer);
165 if (m_renderPass) vkDestroyRenderPass(device(), m_renderPass);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600166
Courtney Goeltzenleuchter7e46b622015-06-08 15:16:04 -0600167 if (m_globalMsgCallback) m_dbgDestroyMsgCallback(this->inst, m_globalMsgCallback);
168 if (m_devMsgCallback) m_dbgDestroyMsgCallback(this->inst, m_devMsgCallback);
169
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600170 if (m_stateViewport) {
Tony Barbour67e99152015-07-10 14:10:27 -0600171 vkDestroyDynamicViewportState(device(), m_stateViewport);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600172 }
Tobin Ehlis976fc162015-03-26 08:23:25 -0600173 while (!m_renderTargets.empty()) {
Tony Barbour6a3faf02015-07-23 10:36:18 -0600174 vkDestroyAttachmentView(device(), m_renderTargets.back()->targetView(m_render_target_fmt));
Tony Barbour67e99152015-07-10 14:10:27 -0600175 vkDestroyImage(device(), m_renderTargets.back()->image());
Mike Stroyanb050c682015-04-17 12:36:38 -0600176 vkFreeMemory(device(), m_renderTargets.back()->memory());
Tobin Ehlis976fc162015-03-26 08:23:25 -0600177 m_renderTargets.pop_back();
178 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600179
Tony Barbour1c45ce02015-03-27 17:03:18 -0600180 delete m_depthStencil;
Tony Barbour823e6ca2015-07-27 13:31:04 -0600181 while (!m_shader_modules.empty())
182 {
183 delete m_shader_modules.back();
184 m_shader_modules.pop_back();
185 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600186
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600187 // reset the driver
Chia-I Wub76e0fa2014-12-28 14:27:28 +0800188 delete m_device;
Chris Forbesbe2fae62015-07-07 11:02:22 +1200189 if (this->inst) vkDestroyInstance(this->inst);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600190}
191
Tony Barbour6918cd52015-04-09 12:58:51 -0600192void VkRenderFramework::InitState()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600193{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600194 VkResult err;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600195
Tony Barbour6a3faf02015-07-23 10:36:18 -0600196 // Get the list of VkFormat's that are supported:
Ian Elliott8b139792015-08-07 11:51:12 -0600197 PFN_vkGetSurfaceFormatsWSI fpGetSurfaceFormatsWSI;
198 uint32_t formatCount;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600199 VkSurfaceDescriptionWSI surface_description;
200 surface_description.sType = VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI;
201 surface_description.pNext = NULL;
Ian Elliott8b139792015-08-07 11:51:12 -0600202 GET_DEVICE_PROC_ADDR(device(), GetSurfaceFormatsWSI);
203 err = fpGetSurfaceFormatsWSI(device(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600204 (VkSurfaceDescriptionWSI *) &surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600205 &formatCount, NULL);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600206 ASSERT_VK_SUCCESS(err);
Ian Elliott8b139792015-08-07 11:51:12 -0600207 VkSurfaceFormatWSI *surfFormats =
208 (VkSurfaceFormatWSI *)malloc(formatCount * sizeof(VkSurfaceFormatWSI));
209 err = fpGetSurfaceFormatsWSI(device(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600210 (VkSurfaceDescriptionWSI *) &surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600211 &formatCount, surfFormats);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600212 ASSERT_VK_SUCCESS(err);
213 m_render_target_fmt = surfFormats[0].format;
214 free(surfFormats);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600215
Cody Northrop12365112015-08-17 11:10:49 -0600216 VkDynamicRasterLineStateCreateInfo rasterLine = {};
217 rasterLine.sType = VK_STRUCTURE_TYPE_DYNAMIC_RASTER_LINE_STATE_CREATE_INFO;
218 rasterLine.lineWidth = 1;
219 err = vkCreateDynamicRasterLineState( device(), &rasterLine, &m_stateRasterLine );
220 ASSERT_VK_SUCCESS(err);
Tony Barbourf52346d2015-01-16 14:27:35 -0700221
Cody Northrop12365112015-08-17 11:10:49 -0600222 VkDynamicRasterDepthBiasStateCreateInfo rasterDepthBias = {};
223 rasterDepthBias.sType = VK_STRUCTURE_TYPE_DYNAMIC_RASTER_DEPTH_BIAS_STATE_CREATE_INFO;
224 rasterDepthBias.depthBias = 0.0f;
225 rasterDepthBias.depthBiasClamp = 0.0f;
226 rasterDepthBias.slopeScaledDepthBias = 0.0f;
227 err = vkCreateDynamicRasterDepthBiasState( device(), &rasterDepthBias, &m_stateRasterDepthBias );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600228 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600229
Tony Barbour67e99152015-07-10 14:10:27 -0600230 VkDynamicColorBlendStateCreateInfo blend = {};
231 blend.sType = VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO;
Tony Barbourd81b8882015-05-15 09:37:57 -0600232 blend.blendConst[0] = 1.0f;
233 blend.blendConst[1] = 1.0f;
234 blend.blendConst[2] = 1.0f;
235 blend.blendConst[3] = 1.0f;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600236 err = vkCreateDynamicColorBlendState(device(), &blend, &m_colorBlend);
237 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600238
Tony Barbour67e99152015-07-10 14:10:27 -0600239 VkDynamicDepthStencilStateCreateInfo depthStencil = {};
240 depthStencil.sType = VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO;
Mark Lobodzinski365feea2015-06-12 11:14:17 -0600241 depthStencil.minDepthBounds = 0.f;
242 depthStencil.maxDepthBounds = 1.f;
Tony Barbourf52346d2015-01-16 14:27:35 -0700243 depthStencil.stencilFrontRef = 0;
244 depthStencil.stencilBackRef = 0;
Tony Barbourd81b8882015-05-15 09:37:57 -0600245 depthStencil.stencilReadMask = 0xff;
246 depthStencil.stencilWriteMask = 0xff;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600247
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600248 err = vkCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil );
249 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600250
Cody Northrope62183e2015-07-09 18:08:05 -0600251 VkCmdPoolCreateInfo cmd_pool_info;
252 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO,
253 cmd_pool_info.pNext = NULL,
254 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
255 cmd_pool_info.flags = 0,
256 err = vkCreateCommandPool(device(), &cmd_pool_info, &m_cmdPool);
257 assert(!err);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600258
Tony Barbourfe3351b2015-07-28 10:17:20 -0600259 m_cmdBuffer = new VkCommandBufferObj(m_device, m_cmdPool);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600260}
261
Tony Barbour6918cd52015-04-09 12:58:51 -0600262void VkRenderFramework::InitViewport(float width, float height)
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600263{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600264 VkResult err;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600265
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600266 VkViewport viewport;
Chris Forbesd9be82b2015-06-22 17:21:59 +1200267 VkRect2D scissor;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600268
Tony Barbour67e99152015-07-10 14:10:27 -0600269 VkDynamicViewportStateCreateInfo viewportCreate = {};
270 viewportCreate.sType = VK_STRUCTURE_TYPE_DYNAMIC_VIEWPORT_STATE_CREATE_INFO;
Courtney Goeltzenleuchterbbe3cc52015-02-11 14:13:34 -0700271 viewportCreate.viewportAndScissorCount = 1;
Tony Barbourf52346d2015-01-16 14:27:35 -0700272 viewport.originX = 0;
273 viewport.originY = 0;
274 viewport.width = 1.f * width;
275 viewport.height = 1.f * height;
276 viewport.minDepth = 0.f;
277 viewport.maxDepth = 1.f;
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600278 scissor.extent.width = (int32_t) width;
279 scissor.extent.height = (int32_t) height;
Courtney Goeltzenleuchterbbe3cc52015-02-11 14:13:34 -0700280 scissor.offset.x = 0;
281 scissor.offset.y = 0;
Tony Barbourf52346d2015-01-16 14:27:35 -0700282 viewportCreate.pViewports = &viewport;
Courtney Goeltzenleuchterbbe3cc52015-02-11 14:13:34 -0700283 viewportCreate.pScissors = &scissor;
Tony Barbourf52346d2015-01-16 14:27:35 -0700284
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600285 err = vkCreateDynamicViewportState( device(), &viewportCreate, &m_stateViewport );
286 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600287 m_width = width;
288 m_height = height;
289}
290
Tony Barbour6918cd52015-04-09 12:58:51 -0600291void VkRenderFramework::InitViewport()
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600292{
293 InitViewport(m_width, m_height);
294}
Tony Barbour6918cd52015-04-09 12:58:51 -0600295void VkRenderFramework::InitRenderTarget()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600296{
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700297 InitRenderTarget(1);
298}
299
Tony Barbour6918cd52015-04-09 12:58:51 -0600300void VkRenderFramework::InitRenderTarget(uint32_t targets)
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700301{
Tony Barbour1c45ce02015-03-27 17:03:18 -0600302 InitRenderTarget(targets, NULL);
303}
304
Cody Northrop3cc85e92015-08-04 10:47:08 -0600305void VkRenderFramework::InitRenderTarget(VkAttachmentView *dsBinding)
Tony Barbour1c45ce02015-03-27 17:03:18 -0600306{
307 InitRenderTarget(1, dsBinding);
308}
309
Cody Northrop3cc85e92015-08-04 10:47:08 -0600310void VkRenderFramework::InitRenderTarget(uint32_t targets, VkAttachmentView *dsBinding)
Tony Barbour1c45ce02015-03-27 17:03:18 -0600311{
Chia-I Wu08accc62015-07-07 11:50:03 +0800312 std::vector<VkAttachmentDescription> attachments;
313 std::vector<VkAttachmentReference> color_references;
Cody Northrop3cc85e92015-08-04 10:47:08 -0600314 std::vector<VkAttachmentView> bindings;
Cody Northropd2ad0342015-08-05 11:15:02 -0600315 attachments.reserve(targets + 1); // +1 for dsBinding
Chia-I Wu08accc62015-07-07 11:50:03 +0800316 color_references.reserve(targets);
Cody Northropd2ad0342015-08-05 11:15:02 -0600317 bindings.reserve(targets + 1); // +1 for dsBinding
Tony Barbour1c45ce02015-03-27 17:03:18 -0600318
Chia-I Wu08accc62015-07-07 11:50:03 +0800319 VkAttachmentDescription att = {};
320 att.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION;
321 att.pNext = NULL;
322 att.format = m_render_target_fmt;
323 att.samples = 1;
324 att.loadOp = (m_clear_via_load_op) ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
325 att.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
326 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
327 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
328 att.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
329 att.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Chia-I Wuecebf752014-12-05 10:45:15 +0800330
Chia-I Wu08accc62015-07-07 11:50:03 +0800331 VkAttachmentReference ref = {};
332 ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
333
334 m_renderPassClearValues.clear();
335 VkClearValue clear = {};
336 clear.color = m_clear_color;
337
Cody Northrop3cc85e92015-08-04 10:47:08 -0600338 VkAttachmentView bind = {};
Chia-I Wu08accc62015-07-07 11:50:03 +0800339
340 for (uint32_t i = 0; i < targets; i++) {
341 attachments.push_back(att);
342
343 ref.attachment = i;
344 color_references.push_back(ref);
345
346 m_renderPassClearValues.push_back(clear);
347
Tony Barbour6918cd52015-04-09 12:58:51 -0600348 VkImageObj *img = new VkImageObj(m_device);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600349
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600350 VkFormatProperties props;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600351 VkResult err;
352
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600353 err = vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), m_render_target_fmt, &props);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600354 ASSERT_VK_SUCCESS(err);
355
356 if (props.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600357 img->init((uint32_t)m_width, (uint32_t)m_height, m_render_target_fmt,
Tony Barboure65788f2015-07-21 17:01:42 -0600358 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT,
359 VK_IMAGE_TILING_LINEAR);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600360 }
361 else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600362 img->init((uint32_t)m_width, (uint32_t)m_height, m_render_target_fmt,
Tony Barboure65788f2015-07-21 17:01:42 -0600363 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT,
364 VK_IMAGE_TILING_OPTIMAL);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600365 }
366 else {
367 FAIL() << "Neither Linear nor Optimal allowed for render target";
368 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600369
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600370 m_renderTargets.push_back(img);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600371 bind = img->targetView(m_render_target_fmt);
Chia-I Wu08accc62015-07-07 11:50:03 +0800372 bindings.push_back(bind);
Chia-I Wuecebf752014-12-05 10:45:15 +0800373 }
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600374
Chia-I Wu08accc62015-07-07 11:50:03 +0800375 VkSubpassDescription subpass = {};
376 subpass.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION;
377 subpass.pNext = NULL;
378 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
379 subpass.flags = 0;
380 subpass.inputCount = 0;
Cody Northropa505dda2015-08-04 11:16:41 -0600381 subpass.pInputAttachments = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800382 subpass.colorCount = targets;
Cody Northropa505dda2015-08-04 11:16:41 -0600383 subpass.pColorAttachments = color_references.data();
384 subpass.pResolveAttachments = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800385
386 if (dsBinding) {
387 att.format = m_depth_stencil_fmt;
Tony Barbour71bd4b32015-07-21 17:00:26 -0600388 att.loadOp = (m_clear_via_load_op) ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;;
Chia-I Wu08accc62015-07-07 11:50:03 +0800389 att.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
390 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
391 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
Chia-I Wu08accc62015-07-07 11:50:03 +0800392 attachments.push_back(att);
393
394 clear.ds.depth = m_depth_clear_color;
395 clear.ds.stencil = m_stencil_clear_color;
396 m_renderPassClearValues.push_back(clear);
397
398 bindings.push_back(*dsBinding);
399
400 subpass.depthStencilAttachment.attachment = targets;
Chia-I Wu08accc62015-07-07 11:50:03 +0800401 } else {
402 subpass.depthStencilAttachment.attachment = VK_ATTACHMENT_UNUSED;
403 }
404
405 subpass.preserveCount = 0;
Cody Northropa505dda2015-08-04 11:16:41 -0600406 subpass.pPreserveAttachments = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800407
408 VkRenderPassCreateInfo rp_info = {};
409 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
410 rp_info.attachmentCount = attachments.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600411 rp_info.pAttachments = attachments.data();
Chia-I Wu08accc62015-07-07 11:50:03 +0800412 rp_info.subpassCount = 1;
413 rp_info.pSubpasses = &subpass;
414
415 vkCreateRenderPass(device(), &rp_info, &m_renderPass);
416
417 // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600418 VkFramebufferCreateInfo fb_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600419 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600420 fb_info.pNext = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800421 fb_info.renderPass = m_renderPass;
422 fb_info.attachmentCount = bindings.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600423 fb_info.pAttachments = bindings.data();
Tony Barbourbdf0a312015-04-01 17:10:07 -0600424 fb_info.width = (uint32_t)m_width;
425 fb_info.height = (uint32_t)m_height;
426 fb_info.layers = 1;
427
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 vkCreateFramebuffer(device(), &fb_info, &m_framebuffer);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600429
Chia-I Wu08accc62015-07-07 11:50:03 +0800430 m_renderPassBeginInfo.renderPass = m_renderPass;
431 m_renderPassBeginInfo.framebuffer = m_framebuffer;
Cody Northropd2ad0342015-08-05 11:15:02 -0600432 m_renderPassBeginInfo.renderArea.extent.width = (int32_t) m_width;
433 m_renderPassBeginInfo.renderArea.extent.height = (int32_t) m_height;
Cody Northrop23dd89d2015-08-04 11:51:03 -0600434 m_renderPassBeginInfo.clearValueCount = m_renderPassClearValues.size();
435 m_renderPassBeginInfo.pClearValues = m_renderPassClearValues.data();
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600436}
437
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600438
439
Tony Barbourd1c35722015-04-16 15:59:00 -0600440VkDeviceObj::VkDeviceObj(uint32_t id, VkPhysicalDevice obj) :
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600441 vk_testing::Device(obj), id(id)
Chia-I Wufb1459b2014-12-29 15:23:20 +0800442{
443 init();
444
Chia-I Wu999f0482015-07-03 10:32:05 +0800445 props = phy().properties();
Tony Barbour482c6092015-07-27 09:37:48 -0600446 queue_props = phy().queue_properties().data();
Chia-I Wufb1459b2014-12-29 15:23:20 +0800447}
448
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600449VkDeviceObj::VkDeviceObj(uint32_t id,
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600450 VkPhysicalDevice obj, std::vector<const char *> &layer_names,
451 std::vector<const char *> &extension_names) :
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600452 vk_testing::Device(obj), id(id)
453{
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600454 init(layer_names, extension_names);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600455
Chia-I Wu999f0482015-07-03 10:32:05 +0800456 props = phy().properties();
Tony Barbour482c6092015-07-27 09:37:48 -0600457 queue_props = phy().queue_properties().data();
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600458}
459
Tony Barbour6918cd52015-04-09 12:58:51 -0600460void VkDeviceObj::get_device_queue()
Chia-I Wufb1459b2014-12-29 15:23:20 +0800461{
462 ASSERT_NE(true, graphics_queues().empty());
Chia-I Wudf12ffd2015-07-03 10:53:18 +0800463 m_queue = graphics_queues()[0]->handle();
Chia-I Wufb1459b2014-12-29 15:23:20 +0800464}
465
Tobin Ehlis3ab1f872015-05-27 14:33:27 -0600466VkDescriptorSetObj::VkDescriptorSetObj(VkDeviceObj *device) :
467 m_device(device), m_nextSlot(0)
Tony Barboure2c58df2014-11-25 13:18:32 -0700468{
Tony Barboure2c58df2014-11-25 13:18:32 -0700469
470}
471
Tony Barbour6918cd52015-04-09 12:58:51 -0600472VkDescriptorSetObj::~VkDescriptorSetObj()
Tony Barboure2c58df2014-11-25 13:18:32 -0700473{
Chia-I Wu11078b02015-01-04 16:27:24 +0800474 delete m_set;
Tony Barboure2c58df2014-11-25 13:18:32 -0700475}
Tony Barbour82c39522014-12-04 14:33:33 -0700476
Tony Barbour6918cd52015-04-09 12:58:51 -0600477int VkDescriptorSetObj::AppendDummy()
Tony Barboure2c58df2014-11-25 13:18:32 -0700478{
Chia-I Wu11078b02015-01-04 16:27:24 +0800479 /* request a descriptor but do not update it */
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600480 VkDescriptorTypeCount tc = {};
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600481 tc.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
Chia-I Wu11078b02015-01-04 16:27:24 +0800482 tc.count = 1;
483 m_type_counts.push_back(tc);
Tony Barboure2c58df2014-11-25 13:18:32 -0700484
Chia-I Wu11078b02015-01-04 16:27:24 +0800485 return m_nextSlot++;
Tony Barboure2c58df2014-11-25 13:18:32 -0700486}
Tony Barbour82c39522014-12-04 14:33:33 -0700487
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600488int VkDescriptorSetObj::AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer)
Tony Barboure2c58df2014-11-25 13:18:32 -0700489{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600490 VkDescriptorTypeCount tc = {};
Chia-I Wu11078b02015-01-04 16:27:24 +0800491 tc.type = type;
492 tc.count = 1;
493 m_type_counts.push_back(tc);
Tony Barboure2c58df2014-11-25 13:18:32 -0700494
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800495 m_writes.push_back(vk_testing::Device::write_descriptor_set(vk_testing::DescriptorSet(),
496 m_nextSlot, 0, type, 1, &constantBuffer.m_descriptorInfo));
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600497
Chia-I Wu11078b02015-01-04 16:27:24 +0800498 return m_nextSlot++;
Tony Barboure2c58df2014-11-25 13:18:32 -0700499}
Tony Barbour82c39522014-12-04 14:33:33 -0700500
Tony Barbour6918cd52015-04-09 12:58:51 -0600501int VkDescriptorSetObj::AppendSamplerTexture( VkSamplerObj* sampler, VkTextureObj* texture)
Tony Barboure2c58df2014-11-25 13:18:32 -0700502{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600503 VkDescriptorTypeCount tc = {};
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600504 tc.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu11078b02015-01-04 16:27:24 +0800505 tc.count = 1;
506 m_type_counts.push_back(tc);
Tony Barboure2c58df2014-11-25 13:18:32 -0700507
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800508 VkDescriptorInfo tmp = texture->m_descriptorInfo;
Chia-I Wu8c721c62015-07-03 11:49:42 +0800509 tmp.sampler = sampler->handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800510 m_imageSamplerDescriptors.push_back(tmp);
Tony Barboure2c58df2014-11-25 13:18:32 -0700511
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800512 m_writes.push_back(vk_testing::Device::write_descriptor_set(vk_testing::DescriptorSet(),
513 m_nextSlot, 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, NULL));
Tony Barboure2c58df2014-11-25 13:18:32 -0700514
Chia-I Wu11078b02015-01-04 16:27:24 +0800515 return m_nextSlot++;
Tony Barboure2c58df2014-11-25 13:18:32 -0700516}
Chia-I Wu11078b02015-01-04 16:27:24 +0800517
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500518VkPipelineLayout VkDescriptorSetObj::GetPipelineLayout() const
Tony Barbourb5f4d082014-12-17 10:54:03 -0700519{
Chia-I Wufd46e7d2015-07-03 11:49:42 +0800520 return m_pipeline_layout.handle();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700521}
522
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600523VkDescriptorSet VkDescriptorSetObj::GetDescriptorSetHandle() const
Tony Barbourb5f4d082014-12-17 10:54:03 -0700524{
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800525 return m_set->handle();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700526}
Tony Barboure2c58df2014-11-25 13:18:32 -0700527
Tony Barbour6918cd52015-04-09 12:58:51 -0600528void VkDescriptorSetObj::CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer)
Tony Barbour824b7712014-12-18 17:06:21 -0700529{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600530 // create VkDescriptorPool
531 VkDescriptorPoolCreateInfo pool = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600532 pool.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Chia-I Wu985ba162015-03-26 13:14:16 +0800533 pool.count = m_type_counts.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600534 pool.pTypeCount = m_type_counts.data();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600535 init(*m_device, VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, pool);
Tony Barbour824b7712014-12-18 17:06:21 -0700536
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600537 // create VkDescriptorSetLayout
538 vector<VkDescriptorSetLayoutBinding> bindings;
Chia-I Wub41393e2015-03-26 15:04:41 +0800539 bindings.resize(m_type_counts.size());
Chia-I Wu11078b02015-01-04 16:27:24 +0800540 for (int i = 0; i < m_type_counts.size(); i++) {
Chia-I Wub41393e2015-03-26 15:04:41 +0800541 bindings[i].descriptorType = m_type_counts[i].type;
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800542 bindings[i].arraySize = m_type_counts[i].count;
Tony Barbourd1c35722015-04-16 15:59:00 -0600543 bindings[i].stageFlags = VK_SHADER_STAGE_ALL;
Chia-I Wu0743e832015-03-27 12:56:09 +0800544 bindings[i].pImmutableSamplers = NULL;
Tony Barboure2c58df2014-11-25 13:18:32 -0700545 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800546
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600547 // create VkDescriptorSetLayout
548 VkDescriptorSetLayoutCreateInfo layout = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600549 layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wub41393e2015-03-26 15:04:41 +0800550 layout.count = bindings.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600551 layout.pBinding = bindings.data();
Chia-I Wub41393e2015-03-26 15:04:41 +0800552
Chia-I Wu41126e52015-03-26 15:27:55 +0800553 m_layout.init(*m_device, layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600554 vector<const vk_testing::DescriptorSetLayout *> layouts;
Chia-I Wu41126e52015-03-26 15:27:55 +0800555 layouts.push_back(&m_layout);
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500556
557 // create VkPipelineLayout
558 VkPipelineLayoutCreateInfo pipeline_layout = {};
559 pipeline_layout.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
560 pipeline_layout.descriptorSetCount = layouts.size();
561 pipeline_layout.pSetLayouts = NULL;
562
563 m_pipeline_layout.init(*m_device, pipeline_layout, layouts);
Tony Barboure2c58df2014-11-25 13:18:32 -0700564
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600565 // create VkDescriptorSet
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500566 m_set = alloc_sets(*m_device, VK_DESCRIPTOR_SET_USAGE_STATIC, m_layout);
Chia-I Wu11078b02015-01-04 16:27:24 +0800567
Chia-I Wu41126e52015-03-26 15:27:55 +0800568 // build the update array
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800569 size_t imageSamplerCount = 0;
570 for (std::vector<VkWriteDescriptorSet>::iterator it = m_writes.begin();
571 it != m_writes.end(); it++) {
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800572 it->destSet = m_set->handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800573 if (it->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
574 it->pDescriptors = &m_imageSamplerDescriptors[imageSamplerCount++];
Chia-I Wu11078b02015-01-04 16:27:24 +0800575 }
Chia-I Wu11078b02015-01-04 16:27:24 +0800576
577 // do the updates
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800578 m_device->update_descriptor_sets(m_writes);
Tony Barbour25ef8a62014-12-03 13:59:18 -0700579}
Tony Barboure2c58df2014-11-25 13:18:32 -0700580
Tony Barbour6918cd52015-04-09 12:58:51 -0600581VkImageObj::VkImageObj(VkDeviceObj *dev)
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800582{
583 m_device = dev;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800584 m_descriptorInfo.imageView = VK_NULL_HANDLE;
585 m_descriptorInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800586}
587
Tony Barbour6918cd52015-04-09 12:58:51 -0600588void VkImageObj::ImageMemoryBarrier(
589 VkCommandBufferObj *cmd_buf,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600590 VkImageAspect aspect,
591 VkFlags output_mask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600592 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600593 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
594 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
595 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
596 VK_MEMORY_OUTPUT_COPY_BIT*/,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600597 VkFlags input_mask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600598 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600599 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
600 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
601 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
602 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
603 VK_MEMORY_INPUT_SHADER_READ_BIT |
604 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
605 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
606 VK_MEMORY_INPUT_COPY_BIT*/,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600607 VkImageLayout image_layout)
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600608{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600609 const VkImageSubresourceRange subresourceRange = subresource_range(aspect, 0, 1, 0, 1);
610 VkImageMemoryBarrier barrier;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600611 barrier = image_memory_barrier(output_mask, input_mask, layout(), image_layout,
612 subresourceRange);
613
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600614 VkImageMemoryBarrier *pmemory_barrier = &barrier;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600615
Tony Barbour0b2cfb22015-06-29 16:20:35 -0600616 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
617 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600618
619 // write barrier to the command buffer
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -0600620 vkCmdPipelineBarrier(cmd_buf->handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600621}
622
Tony Barbour6918cd52015-04-09 12:58:51 -0600623void VkImageObj::SetLayout(VkCommandBufferObj *cmd_buf,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600624 VkImageAspect aspect,
625 VkImageLayout image_layout)
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600626{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600627 VkFlags output_mask, input_mask;
628 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600629 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600630 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
631 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
632 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600633 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600634 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600635 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600636 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
637 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
638 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
639 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
640 VK_MEMORY_INPUT_SHADER_READ_BIT |
641 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
642 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600643 VK_MEMORY_INPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600644
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800645 if (image_layout == m_descriptorInfo.imageLayout) {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600646 return;
647 }
648
649 switch (image_layout) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600650 case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL:
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600651 output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT;
652 input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600653 break;
654
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600655 case VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL:
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600656 output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT;
657 input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600658 break;
659
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600660 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600661 output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT;
662 input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600663 break;
664
665 default:
666 output_mask = all_cache_outputs;
667 input_mask = all_cache_inputs;
668 break;
669 }
670
671 ImageMemoryBarrier(cmd_buf, aspect, output_mask, input_mask, image_layout);
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800672 m_descriptorInfo.imageLayout = image_layout;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600673}
674
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600675void VkImageObj::SetLayout(VkImageAspect aspect,
676 VkImageLayout image_layout)
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600677{
Tony Barbourf20f87b2015-04-22 09:02:32 -0600678 VkResult U_ASSERT_ONLY err;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600679
680 if (image_layout == m_descriptorInfo.imageLayout) {
681 return;
682 }
683
Tony Barbourfe3351b2015-07-28 10:17:20 -0600684 VkCmdPoolCreateInfo cmd_pool_info = {};
685 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
686 cmd_pool_info.pNext = NULL;
687 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
688 cmd_pool_info.flags = 0;
689 vk_testing::CmdPool pool(*m_device, cmd_pool_info);
690 VkCommandBufferObj cmd_buf(m_device, pool.handle());
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600691
692 /* Build command buffer to set image layout in the driver */
693 err = cmd_buf.BeginCommandBuffer();
694 assert(!err);
695
696 SetLayout(&cmd_buf, aspect, image_layout);
697
698 err = cmd_buf.EndCommandBuffer();
699 assert(!err);
700
701 cmd_buf.QueueCommandBuffer();
702}
703
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600704bool VkImageObj::IsCompatible(VkFlags usage, VkFlags features)
Tony Barbour579f7802015-04-03 15:11:43 -0600705{
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600706 if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) &&
Tony Barbourd1c35722015-04-16 15:59:00 -0600707 !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
Tony Barbour579f7802015-04-03 15:11:43 -0600708 return false;
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600709
Tony Barbour579f7802015-04-03 15:11:43 -0600710 return true;
711}
712
Tony Barbour6918cd52015-04-09 12:58:51 -0600713void VkImageObj::init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600714 VkFormat fmt, VkFlags usage,
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600715 VkImageTiling requested_tiling,
716 VkMemoryPropertyFlags reqs)
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800717{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600718 uint32_t mipCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600719 VkFormatProperties image_fmt;
720 VkImageTiling tiling;
721 VkResult err;
Tony Barbour579f7802015-04-03 15:11:43 -0600722
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800723 mipCount = 0;
724
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600725 uint32_t _w = w;
726 uint32_t _h = h;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800727 while( ( _w > 0 ) || ( _h > 0 ) )
728 {
729 _w >>= 1;
730 _h >>= 1;
731 mipCount++;
732 }
733
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600734 err = vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), fmt, &image_fmt);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600735 ASSERT_VK_SUCCESS(err);
Tony Barbour579f7802015-04-03 15:11:43 -0600736
Tony Barbourd1c35722015-04-16 15:59:00 -0600737 if (requested_tiling == VK_IMAGE_TILING_LINEAR) {
Tony Barbour579f7802015-04-03 15:11:43 -0600738 if (IsCompatible(usage, image_fmt.linearTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600739 tiling = VK_IMAGE_TILING_LINEAR;
Tony Barbour579f7802015-04-03 15:11:43 -0600740 } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600741 tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbour579f7802015-04-03 15:11:43 -0600742 } else {
743 ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration";
744 }
745 } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600746 tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbour579f7802015-04-03 15:11:43 -0600747 } else if (IsCompatible(usage, image_fmt.linearTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600748 tiling = VK_IMAGE_TILING_LINEAR;
Tony Barbour579f7802015-04-03 15:11:43 -0600749 } else {
750 ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration";
751 }
752
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600753 VkImageCreateInfo imageCreateInfo = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -0600754 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800755 imageCreateInfo.format = fmt;
756 imageCreateInfo.extent.width = w;
757 imageCreateInfo.extent.height = h;
758 imageCreateInfo.mipLevels = mipCount;
759 imageCreateInfo.tiling = tiling;
760
761 imageCreateInfo.usage = usage;
762
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600763 vk_testing::Image::init(*m_device, imageCreateInfo, reqs);
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800764
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600765 if (usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600766 SetLayout(VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600767 } else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600768 SetLayout(VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_GENERAL);
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600769 }
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800770}
771
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600772VkResult VkImageObj::CopyImage(VkImageObj &src_image)
Tony Barbour5dc515d2015-04-01 17:47:06 -0600773{
Tony Barbourf20f87b2015-04-22 09:02:32 -0600774 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600775 VkImageLayout src_image_layout, dest_image_layout;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600776
Tony Barbourfe3351b2015-07-28 10:17:20 -0600777 VkCmdPoolCreateInfo cmd_pool_info = {};
778 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
779 cmd_pool_info.pNext = NULL;
780 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
781 cmd_pool_info.flags = 0;
782 vk_testing::CmdPool pool(*m_device, cmd_pool_info);
783 VkCommandBufferObj cmd_buf(m_device, pool.handle());
784
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600785 /* Build command buffer to copy staging texture to usable texture */
786 err = cmd_buf.BeginCommandBuffer();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600787 assert(!err);
788
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600789 /* TODO: Can we determine image aspect from image object? */
790 src_image_layout = src_image.layout();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600791 src_image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL);
Tony Barbour5dc515d2015-04-01 17:47:06 -0600792
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600793 dest_image_layout = this->layout();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600794 this->SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600795
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600796 VkImageCopy copy_region = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600797 copy_region.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600798 copy_region.srcSubresource.arraySlice = 0;
799 copy_region.srcSubresource.mipLevel = 0;
800 copy_region.srcOffset.x = 0;
801 copy_region.srcOffset.y = 0;
802 copy_region.srcOffset.z = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600803 copy_region.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600804 copy_region.destSubresource.arraySlice = 0;
805 copy_region.destSubresource.mipLevel = 0;
806 copy_region.destOffset.x = 0;
807 copy_region.destOffset.y = 0;
808 copy_region.destOffset.z = 0;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600809 copy_region.extent = src_image.extent();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600810
Chia-I Wube2b9172015-07-03 11:49:42 +0800811 vkCmdCopyImage(cmd_buf.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800812 src_image.handle(), src_image.layout(),
813 handle(), layout(),
Tony Barbour1c45ce02015-03-27 17:03:18 -0600814 1, &copy_region);
Tony Barbour5dc515d2015-04-01 17:47:06 -0600815
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600816 src_image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, src_image_layout);
Tony Barbour5dc515d2015-04-01 17:47:06 -0600817
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600818 this->SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, dest_image_layout);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600819
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600820 err = cmd_buf.EndCommandBuffer();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600821 assert(!err);
822
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600823 cmd_buf.QueueCommandBuffer();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600824
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600825 return VK_SUCCESS;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600826}
827
Tony Barbour6918cd52015-04-09 12:58:51 -0600828VkTextureObj::VkTextureObj(VkDeviceObj *device, uint32_t *colors)
829 :VkImageObj(device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700830{
831 m_device = device;
Tony Barbourd1c35722015-04-16 15:59:00 -0600832 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tony Barbourebc093f2015-04-01 16:38:10 -0600833 uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
Tony Barbour5dc515d2015-04-01 17:47:06 -0600834 void *data;
835 int32_t x, y;
Tony Barbour6918cd52015-04-09 12:58:51 -0600836 VkImageObj stagingImage(device);
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600837 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600838
Tony Barboure65788f2015-07-21 17:01:42 -0600839 stagingImage.init(16, 16, tex_format, VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT | VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, VK_IMAGE_TILING_LINEAR, reqs);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600840 VkSubresourceLayout layout = stagingImage.subresource_layout(subresource(VK_IMAGE_ASPECT_COLOR, 0, 0));
Tony Barbourebc093f2015-04-01 16:38:10 -0600841
842 if (colors == NULL)
843 colors = tex_colors;
Tony Barboure2c58df2014-11-25 13:18:32 -0700844
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800845 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700846
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600847 VkImageViewCreateInfo view = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600848 view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600849 view.pNext = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600850 view.image = VK_NULL_HANDLE;
Tony Barbourd1c35722015-04-16 15:59:00 -0600851 view.viewType = VK_IMAGE_VIEW_TYPE_2D;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600852 view.format = tex_format;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600853 view.channels.r = VK_CHANNEL_SWIZZLE_R;
854 view.channels.g = VK_CHANNEL_SWIZZLE_G;
855 view.channels.b = VK_CHANNEL_SWIZZLE_B;
856 view.channels.a = VK_CHANNEL_SWIZZLE_A;
857 view.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600858 view.subresourceRange.baseMipLevel = 0;
859 view.subresourceRange.mipLevels = 1;
860 view.subresourceRange.baseArraySlice = 0;
861 view.subresourceRange.arraySize = 1;
Tony Barboure2c58df2014-11-25 13:18:32 -0700862
Tony Barboure2c58df2014-11-25 13:18:32 -0700863 /* create image */
Tony Barboure65788f2015-07-21 17:01:42 -0600864 init(16, 16, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, VK_IMAGE_TILING_OPTIMAL);
Tony Barboure2c58df2014-11-25 13:18:32 -0700865
866 /* create image view */
Chia-I Wu681d7a02015-07-03 13:44:34 +0800867 view.image = handle();
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800868 m_textureView.init(*m_device, view);
Chia-I Wu3158bf32015-07-03 11:49:42 +0800869 m_descriptorInfo.imageView = m_textureView.handle();
Tony Barboure2c58df2014-11-25 13:18:32 -0700870
Chia-I Wu681d7a02015-07-03 13:44:34 +0800871 data = stagingImage.MapMemory();
Tony Barboure2c58df2014-11-25 13:18:32 -0700872
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800873 for (y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700874 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800875 for (x = 0; x < extent().width; x++)
Tony Barbourebc093f2015-04-01 16:38:10 -0600876 row[x] = colors[(x & 1) ^ (y & 1)];
Tony Barboure2c58df2014-11-25 13:18:32 -0700877 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800878 stagingImage.UnmapMemory();
Tony Barbour6918cd52015-04-09 12:58:51 -0600879 VkImageObj::CopyImage(stagingImage);
Tony Barboure2c58df2014-11-25 13:18:32 -0700880}
Tony Barbour82c39522014-12-04 14:33:33 -0700881
Tony Barbour6918cd52015-04-09 12:58:51 -0600882VkSamplerObj::VkSamplerObj(VkDeviceObj *device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700883{
Tony Barboure2c58df2014-11-25 13:18:32 -0700884 m_device = device;
Tony Barboure2c58df2014-11-25 13:18:32 -0700885
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600886 VkSamplerCreateInfo samplerCreateInfo;
Chia-I Wue9864b52014-12-28 16:32:24 +0800887 memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600888 samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
889 samplerCreateInfo.magFilter = VK_TEX_FILTER_NEAREST;
890 samplerCreateInfo.minFilter = VK_TEX_FILTER_NEAREST;
Tony Barbourd1c35722015-04-16 15:59:00 -0600891 samplerCreateInfo.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600892 samplerCreateInfo.addressU = VK_TEX_ADDRESS_WRAP;
893 samplerCreateInfo.addressV = VK_TEX_ADDRESS_WRAP;
894 samplerCreateInfo.addressW = VK_TEX_ADDRESS_WRAP;
Chia-I Wue9864b52014-12-28 16:32:24 +0800895 samplerCreateInfo.mipLodBias = 0.0;
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600896 samplerCreateInfo.maxAnisotropy = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600897 samplerCreateInfo.compareOp = VK_COMPARE_OP_NEVER;
Chia-I Wue9864b52014-12-28 16:32:24 +0800898 samplerCreateInfo.minLod = 0.0;
899 samplerCreateInfo.maxLod = 0.0;
Tony Barbour26b17f82015-06-25 16:56:44 -0600900 samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northropab1f9e22015-08-11 15:50:55 -0600901 samplerCreateInfo.texelCoords = VK_FALSE;
Tony Barboure2c58df2014-11-25 13:18:32 -0700902
Chia-I Wue9864b52014-12-28 16:32:24 +0800903 init(*m_device, samplerCreateInfo);
Tony Barbourf325bf12014-12-03 15:59:38 -0700904}
Tony Barboure2c58df2014-11-25 13:18:32 -0700905
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700906/*
907 * Basic ConstantBuffer constructor. Then use create methods to fill in the details.
908 */
Tony Barbour6918cd52015-04-09 12:58:51 -0600909VkConstantBufferObj::VkConstantBufferObj(VkDeviceObj *device)
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700910{
911 m_device = device;
Tony Barbour38422802014-12-10 14:36:31 -0700912 m_commandBuffer = 0;
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700913
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800914 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700915}
916
Tony Barbour6918cd52015-04-09 12:58:51 -0600917VkConstantBufferObj::~VkConstantBufferObj()
Tony Barbour044703b2015-03-26 12:37:52 -0600918{
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600919 // TODO: Should we call QueueRemoveMemReference for the constant buffer memory here?
Tony Barbour044703b2015-03-26 12:37:52 -0600920 if (m_commandBuffer) {
921 delete m_commandBuffer;
Tony Barbour3d83f492015-07-28 10:23:02 -0600922 delete m_cmdPool;
Tony Barbour044703b2015-03-26 12:37:52 -0600923 }
924}
925
Tony Barbour6918cd52015-04-09 12:58:51 -0600926VkConstantBufferObj::VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data)
Tony Barboure2c58df2014-11-25 13:18:32 -0700927{
Tony Barboure2c58df2014-11-25 13:18:32 -0700928 m_device = device;
Chia-I Wua07fee62014-12-28 15:26:08 +0800929 m_commandBuffer = 0;
930
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800931 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700932 m_numVertices = constantCount;
933 m_stride = constantSize;
934
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600935 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wua07fee62014-12-28 15:26:08 +0800936 const size_t allocationSize = constantCount * constantSize;
Cody Northrop7fb43862015-06-22 14:56:14 -0600937 init_as_src_and_dst(*m_device, allocationSize, reqs);
Tony Barboure2c58df2014-11-25 13:18:32 -0700938
Chia-I Wu681d7a02015-07-03 13:44:34 +0800939 void *pData = memory().map();
Chia-I Wua07fee62014-12-28 15:26:08 +0800940 memcpy(pData, data, allocationSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800941 memory().unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700942
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800943 // set up the buffer view for the constant buffer
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600944 VkBufferViewCreateInfo view_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600945 view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800946 view_info.buffer = handle();
Tony Barbourd1c35722015-04-16 15:59:00 -0600947 view_info.viewType = VK_BUFFER_VIEW_TYPE_RAW;
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800948 view_info.offset = 0;
949 view_info.range = allocationSize;
950 m_bufferView.init(*m_device, view_info);
951
Chia-I Wu3158bf32015-07-03 11:49:42 +0800952 this->m_descriptorInfo.bufferView = m_bufferView.handle();
Tony Barboure2c58df2014-11-25 13:18:32 -0700953}
Tony Barbour82c39522014-12-04 14:33:33 -0700954
Tony Barbourd1c35722015-04-16 15:59:00 -0600955void VkConstantBufferObj::Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding)
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700956{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800957 vkCmdBindVertexBuffers(cmdBuffer, binding, 1, &handle(), &offset);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700958}
959
960
Tony Barbour6918cd52015-04-09 12:58:51 -0600961void VkConstantBufferObj::BufferMemoryBarrier(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600962 VkFlags outputMask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600963 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600964 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
965 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
966 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
967 VK_MEMORY_OUTPUT_COPY_BIT*/,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600968 VkFlags inputMask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600969 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600970 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
971 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
972 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
973 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
974 VK_MEMORY_INPUT_SHADER_READ_BIT |
975 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
976 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
977 VK_MEMORY_INPUT_COPY_BIT*/)
Tony Barboure2c58df2014-11-25 13:18:32 -0700978{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600979 VkResult err = VK_SUCCESS;
Tony Barbour38422802014-12-10 14:36:31 -0700980
Tony Barbour38422802014-12-10 14:36:31 -0700981 if (!m_commandBuffer)
982 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600983 m_fence.init(*m_device, vk_testing::Fence::create_info());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600984 VkCmdPoolCreateInfo cmd_pool_info = {};
985 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
986 cmd_pool_info.pNext = NULL;
987 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
988 cmd_pool_info.flags = 0;
989 m_cmdPool = new vk_testing::CmdPool(*m_device, cmd_pool_info);
990 m_commandBuffer = new VkCommandBufferObj(m_device, m_cmdPool->handle());
Tony Barbour38422802014-12-10 14:36:31 -0700991 }
992 else
993 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800994 m_device->wait(m_fence);
Tony Barbour38422802014-12-10 14:36:31 -0700995 }
996
Tony Barboure2c58df2014-11-25 13:18:32 -0700997 // open the command buffer
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600998 VkCmdBufferBeginInfo cmd_buf_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600999 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Tony Barbourbdf0a312015-04-01 17:10:07 -06001000 cmd_buf_info.pNext = NULL;
1001 cmd_buf_info.flags = 0;
Cody Northropcc09b9e2015-08-11 11:35:58 -06001002 cmd_buf_info.renderPass = VK_NULL_HANDLE;
1003 cmd_buf_info.subpass = 0;
1004 cmd_buf_info.framebuffer = VK_NULL_HANDLE;
Tony Barbourbdf0a312015-04-01 17:10:07 -06001005
Jon Ashburnc4164b12014-12-31 17:10:47 -07001006 err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001007 ASSERT_VK_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -07001008
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001009 VkBufferMemoryBarrier memory_barrier =
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001010 buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001011 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Tony Barboure2c58df2014-11-25 13:18:32 -07001012
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001013 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1014 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001015
1016 // write barrier to the command buffer
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001017 m_commandBuffer->PipelineBarrier(src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier);
Tony Barboure2c58df2014-11-25 13:18:32 -07001018
1019 // finish recording the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -07001020 err = m_commandBuffer->EndCommandBuffer();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001021 ASSERT_VK_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -07001022
Tony Barboure2c58df2014-11-25 13:18:32 -07001023 // submit the command buffer to the universal queue
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001024 VkCmdBuffer bufferArray[1];
Tony Barbour471338d2014-12-10 17:28:39 -07001025 bufferArray[0] = m_commandBuffer->GetBufferHandle();
Chia-I Wud9e8e822015-07-03 11:45:55 +08001026 err = vkQueueSubmit( m_device->m_queue, 1, bufferArray, m_fence.handle() );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001027 ASSERT_VK_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -07001028}
1029
Tony Barbour6918cd52015-04-09 12:58:51 -06001030VkIndexBufferObj::VkIndexBufferObj(VkDeviceObj *device)
1031 : VkConstantBufferObj(device)
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001032{
1033
1034}
1035
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001036void VkIndexBufferObj::CreateAndInitBuffer(int numIndexes, VkIndexType indexType, const void* data)
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001037{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001038 VkFormat viewFormat;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001039
1040 m_numVertices = numIndexes;
1041 m_indexType = indexType;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001042 switch (indexType) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001043 case VK_INDEX_TYPE_UINT16:
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001044 m_stride = 2;
Tony Barbourd1c35722015-04-16 15:59:00 -06001045 viewFormat = VK_FORMAT_R16_UINT;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001046 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001047 case VK_INDEX_TYPE_UINT32:
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001048 m_stride = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001049 viewFormat = VK_FORMAT_R32_UINT;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001050 break;
Chia-I Wub4c2aa42014-12-15 23:50:11 +08001051 default:
1052 assert(!"unknown index type");
Tony Barbourf20f87b2015-04-22 09:02:32 -06001053 m_stride = 2;
1054 viewFormat = VK_FORMAT_R16_UINT;
Chia-I Wub4c2aa42014-12-15 23:50:11 +08001055 break;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001056 }
1057
Chia-I Wua07fee62014-12-28 15:26:08 +08001058 const size_t allocationSize = numIndexes * m_stride;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001059 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -06001060 init_as_src_and_dst(*m_device, allocationSize, reqs);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001061
Chia-I Wu681d7a02015-07-03 13:44:34 +08001062 void *pData = memory().map();
Chia-I Wua07fee62014-12-28 15:26:08 +08001063 memcpy(pData, data, allocationSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +08001064 memory().unmap();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001065
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001066 // set up the buffer view for the constant buffer
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001067 VkBufferViewCreateInfo view_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001068 view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
Chia-I Wu681d7a02015-07-03 13:44:34 +08001069 view_info.buffer = handle();
Tony Barbourd1c35722015-04-16 15:59:00 -06001070 view_info.viewType = VK_BUFFER_VIEW_TYPE_FORMATTED;
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001071 view_info.format = viewFormat;
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001072 view_info.offset = 0;
1073 view_info.range = allocationSize;
1074 m_bufferView.init(*m_device, view_info);
1075
Chia-I Wu3158bf32015-07-03 11:49:42 +08001076 this->m_descriptorInfo.bufferView = m_bufferView.handle();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001077}
1078
Tony Barbourd1c35722015-04-16 15:59:00 -06001079void VkIndexBufferObj::Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset)
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001080{
Chia-I Wu681d7a02015-07-03 13:44:34 +08001081 vkCmdBindIndexBuffer(cmdBuffer, handle(), offset, m_indexType);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001082}
Tony Barboure2c58df2014-11-25 13:18:32 -07001083
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001084VkIndexType VkIndexBufferObj::GetIndexType()
Tony Barbouraf1f9192014-12-17 10:57:58 -07001085{
1086 return m_indexType;
1087}
1088
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001089VkPipelineShaderStageCreateInfo* VkShaderObj::GetStageCreateInfo()
Tony Barboure2c58df2014-11-25 13:18:32 -07001090{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001091 VkPipelineShaderStageCreateInfo *stageInfo = (VkPipelineShaderStageCreateInfo*) calloc( 1,sizeof(VkPipelineShaderStageCreateInfo) );
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001092 stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1093 stageInfo->stage = m_stage;
Chia-I Wu4d0c7922015-07-03 11:49:42 +08001094 stageInfo->shader = handle();
Tony Barboure2c58df2014-11-25 13:18:32 -07001095
Tony Barboure2c58df2014-11-25 13:18:32 -07001096 return stageInfo;
1097}
1098
Tony Barbourd1c35722015-04-16 15:59:00 -06001099VkShaderObj::VkShaderObj(VkDeviceObj *device, const char * shader_code, VkShaderStage stage, VkRenderFramework *framework)
Tony Barboure2c58df2014-11-25 13:18:32 -07001100{
Tony Barbourb5d2c942015-07-14 13:34:05 -06001101 VkResult U_ASSERT_ONLY err = VK_SUCCESS;
Cody Northrop3bfd27c2015-03-17 15:55:58 -06001102 std::vector<unsigned int> spv;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001103 VkShaderCreateInfo createInfo;
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001104 VkShaderModuleCreateInfo moduleCreateInfo;
Tony Barbour823e6ca2015-07-27 13:31:04 -06001105 vk_testing::ShaderModule *module = new vk_testing::ShaderModule();
Tony Barboure2c58df2014-11-25 13:18:32 -07001106 size_t shader_len;
1107
1108 m_stage = stage;
1109 m_device = device;
1110
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001111 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
1112 moduleCreateInfo.pNext = NULL;
1113
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001114 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Tony Barboure2c58df2014-11-25 13:18:32 -07001115 createInfo.pNext = NULL;
1116
Cody Northrop50a2a4b2015-06-03 16:49:20 -06001117 if (framework->m_use_glsl) {
Tony Barboure2c58df2014-11-25 13:18:32 -07001118
1119 shader_len = strlen(shader_code);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001120 moduleCreateInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
1121 moduleCreateInfo.pCode = malloc(moduleCreateInfo.codeSize);
1122 moduleCreateInfo.flags = 0;
Tony Barboure2c58df2014-11-25 13:18:32 -07001123
Tony Barbourd1c35722015-04-16 15:59:00 -06001124 /* try version 0 first: VkShaderStage followed by GLSL */
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001125 ((uint32_t *) moduleCreateInfo.pCode)[0] = ICD_SPV_MAGIC;
1126 ((uint32_t *) moduleCreateInfo.pCode)[1] = 0;
1127 ((uint32_t *) moduleCreateInfo.pCode)[2] = stage;
1128 memcpy(((uint32_t *) moduleCreateInfo.pCode + 3), shader_code, shader_len + 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001129
Cody Northrop50a2a4b2015-06-03 16:49:20 -06001130 } else {
Tony Barboure2c58df2014-11-25 13:18:32 -07001131
Cody Northrop3bfd27c2015-03-17 15:55:58 -06001132 // Use Reference GLSL to SPV compiler
1133 framework->GLSLtoSPV(stage, shader_code, spv);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001134 moduleCreateInfo.pCode = spv.data();
1135 moduleCreateInfo.codeSize = spv.size() * sizeof(unsigned int);
1136 moduleCreateInfo.flags = 0;
Chia-I Wubabc0fd2014-12-29 14:14:03 +08001137 }
Cody Northrop475663c2015-04-15 11:19:06 -06001138
Tony Barbour823e6ca2015-07-27 13:31:04 -06001139 err = module->init_try(*m_device, moduleCreateInfo);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001140 assert(VK_SUCCESS == err);
Cody Northrop50a2a4b2015-06-03 16:49:20 -06001141
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001142 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
1143 createInfo.pNext = NULL;
Tony Barbour823e6ca2015-07-27 13:31:04 -06001144 createInfo.module = module->handle();
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001145 createInfo.pName = "main";
1146 createInfo.flags = 0;
1147
1148 err = init_try(*m_device, createInfo);
Cody Northrop475663c2015-04-15 11:19:06 -06001149 assert(VK_SUCCESS == err);
Tony Barbour823e6ca2015-07-27 13:31:04 -06001150 framework->m_shader_modules.push_back(module);
Tony Barbourf325bf12014-12-03 15:59:38 -07001151}
Tony Barbour82c39522014-12-04 14:33:33 -07001152
Tony Barbour6918cd52015-04-09 12:58:51 -06001153VkPipelineObj::VkPipelineObj(VkDeviceObj *device)
Tony Barboure2c58df2014-11-25 13:18:32 -07001154{
Tony Barboure2c58df2014-11-25 13:18:32 -07001155 m_device = device;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001156
1157 m_vi_state.pNext = VK_NULL_HANDLE;
1158 m_vi_state.bindingCount = 0;
1159 m_vi_state.pVertexBindingDescriptions = VK_NULL_HANDLE;
1160 m_vi_state.attributeCount = 0;
1161 m_vi_state.pVertexAttributeDescriptions = VK_NULL_HANDLE;
1162
Tony Barboure2c58df2014-11-25 13:18:32 -07001163 m_vertexBufferCount = 0;
1164
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001165 m_ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001166 m_ia_state.pNext = VK_NULL_HANDLE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001167 m_ia_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001168 m_ia_state.primitiveRestartEnable = VK_FALSE;
Tony Barboure2c58df2014-11-25 13:18:32 -07001169
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001170 m_rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001171 m_rs_state.pNext = VK_NULL_HANDLE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001172 m_rs_state.depthClipEnable = VK_FALSE;
1173 m_rs_state.rasterizerDiscardEnable = VK_FALSE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001174 m_rs_state.fillMode = VK_FILL_MODE_SOLID;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001175 m_rs_state.cullMode = VK_CULL_MODE_BACK;
1176 m_rs_state.frontFace = VK_FRONT_FACE_CW;
Cody Northrop12365112015-08-17 11:10:49 -06001177 m_rs_state.depthBiasEnable = VK_FALSE;
Tony Barboure2c58df2014-11-25 13:18:32 -07001178
Tony Barboure2c58df2014-11-25 13:18:32 -07001179 memset(&m_cb_state,0,sizeof(m_cb_state));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001180 m_cb_state.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001181 m_cb_state.pNext = VK_NULL_HANDLE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001182 m_cb_state.alphaToCoverageEnable = VK_FALSE;
1183 m_cb_state.logicOp = VK_LOGIC_OP_COPY;
Tony Barboure2c58df2014-11-25 13:18:32 -07001184
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001185 m_ms_state.pNext = VK_NULL_HANDLE;
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001186 m_ms_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Cody Northrop02e61ed2015-08-04 14:34:54 -06001187 m_ms_state.pSampleMask = NULL;
Tony Barbourdfd533a2015-06-26 10:18:34 -06001188 m_ms_state.rasterSamples = 1;
Tony Barbourf52346d2015-01-16 14:27:35 -07001189 m_ms_state.minSampleShading = 0;
1190 m_ms_state.sampleShadingEnable = 0;
Tony Barboure2c58df2014-11-25 13:18:32 -07001191
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001192 m_vp_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001193 m_vp_state.pNext = VK_NULL_HANDLE;
Tony Barbourd81b8882015-05-15 09:37:57 -06001194 m_vp_state.viewportCount = 1;
Tony Barbourd81b8882015-05-15 09:37:57 -06001195
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001196 m_ds_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001197 m_ds_state.pNext = VK_NULL_HANDLE,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001198 m_ds_state.depthTestEnable = VK_FALSE;
1199 m_ds_state.depthWriteEnable = VK_FALSE;
1200 m_ds_state.depthBoundsEnable = VK_FALSE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001201 m_ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001202 m_ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1203 m_ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1204 m_ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001205 m_ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001206 m_ds_state.stencilTestEnable = VK_FALSE;
Tony Barbourf52346d2015-01-16 14:27:35 -07001207 m_ds_state.front = m_ds_state.back;
Tony Barboure2c58df2014-11-25 13:18:32 -07001208};
1209
Tony Barbour6918cd52015-04-09 12:58:51 -06001210void VkPipelineObj::AddShader(VkShaderObj* shader)
Tony Barboure2c58df2014-11-25 13:18:32 -07001211{
1212 m_shaderObjs.push_back(shader);
1213}
1214
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001215void VkPipelineObj::AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count)
Tony Barboure2c58df2014-11-25 13:18:32 -07001216{
1217 m_vi_state.pVertexAttributeDescriptions = vi_attrib;
1218 m_vi_state.attributeCount = count;
1219}
1220
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001221void VkPipelineObj::AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count)
Tony Barboure2c58df2014-11-25 13:18:32 -07001222{
1223 m_vi_state.pVertexBindingDescriptions = vi_binding;
1224 m_vi_state.bindingCount = count;
1225}
1226
Tony Barbour6918cd52015-04-09 12:58:51 -06001227void VkPipelineObj::AddVertexDataBuffer(VkConstantBufferObj* vertexDataBuffer, int binding)
Tony Barboure2c58df2014-11-25 13:18:32 -07001228{
1229 m_vertexBufferObjs.push_back(vertexDataBuffer);
1230 m_vertexBufferBindings.push_back(binding);
1231 m_vertexBufferCount++;
1232}
1233
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001234void VkPipelineObj::AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att)
Chia-I Wuecebf752014-12-05 10:45:15 +08001235{
Tony Barbourf52346d2015-01-16 14:27:35 -07001236 if (binding+1 > m_colorAttachments.size())
1237 {
1238 m_colorAttachments.resize(binding+1);
1239 }
1240 m_colorAttachments[binding] = *att;
1241}
1242
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001243void VkPipelineObj::SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *ds_state)
Tony Barbourf52346d2015-01-16 14:27:35 -07001244{
Tony Barbourf52346d2015-01-16 14:27:35 -07001245 m_ds_state.depthTestEnable = ds_state->depthTestEnable;
1246 m_ds_state.depthWriteEnable = ds_state->depthWriteEnable;
1247 m_ds_state.depthBoundsEnable = ds_state->depthBoundsEnable;
Tony Barbourd1c35722015-04-16 15:59:00 -06001248 m_ds_state.depthCompareOp = ds_state->depthCompareOp;
Tony Barbourf52346d2015-01-16 14:27:35 -07001249 m_ds_state.stencilTestEnable = ds_state->stencilTestEnable;
1250 m_ds_state.back = ds_state->back;
1251 m_ds_state.front = ds_state->front;
Chia-I Wuecebf752014-12-05 10:45:15 +08001252}
1253
Tony Barbour0ec8cd52015-08-06 09:27:11 -06001254void VkPipelineObj::SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state)
1255{
1256 memcpy(&m_ms_state, ms_state, sizeof(VkPipelineMultisampleStateCreateInfo));
1257}
1258
Tony Barbour5781e8f2015-08-04 16:23:11 -06001259VkResult VkPipelineObj::CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass)
Tony Barbour976e1cf2014-12-17 11:57:31 -07001260{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001261 VkGraphicsPipelineCreateInfo info = {};
Tony Barbour976e1cf2014-12-17 11:57:31 -07001262
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001263 VkPipelineShaderStageCreateInfo* shaderCreateInfo;
Tony Barbour976e1cf2014-12-17 11:57:31 -07001264
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001265 info.stageCount = m_shaderObjs.size();
1266 info.pStages = new VkPipelineShaderStageCreateInfo[info.stageCount];
1267
Tony Barbour976e1cf2014-12-17 11:57:31 -07001268 for (int i=0; i<m_shaderObjs.size(); i++)
1269 {
Chia-I Wu11078b02015-01-04 16:27:24 +08001270 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo();
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001271 memcpy((void*)&info.pStages[i], shaderCreateInfo, sizeof(VkPipelineShaderStageCreateInfo));
Tony Barbour976e1cf2014-12-17 11:57:31 -07001272 }
1273
Tony Barboure815fd72015-07-27 09:36:24 -06001274 if (m_vi_state.attributeCount && m_vi_state.bindingCount) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001275 m_vi_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Tony Barboure815fd72015-07-27 09:36:24 -06001276 info.pVertexInputState = &m_vi_state;
1277 } else {
1278 info.pVertexInputState = NULL;
Tony Barbour976e1cf2014-12-17 11:57:31 -07001279 }
1280
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001281 info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001282 info.pNext = NULL;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001283 info.flags = 0;
Tony Barbour5781e8f2015-08-04 16:23:11 -06001284 info.layout = layout;
Tony Barbour976e1cf2014-12-17 11:57:31 -07001285
Tony Barbourf52346d2015-01-16 14:27:35 -07001286 m_cb_state.attachmentCount = m_colorAttachments.size();
Tony Barbour482c6092015-07-27 09:37:48 -06001287 m_cb_state.pAttachments = m_colorAttachments.data();
Tony Barbourf52346d2015-01-16 14:27:35 -07001288
Chia-I Wu08accc62015-07-07 11:50:03 +08001289 info.renderPass = render_pass;
1290 info.subpass = 0;
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001291 info.pTessellationState = NULL;
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001292 info.pInputAssemblyState = &m_ia_state;
1293 info.pViewportState = &m_vp_state;
1294 info.pRasterState = &m_rs_state;
1295 info.pMultisampleState = &m_ms_state;
1296 info.pDepthStencilState = &m_ds_state;
1297 info.pColorBlendState = &m_cb_state;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001298
Chris Forbes95292b12015-05-25 11:13:26 +12001299 return init_try(*m_device, info);
Tony Barbour976e1cf2014-12-17 11:57:31 -07001300}
Chia-I Wu2648d092014-12-29 14:24:14 +08001301
Tony Barbourfe3351b2015-07-28 10:17:20 -06001302VkCommandBufferObj::VkCommandBufferObj(VkDeviceObj *device, VkCmdPool pool)
Tony Barbour6d047bf2014-12-10 14:34:45 -07001303{
Tony Barbour6d047bf2014-12-10 14:34:45 -07001304 m_device = device;
Courtney Goeltzenleuchter0c8385b2015-07-13 12:57:11 -06001305
Tony Barbourfe3351b2015-07-28 10:17:20 -06001306 init(*device, vk_testing::CmdBuffer::create_info(pool));
Tony Barbour6d047bf2014-12-10 14:34:45 -07001307}
Tony Barbour471338d2014-12-10 17:28:39 -07001308
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001309VkCmdBuffer VkCommandBufferObj::GetBufferHandle()
Tony Barbour6d047bf2014-12-10 14:34:45 -07001310{
Chia-I Wube2b9172015-07-03 11:49:42 +08001311 return handle();
Tony Barbour6d047bf2014-12-10 14:34:45 -07001312}
Tony Barbour471338d2014-12-10 17:28:39 -07001313
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001314VkResult VkCommandBufferObj::BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo)
Tony Barbour471338d2014-12-10 17:28:39 -07001315{
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001316 begin(pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001317 return VK_SUCCESS;
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001318}
1319
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001320VkResult VkCommandBufferObj::BeginCommandBuffer()
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001321{
1322 begin();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001323 return VK_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001324}
1325
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001326VkResult VkCommandBufferObj::EndCommandBuffer()
Tony Barbour471338d2014-12-10 17:28:39 -07001327{
Chia-I Wud28343c2014-12-28 15:12:48 +08001328 end();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001329 return VK_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001330}
1331
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001332void VkCommandBufferObj::PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tony Barbour471338d2014-12-10 17:28:39 -07001333{
Chia-I Wube2b9172015-07-03 11:49:42 +08001334 vkCmdPipelineBarrier(handle(), src_stages, dest_stages, byRegion, memBarrierCount, ppMemBarriers);
Tony Barbour471338d2014-12-10 17:28:39 -07001335}
1336
Chris Forbesf0796e12015-06-24 14:34:53 +12001337void VkCommandBufferObj::ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color,
Tony Barbour6918cd52015-04-09 12:58:51 -06001338 VkDepthStencilObj *depthStencilObj)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001339{
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001340 uint32_t i;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001341 const VkFlags output_mask =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -06001342 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001343 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1344 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1345 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -06001346 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001347 const VkFlags input_mask = 0;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001348
1349 // whatever we want to do, we do it to the whole buffer
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001350 VkImageSubresourceRange srRange = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001351 srRange.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001352 srRange.baseMipLevel = 0;
Courtney Goeltzenleuchter62b2d432015-06-04 11:35:43 -06001353 srRange.mipLevels = VK_LAST_MIP_LEVEL;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001354 srRange.baseArraySlice = 0;
Courtney Goeltzenleuchter62b2d432015-06-04 11:35:43 -06001355 srRange.arraySize = VK_LAST_ARRAY_SLICE;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001356
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001357 VkImageMemoryBarrier memory_barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001358 memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001359 memory_barrier.outputMask = output_mask;
1360 memory_barrier.inputMask = input_mask;
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001361 memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001362 memory_barrier.subresourceRange = srRange;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001363 VkImageMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001364
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001365 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1366 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001367
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -07001368 for (i = 0; i < m_renderTargets.size(); i++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001369 memory_barrier.image = m_renderTargets[i]->image();
1370 memory_barrier.oldLayout = m_renderTargets[i]->layout();
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001371 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001372 m_renderTargets[i]->layout(memory_barrier.newLayout);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001373
Chia-I Wube2b9172015-07-03 11:49:42 +08001374 vkCmdClearColorImage(handle(),
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001375 m_renderTargets[i]->image(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001376 &clear_color, 1, &srRange );
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001377
Tony Barbour30cc9e82014-12-17 11:53:55 -07001378 }
1379
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001380 if (depthStencilObj)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001381 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001382 VkImageSubresourceRange dsRange = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001383 dsRange.aspect = VK_IMAGE_ASPECT_DEPTH;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001384 dsRange.baseMipLevel = 0;
Courtney Goeltzenleuchter62b2d432015-06-04 11:35:43 -06001385 dsRange.mipLevels = VK_LAST_MIP_LEVEL;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001386 dsRange.baseArraySlice = 0;
Courtney Goeltzenleuchter62b2d432015-06-04 11:35:43 -06001387 dsRange.arraySize = VK_LAST_ARRAY_SLICE;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001388
1389 // prepare the depth buffer for clear
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001390
Cody Northrop3cc85e92015-08-04 10:47:08 -06001391 memory_barrier.oldLayout = memory_barrier.newLayout;
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001392 memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu681d7a02015-07-03 13:44:34 +08001393 memory_barrier.image = depthStencilObj->handle();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001394 memory_barrier.subresourceRange = dsRange;
1395
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001396 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001397
Chia-I Wube2b9172015-07-03 11:49:42 +08001398 vkCmdClearDepthStencilImage(handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001399 depthStencilObj->handle(), VK_IMAGE_LAYOUT_GENERAL,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001400 depth_clear_color, stencil_clear_color,
1401 1, &dsRange);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001402
1403 // prepare depth buffer for rendering
Chia-I Wu681d7a02015-07-03 13:44:34 +08001404 memory_barrier.image = depthStencilObj->handle();
Cody Northrop3cc85e92015-08-04 10:47:08 -06001405 memory_barrier.newLayout = memory_barrier.oldLayout;
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001406 memory_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001407 memory_barrier.subresourceRange = dsRange;
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001408 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001409 }
1410}
1411
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001412void VkCommandBufferObj::FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data)
1413{
1414 vkCmdFillBuffer( handle(), buffer, offset, fill_size, data);
1415}
1416
Tony Barbour6918cd52015-04-09 12:58:51 -06001417void VkCommandBufferObj::PrepareAttachments()
Tony Barbour30cc9e82014-12-17 11:53:55 -07001418{
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001419 uint32_t i;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001420 const VkFlags output_mask =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -06001421 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001422 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1423 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1424 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -06001425 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001426 const VkFlags input_mask =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -06001427 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001428 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1429 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1430 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1431 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1432 VK_MEMORY_INPUT_SHADER_READ_BIT |
1433 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1434 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -06001435 VK_MEMORY_INPUT_TRANSFER_BIT;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001436
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001437 VkImageSubresourceRange srRange = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001438 srRange.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001439 srRange.baseMipLevel = 0;
Courtney Goeltzenleuchter62b2d432015-06-04 11:35:43 -06001440 srRange.mipLevels = VK_LAST_MIP_LEVEL;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001441 srRange.baseArraySlice = 0;
Courtney Goeltzenleuchter62b2d432015-06-04 11:35:43 -06001442 srRange.arraySize = VK_LAST_ARRAY_SLICE;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001443
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001444 VkImageMemoryBarrier memory_barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001445 memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001446 memory_barrier.outputMask = output_mask;
1447 memory_barrier.inputMask = input_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001448 memory_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001449 memory_barrier.subresourceRange = srRange;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001450 VkImageMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001451
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001452 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1453 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001454
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -07001455 for(i=0; i<m_renderTargets.size(); i++)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001456 {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001457 memory_barrier.image = m_renderTargets[i]->image();
1458 memory_barrier.oldLayout = m_renderTargets[i]->layout();
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001459 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001460 m_renderTargets[i]->layout(memory_barrier.newLayout);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001461 }
Tony Barbour30cc9e82014-12-17 11:53:55 -07001462}
1463
Chia-I Wu08accc62015-07-07 11:50:03 +08001464void VkCommandBufferObj::BeginRenderPass(const VkRenderPassBeginInfo &info)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001465{
Chia-I Wube2b9172015-07-03 11:49:42 +08001466 vkCmdBeginRenderPass( handle(), &info, VK_RENDER_PASS_CONTENTS_INLINE);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001467}
1468
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08001469void VkCommandBufferObj::EndRenderPass()
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001470{
Chia-I Wube2b9172015-07-03 11:49:42 +08001471 vkCmdEndRenderPass(handle());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001472}
1473
Tony Barbour67e99152015-07-10 14:10:27 -06001474void VkCommandBufferObj::BindDynamicViewportState(VkDynamicViewportState viewportState)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001475{
Tony Barbour67e99152015-07-10 14:10:27 -06001476 vkCmdBindDynamicViewportState( handle(), viewportState);
1477}
1478
Cody Northrop12365112015-08-17 11:10:49 -06001479void VkCommandBufferObj::BindDynamicRasterLineState(VkDynamicRasterLineState rasterLineState)
Tony Barbour67e99152015-07-10 14:10:27 -06001480{
Cody Northrop12365112015-08-17 11:10:49 -06001481 vkCmdBindDynamicRasterLineState( handle(), rasterLineState);
1482}
1483
1484void VkCommandBufferObj::BindDynamicRasterDepthBiasState(VkDynamicRasterDepthBiasState rasterDepthBiasState)
1485{
1486 vkCmdBindDynamicRasterDepthBiasState( handle(), rasterDepthBiasState);
Tony Barbour67e99152015-07-10 14:10:27 -06001487}
1488
1489void VkCommandBufferObj::BindDynamicColorBlendState(VkDynamicColorBlendState colorBlendState)
1490{
1491 vkCmdBindDynamicColorBlendState( handle(), colorBlendState);
1492}
1493
1494void VkCommandBufferObj::BindDynamicDepthStencilState(VkDynamicDepthStencilState depthStencilState)
1495{
1496 vkCmdBindDynamicDepthStencilState( handle(), depthStencilState);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001497}
1498
Tony Barbour6918cd52015-04-09 12:58:51 -06001499void VkCommandBufferObj::AddRenderTarget(VkImageObj *renderTarget)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001500{
1501 m_renderTargets.push_back(renderTarget);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001502}
1503
Tony Barbour6918cd52015-04-09 12:58:51 -06001504void VkCommandBufferObj::DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001505{
Chia-I Wube2b9172015-07-03 11:49:42 +08001506 vkCmdDrawIndexed(handle(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001507}
1508
Tony Barbour6918cd52015-04-09 12:58:51 -06001509void VkCommandBufferObj::Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001510{
Chia-I Wube2b9172015-07-03 11:49:42 +08001511 vkCmdDraw(handle(), firstVertex, vertexCount, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001512}
1513
Tony Barbour6918cd52015-04-09 12:58:51 -06001514void VkCommandBufferObj::QueueCommandBuffer()
Tony Barbour30cc9e82014-12-17 11:53:55 -07001515{
Tony Barbour67e99152015-07-10 14:10:27 -06001516 VkFence nullFence = { VK_NULL_HANDLE };
1517 QueueCommandBuffer(nullFence);
Tony Barbour09b7ac32015-04-08 10:11:29 -06001518}
1519
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001520void VkCommandBufferObj::QueueCommandBuffer(VkFence fence)
Tony Barbour09b7ac32015-04-08 10:11:29 -06001521{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001522 VkResult err = VK_SUCCESS;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001523
1524 // submit the command buffer to the universal queue
Chia-I Wube2b9172015-07-03 11:49:42 +08001525 err = vkQueueSubmit( m_device->m_queue, 1, &handle(), fence );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001526 ASSERT_VK_SUCCESS( err );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001527
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001528 err = vkQueueWaitIdle( m_device->m_queue );
1529 ASSERT_VK_SUCCESS( err );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001530
1531 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001532 vkDeviceWaitIdle(m_device->device());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001533}
1534
Tony Barbour6918cd52015-04-09 12:58:51 -06001535void VkCommandBufferObj::BindPipeline(VkPipelineObj &pipeline)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001536{
Chia-I Wube2b9172015-07-03 11:49:42 +08001537 vkCmdBindPipeline( handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.handle() );
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001538}
1539
Tony Barbour6918cd52015-04-09 12:58:51 -06001540void VkCommandBufferObj::BindDescriptorSet(VkDescriptorSetObj &descriptorSet)
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001541{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001542 VkDescriptorSet set_obj = descriptorSet.GetDescriptorSetHandle();
Chia-I Wu53f07d72015-03-28 15:23:55 +08001543
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001544 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view)
Chia-I Wube2b9172015-07-03 11:49:42 +08001545 vkCmdBindDescriptorSets(handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, descriptorSet.GetPipelineLayout(),
Cody Northropd4c1a502015-04-16 13:41:56 -06001546 0, 1, &set_obj, 0, NULL );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001547}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001548
Cody Northropd2ad0342015-08-05 11:15:02 -06001549void VkCommandBufferObj::BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001550{
Chia-I Wu681d7a02015-07-03 13:44:34 +08001551 vkCmdBindIndexBuffer(handle(), indexBuffer->handle(), offset, indexBuffer->GetIndexType());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001552}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001553
Tony Barbourd1c35722015-04-16 15:59:00 -06001554void VkCommandBufferObj::BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001555{
Chia-I Wu681d7a02015-07-03 13:44:34 +08001556 vkCmdBindVertexBuffers(handle(), binding, 1, &vertexBuffer->handle(), &offset);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001557}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001558
Tony Barbour6918cd52015-04-09 12:58:51 -06001559VkDepthStencilObj::VkDepthStencilObj()
Tony Barbour1c45ce02015-03-27 17:03:18 -06001560{
1561 m_initialized = false;
1562}
Tony Barbour6918cd52015-04-09 12:58:51 -06001563bool VkDepthStencilObj::Initialized()
Tony Barbour1c45ce02015-03-27 17:03:18 -06001564{
1565 return m_initialized;
1566}
1567
Cody Northrop3cc85e92015-08-04 10:47:08 -06001568VkAttachmentView* VkDepthStencilObj::BindInfo()
Tony Barbour1c45ce02015-03-27 17:03:18 -06001569{
Chia-I Wu08accc62015-07-07 11:50:03 +08001570 return &m_attachmentBindInfo;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001571}
1572
Chia-I Wu08accc62015-07-07 11:50:03 +08001573void VkDepthStencilObj::Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format)
Tony Barbour1c45ce02015-03-27 17:03:18 -06001574{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001575 VkImageCreateInfo image_info;
Chia-I Wu08accc62015-07-07 11:50:03 +08001576 VkAttachmentViewCreateInfo view_info;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001577
1578 m_device = device;
1579 m_initialized = true;
Chia-I Wu08accc62015-07-07 11:50:03 +08001580 m_depth_stencil_fmt = format;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001581
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001582 image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001583 image_info.pNext = NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -06001584 image_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001585 image_info.format = m_depth_stencil_fmt;
1586 image_info.extent.width = width;
1587 image_info.extent.height = height;
1588 image_info.extent.depth = 1;
1589 image_info.mipLevels = 1;
1590 image_info.arraySize = 1;
1591 image_info.samples = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001592 image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001593 image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001594 image_info.flags = 0;
Tony Barbour3d83f492015-07-28 10:23:02 -06001595 image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1596 image_info.queueFamilyCount = 0;
1597 image_info.pQueueFamilyIndices = NULL;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001598 init(*m_device, image_info);
1599
Chia-I Wu08accc62015-07-07 11:50:03 +08001600 view_info.sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001601 view_info.pNext = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001602 view_info.image = VK_NULL_HANDLE;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001603 view_info.mipLevel = 0;
1604 view_info.baseArraySlice = 0;
1605 view_info.arraySize = 1;
1606 view_info.flags = 0;
Tony Barbour3d83f492015-07-28 10:23:02 -06001607 view_info.format = m_depth_stencil_fmt;
Chia-I Wu681d7a02015-07-03 13:44:34 +08001608 view_info.image = handle();
Chia-I Wu08accc62015-07-07 11:50:03 +08001609 m_attachmentView.init(*m_device, view_info);
Tony Barbour1c45ce02015-03-27 17:03:18 -06001610
Cody Northrop3cc85e92015-08-04 10:47:08 -06001611 m_attachmentBindInfo = m_attachmentView.handle();
Tony Barbour1c45ce02015-03-27 17:03:18 -06001612}