blob: a54fec71b21fb2391f16501978c46135eeef507e [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
37#include "vkrenderframework.h"
Tobin Ehlise2eeffa2016-09-21 17:32:26 -060038#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060039
Mark Lobodzinski3780e142015-05-14 15:08:13 -050040#define GLM_FORCE_RADIANS
41#include "glm/glm.hpp"
42#include <glm/gtc/matrix_transform.hpp>
43
Dustin Gravesffa90fa2016-05-06 11:20:38 -060044#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060045#define MEM_TRACKER_TESTS 1
46#define OBJ_TRACKER_TESTS 1
47#define DRAW_STATE_TESTS 1
48#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120049#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060050#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060051#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060052
Mark Lobodzinski3780e142015-05-14 15:08:13 -050053//--------------------------------------------------------------------------------------
54// Mesh and VertexFormat Data
55//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070056struct Vertex {
57 float posX, posY, posZ, posW; // Position data
58 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059};
60
Karl Schultz6addd812016-02-02 17:17:23 -070061#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050062
63typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070064 BsoFailNone = 0x00000000,
65 BsoFailLineWidth = 0x00000001,
66 BsoFailDepthBias = 0x00000002,
67 BsoFailViewport = 0x00000004,
68 BsoFailScissor = 0x00000008,
69 BsoFailBlend = 0x00000010,
70 BsoFailDepthBounds = 0x00000020,
71 BsoFailStencilReadMask = 0x00000040,
72 BsoFailStencilWriteMask = 0x00000080,
73 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060074 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060075 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050076} BsoFailSelect;
77
78struct vktriangle_vs_uniform {
79 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070080 float mvp[4][4];
81 float position[3][4];
82 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050083};
84
Mark Lobodzinskice751c62016-09-08 10:45:35 -060085static const char bindStateVertShaderText[] = "#version 450\n"
86 "vec2 vertices[3];\n"
87 "out gl_PerVertex {\n"
88 " vec4 gl_Position;\n"
89 "};\n"
90 "void main() {\n"
91 " vertices[0] = vec2(-1.0, -1.0);\n"
92 " vertices[1] = vec2( 1.0, -1.0);\n"
93 " vertices[2] = vec2( 0.0, 1.0);\n"
94 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060097static const char bindStateFragShaderText[] = "#version 450\n"
98 "\n"
99 "layout(location = 0) out vec4 uFragColor;\n"
100 "void main(){\n"
101 " uFragColor = vec4(0,1,0,1);\n"
102 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500103
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600104static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
105 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
106 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600107
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600108// ********************************************************
109// ErrorMonitor Usage:
110//
111// Call SetDesiredFailureMsg with a string to be compared against all
112// encountered log messages. Passing NULL will match all log messages.
113// logMsg will return true for skipCall only if msg is matched or NULL.
114//
115// Call DesiredMsgFound to determine if the desired failure message
116// was encountered.
117
Tony Barbour300a6082015-04-07 13:44:53 -0600118class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700119 public:
120 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600121 test_platform_thread_create_mutex(&m_mutex);
122 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200123 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700124 m_bailout = NULL;
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_desiredMsgSet = false;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600127 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600128
Dustin Graves48458142016-04-29 16:11:55 -0600129 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
130
Karl Schultz6addd812016-02-02 17:17:23 -0700131 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200132 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600133 test_platform_thread_lock_mutex(&m_mutex);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600134 m_failureMsgs.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 m_otherMsgs.clear();
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600136 m_desiredMsgs.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700137 m_msgFound = VK_FALSE;
138 m_msgFlags = msgFlags;
Chris Forbes17756132016-09-16 14:36:39 +1200139 m_desiredMsgSet = true;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600140 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600141 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600142
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600143 VkBool32 CheckForDesiredMsg(const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600144 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600145 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600146 if (m_bailout != NULL) {
147 *m_bailout = true;
148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600150 bool found_expected = false;
151 for (auto desired_msg : m_desiredMsgs) {
152 if (errorString.find(desired_msg) != string::npos) {
153 found_expected = true;
154 m_failureMsgs.insert(errorString);
155 m_msgFound = VK_TRUE;
156 result = VK_TRUE;
157 // We only want one match for each expected error so remove from set here
158 // Since we're about the break the loop it's ok to remove from set we're iterating over
159 m_desiredMsgs.erase(desired_msg);
160 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600162 }
163 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200164 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600165 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600167 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600168 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600169 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600170
Karl Schultz6addd812016-02-02 17:17:23 -0700171 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600172
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600173 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
174
Karl Schultz6addd812016-02-02 17:17:23 -0700175 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600176
Karl Schultz6addd812016-02-02 17:17:23 -0700177 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600178
Karl Schultz6addd812016-02-02 17:17:23 -0700179 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600180 vector<string> otherMsgs = GetOtherFailureMsgs();
181 cout << "Other error messages logged for this test were:" << endl;
182 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
183 cout << " " << *iter << endl;
184 }
185 }
186
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600187 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200188
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600189 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
190 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
191 m_msgFlags = message_flag_mask;
192 // Match ANY message matching specified type
193 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200194 }
195
196 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600197 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200198 if (!DesiredMsgFound()) {
199 DumpFailureMsgs();
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600200 for (auto desired_msg : m_desiredMsgs) {
201 FAIL() << "Did not receive expected error '" << desired_msg << "'";
202 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200203 }
204 }
205
206 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200208 if (DesiredMsgFound()) {
209 DumpFailureMsgs();
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 for (auto msg : m_failureMsgs) {
211 FAIL() << "Expected to succeed but got error: " << msg;
212 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200213 }
214 }
215
Karl Schultz6addd812016-02-02 17:17:23 -0700216 private:
217 VkFlags m_msgFlags;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600218 std::unordered_set<string> m_desiredMsgs;
219 std::unordered_set<string> m_failureMsgs;
Karl Schultz6addd812016-02-02 17:17:23 -0700220 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600221 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700222 bool *m_bailout;
223 VkBool32 m_msgFound;
Chris Forbes17756132016-09-16 14:36:39 +1200224 bool m_desiredMsgSet;
Tony Barbour300a6082015-04-07 13:44:53 -0600225};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500226
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600227static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
228 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
229 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600230 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
231 if (msgFlags & errMonitor->GetMessageFlags()) {
232 return errMonitor->CheckForDesiredMsg(pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600233 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600234 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600235}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500236
Karl Schultz6addd812016-02-02 17:17:23 -0700237class VkLayerTest : public VkRenderFramework {
238 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800239 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
240 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600241 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
242 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700243 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600244 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
245 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700246 }
Tony Barbour300a6082015-04-07 13:44:53 -0600247
Tony Barbourfe3351b2015-07-28 10:17:20 -0600248 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600249 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800250 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600251 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
252 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700253 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600254 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700255 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600256 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700257 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600258 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
259 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
260 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600273 std::vector<const char *> instance_extension_names;
274 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700276 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600277 /*
278 * Since CreateDbgMsgCallback is an instance level extension call
279 * any extension / layer that utilizes that feature also needs
280 * to be enabled at create instance time.
281 */
Karl Schultz6addd812016-02-02 17:17:23 -0700282 // Use Threading layer first to protect others from
283 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700284 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600285 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800286 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700287 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800288 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600289 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700290 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600291
Ian Elliott2c1daf52016-05-12 09:41:46 -0600292 if (m_enableWSI) {
293 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
294 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
295#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
296#if defined(VK_USE_PLATFORM_ANDROID_KHR)
297 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
298#endif // VK_USE_PLATFORM_ANDROID_KHR
299#if defined(VK_USE_PLATFORM_MIR_KHR)
300 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
301#endif // VK_USE_PLATFORM_MIR_KHR
302#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
303 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
304#endif // VK_USE_PLATFORM_WAYLAND_KHR
305#if defined(VK_USE_PLATFORM_WIN32_KHR)
306 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
307#endif // VK_USE_PLATFORM_WIN32_KHR
308#endif // NEED_TO_TEST_THIS_ON_PLATFORM
309#if defined(VK_USE_PLATFORM_XCB_KHR)
310 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
311#elif defined(VK_USE_PLATFORM_XLIB_KHR)
312 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
313#endif // VK_USE_PLATFORM_XLIB_KHR
314 }
315
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600316 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600317 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800318 this->app_info.pApplicationName = "layer_tests";
319 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600320 this->app_info.pEngineName = "unittest";
321 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600322 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600323
Tony Barbour15524c32015-04-29 17:34:29 -0600324 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600325 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600326 }
327
328 virtual void TearDown() {
329 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600330 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600331 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600332 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600333
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600334 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600335};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500336
Karl Schultz6addd812016-02-02 17:17:23 -0700337VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600338 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600339
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800340 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600341
342 /*
343 * For render test all drawing happens in a single render pass
344 * on a single command buffer.
345 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200346 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800347 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600348 }
349
350 return result;
351}
352
Karl Schultz6addd812016-02-02 17:17:23 -0700353VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600354 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600355
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200356 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800357 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200358 }
Tony Barbour300a6082015-04-07 13:44:53 -0600359
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800360 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600361
362 return result;
363}
364
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600365void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500366 // Create identity matrix
367 int i;
368 struct vktriangle_vs_uniform data;
369
370 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700371 glm::mat4 View = glm::mat4(1.0f);
372 glm::mat4 Model = glm::mat4(1.0f);
373 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500374 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700375 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500376
377 memcpy(&data.mvp, &MVP[0][0], matrixSize);
378
Karl Schultz6addd812016-02-02 17:17:23 -0700379 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600380 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500381 };
382
Karl Schultz6addd812016-02-02 17:17:23 -0700383 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500384 data.position[i][0] = tri_data[i].posX;
385 data.position[i][1] = tri_data[i].posY;
386 data.position[i][2] = tri_data[i].posZ;
387 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700388 data.color[i][0] = tri_data[i].r;
389 data.color[i][1] = tri_data[i].g;
390 data.color[i][2] = tri_data[i].b;
391 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392 }
393
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394 ASSERT_NO_FATAL_FAILURE(InitViewport());
395
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200396 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
397 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500398
Karl Schultz6addd812016-02-02 17:17:23 -0700399 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600400 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500401
402 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800403 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500404 pipelineobj.AddShader(&vs);
405 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600406 if (failMask & BsoFailLineWidth) {
407 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600408 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600410 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
411 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600412 }
413 if (failMask & BsoFailDepthBias) {
414 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600415 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600417 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600418 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600419 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600420 }
Karl Schultz6addd812016-02-02 17:17:23 -0700421 // Viewport and scissors must stay in synch or other errors will occur than
422 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600423 if (failMask & BsoFailViewport) {
424 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
425 }
426 if (failMask & BsoFailScissor) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
428 }
429 if (failMask & BsoFailBlend) {
430 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600431 VkPipelineColorBlendAttachmentState att_state = {};
432 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
433 att_state.blendEnable = VK_TRUE;
434 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600435 }
436 if (failMask & BsoFailDepthBounds) {
437 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
438 }
439 if (failMask & BsoFailStencilReadMask) {
440 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
441 }
442 if (failMask & BsoFailStencilWriteMask) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
444 }
445 if (failMask & BsoFailStencilReference) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
447 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500448
449 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600450 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451
452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600453 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500454
Tony Barbourfe3351b2015-07-28 10:17:20 -0600455 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500456
457 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600458 if (failMask & BsoFailIndexBuffer) {
459 // Use DrawIndexed w/o an index buffer bound
460 DrawIndexed(3, 1, 0, 0, 0);
461 } else {
462 Draw(3, 1, 0, 0);
463 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464
Mark Muellerd4914412016-06-13 17:52:06 -0600465 if (failMask & BsoFailCmdClearAttachments) {
466 VkClearAttachment color_attachment = {};
467 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
468 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
469 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
470
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600471 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600472 }
473
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600475 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476
Tony Barbourfe3351b2015-07-28 10:17:20 -0600477 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478}
479
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600480void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
481 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600485 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486 }
487
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800488 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700489 // Make sure depthWriteEnable is set so that Depth fail test will work
490 // correctly
491 // Make sure stencilTestEnable is set so that Stencil fail test will work
492 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600493 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800494 stencil.failOp = VK_STENCIL_OP_KEEP;
495 stencil.passOp = VK_STENCIL_OP_KEEP;
496 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
497 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600498
499 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
500 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600501 ds_ci.pNext = NULL;
502 ds_ci.depthTestEnable = VK_FALSE;
503 ds_ci.depthWriteEnable = VK_TRUE;
504 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
505 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600506 if (failMask & BsoFailDepthBounds) {
507 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600508 ds_ci.maxDepthBounds = 0.0f;
509 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600510 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600511 ds_ci.stencilTestEnable = VK_TRUE;
512 ds_ci.front = stencil;
513 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600514
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600515 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600516 pipelineobj.SetViewport(m_viewports);
517 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800518 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600519 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600520 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800521 commandBuffer->BindPipeline(pipelineobj);
522 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523}
524
Ian Elliott2c1daf52016-05-12 09:41:46 -0600525class VkWsiEnabledLayerTest : public VkLayerTest {
526 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600527 protected:
528 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600529};
530
Mark Muellerdfe37552016-07-07 14:47:42 -0600531class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600533 enum eTestEnFlags {
534 eDoubleDelete,
535 eInvalidDeviceOffset,
536 eInvalidMemoryOffset,
537 eBindNullBuffer,
538 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600539 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600540 };
541
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600542 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600543
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
545 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600546 return true;
547 }
548 VkDeviceSize offset_limit = 0;
549 if (eInvalidMemoryOffset == aTestFlag) {
550 VkBuffer vulkanBuffer;
551 VkBufferCreateInfo buffer_create_info = {};
552 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
553 buffer_create_info.size = 32;
554 buffer_create_info.usage = aBufferUsage;
555
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600556 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600557 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600558
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600559 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600560 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
561 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600562 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
563 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600564 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600565 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600566 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600568 }
569 if (eOffsetAlignment < offset_limit) {
570 return true;
571 }
572 return false;
573 }
574
575 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600576 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
577 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600578
579 if (eBindNullBuffer == aTestFlag) {
580 VulkanMemory = 0;
581 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
582 } else {
583 VkBufferCreateInfo buffer_create_info = {};
584 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
585 buffer_create_info.size = 32;
586 buffer_create_info.usage = aBufferUsage;
587
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600588 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600589
590 CreateCurrent = true;
591
592 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600594
595 VkMemoryAllocateInfo memory_allocate_info = {};
596 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
597 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
599 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 if (!pass) {
601 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
602 return;
603 }
604
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600605 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600606 AllocateCurrent = true;
607 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600608 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
609 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600610 BoundCurrent = true;
611
612 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
613 }
614 }
615
616 ~VkBufferTest() {
617 if (CreateCurrent) {
618 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
619 }
620 if (AllocateCurrent) {
621 if (InvalidDeleteEn) {
622 union {
623 VkDeviceMemory device_memory;
624 unsigned long long index_access;
625 } bad_index;
626
627 bad_index.device_memory = VulkanMemory;
628 bad_index.index_access++;
629
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 }
632 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
633 }
634 }
635
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600636 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600637
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600638 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600639
640 void TestDoubleDestroy() {
641 // Destroy the buffer but leave the flag set, which will cause
642 // the buffer to be destroyed again in the destructor.
643 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
644 }
645
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600646 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600647 bool AllocateCurrent;
648 bool BoundCurrent;
649 bool CreateCurrent;
650 bool InvalidDeleteEn;
651
652 VkBuffer VulkanBuffer;
653 VkDevice VulkanDevice;
654 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655};
656
657class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600658 public:
659 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600661 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600662 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
664 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600665 BindIdGenerator++; // NB: This can wrap w/misuse
666
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
668 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600669
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600670 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
671 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
672 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
673 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
674 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600675
676 unsigned i = 0;
677 do {
678 VertexInputAttributeDescription[i].binding = BindId;
679 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600680 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
681 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600682 i++;
683 } while (AttributeCount < i);
684
685 i = 0;
686 do {
687 VertexInputBindingDescription[i].binding = BindId;
688 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600689 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600690 i++;
691 } while (BindingCount < i);
692 }
693
694 ~VkVerticesObj() {
695 if (VertexInputAttributeDescription) {
696 delete[] VertexInputAttributeDescription;
697 }
698 if (VertexInputBindingDescription) {
699 delete[] VertexInputBindingDescription;
700 }
701 }
702
703 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
705 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600706 return true;
707 }
708
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600709 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600710 VkDeviceSize *offsetList;
711 unsigned offsetCount;
712
713 if (aOffsetCount) {
714 offsetList = aOffsetList;
715 offsetCount = aOffsetCount;
716 } else {
717 offsetList = new VkDeviceSize[1]();
718 offsetCount = 1;
719 }
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600722 BoundCurrent = true;
723
724 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600725 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600726 }
727 }
728
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600729 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600730 static uint32_t BindIdGenerator;
731
732 bool BoundCurrent;
733 unsigned AttributeCount;
734 unsigned BindingCount;
735 uint32_t BindId;
736
737 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
738 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
739 VkVertexInputBindingDescription *VertexInputBindingDescription;
740 VkConstantBufferObj VulkanMemoryBuffer;
741};
742
743uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500744// ********************************************************************************************************************
745// ********************************************************************************************************************
746// ********************************************************************************************************************
747// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600748#if PARAMETER_VALIDATION_TESTS
749TEST_F(VkLayerTest, RequiredParameter) {
750 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
751 "pointer, array, and array count parameters");
752
753 ASSERT_NO_FATAL_FAILURE(InitState());
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600756 // Specify NULL for a pointer to a handle
757 // Expected to trigger an error with
758 // parameter_validation::validate_required_pointer
759 vkGetPhysicalDeviceFeatures(gpu(), NULL);
760 m_errorMonitor->VerifyFound();
761
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
763 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600764 // Specify NULL for pointer to array count
765 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600766 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600767 m_errorMonitor->VerifyFound();
768
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600770 // Specify 0 for a required array count
771 // Expected to trigger an error with parameter_validation::validate_array
772 VkViewport view_port = {};
773 m_commandBuffer->SetViewport(0, 0, &view_port);
774 m_errorMonitor->VerifyFound();
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600777 // Specify NULL for a required array
778 // Expected to trigger an error with parameter_validation::validate_array
779 m_commandBuffer->SetViewport(0, 1, NULL);
780 m_errorMonitor->VerifyFound();
781
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600783 // Specify VK_NULL_HANDLE for a required handle
784 // Expected to trigger an error with
785 // parameter_validation::validate_required_handle
786 vkUnmapMemory(device(), VK_NULL_HANDLE);
787 m_errorMonitor->VerifyFound();
788
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
790 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600791 // Specify VK_NULL_HANDLE for a required handle array entry
792 // Expected to trigger an error with
793 // parameter_validation::validate_required_handle_array
794 VkFence fence = VK_NULL_HANDLE;
795 vkResetFences(device(), 1, &fence);
796 m_errorMonitor->VerifyFound();
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600799 // Specify NULL for a required struct pointer
800 // Expected to trigger an error with
801 // parameter_validation::validate_struct_type
802 VkDeviceMemory memory = VK_NULL_HANDLE;
803 vkAllocateMemory(device(), NULL, NULL, &memory);
804 m_errorMonitor->VerifyFound();
805
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600807 // Specify 0 for a required VkFlags parameter
808 // Expected to trigger an error with parameter_validation::validate_flags
809 m_commandBuffer->SetStencilReference(0, 0);
810 m_errorMonitor->VerifyFound();
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify 0 for a required VkFlags array entry
814 // Expected to trigger an error with
815 // parameter_validation::validate_flags_array
816 VkSemaphore semaphore = VK_NULL_HANDLE;
817 VkPipelineStageFlags stageFlags = 0;
818 VkSubmitInfo submitInfo = {};
819 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
820 submitInfo.waitSemaphoreCount = 1;
821 submitInfo.pWaitSemaphores = &semaphore;
822 submitInfo.pWaitDstStageMask = &stageFlags;
823 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
824 m_errorMonitor->VerifyFound();
825}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600826
Dustin Gravesfce74c02016-05-10 11:42:58 -0600827TEST_F(VkLayerTest, ReservedParameter) {
828 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600833 // Specify 0 for a reserved VkFlags parameter
834 // Expected to trigger an error with
835 // parameter_validation::validate_reserved_flags
836 VkEvent event_handle = VK_NULL_HANDLE;
837 VkEventCreateInfo event_info = {};
838 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
839 event_info.flags = 1;
840 vkCreateEvent(device(), &event_info, NULL, &event_handle);
841 m_errorMonitor->VerifyFound();
842}
843
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600844TEST_F(VkLayerTest, InvalidStructSType) {
845 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
846 "structure's sType field");
847
848 ASSERT_NO_FATAL_FAILURE(InitState());
849
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600851 // Zero struct memory, effectively setting sType to
852 // VK_STRUCTURE_TYPE_APPLICATION_INFO
853 // Expected to trigger an error with
854 // parameter_validation::validate_struct_type
855 VkMemoryAllocateInfo alloc_info = {};
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600861 // Zero struct memory, effectively setting sType to
862 // VK_STRUCTURE_TYPE_APPLICATION_INFO
863 // Expected to trigger an error with
864 // parameter_validation::validate_struct_type_array
865 VkSubmitInfo submit_info = {};
866 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
867 m_errorMonitor->VerifyFound();
868}
869
870TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600871 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600872
873 ASSERT_NO_FATAL_FAILURE(InitState());
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600876 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
Karl Schultz38b50992016-07-11 16:09:09 -0600877 // NULL.
878 // Need to pick a function that has no allowed pNext structure types.
879 // Expected to trigger an error with
880 // parameter_validation::validate_struct_pnext
881 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600882 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600883 // Zero-initialization will provide the correct sType
884 VkApplicationInfo app_info = {};
885 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
886 event_alloc_info.pNext = &app_info;
887 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
888 m_errorMonitor->VerifyFound();
889
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
891 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600892 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
893 // a function that has allowed pNext structure types and specify
894 // a structure type that is not allowed.
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 // Expected to trigger an error with
896 // parameter_validation::validate_struct_pnext
897 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600898 VkMemoryAllocateInfo memory_alloc_info = {};
899 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
900 memory_alloc_info.pNext = &app_info;
901 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600902 m_errorMonitor->VerifyFound();
903
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600904 // Positive test to check parameter_validation and unique_objects support
905 // for NV_dedicated_allocation
906 uint32_t extension_count = 0;
907 bool supports_nv_dedicated_allocation = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600908 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600909 ASSERT_VK_SUCCESS(err);
910
911 if (extension_count > 0) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600912 std::vector<VkExtensionProperties> available_extensions(extension_count);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600915 ASSERT_VK_SUCCESS(err);
916
917 for (const auto &extension_props : available_extensions) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600919 supports_nv_dedicated_allocation = true;
920 }
921 }
922 }
923
924 if (supports_nv_dedicated_allocation) {
925 m_errorMonitor->ExpectSuccess();
926
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600927 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
928 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600929 dedicated_buffer_create_info.pNext = nullptr;
930 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
931
932 uint32_t queue_family_index = 0;
933 VkBufferCreateInfo buffer_create_info = {};
934 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
935 buffer_create_info.pNext = &dedicated_buffer_create_info;
936 buffer_create_info.size = 1024;
937 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
938 buffer_create_info.queueFamilyIndexCount = 1;
939 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
940
941 VkBuffer buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600943 ASSERT_VK_SUCCESS(err);
944
945 VkMemoryRequirements memory_reqs;
946 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
947
948 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600949 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600950 dedicated_memory_info.pNext = nullptr;
951 dedicated_memory_info.buffer = buffer;
952 dedicated_memory_info.image = VK_NULL_HANDLE;
953
954 VkMemoryAllocateInfo memory_info = {};
955 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
956 memory_info.pNext = &dedicated_memory_info;
957 memory_info.allocationSize = memory_reqs.size;
958
959 bool pass;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600961 ASSERT_TRUE(pass);
962
963 VkDeviceMemory buffer_memory;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Gravesfd1c8fe2016-07-15 11:40:20 -0600965 ASSERT_VK_SUCCESS(err);
966
967 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
968 ASSERT_VK_SUCCESS(err);
969
970 vkDestroyBuffer(m_device->device(), buffer, NULL);
971 vkFreeMemory(m_device->device(), buffer_memory, NULL);
972
973 m_errorMonitor->VerifyNotFound();
974 }
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600975}
Dustin Graves5d33d532016-05-09 16:21:12 -0600976
977TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979
980 ASSERT_NO_FATAL_FAILURE(InitState());
981
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
983 "range of the core VkFormat "
984 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 // Specify an invalid VkFormat value
986 // Expected to trigger an error with
987 // parameter_validation::validate_ranged_enum
988 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600989 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600990 m_errorMonitor->VerifyFound();
991
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600993 // Specify an invalid VkFlags bitmask value
994 // Expected to trigger an error with parameter_validation::validate_flags
995 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
997 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600998 m_errorMonitor->VerifyFound();
999
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001001 // Specify an invalid VkFlags array entry
1002 // Expected to trigger an error with
1003 // parameter_validation::validate_flags_array
1004 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001005 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001006 VkSubmitInfo submit_info = {};
1007 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1008 submit_info.waitSemaphoreCount = 1;
1009 submit_info.pWaitSemaphores = &semaphore;
1010 submit_info.pWaitDstStageMask = &stage_flags;
1011 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1012 m_errorMonitor->VerifyFound();
1013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001015 // Specify an invalid VkBool32 value
1016 // Expected to trigger a warning with
1017 // parameter_validation::validate_bool32
1018 VkSampler sampler = VK_NULL_HANDLE;
1019 VkSamplerCreateInfo sampler_info = {};
1020 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1021 sampler_info.pNext = NULL;
1022 sampler_info.magFilter = VK_FILTER_NEAREST;
1023 sampler_info.minFilter = VK_FILTER_NEAREST;
1024 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1025 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1026 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1027 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1028 sampler_info.mipLodBias = 1.0;
1029 sampler_info.maxAnisotropy = 1;
1030 sampler_info.compareEnable = VK_FALSE;
1031 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1032 sampler_info.minLod = 1.0;
1033 sampler_info.maxLod = 1.0;
1034 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1035 sampler_info.unnormalizedCoordinates = VK_FALSE;
1036 // Not VK_TRUE or VK_FALSE
1037 sampler_info.anisotropyEnable = 3;
1038 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1039 m_errorMonitor->VerifyFound();
1040}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001041
1042TEST_F(VkLayerTest, FailedReturnValue) {
1043 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1044
1045 ASSERT_NO_FATAL_FAILURE(InitState());
1046
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 // Find an unsupported image format
1048 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1049 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1050 VkFormat format = static_cast<VkFormat>(f);
1051 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001053 unsupported = format;
1054 break;
1055 }
1056 }
1057
1058 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1060 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001061 // Specify an unsupported VkFormat value to generate a
1062 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1063 // Expected to trigger a warning from
1064 // parameter_validation::validate_result
1065 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001066 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1067 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001068 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1069 m_errorMonitor->VerifyFound();
1070 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001071}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001072
1073TEST_F(VkLayerTest, UpdateBufferAlignment) {
1074 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076
1077 ASSERT_NO_FATAL_FAILURE(InitState());
1078
1079 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1080 vk_testing::Buffer buffer;
1081 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1082
1083 BeginCommandBuffer();
1084 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001086 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1087 m_errorMonitor->VerifyFound();
1088
1089 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is < 0
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1098 m_errorMonitor->VerifyFound();
1099
1100 // Introduce failure by using dataSize that is > 65536
1101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001102 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001103 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1104 m_errorMonitor->VerifyFound();
1105
1106 EndCommandBuffer();
1107}
1108
1109TEST_F(VkLayerTest, FillBufferAlignment) {
1110 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1111
1112 ASSERT_NO_FATAL_FAILURE(InitState());
1113
1114 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1115 vk_testing::Buffer buffer;
1116 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1117
1118 BeginCommandBuffer();
1119
1120 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001122 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1123 m_errorMonitor->VerifyFound();
1124
1125 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001127 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1128 m_errorMonitor->VerifyFound();
1129
1130 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001132 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1133 m_errorMonitor->VerifyFound();
1134
1135 EndCommandBuffer();
1136}
Dustin Graves40f35822016-06-23 11:12:53 -06001137
1138// This is a positive test. No failures are expected.
1139TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) {
1140 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code "
1141 "is ignoring VkWriteDescriptorSet members that are not "
1142 "related to the descriptor type specified by "
1143 "VkWriteDescriptorSet::descriptorType. Correct "
1144 "validation behavior will result in the test running to "
1145 "completion without validation errors.");
1146
Dustin Graves5e2d8fc2016-07-07 16:18:49 -06001147 const uintptr_t invalid_ptr = 0xcdcdcdcd;
1148
Dustin Graves40f35822016-06-23 11:12:53 -06001149 ASSERT_NO_FATAL_FAILURE(InitState());
1150
1151 // Image Case
1152 {
1153 m_errorMonitor->ExpectSuccess();
1154
1155 VkImage image;
1156 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1157 const int32_t tex_width = 32;
1158 const int32_t tex_height = 32;
1159 VkImageCreateInfo image_create_info = {};
1160 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1161 image_create_info.pNext = NULL;
1162 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1163 image_create_info.format = tex_format;
1164 image_create_info.extent.width = tex_width;
1165 image_create_info.extent.height = tex_height;
1166 image_create_info.extent.depth = 1;
1167 image_create_info.mipLevels = 1;
1168 image_create_info.arrayLayers = 1;
1169 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis51cde412016-07-11 16:08:30 -06001170 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Dustin Graves40f35822016-06-23 11:12:53 -06001171 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1172 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001173 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Dustin Graves40f35822016-06-23 11:12:53 -06001174 ASSERT_VK_SUCCESS(err);
1175
1176 VkMemoryRequirements memory_reqs;
1177 VkDeviceMemory image_memory;
1178 bool pass;
1179 VkMemoryAllocateInfo memory_info = {};
1180 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1181 memory_info.pNext = NULL;
1182 memory_info.allocationSize = 0;
1183 memory_info.memoryTypeIndex = 0;
1184 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
1185 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001186 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001187 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001188 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001189 ASSERT_VK_SUCCESS(err);
1190 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
1191 ASSERT_VK_SUCCESS(err);
1192
1193 VkImageViewCreateInfo image_view_create_info = {};
1194 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1195 image_view_create_info.image = image;
1196 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1197 image_view_create_info.format = tex_format;
1198 image_view_create_info.subresourceRange.layerCount = 1;
1199 image_view_create_info.subresourceRange.baseMipLevel = 0;
1200 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001201 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dustin Graves40f35822016-06-23 11:12:53 -06001202
1203 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001204 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Dustin Graves40f35822016-06-23 11:12:53 -06001205 ASSERT_VK_SUCCESS(err);
1206
1207 VkDescriptorPoolSize ds_type_count = {};
1208 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1209 ds_type_count.descriptorCount = 1;
1210
1211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1213 ds_pool_ci.pNext = NULL;
1214 ds_pool_ci.maxSets = 1;
1215 ds_pool_ci.poolSizeCount = 1;
1216 ds_pool_ci.pPoolSizes = &ds_type_count;
1217
1218 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001219 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001220 ASSERT_VK_SUCCESS(err);
1221
1222 VkDescriptorSetLayoutBinding dsl_binding = {};
1223 dsl_binding.binding = 0;
1224 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1225 dsl_binding.descriptorCount = 1;
1226 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1227 dsl_binding.pImmutableSamplers = NULL;
1228
1229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001231 ds_layout_ci.pNext = NULL;
1232 ds_layout_ci.bindingCount = 1;
1233 ds_layout_ci.pBindings = &dsl_binding;
1234 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001235 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001236 ASSERT_VK_SUCCESS(err);
1237
1238 VkDescriptorSet descriptor_set;
1239 VkDescriptorSetAllocateInfo alloc_info = {};
1240 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1241 alloc_info.descriptorSetCount = 1;
1242 alloc_info.descriptorPool = ds_pool;
1243 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001244 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001245 ASSERT_VK_SUCCESS(err);
1246
1247 VkDescriptorImageInfo image_info = {};
1248 image_info.imageView = view;
1249 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
1250
1251 VkWriteDescriptorSet descriptor_write;
1252 memset(&descriptor_write, 0, sizeof(descriptor_write));
1253 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1254 descriptor_write.dstSet = descriptor_set;
1255 descriptor_write.dstBinding = 0;
1256 descriptor_write.descriptorCount = 1;
1257 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
1258 descriptor_write.pImageInfo = &image_info;
1259
1260 // Set pBufferInfo and pTexelBufferView to invalid values, which should
1261 // be
1262 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
1263 // This will most likely produce a crash if the parameter_validation
1264 // layer
1265 // does not correctly ignore pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001266 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
1267 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001269 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001270
1271 m_errorMonitor->VerifyNotFound();
1272
Dustin Graves40f35822016-06-23 11:12:53 -06001273 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1274 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1275 vkDestroyImageView(m_device->device(), view, NULL);
1276 vkDestroyImage(m_device->device(), image, NULL);
1277 vkFreeMemory(m_device->device(), image_memory, NULL);
1278 }
1279
1280 // Buffer Case
1281 {
1282 m_errorMonitor->ExpectSuccess();
1283
1284 VkBuffer buffer;
1285 uint32_t queue_family_index = 0;
1286 VkBufferCreateInfo buffer_create_info = {};
1287 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1288 buffer_create_info.size = 1024;
1289 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1290 buffer_create_info.queueFamilyIndexCount = 1;
1291 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1292
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001293 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001294 ASSERT_VK_SUCCESS(err);
1295
1296 VkMemoryRequirements memory_reqs;
1297 VkDeviceMemory buffer_memory;
1298 bool pass;
1299 VkMemoryAllocateInfo memory_info = {};
1300 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1301 memory_info.pNext = NULL;
1302 memory_info.allocationSize = 0;
1303 memory_info.memoryTypeIndex = 0;
1304
1305 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1306 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001307 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001308 ASSERT_TRUE(pass);
1309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001310 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001311 ASSERT_VK_SUCCESS(err);
1312 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1313 ASSERT_VK_SUCCESS(err);
1314
1315 VkDescriptorPoolSize ds_type_count = {};
1316 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1317 ds_type_count.descriptorCount = 1;
1318
1319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1321 ds_pool_ci.pNext = NULL;
1322 ds_pool_ci.maxSets = 1;
1323 ds_pool_ci.poolSizeCount = 1;
1324 ds_pool_ci.pPoolSizes = &ds_type_count;
1325
1326 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001327 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001328 ASSERT_VK_SUCCESS(err);
1329
1330 VkDescriptorSetLayoutBinding dsl_binding = {};
1331 dsl_binding.binding = 0;
1332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1333 dsl_binding.descriptorCount = 1;
1334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1335 dsl_binding.pImmutableSamplers = NULL;
1336
1337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001339 ds_layout_ci.pNext = NULL;
1340 ds_layout_ci.bindingCount = 1;
1341 ds_layout_ci.pBindings = &dsl_binding;
1342 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001344 ASSERT_VK_SUCCESS(err);
1345
1346 VkDescriptorSet descriptor_set;
1347 VkDescriptorSetAllocateInfo alloc_info = {};
1348 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1349 alloc_info.descriptorSetCount = 1;
1350 alloc_info.descriptorPool = ds_pool;
1351 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001353 ASSERT_VK_SUCCESS(err);
1354
1355 VkDescriptorBufferInfo buffer_info = {};
1356 buffer_info.buffer = buffer;
1357 buffer_info.offset = 0;
1358 buffer_info.range = 1024;
1359
1360 VkWriteDescriptorSet descriptor_write;
1361 memset(&descriptor_write, 0, sizeof(descriptor_write));
1362 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1363 descriptor_write.dstSet = descriptor_set;
1364 descriptor_write.dstBinding = 0;
1365 descriptor_write.descriptorCount = 1;
1366 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1367 descriptor_write.pBufferInfo = &buffer_info;
1368
1369 // Set pImageInfo and pTexelBufferView to invalid values, which should
1370 // be
1371 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
1372 // This will most likely produce a crash if the parameter_validation
1373 // layer
1374 // does not correctly ignore pImageInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001375 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1376 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001378 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001379
1380 m_errorMonitor->VerifyNotFound();
1381
1382 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1385 vkDestroyBuffer(m_device->device(), buffer, NULL);
1386 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1387 }
1388
1389 // Texel Buffer Case
1390 {
1391 m_errorMonitor->ExpectSuccess();
1392
1393 VkBuffer buffer;
1394 uint32_t queue_family_index = 0;
1395 VkBufferCreateInfo buffer_create_info = {};
1396 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1397 buffer_create_info.size = 1024;
1398 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1399 buffer_create_info.queueFamilyIndexCount = 1;
1400 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
1401
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001402 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Dustin Graves40f35822016-06-23 11:12:53 -06001403 ASSERT_VK_SUCCESS(err);
1404
1405 VkMemoryRequirements memory_reqs;
1406 VkDeviceMemory buffer_memory;
1407 bool pass;
1408 VkMemoryAllocateInfo memory_info = {};
1409 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1410 memory_info.pNext = NULL;
1411 memory_info.allocationSize = 0;
1412 memory_info.memoryTypeIndex = 0;
1413
1414 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
1415 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001416 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Dustin Graves40f35822016-06-23 11:12:53 -06001417 ASSERT_TRUE(pass);
1418
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
Dustin Graves40f35822016-06-23 11:12:53 -06001420 ASSERT_VK_SUCCESS(err);
1421 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
1422 ASSERT_VK_SUCCESS(err);
1423
1424 VkBufferViewCreateInfo buff_view_ci = {};
1425 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
1426 buff_view_ci.buffer = buffer;
1427 buff_view_ci.format = VK_FORMAT_R8_UNORM;
1428 buff_view_ci.range = VK_WHOLE_SIZE;
1429 VkBufferView buffer_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001430 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
Dustin Graves40f35822016-06-23 11:12:53 -06001431
1432 VkDescriptorPoolSize ds_type_count = {};
1433 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1434 ds_type_count.descriptorCount = 1;
1435
1436 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1437 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1438 ds_pool_ci.pNext = NULL;
1439 ds_pool_ci.maxSets = 1;
1440 ds_pool_ci.poolSizeCount = 1;
1441 ds_pool_ci.pPoolSizes = &ds_type_count;
1442
1443 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001444 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Dustin Graves40f35822016-06-23 11:12:53 -06001445 ASSERT_VK_SUCCESS(err);
1446
1447 VkDescriptorSetLayoutBinding dsl_binding = {};
1448 dsl_binding.binding = 0;
1449 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1450 dsl_binding.descriptorCount = 1;
1451 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1452 dsl_binding.pImmutableSamplers = NULL;
1453
1454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Dustin Graves40f35822016-06-23 11:12:53 -06001456 ds_layout_ci.pNext = NULL;
1457 ds_layout_ci.bindingCount = 1;
1458 ds_layout_ci.pBindings = &dsl_binding;
1459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Dustin Graves40f35822016-06-23 11:12:53 -06001461 ASSERT_VK_SUCCESS(err);
1462
1463 VkDescriptorSet descriptor_set;
1464 VkDescriptorSetAllocateInfo alloc_info = {};
1465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1466 alloc_info.descriptorSetCount = 1;
1467 alloc_info.descriptorPool = ds_pool;
1468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Dustin Graves40f35822016-06-23 11:12:53 -06001470 ASSERT_VK_SUCCESS(err);
1471
1472 VkWriteDescriptorSet descriptor_write;
1473 memset(&descriptor_write, 0, sizeof(descriptor_write));
1474 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1475 descriptor_write.dstSet = descriptor_set;
1476 descriptor_write.dstBinding = 0;
1477 descriptor_write.descriptorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Dustin Graves40f35822016-06-23 11:12:53 -06001479 descriptor_write.pTexelBufferView = &buffer_view;
1480
1481 // Set pImageInfo and pBufferInfo to invalid values, which should be
1482 // ignored for descriptorType ==
1483 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
1484 // This will most likely produce a crash if the parameter_validation
1485 // layer
1486 // does not correctly ignore pImageInfo and pBufferInfo.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001487 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
1488 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
Dustin Graves40f35822016-06-23 11:12:53 -06001489
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001490 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Dustin Graves40f35822016-06-23 11:12:53 -06001491
1492 m_errorMonitor->VerifyNotFound();
1493
1494 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
1495 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1496 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
1497 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
1498 vkDestroyBuffer(m_device->device(), buffer, NULL);
1499 vkFreeMemory(m_device->device(), buffer_memory, NULL);
1500 }
1501}
Cortd889ff92016-07-27 09:51:27 -07001502
1503TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1504 VkResult err;
1505
1506 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001507 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001508
1509 ASSERT_NO_FATAL_FAILURE(InitState());
1510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1511
1512 std::vector<const char *> device_extension_names;
1513 auto features = m_device->phy().features();
1514 // Artificially disable support for non-solid fill modes
1515 features.fillModeNonSolid = false;
1516 // The sacrificial device object
1517 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1518
1519 VkRenderpassObj render_pass(&test_device);
1520
1521 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1522 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1523 pipeline_layout_ci.setLayoutCount = 0;
1524 pipeline_layout_ci.pSetLayouts = NULL;
1525
1526 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001527 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001528 ASSERT_VK_SUCCESS(err);
1529
1530 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1531 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1532 rs_ci.pNext = nullptr;
1533 rs_ci.lineWidth = 1.0f;
1534 rs_ci.rasterizerDiscardEnable = true;
1535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1537 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001538
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001539 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1541 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001542 {
1543 VkPipelineObj pipe(&test_device);
1544 pipe.AddShader(&vs);
1545 pipe.AddShader(&fs);
1546 pipe.AddColorAttachment();
1547 // Introduce failure by setting unsupported polygon mode
1548 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1549 pipe.SetRasterization(&rs_ci);
1550 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1551 }
1552 m_errorMonitor->VerifyFound();
1553
1554 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001557 {
1558 VkPipelineObj pipe(&test_device);
1559 pipe.AddShader(&vs);
1560 pipe.AddShader(&fs);
1561 pipe.AddColorAttachment();
1562 // Introduce failure by setting unsupported polygon mode
1563 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1564 pipe.SetRasterization(&rs_ci);
1565 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1566 }
1567 m_errorMonitor->VerifyFound();
1568
1569 // Try again with polygonMode=FILL. No error is expected
1570 m_errorMonitor->ExpectSuccess();
1571 {
1572 VkPipelineObj pipe(&test_device);
1573 pipe.AddShader(&vs);
1574 pipe.AddShader(&fs);
1575 pipe.AddColorAttachment();
1576 // Set polygonMode to a good value
1577 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
1578 pipe.SetRasterization(&rs_ci);
1579 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1580 }
1581 m_errorMonitor->VerifyNotFound();
1582
1583 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1584}
1585
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001586#endif // PARAMETER_VALIDATION_TESTS
1587
Tobin Ehlis0788f522015-05-26 16:11:58 -06001588#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001589#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001590TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001591{
1592 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001593 VkFenceCreateInfo fenceInfo = {};
1594 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1595 fenceInfo.pNext = NULL;
1596 fenceInfo.flags = 0;
1597
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001599
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001600 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001601
1602 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1603 vk_testing::Buffer buffer;
1604 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001605
Tony Barbourfe3351b2015-07-28 10:17:20 -06001606 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001607 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001608 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001609
1610 testFence.init(*m_device, fenceInfo);
1611
1612 // Bypass framework since it does the waits automatically
1613 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001614 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001615 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1616 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001617 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001618 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001619 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001620 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001621 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001622 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001623 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001624
1625 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001626 ASSERT_VK_SUCCESS( err );
1627
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001628 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001629 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001630
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001631 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001632}
1633
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001634TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001635{
1636 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001637 VkFenceCreateInfo fenceInfo = {};
1638 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1639 fenceInfo.pNext = NULL;
1640 fenceInfo.flags = 0;
1641
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001643
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001644 ASSERT_NO_FATAL_FAILURE(InitState());
1645 ASSERT_NO_FATAL_FAILURE(InitViewport());
1646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1647
Tony Barbourfe3351b2015-07-28 10:17:20 -06001648 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001649 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001650 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001651
1652 testFence.init(*m_device, fenceInfo);
1653
1654 // Bypass framework since it does the waits automatically
1655 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001656 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001657 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1658 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001659 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001660 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001661 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001662 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001663 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001664 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001665 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001666
1667 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001668 ASSERT_VK_SUCCESS( err );
1669
Jon Ashburnf19916e2016-01-11 13:12:43 -07001670 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001671 VkCommandBufferBeginInfo info = {};
1672 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1673 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001674 info.renderPass = VK_NULL_HANDLE;
1675 info.subpass = 0;
1676 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001677 info.occlusionQueryEnable = VK_FALSE;
1678 info.queryFlags = 0;
1679 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001680
1681 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001682 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001683
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001684 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001685}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001686#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001687
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001688// This is a positive test. No failures are expected.
1689TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1690 VkResult err;
1691 bool pass;
1692
1693 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1694 "the buffer, create an image, and bind the same memory to "
1695 "it");
1696
1697 m_errorMonitor->ExpectSuccess();
1698
1699 ASSERT_NO_FATAL_FAILURE(InitState());
1700
1701 VkBuffer buffer;
1702 VkImage image;
1703 VkDeviceMemory mem;
1704 VkMemoryRequirements mem_reqs;
1705
1706 VkBufferCreateInfo buf_info = {};
1707 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1708 buf_info.pNext = NULL;
1709 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1710 buf_info.size = 256;
1711 buf_info.queueFamilyIndexCount = 0;
1712 buf_info.pQueueFamilyIndices = NULL;
1713 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1714 buf_info.flags = 0;
1715 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1716 ASSERT_VK_SUCCESS(err);
1717
1718 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1719
1720 VkMemoryAllocateInfo alloc_info = {};
1721 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1722 alloc_info.pNext = NULL;
1723 alloc_info.memoryTypeIndex = 0;
1724
1725 // Ensure memory is big enough for both bindings
1726 alloc_info.allocationSize = 0x10000;
1727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001728 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001729 if (!pass) {
1730 vkDestroyBuffer(m_device->device(), buffer, NULL);
1731 return;
1732 }
1733
1734 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1735 ASSERT_VK_SUCCESS(err);
1736
1737 uint8_t *pData;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001738 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001739 ASSERT_VK_SUCCESS(err);
1740
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001741 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001742
1743 vkUnmapMemory(m_device->device(), mem);
1744
1745 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1746 ASSERT_VK_SUCCESS(err);
1747
1748 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1749 // memory. In fact, it was never used by the GPU.
1750 // Just be be sure, wait for idle.
1751 vkDestroyBuffer(m_device->device(), buffer, NULL);
1752 vkDeviceWaitIdle(m_device->device());
1753
1754 VkImageCreateInfo image_create_info = {};
1755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1756 image_create_info.pNext = NULL;
1757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1758 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1759 image_create_info.extent.width = 64;
1760 image_create_info.extent.height = 64;
1761 image_create_info.extent.depth = 1;
1762 image_create_info.mipLevels = 1;
1763 image_create_info.arrayLayers = 1;
1764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1765 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1766 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1767 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1768 image_create_info.queueFamilyIndexCount = 0;
1769 image_create_info.pQueueFamilyIndices = NULL;
1770 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1771 image_create_info.flags = 0;
1772
1773 VkMemoryAllocateInfo mem_alloc = {};
1774 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1775 mem_alloc.pNext = NULL;
1776 mem_alloc.allocationSize = 0;
1777 mem_alloc.memoryTypeIndex = 0;
1778
1779 /* Create a mappable image. It will be the texture if linear images are ok
1780 * to be textures or it will be the staging image if they are not.
1781 */
1782 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1783 ASSERT_VK_SUCCESS(err);
1784
1785 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1786
1787 mem_alloc.allocationSize = mem_reqs.size;
1788
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001790 if (!pass) {
1791 vkDestroyImage(m_device->device(), image, NULL);
1792 return;
1793 }
1794
Tobin Ehlis077ded32016-05-12 17:39:13 -06001795 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001796 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1797 ASSERT_VK_SUCCESS(err);
1798
1799 m_errorMonitor->VerifyNotFound();
1800
Tony Barbourdf4c0042016-06-01 15:55:43 -06001801 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001802 vkDestroyBuffer(m_device->device(), buffer, NULL);
1803 vkDestroyImage(m_device->device(), image, NULL);
1804}
1805
Tobin Ehlisf11be982016-05-11 13:52:53 -06001806TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1807 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1808 "buffer and image to memory such that they will alias.");
1809 VkResult err;
1810 bool pass;
1811 ASSERT_NO_FATAL_FAILURE(InitState());
1812
Tobin Ehlis077ded32016-05-12 17:39:13 -06001813 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001814 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001815 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001816 VkDeviceMemory mem; // buffer will be bound first
1817 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001818 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001819
1820 VkBufferCreateInfo buf_info = {};
1821 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1822 buf_info.pNext = NULL;
1823 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1824 buf_info.size = 256;
1825 buf_info.queueFamilyIndexCount = 0;
1826 buf_info.pQueueFamilyIndices = NULL;
1827 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1828 buf_info.flags = 0;
1829 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1830 ASSERT_VK_SUCCESS(err);
1831
Tobin Ehlis077ded32016-05-12 17:39:13 -06001832 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001833
1834 VkImageCreateInfo image_create_info = {};
1835 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1836 image_create_info.pNext = NULL;
1837 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1838 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1839 image_create_info.extent.width = 64;
1840 image_create_info.extent.height = 64;
1841 image_create_info.extent.depth = 1;
1842 image_create_info.mipLevels = 1;
1843 image_create_info.arrayLayers = 1;
1844 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001845 // Image tiling must be optimal to trigger error when aliasing linear buffer
1846 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001847 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1849 image_create_info.queueFamilyIndexCount = 0;
1850 image_create_info.pQueueFamilyIndices = NULL;
1851 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1852 image_create_info.flags = 0;
1853
Tobin Ehlisf11be982016-05-11 13:52:53 -06001854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1855 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001856 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1857 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001858
Tobin Ehlis077ded32016-05-12 17:39:13 -06001859 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1860
1861 VkMemoryAllocateInfo alloc_info = {};
1862 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1863 alloc_info.pNext = NULL;
1864 alloc_info.memoryTypeIndex = 0;
1865 // Ensure memory is big enough for both bindings
1866 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001867 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1868 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001869 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001870 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001871 vkDestroyImage(m_device->device(), image, NULL);
1872 return;
1873 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001874 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1875 ASSERT_VK_SUCCESS(err);
1876 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1877 ASSERT_VK_SUCCESS(err);
1878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001880 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001881 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1882 m_errorMonitor->VerifyFound();
1883
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001884 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001885 // aliasing buffer2
1886 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1887 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001888 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1889 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001890 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001891 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001893 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001894 m_errorMonitor->VerifyFound();
1895
1896 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001897 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001898 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001899 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001900 vkFreeMemory(m_device->device(), mem, NULL);
1901 vkFreeMemory(m_device->device(), mem_img, NULL);
1902}
1903
Tobin Ehlis35372522016-05-12 08:32:31 -06001904TEST_F(VkLayerTest, InvalidMemoryMapping) {
1905 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1906 VkResult err;
1907 bool pass;
1908 ASSERT_NO_FATAL_FAILURE(InitState());
1909
1910 VkBuffer buffer;
1911 VkDeviceMemory mem;
1912 VkMemoryRequirements mem_reqs;
1913
1914 VkBufferCreateInfo buf_info = {};
1915 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1916 buf_info.pNext = NULL;
1917 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1918 buf_info.size = 256;
1919 buf_info.queueFamilyIndexCount = 0;
1920 buf_info.pQueueFamilyIndices = NULL;
1921 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1922 buf_info.flags = 0;
1923 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1924 ASSERT_VK_SUCCESS(err);
1925
1926 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1927 VkMemoryAllocateInfo alloc_info = {};
1928 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1929 alloc_info.pNext = NULL;
1930 alloc_info.memoryTypeIndex = 0;
1931
1932 // Ensure memory is big enough for both bindings
1933 static const VkDeviceSize allocation_size = 0x10000;
1934 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001935 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001936 if (!pass) {
1937 vkDestroyBuffer(m_device->device(), buffer, NULL);
1938 return;
1939 }
1940 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1941 ASSERT_VK_SUCCESS(err);
1942
1943 uint8_t *pData;
1944 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001946 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1947 m_errorMonitor->VerifyFound();
1948 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001950 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1952 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1953 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001954 m_errorMonitor->VerifyFound();
1955
1956 // Unmap the memory to avoid re-map error
1957 vkUnmapMemory(m_device->device(), mem);
1958 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1960 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1961 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001962 m_errorMonitor->VerifyFound();
1963 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1965 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001966 m_errorMonitor->VerifyFound();
1967 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001969 vkUnmapMemory(m_device->device(), mem);
1970 m_errorMonitor->VerifyFound();
1971 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001972 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001973 ASSERT_VK_SUCCESS(err);
1974 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001975 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001976 mmr.memory = mem;
1977 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001979 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1980 m_errorMonitor->VerifyFound();
1981 // Now flush range that oversteps mapped range
1982 vkUnmapMemory(m_device->device(), mem);
1983 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1984 ASSERT_VK_SUCCESS(err);
1985 mmr.offset = 16;
1986 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001988 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1989 m_errorMonitor->VerifyFound();
1990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001991 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1992 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001993 if (!pass) {
1994 vkFreeMemory(m_device->device(), mem, NULL);
1995 vkDestroyBuffer(m_device->device(), buffer, NULL);
1996 return;
1997 }
1998 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1999 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
2000
2001 vkDestroyBuffer(m_device->device(), buffer, NULL);
2002 vkFreeMemory(m_device->device(), mem, NULL);
2003}
2004
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002005TEST_F(VkLayerTest, NonCoherentMemoryMapping) {
2006
2007 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
2008 "mapping while using VK_WHOLE_SIZE does not cause access "
2009 "violations");
2010 VkResult err;
2011 uint8_t *pData;
2012 ASSERT_NO_FATAL_FAILURE(InitState());
2013
2014 VkDeviceMemory mem;
2015 VkMemoryRequirements mem_reqs;
2016 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
2017 VkMemoryAllocateInfo alloc_info = {};
2018 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2019 alloc_info.pNext = NULL;
2020 alloc_info.memoryTypeIndex = 0;
2021
2022 static const VkDeviceSize allocation_size = 0x1000;
2023 alloc_info.allocationSize = allocation_size;
2024
2025 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002026 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
2027 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002028 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002029 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2030 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2031 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002032 if (!pass) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002033 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
2034 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
2035 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
2036 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002037 if (!pass) {
2038 return;
2039 }
2040 }
2041 }
2042
2043 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
2044 ASSERT_VK_SUCCESS(err);
2045
2046 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
2047 // mapped range
2048 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002049 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002050 ASSERT_VK_SUCCESS(err);
2051 VkMappedMemoryRange mmr = {};
2052 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2053 mmr.memory = mem;
2054 mmr.offset = 0;
2055 mmr.size = VK_WHOLE_SIZE;
2056 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2057 ASSERT_VK_SUCCESS(err);
2058 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2059 ASSERT_VK_SUCCESS(err);
2060 m_errorMonitor->VerifyNotFound();
2061 vkUnmapMemory(m_device->device(), mem);
2062
2063 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
2064 // mapped range
2065 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002067 ASSERT_VK_SUCCESS(err);
2068 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2069 mmr.memory = mem;
2070 mmr.offset = 13;
2071 mmr.size = VK_WHOLE_SIZE;
2072 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2073 ASSERT_VK_SUCCESS(err);
2074 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2075 ASSERT_VK_SUCCESS(err);
2076 m_errorMonitor->VerifyNotFound();
2077 vkUnmapMemory(m_device->device(), mem);
2078
2079 // Map with prime offset and size
2080 // Flush/Invalidate subrange of mapped area with prime offset and size
2081 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002082 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
Mark Lobodzinski1f515922016-08-16 10:03:30 -06002083 ASSERT_VK_SUCCESS(err);
2084 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
2085 mmr.memory = mem;
2086 mmr.offset = allocation_size - 107;
2087 mmr.size = 61;
2088 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
2089 ASSERT_VK_SUCCESS(err);
2090 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
2091 ASSERT_VK_SUCCESS(err);
2092 m_errorMonitor->VerifyNotFound();
2093 vkUnmapMemory(m_device->device(), mem);
2094
2095 vkFreeMemory(m_device->device(), mem, NULL);
2096}
2097
Ian Elliott1c32c772016-04-28 14:47:13 -06002098TEST_F(VkLayerTest, EnableWsiBeforeUse) {
2099 VkResult err;
2100 bool pass;
2101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002102 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
2103 // following declaration (which is temporarily being moved below):
2104 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002105 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2106 VkSwapchainCreateInfoKHR swapchain_create_info = {};
2107 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002108 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06002109 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06002111
2112 ASSERT_NO_FATAL_FAILURE(InitState());
2113
Ian Elliott3f06ce52016-04-29 14:46:21 -06002114#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
2115#if defined(VK_USE_PLATFORM_ANDROID_KHR)
2116 // Use the functions from the VK_KHR_android_surface extension without
2117 // enabling that extension:
2118
2119 // Create a surface:
2120 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2122 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002123 pass = (err != VK_SUCCESS);
2124 ASSERT_TRUE(pass);
2125 m_errorMonitor->VerifyFound();
2126#endif // VK_USE_PLATFORM_ANDROID_KHR
2127
Ian Elliott3f06ce52016-04-29 14:46:21 -06002128#if defined(VK_USE_PLATFORM_MIR_KHR)
2129 // Use the functions from the VK_KHR_mir_surface extension without enabling
2130 // that extension:
2131
2132 // Create a surface:
2133 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06002135 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
2136 pass = (err != VK_SUCCESS);
2137 ASSERT_TRUE(pass);
2138 m_errorMonitor->VerifyFound();
2139
2140 // Tell whether an mir_connection supports presentation:
2141 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2143 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002144 m_errorMonitor->VerifyFound();
2145#endif // VK_USE_PLATFORM_MIR_KHR
2146
Ian Elliott3f06ce52016-04-29 14:46:21 -06002147#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2148 // Use the functions from the VK_KHR_wayland_surface extension without
2149 // enabling that extension:
2150
2151 // Create a surface:
2152 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2154 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002155 pass = (err != VK_SUCCESS);
2156 ASSERT_TRUE(pass);
2157 m_errorMonitor->VerifyFound();
2158
2159 // Tell whether an wayland_display supports presentation:
2160 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2162 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002163 m_errorMonitor->VerifyFound();
2164#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06002165#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06002166
Ian Elliott3f06ce52016-04-29 14:46:21 -06002167#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002168 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2169 // TO NON-LINUX PLATFORMS:
2170 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06002171 // Use the functions from the VK_KHR_win32_surface extension without
2172 // enabling that extension:
2173
2174 // Create a surface:
2175 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2177 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002178 pass = (err != VK_SUCCESS);
2179 ASSERT_TRUE(pass);
2180 m_errorMonitor->VerifyFound();
2181
2182 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06002184 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06002185 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002186// Set this (for now, until all platforms are supported and tested):
2187#define NEED_TO_TEST_THIS_ON_PLATFORM
2188#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06002189
Ian Elliott1c32c772016-04-28 14:47:13 -06002190#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002191 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
2192 // TO NON-LINUX PLATFORMS:
2193 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06002194 // Use the functions from the VK_KHR_xcb_surface extension without enabling
2195 // that extension:
2196
2197 // Create a surface:
2198 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002200 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2201 pass = (err != VK_SUCCESS);
2202 ASSERT_TRUE(pass);
2203 m_errorMonitor->VerifyFound();
2204
2205 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06002206 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06002207 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2209 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06002210 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002211// Set this (for now, until all platforms are supported and tested):
2212#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002213#endif // VK_USE_PLATFORM_XCB_KHR
2214
Ian Elliott12630812016-04-29 14:35:43 -06002215#if defined(VK_USE_PLATFORM_XLIB_KHR)
2216 // Use the functions from the VK_KHR_xlib_surface extension without enabling
2217 // that extension:
2218
2219 // Create a surface:
2220 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002222 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
2223 pass = (err != VK_SUCCESS);
2224 ASSERT_TRUE(pass);
2225 m_errorMonitor->VerifyFound();
2226
2227 // Tell whether an Xlib VisualID supports presentation:
2228 Display *dpy = NULL;
2229 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06002231 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
2232 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002233// Set this (for now, until all platforms are supported and tested):
2234#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06002235#endif // VK_USE_PLATFORM_XLIB_KHR
2236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237// Use the functions from the VK_KHR_surface extension without enabling
2238// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002239
Ian Elliott489eec02016-05-05 14:12:44 -06002240#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002241 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002243 vkDestroySurfaceKHR(instance(), surface, NULL);
2244 m_errorMonitor->VerifyFound();
2245
2246 // Check if surface supports presentation:
2247 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002249 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2250 pass = (err != VK_SUCCESS);
2251 ASSERT_TRUE(pass);
2252 m_errorMonitor->VerifyFound();
2253
2254 // Check surface capabilities:
2255 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2257 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06002258 pass = (err != VK_SUCCESS);
2259 ASSERT_TRUE(pass);
2260 m_errorMonitor->VerifyFound();
2261
2262 // Check surface formats:
2263 uint32_t format_count = 0;
2264 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2266 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06002267 pass = (err != VK_SUCCESS);
2268 ASSERT_TRUE(pass);
2269 m_errorMonitor->VerifyFound();
2270
2271 // Check surface present modes:
2272 uint32_t present_mode_count = 0;
2273 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2275 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06002276 pass = (err != VK_SUCCESS);
2277 ASSERT_TRUE(pass);
2278 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06002279#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06002280
Ian Elliott1c32c772016-04-28 14:47:13 -06002281 // Use the functions from the VK_KHR_swapchain extension without enabling
2282 // that extension:
2283
2284 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002286 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2287 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002288 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06002289 pass = (err != VK_SUCCESS);
2290 ASSERT_TRUE(pass);
2291 m_errorMonitor->VerifyFound();
2292
2293 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
2295 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06002296 pass = (err != VK_SUCCESS);
2297 ASSERT_TRUE(pass);
2298 m_errorMonitor->VerifyFound();
2299
Chris Forbeseb7d5502016-09-13 18:19:21 +12002300 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
2301 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2302 VkFence fence;
2303 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2304
Ian Elliott1c32c772016-04-28 14:47:13 -06002305 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12002307 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06002308 pass = (err != VK_SUCCESS);
2309 ASSERT_TRUE(pass);
2310 m_errorMonitor->VerifyFound();
2311
Chris Forbeseb7d5502016-09-13 18:19:21 +12002312 vkDestroyFence(m_device->device(), fence, nullptr);
2313
Ian Elliott1c32c772016-04-28 14:47:13 -06002314 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002315 //
2316 // NOTE: Currently can't test this because a real swapchain is needed (as
2317 // opposed to the fake one we created) in order for the layer to lookup the
2318 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06002319
2320 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06002322 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
2323 m_errorMonitor->VerifyFound();
2324}
2325
Ian Elliott2c1daf52016-05-12 09:41:46 -06002326TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06002327
Dustin Graves6c6d8982016-05-17 10:09:21 -06002328#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06002329 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002330
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002331 VkResult err;
2332 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002333 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
2334 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002335 // uint32_t swapchain_image_count = 0;
2336 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
2337 // uint32_t image_index = 0;
2338 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06002339
2340 ASSERT_NO_FATAL_FAILURE(InitState());
2341
2342 // Use the create function from one of the VK_KHR_*_surface extension in
2343 // order to create a surface, testing all known errors in the process,
2344 // before successfully creating a surface:
2345 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002347 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
2348 pass = (err != VK_SUCCESS);
2349 ASSERT_TRUE(pass);
2350 m_errorMonitor->VerifyFound();
2351
2352 // Next, try to create a surface with the wrong
2353 // VkXcbSurfaceCreateInfoKHR::sType:
2354 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
2355 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002357 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2358 pass = (err != VK_SUCCESS);
2359 ASSERT_TRUE(pass);
2360 m_errorMonitor->VerifyFound();
2361
Ian Elliott2c1daf52016-05-12 09:41:46 -06002362 // Create a native window, and then correctly create a surface:
2363 xcb_connection_t *connection;
2364 xcb_screen_t *screen;
2365 xcb_window_t xcb_window;
2366 xcb_intern_atom_reply_t *atom_wm_delete_window;
2367
2368 const xcb_setup_t *setup;
2369 xcb_screen_iterator_t iter;
2370 int scr;
2371 uint32_t value_mask, value_list[32];
2372 int width = 1;
2373 int height = 1;
2374
2375 connection = xcb_connect(NULL, &scr);
2376 ASSERT_TRUE(connection != NULL);
2377 setup = xcb_get_setup(connection);
2378 iter = xcb_setup_roots_iterator(setup);
2379 while (scr-- > 0)
2380 xcb_screen_next(&iter);
2381 screen = iter.data;
2382
2383 xcb_window = xcb_generate_id(connection);
2384
2385 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
2386 value_list[0] = screen->black_pixel;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
2390 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002391
2392 /* Magic code that will send notification when window is destroyed */
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
2394 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002396 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002397 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002398 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002399 free(reply);
2400
2401 xcb_map_window(connection, xcb_window);
2402
2403 // Force the x/y coordinates to 100,100 results are identical in consecutive
2404 // runs
2405 const uint32_t coords[] = {100, 100};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002406 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002407
Ian Elliott2c1daf52016-05-12 09:41:46 -06002408 // Finally, try to correctly create a surface:
2409 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
2410 xcb_create_info.pNext = NULL;
2411 xcb_create_info.flags = 0;
2412 xcb_create_info.connection = connection;
2413 xcb_create_info.window = xcb_window;
2414 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
2415 pass = (err == VK_SUCCESS);
2416 ASSERT_TRUE(pass);
2417
Ian Elliott2c1daf52016-05-12 09:41:46 -06002418 // Check if surface supports presentation:
2419
2420 // 1st, do so without having queried the queue families:
2421 VkBool32 supported = false;
2422 // TODO: Get the following error to come out:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2424 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
2425 "function");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002426 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2427 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002428 // ASSERT_TRUE(pass);
2429 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06002430
2431 // Next, query a queue family index that's too large:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2433 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002434 pass = (err != VK_SUCCESS);
2435 ASSERT_TRUE(pass);
2436 m_errorMonitor->VerifyFound();
2437
2438 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002439 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2440 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002441 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
2442 pass = (err == VK_SUCCESS);
2443 ASSERT_TRUE(pass);
2444
Ian Elliott2c1daf52016-05-12 09:41:46 -06002445 // Before proceeding, try to create a swapchain without having called
2446 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
2447 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2448 swapchain_create_info.pNext = NULL;
2449 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2451 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
2452 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002453 pass = (err != VK_SUCCESS);
2454 ASSERT_TRUE(pass);
2455 m_errorMonitor->VerifyFound();
2456
Ian Elliott2c1daf52016-05-12 09:41:46 -06002457 // Get the surface capabilities:
2458 VkSurfaceCapabilitiesKHR surface_capabilities;
2459
2460 // Do so correctly (only error logged by this entrypoint is if the
2461 // extension isn't enabled):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002462 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002463 pass = (err == VK_SUCCESS);
2464 ASSERT_TRUE(pass);
2465
Ian Elliott2c1daf52016-05-12 09:41:46 -06002466 // Get the surface formats:
2467 uint32_t surface_format_count;
2468
2469 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
2471 "specified as NULL");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002472 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
2473 pass = (err == VK_SUCCESS);
2474 ASSERT_TRUE(pass);
2475 m_errorMonitor->VerifyFound();
2476
2477 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
2478 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002480 surface_format_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002481 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002482 pass = (err == VK_SUCCESS);
2483 ASSERT_TRUE(pass);
2484 m_errorMonitor->VerifyFound();
2485
2486 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002487 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002488 pass = (err == VK_SUCCESS);
2489 ASSERT_TRUE(pass);
2490
2491 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002492 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002493
2494 // Next, do a 2nd try with surface_format_count being set too high:
2495 surface_format_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2497 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002498 pass = (err == VK_SUCCESS);
2499 ASSERT_TRUE(pass);
2500 m_errorMonitor->VerifyFound();
2501
2502 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002504 pass = (err == VK_SUCCESS);
2505 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002506 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002507 pass = (err == VK_SUCCESS);
2508 ASSERT_TRUE(pass);
2509
Ian Elliott2c1daf52016-05-12 09:41:46 -06002510 // Get the surface present modes:
2511 uint32_t surface_present_mode_count;
2512
2513 // First, try without a pointer to surface_format_count:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
2515 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002516
Ian Elliott2c1daf52016-05-12 09:41:46 -06002517 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
2518 pass = (err == VK_SUCCESS);
2519 ASSERT_TRUE(pass);
2520 m_errorMonitor->VerifyFound();
2521
2522 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
2523 // correctly done a 1st try (to get the count):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002525 surface_present_mode_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
2527 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002528 pass = (err == VK_SUCCESS);
2529 ASSERT_TRUE(pass);
2530 m_errorMonitor->VerifyFound();
2531
2532 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002533 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002534 pass = (err == VK_SUCCESS);
2535 ASSERT_TRUE(pass);
2536
2537 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002538 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06002539
2540 // Next, do a 2nd try with surface_format_count being set too high:
2541 surface_present_mode_count += 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
2543 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002544 pass = (err == VK_SUCCESS);
2545 ASSERT_TRUE(pass);
2546 m_errorMonitor->VerifyFound();
2547
2548 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002549 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002550 pass = (err == VK_SUCCESS);
2551 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002553 pass = (err == VK_SUCCESS);
2554 ASSERT_TRUE(pass);
2555
Ian Elliott2c1daf52016-05-12 09:41:46 -06002556 // Create a swapchain:
2557
2558 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
2560 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002561
Ian Elliott2c1daf52016-05-12 09:41:46 -06002562 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2563 pass = (err != VK_SUCCESS);
2564 ASSERT_TRUE(pass);
2565 m_errorMonitor->VerifyFound();
2566
2567 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2568 // sType:
2569 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002571
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002572 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002573 pass = (err != VK_SUCCESS);
2574 ASSERT_TRUE(pass);
2575 m_errorMonitor->VerifyFound();
2576
2577 // Next, call with a NULL swapchain pointer:
2578 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2579 swapchain_create_info.pNext = NULL;
2580 swapchain_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
2582 "specified as NULL");
Mark Lobodzinskib02ea642016-08-17 13:03:57 -06002583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002584 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002585 pass = (err != VK_SUCCESS);
2586 ASSERT_TRUE(pass);
2587 m_errorMonitor->VerifyFound();
2588
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002589 // TODO: Enhance swapchain layer so that
2590 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002591
2592 // Next, call with a queue family index that's too large:
2593 uint32_t queueFamilyIndex[2] = {100000, 0};
2594 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2595 swapchain_create_info.queueFamilyIndexCount = 2;
2596 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
2598 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002599 pass = (err != VK_SUCCESS);
2600 ASSERT_TRUE(pass);
2601 m_errorMonitor->VerifyFound();
2602
2603 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2604 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2605 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2607 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2608 "pCreateInfo->pQueueFamilyIndices).");
2609 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002610 pass = (err != VK_SUCCESS);
2611 ASSERT_TRUE(pass);
2612 m_errorMonitor->VerifyFound();
2613
2614 // Next, call with an invalid imageSharingMode:
2615 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2616 swapchain_create_info.queueFamilyIndexCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2618 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
2619 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002620 pass = (err != VK_SUCCESS);
2621 ASSERT_TRUE(pass);
2622 m_errorMonitor->VerifyFound();
2623 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002624 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2625 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002626 swapchain_create_info.queueFamilyIndexCount = 0;
2627 queueFamilyIndex[0] = 0;
2628 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2629
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002630 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002631 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002632 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002633 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002634 // Destroy the swapchain:
2635
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002636 // TODOs:
2637 //
2638 // - Try destroying the device without first destroying the swapchain
2639 //
2640 // - Try destroying the device without first destroying the surface
2641 //
2642 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002643
2644 // Destroy the surface:
2645 vkDestroySurfaceKHR(instance(), surface, NULL);
2646
Ian Elliott2c1daf52016-05-12 09:41:46 -06002647 // Tear down the window:
2648 xcb_destroy_window(connection, xcb_window);
2649 xcb_disconnect(connection);
2650
2651#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002652 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002653#endif // VK_USE_PLATFORM_XCB_KHR
2654}
2655
Karl Schultz6addd812016-02-02 17:17:23 -07002656TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2657 VkResult err;
2658 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002659
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2661 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002662
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002663 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002664
2665 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002666 VkImage image;
2667 VkDeviceMemory mem;
2668 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002669
Karl Schultz6addd812016-02-02 17:17:23 -07002670 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2671 const int32_t tex_width = 32;
2672 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002673
Tony Barboureb254902015-07-15 12:50:33 -06002674 VkImageCreateInfo image_create_info = {};
2675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002676 image_create_info.pNext = NULL;
2677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2678 image_create_info.format = tex_format;
2679 image_create_info.extent.width = tex_width;
2680 image_create_info.extent.height = tex_height;
2681 image_create_info.extent.depth = 1;
2682 image_create_info.mipLevels = 1;
2683 image_create_info.arrayLayers = 1;
2684 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2685 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2686 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2687 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002688 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002689
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002690 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002691 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002692 mem_alloc.pNext = NULL;
2693 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002694
Chia-I Wuf7458c52015-10-26 21:10:41 +08002695 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002696 ASSERT_VK_SUCCESS(err);
2697
Karl Schultz6addd812016-02-02 17:17:23 -07002698 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002699
Mark Lobodzinski23065352015-05-29 09:32:35 -05002700 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002702 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07002703 if (!pass) { // If we can't find any unmappable memory this test doesn't
2704 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002705 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002706 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002707 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002708
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002709 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002710 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002711 ASSERT_VK_SUCCESS(err);
2712
2713 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002714 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002715 ASSERT_VK_SUCCESS(err);
2716
2717 // Map memory as if to initialize the image
2718 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002719 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002720
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002721 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002722
Chia-I Wuf7458c52015-10-26 21:10:41 +08002723 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002724 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002725}
2726
Karl Schultz6addd812016-02-02 17:17:23 -07002727TEST_F(VkLayerTest, RebindMemory) {
2728 VkResult err;
2729 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002732
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002733 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002734
2735 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002736 VkImage image;
2737 VkDeviceMemory mem1;
2738 VkDeviceMemory mem2;
2739 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002740
Karl Schultz6addd812016-02-02 17:17:23 -07002741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2742 const int32_t tex_width = 32;
2743 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002744
Tony Barboureb254902015-07-15 12:50:33 -06002745 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2747 image_create_info.pNext = NULL;
2748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2749 image_create_info.format = tex_format;
2750 image_create_info.extent.width = tex_width;
2751 image_create_info.extent.height = tex_height;
2752 image_create_info.extent.depth = 1;
2753 image_create_info.mipLevels = 1;
2754 image_create_info.arrayLayers = 1;
2755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2756 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2758 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002759
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002760 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 mem_alloc.pNext = NULL;
2763 mem_alloc.allocationSize = 0;
2764 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002765
Karl Schultz6addd812016-02-02 17:17:23 -07002766 // Introduce failure, do NOT set memProps to
2767 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002768 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002769 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002770 ASSERT_VK_SUCCESS(err);
2771
Karl Schultz6addd812016-02-02 17:17:23 -07002772 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002773
2774 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002776 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002777
2778 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002779 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002780 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002781 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002782 ASSERT_VK_SUCCESS(err);
2783
2784 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002785 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002786 ASSERT_VK_SUCCESS(err);
2787
Karl Schultz6addd812016-02-02 17:17:23 -07002788 // Introduce validation failure, try to bind a different memory object to
2789 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002790 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002791
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002792 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002793
Chia-I Wuf7458c52015-10-26 21:10:41 +08002794 vkDestroyImage(m_device->device(), image, NULL);
2795 vkFreeMemory(m_device->device(), mem1, NULL);
2796 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002797}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002798
Karl Schultz6addd812016-02-02 17:17:23 -07002799TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002800 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2803 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002804
2805 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002806 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2807 fenceInfo.pNext = NULL;
2808 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002809
Tony Barbour300a6082015-04-07 13:44:53 -06002810 ASSERT_NO_FATAL_FAILURE(InitState());
2811 ASSERT_NO_FATAL_FAILURE(InitViewport());
2812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2813
Tony Barbourfe3351b2015-07-28 10:17:20 -06002814 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002815 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002816 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002817
2818 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002819
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002820 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002821 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2822 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002823 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002824 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002825 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002826 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002827 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002828 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002829 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002830
2831 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002832 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002833
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002834 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002835}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002836// This is a positive test. We used to expect error in this case but spec now
2837// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002838TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002839 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002840 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002841 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002842 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2843 fenceInfo.pNext = NULL;
2844
Tony Barbour0b4d9562015-04-09 10:48:04 -06002845 ASSERT_NO_FATAL_FAILURE(InitState());
2846 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002847 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002848 VkResult result = vkResetFences(m_device->device(), 1, fences);
2849 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002850
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002851 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002852}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002853#if 0 // A few devices have issues with this test so disabling for now
Chris Forbese70b7d32016-06-15 15:49:12 +12002854TEST_F(VkLayerTest, LongFenceChain)
2855{
2856 m_errorMonitor->ExpectSuccess();
2857
2858 ASSERT_NO_FATAL_FAILURE(InitState());
2859 VkResult err;
2860
2861 std::vector<VkFence> fences;
2862
2863 const int chainLength = 32768;
2864
2865 for (int i = 0; i < chainLength; i++) {
2866 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2867 VkFence fence;
2868 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2869 ASSERT_VK_SUCCESS(err);
2870
2871 fences.push_back(fence);
2872
2873 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2874 0, nullptr, 0, nullptr };
2875 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2876 ASSERT_VK_SUCCESS(err);
2877
2878 }
2879
2880 // BOOM, stack overflow.
2881 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2882
2883 for (auto fence : fences)
2884 vkDestroyFence(m_device->device(), fence, nullptr);
2885
2886 m_errorMonitor->VerifyNotFound();
2887}
Tobin Ehlis56ab9022016-08-17 17:59:31 -06002888#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002889TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) {
Chris Forbes18127d12016-06-08 16:52:28 +12002890 m_errorMonitor->ExpectSuccess();
2891
2892 ASSERT_NO_FATAL_FAILURE(InitState());
2893 VkResult err;
2894
2895 // Record (empty!) command buffer that can be submitted multiple times
2896 // simultaneously.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002897 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2898 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Chris Forbes18127d12016-06-08 16:52:28 +12002899 m_commandBuffer->BeginCommandBuffer(&cbbi);
2900 m_commandBuffer->EndCommandBuffer();
2901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002902 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002903 VkFence fence;
2904 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2905 ASSERT_VK_SUCCESS(err);
2906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002907 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes18127d12016-06-08 16:52:28 +12002908 VkSemaphore s1, s2;
2909 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2910 ASSERT_VK_SUCCESS(err);
2911 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2912 ASSERT_VK_SUCCESS(err);
2913
2914 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002915 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Chris Forbes18127d12016-06-08 16:52:28 +12002916 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2917 ASSERT_VK_SUCCESS(err);
2918
2919 // Submit CB again, signaling s2.
2920 si.pSignalSemaphores = &s2;
2921 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2922 ASSERT_VK_SUCCESS(err);
2923
2924 // Wait for fence.
2925 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2926 ASSERT_VK_SUCCESS(err);
2927
2928 // CB is still in flight from second submission, but semaphore s1 is no
2929 // longer in flight. delete it.
2930 vkDestroySemaphore(m_device->device(), s1, nullptr);
2931
2932 m_errorMonitor->VerifyNotFound();
2933
2934 // Force device idle and clean up remaining objects
2935 vkDeviceWaitIdle(m_device->device());
2936 vkDestroySemaphore(m_device->device(), s2, nullptr);
2937 vkDestroyFence(m_device->device(), fence, nullptr);
2938}
2939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002940TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) {
Chris Forbes4e44c912016-06-16 10:20:00 +12002941 m_errorMonitor->ExpectSuccess();
2942
2943 ASSERT_NO_FATAL_FAILURE(InitState());
2944 VkResult err;
2945
2946 // A fence created signaled
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002947 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Chris Forbes4e44c912016-06-16 10:20:00 +12002948 VkFence f1;
2949 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2950 ASSERT_VK_SUCCESS(err);
2951
2952 // A fence created not
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002953 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes4e44c912016-06-16 10:20:00 +12002954 VkFence f2;
2955 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2956 ASSERT_VK_SUCCESS(err);
2957
2958 // Submit the unsignaled fence
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002959 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Chris Forbes4e44c912016-06-16 10:20:00 +12002960 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2961
2962 // Wait on both fences, with signaled first.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002963 VkFence fences[] = {f1, f2};
Chris Forbes4e44c912016-06-16 10:20:00 +12002964 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2965
2966 // Should have both retired!
2967 vkDestroyFence(m_device->device(), f1, nullptr);
2968 vkDestroyFence(m_device->device(), f2, nullptr);
2969
2970 m_errorMonitor->VerifyNotFound();
2971}
2972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002973TEST_F(VkLayerTest, InvalidUsageBits) {
2974 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
2975 "Initialize buffer with wrong usage then perform copy expecting errors "
2976 "from both the image and the buffer (2 calls)");
2977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002978
2979 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002980 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002981 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002982 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002983 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002984
Tony Barbourf92621a2016-05-02 14:28:12 -06002985 VkImageView dsv;
2986 VkImageViewCreateInfo dsvci = {};
2987 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2988 dsvci.image = image.handle();
2989 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2990 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2991 dsvci.subresourceRange.layerCount = 1;
2992 dsvci.subresourceRange.baseMipLevel = 0;
2993 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002994 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002995
Tony Barbourf92621a2016-05-02 14:28:12 -06002996 // Create a view with depth / stencil aspect for image with different usage
2997 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002998
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002999 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06003000
3001 // Initialize buffer with TRANSFER_DST usage
3002 vk_testing::Buffer buffer;
3003 VkMemoryPropertyFlags reqs = 0;
3004 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3005 VkBufferImageCopy region = {};
3006 region.bufferRowLength = 128;
3007 region.bufferImageHeight = 128;
3008 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3009 region.imageSubresource.layerCount = 1;
3010 region.imageExtent.height = 16;
3011 region.imageExtent.width = 16;
3012 region.imageExtent.depth = 1;
3013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for buffer ");
Tony Barbourf92621a2016-05-02 14:28:12 -06003015 // Buffer usage not set to TRANSFER_SRC and image usage not set to
3016 // TRANSFER_DST
3017 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3019 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003020 m_errorMonitor->VerifyFound();
3021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
3023 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
3024 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06003025 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06003026}
Tony Barbour75d79f02016-08-30 09:39:07 -06003027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003028TEST_F(VkLayerTest, ValidUsage) {
3029 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
3030 "doesn't generate validation errors");
Tony Barbour75d79f02016-08-30 09:39:07 -06003031
3032 ASSERT_NO_FATAL_FAILURE(InitState());
3033
3034 m_errorMonitor->ExpectSuccess();
3035 // Verify that we can create a view with usage INPUT_ATTACHMENT
3036 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003037 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour75d79f02016-08-30 09:39:07 -06003038 ASSERT_TRUE(image.initialized());
3039 VkImageView imageView;
3040 VkImageViewCreateInfo ivci = {};
3041 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3042 ivci.image = image.handle();
3043 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3044 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
3045 ivci.subresourceRange.layerCount = 1;
3046 ivci.subresourceRange.baseMipLevel = 0;
3047 ivci.subresourceRange.levelCount = 1;
3048 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3049
3050 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
3051 m_errorMonitor->VerifyNotFound();
3052 vkDestroyImageView(m_device->device(), imageView, NULL);
3053}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003054#endif // MEM_TRACKER_TESTS
3055
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06003056#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003057
3058TEST_F(VkLayerTest, LeakAnObject) {
3059 VkResult err;
3060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003061 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003062
3063 // Note that we have to create a new device since destroying the
3064 // framework's device causes Teardown() to fail and just calling Teardown
3065 // will destroy the errorMonitor.
3066
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003068
3069 ASSERT_NO_FATAL_FAILURE(InitState());
3070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003071 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003072 std::vector<VkDeviceQueueCreateInfo> queue_info;
3073 queue_info.reserve(queue_props.size());
3074 std::vector<std::vector<float>> queue_priorities;
3075 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
3076 VkDeviceQueueCreateInfo qi = {};
3077 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
3078 qi.pNext = NULL;
3079 qi.queueFamilyIndex = i;
3080 qi.queueCount = queue_props[i].queueCount;
3081 queue_priorities.emplace_back(qi.queueCount, 0.0f);
3082 qi.pQueuePriorities = queue_priorities[i].data();
3083 queue_info.push_back(qi);
3084 }
3085
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003086 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003087
3088 // The sacrificial device object
3089 VkDevice testDevice;
3090 VkDeviceCreateInfo device_create_info = {};
3091 auto features = m_device->phy().features();
3092 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
3093 device_create_info.pNext = NULL;
3094 device_create_info.queueCreateInfoCount = queue_info.size();
3095 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06003096 device_create_info.enabledLayerCount = 0;
3097 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003098 device_create_info.pEnabledFeatures = &features;
3099 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
3100 ASSERT_VK_SUCCESS(err);
3101
3102 VkFence fence;
3103 VkFenceCreateInfo fence_create_info = {};
3104 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3105 fence_create_info.pNext = NULL;
3106 fence_create_info.flags = 0;
3107 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
3108 ASSERT_VK_SUCCESS(err);
3109
3110 // Induce failure by not calling vkDestroyFence
3111 vkDestroyDevice(testDevice, NULL);
3112 m_errorMonitor->VerifyFound();
3113}
3114
3115TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
3116
3117 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
3118 "attempt to delete them from another.");
3119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003121
Cody Northropc31a84f2016-08-22 10:41:47 -06003122 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003123 VkCommandPool command_pool_one;
3124 VkCommandPool command_pool_two;
3125
3126 VkCommandPoolCreateInfo pool_create_info{};
3127 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3128 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3129 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003131 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003132
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003133 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003134
3135 VkCommandBuffer command_buffer[9];
3136 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003138 command_buffer_allocate_info.commandPool = command_pool_one;
3139 command_buffer_allocate_info.commandBufferCount = 9;
3140 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003141 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003143 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003144
3145 m_errorMonitor->VerifyFound();
3146
3147 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
3148 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
3149}
3150
3151TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
3152 VkResult err;
3153
3154 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003155 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003158
3159 ASSERT_NO_FATAL_FAILURE(InitState());
3160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3161
3162 VkDescriptorPoolSize ds_type_count = {};
3163 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3164 ds_type_count.descriptorCount = 1;
3165
3166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3168 ds_pool_ci.pNext = NULL;
3169 ds_pool_ci.flags = 0;
3170 ds_pool_ci.maxSets = 1;
3171 ds_pool_ci.poolSizeCount = 1;
3172 ds_pool_ci.pPoolSizes = &ds_type_count;
3173
3174 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003176 ASSERT_VK_SUCCESS(err);
3177
3178 // Create a second descriptor pool
3179 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003180 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003181 ASSERT_VK_SUCCESS(err);
3182
3183 VkDescriptorSetLayoutBinding dsl_binding = {};
3184 dsl_binding.binding = 0;
3185 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3186 dsl_binding.descriptorCount = 1;
3187 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3188 dsl_binding.pImmutableSamplers = NULL;
3189
3190 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3191 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3192 ds_layout_ci.pNext = NULL;
3193 ds_layout_ci.bindingCount = 1;
3194 ds_layout_ci.pBindings = &dsl_binding;
3195
3196 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003197 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003198 ASSERT_VK_SUCCESS(err);
3199
3200 VkDescriptorSet descriptorSet;
3201 VkDescriptorSetAllocateInfo alloc_info = {};
3202 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3203 alloc_info.descriptorSetCount = 1;
3204 alloc_info.descriptorPool = ds_pool_one;
3205 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003206 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003207 ASSERT_VK_SUCCESS(err);
3208
3209 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
3210
3211 m_errorMonitor->VerifyFound();
3212
3213 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3214 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
3215 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
3216}
3217
3218TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003222
3223 ASSERT_NO_FATAL_FAILURE(InitState());
3224
3225 // Pass bogus handle into GetImageMemoryRequirements
3226 VkMemoryRequirements mem_reqs;
3227 uint64_t fakeImageHandle = 0xCADECADE;
3228 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
3229
3230 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
3231
3232 m_errorMonitor->VerifyFound();
3233}
3234
Karl Schultz6addd812016-02-02 17:17:23 -07003235TEST_F(VkLayerTest, PipelineNotBound) {
3236 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003237
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003238 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06003239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003241
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003242 ASSERT_NO_FATAL_FAILURE(InitState());
3243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003244
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003245 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003246 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3247 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003248
3249 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003250 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3251 ds_pool_ci.pNext = NULL;
3252 ds_pool_ci.maxSets = 1;
3253 ds_pool_ci.poolSizeCount = 1;
3254 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003255
3256 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003258 ASSERT_VK_SUCCESS(err);
3259
3260 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003261 dsl_binding.binding = 0;
3262 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3263 dsl_binding.descriptorCount = 1;
3264 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3265 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003266
3267 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003268 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3269 ds_layout_ci.pNext = NULL;
3270 ds_layout_ci.bindingCount = 1;
3271 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003272
3273 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003274 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003275 ASSERT_VK_SUCCESS(err);
3276
3277 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003278 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003279 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003280 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003281 alloc_info.descriptorPool = ds_pool;
3282 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003284 ASSERT_VK_SUCCESS(err);
3285
3286 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003287 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3288 pipeline_layout_ci.pNext = NULL;
3289 pipeline_layout_ci.setLayoutCount = 1;
3290 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003291
3292 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003294 ASSERT_VK_SUCCESS(err);
3295
Mark Youngad779052016-01-06 14:26:04 -07003296 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003297
3298 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003299 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003300
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003301 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003302
Chia-I Wuf7458c52015-10-26 21:10:41 +08003303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003306}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003307
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003308TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
3309 VkResult err;
3310
3311 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
3312 "during bind[Buffer|Image]Memory time");
3313
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003314 ASSERT_NO_FATAL_FAILURE(InitState());
3315
3316 // Create an image, allocate memory, set a bad typeIndex and then try to
3317 // bind it
3318 VkImage image;
3319 VkDeviceMemory mem;
3320 VkMemoryRequirements mem_reqs;
3321 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3322 const int32_t tex_width = 32;
3323 const int32_t tex_height = 32;
3324
3325 VkImageCreateInfo image_create_info = {};
3326 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3327 image_create_info.pNext = NULL;
3328 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3329 image_create_info.format = tex_format;
3330 image_create_info.extent.width = tex_width;
3331 image_create_info.extent.height = tex_height;
3332 image_create_info.extent.depth = 1;
3333 image_create_info.mipLevels = 1;
3334 image_create_info.arrayLayers = 1;
3335 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3336 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3337 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3338 image_create_info.flags = 0;
3339
3340 VkMemoryAllocateInfo mem_alloc = {};
3341 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3342 mem_alloc.pNext = NULL;
3343 mem_alloc.allocationSize = 0;
3344 mem_alloc.memoryTypeIndex = 0;
3345
3346 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3347 ASSERT_VK_SUCCESS(err);
3348
3349 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
3350 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003351
3352 // Introduce Failure, select invalid TypeIndex
3353 VkPhysicalDeviceMemoryProperties memory_info;
3354
3355 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
3356 unsigned int i;
3357 for (i = 0; i < memory_info.memoryTypeCount; i++) {
3358 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
3359 mem_alloc.memoryTypeIndex = i;
3360 break;
3361 }
3362 }
3363 if (i >= memory_info.memoryTypeCount) {
3364 printf("No invalid memory type index could be found; skipped.\n");
3365 vkDestroyImage(m_device->device(), image, NULL);
3366 return;
3367 }
3368
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06003370
3371 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3372 ASSERT_VK_SUCCESS(err);
3373
3374 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3375 (void)err;
3376
3377 m_errorMonitor->VerifyFound();
3378
3379 vkDestroyImage(m_device->device(), image, NULL);
3380 vkFreeMemory(m_device->device(), mem, NULL);
3381}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06003382
Karl Schultz6addd812016-02-02 17:17:23 -07003383TEST_F(VkLayerTest, BindInvalidMemory) {
3384 VkResult err;
3385 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003388
Tobin Ehlisec598302015-09-15 15:02:17 -06003389 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003390
3391 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07003392 VkImage image;
3393 VkDeviceMemory mem;
3394 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003395
Karl Schultz6addd812016-02-02 17:17:23 -07003396 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3397 const int32_t tex_width = 32;
3398 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003399
3400 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003401 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3402 image_create_info.pNext = NULL;
3403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3404 image_create_info.format = tex_format;
3405 image_create_info.extent.width = tex_width;
3406 image_create_info.extent.height = tex_height;
3407 image_create_info.extent.depth = 1;
3408 image_create_info.mipLevels = 1;
3409 image_create_info.arrayLayers = 1;
3410 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3411 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3412 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3413 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003414
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003415 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003416 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3417 mem_alloc.pNext = NULL;
3418 mem_alloc.allocationSize = 0;
3419 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003420
Chia-I Wuf7458c52015-10-26 21:10:41 +08003421 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003422 ASSERT_VK_SUCCESS(err);
3423
Karl Schultz6addd812016-02-02 17:17:23 -07003424 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003425
3426 mem_alloc.allocationSize = mem_reqs.size;
3427
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003428 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003429 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003430
3431 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003432 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003433 ASSERT_VK_SUCCESS(err);
3434
3435 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003436 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003437
3438 // Try to bind free memory that has been freed
3439 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3440 // This may very well return an error.
3441 (void)err;
3442
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003443 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003444
Chia-I Wuf7458c52015-10-26 21:10:41 +08003445 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003446}
3447
Karl Schultz6addd812016-02-02 17:17:23 -07003448TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
3449 VkResult err;
3450 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06003451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003453
Tobin Ehlisec598302015-09-15 15:02:17 -06003454 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06003455
Karl Schultz6addd812016-02-02 17:17:23 -07003456 // Create an image object, allocate memory, destroy the object and then try
3457 // to bind it
3458 VkImage image;
3459 VkDeviceMemory mem;
3460 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06003461
Karl Schultz6addd812016-02-02 17:17:23 -07003462 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3463 const int32_t tex_width = 32;
3464 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06003465
3466 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003467 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3468 image_create_info.pNext = NULL;
3469 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3470 image_create_info.format = tex_format;
3471 image_create_info.extent.width = tex_width;
3472 image_create_info.extent.height = tex_height;
3473 image_create_info.extent.depth = 1;
3474 image_create_info.mipLevels = 1;
3475 image_create_info.arrayLayers = 1;
3476 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3477 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3478 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3479 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003480
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003481 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003482 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3483 mem_alloc.pNext = NULL;
3484 mem_alloc.allocationSize = 0;
3485 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06003486
Chia-I Wuf7458c52015-10-26 21:10:41 +08003487 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06003488 ASSERT_VK_SUCCESS(err);
3489
Karl Schultz6addd812016-02-02 17:17:23 -07003490 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06003491
3492 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003494 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003495
3496 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003497 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003498 ASSERT_VK_SUCCESS(err);
3499
3500 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003501 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003502 ASSERT_VK_SUCCESS(err);
3503
3504 // Now Try to bind memory to this destroyed object
3505 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3506 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003507 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003508
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003509 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003510
Chia-I Wuf7458c52015-10-26 21:10:41 +08003511 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003512}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003513
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003514#endif // OBJ_TRACKER_TESTS
3515
Tobin Ehlis0788f522015-05-26 16:11:58 -06003516#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003517
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003518TEST_F(VkLayerTest, ImageSampleCounts) {
3519
3520 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
3521 "validation errors.");
3522 ASSERT_NO_FATAL_FAILURE(InitState());
3523
3524 VkMemoryPropertyFlags reqs = 0;
3525 VkImageCreateInfo image_create_info = {};
3526 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3527 image_create_info.pNext = NULL;
3528 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3529 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3530 image_create_info.extent.width = 256;
3531 image_create_info.extent.height = 256;
3532 image_create_info.extent.depth = 1;
3533 image_create_info.mipLevels = 1;
3534 image_create_info.arrayLayers = 1;
3535 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3536 image_create_info.flags = 0;
3537
3538 VkImageBlit blit_region = {};
3539 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3540 blit_region.srcSubresource.baseArrayLayer = 0;
3541 blit_region.srcSubresource.layerCount = 1;
3542 blit_region.srcSubresource.mipLevel = 0;
3543 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3544 blit_region.dstSubresource.baseArrayLayer = 0;
3545 blit_region.dstSubresource.layerCount = 1;
3546 blit_region.dstSubresource.mipLevel = 0;
3547
3548 // Create two images, the source with sampleCount = 2, and attempt to blit
3549 // between them
3550 {
3551 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003552 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003553 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003555 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003557 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003558 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003559 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3561 "of VK_SAMPLE_COUNT_2_BIT but "
3562 "must be VK_SAMPLE_COUNT_1_BIT");
3563 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3564 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003565 m_errorMonitor->VerifyFound();
3566 m_commandBuffer->EndCommandBuffer();
3567 }
3568
3569 // Create two images, the dest with sampleCount = 4, and attempt to blit
3570 // between them
3571 {
3572 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003574 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003576 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003577 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003578 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003579 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003580 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3582 "of VK_SAMPLE_COUNT_4_BIT but "
3583 "must be VK_SAMPLE_COUNT_1_BIT");
3584 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3585 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003586 m_errorMonitor->VerifyFound();
3587 m_commandBuffer->EndCommandBuffer();
3588 }
3589
3590 VkBufferImageCopy copy_region = {};
3591 copy_region.bufferRowLength = 128;
3592 copy_region.bufferImageHeight = 128;
3593 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3594 copy_region.imageSubresource.layerCount = 1;
3595 copy_region.imageExtent.height = 64;
3596 copy_region.imageExtent.width = 64;
3597 copy_region.imageExtent.depth = 1;
3598
3599 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3600 // buffer to image
3601 {
3602 vk_testing::Buffer src_buffer;
3603 VkMemoryPropertyFlags reqs = 0;
3604 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3605 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003606 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003607 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003609 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3611 "of VK_SAMPLE_COUNT_8_BIT but "
3612 "must be VK_SAMPLE_COUNT_1_BIT");
3613 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3614 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003615 m_errorMonitor->VerifyFound();
3616 m_commandBuffer->EndCommandBuffer();
3617 }
3618
3619 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3620 // image to buffer
3621 {
3622 vk_testing::Buffer dst_buffer;
3623 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3624 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003626 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003628 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
3630 "of VK_SAMPLE_COUNT_2_BIT but "
3631 "must be VK_SAMPLE_COUNT_1_BIT");
3632 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003633 dst_buffer.handle(), 1, &copy_region);
3634 m_errorMonitor->VerifyFound();
3635 m_commandBuffer->EndCommandBuffer();
3636 }
3637}
3638
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003639TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3640 VkResult err;
3641 bool pass;
3642
3643 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3644 ASSERT_NO_FATAL_FAILURE(InitState());
3645
3646 // If w/d/h granularity is 1, test is not meaningful
3647 // TODO: When virtual device limits are available, create a set of limits for this test that
3648 // will always have a granularity of > 1 for w, h, and d
3649 auto index = m_device->graphics_queue_node_index_;
3650 auto queue_family_properties = m_device->phy().queue_properties();
3651
3652 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3653 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3654 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3655 return;
3656 }
3657
3658 // Create two images of different types and try to copy between them
3659 VkImage srcImage;
3660 VkImage dstImage;
3661 VkDeviceMemory srcMem;
3662 VkDeviceMemory destMem;
3663 VkMemoryRequirements memReqs;
3664
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003665 VkImageCreateInfo image_create_info = {};
3666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3667 image_create_info.pNext = NULL;
3668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3669 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3670 image_create_info.extent.width = 32;
3671 image_create_info.extent.height = 32;
3672 image_create_info.extent.depth = 1;
3673 image_create_info.mipLevels = 1;
3674 image_create_info.arrayLayers = 4;
3675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3676 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3677 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3678 image_create_info.flags = 0;
3679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003681 ASSERT_VK_SUCCESS(err);
3682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003683 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003684 ASSERT_VK_SUCCESS(err);
3685
3686 // Allocate memory
3687 VkMemoryAllocateInfo memAlloc = {};
3688 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3689 memAlloc.pNext = NULL;
3690 memAlloc.allocationSize = 0;
3691 memAlloc.memoryTypeIndex = 0;
3692
3693 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3694 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003695 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003696 ASSERT_TRUE(pass);
3697 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3698 ASSERT_VK_SUCCESS(err);
3699
3700 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3701 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003703 ASSERT_VK_SUCCESS(err);
3704 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3705 ASSERT_VK_SUCCESS(err);
3706
3707 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3708 ASSERT_VK_SUCCESS(err);
3709 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3710 ASSERT_VK_SUCCESS(err);
3711
3712 BeginCommandBuffer();
3713 VkImageCopy copyRegion;
3714 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3715 copyRegion.srcSubresource.mipLevel = 0;
3716 copyRegion.srcSubresource.baseArrayLayer = 0;
3717 copyRegion.srcSubresource.layerCount = 1;
3718 copyRegion.srcOffset.x = 0;
3719 copyRegion.srcOffset.y = 0;
3720 copyRegion.srcOffset.z = 0;
3721 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3722 copyRegion.dstSubresource.mipLevel = 0;
3723 copyRegion.dstSubresource.baseArrayLayer = 0;
3724 copyRegion.dstSubresource.layerCount = 1;
3725 copyRegion.dstOffset.x = 0;
3726 copyRegion.dstOffset.y = 0;
3727 copyRegion.dstOffset.z = 0;
3728 copyRegion.extent.width = 1;
3729 copyRegion.extent.height = 1;
3730 copyRegion.extent.depth = 1;
3731
3732 // Introduce failure by setting srcOffset to a bad granularity value
3733 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3735 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003736 m_errorMonitor->VerifyFound();
3737
3738 // Introduce failure by setting extent to a bad granularity value
3739 copyRegion.srcOffset.y = 0;
3740 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3742 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003743 m_errorMonitor->VerifyFound();
3744
3745 // Now do some buffer/image copies
3746 vk_testing::Buffer buffer;
3747 VkMemoryPropertyFlags reqs = 0;
3748 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3749 VkBufferImageCopy region = {};
3750 region.bufferOffset = 0;
3751 region.bufferRowLength = 3;
3752 region.bufferImageHeight = 128;
3753 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3754 region.imageSubresource.layerCount = 1;
3755 region.imageExtent.height = 16;
3756 region.imageExtent.width = 16;
3757 region.imageExtent.depth = 1;
3758 region.imageOffset.x = 0;
3759 region.imageOffset.y = 0;
3760 region.imageOffset.z = 0;
3761
3762 // Introduce failure by setting bufferRowLength to a bad granularity value
3763 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3765 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3766 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003767 m_errorMonitor->VerifyFound();
3768 region.bufferRowLength = 128;
3769
3770 // Introduce failure by setting bufferOffset to a bad granularity value
3771 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3773 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3774 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003775 m_errorMonitor->VerifyFound();
3776 region.bufferOffset = 0;
3777
3778 // Introduce failure by setting bufferImageHeight to a bad granularity value
3779 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3781 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3782 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003783 m_errorMonitor->VerifyFound();
3784 region.bufferImageHeight = 128;
3785
3786 // Introduce failure by setting imageExtent to a bad granularity value
3787 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3789 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3790 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003791 m_errorMonitor->VerifyFound();
3792 region.imageExtent.width = 16;
3793
3794 // Introduce failure by setting imageOffset to a bad granularity value
3795 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3797 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3798 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003799 m_errorMonitor->VerifyFound();
3800
3801 EndCommandBuffer();
3802
3803 vkDestroyImage(m_device->device(), srcImage, NULL);
3804 vkDestroyImage(m_device->device(), dstImage, NULL);
3805 vkFreeMemory(m_device->device(), srcMem, NULL);
3806 vkFreeMemory(m_device->device(), destMem, NULL);
3807}
3808
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003809TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003810 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
3811 "attempt to submit them on a queue created in a different "
3812 "queue family.");
3813
Cody Northropc31a84f2016-08-22 10:41:47 -06003814 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003815 // This test is meaningless unless we have multiple queue families
3816 auto queue_family_properties = m_device->phy().queue_properties();
3817 if (queue_family_properties.size() < 2) {
3818 return;
3819 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003821 // Get safe index of another queue family
3822 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3823 ASSERT_NO_FATAL_FAILURE(InitState());
3824 // Create a second queue using a different queue family
3825 VkQueue other_queue;
3826 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3827
3828 // Record an empty cmd buffer
3829 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3830 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3831 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3832 vkEndCommandBuffer(m_commandBuffer->handle());
3833
3834 // And submit on the wrong queue
3835 VkSubmitInfo submit_info = {};
3836 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3837 submit_info.commandBufferCount = 1;
3838 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003839 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003840
3841 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003842}
3843
Chris Forbes48a53902016-06-30 11:46:27 +12003844TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) {
3845 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
3846 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
3847 "the command buffer has prior knowledge of that "
3848 "attachment's layout.");
3849
3850 m_errorMonitor->ExpectSuccess();
3851
3852 ASSERT_NO_FATAL_FAILURE(InitState());
3853
3854 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003855 VkAttachmentDescription attachment = {0,
3856 VK_FORMAT_R8G8B8A8_UNORM,
3857 VK_SAMPLE_COUNT_1_BIT,
3858 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3859 VK_ATTACHMENT_STORE_OP_STORE,
3860 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3861 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3862 VK_IMAGE_LAYOUT_UNDEFINED,
3863 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003865 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes48a53902016-06-30 11:46:27 +12003866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003867 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003869 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003870
3871 VkRenderPass rp;
3872 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3873 ASSERT_VK_SUCCESS(err);
3874
3875 // A compatible framebuffer.
3876 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003877 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes48a53902016-06-30 11:46:27 +12003878 ASSERT_TRUE(image.initialized());
3879
3880 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003881 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3882 nullptr,
3883 0,
3884 image.handle(),
3885 VK_IMAGE_VIEW_TYPE_2D,
3886 VK_FORMAT_R8G8B8A8_UNORM,
3887 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3888 VK_COMPONENT_SWIZZLE_IDENTITY},
3889 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes48a53902016-06-30 11:46:27 +12003890 };
3891 VkImageView view;
3892 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3893 ASSERT_VK_SUCCESS(err);
3894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003895 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes48a53902016-06-30 11:46:27 +12003896 VkFramebuffer fb;
3897 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3898 ASSERT_VK_SUCCESS(err);
3899
3900 // Record a single command buffer which uses this renderpass twice. The
3901 // bug is triggered at the beginning of the second renderpass, when the
3902 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003903 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes48a53902016-06-30 11:46:27 +12003904 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003905 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003906 vkCmdEndRenderPass(m_commandBuffer->handle());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003907 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes48a53902016-06-30 11:46:27 +12003908
3909 m_errorMonitor->VerifyNotFound();
3910
3911 vkCmdEndRenderPass(m_commandBuffer->handle());
3912 EndCommandBuffer();
3913
3914 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3915 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3916 vkDestroyImageView(m_device->device(), view, nullptr);
3917}
3918
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003919TEST_F(VkLayerTest, FramebufferBindingDestroyCommandPool) {
3920 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
3921 "command buffer, bind them together, then destroy "
3922 "command pool and framebuffer and verify there are no "
3923 "errors.");
3924
3925 m_errorMonitor->ExpectSuccess();
3926
3927 ASSERT_NO_FATAL_FAILURE(InitState());
3928
3929 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003930 VkAttachmentDescription attachment = {0,
3931 VK_FORMAT_R8G8B8A8_UNORM,
3932 VK_SAMPLE_COUNT_1_BIT,
3933 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3934 VK_ATTACHMENT_STORE_OP_STORE,
3935 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
3936 VK_ATTACHMENT_STORE_OP_DONT_CARE,
3937 VK_IMAGE_LAYOUT_UNDEFINED,
3938 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003940 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003942 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003944 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003945
3946 VkRenderPass rp;
3947 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3948 ASSERT_VK_SUCCESS(err);
3949
3950 // A compatible framebuffer.
3951 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003952 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003953 ASSERT_TRUE(image.initialized());
3954
3955 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003956 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
3957 nullptr,
3958 0,
3959 image.handle(),
3960 VK_IMAGE_VIEW_TYPE_2D,
3961 VK_FORMAT_R8G8B8A8_UNORM,
3962 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
3963 VK_COMPONENT_SWIZZLE_IDENTITY},
3964 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003965 };
3966 VkImageView view;
3967 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
3968 ASSERT_VK_SUCCESS(err);
3969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003970 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003971 VkFramebuffer fb;
3972 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
3973 ASSERT_VK_SUCCESS(err);
3974
3975 // Explicitly create a command buffer to bind the FB to so that we can then
3976 // destroy the command pool in order to implicitly free command buffer
3977 VkCommandPool command_pool;
3978 VkCommandPoolCreateInfo pool_create_info{};
3979 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3980 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3981 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003983
3984 VkCommandBuffer command_buffer;
3985 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003986 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003987 command_buffer_allocate_info.commandPool = command_pool;
3988 command_buffer_allocate_info.commandBufferCount = 1;
3989 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003990 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003991
3992 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003993 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06003994 VkCommandBufferBeginInfo begin_info{};
3995 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3996 vkBeginCommandBuffer(command_buffer, &begin_info);
3997
3998 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3999 vkCmdEndRenderPass(command_buffer);
4000 vkEndCommandBuffer(command_buffer);
Mark Lobodzinski7d10a822016-08-03 14:08:40 -06004001 vkDestroyImageView(m_device->device(), view, nullptr);
Tobin Ehlis75ac37b2016-07-29 10:55:41 -06004002 // Destroy command pool to implicitly free command buffer
4003 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4004 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4005 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4006 m_errorMonitor->VerifyNotFound();
4007}
4008
Chris Forbes51bf7c92016-06-30 15:22:08 +12004009TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) {
4010 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
4011 "transitions for the first subpass");
4012
4013 m_errorMonitor->ExpectSuccess();
4014
4015 ASSERT_NO_FATAL_FAILURE(InitState());
4016
4017 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004018 VkAttachmentDescription attachment = {0,
4019 VK_FORMAT_R8G8B8A8_UNORM,
4020 VK_SAMPLE_COUNT_1_BIT,
4021 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4022 VK_ATTACHMENT_STORE_OP_STORE,
4023 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4024 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4025 VK_IMAGE_LAYOUT_UNDEFINED,
4026 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004028 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004030 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004032 VkSubpassDependency dep = {0,
4033 0,
4034 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4035 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4036 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4037 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4038 VK_DEPENDENCY_BY_REGION_BIT};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004040 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004041
4042 VkResult err;
4043 VkRenderPass rp;
4044 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4045 ASSERT_VK_SUCCESS(err);
4046
4047 // A compatible framebuffer.
4048 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004049 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004050 ASSERT_TRUE(image.initialized());
4051
4052 VkImageViewCreateInfo ivci = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004053 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4054 nullptr,
4055 0,
4056 image.handle(),
4057 VK_IMAGE_VIEW_TYPE_2D,
4058 VK_FORMAT_R8G8B8A8_UNORM,
4059 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
4060 VK_COMPONENT_SWIZZLE_IDENTITY},
4061 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Chris Forbes51bf7c92016-06-30 15:22:08 +12004062 };
4063 VkImageView view;
4064 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4065 ASSERT_VK_SUCCESS(err);
4066
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004067 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004068 VkFramebuffer fb;
4069 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4070 ASSERT_VK_SUCCESS(err);
4071
4072 // Record a single command buffer which issues a pipeline barrier w/
4073 // image memory barrier for the attachment. This detects the previously
4074 // missing tracking of the subpass layout by throwing a validation error
4075 // if it doesn't occur.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004076 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes51bf7c92016-06-30 15:22:08 +12004077 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004078 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004080 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
4081 nullptr,
4082 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4083 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4084 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4085 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4086 VK_QUEUE_FAMILY_IGNORED,
4087 VK_QUEUE_FAMILY_IGNORED,
4088 image.handle(),
4089 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
4090 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4091 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
4092 &imb);
Chris Forbes51bf7c92016-06-30 15:22:08 +12004093
4094 vkCmdEndRenderPass(m_commandBuffer->handle());
4095 m_errorMonitor->VerifyNotFound();
4096 EndCommandBuffer();
4097
4098 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4099 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4100 vkDestroyImageView(m_device->device(), view, nullptr);
4101}
4102
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004103TEST_F(VkLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
4104 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
4105 "is used as a depth/stencil framebuffer attachment, the "
4106 "aspectMask is ignored and both depth and stencil image "
4107 "subresources are used.");
4108
4109 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004110 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
4111 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004112 return;
4113 }
4114
4115 m_errorMonitor->ExpectSuccess();
4116
4117 ASSERT_NO_FATAL_FAILURE(InitState());
4118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004119 VkAttachmentDescription attachment = {0,
4120 VK_FORMAT_D32_SFLOAT_S8_UINT,
4121 VK_SAMPLE_COUNT_1_BIT,
4122 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4123 VK_ATTACHMENT_STORE_OP_STORE,
4124 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
4125 VK_ATTACHMENT_STORE_OP_DONT_CARE,
4126 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4127 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004129 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004131 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004132
4133 VkSubpassDependency dep = {0,
4134 0,
4135 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4136 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4137 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4138 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4139 VK_DEPENDENCY_BY_REGION_BIT};
4140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004141 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004142
4143 VkResult err;
4144 VkRenderPass rp;
4145 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4146 ASSERT_VK_SUCCESS(err);
4147
4148 VkImageObj image(m_device);
4149 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
4150 0x26, // usage
4151 VK_IMAGE_TILING_OPTIMAL, 0);
4152 ASSERT_TRUE(image.initialized());
4153 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
4154
4155 VkImageViewCreateInfo ivci = {
4156 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4157 nullptr,
4158 0,
4159 image.handle(),
4160 VK_IMAGE_VIEW_TYPE_2D,
4161 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004163 {0x2, 0, 1, 0, 1},
4164 };
4165 VkImageView view;
4166 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4167 ASSERT_VK_SUCCESS(err);
4168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004169 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004170 VkFramebuffer fb;
4171 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4172 ASSERT_VK_SUCCESS(err);
4173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004174 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004175 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004176 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004177
4178 VkImageMemoryBarrier imb = {};
4179 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
4180 imb.pNext = nullptr;
4181 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4182 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
4183 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4184 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4185 imb.srcQueueFamilyIndex = 0;
4186 imb.dstQueueFamilyIndex = 0;
4187 imb.image = image.handle();
4188 imb.subresourceRange.aspectMask = 0x6;
4189 imb.subresourceRange.baseMipLevel = 0;
4190 imb.subresourceRange.levelCount = 0x1;
4191 imb.subresourceRange.baseArrayLayer = 0;
4192 imb.subresourceRange.layerCount = 0x1;
4193
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004194 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
4195 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski77a5d6f2016-08-05 09:38:18 -06004196 &imb);
4197
4198 vkCmdEndRenderPass(m_commandBuffer->handle());
4199 EndCommandBuffer();
4200 QueueCommandBuffer(false);
4201 m_errorMonitor->VerifyNotFound();
4202
4203 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4204 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4205 vkDestroyImageView(m_device->device(), view, nullptr);
4206}
Tony Barbourd5f7b822016-08-02 15:39:33 -06004207
Tony Barbour4e919972016-08-09 13:27:40 -06004208TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
4209 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
4210 "with extent outside of framebuffer");
4211 ASSERT_NO_FATAL_FAILURE(InitState());
4212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
4215 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06004216
4217 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
4218 m_renderPassBeginInfo.renderArea.extent.width = 257;
4219 m_renderPassBeginInfo.renderArea.extent.height = 257;
4220 BeginCommandBuffer();
4221 m_errorMonitor->VerifyFound();
4222}
4223
4224TEST_F(VkLayerTest, DisabledIndependentBlend) {
4225 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
4226 "blend and then specifying different blend states for two "
4227 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06004228 VkPhysicalDeviceFeatures features = {};
4229 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06004230 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06004231
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4233 "Invalid Pipeline CreateInfo: If independent blend feature not "
4234 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06004235
Cody Northropc31a84f2016-08-22 10:41:47 -06004236 VkDescriptorSetObj descriptorSet(m_device);
4237 descriptorSet.AppendDummy();
4238 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06004239
Cody Northropc31a84f2016-08-22 10:41:47 -06004240 VkPipelineObj pipeline(m_device);
4241 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06004243 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06004244
Cody Northropc31a84f2016-08-22 10:41:47 -06004245 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
4246 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4247 att_state1.blendEnable = VK_TRUE;
4248 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
4249 att_state2.blendEnable = VK_FALSE;
4250 pipeline.AddColorAttachment(0, &att_state1);
4251 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06004253 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06004254}
4255
4256TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
4257 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
4258 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06004259 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06004260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4262 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06004263
4264 // Create a renderPass with a single color attachment
4265 VkAttachmentReference attach = {};
4266 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4267 VkSubpassDescription subpass = {};
4268 VkRenderPassCreateInfo rpci = {};
4269 rpci.subpassCount = 1;
4270 rpci.pSubpasses = &subpass;
4271 rpci.attachmentCount = 1;
4272 VkAttachmentDescription attach_desc = {};
4273 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4274 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4275 rpci.pAttachments = &attach_desc;
4276 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4277 VkRenderPass rp;
4278 subpass.pDepthStencilAttachment = &attach;
4279 subpass.pColorAttachments = NULL;
4280 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4281 m_errorMonitor->VerifyFound();
4282}
4283
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004284TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) {
4285 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
4286 "errors, when an attachment reference is "
4287 "VK_ATTACHMENT_UNUSED");
4288
4289 m_errorMonitor->ExpectSuccess();
4290
4291 ASSERT_NO_FATAL_FAILURE(InitState());
4292
4293 // A renderpass with no attachments
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004294 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004295
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004296 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004298 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004299
4300 VkRenderPass rp;
4301 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4302 ASSERT_VK_SUCCESS(err);
4303
4304 // A compatible framebuffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004306 VkFramebuffer fb;
4307 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4308 ASSERT_VK_SUCCESS(err);
4309
4310 // Record a command buffer which just begins and ends the renderpass. The
4311 // bug manifests in BeginRenderPass.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004313 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004314 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes6b3d3f42016-06-30 16:09:47 +12004315 vkCmdEndRenderPass(m_commandBuffer->handle());
4316 m_errorMonitor->VerifyNotFound();
4317 EndCommandBuffer();
4318
4319 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4320 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4321}
4322
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004323// This is a positive test. No errors are expected.
4324TEST_F(VkLayerTest, StencilLoadOp) {
4325 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
4326 "CLEAR. stencil[Load|Store]Op used to be ignored.");
4327 VkResult result = VK_SUCCESS;
4328 VkImageFormatProperties formatProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
4330 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
4331 &formatProps);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004332 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
4333 return;
4334 }
4335
4336 ASSERT_NO_FATAL_FAILURE(InitState());
4337 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
4338 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004339 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004340 VkAttachmentDescription att = {};
4341 VkAttachmentReference ref = {};
4342 att.format = depth_stencil_fmt;
Chris Forbes787b4532016-09-16 16:45:16 +12004343 att.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004344 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
4345 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
4346 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
4347 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
4348 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4349 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4350
4351 VkClearValue clear;
4352 clear.depthStencil.depth = 1.0;
4353 clear.depthStencil.stencil = 0;
4354 ref.attachment = 0;
4355 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4356
4357 VkSubpassDescription subpass = {};
4358 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
4359 subpass.flags = 0;
4360 subpass.inputAttachmentCount = 0;
4361 subpass.pInputAttachments = NULL;
4362 subpass.colorAttachmentCount = 0;
4363 subpass.pColorAttachments = NULL;
4364 subpass.pResolveAttachments = NULL;
4365 subpass.pDepthStencilAttachment = &ref;
4366 subpass.preserveAttachmentCount = 0;
4367 subpass.pPreserveAttachments = NULL;
4368
4369 VkRenderPass rp;
4370 VkRenderPassCreateInfo rp_info = {};
4371 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4372 rp_info.attachmentCount = 1;
4373 rp_info.pAttachments = &att;
4374 rp_info.subpassCount = 1;
4375 rp_info.pSubpasses = &subpass;
4376 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
4377 ASSERT_VK_SUCCESS(result);
4378
4379 VkImageView *depthView = m_depthStencil->BindInfo();
4380 VkFramebufferCreateInfo fb_info = {};
4381 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4382 fb_info.pNext = NULL;
4383 fb_info.renderPass = rp;
4384 fb_info.attachmentCount = 1;
4385 fb_info.pAttachments = depthView;
4386 fb_info.width = 100;
4387 fb_info.height = 100;
4388 fb_info.layers = 1;
4389 VkFramebuffer fb;
4390 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4391 ASSERT_VK_SUCCESS(result);
4392
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004393 VkRenderPassBeginInfo rpbinfo = {};
4394 rpbinfo.clearValueCount = 1;
4395 rpbinfo.pClearValues = &clear;
4396 rpbinfo.pNext = NULL;
4397 rpbinfo.renderPass = rp;
4398 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
4399 rpbinfo.renderArea.extent.width = 100;
4400 rpbinfo.renderArea.extent.height = 100;
4401 rpbinfo.renderArea.offset.x = 0;
4402 rpbinfo.renderArea.offset.y = 0;
4403 rpbinfo.framebuffer = fb;
4404
4405 VkFence fence = {};
4406 VkFenceCreateInfo fence_ci = {};
4407 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4408 fence_ci.pNext = nullptr;
4409 fence_ci.flags = 0;
4410 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
4411 ASSERT_VK_SUCCESS(result);
4412
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004413 m_commandBuffer->BeginCommandBuffer();
4414 m_commandBuffer->BeginRenderPass(rpbinfo);
4415 m_commandBuffer->EndRenderPass();
4416 m_commandBuffer->EndCommandBuffer();
4417 m_commandBuffer->QueueCommandBuffer(fence);
4418
4419 VkImageObj destImage(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004421 VK_IMAGE_TILING_OPTIMAL, 0);
4422 VkImageMemoryBarrier barrier = {};
4423 VkImageSubresourceRange range;
4424 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004425 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4426 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004427 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
4428 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4429 barrier.image = m_depthStencil->handle();
4430 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4431 range.baseMipLevel = 0;
4432 range.levelCount = 1;
4433 range.baseArrayLayer = 0;
4434 range.layerCount = 1;
4435 barrier.subresourceRange = range;
4436 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4437 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
4438 cmdbuf.BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004439 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4440 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004441 barrier.srcAccessMask = 0;
4442 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4443 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4444 barrier.image = destImage.handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004445 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
4446 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
4447 &barrier);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004448 VkImageCopy cregion;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004449 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004450 cregion.srcSubresource.mipLevel = 0;
4451 cregion.srcSubresource.baseArrayLayer = 0;
4452 cregion.srcSubresource.layerCount = 1;
4453 cregion.srcOffset.x = 0;
4454 cregion.srcOffset.y = 0;
4455 cregion.srcOffset.z = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004456 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004457 cregion.dstSubresource.mipLevel = 0;
4458 cregion.dstSubresource.baseArrayLayer = 0;
4459 cregion.dstSubresource.layerCount = 1;
4460 cregion.dstOffset.x = 0;
4461 cregion.dstOffset.y = 0;
4462 cregion.dstOffset.z = 0;
4463 cregion.extent.width = 100;
4464 cregion.extent.height = 100;
4465 cregion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004466 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004467 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
4468 cmdbuf.EndCommandBuffer();
4469
4470 VkSubmitInfo submit_info;
4471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4472 submit_info.pNext = NULL;
4473 submit_info.waitSemaphoreCount = 0;
4474 submit_info.pWaitSemaphores = NULL;
4475 submit_info.pWaitDstStageMask = NULL;
4476 submit_info.commandBufferCount = 1;
4477 submit_info.pCommandBuffers = &cmdbuf.handle();
4478 submit_info.signalSemaphoreCount = 0;
4479 submit_info.pSignalSemaphores = NULL;
4480
4481 m_errorMonitor->ExpectSuccess();
4482 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4483 m_errorMonitor->VerifyNotFound();
4484
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06004485 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06004486 vkDestroyFence(m_device->device(), fence, nullptr);
4487 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4488 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4489}
4490
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004491TEST_F(VkLayerTest, UnusedPreserveAttachment) {
4492 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
4493 "attachment reference of VK_ATTACHMENT_UNUSED");
4494
4495 ASSERT_NO_FATAL_FAILURE(InitState());
4496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004499
4500 VkAttachmentReference color_attach = {};
4501 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4502 color_attach.attachment = 0;
4503 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
4504 VkSubpassDescription subpass = {};
4505 subpass.colorAttachmentCount = 1;
4506 subpass.pColorAttachments = &color_attach;
4507 subpass.preserveAttachmentCount = 1;
4508 subpass.pPreserveAttachments = &preserve_attachment;
4509
4510 VkRenderPassCreateInfo rpci = {};
4511 rpci.subpassCount = 1;
4512 rpci.pSubpasses = &subpass;
4513 rpci.attachmentCount = 1;
4514 VkAttachmentDescription attach_desc = {};
4515 attach_desc.format = VK_FORMAT_UNDEFINED;
4516 rpci.pAttachments = &attach_desc;
4517 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4518 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004519 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004520
4521 m_errorMonitor->VerifyFound();
4522
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06004523 if (result == VK_SUCCESS) {
4524 vkDestroyRenderPass(m_device->device(), rp, NULL);
4525 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004526}
4527
Chris Forbesc5389742016-06-29 11:49:23 +12004528TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004529 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
4530 "when the source of a subpass multisample resolve "
4531 "does not have multiple samples.");
4532
Chris Forbesc5389742016-06-29 11:49:23 +12004533 ASSERT_NO_FATAL_FAILURE(InitState());
4534
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4536 "Subpass 0 requests multisample resolve from attachment 0 which has "
4537 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004538
4539 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004540 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4541 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4542 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4543 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4544 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4545 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004546 };
4547
4548 VkAttachmentReference color = {
4549 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4550 };
4551
4552 VkAttachmentReference resolve = {
4553 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4554 };
4555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004556 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004557
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004558 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004559
4560 VkRenderPass rp;
4561 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4562
4563 m_errorMonitor->VerifyFound();
4564
4565 if (err == VK_SUCCESS)
4566 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4567}
4568
4569TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004570 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4571 "when a subpass multisample resolve operation is "
4572 "requested, and the destination of that resolve has "
4573 "multiple samples.");
4574
Chris Forbesc5389742016-06-29 11:49:23 +12004575 ASSERT_NO_FATAL_FAILURE(InitState());
4576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4578 "Subpass 0 requests multisample resolve into attachment 1, which "
4579 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12004580
4581 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004582 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4583 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4584 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4585 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4586 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4587 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12004588 };
4589
4590 VkAttachmentReference color = {
4591 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4592 };
4593
4594 VkAttachmentReference resolve = {
4595 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4596 };
4597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004598 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004600 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12004601
4602 VkRenderPass rp;
4603 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4604
4605 m_errorMonitor->VerifyFound();
4606
4607 if (err == VK_SUCCESS)
4608 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4609}
4610
Chris Forbes3f128ef2016-06-29 14:58:53 +12004611TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12004612 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
4613 "when the color and depth attachments used by a subpass "
4614 "have inconsistent sample counts");
4615
Chris Forbes3f128ef2016-06-29 14:58:53 +12004616 ASSERT_NO_FATAL_FAILURE(InitState());
4617
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4619 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12004620
4621 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004622 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4623 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4624 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
4625 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
4626 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4627 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12004628 };
4629
4630 VkAttachmentReference color[] = {
4631 {
4632 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4633 },
4634 {
4635 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4636 },
4637 };
4638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004640
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004641 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12004642
4643 VkRenderPass rp;
4644 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
4645
4646 m_errorMonitor->VerifyFound();
4647
4648 if (err == VK_SUCCESS)
4649 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4650}
4651
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004652TEST_F(VkLayerTest, FramebufferCreateErrors) {
4653 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
4654 " 1. Mismatch between fb & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004655 " 2. Use a color image as depthStencil attachment\n"
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004656 " 3. Mismatch fb & renderPass attachment formats\n"
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004657 " 4. Mismatch fb & renderPass attachment #samples\n"
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004658 " 5. FB attachment w/ non-1 mip-levels\n"
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004659 " 6. FB attachment where dimensions don't match\n"
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004660 " 7. FB attachment w/o identity swizzle\n"
4661 " 8. FB dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004662
4663 ASSERT_NO_FATAL_FAILURE(InitState());
4664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4665
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4667 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
4668 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004669
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004670 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004671 VkAttachmentReference attach = {};
4672 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4673 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004674 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004675 VkRenderPassCreateInfo rpci = {};
4676 rpci.subpassCount = 1;
4677 rpci.pSubpasses = &subpass;
4678 rpci.attachmentCount = 1;
4679 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004680 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004681 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004682 rpci.pAttachments = &attach_desc;
4683 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4684 VkRenderPass rp;
4685 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4686 ASSERT_VK_SUCCESS(err);
4687
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004688 VkImageView ivs[2];
4689 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
4690 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004691 VkFramebufferCreateInfo fb_info = {};
4692 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
4693 fb_info.pNext = NULL;
4694 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004695 // Set mis-matching attachmentCount
4696 fb_info.attachmentCount = 2;
4697 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004698 fb_info.width = 100;
4699 fb_info.height = 100;
4700 fb_info.layers = 1;
4701
4702 VkFramebuffer fb;
4703 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4704
4705 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004706 if (err == VK_SUCCESS) {
4707 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4708 }
4709 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004710
4711 // Create a renderPass with a depth-stencil attachment created with
4712 // IMAGE_USAGE_COLOR_ATTACHMENT
4713 // Add our color attachment to pDepthStencilAttachment
4714 subpass.pDepthStencilAttachment = &attach;
4715 subpass.pColorAttachments = NULL;
4716 VkRenderPass rp_ds;
4717 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
4718 ASSERT_VK_SUCCESS(err);
4719 // Set correct attachment count, but attachment has COLOR usage bit set
4720 fb_info.attachmentCount = 1;
4721 fb_info.renderPass = rp_ds;
4722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06004724 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4725
4726 m_errorMonitor->VerifyFound();
4727 if (err == VK_SUCCESS) {
4728 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4729 }
4730 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004731
4732 // Create new renderpass with alternate attachment format from fb
4733 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
4734 subpass.pDepthStencilAttachment = NULL;
4735 subpass.pColorAttachments = &attach;
4736 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4737 ASSERT_VK_SUCCESS(err);
4738
4739 // Cause error due to mis-matched formats between rp & fb
4740 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
4741 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4743 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004744 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4745
4746 m_errorMonitor->VerifyFound();
4747 if (err == VK_SUCCESS) {
4748 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4749 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004750 vkDestroyRenderPass(m_device->device(), rp, NULL);
4751
4752 // Create new renderpass with alternate sample count from fb
4753 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4754 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
4755 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4756 ASSERT_VK_SUCCESS(err);
4757
4758 // Cause error due to mis-matched sample count between rp & fb
4759 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
4761 "that do not match the "
4762 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06004763 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4764
4765 m_errorMonitor->VerifyFound();
4766 if (err == VK_SUCCESS) {
4767 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4768 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06004769
4770 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004771
4772 // Create a custom imageView with non-1 mip levels
4773 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004774 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004775 ASSERT_TRUE(image.initialized());
4776
4777 VkImageView view;
4778 VkImageViewCreateInfo ivci = {};
4779 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4780 ivci.image = image.handle();
4781 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4782 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4783 ivci.subresourceRange.layerCount = 1;
4784 ivci.subresourceRange.baseMipLevel = 0;
4785 // Set level count 2 (only 1 is allowed for FB attachment)
4786 ivci.subresourceRange.levelCount = 2;
4787 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4788 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4789 ASSERT_VK_SUCCESS(err);
4790 // Re-create renderpass to have matching sample count
4791 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4792 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4793 ASSERT_VK_SUCCESS(err);
4794
4795 fb_info.renderPass = rp;
4796 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004798 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4799
4800 m_errorMonitor->VerifyFound();
4801 if (err == VK_SUCCESS) {
4802 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4803 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004804 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004805 // Update view to original color buffer and grow FB dimensions too big
4806 fb_info.pAttachments = ivs;
4807 fb_info.height = 1024;
4808 fb_info.width = 1024;
4809 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
4811 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004812 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4813
4814 m_errorMonitor->VerifyFound();
4815 if (err == VK_SUCCESS) {
4816 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4817 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004818 // Create view attachment with non-identity swizzle
4819 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4820 ivci.image = image.handle();
4821 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4822 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4823 ivci.subresourceRange.layerCount = 1;
4824 ivci.subresourceRange.baseMipLevel = 0;
4825 ivci.subresourceRange.levelCount = 1;
4826 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4827 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4828 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4829 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4830 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4831 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4832 ASSERT_VK_SUCCESS(err);
4833
4834 fb_info.pAttachments = &view;
4835 fb_info.height = 100;
4836 fb_info.width = 100;
4837 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
4839 "framebuffer attachments must have "
4840 "been created with the identity "
4841 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004842 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4843
4844 m_errorMonitor->VerifyFound();
4845 if (err == VK_SUCCESS) {
4846 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4847 }
4848 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004849 // Request fb that exceeds max dimensions
4850 // reset attachment to color attachment
4851 fb_info.pAttachments = ivs;
4852 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
4853 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
4854 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
4856 "dimensions exceed physical device "
4857 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004858 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4859
4860 m_errorMonitor->VerifyFound();
4861 if (err == VK_SUCCESS) {
4862 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4863 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004864
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004865 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004866}
4867
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004868// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05004869TEST_F(VkLayerTest, WaitEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004870 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05004871
Michael Lentine860b0fe2016-05-20 10:14:00 -05004872 m_errorMonitor->ExpectSuccess();
Cody Northropc31a84f2016-08-22 10:41:47 -06004873 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05004874
4875 VkEvent event;
4876 VkEventCreateInfo event_create_info{};
4877 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4878 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
4879
4880 VkCommandPool command_pool;
4881 VkCommandPoolCreateInfo pool_create_info{};
4882 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4883 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4884 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004886
4887 VkCommandBuffer command_buffer;
4888 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05004890 command_buffer_allocate_info.commandPool = command_pool;
4891 command_buffer_allocate_info.commandBufferCount = 1;
4892 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004894
4895 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004897
4898 {
4899 VkCommandBufferBeginInfo begin_info{};
4900 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4901 vkBeginCommandBuffer(command_buffer, &begin_info);
4902
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004903 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
Michael Lentine860b0fe2016-05-20 10:14:00 -05004904 nullptr, 0, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004905 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Michael Lentine860b0fe2016-05-20 10:14:00 -05004906 vkEndCommandBuffer(command_buffer);
4907 }
4908 {
4909 VkSubmitInfo submit_info{};
4910 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4911 submit_info.commandBufferCount = 1;
4912 submit_info.pCommandBuffers = &command_buffer;
4913 submit_info.signalSemaphoreCount = 0;
4914 submit_info.pSignalSemaphores = nullptr;
4915 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4916 }
4917 { vkSetEvent(m_device->device(), event); }
4918
4919 vkQueueWaitIdle(queue);
4920
4921 vkDestroyEvent(m_device->device(), event, nullptr);
4922 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
4923 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4924
4925 m_errorMonitor->VerifyNotFound();
4926}
Michael Lentine5627e692016-05-20 17:45:02 -05004927// This is a positive test. No errors should be generated.
Michael Lentinef01fb382016-07-21 17:24:56 -05004928TEST_F(VkLayerTest, QueryAndCopySecondaryCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004929 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
Michael Lentinef01fb382016-07-21 17:24:56 -05004930
Cody Northropc31a84f2016-08-22 10:41:47 -06004931 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004932 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentinef01fb382016-07-21 17:24:56 -05004933 return;
4934
4935 m_errorMonitor->ExpectSuccess();
4936
4937 VkQueryPool query_pool;
4938 VkQueryPoolCreateInfo query_pool_create_info{};
4939 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4940 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
4941 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004943
4944 VkCommandPool command_pool;
4945 VkCommandPoolCreateInfo pool_create_info{};
4946 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4947 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4948 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentinef01fb382016-07-21 17:24:56 -05004950
4951 VkCommandBuffer command_buffer;
4952 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentinef01fb382016-07-21 17:24:56 -05004954 command_buffer_allocate_info.commandPool = command_pool;
4955 command_buffer_allocate_info.commandBufferCount = 1;
4956 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004957 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004958
4959 VkCommandBuffer secondary_command_buffer;
4960 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
Michael Lentinef01fb382016-07-21 17:24:56 -05004962
4963 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004964 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentinef01fb382016-07-21 17:24:56 -05004965
4966 uint32_t qfi = 0;
4967 VkBufferCreateInfo buff_create_info = {};
4968 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4969 buff_create_info.size = 1024;
4970 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
4971 buff_create_info.queueFamilyIndexCount = 1;
4972 buff_create_info.pQueueFamilyIndices = &qfi;
4973
4974 VkResult err;
4975 VkBuffer buffer;
4976 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
4977 ASSERT_VK_SUCCESS(err);
4978 VkMemoryAllocateInfo mem_alloc = {};
4979 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4980 mem_alloc.pNext = NULL;
4981 mem_alloc.allocationSize = 1024;
4982 mem_alloc.memoryTypeIndex = 0;
4983
4984 VkMemoryRequirements memReqs;
4985 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05004987 if (!pass) {
4988 vkDestroyBuffer(m_device->device(), buffer, NULL);
4989 return;
4990 }
4991
4992 VkDeviceMemory mem;
4993 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4994 ASSERT_VK_SUCCESS(err);
4995 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4996 ASSERT_VK_SUCCESS(err);
4997
4998 VkCommandBufferInheritanceInfo hinfo = {};
4999 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
5000 hinfo.renderPass = VK_NULL_HANDLE;
5001 hinfo.subpass = 0;
5002 hinfo.framebuffer = VK_NULL_HANDLE;
5003 hinfo.occlusionQueryEnable = VK_FALSE;
5004 hinfo.queryFlags = 0;
5005 hinfo.pipelineStatistics = 0;
5006
5007 {
5008 VkCommandBufferBeginInfo begin_info{};
5009 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5010 begin_info.pInheritanceInfo = &hinfo;
5011 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
5012
5013 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005015
5016 vkEndCommandBuffer(secondary_command_buffer);
5017
5018 begin_info.pInheritanceInfo = nullptr;
5019 vkBeginCommandBuffer(command_buffer, &begin_info);
5020
5021 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentinef01fb382016-07-21 17:24:56 -05005023
5024 vkEndCommandBuffer(command_buffer);
5025 }
5026 {
5027 VkSubmitInfo submit_info{};
5028 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5029 submit_info.commandBufferCount = 1;
5030 submit_info.pCommandBuffers = &command_buffer;
5031 submit_info.signalSemaphoreCount = 0;
5032 submit_info.pSignalSemaphores = nullptr;
5033 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5034 }
5035
5036 vkQueueWaitIdle(queue);
5037
5038 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5039 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5040 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
5041 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5042 vkDestroyBuffer(m_device->device(), buffer, NULL);
5043 vkFreeMemory(m_device->device(), mem, NULL);
5044
5045 m_errorMonitor->VerifyNotFound();
5046}
5047
5048// This is a positive test. No errors should be generated.
Michael Lentine5627e692016-05-20 17:45:02 -05005049TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005050 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
Michael Lentine5627e692016-05-20 17:45:02 -05005051
Cody Northropc31a84f2016-08-22 10:41:47 -06005052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005053 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Michael Lentine5627e692016-05-20 17:45:02 -05005054 return;
5055
5056 m_errorMonitor->ExpectSuccess();
5057
5058 VkQueryPool query_pool;
5059 VkQueryPoolCreateInfo query_pool_create_info{};
5060 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5061 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
5062 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005063 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005064
5065 VkCommandPool command_pool;
5066 VkCommandPoolCreateInfo pool_create_info{};
5067 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5068 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5069 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine5627e692016-05-20 17:45:02 -05005071
5072 VkCommandBuffer command_buffer[2];
5073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine5627e692016-05-20 17:45:02 -05005075 command_buffer_allocate_info.commandPool = command_pool;
5076 command_buffer_allocate_info.commandBufferCount = 2;
5077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Michael Lentine5627e692016-05-20 17:45:02 -05005079
5080 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005081 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Michael Lentine5627e692016-05-20 17:45:02 -05005082
5083 uint32_t qfi = 0;
5084 VkBufferCreateInfo buff_create_info = {};
5085 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5086 buff_create_info.size = 1024;
5087 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
5088 buff_create_info.queueFamilyIndexCount = 1;
5089 buff_create_info.pQueueFamilyIndices = &qfi;
5090
5091 VkResult err;
5092 VkBuffer buffer;
5093 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
5094 ASSERT_VK_SUCCESS(err);
5095 VkMemoryAllocateInfo mem_alloc = {};
5096 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5097 mem_alloc.pNext = NULL;
5098 mem_alloc.allocationSize = 1024;
5099 mem_alloc.memoryTypeIndex = 0;
5100
5101 VkMemoryRequirements memReqs;
5102 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005103 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005104 if (!pass) {
5105 vkDestroyBuffer(m_device->device(), buffer, NULL);
5106 return;
5107 }
5108
5109 VkDeviceMemory mem;
5110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5111 ASSERT_VK_SUCCESS(err);
5112 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5113 ASSERT_VK_SUCCESS(err);
5114
5115 {
5116 VkCommandBufferBeginInfo begin_info{};
5117 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5118 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5119
5120 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005121 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005122
5123 vkEndCommandBuffer(command_buffer[0]);
5124
5125 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005127 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
Michael Lentine5627e692016-05-20 17:45:02 -05005128
5129 vkEndCommandBuffer(command_buffer[1]);
5130 }
5131 {
5132 VkSubmitInfo submit_info{};
5133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5134 submit_info.commandBufferCount = 2;
5135 submit_info.pCommandBuffers = command_buffer;
5136 submit_info.signalSemaphoreCount = 0;
5137 submit_info.pSignalSemaphores = nullptr;
5138 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5139 }
5140
5141 vkQueueWaitIdle(queue);
5142
5143 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
5144 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
5145 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005146 vkDestroyBuffer(m_device->device(), buffer, NULL);
5147 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05005148
5149 m_errorMonitor->VerifyNotFound();
5150}
Michael Lentine860b0fe2016-05-20 10:14:00 -05005151
5152TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005153 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005154
Michael Lentine860b0fe2016-05-20 10:14:00 -05005155 m_errorMonitor->ExpectSuccess();
5156
Cody Northropc31a84f2016-08-22 10:41:47 -06005157 ASSERT_NO_FATAL_FAILURE(InitState());
Michael Lentine860b0fe2016-05-20 10:14:00 -05005158 VkEvent event;
5159 VkEventCreateInfo event_create_info{};
5160 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5161 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
5162
5163 VkCommandPool command_pool;
5164 VkCommandPoolCreateInfo pool_create_info{};
5165 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5166 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5167 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005168 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005169
5170 VkCommandBuffer command_buffer;
5171 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Michael Lentine860b0fe2016-05-20 10:14:00 -05005173 command_buffer_allocate_info.commandPool = command_pool;
5174 command_buffer_allocate_info.commandBufferCount = 1;
5175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005176 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005177
5178 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005179 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005180
5181 {
5182 VkCommandBufferBeginInfo begin_info{};
5183 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5184 vkBeginCommandBuffer(command_buffer, &begin_info);
5185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005186 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
5187 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
5188 nullptr, 0, nullptr, 0, nullptr);
Michael Lentine860b0fe2016-05-20 10:14:00 -05005189 vkEndCommandBuffer(command_buffer);
5190 }
5191 {
5192 VkSubmitInfo submit_info{};
5193 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5194 submit_info.commandBufferCount = 1;
5195 submit_info.pCommandBuffers = &command_buffer;
5196 submit_info.signalSemaphoreCount = 0;
5197 submit_info.pSignalSemaphores = nullptr;
5198 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5199 }
5200 {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
5202 "command buffer.");
Michael Lentine860b0fe2016-05-20 10:14:00 -05005203 vkSetEvent(m_device->device(), event);
5204 m_errorMonitor->VerifyFound();
5205 }
5206
5207 vkQueueWaitIdle(queue);
5208
5209 vkDestroyEvent(m_device->device(), event, nullptr);
5210 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
5211 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5212}
5213
5214// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005215TEST_F(VkLayerTest, TwoFencesThreeFrames) {
5216 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
5217 "run through a Submit & WaitForFences cycle 3 times. This "
5218 "previously revealed a bug so running this positive test "
5219 "to prevent a regression.");
5220 m_errorMonitor->ExpectSuccess();
5221
5222 ASSERT_NO_FATAL_FAILURE(InitState());
5223 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005224 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005225
5226 static const uint32_t NUM_OBJECTS = 2;
5227 static const uint32_t NUM_FRAMES = 3;
5228 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
5229 VkFence fences[NUM_OBJECTS] = {};
5230
5231 VkCommandPool cmd_pool;
5232 VkCommandPoolCreateInfo cmd_pool_ci = {};
5233 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5234 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
5235 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005236 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005237 ASSERT_VK_SUCCESS(err);
5238
5239 VkCommandBufferAllocateInfo cmd_buf_info = {};
5240 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
5241 cmd_buf_info.commandPool = cmd_pool;
5242 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
5243 cmd_buf_info.commandBufferCount = 1;
5244
5245 VkFenceCreateInfo fence_ci = {};
5246 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5247 fence_ci.pNext = nullptr;
5248 fence_ci.flags = 0;
5249
5250 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005251 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005252 ASSERT_VK_SUCCESS(err);
5253 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
5254 ASSERT_VK_SUCCESS(err);
5255 }
5256
5257 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06005258 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
5259 // Create empty cmd buffer
5260 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
5261 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005262
Tobin Ehlisf9025162016-05-26 06:55:21 -06005263 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
5264 ASSERT_VK_SUCCESS(err);
5265 err = vkEndCommandBuffer(cmd_buffers[obj]);
5266 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005267
Tobin Ehlisf9025162016-05-26 06:55:21 -06005268 VkSubmitInfo submit_info = {};
5269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5270 submit_info.commandBufferCount = 1;
5271 submit_info.pCommandBuffers = &cmd_buffers[obj];
5272 // Submit cmd buffer and wait for fence
5273 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
5274 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005275 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
Tobin Ehlisf9025162016-05-26 06:55:21 -06005276 ASSERT_VK_SUCCESS(err);
5277 err = vkResetFences(m_device->device(), 1, &fences[obj]);
5278 ASSERT_VK_SUCCESS(err);
5279 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005280 }
5281 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06005282 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
5283 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
5284 vkDestroyFence(m_device->device(), fences[i], nullptr);
5285 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06005286}
5287// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005288TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
5289
5290 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005291 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005292
Cody Northropc31a84f2016-08-22 10:41:47 -06005293 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005294 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005295 return;
5296
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005297 m_errorMonitor->ExpectSuccess();
5298
5299 VkSemaphore semaphore;
5300 VkSemaphoreCreateInfo semaphore_create_info{};
5301 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005303
5304 VkCommandPool command_pool;
5305 VkCommandPoolCreateInfo pool_create_info{};
5306 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5307 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5308 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005309 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005310
5311 VkCommandBuffer command_buffer[2];
5312 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005313 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005314 command_buffer_allocate_info.commandPool = command_pool;
5315 command_buffer_allocate_info.commandBufferCount = 2;
5316 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005317 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005318
5319 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005320 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005321
5322 {
5323 VkCommandBufferBeginInfo begin_info{};
5324 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5325 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5326
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5328 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005329
5330 VkViewport viewport{};
5331 viewport.maxDepth = 1.0f;
5332 viewport.minDepth = 0.0f;
5333 viewport.width = 512;
5334 viewport.height = 512;
5335 viewport.x = 0;
5336 viewport.y = 0;
5337 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5338 vkEndCommandBuffer(command_buffer[0]);
5339 }
5340 {
5341 VkCommandBufferBeginInfo begin_info{};
5342 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5343 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5344
5345 VkViewport viewport{};
5346 viewport.maxDepth = 1.0f;
5347 viewport.minDepth = 0.0f;
5348 viewport.width = 512;
5349 viewport.height = 512;
5350 viewport.x = 0;
5351 viewport.y = 0;
5352 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5353 vkEndCommandBuffer(command_buffer[1]);
5354 }
5355 {
5356 VkSubmitInfo submit_info{};
5357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5358 submit_info.commandBufferCount = 1;
5359 submit_info.pCommandBuffers = &command_buffer[0];
5360 submit_info.signalSemaphoreCount = 1;
5361 submit_info.pSignalSemaphores = &semaphore;
5362 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5363 }
5364 {
5365 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5366 VkSubmitInfo submit_info{};
5367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5368 submit_info.commandBufferCount = 1;
5369 submit_info.pCommandBuffers = &command_buffer[1];
5370 submit_info.waitSemaphoreCount = 1;
5371 submit_info.pWaitSemaphores = &semaphore;
5372 submit_info.pWaitDstStageMask = flags;
5373 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5374 }
5375
5376 vkQueueWaitIdle(m_device->m_queue);
5377
5378 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005379 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005380 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5381
5382 m_errorMonitor->VerifyNotFound();
5383}
5384
5385// This is a positive test. No errors should be generated.
5386TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
5387
5388 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5389 "submitted on separate queues, the second having a fence"
5390 "followed by a QueueWaitIdle.");
5391
Cody Northropc31a84f2016-08-22 10:41:47 -06005392 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005393 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005394 return;
5395
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005396 m_errorMonitor->ExpectSuccess();
5397
5398 VkFence fence;
5399 VkFenceCreateInfo fence_create_info{};
5400 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5401 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5402
5403 VkSemaphore semaphore;
5404 VkSemaphoreCreateInfo semaphore_create_info{};
5405 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005406 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005407
5408 VkCommandPool command_pool;
5409 VkCommandPoolCreateInfo pool_create_info{};
5410 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5411 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5412 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005413 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005414
5415 VkCommandBuffer command_buffer[2];
5416 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005418 command_buffer_allocate_info.commandPool = command_pool;
5419 command_buffer_allocate_info.commandBufferCount = 2;
5420 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005421 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005422
5423 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005424 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005425
5426 {
5427 VkCommandBufferBeginInfo begin_info{};
5428 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5429 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5430
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005431 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5432 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005433
5434 VkViewport viewport{};
5435 viewport.maxDepth = 1.0f;
5436 viewport.minDepth = 0.0f;
5437 viewport.width = 512;
5438 viewport.height = 512;
5439 viewport.x = 0;
5440 viewport.y = 0;
5441 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5442 vkEndCommandBuffer(command_buffer[0]);
5443 }
5444 {
5445 VkCommandBufferBeginInfo begin_info{};
5446 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5447 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5448
5449 VkViewport viewport{};
5450 viewport.maxDepth = 1.0f;
5451 viewport.minDepth = 0.0f;
5452 viewport.width = 512;
5453 viewport.height = 512;
5454 viewport.x = 0;
5455 viewport.y = 0;
5456 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5457 vkEndCommandBuffer(command_buffer[1]);
5458 }
5459 {
5460 VkSubmitInfo submit_info{};
5461 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5462 submit_info.commandBufferCount = 1;
5463 submit_info.pCommandBuffers = &command_buffer[0];
5464 submit_info.signalSemaphoreCount = 1;
5465 submit_info.pSignalSemaphores = &semaphore;
5466 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5467 }
5468 {
5469 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5470 VkSubmitInfo submit_info{};
5471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5472 submit_info.commandBufferCount = 1;
5473 submit_info.pCommandBuffers = &command_buffer[1];
5474 submit_info.waitSemaphoreCount = 1;
5475 submit_info.pWaitSemaphores = &semaphore;
5476 submit_info.pWaitDstStageMask = flags;
5477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5478 }
5479
5480 vkQueueWaitIdle(m_device->m_queue);
5481
5482 vkDestroyFence(m_device->device(), fence, nullptr);
5483 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005484 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005485 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5486
5487 m_errorMonitor->VerifyNotFound();
5488}
5489
5490// This is a positive test. No errors should be generated.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005491TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005492
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005493 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5494 "submitted on separate queues, the second having a fence"
5495 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005496
Cody Northropc31a84f2016-08-22 10:41:47 -06005497 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005499 return;
5500
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005501 m_errorMonitor->ExpectSuccess();
5502
5503 VkFence fence;
5504 VkFenceCreateInfo fence_create_info{};
5505 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5506 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5507
5508 VkSemaphore semaphore;
5509 VkSemaphoreCreateInfo semaphore_create_info{};
5510 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005512
5513 VkCommandPool command_pool;
5514 VkCommandPoolCreateInfo pool_create_info{};
5515 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5516 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5517 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005519
5520 VkCommandBuffer command_buffer[2];
5521 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005522 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005523 command_buffer_allocate_info.commandPool = command_pool;
5524 command_buffer_allocate_info.commandBufferCount = 2;
5525 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005526 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005527
5528 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005529 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005530
5531 {
5532 VkCommandBufferBeginInfo begin_info{};
5533 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5534 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005536 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5537 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005538
5539 VkViewport viewport{};
5540 viewport.maxDepth = 1.0f;
5541 viewport.minDepth = 0.0f;
5542 viewport.width = 512;
5543 viewport.height = 512;
5544 viewport.x = 0;
5545 viewport.y = 0;
5546 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5547 vkEndCommandBuffer(command_buffer[0]);
5548 }
5549 {
5550 VkCommandBufferBeginInfo begin_info{};
5551 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5552 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5553
5554 VkViewport viewport{};
5555 viewport.maxDepth = 1.0f;
5556 viewport.minDepth = 0.0f;
5557 viewport.width = 512;
5558 viewport.height = 512;
5559 viewport.x = 0;
5560 viewport.y = 0;
5561 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5562 vkEndCommandBuffer(command_buffer[1]);
5563 }
5564 {
5565 VkSubmitInfo submit_info{};
5566 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5567 submit_info.commandBufferCount = 1;
5568 submit_info.pCommandBuffers = &command_buffer[0];
5569 submit_info.signalSemaphoreCount = 1;
5570 submit_info.pSignalSemaphores = &semaphore;
5571 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5572 }
5573 {
5574 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5575 VkSubmitInfo submit_info{};
5576 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5577 submit_info.commandBufferCount = 1;
5578 submit_info.pCommandBuffers = &command_buffer[1];
5579 submit_info.waitSemaphoreCount = 1;
5580 submit_info.pWaitSemaphores = &semaphore;
5581 submit_info.pWaitDstStageMask = flags;
5582 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5583 }
5584
5585 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5586 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5587
5588 vkDestroyFence(m_device->device(), fence, nullptr);
5589 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005590 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005591 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5592
5593 m_errorMonitor->VerifyNotFound();
5594}
5595
Chris Forbes0f8126b2016-06-20 17:48:22 +12005596TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Cody Northropc31a84f2016-08-22 10:41:47 -06005597
5598 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005599 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Chris Forbes0f8126b2016-06-20 17:48:22 +12005600 printf("Test requires two queues, skipping\n");
5601 return;
5602 }
5603
5604 VkResult err;
5605
5606 m_errorMonitor->ExpectSuccess();
5607
5608 VkQueue q0 = m_device->m_queue;
5609 VkQueue q1 = nullptr;
5610 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
5611 ASSERT_NE(q1, nullptr);
5612
5613 // An (empty) command buffer. We must have work in the first submission --
5614 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005615 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005616 VkCommandPool pool;
5617 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
5618 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
5620 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005621 VkCommandBuffer cb;
5622 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
5623 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005625 err = vkBeginCommandBuffer(cb, &cbbi);
5626 ASSERT_VK_SUCCESS(err);
5627 err = vkEndCommandBuffer(cb);
5628 ASSERT_VK_SUCCESS(err);
5629
5630 // A semaphore
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005631 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005632 VkSemaphore s;
5633 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
5634 ASSERT_VK_SUCCESS(err);
5635
5636 // First submission, to q0
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005638
5639 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
5640 ASSERT_VK_SUCCESS(err);
5641
5642 // Second submission, to q1, waiting on s
5643 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Chris Forbes0f8126b2016-06-20 17:48:22 +12005645
5646 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
5647 ASSERT_VK_SUCCESS(err);
5648
5649 // Wait for q0 idle
5650 err = vkQueueWaitIdle(q0);
5651 ASSERT_VK_SUCCESS(err);
5652
5653 // Command buffer should have been completed (it was on q0); reset the pool.
5654 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
5655
5656 m_errorMonitor->VerifyNotFound();
5657
5658 // Force device completely idle and clean up resources
5659 vkDeviceWaitIdle(m_device->device());
5660 vkDestroyCommandPool(m_device->device(), pool, nullptr);
5661 vkDestroySemaphore(m_device->device(), s, nullptr);
5662}
Chris Forbes0f8126b2016-06-20 17:48:22 +12005663
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005664// This is a positive test. No errors should be generated.
5665TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
5666
5667 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5668 "submitted on separate queues, the second having a fence, "
5669 "followed by a WaitForFences call.");
5670
Cody Northropc31a84f2016-08-22 10:41:47 -06005671 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005672 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06005673 return;
5674
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005675 m_errorMonitor->ExpectSuccess();
5676
Cody Northropc31a84f2016-08-22 10:41:47 -06005677 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005678 VkFence fence;
5679 VkFenceCreateInfo fence_create_info{};
5680 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5681 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5682
5683 VkSemaphore semaphore;
5684 VkSemaphoreCreateInfo semaphore_create_info{};
5685 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005686 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005687
5688 VkCommandPool command_pool;
5689 VkCommandPoolCreateInfo pool_create_info{};
5690 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5691 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5692 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005694
5695 VkCommandBuffer command_buffer[2];
5696 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005698 command_buffer_allocate_info.commandPool = command_pool;
5699 command_buffer_allocate_info.commandBufferCount = 2;
5700 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005701 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005702
5703 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005705
5706 {
5707 VkCommandBufferBeginInfo begin_info{};
5708 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5709 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005711 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5712 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005713
5714 VkViewport viewport{};
5715 viewport.maxDepth = 1.0f;
5716 viewport.minDepth = 0.0f;
5717 viewport.width = 512;
5718 viewport.height = 512;
5719 viewport.x = 0;
5720 viewport.y = 0;
5721 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5722 vkEndCommandBuffer(command_buffer[0]);
5723 }
5724 {
5725 VkCommandBufferBeginInfo begin_info{};
5726 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5727 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5728
5729 VkViewport viewport{};
5730 viewport.maxDepth = 1.0f;
5731 viewport.minDepth = 0.0f;
5732 viewport.width = 512;
5733 viewport.height = 512;
5734 viewport.x = 0;
5735 viewport.y = 0;
5736 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5737 vkEndCommandBuffer(command_buffer[1]);
5738 }
5739 {
5740 VkSubmitInfo submit_info{};
5741 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5742 submit_info.commandBufferCount = 1;
5743 submit_info.pCommandBuffers = &command_buffer[0];
5744 submit_info.signalSemaphoreCount = 1;
5745 submit_info.pSignalSemaphores = &semaphore;
5746 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
5747 }
5748 {
5749 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5750 VkSubmitInfo submit_info{};
5751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5752 submit_info.commandBufferCount = 1;
5753 submit_info.pCommandBuffers = &command_buffer[1];
5754 submit_info.waitSemaphoreCount = 1;
5755 submit_info.pWaitSemaphores = &semaphore;
5756 submit_info.pWaitDstStageMask = flags;
5757 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5758 }
5759
5760 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5761
5762 vkDestroyFence(m_device->device(), fence, nullptr);
5763 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005764 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005765 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5766
5767 m_errorMonitor->VerifyNotFound();
5768}
5769
5770// This is a positive test. No errors should be generated.
5771TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
5772
5773 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5774 "on the same queue, sharing a signal/wait semaphore, the "
5775 "second having a fence, "
5776 "followed by a WaitForFences call.");
5777
5778 m_errorMonitor->ExpectSuccess();
5779
Cody Northropc31a84f2016-08-22 10:41:47 -06005780 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005781 VkFence fence;
5782 VkFenceCreateInfo fence_create_info{};
5783 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5784 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5785
5786 VkSemaphore semaphore;
5787 VkSemaphoreCreateInfo semaphore_create_info{};
5788 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005790
5791 VkCommandPool command_pool;
5792 VkCommandPoolCreateInfo pool_create_info{};
5793 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5794 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5795 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005797
5798 VkCommandBuffer command_buffer[2];
5799 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005801 command_buffer_allocate_info.commandPool = command_pool;
5802 command_buffer_allocate_info.commandBufferCount = 2;
5803 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005804 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005805
5806 {
5807 VkCommandBufferBeginInfo begin_info{};
5808 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5809 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5812 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005813
5814 VkViewport viewport{};
5815 viewport.maxDepth = 1.0f;
5816 viewport.minDepth = 0.0f;
5817 viewport.width = 512;
5818 viewport.height = 512;
5819 viewport.x = 0;
5820 viewport.y = 0;
5821 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5822 vkEndCommandBuffer(command_buffer[0]);
5823 }
5824 {
5825 VkCommandBufferBeginInfo begin_info{};
5826 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5827 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5828
5829 VkViewport viewport{};
5830 viewport.maxDepth = 1.0f;
5831 viewport.minDepth = 0.0f;
5832 viewport.width = 512;
5833 viewport.height = 512;
5834 viewport.x = 0;
5835 viewport.y = 0;
5836 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5837 vkEndCommandBuffer(command_buffer[1]);
5838 }
5839 {
5840 VkSubmitInfo submit_info{};
5841 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5842 submit_info.commandBufferCount = 1;
5843 submit_info.pCommandBuffers = &command_buffer[0];
5844 submit_info.signalSemaphoreCount = 1;
5845 submit_info.pSignalSemaphores = &semaphore;
5846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5847 }
5848 {
5849 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5850 VkSubmitInfo submit_info{};
5851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5852 submit_info.commandBufferCount = 1;
5853 submit_info.pCommandBuffers = &command_buffer[1];
5854 submit_info.waitSemaphoreCount = 1;
5855 submit_info.pWaitSemaphores = &semaphore;
5856 submit_info.pWaitDstStageMask = flags;
5857 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
5858 }
5859
5860 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
5861
5862 vkDestroyFence(m_device->device(), fence, nullptr);
5863 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005864 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005865 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5866
5867 m_errorMonitor->VerifyNotFound();
5868}
5869
5870// This is a positive test. No errors should be generated.
5871TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
5872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5874 "on the same queue, no fences, followed by a third QueueSubmit with NO "
5875 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005876
5877 m_errorMonitor->ExpectSuccess();
5878
Cody Northropc31a84f2016-08-22 10:41:47 -06005879 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005880 VkFence fence;
5881 VkFenceCreateInfo fence_create_info{};
5882 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5883 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5884
5885 VkCommandPool command_pool;
5886 VkCommandPoolCreateInfo pool_create_info{};
5887 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5888 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5889 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005890 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005891
5892 VkCommandBuffer command_buffer[2];
5893 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005895 command_buffer_allocate_info.commandPool = command_pool;
5896 command_buffer_allocate_info.commandBufferCount = 2;
5897 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005898 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005899
5900 {
5901 VkCommandBufferBeginInfo begin_info{};
5902 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5903 vkBeginCommandBuffer(command_buffer[0], &begin_info);
5904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
5906 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005907
5908 VkViewport viewport{};
5909 viewport.maxDepth = 1.0f;
5910 viewport.minDepth = 0.0f;
5911 viewport.width = 512;
5912 viewport.height = 512;
5913 viewport.x = 0;
5914 viewport.y = 0;
5915 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
5916 vkEndCommandBuffer(command_buffer[0]);
5917 }
5918 {
5919 VkCommandBufferBeginInfo begin_info{};
5920 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5921 vkBeginCommandBuffer(command_buffer[1], &begin_info);
5922
5923 VkViewport viewport{};
5924 viewport.maxDepth = 1.0f;
5925 viewport.minDepth = 0.0f;
5926 viewport.width = 512;
5927 viewport.height = 512;
5928 viewport.x = 0;
5929 viewport.y = 0;
5930 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
5931 vkEndCommandBuffer(command_buffer[1]);
5932 }
5933 {
5934 VkSubmitInfo submit_info{};
5935 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5936 submit_info.commandBufferCount = 1;
5937 submit_info.pCommandBuffers = &command_buffer[0];
5938 submit_info.signalSemaphoreCount = 0;
5939 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
5940 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5941 }
5942 {
5943 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
5944 VkSubmitInfo submit_info{};
5945 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5946 submit_info.commandBufferCount = 1;
5947 submit_info.pCommandBuffers = &command_buffer[1];
5948 submit_info.waitSemaphoreCount = 0;
5949 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
5950 submit_info.pWaitDstStageMask = flags;
5951 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5952 }
5953
5954 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
5955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005956 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
Mike Stroyancd1c3e52016-06-21 09:20:01 -06005957 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005958
5959 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005961 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
5962
5963 m_errorMonitor->VerifyNotFound();
5964}
5965
5966// This is a positive test. No errors should be generated.
5967TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
5968
5969 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
5970 "on the same queue, the second having a fence, followed "
5971 "by a WaitForFences call.");
5972
5973 m_errorMonitor->ExpectSuccess();
5974
Cody Northropc31a84f2016-08-22 10:41:47 -06005975 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005976 VkFence fence;
5977 VkFenceCreateInfo fence_create_info{};
5978 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
5979 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
5980
5981 VkCommandPool command_pool;
5982 VkCommandPoolCreateInfo pool_create_info{};
5983 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
5984 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
5985 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005986 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005987
5988 VkCommandBuffer command_buffer[2];
5989 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005991 command_buffer_allocate_info.commandPool = command_pool;
5992 command_buffer_allocate_info.commandBufferCount = 2;
5993 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005994 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06005995
5996 {
5997 VkCommandBufferBeginInfo begin_info{};
5998 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5999 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6000
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006001 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6002 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006003
6004 VkViewport viewport{};
6005 viewport.maxDepth = 1.0f;
6006 viewport.minDepth = 0.0f;
6007 viewport.width = 512;
6008 viewport.height = 512;
6009 viewport.x = 0;
6010 viewport.y = 0;
6011 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6012 vkEndCommandBuffer(command_buffer[0]);
6013 }
6014 {
6015 VkCommandBufferBeginInfo begin_info{};
6016 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6017 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6018
6019 VkViewport viewport{};
6020 viewport.maxDepth = 1.0f;
6021 viewport.minDepth = 0.0f;
6022 viewport.width = 512;
6023 viewport.height = 512;
6024 viewport.x = 0;
6025 viewport.y = 0;
6026 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6027 vkEndCommandBuffer(command_buffer[1]);
6028 }
6029 {
6030 VkSubmitInfo submit_info{};
6031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6032 submit_info.commandBufferCount = 1;
6033 submit_info.pCommandBuffers = &command_buffer[0];
6034 submit_info.signalSemaphoreCount = 0;
6035 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
6036 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6037 }
6038 {
6039 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6040 VkSubmitInfo submit_info{};
6041 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6042 submit_info.commandBufferCount = 1;
6043 submit_info.pCommandBuffers = &command_buffer[1];
6044 submit_info.waitSemaphoreCount = 0;
6045 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
6046 submit_info.pWaitDstStageMask = flags;
6047 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
6048 }
6049
6050 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6051
6052 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006053 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006054 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
6055
6056 m_errorMonitor->VerifyNotFound();
6057}
6058
6059// This is a positive test. No errors should be generated.
6060TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
6061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006062 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
6063 "QueueSubmit call followed by a WaitForFences call.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006064 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006065
6066 m_errorMonitor->ExpectSuccess();
6067
6068 VkFence fence;
6069 VkFenceCreateInfo fence_create_info{};
6070 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
6071 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
6072
6073 VkSemaphore semaphore;
6074 VkSemaphoreCreateInfo semaphore_create_info{};
6075 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006076 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006077
6078 VkCommandPool command_pool;
6079 VkCommandPoolCreateInfo pool_create_info{};
6080 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
6081 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
6082 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006083 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006084
6085 VkCommandBuffer command_buffer[2];
6086 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006088 command_buffer_allocate_info.commandPool = command_pool;
6089 command_buffer_allocate_info.commandBufferCount = 2;
6090 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006091 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006092
6093 {
6094 VkCommandBufferBeginInfo begin_info{};
6095 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6096 vkBeginCommandBuffer(command_buffer[0], &begin_info);
6097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006098 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
6099 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006100
6101 VkViewport viewport{};
6102 viewport.maxDepth = 1.0f;
6103 viewport.minDepth = 0.0f;
6104 viewport.width = 512;
6105 viewport.height = 512;
6106 viewport.x = 0;
6107 viewport.y = 0;
6108 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
6109 vkEndCommandBuffer(command_buffer[0]);
6110 }
6111 {
6112 VkCommandBufferBeginInfo begin_info{};
6113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
6115
6116 VkViewport viewport{};
6117 viewport.maxDepth = 1.0f;
6118 viewport.minDepth = 0.0f;
6119 viewport.width = 512;
6120 viewport.height = 512;
6121 viewport.x = 0;
6122 viewport.y = 0;
6123 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
6124 vkEndCommandBuffer(command_buffer[1]);
6125 }
6126 {
6127 VkSubmitInfo submit_info[2];
6128 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
6129
6130 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6131 submit_info[0].pNext = NULL;
6132 submit_info[0].commandBufferCount = 1;
6133 submit_info[0].pCommandBuffers = &command_buffer[0];
6134 submit_info[0].signalSemaphoreCount = 1;
6135 submit_info[0].pSignalSemaphores = &semaphore;
6136 submit_info[0].waitSemaphoreCount = 0;
6137 submit_info[0].pWaitSemaphores = NULL;
6138 submit_info[0].pWaitDstStageMask = 0;
6139
6140 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6141 submit_info[1].pNext = NULL;
6142 submit_info[1].commandBufferCount = 1;
6143 submit_info[1].pCommandBuffers = &command_buffer[1];
6144 submit_info[1].waitSemaphoreCount = 1;
6145 submit_info[1].pWaitSemaphores = &semaphore;
6146 submit_info[1].pWaitDstStageMask = flags;
6147 submit_info[1].signalSemaphoreCount = 0;
6148 submit_info[1].pSignalSemaphores = NULL;
6149 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
6150 }
6151
6152 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
6153
6154 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006155 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006156 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006157 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06006158
6159 m_errorMonitor->VerifyNotFound();
6160}
6161
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006162TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
6164 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006165
Cody Northropc31a84f2016-08-22 10:41:47 -06006166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006167 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
6169 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006170 m_errorMonitor->VerifyFound();
6171}
6172
6173TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006174 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
6175 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006176
Cody Northropc31a84f2016-08-22 10:41:47 -06006177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006178 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
6180 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006181 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006182}
6183
6184TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006185 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
6186 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006187
Cody Northropc31a84f2016-08-22 10:41:47 -06006188 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006189 // Dynamic viewport state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006191 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006192 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006193}
6194
6195TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006196 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
6197 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006198
Cody Northropc31a84f2016-08-22 10:41:47 -06006199 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006200 // Dynamic scissor state
Chris Forbesb2ba95b2016-09-16 17:11:50 +12006201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006202 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006203 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006204}
6205
Cortd713fe82016-07-27 09:51:27 -07006206TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006207 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
6208 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006209
6210 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006211 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6213 "Dynamic blend constants state not set for this command buffer");
6214 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06006215 m_errorMonitor->VerifyFound();
6216}
6217
6218TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006219 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
6220 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006221
6222 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06006223 if (!m_device->phy().features().depthBounds) {
6224 printf("Device does not support depthBounds test; skipped.\n");
6225 return;
6226 }
6227 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6229 "Dynamic depth bounds state not set for this command buffer");
6230 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006231 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006232}
6233
6234TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
6236 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006237
6238 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006239 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6241 "Dynamic stencil read mask state not set for this command buffer");
6242 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006243 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006244}
6245
6246TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006247 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
6248 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006249
6250 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006251 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6253 "Dynamic stencil write mask state not set for this command buffer");
6254 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006255 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06006256}
6257
6258TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
6260 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006261
6262 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06006263 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6265 "Dynamic stencil reference state not set for this command buffer");
6266 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006267 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06006268}
6269
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006270TEST_F(VkLayerTest, IndexBufferNotBound) {
6271 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06006272
6273 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6275 "Index buffer object not bound to this command buffer when Indexed ");
6276 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06006277 m_errorMonitor->VerifyFound();
6278}
6279
Karl Schultz6addd812016-02-02 17:17:23 -07006280TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6282 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
6283 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006284
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006285 ASSERT_NO_FATAL_FAILURE(InitState());
6286 ASSERT_NO_FATAL_FAILURE(InitViewport());
6287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6288
Karl Schultz6addd812016-02-02 17:17:23 -07006289 // We luck out b/c by default the framework creates CB w/ the
6290 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006291 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006292 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006293 EndCommandBuffer();
6294
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006295 // Bypass framework since it does the waits automatically
6296 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006297 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08006298 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6299 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006300 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006301 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07006302 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006303 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006304 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08006305 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06006306 submit_info.pSignalSemaphores = NULL;
6307
Chris Forbes40028e22016-06-13 09:59:34 +12006308 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07006309 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006310
Karl Schultz6addd812016-02-02 17:17:23 -07006311 // Cause validation error by re-submitting cmd buffer that should only be
6312 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12006313 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006314
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006315 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06006316}
6317
Karl Schultz6addd812016-02-02 17:17:23 -07006318TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006319 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07006320 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
6323 "type "
6324 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006325
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006326 ASSERT_NO_FATAL_FAILURE(InitState());
6327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006328
Karl Schultz6addd812016-02-02 17:17:23 -07006329 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
6330 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006331 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
6333 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006334
6335 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006336 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6337 ds_pool_ci.pNext = NULL;
6338 ds_pool_ci.flags = 0;
6339 ds_pool_ci.maxSets = 1;
6340 ds_pool_ci.poolSizeCount = 1;
6341 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006342
6343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006345 ASSERT_VK_SUCCESS(err);
6346
6347 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006348 dsl_binding.binding = 0;
6349 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6350 dsl_binding.descriptorCount = 1;
6351 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6352 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006353
6354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6356 ds_layout_ci.pNext = NULL;
6357 ds_layout_ci.bindingCount = 1;
6358 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006359
6360 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006361 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006362 ASSERT_VK_SUCCESS(err);
6363
6364 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006365 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006366 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006367 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006368 alloc_info.descriptorPool = ds_pool;
6369 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006371
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006372 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006373
Chia-I Wuf7458c52015-10-26 21:10:41 +08006374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06006376}
6377
Karl Schultz6addd812016-02-02 17:17:23 -07006378TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
6379 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06006380
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6382 "It is invalid to call vkFreeDescriptorSets() with a pool created "
6383 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006384
Tobin Ehlise735c692015-10-08 13:13:50 -06006385 ASSERT_NO_FATAL_FAILURE(InitState());
6386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06006387
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006388 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006389 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6390 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06006391
6392 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006393 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6394 ds_pool_ci.pNext = NULL;
6395 ds_pool_ci.maxSets = 1;
6396 ds_pool_ci.poolSizeCount = 1;
6397 ds_pool_ci.flags = 0;
6398 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
6399 // app can only call vkResetDescriptorPool on this pool.;
6400 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06006401
6402 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06006404 ASSERT_VK_SUCCESS(err);
6405
6406 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006407 dsl_binding.binding = 0;
6408 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6409 dsl_binding.descriptorCount = 1;
6410 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6411 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06006412
6413 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006414 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6415 ds_layout_ci.pNext = NULL;
6416 ds_layout_ci.bindingCount = 1;
6417 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06006418
6419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06006421 ASSERT_VK_SUCCESS(err);
6422
6423 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006424 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006426 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006427 alloc_info.descriptorPool = ds_pool;
6428 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06006430 ASSERT_VK_SUCCESS(err);
6431
6432 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006433 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06006434
Chia-I Wuf7458c52015-10-26 21:10:41 +08006435 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06006437}
6438
Karl Schultz6addd812016-02-02 17:17:23 -07006439TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006440 // Attempt to clear Descriptor Pool with bad object.
6441 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06006442
6443 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006445 uint64_t fake_pool_handle = 0xbaad6001;
6446 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
6447 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06006448 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006449}
6450
Karl Schultz6addd812016-02-02 17:17:23 -07006451TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006452 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
6453 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006454 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06006455 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006456
6457 uint64_t fake_set_handle = 0xbaad6001;
6458 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006459 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06006461
6462 ASSERT_NO_FATAL_FAILURE(InitState());
6463
6464 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
6465 layout_bindings[0].binding = 0;
6466 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6467 layout_bindings[0].descriptorCount = 1;
6468 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
6469 layout_bindings[0].pImmutableSamplers = NULL;
6470
6471 VkDescriptorSetLayout descriptor_set_layout;
6472 VkDescriptorSetLayoutCreateInfo dslci = {};
6473 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6474 dslci.pNext = NULL;
6475 dslci.bindingCount = 1;
6476 dslci.pBindings = layout_bindings;
6477 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006478 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006479
6480 VkPipelineLayout pipeline_layout;
6481 VkPipelineLayoutCreateInfo plci = {};
6482 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6483 plci.pNext = NULL;
6484 plci.setLayoutCount = 1;
6485 plci.pSetLayouts = &descriptor_set_layout;
6486 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06006487 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06006488
6489 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006490 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
6491 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06006492 m_errorMonitor->VerifyFound();
6493 EndCommandBuffer();
6494 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
6495 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006496}
6497
Karl Schultz6addd812016-02-02 17:17:23 -07006498TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006499 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
6500 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006501 uint64_t fake_layout_handle = 0xbaad6001;
6502 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06006504 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06006505 VkPipelineLayout pipeline_layout;
6506 VkPipelineLayoutCreateInfo plci = {};
6507 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6508 plci.pNext = NULL;
6509 plci.setLayoutCount = 1;
6510 plci.pSetLayouts = &bad_layout;
6511 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
6512
6513 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006514}
6515
Mark Muellerd4914412016-06-13 17:52:06 -06006516TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
6517 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
6518 "1) A uniform buffer update must have a valid buffer index."
6519 "2) When using an array of descriptors in a single WriteDescriptor,"
6520 " the descriptor types and stageflags must all be the same."
6521 "3) Immutable Sampler state must match across descriptors");
6522
6523 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
6525 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
6526 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
6527 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
6528 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06006529
Mark Muellerd4914412016-06-13 17:52:06 -06006530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
6531
6532 ASSERT_NO_FATAL_FAILURE(InitState());
6533 VkDescriptorPoolSize ds_type_count[4] = {};
6534 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6535 ds_type_count[0].descriptorCount = 1;
6536 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6537 ds_type_count[1].descriptorCount = 1;
6538 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6539 ds_type_count[2].descriptorCount = 1;
6540 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6541 ds_type_count[3].descriptorCount = 1;
6542
6543 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6544 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6545 ds_pool_ci.maxSets = 1;
6546 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
6547 ds_pool_ci.pPoolSizes = ds_type_count;
6548
6549 VkDescriptorPool ds_pool;
6550 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6551 ASSERT_VK_SUCCESS(err);
6552
Mark Muellerb9896722016-06-16 09:54:29 -06006553 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006554 layout_binding[0].binding = 0;
6555 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6556 layout_binding[0].descriptorCount = 1;
6557 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6558 layout_binding[0].pImmutableSamplers = NULL;
6559
6560 layout_binding[1].binding = 1;
6561 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6562 layout_binding[1].descriptorCount = 1;
6563 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6564 layout_binding[1].pImmutableSamplers = NULL;
6565
6566 VkSamplerCreateInfo sampler_ci = {};
6567 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6568 sampler_ci.pNext = NULL;
6569 sampler_ci.magFilter = VK_FILTER_NEAREST;
6570 sampler_ci.minFilter = VK_FILTER_NEAREST;
6571 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6572 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6573 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6574 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6575 sampler_ci.mipLodBias = 1.0;
6576 sampler_ci.anisotropyEnable = VK_FALSE;
6577 sampler_ci.maxAnisotropy = 1;
6578 sampler_ci.compareEnable = VK_FALSE;
6579 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6580 sampler_ci.minLod = 1.0;
6581 sampler_ci.maxLod = 1.0;
6582 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6583 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6584 VkSampler sampler;
6585
6586 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6587 ASSERT_VK_SUCCESS(err);
6588
6589 layout_binding[2].binding = 2;
6590 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6591 layout_binding[2].descriptorCount = 1;
6592 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
6593 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
6594
Mark Muellerd4914412016-06-13 17:52:06 -06006595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6597 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
6598 ds_layout_ci.pBindings = layout_binding;
6599 VkDescriptorSetLayout ds_layout;
6600 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6601 ASSERT_VK_SUCCESS(err);
6602
6603 VkDescriptorSetAllocateInfo alloc_info = {};
6604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6605 alloc_info.descriptorSetCount = 1;
6606 alloc_info.descriptorPool = ds_pool;
6607 alloc_info.pSetLayouts = &ds_layout;
6608 VkDescriptorSet descriptorSet;
6609 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6610 ASSERT_VK_SUCCESS(err);
6611
6612 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6613 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6614 pipeline_layout_ci.pNext = NULL;
6615 pipeline_layout_ci.setLayoutCount = 1;
6616 pipeline_layout_ci.pSetLayouts = &ds_layout;
6617
6618 VkPipelineLayout pipeline_layout;
6619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6620 ASSERT_VK_SUCCESS(err);
6621
Mark Mueller5c838ce2016-06-16 09:54:29 -06006622 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06006623 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6624 descriptor_write.dstSet = descriptorSet;
6625 descriptor_write.dstBinding = 0;
6626 descriptor_write.descriptorCount = 1;
6627 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6628
Mark Mueller5c838ce2016-06-16 09:54:29 -06006629 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06006630 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6631 m_errorMonitor->VerifyFound();
6632
6633 // Create a buffer to update the descriptor with
6634 uint32_t qfi = 0;
6635 VkBufferCreateInfo buffCI = {};
6636 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6637 buffCI.size = 1024;
6638 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6639 buffCI.queueFamilyIndexCount = 1;
6640 buffCI.pQueueFamilyIndices = &qfi;
6641
6642 VkBuffer dyub;
6643 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6644 ASSERT_VK_SUCCESS(err);
6645 VkDescriptorBufferInfo buffInfo = {};
6646 buffInfo.buffer = dyub;
6647 buffInfo.offset = 0;
6648 buffInfo.range = 1024;
6649
6650 descriptor_write.pBufferInfo = &buffInfo;
6651 descriptor_write.descriptorCount = 2;
6652
Mark Mueller5c838ce2016-06-16 09:54:29 -06006653 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06006654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
6655 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6656 m_errorMonitor->VerifyFound();
6657
Mark Mueller5c838ce2016-06-16 09:54:29 -06006658 // 3) The second descriptor has a null_ptr pImmutableSamplers and
6659 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06006660 descriptor_write.dstBinding = 1;
6661 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06006662
Mark Mueller5c838ce2016-06-16 09:54:29 -06006663 // Make pImageInfo index non-null to avoid complaints of it missing
6664 VkDescriptorImageInfo imageInfo = {};
6665 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6666 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06006667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
6668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6669 m_errorMonitor->VerifyFound();
6670
Mark Muellerd4914412016-06-13 17:52:06 -06006671 vkDestroyBuffer(m_device->device(), dyub, NULL);
6672 vkDestroySampler(m_device->device(), sampler, NULL);
6673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6676}
6677
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006678TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
6679 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6680 "due to a buffer dependency being destroyed.");
6681 ASSERT_NO_FATAL_FAILURE(InitState());
6682
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006683 VkBuffer buffer;
6684 VkDeviceMemory mem;
6685 VkMemoryRequirements mem_reqs;
6686
6687 VkBufferCreateInfo buf_info = {};
6688 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12006689 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006690 buf_info.size = 256;
6691 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6692 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
6693 ASSERT_VK_SUCCESS(err);
6694
6695 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
6696
6697 VkMemoryAllocateInfo alloc_info = {};
6698 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6699 alloc_info.allocationSize = 256;
6700 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006701 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006702 if (!pass) {
6703 vkDestroyBuffer(m_device->device(), buffer, NULL);
6704 return;
6705 }
6706 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
6707 ASSERT_VK_SUCCESS(err);
6708
6709 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
6710 ASSERT_VK_SUCCESS(err);
6711
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006712 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12006713 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006714 m_commandBuffer->EndCommandBuffer();
6715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06006717 // Destroy buffer dependency prior to submit to cause ERROR
6718 vkDestroyBuffer(m_device->device(), buffer, NULL);
6719
6720 VkSubmitInfo submit_info = {};
6721 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6722 submit_info.commandBufferCount = 1;
6723 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6724 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6725
6726 m_errorMonitor->VerifyFound();
6727 vkFreeMemory(m_device->handle(), mem, NULL);
6728}
6729
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006730TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
6731 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6732 "due to an image dependency being destroyed.");
6733 ASSERT_NO_FATAL_FAILURE(InitState());
6734
6735 VkImage image;
6736 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6737 VkImageCreateInfo image_create_info = {};
6738 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6739 image_create_info.pNext = NULL;
6740 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6741 image_create_info.format = tex_format;
6742 image_create_info.extent.width = 32;
6743 image_create_info.extent.height = 32;
6744 image_create_info.extent.depth = 1;
6745 image_create_info.mipLevels = 1;
6746 image_create_info.arrayLayers = 1;
6747 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6748 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006750 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006752 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006753 // Have to bind memory to image before recording cmd in cmd buffer using it
6754 VkMemoryRequirements mem_reqs;
6755 VkDeviceMemory image_mem;
6756 bool pass;
6757 VkMemoryAllocateInfo mem_alloc = {};
6758 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6759 mem_alloc.pNext = NULL;
6760 mem_alloc.memoryTypeIndex = 0;
6761 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
6762 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006763 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006764 ASSERT_TRUE(pass);
6765 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
6766 ASSERT_VK_SUCCESS(err);
6767 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
6768 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006769
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006770 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06006771 VkClearColorValue ccv;
6772 ccv.float32[0] = 1.0f;
6773 ccv.float32[1] = 1.0f;
6774 ccv.float32[2] = 1.0f;
6775 ccv.float32[3] = 1.0f;
6776 VkImageSubresourceRange isr = {};
6777 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006778 isr.baseArrayLayer = 0;
6779 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06006780 isr.layerCount = 1;
6781 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006782 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006783 m_commandBuffer->EndCommandBuffer();
6784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006786 // Destroy image dependency prior to submit to cause ERROR
6787 vkDestroyImage(m_device->device(), image, NULL);
6788
6789 VkSubmitInfo submit_info = {};
6790 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6791 submit_info.commandBufferCount = 1;
6792 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6793 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6794
6795 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06006796 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06006797}
6798
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006799TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
6800 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
6801 "due to a framebuffer image dependency being destroyed.");
6802 VkFormatProperties format_properties;
6803 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
6805 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006806 return;
6807 }
6808
6809 ASSERT_NO_FATAL_FAILURE(InitState());
6810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6811
6812 VkImageCreateInfo image_ci = {};
6813 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6814 image_ci.pNext = NULL;
6815 image_ci.imageType = VK_IMAGE_TYPE_2D;
6816 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6817 image_ci.extent.width = 32;
6818 image_ci.extent.height = 32;
6819 image_ci.extent.depth = 1;
6820 image_ci.mipLevels = 1;
6821 image_ci.arrayLayers = 1;
6822 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6823 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006824 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006825 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6826 image_ci.flags = 0;
6827 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006828 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006829
6830 VkMemoryRequirements memory_reqs;
6831 VkDeviceMemory image_memory;
6832 bool pass;
6833 VkMemoryAllocateInfo memory_info = {};
6834 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6835 memory_info.pNext = NULL;
6836 memory_info.allocationSize = 0;
6837 memory_info.memoryTypeIndex = 0;
6838 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6839 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006840 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006841 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006842 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006843 ASSERT_VK_SUCCESS(err);
6844 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6845 ASSERT_VK_SUCCESS(err);
6846
6847 VkImageViewCreateInfo ivci = {
6848 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6849 nullptr,
6850 0,
6851 image,
6852 VK_IMAGE_VIEW_TYPE_2D,
6853 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006854 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006855 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6856 };
6857 VkImageView view;
6858 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6859 ASSERT_VK_SUCCESS(err);
6860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006861 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006862 VkFramebuffer fb;
6863 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6864 ASSERT_VK_SUCCESS(err);
6865
6866 // Just use default renderpass with our framebuffer
6867 m_renderPassBeginInfo.framebuffer = fb;
6868 // Create Null cmd buffer for submit
6869 BeginCommandBuffer();
6870 EndCommandBuffer();
6871 // Destroy image attached to framebuffer to invalidate cmd buffer
6872 vkDestroyImage(m_device->device(), image, NULL);
6873 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06006875 QueueCommandBuffer(false);
6876 m_errorMonitor->VerifyFound();
6877
6878 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6879 vkDestroyImageView(m_device->device(), view, nullptr);
6880 vkFreeMemory(m_device->device(), image_memory, nullptr);
6881}
6882
Tobin Ehlis88becd72016-09-21 14:33:41 -06006883TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
6884 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
6885 VkFormatProperties format_properties;
6886 VkResult err = VK_SUCCESS;
6887 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06006888
6889 ASSERT_NO_FATAL_FAILURE(InitState());
6890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6891
6892 VkImageCreateInfo image_ci = {};
6893 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6894 image_ci.pNext = NULL;
6895 image_ci.imageType = VK_IMAGE_TYPE_2D;
6896 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
6897 image_ci.extent.width = 256;
6898 image_ci.extent.height = 256;
6899 image_ci.extent.depth = 1;
6900 image_ci.mipLevels = 1;
6901 image_ci.arrayLayers = 1;
6902 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6903 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06006904 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06006905 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6906 image_ci.flags = 0;
6907 VkImage image;
6908 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
6909
6910 VkMemoryRequirements memory_reqs;
6911 VkDeviceMemory image_memory;
6912 bool pass;
6913 VkMemoryAllocateInfo memory_info = {};
6914 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6915 memory_info.pNext = NULL;
6916 memory_info.allocationSize = 0;
6917 memory_info.memoryTypeIndex = 0;
6918 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6919 memory_info.allocationSize = memory_reqs.size;
6920 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6921 ASSERT_TRUE(pass);
6922 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6923 ASSERT_VK_SUCCESS(err);
6924 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6925 ASSERT_VK_SUCCESS(err);
6926
6927 VkImageViewCreateInfo ivci = {
6928 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
6929 nullptr,
6930 0,
6931 image,
6932 VK_IMAGE_VIEW_TYPE_2D,
6933 VK_FORMAT_B8G8R8A8_UNORM,
6934 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
6935 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
6936 };
6937 VkImageView view;
6938 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
6939 ASSERT_VK_SUCCESS(err);
6940
6941 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
6942 VkFramebuffer fb;
6943 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
6944 ASSERT_VK_SUCCESS(err);
6945
6946 // Just use default renderpass with our framebuffer
6947 m_renderPassBeginInfo.framebuffer = fb;
6948 // Create Null cmd buffer for submit
6949 BeginCommandBuffer();
6950 EndCommandBuffer();
6951 // Submit cmd buffer to put it (and attached imageView) in-flight
6952 VkSubmitInfo submit_info = {};
6953 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6954 submit_info.commandBufferCount = 1;
6955 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6956 // Submit cmd buffer to put framebuffer and children in-flight
6957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6958 // Destroy image attached to framebuffer while in-flight
6959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
6960 vkDestroyImage(m_device->device(), image, NULL);
6961 m_errorMonitor->VerifyFound();
6962 // Wait for queue to complete so we can safely destroy image and other objects
6963 vkQueueWaitIdle(m_device->m_queue);
6964 vkDestroyImage(m_device->device(), image, NULL);
6965 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
6966 vkDestroyImageView(m_device->device(), view, nullptr);
6967 vkFreeMemory(m_device->device(), image_memory, nullptr);
6968}
6969
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006970TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006971 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006972 ASSERT_NO_FATAL_FAILURE(InitState());
6973
6974 VkImage image;
6975 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6976 VkImageCreateInfo image_create_info = {};
6977 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6978 image_create_info.pNext = NULL;
6979 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6980 image_create_info.format = tex_format;
6981 image_create_info.extent.width = 32;
6982 image_create_info.extent.height = 32;
6983 image_create_info.extent.depth = 1;
6984 image_create_info.mipLevels = 1;
6985 image_create_info.arrayLayers = 1;
6986 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6987 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006988 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006989 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006990 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06006991 ASSERT_VK_SUCCESS(err);
6992 // Have to bind memory to image before recording cmd in cmd buffer using it
6993 VkMemoryRequirements mem_reqs;
6994 VkDeviceMemory image_mem;
6995 bool pass;
6996 VkMemoryAllocateInfo mem_alloc = {};
6997 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6998 mem_alloc.pNext = NULL;
6999 mem_alloc.memoryTypeIndex = 0;
7000 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7001 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007003 ASSERT_TRUE(pass);
7004 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7005 ASSERT_VK_SUCCESS(err);
7006
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007007 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
7008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007009 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007010
7011 m_commandBuffer->BeginCommandBuffer();
7012 VkClearColorValue ccv;
7013 ccv.float32[0] = 1.0f;
7014 ccv.float32[1] = 1.0f;
7015 ccv.float32[2] = 1.0f;
7016 ccv.float32[3] = 1.0f;
7017 VkImageSubresourceRange isr = {};
7018 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7019 isr.baseArrayLayer = 0;
7020 isr.baseMipLevel = 0;
7021 isr.layerCount = 1;
7022 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007023 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007024 m_commandBuffer->EndCommandBuffer();
7025
7026 m_errorMonitor->VerifyFound();
7027 vkDestroyImage(m_device->device(), image, NULL);
7028 vkFreeMemory(m_device->device(), image_mem, nullptr);
7029}
7030
7031TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007033 ASSERT_NO_FATAL_FAILURE(InitState());
7034
7035 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007036 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007037 VK_IMAGE_TILING_OPTIMAL, 0);
7038 ASSERT_TRUE(image.initialized());
7039
7040 VkBuffer buffer;
7041 VkDeviceMemory mem;
7042 VkMemoryRequirements mem_reqs;
7043
7044 VkBufferCreateInfo buf_info = {};
7045 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12007046 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007047 buf_info.size = 256;
7048 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7049 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
7050 ASSERT_VK_SUCCESS(err);
7051
7052 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
7053
7054 VkMemoryAllocateInfo alloc_info = {};
7055 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7056 alloc_info.allocationSize = 256;
7057 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007058 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007059 if (!pass) {
7060 vkDestroyBuffer(m_device->device(), buffer, NULL);
7061 return;
7062 }
7063 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
7064 ASSERT_VK_SUCCESS(err);
7065
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007066 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007068 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007069 VkBufferImageCopy region = {};
7070 region.bufferRowLength = 128;
7071 region.bufferImageHeight = 128;
7072 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7073
7074 region.imageSubresource.layerCount = 1;
7075 region.imageExtent.height = 4;
7076 region.imageExtent.width = 4;
7077 region.imageExtent.depth = 1;
7078 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007079 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
7080 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06007081 m_commandBuffer->EndCommandBuffer();
7082
7083 m_errorMonitor->VerifyFound();
7084
7085 vkDestroyBuffer(m_device->device(), buffer, NULL);
7086 vkFreeMemory(m_device->handle(), mem, NULL);
7087}
7088
Tobin Ehlis85940f52016-07-07 16:57:21 -06007089TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
7090 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7091 "due to an event dependency being destroyed.");
7092 ASSERT_NO_FATAL_FAILURE(InitState());
7093
7094 VkEvent event;
7095 VkEventCreateInfo evci = {};
7096 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
7097 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
7098 ASSERT_VK_SUCCESS(result);
7099
7100 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007101 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06007102 m_commandBuffer->EndCommandBuffer();
7103
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06007105 // Destroy event dependency prior to submit to cause ERROR
7106 vkDestroyEvent(m_device->device(), event, NULL);
7107
7108 VkSubmitInfo submit_info = {};
7109 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7110 submit_info.commandBufferCount = 1;
7111 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7112 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7113
7114 m_errorMonitor->VerifyFound();
7115}
7116
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007117TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
7118 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7119 "due to a query pool dependency being destroyed.");
7120 ASSERT_NO_FATAL_FAILURE(InitState());
7121
7122 VkQueryPool query_pool;
7123 VkQueryPoolCreateInfo qpci{};
7124 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
7125 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
7126 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007127 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007128 ASSERT_VK_SUCCESS(result);
7129
7130 m_commandBuffer->BeginCommandBuffer();
7131 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
7132 m_commandBuffer->EndCommandBuffer();
7133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06007135 // Destroy query pool dependency prior to submit to cause ERROR
7136 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
7137
7138 VkSubmitInfo submit_info = {};
7139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7140 submit_info.commandBufferCount = 1;
7141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7143
7144 m_errorMonitor->VerifyFound();
7145}
7146
Tobin Ehlis24130d92016-07-08 15:50:53 -06007147TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
7148 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7149 "due to a pipeline dependency being destroyed.");
7150 ASSERT_NO_FATAL_FAILURE(InitState());
7151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7152
7153 VkResult err;
7154
7155 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7156 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7157
7158 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007159 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007160 ASSERT_VK_SUCCESS(err);
7161
7162 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7163 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7164 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06007166 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007167 vp_state_ci.scissorCount = 1;
7168 VkRect2D scissors = {}; // Dummy scissors to point to
7169 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007170
7171 VkPipelineShaderStageCreateInfo shaderStages[2];
7172 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7175 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7176 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06007177 shaderStages[0] = vs.GetStageCreateInfo();
7178 shaderStages[1] = fs.GetStageCreateInfo();
7179
7180 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7181 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7182
7183 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7184 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7185 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7186
7187 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7188 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12007189 rs_ci.rasterizerDiscardEnable = true;
7190 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007191
7192 VkPipelineColorBlendAttachmentState att = {};
7193 att.blendEnable = VK_FALSE;
7194 att.colorWriteMask = 0xf;
7195
7196 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7197 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7198 cb_ci.attachmentCount = 1;
7199 cb_ci.pAttachments = &att;
7200
7201 VkGraphicsPipelineCreateInfo gp_ci = {};
7202 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7203 gp_ci.stageCount = 2;
7204 gp_ci.pStages = shaderStages;
7205 gp_ci.pVertexInputState = &vi_ci;
7206 gp_ci.pInputAssemblyState = &ia_ci;
7207 gp_ci.pViewportState = &vp_state_ci;
7208 gp_ci.pRasterizationState = &rs_ci;
7209 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06007210 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7211 gp_ci.layout = pipeline_layout;
7212 gp_ci.renderPass = renderPass();
7213
7214 VkPipelineCacheCreateInfo pc_ci = {};
7215 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7216
7217 VkPipeline pipeline;
7218 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007219 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007220 ASSERT_VK_SUCCESS(err);
7221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007223 ASSERT_VK_SUCCESS(err);
7224
7225 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007226 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06007227 m_commandBuffer->EndCommandBuffer();
7228 // Now destroy pipeline in order to cause error when submitting
7229 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
7230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06007232
7233 VkSubmitInfo submit_info = {};
7234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7235 submit_info.commandBufferCount = 1;
7236 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7238
7239 m_errorMonitor->VerifyFound();
7240 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7241 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7242}
7243
Tobin Ehlis31289162016-08-17 14:57:58 -06007244TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
7245 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7246 "due to a bound descriptor set with a buffer dependency "
7247 "being destroyed.");
7248 ASSERT_NO_FATAL_FAILURE(InitState());
7249 ASSERT_NO_FATAL_FAILURE(InitViewport());
7250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7251
7252 VkDescriptorPoolSize ds_type_count = {};
7253 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7254 ds_type_count.descriptorCount = 1;
7255
7256 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7257 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7258 ds_pool_ci.pNext = NULL;
7259 ds_pool_ci.maxSets = 1;
7260 ds_pool_ci.poolSizeCount = 1;
7261 ds_pool_ci.pPoolSizes = &ds_type_count;
7262
7263 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007264 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06007265 ASSERT_VK_SUCCESS(err);
7266
7267 VkDescriptorSetLayoutBinding dsl_binding = {};
7268 dsl_binding.binding = 0;
7269 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7270 dsl_binding.descriptorCount = 1;
7271 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7272 dsl_binding.pImmutableSamplers = NULL;
7273
7274 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7275 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7276 ds_layout_ci.pNext = NULL;
7277 ds_layout_ci.bindingCount = 1;
7278 ds_layout_ci.pBindings = &dsl_binding;
7279 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007280 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007281 ASSERT_VK_SUCCESS(err);
7282
7283 VkDescriptorSet descriptorSet;
7284 VkDescriptorSetAllocateInfo alloc_info = {};
7285 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7286 alloc_info.descriptorSetCount = 1;
7287 alloc_info.descriptorPool = ds_pool;
7288 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007289 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06007290 ASSERT_VK_SUCCESS(err);
7291
7292 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7293 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7294 pipeline_layout_ci.pNext = NULL;
7295 pipeline_layout_ci.setLayoutCount = 1;
7296 pipeline_layout_ci.pSetLayouts = &ds_layout;
7297
7298 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007299 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06007300 ASSERT_VK_SUCCESS(err);
7301
7302 // Create a buffer to update the descriptor with
7303 uint32_t qfi = 0;
7304 VkBufferCreateInfo buffCI = {};
7305 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7306 buffCI.size = 1024;
7307 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7308 buffCI.queueFamilyIndexCount = 1;
7309 buffCI.pQueueFamilyIndices = &qfi;
7310
7311 VkBuffer buffer;
7312 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
7313 ASSERT_VK_SUCCESS(err);
7314 // Allocate memory and bind to buffer so we can make it to the appropriate
7315 // error
7316 VkMemoryAllocateInfo mem_alloc = {};
7317 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7318 mem_alloc.pNext = NULL;
7319 mem_alloc.allocationSize = 1024;
7320 mem_alloc.memoryTypeIndex = 0;
7321
7322 VkMemoryRequirements memReqs;
7323 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06007325 if (!pass) {
7326 vkDestroyBuffer(m_device->device(), buffer, NULL);
7327 return;
7328 }
7329
7330 VkDeviceMemory mem;
7331 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
7332 ASSERT_VK_SUCCESS(err);
7333 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
7334 ASSERT_VK_SUCCESS(err);
7335 // Correctly update descriptor to avoid "NOT_UPDATED" error
7336 VkDescriptorBufferInfo buffInfo = {};
7337 buffInfo.buffer = buffer;
7338 buffInfo.offset = 0;
7339 buffInfo.range = 1024;
7340
7341 VkWriteDescriptorSet descriptor_write;
7342 memset(&descriptor_write, 0, sizeof(descriptor_write));
7343 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7344 descriptor_write.dstSet = descriptorSet;
7345 descriptor_write.dstBinding = 0;
7346 descriptor_write.descriptorCount = 1;
7347 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7348 descriptor_write.pBufferInfo = &buffInfo;
7349
7350 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7351
7352 // Create PSO to be used for draw-time errors below
7353 char const *vsSource = "#version 450\n"
7354 "\n"
7355 "out gl_PerVertex { \n"
7356 " vec4 gl_Position;\n"
7357 "};\n"
7358 "void main(){\n"
7359 " gl_Position = vec4(1);\n"
7360 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007361 char const *fsSource = "#version 450\n"
7362 "\n"
7363 "layout(location=0) out vec4 x;\n"
7364 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7365 "void main(){\n"
7366 " x = vec4(bar.y);\n"
7367 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06007368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7370 VkPipelineObj pipe(m_device);
7371 pipe.AddShader(&vs);
7372 pipe.AddShader(&fs);
7373 pipe.AddColorAttachment();
7374 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7375
7376 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007377 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7378 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7379 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06007380 Draw(1, 0, 0, 0);
7381 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06007383 // Destroy buffer should invalidate the cmd buffer, causing error on submit
7384 vkDestroyBuffer(m_device->device(), buffer, NULL);
7385 // Attempt to submit cmd buffer
7386 VkSubmitInfo submit_info = {};
7387 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7388 submit_info.commandBufferCount = 1;
7389 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7390 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7391 m_errorMonitor->VerifyFound();
7392 // Cleanup
7393 vkFreeMemory(m_device->device(), mem, NULL);
7394
7395 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7396 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7397 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7398}
7399
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007400TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
7401 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
7402 "due to a bound descriptor sets with a combined image "
7403 "sampler having their image, sampler, and descriptor set "
7404 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06007405 "submit associated cmd buffers. Attempt to destroy a "
7406 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007407 ASSERT_NO_FATAL_FAILURE(InitState());
7408 ASSERT_NO_FATAL_FAILURE(InitViewport());
7409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7410
7411 VkDescriptorPoolSize ds_type_count = {};
7412 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7413 ds_type_count.descriptorCount = 1;
7414
7415 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7416 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7417 ds_pool_ci.pNext = NULL;
7418 ds_pool_ci.maxSets = 1;
7419 ds_pool_ci.poolSizeCount = 1;
7420 ds_pool_ci.pPoolSizes = &ds_type_count;
7421
7422 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007424 ASSERT_VK_SUCCESS(err);
7425
7426 VkDescriptorSetLayoutBinding dsl_binding = {};
7427 dsl_binding.binding = 0;
7428 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7429 dsl_binding.descriptorCount = 1;
7430 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7431 dsl_binding.pImmutableSamplers = NULL;
7432
7433 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7434 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7435 ds_layout_ci.pNext = NULL;
7436 ds_layout_ci.bindingCount = 1;
7437 ds_layout_ci.pBindings = &dsl_binding;
7438 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007440 ASSERT_VK_SUCCESS(err);
7441
7442 VkDescriptorSet descriptorSet;
7443 VkDescriptorSetAllocateInfo alloc_info = {};
7444 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7445 alloc_info.descriptorSetCount = 1;
7446 alloc_info.descriptorPool = ds_pool;
7447 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007449 ASSERT_VK_SUCCESS(err);
7450
7451 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7452 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7453 pipeline_layout_ci.pNext = NULL;
7454 pipeline_layout_ci.setLayoutCount = 1;
7455 pipeline_layout_ci.pSetLayouts = &ds_layout;
7456
7457 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007458 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007459 ASSERT_VK_SUCCESS(err);
7460
7461 // Create images to update the descriptor with
7462 VkImage image;
7463 VkImage image2;
7464 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7465 const int32_t tex_width = 32;
7466 const int32_t tex_height = 32;
7467 VkImageCreateInfo image_create_info = {};
7468 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7469 image_create_info.pNext = NULL;
7470 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7471 image_create_info.format = tex_format;
7472 image_create_info.extent.width = tex_width;
7473 image_create_info.extent.height = tex_height;
7474 image_create_info.extent.depth = 1;
7475 image_create_info.mipLevels = 1;
7476 image_create_info.arrayLayers = 1;
7477 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7478 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7479 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7480 image_create_info.flags = 0;
7481 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7482 ASSERT_VK_SUCCESS(err);
7483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
7484 ASSERT_VK_SUCCESS(err);
7485
7486 VkMemoryRequirements memory_reqs;
7487 VkDeviceMemory image_memory;
7488 bool pass;
7489 VkMemoryAllocateInfo memory_info = {};
7490 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7491 memory_info.pNext = NULL;
7492 memory_info.allocationSize = 0;
7493 memory_info.memoryTypeIndex = 0;
7494 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7495 // Allocate enough memory for both images
7496 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007498 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007499 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007500 ASSERT_VK_SUCCESS(err);
7501 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7502 ASSERT_VK_SUCCESS(err);
7503 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007504 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007505 ASSERT_VK_SUCCESS(err);
7506
7507 VkImageViewCreateInfo image_view_create_info = {};
7508 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7509 image_view_create_info.image = image;
7510 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7511 image_view_create_info.format = tex_format;
7512 image_view_create_info.subresourceRange.layerCount = 1;
7513 image_view_create_info.subresourceRange.baseMipLevel = 0;
7514 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007515 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007516
7517 VkImageView view;
7518 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007519 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007520 ASSERT_VK_SUCCESS(err);
7521 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007522 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007523 ASSERT_VK_SUCCESS(err);
7524 // Create Samplers
7525 VkSamplerCreateInfo sampler_ci = {};
7526 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7527 sampler_ci.pNext = NULL;
7528 sampler_ci.magFilter = VK_FILTER_NEAREST;
7529 sampler_ci.minFilter = VK_FILTER_NEAREST;
7530 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7531 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7532 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7533 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7534 sampler_ci.mipLodBias = 1.0;
7535 sampler_ci.anisotropyEnable = VK_FALSE;
7536 sampler_ci.maxAnisotropy = 1;
7537 sampler_ci.compareEnable = VK_FALSE;
7538 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7539 sampler_ci.minLod = 1.0;
7540 sampler_ci.maxLod = 1.0;
7541 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7542 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7543 VkSampler sampler;
7544 VkSampler sampler2;
7545 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7546 ASSERT_VK_SUCCESS(err);
7547 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
7548 ASSERT_VK_SUCCESS(err);
7549 // Update descriptor with image and sampler
7550 VkDescriptorImageInfo img_info = {};
7551 img_info.sampler = sampler;
7552 img_info.imageView = view;
7553 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7554
7555 VkWriteDescriptorSet descriptor_write;
7556 memset(&descriptor_write, 0, sizeof(descriptor_write));
7557 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7558 descriptor_write.dstSet = descriptorSet;
7559 descriptor_write.dstBinding = 0;
7560 descriptor_write.descriptorCount = 1;
7561 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7562 descriptor_write.pImageInfo = &img_info;
7563
7564 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7565
7566 // Create PSO to be used for draw-time errors below
7567 char const *vsSource = "#version 450\n"
7568 "\n"
7569 "out gl_PerVertex { \n"
7570 " vec4 gl_Position;\n"
7571 "};\n"
7572 "void main(){\n"
7573 " gl_Position = vec4(1);\n"
7574 "}\n";
7575 char const *fsSource = "#version 450\n"
7576 "\n"
7577 "layout(set=0, binding=0) uniform sampler2D s;\n"
7578 "layout(location=0) out vec4 x;\n"
7579 "void main(){\n"
7580 " x = texture(s, vec2(1));\n"
7581 "}\n";
7582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7584 VkPipelineObj pipe(m_device);
7585 pipe.AddShader(&vs);
7586 pipe.AddShader(&fs);
7587 pipe.AddColorAttachment();
7588 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7589
7590 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007592 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007593 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7594 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7595 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007596 Draw(1, 0, 0, 0);
7597 EndCommandBuffer();
7598 // Destroy sampler invalidates the cmd buffer, causing error on submit
7599 vkDestroySampler(m_device->device(), sampler, NULL);
7600 // Attempt to submit cmd buffer
7601 VkSubmitInfo submit_info = {};
7602 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7603 submit_info.commandBufferCount = 1;
7604 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7605 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7606 m_errorMonitor->VerifyFound();
7607 // Now re-update descriptor with valid sampler and delete image
7608 img_info.sampler = sampler2;
7609 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007611 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007612 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7613 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7614 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007615 Draw(1, 0, 0, 0);
7616 EndCommandBuffer();
7617 // Destroy image invalidates the cmd buffer, causing error on submit
7618 vkDestroyImage(m_device->device(), image, NULL);
7619 // Attempt to submit cmd buffer
7620 submit_info = {};
7621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7622 submit_info.commandBufferCount = 1;
7623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7625 m_errorMonitor->VerifyFound();
7626 // Now update descriptor to be valid, but then free descriptor
7627 img_info.imageView = view2;
7628 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007630 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007631 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7632 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7633 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007634 Draw(1, 0, 0, 0);
7635 EndCommandBuffer();
7636 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007638 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06007639 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06007640 // Attempt to submit cmd buffer
7641 submit_info = {};
7642 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
7643 submit_info.commandBufferCount = 1;
7644 submit_info.pCommandBuffers = &m_commandBuffer->handle();
7645 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
7646 m_errorMonitor->VerifyFound();
7647 // Cleanup
7648 vkFreeMemory(m_device->device(), image_memory, NULL);
7649 vkDestroySampler(m_device->device(), sampler2, NULL);
7650 vkDestroyImage(m_device->device(), image2, NULL);
7651 vkDestroyImageView(m_device->device(), view, NULL);
7652 vkDestroyImageView(m_device->device(), view2, NULL);
7653 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7656}
7657
Tobin Ehlis50a095d2016-09-21 17:32:49 -06007658TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
7659 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
7660 ASSERT_NO_FATAL_FAILURE(InitState());
7661 ASSERT_NO_FATAL_FAILURE(InitViewport());
7662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7663
7664 VkDescriptorPoolSize ds_type_count = {};
7665 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7666 ds_type_count.descriptorCount = 1;
7667
7668 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7669 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7670 ds_pool_ci.pNext = NULL;
7671 ds_pool_ci.maxSets = 1;
7672 ds_pool_ci.poolSizeCount = 1;
7673 ds_pool_ci.pPoolSizes = &ds_type_count;
7674
7675 VkDescriptorPool ds_pool;
7676 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7677 ASSERT_VK_SUCCESS(err);
7678
7679 VkDescriptorSetLayoutBinding dsl_binding = {};
7680 dsl_binding.binding = 0;
7681 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7682 dsl_binding.descriptorCount = 1;
7683 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7684 dsl_binding.pImmutableSamplers = NULL;
7685
7686 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7687 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7688 ds_layout_ci.pNext = NULL;
7689 ds_layout_ci.bindingCount = 1;
7690 ds_layout_ci.pBindings = &dsl_binding;
7691 VkDescriptorSetLayout ds_layout;
7692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
7693 ASSERT_VK_SUCCESS(err);
7694
7695 VkDescriptorSet descriptorSet;
7696 VkDescriptorSetAllocateInfo alloc_info = {};
7697 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7698 alloc_info.descriptorSetCount = 1;
7699 alloc_info.descriptorPool = ds_pool;
7700 alloc_info.pSetLayouts = &ds_layout;
7701 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
7702 ASSERT_VK_SUCCESS(err);
7703
7704 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7705 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7706 pipeline_layout_ci.pNext = NULL;
7707 pipeline_layout_ci.setLayoutCount = 1;
7708 pipeline_layout_ci.pSetLayouts = &ds_layout;
7709
7710 VkPipelineLayout pipeline_layout;
7711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
7712 ASSERT_VK_SUCCESS(err);
7713
7714 // Create images to update the descriptor with
7715 VkImage image;
7716 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7717 const int32_t tex_width = 32;
7718 const int32_t tex_height = 32;
7719 VkImageCreateInfo image_create_info = {};
7720 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7721 image_create_info.pNext = NULL;
7722 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7723 image_create_info.format = tex_format;
7724 image_create_info.extent.width = tex_width;
7725 image_create_info.extent.height = tex_height;
7726 image_create_info.extent.depth = 1;
7727 image_create_info.mipLevels = 1;
7728 image_create_info.arrayLayers = 1;
7729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7730 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7731 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7732 image_create_info.flags = 0;
7733 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
7734 ASSERT_VK_SUCCESS(err);
7735 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
7736 VkMemoryRequirements memory_reqs;
7737 VkDeviceMemory image_memory;
7738 bool pass;
7739 VkMemoryAllocateInfo memory_info = {};
7740 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7741 memory_info.pNext = NULL;
7742 memory_info.allocationSize = 0;
7743 memory_info.memoryTypeIndex = 0;
7744 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
7745 // Allocate enough memory for image
7746 memory_info.allocationSize = memory_reqs.size;
7747 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
7748 ASSERT_TRUE(pass);
7749 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
7750 ASSERT_VK_SUCCESS(err);
7751 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
7752 ASSERT_VK_SUCCESS(err);
7753
7754 VkImageViewCreateInfo image_view_create_info = {};
7755 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7756 image_view_create_info.image = image;
7757 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
7758 image_view_create_info.format = tex_format;
7759 image_view_create_info.subresourceRange.layerCount = 1;
7760 image_view_create_info.subresourceRange.baseMipLevel = 0;
7761 image_view_create_info.subresourceRange.levelCount = 1;
7762 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7763
7764 VkImageView view;
7765 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
7766 ASSERT_VK_SUCCESS(err);
7767 // Create Samplers
7768 VkSamplerCreateInfo sampler_ci = {};
7769 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7770 sampler_ci.pNext = NULL;
7771 sampler_ci.magFilter = VK_FILTER_NEAREST;
7772 sampler_ci.minFilter = VK_FILTER_NEAREST;
7773 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7774 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7775 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7776 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7777 sampler_ci.mipLodBias = 1.0;
7778 sampler_ci.anisotropyEnable = VK_FALSE;
7779 sampler_ci.maxAnisotropy = 1;
7780 sampler_ci.compareEnable = VK_FALSE;
7781 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7782 sampler_ci.minLod = 1.0;
7783 sampler_ci.maxLod = 1.0;
7784 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7785 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7786 VkSampler sampler;
7787 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7788 ASSERT_VK_SUCCESS(err);
7789 // Update descriptor with image and sampler
7790 VkDescriptorImageInfo img_info = {};
7791 img_info.sampler = sampler;
7792 img_info.imageView = view;
7793 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
7794
7795 VkWriteDescriptorSet descriptor_write;
7796 memset(&descriptor_write, 0, sizeof(descriptor_write));
7797 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7798 descriptor_write.dstSet = descriptorSet;
7799 descriptor_write.dstBinding = 0;
7800 descriptor_write.descriptorCount = 1;
7801 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7802 descriptor_write.pImageInfo = &img_info;
7803 // Break memory binding and attempt update
7804 vkFreeMemory(m_device->device(), image_memory, nullptr);
7805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007806 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06007807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7808 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
7809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7810 m_errorMonitor->VerifyFound();
7811 // Cleanup
7812 vkDestroyImage(m_device->device(), image, NULL);
7813 vkDestroySampler(m_device->device(), sampler, NULL);
7814 vkDestroyImageView(m_device->device(), view, NULL);
7815 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7816 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7817 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7818}
7819
Karl Schultz6addd812016-02-02 17:17:23 -07007820TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06007821 // Attempt to bind an invalid Pipeline to a valid Command Buffer
7822 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007823 // Create a valid cmd buffer
7824 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06007825 uint64_t fake_pipeline_handle = 0xbaad6001;
7826 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06007827 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007828 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7829
7830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06007831 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007832 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06007833 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007834
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007835 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007837 Draw(1, 0, 0, 0);
7838 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007839
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007840 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12007842 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06007843 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
7844 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007845}
7846
Karl Schultz6addd812016-02-02 17:17:23 -07007847TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06007848 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07007849 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007852
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007853 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06007854 ASSERT_NO_FATAL_FAILURE(InitViewport());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007856 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007857 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7858 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007859
7860 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007861 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7862 ds_pool_ci.pNext = NULL;
7863 ds_pool_ci.maxSets = 1;
7864 ds_pool_ci.poolSizeCount = 1;
7865 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06007866
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007869 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007870
Tony Barboureb254902015-07-15 12:50:33 -06007871 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 dsl_binding.binding = 0;
7873 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7874 dsl_binding.descriptorCount = 1;
7875 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7876 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007877
Tony Barboureb254902015-07-15 12:50:33 -06007878 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007879 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7880 ds_layout_ci.pNext = NULL;
7881 ds_layout_ci.bindingCount = 1;
7882 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007883 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007885 ASSERT_VK_SUCCESS(err);
7886
7887 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007888 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007890 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007891 alloc_info.descriptorPool = ds_pool;
7892 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007893 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007894 ASSERT_VK_SUCCESS(err);
7895
Tony Barboureb254902015-07-15 12:50:33 -06007896 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007897 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7898 pipeline_layout_ci.pNext = NULL;
7899 pipeline_layout_ci.setLayoutCount = 1;
7900 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007901
7902 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007903 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007904 ASSERT_VK_SUCCESS(err);
7905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007906 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007907 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007908 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007910
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007911 VkPipelineObj pipe(m_device);
7912 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007913 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007914 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06007915 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007916
7917 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007918 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7919 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
7920 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007922 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007923
Chia-I Wuf7458c52015-10-26 21:10:41 +08007924 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7925 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7926 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007927}
7928
Karl Schultz6addd812016-02-02 17:17:23 -07007929TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007930 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07007931 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
7934 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007935
7936 ASSERT_NO_FATAL_FAILURE(InitState());
7937 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007938 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7939 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007940
7941 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007942 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7943 ds_pool_ci.pNext = NULL;
7944 ds_pool_ci.maxSets = 1;
7945 ds_pool_ci.poolSizeCount = 1;
7946 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007947
7948 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007950 ASSERT_VK_SUCCESS(err);
7951
7952 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007953 dsl_binding.binding = 0;
7954 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7955 dsl_binding.descriptorCount = 1;
7956 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7957 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007958
7959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7961 ds_layout_ci.pNext = NULL;
7962 ds_layout_ci.bindingCount = 1;
7963 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007964 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007966 ASSERT_VK_SUCCESS(err);
7967
7968 VkDescriptorSet descriptorSet;
7969 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007971 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007972 alloc_info.descriptorPool = ds_pool;
7973 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007975 ASSERT_VK_SUCCESS(err);
7976
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007977 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007978 VkWriteDescriptorSet descriptor_write;
7979 memset(&descriptor_write, 0, sizeof(descriptor_write));
7980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7981 descriptor_write.dstSet = descriptorSet;
7982 descriptor_write.dstBinding = 0;
7983 descriptor_write.descriptorCount = 1;
7984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
7985 descriptor_write.pTexelBufferView = &view;
7986
7987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7988
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007989 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07007990
7991 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7992 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7993}
7994
Mark Youngd339ba32016-05-30 13:28:35 -06007995TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06007996 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06007997
7998 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06007999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06008000 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06008001
8002 ASSERT_NO_FATAL_FAILURE(InitState());
8003
8004 // Create a buffer with no bound memory and then attempt to create
8005 // a buffer view.
8006 VkBufferCreateInfo buff_ci = {};
8007 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12008008 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06008009 buff_ci.size = 256;
8010 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8011 VkBuffer buffer;
8012 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8013 ASSERT_VK_SUCCESS(err);
8014
8015 VkBufferViewCreateInfo buff_view_ci = {};
8016 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8017 buff_view_ci.buffer = buffer;
8018 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8019 buff_view_ci.range = VK_WHOLE_SIZE;
8020 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06008022
8023 m_errorMonitor->VerifyFound();
8024 vkDestroyBuffer(m_device->device(), buffer, NULL);
8025 // If last error is success, it still created the view, so delete it.
8026 if (err == VK_SUCCESS) {
8027 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8028 }
8029}
8030
Karl Schultz6addd812016-02-02 17:17:23 -07008031TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
8032 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
8033 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07008034 // 1. No dynamicOffset supplied
8035 // 2. Too many dynamicOffsets supplied
8036 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07008037 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
8039 "0 dynamicOffsets are left in "
8040 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008041
8042 ASSERT_NO_FATAL_FAILURE(InitState());
8043 ASSERT_NO_FATAL_FAILURE(InitViewport());
8044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8045
8046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8048 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008049
8050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8052 ds_pool_ci.pNext = NULL;
8053 ds_pool_ci.maxSets = 1;
8054 ds_pool_ci.poolSizeCount = 1;
8055 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008056
8057 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008059 ASSERT_VK_SUCCESS(err);
8060
8061 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008062 dsl_binding.binding = 0;
8063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8064 dsl_binding.descriptorCount = 1;
8065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8066 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008067
8068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8070 ds_layout_ci.pNext = NULL;
8071 ds_layout_ci.bindingCount = 1;
8072 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008073 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008074 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008075 ASSERT_VK_SUCCESS(err);
8076
8077 VkDescriptorSet descriptorSet;
8078 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008079 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008080 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008081 alloc_info.descriptorPool = ds_pool;
8082 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008083 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008084 ASSERT_VK_SUCCESS(err);
8085
8086 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008087 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8088 pipeline_layout_ci.pNext = NULL;
8089 pipeline_layout_ci.setLayoutCount = 1;
8090 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008091
8092 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008093 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008094 ASSERT_VK_SUCCESS(err);
8095
8096 // Create a buffer to update the descriptor with
8097 uint32_t qfi = 0;
8098 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008099 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8100 buffCI.size = 1024;
8101 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8102 buffCI.queueFamilyIndexCount = 1;
8103 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008104
8105 VkBuffer dyub;
8106 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8107 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008108 // Allocate memory and bind to buffer so we can make it to the appropriate
8109 // error
8110 VkMemoryAllocateInfo mem_alloc = {};
8111 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8112 mem_alloc.pNext = NULL;
8113 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12008114 mem_alloc.memoryTypeIndex = 0;
8115
8116 VkMemoryRequirements memReqs;
8117 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008118 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12008119 if (!pass) {
8120 vkDestroyBuffer(m_device->device(), dyub, NULL);
8121 return;
8122 }
8123
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008124 VkDeviceMemory mem;
8125 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8126 ASSERT_VK_SUCCESS(err);
8127 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
8128 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008129 // Correctly update descriptor to avoid "NOT_UPDATED" error
8130 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008131 buffInfo.buffer = dyub;
8132 buffInfo.offset = 0;
8133 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008134
8135 VkWriteDescriptorSet descriptor_write;
8136 memset(&descriptor_write, 0, sizeof(descriptor_write));
8137 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8138 descriptor_write.dstSet = descriptorSet;
8139 descriptor_write.dstBinding = 0;
8140 descriptor_write.descriptorCount = 1;
8141 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8142 descriptor_write.pBufferInfo = &buffInfo;
8143
8144 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8145
8146 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008147 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8148 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008149 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07008150 uint32_t pDynOff[2] = {512, 756};
8151 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8153 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
8154 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8155 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12008156 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07008157 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
8159 "offset 0 and range 1024 that "
8160 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07008161 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 char const *vsSource = "#version 450\n"
8163 "\n"
8164 "out gl_PerVertex { \n"
8165 " vec4 gl_Position;\n"
8166 "};\n"
8167 "void main(){\n"
8168 " gl_Position = vec4(1);\n"
8169 "}\n";
8170 char const *fsSource = "#version 450\n"
8171 "\n"
8172 "layout(location=0) out vec4 x;\n"
8173 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8174 "void main(){\n"
8175 " x = vec4(bar.y);\n"
8176 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07008177 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8178 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8179 VkPipelineObj pipe(m_device);
8180 pipe.AddShader(&vs);
8181 pipe.AddShader(&fs);
8182 pipe.AddColorAttachment();
8183 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008186 // This update should succeed, but offset size of 512 will overstep buffer
8187 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
8189 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07008190 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008191 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008192
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008193 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06008194 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008195
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008196 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07008198 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8199}
8200
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008201TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
8202 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
8203 "that doesn't have memory bound");
8204 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06008206 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06008207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8208 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008209
8210 ASSERT_NO_FATAL_FAILURE(InitState());
8211 ASSERT_NO_FATAL_FAILURE(InitViewport());
8212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8213
8214 VkDescriptorPoolSize ds_type_count = {};
8215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8216 ds_type_count.descriptorCount = 1;
8217
8218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8220 ds_pool_ci.pNext = NULL;
8221 ds_pool_ci.maxSets = 1;
8222 ds_pool_ci.poolSizeCount = 1;
8223 ds_pool_ci.pPoolSizes = &ds_type_count;
8224
8225 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008226 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008227 ASSERT_VK_SUCCESS(err);
8228
8229 VkDescriptorSetLayoutBinding dsl_binding = {};
8230 dsl_binding.binding = 0;
8231 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8232 dsl_binding.descriptorCount = 1;
8233 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8234 dsl_binding.pImmutableSamplers = NULL;
8235
8236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8238 ds_layout_ci.pNext = NULL;
8239 ds_layout_ci.bindingCount = 1;
8240 ds_layout_ci.pBindings = &dsl_binding;
8241 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008243 ASSERT_VK_SUCCESS(err);
8244
8245 VkDescriptorSet descriptorSet;
8246 VkDescriptorSetAllocateInfo alloc_info = {};
8247 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8248 alloc_info.descriptorSetCount = 1;
8249 alloc_info.descriptorPool = ds_pool;
8250 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06008252 ASSERT_VK_SUCCESS(err);
8253
8254 // Create a buffer to update the descriptor with
8255 uint32_t qfi = 0;
8256 VkBufferCreateInfo buffCI = {};
8257 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8258 buffCI.size = 1024;
8259 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8260 buffCI.queueFamilyIndexCount = 1;
8261 buffCI.pQueueFamilyIndices = &qfi;
8262
8263 VkBuffer dyub;
8264 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8265 ASSERT_VK_SUCCESS(err);
8266
8267 // Attempt to update descriptor without binding memory to it
8268 VkDescriptorBufferInfo buffInfo = {};
8269 buffInfo.buffer = dyub;
8270 buffInfo.offset = 0;
8271 buffInfo.range = 1024;
8272
8273 VkWriteDescriptorSet descriptor_write;
8274 memset(&descriptor_write, 0, sizeof(descriptor_write));
8275 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8276 descriptor_write.dstSet = descriptorSet;
8277 descriptor_write.dstBinding = 0;
8278 descriptor_write.descriptorCount = 1;
8279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
8280 descriptor_write.pBufferInfo = &buffInfo;
8281
8282 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8283 m_errorMonitor->VerifyFound();
8284
8285 vkDestroyBuffer(m_device->device(), dyub, NULL);
8286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8288}
8289
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008290TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008291 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008292 ASSERT_NO_FATAL_FAILURE(InitState());
8293 ASSERT_NO_FATAL_FAILURE(InitViewport());
8294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8295
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008296 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008297 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008298 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8299 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8300 pipeline_layout_ci.pushConstantRangeCount = 1;
8301 pipeline_layout_ci.pPushConstantRanges = &pc_range;
8302
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008303 //
8304 // Check for invalid push constant ranges in pipeline layouts.
8305 //
8306 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008307 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008308 char const *msg;
8309 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008310
Karl Schultzc81037d2016-05-12 08:11:23 -06008311 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
8312 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
8313 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
8314 "vkCreatePipelineLayout() call has push constants index 0 with "
8315 "size 0."},
8316 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8317 "vkCreatePipelineLayout() call has push constants index 0 with "
8318 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008319 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008320 "vkCreatePipelineLayout() call has push constants index 0 with "
8321 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008322 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06008323 "vkCreatePipelineLayout() call has push constants index 0 with "
8324 "size 0."},
8325 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8326 "vkCreatePipelineLayout() call has push constants index 0 with "
8327 "offset 1. Offset must"},
8328 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
8329 "vkCreatePipelineLayout() call has push constants index 0 "
8330 "with offset "},
8331 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
8332 "vkCreatePipelineLayout() call has push constants "
8333 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008334 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008335 "vkCreatePipelineLayout() call has push constants index 0 "
8336 "with offset "},
8337 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
8338 "vkCreatePipelineLayout() call has push "
8339 "constants index 0 with offset "},
8340 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
8341 "vkCreatePipelineLayout() call has push "
8342 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008343 }};
8344
8345 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06008346 for (const auto &iter : range_tests) {
8347 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8349 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008350 m_errorMonitor->VerifyFound();
8351 if (VK_SUCCESS == err) {
8352 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8353 }
8354 }
8355
8356 // Check for invalid stage flag
8357 pc_range.offset = 0;
8358 pc_range.size = 16;
8359 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008360 m_errorMonitor->SetDesiredFailureMsg(
8361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8362 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008364 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008365 if (VK_SUCCESS == err) {
8366 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8367 }
8368
8369 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06008370 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008371 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06008372 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008373 char const *msg;
8374 };
8375
Karl Schultzc81037d2016-05-12 08:11:23 -06008376 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008377 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8378 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8379 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8380 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8381 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008382 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008383 {
8384 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8385 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8386 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8387 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8388 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008389 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008390 },
8391 {
8392 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8393 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8394 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8395 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8396 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008397 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008398 },
8399 {
8400 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8401 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8402 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8403 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
8404 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008405 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008406 },
8407 {
8408 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8409 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
8410 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
8411 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
8412 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008413 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008414 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008415
Karl Schultzc81037d2016-05-12 08:11:23 -06008416 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008417 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06008418 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
8420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008421 m_errorMonitor->VerifyFound();
8422 if (VK_SUCCESS == err) {
8423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8424 }
8425 }
8426
8427 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008428 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
8429 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
8430 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
8431 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
8432 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
8433 ""},
8434 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
8435 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
8436 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
8437 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
8438 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
8439 ""}}};
Karl Schultzc81037d2016-05-12 08:11:23 -06008440 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008441 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
8442 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008444 m_errorMonitor->VerifyNotFound();
8445 if (VK_SUCCESS == err) {
8446 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8447 }
8448 }
8449
8450 //
8451 // CmdPushConstants tests
8452 //
Karl Schultzc81037d2016-05-12 08:11:23 -06008453 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008454
8455 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008456 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
8457 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06008458 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
8459 "vkCmdPushConstants() call has push constants with size 1. Size "
8460 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008461 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06008462 "vkCmdPushConstants() call has push constants with size 1. Size "
8463 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008464 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06008465 "vkCmdPushConstants() call has push constants with offset 1. "
8466 "Offset must be a multiple of 4."},
8467 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
8468 "vkCmdPushConstants() call has push constants with offset 1. "
8469 "Offset must be a multiple of 4."},
8470 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8471 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8472 "0x1 not within flag-matching ranges in pipeline layout"},
8473 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
8474 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
8475 "0x1 not within flag-matching ranges in pipeline layout"},
8476 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
8477 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
8478 "0x1 not within flag-matching ranges in pipeline layout"},
8479 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
8480 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
8481 "0x1 not within flag-matching ranges in pipeline layout"},
8482 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
8483 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
8484 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008485 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06008486 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
8487 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008488 }};
8489
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008490 BeginCommandBuffer();
8491
8492 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06008493 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008494 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008495 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008497 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008499 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008500 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8502 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008503 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008504 m_errorMonitor->VerifyFound();
8505 }
8506
8507 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008509 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008510 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06008511 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06008512
Karl Schultzc81037d2016-05-12 08:11:23 -06008513 // overlapping range tests with cmd
8514 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
8515 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
8516 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
8517 "0x1 not within flag-matching ranges in pipeline layout"},
8518 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
8519 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
8520 "0x1 not within flag-matching ranges in pipeline layout"},
8521 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
8522 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
8523 "0x1 not within flag-matching ranges in pipeline layout"},
8524 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008525 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008526 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008527 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8528 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06008529 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008531 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008532 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008533 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008534 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
8536 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008537 iter.range.size, dummy_values);
8538 m_errorMonitor->VerifyFound();
8539 }
Karl Schultzc81037d2016-05-12 08:11:23 -06008540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8541
8542 // positive overlapping range tests with cmd
8543 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
8544 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
8545 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
8546 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
8547 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
8548 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008549 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06008550 const VkPushConstantRange pc_range4[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008551 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
8552 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Karl Schultzc81037d2016-05-12 08:11:23 -06008553 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008554 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06008555 pipeline_layout_ci.pPushConstantRanges = pc_range4;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06008557 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06008558 for (const auto &iter : cmd_overlap_tests_pos) {
8559 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008560 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06008561 iter.range.size, dummy_values);
8562 m_errorMonitor->VerifyNotFound();
8563 }
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008564 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06008565
8566 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07008567}
8568
Karl Schultz6addd812016-02-02 17:17:23 -07008569TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008570 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07008571 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008572
8573 ASSERT_NO_FATAL_FAILURE(InitState());
8574 ASSERT_NO_FATAL_FAILURE(InitViewport());
8575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8576
Mike Stroyanb8a61002016-06-20 16:00:28 -06008577 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
8578 VkImageTiling tiling;
8579 VkFormatProperties format_properties;
8580 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008581 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008582 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008583 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06008584 tiling = VK_IMAGE_TILING_OPTIMAL;
8585 } else {
8586 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
8587 "skipped.\n");
8588 return;
8589 }
8590
Tobin Ehlis559c6382015-11-05 09:52:49 -07008591 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
8592 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008593 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8594 ds_type_count[0].descriptorCount = 10;
8595 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8596 ds_type_count[1].descriptorCount = 2;
8597 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8598 ds_type_count[2].descriptorCount = 2;
8599 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8600 ds_type_count[3].descriptorCount = 5;
8601 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
8602 // type
8603 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8604 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
8605 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008606
8607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8609 ds_pool_ci.pNext = NULL;
8610 ds_pool_ci.maxSets = 5;
8611 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
8612 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008613
8614 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008615 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008616 ASSERT_VK_SUCCESS(err);
8617
8618 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
8619 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008620 dsl_binding[0].binding = 0;
8621 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8622 dsl_binding[0].descriptorCount = 5;
8623 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8624 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008625
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008626 // Create layout identical to set0 layout but w/ different stageFlags
8627 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008628 dsl_fs_stage_only.binding = 0;
8629 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8630 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008631 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
8632 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07008633 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8636 ds_layout_ci.pNext = NULL;
8637 ds_layout_ci.bindingCount = 1;
8638 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008639 static const uint32_t NUM_LAYOUTS = 4;
8640 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008641 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008642 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
8643 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008645 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008646 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008648 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008649 dsl_binding[0].binding = 0;
8650 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008651 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008652 dsl_binding[1].binding = 1;
8653 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
8654 dsl_binding[1].descriptorCount = 2;
8655 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8656 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008657 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008658 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008659 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008660 ASSERT_VK_SUCCESS(err);
8661 dsl_binding[0].binding = 0;
8662 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008663 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008664 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008666 ASSERT_VK_SUCCESS(err);
8667 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008668 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008670 ASSERT_VK_SUCCESS(err);
8671
8672 static const uint32_t NUM_SETS = 4;
8673 VkDescriptorSet descriptorSet[NUM_SETS] = {};
8674 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008676 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008677 alloc_info.descriptorPool = ds_pool;
8678 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008680 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008681 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008682 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008683 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008685 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008686
8687 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008688 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8689 pipeline_layout_ci.pNext = NULL;
8690 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
8691 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008692
8693 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008695 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008696 // Create pipelineLayout with only one setLayout
8697 pipeline_layout_ci.setLayoutCount = 1;
8698 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008700 ASSERT_VK_SUCCESS(err);
8701 // Create pipelineLayout with 2 descriptor setLayout at index 0
8702 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
8703 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008704 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008705 ASSERT_VK_SUCCESS(err);
8706 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
8707 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
8708 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008709 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008710 ASSERT_VK_SUCCESS(err);
8711 // Create pipelineLayout with UB type, but stageFlags for FS only
8712 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
8713 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008715 ASSERT_VK_SUCCESS(err);
8716 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
8717 VkDescriptorSetLayout pl_bad_s0[2] = {};
8718 pl_bad_s0[0] = ds_layout_fs_only;
8719 pl_bad_s0[1] = ds_layout[1];
8720 pipeline_layout_ci.setLayoutCount = 2;
8721 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
8722 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008724 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008725
8726 // Create a buffer to update the descriptor with
8727 uint32_t qfi = 0;
8728 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008729 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8730 buffCI.size = 1024;
8731 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8732 buffCI.queueFamilyIndexCount = 1;
8733 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008734
8735 VkBuffer dyub;
8736 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
8737 ASSERT_VK_SUCCESS(err);
8738 // Correctly update descriptor to avoid "NOT_UPDATED" error
8739 static const uint32_t NUM_BUFFS = 5;
8740 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008741 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07008742 buffInfo[i].buffer = dyub;
8743 buffInfo[i].offset = 0;
8744 buffInfo[i].range = 1024;
8745 }
Karl Schultz6addd812016-02-02 17:17:23 -07008746 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07008747 const int32_t tex_width = 32;
8748 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008749 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008750 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8751 image_create_info.pNext = NULL;
8752 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8753 image_create_info.format = tex_format;
8754 image_create_info.extent.width = tex_width;
8755 image_create_info.extent.height = tex_height;
8756 image_create_info.extent.depth = 1;
8757 image_create_info.mipLevels = 1;
8758 image_create_info.arrayLayers = 1;
8759 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06008760 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008761 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07008762 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8764 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008765
Karl Schultz6addd812016-02-02 17:17:23 -07008766 VkMemoryRequirements memReqs;
8767 VkDeviceMemory imageMem;
8768 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008769 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008770 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8771 memAlloc.pNext = NULL;
8772 memAlloc.allocationSize = 0;
8773 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008774 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
8775 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07008777 ASSERT_TRUE(pass);
8778 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
8779 ASSERT_VK_SUCCESS(err);
8780 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
8781 ASSERT_VK_SUCCESS(err);
8782
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008783 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008784 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8785 image_view_create_info.image = image;
8786 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8787 image_view_create_info.format = tex_format;
8788 image_view_create_info.subresourceRange.layerCount = 1;
8789 image_view_create_info.subresourceRange.baseMipLevel = 0;
8790 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07008792
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008793 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008794 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008796 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008797 imageInfo[0].imageView = view;
8798 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8799 imageInfo[1].imageView = view;
8800 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008801 imageInfo[2].imageView = view;
8802 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8803 imageInfo[3].imageView = view;
8804 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008805
8806 static const uint32_t NUM_SET_UPDATES = 3;
8807 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
8808 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8809 descriptor_write[0].dstSet = descriptorSet[0];
8810 descriptor_write[0].dstBinding = 0;
8811 descriptor_write[0].descriptorCount = 5;
8812 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8813 descriptor_write[0].pBufferInfo = buffInfo;
8814 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8815 descriptor_write[1].dstSet = descriptorSet[1];
8816 descriptor_write[1].dstBinding = 0;
8817 descriptor_write[1].descriptorCount = 2;
8818 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
8819 descriptor_write[1].pImageInfo = imageInfo;
8820 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8821 descriptor_write[2].dstSet = descriptorSet[1];
8822 descriptor_write[2].dstBinding = 1;
8823 descriptor_write[2].descriptorCount = 2;
8824 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008825 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008826
8827 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008828
Tobin Ehlis88452832015-12-03 09:40:56 -07008829 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008830 char const *vsSource = "#version 450\n"
8831 "\n"
8832 "out gl_PerVertex {\n"
8833 " vec4 gl_Position;\n"
8834 "};\n"
8835 "void main(){\n"
8836 " gl_Position = vec4(1);\n"
8837 "}\n";
8838 char const *fsSource = "#version 450\n"
8839 "\n"
8840 "layout(location=0) out vec4 x;\n"
8841 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8842 "void main(){\n"
8843 " x = vec4(bar.y);\n"
8844 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07008845 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8846 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008847 VkPipelineObj pipe(m_device);
8848 pipe.AddShader(&vs);
8849 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07008850 pipe.AddColorAttachment();
8851 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07008852
8853 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07008854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07008856 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
8857 // of PSO
8858 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
8859 // cmd_pipeline.c
8860 // due to the fact that cmd_alloc_dset_data() has not been called in
8861 // cmd_bind_graphics_pipeline()
8862 // TODO : Want to cause various binding incompatibility issues here to test
8863 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07008864 // First cause various verify_layout_compatibility() fails
8865 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008866 // verify_set_layout_compatibility fail cases:
8867 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
8869 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
8870 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008871 m_errorMonitor->VerifyFound();
8872
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008873 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
8875 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
8876 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008877 m_errorMonitor->VerifyFound();
8878
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008879 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008880 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
8881 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
8883 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
8884 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008885 m_errorMonitor->VerifyFound();
8886
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008887 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
8888 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
8890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
8891 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008892 m_errorMonitor->VerifyFound();
8893
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008894 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
8895 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8897 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
8898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8899 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008900 m_errorMonitor->VerifyFound();
8901
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008902 // Cause INFO messages due to disturbing previously bound Sets
8903 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8905 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008906 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
8908 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8909 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008910 m_errorMonitor->VerifyFound();
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8913 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008914 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
8916 "any subsequent sets were disturbed ");
8917 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
8918 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008919 m_errorMonitor->VerifyFound();
8920
Tobin Ehlis10fad692016-07-07 12:00:36 -06008921 // Now that we're done actively using the pipelineLayout that gfx pipeline
8922 // was created with, we should be able to delete it. Do that now to verify
8923 // that validation obeys pipelineLayout lifetime
8924 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
8925
Tobin Ehlis88452832015-12-03 09:40:56 -07008926 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07008927 // 1. Error due to not binding required set (we actually use same code as
8928 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008929 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8930 &descriptorSet[0], 0, NULL);
8931 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
8932 &descriptorSet[1], 0, NULL);
8933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07008934 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008935 m_errorMonitor->VerifyFound();
8936
Tobin Ehlis991d45a2016-01-06 08:48:41 -07008937 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008938 // 2. Error due to bound set not being compatible with PSO's
8939 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
8941 &descriptorSet[0], 0, NULL);
8942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07008943 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008944 m_errorMonitor->VerifyFound();
8945
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008946 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07008947 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008948 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
8949 }
8950 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06008951 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
8952 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07008953 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008954 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8955 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008956 vkFreeMemory(m_device->device(), imageMem, NULL);
8957 vkDestroyImage(m_device->device(), image, NULL);
8958 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07008959}
Tobin Ehlis559c6382015-11-05 09:52:49 -07008960
Karl Schultz6addd812016-02-02 17:17:23 -07008961TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8964 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008965
8966 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008967 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008968 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008969 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008970
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008971 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008972}
8973
Karl Schultz6addd812016-02-02 17:17:23 -07008974TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
8975 VkResult err;
8976 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008979
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008980 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008981
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008982 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008983 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008984 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008985 cmd.commandPool = m_commandPool;
8986 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008987 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06008988
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008989 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06008990 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008991
8992 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008993 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07008994 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008995 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06008996 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008997 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008998 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06008999
9000 // The error should be caught by validation of the BeginCommandBuffer call
9001 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
9002
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009003 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009004 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06009005}
9006
Karl Schultz6addd812016-02-02 17:17:23 -07009007TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009008 // Cause error due to Begin while recording CB
9009 // Then cause 2 errors for attempting to reset CB w/o having
9010 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
9011 // which CBs were allocated. Note that this bit is off by default.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009013
9014 ASSERT_NO_FATAL_FAILURE(InitState());
9015
9016 // Calls AllocateCommandBuffers
9017 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
9018
Karl Schultz6addd812016-02-02 17:17:23 -07009019 // Force the failure by setting the Renderpass and Framebuffer fields with
9020 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009021 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07009022 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009023 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9024 cmd_buf_info.pNext = NULL;
9025 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009026 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009027
9028 // Begin CB to transition to recording state
9029 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
9030 // Can't re-begin. This should trigger error
9031 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009032 m_errorMonitor->VerifyFound();
9033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009035 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
9036 // Reset attempt will trigger error due to incorrect CommandPool state
9037 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009038 m_errorMonitor->VerifyFound();
9039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009041 // Transition CB to RECORDED state
9042 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
9043 // Now attempting to Begin will implicitly reset, which triggers error
9044 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009045 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07009046}
9047
Karl Schultz6addd812016-02-02 17:17:23 -07009048TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009049 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009050 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vtx Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009053
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009054 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009056
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009057 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009058 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9059 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009060
9061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9063 ds_pool_ci.pNext = NULL;
9064 ds_pool_ci.maxSets = 1;
9065 ds_pool_ci.poolSizeCount = 1;
9066 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009067
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009068 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009069 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009070 ASSERT_VK_SUCCESS(err);
9071
Tony Barboureb254902015-07-15 12:50:33 -06009072 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009073 dsl_binding.binding = 0;
9074 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9075 dsl_binding.descriptorCount = 1;
9076 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9077 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009078
Tony Barboureb254902015-07-15 12:50:33 -06009079 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009080 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9081 ds_layout_ci.pNext = NULL;
9082 ds_layout_ci.bindingCount = 1;
9083 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009084
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009085 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009087 ASSERT_VK_SUCCESS(err);
9088
9089 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009090 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009091 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009092 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009093 alloc_info.descriptorPool = ds_pool;
9094 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009096 ASSERT_VK_SUCCESS(err);
9097
Tony Barboureb254902015-07-15 12:50:33 -06009098 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009099 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9100 pipeline_layout_ci.setLayoutCount = 1;
9101 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009102
9103 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009104 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009105 ASSERT_VK_SUCCESS(err);
9106
Tobin Ehlise68360f2015-10-01 11:15:13 -06009107 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07009108 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06009109
9110 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009111 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9112 vp_state_ci.scissorCount = 1;
9113 vp_state_ci.pScissors = &sc;
9114 vp_state_ci.viewportCount = 1;
9115 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009116
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009117 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9118 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9119 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9120 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9121 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9122 rs_state_ci.depthClampEnable = VK_FALSE;
9123 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9124 rs_state_ci.depthBiasEnable = VK_FALSE;
9125
Tony Barboureb254902015-07-15 12:50:33 -06009126 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009127 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9128 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009129 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009130 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9131 gp_ci.layout = pipeline_layout;
9132 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06009133
9134 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009135 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9136 pc_ci.initialDataSize = 0;
9137 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009138
9139 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06009140 VkPipelineCache pipelineCache;
9141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06009143 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009144 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06009145
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009146 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009147
Chia-I Wuf7458c52015-10-26 21:10:41 +08009148 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9151 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009152}
Tobin Ehlis912df022015-09-17 08:46:18 -06009153/*// TODO : This test should be good, but needs Tess support in compiler to run
9154TEST_F(VkLayerTest, InvalidPatchControlPoints)
9155{
9156 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06009157 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009158
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009160 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
9161primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009162
Tobin Ehlis912df022015-09-17 08:46:18 -06009163 ASSERT_NO_FATAL_FAILURE(InitState());
9164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06009165
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009166 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06009167 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009168 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009169
9170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9172 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009173 ds_pool_ci.poolSizeCount = 1;
9174 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06009175
9176 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009177 err = vkCreateDescriptorPool(m_device->device(),
9178VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06009179 ASSERT_VK_SUCCESS(err);
9180
9181 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009182 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06009183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009184 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9186 dsl_binding.pImmutableSamplers = NULL;
9187
9188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009189 ds_layout_ci.sType =
9190VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009191 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009192 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009193 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06009194
9195 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009196 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9197&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009198 ASSERT_VK_SUCCESS(err);
9199
9200 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009201 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
9202VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06009203 ASSERT_VK_SUCCESS(err);
9204
9205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009206 pipeline_layout_ci.sType =
9207VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06009208 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009209 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06009210 pipeline_layout_ci.pSetLayouts = &ds_layout;
9211
9212 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009213 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9214&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06009215 ASSERT_VK_SUCCESS(err);
9216
9217 VkPipelineShaderStageCreateInfo shaderStages[3];
9218 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
9219
Karl Schultz6addd812016-02-02 17:17:23 -07009220 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
9221this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009222 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07009223 VkShaderObj
9224tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
9225this);
9226 VkShaderObj
9227te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
9228this);
Tobin Ehlis912df022015-09-17 08:46:18 -06009229
Karl Schultz6addd812016-02-02 17:17:23 -07009230 shaderStages[0].sType =
9231VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009232 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009233 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009234 shaderStages[1].sType =
9235VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009236 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009237 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07009238 shaderStages[2].sType =
9239VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009240 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06009241 shaderStages[2].shader = te.handle();
9242
9243 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 iaCI.sType =
9245VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08009246 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06009247
9248 VkPipelineTessellationStateCreateInfo tsCI = {};
9249 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
9250 tsCI.patchControlPoints = 0; // This will cause an error
9251
9252 VkGraphicsPipelineCreateInfo gp_ci = {};
9253 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9254 gp_ci.pNext = NULL;
9255 gp_ci.stageCount = 3;
9256 gp_ci.pStages = shaderStages;
9257 gp_ci.pVertexInputState = NULL;
9258 gp_ci.pInputAssemblyState = &iaCI;
9259 gp_ci.pTessellationState = &tsCI;
9260 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009261 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06009262 gp_ci.pMultisampleState = NULL;
9263 gp_ci.pDepthStencilState = NULL;
9264 gp_ci.pColorBlendState = NULL;
9265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9266 gp_ci.layout = pipeline_layout;
9267 gp_ci.renderPass = renderPass();
9268
9269 VkPipelineCacheCreateInfo pc_ci = {};
9270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9271 pc_ci.pNext = NULL;
9272 pc_ci.initialSize = 0;
9273 pc_ci.initialData = 0;
9274 pc_ci.maxSize = 0;
9275
9276 VkPipeline pipeline;
9277 VkPipelineCache pipelineCache;
9278
Karl Schultz6addd812016-02-02 17:17:23 -07009279 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
9280&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06009281 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009282 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
9283&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06009284
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009285 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009286
Chia-I Wuf7458c52015-10-26 21:10:41 +08009287 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9288 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9289 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9290 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06009291}
9292*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06009293// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07009294TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07009295 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009296
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9298 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009299
Tobin Ehlise68360f2015-10-01 11:15:13 -06009300 ASSERT_NO_FATAL_FAILURE(InitState());
9301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009302
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009303 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009304 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9305 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009306
9307 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009308 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9309 ds_pool_ci.maxSets = 1;
9310 ds_pool_ci.poolSizeCount = 1;
9311 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009312
9313 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009315 ASSERT_VK_SUCCESS(err);
9316
9317 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009318 dsl_binding.binding = 0;
9319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9320 dsl_binding.descriptorCount = 1;
9321 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009322
9323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9325 ds_layout_ci.bindingCount = 1;
9326 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009327
9328 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009330 ASSERT_VK_SUCCESS(err);
9331
9332 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009333 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009335 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009336 alloc_info.descriptorPool = ds_pool;
9337 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009339 ASSERT_VK_SUCCESS(err);
9340
9341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9343 pipeline_layout_ci.setLayoutCount = 1;
9344 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009345
9346 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009347 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009348 ASSERT_VK_SUCCESS(err);
9349
9350 VkViewport vp = {}; // Just need dummy vp to point to
9351
9352 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009353 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9354 vp_state_ci.scissorCount = 0;
9355 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
9356 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009357
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009358 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9359 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9360 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9361 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9362 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9363 rs_state_ci.depthClampEnable = VK_FALSE;
9364 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9365 rs_state_ci.depthBiasEnable = VK_FALSE;
9366
Cody Northropeb3a6c12015-10-05 14:44:45 -06009367 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009368 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9371 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9372 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009373 shaderStages[0] = vs.GetStageCreateInfo();
9374 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009375
9376 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009377 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9378 gp_ci.stageCount = 2;
9379 gp_ci.pStages = shaderStages;
9380 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009381 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009382 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9383 gp_ci.layout = pipeline_layout;
9384 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009385
9386 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009387 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009388
9389 VkPipeline pipeline;
9390 VkPipelineCache pipelineCache;
9391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009392 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009393 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009394 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009395
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009396 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009397
Chia-I Wuf7458c52015-10-26 21:10:41 +08009398 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9399 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9401 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009402}
Karl Schultz6addd812016-02-02 17:17:23 -07009403// Don't set viewport state in PSO. This is an error b/c we always need this
9404// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06009405// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07009406TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06009407 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07009408 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009411
Tobin Ehlise68360f2015-10-01 11:15:13 -06009412 ASSERT_NO_FATAL_FAILURE(InitState());
9413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009414
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009415 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009416 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9417 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009418
9419 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009420 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9421 ds_pool_ci.maxSets = 1;
9422 ds_pool_ci.poolSizeCount = 1;
9423 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009424
9425 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009426 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009427 ASSERT_VK_SUCCESS(err);
9428
9429 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009430 dsl_binding.binding = 0;
9431 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9432 dsl_binding.descriptorCount = 1;
9433 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009434
9435 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009436 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9437 ds_layout_ci.bindingCount = 1;
9438 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009439
9440 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009441 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009442 ASSERT_VK_SUCCESS(err);
9443
9444 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009445 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009446 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009447 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009448 alloc_info.descriptorPool = ds_pool;
9449 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009451 ASSERT_VK_SUCCESS(err);
9452
9453 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009454 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9455 pipeline_layout_ci.setLayoutCount = 1;
9456 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009457
9458 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009460 ASSERT_VK_SUCCESS(err);
9461
9462 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9463 // Set scissor as dynamic to avoid second error
9464 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009465 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9466 dyn_state_ci.dynamicStateCount = 1;
9467 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009468
Cody Northropeb3a6c12015-10-05 14:44:45 -06009469 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009470 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009471
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009472 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9473 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9474 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009475 shaderStages[0] = vs.GetStageCreateInfo();
9476 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009477
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009478 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
9479 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9480 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
9481 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
9482 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9483 rs_state_ci.depthClampEnable = VK_FALSE;
9484 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
9485 rs_state_ci.depthBiasEnable = VK_FALSE;
9486
Tobin Ehlise68360f2015-10-01 11:15:13 -06009487 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009488 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9489 gp_ci.stageCount = 2;
9490 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07009491 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07009492 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
9493 // should cause validation error
9494 gp_ci.pDynamicState = &dyn_state_ci;
9495 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9496 gp_ci.layout = pipeline_layout;
9497 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009498
9499 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009500 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009501
9502 VkPipeline pipeline;
9503 VkPipelineCache pipelineCache;
9504
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009506 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009507 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009508
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009509 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009510
Chia-I Wuf7458c52015-10-26 21:10:41 +08009511 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9513 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9514 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009515}
9516// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07009517// Then run second test where dynamic scissor count doesn't match PSO scissor
9518// count
9519TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
9520 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9523 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009524
Tobin Ehlise68360f2015-10-01 11:15:13 -06009525 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009526
9527 if (!m_device->phy().features().multiViewport) {
9528 printf("Device does not support multiple viewports/scissors; skipped.\n");
9529 return;
9530 }
9531
Tobin Ehlise68360f2015-10-01 11:15:13 -06009532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06009533
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009534 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009535 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9536 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009537
9538 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009539 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9540 ds_pool_ci.maxSets = 1;
9541 ds_pool_ci.poolSizeCount = 1;
9542 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009543
9544 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009545 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009546 ASSERT_VK_SUCCESS(err);
9547
9548 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009549 dsl_binding.binding = 0;
9550 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9551 dsl_binding.descriptorCount = 1;
9552 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009553
9554 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009555 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9556 ds_layout_ci.bindingCount = 1;
9557 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009558
9559 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009560 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009561 ASSERT_VK_SUCCESS(err);
9562
9563 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009564 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009565 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009566 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009567 alloc_info.descriptorPool = ds_pool;
9568 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009570 ASSERT_VK_SUCCESS(err);
9571
9572 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009573 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9574 pipeline_layout_ci.setLayoutCount = 1;
9575 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009576
9577 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009579 ASSERT_VK_SUCCESS(err);
9580
9581 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009582 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9583 vp_state_ci.viewportCount = 1;
9584 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
9585 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06009587
9588 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
9589 // Set scissor as dynamic to avoid that error
9590 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009591 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9592 dyn_state_ci.dynamicStateCount = 1;
9593 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009594
Cody Northropeb3a6c12015-10-05 14:44:45 -06009595 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07009596 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06009597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009598 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9599 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9600 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08009601 shaderStages[0] = vs.GetStageCreateInfo();
9602 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009603
Cody Northropf6622dc2015-10-06 10:33:21 -06009604 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9605 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9606 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009607 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009608 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009609 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06009610 vi_ci.pVertexAttributeDescriptions = nullptr;
9611
9612 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9613 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9614 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9615
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009616 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009617 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06009618 rs_ci.pNext = nullptr;
9619
Mark Youngc89c6312016-03-31 16:03:20 -06009620 VkPipelineColorBlendAttachmentState att = {};
9621 att.blendEnable = VK_FALSE;
9622 att.colorWriteMask = 0xf;
9623
Cody Northropf6622dc2015-10-06 10:33:21 -06009624 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9625 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9626 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009627 cb_ci.attachmentCount = 1;
9628 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06009629
Tobin Ehlise68360f2015-10-01 11:15:13 -06009630 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009631 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9632 gp_ci.stageCount = 2;
9633 gp_ci.pStages = shaderStages;
9634 gp_ci.pVertexInputState = &vi_ci;
9635 gp_ci.pInputAssemblyState = &ia_ci;
9636 gp_ci.pViewportState = &vp_state_ci;
9637 gp_ci.pRasterizationState = &rs_ci;
9638 gp_ci.pColorBlendState = &cb_ci;
9639 gp_ci.pDynamicState = &dyn_state_ci;
9640 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9641 gp_ci.layout = pipeline_layout;
9642 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009643
9644 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009645 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06009646
9647 VkPipeline pipeline;
9648 VkPipelineCache pipelineCache;
9649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009651 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009653
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009654 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009655
Tobin Ehlisd332f282015-10-02 11:00:56 -06009656 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07009657 // First need to successfully create the PSO from above by setting
9658 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by PSO, ");
Karl Schultz6addd812016-02-02 17:17:23 -07009660
9661 VkViewport vp = {}; // Just need dummy vp to point to
9662 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009663 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009664 ASSERT_VK_SUCCESS(err);
9665 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009666 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009667 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07009668 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009669 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07009670 Draw(1, 0, 0, 0);
9671
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009672 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009673
9674 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9675 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9677 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009678 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07009679}
9680// Create PSO w/o non-zero scissorCount but no scissor data
9681// Then run second test where dynamic viewportCount doesn't match PSO
9682// viewportCount
9683TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
9684 VkResult err;
9685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07009687
9688 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009689
9690 if (!m_device->phy().features().multiViewport) {
9691 printf("Device does not support multiple viewports/scissors; skipped.\n");
9692 return;
9693 }
9694
Karl Schultz6addd812016-02-02 17:17:23 -07009695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9696
9697 VkDescriptorPoolSize ds_type_count = {};
9698 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9699 ds_type_count.descriptorCount = 1;
9700
9701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9703 ds_pool_ci.maxSets = 1;
9704 ds_pool_ci.poolSizeCount = 1;
9705 ds_pool_ci.pPoolSizes = &ds_type_count;
9706
9707 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07009709 ASSERT_VK_SUCCESS(err);
9710
9711 VkDescriptorSetLayoutBinding dsl_binding = {};
9712 dsl_binding.binding = 0;
9713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9714 dsl_binding.descriptorCount = 1;
9715 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9716
9717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9719 ds_layout_ci.bindingCount = 1;
9720 ds_layout_ci.pBindings = &dsl_binding;
9721
9722 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009724 ASSERT_VK_SUCCESS(err);
9725
9726 VkDescriptorSet descriptorSet;
9727 VkDescriptorSetAllocateInfo alloc_info = {};
9728 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9729 alloc_info.descriptorSetCount = 1;
9730 alloc_info.descriptorPool = ds_pool;
9731 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07009733 ASSERT_VK_SUCCESS(err);
9734
9735 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9736 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9737 pipeline_layout_ci.setLayoutCount = 1;
9738 pipeline_layout_ci.pSetLayouts = &ds_layout;
9739
9740 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07009742 ASSERT_VK_SUCCESS(err);
9743
9744 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9745 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9746 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009747 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009748 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07009750
9751 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
9752 // Set scissor as dynamic to avoid that error
9753 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9754 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9755 dyn_state_ci.dynamicStateCount = 1;
9756 dyn_state_ci.pDynamicStates = &vp_state;
9757
9758 VkPipelineShaderStageCreateInfo shaderStages[2];
9759 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009761 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9762 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9763 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07009764 shaderStages[0] = vs.GetStageCreateInfo();
9765 shaderStages[1] = fs.GetStageCreateInfo();
9766
9767 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9768 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9769 vi_ci.pNext = nullptr;
9770 vi_ci.vertexBindingDescriptionCount = 0;
9771 vi_ci.pVertexBindingDescriptions = nullptr;
9772 vi_ci.vertexAttributeDescriptionCount = 0;
9773 vi_ci.pVertexAttributeDescriptions = nullptr;
9774
9775 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9776 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9777 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9778
9779 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9780 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9781 rs_ci.pNext = nullptr;
9782
Mark Youngc89c6312016-03-31 16:03:20 -06009783 VkPipelineColorBlendAttachmentState att = {};
9784 att.blendEnable = VK_FALSE;
9785 att.colorWriteMask = 0xf;
9786
Karl Schultz6addd812016-02-02 17:17:23 -07009787 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9788 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9789 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06009790 cb_ci.attachmentCount = 1;
9791 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07009792
9793 VkGraphicsPipelineCreateInfo gp_ci = {};
9794 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9795 gp_ci.stageCount = 2;
9796 gp_ci.pStages = shaderStages;
9797 gp_ci.pVertexInputState = &vi_ci;
9798 gp_ci.pInputAssemblyState = &ia_ci;
9799 gp_ci.pViewportState = &vp_state_ci;
9800 gp_ci.pRasterizationState = &rs_ci;
9801 gp_ci.pColorBlendState = &cb_ci;
9802 gp_ci.pDynamicState = &dyn_state_ci;
9803 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9804 gp_ci.layout = pipeline_layout;
9805 gp_ci.renderPass = renderPass();
9806
9807 VkPipelineCacheCreateInfo pc_ci = {};
9808 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9809
9810 VkPipeline pipeline;
9811 VkPipelineCache pipelineCache;
9812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009813 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07009814 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07009816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009817 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07009818
9819 // Now hit second fail case where we set scissor w/ different count than PSO
9820 // First need to successfully create the PSO from above by setting
9821 // pViewports
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by PSO, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009823
Tobin Ehlisd332f282015-10-02 11:00:56 -06009824 VkRect2D sc = {}; // Just need dummy vp to point to
9825 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009826 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009827 ASSERT_VK_SUCCESS(err);
9828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009830 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06009831 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12009832 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009833 Draw(1, 0, 0, 0);
9834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009835 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06009836
Chia-I Wuf7458c52015-10-26 21:10:41 +08009837 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
9838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009841 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06009842}
9843
Mark Young7394fdd2016-03-31 14:56:43 -06009844TEST_F(VkLayerTest, PSOLineWidthInvalid) {
9845 VkResult err;
9846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009848
9849 ASSERT_NO_FATAL_FAILURE(InitState());
9850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9851
9852 VkDescriptorPoolSize ds_type_count = {};
9853 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9854 ds_type_count.descriptorCount = 1;
9855
9856 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9857 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9858 ds_pool_ci.maxSets = 1;
9859 ds_pool_ci.poolSizeCount = 1;
9860 ds_pool_ci.pPoolSizes = &ds_type_count;
9861
9862 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06009864 ASSERT_VK_SUCCESS(err);
9865
9866 VkDescriptorSetLayoutBinding dsl_binding = {};
9867 dsl_binding.binding = 0;
9868 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9869 dsl_binding.descriptorCount = 1;
9870 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9871
9872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9874 ds_layout_ci.bindingCount = 1;
9875 ds_layout_ci.pBindings = &dsl_binding;
9876
9877 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009879 ASSERT_VK_SUCCESS(err);
9880
9881 VkDescriptorSet descriptorSet;
9882 VkDescriptorSetAllocateInfo alloc_info = {};
9883 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9884 alloc_info.descriptorSetCount = 1;
9885 alloc_info.descriptorPool = ds_pool;
9886 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06009888 ASSERT_VK_SUCCESS(err);
9889
9890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9892 pipeline_layout_ci.setLayoutCount = 1;
9893 pipeline_layout_ci.pSetLayouts = &ds_layout;
9894
9895 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06009897 ASSERT_VK_SUCCESS(err);
9898
9899 VkPipelineViewportStateCreateInfo vp_state_ci = {};
9900 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9901 vp_state_ci.scissorCount = 1;
9902 vp_state_ci.pScissors = NULL;
9903 vp_state_ci.viewportCount = 1;
9904 vp_state_ci.pViewports = NULL;
9905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009906 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06009907 // Set scissor as dynamic to avoid that error
9908 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
9909 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
9910 dyn_state_ci.dynamicStateCount = 2;
9911 dyn_state_ci.pDynamicStates = dynamic_states;
9912
9913 VkPipelineShaderStageCreateInfo shaderStages[2];
9914 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
9915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9917 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06009918 this); // TODO - We shouldn't need a fragment shader
9919 // but add it to be able to run on more devices
9920 shaderStages[0] = vs.GetStageCreateInfo();
9921 shaderStages[1] = fs.GetStageCreateInfo();
9922
9923 VkPipelineVertexInputStateCreateInfo vi_ci = {};
9924 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9925 vi_ci.pNext = nullptr;
9926 vi_ci.vertexBindingDescriptionCount = 0;
9927 vi_ci.pVertexBindingDescriptions = nullptr;
9928 vi_ci.vertexAttributeDescriptionCount = 0;
9929 vi_ci.pVertexAttributeDescriptions = nullptr;
9930
9931 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
9932 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9933 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9934
9935 VkPipelineRasterizationStateCreateInfo rs_ci = {};
9936 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9937 rs_ci.pNext = nullptr;
9938
Mark Young47107952016-05-02 15:59:55 -06009939 // Check too low (line width of -1.0f).
9940 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06009941
9942 VkPipelineColorBlendAttachmentState att = {};
9943 att.blendEnable = VK_FALSE;
9944 att.colorWriteMask = 0xf;
9945
9946 VkPipelineColorBlendStateCreateInfo cb_ci = {};
9947 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
9948 cb_ci.pNext = nullptr;
9949 cb_ci.attachmentCount = 1;
9950 cb_ci.pAttachments = &att;
9951
9952 VkGraphicsPipelineCreateInfo gp_ci = {};
9953 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9954 gp_ci.stageCount = 2;
9955 gp_ci.pStages = shaderStages;
9956 gp_ci.pVertexInputState = &vi_ci;
9957 gp_ci.pInputAssemblyState = &ia_ci;
9958 gp_ci.pViewportState = &vp_state_ci;
9959 gp_ci.pRasterizationState = &rs_ci;
9960 gp_ci.pColorBlendState = &cb_ci;
9961 gp_ci.pDynamicState = &dyn_state_ci;
9962 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9963 gp_ci.layout = pipeline_layout;
9964 gp_ci.renderPass = renderPass();
9965
9966 VkPipelineCacheCreateInfo pc_ci = {};
9967 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9968
9969 VkPipeline pipeline;
9970 VkPipelineCache pipelineCache;
9971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009973 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009975
9976 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009977 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06009980
9981 // Check too high (line width of 65536.0f).
9982 rs_ci.lineWidth = 65536.0f;
9983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009984 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009985 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06009987
9988 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009989 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06009990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06009992
9993 dyn_state_ci.dynamicStateCount = 3;
9994
9995 rs_ci.lineWidth = 1.0f;
9996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009997 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06009998 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -060010000 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -060010002
10003 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -060010004 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -060010005 m_errorMonitor->VerifyFound();
10006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -060010008
10009 // Check too high with dynamic setting.
10010 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
10011 m_errorMonitor->VerifyFound();
10012 EndCommandBuffer();
10013
10014 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
10015 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010018 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -060010019}
10020
Karl Schultz6addd812016-02-02 17:17:23 -070010021TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010022 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10024 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010025
10026 ASSERT_NO_FATAL_FAILURE(InitState());
10027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010028
Tony Barbourfe3351b2015-07-28 10:17:20 -060010029 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -070010030 // Don't care about RenderPass handle b/c error should be flagged before
10031 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010032 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010033
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010034 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -060010035}
10036
Karl Schultz6addd812016-02-02 17:17:23 -070010037TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010038 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10040 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010041
10042 ASSERT_NO_FATAL_FAILURE(InitState());
10043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010044
Tony Barbourfe3351b2015-07-28 10:17:20 -060010045 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -070010046 // Just create a dummy Renderpass that's non-NULL so we can get to the
10047 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010048 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -060010049
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010050 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010051}
10052
Chris Forbes2eeabe32016-06-21 20:52:34 +120010053TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
10054 m_errorMonitor->ExpectSuccess();
10055
10056 ASSERT_NO_FATAL_FAILURE(InitState());
10057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 BeginCommandBuffer(); // framework implicitly begins the renderpass.
Chris Forbes2eeabe32016-06-21 20:52:34 +120010060 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit.
10061
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010062 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Chris Forbes2eeabe32016-06-21 20:52:34 +120010063 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10064 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010065 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Chris Forbes2eeabe32016-06-21 20:52:34 +120010066 m_errorMonitor->VerifyNotFound();
10067 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10068 m_errorMonitor->VerifyNotFound();
10069
10070 m_commandBuffer->EndCommandBuffer();
10071 m_errorMonitor->VerifyNotFound();
10072}
10073
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010074TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
10075 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
10076 "the number of renderPass attachments that use loadOp"
10077 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
10078
10079 ASSERT_NO_FATAL_FAILURE(InitState());
10080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10081
10082 // Create a renderPass with a single attachment that uses loadOp CLEAR
10083 VkAttachmentReference attach = {};
10084 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10085 VkSubpassDescription subpass = {};
10086 subpass.inputAttachmentCount = 1;
10087 subpass.pInputAttachments = &attach;
10088 VkRenderPassCreateInfo rpci = {};
10089 rpci.subpassCount = 1;
10090 rpci.pSubpasses = &subpass;
10091 rpci.attachmentCount = 1;
10092 VkAttachmentDescription attach_desc = {};
10093 attach_desc.format = VK_FORMAT_UNDEFINED;
10094 // Set loadOp to CLEAR
10095 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10096 rpci.pAttachments = &attach_desc;
10097 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10098 VkRenderPass rp;
10099 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10100
10101 VkCommandBufferInheritanceInfo hinfo = {};
10102 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10103 hinfo.renderPass = VK_NULL_HANDLE;
10104 hinfo.subpass = 0;
10105 hinfo.framebuffer = VK_NULL_HANDLE;
10106 hinfo.occlusionQueryEnable = VK_FALSE;
10107 hinfo.queryFlags = 0;
10108 hinfo.pipelineStatistics = 0;
10109 VkCommandBufferBeginInfo info = {};
10110 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
10111 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10112 info.pInheritanceInfo = &hinfo;
10113
10114 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
10115 VkRenderPassBeginInfo rp_begin = {};
10116 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10117 rp_begin.pNext = NULL;
10118 rp_begin.renderPass = renderPass();
10119 rp_begin.framebuffer = framebuffer();
10120 rp_begin.clearValueCount = 0; // Should be 1
10121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
10123 "there must be at least 1 entries in "
10124 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010127
10128 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -060010129
10130 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -060010131}
10132
Cody Northrop3bb4d962016-05-09 16:15:57 -060010133TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
10134
10135 TEST_DESCRIPTION("End a command buffer with an active render pass");
10136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10138 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -060010139
10140 ASSERT_NO_FATAL_FAILURE(InitState());
10141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10142
10143 // The framework's BeginCommandBuffer calls CreateRenderPass
10144 BeginCommandBuffer();
10145
10146 // Call directly into vkEndCommandBuffer instead of the
10147 // the framework's EndCommandBuffer, which inserts a
10148 // vkEndRenderPass
10149 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
10150
10151 m_errorMonitor->VerifyFound();
10152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
10154 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -060010155}
10156
Karl Schultz6addd812016-02-02 17:17:23 -070010157TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010158 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10160 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010161
10162 ASSERT_NO_FATAL_FAILURE(InitState());
10163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010164
10165 // Renderpass is started here
10166 BeginCommandBuffer();
10167
10168 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010169 vk_testing::Buffer dstBuffer;
10170 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010171
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010172 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010173
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010174 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010175}
10176
Karl Schultz6addd812016-02-02 17:17:23 -070010177TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010178 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10180 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010181
10182 ASSERT_NO_FATAL_FAILURE(InitState());
10183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010184
10185 // Renderpass is started here
10186 BeginCommandBuffer();
10187
10188 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010189 vk_testing::Buffer dstBuffer;
10190 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010191
Karl Schultz6addd812016-02-02 17:17:23 -070010192 VkDeviceSize dstOffset = 0;
10193 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -060010194 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010196 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010197
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010198 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010199}
10200
Karl Schultz6addd812016-02-02 17:17:23 -070010201TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010202 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10204 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010205
10206 ASSERT_NO_FATAL_FAILURE(InitState());
10207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010208
10209 // Renderpass is started here
10210 BeginCommandBuffer();
10211
Michael Lentine0a369f62016-02-03 16:51:46 -060010212 VkClearColorValue clear_color;
10213 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -070010214 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
10215 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10216 const int32_t tex_width = 32;
10217 const int32_t tex_height = 32;
10218 VkImageCreateInfo image_create_info = {};
10219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10220 image_create_info.pNext = NULL;
10221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10222 image_create_info.format = tex_format;
10223 image_create_info.extent.width = tex_width;
10224 image_create_info.extent.height = tex_height;
10225 image_create_info.extent.depth = 1;
10226 image_create_info.mipLevels = 1;
10227 image_create_info.arrayLayers = 1;
10228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10229 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10230 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010231
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010232 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010238
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010239 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010240}
10241
Karl Schultz6addd812016-02-02 17:17:23 -070010242TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010243 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10245 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010246
10247 ASSERT_NO_FATAL_FAILURE(InitState());
10248 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010249
10250 // Renderpass is started here
10251 BeginCommandBuffer();
10252
10253 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -070010254 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010255 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
10256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10257 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10258 image_create_info.extent.width = 64;
10259 image_create_info.extent.height = 64;
10260 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10261 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010262
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010263 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010264 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010268 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
10269 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010270
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010271 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010272}
10273
Karl Schultz6addd812016-02-02 17:17:23 -070010274TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010275 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010276 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
10279 "must be issued inside an active "
10280 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010281
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010282 ASSERT_NO_FATAL_FAILURE(InitState());
10283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010284
10285 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010286 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010287 ASSERT_VK_SUCCESS(err);
10288
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010289 VkClearAttachment color_attachment;
10290 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10291 color_attachment.clearValue.color.float32[0] = 0;
10292 color_attachment.clearValue.color.float32[1] = 0;
10293 color_attachment.clearValue.color.float32[2] = 0;
10294 color_attachment.clearValue.color.float32[3] = 0;
10295 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -070010296 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010298
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010299 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -060010300}
10301
Chris Forbes3b97e932016-09-07 11:29:24 +120010302TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
10303 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
10304 "called too many times in a renderpass instance");
10305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
10307 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +120010308
10309 ASSERT_NO_FATAL_FAILURE(InitState());
10310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10311
10312 BeginCommandBuffer();
10313
10314 // error here.
10315 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
10316 m_errorMonitor->VerifyFound();
10317
10318 EndCommandBuffer();
10319}
10320
Chris Forbes6d624702016-09-07 13:57:05 +120010321TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
10322 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
10323 "called before the final subpass has been reached");
10324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
10326 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +120010327
10328 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
10330 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +120010331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010332 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010333
10334 VkRenderPass rp;
10335 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
10336 ASSERT_VK_SUCCESS(err);
10337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010338 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +120010339
10340 VkFramebuffer fb;
10341 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
10342 ASSERT_VK_SUCCESS(err);
10343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010344 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +120010345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {16, 16}}, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +120010347
10348 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10349
10350 // Error here.
10351 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10352 m_errorMonitor->VerifyFound();
10353
10354 // Clean up.
10355 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
10356 vkDestroyRenderPass(m_device->device(), rp, nullptr);
10357}
10358
Karl Schultz9e66a292016-04-21 15:57:51 -060010359TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
10360 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10362 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -060010363
10364 ASSERT_NO_FATAL_FAILURE(InitState());
10365 BeginCommandBuffer();
10366
10367 VkBufferMemoryBarrier buf_barrier = {};
10368 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10369 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10370 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10371 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10372 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10373 buf_barrier.buffer = VK_NULL_HANDLE;
10374 buf_barrier.offset = 0;
10375 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010376 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10377 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -060010378
10379 m_errorMonitor->VerifyFound();
10380}
10381
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010382TEST_F(VkLayerTest, InvalidBarriers) {
10383 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
10384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010386
10387 ASSERT_NO_FATAL_FAILURE(InitState());
10388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10389
10390 VkMemoryBarrier mem_barrier = {};
10391 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
10392 mem_barrier.pNext = NULL;
10393 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10394 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10395 BeginCommandBuffer();
10396 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010398 &mem_barrier, 0, nullptr, 0, nullptr);
10399 m_errorMonitor->VerifyFound();
10400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010402 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010404 ASSERT_TRUE(image.initialized());
10405 VkImageMemoryBarrier img_barrier = {};
10406 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10407 img_barrier.pNext = NULL;
10408 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10409 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10410 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10411 // New layout can't be UNDEFINED
10412 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10413 img_barrier.image = image.handle();
10414 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10415 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10416 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10417 img_barrier.subresourceRange.baseArrayLayer = 0;
10418 img_barrier.subresourceRange.baseMipLevel = 0;
10419 img_barrier.subresourceRange.layerCount = 1;
10420 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010421 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10422 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010423 m_errorMonitor->VerifyFound();
10424 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
10427 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010428 // baseArrayLayer + layerCount must be <= image's arrayLayers
10429 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10431 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010432 m_errorMonitor->VerifyFound();
10433 img_barrier.subresourceRange.baseArrayLayer = 0;
10434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010436 // baseMipLevel + levelCount must be <= image's mipLevels
10437 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10439 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010440 m_errorMonitor->VerifyFound();
10441 img_barrier.subresourceRange.baseMipLevel = 0;
10442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer Barriers cannot be used during a render pass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010444 vk_testing::Buffer buffer;
10445 buffer.init(*m_device, 256);
10446 VkBufferMemoryBarrier buf_barrier = {};
10447 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
10448 buf_barrier.pNext = NULL;
10449 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10450 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10451 buf_barrier.buffer = buffer.handle();
10452 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10453 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10454 buf_barrier.offset = 0;
10455 buf_barrier.size = VK_WHOLE_SIZE;
10456 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10458 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010459 m_errorMonitor->VerifyFound();
10460 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010463 buf_barrier.offset = 257;
10464 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10466 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010467 m_errorMonitor->VerifyFound();
10468 buf_barrier.offset = 0;
10469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010471 buf_barrier.size = 257;
10472 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010473 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10474 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010475 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010476
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010477 // Now exercise barrier aspect bit errors, first DS
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
10479 "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
10480 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010481 VkDepthStencilObj ds_image(m_device);
10482 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
10483 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -060010484 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
10485 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010486 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010487 // Use of COLOR aspect on DS image is error
10488 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10490 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010491 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010492 // Now test depth-only
10493 VkFormatProperties format_props;
10494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010495 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
10496 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
10497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
10498 "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010499 VkDepthStencilObj d_image(m_device);
10500 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
10501 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010503 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010504 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010505 // Use of COLOR aspect on depth image is error
10506 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10508 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010509 m_errorMonitor->VerifyFound();
10510 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
10512 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010513 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
10515 "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010516 VkDepthStencilObj s_image(m_device);
10517 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
10518 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010519 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -060010520 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010521 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -060010522 // Use of COLOR aspect on depth image is error
10523 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
10525 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010526 m_errorMonitor->VerifyFound();
10527 }
10528 // Finally test color
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
10530 "have VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010531 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010533 ASSERT_TRUE(c_image.initialized());
10534 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10535 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
10536 img_barrier.image = c_image.handle();
10537 // Set aspect to depth (non-color)
10538 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010539 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
10540 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -060010541 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010542}
10543
Karl Schultz6addd812016-02-02 17:17:23 -070010544TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010545 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -070010546 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010549
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010550 ASSERT_NO_FATAL_FAILURE(InitState());
10551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010552 uint32_t qfi = 0;
10553 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010554 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10555 buffCI.size = 1024;
10556 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10557 buffCI.queueFamilyIndexCount = 1;
10558 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010559
10560 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010561 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010562 ASSERT_VK_SUCCESS(err);
10563
10564 BeginCommandBuffer();
10565 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -070010566 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10567 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010568 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010571 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010572
Chia-I Wuf7458c52015-10-26 21:10:41 +080010573 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010574}
10575
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010576TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10577 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10579 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
10580 "of the indices specified when the device was created, via the "
10581 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010582
10583 ASSERT_NO_FATAL_FAILURE(InitState());
10584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10585 VkBufferCreateInfo buffCI = {};
10586 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10587 buffCI.size = 1024;
10588 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10589 buffCI.queueFamilyIndexCount = 1;
10590 // Introduce failure by specifying invalid queue_family_index
10591 uint32_t qfi = 777;
10592 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -060010593 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010594
10595 VkBuffer ib;
10596 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
10597
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010598 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010599 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010600}
10601
Karl Schultz6addd812016-02-02 17:17:23 -070010602TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010603 TEST_DESCRIPTION("Attempt vkCmdExecuteCommands w/ a primary cmd buffer"
10604 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010607
10608 ASSERT_NO_FATAL_FAILURE(InitState());
10609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010610
10611 BeginCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010612
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010613 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
10614 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010615
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010616 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010617}
10618
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010619TEST_F(VkLayerTest, DSUsageBitsErrors) {
10620 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
10621 "that do not have correct usage bits sets.");
10622 VkResult err;
10623
10624 ASSERT_NO_FATAL_FAILURE(InitState());
10625 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10626 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10627 ds_type_count[i].type = VkDescriptorType(i);
10628 ds_type_count[i].descriptorCount = 1;
10629 }
10630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10632 ds_pool_ci.pNext = NULL;
10633 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10634 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10635 ds_pool_ci.pPoolSizes = ds_type_count;
10636
10637 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010639 ASSERT_VK_SUCCESS(err);
10640
10641 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010643 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10644 dsl_binding[i].binding = 0;
10645 dsl_binding[i].descriptorType = VkDescriptorType(i);
10646 dsl_binding[i].descriptorCount = 1;
10647 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10648 dsl_binding[i].pImmutableSamplers = NULL;
10649 }
10650
10651 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10652 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10653 ds_layout_ci.pNext = NULL;
10654 ds_layout_ci.bindingCount = 1;
10655 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10656 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10657 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010659 ASSERT_VK_SUCCESS(err);
10660 }
10661 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10662 VkDescriptorSetAllocateInfo alloc_info = {};
10663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10664 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10665 alloc_info.descriptorPool = ds_pool;
10666 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010668 ASSERT_VK_SUCCESS(err);
10669
10670 // Create a buffer & bufferView to be used for invalid updates
10671 VkBufferCreateInfo buff_ci = {};
10672 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10673 // This usage is not valid for any descriptor type
10674 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
10675 buff_ci.size = 256;
10676 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10677 VkBuffer buffer;
10678 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10679 ASSERT_VK_SUCCESS(err);
10680
10681 VkBufferViewCreateInfo buff_view_ci = {};
10682 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10683 buff_view_ci.buffer = buffer;
10684 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10685 buff_view_ci.range = VK_WHOLE_SIZE;
10686 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010688 ASSERT_VK_SUCCESS(err);
10689
10690 // Create an image to be used for invalid updates
10691 VkImageCreateInfo image_ci = {};
10692 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10693 image_ci.imageType = VK_IMAGE_TYPE_2D;
10694 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10695 image_ci.extent.width = 64;
10696 image_ci.extent.height = 64;
10697 image_ci.extent.depth = 1;
10698 image_ci.mipLevels = 1;
10699 image_ci.arrayLayers = 1;
10700 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10701 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10702 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10703 // This usage is not valid for any descriptor type
10704 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10705 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10706 VkImage image;
10707 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10708 ASSERT_VK_SUCCESS(err);
10709 // Bind memory to image
10710 VkMemoryRequirements mem_reqs;
10711 VkDeviceMemory image_mem;
10712 bool pass;
10713 VkMemoryAllocateInfo mem_alloc = {};
10714 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10715 mem_alloc.pNext = NULL;
10716 mem_alloc.allocationSize = 0;
10717 mem_alloc.memoryTypeIndex = 0;
10718 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10719 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010721 ASSERT_TRUE(pass);
10722 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10723 ASSERT_VK_SUCCESS(err);
10724 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10725 ASSERT_VK_SUCCESS(err);
10726 // Now create view for image
10727 VkImageViewCreateInfo image_view_ci = {};
10728 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10729 image_view_ci.image = image;
10730 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
10731 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10732 image_view_ci.subresourceRange.layerCount = 1;
10733 image_view_ci.subresourceRange.baseArrayLayer = 0;
10734 image_view_ci.subresourceRange.levelCount = 1;
10735 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10736 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010737 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010738 ASSERT_VK_SUCCESS(err);
10739
10740 VkDescriptorBufferInfo buff_info = {};
10741 buff_info.buffer = buffer;
10742 VkDescriptorImageInfo img_info = {};
10743 img_info.imageView = image_view;
10744 VkWriteDescriptorSet descriptor_write = {};
10745 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10746 descriptor_write.dstBinding = 0;
10747 descriptor_write.descriptorCount = 1;
10748 descriptor_write.pTexelBufferView = &buff_view;
10749 descriptor_write.pBufferInfo = &buff_info;
10750 descriptor_write.pImageInfo = &img_info;
10751
10752 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010753 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
10754 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10755 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
10756 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
10757 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
10758 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
10759 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10760 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10761 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
10762 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
10763 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010764 // Start loop at 1 as SAMPLER desc type has no usage bit error
10765 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10766 descriptor_write.descriptorType = VkDescriptorType(i);
10767 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010770 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010771
10772 m_errorMonitor->VerifyFound();
10773 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
10774 }
10775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10776 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010777 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010778 vkDestroyImageView(m_device->device(), image_view, NULL);
10779 vkDestroyBuffer(m_device->device(), buffer, NULL);
10780 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010782 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10783}
10784
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010785TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010786 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
10787 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
10788 "1. offset value greater than buffer size\n"
10789 "2. range value of 0\n"
10790 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010791 VkResult err;
10792
10793 ASSERT_NO_FATAL_FAILURE(InitState());
10794 VkDescriptorPoolSize ds_type_count = {};
10795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10796 ds_type_count.descriptorCount = 1;
10797
10798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10800 ds_pool_ci.pNext = NULL;
10801 ds_pool_ci.maxSets = 1;
10802 ds_pool_ci.poolSizeCount = 1;
10803 ds_pool_ci.pPoolSizes = &ds_type_count;
10804
10805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010807 ASSERT_VK_SUCCESS(err);
10808
10809 // Create layout with single uniform buffer descriptor
10810 VkDescriptorSetLayoutBinding dsl_binding = {};
10811 dsl_binding.binding = 0;
10812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10813 dsl_binding.descriptorCount = 1;
10814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10815 dsl_binding.pImmutableSamplers = NULL;
10816
10817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10819 ds_layout_ci.pNext = NULL;
10820 ds_layout_ci.bindingCount = 1;
10821 ds_layout_ci.pBindings = &dsl_binding;
10822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010824 ASSERT_VK_SUCCESS(err);
10825
10826 VkDescriptorSet descriptor_set = {};
10827 VkDescriptorSetAllocateInfo alloc_info = {};
10828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10829 alloc_info.descriptorSetCount = 1;
10830 alloc_info.descriptorPool = ds_pool;
10831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010833 ASSERT_VK_SUCCESS(err);
10834
10835 // Create a buffer to be used for invalid updates
10836 VkBufferCreateInfo buff_ci = {};
10837 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10838 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10839 buff_ci.size = 256;
10840 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10841 VkBuffer buffer;
10842 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10843 ASSERT_VK_SUCCESS(err);
10844 // Have to bind memory to buffer before descriptor update
10845 VkMemoryAllocateInfo mem_alloc = {};
10846 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10847 mem_alloc.pNext = NULL;
10848 mem_alloc.allocationSize = 256;
10849 mem_alloc.memoryTypeIndex = 0;
10850
10851 VkMemoryRequirements mem_reqs;
10852 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010853 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010854 if (!pass) {
10855 vkDestroyBuffer(m_device->device(), buffer, NULL);
10856 return;
10857 }
10858
10859 VkDeviceMemory mem;
10860 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10861 ASSERT_VK_SUCCESS(err);
10862 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10863 ASSERT_VK_SUCCESS(err);
10864
10865 VkDescriptorBufferInfo buff_info = {};
10866 buff_info.buffer = buffer;
10867 // First make offset 1 larger than buffer size
10868 buff_info.offset = 257;
10869 buff_info.range = VK_WHOLE_SIZE;
10870 VkWriteDescriptorSet descriptor_write = {};
10871 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10872 descriptor_write.dstBinding = 0;
10873 descriptor_write.descriptorCount = 1;
10874 descriptor_write.pTexelBufferView = nullptr;
10875 descriptor_write.pBufferInfo = &buff_info;
10876 descriptor_write.pImageInfo = nullptr;
10877
10878 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10879 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010881
10882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10883
10884 m_errorMonitor->VerifyFound();
10885 // Now cause error due to range of 0
10886 buff_info.offset = 0;
10887 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10889 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010890
10891 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10892
10893 m_errorMonitor->VerifyFound();
10894 // Now cause error due to range exceeding buffer size - offset
10895 buff_info.offset = 128;
10896 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " range is 200 which is greater than buffer size ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010898
10899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10900
10901 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010902 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010903 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10904 vkDestroyBuffer(m_device->device(), buffer, NULL);
10905 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10906 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10907}
10908
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010909TEST_F(VkLayerTest, DSAspectBitsErrors) {
10910 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10911 // are set, but could expand this test to hit more cases.
10912 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
10913 "that do not have correct aspect bits sets.");
10914 VkResult err;
10915
10916 ASSERT_NO_FATAL_FAILURE(InitState());
10917 VkDescriptorPoolSize ds_type_count = {};
10918 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10919 ds_type_count.descriptorCount = 1;
10920
10921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10923 ds_pool_ci.pNext = NULL;
10924 ds_pool_ci.maxSets = 5;
10925 ds_pool_ci.poolSizeCount = 1;
10926 ds_pool_ci.pPoolSizes = &ds_type_count;
10927
10928 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010929 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010930 ASSERT_VK_SUCCESS(err);
10931
10932 VkDescriptorSetLayoutBinding dsl_binding = {};
10933 dsl_binding.binding = 0;
10934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10935 dsl_binding.descriptorCount = 1;
10936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10937 dsl_binding.pImmutableSamplers = NULL;
10938
10939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10941 ds_layout_ci.pNext = NULL;
10942 ds_layout_ci.bindingCount = 1;
10943 ds_layout_ci.pBindings = &dsl_binding;
10944 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010946 ASSERT_VK_SUCCESS(err);
10947
10948 VkDescriptorSet descriptor_set = {};
10949 VkDescriptorSetAllocateInfo alloc_info = {};
10950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10951 alloc_info.descriptorSetCount = 1;
10952 alloc_info.descriptorPool = ds_pool;
10953 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010955 ASSERT_VK_SUCCESS(err);
10956
10957 // Create an image to be used for invalid updates
10958 VkImageCreateInfo image_ci = {};
10959 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10960 image_ci.imageType = VK_IMAGE_TYPE_2D;
10961 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10962 image_ci.extent.width = 64;
10963 image_ci.extent.height = 64;
10964 image_ci.extent.depth = 1;
10965 image_ci.mipLevels = 1;
10966 image_ci.arrayLayers = 1;
10967 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
10968 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10969 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10970 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10971 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10972 VkImage image;
10973 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10974 ASSERT_VK_SUCCESS(err);
10975 // Bind memory to image
10976 VkMemoryRequirements mem_reqs;
10977 VkDeviceMemory image_mem;
10978 bool pass;
10979 VkMemoryAllocateInfo mem_alloc = {};
10980 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10981 mem_alloc.pNext = NULL;
10982 mem_alloc.allocationSize = 0;
10983 mem_alloc.memoryTypeIndex = 0;
10984 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10985 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010986 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010987 ASSERT_TRUE(pass);
10988 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10989 ASSERT_VK_SUCCESS(err);
10990 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10991 ASSERT_VK_SUCCESS(err);
10992 // Now create view for image
10993 VkImageViewCreateInfo image_view_ci = {};
10994 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10995 image_view_ci.image = image;
10996 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
10997 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10998 image_view_ci.subresourceRange.layerCount = 1;
10999 image_view_ci.subresourceRange.baseArrayLayer = 0;
11000 image_view_ci.subresourceRange.levelCount = 1;
11001 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011002 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011003
11004 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011005 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011006 ASSERT_VK_SUCCESS(err);
11007
11008 VkDescriptorImageInfo img_info = {};
11009 img_info.imageView = image_view;
11010 VkWriteDescriptorSet descriptor_write = {};
11011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11012 descriptor_write.dstBinding = 0;
11013 descriptor_write.descriptorCount = 1;
11014 descriptor_write.pTexelBufferView = NULL;
11015 descriptor_write.pBufferInfo = NULL;
11016 descriptor_write.pImageInfo = &img_info;
11017 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
11018 descriptor_write.dstSet = descriptor_set;
11019 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
11020 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060011022
11023 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11024
11025 m_errorMonitor->VerifyFound();
11026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11027 vkDestroyImage(m_device->device(), image, NULL);
11028 vkFreeMemory(m_device->device(), image_mem, NULL);
11029 vkDestroyImageView(m_device->device(), image_view, NULL);
11030 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11031 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11032}
11033
Karl Schultz6addd812016-02-02 17:17:23 -070011034TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011035 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070011036 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11039 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
11040 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011041
Tobin Ehlis3b780662015-05-28 12:11:26 -060011042 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011043 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011044 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011045 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11046 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011047
11048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11050 ds_pool_ci.pNext = NULL;
11051 ds_pool_ci.maxSets = 1;
11052 ds_pool_ci.poolSizeCount = 1;
11053 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011054
Tobin Ehlis3b780662015-05-28 12:11:26 -060011055 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011056 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011057 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011058 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011059 dsl_binding.binding = 0;
11060 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11061 dsl_binding.descriptorCount = 1;
11062 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11063 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011064
Tony Barboureb254902015-07-15 12:50:33 -060011065 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011066 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11067 ds_layout_ci.pNext = NULL;
11068 ds_layout_ci.bindingCount = 1;
11069 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011070
Tobin Ehlis3b780662015-05-28 12:11:26 -060011071 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011073 ASSERT_VK_SUCCESS(err);
11074
11075 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011076 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011077 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011078 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011079 alloc_info.descriptorPool = ds_pool;
11080 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011081 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011082 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011083
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011084 VkSamplerCreateInfo sampler_ci = {};
11085 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11086 sampler_ci.pNext = NULL;
11087 sampler_ci.magFilter = VK_FILTER_NEAREST;
11088 sampler_ci.minFilter = VK_FILTER_NEAREST;
11089 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11090 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11091 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11092 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11093 sampler_ci.mipLodBias = 1.0;
11094 sampler_ci.anisotropyEnable = VK_FALSE;
11095 sampler_ci.maxAnisotropy = 1;
11096 sampler_ci.compareEnable = VK_FALSE;
11097 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11098 sampler_ci.minLod = 1.0;
11099 sampler_ci.maxLod = 1.0;
11100 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11101 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11102 VkSampler sampler;
11103 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11104 ASSERT_VK_SUCCESS(err);
11105
11106 VkDescriptorImageInfo info = {};
11107 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011108
11109 VkWriteDescriptorSet descriptor_write;
11110 memset(&descriptor_write, 0, sizeof(descriptor_write));
11111 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011112 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011113 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011114 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011115 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011116 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011117
11118 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11119
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011120 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011121
Chia-I Wuf7458c52015-10-26 21:10:41 +080011122 vkDestroySampler(m_device->device(), sampler, NULL);
11123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011125}
11126
Karl Schultz6addd812016-02-02 17:17:23 -070011127TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011128 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070011129 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11132 " binding #0 with 1 total descriptors but update of 1 descriptors "
11133 "starting at binding offset of 0 combined with update array element "
11134 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011135
Tobin Ehlis3b780662015-05-28 12:11:26 -060011136 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011137 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011138 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11140 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011141
11142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11144 ds_pool_ci.pNext = NULL;
11145 ds_pool_ci.maxSets = 1;
11146 ds_pool_ci.poolSizeCount = 1;
11147 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011148
Tobin Ehlis3b780662015-05-28 12:11:26 -060011149 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011151 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011152
Tony Barboureb254902015-07-15 12:50:33 -060011153 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011154 dsl_binding.binding = 0;
11155 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11156 dsl_binding.descriptorCount = 1;
11157 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11158 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011159
11160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11162 ds_layout_ci.pNext = NULL;
11163 ds_layout_ci.bindingCount = 1;
11164 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011165
Tobin Ehlis3b780662015-05-28 12:11:26 -060011166 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011168 ASSERT_VK_SUCCESS(err);
11169
11170 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011171 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011173 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011174 alloc_info.descriptorPool = ds_pool;
11175 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011177 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011178
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011179 // Correctly update descriptor to avoid "NOT_UPDATED" error
11180 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060011182 buff_info.offset = 0;
11183 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011184
11185 VkWriteDescriptorSet descriptor_write;
11186 memset(&descriptor_write, 0, sizeof(descriptor_write));
11187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011188 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011190 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11192 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011193
11194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11195
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011196 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011197
Chia-I Wuf7458c52015-10-26 21:10:41 +080011198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011200}
11201
Karl Schultz6addd812016-02-02 17:17:23 -070011202TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
11203 // Create layout w/ count of 1 and attempt update to that layout w/ binding
11204 // index 2
11205 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011208
Tobin Ehlis3b780662015-05-28 12:11:26 -060011209 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011210 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011211 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011212 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11213 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011214
11215 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011216 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11217 ds_pool_ci.pNext = NULL;
11218 ds_pool_ci.maxSets = 1;
11219 ds_pool_ci.poolSizeCount = 1;
11220 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011221
Tobin Ehlis3b780662015-05-28 12:11:26 -060011222 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011223 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011224 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011225
Tony Barboureb254902015-07-15 12:50:33 -060011226 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011227 dsl_binding.binding = 0;
11228 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11229 dsl_binding.descriptorCount = 1;
11230 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11231 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011232
11233 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011234 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11235 ds_layout_ci.pNext = NULL;
11236 ds_layout_ci.bindingCount = 1;
11237 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011238 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011240 ASSERT_VK_SUCCESS(err);
11241
11242 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011243 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011245 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011246 alloc_info.descriptorPool = ds_pool;
11247 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011250
Tony Barboureb254902015-07-15 12:50:33 -060011251 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011252 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11253 sampler_ci.pNext = NULL;
11254 sampler_ci.magFilter = VK_FILTER_NEAREST;
11255 sampler_ci.minFilter = VK_FILTER_NEAREST;
11256 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11257 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11258 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11259 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11260 sampler_ci.mipLodBias = 1.0;
11261 sampler_ci.anisotropyEnable = VK_FALSE;
11262 sampler_ci.maxAnisotropy = 1;
11263 sampler_ci.compareEnable = VK_FALSE;
11264 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11265 sampler_ci.minLod = 1.0;
11266 sampler_ci.maxLod = 1.0;
11267 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11268 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011269
Tobin Ehlis3b780662015-05-28 12:11:26 -060011270 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011271 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011272 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011273
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011274 VkDescriptorImageInfo info = {};
11275 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011276
11277 VkWriteDescriptorSet descriptor_write;
11278 memset(&descriptor_write, 0, sizeof(descriptor_write));
11279 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011280 descriptor_write.dstSet = descriptorSet;
11281 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011282 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011283 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011285 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011286
11287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011289 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011290
Chia-I Wuf7458c52015-10-26 21:10:41 +080011291 vkDestroySampler(m_device->device(), sampler, NULL);
11292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011294}
11295
Karl Schultz6addd812016-02-02 17:17:23 -070011296TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11297 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11298 // types
11299 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011302
Tobin Ehlis3b780662015-05-28 12:11:26 -060011303 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011304
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011305 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11307 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011308
11309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11311 ds_pool_ci.pNext = NULL;
11312 ds_pool_ci.maxSets = 1;
11313 ds_pool_ci.poolSizeCount = 1;
11314 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011315
Tobin Ehlis3b780662015-05-28 12:11:26 -060011316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011318 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011319 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011320 dsl_binding.binding = 0;
11321 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11322 dsl_binding.descriptorCount = 1;
11323 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11324 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011325
Tony Barboureb254902015-07-15 12:50:33 -060011326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11328 ds_layout_ci.pNext = NULL;
11329 ds_layout_ci.bindingCount = 1;
11330 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011331
Tobin Ehlis3b780662015-05-28 12:11:26 -060011332 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011334 ASSERT_VK_SUCCESS(err);
11335
11336 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011337 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011339 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011340 alloc_info.descriptorPool = ds_pool;
11341 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011342 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011343 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011344
Tony Barboureb254902015-07-15 12:50:33 -060011345 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011346 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11347 sampler_ci.pNext = NULL;
11348 sampler_ci.magFilter = VK_FILTER_NEAREST;
11349 sampler_ci.minFilter = VK_FILTER_NEAREST;
11350 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11351 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11352 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11353 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11354 sampler_ci.mipLodBias = 1.0;
11355 sampler_ci.anisotropyEnable = VK_FALSE;
11356 sampler_ci.maxAnisotropy = 1;
11357 sampler_ci.compareEnable = VK_FALSE;
11358 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11359 sampler_ci.minLod = 1.0;
11360 sampler_ci.maxLod = 1.0;
11361 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11362 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011363 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011364 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011365 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011366
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011367 VkDescriptorImageInfo info = {};
11368 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011369
11370 VkWriteDescriptorSet descriptor_write;
11371 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011372 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011373 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011374 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011375 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011376 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011377 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011378
11379 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011381 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011382
Chia-I Wuf7458c52015-10-26 21:10:41 +080011383 vkDestroySampler(m_device->device(), sampler, NULL);
11384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011386}
11387
Karl Schultz6addd812016-02-02 17:17:23 -070011388TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011389 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011390 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11393 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011394
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011395 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011396 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11397 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011398 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011399 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11400 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011401
11402 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011403 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11404 ds_pool_ci.pNext = NULL;
11405 ds_pool_ci.maxSets = 1;
11406 ds_pool_ci.poolSizeCount = 1;
11407 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011408
11409 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011410 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011411 ASSERT_VK_SUCCESS(err);
11412
11413 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011414 dsl_binding.binding = 0;
11415 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11416 dsl_binding.descriptorCount = 1;
11417 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11418 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011419
11420 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011421 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11422 ds_layout_ci.pNext = NULL;
11423 ds_layout_ci.bindingCount = 1;
11424 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011425 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011426 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011427 ASSERT_VK_SUCCESS(err);
11428
11429 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011430 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011432 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011433 alloc_info.descriptorPool = ds_pool;
11434 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011435 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011436 ASSERT_VK_SUCCESS(err);
11437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011439
11440 VkDescriptorImageInfo descriptor_info;
11441 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11442 descriptor_info.sampler = sampler;
11443
11444 VkWriteDescriptorSet descriptor_write;
11445 memset(&descriptor_write, 0, sizeof(descriptor_write));
11446 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011447 descriptor_write.dstSet = descriptorSet;
11448 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011449 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011450 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11451 descriptor_write.pImageInfo = &descriptor_info;
11452
11453 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11454
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011455 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011456
Chia-I Wuf7458c52015-10-26 21:10:41 +080011457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011459}
11460
Karl Schultz6addd812016-02-02 17:17:23 -070011461TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11462 // Create a single combined Image/Sampler descriptor and send it an invalid
11463 // imageView
11464 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
11467 "image sampler descriptor failed due "
11468 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011469
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011470 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011472 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11473 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011474
11475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11477 ds_pool_ci.pNext = NULL;
11478 ds_pool_ci.maxSets = 1;
11479 ds_pool_ci.poolSizeCount = 1;
11480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011481
11482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011484 ASSERT_VK_SUCCESS(err);
11485
11486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011487 dsl_binding.binding = 0;
11488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11489 dsl_binding.descriptorCount = 1;
11490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11491 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011492
11493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11495 ds_layout_ci.pNext = NULL;
11496 ds_layout_ci.bindingCount = 1;
11497 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011498 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011499 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011500 ASSERT_VK_SUCCESS(err);
11501
11502 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011503 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011504 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011505 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011506 alloc_info.descriptorPool = ds_pool;
11507 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011509 ASSERT_VK_SUCCESS(err);
11510
11511 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011512 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11513 sampler_ci.pNext = NULL;
11514 sampler_ci.magFilter = VK_FILTER_NEAREST;
11515 sampler_ci.minFilter = VK_FILTER_NEAREST;
11516 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11517 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11518 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11519 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11520 sampler_ci.mipLodBias = 1.0;
11521 sampler_ci.anisotropyEnable = VK_FALSE;
11522 sampler_ci.maxAnisotropy = 1;
11523 sampler_ci.compareEnable = VK_FALSE;
11524 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11525 sampler_ci.minLod = 1.0;
11526 sampler_ci.maxLod = 1.0;
11527 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11528 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011529
11530 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011531 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011532 ASSERT_VK_SUCCESS(err);
11533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011534 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011535
11536 VkDescriptorImageInfo descriptor_info;
11537 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11538 descriptor_info.sampler = sampler;
11539 descriptor_info.imageView = view;
11540
11541 VkWriteDescriptorSet descriptor_write;
11542 memset(&descriptor_write, 0, sizeof(descriptor_write));
11543 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011544 descriptor_write.dstSet = descriptorSet;
11545 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011546 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011547 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11548 descriptor_write.pImageInfo = &descriptor_info;
11549
11550 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11551
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011552 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011553
Chia-I Wuf7458c52015-10-26 21:10:41 +080011554 vkDestroySampler(m_device->device(), sampler, NULL);
11555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011557}
11558
Karl Schultz6addd812016-02-02 17:17:23 -070011559TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11560 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11561 // into the other
11562 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
11565 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11566 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011567
Tobin Ehlis04356f92015-10-27 16:35:27 -060011568 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070011569 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011570 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011571 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11572 ds_type_count[0].descriptorCount = 1;
11573 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11574 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011575
11576 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011577 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11578 ds_pool_ci.pNext = NULL;
11579 ds_pool_ci.maxSets = 1;
11580 ds_pool_ci.poolSizeCount = 2;
11581 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011582
11583 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011584 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011585 ASSERT_VK_SUCCESS(err);
11586 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011587 dsl_binding[0].binding = 0;
11588 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11589 dsl_binding[0].descriptorCount = 1;
11590 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11591 dsl_binding[0].pImmutableSamplers = NULL;
11592 dsl_binding[1].binding = 1;
11593 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11594 dsl_binding[1].descriptorCount = 1;
11595 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11596 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011597
11598 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011599 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11600 ds_layout_ci.pNext = NULL;
11601 ds_layout_ci.bindingCount = 2;
11602 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011603
11604 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011606 ASSERT_VK_SUCCESS(err);
11607
11608 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011609 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011611 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011612 alloc_info.descriptorPool = ds_pool;
11613 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011615 ASSERT_VK_SUCCESS(err);
11616
11617 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011618 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11619 sampler_ci.pNext = NULL;
11620 sampler_ci.magFilter = VK_FILTER_NEAREST;
11621 sampler_ci.minFilter = VK_FILTER_NEAREST;
11622 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11623 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11624 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11625 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11626 sampler_ci.mipLodBias = 1.0;
11627 sampler_ci.anisotropyEnable = VK_FALSE;
11628 sampler_ci.maxAnisotropy = 1;
11629 sampler_ci.compareEnable = VK_FALSE;
11630 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11631 sampler_ci.minLod = 1.0;
11632 sampler_ci.maxLod = 1.0;
11633 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11634 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011635
11636 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011637 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011638 ASSERT_VK_SUCCESS(err);
11639
11640 VkDescriptorImageInfo info = {};
11641 info.sampler = sampler;
11642
11643 VkWriteDescriptorSet descriptor_write;
11644 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11645 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011646 descriptor_write.dstSet = descriptorSet;
11647 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011648 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011649 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11650 descriptor_write.pImageInfo = &info;
11651 // This write update should succeed
11652 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11653 // Now perform a copy update that fails due to type mismatch
11654 VkCopyDescriptorSet copy_ds_update;
11655 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11656 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11657 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -060011658 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011659 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -070011660 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +080011661 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011662 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11663
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011664 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011665 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -060011667 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11668 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11669 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011670 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011671 copy_ds_update.dstSet = descriptorSet;
11672 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -060011673 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011674 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11675
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011676 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011677
Tobin Ehlis04356f92015-10-27 16:35:27 -060011678 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
11680 "update array offset of 0 and update of "
11681 "5 descriptors oversteps total number "
11682 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011683
Tobin Ehlis04356f92015-10-27 16:35:27 -060011684 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11685 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11686 copy_ds_update.srcSet = descriptorSet;
11687 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011688 copy_ds_update.dstSet = descriptorSet;
11689 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011690 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011691 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011693 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011694
Chia-I Wuf7458c52015-10-26 21:10:41 +080011695 vkDestroySampler(m_device->device(), sampler, NULL);
11696 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11697 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011698}
11699
Karl Schultz6addd812016-02-02 17:17:23 -070011700TEST_F(VkLayerTest, NumSamplesMismatch) {
11701 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11702 // sampleCount
11703 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011706
Tobin Ehlis3b780662015-05-28 12:11:26 -060011707 ASSERT_NO_FATAL_FAILURE(InitState());
11708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011709 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011711 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011712
11713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11715 ds_pool_ci.pNext = NULL;
11716 ds_pool_ci.maxSets = 1;
11717 ds_pool_ci.poolSizeCount = 1;
11718 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011719
Tobin Ehlis3b780662015-05-28 12:11:26 -060011720 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011721 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011722 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011723
Tony Barboureb254902015-07-15 12:50:33 -060011724 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011725 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011726 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011727 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011728 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11729 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011730
Tony Barboureb254902015-07-15 12:50:33 -060011731 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11732 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11733 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011734 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011735 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011736
Tobin Ehlis3b780662015-05-28 12:11:26 -060011737 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011739 ASSERT_VK_SUCCESS(err);
11740
11741 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011742 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011744 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011745 alloc_info.descriptorPool = ds_pool;
11746 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011748 ASSERT_VK_SUCCESS(err);
11749
Tony Barboureb254902015-07-15 12:50:33 -060011750 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011751 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011752 pipe_ms_state_ci.pNext = NULL;
11753 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11754 pipe_ms_state_ci.sampleShadingEnable = 0;
11755 pipe_ms_state_ci.minSampleShading = 1.0;
11756 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011757
Tony Barboureb254902015-07-15 12:50:33 -060011758 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011759 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11760 pipeline_layout_ci.pNext = NULL;
11761 pipeline_layout_ci.setLayoutCount = 1;
11762 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011763
11764 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011765 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011766 ASSERT_VK_SUCCESS(err);
11767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011768 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11769 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11770 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011771 VkPipelineObj pipe(m_device);
11772 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011773 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011774 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011775 pipe.SetMSAA(&pipe_ms_state_ci);
11776 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011777
Tony Barbourfe3351b2015-07-28 10:17:20 -060011778 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011779 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011780
Mark Young29927482016-05-04 14:38:51 -060011781 // Render triangle (the error should trigger on the attempt to draw).
11782 Draw(3, 1, 0, 0);
11783
11784 // Finalize recording of the command buffer
11785 EndCommandBuffer();
11786
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011787 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011788
Chia-I Wuf7458c52015-10-26 21:10:41 +080011789 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011792}
Mark Young29927482016-05-04 14:38:51 -060011793
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011794TEST_F(VkLayerTest, RenderPassIncompatible) {
11795 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
11796 "Initial case is drawing with an active renderpass that's "
11797 "not compatible with the bound PSO's creation renderpass");
11798 VkResult err;
11799
11800 ASSERT_NO_FATAL_FAILURE(InitState());
11801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11802
11803 VkDescriptorSetLayoutBinding dsl_binding = {};
11804 dsl_binding.binding = 0;
11805 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11806 dsl_binding.descriptorCount = 1;
11807 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11808 dsl_binding.pImmutableSamplers = NULL;
11809
11810 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11811 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11812 ds_layout_ci.pNext = NULL;
11813 ds_layout_ci.bindingCount = 1;
11814 ds_layout_ci.pBindings = &dsl_binding;
11815
11816 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011817 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011818 ASSERT_VK_SUCCESS(err);
11819
11820 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11821 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11822 pipeline_layout_ci.pNext = NULL;
11823 pipeline_layout_ci.setLayoutCount = 1;
11824 pipeline_layout_ci.pSetLayouts = &ds_layout;
11825
11826 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011827 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011828 ASSERT_VK_SUCCESS(err);
11829
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011830 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11831 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11832 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011833 // Create a renderpass that will be incompatible with default renderpass
11834 VkAttachmentReference attach = {};
11835 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11836 VkAttachmentReference color_att = {};
11837 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11838 VkSubpassDescription subpass = {};
11839 subpass.inputAttachmentCount = 1;
11840 subpass.pInputAttachments = &attach;
11841 subpass.colorAttachmentCount = 1;
11842 subpass.pColorAttachments = &color_att;
11843 VkRenderPassCreateInfo rpci = {};
11844 rpci.subpassCount = 1;
11845 rpci.pSubpasses = &subpass;
11846 rpci.attachmentCount = 1;
11847 VkAttachmentDescription attach_desc = {};
11848 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011849 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11850 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011851 rpci.pAttachments = &attach_desc;
11852 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11853 VkRenderPass rp;
11854 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11855 VkPipelineObj pipe(m_device);
11856 pipe.AddShader(&vs);
11857 pipe.AddShader(&fs);
11858 pipe.AddColorAttachment();
11859 VkViewport view_port = {};
11860 m_viewports.push_back(view_port);
11861 pipe.SetViewport(m_viewports);
11862 VkRect2D rect = {};
11863 m_scissors.push_back(rect);
11864 pipe.SetScissor(m_scissors);
11865 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11866
11867 VkCommandBufferInheritanceInfo cbii = {};
11868 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11869 cbii.renderPass = rp;
11870 cbii.subpass = 0;
11871 VkCommandBufferBeginInfo cbbi = {};
11872 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11873 cbbi.pInheritanceInfo = &cbii;
11874 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11875 VkRenderPassBeginInfo rpbi = {};
11876 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11877 rpbi.framebuffer = m_framebuffer;
11878 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11880 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011881
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011883 // Render triangle (the error should trigger on the attempt to draw).
11884 Draw(3, 1, 0, 0);
11885
11886 // Finalize recording of the command buffer
11887 EndCommandBuffer();
11888
11889 m_errorMonitor->VerifyFound();
11890
11891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11893 vkDestroyRenderPass(m_device->device(), rp, NULL);
11894}
11895
Mark Youngc89c6312016-03-31 16:03:20 -060011896TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11897 // Create Pipeline where the number of blend attachments doesn't match the
11898 // number of color attachments. In this case, we don't add any color
11899 // blend attachments even though we have a color attachment.
11900 VkResult err;
11901
11902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060011904
11905 ASSERT_NO_FATAL_FAILURE(InitState());
11906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11907 VkDescriptorPoolSize ds_type_count = {};
11908 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11909 ds_type_count.descriptorCount = 1;
11910
11911 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11912 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11913 ds_pool_ci.pNext = NULL;
11914 ds_pool_ci.maxSets = 1;
11915 ds_pool_ci.poolSizeCount = 1;
11916 ds_pool_ci.pPoolSizes = &ds_type_count;
11917
11918 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011919 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011920 ASSERT_VK_SUCCESS(err);
11921
11922 VkDescriptorSetLayoutBinding dsl_binding = {};
11923 dsl_binding.binding = 0;
11924 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11925 dsl_binding.descriptorCount = 1;
11926 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11927 dsl_binding.pImmutableSamplers = NULL;
11928
11929 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11930 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11931 ds_layout_ci.pNext = NULL;
11932 ds_layout_ci.bindingCount = 1;
11933 ds_layout_ci.pBindings = &dsl_binding;
11934
11935 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011937 ASSERT_VK_SUCCESS(err);
11938
11939 VkDescriptorSet descriptorSet;
11940 VkDescriptorSetAllocateInfo alloc_info = {};
11941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11942 alloc_info.descriptorSetCount = 1;
11943 alloc_info.descriptorPool = ds_pool;
11944 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011946 ASSERT_VK_SUCCESS(err);
11947
11948 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011949 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011950 pipe_ms_state_ci.pNext = NULL;
11951 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11952 pipe_ms_state_ci.sampleShadingEnable = 0;
11953 pipe_ms_state_ci.minSampleShading = 1.0;
11954 pipe_ms_state_ci.pSampleMask = NULL;
11955
11956 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11957 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11958 pipeline_layout_ci.pNext = NULL;
11959 pipeline_layout_ci.setLayoutCount = 1;
11960 pipeline_layout_ci.pSetLayouts = &ds_layout;
11961
11962 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011963 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011964 ASSERT_VK_SUCCESS(err);
11965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11967 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
11968 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011969 VkPipelineObj pipe(m_device);
11970 pipe.AddShader(&vs);
11971 pipe.AddShader(&fs);
11972 pipe.SetMSAA(&pipe_ms_state_ci);
11973 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11974
11975 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011976 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060011977
Mark Young29927482016-05-04 14:38:51 -060011978 // Render triangle (the error should trigger on the attempt to draw).
11979 Draw(3, 1, 0, 0);
11980
11981 // Finalize recording of the command buffer
11982 EndCommandBuffer();
11983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011984 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011985
11986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11987 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11988 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11989}
Mark Young29927482016-05-04 14:38:51 -060011990
Mark Muellerd4914412016-06-13 17:52:06 -060011991TEST_F(VkLayerTest, MissingClearAttachment) {
11992 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
11993 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011994 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +120011995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesef5e2842016-09-08 15:25:24 +120011996 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0; ignored");
Mark Muellerd4914412016-06-13 17:52:06 -060011997
11998 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11999 m_errorMonitor->VerifyFound();
12000}
12001
Karl Schultz6addd812016-02-02 17:17:23 -070012002TEST_F(VkLayerTest, ClearCmdNoDraw) {
12003 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
12004 // to issuing a Draw
12005 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12008 "vkCmdClearAttachments() issued on CB object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012009
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012010 ASSERT_NO_FATAL_FAILURE(InitState());
12011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012012
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012013 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12015 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012016
12017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12019 ds_pool_ci.pNext = NULL;
12020 ds_pool_ci.maxSets = 1;
12021 ds_pool_ci.poolSizeCount = 1;
12022 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012023
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012024 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012026 ASSERT_VK_SUCCESS(err);
12027
Tony Barboureb254902015-07-15 12:50:33 -060012028 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012029 dsl_binding.binding = 0;
12030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12031 dsl_binding.descriptorCount = 1;
12032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12033 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012034
Tony Barboureb254902015-07-15 12:50:33 -060012035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12037 ds_layout_ci.pNext = NULL;
12038 ds_layout_ci.bindingCount = 1;
12039 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012040
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012041 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012043 ASSERT_VK_SUCCESS(err);
12044
12045 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012046 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012048 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012049 alloc_info.descriptorPool = ds_pool;
12050 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012052 ASSERT_VK_SUCCESS(err);
12053
Tony Barboureb254902015-07-15 12:50:33 -060012054 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012055 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012056 pipe_ms_state_ci.pNext = NULL;
12057 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
12058 pipe_ms_state_ci.sampleShadingEnable = 0;
12059 pipe_ms_state_ci.minSampleShading = 1.0;
12060 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012061
Tony Barboureb254902015-07-15 12:50:33 -060012062 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012063 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12064 pipeline_layout_ci.pNext = NULL;
12065 pipeline_layout_ci.setLayoutCount = 1;
12066 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012067
12068 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012070 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012072 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060012073 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070012074 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012075 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012076
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012077 VkPipelineObj pipe(m_device);
12078 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012079 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012080 pipe.SetMSAA(&pipe_ms_state_ci);
12081 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012082
12083 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012084
Karl Schultz6addd812016-02-02 17:17:23 -070012085 // Main thing we care about for this test is that the VkImage obj we're
12086 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012087 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060012088 VkClearAttachment color_attachment;
12089 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12090 color_attachment.clearValue.color.float32[0] = 1.0;
12091 color_attachment.clearValue.color.float32[1] = 1.0;
12092 color_attachment.clearValue.color.float32[2] = 1.0;
12093 color_attachment.clearValue.color.float32[3] = 1.0;
12094 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012095 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012097 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012098
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012099 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012100
Chia-I Wuf7458c52015-10-26 21:10:41 +080012101 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12102 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12103 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012104}
12105
Karl Schultz6addd812016-02-02 17:17:23 -070012106TEST_F(VkLayerTest, VtxBufferBadIndex) {
12107 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12110 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012111
Tobin Ehlis502480b2015-06-24 15:53:07 -060012112 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012113 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012115
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012116 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012117 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12118 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012119
12120 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012121 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12122 ds_pool_ci.pNext = NULL;
12123 ds_pool_ci.maxSets = 1;
12124 ds_pool_ci.poolSizeCount = 1;
12125 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012126
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012127 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012128 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012129 ASSERT_VK_SUCCESS(err);
12130
Tony Barboureb254902015-07-15 12:50:33 -060012131 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012132 dsl_binding.binding = 0;
12133 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12134 dsl_binding.descriptorCount = 1;
12135 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12136 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012137
Tony Barboureb254902015-07-15 12:50:33 -060012138 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012139 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12140 ds_layout_ci.pNext = NULL;
12141 ds_layout_ci.bindingCount = 1;
12142 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012143
Tobin Ehlis502480b2015-06-24 15:53:07 -060012144 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012146 ASSERT_VK_SUCCESS(err);
12147
12148 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012149 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012150 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012151 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012152 alloc_info.descriptorPool = ds_pool;
12153 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012154 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012155 ASSERT_VK_SUCCESS(err);
12156
Tony Barboureb254902015-07-15 12:50:33 -060012157 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012158 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012159 pipe_ms_state_ci.pNext = NULL;
12160 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12161 pipe_ms_state_ci.sampleShadingEnable = 0;
12162 pipe_ms_state_ci.minSampleShading = 1.0;
12163 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012164
Tony Barboureb254902015-07-15 12:50:33 -060012165 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012166 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12167 pipeline_layout_ci.pNext = NULL;
12168 pipeline_layout_ci.setLayoutCount = 1;
12169 pipeline_layout_ci.pSetLayouts = &ds_layout;
12170 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012173 ASSERT_VK_SUCCESS(err);
12174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012175 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12176 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
12177 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012178 VkPipelineObj pipe(m_device);
12179 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012180 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012181 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012182 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012183 pipe.SetViewport(m_viewports);
12184 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012185 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012186
12187 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012188 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012189 // Don't care about actual data, just need to get to draw to flag error
12190 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012191 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012192 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012193 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012194
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012195 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012196
Chia-I Wuf7458c52015-10-26 21:10:41 +080012197 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12198 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12199 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012200}
Mark Muellerdfe37552016-07-07 14:47:42 -060012201
Mark Mueller2ee294f2016-08-04 12:59:48 -060012202TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
12203 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
12204 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060012205 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
12208 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012210 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
12211 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012212
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012213 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060012216 // The following test fails with recent NVidia drivers.
12217 // By the time core_validation is reached, the NVidia
12218 // driver has sanitized the invalid condition and core_validation
12219 // is not introduced to the failure condition. This is not the case
12220 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 // uint32_t count = static_cast<uint32_t>(~0);
12222 // VkPhysicalDevice physical_device;
12223 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12224 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012227 float queue_priority = 0.0;
12228
12229 VkDeviceQueueCreateInfo queue_create_info = {};
12230 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12231 queue_create_info.queueCount = 1;
12232 queue_create_info.pQueuePriorities = &queue_priority;
12233 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12234
12235 VkPhysicalDeviceFeatures features = m_device->phy().features();
12236 VkDevice testDevice;
12237 VkDeviceCreateInfo device_create_info = {};
12238 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12239 device_create_info.queueCreateInfoCount = 1;
12240 device_create_info.pQueueCreateInfos = &queue_create_info;
12241 device_create_info.pEnabledFeatures = &features;
12242 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12243 m_errorMonitor->VerifyFound();
12244
12245 queue_create_info.queueFamilyIndex = 1;
12246
12247 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12248 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12249 for (unsigned i = 0; i < feature_count; i++) {
12250 if (VK_FALSE == feature_array[i]) {
12251 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012253 device_create_info.pEnabledFeatures = &features;
12254 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12255 m_errorMonitor->VerifyFound();
12256 break;
12257 }
12258 }
12259}
12260
12261TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
12262 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
12263 "End a command buffer with a query still in progress.");
12264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12266 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12267 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012269 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012272
12273 ASSERT_NO_FATAL_FAILURE(InitState());
12274
12275 VkEvent event;
12276 VkEventCreateInfo event_create_info{};
12277 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12278 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12279
Mark Mueller2ee294f2016-08-04 12:59:48 -060012280 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012282
12283 BeginCommandBuffer();
12284
12285 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012287 ASSERT_TRUE(image.initialized());
12288 VkImageMemoryBarrier img_barrier = {};
12289 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12290 img_barrier.pNext = NULL;
12291 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12292 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12293 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12294 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12295 img_barrier.image = image.handle();
12296 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012297
12298 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12299 // that layer validation catches the case when it is not.
12300 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012301 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12302 img_barrier.subresourceRange.baseArrayLayer = 0;
12303 img_barrier.subresourceRange.baseMipLevel = 0;
12304 img_barrier.subresourceRange.layerCount = 1;
12305 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012306 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12307 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012308 m_errorMonitor->VerifyFound();
12309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012311
12312 VkQueryPool query_pool;
12313 VkQueryPoolCreateInfo query_pool_create_info = {};
12314 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12315 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12316 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012319 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012320 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12321
12322 vkEndCommandBuffer(m_commandBuffer->handle());
12323 m_errorMonitor->VerifyFound();
12324
12325 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12326 vkDestroyEvent(m_device->device(), event, nullptr);
12327}
12328
Mark Muellerdfe37552016-07-07 14:47:42 -060012329TEST_F(VkLayerTest, VertexBufferInvalid) {
12330 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
12331 "delete a buffer twice, use an invalid offset for each "
12332 "buffer type, and attempt to bind a null buffer");
12333
12334 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
12335 "using deleted buffer ";
12336 const char *double_destroy_message = "Cannot free buffer 0x";
12337 const char *invalid_offset_message = "vkBindBufferMemory(): "
12338 "memoryOffset is 0x";
12339 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
12340 "storage memoryOffset "
12341 "is 0x";
12342 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
12343 "texel memoryOffset "
12344 "is 0x";
12345 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
12346 "uniform memoryOffset "
12347 "is 0x";
12348 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
12349 " to Bind Obj(0x";
12350 const char *free_invalid_buffer_message = "Request to delete memory "
12351 "object 0x";
12352
12353 ASSERT_NO_FATAL_FAILURE(InitState());
12354 ASSERT_NO_FATAL_FAILURE(InitViewport());
12355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12356
12357 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012358 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012359 pipe_ms_state_ci.pNext = NULL;
12360 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12361 pipe_ms_state_ci.sampleShadingEnable = 0;
12362 pipe_ms_state_ci.minSampleShading = 1.0;
12363 pipe_ms_state_ci.pSampleMask = nullptr;
12364
12365 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12366 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12367 VkPipelineLayout pipeline_layout;
12368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012370 ASSERT_VK_SUCCESS(err);
12371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012372 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12373 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012374 VkPipelineObj pipe(m_device);
12375 pipe.AddShader(&vs);
12376 pipe.AddShader(&fs);
12377 pipe.AddColorAttachment();
12378 pipe.SetMSAA(&pipe_ms_state_ci);
12379 pipe.SetViewport(m_viewports);
12380 pipe.SetScissor(m_scissors);
12381 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12382
12383 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012384 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012385
12386 {
12387 // Create and bind a vertex buffer in a reduced scope, which will cause
12388 // it to be deleted upon leaving this scope
12389 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012390 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012391 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12392 draw_verticies.AddVertexInputToPipe(pipe);
12393 }
12394
12395 Draw(1, 0, 0, 0);
12396
12397 EndCommandBuffer();
12398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012400 QueueCommandBuffer(false);
12401 m_errorMonitor->VerifyFound();
12402
12403 {
12404 // Create and bind a vertex buffer in a reduced scope, and delete it
12405 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012406 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
12407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060012408 buffer_test.TestDoubleDestroy();
12409 }
12410 m_errorMonitor->VerifyFound();
12411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012413 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
12415 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12416 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012417 m_errorMonitor->VerifyFound();
12418 }
12419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012420 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12421 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012422 // Create and bind a memory buffer with an invalid offset again,
12423 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
12425 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12426 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012427 m_errorMonitor->VerifyFound();
12428 }
12429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012430 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012431 // Create and bind a memory buffer with an invalid offset again, but
12432 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
12434 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12435 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012436 m_errorMonitor->VerifyFound();
12437 }
12438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012439 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012440 // Create and bind a memory buffer with an invalid offset again, but
12441 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
12443 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12444 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012445 m_errorMonitor->VerifyFound();
12446 }
12447
12448 {
12449 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
12451 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12452 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012453 m_errorMonitor->VerifyFound();
12454 }
12455
12456 {
12457 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
12459 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12460 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012461 }
12462 m_errorMonitor->VerifyFound();
12463
12464 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12465}
12466
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012467// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12468TEST_F(VkLayerTest, InvalidImageLayout) {
12469 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012470 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12471 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012472 // 3 in ValidateCmdBufImageLayouts
12473 // * -1 Attempt to submit cmd buf w/ deleted image
12474 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12475 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12477 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012478
12479 ASSERT_NO_FATAL_FAILURE(InitState());
12480 // Create src & dst images to use for copy operations
12481 VkImage src_image;
12482 VkImage dst_image;
12483
12484 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12485 const int32_t tex_width = 32;
12486 const int32_t tex_height = 32;
12487
12488 VkImageCreateInfo image_create_info = {};
12489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12490 image_create_info.pNext = NULL;
12491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12492 image_create_info.format = tex_format;
12493 image_create_info.extent.width = tex_width;
12494 image_create_info.extent.height = tex_height;
12495 image_create_info.extent.depth = 1;
12496 image_create_info.mipLevels = 1;
12497 image_create_info.arrayLayers = 4;
12498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12499 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12500 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
12501 image_create_info.flags = 0;
12502
12503 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12504 ASSERT_VK_SUCCESS(err);
12505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12506 ASSERT_VK_SUCCESS(err);
12507
12508 BeginCommandBuffer();
12509 VkImageCopy copyRegion;
12510 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12511 copyRegion.srcSubresource.mipLevel = 0;
12512 copyRegion.srcSubresource.baseArrayLayer = 0;
12513 copyRegion.srcSubresource.layerCount = 1;
12514 copyRegion.srcOffset.x = 0;
12515 copyRegion.srcOffset.y = 0;
12516 copyRegion.srcOffset.z = 0;
12517 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12518 copyRegion.dstSubresource.mipLevel = 0;
12519 copyRegion.dstSubresource.baseArrayLayer = 0;
12520 copyRegion.dstSubresource.layerCount = 1;
12521 copyRegion.dstOffset.x = 0;
12522 copyRegion.dstOffset.y = 0;
12523 copyRegion.dstOffset.z = 0;
12524 copyRegion.extent.width = 1;
12525 copyRegion.extent.height = 1;
12526 copyRegion.extent.depth = 1;
12527 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12528 m_errorMonitor->VerifyFound();
12529 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
12531 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12532 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012533 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12534 m_errorMonitor->VerifyFound();
12535 // Final src error is due to bad layout type
12536 m_errorMonitor->SetDesiredFailureMsg(
12537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12538 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
12539 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12540 m_errorMonitor->VerifyFound();
12541 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12543 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012544 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
12545 m_errorMonitor->VerifyFound();
12546 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
12548 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
12549 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012550 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12551 m_errorMonitor->VerifyFound();
12552 m_errorMonitor->SetDesiredFailureMsg(
12553 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12554 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
12555 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
12556 m_errorMonitor->VerifyFound();
12557 // Now cause error due to bad image layout transition in PipelineBarrier
12558 VkImageMemoryBarrier image_barrier[1] = {};
12559 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12560 image_barrier[0].image = src_image;
12561 image_barrier[0].subresourceRange.layerCount = 2;
12562 image_barrier[0].subresourceRange.levelCount = 2;
12563 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
12565 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
12566 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
12567 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12568 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012569 m_errorMonitor->VerifyFound();
12570
12571 // Finally some layout errors at RenderPass create time
12572 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12573 VkAttachmentReference attach = {};
12574 // perf warning for GENERAL layout w/ non-DS input attachment
12575 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12576 VkSubpassDescription subpass = {};
12577 subpass.inputAttachmentCount = 1;
12578 subpass.pInputAttachments = &attach;
12579 VkRenderPassCreateInfo rpci = {};
12580 rpci.subpassCount = 1;
12581 rpci.pSubpasses = &subpass;
12582 rpci.attachmentCount = 1;
12583 VkAttachmentDescription attach_desc = {};
12584 attach_desc.format = VK_FORMAT_UNDEFINED;
12585 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012586 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012587 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12589 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012590 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12591 m_errorMonitor->VerifyFound();
12592 // error w/ non-general layout
12593 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12594
12595 m_errorMonitor->SetDesiredFailureMsg(
12596 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12597 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12598 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12599 m_errorMonitor->VerifyFound();
12600 subpass.inputAttachmentCount = 0;
12601 subpass.colorAttachmentCount = 1;
12602 subpass.pColorAttachments = &attach;
12603 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12604 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12606 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012607 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12608 m_errorMonitor->VerifyFound();
12609 // error w/ non-color opt or GENERAL layout for color attachment
12610 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12611 m_errorMonitor->SetDesiredFailureMsg(
12612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12613 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12614 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12615 m_errorMonitor->VerifyFound();
12616 subpass.colorAttachmentCount = 0;
12617 subpass.pDepthStencilAttachment = &attach;
12618 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12619 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12621 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012622 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12623 m_errorMonitor->VerifyFound();
12624 // error w/ non-ds opt or GENERAL layout for color attachment
12625 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12627 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12628 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012629 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12630 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012631 // For this error we need a valid renderpass so create default one
12632 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12633 attach.attachment = 0;
12634 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12635 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12636 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12637 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12638 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12639 // Can't do a CLEAR load on READ_ONLY initialLayout
12640 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12641 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12642 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
12644 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12645 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012646 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12647 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012648
12649 vkDestroyImage(m_device->device(), src_image, NULL);
12650 vkDestroyImage(m_device->device(), dst_image, NULL);
12651}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012652
12653TEST_F(VkLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
12654 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
12655 "attachment that uses LOAD_OP_CLEAR, the first subpass "
12656 "has a valid layout, and a second subpass then uses a "
12657 "valid *READ_ONLY* layout.");
12658 m_errorMonitor->ExpectSuccess();
12659 ASSERT_NO_FATAL_FAILURE(InitState());
12660
12661 VkAttachmentReference attach[2] = {};
12662 attach[0].attachment = 0;
12663 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
12664 attach[1].attachment = 0;
12665 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12666 VkSubpassDescription subpasses[2] = {};
12667 // First subpass clears DS attach on load
12668 subpasses[0].pDepthStencilAttachment = &attach[0];
12669 // 2nd subpass reads in DS as input attachment
12670 subpasses[1].inputAttachmentCount = 1;
12671 subpasses[1].pInputAttachments = &attach[1];
12672 VkAttachmentDescription attach_desc = {};
12673 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
12674 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12675 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12676 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12677 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12678 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012679 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012680 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12681 VkRenderPassCreateInfo rpci = {};
12682 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
12683 rpci.attachmentCount = 1;
12684 rpci.pAttachments = &attach_desc;
12685 rpci.subpassCount = 2;
12686 rpci.pSubpasses = subpasses;
12687
12688 // Now create RenderPass and verify no errors
12689 VkRenderPass rp;
12690 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12691 m_errorMonitor->VerifyNotFound();
12692
12693 vkDestroyRenderPass(m_device->device(), rp, NULL);
12694}
Tobin Ehlis4af23302016-07-19 10:50:30 -060012695
Mark Mueller93b938f2016-08-18 10:27:40 -060012696TEST_F(VkLayerTest, SimultaneousUse) {
12697 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12698 "in primary and secondary command buffers.");
12699
12700 ASSERT_NO_FATAL_FAILURE(InitState());
12701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012703 const char *simultaneous_use_message1 = "w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12704 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12705 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012706
12707 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012708 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012709 command_buffer_allocate_info.commandPool = m_commandPool;
12710 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12711 command_buffer_allocate_info.commandBufferCount = 1;
12712
12713 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012714 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012715 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12716 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012717 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012718 command_buffer_inheritance_info.renderPass = m_renderPass;
12719 command_buffer_inheritance_info.framebuffer = m_framebuffer;
12720 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012721 command_buffer_begin_info.flags =
12722 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012723 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12724
12725 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012726 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12727 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060012728 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012729 vkEndCommandBuffer(secondary_command_buffer);
12730
Mark Mueller93b938f2016-08-18 10:27:40 -060012731 VkSubmitInfo submit_info = {};
12732 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12733 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012734 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060012735 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060012736
Mark Mueller4042b652016-09-05 22:52:21 -060012737 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012738 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12740 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012741 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012742 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12743 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012744
12745 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060012746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12747
Mark Mueller4042b652016-09-05 22:52:21 -060012748 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012749 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012750 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12753 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012754 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012755 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12756 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012757}
12758
Mark Mueller917f6bc2016-08-30 10:57:19 -060012759TEST_F(VkLayerTest, InUseDestroyedSignaled) {
12760 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
12761 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060012762 "Delete objects that are inuse. Call VkQueueSubmit "
12763 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012764
12765 ASSERT_NO_FATAL_FAILURE(InitState());
12766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012768 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
12769 const char *cannot_delete_event_message = "Cannot delete event 0x";
12770 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
12771 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060012772
12773 BeginCommandBuffer();
12774
12775 VkEvent event;
12776 VkEventCreateInfo event_create_info = {};
12777 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12778 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012779 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012780
Mark Muellerc8d441e2016-08-23 17:36:00 -060012781 EndCommandBuffer();
12782 vkDestroyEvent(m_device->device(), event, nullptr);
12783
12784 VkSubmitInfo submit_info = {};
12785 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12786 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012787 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012789 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12790 m_errorMonitor->VerifyFound();
12791
12792 m_errorMonitor->SetDesiredFailureMsg(0, "");
12793 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12794
12795 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12796
Mark Mueller917f6bc2016-08-30 10:57:19 -060012797 VkSemaphoreCreateInfo semaphore_create_info = {};
12798 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12799 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012800 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012801 VkFenceCreateInfo fence_create_info = {};
12802 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12803 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012804 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012805
12806 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012807 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012808 descriptor_pool_type_count.descriptorCount = 1;
12809
12810 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12811 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12812 descriptor_pool_create_info.maxSets = 1;
12813 descriptor_pool_create_info.poolSizeCount = 1;
12814 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012815 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012816
12817 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012818 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012819
12820 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012821 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012822 descriptorset_layout_binding.descriptorCount = 1;
12823 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12824
12825 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012826 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012827 descriptorset_layout_create_info.bindingCount = 1;
12828 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12829
12830 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012831 ASSERT_VK_SUCCESS(
12832 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012833
12834 VkDescriptorSet descriptorset;
12835 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012836 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012837 descriptorset_allocate_info.descriptorSetCount = 1;
12838 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12839 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012840 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012841
Mark Mueller4042b652016-09-05 22:52:21 -060012842 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12843
12844 VkDescriptorBufferInfo buffer_info = {};
12845 buffer_info.buffer = buffer_test.GetBuffer();
12846 buffer_info.offset = 0;
12847 buffer_info.range = 1024;
12848
12849 VkWriteDescriptorSet write_descriptor_set = {};
12850 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12851 write_descriptor_set.dstSet = descriptorset;
12852 write_descriptor_set.descriptorCount = 1;
12853 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12854 write_descriptor_set.pBufferInfo = &buffer_info;
12855
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012856 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012857
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012858 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12859 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012860
12861 VkPipelineObj pipe(m_device);
12862 pipe.AddColorAttachment();
12863 pipe.AddShader(&vs);
12864 pipe.AddShader(&fs);
12865
12866 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012867 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012868 pipeline_layout_create_info.setLayoutCount = 1;
12869 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12870
12871 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012872 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012873
12874 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12875
Mark Muellerc8d441e2016-08-23 17:36:00 -060012876 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012877 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12880 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12881 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012882
Mark Muellerc8d441e2016-08-23 17:36:00 -060012883 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012884
Mark Mueller917f6bc2016-08-30 10:57:19 -060012885 submit_info.signalSemaphoreCount = 1;
12886 submit_info.pSignalSemaphores = &semaphore;
12887 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012890 vkDestroyEvent(m_device->device(), event, nullptr);
12891 m_errorMonitor->VerifyFound();
12892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012894 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12895 m_errorMonitor->VerifyFound();
12896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012898 vkDestroyFence(m_device->device(), fence, nullptr);
12899 m_errorMonitor->VerifyFound();
12900
Tobin Ehlis122207b2016-09-01 08:50:06 -070012901 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012902 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12903 vkDestroyFence(m_device->device(), fence, nullptr);
12904 vkDestroyEvent(m_device->device(), event, nullptr);
12905 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012906 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012907 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12908}
12909
Tobin Ehlis2adda372016-09-01 08:51:06 -070012910TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12911 TEST_DESCRIPTION("Delete in-use query pool.");
12912
12913 ASSERT_NO_FATAL_FAILURE(InitState());
12914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12915
12916 VkQueryPool query_pool;
12917 VkQueryPoolCreateInfo query_pool_ci{};
12918 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12919 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12920 query_pool_ci.queryCount = 1;
12921 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
12922 BeginCommandBuffer();
12923 // Reset query pool to create binding with cmd buffer
12924 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12925
12926 EndCommandBuffer();
12927
12928 VkSubmitInfo submit_info = {};
12929 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12930 submit_info.commandBufferCount = 1;
12931 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12932 // Submit cmd buffer and then destroy query pool while in-flight
12933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012936 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12937 m_errorMonitor->VerifyFound();
12938
12939 vkQueueWaitIdle(m_device->m_queue);
12940 // Now that cmd buffer done we can safely destroy query_pool
12941 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12942}
12943
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012944TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12945 TEST_DESCRIPTION("Delete in-use pipeline.");
12946
12947 ASSERT_NO_FATAL_FAILURE(InitState());
12948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12949
12950 // Empty pipeline layout used for binding PSO
12951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12953 pipeline_layout_ci.setLayoutCount = 0;
12954 pipeline_layout_ci.pSetLayouts = NULL;
12955
12956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012958 ASSERT_VK_SUCCESS(err);
12959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012961 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012962 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12963 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012964 // Store pipeline handle so we can actually delete it before test finishes
12965 VkPipeline delete_this_pipeline;
12966 { // Scope pipeline so it will be auto-deleted
12967 VkPipelineObj pipe(m_device);
12968 pipe.AddShader(&vs);
12969 pipe.AddShader(&fs);
12970 pipe.AddColorAttachment();
12971 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12972 delete_this_pipeline = pipe.handle();
12973
12974 BeginCommandBuffer();
12975 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012976 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012977
12978 EndCommandBuffer();
12979
12980 VkSubmitInfo submit_info = {};
12981 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12982 submit_info.commandBufferCount = 1;
12983 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12984 // Submit cmd buffer and then pipeline destroyed while in-flight
12985 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12986 } // Pipeline deletion triggered here
12987 m_errorMonitor->VerifyFound();
12988 // Make sure queue finished and then actually delete pipeline
12989 vkQueueWaitIdle(m_device->m_queue);
12990 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12991 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12992}
12993
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012994TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12995 TEST_DESCRIPTION("Delete in-use imageView.");
12996
12997 ASSERT_NO_FATAL_FAILURE(InitState());
12998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12999
13000 VkDescriptorPoolSize ds_type_count;
13001 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13002 ds_type_count.descriptorCount = 1;
13003
13004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13006 ds_pool_ci.maxSets = 1;
13007 ds_pool_ci.poolSizeCount = 1;
13008 ds_pool_ci.pPoolSizes = &ds_type_count;
13009
13010 VkDescriptorPool ds_pool;
13011 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13012 ASSERT_VK_SUCCESS(err);
13013
13014 VkSamplerCreateInfo sampler_ci = {};
13015 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13016 sampler_ci.pNext = NULL;
13017 sampler_ci.magFilter = VK_FILTER_NEAREST;
13018 sampler_ci.minFilter = VK_FILTER_NEAREST;
13019 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13020 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13021 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13022 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13023 sampler_ci.mipLodBias = 1.0;
13024 sampler_ci.anisotropyEnable = VK_FALSE;
13025 sampler_ci.maxAnisotropy = 1;
13026 sampler_ci.compareEnable = VK_FALSE;
13027 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13028 sampler_ci.minLod = 1.0;
13029 sampler_ci.maxLod = 1.0;
13030 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13031 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13032 VkSampler sampler;
13033
13034 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13035 ASSERT_VK_SUCCESS(err);
13036
13037 VkDescriptorSetLayoutBinding layout_binding;
13038 layout_binding.binding = 0;
13039 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13040 layout_binding.descriptorCount = 1;
13041 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13042 layout_binding.pImmutableSamplers = NULL;
13043
13044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13046 ds_layout_ci.bindingCount = 1;
13047 ds_layout_ci.pBindings = &layout_binding;
13048 VkDescriptorSetLayout ds_layout;
13049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13050 ASSERT_VK_SUCCESS(err);
13051
13052 VkDescriptorSetAllocateInfo alloc_info = {};
13053 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13054 alloc_info.descriptorSetCount = 1;
13055 alloc_info.descriptorPool = ds_pool;
13056 alloc_info.pSetLayouts = &ds_layout;
13057 VkDescriptorSet descriptor_set;
13058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13059 ASSERT_VK_SUCCESS(err);
13060
13061 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13062 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13063 pipeline_layout_ci.pNext = NULL;
13064 pipeline_layout_ci.setLayoutCount = 1;
13065 pipeline_layout_ci.pSetLayouts = &ds_layout;
13066
13067 VkPipelineLayout pipeline_layout;
13068 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13069 ASSERT_VK_SUCCESS(err);
13070
13071 VkImageObj image(m_device);
13072 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
13073 ASSERT_TRUE(image.initialized());
13074
13075 VkImageView view;
13076 VkImageViewCreateInfo ivci = {};
13077 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13078 ivci.image = image.handle();
13079 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13080 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13081 ivci.subresourceRange.layerCount = 1;
13082 ivci.subresourceRange.baseMipLevel = 0;
13083 ivci.subresourceRange.levelCount = 1;
13084 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13085
13086 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13087 ASSERT_VK_SUCCESS(err);
13088
13089 VkDescriptorImageInfo image_info{};
13090 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13091 image_info.imageView = view;
13092 image_info.sampler = sampler;
13093
13094 VkWriteDescriptorSet descriptor_write = {};
13095 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13096 descriptor_write.dstSet = descriptor_set;
13097 descriptor_write.dstBinding = 0;
13098 descriptor_write.descriptorCount = 1;
13099 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13100 descriptor_write.pImageInfo = &image_info;
13101
13102 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13103
13104 // Create PSO to use the sampler
13105 char const *vsSource = "#version 450\n"
13106 "\n"
13107 "out gl_PerVertex { \n"
13108 " vec4 gl_Position;\n"
13109 "};\n"
13110 "void main(){\n"
13111 " gl_Position = vec4(1);\n"
13112 "}\n";
13113 char const *fsSource = "#version 450\n"
13114 "\n"
13115 "layout(set=0, binding=0) uniform sampler2D s;\n"
13116 "layout(location=0) out vec4 x;\n"
13117 "void main(){\n"
13118 " x = texture(s, vec2(1));\n"
13119 "}\n";
13120 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13121 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13122 VkPipelineObj pipe(m_device);
13123 pipe.AddShader(&vs);
13124 pipe.AddShader(&fs);
13125 pipe.AddColorAttachment();
13126 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13127
13128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
13129
13130 BeginCommandBuffer();
13131 // Bind pipeline to cmd buffer
13132 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13133 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13134 &descriptor_set, 0, nullptr);
13135 Draw(1, 0, 0, 0);
13136 EndCommandBuffer();
13137 // Submit cmd buffer then destroy sampler
13138 VkSubmitInfo submit_info = {};
13139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13140 submit_info.commandBufferCount = 1;
13141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13142 // Submit cmd buffer and then destroy imageView while in-flight
13143 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13144
13145 vkDestroyImageView(m_device->device(), view, nullptr);
13146 m_errorMonitor->VerifyFound();
13147 vkQueueWaitIdle(m_device->m_queue);
13148 // Now we can actually destroy imageView
13149 vkDestroyImageView(m_device->device(), view, NULL);
13150 vkDestroySampler(m_device->device(), sampler, nullptr);
13151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13154}
13155
Tobin Ehlis209532e2016-09-07 13:52:18 -060013156TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13157 TEST_DESCRIPTION("Delete in-use sampler.");
13158
13159 ASSERT_NO_FATAL_FAILURE(InitState());
13160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13161
13162 VkDescriptorPoolSize ds_type_count;
13163 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13164 ds_type_count.descriptorCount = 1;
13165
13166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13168 ds_pool_ci.maxSets = 1;
13169 ds_pool_ci.poolSizeCount = 1;
13170 ds_pool_ci.pPoolSizes = &ds_type_count;
13171
13172 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013173 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013174 ASSERT_VK_SUCCESS(err);
13175
13176 VkSamplerCreateInfo sampler_ci = {};
13177 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13178 sampler_ci.pNext = NULL;
13179 sampler_ci.magFilter = VK_FILTER_NEAREST;
13180 sampler_ci.minFilter = VK_FILTER_NEAREST;
13181 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13182 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13183 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13184 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13185 sampler_ci.mipLodBias = 1.0;
13186 sampler_ci.anisotropyEnable = VK_FALSE;
13187 sampler_ci.maxAnisotropy = 1;
13188 sampler_ci.compareEnable = VK_FALSE;
13189 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13190 sampler_ci.minLod = 1.0;
13191 sampler_ci.maxLod = 1.0;
13192 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13193 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13194 VkSampler sampler;
13195
13196 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13197 ASSERT_VK_SUCCESS(err);
13198
13199 VkDescriptorSetLayoutBinding layout_binding;
13200 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013201 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013202 layout_binding.descriptorCount = 1;
13203 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13204 layout_binding.pImmutableSamplers = NULL;
13205
13206 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13207 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13208 ds_layout_ci.bindingCount = 1;
13209 ds_layout_ci.pBindings = &layout_binding;
13210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013212 ASSERT_VK_SUCCESS(err);
13213
13214 VkDescriptorSetAllocateInfo alloc_info = {};
13215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13216 alloc_info.descriptorSetCount = 1;
13217 alloc_info.descriptorPool = ds_pool;
13218 alloc_info.pSetLayouts = &ds_layout;
13219 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013221 ASSERT_VK_SUCCESS(err);
13222
13223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13225 pipeline_layout_ci.pNext = NULL;
13226 pipeline_layout_ci.setLayoutCount = 1;
13227 pipeline_layout_ci.pSetLayouts = &ds_layout;
13228
13229 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013231 ASSERT_VK_SUCCESS(err);
13232
13233 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013235 ASSERT_TRUE(image.initialized());
13236
13237 VkImageView view;
13238 VkImageViewCreateInfo ivci = {};
13239 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13240 ivci.image = image.handle();
13241 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13242 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13243 ivci.subresourceRange.layerCount = 1;
13244 ivci.subresourceRange.baseMipLevel = 0;
13245 ivci.subresourceRange.levelCount = 1;
13246 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13247
13248 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13249 ASSERT_VK_SUCCESS(err);
13250
13251 VkDescriptorImageInfo image_info{};
13252 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13253 image_info.imageView = view;
13254 image_info.sampler = sampler;
13255
13256 VkWriteDescriptorSet descriptor_write = {};
13257 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13258 descriptor_write.dstSet = descriptor_set;
13259 descriptor_write.dstBinding = 0;
13260 descriptor_write.descriptorCount = 1;
13261 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13262 descriptor_write.pImageInfo = &image_info;
13263
13264 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13265
13266 // Create PSO to use the sampler
13267 char const *vsSource = "#version 450\n"
13268 "\n"
13269 "out gl_PerVertex { \n"
13270 " vec4 gl_Position;\n"
13271 "};\n"
13272 "void main(){\n"
13273 " gl_Position = vec4(1);\n"
13274 "}\n";
13275 char const *fsSource = "#version 450\n"
13276 "\n"
13277 "layout(set=0, binding=0) uniform sampler2D s;\n"
13278 "layout(location=0) out vec4 x;\n"
13279 "void main(){\n"
13280 " x = texture(s, vec2(1));\n"
13281 "}\n";
13282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13284 VkPipelineObj pipe(m_device);
13285 pipe.AddShader(&vs);
13286 pipe.AddShader(&fs);
13287 pipe.AddColorAttachment();
13288 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060013291
13292 BeginCommandBuffer();
13293 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13295 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13296 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013297 Draw(1, 0, 0, 0);
13298 EndCommandBuffer();
13299 // Submit cmd buffer then destroy sampler
13300 VkSubmitInfo submit_info = {};
13301 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13302 submit_info.commandBufferCount = 1;
13303 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13304 // Submit cmd buffer and then destroy sampler while in-flight
13305 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13306
13307 vkDestroySampler(m_device->device(), sampler, nullptr);
13308 m_errorMonitor->VerifyFound();
13309 vkQueueWaitIdle(m_device->m_queue);
13310 // Now we can actually destroy sampler
13311 vkDestroySampler(m_device->device(), sampler, nullptr);
13312 vkDestroyImageView(m_device->device(), view, NULL);
13313 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13316}
13317
Mark Mueller1cd9f412016-08-25 13:23:52 -060013318TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060013319 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060013320 "signaled but not waited on by the queue. Wait on a "
13321 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013322
13323 ASSERT_NO_FATAL_FAILURE(InitState());
13324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13325
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013326 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
13327 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
13328 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013329
13330 BeginCommandBuffer();
13331 EndCommandBuffer();
13332
13333 VkSemaphoreCreateInfo semaphore_create_info = {};
13334 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13335 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013336 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013337 VkSubmitInfo submit_info = {};
13338 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13339 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013340 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013341 submit_info.signalSemaphoreCount = 1;
13342 submit_info.pSignalSemaphores = &semaphore;
13343 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13344 m_errorMonitor->SetDesiredFailureMsg(0, "");
13345 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
13346 BeginCommandBuffer();
13347 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013349 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13350 m_errorMonitor->VerifyFound();
13351
Mark Mueller1cd9f412016-08-25 13:23:52 -060013352 VkFenceCreateInfo fence_create_info = {};
13353 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13354 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013355 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013358 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13359 m_errorMonitor->VerifyFound();
13360
Mark Mueller4042b652016-09-05 22:52:21 -060013361 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013362 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013363 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13364}
13365
Tobin Ehlis4af23302016-07-19 10:50:30 -060013366TEST_F(VkLayerTest, FramebufferIncompatible) {
13367 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
13368 "that does not match the framebuffer for the active "
13369 "renderpass.");
13370 ASSERT_NO_FATAL_FAILURE(InitState());
13371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13372
13373 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013374 VkAttachmentDescription attachment = {0,
13375 VK_FORMAT_B8G8R8A8_UNORM,
13376 VK_SAMPLE_COUNT_1_BIT,
13377 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13378 VK_ATTACHMENT_STORE_OP_STORE,
13379 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13380 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13381 VK_IMAGE_LAYOUT_UNDEFINED,
13382 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013384 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013386 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013388 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013389
13390 VkRenderPass rp;
13391 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13392 ASSERT_VK_SUCCESS(err);
13393
13394 // A compatible framebuffer.
13395 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013396 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013397 ASSERT_TRUE(image.initialized());
13398
13399 VkImageViewCreateInfo ivci = {
13400 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13401 nullptr,
13402 0,
13403 image.handle(),
13404 VK_IMAGE_VIEW_TYPE_2D,
13405 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013406 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13407 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013408 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13409 };
13410 VkImageView view;
13411 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13412 ASSERT_VK_SUCCESS(err);
13413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013414 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013415 VkFramebuffer fb;
13416 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13417 ASSERT_VK_SUCCESS(err);
13418
13419 VkCommandBufferAllocateInfo cbai = {};
13420 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13421 cbai.commandPool = m_commandPool;
13422 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13423 cbai.commandBufferCount = 1;
13424
13425 VkCommandBuffer sec_cb;
13426 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13427 ASSERT_VK_SUCCESS(err);
13428 VkCommandBufferBeginInfo cbbi = {};
13429 VkCommandBufferInheritanceInfo cbii = {};
13430 cbii.renderPass = renderPass();
13431 cbii.framebuffer = fb;
13432 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13433 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013434 cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013435 cbbi.pInheritanceInfo = &cbii;
13436 vkBeginCommandBuffer(sec_cb, &cbbi);
13437 vkEndCommandBuffer(sec_cb);
13438
Chris Forbes3400bc52016-09-13 18:10:34 +120013439 VkCommandBufferBeginInfo cbbi2 = {
13440 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
13441 0, nullptr
13442 };
13443 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13444 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13447 " that is not the same as the primaryCB's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013448 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13449 m_errorMonitor->VerifyFound();
13450 // Cleanup
13451 vkDestroyImageView(m_device->device(), view, NULL);
13452 vkDestroyRenderPass(m_device->device(), rp, NULL);
13453 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13454}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013455
13456TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
13457 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
13458 "invalid value. If logicOp is not available, attempt to "
13459 "use it and verify that we see the correct error.");
13460 ASSERT_NO_FATAL_FAILURE(InitState());
13461 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13462
13463 auto features = m_device->phy().features();
13464 // Set the expected error depending on whether or not logicOp available
13465 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
13467 "enabled, logicOpEnable must be "
13468 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013469 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ", logicOp must be a valid VkLogicOp value");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013471 }
13472 // Create a pipeline using logicOp
13473 VkResult err;
13474
13475 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13476 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13477
13478 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013479 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013480 ASSERT_VK_SUCCESS(err);
13481
13482 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13483 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13484 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013485 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013486 vp_state_ci.pViewports = &vp;
13487 vp_state_ci.scissorCount = 1;
13488 VkRect2D scissors = {}; // Dummy scissors to point to
13489 vp_state_ci.pScissors = &scissors;
13490 // No dynamic state
13491 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
13492 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13493
13494 VkPipelineShaderStageCreateInfo shaderStages[2];
13495 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013497 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13498 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013499 shaderStages[0] = vs.GetStageCreateInfo();
13500 shaderStages[1] = fs.GetStageCreateInfo();
13501
13502 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13503 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13504
13505 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13506 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13507 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13508
13509 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13510 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13511
13512 VkPipelineColorBlendAttachmentState att = {};
13513 att.blendEnable = VK_FALSE;
13514 att.colorWriteMask = 0xf;
13515
13516 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13517 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13518 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13519 cb_ci.logicOpEnable = VK_TRUE;
13520 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
13521 cb_ci.attachmentCount = 1;
13522 cb_ci.pAttachments = &att;
13523
13524 VkGraphicsPipelineCreateInfo gp_ci = {};
13525 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13526 gp_ci.stageCount = 2;
13527 gp_ci.pStages = shaderStages;
13528 gp_ci.pVertexInputState = &vi_ci;
13529 gp_ci.pInputAssemblyState = &ia_ci;
13530 gp_ci.pViewportState = &vp_state_ci;
13531 gp_ci.pRasterizationState = &rs_ci;
13532 gp_ci.pColorBlendState = &cb_ci;
13533 gp_ci.pDynamicState = &dyn_state_ci;
13534 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13535 gp_ci.layout = pipeline_layout;
13536 gp_ci.renderPass = renderPass();
13537
13538 VkPipelineCacheCreateInfo pc_ci = {};
13539 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13540
13541 VkPipeline pipeline;
13542 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013543 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013544 ASSERT_VK_SUCCESS(err);
13545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013546 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013547 m_errorMonitor->VerifyFound();
13548 if (VK_SUCCESS == err) {
13549 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13550 }
13551 m_errorMonitor->VerifyFound();
13552 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13553 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13554}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013555#endif // DRAW_STATE_TESTS
13556
Tobin Ehlis0788f522015-05-26 16:11:58 -060013557#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060013558#if GTEST_IS_THREADSAFE
13559struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013560 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013561 VkEvent event;
13562 bool bailout;
13563};
13564
Karl Schultz6addd812016-02-02 17:17:23 -070013565extern "C" void *AddToCommandBuffer(void *arg) {
13566 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013567
Mike Stroyana6d14942016-07-13 15:10:05 -060013568 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013569 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013570 if (data->bailout) {
13571 break;
13572 }
13573 }
13574 return NULL;
13575}
13576
Karl Schultz6addd812016-02-02 17:17:23 -070013577TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013578 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013581
Mike Stroyanaccf7692015-05-12 16:00:45 -060013582 ASSERT_NO_FATAL_FAILURE(InitState());
13583 ASSERT_NO_FATAL_FAILURE(InitViewport());
13584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13585
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013586 // Calls AllocateCommandBuffers
13587 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013588
13589 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013590 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013591
13592 VkEventCreateInfo event_info;
13593 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013594 VkResult err;
13595
13596 memset(&event_info, 0, sizeof(event_info));
13597 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13598
Chia-I Wuf7458c52015-10-26 21:10:41 +080013599 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013600 ASSERT_VK_SUCCESS(err);
13601
Mike Stroyanaccf7692015-05-12 16:00:45 -060013602 err = vkResetEvent(device(), event);
13603 ASSERT_VK_SUCCESS(err);
13604
13605 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013606 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013607 data.event = event;
13608 data.bailout = false;
13609 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013610
13611 // First do some correct operations using multiple threads.
13612 // Add many entries to command buffer from another thread.
13613 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13614 // Make non-conflicting calls from this thread at the same time.
13615 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013616 uint32_t count;
13617 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013618 }
13619 test_platform_thread_join(thread, NULL);
13620
13621 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013622 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013623 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013624 // Add many entries to command buffer from this thread at the same time.
13625 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013626
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013627 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013628 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013629
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013630 m_errorMonitor->SetBailout(NULL);
13631
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013632 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013633
Chia-I Wuf7458c52015-10-26 21:10:41 +080013634 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013635}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013636#endif // GTEST_IS_THREADSAFE
13637#endif // THREADING_TESTS
13638
Chris Forbes9f7ff632015-05-25 11:13:08 +120013639#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070013640TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013641 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13642 "with an impossible code size");
13643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013645
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013646 ASSERT_NO_FATAL_FAILURE(InitState());
13647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13648
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013649 VkShaderModule module;
13650 VkShaderModuleCreateInfo moduleCreateInfo;
13651 struct icd_spv_header spv;
13652
13653 spv.magic = ICD_SPV_MAGIC;
13654 spv.version = ICD_SPV_VERSION;
13655 spv.gen_magic = 0;
13656
13657 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13658 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013659 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013660 moduleCreateInfo.codeSize = 4;
13661 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013662 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013663
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013664 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013665}
13666
Karl Schultz6addd812016-02-02 17:17:23 -070013667TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013668 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
13669 "with a bad magic number");
13670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013672
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013673 ASSERT_NO_FATAL_FAILURE(InitState());
13674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13675
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013676 VkShaderModule module;
13677 VkShaderModuleCreateInfo moduleCreateInfo;
13678 struct icd_spv_header spv;
13679
13680 spv.magic = ~ICD_SPV_MAGIC;
13681 spv.version = ICD_SPV_VERSION;
13682 spv.gen_magic = 0;
13683
13684 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13685 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013686 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013687 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13688 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013689 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013691 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013692}
13693
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013694#if 0
13695// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013696TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013698 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013699
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013700 ASSERT_NO_FATAL_FAILURE(InitState());
13701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13702
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013703 VkShaderModule module;
13704 VkShaderModuleCreateInfo moduleCreateInfo;
13705 struct icd_spv_header spv;
13706
13707 spv.magic = ICD_SPV_MAGIC;
13708 spv.version = ~ICD_SPV_VERSION;
13709 spv.gen_magic = 0;
13710
13711 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13712 moduleCreateInfo.pNext = NULL;
13713
Karl Schultz6addd812016-02-02 17:17:23 -070013714 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013715 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13716 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013717 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013719 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013720}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013721#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013722
Karl Schultz6addd812016-02-02 17:17:23 -070013723TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013724 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
13725 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013727
Chris Forbes9f7ff632015-05-25 11:13:08 +120013728 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013731 char const *vsSource = "#version 450\n"
13732 "\n"
13733 "layout(location=0) out float x;\n"
13734 "out gl_PerVertex {\n"
13735 " vec4 gl_Position;\n"
13736 "};\n"
13737 "void main(){\n"
13738 " gl_Position = vec4(1);\n"
13739 " x = 0;\n"
13740 "}\n";
13741 char const *fsSource = "#version 450\n"
13742 "\n"
13743 "layout(location=0) out vec4 color;\n"
13744 "void main(){\n"
13745 " color = vec4(1);\n"
13746 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013747
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013750
13751 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013752 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013753 pipe.AddShader(&vs);
13754 pipe.AddShader(&fs);
13755
Chris Forbes9f7ff632015-05-25 11:13:08 +120013756 VkDescriptorSetObj descriptorSet(m_device);
13757 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013758 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013759
Tony Barbour5781e8f2015-08-04 16:23:11 -060013760 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013761
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013762 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013763}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013764
Karl Schultz6addd812016-02-02 17:17:23 -070013765TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013766 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13767 "which is not present in the outputs of the previous stage");
13768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013770
Chris Forbes59cb88d2015-05-25 11:13:13 +120013771 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013773
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013774 char const *vsSource = "#version 450\n"
13775 "\n"
13776 "out gl_PerVertex {\n"
13777 " vec4 gl_Position;\n"
13778 "};\n"
13779 "void main(){\n"
13780 " gl_Position = vec4(1);\n"
13781 "}\n";
13782 char const *fsSource = "#version 450\n"
13783 "\n"
13784 "layout(location=0) in float x;\n"
13785 "layout(location=0) out vec4 color;\n"
13786 "void main(){\n"
13787 " color = vec4(x);\n"
13788 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013789
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13791 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013792
13793 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013794 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013795 pipe.AddShader(&vs);
13796 pipe.AddShader(&fs);
13797
Chris Forbes59cb88d2015-05-25 11:13:13 +120013798 VkDescriptorSetObj descriptorSet(m_device);
13799 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013800 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013801
Tony Barbour5781e8f2015-08-04 16:23:11 -060013802 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013803
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013804 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013805}
13806
Karl Schultz6addd812016-02-02 17:17:23 -070013807TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013808 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
13809 "within an interace block, which is not present in the outputs "
13810 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013812
13813 ASSERT_NO_FATAL_FAILURE(InitState());
13814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 char const *vsSource = "#version 450\n"
13817 "\n"
13818 "out gl_PerVertex {\n"
13819 " vec4 gl_Position;\n"
13820 "};\n"
13821 "void main(){\n"
13822 " gl_Position = vec4(1);\n"
13823 "}\n";
13824 char const *fsSource = "#version 450\n"
13825 "\n"
13826 "in block { layout(location=0) float x; } ins;\n"
13827 "layout(location=0) out vec4 color;\n"
13828 "void main(){\n"
13829 " color = vec4(ins.x);\n"
13830 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013831
13832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13834
13835 VkPipelineObj pipe(m_device);
13836 pipe.AddColorAttachment();
13837 pipe.AddShader(&vs);
13838 pipe.AddShader(&fs);
13839
13840 VkDescriptorSetObj descriptorSet(m_device);
13841 descriptorSet.AppendDummy();
13842 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13843
13844 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13845
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013846 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013847}
13848
Karl Schultz6addd812016-02-02 17:17:23 -070013849TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013850 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
13851 "across the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13853 "output arr[2] of float32' vs 'ptr to "
13854 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013855
13856 ASSERT_NO_FATAL_FAILURE(InitState());
13857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13858
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 char const *vsSource = "#version 450\n"
13860 "\n"
13861 "layout(location=0) out float x[2];\n"
13862 "out gl_PerVertex {\n"
13863 " vec4 gl_Position;\n"
13864 "};\n"
13865 "void main(){\n"
13866 " x[0] = 0; x[1] = 0;\n"
13867 " gl_Position = vec4(1);\n"
13868 "}\n";
13869 char const *fsSource = "#version 450\n"
13870 "\n"
13871 "layout(location=0) in float x[3];\n"
13872 "layout(location=0) out vec4 color;\n"
13873 "void main(){\n"
13874 " color = vec4(x[0] + x[1] + x[2]);\n"
13875 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013876
13877 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13879
13880 VkPipelineObj pipe(m_device);
13881 pipe.AddColorAttachment();
13882 pipe.AddShader(&vs);
13883 pipe.AddShader(&fs);
13884
13885 VkDescriptorSetObj descriptorSet(m_device);
13886 descriptorSet.AppendDummy();
13887 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13888
13889 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13890
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013891 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013892}
13893
Karl Schultz6addd812016-02-02 17:17:23 -070013894TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013895 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13896 "the VS->FS interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013898
Chris Forbesb56af562015-05-25 11:13:17 +120013899 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013902 char const *vsSource = "#version 450\n"
13903 "\n"
13904 "layout(location=0) out int x;\n"
13905 "out gl_PerVertex {\n"
13906 " vec4 gl_Position;\n"
13907 "};\n"
13908 "void main(){\n"
13909 " x = 0;\n"
13910 " gl_Position = vec4(1);\n"
13911 "}\n";
13912 char const *fsSource = "#version 450\n"
13913 "\n"
13914 "layout(location=0) in float x;\n" /* VS writes int */
13915 "layout(location=0) out vec4 color;\n"
13916 "void main(){\n"
13917 " color = vec4(x);\n"
13918 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013919
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013920 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13921 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013922
13923 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013924 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013925 pipe.AddShader(&vs);
13926 pipe.AddShader(&fs);
13927
Chris Forbesb56af562015-05-25 11:13:17 +120013928 VkDescriptorSetObj descriptorSet(m_device);
13929 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013930 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013931
Tony Barbour5781e8f2015-08-04 16:23:11 -060013932 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013933
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013934 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013935}
13936
Karl Schultz6addd812016-02-02 17:17:23 -070013937TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013938 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
13939 "the VS->FS interface, when the variable is contained within "
13940 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013942
13943 ASSERT_NO_FATAL_FAILURE(InitState());
13944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013946 char const *vsSource = "#version 450\n"
13947 "\n"
13948 "out block { layout(location=0) int x; } outs;\n"
13949 "out gl_PerVertex {\n"
13950 " vec4 gl_Position;\n"
13951 "};\n"
13952 "void main(){\n"
13953 " outs.x = 0;\n"
13954 " gl_Position = vec4(1);\n"
13955 "}\n";
13956 char const *fsSource = "#version 450\n"
13957 "\n"
13958 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13959 "layout(location=0) out vec4 color;\n"
13960 "void main(){\n"
13961 " color = vec4(ins.x);\n"
13962 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013963
13964 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13965 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13966
13967 VkPipelineObj pipe(m_device);
13968 pipe.AddColorAttachment();
13969 pipe.AddShader(&vs);
13970 pipe.AddShader(&fs);
13971
13972 VkDescriptorSetObj descriptorSet(m_device);
13973 descriptorSet.AppendDummy();
13974 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13975
13976 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13977
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013978 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013979}
13980
13981TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013982 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
13983 "the VS->FS interface; This should manifest as a not-written/not-consumed "
13984 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.0 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130013986
13987 ASSERT_NO_FATAL_FAILURE(InitState());
13988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013990 char const *vsSource = "#version 450\n"
13991 "\n"
13992 "out block { layout(location=1) float x; } outs;\n"
13993 "out gl_PerVertex {\n"
13994 " vec4 gl_Position;\n"
13995 "};\n"
13996 "void main(){\n"
13997 " outs.x = 0;\n"
13998 " gl_Position = vec4(1);\n"
13999 "}\n";
14000 char const *fsSource = "#version 450\n"
14001 "\n"
14002 "in block { layout(location=0) float x; } ins;\n"
14003 "layout(location=0) out vec4 color;\n"
14004 "void main(){\n"
14005 " color = vec4(ins.x);\n"
14006 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014007
14008 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14009 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14010
14011 VkPipelineObj pipe(m_device);
14012 pipe.AddColorAttachment();
14013 pipe.AddShader(&vs);
14014 pipe.AddShader(&fs);
14015
14016 VkDescriptorSetObj descriptorSet(m_device);
14017 descriptorSet.AppendDummy();
14018 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14019
14020 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14021
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014022 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014023}
14024
14025TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014026 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
14027 "VS->FS interface. It's not enough to have the same set of locations in "
14028 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0.1 which is not written by vertex shader");
Chris Forbese9928822016-02-17 14:44:52 +130014030
14031 ASSERT_NO_FATAL_FAILURE(InitState());
14032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 char const *vsSource = "#version 450\n"
14035 "\n"
14036 "out block { layout(location=0, component=0) float x; } outs;\n"
14037 "out gl_PerVertex {\n"
14038 " vec4 gl_Position;\n"
14039 "};\n"
14040 "void main(){\n"
14041 " outs.x = 0;\n"
14042 " gl_Position = vec4(1);\n"
14043 "}\n";
14044 char const *fsSource = "#version 450\n"
14045 "\n"
14046 "in block { layout(location=0, component=1) float x; } ins;\n"
14047 "layout(location=0) out vec4 color;\n"
14048 "void main(){\n"
14049 " color = vec4(ins.x);\n"
14050 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014051
14052 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14053 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14054
14055 VkPipelineObj pipe(m_device);
14056 pipe.AddColorAttachment();
14057 pipe.AddShader(&vs);
14058 pipe.AddShader(&fs);
14059
14060 VkDescriptorSetObj descriptorSet(m_device);
14061 descriptorSet.AppendDummy();
14062 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14063
14064 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14065
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014066 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014067}
14068
Karl Schultz6addd812016-02-02 17:17:23 -070014069TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014070 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
14071 "not consumed by the vertex shader");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014073
Chris Forbesde136e02015-05-25 11:13:28 +120014074 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014076
14077 VkVertexInputBindingDescription input_binding;
14078 memset(&input_binding, 0, sizeof(input_binding));
14079
14080 VkVertexInputAttributeDescription input_attrib;
14081 memset(&input_attrib, 0, sizeof(input_attrib));
14082 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 char const *vsSource = "#version 450\n"
14085 "\n"
14086 "out gl_PerVertex {\n"
14087 " vec4 gl_Position;\n"
14088 "};\n"
14089 "void main(){\n"
14090 " gl_Position = vec4(1);\n"
14091 "}\n";
14092 char const *fsSource = "#version 450\n"
14093 "\n"
14094 "layout(location=0) out vec4 color;\n"
14095 "void main(){\n"
14096 " color = vec4(1);\n"
14097 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014098
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014101
14102 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014103 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014104 pipe.AddShader(&vs);
14105 pipe.AddShader(&fs);
14106
14107 pipe.AddVertexInputBindings(&input_binding, 1);
14108 pipe.AddVertexInputAttribs(&input_attrib, 1);
14109
Chris Forbesde136e02015-05-25 11:13:28 +120014110 VkDescriptorSetObj descriptorSet(m_device);
14111 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014112 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014113
Tony Barbour5781e8f2015-08-04 16:23:11 -060014114 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014115
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014116 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014117}
14118
Karl Schultz6addd812016-02-02 17:17:23 -070014119TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014120 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
14121 "vertex attributes. This flushes out bad behavior in the interface walker");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014123
14124 ASSERT_NO_FATAL_FAILURE(InitState());
14125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14126
14127 VkVertexInputBindingDescription input_binding;
14128 memset(&input_binding, 0, sizeof(input_binding));
14129
14130 VkVertexInputAttributeDescription input_attrib;
14131 memset(&input_attrib, 0, sizeof(input_attrib));
14132 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 char const *vsSource = "#version 450\n"
14135 "\n"
14136 "layout(location=1) in float x;\n"
14137 "out gl_PerVertex {\n"
14138 " vec4 gl_Position;\n"
14139 "};\n"
14140 "void main(){\n"
14141 " gl_Position = vec4(x);\n"
14142 "}\n";
14143 char const *fsSource = "#version 450\n"
14144 "\n"
14145 "layout(location=0) out vec4 color;\n"
14146 "void main(){\n"
14147 " color = vec4(1);\n"
14148 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014149
14150 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14151 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14152
14153 VkPipelineObj pipe(m_device);
14154 pipe.AddColorAttachment();
14155 pipe.AddShader(&vs);
14156 pipe.AddShader(&fs);
14157
14158 pipe.AddVertexInputBindings(&input_binding, 1);
14159 pipe.AddVertexInputAttribs(&input_attrib, 1);
14160
14161 VkDescriptorSetObj descriptorSet(m_device);
14162 descriptorSet.AppendDummy();
14163 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14164
14165 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14166
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014167 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014168}
14169
Karl Schultz6addd812016-02-02 17:17:23 -070014170TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014171 TEST_DESCRIPTION("Test that an error is produced for a VS input which is not "
14172 "provided by a vertex attribute");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VS consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014174
Chris Forbes62e8e502015-05-25 11:13:29 +120014175 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014178 char const *vsSource = "#version 450\n"
14179 "\n"
14180 "layout(location=0) in vec4 x;\n" /* not provided */
14181 "out gl_PerVertex {\n"
14182 " vec4 gl_Position;\n"
14183 "};\n"
14184 "void main(){\n"
14185 " gl_Position = x;\n"
14186 "}\n";
14187 char const *fsSource = "#version 450\n"
14188 "\n"
14189 "layout(location=0) out vec4 color;\n"
14190 "void main(){\n"
14191 " color = vec4(1);\n"
14192 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014193
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014194 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14195 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014196
14197 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014198 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014199 pipe.AddShader(&vs);
14200 pipe.AddShader(&fs);
14201
Chris Forbes62e8e502015-05-25 11:13:29 +120014202 VkDescriptorSetObj descriptorSet(m_device);
14203 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014204 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014205
Tony Barbour5781e8f2015-08-04 16:23:11 -060014206 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014207
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014208 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014209}
14210
Karl Schultz6addd812016-02-02 17:17:23 -070014211TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014212 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
14213 "fundamental type (float/int/uint) of an attribute and the "
14214 "VS input that consumes it");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match VS input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014216
Chris Forbesc97d98e2015-05-25 11:13:31 +120014217 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014219
14220 VkVertexInputBindingDescription input_binding;
14221 memset(&input_binding, 0, sizeof(input_binding));
14222
14223 VkVertexInputAttributeDescription input_attrib;
14224 memset(&input_attrib, 0, sizeof(input_attrib));
14225 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014227 char const *vsSource = "#version 450\n"
14228 "\n"
14229 "layout(location=0) in int x;\n" /* attrib provided float */
14230 "out gl_PerVertex {\n"
14231 " vec4 gl_Position;\n"
14232 "};\n"
14233 "void main(){\n"
14234 " gl_Position = vec4(x);\n"
14235 "}\n";
14236 char const *fsSource = "#version 450\n"
14237 "\n"
14238 "layout(location=0) out vec4 color;\n"
14239 "void main(){\n"
14240 " color = vec4(1);\n"
14241 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014242
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014243 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14244 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014245
14246 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014247 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014248 pipe.AddShader(&vs);
14249 pipe.AddShader(&fs);
14250
14251 pipe.AddVertexInputBindings(&input_binding, 1);
14252 pipe.AddVertexInputAttribs(&input_attrib, 1);
14253
Chris Forbesc97d98e2015-05-25 11:13:31 +120014254 VkDescriptorSetObj descriptorSet(m_device);
14255 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014256 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014257
Tony Barbour5781e8f2015-08-04 16:23:11 -060014258 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014260 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014261}
14262
Chris Forbesc68b43c2016-04-06 11:18:47 +120014263TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014264 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
14265 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14267 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014268
14269 ASSERT_NO_FATAL_FAILURE(InitState());
14270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 char const *vsSource = "#version 450\n"
14273 "\n"
14274 "out gl_PerVertex {\n"
14275 " vec4 gl_Position;\n"
14276 "};\n"
14277 "void main(){\n"
14278 " gl_Position = vec4(1);\n"
14279 "}\n";
14280 char const *fsSource = "#version 450\n"
14281 "\n"
14282 "layout(location=0) out vec4 color;\n"
14283 "void main(){\n"
14284 " color = vec4(1);\n"
14285 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014286
14287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14289
14290 VkPipelineObj pipe(m_device);
14291 pipe.AddColorAttachment();
14292 pipe.AddShader(&vs);
14293 pipe.AddShader(&vs);
14294 pipe.AddShader(&fs);
14295
14296 VkDescriptorSetObj descriptorSet(m_device);
14297 descriptorSet.AppendDummy();
14298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14299
14300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14301
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014302 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014303}
14304
Karl Schultz6addd812016-02-02 17:17:23 -070014305TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014306 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
14307 "as vertex attributes");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014308 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014309
14310 ASSERT_NO_FATAL_FAILURE(InitState());
14311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14312
14313 VkVertexInputBindingDescription input_binding;
14314 memset(&input_binding, 0, sizeof(input_binding));
14315
14316 VkVertexInputAttributeDescription input_attribs[2];
14317 memset(input_attribs, 0, sizeof(input_attribs));
14318
14319 for (int i = 0; i < 2; i++) {
14320 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14321 input_attribs[i].location = i;
14322 }
14323
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 char const *vsSource = "#version 450\n"
14325 "\n"
14326 "layout(location=0) in mat2x4 x;\n"
14327 "out gl_PerVertex {\n"
14328 " vec4 gl_Position;\n"
14329 "};\n"
14330 "void main(){\n"
14331 " gl_Position = x[0] + x[1];\n"
14332 "}\n";
14333 char const *fsSource = "#version 450\n"
14334 "\n"
14335 "layout(location=0) out vec4 color;\n"
14336 "void main(){\n"
14337 " color = vec4(1);\n"
14338 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014339
14340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14341 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14342
14343 VkPipelineObj pipe(m_device);
14344 pipe.AddColorAttachment();
14345 pipe.AddShader(&vs);
14346 pipe.AddShader(&fs);
14347
14348 pipe.AddVertexInputBindings(&input_binding, 1);
14349 pipe.AddVertexInputAttribs(input_attribs, 2);
14350
14351 VkDescriptorSetObj descriptorSet(m_device);
14352 descriptorSet.AppendDummy();
14353 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14354
14355 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14356
14357 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014358 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014359}
14360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361TEST_F(VkLayerTest, CreatePipelineAttribArrayType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014362 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130014363
14364 ASSERT_NO_FATAL_FAILURE(InitState());
14365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14366
14367 VkVertexInputBindingDescription input_binding;
14368 memset(&input_binding, 0, sizeof(input_binding));
14369
14370 VkVertexInputAttributeDescription input_attribs[2];
14371 memset(input_attribs, 0, sizeof(input_attribs));
14372
14373 for (int i = 0; i < 2; i++) {
14374 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14375 input_attribs[i].location = i;
14376 }
14377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378 char const *vsSource = "#version 450\n"
14379 "\n"
14380 "layout(location=0) in vec4 x[2];\n"
14381 "out gl_PerVertex {\n"
14382 " vec4 gl_Position;\n"
14383 "};\n"
14384 "void main(){\n"
14385 " gl_Position = x[0] + x[1];\n"
14386 "}\n";
14387 char const *fsSource = "#version 450\n"
14388 "\n"
14389 "layout(location=0) out vec4 color;\n"
14390 "void main(){\n"
14391 " color = vec4(1);\n"
14392 "}\n";
Chris Forbes2682b242015-11-24 11:13:14 +130014393
14394 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14395 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14396
14397 VkPipelineObj pipe(m_device);
14398 pipe.AddColorAttachment();
14399 pipe.AddShader(&vs);
14400 pipe.AddShader(&fs);
14401
14402 pipe.AddVertexInputBindings(&input_binding, 1);
14403 pipe.AddVertexInputAttribs(input_attribs, 2);
14404
14405 VkDescriptorSetObj descriptorSet(m_device);
14406 descriptorSet.AppendDummy();
14407 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14408
14409 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014411 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130014412}
Chris Forbes2682b242015-11-24 11:13:14 +130014413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014414TEST_F(VkLayerTest, CreatePipelineAttribComponents) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014415 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
14416 "through multiple VS inputs, each consuming a different subset of the "
14417 "components.");
Chris Forbesbc290ce2016-07-06 12:01:49 +120014418 m_errorMonitor->ExpectSuccess();
14419
14420 ASSERT_NO_FATAL_FAILURE(InitState());
14421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14422
14423 VkVertexInputBindingDescription input_binding;
14424 memset(&input_binding, 0, sizeof(input_binding));
14425
14426 VkVertexInputAttributeDescription input_attribs[3];
14427 memset(input_attribs, 0, sizeof(input_attribs));
14428
14429 for (int i = 0; i < 3; i++) {
14430 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
14431 input_attribs[i].location = i;
14432 }
14433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014434 char const *vsSource = "#version 450\n"
14435 "\n"
14436 "layout(location=0) in vec4 x;\n"
14437 "layout(location=1) in vec3 y1;\n"
14438 "layout(location=1, component=3) in float y2;\n"
14439 "layout(location=2) in vec4 z;\n"
14440 "out gl_PerVertex {\n"
14441 " vec4 gl_Position;\n"
14442 "};\n"
14443 "void main(){\n"
14444 " gl_Position = x + vec4(y1, y2) + z;\n"
14445 "}\n";
14446 char const *fsSource = "#version 450\n"
14447 "\n"
14448 "layout(location=0) out vec4 color;\n"
14449 "void main(){\n"
14450 " color = vec4(1);\n"
14451 "}\n";
Chris Forbesbc290ce2016-07-06 12:01:49 +120014452
14453 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14454 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14455
14456 VkPipelineObj pipe(m_device);
14457 pipe.AddColorAttachment();
14458 pipe.AddShader(&vs);
14459 pipe.AddShader(&fs);
14460
14461 pipe.AddVertexInputBindings(&input_binding, 1);
14462 pipe.AddVertexInputAttribs(input_attribs, 3);
14463
14464 VkDescriptorSetObj descriptorSet(m_device);
14465 descriptorSet.AppendDummy();
14466 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14467
14468 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14469
14470 m_errorMonitor->VerifyNotFound();
14471}
14472
Chris Forbes82ff92a2016-09-09 10:50:24 +120014473TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
14474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14475 "No entrypoint found named `foo`");
14476
14477 ASSERT_NO_FATAL_FAILURE(InitState());
14478 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14479
14480 char const *vsSource = "#version 450\n"
14481 "out gl_PerVertex {\n"
14482 " vec4 gl_Position;\n"
14483 "};\n"
14484 "void main(){\n"
14485 " gl_Position = vec4(0);\n"
14486 "}\n";
14487 char const *fsSource = "#version 450\n"
14488 "\n"
14489 "layout(location=0) out vec4 color;\n"
14490 "void main(){\n"
14491 " color = vec4(1);\n"
14492 "}\n";
14493
14494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14496
14497 VkPipelineObj pipe(m_device);
14498 pipe.AddColorAttachment();
14499 pipe.AddShader(&vs);
14500 pipe.AddShader(&fs);
14501
14502 VkDescriptorSetObj descriptorSet(m_device);
14503 descriptorSet.AppendDummy();
14504 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14505
14506 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14507
14508 m_errorMonitor->VerifyFound();
14509}
14510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014511TEST_F(VkLayerTest, CreatePipelineSimplePositive) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014512 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014513
14514 ASSERT_NO_FATAL_FAILURE(InitState());
14515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014517 char const *vsSource = "#version 450\n"
14518 "out gl_PerVertex {\n"
14519 " vec4 gl_Position;\n"
14520 "};\n"
14521 "void main(){\n"
14522 " gl_Position = vec4(0);\n"
14523 "}\n";
14524 char const *fsSource = "#version 450\n"
14525 "\n"
14526 "layout(location=0) out vec4 color;\n"
14527 "void main(){\n"
14528 " color = vec4(1);\n"
14529 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014530
14531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14533
14534 VkPipelineObj pipe(m_device);
14535 pipe.AddColorAttachment();
14536 pipe.AddShader(&vs);
14537 pipe.AddShader(&fs);
14538
14539 VkDescriptorSetObj descriptorSet(m_device);
14540 descriptorSet.AppendDummy();
14541 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14542
14543 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14544
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014545 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014546}
14547
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014548TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
14549 m_errorMonitor->SetDesiredFailureMsg(
14550 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14551 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14552 "uses a depth/stencil attachment");
14553
14554 ASSERT_NO_FATAL_FAILURE(InitState());
14555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14556
14557 char const *vsSource = "#version 450\n"
14558 "void main(){ gl_Position = vec4(0); }\n";
14559 char const *fsSource = "#version 450\n"
14560 "\n"
14561 "layout(location=0) out vec4 color;\n"
14562 "void main(){\n"
14563 " color = vec4(1);\n"
14564 "}\n";
14565
14566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14568
14569 VkPipelineObj pipe(m_device);
14570 pipe.AddColorAttachment();
14571 pipe.AddShader(&vs);
14572 pipe.AddShader(&fs);
14573
14574 VkDescriptorSetObj descriptorSet(m_device);
14575 descriptorSet.AppendDummy();
14576 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14577
14578 VkAttachmentDescription attachments[] = {
14579 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
14580 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14581 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14582 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14583 },
14584 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
14585 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14586 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14587 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
14588 },
14589 };
14590 VkAttachmentReference refs[] = {
14591 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
14592 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
14593 };
14594 VkSubpassDescription subpass = {
14595 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
14596 1, &refs[0], nullptr, &refs[1],
14597 0, nullptr
14598 };
14599 VkRenderPassCreateInfo rpci = {
14600 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
14601 0, 2, attachments, 1, &subpass, 0, nullptr
14602 };
14603 VkRenderPass rp;
14604 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14605 ASSERT_VK_SUCCESS(err);
14606
14607 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14608
14609 m_errorMonitor->VerifyFound();
14610
14611 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14612}
14613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014614TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014615 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
14616 "set out in 14.1.3: fundamental type must match, and producer side must "
14617 "have at least as many components");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014618 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120014619
14620 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
14621
14622 ASSERT_NO_FATAL_FAILURE(InitState());
14623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014625 char const *vsSource = "#version 450\n"
14626 "out gl_PerVertex {\n"
14627 " vec4 gl_Position;\n"
14628 "};\n"
14629 "layout(location=0) out vec3 x;\n"
14630 "layout(location=1) out ivec3 y;\n"
14631 "layout(location=2) out vec3 z;\n"
14632 "void main(){\n"
14633 " gl_Position = vec4(0);\n"
14634 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
14635 "}\n";
14636 char const *fsSource = "#version 450\n"
14637 "\n"
14638 "layout(location=0) out vec4 color;\n"
14639 "layout(location=0) in float x;\n"
14640 "layout(location=1) flat in int y;\n"
14641 "layout(location=2) in vec2 z;\n"
14642 "void main(){\n"
14643 " color = vec4(1 + x + y + z.x);\n"
14644 "}\n";
Chris Forbes912c9192016-04-05 17:50:35 +120014645
14646 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14647 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14648
14649 VkPipelineObj pipe(m_device);
14650 pipe.AddColorAttachment();
14651 pipe.AddShader(&vs);
14652 pipe.AddShader(&fs);
14653
14654 VkDescriptorSetObj descriptorSet(m_device);
14655 descriptorSet.AppendDummy();
14656 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14657
Mike Stroyan255e9582016-06-24 09:49:32 -060014658 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Mike Stroyan255e9582016-06-24 09:49:32 -060014660 ASSERT_VK_SUCCESS(err);
14661
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014662 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120014663}
14664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014665TEST_F(VkLayerTest, CreatePipelineTessPerVertex) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014666 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
14667 "passed between the TCS and TES stages");
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014668 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014669
14670 ASSERT_NO_FATAL_FAILURE(InitState());
14671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14672
Chris Forbesc1e852d2016-04-04 19:26:42 +120014673 if (!m_device->phy().features().tessellationShader) {
14674 printf("Device does not support tessellation shaders; skipped.\n");
14675 return;
14676 }
14677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014678 char const *vsSource = "#version 450\n"
14679 "void main(){}\n";
14680 char const *tcsSource = "#version 450\n"
14681 "layout(location=0) out int x[];\n"
14682 "layout(vertices=3) out;\n"
14683 "void main(){\n"
14684 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14685 " gl_TessLevelInner[0] = 1;\n"
14686 " x[gl_InvocationID] = gl_InvocationID;\n"
14687 "}\n";
14688 char const *tesSource = "#version 450\n"
14689 "layout(triangles, equal_spacing, cw) in;\n"
14690 "layout(location=0) in int x[];\n"
14691 "out gl_PerVertex { vec4 gl_Position; };\n"
14692 "void main(){\n"
14693 " gl_Position.xyz = gl_TessCoord;\n"
14694 " gl_Position.w = x[0] + x[1] + x[2];\n"
14695 "}\n";
14696 char const *fsSource = "#version 450\n"
14697 "layout(location=0) out vec4 color;\n"
14698 "void main(){\n"
14699 " color = vec4(1);\n"
14700 "}\n";
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014701
14702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14703 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14704 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014707 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14708 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014710 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesb4cacb62016-04-04 19:15:00 +120014711
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014712 VkPipelineObj pipe(m_device);
14713 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120014714 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014715 pipe.AddColorAttachment();
14716 pipe.AddShader(&vs);
14717 pipe.AddShader(&tcs);
14718 pipe.AddShader(&tes);
14719 pipe.AddShader(&fs);
14720
14721 VkDescriptorSetObj descriptorSet(m_device);
14722 descriptorSet.AppendDummy();
14723 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14724
14725 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14726
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014727 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120014728}
14729
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014730TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014731 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
14732 "interface block passed into the geometry shader. This "
14733 "is interesting because the 'extra' array level is not "
14734 "present on the member type, but on the block instance.");
Chris Forbesa0ab8152016-04-20 13:34:27 +120014735 m_errorMonitor->ExpectSuccess();
14736
14737 ASSERT_NO_FATAL_FAILURE(InitState());
14738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14739
14740 if (!m_device->phy().features().geometryShader) {
14741 printf("Device does not support geometry shaders; skipped.\n");
14742 return;
14743 }
14744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014745 char const *vsSource = "#version 450\n"
14746 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
14747 "void main(){\n"
14748 " vs_out.x = vec4(1);\n"
14749 "}\n";
14750 char const *gsSource = "#version 450\n"
14751 "layout(triangles) in;\n"
14752 "layout(triangle_strip, max_vertices=3) out;\n"
14753 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
14754 "out gl_PerVertex { vec4 gl_Position; };\n"
14755 "void main() {\n"
14756 " gl_Position = gs_in[0].x;\n"
14757 " EmitVertex();\n"
14758 "}\n";
14759 char const *fsSource = "#version 450\n"
14760 "layout(location=0) out vec4 color;\n"
14761 "void main(){\n"
14762 " color = vec4(1);\n"
14763 "}\n";
Chris Forbesa0ab8152016-04-20 13:34:27 +120014764
14765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14766 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
14767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14768
14769 VkPipelineObj pipe(m_device);
14770 pipe.AddColorAttachment();
14771 pipe.AddShader(&vs);
14772 pipe.AddShader(&gs);
14773 pipe.AddShader(&fs);
14774
14775 VkDescriptorSetObj descriptorSet(m_device);
14776 descriptorSet.AppendDummy();
14777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14778
14779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14780
14781 m_errorMonitor->VerifyNotFound();
14782}
14783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014784TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014785 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
14786 "the TCS without the patch decoration, but consumed in the TES "
14787 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
14789 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014790
14791 ASSERT_NO_FATAL_FAILURE(InitState());
14792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14793
Chris Forbesc1e852d2016-04-04 19:26:42 +120014794 if (!m_device->phy().features().tessellationShader) {
14795 printf("Device does not support tessellation shaders; skipped.\n");
14796 return;
14797 }
14798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014799 char const *vsSource = "#version 450\n"
14800 "void main(){}\n";
14801 char const *tcsSource = "#version 450\n"
14802 "layout(location=0) out int x[];\n"
14803 "layout(vertices=3) out;\n"
14804 "void main(){\n"
14805 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14806 " gl_TessLevelInner[0] = 1;\n"
14807 " x[gl_InvocationID] = gl_InvocationID;\n"
14808 "}\n";
14809 char const *tesSource = "#version 450\n"
14810 "layout(triangles, equal_spacing, cw) in;\n"
14811 "layout(location=0) patch in int x;\n"
14812 "out gl_PerVertex { vec4 gl_Position; };\n"
14813 "void main(){\n"
14814 " gl_Position.xyz = gl_TessCoord;\n"
14815 " gl_Position.w = x;\n"
14816 "}\n";
14817 char const *fsSource = "#version 450\n"
14818 "layout(location=0) out vec4 color;\n"
14819 "void main(){\n"
14820 " color = vec4(1);\n"
14821 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014822
14823 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14824 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14825 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14826 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014828 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14829 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014831 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014832
14833 VkPipelineObj pipe(m_device);
14834 pipe.SetInputAssembly(&iasci);
14835 pipe.SetTessellation(&tsci);
14836 pipe.AddColorAttachment();
14837 pipe.AddShader(&vs);
14838 pipe.AddShader(&tcs);
14839 pipe.AddShader(&tes);
14840 pipe.AddShader(&fs);
14841
14842 VkDescriptorSetObj descriptorSet(m_device);
14843 descriptorSet.AppendDummy();
14844 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14845
14846 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14847
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014848 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014849}
14850
Karl Schultz6addd812016-02-02 17:17:23 -070014851TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014852 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
14853 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14855 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014856
Chris Forbes280ba2c2015-06-12 11:16:41 +120014857 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014859
14860 /* Two binding descriptions for binding 0 */
14861 VkVertexInputBindingDescription input_bindings[2];
14862 memset(input_bindings, 0, sizeof(input_bindings));
14863
14864 VkVertexInputAttributeDescription input_attrib;
14865 memset(&input_attrib, 0, sizeof(input_attrib));
14866 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014868 char const *vsSource = "#version 450\n"
14869 "\n"
14870 "layout(location=0) in float x;\n" /* attrib provided float */
14871 "out gl_PerVertex {\n"
14872 " vec4 gl_Position;\n"
14873 "};\n"
14874 "void main(){\n"
14875 " gl_Position = vec4(x);\n"
14876 "}\n";
14877 char const *fsSource = "#version 450\n"
14878 "\n"
14879 "layout(location=0) out vec4 color;\n"
14880 "void main(){\n"
14881 " color = vec4(1);\n"
14882 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014883
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014886
14887 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014888 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014889 pipe.AddShader(&vs);
14890 pipe.AddShader(&fs);
14891
14892 pipe.AddVertexInputBindings(input_bindings, 2);
14893 pipe.AddVertexInputAttribs(&input_attrib, 1);
14894
Chris Forbes280ba2c2015-06-12 11:16:41 +120014895 VkDescriptorSetObj descriptorSet(m_device);
14896 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014897 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014898
Tony Barbour5781e8f2015-08-04 16:23:11 -060014899 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014900
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014901 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014902}
Chris Forbes8f68b562015-05-25 11:13:32 +120014903
Chris Forbes35efec72016-04-21 14:32:08 +120014904TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014905 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
14906 "attributes. This is interesting because they consume multiple "
14907 "locations.");
Chris Forbes35efec72016-04-21 14:32:08 +120014908 m_errorMonitor->ExpectSuccess();
14909
14910 ASSERT_NO_FATAL_FAILURE(InitState());
14911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14912
Chris Forbes91cf3a82016-06-28 17:51:35 +120014913 if (!m_device->phy().features().shaderFloat64) {
Chris Forbes35efec72016-04-21 14:32:08 +120014914 printf("Device does not support 64bit vertex attributes; skipped.\n");
14915 return;
14916 }
14917
14918 VkVertexInputBindingDescription input_bindings[1];
14919 memset(input_bindings, 0, sizeof(input_bindings));
14920
14921 VkVertexInputAttributeDescription input_attribs[4];
14922 memset(input_attribs, 0, sizeof(input_attribs));
14923 input_attribs[0].location = 0;
14924 input_attribs[0].offset = 0;
14925 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14926 input_attribs[1].location = 2;
14927 input_attribs[1].offset = 32;
14928 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14929 input_attribs[2].location = 4;
14930 input_attribs[2].offset = 64;
14931 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14932 input_attribs[3].location = 6;
14933 input_attribs[3].offset = 96;
14934 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
14935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014936 char const *vsSource = "#version 450\n"
14937 "\n"
14938 "layout(location=0) in dmat4 x;\n"
14939 "out gl_PerVertex {\n"
14940 " vec4 gl_Position;\n"
14941 "};\n"
14942 "void main(){\n"
14943 " gl_Position = vec4(x[0][0]);\n"
14944 "}\n";
14945 char const *fsSource = "#version 450\n"
14946 "\n"
14947 "layout(location=0) out vec4 color;\n"
14948 "void main(){\n"
14949 " color = vec4(1);\n"
14950 "}\n";
Chris Forbes35efec72016-04-21 14:32:08 +120014951
14952 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14953 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14954
14955 VkPipelineObj pipe(m_device);
14956 pipe.AddColorAttachment();
14957 pipe.AddShader(&vs);
14958 pipe.AddShader(&fs);
14959
14960 pipe.AddVertexInputBindings(input_bindings, 1);
14961 pipe.AddVertexInputAttribs(input_attribs, 4);
14962
14963 VkDescriptorSetObj descriptorSet(m_device);
14964 descriptorSet.AppendDummy();
14965 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14966
14967 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14968
14969 m_errorMonitor->VerifyNotFound();
14970}
14971
Karl Schultz6addd812016-02-02 17:17:23 -070014972TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014973 TEST_DESCRIPTION("Test that an error is produced for a FS which does not "
14974 "provide an output for one of the pipeline's color attachments");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014976
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014977 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014979 char const *vsSource = "#version 450\n"
14980 "\n"
14981 "out gl_PerVertex {\n"
14982 " vec4 gl_Position;\n"
14983 "};\n"
14984 "void main(){\n"
14985 " gl_Position = vec4(1);\n"
14986 "}\n";
14987 char const *fsSource = "#version 450\n"
14988 "\n"
14989 "void main(){\n"
14990 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014991
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014994
14995 VkPipelineObj pipe(m_device);
14996 pipe.AddShader(&vs);
14997 pipe.AddShader(&fs);
14998
Chia-I Wu08accc62015-07-07 11:50:03 +080014999 /* set up CB 0, not written */
15000 pipe.AddColorAttachment();
15001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015002
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015003 VkDescriptorSetObj descriptorSet(m_device);
15004 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015006
Tony Barbour5781e8f2015-08-04 16:23:11 -060015007 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015008
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015009 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015010}
15011
Karl Schultz6addd812016-02-02 17:17:23 -070015012TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015013 TEST_DESCRIPTION("Test that a warning is produced for a FS which provides a spurious "
15014 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
15016 "FS writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015017
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015018 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015020 char const *vsSource = "#version 450\n"
15021 "\n"
15022 "out gl_PerVertex {\n"
15023 " vec4 gl_Position;\n"
15024 "};\n"
15025 "void main(){\n"
15026 " gl_Position = vec4(1);\n"
15027 "}\n";
15028 char const *fsSource = "#version 450\n"
15029 "\n"
15030 "layout(location=0) out vec4 x;\n"
15031 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15032 "void main(){\n"
15033 " x = vec4(1);\n"
15034 " y = vec4(1);\n"
15035 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015036
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015039
15040 VkPipelineObj pipe(m_device);
15041 pipe.AddShader(&vs);
15042 pipe.AddShader(&fs);
15043
Chia-I Wu08accc62015-07-07 11:50:03 +080015044 /* set up CB 0, not written */
15045 pipe.AddColorAttachment();
15046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015047 /* FS writes CB 1, but we don't configure it */
15048
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015049 VkDescriptorSetObj descriptorSet(m_device);
15050 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015051 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015052
Tony Barbour5781e8f2015-08-04 16:23:11 -060015053 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015054
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015055 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015056}
15057
Karl Schultz6addd812016-02-02 17:17:23 -070015058TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015059 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
15060 "type of an FS output variable, and the format of the corresponding attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015062
Chris Forbesa36d69e2015-05-25 11:13:44 +120015063 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 char const *vsSource = "#version 450\n"
15066 "\n"
15067 "out gl_PerVertex {\n"
15068 " vec4 gl_Position;\n"
15069 "};\n"
15070 "void main(){\n"
15071 " gl_Position = vec4(1);\n"
15072 "}\n";
15073 char const *fsSource = "#version 450\n"
15074 "\n"
15075 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15076 "void main(){\n"
15077 " x = ivec4(1);\n"
15078 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015079
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015082
15083 VkPipelineObj pipe(m_device);
15084 pipe.AddShader(&vs);
15085 pipe.AddShader(&fs);
15086
Chia-I Wu08accc62015-07-07 11:50:03 +080015087 /* set up CB 0; type is UNORM by default */
15088 pipe.AddColorAttachment();
15089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015090
Chris Forbesa36d69e2015-05-25 11:13:44 +120015091 VkDescriptorSetObj descriptorSet(m_device);
15092 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015094
Tony Barbour5781e8f2015-08-04 16:23:11 -060015095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015096
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015097 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015098}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015099
Karl Schultz6addd812016-02-02 17:17:23 -070015100TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015101 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
15102 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015104
Chris Forbes556c76c2015-08-14 12:04:59 +120015105 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015107 char const *vsSource = "#version 450\n"
15108 "\n"
15109 "out gl_PerVertex {\n"
15110 " vec4 gl_Position;\n"
15111 "};\n"
15112 "void main(){\n"
15113 " gl_Position = vec4(1);\n"
15114 "}\n";
15115 char const *fsSource = "#version 450\n"
15116 "\n"
15117 "layout(location=0) out vec4 x;\n"
15118 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15119 "void main(){\n"
15120 " x = vec4(bar.y);\n"
15121 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015122
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015123 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15124 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015125
Chris Forbes556c76c2015-08-14 12:04:59 +120015126 VkPipelineObj pipe(m_device);
15127 pipe.AddShader(&vs);
15128 pipe.AddShader(&fs);
15129
15130 /* set up CB 0; type is UNORM by default */
15131 pipe.AddColorAttachment();
15132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15133
15134 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015135 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015136
15137 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015139 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015140}
15141
Chris Forbes5c59e902016-02-26 16:56:09 +130015142TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015143 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
15144 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015146
15147 ASSERT_NO_FATAL_FAILURE(InitState());
15148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015149 char const *vsSource = "#version 450\n"
15150 "\n"
15151 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15152 "out gl_PerVertex {\n"
15153 " vec4 gl_Position;\n"
15154 "};\n"
15155 "void main(){\n"
15156 " gl_Position = vec4(consts.x);\n"
15157 "}\n";
15158 char const *fsSource = "#version 450\n"
15159 "\n"
15160 "layout(location=0) out vec4 x;\n"
15161 "void main(){\n"
15162 " x = vec4(1);\n"
15163 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015164
15165 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15166 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15167
15168 VkPipelineObj pipe(m_device);
15169 pipe.AddShader(&vs);
15170 pipe.AddShader(&fs);
15171
15172 /* set up CB 0; type is UNORM by default */
15173 pipe.AddColorAttachment();
15174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15175
15176 VkDescriptorSetObj descriptorSet(m_device);
15177 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15178
15179 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15180
15181 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015182 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015183}
15184
Chris Forbes3fb17902016-08-22 14:57:55 +120015185TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
15186 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15187 "which is not included in the subpass description");
15188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15189 "consumes input attachment index 0 but not provided in subpass");
15190
15191 ASSERT_NO_FATAL_FAILURE(InitState());
15192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 char const *vsSource = "#version 450\n"
15194 "\n"
15195 "out gl_PerVertex {\n"
15196 " vec4 gl_Position;\n"
15197 "};\n"
15198 "void main(){\n"
15199 " gl_Position = vec4(1);\n"
15200 "}\n";
15201 char const *fsSource = "#version 450\n"
15202 "\n"
15203 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15204 "layout(location=0) out vec4 color;\n"
15205 "void main() {\n"
15206 " color = subpassLoad(x);\n"
15207 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015208
15209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15211
15212 VkPipelineObj pipe(m_device);
15213 pipe.AddShader(&vs);
15214 pipe.AddShader(&fs);
15215 pipe.AddColorAttachment();
15216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015218 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15219 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015220 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015222 ASSERT_VK_SUCCESS(err);
15223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015224 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015225 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015226 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015227 ASSERT_VK_SUCCESS(err);
15228
15229 // error here.
15230 pipe.CreateVKPipeline(pl, renderPass());
15231
15232 m_errorMonitor->VerifyFound();
15233
15234 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15235 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15236}
15237
Chris Forbes663b5a82016-08-22 16:14:06 +120015238TEST_F(VkLayerTest, CreatePipelineInputAttachmentPositive) {
15239 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
15240 m_errorMonitor->ExpectSuccess();
15241
15242 ASSERT_NO_FATAL_FAILURE(InitState());
15243
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015244 char const *vsSource = "#version 450\n"
15245 "\n"
15246 "out gl_PerVertex {\n"
15247 " vec4 gl_Position;\n"
15248 "};\n"
15249 "void main(){\n"
15250 " gl_Position = vec4(1);\n"
15251 "}\n";
15252 char const *fsSource = "#version 450\n"
15253 "\n"
15254 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15255 "layout(location=0) out vec4 color;\n"
15256 "void main() {\n"
15257 " color = subpassLoad(x);\n"
15258 "}\n";
Chris Forbes663b5a82016-08-22 16:14:06 +120015259
15260 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15261 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15262
15263 VkPipelineObj pipe(m_device);
15264 pipe.AddShader(&vs);
15265 pipe.AddShader(&fs);
15266 pipe.AddColorAttachment();
15267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015269 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15270 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes663b5a82016-08-22 16:14:06 +120015271 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015272 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015273 ASSERT_VK_SUCCESS(err);
15274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015275 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015276 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015277 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes663b5a82016-08-22 16:14:06 +120015278 ASSERT_VK_SUCCESS(err);
15279
15280 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15282 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15283 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15284 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15285 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes663b5a82016-08-22 16:14:06 +120015286 };
15287 VkAttachmentReference color = {
15288 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15289 };
15290 VkAttachmentReference input = {
15291 1, VK_IMAGE_LAYOUT_GENERAL,
15292 };
15293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015294 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015296 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes663b5a82016-08-22 16:14:06 +120015297 VkRenderPass rp;
15298 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15299 ASSERT_VK_SUCCESS(err);
15300
15301 // should be OK. would go wrong here if it's going to...
15302 pipe.CreateVKPipeline(pl, rp);
15303
15304 m_errorMonitor->VerifyNotFound();
15305
15306 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15307 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15308 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15309}
15310
Chris Forbes5a9a0472016-08-22 16:02:09 +120015311TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
15312 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15313 "with a format having a different fundamental type");
15314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15315 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15316
15317 ASSERT_NO_FATAL_FAILURE(InitState());
15318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015319 char const *vsSource = "#version 450\n"
15320 "\n"
15321 "out gl_PerVertex {\n"
15322 " vec4 gl_Position;\n"
15323 "};\n"
15324 "void main(){\n"
15325 " gl_Position = vec4(1);\n"
15326 "}\n";
15327 char const *fsSource = "#version 450\n"
15328 "\n"
15329 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15330 "layout(location=0) out vec4 color;\n"
15331 "void main() {\n"
15332 " color = subpassLoad(x);\n"
15333 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015334
15335 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15336 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15337
15338 VkPipelineObj pipe(m_device);
15339 pipe.AddShader(&vs);
15340 pipe.AddShader(&fs);
15341 pipe.AddColorAttachment();
15342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015344 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15345 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015346 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015347 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015348 ASSERT_VK_SUCCESS(err);
15349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015350 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015351 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015352 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015353 ASSERT_VK_SUCCESS(err);
15354
15355 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015356 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15357 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15358 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15359 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15360 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Chris Forbes5a9a0472016-08-22 16:02:09 +120015361 };
15362 VkAttachmentReference color = {
15363 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15364 };
15365 VkAttachmentReference input = {
15366 1, VK_IMAGE_LAYOUT_GENERAL,
15367 };
15368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015369 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015371 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015372 VkRenderPass rp;
15373 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15374 ASSERT_VK_SUCCESS(err);
15375
15376 // error here.
15377 pipe.CreateVKPipeline(pl, rp);
15378
15379 m_errorMonitor->VerifyFound();
15380
15381 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15382 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15383 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15384}
15385
Chris Forbes541f7b02016-08-22 15:30:27 +120015386TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
15387 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
15388 "which is not included in the subpass description -- array case");
15389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15390 "consumes input attachment index 1 but not provided in subpass");
15391
15392 ASSERT_NO_FATAL_FAILURE(InitState());
15393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015394 char const *vsSource = "#version 450\n"
15395 "\n"
15396 "out gl_PerVertex {\n"
15397 " vec4 gl_Position;\n"
15398 "};\n"
15399 "void main(){\n"
15400 " gl_Position = vec4(1);\n"
15401 "}\n";
15402 char const *fsSource = "#version 450\n"
15403 "\n"
15404 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
15405 "layout(location=0) out vec4 color;\n"
15406 "void main() {\n"
15407 " color = subpassLoad(xs[1]);\n"
15408 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015409
15410 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15411 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15412
15413 VkPipelineObj pipe(m_device);
15414 pipe.AddShader(&vs);
15415 pipe.AddShader(&fs);
15416 pipe.AddColorAttachment();
15417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015419 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15420 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015421 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015422 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015423 ASSERT_VK_SUCCESS(err);
15424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015425 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015426 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015427 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015428 ASSERT_VK_SUCCESS(err);
15429
15430 // error here.
15431 pipe.CreateVKPipeline(pl, renderPass());
15432
15433 m_errorMonitor->VerifyFound();
15434
15435 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15436 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15437}
15438
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015439TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015440 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
15441 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015443
15444 ASSERT_NO_FATAL_FAILURE(InitState());
15445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015446 char const *csSource = "#version 450\n"
15447 "\n"
15448 "layout(local_size_x=1) in;\n"
15449 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15450 "void main(){\n"
15451 " x = vec4(1);\n"
15452 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015453
15454 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15455
15456 VkDescriptorSetObj descriptorSet(m_device);
15457 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015459 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15460 nullptr,
15461 0,
15462 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15463 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15464 descriptorSet.GetPipelineLayout(),
15465 VK_NULL_HANDLE,
15466 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015467
15468 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015469 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015470
15471 m_errorMonitor->VerifyFound();
15472
15473 if (err == VK_SUCCESS) {
15474 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15475 }
15476}
15477
15478TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015479 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
15480 "descriptor-backed resource which is not provided, but the shader does not "
15481 "statically use it. This is interesting because it requires compute pipelines "
15482 "to have a proper descriptor use walk, which they didn't for some time.");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015483 m_errorMonitor->ExpectSuccess();
15484
15485 ASSERT_NO_FATAL_FAILURE(InitState());
15486
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015487 char const *csSource = "#version 450\n"
15488 "\n"
15489 "layout(local_size_x=1) in;\n"
15490 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15491 "void main(){\n"
15492 " // x is not used.\n"
15493 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015494
15495 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15496
15497 VkDescriptorSetObj descriptorSet(m_device);
15498 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015500 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15501 nullptr,
15502 0,
15503 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15504 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15505 descriptorSet.GetPipelineLayout(),
15506 VK_NULL_HANDLE,
15507 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015508
15509 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015510 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015511
15512 m_errorMonitor->VerifyNotFound();
15513
15514 if (err == VK_SUCCESS) {
15515 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15516 }
15517}
15518
Chris Forbes22a9b092016-07-19 14:34:05 +120015519TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015520 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
15521 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15523 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015524
15525 ASSERT_NO_FATAL_FAILURE(InitState());
15526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015527 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15528 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015529 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015530 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015531 ASSERT_VK_SUCCESS(err);
15532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015533 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015534 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015535 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015536 ASSERT_VK_SUCCESS(err);
15537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015538 char const *csSource = "#version 450\n"
15539 "\n"
15540 "layout(local_size_x=1) in;\n"
15541 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15542 "void main() {\n"
15543 " x.x = 1.0f;\n"
15544 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015545 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015547 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15548 nullptr,
15549 0,
15550 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15551 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15552 pl,
15553 VK_NULL_HANDLE,
15554 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015555
15556 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015557 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015558
15559 m_errorMonitor->VerifyFound();
15560
15561 if (err == VK_SUCCESS) {
15562 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15563 }
15564
15565 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15566 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15567}
15568
Chris Forbese10a51f2016-07-19 14:42:51 +120015569TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015570 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15571 "sampler portion of a combined image + sampler");
Chris Forbese10a51f2016-07-19 14:42:51 +120015572 m_errorMonitor->ExpectSuccess();
15573
15574 ASSERT_NO_FATAL_FAILURE(InitState());
15575
15576 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015577 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15578 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15579 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbese10a51f2016-07-19 14:42:51 +120015580 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015581 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbese10a51f2016-07-19 14:42:51 +120015582 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015583 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015584 ASSERT_VK_SUCCESS(err);
15585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015586 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbese10a51f2016-07-19 14:42:51 +120015587 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbese10a51f2016-07-19 14:42:51 +120015589 ASSERT_VK_SUCCESS(err);
15590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015591 char const *csSource = "#version 450\n"
15592 "\n"
15593 "layout(local_size_x=1) in;\n"
15594 "layout(set=0, binding=0) uniform sampler s;\n"
15595 "layout(set=0, binding=1) uniform texture2D t;\n"
15596 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15597 "void main() {\n"
15598 " x = texture(sampler2D(t, s), vec2(0));\n"
15599 "}\n";
Chris Forbese10a51f2016-07-19 14:42:51 +120015600 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015602 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15603 nullptr,
15604 0,
15605 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15606 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15607 pl,
15608 VK_NULL_HANDLE,
15609 -1};
Chris Forbese10a51f2016-07-19 14:42:51 +120015610
15611 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbese10a51f2016-07-19 14:42:51 +120015613
15614 m_errorMonitor->VerifyNotFound();
15615
15616 if (err == VK_SUCCESS) {
15617 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15618 }
15619
15620 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15621 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15622}
15623
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015624TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015625 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
15626 "image portion of a combined image + sampler");
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015627 m_errorMonitor->ExpectSuccess();
15628
15629 ASSERT_NO_FATAL_FAILURE(InitState());
15630
15631 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15633 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15634 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015635 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015636 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015637 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015638 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015639 ASSERT_VK_SUCCESS(err);
15640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015641 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015642 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015643 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015644 ASSERT_VK_SUCCESS(err);
15645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015646 char const *csSource = "#version 450\n"
15647 "\n"
15648 "layout(local_size_x=1) in;\n"
15649 "layout(set=0, binding=0) uniform texture2D t;\n"
15650 "layout(set=0, binding=1) uniform sampler s;\n"
15651 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
15652 "void main() {\n"
15653 " x = texture(sampler2D(t, s), vec2(0));\n"
15654 "}\n";
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015655 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015657 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15658 nullptr,
15659 0,
15660 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15661 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15662 pl,
15663 VK_NULL_HANDLE,
15664 -1};
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015665
15666 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015667 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes91c3b2a2016-07-19 14:46:38 +120015668
15669 m_errorMonitor->VerifyNotFound();
15670
15671 if (err == VK_SUCCESS) {
15672 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15673 }
15674
15675 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15676 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15677}
15678
Chris Forbes6a4991a2016-07-19 15:07:32 +120015679TEST_F(VkLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Chris Forbes1cc79542016-07-20 11:13:44 +120015680 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
15681 "both the sampler and the image of a combined image+sampler "
15682 "but via separate variables");
Chris Forbes6a4991a2016-07-19 15:07:32 +120015683 m_errorMonitor->ExpectSuccess();
15684
15685 ASSERT_NO_FATAL_FAILURE(InitState());
15686
15687 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015688 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
15689 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Chris Forbes6a4991a2016-07-19 15:07:32 +120015690 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015692 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015694 ASSERT_VK_SUCCESS(err);
15695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015696 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015697 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015698 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015699 ASSERT_VK_SUCCESS(err);
15700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015701 char const *csSource = "#version 450\n"
15702 "\n"
15703 "layout(local_size_x=1) in;\n"
15704 "layout(set=0, binding=0) uniform texture2D t;\n"
15705 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
15706 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
15707 "void main() {\n"
15708 " x = texture(sampler2D(t, s), vec2(0));\n"
15709 "}\n";
Chris Forbes6a4991a2016-07-19 15:07:32 +120015710 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015712 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15713 nullptr,
15714 0,
15715 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15716 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15717 pl,
15718 VK_NULL_HANDLE,
15719 -1};
Chris Forbes6a4991a2016-07-19 15:07:32 +120015720
15721 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015722 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes6a4991a2016-07-19 15:07:32 +120015723
15724 m_errorMonitor->VerifyNotFound();
15725
15726 if (err == VK_SUCCESS) {
15727 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15728 }
15729
15730 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15731 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15732}
15733
Chris Forbes50020592016-07-27 13:52:41 +120015734TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
15735 TEST_DESCRIPTION("Test that an error is produced when an image view type "
15736 "does not match the dimensionality declared in the shader");
15737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires an image view of type VK_IMAGE_VIEW_TYPE_3D");
Chris Forbes50020592016-07-27 13:52:41 +120015739
15740 ASSERT_NO_FATAL_FAILURE(InitState());
15741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015743 char const *vsSource = "#version 450\n"
15744 "\n"
15745 "out gl_PerVertex { vec4 gl_Position; };\n"
15746 "void main() { gl_Position = vec4(0); }\n";
15747 char const *fsSource = "#version 450\n"
15748 "\n"
15749 "layout(set=0, binding=0) uniform sampler3D s;\n"
15750 "layout(location=0) out vec4 color;\n"
15751 "void main() {\n"
15752 " color = texture(s, vec3(0));\n"
15753 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015754 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15755 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15756
15757 VkPipelineObj pipe(m_device);
15758 pipe.AddShader(&vs);
15759 pipe.AddShader(&fs);
15760 pipe.AddColorAttachment();
15761
15762 VkTextureObj texture(m_device, nullptr);
15763 VkSamplerObj sampler(m_device);
15764
15765 VkDescriptorSetObj descriptorSet(m_device);
15766 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15767 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15768
15769 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15770 ASSERT_VK_SUCCESS(err);
15771
15772 BeginCommandBuffer();
15773
15774 m_commandBuffer->BindPipeline(pipe);
15775 m_commandBuffer->BindDescriptorSet(descriptorSet);
15776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015777 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015778 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015779 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015780 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15781
15782 // error produced here.
15783 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15784
15785 m_errorMonitor->VerifyFound();
15786
15787 EndCommandBuffer();
15788}
15789
Chris Forbes5533bfc2016-07-27 14:12:34 +120015790TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
15791 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
15792 "are consumed via singlesample images types in the shader, or vice versa.");
15793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015795
15796 ASSERT_NO_FATAL_FAILURE(InitState());
15797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015799 char const *vsSource = "#version 450\n"
15800 "\n"
15801 "out gl_PerVertex { vec4 gl_Position; };\n"
15802 "void main() { gl_Position = vec4(0); }\n";
15803 char const *fsSource = "#version 450\n"
15804 "\n"
15805 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15806 "layout(location=0) out vec4 color;\n"
15807 "void main() {\n"
15808 " color = texelFetch(s, ivec2(0), 0);\n"
15809 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15812
15813 VkPipelineObj pipe(m_device);
15814 pipe.AddShader(&vs);
15815 pipe.AddShader(&fs);
15816 pipe.AddColorAttachment();
15817
15818 VkTextureObj texture(m_device, nullptr);
15819 VkSamplerObj sampler(m_device);
15820
15821 VkDescriptorSetObj descriptorSet(m_device);
15822 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15823 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15824
15825 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15826 ASSERT_VK_SUCCESS(err);
15827
15828 BeginCommandBuffer();
15829
15830 m_commandBuffer->BindPipeline(pipe);
15831 m_commandBuffer->BindDescriptorSet(descriptorSet);
15832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015833 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015834 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015835 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015836 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15837
15838 // error produced here.
15839 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15840
15841 m_errorMonitor->VerifyFound();
15842
15843 EndCommandBuffer();
15844}
15845
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015846#endif // SHADER_CHECKER_TESTS
15847
15848#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060015849TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015851
15852 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015853
15854 // Create an image
15855 VkImage image;
15856
Karl Schultz6addd812016-02-02 17:17:23 -070015857 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15858 const int32_t tex_width = 32;
15859 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015860
15861 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015862 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15863 image_create_info.pNext = NULL;
15864 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15865 image_create_info.format = tex_format;
15866 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015867 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015868 image_create_info.extent.depth = 1;
15869 image_create_info.mipLevels = 1;
15870 image_create_info.arrayLayers = 1;
15871 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15872 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15873 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15874 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015875
15876 // Introduce error by sending down a bogus width extent
15877 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015878 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015879
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015880 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015881}
15882
Mark Youngc48c4c12016-04-11 14:26:49 -060015883TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15885 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060015886
15887 ASSERT_NO_FATAL_FAILURE(InitState());
15888
15889 // Create an image
15890 VkImage image;
15891
15892 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15893 const int32_t tex_width = 32;
15894 const int32_t tex_height = 32;
15895
15896 VkImageCreateInfo image_create_info = {};
15897 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15898 image_create_info.pNext = NULL;
15899 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15900 image_create_info.format = tex_format;
15901 image_create_info.extent.width = tex_width;
15902 image_create_info.extent.height = tex_height;
15903 image_create_info.extent.depth = 1;
15904 image_create_info.mipLevels = 1;
15905 image_create_info.arrayLayers = 1;
15906 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15907 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15908 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15909 image_create_info.flags = 0;
15910
15911 // Introduce error by sending down a bogus width extent
15912 image_create_info.extent.width = 0;
15913 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15914
15915 m_errorMonitor->VerifyFound();
15916}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060015917#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120015918
Tobin Ehliscde08892015-09-22 10:11:37 -060015919#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015920TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
15921 TEST_DESCRIPTION("Create a render pass with an attachment description "
15922 "format set to VK_FORMAT_UNDEFINED");
15923
15924 ASSERT_NO_FATAL_FAILURE(InitState());
15925 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015928
15929 VkAttachmentReference color_attach = {};
15930 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15931 color_attach.attachment = 0;
15932 VkSubpassDescription subpass = {};
15933 subpass.colorAttachmentCount = 1;
15934 subpass.pColorAttachments = &color_attach;
15935
15936 VkRenderPassCreateInfo rpci = {};
15937 rpci.subpassCount = 1;
15938 rpci.pSubpasses = &subpass;
15939 rpci.attachmentCount = 1;
15940 VkAttachmentDescription attach_desc = {};
15941 attach_desc.format = VK_FORMAT_UNDEFINED;
15942 rpci.pAttachments = &attach_desc;
15943 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15944 VkRenderPass rp;
15945 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15946
15947 m_errorMonitor->VerifyFound();
15948
15949 if (result == VK_SUCCESS) {
15950 vkDestroyRenderPass(m_device->device(), rp, NULL);
15951 }
15952}
15953
Karl Schultz6addd812016-02-02 17:17:23 -070015954TEST_F(VkLayerTest, InvalidImageView) {
15955 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015958
Tobin Ehliscde08892015-09-22 10:11:37 -060015959 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015960
Mike Stroyana3082432015-09-25 13:39:21 -060015961 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015962 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015963
Karl Schultz6addd812016-02-02 17:17:23 -070015964 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15965 const int32_t tex_width = 32;
15966 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015967
15968 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015969 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15970 image_create_info.pNext = NULL;
15971 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15972 image_create_info.format = tex_format;
15973 image_create_info.extent.width = tex_width;
15974 image_create_info.extent.height = tex_height;
15975 image_create_info.extent.depth = 1;
15976 image_create_info.mipLevels = 1;
15977 image_create_info.arrayLayers = 1;
15978 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15979 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15980 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15981 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015982
Chia-I Wuf7458c52015-10-26 21:10:41 +080015983 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015984 ASSERT_VK_SUCCESS(err);
15985
15986 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015987 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15988 image_view_create_info.image = image;
15989 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15990 image_view_create_info.format = tex_format;
15991 image_view_create_info.subresourceRange.layerCount = 1;
15992 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
15993 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015994 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015995
15996 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015997 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015998
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015999 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060016000 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016001}
Mike Stroyana3082432015-09-25 13:39:21 -060016002
Mark Youngd339ba32016-05-30 13:28:35 -060016003TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16004 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016006 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016007
16008 ASSERT_NO_FATAL_FAILURE(InitState());
16009
16010 // Create an image and try to create a view with no memory backing the image
16011 VkImage image;
16012
16013 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16014 const int32_t tex_width = 32;
16015 const int32_t tex_height = 32;
16016
16017 VkImageCreateInfo image_create_info = {};
16018 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16019 image_create_info.pNext = NULL;
16020 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16021 image_create_info.format = tex_format;
16022 image_create_info.extent.width = tex_width;
16023 image_create_info.extent.height = tex_height;
16024 image_create_info.extent.depth = 1;
16025 image_create_info.mipLevels = 1;
16026 image_create_info.arrayLayers = 1;
16027 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16028 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16029 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16030 image_create_info.flags = 0;
16031
16032 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16033 ASSERT_VK_SUCCESS(err);
16034
16035 VkImageViewCreateInfo image_view_create_info = {};
16036 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16037 image_view_create_info.image = image;
16038 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16039 image_view_create_info.format = tex_format;
16040 image_view_create_info.subresourceRange.layerCount = 1;
16041 image_view_create_info.subresourceRange.baseMipLevel = 0;
16042 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016043 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016044
16045 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016046 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016047
16048 m_errorMonitor->VerifyFound();
16049 vkDestroyImage(m_device->device(), image, NULL);
16050 // If last error is success, it still created the view, so delete it.
16051 if (err == VK_SUCCESS) {
16052 vkDestroyImageView(m_device->device(), view, NULL);
16053 }
Mark Youngd339ba32016-05-30 13:28:35 -060016054}
16055
Karl Schultz6addd812016-02-02 17:17:23 -070016056TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016057 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
16058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
16059 "formats must have ONLY the "
16060 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016061
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016063
Karl Schultz6addd812016-02-02 17:17:23 -070016064 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016065 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016066 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016067 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016068
16069 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016070 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016071 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016072 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16073 image_view_create_info.format = tex_format;
16074 image_view_create_info.subresourceRange.baseMipLevel = 0;
16075 image_view_create_info.subresourceRange.levelCount = 1;
16076 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016077 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016078
16079 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016080 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016081
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016082 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016083}
16084
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016085TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016086 VkResult err;
16087 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16090 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016091
Mike Stroyana3082432015-09-25 13:39:21 -060016092 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016093
16094 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016095 VkImage srcImage;
16096 VkImage dstImage;
16097 VkDeviceMemory srcMem;
16098 VkDeviceMemory destMem;
16099 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016100
16101 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016102 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16103 image_create_info.pNext = NULL;
16104 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16105 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16106 image_create_info.extent.width = 32;
16107 image_create_info.extent.height = 32;
16108 image_create_info.extent.depth = 1;
16109 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016110 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016111 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16112 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16113 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16114 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016116 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016117 ASSERT_VK_SUCCESS(err);
16118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016119 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016120 ASSERT_VK_SUCCESS(err);
16121
16122 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016123 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016124 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16125 memAlloc.pNext = NULL;
16126 memAlloc.allocationSize = 0;
16127 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016128
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016129 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016130 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016131 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016132 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016133 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016134 ASSERT_VK_SUCCESS(err);
16135
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016136 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016137 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016138 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016139 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016140 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016141 ASSERT_VK_SUCCESS(err);
16142
16143 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16144 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016145 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016146 ASSERT_VK_SUCCESS(err);
16147
16148 BeginCommandBuffer();
16149 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016150 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016151 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016152 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016153 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016154 copyRegion.srcOffset.x = 0;
16155 copyRegion.srcOffset.y = 0;
16156 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016157 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016158 copyRegion.dstSubresource.mipLevel = 0;
16159 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016160 // Introduce failure by forcing the dst layerCount to differ from src
16161 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016162 copyRegion.dstOffset.x = 0;
16163 copyRegion.dstOffset.y = 0;
16164 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016165 copyRegion.extent.width = 1;
16166 copyRegion.extent.height = 1;
16167 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016168 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016169 EndCommandBuffer();
16170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016171 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016172
Chia-I Wuf7458c52015-10-26 21:10:41 +080016173 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016174 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016175 vkFreeMemory(m_device->device(), srcMem, NULL);
16176 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016177}
16178
Tony Barbourd6673642016-05-05 14:46:39 -060016179TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
16180
16181 TEST_DESCRIPTION("Creating images with unsuported formats ");
16182
16183 ASSERT_NO_FATAL_FAILURE(InitState());
16184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16185 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016186 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060016187 VK_IMAGE_TILING_OPTIMAL, 0);
16188 ASSERT_TRUE(image.initialized());
16189
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016190 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
16191 VkImageCreateInfo image_create_info;
16192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16193 image_create_info.pNext = NULL;
16194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16195 image_create_info.format = VK_FORMAT_UNDEFINED;
16196 image_create_info.extent.width = 32;
16197 image_create_info.extent.height = 32;
16198 image_create_info.extent.depth = 1;
16199 image_create_info.mipLevels = 1;
16200 image_create_info.arrayLayers = 1;
16201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16202 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16203 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16204 image_create_info.flags = 0;
16205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16207 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016208
16209 VkImage localImage;
16210 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
16211 m_errorMonitor->VerifyFound();
16212
Tony Barbourd6673642016-05-05 14:46:39 -060016213 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016214 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060016215 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16216 VkFormat format = static_cast<VkFormat>(f);
16217 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016218 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016219 unsupported = format;
16220 break;
16221 }
16222 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016223
Tony Barbourd6673642016-05-05 14:46:39 -060016224 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016225 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016227
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016228 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016229 m_errorMonitor->VerifyFound();
16230 }
16231}
16232
16233TEST_F(VkLayerTest, ImageLayerViewTests) {
16234 VkResult ret;
16235 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16236
16237 ASSERT_NO_FATAL_FAILURE(InitState());
16238
16239 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016240 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060016241 VK_IMAGE_TILING_OPTIMAL, 0);
16242 ASSERT_TRUE(image.initialized());
16243
16244 VkImageView imgView;
16245 VkImageViewCreateInfo imgViewInfo = {};
16246 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16247 imgViewInfo.image = image.handle();
16248 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16249 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16250 imgViewInfo.subresourceRange.layerCount = 1;
16251 imgViewInfo.subresourceRange.baseMipLevel = 0;
16252 imgViewInfo.subresourceRange.levelCount = 1;
16253 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060016256 // View can't have baseMipLevel >= image's mipLevels - Expect
16257 // VIEW_CREATE_ERROR
16258 imgViewInfo.subresourceRange.baseMipLevel = 1;
16259 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16260 m_errorMonitor->VerifyFound();
16261 imgViewInfo.subresourceRange.baseMipLevel = 0;
16262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060016264 // View can't have baseArrayLayer >= image's arraySize - Expect
16265 // VIEW_CREATE_ERROR
16266 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16267 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16268 m_errorMonitor->VerifyFound();
16269 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16272 "pCreateInfo->subresourceRange."
16273 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016274 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16275 imgViewInfo.subresourceRange.levelCount = 0;
16276 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16277 m_errorMonitor->VerifyFound();
16278 imgViewInfo.subresourceRange.levelCount = 1;
16279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
16281 "pCreateInfo->subresourceRange."
16282 "layerCount");
Tony Barbourd6673642016-05-05 14:46:39 -060016283 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16284 imgViewInfo.subresourceRange.layerCount = 0;
16285 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16286 m_errorMonitor->VerifyFound();
16287 imgViewInfo.subresourceRange.layerCount = 1;
16288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tony Barbourd6673642016-05-05 14:46:39 -060016290 // Can't use depth format for view into color image - Expect INVALID_FORMAT
16291 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
16292 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16293 m_errorMonitor->VerifyFound();
16294 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
16297 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16298 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016299 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16300 // VIEW_CREATE_ERROR
16301 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16302 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16303 m_errorMonitor->VerifyFound();
16304 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
16307 "differing formats but they must be "
16308 "in the same compatibility class.");
Tony Barbourd6673642016-05-05 14:46:39 -060016309 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16310 // VIEW_CREATE_ERROR
16311 VkImageCreateInfo mutImgInfo = image.create_info();
16312 VkImage mutImage;
16313 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016314 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016315 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16316 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16317 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16318 ASSERT_VK_SUCCESS(ret);
16319 imgViewInfo.image = mutImage;
16320 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16321 m_errorMonitor->VerifyFound();
16322 imgViewInfo.image = image.handle();
16323 vkDestroyImage(m_device->handle(), mutImage, NULL);
16324}
16325
16326TEST_F(VkLayerTest, MiscImageLayerTests) {
16327
16328 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
16329
16330 ASSERT_NO_FATAL_FAILURE(InitState());
16331
16332 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016333 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060016334 VK_IMAGE_TILING_OPTIMAL, 0);
16335 ASSERT_TRUE(image.initialized());
16336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060016338 vk_testing::Buffer buffer;
16339 VkMemoryPropertyFlags reqs = 0;
16340 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
16341 VkBufferImageCopy region = {};
16342 region.bufferRowLength = 128;
16343 region.bufferImageHeight = 128;
16344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16345 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16346 region.imageSubresource.layerCount = 0;
16347 region.imageExtent.height = 4;
16348 region.imageExtent.width = 4;
16349 region.imageExtent.depth = 1;
16350 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016351 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16352 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016353 m_errorMonitor->VerifyFound();
16354 region.imageSubresource.layerCount = 1;
16355
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016356 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16357 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
16358 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
16360 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16361 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016362 m_errorMonitor->VerifyFound();
16363
16364 // BufferOffset must be a multiple of 4
16365 // Introduce failure by setting bufferOffset to a value not divisible by 4
16366 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
16368 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16369 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016370 m_errorMonitor->VerifyFound();
16371
16372 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16373 region.bufferOffset = 0;
16374 region.imageExtent.height = 128;
16375 region.imageExtent.width = 128;
16376 // Introduce failure by setting bufferRowLength > 0 but less than width
16377 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16379 "must be zero or greater-than-or-equal-to imageExtent.width");
16380 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16381 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016382 m_errorMonitor->VerifyFound();
16383
16384 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16385 region.bufferRowLength = 128;
16386 // Introduce failure by setting bufferRowHeight > 0 but less than height
16387 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16389 "must be zero or greater-than-or-equal-to imageExtent.height");
16390 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16391 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016392 m_errorMonitor->VerifyFound();
16393
16394 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
16396 "specify only COLOR or DEPTH or "
16397 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060016398 // Expect MISMATCHED_IMAGE_ASPECT
16399 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016400 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16401 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060016402 m_errorMonitor->VerifyFound();
16403 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16406 "If the format of srcImage is a depth, stencil, depth stencil or "
16407 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060016408 // Expect INVALID_FILTER
16409 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016410 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016411 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016412 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016413 VkImageBlit blitRegion = {};
16414 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16415 blitRegion.srcSubresource.baseArrayLayer = 0;
16416 blitRegion.srcSubresource.layerCount = 1;
16417 blitRegion.srcSubresource.mipLevel = 0;
16418 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16419 blitRegion.dstSubresource.baseArrayLayer = 0;
16420 blitRegion.dstSubresource.layerCount = 1;
16421 blitRegion.dstSubresource.mipLevel = 0;
16422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16424 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060016425 m_errorMonitor->VerifyFound();
16426
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016427 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
16429 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16430 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016431 m_errorMonitor->VerifyFound();
16432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060016434 VkImageMemoryBarrier img_barrier;
16435 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16436 img_barrier.pNext = NULL;
16437 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16438 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16439 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16440 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16441 img_barrier.image = image.handle();
16442 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16443 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16444 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16445 img_barrier.subresourceRange.baseArrayLayer = 0;
16446 img_barrier.subresourceRange.baseMipLevel = 0;
16447 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
16448 img_barrier.subresourceRange.layerCount = 0;
16449 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016450 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16451 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016452 m_errorMonitor->VerifyFound();
16453 img_barrier.subresourceRange.layerCount = 1;
16454}
16455
16456TEST_F(VkLayerTest, ImageFormatLimits) {
16457
16458 TEST_DESCRIPTION("Exceed the limits of image format ");
16459
Cody Northropc31a84f2016-08-22 10:41:47 -060016460 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016462 VkImageCreateInfo image_create_info = {};
16463 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16464 image_create_info.pNext = NULL;
16465 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16466 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16467 image_create_info.extent.width = 32;
16468 image_create_info.extent.height = 32;
16469 image_create_info.extent.depth = 1;
16470 image_create_info.mipLevels = 1;
16471 image_create_info.arrayLayers = 1;
16472 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16473 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16474 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16475 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16476 image_create_info.flags = 0;
16477
16478 VkImage nullImg;
16479 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016480 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16481 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060016482 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
16483 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16484 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16485 m_errorMonitor->VerifyFound();
16486 image_create_info.extent.depth = 1;
16487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016489 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16490 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16491 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16492 m_errorMonitor->VerifyFound();
16493 image_create_info.mipLevels = 1;
16494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016496 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16497 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16498 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16499 m_errorMonitor->VerifyFound();
16500 image_create_info.arrayLayers = 1;
16501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016503 int samples = imgFmtProps.sampleCounts >> 1;
16504 image_create_info.samples = (VkSampleCountFlagBits)samples;
16505 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16506 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16507 m_errorMonitor->VerifyFound();
16508 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
16511 "VK_IMAGE_LAYOUT_UNDEFINED or "
16512 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016513 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16514 // Expect INVALID_LAYOUT
16515 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16516 m_errorMonitor->VerifyFound();
16517 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16518}
16519
Karl Schultz6addd812016-02-02 17:17:23 -070016520TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016521 VkResult err;
16522 bool pass;
16523
16524 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16526 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060016527
16528 ASSERT_NO_FATAL_FAILURE(InitState());
16529
16530 // Create two images of different types and try to copy between them
16531 VkImage srcImage;
16532 VkImage dstImage;
16533 VkDeviceMemory srcMem;
16534 VkDeviceMemory destMem;
16535 VkMemoryRequirements memReqs;
16536
16537 VkImageCreateInfo image_create_info = {};
16538 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16539 image_create_info.pNext = NULL;
16540 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16541 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16542 image_create_info.extent.width = 32;
16543 image_create_info.extent.height = 32;
16544 image_create_info.extent.depth = 1;
16545 image_create_info.mipLevels = 1;
16546 image_create_info.arrayLayers = 1;
16547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16548 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16549 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16550 image_create_info.flags = 0;
16551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016552 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016553 ASSERT_VK_SUCCESS(err);
16554
16555 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16556 // Introduce failure by creating second image with a different-sized format.
16557 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016559 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016560 ASSERT_VK_SUCCESS(err);
16561
16562 // Allocate memory
16563 VkMemoryAllocateInfo memAlloc = {};
16564 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16565 memAlloc.pNext = NULL;
16566 memAlloc.allocationSize = 0;
16567 memAlloc.memoryTypeIndex = 0;
16568
16569 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16570 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016571 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016572 ASSERT_TRUE(pass);
16573 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16574 ASSERT_VK_SUCCESS(err);
16575
16576 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16577 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016578 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016579 ASSERT_TRUE(pass);
16580 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16581 ASSERT_VK_SUCCESS(err);
16582
16583 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16584 ASSERT_VK_SUCCESS(err);
16585 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16586 ASSERT_VK_SUCCESS(err);
16587
16588 BeginCommandBuffer();
16589 VkImageCopy copyRegion;
16590 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16591 copyRegion.srcSubresource.mipLevel = 0;
16592 copyRegion.srcSubresource.baseArrayLayer = 0;
16593 copyRegion.srcSubresource.layerCount = 0;
16594 copyRegion.srcOffset.x = 0;
16595 copyRegion.srcOffset.y = 0;
16596 copyRegion.srcOffset.z = 0;
16597 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16598 copyRegion.dstSubresource.mipLevel = 0;
16599 copyRegion.dstSubresource.baseArrayLayer = 0;
16600 copyRegion.dstSubresource.layerCount = 0;
16601 copyRegion.dstOffset.x = 0;
16602 copyRegion.dstOffset.y = 0;
16603 copyRegion.dstOffset.z = 0;
16604 copyRegion.extent.width = 1;
16605 copyRegion.extent.height = 1;
16606 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016607 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060016608 EndCommandBuffer();
16609
16610 m_errorMonitor->VerifyFound();
16611
16612 vkDestroyImage(m_device->device(), srcImage, NULL);
16613 vkDestroyImage(m_device->device(), dstImage, NULL);
16614 vkFreeMemory(m_device->device(), srcMem, NULL);
16615 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016616}
16617
Karl Schultz6addd812016-02-02 17:17:23 -070016618TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16619 VkResult err;
16620 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016621
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016622 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16624 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016625
Mike Stroyana3082432015-09-25 13:39:21 -060016626 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016627
16628 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016629 VkImage srcImage;
16630 VkImage dstImage;
16631 VkDeviceMemory srcMem;
16632 VkDeviceMemory destMem;
16633 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016634
16635 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016636 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16637 image_create_info.pNext = NULL;
16638 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16639 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16640 image_create_info.extent.width = 32;
16641 image_create_info.extent.height = 32;
16642 image_create_info.extent.depth = 1;
16643 image_create_info.mipLevels = 1;
16644 image_create_info.arrayLayers = 1;
16645 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16646 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16647 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16648 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016650 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016651 ASSERT_VK_SUCCESS(err);
16652
Karl Schultzbdb75952016-04-19 11:36:49 -060016653 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16654
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016655 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016656 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016657 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16658 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016660 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016661 ASSERT_VK_SUCCESS(err);
16662
16663 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016664 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016665 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16666 memAlloc.pNext = NULL;
16667 memAlloc.allocationSize = 0;
16668 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016669
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016670 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016671 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016673 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016674 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016675 ASSERT_VK_SUCCESS(err);
16676
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016677 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016678 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016679 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016680 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016682 ASSERT_VK_SUCCESS(err);
16683
16684 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16685 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016686 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016687 ASSERT_VK_SUCCESS(err);
16688
16689 BeginCommandBuffer();
16690 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016691 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016692 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016693 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016694 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016695 copyRegion.srcOffset.x = 0;
16696 copyRegion.srcOffset.y = 0;
16697 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016698 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016699 copyRegion.dstSubresource.mipLevel = 0;
16700 copyRegion.dstSubresource.baseArrayLayer = 0;
16701 copyRegion.dstSubresource.layerCount = 0;
16702 copyRegion.dstOffset.x = 0;
16703 copyRegion.dstOffset.y = 0;
16704 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016705 copyRegion.extent.width = 1;
16706 copyRegion.extent.height = 1;
16707 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016708 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016709 EndCommandBuffer();
16710
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016711 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016712
Chia-I Wuf7458c52015-10-26 21:10:41 +080016713 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016714 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016715 vkFreeMemory(m_device->device(), srcMem, NULL);
16716 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016717}
16718
Karl Schultz6addd812016-02-02 17:17:23 -070016719TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16720 VkResult err;
16721 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16724 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016725
Mike Stroyana3082432015-09-25 13:39:21 -060016726 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016727
16728 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016729 VkImage srcImage;
16730 VkImage dstImage;
16731 VkDeviceMemory srcMem;
16732 VkDeviceMemory destMem;
16733 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016734
16735 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016736 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16737 image_create_info.pNext = NULL;
16738 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16739 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16740 image_create_info.extent.width = 32;
16741 image_create_info.extent.height = 1;
16742 image_create_info.extent.depth = 1;
16743 image_create_info.mipLevels = 1;
16744 image_create_info.arrayLayers = 1;
16745 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16746 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16747 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16748 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016749
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016750 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016751 ASSERT_VK_SUCCESS(err);
16752
Karl Schultz6addd812016-02-02 17:17:23 -070016753 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016756 ASSERT_VK_SUCCESS(err);
16757
16758 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016759 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016760 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16761 memAlloc.pNext = NULL;
16762 memAlloc.allocationSize = 0;
16763 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016764
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016765 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016766 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016767 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016768 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016769 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016770 ASSERT_VK_SUCCESS(err);
16771
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016772 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016773 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016774 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016775 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016776 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016777 ASSERT_VK_SUCCESS(err);
16778
16779 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16780 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016781 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016782 ASSERT_VK_SUCCESS(err);
16783
16784 BeginCommandBuffer();
16785 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016786 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16787 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016788 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016789 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016790 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016791 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016792 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016793 resolveRegion.srcOffset.x = 0;
16794 resolveRegion.srcOffset.y = 0;
16795 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016796 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016797 resolveRegion.dstSubresource.mipLevel = 0;
16798 resolveRegion.dstSubresource.baseArrayLayer = 0;
16799 resolveRegion.dstSubresource.layerCount = 0;
16800 resolveRegion.dstOffset.x = 0;
16801 resolveRegion.dstOffset.y = 0;
16802 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016803 resolveRegion.extent.width = 1;
16804 resolveRegion.extent.height = 1;
16805 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016806 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016807 EndCommandBuffer();
16808
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016809 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016810
Chia-I Wuf7458c52015-10-26 21:10:41 +080016811 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016812 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016813 vkFreeMemory(m_device->device(), srcMem, NULL);
16814 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016815}
16816
Karl Schultz6addd812016-02-02 17:17:23 -070016817TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16818 VkResult err;
16819 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016820
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16822 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016823
Mike Stroyana3082432015-09-25 13:39:21 -060016824 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016825
Chris Forbesa7530692016-05-08 12:35:39 +120016826 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016827 VkImage srcImage;
16828 VkImage dstImage;
16829 VkDeviceMemory srcMem;
16830 VkDeviceMemory destMem;
16831 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016832
16833 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016834 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16835 image_create_info.pNext = NULL;
16836 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16837 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16838 image_create_info.extent.width = 32;
16839 image_create_info.extent.height = 1;
16840 image_create_info.extent.depth = 1;
16841 image_create_info.mipLevels = 1;
16842 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016843 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016844 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16845 // Note: Some implementations expect color attachment usage for any
16846 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016847 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016848 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016850 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016851 ASSERT_VK_SUCCESS(err);
16852
Karl Schultz6addd812016-02-02 17:17:23 -070016853 // Note: Some implementations expect color attachment usage for any
16854 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016855 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016857 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016858 ASSERT_VK_SUCCESS(err);
16859
16860 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016861 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016862 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16863 memAlloc.pNext = NULL;
16864 memAlloc.allocationSize = 0;
16865 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016866
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016867 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016868 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016869 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016870 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016871 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016872 ASSERT_VK_SUCCESS(err);
16873
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016874 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016875 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016876 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016877 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016878 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016879 ASSERT_VK_SUCCESS(err);
16880
16881 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16882 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016883 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016884 ASSERT_VK_SUCCESS(err);
16885
16886 BeginCommandBuffer();
16887 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016888 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16889 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016890 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016891 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016892 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016893 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016894 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016895 resolveRegion.srcOffset.x = 0;
16896 resolveRegion.srcOffset.y = 0;
16897 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016898 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016899 resolveRegion.dstSubresource.mipLevel = 0;
16900 resolveRegion.dstSubresource.baseArrayLayer = 0;
16901 resolveRegion.dstSubresource.layerCount = 0;
16902 resolveRegion.dstOffset.x = 0;
16903 resolveRegion.dstOffset.y = 0;
16904 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016905 resolveRegion.extent.width = 1;
16906 resolveRegion.extent.height = 1;
16907 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016908 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060016909 EndCommandBuffer();
16910
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016911 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016912
Chia-I Wuf7458c52015-10-26 21:10:41 +080016913 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016914 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016915 vkFreeMemory(m_device->device(), srcMem, NULL);
16916 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016917}
16918
Karl Schultz6addd812016-02-02 17:17:23 -070016919TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16920 VkResult err;
16921 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16924 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016925
Mike Stroyana3082432015-09-25 13:39:21 -060016926 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016927
16928 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016929 VkImage srcImage;
16930 VkImage dstImage;
16931 VkDeviceMemory srcMem;
16932 VkDeviceMemory destMem;
16933 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016934
16935 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016936 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16937 image_create_info.pNext = NULL;
16938 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16939 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16940 image_create_info.extent.width = 32;
16941 image_create_info.extent.height = 1;
16942 image_create_info.extent.depth = 1;
16943 image_create_info.mipLevels = 1;
16944 image_create_info.arrayLayers = 1;
16945 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16946 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16947 // Note: Some implementations expect color attachment usage for any
16948 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016949 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016950 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016952 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016953 ASSERT_VK_SUCCESS(err);
16954
Karl Schultz6addd812016-02-02 17:17:23 -070016955 // Set format to something other than source image
16956 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16957 // Note: Some implementations expect color attachment usage for any
16958 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016959 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016960 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016962 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016963 ASSERT_VK_SUCCESS(err);
16964
16965 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016966 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016967 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16968 memAlloc.pNext = NULL;
16969 memAlloc.allocationSize = 0;
16970 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016971
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016972 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016973 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016974 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016975 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016976 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016977 ASSERT_VK_SUCCESS(err);
16978
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016979 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016980 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016981 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016982 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016983 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016984 ASSERT_VK_SUCCESS(err);
16985
16986 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16987 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016988 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016989 ASSERT_VK_SUCCESS(err);
16990
16991 BeginCommandBuffer();
16992 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016993 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16994 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016995 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016996 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016997 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016998 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016999 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017000 resolveRegion.srcOffset.x = 0;
17001 resolveRegion.srcOffset.y = 0;
17002 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017003 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017004 resolveRegion.dstSubresource.mipLevel = 0;
17005 resolveRegion.dstSubresource.baseArrayLayer = 0;
17006 resolveRegion.dstSubresource.layerCount = 0;
17007 resolveRegion.dstOffset.x = 0;
17008 resolveRegion.dstOffset.y = 0;
17009 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017010 resolveRegion.extent.width = 1;
17011 resolveRegion.extent.height = 1;
17012 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017013 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017014 EndCommandBuffer();
17015
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017016 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017017
Chia-I Wuf7458c52015-10-26 21:10:41 +080017018 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017019 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017020 vkFreeMemory(m_device->device(), srcMem, NULL);
17021 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017022}
17023
Karl Schultz6addd812016-02-02 17:17:23 -070017024TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17025 VkResult err;
17026 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17029 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017030
Mike Stroyana3082432015-09-25 13:39:21 -060017031 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017032
17033 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017034 VkImage srcImage;
17035 VkImage dstImage;
17036 VkDeviceMemory srcMem;
17037 VkDeviceMemory destMem;
17038 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017039
17040 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017041 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17042 image_create_info.pNext = NULL;
17043 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17044 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17045 image_create_info.extent.width = 32;
17046 image_create_info.extent.height = 1;
17047 image_create_info.extent.depth = 1;
17048 image_create_info.mipLevels = 1;
17049 image_create_info.arrayLayers = 1;
17050 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17051 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17052 // Note: Some implementations expect color attachment usage for any
17053 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017054 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017055 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017057 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017058 ASSERT_VK_SUCCESS(err);
17059
Karl Schultz6addd812016-02-02 17:17:23 -070017060 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17061 // Note: Some implementations expect color attachment usage for any
17062 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017063 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017064 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017066 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017067 ASSERT_VK_SUCCESS(err);
17068
17069 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017070 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017071 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17072 memAlloc.pNext = NULL;
17073 memAlloc.allocationSize = 0;
17074 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017075
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017076 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017077 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017078 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017079 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017080 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017081 ASSERT_VK_SUCCESS(err);
17082
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017083 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017084 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017085 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017086 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017087 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017088 ASSERT_VK_SUCCESS(err);
17089
17090 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17091 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017092 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017093 ASSERT_VK_SUCCESS(err);
17094
17095 BeginCommandBuffer();
17096 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017097 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17098 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017099 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017100 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017101 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017102 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017103 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017104 resolveRegion.srcOffset.x = 0;
17105 resolveRegion.srcOffset.y = 0;
17106 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017107 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017108 resolveRegion.dstSubresource.mipLevel = 0;
17109 resolveRegion.dstSubresource.baseArrayLayer = 0;
17110 resolveRegion.dstSubresource.layerCount = 0;
17111 resolveRegion.dstOffset.x = 0;
17112 resolveRegion.dstOffset.y = 0;
17113 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017114 resolveRegion.extent.width = 1;
17115 resolveRegion.extent.height = 1;
17116 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017117 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060017118 EndCommandBuffer();
17119
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017120 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017121
Chia-I Wuf7458c52015-10-26 21:10:41 +080017122 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017123 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017124 vkFreeMemory(m_device->device(), srcMem, NULL);
17125 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017126}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017127
Karl Schultz6addd812016-02-02 17:17:23 -070017128TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017129 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017130 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17131 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017132 // The image format check comes 2nd in validation so we trigger it first,
17133 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017134 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17137 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017138
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017139 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017140
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017141 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017142 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17143 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017144
17145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17147 ds_pool_ci.pNext = NULL;
17148 ds_pool_ci.maxSets = 1;
17149 ds_pool_ci.poolSizeCount = 1;
17150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017151
17152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017153 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017154 ASSERT_VK_SUCCESS(err);
17155
17156 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017157 dsl_binding.binding = 0;
17158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17159 dsl_binding.descriptorCount = 1;
17160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17161 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017162
17163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17165 ds_layout_ci.pNext = NULL;
17166 ds_layout_ci.bindingCount = 1;
17167 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017168 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017170 ASSERT_VK_SUCCESS(err);
17171
17172 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017173 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017175 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017176 alloc_info.descriptorPool = ds_pool;
17177 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017179 ASSERT_VK_SUCCESS(err);
17180
Karl Schultz6addd812016-02-02 17:17:23 -070017181 VkImage image_bad;
17182 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017183 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017184 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017185 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017186 const int32_t tex_width = 32;
17187 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017188
17189 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017190 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17191 image_create_info.pNext = NULL;
17192 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17193 image_create_info.format = tex_format_bad;
17194 image_create_info.extent.width = tex_width;
17195 image_create_info.extent.height = tex_height;
17196 image_create_info.extent.depth = 1;
17197 image_create_info.mipLevels = 1;
17198 image_create_info.arrayLayers = 1;
17199 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17200 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017201 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017202 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017205 ASSERT_VK_SUCCESS(err);
17206 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017207 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17208 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017209 ASSERT_VK_SUCCESS(err);
17210
17211 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017212 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17213 image_view_create_info.image = image_bad;
17214 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17215 image_view_create_info.format = tex_format_bad;
17216 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17217 image_view_create_info.subresourceRange.baseMipLevel = 0;
17218 image_view_create_info.subresourceRange.layerCount = 1;
17219 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017220 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017221
17222 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017223 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017224
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017225 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017226
Chia-I Wuf7458c52015-10-26 21:10:41 +080017227 vkDestroyImage(m_device->device(), image_bad, NULL);
17228 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017229 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17230 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017231}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017232
17233TEST_F(VkLayerTest, ClearImageErrors) {
17234 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
17235 "ClearDepthStencilImage with a color image.");
17236
17237 ASSERT_NO_FATAL_FAILURE(InitState());
17238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17239
17240 // Renderpass is started here so end it as Clear cmds can't be in renderpass
17241 BeginCommandBuffer();
17242 m_commandBuffer->EndRenderPass();
17243
17244 // Color image
17245 VkClearColorValue clear_color;
17246 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17247 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17248 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17249 const int32_t img_width = 32;
17250 const int32_t img_height = 32;
17251 VkImageCreateInfo image_create_info = {};
17252 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17253 image_create_info.pNext = NULL;
17254 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17255 image_create_info.format = color_format;
17256 image_create_info.extent.width = img_width;
17257 image_create_info.extent.height = img_height;
17258 image_create_info.extent.depth = 1;
17259 image_create_info.mipLevels = 1;
17260 image_create_info.arrayLayers = 1;
17261 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17262 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17263 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17264
17265 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017266 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017268 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017269
17270 // Depth/Stencil image
17271 VkClearDepthStencilValue clear_value = {0};
17272 reqs = 0; // don't need HOST_VISIBLE DS image
17273 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17274 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17275 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17276 ds_image_create_info.extent.width = 64;
17277 ds_image_create_info.extent.height = 64;
17278 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17279 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
17280
17281 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017282 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017284 const VkImageSubresourceRange ds_range = vk_testing::Image::subresource_range(ds_image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017288 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017289 &color_range);
17290
17291 m_errorMonitor->VerifyFound();
17292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
17294 "image created without "
17295 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017297 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017298 &color_range);
17299
17300 m_errorMonitor->VerifyFound();
17301
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017302 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17304 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017306 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
17307 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017308
17309 m_errorMonitor->VerifyFound();
17310}
Tobin Ehliscde08892015-09-22 10:11:37 -060017311#endif // IMAGE_TESTS
17312
Cody Northrop1242dfd2016-07-13 17:24:59 -060017313#if defined(ANDROID) && defined(VALIDATION_APK)
17314static bool initialized = false;
17315static bool active = false;
17316
17317// Convert Intents to argv
17318// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017319std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017320 std::vector<std::string> args;
17321 JavaVM &vm = *app.activity->vm;
17322 JNIEnv *p_env;
17323 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
17324 return args;
17325
17326 JNIEnv &env = *p_env;
17327 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017328 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017329 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017330 jmethodID get_string_extra_method =
17331 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060017332 jvalue get_string_extra_args;
17333 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017334 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060017335
17336 std::string args_str;
17337 if (extra_str) {
17338 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
17339 args_str = extra_utf;
17340 env.ReleaseStringUTFChars(extra_str, extra_utf);
17341 env.DeleteLocalRef(extra_str);
17342 }
17343
17344 env.DeleteLocalRef(get_string_extra_args.l);
17345 env.DeleteLocalRef(intent);
17346 vm.DetachCurrentThread();
17347
17348 // split args_str
17349 std::stringstream ss(args_str);
17350 std::string arg;
17351 while (std::getline(ss, arg, ' ')) {
17352 if (!arg.empty())
17353 args.push_back(arg);
17354 }
17355
17356 return args;
17357}
17358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017359static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017361static void processCommand(struct android_app *app, int32_t cmd) {
17362 switch (cmd) {
17363 case APP_CMD_INIT_WINDOW: {
17364 if (app->window) {
17365 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017366 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017367 break;
17368 }
17369 case APP_CMD_GAINED_FOCUS: {
17370 active = true;
17371 break;
17372 }
17373 case APP_CMD_LOST_FOCUS: {
17374 active = false;
17375 break;
17376 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017377 }
17378}
17379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017380void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017381 app_dummy();
17382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017383 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060017384
17385 int vulkanSupport = InitVulkan();
17386 if (vulkanSupport == 0) {
17387 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
17388 return;
17389 }
17390
17391 app->onAppCmd = processCommand;
17392 app->onInputEvent = processInput;
17393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017394 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017395 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017396 struct android_poll_source *source;
17397 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060017398 if (source) {
17399 source->process(app, source);
17400 }
17401
17402 if (app->destroyRequested != 0) {
17403 VkTestFramework::Finish();
17404 return;
17405 }
17406 }
17407
17408 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017409 // Use the following key to send arguments to gtest, i.e.
17410 // --es args "--gtest_filter=-VkLayerTest.foo"
17411 const char key[] = "args";
17412 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017414 std::string filter = "";
17415 if (args.size() > 0) {
17416 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
17417 filter += args[0];
17418 } else {
17419 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
17420 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017422 int argc = 2;
17423 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
17424 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017426 // Route output to files until we can override the gtest output
17427 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
17428 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017430 ::testing::InitGoogleTest(&argc, argv);
17431 VkTestFramework::InitArgs(&argc, argv);
17432 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017434 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017436 if (result != 0) {
17437 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
17438 } else {
17439 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
17440 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060017441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017442 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060017443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017444 fclose(stdout);
17445 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017447 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060017448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017449 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060017450 }
17451 }
17452}
17453#endif
17454
Tony Barbour300a6082015-04-07 13:44:53 -060017455int main(int argc, char **argv) {
17456 int result;
17457
Cody Northrop8e54a402016-03-08 22:25:52 -070017458#ifdef ANDROID
17459 int vulkanSupport = InitVulkan();
17460 if (vulkanSupport == 0)
17461 return 1;
17462#endif
17463
Tony Barbour300a6082015-04-07 13:44:53 -060017464 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060017465 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060017466
17467 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
17468
17469 result = RUN_ALL_TESTS();
17470
Tony Barbour6918cd52015-04-09 12:58:51 -060017471 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060017472 return result;
17473}