blob: 2eed8d89006c8e2a2c5d455f3f3dbc51617b7d57 [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 Northrop271ba752015-08-26 10:01:32 -060043 m_stateLineWidth( VK_NULL_HANDLE ),
44 m_stateDepthBias( VK_NULL_HANDLE ),
45 m_stateBlend( VK_NULL_HANDLE ),
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060046 m_stateViewport( VK_NULL_HANDLE ),
Cody Northrop271ba752015-08-26 10:01:32 -060047 m_stateDepthBounds( VK_NULL_HANDLE ),
Cody Northrop82485a82015-08-18 15:21:16 -060048 m_stateStencil( VK_NULL_HANDLE ),
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060049 m_width( 256.0 ), // default window width
Courtney Goeltzenleuchter679bbfa2015-03-05 17:26:38 -070050 m_height( 256.0 ), // default window height
Tony Barbourd1c35722015-04-16 15:59:00 -060051 m_render_target_fmt( VK_FORMAT_R8G8B8A8_UNORM ),
52 m_depth_stencil_fmt( VK_FORMAT_UNDEFINED ),
Tony Barbour71bd4b32015-07-21 17:00:26 -060053 m_clear_via_load_op( true ),
Courtney Goeltzenleuchter679bbfa2015-03-05 17:26:38 -070054 m_depth_clear_color( 1.0 ),
Courtney Goeltzenleuchterb6c9aca2015-06-08 16:19:37 -060055 m_stencil_clear_color( 0 ),
56 m_depthStencil( NULL ),
57 m_dbgCreateMsgCallback( VK_NULL_HANDLE ),
58 m_dbgDestroyMsgCallback( VK_NULL_HANDLE ),
59 m_globalMsgCallback( VK_NULL_HANDLE ),
60 m_devMsgCallback( VK_NULL_HANDLE )
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060061{
Tony Barbour1c45ce02015-03-27 17:03:18 -060062
Chia-I Wu08accc62015-07-07 11:50:03 +080063 memset(&m_renderPassBeginInfo, 0, sizeof(m_renderPassBeginInfo));
64 m_renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
65
Courtney Goeltzenleuchter679bbfa2015-03-05 17:26:38 -070066 // clear the back buffer to dark grey
Cody Northrop85789d52015-08-25 15:26:38 -060067 m_clear_color.float32[0] = 0.25f;
68 m_clear_color.float32[1] = 0.25f;
69 m_clear_color.float32[2] = 0.25f;
70 m_clear_color.float32[3] = 0.0f;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060071}
72
Tony Barbour6918cd52015-04-09 12:58:51 -060073VkRenderFramework::~VkRenderFramework()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060074{
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060075
76}
77
Tony Barbour6918cd52015-04-09 12:58:51 -060078void VkRenderFramework::InitFramework()
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060079{
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060080 std::vector<const char*> instance_layer_names;
81 std::vector<const char*> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060082 std::vector<const char*> instance_extension_names;
83 std::vector<const char*> device_extension_names;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060084 InitFramework(
85 instance_layer_names, device_layer_names,
86 instance_extension_names, device_extension_names);
Tony Barbour3fdff9e2015-04-23 12:55:36 -060087}
88
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060089void VkRenderFramework::InitFramework(
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -060090 std::vector<const char *> instance_layer_names,
91 std::vector<const char *> device_layer_names,
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060092 std::vector<const char *> instance_extension_names,
93 std::vector<const char *> device_extension_names,
94 PFN_vkDbgMsgCallback dbgFunction,
95 void *userData)
Tony Barbour3fdff9e2015-04-23 12:55:36 -060096{
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -060097 VkInstanceCreateInfo instInfo = {};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -060098 std::vector<VkExtensionProperties> instance_extensions;
99 std::vector<VkExtensionProperties> device_extensions;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600100 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600101
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600102 /* TODO: Verify requested extensions are available */
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600103
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600104 instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
Jon Ashburnb317fad2015-04-04 14:52:07 -0600105 instInfo.pNext = NULL;
106 instInfo.pAppInfo = &app_info;
107 instInfo.pAllocCb = NULL;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600108 instInfo.layerCount = instance_layer_names.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600109 instInfo.ppEnabledLayerNames = instance_layer_names.data();
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600110 instInfo.extensionCount = instance_extension_names.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600111 instInfo.ppEnabledExtensionNames = instance_extension_names.data();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600112 err = vkCreateInstance(&instInfo, &this->inst);
113 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600114
Jon Ashburn83a64252015-04-15 11:31:12 -0600115 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, NULL);
116 ASSERT_LE(this->gpu_count, ARRAY_SIZE(objs)) << "Too many gpus";
117 ASSERT_VK_SUCCESS(err);
118 err = vkEnumeratePhysicalDevices(inst, &this->gpu_count, objs);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600119 ASSERT_VK_SUCCESS(err);
Jon Ashburnbf843b22014-11-26 11:06:49 -0700120 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Tony Barbour15524c32015-04-29 17:34:29 -0600121 if (dbgFunction) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600122 m_dbgCreateMsgCallback = (PFN_vkDbgCreateMsgCallback) vkGetInstanceProcAddr(this->inst, "vkDbgCreateMsgCallback");
123 ASSERT_NE(m_dbgCreateMsgCallback, (PFN_vkDbgCreateMsgCallback) NULL) << "Did not get function pointer for DbgCreateMsgCallback";
124 if (m_dbgCreateMsgCallback) {
125 err = m_dbgCreateMsgCallback(this->inst,
126 VK_DBG_REPORT_ERROR_BIT | VK_DBG_REPORT_WARN_BIT,
127 dbgFunction,
128 userData,
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600129 &m_globalMsgCallback);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600130 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchter7e46b622015-06-08 15:16:04 -0600131
132 m_dbgDestroyMsgCallback = (PFN_vkDbgDestroyMsgCallback) vkGetInstanceProcAddr(this->inst, "vkDbgDestroyMsgCallback");
133 ASSERT_NE(m_dbgDestroyMsgCallback, (PFN_vkDbgDestroyMsgCallback) NULL) << "Did not get function pointer for DbgDestroyMsgCallback";
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600134 }
Tony Barbour15524c32015-04-29 17:34:29 -0600135 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600136
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600137 /* TODO: Verify requested physical device extensions are available */
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600138 m_device = new VkDeviceObj(0, objs[0], device_layer_names, device_extension_names);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600139
140 /* Now register callback on device */
141 if (0) {
142 if (m_dbgCreateMsgCallback) {
143 err = m_dbgCreateMsgCallback(this->inst,
144 VK_DBG_REPORT_ERROR_BIT | VK_DBG_REPORT_WARN_BIT,
145 dbgFunction,
146 userData,
147 &m_devMsgCallback);
148 ASSERT_VK_SUCCESS(err);
149 }
150 }
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600151 m_device->get_device_queue();
Tony Barbour1c45ce02015-03-27 17:03:18 -0600152
Tony Barbour6918cd52015-04-09 12:58:51 -0600153 m_depthStencil = new VkDepthStencilObj();
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600154}
155
Tony Barbour6918cd52015-04-09 12:58:51 -0600156void VkRenderFramework::ShutdownFramework()
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600157{
Cody Northrop271ba752015-08-26 10:01:32 -0600158 if (m_stateBlend) vkDestroyDynamicBlendState(device(), m_stateBlend);
159 if (m_stateDepthBounds) vkDestroyDynamicDepthBoundsState(device(), m_stateDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -0600160 if (m_stateStencil) vkDestroyDynamicStencilState(device(), m_stateStencil);
Cody Northrop271ba752015-08-26 10:01:32 -0600161 if (m_stateLineWidth) vkDestroyDynamicLineWidthState(device(), m_stateLineWidth);
162 if (m_stateDepthBias) vkDestroyDynamicDepthBiasState(device(), m_stateDepthBias);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600163 if (m_cmdBuffer)
164 delete m_cmdBuffer;
Cody Northrope62183e2015-07-09 18:08:05 -0600165 if (m_cmdPool) vkDestroyCommandPool(device(), m_cmdPool);
Tony Barbour67e99152015-07-10 14:10:27 -0600166 if (m_framebuffer) vkDestroyFramebuffer(device(), m_framebuffer);
167 if (m_renderPass) vkDestroyRenderPass(device(), m_renderPass);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600168
Courtney Goeltzenleuchter7e46b622015-06-08 15:16:04 -0600169 if (m_globalMsgCallback) m_dbgDestroyMsgCallback(this->inst, m_globalMsgCallback);
170 if (m_devMsgCallback) m_dbgDestroyMsgCallback(this->inst, m_devMsgCallback);
171
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600172 if (m_stateViewport) {
Tony Barbour67e99152015-07-10 14:10:27 -0600173 vkDestroyDynamicViewportState(device(), m_stateViewport);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600174 }
Tobin Ehlis976fc162015-03-26 08:23:25 -0600175 while (!m_renderTargets.empty()) {
Tony Barbour6a3faf02015-07-23 10:36:18 -0600176 vkDestroyAttachmentView(device(), m_renderTargets.back()->targetView(m_render_target_fmt));
Tony Barbour67e99152015-07-10 14:10:27 -0600177 vkDestroyImage(device(), m_renderTargets.back()->image());
Mike Stroyanb050c682015-04-17 12:36:38 -0600178 vkFreeMemory(device(), m_renderTargets.back()->memory());
Tobin Ehlis976fc162015-03-26 08:23:25 -0600179 m_renderTargets.pop_back();
180 }
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600181
Tony Barbour1c45ce02015-03-27 17:03:18 -0600182 delete m_depthStencil;
Tony Barbour823e6ca2015-07-27 13:31:04 -0600183 while (!m_shader_modules.empty())
184 {
185 delete m_shader_modules.back();
186 m_shader_modules.pop_back();
187 }
Tony Barbour1c45ce02015-03-27 17:03:18 -0600188
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -0600189 // reset the driver
Chia-I Wub76e0fa2014-12-28 14:27:28 +0800190 delete m_device;
Chris Forbesbe2fae62015-07-07 11:02:22 +1200191 if (this->inst) vkDestroyInstance(this->inst);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600192}
193
Tony Barbour6918cd52015-04-09 12:58:51 -0600194void VkRenderFramework::InitState()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600195{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600196 VkResult err;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600197
Tony Barbour6a3faf02015-07-23 10:36:18 -0600198 // Get the list of VkFormat's that are supported:
Ian Elliott8b139792015-08-07 11:51:12 -0600199 PFN_vkGetSurfaceFormatsWSI fpGetSurfaceFormatsWSI;
200 uint32_t formatCount;
Tony Barbour6a3faf02015-07-23 10:36:18 -0600201 VkSurfaceDescriptionWSI surface_description;
202 surface_description.sType = VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI;
203 surface_description.pNext = NULL;
Ian Elliott8b139792015-08-07 11:51:12 -0600204 GET_DEVICE_PROC_ADDR(device(), GetSurfaceFormatsWSI);
205 err = fpGetSurfaceFormatsWSI(device(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600206 (VkSurfaceDescriptionWSI *) &surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600207 &formatCount, NULL);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600208 ASSERT_VK_SUCCESS(err);
Ian Elliott8b139792015-08-07 11:51:12 -0600209 VkSurfaceFormatWSI *surfFormats =
210 (VkSurfaceFormatWSI *)malloc(formatCount * sizeof(VkSurfaceFormatWSI));
211 err = fpGetSurfaceFormatsWSI(device(),
Tony Barbour6a3faf02015-07-23 10:36:18 -0600212 (VkSurfaceDescriptionWSI *) &surface_description,
Ian Elliott8b139792015-08-07 11:51:12 -0600213 &formatCount, surfFormats);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600214 ASSERT_VK_SUCCESS(err);
215 m_render_target_fmt = surfFormats[0].format;
216 free(surfFormats);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600217
Cody Northrop271ba752015-08-26 10:01:32 -0600218 VkDynamicLineWidthStateCreateInfo lineWidth = {};
219 lineWidth.sType = VK_STRUCTURE_TYPE_DYNAMIC_LINE_WIDTH_STATE_CREATE_INFO;
220 lineWidth.lineWidth = 1;
221 err = vkCreateDynamicLineWidthState( device(), &lineWidth, &m_stateLineWidth );
Cody Northrop12365112015-08-17 11:10:49 -0600222 ASSERT_VK_SUCCESS(err);
Tony Barbourf52346d2015-01-16 14:27:35 -0700223
Cody Northrop271ba752015-08-26 10:01:32 -0600224 VkDynamicDepthBiasStateCreateInfo depthBias = {};
225 depthBias.sType = VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_BIAS_STATE_CREATE_INFO;
226 depthBias.depthBias = 0.0f;
227 depthBias.depthBiasClamp = 0.0f;
228 depthBias.slopeScaledDepthBias = 0.0f;
229 err = vkCreateDynamicDepthBiasState( device(), &depthBias, &m_stateDepthBias );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600230 ASSERT_VK_SUCCESS(err);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600231
Cody Northrop271ba752015-08-26 10:01:32 -0600232 VkDynamicBlendStateCreateInfo blend = {};
233 blend.sType = VK_STRUCTURE_TYPE_DYNAMIC_BLEND_STATE_CREATE_INFO;
Tony Barbourd81b8882015-05-15 09:37:57 -0600234 blend.blendConst[0] = 1.0f;
235 blend.blendConst[1] = 1.0f;
236 blend.blendConst[2] = 1.0f;
237 blend.blendConst[3] = 1.0f;
Cody Northrop271ba752015-08-26 10:01:32 -0600238 err = vkCreateDynamicBlendState(device(), &blend, &m_stateBlend);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600239 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600240
Cody Northrop271ba752015-08-26 10:01:32 -0600241 VkDynamicDepthBoundsStateCreateInfo depth = {};
242 depth.sType = VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_BOUNDS_STATE_CREATE_INFO;
Cody Northrop82485a82015-08-18 15:21:16 -0600243 depth.minDepthBounds = 0.f;
244 depth.maxDepthBounds = 1.f;
Cody Northrop271ba752015-08-26 10:01:32 -0600245 err = vkCreateDynamicDepthBoundsState( device(), &depth, &m_stateDepthBounds );
Cody Northrop82485a82015-08-18 15:21:16 -0600246 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600247
Cody Northrop82485a82015-08-18 15:21:16 -0600248 VkDynamicStencilStateCreateInfo stencil = {};
249 stencil.sType = VK_STRUCTURE_TYPE_DYNAMIC_STENCIL_STATE_CREATE_INFO;
Cody Northrop271ba752015-08-26 10:01:32 -0600250 stencil.stencilCompareMask = 0xff;
Cody Northrop82485a82015-08-18 15:21:16 -0600251 stencil.stencilWriteMask = 0xff;
252 stencil.stencilReference = 0;
253 err = vkCreateDynamicStencilState( device(), &stencil, &stencil, &m_stateStencil );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600254 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600255
Cody Northrope62183e2015-07-09 18:08:05 -0600256 VkCmdPoolCreateInfo cmd_pool_info;
257 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO,
258 cmd_pool_info.pNext = NULL,
259 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
260 cmd_pool_info.flags = 0,
261 err = vkCreateCommandPool(device(), &cmd_pool_info, &m_cmdPool);
262 assert(!err);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600263
Tony Barbourfe3351b2015-07-28 10:17:20 -0600264 m_cmdBuffer = new VkCommandBufferObj(m_device, m_cmdPool);
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600265}
266
Tony Barbour6918cd52015-04-09 12:58:51 -0600267void VkRenderFramework::InitViewport(float width, float height)
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600268{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600269 VkResult err;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600270
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271 VkViewport viewport;
Chris Forbesd9be82b2015-06-22 17:21:59 +1200272 VkRect2D scissor;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600273
Tony Barbour67e99152015-07-10 14:10:27 -0600274 VkDynamicViewportStateCreateInfo viewportCreate = {};
275 viewportCreate.sType = VK_STRUCTURE_TYPE_DYNAMIC_VIEWPORT_STATE_CREATE_INFO;
Courtney Goeltzenleuchterbbe3cc52015-02-11 14:13:34 -0700276 viewportCreate.viewportAndScissorCount = 1;
Tony Barbourf52346d2015-01-16 14:27:35 -0700277 viewport.originX = 0;
278 viewport.originY = 0;
279 viewport.width = 1.f * width;
280 viewport.height = 1.f * height;
281 viewport.minDepth = 0.f;
282 viewport.maxDepth = 1.f;
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600283 scissor.extent.width = (int32_t) width;
284 scissor.extent.height = (int32_t) height;
Courtney Goeltzenleuchterbbe3cc52015-02-11 14:13:34 -0700285 scissor.offset.x = 0;
286 scissor.offset.y = 0;
Tony Barbourf52346d2015-01-16 14:27:35 -0700287 viewportCreate.pViewports = &viewport;
Courtney Goeltzenleuchterbbe3cc52015-02-11 14:13:34 -0700288 viewportCreate.pScissors = &scissor;
Tony Barbourf52346d2015-01-16 14:27:35 -0700289
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600290 err = vkCreateDynamicViewportState( device(), &viewportCreate, &m_stateViewport );
291 ASSERT_VK_SUCCESS( err );
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600292 m_width = width;
293 m_height = height;
294}
295
Tony Barbour6918cd52015-04-09 12:58:51 -0600296void VkRenderFramework::InitViewport()
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -0600297{
298 InitViewport(m_width, m_height);
299}
Tony Barbour6918cd52015-04-09 12:58:51 -0600300void VkRenderFramework::InitRenderTarget()
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600301{
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700302 InitRenderTarget(1);
303}
304
Tony Barbour6918cd52015-04-09 12:58:51 -0600305void VkRenderFramework::InitRenderTarget(uint32_t targets)
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -0700306{
Tony Barbour1c45ce02015-03-27 17:03:18 -0600307 InitRenderTarget(targets, NULL);
308}
309
Cody Northrop3cc85e92015-08-04 10:47:08 -0600310void VkRenderFramework::InitRenderTarget(VkAttachmentView *dsBinding)
Tony Barbour1c45ce02015-03-27 17:03:18 -0600311{
312 InitRenderTarget(1, dsBinding);
313}
314
Cody Northrop3cc85e92015-08-04 10:47:08 -0600315void VkRenderFramework::InitRenderTarget(uint32_t targets, VkAttachmentView *dsBinding)
Tony Barbour1c45ce02015-03-27 17:03:18 -0600316{
Chia-I Wu08accc62015-07-07 11:50:03 +0800317 std::vector<VkAttachmentDescription> attachments;
318 std::vector<VkAttachmentReference> color_references;
Cody Northrop3cc85e92015-08-04 10:47:08 -0600319 std::vector<VkAttachmentView> bindings;
Cody Northropd2ad0342015-08-05 11:15:02 -0600320 attachments.reserve(targets + 1); // +1 for dsBinding
Chia-I Wu08accc62015-07-07 11:50:03 +0800321 color_references.reserve(targets);
Cody Northropd2ad0342015-08-05 11:15:02 -0600322 bindings.reserve(targets + 1); // +1 for dsBinding
Tony Barbour1c45ce02015-03-27 17:03:18 -0600323
Chia-I Wu08accc62015-07-07 11:50:03 +0800324 VkAttachmentDescription att = {};
325 att.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION;
326 att.pNext = NULL;
327 att.format = m_render_target_fmt;
328 att.samples = 1;
329 att.loadOp = (m_clear_via_load_op) ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
330 att.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
331 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
332 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
333 att.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
334 att.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Chia-I Wuecebf752014-12-05 10:45:15 +0800335
Chia-I Wu08accc62015-07-07 11:50:03 +0800336 VkAttachmentReference ref = {};
337 ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
338
339 m_renderPassClearValues.clear();
340 VkClearValue clear = {};
341 clear.color = m_clear_color;
342
Cody Northrop3cc85e92015-08-04 10:47:08 -0600343 VkAttachmentView bind = {};
Chia-I Wu08accc62015-07-07 11:50:03 +0800344
345 for (uint32_t i = 0; i < targets; i++) {
346 attachments.push_back(att);
347
348 ref.attachment = i;
349 color_references.push_back(ref);
350
351 m_renderPassClearValues.push_back(clear);
352
Tony Barbour6918cd52015-04-09 12:58:51 -0600353 VkImageObj *img = new VkImageObj(m_device);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600354
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600355 VkFormatProperties props;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600356 VkResult err;
357
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600358 err = vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), m_render_target_fmt, &props);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600359 ASSERT_VK_SUCCESS(err);
360
361 if (props.linearTilingFeatures & 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_LINEAR);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600365 }
366 else if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600367 img->init((uint32_t)m_width, (uint32_t)m_height, m_render_target_fmt,
Tony Barboure65788f2015-07-21 17:01:42 -0600368 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT,
369 VK_IMAGE_TILING_OPTIMAL);
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600370 }
371 else {
372 FAIL() << "Neither Linear nor Optimal allowed for render target";
373 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600374
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600375 m_renderTargets.push_back(img);
Tony Barbour6a3faf02015-07-23 10:36:18 -0600376 bind = img->targetView(m_render_target_fmt);
Chia-I Wu08accc62015-07-07 11:50:03 +0800377 bindings.push_back(bind);
Chia-I Wuecebf752014-12-05 10:45:15 +0800378 }
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600379
Chia-I Wu08accc62015-07-07 11:50:03 +0800380 VkSubpassDescription subpass = {};
381 subpass.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION;
382 subpass.pNext = NULL;
383 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
384 subpass.flags = 0;
385 subpass.inputCount = 0;
Cody Northropa505dda2015-08-04 11:16:41 -0600386 subpass.pInputAttachments = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800387 subpass.colorCount = targets;
Cody Northropa505dda2015-08-04 11:16:41 -0600388 subpass.pColorAttachments = color_references.data();
389 subpass.pResolveAttachments = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800390
391 if (dsBinding) {
392 att.format = m_depth_stencil_fmt;
Tony Barbour71bd4b32015-07-21 17:00:26 -0600393 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 +0800394 att.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
395 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
396 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
Chia-I Wu08accc62015-07-07 11:50:03 +0800397 attachments.push_back(att);
398
Cody Northrop85789d52015-08-25 15:26:38 -0600399 clear.depthStencil.depth = m_depth_clear_color;
400 clear.depthStencil.stencil = m_stencil_clear_color;
Chia-I Wu08accc62015-07-07 11:50:03 +0800401 m_renderPassClearValues.push_back(clear);
402
403 bindings.push_back(*dsBinding);
404
405 subpass.depthStencilAttachment.attachment = targets;
Chia-I Wu08accc62015-07-07 11:50:03 +0800406 } else {
407 subpass.depthStencilAttachment.attachment = VK_ATTACHMENT_UNUSED;
408 }
409
410 subpass.preserveCount = 0;
Cody Northropa505dda2015-08-04 11:16:41 -0600411 subpass.pPreserveAttachments = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800412
413 VkRenderPassCreateInfo rp_info = {};
414 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
415 rp_info.attachmentCount = attachments.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600416 rp_info.pAttachments = attachments.data();
Chia-I Wu08accc62015-07-07 11:50:03 +0800417 rp_info.subpassCount = 1;
418 rp_info.pSubpasses = &subpass;
419
420 vkCreateRenderPass(device(), &rp_info, &m_renderPass);
421
422 // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600423 VkFramebufferCreateInfo fb_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600424 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600425 fb_info.pNext = NULL;
Chia-I Wu08accc62015-07-07 11:50:03 +0800426 fb_info.renderPass = m_renderPass;
427 fb_info.attachmentCount = bindings.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600428 fb_info.pAttachments = bindings.data();
Tony Barbourbdf0a312015-04-01 17:10:07 -0600429 fb_info.width = (uint32_t)m_width;
430 fb_info.height = (uint32_t)m_height;
431 fb_info.layers = 1;
432
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600433 vkCreateFramebuffer(device(), &fb_info, &m_framebuffer);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600434
Chia-I Wu08accc62015-07-07 11:50:03 +0800435 m_renderPassBeginInfo.renderPass = m_renderPass;
436 m_renderPassBeginInfo.framebuffer = m_framebuffer;
Cody Northropd2ad0342015-08-05 11:15:02 -0600437 m_renderPassBeginInfo.renderArea.extent.width = (int32_t) m_width;
438 m_renderPassBeginInfo.renderArea.extent.height = (int32_t) m_height;
Cody Northrop23dd89d2015-08-04 11:51:03 -0600439 m_renderPassBeginInfo.clearValueCount = m_renderPassClearValues.size();
440 m_renderPassBeginInfo.pClearValues = m_renderPassClearValues.data();
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600441}
442
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600443
444
Tony Barbourd1c35722015-04-16 15:59:00 -0600445VkDeviceObj::VkDeviceObj(uint32_t id, VkPhysicalDevice obj) :
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600446 vk_testing::Device(obj), id(id)
Chia-I Wufb1459b2014-12-29 15:23:20 +0800447{
448 init();
449
Chia-I Wu999f0482015-07-03 10:32:05 +0800450 props = phy().properties();
Tony Barbour482c6092015-07-27 09:37:48 -0600451 queue_props = phy().queue_properties().data();
Chia-I Wufb1459b2014-12-29 15:23:20 +0800452}
453
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600454VkDeviceObj::VkDeviceObj(uint32_t id,
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600455 VkPhysicalDevice obj, std::vector<const char *> &layer_names,
456 std::vector<const char *> &extension_names) :
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600457 vk_testing::Device(obj), id(id)
458{
Courtney Goeltzenleuchter5bac6092015-07-07 11:47:33 -0600459 init(layer_names, extension_names);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600460
Chia-I Wu999f0482015-07-03 10:32:05 +0800461 props = phy().properties();
Tony Barbour482c6092015-07-27 09:37:48 -0600462 queue_props = phy().queue_properties().data();
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600463}
464
Tony Barbour6918cd52015-04-09 12:58:51 -0600465void VkDeviceObj::get_device_queue()
Chia-I Wufb1459b2014-12-29 15:23:20 +0800466{
467 ASSERT_NE(true, graphics_queues().empty());
Chia-I Wudf12ffd2015-07-03 10:53:18 +0800468 m_queue = graphics_queues()[0]->handle();
Chia-I Wufb1459b2014-12-29 15:23:20 +0800469}
470
Tobin Ehlis3ab1f872015-05-27 14:33:27 -0600471VkDescriptorSetObj::VkDescriptorSetObj(VkDeviceObj *device) :
472 m_device(device), m_nextSlot(0)
Tony Barboure2c58df2014-11-25 13:18:32 -0700473{
Tony Barboure2c58df2014-11-25 13:18:32 -0700474
475}
476
Tony Barbour6918cd52015-04-09 12:58:51 -0600477VkDescriptorSetObj::~VkDescriptorSetObj()
Tony Barboure2c58df2014-11-25 13:18:32 -0700478{
Chia-I Wu11078b02015-01-04 16:27:24 +0800479 delete m_set;
Tony Barboure2c58df2014-11-25 13:18:32 -0700480}
Tony Barbour82c39522014-12-04 14:33:33 -0700481
Tony Barbour6918cd52015-04-09 12:58:51 -0600482int VkDescriptorSetObj::AppendDummy()
Tony Barboure2c58df2014-11-25 13:18:32 -0700483{
Chia-I Wu11078b02015-01-04 16:27:24 +0800484 /* request a descriptor but do not update it */
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600485 VkDescriptorTypeCount tc = {};
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600486 tc.type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
Chia-I Wu11078b02015-01-04 16:27:24 +0800487 tc.count = 1;
488 m_type_counts.push_back(tc);
Tony Barboure2c58df2014-11-25 13:18:32 -0700489
Chia-I Wu11078b02015-01-04 16:27:24 +0800490 return m_nextSlot++;
Tony Barboure2c58df2014-11-25 13:18:32 -0700491}
Tony Barbour82c39522014-12-04 14:33:33 -0700492
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600493int VkDescriptorSetObj::AppendBuffer(VkDescriptorType type, VkConstantBufferObj &constantBuffer)
Tony Barboure2c58df2014-11-25 13:18:32 -0700494{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600495 VkDescriptorTypeCount tc = {};
Chia-I Wu11078b02015-01-04 16:27:24 +0800496 tc.type = type;
497 tc.count = 1;
498 m_type_counts.push_back(tc);
Tony Barboure2c58df2014-11-25 13:18:32 -0700499
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800500 m_writes.push_back(vk_testing::Device::write_descriptor_set(vk_testing::DescriptorSet(),
501 m_nextSlot, 0, type, 1, &constantBuffer.m_descriptorInfo));
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600502
Chia-I Wu11078b02015-01-04 16:27:24 +0800503 return m_nextSlot++;
Tony Barboure2c58df2014-11-25 13:18:32 -0700504}
Tony Barbour82c39522014-12-04 14:33:33 -0700505
Tony Barbour6918cd52015-04-09 12:58:51 -0600506int VkDescriptorSetObj::AppendSamplerTexture( VkSamplerObj* sampler, VkTextureObj* texture)
Tony Barboure2c58df2014-11-25 13:18:32 -0700507{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600508 VkDescriptorTypeCount tc = {};
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600509 tc.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Chia-I Wu11078b02015-01-04 16:27:24 +0800510 tc.count = 1;
511 m_type_counts.push_back(tc);
Tony Barboure2c58df2014-11-25 13:18:32 -0700512
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800513 VkDescriptorInfo tmp = texture->m_descriptorInfo;
Chia-I Wu8c721c62015-07-03 11:49:42 +0800514 tmp.sampler = sampler->handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800515 m_imageSamplerDescriptors.push_back(tmp);
Tony Barboure2c58df2014-11-25 13:18:32 -0700516
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800517 m_writes.push_back(vk_testing::Device::write_descriptor_set(vk_testing::DescriptorSet(),
518 m_nextSlot, 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, NULL));
Tony Barboure2c58df2014-11-25 13:18:32 -0700519
Chia-I Wu11078b02015-01-04 16:27:24 +0800520 return m_nextSlot++;
Tony Barboure2c58df2014-11-25 13:18:32 -0700521}
Chia-I Wu11078b02015-01-04 16:27:24 +0800522
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500523VkPipelineLayout VkDescriptorSetObj::GetPipelineLayout() const
Tony Barbourb5f4d082014-12-17 10:54:03 -0700524{
Chia-I Wufd46e7d2015-07-03 11:49:42 +0800525 return m_pipeline_layout.handle();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700526}
527
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600528VkDescriptorSet VkDescriptorSetObj::GetDescriptorSetHandle() const
Tony Barbourb5f4d082014-12-17 10:54:03 -0700529{
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800530 return m_set->handle();
Tony Barbourb5f4d082014-12-17 10:54:03 -0700531}
Tony Barboure2c58df2014-11-25 13:18:32 -0700532
Tony Barbour6918cd52015-04-09 12:58:51 -0600533void VkDescriptorSetObj::CreateVKDescriptorSet(VkCommandBufferObj *cmdBuffer)
Tony Barbour824b7712014-12-18 17:06:21 -0700534{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600535 // create VkDescriptorPool
536 VkDescriptorPoolCreateInfo pool = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600537 pool.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
Chia-I Wu985ba162015-03-26 13:14:16 +0800538 pool.count = m_type_counts.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600539 pool.pTypeCount = m_type_counts.data();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600540 init(*m_device, VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, pool);
Tony Barbour824b7712014-12-18 17:06:21 -0700541
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600542 // create VkDescriptorSetLayout
543 vector<VkDescriptorSetLayoutBinding> bindings;
Chia-I Wub41393e2015-03-26 15:04:41 +0800544 bindings.resize(m_type_counts.size());
Chia-I Wu11078b02015-01-04 16:27:24 +0800545 for (int i = 0; i < m_type_counts.size(); i++) {
Chia-I Wub41393e2015-03-26 15:04:41 +0800546 bindings[i].descriptorType = m_type_counts[i].type;
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800547 bindings[i].arraySize = m_type_counts[i].count;
Tony Barbourd1c35722015-04-16 15:59:00 -0600548 bindings[i].stageFlags = VK_SHADER_STAGE_ALL;
Chia-I Wu0743e832015-03-27 12:56:09 +0800549 bindings[i].pImmutableSamplers = NULL;
Tony Barboure2c58df2014-11-25 13:18:32 -0700550 }
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800551
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600552 // create VkDescriptorSetLayout
553 VkDescriptorSetLayoutCreateInfo layout = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600554 layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Chia-I Wub41393e2015-03-26 15:04:41 +0800555 layout.count = bindings.size();
Tony Barbour482c6092015-07-27 09:37:48 -0600556 layout.pBinding = bindings.data();
Chia-I Wub41393e2015-03-26 15:04:41 +0800557
Chia-I Wu41126e52015-03-26 15:27:55 +0800558 m_layout.init(*m_device, layout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600559 vector<const vk_testing::DescriptorSetLayout *> layouts;
Chia-I Wu41126e52015-03-26 15:27:55 +0800560 layouts.push_back(&m_layout);
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -0500561
562 // create VkPipelineLayout
563 VkPipelineLayoutCreateInfo pipeline_layout = {};
564 pipeline_layout.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
565 pipeline_layout.descriptorSetCount = layouts.size();
566 pipeline_layout.pSetLayouts = NULL;
567
568 m_pipeline_layout.init(*m_device, pipeline_layout, layouts);
Tony Barboure2c58df2014-11-25 13:18:32 -0700569
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600570 // create VkDescriptorSet
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500571 m_set = alloc_sets(*m_device, VK_DESCRIPTOR_SET_USAGE_STATIC, m_layout);
Chia-I Wu11078b02015-01-04 16:27:24 +0800572
Chia-I Wu41126e52015-03-26 15:27:55 +0800573 // build the update array
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800574 size_t imageSamplerCount = 0;
575 for (std::vector<VkWriteDescriptorSet>::iterator it = m_writes.begin();
576 it != m_writes.end(); it++) {
Chia-I Wuafdfd7f2015-07-03 11:49:42 +0800577 it->destSet = m_set->handle();
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800578 if (it->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
579 it->pDescriptors = &m_imageSamplerDescriptors[imageSamplerCount++];
Chia-I Wu11078b02015-01-04 16:27:24 +0800580 }
Chia-I Wu11078b02015-01-04 16:27:24 +0800581
582 // do the updates
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800583 m_device->update_descriptor_sets(m_writes);
Tony Barbour25ef8a62014-12-03 13:59:18 -0700584}
Tony Barboure2c58df2014-11-25 13:18:32 -0700585
Tony Barbour6918cd52015-04-09 12:58:51 -0600586VkImageObj::VkImageObj(VkDeviceObj *dev)
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800587{
588 m_device = dev;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800589 m_descriptorInfo.imageView = VK_NULL_HANDLE;
590 m_descriptorInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800591}
592
Tony Barbour6918cd52015-04-09 12:58:51 -0600593void VkImageObj::ImageMemoryBarrier(
594 VkCommandBufferObj *cmd_buf,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600595 VkImageAspect aspect,
596 VkFlags output_mask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600597 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600598 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
599 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
600 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
601 VK_MEMORY_OUTPUT_COPY_BIT*/,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600602 VkFlags input_mask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600603 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600604 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
605 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
606 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
607 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
608 VK_MEMORY_INPUT_SHADER_READ_BIT |
609 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
610 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
611 VK_MEMORY_INPUT_COPY_BIT*/,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600612 VkImageLayout image_layout)
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600613{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600614 const VkImageSubresourceRange subresourceRange = subresource_range(aspect, 0, 1, 0, 1);
615 VkImageMemoryBarrier barrier;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600616 barrier = image_memory_barrier(output_mask, input_mask, layout(), image_layout,
617 subresourceRange);
618
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600619 VkImageMemoryBarrier *pmemory_barrier = &barrier;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600620
Tony Barbour0b2cfb22015-06-29 16:20:35 -0600621 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
622 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600623
624 // write barrier to the command buffer
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -0600625 vkCmdPipelineBarrier(cmd_buf->handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600626}
627
Tony Barbour6918cd52015-04-09 12:58:51 -0600628void VkImageObj::SetLayout(VkCommandBufferObj *cmd_buf,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600629 VkImageAspect aspect,
630 VkImageLayout image_layout)
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600631{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600632 VkFlags output_mask, input_mask;
633 const VkFlags all_cache_outputs =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600634 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600635 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
636 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
637 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600638 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600639 const VkFlags all_cache_inputs =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600640 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600641 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
642 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
643 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
644 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
645 VK_MEMORY_INPUT_SHADER_READ_BIT |
646 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
647 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600648 VK_MEMORY_INPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600649
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800650 if (image_layout == m_descriptorInfo.imageLayout) {
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600651 return;
652 }
653
654 switch (image_layout) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600655 case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_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_TRANSFER_DESTINATION_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
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600665 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600666 output_mask = VK_MEMORY_OUTPUT_TRANSFER_BIT;
667 input_mask = VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_TRANSFER_BIT;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600668 break;
669
670 default:
671 output_mask = all_cache_outputs;
672 input_mask = all_cache_inputs;
673 break;
674 }
675
676 ImageMemoryBarrier(cmd_buf, aspect, output_mask, input_mask, image_layout);
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800677 m_descriptorInfo.imageLayout = image_layout;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600678}
679
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600680void VkImageObj::SetLayout(VkImageAspect aspect,
681 VkImageLayout image_layout)
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600682{
Tony Barbourf20f87b2015-04-22 09:02:32 -0600683 VkResult U_ASSERT_ONLY err;
Tony Barbour3d69c9e2015-05-20 16:53:31 -0600684
685 if (image_layout == m_descriptorInfo.imageLayout) {
686 return;
687 }
688
Tony Barbourfe3351b2015-07-28 10:17:20 -0600689 VkCmdPoolCreateInfo cmd_pool_info = {};
690 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
691 cmd_pool_info.pNext = NULL;
692 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
693 cmd_pool_info.flags = 0;
694 vk_testing::CmdPool pool(*m_device, cmd_pool_info);
695 VkCommandBufferObj cmd_buf(m_device, pool.handle());
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600696
697 /* Build command buffer to set image layout in the driver */
698 err = cmd_buf.BeginCommandBuffer();
699 assert(!err);
700
701 SetLayout(&cmd_buf, aspect, image_layout);
702
703 err = cmd_buf.EndCommandBuffer();
704 assert(!err);
705
706 cmd_buf.QueueCommandBuffer();
707}
708
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600709bool VkImageObj::IsCompatible(VkFlags usage, VkFlags features)
Tony Barbour579f7802015-04-03 15:11:43 -0600710{
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600711 if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) &&
Tony Barbourd1c35722015-04-16 15:59:00 -0600712 !(features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))
Tony Barbour579f7802015-04-03 15:11:43 -0600713 return false;
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600714
Tony Barbour579f7802015-04-03 15:11:43 -0600715 return true;
716}
717
Tony Barbour6918cd52015-04-09 12:58:51 -0600718void VkImageObj::init(uint32_t w, uint32_t h,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600719 VkFormat fmt, VkFlags usage,
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600720 VkImageTiling requested_tiling,
721 VkMemoryPropertyFlags reqs)
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800722{
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600723 uint32_t mipCount;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600724 VkFormatProperties image_fmt;
725 VkImageTiling tiling;
726 VkResult err;
Tony Barbour579f7802015-04-03 15:11:43 -0600727
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800728 mipCount = 0;
729
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600730 uint32_t _w = w;
731 uint32_t _h = h;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800732 while( ( _w > 0 ) || ( _h > 0 ) )
733 {
734 _w >>= 1;
735 _h >>= 1;
736 mipCount++;
737 }
738
Courtney Goeltzenleuchter2caec862015-07-12 12:52:09 -0600739 err = vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), fmt, &image_fmt);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600740 ASSERT_VK_SUCCESS(err);
Tony Barbour579f7802015-04-03 15:11:43 -0600741
Tony Barbourd1c35722015-04-16 15:59:00 -0600742 if (requested_tiling == VK_IMAGE_TILING_LINEAR) {
Tony Barbour579f7802015-04-03 15:11:43 -0600743 if (IsCompatible(usage, image_fmt.linearTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600744 tiling = VK_IMAGE_TILING_LINEAR;
Tony Barbour579f7802015-04-03 15:11:43 -0600745 } 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 {
748 ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration";
749 }
750 } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600751 tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbour579f7802015-04-03 15:11:43 -0600752 } else if (IsCompatible(usage, image_fmt.linearTilingFeatures)) {
Tony Barbourd1c35722015-04-16 15:59:00 -0600753 tiling = VK_IMAGE_TILING_LINEAR;
Tony Barbour579f7802015-04-03 15:11:43 -0600754 } else {
755 ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration";
756 }
757
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600758 VkImageCreateInfo imageCreateInfo = vk_testing::Image::create_info();
Tony Barbourd1c35722015-04-16 15:59:00 -0600759 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800760 imageCreateInfo.format = fmt;
761 imageCreateInfo.extent.width = w;
762 imageCreateInfo.extent.height = h;
763 imageCreateInfo.mipLevels = mipCount;
764 imageCreateInfo.tiling = tiling;
765
766 imageCreateInfo.usage = usage;
767
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600768 vk_testing::Image::init(*m_device, imageCreateInfo, reqs);
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800769
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600770 if (usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600771 SetLayout(VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600772 } else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600773 SetLayout(VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_GENERAL);
Courtney Goeltzenleuchterbe4f0cd2015-04-07 08:57:30 -0600774 }
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800775}
776
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600777VkResult VkImageObj::CopyImage(VkImageObj &src_image)
Tony Barbour5dc515d2015-04-01 17:47:06 -0600778{
Tony Barbourf20f87b2015-04-22 09:02:32 -0600779 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600780 VkImageLayout src_image_layout, dest_image_layout;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600781
Tony Barbourfe3351b2015-07-28 10:17:20 -0600782 VkCmdPoolCreateInfo cmd_pool_info = {};
783 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
784 cmd_pool_info.pNext = NULL;
785 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
786 cmd_pool_info.flags = 0;
787 vk_testing::CmdPool pool(*m_device, cmd_pool_info);
788 VkCommandBufferObj cmd_buf(m_device, pool.handle());
789
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600790 /* Build command buffer to copy staging texture to usable texture */
791 err = cmd_buf.BeginCommandBuffer();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600792 assert(!err);
793
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600794 /* TODO: Can we determine image aspect from image object? */
795 src_image_layout = src_image.layout();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600796 src_image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL);
Tony Barbour5dc515d2015-04-01 17:47:06 -0600797
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600798 dest_image_layout = this->layout();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600799 this->SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600800
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600801 VkImageCopy copy_region = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600802 copy_region.srcSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600803 copy_region.srcSubresource.arraySlice = 0;
804 copy_region.srcSubresource.mipLevel = 0;
805 copy_region.srcOffset.x = 0;
806 copy_region.srcOffset.y = 0;
807 copy_region.srcOffset.z = 0;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600808 copy_region.destSubresource.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600809 copy_region.destSubresource.arraySlice = 0;
810 copy_region.destSubresource.mipLevel = 0;
811 copy_region.destOffset.x = 0;
812 copy_region.destOffset.y = 0;
813 copy_region.destOffset.z = 0;
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600814 copy_region.extent = src_image.extent();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600815
Chia-I Wube2b9172015-07-03 11:49:42 +0800816 vkCmdCopyImage(cmd_buf.handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +0800817 src_image.handle(), src_image.layout(),
818 handle(), layout(),
Tony Barbour1c45ce02015-03-27 17:03:18 -0600819 1, &copy_region);
Tony Barbour5dc515d2015-04-01 17:47:06 -0600820
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600821 src_image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, src_image_layout);
Tony Barbour5dc515d2015-04-01 17:47:06 -0600822
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600823 this->SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR, dest_image_layout);
Tony Barbour1c45ce02015-03-27 17:03:18 -0600824
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600825 err = cmd_buf.EndCommandBuffer();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600826 assert(!err);
827
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600828 cmd_buf.QueueCommandBuffer();
Tony Barbour5dc515d2015-04-01 17:47:06 -0600829
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600830 return VK_SUCCESS;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600831}
832
Tony Barbour6918cd52015-04-09 12:58:51 -0600833VkTextureObj::VkTextureObj(VkDeviceObj *device, uint32_t *colors)
834 :VkImageObj(device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700835{
836 m_device = device;
Tony Barbourd1c35722015-04-16 15:59:00 -0600837 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tony Barbourebc093f2015-04-01 16:38:10 -0600838 uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 };
Tony Barbour5dc515d2015-04-01 17:47:06 -0600839 void *data;
840 int32_t x, y;
Tony Barbour6918cd52015-04-09 12:58:51 -0600841 VkImageObj stagingImage(device);
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600842 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600843
Tony Barboure65788f2015-07-21 17:01:42 -0600844 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 -0600845 VkSubresourceLayout layout = stagingImage.subresource_layout(subresource(VK_IMAGE_ASPECT_COLOR, 0, 0));
Tony Barbourebc093f2015-04-01 16:38:10 -0600846
847 if (colors == NULL)
848 colors = tex_colors;
Tony Barboure2c58df2014-11-25 13:18:32 -0700849
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800850 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700851
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600852 VkImageViewCreateInfo view = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600853 view.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600854 view.pNext = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600855 view.image = VK_NULL_HANDLE;
Tony Barbourd1c35722015-04-16 15:59:00 -0600856 view.viewType = VK_IMAGE_VIEW_TYPE_2D;
Tony Barbour5dc515d2015-04-01 17:47:06 -0600857 view.format = tex_format;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600858 view.channels.r = VK_CHANNEL_SWIZZLE_R;
859 view.channels.g = VK_CHANNEL_SWIZZLE_G;
860 view.channels.b = VK_CHANNEL_SWIZZLE_B;
861 view.channels.a = VK_CHANNEL_SWIZZLE_A;
862 view.subresourceRange.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbourbdf0a312015-04-01 17:10:07 -0600863 view.subresourceRange.baseMipLevel = 0;
864 view.subresourceRange.mipLevels = 1;
865 view.subresourceRange.baseArraySlice = 0;
866 view.subresourceRange.arraySize = 1;
Tony Barboure2c58df2014-11-25 13:18:32 -0700867
Tony Barboure2c58df2014-11-25 13:18:32 -0700868 /* create image */
Tony Barboure65788f2015-07-21 17:01:42 -0600869 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 -0700870
871 /* create image view */
Chia-I Wu681d7a02015-07-03 13:44:34 +0800872 view.image = handle();
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800873 m_textureView.init(*m_device, view);
Chia-I Wu3158bf32015-07-03 11:49:42 +0800874 m_descriptorInfo.imageView = m_textureView.handle();
Tony Barboure2c58df2014-11-25 13:18:32 -0700875
Chia-I Wu681d7a02015-07-03 13:44:34 +0800876 data = stagingImage.MapMemory();
Tony Barboure2c58df2014-11-25 13:18:32 -0700877
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800878 for (y = 0; y < extent().height; y++) {
Tony Barboure2c58df2014-11-25 13:18:32 -0700879 uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y);
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800880 for (x = 0; x < extent().width; x++)
Tony Barbourebc093f2015-04-01 16:38:10 -0600881 row[x] = colors[(x & 1) ^ (y & 1)];
Tony Barboure2c58df2014-11-25 13:18:32 -0700882 }
Chia-I Wu681d7a02015-07-03 13:44:34 +0800883 stagingImage.UnmapMemory();
Tony Barbour6918cd52015-04-09 12:58:51 -0600884 VkImageObj::CopyImage(stagingImage);
Tony Barboure2c58df2014-11-25 13:18:32 -0700885}
Tony Barbour82c39522014-12-04 14:33:33 -0700886
Tony Barbour6918cd52015-04-09 12:58:51 -0600887VkSamplerObj::VkSamplerObj(VkDeviceObj *device)
Tony Barboure2c58df2014-11-25 13:18:32 -0700888{
Tony Barboure2c58df2014-11-25 13:18:32 -0700889 m_device = device;
Tony Barboure2c58df2014-11-25 13:18:32 -0700890
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600891 VkSamplerCreateInfo samplerCreateInfo;
Chia-I Wue9864b52014-12-28 16:32:24 +0800892 memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600893 samplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
894 samplerCreateInfo.magFilter = VK_TEX_FILTER_NEAREST;
895 samplerCreateInfo.minFilter = VK_TEX_FILTER_NEAREST;
Tony Barbourd1c35722015-04-16 15:59:00 -0600896 samplerCreateInfo.mipMode = VK_TEX_MIPMAP_MODE_BASE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600897 samplerCreateInfo.addressU = VK_TEX_ADDRESS_WRAP;
898 samplerCreateInfo.addressV = VK_TEX_ADDRESS_WRAP;
899 samplerCreateInfo.addressW = VK_TEX_ADDRESS_WRAP;
Chia-I Wue9864b52014-12-28 16:32:24 +0800900 samplerCreateInfo.mipLodBias = 0.0;
Tony Barbour7ea6aa22015-05-22 09:44:58 -0600901 samplerCreateInfo.maxAnisotropy = 0;
Tony Barbourd1c35722015-04-16 15:59:00 -0600902 samplerCreateInfo.compareOp = VK_COMPARE_OP_NEVER;
Chia-I Wue9864b52014-12-28 16:32:24 +0800903 samplerCreateInfo.minLod = 0.0;
904 samplerCreateInfo.maxLod = 0.0;
Tony Barbour26b17f82015-06-25 16:56:44 -0600905 samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
Cody Northropab1f9e22015-08-11 15:50:55 -0600906 samplerCreateInfo.texelCoords = VK_FALSE;
Tony Barboure2c58df2014-11-25 13:18:32 -0700907
Chia-I Wue9864b52014-12-28 16:32:24 +0800908 init(*m_device, samplerCreateInfo);
Tony Barbourf325bf12014-12-03 15:59:38 -0700909}
Tony Barboure2c58df2014-11-25 13:18:32 -0700910
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700911/*
912 * Basic ConstantBuffer constructor. Then use create methods to fill in the details.
913 */
Tony Barbour6918cd52015-04-09 12:58:51 -0600914VkConstantBufferObj::VkConstantBufferObj(VkDeviceObj *device)
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700915{
916 m_device = device;
Tony Barbour38422802014-12-10 14:36:31 -0700917 m_commandBuffer = 0;
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700918
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800919 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700920}
921
Tony Barbour6918cd52015-04-09 12:58:51 -0600922VkConstantBufferObj::~VkConstantBufferObj()
Tony Barbour044703b2015-03-26 12:37:52 -0600923{
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600924 // TODO: Should we call QueueRemoveMemReference for the constant buffer memory here?
Tony Barbour044703b2015-03-26 12:37:52 -0600925 if (m_commandBuffer) {
926 delete m_commandBuffer;
Tony Barbour3d83f492015-07-28 10:23:02 -0600927 delete m_cmdPool;
Tony Barbour044703b2015-03-26 12:37:52 -0600928 }
929}
930
Tony Barbour6918cd52015-04-09 12:58:51 -0600931VkConstantBufferObj::VkConstantBufferObj(VkDeviceObj *device, int constantCount, int constantSize, const void* data)
Tony Barboure2c58df2014-11-25 13:18:32 -0700932{
Tony Barboure2c58df2014-11-25 13:18:32 -0700933 m_device = device;
Chia-I Wua07fee62014-12-28 15:26:08 +0800934 m_commandBuffer = 0;
935
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800936 memset(&m_descriptorInfo,0,sizeof(m_descriptorInfo));
Tony Barboure2c58df2014-11-25 13:18:32 -0700937 m_numVertices = constantCount;
938 m_stride = constantSize;
939
Tony Barbour4c97d7a2015-04-22 15:10:33 -0600940 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wua07fee62014-12-28 15:26:08 +0800941 const size_t allocationSize = constantCount * constantSize;
Cody Northrop7fb43862015-06-22 14:56:14 -0600942 init_as_src_and_dst(*m_device, allocationSize, reqs);
Tony Barboure2c58df2014-11-25 13:18:32 -0700943
Chia-I Wu681d7a02015-07-03 13:44:34 +0800944 void *pData = memory().map();
Chia-I Wua07fee62014-12-28 15:26:08 +0800945 memcpy(pData, data, allocationSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +0800946 memory().unmap();
Tony Barboure2c58df2014-11-25 13:18:32 -0700947
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800948 // set up the buffer view for the constant buffer
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600949 VkBufferViewCreateInfo view_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600950 view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
Chia-I Wu681d7a02015-07-03 13:44:34 +0800951 view_info.buffer = handle();
Tony Barbourd1c35722015-04-16 15:59:00 -0600952 view_info.viewType = VK_BUFFER_VIEW_TYPE_RAW;
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800953 view_info.offset = 0;
954 view_info.range = allocationSize;
955 m_bufferView.init(*m_device, view_info);
956
Chia-I Wu3158bf32015-07-03 11:49:42 +0800957 this->m_descriptorInfo.bufferView = m_bufferView.handle();
Tony Barboure2c58df2014-11-25 13:18:32 -0700958}
Tony Barbour82c39522014-12-04 14:33:33 -0700959
Tony Barbourd1c35722015-04-16 15:59:00 -0600960void VkConstantBufferObj::Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset, uint32_t binding)
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700961{
Chia-I Wu681d7a02015-07-03 13:44:34 +0800962 vkCmdBindVertexBuffers(cmdBuffer, binding, 1, &handle(), &offset);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700963}
964
965
Tony Barbour6918cd52015-04-09 12:58:51 -0600966void VkConstantBufferObj::BufferMemoryBarrier(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600967 VkFlags outputMask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600968 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600969 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
970 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
971 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
972 VK_MEMORY_OUTPUT_COPY_BIT*/,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600973 VkFlags inputMask /*=
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -0600974 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600975 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
976 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
977 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
978 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
979 VK_MEMORY_INPUT_SHADER_READ_BIT |
980 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
981 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
982 VK_MEMORY_INPUT_COPY_BIT*/)
Tony Barboure2c58df2014-11-25 13:18:32 -0700983{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600984 VkResult err = VK_SUCCESS;
Tony Barbour38422802014-12-10 14:36:31 -0700985
Tony Barbour38422802014-12-10 14:36:31 -0700986 if (!m_commandBuffer)
987 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600988 m_fence.init(*m_device, vk_testing::Fence::create_info());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600989 VkCmdPoolCreateInfo cmd_pool_info = {};
990 cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
991 cmd_pool_info.pNext = NULL;
992 cmd_pool_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
993 cmd_pool_info.flags = 0;
994 m_cmdPool = new vk_testing::CmdPool(*m_device, cmd_pool_info);
995 m_commandBuffer = new VkCommandBufferObj(m_device, m_cmdPool->handle());
Tony Barbour38422802014-12-10 14:36:31 -0700996 }
997 else
998 {
Chia-I Wua07fee62014-12-28 15:26:08 +0800999 m_device->wait(m_fence);
Tony Barbour38422802014-12-10 14:36:31 -07001000 }
1001
Tony Barboure2c58df2014-11-25 13:18:32 -07001002 // open the command buffer
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001003 VkCmdBufferBeginInfo cmd_buf_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001004 cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
Tony Barbourbdf0a312015-04-01 17:10:07 -06001005 cmd_buf_info.pNext = NULL;
1006 cmd_buf_info.flags = 0;
Cody Northropcc09b9e2015-08-11 11:35:58 -06001007 cmd_buf_info.renderPass = VK_NULL_HANDLE;
1008 cmd_buf_info.subpass = 0;
1009 cmd_buf_info.framebuffer = VK_NULL_HANDLE;
Tony Barbourbdf0a312015-04-01 17:10:07 -06001010
Jon Ashburnc4164b12014-12-31 17:10:47 -07001011 err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001012 ASSERT_VK_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -07001013
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001014 VkBufferMemoryBarrier memory_barrier =
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001015 buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001016 VkBufferMemoryBarrier *pmemory_barrier = &memory_barrier;
Tony Barboure2c58df2014-11-25 13:18:32 -07001017
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001018 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1019 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001020
1021 // write barrier to the command buffer
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001022 m_commandBuffer->PipelineBarrier(src_stages, dest_stages, false, 1, (const void **)&pmemory_barrier);
Tony Barboure2c58df2014-11-25 13:18:32 -07001023
1024 // finish recording the command buffer
Tony Barbour471338d2014-12-10 17:28:39 -07001025 err = m_commandBuffer->EndCommandBuffer();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001026 ASSERT_VK_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -07001027
Tony Barboure2c58df2014-11-25 13:18:32 -07001028 // submit the command buffer to the universal queue
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001029 VkCmdBuffer bufferArray[1];
Tony Barbour471338d2014-12-10 17:28:39 -07001030 bufferArray[0] = m_commandBuffer->GetBufferHandle();
Chia-I Wud9e8e822015-07-03 11:45:55 +08001031 err = vkQueueSubmit( m_device->m_queue, 1, bufferArray, m_fence.handle() );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001032 ASSERT_VK_SUCCESS(err);
Tony Barboure2c58df2014-11-25 13:18:32 -07001033}
1034
Tony Barbour6918cd52015-04-09 12:58:51 -06001035VkIndexBufferObj::VkIndexBufferObj(VkDeviceObj *device)
1036 : VkConstantBufferObj(device)
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001037{
1038
1039}
1040
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001041void VkIndexBufferObj::CreateAndInitBuffer(int numIndexes, VkIndexType indexType, const void* data)
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001042{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001043 VkFormat viewFormat;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001044
1045 m_numVertices = numIndexes;
1046 m_indexType = indexType;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001047 switch (indexType) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001048 case VK_INDEX_TYPE_UINT16:
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001049 m_stride = 2;
Tony Barbourd1c35722015-04-16 15:59:00 -06001050 viewFormat = VK_FORMAT_R16_UINT;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001051 break;
Tony Barbourd1c35722015-04-16 15:59:00 -06001052 case VK_INDEX_TYPE_UINT32:
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001053 m_stride = 4;
Tony Barbourd1c35722015-04-16 15:59:00 -06001054 viewFormat = VK_FORMAT_R32_UINT;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001055 break;
Chia-I Wub4c2aa42014-12-15 23:50:11 +08001056 default:
1057 assert(!"unknown index type");
Tony Barbourf20f87b2015-04-22 09:02:32 -06001058 m_stride = 2;
1059 viewFormat = VK_FORMAT_R16_UINT;
Chia-I Wub4c2aa42014-12-15 23:50:11 +08001060 break;
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001061 }
1062
Chia-I Wua07fee62014-12-28 15:26:08 +08001063 const size_t allocationSize = numIndexes * m_stride;
Tony Barbour4c97d7a2015-04-22 15:10:33 -06001064 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Cody Northrop7fb43862015-06-22 14:56:14 -06001065 init_as_src_and_dst(*m_device, allocationSize, reqs);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001066
Chia-I Wu681d7a02015-07-03 13:44:34 +08001067 void *pData = memory().map();
Chia-I Wua07fee62014-12-28 15:26:08 +08001068 memcpy(pData, data, allocationSize);
Chia-I Wu681d7a02015-07-03 13:44:34 +08001069 memory().unmap();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001070
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001071 // set up the buffer view for the constant buffer
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001072 VkBufferViewCreateInfo view_info = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001073 view_info.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
Chia-I Wu681d7a02015-07-03 13:44:34 +08001074 view_info.buffer = handle();
Tony Barbourd1c35722015-04-16 15:59:00 -06001075 view_info.viewType = VK_BUFFER_VIEW_TYPE_FORMATTED;
Jeremy Hayesa058eee2015-01-23 08:51:43 -07001076 view_info.format = viewFormat;
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001077 view_info.offset = 0;
1078 view_info.range = allocationSize;
1079 m_bufferView.init(*m_device, view_info);
1080
Chia-I Wu3158bf32015-07-03 11:49:42 +08001081 this->m_descriptorInfo.bufferView = m_bufferView.handle();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001082}
1083
Tony Barbourd1c35722015-04-16 15:59:00 -06001084void VkIndexBufferObj::Bind(VkCmdBuffer cmdBuffer, VkDeviceSize offset)
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001085{
Chia-I Wu681d7a02015-07-03 13:44:34 +08001086 vkCmdBindIndexBuffer(cmdBuffer, handle(), offset, m_indexType);
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -07001087}
Tony Barboure2c58df2014-11-25 13:18:32 -07001088
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001089VkIndexType VkIndexBufferObj::GetIndexType()
Tony Barbouraf1f9192014-12-17 10:57:58 -07001090{
1091 return m_indexType;
1092}
1093
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001094VkPipelineShaderStageCreateInfo* VkShaderObj::GetStageCreateInfo()
Tony Barboure2c58df2014-11-25 13:18:32 -07001095{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001096 VkPipelineShaderStageCreateInfo *stageInfo = (VkPipelineShaderStageCreateInfo*) calloc( 1,sizeof(VkPipelineShaderStageCreateInfo) );
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001097 stageInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
1098 stageInfo->stage = m_stage;
Chia-I Wu4d0c7922015-07-03 11:49:42 +08001099 stageInfo->shader = handle();
Tony Barboure2c58df2014-11-25 13:18:32 -07001100
Tony Barboure2c58df2014-11-25 13:18:32 -07001101 return stageInfo;
1102}
1103
Tony Barbourd1c35722015-04-16 15:59:00 -06001104VkShaderObj::VkShaderObj(VkDeviceObj *device, const char * shader_code, VkShaderStage stage, VkRenderFramework *framework)
Tony Barboure2c58df2014-11-25 13:18:32 -07001105{
Tony Barbourb5d2c942015-07-14 13:34:05 -06001106 VkResult U_ASSERT_ONLY err = VK_SUCCESS;
Cody Northrop3bfd27c2015-03-17 15:55:58 -06001107 std::vector<unsigned int> spv;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001108 VkShaderCreateInfo createInfo;
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001109 VkShaderModuleCreateInfo moduleCreateInfo;
Tony Barbour823e6ca2015-07-27 13:31:04 -06001110 vk_testing::ShaderModule *module = new vk_testing::ShaderModule();
Tony Barboure2c58df2014-11-25 13:18:32 -07001111 size_t shader_len;
1112
1113 m_stage = stage;
1114 m_device = device;
1115
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001116 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
1117 moduleCreateInfo.pNext = NULL;
1118
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001119 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
Tony Barboure2c58df2014-11-25 13:18:32 -07001120 createInfo.pNext = NULL;
1121
Cody Northrop50a2a4b2015-06-03 16:49:20 -06001122 if (framework->m_use_glsl) {
Tony Barboure2c58df2014-11-25 13:18:32 -07001123
1124 shader_len = strlen(shader_code);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001125 moduleCreateInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1;
1126 moduleCreateInfo.pCode = malloc(moduleCreateInfo.codeSize);
1127 moduleCreateInfo.flags = 0;
Tony Barboure2c58df2014-11-25 13:18:32 -07001128
Tony Barbourd1c35722015-04-16 15:59:00 -06001129 /* try version 0 first: VkShaderStage followed by GLSL */
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001130 ((uint32_t *) moduleCreateInfo.pCode)[0] = ICD_SPV_MAGIC;
1131 ((uint32_t *) moduleCreateInfo.pCode)[1] = 0;
1132 ((uint32_t *) moduleCreateInfo.pCode)[2] = stage;
1133 memcpy(((uint32_t *) moduleCreateInfo.pCode + 3), shader_code, shader_len + 1);
Tony Barboure2c58df2014-11-25 13:18:32 -07001134
Cody Northrop50a2a4b2015-06-03 16:49:20 -06001135 } else {
Tony Barboure2c58df2014-11-25 13:18:32 -07001136
Cody Northrop3bfd27c2015-03-17 15:55:58 -06001137 // Use Reference GLSL to SPV compiler
1138 framework->GLSLtoSPV(stage, shader_code, spv);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001139 moduleCreateInfo.pCode = spv.data();
1140 moduleCreateInfo.codeSize = spv.size() * sizeof(unsigned int);
1141 moduleCreateInfo.flags = 0;
Chia-I Wubabc0fd2014-12-29 14:14:03 +08001142 }
Cody Northrop475663c2015-04-15 11:19:06 -06001143
Tony Barbour823e6ca2015-07-27 13:31:04 -06001144 err = module->init_try(*m_device, moduleCreateInfo);
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001145 assert(VK_SUCCESS == err);
Cody Northrop50a2a4b2015-06-03 16:49:20 -06001146
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001147 createInfo.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO;
1148 createInfo.pNext = NULL;
Tony Barbour823e6ca2015-07-27 13:31:04 -06001149 createInfo.module = module->handle();
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001150 createInfo.pName = "main";
1151 createInfo.flags = 0;
Cody Northropfd4bcfd2015-08-24 15:11:10 -06001152 createInfo.stage = stage;
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001153
1154 err = init_try(*m_device, createInfo);
Cody Northrop475663c2015-04-15 11:19:06 -06001155 assert(VK_SUCCESS == err);
Tony Barbour823e6ca2015-07-27 13:31:04 -06001156 framework->m_shader_modules.push_back(module);
Tony Barbourf325bf12014-12-03 15:59:38 -07001157}
Tony Barbour82c39522014-12-04 14:33:33 -07001158
Tony Barbour6918cd52015-04-09 12:58:51 -06001159VkPipelineObj::VkPipelineObj(VkDeviceObj *device)
Tony Barboure2c58df2014-11-25 13:18:32 -07001160{
Tony Barboure2c58df2014-11-25 13:18:32 -07001161 m_device = device;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001162
1163 m_vi_state.pNext = VK_NULL_HANDLE;
1164 m_vi_state.bindingCount = 0;
1165 m_vi_state.pVertexBindingDescriptions = VK_NULL_HANDLE;
1166 m_vi_state.attributeCount = 0;
1167 m_vi_state.pVertexAttributeDescriptions = VK_NULL_HANDLE;
1168
Tony Barboure2c58df2014-11-25 13:18:32 -07001169 m_vertexBufferCount = 0;
1170
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001171 m_ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001172 m_ia_state.pNext = VK_NULL_HANDLE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001173 m_ia_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001174 m_ia_state.primitiveRestartEnable = VK_FALSE;
Tony Barboure2c58df2014-11-25 13:18:32 -07001175
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001176 m_rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001177 m_rs_state.pNext = VK_NULL_HANDLE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001178 m_rs_state.depthClipEnable = VK_FALSE;
1179 m_rs_state.rasterizerDiscardEnable = VK_FALSE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001180 m_rs_state.fillMode = VK_FILL_MODE_SOLID;
Courtney Goeltzenleuchter43fb2c72015-04-30 17:44:12 -06001181 m_rs_state.cullMode = VK_CULL_MODE_BACK;
1182 m_rs_state.frontFace = VK_FRONT_FACE_CW;
Cody Northrop12365112015-08-17 11:10:49 -06001183 m_rs_state.depthBiasEnable = VK_FALSE;
Tony Barboure2c58df2014-11-25 13:18:32 -07001184
Tony Barboure2c58df2014-11-25 13:18:32 -07001185 memset(&m_cb_state,0,sizeof(m_cb_state));
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001186 m_cb_state.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001187 m_cb_state.pNext = VK_NULL_HANDLE;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001188 m_cb_state.alphaToCoverageEnable = VK_FALSE;
1189 m_cb_state.logicOp = VK_LOGIC_OP_COPY;
Tony Barboure2c58df2014-11-25 13:18:32 -07001190
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001191 m_ms_state.pNext = VK_NULL_HANDLE;
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001192 m_ms_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Cody Northrop02e61ed2015-08-04 14:34:54 -06001193 m_ms_state.pSampleMask = NULL;
Tony Barbourdfd533a2015-06-26 10:18:34 -06001194 m_ms_state.rasterSamples = 1;
Tony Barbourf52346d2015-01-16 14:27:35 -07001195 m_ms_state.minSampleShading = 0;
1196 m_ms_state.sampleShadingEnable = 0;
Tony Barboure2c58df2014-11-25 13:18:32 -07001197
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001198 m_vp_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001199 m_vp_state.pNext = VK_NULL_HANDLE;
Tony Barbourd81b8882015-05-15 09:37:57 -06001200 m_vp_state.viewportCount = 1;
Tony Barbourd81b8882015-05-15 09:37:57 -06001201
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001202 m_ds_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001203 m_ds_state.pNext = VK_NULL_HANDLE,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001204 m_ds_state.depthTestEnable = VK_FALSE;
1205 m_ds_state.depthWriteEnable = VK_FALSE;
Cody Northrop271ba752015-08-26 10:01:32 -06001206 m_ds_state.depthBoundsTestEnable = VK_FALSE;
Tony Barbourd1c35722015-04-16 15:59:00 -06001207 m_ds_state.depthCompareOp = VK_COMPARE_OP_LESS_EQUAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001208 m_ds_state.back.stencilDepthFailOp = VK_STENCIL_OP_KEEP;
1209 m_ds_state.back.stencilFailOp = VK_STENCIL_OP_KEEP;
1210 m_ds_state.back.stencilPassOp = VK_STENCIL_OP_KEEP;
Tony Barbourd1c35722015-04-16 15:59:00 -06001211 m_ds_state.back.stencilCompareOp = VK_COMPARE_OP_ALWAYS;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001212 m_ds_state.stencilTestEnable = VK_FALSE;
Tony Barbourf52346d2015-01-16 14:27:35 -07001213 m_ds_state.front = m_ds_state.back;
Tony Barboure2c58df2014-11-25 13:18:32 -07001214};
1215
Tony Barbour6918cd52015-04-09 12:58:51 -06001216void VkPipelineObj::AddShader(VkShaderObj* shader)
Tony Barboure2c58df2014-11-25 13:18:32 -07001217{
1218 m_shaderObjs.push_back(shader);
1219}
1220
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001221void VkPipelineObj::AddVertexInputAttribs(VkVertexInputAttributeDescription* vi_attrib, int count)
Tony Barboure2c58df2014-11-25 13:18:32 -07001222{
1223 m_vi_state.pVertexAttributeDescriptions = vi_attrib;
1224 m_vi_state.attributeCount = count;
1225}
1226
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001227void VkPipelineObj::AddVertexInputBindings(VkVertexInputBindingDescription* vi_binding, int count)
Tony Barboure2c58df2014-11-25 13:18:32 -07001228{
1229 m_vi_state.pVertexBindingDescriptions = vi_binding;
1230 m_vi_state.bindingCount = count;
1231}
1232
Tony Barbour6918cd52015-04-09 12:58:51 -06001233void VkPipelineObj::AddVertexDataBuffer(VkConstantBufferObj* vertexDataBuffer, int binding)
Tony Barboure2c58df2014-11-25 13:18:32 -07001234{
1235 m_vertexBufferObjs.push_back(vertexDataBuffer);
1236 m_vertexBufferBindings.push_back(binding);
1237 m_vertexBufferCount++;
1238}
1239
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001240void VkPipelineObj::AddColorAttachment(uint32_t binding, const VkPipelineColorBlendAttachmentState *att)
Chia-I Wuecebf752014-12-05 10:45:15 +08001241{
Tony Barbourf52346d2015-01-16 14:27:35 -07001242 if (binding+1 > m_colorAttachments.size())
1243 {
1244 m_colorAttachments.resize(binding+1);
1245 }
1246 m_colorAttachments[binding] = *att;
1247}
1248
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001249void VkPipelineObj::SetDepthStencil(VkPipelineDepthStencilStateCreateInfo *ds_state)
Tony Barbourf52346d2015-01-16 14:27:35 -07001250{
Tony Barbourf52346d2015-01-16 14:27:35 -07001251 m_ds_state.depthTestEnable = ds_state->depthTestEnable;
1252 m_ds_state.depthWriteEnable = ds_state->depthWriteEnable;
Cody Northrop271ba752015-08-26 10:01:32 -06001253 m_ds_state.depthBoundsTestEnable = ds_state->depthBoundsTestEnable;
Tony Barbourd1c35722015-04-16 15:59:00 -06001254 m_ds_state.depthCompareOp = ds_state->depthCompareOp;
Tony Barbourf52346d2015-01-16 14:27:35 -07001255 m_ds_state.stencilTestEnable = ds_state->stencilTestEnable;
1256 m_ds_state.back = ds_state->back;
1257 m_ds_state.front = ds_state->front;
Chia-I Wuecebf752014-12-05 10:45:15 +08001258}
1259
Tony Barbour0ec8cd52015-08-06 09:27:11 -06001260void VkPipelineObj::SetMSAA(VkPipelineMultisampleStateCreateInfo *ms_state)
1261{
1262 memcpy(&m_ms_state, ms_state, sizeof(VkPipelineMultisampleStateCreateInfo));
1263}
1264
Tony Barbour5781e8f2015-08-04 16:23:11 -06001265VkResult VkPipelineObj::CreateVKPipeline(VkPipelineLayout layout, VkRenderPass render_pass)
Tony Barbour976e1cf2014-12-17 11:57:31 -07001266{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001267 VkGraphicsPipelineCreateInfo info = {};
Tony Barbour976e1cf2014-12-17 11:57:31 -07001268
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001269 VkPipelineShaderStageCreateInfo* shaderCreateInfo;
Tony Barbour976e1cf2014-12-17 11:57:31 -07001270
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001271 info.stageCount = m_shaderObjs.size();
1272 info.pStages = new VkPipelineShaderStageCreateInfo[info.stageCount];
1273
Tony Barbour976e1cf2014-12-17 11:57:31 -07001274 for (int i=0; i<m_shaderObjs.size(); i++)
1275 {
Chia-I Wu11078b02015-01-04 16:27:24 +08001276 shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo();
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001277 memcpy((void*)&info.pStages[i], shaderCreateInfo, sizeof(VkPipelineShaderStageCreateInfo));
Tony Barbour976e1cf2014-12-17 11:57:31 -07001278 }
1279
Tony Barboure815fd72015-07-27 09:36:24 -06001280 if (m_vi_state.attributeCount && m_vi_state.bindingCount) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001281 m_vi_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Tony Barboure815fd72015-07-27 09:36:24 -06001282 info.pVertexInputState = &m_vi_state;
1283 } else {
1284 info.pVertexInputState = NULL;
Tony Barbour976e1cf2014-12-17 11:57:31 -07001285 }
1286
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001287 info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001288 info.pNext = NULL;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001289 info.flags = 0;
Tony Barbour5781e8f2015-08-04 16:23:11 -06001290 info.layout = layout;
Tony Barbour976e1cf2014-12-17 11:57:31 -07001291
Tony Barbourf52346d2015-01-16 14:27:35 -07001292 m_cb_state.attachmentCount = m_colorAttachments.size();
Tony Barbour482c6092015-07-27 09:37:48 -06001293 m_cb_state.pAttachments = m_colorAttachments.data();
Tony Barbourf52346d2015-01-16 14:27:35 -07001294
Chia-I Wu08accc62015-07-07 11:50:03 +08001295 info.renderPass = render_pass;
1296 info.subpass = 0;
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001297 info.pTessellationState = NULL;
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001298 info.pInputAssemblyState = &m_ia_state;
1299 info.pViewportState = &m_vp_state;
1300 info.pRasterState = &m_rs_state;
1301 info.pMultisampleState = &m_ms_state;
1302 info.pDepthStencilState = &m_ds_state;
1303 info.pColorBlendState = &m_cb_state;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001304
Chris Forbes95292b12015-05-25 11:13:26 +12001305 return init_try(*m_device, info);
Tony Barbour976e1cf2014-12-17 11:57:31 -07001306}
Chia-I Wu2648d092014-12-29 14:24:14 +08001307
Tony Barbourfe3351b2015-07-28 10:17:20 -06001308VkCommandBufferObj::VkCommandBufferObj(VkDeviceObj *device, VkCmdPool pool)
Tony Barbour6d047bf2014-12-10 14:34:45 -07001309{
Tony Barbour6d047bf2014-12-10 14:34:45 -07001310 m_device = device;
Courtney Goeltzenleuchter0c8385b2015-07-13 12:57:11 -06001311
Tony Barbourfe3351b2015-07-28 10:17:20 -06001312 init(*device, vk_testing::CmdBuffer::create_info(pool));
Tony Barbour6d047bf2014-12-10 14:34:45 -07001313}
Tony Barbour471338d2014-12-10 17:28:39 -07001314
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001315VkCmdBuffer VkCommandBufferObj::GetBufferHandle()
Tony Barbour6d047bf2014-12-10 14:34:45 -07001316{
Chia-I Wube2b9172015-07-03 11:49:42 +08001317 return handle();
Tony Barbour6d047bf2014-12-10 14:34:45 -07001318}
Tony Barbour471338d2014-12-10 17:28:39 -07001319
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001320VkResult VkCommandBufferObj::BeginCommandBuffer(VkCmdBufferBeginInfo *pInfo)
Tony Barbour471338d2014-12-10 17:28:39 -07001321{
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001322 begin(pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001323 return VK_SUCCESS;
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001324}
1325
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001326VkResult VkCommandBufferObj::BeginCommandBuffer()
Jeremy Hayesd65ae082015-01-14 16:17:08 -07001327{
1328 begin();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001329 return VK_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001330}
1331
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001332VkResult VkCommandBufferObj::EndCommandBuffer()
Tony Barbour471338d2014-12-10 17:28:39 -07001333{
Chia-I Wud28343c2014-12-28 15:12:48 +08001334 end();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001335 return VK_SUCCESS;
Tony Barbour471338d2014-12-10 17:28:39 -07001336}
1337
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001338void VkCommandBufferObj::PipelineBarrier(VkPipelineStageFlags src_stages, VkPipelineStageFlags dest_stages, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tony Barbour471338d2014-12-10 17:28:39 -07001339{
Chia-I Wube2b9172015-07-03 11:49:42 +08001340 vkCmdPipelineBarrier(handle(), src_stages, dest_stages, byRegion, memBarrierCount, ppMemBarriers);
Tony Barbour471338d2014-12-10 17:28:39 -07001341}
1342
Chris Forbesf0796e12015-06-24 14:34:53 +12001343void VkCommandBufferObj::ClearAllBuffers(VkClearColorValue clear_color, float depth_clear_color, uint32_t stencil_clear_color,
Tony Barbour6918cd52015-04-09 12:58:51 -06001344 VkDepthStencilObj *depthStencilObj)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001345{
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001346 uint32_t i;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001347 const VkFlags output_mask =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -06001348 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001349 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1350 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1351 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -06001352 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001353 const VkFlags input_mask = 0;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001354
1355 // whatever we want to do, we do it to the whole buffer
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001356 VkImageSubresourceRange srRange = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001357 srRange.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001358 srRange.baseMipLevel = 0;
Courtney Goeltzenleuchter13dbde02015-08-28 16:47:15 -06001359 srRange.mipLevels = VK_REMAINING_MIP_LEVELS;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001360 srRange.baseArraySlice = 0;
Courtney Goeltzenleuchter13dbde02015-08-28 16:47:15 -06001361 srRange.arraySize = VK_REMAINING_ARRAY_SLICES;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001362
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001363 VkImageMemoryBarrier memory_barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001364 memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001365 memory_barrier.outputMask = output_mask;
1366 memory_barrier.inputMask = input_mask;
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001367 memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001368 memory_barrier.subresourceRange = srRange;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001369 VkImageMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001370
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001371 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1372 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001373
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -07001374 for (i = 0; i < m_renderTargets.size(); i++) {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001375 memory_barrier.image = m_renderTargets[i]->image();
1376 memory_barrier.oldLayout = m_renderTargets[i]->layout();
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001377 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001378 m_renderTargets[i]->layout(memory_barrier.newLayout);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001379
Chia-I Wube2b9172015-07-03 11:49:42 +08001380 vkCmdClearColorImage(handle(),
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001381 m_renderTargets[i]->image(), VK_IMAGE_LAYOUT_GENERAL,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001382 &clear_color, 1, &srRange );
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001383
Tony Barbour30cc9e82014-12-17 11:53:55 -07001384 }
1385
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001386 if (depthStencilObj)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001387 {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001388 VkImageSubresourceRange dsRange = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001389 dsRange.aspect = VK_IMAGE_ASPECT_DEPTH;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001390 dsRange.baseMipLevel = 0;
Courtney Goeltzenleuchter13dbde02015-08-28 16:47:15 -06001391 dsRange.mipLevels = VK_REMAINING_MIP_LEVELS;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001392 dsRange.baseArraySlice = 0;
Courtney Goeltzenleuchter13dbde02015-08-28 16:47:15 -06001393 dsRange.arraySize = VK_REMAINING_ARRAY_SLICES;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001394
1395 // prepare the depth buffer for clear
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001396
Cody Northrop3cc85e92015-08-04 10:47:08 -06001397 memory_barrier.oldLayout = memory_barrier.newLayout;
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001398 memory_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Chia-I Wu681d7a02015-07-03 13:44:34 +08001399 memory_barrier.image = depthStencilObj->handle();
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001400 memory_barrier.subresourceRange = dsRange;
1401
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001402 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001403
Chia-I Wube2b9172015-07-03 11:49:42 +08001404 vkCmdClearDepthStencilImage(handle(),
Chia-I Wu681d7a02015-07-03 13:44:34 +08001405 depthStencilObj->handle(), VK_IMAGE_LAYOUT_GENERAL,
Chris Forbesd9be82b2015-06-22 17:21:59 +12001406 depth_clear_color, stencil_clear_color,
1407 1, &dsRange);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001408
1409 // prepare depth buffer for rendering
Chia-I Wu681d7a02015-07-03 13:44:34 +08001410 memory_barrier.image = depthStencilObj->handle();
Cody Northrop3cc85e92015-08-04 10:47:08 -06001411 memory_barrier.newLayout = memory_barrier.oldLayout;
Mark Lobodzinski2b3fa3d2015-07-01 15:18:26 -06001412 memory_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001413 memory_barrier.subresourceRange = dsRange;
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001414 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001415 }
1416}
1417
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001418void VkCommandBufferObj::FillBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize fill_size, uint32_t data)
1419{
1420 vkCmdFillBuffer( handle(), buffer, offset, fill_size, data);
1421}
1422
Tony Barbour6918cd52015-04-09 12:58:51 -06001423void VkCommandBufferObj::PrepareAttachments()
Tony Barbour30cc9e82014-12-17 11:53:55 -07001424{
Mark Lobodzinski17caf572015-01-29 08:55:56 -06001425 uint32_t i;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001426 const VkFlags output_mask =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -06001427 VK_MEMORY_OUTPUT_HOST_WRITE_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001428 VK_MEMORY_OUTPUT_SHADER_WRITE_BIT |
1429 VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT |
1430 VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -06001431 VK_MEMORY_OUTPUT_TRANSFER_BIT;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001432 const VkFlags input_mask =
Courtney Goeltzenleuchterf69f8a22015-04-29 17:16:21 -06001433 VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001434 VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
1435 VK_MEMORY_INPUT_INDEX_FETCH_BIT |
1436 VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT |
1437 VK_MEMORY_INPUT_UNIFORM_READ_BIT |
1438 VK_MEMORY_INPUT_SHADER_READ_BIT |
1439 VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
1440 VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -06001441 VK_MEMORY_INPUT_TRANSFER_BIT;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001442
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001443 VkImageSubresourceRange srRange = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001444 srRange.aspect = VK_IMAGE_ASPECT_COLOR;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001445 srRange.baseMipLevel = 0;
Courtney Goeltzenleuchter13dbde02015-08-28 16:47:15 -06001446 srRange.mipLevels = VK_REMAINING_MIP_LEVELS;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001447 srRange.baseArraySlice = 0;
Courtney Goeltzenleuchter13dbde02015-08-28 16:47:15 -06001448 srRange.arraySize = VK_REMAINING_ARRAY_SLICES;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001449
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001450 VkImageMemoryBarrier memory_barrier = {};
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001451 memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001452 memory_barrier.outputMask = output_mask;
1453 memory_barrier.inputMask = input_mask;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001454 memory_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001455 memory_barrier.subresourceRange = srRange;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001456 VkImageMemoryBarrier *pmemory_barrier = &memory_barrier;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001457
Tony Barbour0b2cfb22015-06-29 16:20:35 -06001458 VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
1459 VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_ALL_GPU_COMMANDS;
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001460
Courtney Goeltzenleuchterb4337c12015-03-05 16:47:18 -07001461 for(i=0; i<m_renderTargets.size(); i++)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001462 {
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001463 memory_barrier.image = m_renderTargets[i]->image();
1464 memory_barrier.oldLayout = m_renderTargets[i]->layout();
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06001465 vkCmdPipelineBarrier( handle(), src_stages, dest_stages, false, 1, (const void * const*)&pmemory_barrier);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001466 m_renderTargets[i]->layout(memory_barrier.newLayout);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001467 }
Tony Barbour30cc9e82014-12-17 11:53:55 -07001468}
1469
Chia-I Wu08accc62015-07-07 11:50:03 +08001470void VkCommandBufferObj::BeginRenderPass(const VkRenderPassBeginInfo &info)
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001471{
Chia-I Wube2b9172015-07-03 11:49:42 +08001472 vkCmdBeginRenderPass( handle(), &info, VK_RENDER_PASS_CONTENTS_INLINE);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001473}
1474
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08001475void VkCommandBufferObj::EndRenderPass()
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001476{
Chia-I Wube2b9172015-07-03 11:49:42 +08001477 vkCmdEndRenderPass(handle());
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001478}
1479
Tony Barbour67e99152015-07-10 14:10:27 -06001480void VkCommandBufferObj::BindDynamicViewportState(VkDynamicViewportState viewportState)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001481{
Tony Barbour67e99152015-07-10 14:10:27 -06001482 vkCmdBindDynamicViewportState( handle(), viewportState);
1483}
1484
Cody Northrop271ba752015-08-26 10:01:32 -06001485void VkCommandBufferObj::BindDynamicLineWidthState(VkDynamicLineWidthState lineWidthState)
Tony Barbour67e99152015-07-10 14:10:27 -06001486{
Cody Northrop271ba752015-08-26 10:01:32 -06001487 vkCmdBindDynamicLineWidthState( handle(), lineWidthState);
Cody Northrop12365112015-08-17 11:10:49 -06001488}
1489
Cody Northrop271ba752015-08-26 10:01:32 -06001490void VkCommandBufferObj::BindDynamicDepthBiasState(VkDynamicDepthBiasState depthBiasState)
Cody Northrop12365112015-08-17 11:10:49 -06001491{
Cody Northrop271ba752015-08-26 10:01:32 -06001492 vkCmdBindDynamicDepthBiasState( handle(), depthBiasState);
Tony Barbour67e99152015-07-10 14:10:27 -06001493}
1494
Cody Northrop271ba752015-08-26 10:01:32 -06001495void VkCommandBufferObj::BindDynamicBlendState(VkDynamicBlendState blendState)
Tony Barbour67e99152015-07-10 14:10:27 -06001496{
Cody Northrop271ba752015-08-26 10:01:32 -06001497 vkCmdBindDynamicBlendState( handle(), blendState);
Tony Barbour67e99152015-07-10 14:10:27 -06001498}
1499
Cody Northrop271ba752015-08-26 10:01:32 -06001500void VkCommandBufferObj::BindDynamicDepthBoundsState(VkDynamicDepthBoundsState depthBoundsState)
Tony Barbour67e99152015-07-10 14:10:27 -06001501{
Cody Northrop271ba752015-08-26 10:01:32 -06001502 vkCmdBindDynamicDepthBoundsState( handle(), depthBoundsState);
Cody Northrop82485a82015-08-18 15:21:16 -06001503}
1504
1505void VkCommandBufferObj::BindDynamicStencilState(VkDynamicStencilState stencilState)
1506{
1507 vkCmdBindDynamicStencilState( handle(), stencilState);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001508}
1509
Tony Barbour6918cd52015-04-09 12:58:51 -06001510void VkCommandBufferObj::AddRenderTarget(VkImageObj *renderTarget)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001511{
1512 m_renderTargets.push_back(renderTarget);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001513}
1514
Tony Barbour6918cd52015-04-09 12:58:51 -06001515void VkCommandBufferObj::DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001516{
Chia-I Wube2b9172015-07-03 11:49:42 +08001517 vkCmdDrawIndexed(handle(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001518}
1519
Tony Barbour6918cd52015-04-09 12:58:51 -06001520void VkCommandBufferObj::Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001521{
Chia-I Wube2b9172015-07-03 11:49:42 +08001522 vkCmdDraw(handle(), firstVertex, vertexCount, firstInstance, instanceCount);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001523}
1524
Tony Barbour6918cd52015-04-09 12:58:51 -06001525void VkCommandBufferObj::QueueCommandBuffer()
Tony Barbour30cc9e82014-12-17 11:53:55 -07001526{
Tony Barbour67e99152015-07-10 14:10:27 -06001527 VkFence nullFence = { VK_NULL_HANDLE };
1528 QueueCommandBuffer(nullFence);
Tony Barbour09b7ac32015-04-08 10:11:29 -06001529}
1530
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001531void VkCommandBufferObj::QueueCommandBuffer(VkFence fence)
Tony Barbour09b7ac32015-04-08 10:11:29 -06001532{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001533 VkResult err = VK_SUCCESS;
Tony Barbour30cc9e82014-12-17 11:53:55 -07001534
1535 // submit the command buffer to the universal queue
Chia-I Wube2b9172015-07-03 11:49:42 +08001536 err = vkQueueSubmit( m_device->m_queue, 1, &handle(), fence );
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001537 ASSERT_VK_SUCCESS( err );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001538
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001539 err = vkQueueWaitIdle( m_device->m_queue );
1540 ASSERT_VK_SUCCESS( err );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001541
1542 // Wait for work to finish before cleaning up.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001543 vkDeviceWaitIdle(m_device->device());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001544}
1545
Tony Barbour6918cd52015-04-09 12:58:51 -06001546void VkCommandBufferObj::BindPipeline(VkPipelineObj &pipeline)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001547{
Chia-I Wube2b9172015-07-03 11:49:42 +08001548 vkCmdBindPipeline( handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.handle() );
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001549}
1550
Tony Barbour6918cd52015-04-09 12:58:51 -06001551void VkCommandBufferObj::BindDescriptorSet(VkDescriptorSetObj &descriptorSet)
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001552{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001553 VkDescriptorSet set_obj = descriptorSet.GetDescriptorSetHandle();
Chia-I Wu53f07d72015-03-28 15:23:55 +08001554
Chia-I Wu1a28fe02015-01-01 07:55:04 +08001555 // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view)
Chia-I Wube2b9172015-07-03 11:49:42 +08001556 vkCmdBindDescriptorSets(handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, descriptorSet.GetPipelineLayout(),
Cody Northropd4c1a502015-04-16 13:41:56 -06001557 0, 1, &set_obj, 0, NULL );
Tony Barbour30cc9e82014-12-17 11:53:55 -07001558}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001559
Cody Northropd2ad0342015-08-05 11:15:02 -06001560void VkCommandBufferObj::BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001561{
Chia-I Wu681d7a02015-07-03 13:44:34 +08001562 vkCmdBindIndexBuffer(handle(), indexBuffer->handle(), offset, indexBuffer->GetIndexType());
Tony Barbour30cc9e82014-12-17 11:53:55 -07001563}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001564
Tony Barbourd1c35722015-04-16 15:59:00 -06001565void VkCommandBufferObj::BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding)
Tony Barbour30cc9e82014-12-17 11:53:55 -07001566{
Chia-I Wu681d7a02015-07-03 13:44:34 +08001567 vkCmdBindVertexBuffers(handle(), binding, 1, &vertexBuffer->handle(), &offset);
Tony Barbour30cc9e82014-12-17 11:53:55 -07001568}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001569
Tony Barbour6918cd52015-04-09 12:58:51 -06001570VkDepthStencilObj::VkDepthStencilObj()
Tony Barbour1c45ce02015-03-27 17:03:18 -06001571{
1572 m_initialized = false;
1573}
Tony Barbour6918cd52015-04-09 12:58:51 -06001574bool VkDepthStencilObj::Initialized()
Tony Barbour1c45ce02015-03-27 17:03:18 -06001575{
1576 return m_initialized;
1577}
1578
Cody Northrop3cc85e92015-08-04 10:47:08 -06001579VkAttachmentView* VkDepthStencilObj::BindInfo()
Tony Barbour1c45ce02015-03-27 17:03:18 -06001580{
Chia-I Wu08accc62015-07-07 11:50:03 +08001581 return &m_attachmentBindInfo;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001582}
1583
Chia-I Wu08accc62015-07-07 11:50:03 +08001584void VkDepthStencilObj::Init(VkDeviceObj *device, int32_t width, int32_t height, VkFormat format)
Tony Barbour1c45ce02015-03-27 17:03:18 -06001585{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001586 VkImageCreateInfo image_info;
Chia-I Wu08accc62015-07-07 11:50:03 +08001587 VkAttachmentViewCreateInfo view_info;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001588
1589 m_device = device;
1590 m_initialized = true;
Chia-I Wu08accc62015-07-07 11:50:03 +08001591 m_depth_stencil_fmt = format;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001592
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001593 image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001594 image_info.pNext = NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -06001595 image_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001596 image_info.format = m_depth_stencil_fmt;
1597 image_info.extent.width = width;
1598 image_info.extent.height = height;
1599 image_info.extent.depth = 1;
1600 image_info.mipLevels = 1;
1601 image_info.arraySize = 1;
1602 image_info.samples = 1;
Tony Barbourd1c35722015-04-16 15:59:00 -06001603 image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001604 image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_BIT;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001605 image_info.flags = 0;
Tony Barbour3d83f492015-07-28 10:23:02 -06001606 image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1607 image_info.queueFamilyCount = 0;
1608 image_info.pQueueFamilyIndices = NULL;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001609 init(*m_device, image_info);
1610
Chia-I Wu08accc62015-07-07 11:50:03 +08001611 view_info.sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001612 view_info.pNext = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001613 view_info.image = VK_NULL_HANDLE;
Tony Barbour1c45ce02015-03-27 17:03:18 -06001614 view_info.mipLevel = 0;
1615 view_info.baseArraySlice = 0;
1616 view_info.arraySize = 1;
1617 view_info.flags = 0;
Tony Barbour3d83f492015-07-28 10:23:02 -06001618 view_info.format = m_depth_stencil_fmt;
Chia-I Wu681d7a02015-07-03 13:44:34 +08001619 view_info.image = handle();
Chia-I Wu08accc62015-07-07 11:50:03 +08001620 m_attachmentView.init(*m_device, view_info);
Tony Barbour1c45ce02015-03-27 17:03:18 -06001621
Cody Northrop3cc85e92015-08-04 10:47:08 -06001622 m_attachmentBindInfo = m_attachmentView.handle();
Tony Barbour1c45ce02015-03-27 17:03:18 -06001623}