blob: 5f06e6a018fa57e2af8d69af92be11b98e8e2f95 [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"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700175 found_expected = true;
176 m_msgFound = VK_TRUE;
177 m_failure_message_strings.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600178 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 m_msgFound = VK_TRUE;
182 result = VK_TRUE;
183 // We only want one match for each expected error so remove from set here
184 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600187 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600188 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600189 for (auto desired_id : m_desired_message_ids) {
190 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
191 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
192 // Return true to avoid calling layers/driver with this error.
193 result = VK_TRUE;
194 } else if (desired_id == message_code) {
195 // Double-check that the string matches the error enum
196 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
197 found_expected = true;
198 result = VK_TRUE;
199 m_msgFound = VK_TRUE;
200 m_desired_message_ids.erase(desired_id);
201 break;
202 } else {
203 // Treat this message as a regular unexpected error, but print a warning jic
204 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
205 errorString.c_str(), desired_id, validation_error_map[desired_id]);
206 }
207 }
208 }
209
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600210 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200211 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600212 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600213 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600214 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600215 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600216 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217
Karl Schultz6addd812016-02-02 17:17:23 -0700218 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600220 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
221
Karl Schultz6addd812016-02-02 17:17:23 -0700222 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Karl Schultz6addd812016-02-02 17:17:23 -0700224 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600225
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600228 if (otherMsgs.size()) {
229 cout << "Other error messages logged for this test were:" << endl;
230 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
231 cout << " " << *iter << endl;
232 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 }
234 }
235
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600236 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200237
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600238 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
239 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
240 m_msgFlags = message_flag_mask;
241 // Match ANY message matching specified type
242 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243 }
244
245 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600246 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 if (!DesiredMsgFound()) {
248 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600249 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600250 FAIL() << "Did not receive expected error '" << desired_msg << "'";
251 }
Tony Barbour59b42282016-11-03 13:31:28 -0600252 for (auto desired_id : m_desired_message_ids) {
253 FAIL() << "Did not receive expected error '" << desired_id << "'";
254 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 }
256 }
257
258 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200260 if (DesiredMsgFound()) {
261 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600263 FAIL() << "Expected to succeed but got error: " << msg;
264 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266 }
267
Karl Schultz6addd812016-02-02 17:17:23 -0700268 private:
269 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600270 std::unordered_set<uint32_t>m_desired_message_ids;
271 std::unordered_set<string> m_desired_message_strings;
272 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700273 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600274 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700275 bool *m_bailout;
276 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600277};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500278
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600279static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
280 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
281 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600282 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
283 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600284 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600285 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600286 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600287}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Karl Schultz6addd812016-02-02 17:17:23 -0700289class VkLayerTest : public VkRenderFramework {
290 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600291 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
292 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700293 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600294 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
295 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700296 }
Tony Barbour300a6082015-04-07 13:44:53 -0600297
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
299 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700300 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700302 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700304 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
306 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
307 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700308 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
309 }
310 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
311 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
312 }
313
314 protected:
315 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600316 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600317
318 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600319 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600320 std::vector<const char *> instance_extension_names;
321 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600322
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700323 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600324 /*
325 * Since CreateDbgMsgCallback is an instance level extension call
326 * any extension / layer that utilizes that feature also needs
327 * to be enabled at create instance time.
328 */
Karl Schultz6addd812016-02-02 17:17:23 -0700329 // Use Threading layer first to protect others from
330 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700331 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600332 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800333 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700334 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600336 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700337 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600338
Ian Elliott2c1daf52016-05-12 09:41:46 -0600339 if (m_enableWSI) {
340 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
341 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
342#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
343#if defined(VK_USE_PLATFORM_ANDROID_KHR)
344 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
345#endif // VK_USE_PLATFORM_ANDROID_KHR
346#if defined(VK_USE_PLATFORM_MIR_KHR)
347 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
348#endif // VK_USE_PLATFORM_MIR_KHR
349#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
350 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
351#endif // VK_USE_PLATFORM_WAYLAND_KHR
352#if defined(VK_USE_PLATFORM_WIN32_KHR)
353 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
354#endif // VK_USE_PLATFORM_WIN32_KHR
355#endif // NEED_TO_TEST_THIS_ON_PLATFORM
356#if defined(VK_USE_PLATFORM_XCB_KHR)
357 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
358#elif defined(VK_USE_PLATFORM_XLIB_KHR)
359 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
360#endif // VK_USE_PLATFORM_XLIB_KHR
361 }
362
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600363 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600364 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800365 this->app_info.pApplicationName = "layer_tests";
366 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600367 this->app_info.pEngineName = "unittest";
368 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600369 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Tony Barbour15524c32015-04-29 17:34:29 -0600371 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600372 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600373 }
374
375 virtual void TearDown() {
376 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600377 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600378 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600379 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600381 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600382};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600384void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385 // Create identity matrix
386 int i;
387 struct vktriangle_vs_uniform data;
388
389 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700390 glm::mat4 View = glm::mat4(1.0f);
391 glm::mat4 Model = glm::mat4(1.0f);
392 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700394 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500395
396 memcpy(&data.mvp, &MVP[0][0], matrixSize);
397
Karl Schultz6addd812016-02-02 17:17:23 -0700398 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600399 {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 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500413 ASSERT_NO_FATAL_FAILURE(InitViewport());
414
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200415 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
416 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Karl Schultz6addd812016-02-02 17:17:23 -0700418 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600419 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500420
421 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800422 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 pipelineobj.AddShader(&vs);
424 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600425 if (failMask & BsoFailLineWidth) {
426 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600427 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
430 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600431 }
432 if (failMask & BsoFailDepthBias) {
433 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600434 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600435 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600437 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600438 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600439 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700440 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700441 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 if (failMask & BsoFailViewport) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
444 }
445 if (failMask & BsoFailScissor) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
447 }
448 if (failMask & BsoFailBlend) {
449 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600450 VkPipelineColorBlendAttachmentState att_state = {};
451 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
452 att_state.blendEnable = VK_TRUE;
453 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600454 }
455 if (failMask & BsoFailDepthBounds) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
457 }
458 if (failMask & BsoFailStencilReadMask) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
460 }
461 if (failMask & BsoFailStencilWriteMask) {
462 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
463 }
464 if (failMask & BsoFailStencilReference) {
465 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
466 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467
468 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600469 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500470
471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700472 m_commandBuffer->BeginCommandBuffer();
473 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474
Tony Barbourfe3351b2015-07-28 10:17:20 -0600475 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476
477 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600478 if (failMask & BsoFailIndexBuffer) {
479 // Use DrawIndexed w/o an index buffer bound
480 DrawIndexed(3, 1, 0, 0, 0);
481 } else {
482 Draw(3, 1, 0, 0);
483 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
Mark Muellerd4914412016-06-13 17:52:06 -0600485 if (failMask & BsoFailCmdClearAttachments) {
486 VkClearAttachment color_attachment = {};
487 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
488 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
489 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
490
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600491 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600492 }
493
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500494 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700495 m_commandBuffer->EndRenderPass();
496 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600497 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498}
499
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600500void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
501 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600503 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500504 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600505 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500506 }
507
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800508 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700509 // Make sure depthWriteEnable is set so that Depth fail test will work
510 // correctly
511 // Make sure stencilTestEnable is set so that Stencil fail test will work
512 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600513 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800514 stencil.failOp = VK_STENCIL_OP_KEEP;
515 stencil.passOp = VK_STENCIL_OP_KEEP;
516 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
517 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600518
519 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
520 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600521 ds_ci.pNext = NULL;
522 ds_ci.depthTestEnable = VK_FALSE;
523 ds_ci.depthWriteEnable = VK_TRUE;
524 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
525 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600526 if (failMask & BsoFailDepthBounds) {
527 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600528 ds_ci.maxDepthBounds = 0.0f;
529 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600530 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600531 ds_ci.stencilTestEnable = VK_TRUE;
532 ds_ci.front = stencil;
533 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600534
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600535 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600536 pipelineobj.SetViewport(m_viewports);
537 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800538 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600539 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600540 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800541 commandBuffer->BindPipeline(pipelineobj);
542 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500543}
544
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600545class VkPositiveLayerTest : public VkLayerTest {
546 public:
547 protected:
548};
549
Ian Elliott2c1daf52016-05-12 09:41:46 -0600550class VkWsiEnabledLayerTest : public VkLayerTest {
551 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600552 protected:
553 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554};
555
Mark Muellerdfe37552016-07-07 14:47:42 -0600556class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600557 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600558 enum eTestEnFlags {
559 eDoubleDelete,
560 eInvalidDeviceOffset,
561 eInvalidMemoryOffset,
562 eBindNullBuffer,
563 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600564 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600565 };
566
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600568
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
570 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600571 return true;
572 }
573 VkDeviceSize offset_limit = 0;
574 if (eInvalidMemoryOffset == aTestFlag) {
575 VkBuffer vulkanBuffer;
576 VkBufferCreateInfo buffer_create_info = {};
577 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
578 buffer_create_info.size = 32;
579 buffer_create_info.usage = aBufferUsage;
580
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600582 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600583
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600584 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600585 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
586 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600587 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
588 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600589 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600591 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600592 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600593 }
594 if (eOffsetAlignment < offset_limit) {
595 return true;
596 }
597 return false;
598 }
599
600 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
602 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600603
604 if (eBindNullBuffer == aTestFlag) {
605 VulkanMemory = 0;
606 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
607 } else {
608 VkBufferCreateInfo buffer_create_info = {};
609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
610 buffer_create_info.size = 32;
611 buffer_create_info.usage = aBufferUsage;
612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614
615 CreateCurrent = true;
616
617 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600618 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600619
620 VkMemoryAllocateInfo memory_allocate_info = {};
621 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
622 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
624 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 if (!pass) {
626 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
627 return;
628 }
629
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 AllocateCurrent = true;
632 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
634 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 BoundCurrent = true;
636
637 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
638 }
639 }
640
641 ~VkBufferTest() {
642 if (CreateCurrent) {
643 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
644 }
645 if (AllocateCurrent) {
646 if (InvalidDeleteEn) {
647 union {
648 VkDeviceMemory device_memory;
649 unsigned long long index_access;
650 } bad_index;
651
652 bad_index.device_memory = VulkanMemory;
653 bad_index.index_access++;
654
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600655 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600656 }
657 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
658 }
659 }
660
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600661 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600662
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600663 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600664
665 void TestDoubleDestroy() {
666 // Destroy the buffer but leave the flag set, which will cause
667 // the buffer to be destroyed again in the destructor.
668 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
669 }
670
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600671 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600672 bool AllocateCurrent;
673 bool BoundCurrent;
674 bool CreateCurrent;
675 bool InvalidDeleteEn;
676
677 VkBuffer VulkanBuffer;
678 VkDevice VulkanDevice;
679 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600680};
681
682class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600683 public:
684 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600687 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600688 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
689 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600690 BindIdGenerator++; // NB: This can wrap w/misuse
691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
693 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
696 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
697 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
698 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
699 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600700
701 unsigned i = 0;
702 do {
703 VertexInputAttributeDescription[i].binding = BindId;
704 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600705 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
706 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600707 i++;
708 } while (AttributeCount < i);
709
710 i = 0;
711 do {
712 VertexInputBindingDescription[i].binding = BindId;
713 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600715 i++;
716 } while (BindingCount < i);
717 }
718
719 ~VkVerticesObj() {
720 if (VertexInputAttributeDescription) {
721 delete[] VertexInputAttributeDescription;
722 }
723 if (VertexInputBindingDescription) {
724 delete[] VertexInputBindingDescription;
725 }
726 }
727
728 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600729 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
730 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600731 return true;
732 }
733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 VkDeviceSize *offsetList;
736 unsigned offsetCount;
737
738 if (aOffsetCount) {
739 offsetList = aOffsetList;
740 offsetCount = aOffsetCount;
741 } else {
742 offsetList = new VkDeviceSize[1]();
743 offsetCount = 1;
744 }
745
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 BoundCurrent = true;
748
749 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600750 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600751 }
752 }
753
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600755 static uint32_t BindIdGenerator;
756
757 bool BoundCurrent;
758 unsigned AttributeCount;
759 unsigned BindingCount;
760 uint32_t BindId;
761
762 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
763 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
764 VkVertexInputBindingDescription *VertexInputBindingDescription;
765 VkConstantBufferObj VulkanMemoryBuffer;
766};
767
768uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500769// ********************************************************************************************************************
770// ********************************************************************************************************************
771// ********************************************************************************************************************
772// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600773#if PARAMETER_VALIDATION_TESTS
774TEST_F(VkLayerTest, RequiredParameter) {
775 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
776 "pointer, array, and array count parameters");
777
778 ASSERT_NO_FATAL_FAILURE(InitState());
779
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600781 // Specify NULL for a pointer to a handle
782 // Expected to trigger an error with
783 // parameter_validation::validate_required_pointer
784 vkGetPhysicalDeviceFeatures(gpu(), NULL);
785 m_errorMonitor->VerifyFound();
786
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
788 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600789 // Specify NULL for pointer to array count
790 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600791 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600792 m_errorMonitor->VerifyFound();
793
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600795 // Specify 0 for a required array count
796 // Expected to trigger an error with parameter_validation::validate_array
797 VkViewport view_port = {};
798 m_commandBuffer->SetViewport(0, 0, &view_port);
799 m_errorMonitor->VerifyFound();
800
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802 // Specify NULL for a required array
803 // Expected to trigger an error with parameter_validation::validate_array
804 m_commandBuffer->SetViewport(0, 1, NULL);
805 m_errorMonitor->VerifyFound();
806
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600808 // Specify VK_NULL_HANDLE for a required handle
809 // Expected to trigger an error with
810 // parameter_validation::validate_required_handle
811 vkUnmapMemory(device(), VK_NULL_HANDLE);
812 m_errorMonitor->VerifyFound();
813
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
815 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600816 // Specify VK_NULL_HANDLE for a required handle array entry
817 // Expected to trigger an error with
818 // parameter_validation::validate_required_handle_array
819 VkFence fence = VK_NULL_HANDLE;
820 vkResetFences(device(), 1, &fence);
821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify NULL for a required struct pointer
825 // Expected to trigger an error with
826 // parameter_validation::validate_struct_type
827 VkDeviceMemory memory = VK_NULL_HANDLE;
828 vkAllocateMemory(device(), NULL, NULL, &memory);
829 m_errorMonitor->VerifyFound();
830
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600832 // Specify 0 for a required VkFlags parameter
833 // Expected to trigger an error with parameter_validation::validate_flags
834 m_commandBuffer->SetStencilReference(0, 0);
835 m_errorMonitor->VerifyFound();
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 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 -0600838 // Specify 0 for a required VkFlags array entry
839 // Expected to trigger an error with
840 // parameter_validation::validate_flags_array
841 VkSemaphore semaphore = VK_NULL_HANDLE;
842 VkPipelineStageFlags stageFlags = 0;
843 VkSubmitInfo submitInfo = {};
844 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
845 submitInfo.waitSemaphoreCount = 1;
846 submitInfo.pWaitSemaphores = &semaphore;
847 submitInfo.pWaitDstStageMask = &stageFlags;
848 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
849 m_errorMonitor->VerifyFound();
850}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600851
Dustin Gravesfce74c02016-05-10 11:42:58 -0600852TEST_F(VkLayerTest, ReservedParameter) {
853 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
854
855 ASSERT_NO_FATAL_FAILURE(InitState());
856
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600858 // Specify 0 for a reserved VkFlags parameter
859 // Expected to trigger an error with
860 // parameter_validation::validate_reserved_flags
861 VkEvent event_handle = VK_NULL_HANDLE;
862 VkEventCreateInfo event_info = {};
863 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
864 event_info.flags = 1;
865 vkCreateEvent(device(), &event_info, NULL, &event_handle);
866 m_errorMonitor->VerifyFound();
867}
868
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600869TEST_F(VkLayerTest, InvalidStructSType) {
870 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
871 "structure's sType field");
872
873 ASSERT_NO_FATAL_FAILURE(InitState());
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600876 // Zero struct memory, effectively setting sType to
877 // VK_STRUCTURE_TYPE_APPLICATION_INFO
878 // Expected to trigger an error with
879 // parameter_validation::validate_struct_type
880 VkMemoryAllocateInfo alloc_info = {};
881 VkDeviceMemory memory = VK_NULL_HANDLE;
882 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
883 m_errorMonitor->VerifyFound();
884
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600886 // Zero struct memory, effectively setting sType to
887 // VK_STRUCTURE_TYPE_APPLICATION_INFO
888 // Expected to trigger an error with
889 // parameter_validation::validate_struct_type_array
890 VkSubmitInfo submit_info = {};
891 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
892 m_errorMonitor->VerifyFound();
893}
894
895TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600896 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600897
898 ASSERT_NO_FATAL_FAILURE(InitState());
899
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600901 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600902 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600903 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600904 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600905 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600906 // Zero-initialization will provide the correct sType
907 VkApplicationInfo app_info = {};
908 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
909 event_alloc_info.pNext = &app_info;
910 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
911 m_errorMonitor->VerifyFound();
912
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
914 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600915 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
916 // a function that has allowed pNext structure types and specify
917 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600918 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600920 VkMemoryAllocateInfo memory_alloc_info = {};
921 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
922 memory_alloc_info.pNext = &app_info;
923 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600924 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600925}
Dustin Graves5d33d532016-05-09 16:21:12 -0600926
927TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600929
930 ASSERT_NO_FATAL_FAILURE(InitState());
931
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
933 "range of the core VkFormat "
934 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600935 // Specify an invalid VkFormat value
936 // Expected to trigger an error with
937 // parameter_validation::validate_ranged_enum
938 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 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 -0600943 // Specify an invalid VkFlags bitmask value
944 // Expected to trigger an error with parameter_validation::validate_flags
945 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600946 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
947 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600948 m_errorMonitor->VerifyFound();
949
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600950 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 -0600951 // Specify an invalid VkFlags array entry
952 // Expected to trigger an error with
953 // parameter_validation::validate_flags_array
954 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600955 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600956 VkSubmitInfo submit_info = {};
957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
958 submit_info.waitSemaphoreCount = 1;
959 submit_info.pWaitSemaphores = &semaphore;
960 submit_info.pWaitDstStageMask = &stage_flags;
961 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
962 m_errorMonitor->VerifyFound();
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600965 // Specify an invalid VkBool32 value
966 // Expected to trigger a warning with
967 // parameter_validation::validate_bool32
968 VkSampler sampler = VK_NULL_HANDLE;
969 VkSamplerCreateInfo sampler_info = {};
970 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
971 sampler_info.pNext = NULL;
972 sampler_info.magFilter = VK_FILTER_NEAREST;
973 sampler_info.minFilter = VK_FILTER_NEAREST;
974 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
975 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
976 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
977 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
978 sampler_info.mipLodBias = 1.0;
979 sampler_info.maxAnisotropy = 1;
980 sampler_info.compareEnable = VK_FALSE;
981 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
982 sampler_info.minLod = 1.0;
983 sampler_info.maxLod = 1.0;
984 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
985 sampler_info.unnormalizedCoordinates = VK_FALSE;
986 // Not VK_TRUE or VK_FALSE
987 sampler_info.anisotropyEnable = 3;
988 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
989 m_errorMonitor->VerifyFound();
990}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600991
992TEST_F(VkLayerTest, FailedReturnValue) {
993 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
994
995 ASSERT_NO_FATAL_FAILURE(InitState());
996
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600997 // Find an unsupported image format
998 VkFormat unsupported = VK_FORMAT_UNDEFINED;
999 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1000 VkFormat format = static_cast<VkFormat>(f);
1001 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001002 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001003 unsupported = format;
1004 break;
1005 }
1006 }
1007
1008 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1010 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001011 // Specify an unsupported VkFormat value to generate a
1012 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1013 // Expected to trigger a warning from
1014 // parameter_validation::validate_result
1015 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001016 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1017 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001018 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1019 m_errorMonitor->VerifyFound();
1020 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001021}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001022
1023TEST_F(VkLayerTest, UpdateBufferAlignment) {
1024 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001025 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001026
1027 ASSERT_NO_FATAL_FAILURE(InitState());
1028
1029 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1030 vk_testing::Buffer buffer;
1031 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1032
Tony Barbour552f6c02016-12-21 14:34:07 -07001033 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001034 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001036 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1037 m_errorMonitor->VerifyFound();
1038
1039 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001041 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1042 m_errorMonitor->VerifyFound();
1043
1044 // Introduce failure by using dataSize that is < 0
1045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001047 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1048 m_errorMonitor->VerifyFound();
1049
1050 // Introduce failure by using dataSize that is > 65536
1051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001052 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001053 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1054 m_errorMonitor->VerifyFound();
1055
Tony Barbour552f6c02016-12-21 14:34:07 -07001056 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001057}
1058
1059TEST_F(VkLayerTest, FillBufferAlignment) {
1060 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1061
1062 ASSERT_NO_FATAL_FAILURE(InitState());
1063
1064 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1065 vk_testing::Buffer buffer;
1066 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1067
Tony Barbour552f6c02016-12-21 14:34:07 -07001068 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069
1070 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001072 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1073 m_errorMonitor->VerifyFound();
1074
1075 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001077 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1078 m_errorMonitor->VerifyFound();
1079
1080 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1083 m_errorMonitor->VerifyFound();
1084
Tony Barbour552f6c02016-12-21 14:34:07 -07001085 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001086}
Dustin Graves40f35822016-06-23 11:12:53 -06001087
Cortd889ff92016-07-27 09:51:27 -07001088TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1089 VkResult err;
1090
1091 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001092 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1096
1097 std::vector<const char *> device_extension_names;
1098 auto features = m_device->phy().features();
1099 // Artificially disable support for non-solid fill modes
1100 features.fillModeNonSolid = false;
1101 // The sacrificial device object
1102 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1103
1104 VkRenderpassObj render_pass(&test_device);
1105
1106 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1107 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1108 pipeline_layout_ci.setLayoutCount = 0;
1109 pipeline_layout_ci.pSetLayouts = NULL;
1110
1111 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001112 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001113 ASSERT_VK_SUCCESS(err);
1114
1115 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1116 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1117 rs_ci.pNext = nullptr;
1118 rs_ci.lineWidth = 1.0f;
1119 rs_ci.rasterizerDiscardEnable = true;
1120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1122 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001123
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001124 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1126 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001127 {
1128 VkPipelineObj pipe(&test_device);
1129 pipe.AddShader(&vs);
1130 pipe.AddShader(&fs);
1131 pipe.AddColorAttachment();
1132 // Introduce failure by setting unsupported polygon mode
1133 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1134 pipe.SetRasterization(&rs_ci);
1135 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1136 }
1137 m_errorMonitor->VerifyFound();
1138
1139 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1141 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001142 {
1143 VkPipelineObj pipe(&test_device);
1144 pipe.AddShader(&vs);
1145 pipe.AddShader(&fs);
1146 pipe.AddColorAttachment();
1147 // Introduce failure by setting unsupported polygon mode
1148 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1149 pipe.SetRasterization(&rs_ci);
1150 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1151 }
1152 m_errorMonitor->VerifyFound();
1153
Cortd889ff92016-07-27 09:51:27 -07001154 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1155}
1156
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001157#endif // PARAMETER_VALIDATION_TESTS
1158
Tobin Ehlis0788f522015-05-26 16:11:58 -06001159#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001160#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001161TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001162{
1163 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001164 VkFenceCreateInfo fenceInfo = {};
1165 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1166 fenceInfo.pNext = NULL;
1167 fenceInfo.flags = 0;
1168
Mike Weiblencce7ec72016-10-17 19:33:05 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001170
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001171 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001172
1173 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1174 vk_testing::Buffer buffer;
1175 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001176
Tony Barbourfe3351b2015-07-28 10:17:20 -06001177 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001178 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001179 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001180
1181 testFence.init(*m_device, fenceInfo);
1182
1183 // Bypass framework since it does the waits automatically
1184 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001185 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1187 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001188 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001189 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001190 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001191 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001192 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001193 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001194 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001195
1196 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001197 ASSERT_VK_SUCCESS( err );
1198
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001199 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001200 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001201
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001202 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001203}
1204
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001205TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206{
1207 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208 VkFenceCreateInfo fenceInfo = {};
1209 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1210 fenceInfo.pNext = NULL;
1211 fenceInfo.flags = 0;
1212
Mike Weiblencce7ec72016-10-17 19:33:05 -06001213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001214
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001215 ASSERT_NO_FATAL_FAILURE(InitState());
1216 ASSERT_NO_FATAL_FAILURE(InitViewport());
1217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Jon Ashburnf19916e2016-01-11 13:12:43 -07001241 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 VkCommandBufferBeginInfo info = {};
1243 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1244 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001245 info.renderPass = VK_NULL_HANDLE;
1246 info.subpass = 0;
1247 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001248 info.occlusionQueryEnable = VK_FALSE;
1249 info.queryFlags = 0;
1250 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001251
1252 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001253 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001254
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001255 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001256}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001257#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001258
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001259TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1260 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1261
1262 ASSERT_NO_FATAL_FAILURE(InitState());
1263
1264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1265 VkBuffer buffer;
1266 VkBufferCreateInfo buf_info = {};
1267 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1268 buf_info.pNext = NULL;
1269 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1270 buf_info.size = 2048;
1271 buf_info.queueFamilyIndexCount = 0;
1272 buf_info.pQueueFamilyIndices = NULL;
1273 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1274 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1275 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1276 m_errorMonitor->VerifyFound();
1277
1278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1279 VkImage image;
1280 VkImageCreateInfo image_create_info = {};
1281 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1282 image_create_info.pNext = NULL;
1283 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1284 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1285 image_create_info.extent.width = 512;
1286 image_create_info.extent.height = 64;
1287 image_create_info.extent.depth = 1;
1288 image_create_info.mipLevels = 1;
1289 image_create_info.arrayLayers = 1;
1290 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1291 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1292 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1293 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1294 image_create_info.queueFamilyIndexCount = 0;
1295 image_create_info.pQueueFamilyIndices = NULL;
1296 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1297 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1298 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1299 m_errorMonitor->VerifyFound();
1300}
1301
Tobin Ehlisf11be982016-05-11 13:52:53 -06001302TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1303 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1304 "buffer and image to memory such that they will alias.");
1305 VkResult err;
1306 bool pass;
1307 ASSERT_NO_FATAL_FAILURE(InitState());
1308
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001310 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001311 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001312 VkDeviceMemory mem; // buffer will be bound first
1313 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001315 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001316
1317 VkBufferCreateInfo buf_info = {};
1318 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1319 buf_info.pNext = NULL;
1320 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1321 buf_info.size = 256;
1322 buf_info.queueFamilyIndexCount = 0;
1323 buf_info.pQueueFamilyIndices = NULL;
1324 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1325 buf_info.flags = 0;
1326 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1327 ASSERT_VK_SUCCESS(err);
1328
Tobin Ehlis077ded32016-05-12 17:39:13 -06001329 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001330
1331 VkImageCreateInfo image_create_info = {};
1332 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1333 image_create_info.pNext = NULL;
1334 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1335 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1336 image_create_info.extent.width = 64;
1337 image_create_info.extent.height = 64;
1338 image_create_info.extent.depth = 1;
1339 image_create_info.mipLevels = 1;
1340 image_create_info.arrayLayers = 1;
1341 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001342 // Image tiling must be optimal to trigger error when aliasing linear buffer
1343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001344 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1346 image_create_info.queueFamilyIndexCount = 0;
1347 image_create_info.pQueueFamilyIndices = NULL;
1348 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1349 image_create_info.flags = 0;
1350
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1352 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001353 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1354 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001355
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1357
1358 VkMemoryAllocateInfo alloc_info = {};
1359 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1360 alloc_info.pNext = NULL;
1361 alloc_info.memoryTypeIndex = 0;
1362 // Ensure memory is big enough for both bindings
1363 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001364 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1365 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001366 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001368 vkDestroyImage(m_device->device(), image, NULL);
1369 return;
1370 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001371 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1372 ASSERT_VK_SUCCESS(err);
1373 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1374 ASSERT_VK_SUCCESS(err);
1375
Rene Lindsayd14f5572016-12-16 14:57:18 -07001376 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1377
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1381 m_errorMonitor->VerifyFound();
1382
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001383 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001384 // aliasing buffer2
1385 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1386 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001387 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1388 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001389 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001390 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001392 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001393 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001394 m_errorMonitor->VerifyFound();
1395
1396 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001397 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001398 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001399 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001400 vkFreeMemory(m_device->device(), mem, NULL);
1401 vkFreeMemory(m_device->device(), mem_img, NULL);
1402}
1403
Tobin Ehlis35372522016-05-12 08:32:31 -06001404TEST_F(VkLayerTest, InvalidMemoryMapping) {
1405 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1406 VkResult err;
1407 bool pass;
1408 ASSERT_NO_FATAL_FAILURE(InitState());
1409
1410 VkBuffer buffer;
1411 VkDeviceMemory mem;
1412 VkMemoryRequirements mem_reqs;
1413
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001414 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1415
Tobin Ehlis35372522016-05-12 08:32:31 -06001416 VkBufferCreateInfo buf_info = {};
1417 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1418 buf_info.pNext = NULL;
1419 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1420 buf_info.size = 256;
1421 buf_info.queueFamilyIndexCount = 0;
1422 buf_info.pQueueFamilyIndices = NULL;
1423 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1424 buf_info.flags = 0;
1425 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1426 ASSERT_VK_SUCCESS(err);
1427
1428 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1429 VkMemoryAllocateInfo alloc_info = {};
1430 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1431 alloc_info.pNext = NULL;
1432 alloc_info.memoryTypeIndex = 0;
1433
1434 // Ensure memory is big enough for both bindings
1435 static const VkDeviceSize allocation_size = 0x10000;
1436 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001437 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 -06001438 if (!pass) {
1439 vkDestroyBuffer(m_device->device(), buffer, NULL);
1440 return;
1441 }
1442 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1443 ASSERT_VK_SUCCESS(err);
1444
1445 uint8_t *pData;
1446 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001447 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 -06001448 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1449 m_errorMonitor->VerifyFound();
1450 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001451 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001452 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1455 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 m_errorMonitor->VerifyFound();
1457
1458 // Unmap the memory to avoid re-map error
1459 vkUnmapMemory(m_device->device(), mem);
1460 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1462 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1463 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 m_errorMonitor->VerifyFound();
1465 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1467 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001468 m_errorMonitor->VerifyFound();
1469 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001471 vkUnmapMemory(m_device->device(), mem);
1472 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001473
Tobin Ehlis35372522016-05-12 08:32:31 -06001474 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001475 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001476 ASSERT_VK_SUCCESS(err);
1477 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001478 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001479 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001480 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001482 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1483 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001484
Tobin Ehlis35372522016-05-12 08:32:31 -06001485 // Now flush range that oversteps mapped range
1486 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001487 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001488 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001489 mmr.offset = atom_size;
1490 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1492 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1493 m_errorMonitor->VerifyFound();
1494
1495 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1496 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001497 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001498 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001499 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001500 mmr.size = VK_WHOLE_SIZE;
1501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001502 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1503 m_errorMonitor->VerifyFound();
1504
Tony Barboure3975eb2016-12-15 14:52:44 -07001505#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001506 // Some platforms have an atomsize of 1 which makes the test meaningless
1507 if (atom_size > 3) {
1508 // Now with an offset NOT a multiple of the device limit
1509 vkUnmapMemory(m_device->device(), mem);
1510 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1511 ASSERT_VK_SUCCESS(err);
1512 mmr.offset = 3; // Not a multiple of atom_size
1513 mmr.size = VK_WHOLE_SIZE;
1514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1515 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1516 m_errorMonitor->VerifyFound();
1517
1518 // Now with a size NOT a multiple of the device limit
1519 vkUnmapMemory(m_device->device(), mem);
1520 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1521 ASSERT_VK_SUCCESS(err);
1522 mmr.offset = atom_size;
1523 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1525 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1526 m_errorMonitor->VerifyFound();
1527 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001528#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1530 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001531 if (!pass) {
1532 vkFreeMemory(m_device->device(), mem, NULL);
1533 vkDestroyBuffer(m_device->device(), buffer, NULL);
1534 return;
1535 }
1536 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1537 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1538
1539 vkDestroyBuffer(m_device->device(), buffer, NULL);
1540 vkFreeMemory(m_device->device(), mem, NULL);
1541}
1542
Chris Forbes09368e42016-10-13 11:59:22 +13001543#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001544TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1545 VkResult err;
1546 bool pass;
1547
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1549 // following declaration (which is temporarily being moved below):
1550 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001551 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001552 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001553 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001554 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001555 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001556 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001557
1558 ASSERT_NO_FATAL_FAILURE(InitState());
1559
Ian Elliott3f06ce52016-04-29 14:46:21 -06001560#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1561#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1562 // Use the functions from the VK_KHR_android_surface extension without
1563 // enabling that extension:
1564
1565 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001566 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1568 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569 pass = (err != VK_SUCCESS);
1570 ASSERT_TRUE(pass);
1571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_ANDROID_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_MIR_KHR)
1575 // Use the functions from the VK_KHR_mir_surface extension without enabling
1576 // that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001581 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an mir_connection supports presentation:
1587 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_MIR_KHR
1592
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1594 // Use the functions from the VK_KHR_wayland_surface extension without
1595 // enabling that extension:
1596
1597 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001598 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1600 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001601 pass = (err != VK_SUCCESS);
1602 ASSERT_TRUE(pass);
1603 m_errorMonitor->VerifyFound();
1604
1605 // Tell whether an wayland_display supports presentation:
1606 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1608 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001609 m_errorMonitor->VerifyFound();
1610#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001611#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612
Ian Elliott3f06ce52016-04-29 14:46:21 -06001613#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001614 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1615 // TO NON-LINUX PLATFORMS:
1616 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001617 // Use the functions from the VK_KHR_win32_surface extension without
1618 // enabling that extension:
1619
1620 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001621 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1623 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001624 pass = (err != VK_SUCCESS);
1625 ASSERT_TRUE(pass);
1626 m_errorMonitor->VerifyFound();
1627
1628 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001630 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001631 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001632// Set this (for now, until all platforms are supported and tested):
1633#define NEED_TO_TEST_THIS_ON_PLATFORM
1634#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001635#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1637 // TO NON-LINUX PLATFORMS:
1638 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001639#endif
1640#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001641 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1642 // that extension:
1643
1644 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001645 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001647 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1648 pass = (err != VK_SUCCESS);
1649 ASSERT_TRUE(pass);
1650 m_errorMonitor->VerifyFound();
1651
1652 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001653 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001654 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1656 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001657 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001658// Set this (for now, until all platforms are supported and tested):
1659#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001660#endif // VK_USE_PLATFORM_XCB_KHR
1661
Ian Elliott12630812016-04-29 14:35:43 -06001662#if defined(VK_USE_PLATFORM_XLIB_KHR)
1663 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1664 // that extension:
1665
1666 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001667 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001669 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1670 pass = (err != VK_SUCCESS);
1671 ASSERT_TRUE(pass);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Tell whether an Xlib VisualID supports presentation:
1675 Display *dpy = NULL;
1676 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001678 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1679 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001680// Set this (for now, until all platforms are supported and tested):
1681#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001682#endif // VK_USE_PLATFORM_XLIB_KHR
1683
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684// Use the functions from the VK_KHR_surface extension without enabling
1685// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001686
Ian Elliott489eec02016-05-05 14:12:44 -06001687#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001690 vkDestroySurfaceKHR(instance(), surface, NULL);
1691 m_errorMonitor->VerifyFound();
1692
1693 // Check if surface supports presentation:
1694 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001696 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1697 pass = (err != VK_SUCCESS);
1698 ASSERT_TRUE(pass);
1699 m_errorMonitor->VerifyFound();
1700
1701 // Check surface capabilities:
1702 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1704 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001705 pass = (err != VK_SUCCESS);
1706 ASSERT_TRUE(pass);
1707 m_errorMonitor->VerifyFound();
1708
1709 // Check surface formats:
1710 uint32_t format_count = 0;
1711 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1713 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 pass = (err != VK_SUCCESS);
1715 ASSERT_TRUE(pass);
1716 m_errorMonitor->VerifyFound();
1717
1718 // Check surface present modes:
1719 uint32_t present_mode_count = 0;
1720 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001726#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001727
Ian Elliott1c32c772016-04-28 14:47:13 -06001728 // Use the functions from the VK_KHR_swapchain extension without enabling
1729 // that extension:
1730
1731 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1734 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001735 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
1740 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1742 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001743 pass = (err != VK_SUCCESS);
1744 ASSERT_TRUE(pass);
1745 m_errorMonitor->VerifyFound();
1746
Chris Forbeseb7d5502016-09-13 18:19:21 +12001747 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1748 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1749 VkFence fence;
1750 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1751
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001754 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 pass = (err != VK_SUCCESS);
1756 ASSERT_TRUE(pass);
1757 m_errorMonitor->VerifyFound();
1758
Chris Forbeseb7d5502016-09-13 18:19:21 +12001759 vkDestroyFence(m_device->device(), fence, nullptr);
1760
Ian Elliott1c32c772016-04-28 14:47:13 -06001761 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001762 //
1763 // NOTE: Currently can't test this because a real swapchain is needed (as
1764 // opposed to the fake one we created) in order for the layer to lookup the
1765 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001766
1767 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001769 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1770 m_errorMonitor->VerifyFound();
1771}
Chris Forbes09368e42016-10-13 11:59:22 +13001772#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001773
Karl Schultz6addd812016-02-02 17:17:23 -07001774TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1775 VkResult err;
1776 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1779 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001780
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001781 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001782
1783 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001784 VkImage image;
1785 VkDeviceMemory mem;
1786 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001787
Karl Schultz6addd812016-02-02 17:17:23 -07001788 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1789 const int32_t tex_width = 32;
1790 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001791
Tony Barboureb254902015-07-15 12:50:33 -06001792 VkImageCreateInfo image_create_info = {};
1793 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001794 image_create_info.pNext = NULL;
1795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1796 image_create_info.format = tex_format;
1797 image_create_info.extent.width = tex_width;
1798 image_create_info.extent.height = tex_height;
1799 image_create_info.extent.depth = 1;
1800 image_create_info.mipLevels = 1;
1801 image_create_info.arrayLayers = 1;
1802 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1803 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1804 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1805 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001806 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001807
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001808 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001809 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001810 mem_alloc.pNext = NULL;
1811 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001812
Chia-I Wuf7458c52015-10-26 21:10:41 +08001813 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
Karl Schultz6addd812016-02-02 17:17:23 -07001816 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001817
Mark Lobodzinski23065352015-05-29 09:32:35 -05001818 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001820 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 -07001821 if (!pass) { // If we can't find any unmappable memory this test doesn't
1822 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001823 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001824 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001825 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001826
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001827 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001828 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001829 ASSERT_VK_SUCCESS(err);
1830
1831 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001832 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001833 ASSERT_VK_SUCCESS(err);
1834
1835 // Map memory as if to initialize the image
1836 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001838
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001839 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001840
Chia-I Wuf7458c52015-10-26 21:10:41 +08001841 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001842 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001843}
1844
Karl Schultz6addd812016-02-02 17:17:23 -07001845TEST_F(VkLayerTest, RebindMemory) {
1846 VkResult err;
1847 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001850
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001851 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001852
1853 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001854 VkImage image;
1855 VkDeviceMemory mem1;
1856 VkDeviceMemory mem2;
1857 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Karl Schultz6addd812016-02-02 17:17:23 -07001859 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1860 const int32_t tex_width = 32;
1861 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001862
Tony Barboureb254902015-07-15 12:50:33 -06001863 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001864 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1865 image_create_info.pNext = NULL;
1866 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1867 image_create_info.format = tex_format;
1868 image_create_info.extent.width = tex_width;
1869 image_create_info.extent.height = tex_height;
1870 image_create_info.extent.depth = 1;
1871 image_create_info.mipLevels = 1;
1872 image_create_info.arrayLayers = 1;
1873 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1874 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1875 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1876 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001877
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001879 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1880 mem_alloc.pNext = NULL;
1881 mem_alloc.allocationSize = 0;
1882 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001883
Karl Schultz6addd812016-02-02 17:17:23 -07001884 // Introduce failure, do NOT set memProps to
1885 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001886 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001887 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001888 ASSERT_VK_SUCCESS(err);
1889
Karl Schultz6addd812016-02-02 17:17:23 -07001890 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001891
1892 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001893 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001894 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001895
1896 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001897 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001898 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001899 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001900 ASSERT_VK_SUCCESS(err);
1901
1902 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001903 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001904 ASSERT_VK_SUCCESS(err);
1905
Karl Schultz6addd812016-02-02 17:17:23 -07001906 // Introduce validation failure, try to bind a different memory object to
1907 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001908 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001910 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001911
Chia-I Wuf7458c52015-10-26 21:10:41 +08001912 vkDestroyImage(m_device->device(), image, NULL);
1913 vkFreeMemory(m_device->device(), mem1, NULL);
1914 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001915}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001916
Karl Schultz6addd812016-02-02 17:17:23 -07001917TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001918 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001919
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1921 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001922
1923 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001924 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1925 fenceInfo.pNext = NULL;
1926 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001927
Tony Barbour300a6082015-04-07 13:44:53 -06001928 ASSERT_NO_FATAL_FAILURE(InitState());
1929 ASSERT_NO_FATAL_FAILURE(InitViewport());
1930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1931
Tony Barbour552f6c02016-12-21 14:34:07 -07001932 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07001934 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001935
1936 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001937
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001938 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001939 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1940 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001941 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001942 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001943 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001944 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001945 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001946 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001947 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001948
1949 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001950 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001952 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001953}
Chris Forbes4e44c912016-06-16 10:20:00 +12001954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955TEST_F(VkLayerTest, InvalidUsageBits) {
1956 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1957 "Initialize buffer with wrong usage then perform copy expecting errors "
1958 "from both the image and the buffer (2 calls)");
1959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001960
1961 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001962
1963 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1964
Tony Barbourf92621a2016-05-02 14:28:12 -06001965 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001966 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001967 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001968 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001969
Tony Barbourf92621a2016-05-02 14:28:12 -06001970 VkImageView dsv;
1971 VkImageViewCreateInfo dsvci = {};
1972 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1973 dsvci.image = image.handle();
1974 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001975 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001976 dsvci.subresourceRange.layerCount = 1;
1977 dsvci.subresourceRange.baseMipLevel = 0;
1978 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001980
Tony Barbourf92621a2016-05-02 14:28:12 -06001981 // Create a view with depth / stencil aspect for image with different usage
1982 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001983
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001984 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001985
1986 // Initialize buffer with TRANSFER_DST usage
1987 vk_testing::Buffer buffer;
1988 VkMemoryPropertyFlags reqs = 0;
1989 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1990 VkBufferImageCopy region = {};
1991 region.bufferRowLength = 128;
1992 region.bufferImageHeight = 128;
1993 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1994 region.imageSubresource.layerCount = 1;
1995 region.imageExtent.height = 16;
1996 region.imageExtent.width = 16;
1997 region.imageExtent.depth = 1;
1998
Tony Barbourf92621a2016-05-02 14:28:12 -06001999 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2000 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002001 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002002
Chris Forbesda581202016-10-06 18:25:26 +13002003 // two separate errors from this call:
2004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002009 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002010}
Tony Barbour75d79f02016-08-30 09:39:07 -06002011
Tony Barbour75d79f02016-08-30 09:39:07 -06002012
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002013#endif // MEM_TRACKER_TESTS
2014
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002015#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002016
2017TEST_F(VkLayerTest, LeakAnObject) {
2018 VkResult err;
2019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002020 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021
2022 // Note that we have to create a new device since destroying the
2023 // framework's device causes Teardown() to fail and just calling Teardown
2024 // will destroy the errorMonitor.
2025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002027
2028 ASSERT_NO_FATAL_FAILURE(InitState());
2029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002030 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002031 std::vector<VkDeviceQueueCreateInfo> queue_info;
2032 queue_info.reserve(queue_props.size());
2033 std::vector<std::vector<float>> queue_priorities;
2034 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2035 VkDeviceQueueCreateInfo qi = {};
2036 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2037 qi.pNext = NULL;
2038 qi.queueFamilyIndex = i;
2039 qi.queueCount = queue_props[i].queueCount;
2040 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2041 qi.pQueuePriorities = queue_priorities[i].data();
2042 queue_info.push_back(qi);
2043 }
2044
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002045 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002046
2047 // The sacrificial device object
2048 VkDevice testDevice;
2049 VkDeviceCreateInfo device_create_info = {};
2050 auto features = m_device->phy().features();
2051 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2052 device_create_info.pNext = NULL;
2053 device_create_info.queueCreateInfoCount = queue_info.size();
2054 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002055 device_create_info.enabledLayerCount = 0;
2056 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002057 device_create_info.pEnabledFeatures = &features;
2058 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2059 ASSERT_VK_SUCCESS(err);
2060
2061 VkFence fence;
2062 VkFenceCreateInfo fence_create_info = {};
2063 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2064 fence_create_info.pNext = NULL;
2065 fence_create_info.flags = 0;
2066 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2067 ASSERT_VK_SUCCESS(err);
2068
2069 // Induce failure by not calling vkDestroyFence
2070 vkDestroyDevice(testDevice, NULL);
2071 m_errorMonitor->VerifyFound();
2072}
2073
2074TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2075
2076 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2077 "attempt to delete them from another.");
2078
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002080
Cody Northropc31a84f2016-08-22 10:41:47 -06002081 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002082 VkCommandPool command_pool_one;
2083 VkCommandPool command_pool_two;
2084
2085 VkCommandPoolCreateInfo pool_create_info{};
2086 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2087 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2088 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002094 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002096 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002097 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002098 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002099 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002100 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002101
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002102 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002103
2104 m_errorMonitor->VerifyFound();
2105
2106 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2107 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2108}
2109
2110TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2111 VkResult err;
2112
2113 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002114 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002117
2118 ASSERT_NO_FATAL_FAILURE(InitState());
2119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2120
2121 VkDescriptorPoolSize ds_type_count = {};
2122 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 ds_type_count.descriptorCount = 1;
2124
2125 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2126 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2127 ds_pool_ci.pNext = NULL;
2128 ds_pool_ci.flags = 0;
2129 ds_pool_ci.maxSets = 1;
2130 ds_pool_ci.poolSizeCount = 1;
2131 ds_pool_ci.pPoolSizes = &ds_type_count;
2132
2133 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 // Create a second descriptor pool
2138 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002139 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002140 ASSERT_VK_SUCCESS(err);
2141
2142 VkDescriptorSetLayoutBinding dsl_binding = {};
2143 dsl_binding.binding = 0;
2144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2145 dsl_binding.descriptorCount = 1;
2146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2147 dsl_binding.pImmutableSamplers = NULL;
2148
2149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2151 ds_layout_ci.pNext = NULL;
2152 ds_layout_ci.bindingCount = 1;
2153 ds_layout_ci.pBindings = &dsl_binding;
2154
2155 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157 ASSERT_VK_SUCCESS(err);
2158
2159 VkDescriptorSet descriptorSet;
2160 VkDescriptorSetAllocateInfo alloc_info = {};
2161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2162 alloc_info.descriptorSetCount = 1;
2163 alloc_info.descriptorPool = ds_pool_one;
2164 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002166 ASSERT_VK_SUCCESS(err);
2167
2168 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2169
2170 m_errorMonitor->VerifyFound();
2171
2172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2173 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2174 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2175}
2176
2177TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002179
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002181
2182 ASSERT_NO_FATAL_FAILURE(InitState());
2183
2184 // Pass bogus handle into GetImageMemoryRequirements
2185 VkMemoryRequirements mem_reqs;
2186 uint64_t fakeImageHandle = 0xCADECADE;
2187 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2188
2189 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2190
2191 m_errorMonitor->VerifyFound();
2192}
2193
Karl Schultz6addd812016-02-02 17:17:23 -07002194TEST_F(VkLayerTest, PipelineNotBound) {
2195 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002198
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002201 ASSERT_NO_FATAL_FAILURE(InitState());
2202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2206 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002207
2208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2210 ds_pool_ci.pNext = NULL;
2211 ds_pool_ci.maxSets = 1;
2212 ds_pool_ci.poolSizeCount = 1;
2213 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002214
2215 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002216 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002217 ASSERT_VK_SUCCESS(err);
2218
2219 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002220 dsl_binding.binding = 0;
2221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2222 dsl_binding.descriptorCount = 1;
2223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2224 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002225
2226 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002227 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2228 ds_layout_ci.pNext = NULL;
2229 ds_layout_ci.bindingCount = 1;
2230 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231
2232 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234 ASSERT_VK_SUCCESS(err);
2235
2236 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002237 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002238 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002239 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002240 alloc_info.descriptorPool = ds_pool;
2241 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002243 ASSERT_VK_SUCCESS(err);
2244
2245 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002246 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2247 pipeline_layout_ci.pNext = NULL;
2248 pipeline_layout_ci.setLayoutCount = 1;
2249 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002250
2251 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002252 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002253 ASSERT_VK_SUCCESS(err);
2254
Mark Youngad779052016-01-06 14:26:04 -07002255 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002256
Tony Barbour552f6c02016-12-21 14:34:07 -07002257 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002258 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002259
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002260 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002261
Chia-I Wuf7458c52015-10-26 21:10:41 +08002262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002265}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002266
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002267TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2268 VkResult err;
2269
2270 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2271 "during bind[Buffer|Image]Memory time");
2272
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002273 ASSERT_NO_FATAL_FAILURE(InitState());
2274
2275 // Create an image, allocate memory, set a bad typeIndex and then try to
2276 // bind it
2277 VkImage image;
2278 VkDeviceMemory mem;
2279 VkMemoryRequirements mem_reqs;
2280 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2281 const int32_t tex_width = 32;
2282 const int32_t tex_height = 32;
2283
2284 VkImageCreateInfo image_create_info = {};
2285 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2286 image_create_info.pNext = NULL;
2287 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2288 image_create_info.format = tex_format;
2289 image_create_info.extent.width = tex_width;
2290 image_create_info.extent.height = tex_height;
2291 image_create_info.extent.depth = 1;
2292 image_create_info.mipLevels = 1;
2293 image_create_info.arrayLayers = 1;
2294 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2295 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2296 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2297 image_create_info.flags = 0;
2298
2299 VkMemoryAllocateInfo mem_alloc = {};
2300 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2301 mem_alloc.pNext = NULL;
2302 mem_alloc.allocationSize = 0;
2303 mem_alloc.memoryTypeIndex = 0;
2304
2305 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2306 ASSERT_VK_SUCCESS(err);
2307
2308 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2309 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002310
2311 // Introduce Failure, select invalid TypeIndex
2312 VkPhysicalDeviceMemoryProperties memory_info;
2313
2314 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2315 unsigned int i;
2316 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2317 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2318 mem_alloc.memoryTypeIndex = i;
2319 break;
2320 }
2321 }
2322 if (i >= memory_info.memoryTypeCount) {
2323 printf("No invalid memory type index could be found; skipped.\n");
2324 vkDestroyImage(m_device->device(), image, NULL);
2325 return;
2326 }
2327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 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 -06002329
2330 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2331 ASSERT_VK_SUCCESS(err);
2332
2333 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2334 (void)err;
2335
2336 m_errorMonitor->VerifyFound();
2337
2338 vkDestroyImage(m_device->device(), image, NULL);
2339 vkFreeMemory(m_device->device(), mem, NULL);
2340}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002341
Karl Schultz6addd812016-02-02 17:17:23 -07002342TEST_F(VkLayerTest, BindInvalidMemory) {
2343 VkResult err;
2344 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002345
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002347
Tobin Ehlisec598302015-09-15 15:02:17 -06002348 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
2350 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002351 VkImage image;
2352 VkDeviceMemory mem;
2353 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002354
Karl Schultz6addd812016-02-02 17:17:23 -07002355 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2356 const int32_t tex_width = 32;
2357 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002358
2359 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2361 image_create_info.pNext = NULL;
2362 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2363 image_create_info.format = tex_format;
2364 image_create_info.extent.width = tex_width;
2365 image_create_info.extent.height = tex_height;
2366 image_create_info.extent.depth = 1;
2367 image_create_info.mipLevels = 1;
2368 image_create_info.arrayLayers = 1;
2369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2370 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2371 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2372 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002373
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002374 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002375 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2376 mem_alloc.pNext = NULL;
2377 mem_alloc.allocationSize = 0;
2378 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002379
Chia-I Wuf7458c52015-10-26 21:10:41 +08002380 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002381 ASSERT_VK_SUCCESS(err);
2382
Karl Schultz6addd812016-02-02 17:17:23 -07002383 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002384
2385 mem_alloc.allocationSize = mem_reqs.size;
2386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002388 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389
2390 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002391 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002392 ASSERT_VK_SUCCESS(err);
2393
2394 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002395 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002396
2397 // Try to bind free memory that has been freed
2398 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2399 // This may very well return an error.
2400 (void)err;
2401
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002402 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002403
Chia-I Wuf7458c52015-10-26 21:10:41 +08002404 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002405}
2406
Karl Schultz6addd812016-02-02 17:17:23 -07002407TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2408 VkResult err;
2409 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002410
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002412
Tobin Ehlisec598302015-09-15 15:02:17 -06002413 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002414
Karl Schultz6addd812016-02-02 17:17:23 -07002415 // Create an image object, allocate memory, destroy the object and then try
2416 // to bind it
2417 VkImage image;
2418 VkDeviceMemory mem;
2419 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002420
Karl Schultz6addd812016-02-02 17:17:23 -07002421 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2422 const int32_t tex_width = 32;
2423 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002424
2425 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002426 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2427 image_create_info.pNext = NULL;
2428 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2429 image_create_info.format = tex_format;
2430 image_create_info.extent.width = tex_width;
2431 image_create_info.extent.height = tex_height;
2432 image_create_info.extent.depth = 1;
2433 image_create_info.mipLevels = 1;
2434 image_create_info.arrayLayers = 1;
2435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2436 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2437 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2438 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002439
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002440 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002441 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2442 mem_alloc.pNext = NULL;
2443 mem_alloc.allocationSize = 0;
2444 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chia-I Wuf7458c52015-10-26 21:10:41 +08002446 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002447 ASSERT_VK_SUCCESS(err);
2448
Karl Schultz6addd812016-02-02 17:17:23 -07002449 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002450
2451 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002453 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002454
2455 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002456 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002457 ASSERT_VK_SUCCESS(err);
2458
2459 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002460 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002461 ASSERT_VK_SUCCESS(err);
2462
2463 // Now Try to bind memory to this destroyed object
2464 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2465 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002466 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002467
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002468 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002469
Chia-I Wuf7458c52015-10-26 21:10:41 +08002470 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002472
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002473#endif // OBJ_TRACKER_TESTS
2474
Tobin Ehlis0788f522015-05-26 16:11:58 -06002475#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002476
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002477TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2478 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2479
2480 ASSERT_NO_FATAL_FAILURE(InitState());
2481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2482
2483 VkVertexInputBindingDescription input_binding;
2484 memset(&input_binding, 0, sizeof(input_binding));
2485
2486 VkVertexInputAttributeDescription input_attribs;
2487 memset(&input_attribs, 0, sizeof(input_attribs));
2488
2489 // Pick a really bad format for this purpose and make sure it should fail
2490 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2491 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2492 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2493 printf("Format unsuitable for test; skipped.\n");
2494 return;
2495 }
2496
2497 input_attribs.location = 0;
2498 char const *vsSource = "#version 450\n"
2499 "\n"
2500 "out gl_PerVertex {\n"
2501 " vec4 gl_Position;\n"
2502 "};\n"
2503 "void main(){\n"
2504 " gl_Position = vec4(1);\n"
2505 "}\n";
2506 char const *fsSource = "#version 450\n"
2507 "\n"
2508 "layout(location=0) out vec4 color;\n"
2509 "void main(){\n"
2510 " color = vec4(1);\n"
2511 "}\n";
2512
2513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2514 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2515 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2516
2517 VkPipelineObj pipe(m_device);
2518 pipe.AddColorAttachment();
2519 pipe.AddShader(&vs);
2520 pipe.AddShader(&fs);
2521
2522 pipe.AddVertexInputBindings(&input_binding, 1);
2523 pipe.AddVertexInputAttribs(&input_attribs, 1);
2524
2525 VkDescriptorSetObj descriptorSet(m_device);
2526 descriptorSet.AppendDummy();
2527 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2528
2529 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2530
2531 m_errorMonitor->VerifyFound();
2532}
2533
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002534TEST_F(VkLayerTest, ImageSampleCounts) {
2535
2536 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2537 "validation errors.");
2538 ASSERT_NO_FATAL_FAILURE(InitState());
2539
2540 VkMemoryPropertyFlags reqs = 0;
2541 VkImageCreateInfo image_create_info = {};
2542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2543 image_create_info.pNext = NULL;
2544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2545 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2546 image_create_info.extent.width = 256;
2547 image_create_info.extent.height = 256;
2548 image_create_info.extent.depth = 1;
2549 image_create_info.mipLevels = 1;
2550 image_create_info.arrayLayers = 1;
2551 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2552 image_create_info.flags = 0;
2553
2554 VkImageBlit blit_region = {};
2555 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2556 blit_region.srcSubresource.baseArrayLayer = 0;
2557 blit_region.srcSubresource.layerCount = 1;
2558 blit_region.srcSubresource.mipLevel = 0;
2559 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2560 blit_region.dstSubresource.baseArrayLayer = 0;
2561 blit_region.dstSubresource.layerCount = 1;
2562 blit_region.dstSubresource.mipLevel = 0;
2563
2564 // Create two images, the source with sampleCount = 2, and attempt to blit
2565 // between them
2566 {
2567 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002568 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002569 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002572 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002573 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002574 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002575 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2577 "of VK_SAMPLE_COUNT_2_BIT but "
2578 "must be VK_SAMPLE_COUNT_1_BIT");
2579 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2580 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002581 m_errorMonitor->VerifyFound();
2582 m_commandBuffer->EndCommandBuffer();
2583 }
2584
2585 // Create two images, the dest with sampleCount = 4, and attempt to blit
2586 // between them
2587 {
2588 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002589 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002590 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002591 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002592 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002593 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002594 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002596 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2598 "of VK_SAMPLE_COUNT_4_BIT but "
2599 "must be VK_SAMPLE_COUNT_1_BIT");
2600 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2601 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002602 m_errorMonitor->VerifyFound();
2603 m_commandBuffer->EndCommandBuffer();
2604 }
2605
2606 VkBufferImageCopy copy_region = {};
2607 copy_region.bufferRowLength = 128;
2608 copy_region.bufferImageHeight = 128;
2609 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2610 copy_region.imageSubresource.layerCount = 1;
2611 copy_region.imageExtent.height = 64;
2612 copy_region.imageExtent.width = 64;
2613 copy_region.imageExtent.depth = 1;
2614
2615 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2616 // buffer to image
2617 {
2618 vk_testing::Buffer src_buffer;
2619 VkMemoryPropertyFlags reqs = 0;
2620 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2621 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002623 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2627 "of VK_SAMPLE_COUNT_8_BIT but "
2628 "must be VK_SAMPLE_COUNT_1_BIT");
2629 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2630 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002631 m_errorMonitor->VerifyFound();
2632 m_commandBuffer->EndCommandBuffer();
2633 }
2634
2635 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2636 // image to buffer
2637 {
2638 vk_testing::Buffer dst_buffer;
2639 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2640 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002641 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002642 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002643 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002644 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2646 "of VK_SAMPLE_COUNT_2_BIT but "
2647 "must be VK_SAMPLE_COUNT_1_BIT");
2648 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002649 dst_buffer.handle(), 1, &copy_region);
2650 m_errorMonitor->VerifyFound();
2651 m_commandBuffer->EndCommandBuffer();
2652 }
2653}
2654
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002655TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002656 ASSERT_NO_FATAL_FAILURE(InitState());
2657
2658 VkImageObj src_image(m_device);
2659 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2660 VkImageObj dst_image(m_device);
2661 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2662 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002663 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002664
2665 VkImageBlit blitRegion = {};
2666 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2667 blitRegion.srcSubresource.baseArrayLayer = 0;
2668 blitRegion.srcSubresource.layerCount = 1;
2669 blitRegion.srcSubresource.mipLevel = 0;
2670 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2671 blitRegion.dstSubresource.baseArrayLayer = 0;
2672 blitRegion.dstSubresource.layerCount = 1;
2673 blitRegion.dstSubresource.mipLevel = 0;
2674
Dave Houlton34df4cb2016-12-01 16:43:06 -07002675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2676
2677 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2678 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002679
2680 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002681 m_commandBuffer->BeginCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002682 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2683 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2684
2685 m_errorMonitor->VerifyFound();
2686
Dave Houlton34df4cb2016-12-01 16:43:06 -07002687 // Test should generate 2 VU failures
2688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002690
2691 // Unsigned int vs signed int
2692 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2693 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2694
Dave Houlton34df4cb2016-12-01 16:43:06 -07002695 // TODO: Note that this only verifies that at least one of the VU enums was found
2696 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002697 m_errorMonitor->VerifyFound();
2698
Tony Barbour552f6c02016-12-21 14:34:07 -07002699 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002700}
2701
2702
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002703TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2704 VkResult err;
2705 bool pass;
2706
2707 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2708 ASSERT_NO_FATAL_FAILURE(InitState());
2709
2710 // If w/d/h granularity is 1, test is not meaningful
2711 // TODO: When virtual device limits are available, create a set of limits for this test that
2712 // will always have a granularity of > 1 for w, h, and d
2713 auto index = m_device->graphics_queue_node_index_;
2714 auto queue_family_properties = m_device->phy().queue_properties();
2715
2716 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2717 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2718 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2719 return;
2720 }
2721
2722 // Create two images of different types and try to copy between them
2723 VkImage srcImage;
2724 VkImage dstImage;
2725 VkDeviceMemory srcMem;
2726 VkDeviceMemory destMem;
2727 VkMemoryRequirements memReqs;
2728
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002729 VkImageCreateInfo image_create_info = {};
2730 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2731 image_create_info.pNext = NULL;
2732 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2733 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2734 image_create_info.extent.width = 32;
2735 image_create_info.extent.height = 32;
2736 image_create_info.extent.depth = 1;
2737 image_create_info.mipLevels = 1;
2738 image_create_info.arrayLayers = 4;
2739 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2740 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2741 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2742 image_create_info.flags = 0;
2743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002744 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002745 ASSERT_VK_SUCCESS(err);
2746
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002747 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002748 ASSERT_VK_SUCCESS(err);
2749
2750 // Allocate memory
2751 VkMemoryAllocateInfo memAlloc = {};
2752 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2753 memAlloc.pNext = NULL;
2754 memAlloc.allocationSize = 0;
2755 memAlloc.memoryTypeIndex = 0;
2756
2757 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2758 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002759 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002760 ASSERT_TRUE(pass);
2761 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2762 ASSERT_VK_SUCCESS(err);
2763
2764 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2765 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002766 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002767 ASSERT_VK_SUCCESS(err);
2768 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2769 ASSERT_VK_SUCCESS(err);
2770
2771 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2772 ASSERT_VK_SUCCESS(err);
2773 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2774 ASSERT_VK_SUCCESS(err);
2775
Tony Barbour552f6c02016-12-21 14:34:07 -07002776 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 VkImageCopy copyRegion;
2778 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2779 copyRegion.srcSubresource.mipLevel = 0;
2780 copyRegion.srcSubresource.baseArrayLayer = 0;
2781 copyRegion.srcSubresource.layerCount = 1;
2782 copyRegion.srcOffset.x = 0;
2783 copyRegion.srcOffset.y = 0;
2784 copyRegion.srcOffset.z = 0;
2785 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2786 copyRegion.dstSubresource.mipLevel = 0;
2787 copyRegion.dstSubresource.baseArrayLayer = 0;
2788 copyRegion.dstSubresource.layerCount = 1;
2789 copyRegion.dstOffset.x = 0;
2790 copyRegion.dstOffset.y = 0;
2791 copyRegion.dstOffset.z = 0;
2792 copyRegion.extent.width = 1;
2793 copyRegion.extent.height = 1;
2794 copyRegion.extent.depth = 1;
2795
2796 // Introduce failure by setting srcOffset to a bad granularity value
2797 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2799 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002800 m_errorMonitor->VerifyFound();
2801
2802 // Introduce failure by setting extent to a bad granularity value
2803 copyRegion.srcOffset.y = 0;
2804 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002807 m_errorMonitor->VerifyFound();
2808
2809 // Now do some buffer/image copies
2810 vk_testing::Buffer buffer;
2811 VkMemoryPropertyFlags reqs = 0;
2812 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2813 VkBufferImageCopy region = {};
2814 region.bufferOffset = 0;
2815 region.bufferRowLength = 3;
2816 region.bufferImageHeight = 128;
2817 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2818 region.imageSubresource.layerCount = 1;
2819 region.imageExtent.height = 16;
2820 region.imageExtent.width = 16;
2821 region.imageExtent.depth = 1;
2822 region.imageOffset.x = 0;
2823 region.imageOffset.y = 0;
2824 region.imageOffset.z = 0;
2825
2826 // Introduce failure by setting bufferRowLength to a bad granularity value
2827 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2829 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2830 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002831 m_errorMonitor->VerifyFound();
2832 region.bufferRowLength = 128;
2833
2834 // Introduce failure by setting bufferOffset to a bad granularity value
2835 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2837 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2838 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002839 m_errorMonitor->VerifyFound();
2840 region.bufferOffset = 0;
2841
2842 // Introduce failure by setting bufferImageHeight to a bad granularity value
2843 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2845 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2846 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002847 m_errorMonitor->VerifyFound();
2848 region.bufferImageHeight = 128;
2849
2850 // Introduce failure by setting imageExtent to a bad granularity value
2851 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2853 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2854 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002855 m_errorMonitor->VerifyFound();
2856 region.imageExtent.width = 16;
2857
2858 // Introduce failure by setting imageOffset to a bad granularity value
2859 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2861 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2862 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002863 m_errorMonitor->VerifyFound();
2864
Tony Barbour552f6c02016-12-21 14:34:07 -07002865 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002866
2867 vkDestroyImage(m_device->device(), srcImage, NULL);
2868 vkDestroyImage(m_device->device(), dstImage, NULL);
2869 vkFreeMemory(m_device->device(), srcMem, NULL);
2870 vkFreeMemory(m_device->device(), destMem, NULL);
2871}
2872
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002873TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002874 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2875 "attempt to submit them on a queue created in a different "
2876 "queue family.");
2877
Cody Northropc31a84f2016-08-22 10:41:47 -06002878 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002879 // This test is meaningless unless we have multiple queue families
2880 auto queue_family_properties = m_device->phy().queue_properties();
2881 if (queue_family_properties.size() < 2) {
2882 return;
2883 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002885 // Get safe index of another queue family
2886 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2887 ASSERT_NO_FATAL_FAILURE(InitState());
2888 // Create a second queue using a different queue family
2889 VkQueue other_queue;
2890 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2891
2892 // Record an empty cmd buffer
2893 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2894 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2895 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2896 vkEndCommandBuffer(m_commandBuffer->handle());
2897
2898 // And submit on the wrong queue
2899 VkSubmitInfo submit_info = {};
2900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2901 submit_info.commandBufferCount = 1;
2902 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002903 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002904
2905 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002906}
2907
Chris Forbes4c24a922016-11-16 08:59:10 +13002908TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2909 ASSERT_NO_FATAL_FAILURE(InitState());
2910
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002911 // There are no attachments, but refer to attachment 0.
2912 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002913 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002914 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2915 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002916 };
2917
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002918 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2919 nullptr,
2920 0,
2921 0,
2922 nullptr,
2923 1,
2924 subpasses,
2925 0,
2926 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002927 VkRenderPass rp;
2928
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002929 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002931 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002932 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2933 m_errorMonitor->VerifyFound();
2934}
2935
Chris Forbesa58c4522016-09-28 15:19:39 +13002936TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2937 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2938 ASSERT_NO_FATAL_FAILURE(InitState());
2939
2940 // A renderpass with two subpasses, both writing the same attachment.
2941 VkAttachmentDescription attach[] = {
2942 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2943 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2944 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2945 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2946 },
2947 };
2948 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2949 VkSubpassDescription subpasses[] = {
2950 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2951 1, &ref, nullptr, nullptr, 0, nullptr },
2952 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2953 1, &ref, nullptr, nullptr, 0, nullptr },
2954 };
2955 VkSubpassDependency dep = {
2956 0, 1,
2957 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2958 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2959 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2960 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2961 VK_DEPENDENCY_BY_REGION_BIT
2962 };
2963 VkRenderPassCreateInfo rpci = {
2964 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2965 0, 1, attach, 2, subpasses, 1, &dep
2966 };
2967 VkRenderPass rp;
2968 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2969 ASSERT_VK_SUCCESS(err);
2970
2971 VkImageObj image(m_device);
2972 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2973 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2974 VK_IMAGE_TILING_OPTIMAL, 0);
2975 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2976
2977 VkFramebufferCreateInfo fbci = {
2978 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2979 0, rp, 1, &imageView, 32, 32, 1
2980 };
2981 VkFramebuffer fb;
2982 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2983 ASSERT_VK_SUCCESS(err);
2984
2985 char const *vsSource =
2986 "#version 450\n"
2987 "void main() { gl_Position = vec4(1); }\n";
2988 char const *fsSource =
2989 "#version 450\n"
2990 "layout(location=0) out vec4 color;\n"
2991 "void main() { color = vec4(1); }\n";
2992
2993 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2994 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2995 VkPipelineObj pipe(m_device);
2996 pipe.AddColorAttachment();
2997 pipe.AddShader(&vs);
2998 pipe.AddShader(&fs);
2999 VkViewport view_port = {};
3000 m_viewports.push_back(view_port);
3001 pipe.SetViewport(m_viewports);
3002 VkRect2D rect = {};
3003 m_scissors.push_back(rect);
3004 pipe.SetScissor(m_scissors);
3005
3006 VkPipelineLayoutCreateInfo plci = {
3007 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3008 0, 0, nullptr, 0, nullptr
3009 };
3010 VkPipelineLayout pl;
3011 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3012 ASSERT_VK_SUCCESS(err);
3013 pipe.CreateVKPipeline(pl, rp);
3014
Tony Barbour552f6c02016-12-21 14:34:07 -07003015 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003016
3017 VkRenderPassBeginInfo rpbi = {
3018 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3019 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3020 };
3021
3022 // subtest 1: bind in the wrong subpass
3023 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3024 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3026 "built for subpass 0 but used in subpass 1");
3027 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3028 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3029 m_errorMonitor->VerifyFound();
3030
3031 vkCmdEndRenderPass(m_commandBuffer->handle());
3032
3033 // subtest 2: bind in correct subpass, then transition to next subpass
3034 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3035 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3036 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3038 "built for subpass 0 but used in subpass 1");
3039 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3040 m_errorMonitor->VerifyFound();
3041
3042 vkCmdEndRenderPass(m_commandBuffer->handle());
3043
Tony Barbour552f6c02016-12-21 14:34:07 -07003044 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003045
3046 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3047 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3048 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3049}
3050
Tony Barbour4e919972016-08-09 13:27:40 -06003051TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3052 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3053 "with extent outside of framebuffer");
3054 ASSERT_NO_FATAL_FAILURE(InitState());
3055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3058 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003059
3060 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3061 m_renderPassBeginInfo.renderArea.extent.width = 257;
3062 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003063 m_commandBuffer->BeginCommandBuffer();
3064 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003065 m_errorMonitor->VerifyFound();
3066}
3067
3068TEST_F(VkLayerTest, DisabledIndependentBlend) {
3069 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3070 "blend and then specifying different blend states for two "
3071 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003072 VkPhysicalDeviceFeatures features = {};
3073 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003074 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3077 "Invalid Pipeline CreateInfo: If independent blend feature not "
3078 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003079
Cody Northropc31a84f2016-08-22 10:41:47 -06003080 VkDescriptorSetObj descriptorSet(m_device);
3081 descriptorSet.AppendDummy();
3082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003083
Cody Northropc31a84f2016-08-22 10:41:47 -06003084 VkPipelineObj pipeline(m_device);
3085 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003087 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003088
Cody Northropc31a84f2016-08-22 10:41:47 -06003089 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3090 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3091 att_state1.blendEnable = VK_TRUE;
3092 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3093 att_state2.blendEnable = VK_FALSE;
3094 pipeline.AddColorAttachment(0, &att_state1);
3095 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003096 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003097 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003098}
3099
Chris Forbes26ec2122016-11-29 08:58:33 +13003100#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003101TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3102 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3103 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003104 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003108
3109 // Create a renderPass with a single color attachment
3110 VkAttachmentReference attach = {};
3111 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3112 VkSubpassDescription subpass = {};
3113 VkRenderPassCreateInfo rpci = {};
3114 rpci.subpassCount = 1;
3115 rpci.pSubpasses = &subpass;
3116 rpci.attachmentCount = 1;
3117 VkAttachmentDescription attach_desc = {};
3118 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3119 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3120 rpci.pAttachments = &attach_desc;
3121 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3122 VkRenderPass rp;
3123 subpass.pDepthStencilAttachment = &attach;
3124 subpass.pColorAttachments = NULL;
3125 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3126 m_errorMonitor->VerifyFound();
3127}
Chris Forbes26ec2122016-11-29 08:58:33 +13003128#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003129
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003130TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3131 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3132 "attachment reference of VK_ATTACHMENT_UNUSED");
3133
3134 ASSERT_NO_FATAL_FAILURE(InitState());
3135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003138
3139 VkAttachmentReference color_attach = {};
3140 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3141 color_attach.attachment = 0;
3142 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3143 VkSubpassDescription subpass = {};
3144 subpass.colorAttachmentCount = 1;
3145 subpass.pColorAttachments = &color_attach;
3146 subpass.preserveAttachmentCount = 1;
3147 subpass.pPreserveAttachments = &preserve_attachment;
3148
3149 VkRenderPassCreateInfo rpci = {};
3150 rpci.subpassCount = 1;
3151 rpci.pSubpasses = &subpass;
3152 rpci.attachmentCount = 1;
3153 VkAttachmentDescription attach_desc = {};
3154 attach_desc.format = VK_FORMAT_UNDEFINED;
3155 rpci.pAttachments = &attach_desc;
3156 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3157 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003158 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003159
3160 m_errorMonitor->VerifyFound();
3161
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003162 if (result == VK_SUCCESS) {
3163 vkDestroyRenderPass(m_device->device(), rp, NULL);
3164 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003165}
3166
Chris Forbesc5389742016-06-29 11:49:23 +12003167TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003168 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3169 "when the source of a subpass multisample resolve "
3170 "does not have multiple samples.");
3171
Chris Forbesc5389742016-06-29 11:49:23 +12003172 ASSERT_NO_FATAL_FAILURE(InitState());
3173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "Subpass 0 requests multisample resolve from attachment 0 which has "
3176 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003177
3178 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003179 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3180 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3181 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3182 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3183 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3184 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003185 };
3186
3187 VkAttachmentReference color = {
3188 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3189 };
3190
3191 VkAttachmentReference resolve = {
3192 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3193 };
3194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003197 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003198
3199 VkRenderPass rp;
3200 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3201
3202 m_errorMonitor->VerifyFound();
3203
3204 if (err == VK_SUCCESS)
3205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3206}
3207
3208TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003209 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3210 "when a subpass multisample resolve operation is "
3211 "requested, and the destination of that resolve has "
3212 "multiple samples.");
3213
Chris Forbesc5389742016-06-29 11:49:23 +12003214 ASSERT_NO_FATAL_FAILURE(InitState());
3215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3217 "Subpass 0 requests multisample resolve into attachment 1, which "
3218 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003219
3220 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003221 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3222 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3224 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3225 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3226 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003227 };
3228
3229 VkAttachmentReference color = {
3230 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3231 };
3232
3233 VkAttachmentReference resolve = {
3234 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3235 };
3236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003237 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003239 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003240
3241 VkRenderPass rp;
3242 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3243
3244 m_errorMonitor->VerifyFound();
3245
3246 if (err == VK_SUCCESS)
3247 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3248}
3249
Chris Forbes3f128ef2016-06-29 14:58:53 +12003250TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003251 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3252 "when the color and depth attachments used by a subpass "
3253 "have inconsistent sample counts");
3254
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255 ASSERT_NO_FATAL_FAILURE(InitState());
3256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3258 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003259
3260 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003261 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3262 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3263 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3264 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3265 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3266 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003267 };
3268
3269 VkAttachmentReference color[] = {
3270 {
3271 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3272 },
3273 {
3274 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3275 },
3276 };
3277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003280 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003281
3282 VkRenderPass rp;
3283 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3284
3285 m_errorMonitor->VerifyFound();
3286
3287 if (err == VK_SUCCESS)
3288 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3289}
3290
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003291TEST_F(VkLayerTest, FramebufferCreateErrors) {
3292 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003293 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003294 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003295 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3296 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3297 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3298 " 6. Framebuffer attachment where dimensions don't match\n"
3299 " 7. Framebuffer attachment w/o identity swizzle\n"
3300 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003301
3302 ASSERT_NO_FATAL_FAILURE(InitState());
3303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3304
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3306 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3307 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003308
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003309 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003310 VkAttachmentReference attach = {};
3311 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3312 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003313 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003314 VkRenderPassCreateInfo rpci = {};
3315 rpci.subpassCount = 1;
3316 rpci.pSubpasses = &subpass;
3317 rpci.attachmentCount = 1;
3318 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003319 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003320 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003321 rpci.pAttachments = &attach_desc;
3322 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3323 VkRenderPass rp;
3324 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3325 ASSERT_VK_SUCCESS(err);
3326
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003327 VkImageView ivs[2];
3328 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3329 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003330 VkFramebufferCreateInfo fb_info = {};
3331 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3332 fb_info.pNext = NULL;
3333 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003334 // Set mis-matching attachmentCount
3335 fb_info.attachmentCount = 2;
3336 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003337 fb_info.width = 100;
3338 fb_info.height = 100;
3339 fb_info.layers = 1;
3340
3341 VkFramebuffer fb;
3342 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3343
3344 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003345 if (err == VK_SUCCESS) {
3346 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3347 }
3348 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003349
3350 // Create a renderPass with a depth-stencil attachment created with
3351 // IMAGE_USAGE_COLOR_ATTACHMENT
3352 // Add our color attachment to pDepthStencilAttachment
3353 subpass.pDepthStencilAttachment = &attach;
3354 subpass.pColorAttachments = NULL;
3355 VkRenderPass rp_ds;
3356 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3357 ASSERT_VK_SUCCESS(err);
3358 // Set correct attachment count, but attachment has COLOR usage bit set
3359 fb_info.attachmentCount = 1;
3360 fb_info.renderPass = rp_ds;
3361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003363 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3364
3365 m_errorMonitor->VerifyFound();
3366 if (err == VK_SUCCESS) {
3367 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3368 }
3369 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003370
3371 // Create new renderpass with alternate attachment format from fb
3372 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3373 subpass.pDepthStencilAttachment = NULL;
3374 subpass.pColorAttachments = &attach;
3375 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3376 ASSERT_VK_SUCCESS(err);
3377
3378 // Cause error due to mis-matched formats between rp & fb
3379 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3380 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3382 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003383 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3384
3385 m_errorMonitor->VerifyFound();
3386 if (err == VK_SUCCESS) {
3387 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3388 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003389 vkDestroyRenderPass(m_device->device(), rp, NULL);
3390
3391 // Create new renderpass with alternate sample count from fb
3392 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3393 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3394 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3395 ASSERT_VK_SUCCESS(err);
3396
3397 // Cause error due to mis-matched sample count between rp & fb
3398 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3400 "that do not match the "
3401 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003402 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3403
3404 m_errorMonitor->VerifyFound();
3405 if (err == VK_SUCCESS) {
3406 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3407 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003408
3409 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003410
3411 // Create a custom imageView with non-1 mip levels
3412 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 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 -06003414 ASSERT_TRUE(image.initialized());
3415
3416 VkImageView view;
3417 VkImageViewCreateInfo ivci = {};
3418 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3419 ivci.image = image.handle();
3420 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3421 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3422 ivci.subresourceRange.layerCount = 1;
3423 ivci.subresourceRange.baseMipLevel = 0;
3424 // Set level count 2 (only 1 is allowed for FB attachment)
3425 ivci.subresourceRange.levelCount = 2;
3426 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3427 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3428 ASSERT_VK_SUCCESS(err);
3429 // Re-create renderpass to have matching sample count
3430 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3431 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3432 ASSERT_VK_SUCCESS(err);
3433
3434 fb_info.renderPass = rp;
3435 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003437 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3438
3439 m_errorMonitor->VerifyFound();
3440 if (err == VK_SUCCESS) {
3441 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3442 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003443 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003444 // Update view to original color buffer and grow FB dimensions too big
3445 fb_info.pAttachments = ivs;
3446 fb_info.height = 1024;
3447 fb_info.width = 1024;
3448 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3450 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003451 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3452
3453 m_errorMonitor->VerifyFound();
3454 if (err == VK_SUCCESS) {
3455 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3456 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003457 // Create view attachment with non-identity swizzle
3458 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3459 ivci.image = image.handle();
3460 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3461 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3462 ivci.subresourceRange.layerCount = 1;
3463 ivci.subresourceRange.baseMipLevel = 0;
3464 ivci.subresourceRange.levelCount = 1;
3465 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3466 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3467 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3468 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3469 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3470 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3471 ASSERT_VK_SUCCESS(err);
3472
3473 fb_info.pAttachments = &view;
3474 fb_info.height = 100;
3475 fb_info.width = 100;
3476 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3478 "framebuffer attachments must have "
3479 "been created with the identity "
3480 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003481 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3482
3483 m_errorMonitor->VerifyFound();
3484 if (err == VK_SUCCESS) {
3485 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3486 }
3487 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003488 // reset attachment to color attachment
3489 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003490
3491 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003492 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003493 fb_info.height = 100;
3494 fb_info.layers = 1;
3495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3496 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3497
3498 m_errorMonitor->VerifyFound();
3499 if (err == VK_SUCCESS) {
3500 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3501 }
3502
3503 // Request fb that exceeds max height
3504 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003505 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003506 fb_info.layers = 1;
3507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3508 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3509
3510 m_errorMonitor->VerifyFound();
3511 if (err == VK_SUCCESS) {
3512 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3513 }
3514
3515 // Request fb that exceeds max layers
3516 fb_info.width = 100;
3517 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003518 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003520 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3521
3522 m_errorMonitor->VerifyFound();
3523 if (err == VK_SUCCESS) {
3524 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3525 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003526
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003527 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003528}
3529
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003530TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3532 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003533
Cody Northropc31a84f2016-08-22 10:41:47 -06003534 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003535 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3537 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003538 m_errorMonitor->VerifyFound();
3539}
3540
3541TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003542 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3543 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003544
Cody Northropc31a84f2016-08-22 10:41:47 -06003545 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003546 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3548 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003549 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003550}
3551
3552TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003553 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3554 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003555
Cody Northropc31a84f2016-08-22 10:41:47 -06003556 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003557 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003560 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003561}
3562
3563TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3565 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003566
Cody Northropc31a84f2016-08-22 10:41:47 -06003567 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003568 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003571 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003572}
3573
Cortd713fe82016-07-27 09:51:27 -07003574TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3576 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003577
3578 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003579 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3581 "Dynamic blend constants state not set for this command buffer");
3582 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003583 m_errorMonitor->VerifyFound();
3584}
3585
3586TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003587 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3588 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003589
3590 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003591 if (!m_device->phy().features().depthBounds) {
3592 printf("Device does not support depthBounds test; skipped.\n");
3593 return;
3594 }
3595 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3597 "Dynamic depth bounds state not set for this command buffer");
3598 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003599 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003600}
3601
3602TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3604 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003605
3606 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003607 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3609 "Dynamic stencil read mask state not set for this command buffer");
3610 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003611 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003612}
3613
3614TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3616 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003617
3618 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003619 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3621 "Dynamic stencil write mask state not set for this command buffer");
3622 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003623 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003624}
3625
3626TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003627 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3628 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003629
3630 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003631 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3633 "Dynamic stencil reference state not set for this command buffer");
3634 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003635 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003636}
3637
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003638TEST_F(VkLayerTest, IndexBufferNotBound) {
3639 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003640
3641 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3643 "Index buffer object not bound to this command buffer when Indexed ");
3644 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003645 m_errorMonitor->VerifyFound();
3646}
3647
Karl Schultz6addd812016-02-02 17:17:23 -07003648TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3650 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3651 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003652
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003653 ASSERT_NO_FATAL_FAILURE(InitState());
3654 ASSERT_NO_FATAL_FAILURE(InitViewport());
3655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3656
Karl Schultz6addd812016-02-02 17:17:23 -07003657 // We luck out b/c by default the framework creates CB w/ the
3658 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003659 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003660 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003661 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003662
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003663 // Bypass framework since it does the waits automatically
3664 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003665 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003666 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3667 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003668 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003669 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003670 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003671 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003672 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003673 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003674 submit_info.pSignalSemaphores = NULL;
3675
Chris Forbes40028e22016-06-13 09:59:34 +12003676 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003677 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003678 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003679
Karl Schultz6addd812016-02-02 17:17:23 -07003680 // Cause validation error by re-submitting cmd buffer that should only be
3681 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003682 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003683 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003684
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003685 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686}
3687
Karl Schultz6addd812016-02-02 17:17:23 -07003688TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003689 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003690 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003691
3692 ASSERT_NO_FATAL_FAILURE(InitState());
3693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
Karl Schultz6addd812016-02-02 17:17:23 -07003695 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3696 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003697 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003698 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003699 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003700
3701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3703 ds_pool_ci.pNext = NULL;
3704 ds_pool_ci.flags = 0;
3705 ds_pool_ci.maxSets = 1;
3706 ds_pool_ci.poolSizeCount = 1;
3707 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003708
3709 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003710 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003711 ASSERT_VK_SUCCESS(err);
3712
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003713 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3714 dsl_binding_samp.binding = 0;
3715 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3716 dsl_binding_samp.descriptorCount = 1;
3717 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3718 dsl_binding_samp.pImmutableSamplers = NULL;
3719
3720 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3721 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3722 ds_layout_ci.pNext = NULL;
3723 ds_layout_ci.bindingCount = 1;
3724 ds_layout_ci.pBindings = &dsl_binding_samp;
3725
3726 VkDescriptorSetLayout ds_layout_samp;
3727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3728 ASSERT_VK_SUCCESS(err);
3729
3730 // Try to allocate 2 sets when pool only has 1 set
3731 VkDescriptorSet descriptor_sets[2];
3732 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3733 VkDescriptorSetAllocateInfo alloc_info = {};
3734 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3735 alloc_info.descriptorSetCount = 2;
3736 alloc_info.descriptorPool = ds_pool;
3737 alloc_info.pSetLayouts = set_layouts;
3738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3739 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3740 m_errorMonitor->VerifyFound();
3741
3742 alloc_info.descriptorSetCount = 1;
3743 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003744 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003745 dsl_binding.binding = 0;
3746 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3747 dsl_binding.descriptorCount = 1;
3748 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3749 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003750
Karl Schultz6addd812016-02-02 17:17:23 -07003751 ds_layout_ci.bindingCount = 1;
3752 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003753
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003754 VkDescriptorSetLayout ds_layout_ub;
3755 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003756 ASSERT_VK_SUCCESS(err);
3757
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003758 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003759 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003760 alloc_info.pSetLayouts = &ds_layout_ub;
3761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003763
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003764 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003765
Karl Schultz2825ab92016-12-02 08:23:14 -07003766 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003769}
3770
Karl Schultz6addd812016-02-02 17:17:23 -07003771TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3772 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003773
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003775
Tobin Ehlise735c692015-10-08 13:13:50 -06003776 ASSERT_NO_FATAL_FAILURE(InitState());
3777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003778
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003779 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3781 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003782
3783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3785 ds_pool_ci.pNext = NULL;
3786 ds_pool_ci.maxSets = 1;
3787 ds_pool_ci.poolSizeCount = 1;
3788 ds_pool_ci.flags = 0;
3789 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3790 // app can only call vkResetDescriptorPool on this pool.;
3791 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003792
3793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003795 ASSERT_VK_SUCCESS(err);
3796
3797 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003798 dsl_binding.binding = 0;
3799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3800 dsl_binding.descriptorCount = 1;
3801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3802 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003803
3804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3806 ds_layout_ci.pNext = NULL;
3807 ds_layout_ci.bindingCount = 1;
3808 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003809
3810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003812 ASSERT_VK_SUCCESS(err);
3813
3814 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003815 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003816 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003817 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003818 alloc_info.descriptorPool = ds_pool;
3819 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003821 ASSERT_VK_SUCCESS(err);
3822
3823 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003824 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003825
Chia-I Wuf7458c52015-10-26 21:10:41 +08003826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003828}
3829
Karl Schultz6addd812016-02-02 17:17:23 -07003830TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003831 // Attempt to clear Descriptor Pool with bad object.
3832 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003833
3834 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003836 uint64_t fake_pool_handle = 0xbaad6001;
3837 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3838 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003839 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003840}
3841
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003842TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003843 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3844 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003845 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003846 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003847
3848 uint64_t fake_set_handle = 0xbaad6001;
3849 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003850 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003852
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854
3855 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3856 layout_bindings[0].binding = 0;
3857 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3858 layout_bindings[0].descriptorCount = 1;
3859 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3860 layout_bindings[0].pImmutableSamplers = NULL;
3861
3862 VkDescriptorSetLayout descriptor_set_layout;
3863 VkDescriptorSetLayoutCreateInfo dslci = {};
3864 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3865 dslci.pNext = NULL;
3866 dslci.bindingCount = 1;
3867 dslci.pBindings = layout_bindings;
3868 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003869 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003870
3871 VkPipelineLayout pipeline_layout;
3872 VkPipelineLayoutCreateInfo plci = {};
3873 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3874 plci.pNext = NULL;
3875 plci.setLayoutCount = 1;
3876 plci.pSetLayouts = &descriptor_set_layout;
3877 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003878 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003879
Tony Barbour552f6c02016-12-21 14:34:07 -07003880 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003881 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3882 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003883 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07003884 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06003885 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3886 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003887}
3888
Karl Schultz6addd812016-02-02 17:17:23 -07003889TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003890 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3891 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003892 uint64_t fake_layout_handle = 0xbaad6001;
3893 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003895 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003896 VkPipelineLayout pipeline_layout;
3897 VkPipelineLayoutCreateInfo plci = {};
3898 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3899 plci.pNext = NULL;
3900 plci.setLayoutCount = 1;
3901 plci.pSetLayouts = &bad_layout;
3902 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3903
3904 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003905}
3906
Mark Muellerd4914412016-06-13 17:52:06 -06003907TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3908 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3909 "1) A uniform buffer update must have a valid buffer index."
3910 "2) When using an array of descriptors in a single WriteDescriptor,"
3911 " the descriptor types and stageflags must all be the same."
3912 "3) Immutable Sampler state must match across descriptors");
3913
Mike Weiblena6666382017-01-05 15:16:11 -07003914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06003915
3916 ASSERT_NO_FATAL_FAILURE(InitState());
3917 VkDescriptorPoolSize ds_type_count[4] = {};
3918 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3919 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003920 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003921 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003922 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003923 ds_type_count[2].descriptorCount = 1;
3924 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3925 ds_type_count[3].descriptorCount = 1;
3926
3927 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3928 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3929 ds_pool_ci.maxSets = 1;
3930 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3931 ds_pool_ci.pPoolSizes = ds_type_count;
3932
3933 VkDescriptorPool ds_pool;
3934 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3935 ASSERT_VK_SUCCESS(err);
3936
Mark Muellerb9896722016-06-16 09:54:29 -06003937 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003938 layout_binding[0].binding = 0;
3939 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3940 layout_binding[0].descriptorCount = 1;
3941 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3942 layout_binding[0].pImmutableSamplers = NULL;
3943
3944 layout_binding[1].binding = 1;
3945 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3946 layout_binding[1].descriptorCount = 1;
3947 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3948 layout_binding[1].pImmutableSamplers = NULL;
3949
3950 VkSamplerCreateInfo sampler_ci = {};
3951 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3952 sampler_ci.pNext = NULL;
3953 sampler_ci.magFilter = VK_FILTER_NEAREST;
3954 sampler_ci.minFilter = VK_FILTER_NEAREST;
3955 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3956 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3957 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3958 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3959 sampler_ci.mipLodBias = 1.0;
3960 sampler_ci.anisotropyEnable = VK_FALSE;
3961 sampler_ci.maxAnisotropy = 1;
3962 sampler_ci.compareEnable = VK_FALSE;
3963 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3964 sampler_ci.minLod = 1.0;
3965 sampler_ci.maxLod = 1.0;
3966 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3967 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3968 VkSampler sampler;
3969
3970 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 layout_binding[2].binding = 2;
3974 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3975 layout_binding[2].descriptorCount = 1;
3976 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3977 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3978
Mark Muellerd4914412016-06-13 17:52:06 -06003979 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3980 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3981 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3982 ds_layout_ci.pBindings = layout_binding;
3983 VkDescriptorSetLayout ds_layout;
3984 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3985 ASSERT_VK_SUCCESS(err);
3986
3987 VkDescriptorSetAllocateInfo alloc_info = {};
3988 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3989 alloc_info.descriptorSetCount = 1;
3990 alloc_info.descriptorPool = ds_pool;
3991 alloc_info.pSetLayouts = &ds_layout;
3992 VkDescriptorSet descriptorSet;
3993 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3994 ASSERT_VK_SUCCESS(err);
3995
3996 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3997 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3998 pipeline_layout_ci.pNext = NULL;
3999 pipeline_layout_ci.setLayoutCount = 1;
4000 pipeline_layout_ci.pSetLayouts = &ds_layout;
4001
4002 VkPipelineLayout pipeline_layout;
4003 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4004 ASSERT_VK_SUCCESS(err);
4005
Mark Mueller5c838ce2016-06-16 09:54:29 -06004006 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004007 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4008 descriptor_write.dstSet = descriptorSet;
4009 descriptor_write.dstBinding = 0;
4010 descriptor_write.descriptorCount = 1;
4011 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4012
Mark Mueller5c838ce2016-06-16 09:54:29 -06004013 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004014 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4015 m_errorMonitor->VerifyFound();
4016
4017 // Create a buffer to update the descriptor with
4018 uint32_t qfi = 0;
4019 VkBufferCreateInfo buffCI = {};
4020 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4021 buffCI.size = 1024;
4022 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4023 buffCI.queueFamilyIndexCount = 1;
4024 buffCI.pQueueFamilyIndices = &qfi;
4025
4026 VkBuffer dyub;
4027 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4028 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004029
Tony Barboure132c5f2016-12-12 11:50:20 -07004030 VkDeviceMemory mem;
4031 VkMemoryRequirements mem_reqs;
4032 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4033
4034 VkMemoryAllocateInfo mem_alloc_info = {};
4035 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4036 mem_alloc_info.allocationSize = mem_reqs.size;
4037 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4038 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4039 ASSERT_VK_SUCCESS(err);
4040
4041 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4042 ASSERT_VK_SUCCESS(err);
4043
4044 VkDescriptorBufferInfo buffInfo[2] = {};
4045 buffInfo[0].buffer = dyub;
4046 buffInfo[0].offset = 0;
4047 buffInfo[0].range = 1024;
4048 buffInfo[1].buffer = dyub;
4049 buffInfo[1].offset = 0;
4050 buffInfo[1].range = 1024;
4051 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004052 descriptor_write.descriptorCount = 2;
4053
Mark Mueller5c838ce2016-06-16 09:54:29 -06004054 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004056 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4057 m_errorMonitor->VerifyFound();
4058
Mark Mueller5c838ce2016-06-16 09:54:29 -06004059 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4060 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004061 descriptor_write.dstBinding = 1;
4062 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004063
Mark Mueller5c838ce2016-06-16 09:54:29 -06004064 // Make pImageInfo index non-null to avoid complaints of it missing
4065 VkDescriptorImageInfo imageInfo = {};
4066 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4067 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4070 m_errorMonitor->VerifyFound();
4071
Mark Muellerd4914412016-06-13 17:52:06 -06004072 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004073 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004074 vkDestroySampler(m_device->device(), sampler, NULL);
4075 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4076 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4077 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4078}
4079
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004080TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4081 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4082 "due to a buffer dependency being destroyed.");
4083 ASSERT_NO_FATAL_FAILURE(InitState());
4084
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004085 VkBuffer buffer;
4086 VkDeviceMemory mem;
4087 VkMemoryRequirements mem_reqs;
4088
4089 VkBufferCreateInfo buf_info = {};
4090 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004091 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004092 buf_info.size = 256;
4093 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4094 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4095 ASSERT_VK_SUCCESS(err);
4096
4097 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4098
4099 VkMemoryAllocateInfo alloc_info = {};
4100 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4101 alloc_info.allocationSize = 256;
4102 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004103 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 -06004104 if (!pass) {
4105 vkDestroyBuffer(m_device->device(), buffer, NULL);
4106 return;
4107 }
4108 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4109 ASSERT_VK_SUCCESS(err);
4110
4111 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4112 ASSERT_VK_SUCCESS(err);
4113
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004114 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004115 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004116 m_commandBuffer->EndCommandBuffer();
4117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004119 // Destroy buffer dependency prior to submit to cause ERROR
4120 vkDestroyBuffer(m_device->device(), buffer, NULL);
4121
4122 VkSubmitInfo submit_info = {};
4123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4124 submit_info.commandBufferCount = 1;
4125 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4126 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4127
4128 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004129 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004130 vkFreeMemory(m_device->handle(), mem, NULL);
4131}
4132
Tobin Ehlisea413442016-09-28 10:23:59 -06004133TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4134 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4135
4136 ASSERT_NO_FATAL_FAILURE(InitState());
4137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4138
4139 VkDescriptorPoolSize ds_type_count;
4140 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4141 ds_type_count.descriptorCount = 1;
4142
4143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4145 ds_pool_ci.maxSets = 1;
4146 ds_pool_ci.poolSizeCount = 1;
4147 ds_pool_ci.pPoolSizes = &ds_type_count;
4148
4149 VkDescriptorPool ds_pool;
4150 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4151 ASSERT_VK_SUCCESS(err);
4152
4153 VkDescriptorSetLayoutBinding layout_binding;
4154 layout_binding.binding = 0;
4155 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4156 layout_binding.descriptorCount = 1;
4157 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4158 layout_binding.pImmutableSamplers = NULL;
4159
4160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4162 ds_layout_ci.bindingCount = 1;
4163 ds_layout_ci.pBindings = &layout_binding;
4164 VkDescriptorSetLayout ds_layout;
4165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4166 ASSERT_VK_SUCCESS(err);
4167
4168 VkDescriptorSetAllocateInfo alloc_info = {};
4169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4170 alloc_info.descriptorSetCount = 1;
4171 alloc_info.descriptorPool = ds_pool;
4172 alloc_info.pSetLayouts = &ds_layout;
4173 VkDescriptorSet descriptor_set;
4174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4175 ASSERT_VK_SUCCESS(err);
4176
4177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4179 pipeline_layout_ci.pNext = NULL;
4180 pipeline_layout_ci.setLayoutCount = 1;
4181 pipeline_layout_ci.pSetLayouts = &ds_layout;
4182
4183 VkPipelineLayout pipeline_layout;
4184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4185 ASSERT_VK_SUCCESS(err);
4186
4187 VkBuffer buffer;
4188 uint32_t queue_family_index = 0;
4189 VkBufferCreateInfo buffer_create_info = {};
4190 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4191 buffer_create_info.size = 1024;
4192 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4193 buffer_create_info.queueFamilyIndexCount = 1;
4194 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4195
4196 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4197 ASSERT_VK_SUCCESS(err);
4198
4199 VkMemoryRequirements memory_reqs;
4200 VkDeviceMemory buffer_memory;
4201
4202 VkMemoryAllocateInfo memory_info = {};
4203 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4204 memory_info.allocationSize = 0;
4205 memory_info.memoryTypeIndex = 0;
4206
4207 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4208 memory_info.allocationSize = memory_reqs.size;
4209 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4210 ASSERT_TRUE(pass);
4211
4212 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4213 ASSERT_VK_SUCCESS(err);
4214 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4215 ASSERT_VK_SUCCESS(err);
4216
4217 VkBufferView view;
4218 VkBufferViewCreateInfo bvci = {};
4219 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4220 bvci.buffer = buffer;
4221 bvci.format = VK_FORMAT_R8_UNORM;
4222 bvci.range = VK_WHOLE_SIZE;
4223
4224 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4225 ASSERT_VK_SUCCESS(err);
4226
4227 VkWriteDescriptorSet descriptor_write = {};
4228 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4229 descriptor_write.dstSet = descriptor_set;
4230 descriptor_write.dstBinding = 0;
4231 descriptor_write.descriptorCount = 1;
4232 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4233 descriptor_write.pTexelBufferView = &view;
4234
4235 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4236
4237 char const *vsSource = "#version 450\n"
4238 "\n"
4239 "out gl_PerVertex { \n"
4240 " vec4 gl_Position;\n"
4241 "};\n"
4242 "void main(){\n"
4243 " gl_Position = vec4(1);\n"
4244 "}\n";
4245 char const *fsSource = "#version 450\n"
4246 "\n"
4247 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4248 "layout(location=0) out vec4 x;\n"
4249 "void main(){\n"
4250 " x = imageLoad(s, 0);\n"
4251 "}\n";
4252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4254 VkPipelineObj pipe(m_device);
4255 pipe.AddShader(&vs);
4256 pipe.AddShader(&fs);
4257 pipe.AddColorAttachment();
4258 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4259
4260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4262
Tony Barbour552f6c02016-12-21 14:34:07 -07004263 m_commandBuffer->BeginCommandBuffer();
4264 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4265
Tobin Ehlisea413442016-09-28 10:23:59 -06004266 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4267 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4268 VkRect2D scissor = {{0, 0}, {16, 16}};
4269 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4270 // Bind pipeline to cmd buffer
4271 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4272 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4273 &descriptor_set, 0, nullptr);
4274 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004275 m_commandBuffer->EndRenderPass();
4276 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004277
4278 // Delete BufferView in order to invalidate cmd buffer
4279 vkDestroyBufferView(m_device->device(), view, NULL);
4280 // Now attempt submit of cmd buffer
4281 VkSubmitInfo submit_info = {};
4282 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4283 submit_info.commandBufferCount = 1;
4284 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4286 m_errorMonitor->VerifyFound();
4287
4288 // Clean-up
4289 vkDestroyBuffer(m_device->device(), buffer, NULL);
4290 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4291 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4294}
4295
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004296TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4297 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4298 "due to an image dependency being destroyed.");
4299 ASSERT_NO_FATAL_FAILURE(InitState());
4300
4301 VkImage image;
4302 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4303 VkImageCreateInfo image_create_info = {};
4304 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4305 image_create_info.pNext = NULL;
4306 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4307 image_create_info.format = tex_format;
4308 image_create_info.extent.width = 32;
4309 image_create_info.extent.height = 32;
4310 image_create_info.extent.depth = 1;
4311 image_create_info.mipLevels = 1;
4312 image_create_info.arrayLayers = 1;
4313 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4314 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004315 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004316 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004317 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004318 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004319 // Have to bind memory to image before recording cmd in cmd buffer using it
4320 VkMemoryRequirements mem_reqs;
4321 VkDeviceMemory image_mem;
4322 bool pass;
4323 VkMemoryAllocateInfo mem_alloc = {};
4324 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4325 mem_alloc.pNext = NULL;
4326 mem_alloc.memoryTypeIndex = 0;
4327 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4328 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004330 ASSERT_TRUE(pass);
4331 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4332 ASSERT_VK_SUCCESS(err);
4333 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4334 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004335
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004336 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004337 VkClearColorValue ccv;
4338 ccv.float32[0] = 1.0f;
4339 ccv.float32[1] = 1.0f;
4340 ccv.float32[2] = 1.0f;
4341 ccv.float32[3] = 1.0f;
4342 VkImageSubresourceRange isr = {};
4343 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004344 isr.baseArrayLayer = 0;
4345 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004346 isr.layerCount = 1;
4347 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004348 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004349 m_commandBuffer->EndCommandBuffer();
4350
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004352 // Destroy image dependency prior to submit to cause ERROR
4353 vkDestroyImage(m_device->device(), image, NULL);
4354
4355 VkSubmitInfo submit_info = {};
4356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4357 submit_info.commandBufferCount = 1;
4358 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4359 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4360
4361 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004362 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004363}
4364
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004365TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4366 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4367 "due to a framebuffer image dependency being destroyed.");
4368 VkFormatProperties format_properties;
4369 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004370 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4371 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004372 return;
4373 }
4374
4375 ASSERT_NO_FATAL_FAILURE(InitState());
4376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4377
4378 VkImageCreateInfo image_ci = {};
4379 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4380 image_ci.pNext = NULL;
4381 image_ci.imageType = VK_IMAGE_TYPE_2D;
4382 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4383 image_ci.extent.width = 32;
4384 image_ci.extent.height = 32;
4385 image_ci.extent.depth = 1;
4386 image_ci.mipLevels = 1;
4387 image_ci.arrayLayers = 1;
4388 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4389 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004390 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004391 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4392 image_ci.flags = 0;
4393 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004394 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004395
4396 VkMemoryRequirements memory_reqs;
4397 VkDeviceMemory image_memory;
4398 bool pass;
4399 VkMemoryAllocateInfo memory_info = {};
4400 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4401 memory_info.pNext = NULL;
4402 memory_info.allocationSize = 0;
4403 memory_info.memoryTypeIndex = 0;
4404 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4405 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004406 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004407 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004409 ASSERT_VK_SUCCESS(err);
4410 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4411 ASSERT_VK_SUCCESS(err);
4412
4413 VkImageViewCreateInfo ivci = {
4414 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4415 nullptr,
4416 0,
4417 image,
4418 VK_IMAGE_VIEW_TYPE_2D,
4419 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004421 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4422 };
4423 VkImageView view;
4424 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4425 ASSERT_VK_SUCCESS(err);
4426
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004427 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004428 VkFramebuffer fb;
4429 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4430 ASSERT_VK_SUCCESS(err);
4431
4432 // Just use default renderpass with our framebuffer
4433 m_renderPassBeginInfo.framebuffer = fb;
4434 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004435 m_commandBuffer->BeginCommandBuffer();
4436 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4437 m_commandBuffer->EndRenderPass();
4438 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004439 // Destroy image attached to framebuffer to invalidate cmd buffer
4440 vkDestroyImage(m_device->device(), image, NULL);
4441 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004443 QueueCommandBuffer(false);
4444 m_errorMonitor->VerifyFound();
4445
4446 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4447 vkDestroyImageView(m_device->device(), view, nullptr);
4448 vkFreeMemory(m_device->device(), image_memory, nullptr);
4449}
4450
Tobin Ehlisb329f992016-10-12 13:20:29 -06004451TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4452 TEST_DESCRIPTION("Delete in-use framebuffer.");
4453 VkFormatProperties format_properties;
4454 VkResult err = VK_SUCCESS;
4455 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4456
4457 ASSERT_NO_FATAL_FAILURE(InitState());
4458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4459
4460 VkImageObj image(m_device);
4461 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4462 ASSERT_TRUE(image.initialized());
4463 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4464
4465 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4466 VkFramebuffer fb;
4467 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4468 ASSERT_VK_SUCCESS(err);
4469
4470 // Just use default renderpass with our framebuffer
4471 m_renderPassBeginInfo.framebuffer = fb;
4472 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004473 m_commandBuffer->BeginCommandBuffer();
4474 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4475 m_commandBuffer->EndRenderPass();
4476 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004477 // Submit cmd buffer to put it in-flight
4478 VkSubmitInfo submit_info = {};
4479 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4480 submit_info.commandBufferCount = 1;
4481 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4482 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4483 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004485 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4486 m_errorMonitor->VerifyFound();
4487 // Wait for queue to complete so we can safely destroy everything
4488 vkQueueWaitIdle(m_device->m_queue);
4489 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4490}
4491
Tobin Ehlis88becd72016-09-21 14:33:41 -06004492TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4493 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4494 VkFormatProperties format_properties;
4495 VkResult err = VK_SUCCESS;
4496 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004497
4498 ASSERT_NO_FATAL_FAILURE(InitState());
4499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4500
4501 VkImageCreateInfo image_ci = {};
4502 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4503 image_ci.pNext = NULL;
4504 image_ci.imageType = VK_IMAGE_TYPE_2D;
4505 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4506 image_ci.extent.width = 256;
4507 image_ci.extent.height = 256;
4508 image_ci.extent.depth = 1;
4509 image_ci.mipLevels = 1;
4510 image_ci.arrayLayers = 1;
4511 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4512 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004513 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004514 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4515 image_ci.flags = 0;
4516 VkImage image;
4517 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4518
4519 VkMemoryRequirements memory_reqs;
4520 VkDeviceMemory image_memory;
4521 bool pass;
4522 VkMemoryAllocateInfo memory_info = {};
4523 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4524 memory_info.pNext = NULL;
4525 memory_info.allocationSize = 0;
4526 memory_info.memoryTypeIndex = 0;
4527 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4528 memory_info.allocationSize = memory_reqs.size;
4529 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4530 ASSERT_TRUE(pass);
4531 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4532 ASSERT_VK_SUCCESS(err);
4533 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4534 ASSERT_VK_SUCCESS(err);
4535
4536 VkImageViewCreateInfo ivci = {
4537 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4538 nullptr,
4539 0,
4540 image,
4541 VK_IMAGE_VIEW_TYPE_2D,
4542 VK_FORMAT_B8G8R8A8_UNORM,
4543 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4544 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4545 };
4546 VkImageView view;
4547 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4548 ASSERT_VK_SUCCESS(err);
4549
4550 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4551 VkFramebuffer fb;
4552 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4553 ASSERT_VK_SUCCESS(err);
4554
4555 // Just use default renderpass with our framebuffer
4556 m_renderPassBeginInfo.framebuffer = fb;
4557 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004558 m_commandBuffer->BeginCommandBuffer();
4559 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4560 m_commandBuffer->EndRenderPass();
4561 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004562 // Submit cmd buffer to put it (and attached imageView) in-flight
4563 VkSubmitInfo submit_info = {};
4564 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4565 submit_info.commandBufferCount = 1;
4566 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4567 // Submit cmd buffer to put framebuffer and children in-flight
4568 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4569 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004571 vkDestroyImage(m_device->device(), image, NULL);
4572 m_errorMonitor->VerifyFound();
4573 // Wait for queue to complete so we can safely destroy image and other objects
4574 vkQueueWaitIdle(m_device->m_queue);
4575 vkDestroyImage(m_device->device(), image, NULL);
4576 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4577 vkDestroyImageView(m_device->device(), view, nullptr);
4578 vkFreeMemory(m_device->device(), image_memory, nullptr);
4579}
4580
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004581TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4582 TEST_DESCRIPTION("Delete in-use renderPass.");
4583
4584 ASSERT_NO_FATAL_FAILURE(InitState());
4585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4586
4587 // Create simple renderpass
4588 VkAttachmentReference attach = {};
4589 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4590 VkSubpassDescription subpass = {};
4591 subpass.pColorAttachments = &attach;
4592 VkRenderPassCreateInfo rpci = {};
4593 rpci.subpassCount = 1;
4594 rpci.pSubpasses = &subpass;
4595 rpci.attachmentCount = 1;
4596 VkAttachmentDescription attach_desc = {};
4597 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4598 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4599 rpci.pAttachments = &attach_desc;
4600 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4601 VkRenderPass rp;
4602 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4603 ASSERT_VK_SUCCESS(err);
4604
4605 // Create a pipeline that uses the given renderpass
4606 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4607 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4608
4609 VkPipelineLayout pipeline_layout;
4610 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4611 ASSERT_VK_SUCCESS(err);
4612
4613 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4614 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4615 vp_state_ci.viewportCount = 1;
4616 VkViewport vp = {}; // Just need dummy vp to point to
4617 vp_state_ci.pViewports = &vp;
4618 vp_state_ci.scissorCount = 1;
4619 VkRect2D scissors = {}; // Dummy scissors to point to
4620 vp_state_ci.pScissors = &scissors;
4621
4622 VkPipelineShaderStageCreateInfo shaderStages[2];
4623 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4624
4625 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4626 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4627 // but add it to be able to run on more devices
4628 shaderStages[0] = vs.GetStageCreateInfo();
4629 shaderStages[1] = fs.GetStageCreateInfo();
4630
4631 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4632 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4633
4634 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4635 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4636 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4637
4638 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4639 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4640 rs_ci.rasterizerDiscardEnable = true;
4641 rs_ci.lineWidth = 1.0f;
4642
4643 VkPipelineColorBlendAttachmentState att = {};
4644 att.blendEnable = VK_FALSE;
4645 att.colorWriteMask = 0xf;
4646
4647 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4648 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4649 cb_ci.attachmentCount = 1;
4650 cb_ci.pAttachments = &att;
4651
4652 VkGraphicsPipelineCreateInfo gp_ci = {};
4653 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4654 gp_ci.stageCount = 2;
4655 gp_ci.pStages = shaderStages;
4656 gp_ci.pVertexInputState = &vi_ci;
4657 gp_ci.pInputAssemblyState = &ia_ci;
4658 gp_ci.pViewportState = &vp_state_ci;
4659 gp_ci.pRasterizationState = &rs_ci;
4660 gp_ci.pColorBlendState = &cb_ci;
4661 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4662 gp_ci.layout = pipeline_layout;
4663 gp_ci.renderPass = rp;
4664
4665 VkPipelineCacheCreateInfo pc_ci = {};
4666 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4667
4668 VkPipeline pipeline;
4669 VkPipelineCache pipe_cache;
4670 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4671 ASSERT_VK_SUCCESS(err);
4672
4673 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4674 ASSERT_VK_SUCCESS(err);
4675 // Bind pipeline to cmd buffer, will also bind renderpass
4676 m_commandBuffer->BeginCommandBuffer();
4677 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4678 m_commandBuffer->EndCommandBuffer();
4679
4680 VkSubmitInfo submit_info = {};
4681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4682 submit_info.commandBufferCount = 1;
4683 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4684 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4685
4686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4687 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4688 m_errorMonitor->VerifyFound();
4689
4690 // Wait for queue to complete so we can safely destroy everything
4691 vkQueueWaitIdle(m_device->m_queue);
4692 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4693 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4694 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4695 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4696}
4697
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004698TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004699 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004700 ASSERT_NO_FATAL_FAILURE(InitState());
4701
4702 VkImage image;
4703 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4704 VkImageCreateInfo image_create_info = {};
4705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4706 image_create_info.pNext = NULL;
4707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4708 image_create_info.format = tex_format;
4709 image_create_info.extent.width = 32;
4710 image_create_info.extent.height = 32;
4711 image_create_info.extent.depth = 1;
4712 image_create_info.mipLevels = 1;
4713 image_create_info.arrayLayers = 1;
4714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004716 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004717 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004718 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004719 ASSERT_VK_SUCCESS(err);
4720 // Have to bind memory to image before recording cmd in cmd buffer using it
4721 VkMemoryRequirements mem_reqs;
4722 VkDeviceMemory image_mem;
4723 bool pass;
4724 VkMemoryAllocateInfo mem_alloc = {};
4725 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4726 mem_alloc.pNext = NULL;
4727 mem_alloc.memoryTypeIndex = 0;
4728 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4729 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004731 ASSERT_TRUE(pass);
4732 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4733 ASSERT_VK_SUCCESS(err);
4734
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004735 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004737 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004738
4739 m_commandBuffer->BeginCommandBuffer();
4740 VkClearColorValue ccv;
4741 ccv.float32[0] = 1.0f;
4742 ccv.float32[1] = 1.0f;
4743 ccv.float32[2] = 1.0f;
4744 ccv.float32[3] = 1.0f;
4745 VkImageSubresourceRange isr = {};
4746 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4747 isr.baseArrayLayer = 0;
4748 isr.baseMipLevel = 0;
4749 isr.layerCount = 1;
4750 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004751 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004752 m_commandBuffer->EndCommandBuffer();
4753
4754 m_errorMonitor->VerifyFound();
4755 vkDestroyImage(m_device->device(), image, NULL);
4756 vkFreeMemory(m_device->device(), image_mem, nullptr);
4757}
4758
4759TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004761 ASSERT_NO_FATAL_FAILURE(InitState());
4762
4763 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 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 -06004765 VK_IMAGE_TILING_OPTIMAL, 0);
4766 ASSERT_TRUE(image.initialized());
4767
4768 VkBuffer buffer;
4769 VkDeviceMemory mem;
4770 VkMemoryRequirements mem_reqs;
4771
4772 VkBufferCreateInfo buf_info = {};
4773 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004774 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004775 buf_info.size = 256;
4776 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4777 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4778 ASSERT_VK_SUCCESS(err);
4779
4780 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4781
4782 VkMemoryAllocateInfo alloc_info = {};
4783 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4784 alloc_info.allocationSize = 256;
4785 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004786 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 -06004787 if (!pass) {
4788 vkDestroyBuffer(m_device->device(), buffer, NULL);
4789 return;
4790 }
4791 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4792 ASSERT_VK_SUCCESS(err);
4793
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004794 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004796 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004797 VkBufferImageCopy region = {};
4798 region.bufferRowLength = 128;
4799 region.bufferImageHeight = 128;
4800 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4801
4802 region.imageSubresource.layerCount = 1;
4803 region.imageExtent.height = 4;
4804 region.imageExtent.width = 4;
4805 region.imageExtent.depth = 1;
4806 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004807 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4808 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004809 m_commandBuffer->EndCommandBuffer();
4810
4811 m_errorMonitor->VerifyFound();
4812
4813 vkDestroyBuffer(m_device->device(), buffer, NULL);
4814 vkFreeMemory(m_device->handle(), mem, NULL);
4815}
4816
Tobin Ehlis85940f52016-07-07 16:57:21 -06004817TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4818 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4819 "due to an event dependency being destroyed.");
4820 ASSERT_NO_FATAL_FAILURE(InitState());
4821
4822 VkEvent event;
4823 VkEventCreateInfo evci = {};
4824 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4825 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4826 ASSERT_VK_SUCCESS(result);
4827
4828 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004829 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004830 m_commandBuffer->EndCommandBuffer();
4831
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004833 // Destroy event dependency prior to submit to cause ERROR
4834 vkDestroyEvent(m_device->device(), event, NULL);
4835
4836 VkSubmitInfo submit_info = {};
4837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4838 submit_info.commandBufferCount = 1;
4839 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4840 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4841
4842 m_errorMonitor->VerifyFound();
4843}
4844
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004845TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4846 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4847 "due to a query pool dependency being destroyed.");
4848 ASSERT_NO_FATAL_FAILURE(InitState());
4849
4850 VkQueryPool query_pool;
4851 VkQueryPoolCreateInfo qpci{};
4852 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4853 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4854 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004855 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004856 ASSERT_VK_SUCCESS(result);
4857
4858 m_commandBuffer->BeginCommandBuffer();
4859 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4860 m_commandBuffer->EndCommandBuffer();
4861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004863 // Destroy query pool dependency prior to submit to cause ERROR
4864 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4865
4866 VkSubmitInfo submit_info = {};
4867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4868 submit_info.commandBufferCount = 1;
4869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4871
4872 m_errorMonitor->VerifyFound();
4873}
4874
Tobin Ehlis24130d92016-07-08 15:50:53 -06004875TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4876 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4877 "due to a pipeline dependency being destroyed.");
4878 ASSERT_NO_FATAL_FAILURE(InitState());
4879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4880
4881 VkResult err;
4882
4883 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4884 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4885
4886 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004888 ASSERT_VK_SUCCESS(err);
4889
4890 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4891 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4892 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004894 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004895 vp_state_ci.scissorCount = 1;
4896 VkRect2D scissors = {}; // Dummy scissors to point to
4897 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004898
4899 VkPipelineShaderStageCreateInfo shaderStages[2];
4900 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004902 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4903 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4904 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004905 shaderStages[0] = vs.GetStageCreateInfo();
4906 shaderStages[1] = fs.GetStageCreateInfo();
4907
4908 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4909 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4910
4911 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4912 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4913 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4914
4915 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4916 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004917 rs_ci.rasterizerDiscardEnable = true;
4918 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004919
4920 VkPipelineColorBlendAttachmentState att = {};
4921 att.blendEnable = VK_FALSE;
4922 att.colorWriteMask = 0xf;
4923
4924 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4925 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4926 cb_ci.attachmentCount = 1;
4927 cb_ci.pAttachments = &att;
4928
4929 VkGraphicsPipelineCreateInfo gp_ci = {};
4930 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4931 gp_ci.stageCount = 2;
4932 gp_ci.pStages = shaderStages;
4933 gp_ci.pVertexInputState = &vi_ci;
4934 gp_ci.pInputAssemblyState = &ia_ci;
4935 gp_ci.pViewportState = &vp_state_ci;
4936 gp_ci.pRasterizationState = &rs_ci;
4937 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004938 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4939 gp_ci.layout = pipeline_layout;
4940 gp_ci.renderPass = renderPass();
4941
4942 VkPipelineCacheCreateInfo pc_ci = {};
4943 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4944
4945 VkPipeline pipeline;
4946 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004947 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004948 ASSERT_VK_SUCCESS(err);
4949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004951 ASSERT_VK_SUCCESS(err);
4952
4953 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004954 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004955 m_commandBuffer->EndCommandBuffer();
4956 // Now destroy pipeline in order to cause error when submitting
4957 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004960
4961 VkSubmitInfo submit_info = {};
4962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4963 submit_info.commandBufferCount = 1;
4964 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4965 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4966
4967 m_errorMonitor->VerifyFound();
4968 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4969 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4970}
4971
Tobin Ehlis31289162016-08-17 14:57:58 -06004972TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4973 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4974 "due to a bound descriptor set with a buffer dependency "
4975 "being destroyed.");
4976 ASSERT_NO_FATAL_FAILURE(InitState());
4977 ASSERT_NO_FATAL_FAILURE(InitViewport());
4978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4979
4980 VkDescriptorPoolSize ds_type_count = {};
4981 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4982 ds_type_count.descriptorCount = 1;
4983
4984 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4985 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4986 ds_pool_ci.pNext = NULL;
4987 ds_pool_ci.maxSets = 1;
4988 ds_pool_ci.poolSizeCount = 1;
4989 ds_pool_ci.pPoolSizes = &ds_type_count;
4990
4991 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004992 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004993 ASSERT_VK_SUCCESS(err);
4994
4995 VkDescriptorSetLayoutBinding dsl_binding = {};
4996 dsl_binding.binding = 0;
4997 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4998 dsl_binding.descriptorCount = 1;
4999 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5000 dsl_binding.pImmutableSamplers = NULL;
5001
5002 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5003 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5004 ds_layout_ci.pNext = NULL;
5005 ds_layout_ci.bindingCount = 1;
5006 ds_layout_ci.pBindings = &dsl_binding;
5007 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005008 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005009 ASSERT_VK_SUCCESS(err);
5010
5011 VkDescriptorSet descriptorSet;
5012 VkDescriptorSetAllocateInfo alloc_info = {};
5013 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5014 alloc_info.descriptorSetCount = 1;
5015 alloc_info.descriptorPool = ds_pool;
5016 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005017 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005018 ASSERT_VK_SUCCESS(err);
5019
5020 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5021 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5022 pipeline_layout_ci.pNext = NULL;
5023 pipeline_layout_ci.setLayoutCount = 1;
5024 pipeline_layout_ci.pSetLayouts = &ds_layout;
5025
5026 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005027 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005028 ASSERT_VK_SUCCESS(err);
5029
5030 // Create a buffer to update the descriptor with
5031 uint32_t qfi = 0;
5032 VkBufferCreateInfo buffCI = {};
5033 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5034 buffCI.size = 1024;
5035 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5036 buffCI.queueFamilyIndexCount = 1;
5037 buffCI.pQueueFamilyIndices = &qfi;
5038
5039 VkBuffer buffer;
5040 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5041 ASSERT_VK_SUCCESS(err);
5042 // Allocate memory and bind to buffer so we can make it to the appropriate
5043 // error
5044 VkMemoryAllocateInfo mem_alloc = {};
5045 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5046 mem_alloc.pNext = NULL;
5047 mem_alloc.allocationSize = 1024;
5048 mem_alloc.memoryTypeIndex = 0;
5049
5050 VkMemoryRequirements memReqs;
5051 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005052 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005053 if (!pass) {
5054 vkDestroyBuffer(m_device->device(), buffer, NULL);
5055 return;
5056 }
5057
5058 VkDeviceMemory mem;
5059 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5060 ASSERT_VK_SUCCESS(err);
5061 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5062 ASSERT_VK_SUCCESS(err);
5063 // Correctly update descriptor to avoid "NOT_UPDATED" error
5064 VkDescriptorBufferInfo buffInfo = {};
5065 buffInfo.buffer = buffer;
5066 buffInfo.offset = 0;
5067 buffInfo.range = 1024;
5068
5069 VkWriteDescriptorSet descriptor_write;
5070 memset(&descriptor_write, 0, sizeof(descriptor_write));
5071 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5072 descriptor_write.dstSet = descriptorSet;
5073 descriptor_write.dstBinding = 0;
5074 descriptor_write.descriptorCount = 1;
5075 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5076 descriptor_write.pBufferInfo = &buffInfo;
5077
5078 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5079
5080 // Create PSO to be used for draw-time errors below
5081 char const *vsSource = "#version 450\n"
5082 "\n"
5083 "out gl_PerVertex { \n"
5084 " vec4 gl_Position;\n"
5085 "};\n"
5086 "void main(){\n"
5087 " gl_Position = vec4(1);\n"
5088 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005089 char const *fsSource = "#version 450\n"
5090 "\n"
5091 "layout(location=0) out vec4 x;\n"
5092 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5093 "void main(){\n"
5094 " x = vec4(bar.y);\n"
5095 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005096 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5097 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5098 VkPipelineObj pipe(m_device);
5099 pipe.AddShader(&vs);
5100 pipe.AddShader(&fs);
5101 pipe.AddColorAttachment();
5102 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5103
Tony Barbour552f6c02016-12-21 14:34:07 -07005104 m_commandBuffer->BeginCommandBuffer();
5105 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005106 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5107 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5108 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005109
5110 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5111 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5112
Tobin Ehlis31289162016-08-17 14:57:58 -06005113 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005114 m_commandBuffer->EndRenderPass();
5115 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005117 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5118 vkDestroyBuffer(m_device->device(), buffer, NULL);
5119 // Attempt to submit cmd buffer
5120 VkSubmitInfo submit_info = {};
5121 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5122 submit_info.commandBufferCount = 1;
5123 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5124 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5125 m_errorMonitor->VerifyFound();
5126 // Cleanup
5127 vkFreeMemory(m_device->device(), mem, NULL);
5128
5129 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5130 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5131 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5132}
5133
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005134TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5135 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5136 "due to a bound descriptor sets with a combined image "
5137 "sampler having their image, sampler, and descriptor set "
5138 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005139 "submit associated cmd buffers. Attempt to destroy a "
5140 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005141 ASSERT_NO_FATAL_FAILURE(InitState());
5142 ASSERT_NO_FATAL_FAILURE(InitViewport());
5143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5144
5145 VkDescriptorPoolSize ds_type_count = {};
5146 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5147 ds_type_count.descriptorCount = 1;
5148
5149 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5150 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5151 ds_pool_ci.pNext = NULL;
5152 ds_pool_ci.maxSets = 1;
5153 ds_pool_ci.poolSizeCount = 1;
5154 ds_pool_ci.pPoolSizes = &ds_type_count;
5155
5156 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005157 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005158 ASSERT_VK_SUCCESS(err);
5159
5160 VkDescriptorSetLayoutBinding dsl_binding = {};
5161 dsl_binding.binding = 0;
5162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5163 dsl_binding.descriptorCount = 1;
5164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5165 dsl_binding.pImmutableSamplers = NULL;
5166
5167 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5168 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5169 ds_layout_ci.pNext = NULL;
5170 ds_layout_ci.bindingCount = 1;
5171 ds_layout_ci.pBindings = &dsl_binding;
5172 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005174 ASSERT_VK_SUCCESS(err);
5175
5176 VkDescriptorSet descriptorSet;
5177 VkDescriptorSetAllocateInfo alloc_info = {};
5178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5179 alloc_info.descriptorSetCount = 1;
5180 alloc_info.descriptorPool = ds_pool;
5181 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5187 pipeline_layout_ci.pNext = NULL;
5188 pipeline_layout_ci.setLayoutCount = 1;
5189 pipeline_layout_ci.pSetLayouts = &ds_layout;
5190
5191 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005192 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005193 ASSERT_VK_SUCCESS(err);
5194
5195 // Create images to update the descriptor with
5196 VkImage image;
5197 VkImage image2;
5198 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5199 const int32_t tex_width = 32;
5200 const int32_t tex_height = 32;
5201 VkImageCreateInfo image_create_info = {};
5202 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5203 image_create_info.pNext = NULL;
5204 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5205 image_create_info.format = tex_format;
5206 image_create_info.extent.width = tex_width;
5207 image_create_info.extent.height = tex_height;
5208 image_create_info.extent.depth = 1;
5209 image_create_info.mipLevels = 1;
5210 image_create_info.arrayLayers = 1;
5211 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5212 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5213 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5214 image_create_info.flags = 0;
5215 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5216 ASSERT_VK_SUCCESS(err);
5217 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5218 ASSERT_VK_SUCCESS(err);
5219
5220 VkMemoryRequirements memory_reqs;
5221 VkDeviceMemory image_memory;
5222 bool pass;
5223 VkMemoryAllocateInfo memory_info = {};
5224 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5225 memory_info.pNext = NULL;
5226 memory_info.allocationSize = 0;
5227 memory_info.memoryTypeIndex = 0;
5228 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5229 // Allocate enough memory for both images
5230 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005231 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005232 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005233 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005234 ASSERT_VK_SUCCESS(err);
5235 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5236 ASSERT_VK_SUCCESS(err);
5237 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005238 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005239 ASSERT_VK_SUCCESS(err);
5240
5241 VkImageViewCreateInfo image_view_create_info = {};
5242 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5243 image_view_create_info.image = image;
5244 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5245 image_view_create_info.format = tex_format;
5246 image_view_create_info.subresourceRange.layerCount = 1;
5247 image_view_create_info.subresourceRange.baseMipLevel = 0;
5248 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250
5251 VkImageView view;
5252 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005253 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005254 ASSERT_VK_SUCCESS(err);
5255 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005256 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005257 ASSERT_VK_SUCCESS(err);
5258 // Create Samplers
5259 VkSamplerCreateInfo sampler_ci = {};
5260 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5261 sampler_ci.pNext = NULL;
5262 sampler_ci.magFilter = VK_FILTER_NEAREST;
5263 sampler_ci.minFilter = VK_FILTER_NEAREST;
5264 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5265 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5266 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5267 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5268 sampler_ci.mipLodBias = 1.0;
5269 sampler_ci.anisotropyEnable = VK_FALSE;
5270 sampler_ci.maxAnisotropy = 1;
5271 sampler_ci.compareEnable = VK_FALSE;
5272 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5273 sampler_ci.minLod = 1.0;
5274 sampler_ci.maxLod = 1.0;
5275 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5276 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5277 VkSampler sampler;
5278 VkSampler sampler2;
5279 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5280 ASSERT_VK_SUCCESS(err);
5281 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5282 ASSERT_VK_SUCCESS(err);
5283 // Update descriptor with image and sampler
5284 VkDescriptorImageInfo img_info = {};
5285 img_info.sampler = sampler;
5286 img_info.imageView = view;
5287 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5288
5289 VkWriteDescriptorSet descriptor_write;
5290 memset(&descriptor_write, 0, sizeof(descriptor_write));
5291 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5292 descriptor_write.dstSet = descriptorSet;
5293 descriptor_write.dstBinding = 0;
5294 descriptor_write.descriptorCount = 1;
5295 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5296 descriptor_write.pImageInfo = &img_info;
5297
5298 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5299
5300 // Create PSO to be used for draw-time errors below
5301 char const *vsSource = "#version 450\n"
5302 "\n"
5303 "out gl_PerVertex { \n"
5304 " vec4 gl_Position;\n"
5305 "};\n"
5306 "void main(){\n"
5307 " gl_Position = vec4(1);\n"
5308 "}\n";
5309 char const *fsSource = "#version 450\n"
5310 "\n"
5311 "layout(set=0, binding=0) uniform sampler2D s;\n"
5312 "layout(location=0) out vec4 x;\n"
5313 "void main(){\n"
5314 " x = texture(s, vec2(1));\n"
5315 "}\n";
5316 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5317 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5318 VkPipelineObj pipe(m_device);
5319 pipe.AddShader(&vs);
5320 pipe.AddShader(&fs);
5321 pipe.AddColorAttachment();
5322 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5323
5324 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005326 m_commandBuffer->BeginCommandBuffer();
5327 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005328 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5329 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5330 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005331 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5332 VkRect2D scissor = {{0, 0}, {16, 16}};
5333 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5334 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005335 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005336 m_commandBuffer->EndRenderPass();
5337 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005338 // Destroy sampler invalidates the cmd buffer, causing error on submit
5339 vkDestroySampler(m_device->device(), sampler, NULL);
5340 // Attempt to submit cmd buffer
5341 VkSubmitInfo submit_info = {};
5342 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5343 submit_info.commandBufferCount = 1;
5344 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5345 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5346 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005347
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005348 // Now re-update descriptor with valid sampler and delete image
5349 img_info.sampler = sampler2;
5350 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005352 m_commandBuffer->BeginCommandBuffer();
5353 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005354 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5355 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5356 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005357 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5358 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005359 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005360 m_commandBuffer->EndRenderPass();
5361 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005362 // Destroy image invalidates the cmd buffer, causing error on submit
5363 vkDestroyImage(m_device->device(), image, NULL);
5364 // Attempt to submit cmd buffer
5365 submit_info = {};
5366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5367 submit_info.commandBufferCount = 1;
5368 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5369 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5370 m_errorMonitor->VerifyFound();
5371 // Now update descriptor to be valid, but then free descriptor
5372 img_info.imageView = view2;
5373 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005375 m_commandBuffer->BeginCommandBuffer();
5376 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5378 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5379 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005380 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5381 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005382 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005383 m_commandBuffer->EndRenderPass();
5384 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005385 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005387 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005388 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005389 // Attempt to submit cmd buffer
5390 submit_info = {};
5391 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5392 submit_info.commandBufferCount = 1;
5393 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5394 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5395 m_errorMonitor->VerifyFound();
5396 // Cleanup
5397 vkFreeMemory(m_device->device(), image_memory, NULL);
5398 vkDestroySampler(m_device->device(), sampler2, NULL);
5399 vkDestroyImage(m_device->device(), image2, NULL);
5400 vkDestroyImageView(m_device->device(), view, NULL);
5401 vkDestroyImageView(m_device->device(), view2, NULL);
5402 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5403 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5404 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5405}
5406
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005407TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5408 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5409 ASSERT_NO_FATAL_FAILURE(InitState());
5410 ASSERT_NO_FATAL_FAILURE(InitViewport());
5411 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5412
5413 VkDescriptorPoolSize ds_type_count = {};
5414 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5415 ds_type_count.descriptorCount = 1;
5416
5417 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5418 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5419 ds_pool_ci.pNext = NULL;
5420 ds_pool_ci.maxSets = 1;
5421 ds_pool_ci.poolSizeCount = 1;
5422 ds_pool_ci.pPoolSizes = &ds_type_count;
5423
5424 VkDescriptorPool ds_pool;
5425 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5426 ASSERT_VK_SUCCESS(err);
5427
5428 VkDescriptorSetLayoutBinding dsl_binding = {};
5429 dsl_binding.binding = 0;
5430 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5431 dsl_binding.descriptorCount = 1;
5432 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5433 dsl_binding.pImmutableSamplers = NULL;
5434
5435 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5436 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5437 ds_layout_ci.pNext = NULL;
5438 ds_layout_ci.bindingCount = 1;
5439 ds_layout_ci.pBindings = &dsl_binding;
5440 VkDescriptorSetLayout ds_layout;
5441 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5442 ASSERT_VK_SUCCESS(err);
5443
5444 VkDescriptorSet descriptor_set;
5445 VkDescriptorSetAllocateInfo alloc_info = {};
5446 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5447 alloc_info.descriptorSetCount = 1;
5448 alloc_info.descriptorPool = ds_pool;
5449 alloc_info.pSetLayouts = &ds_layout;
5450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5451 ASSERT_VK_SUCCESS(err);
5452
5453 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5454 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5455 pipeline_layout_ci.pNext = NULL;
5456 pipeline_layout_ci.setLayoutCount = 1;
5457 pipeline_layout_ci.pSetLayouts = &ds_layout;
5458
5459 VkPipelineLayout pipeline_layout;
5460 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5461 ASSERT_VK_SUCCESS(err);
5462
5463 // Create image to update the descriptor with
5464 VkImageObj image(m_device);
5465 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5466 ASSERT_TRUE(image.initialized());
5467
5468 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5469 // Create Sampler
5470 VkSamplerCreateInfo sampler_ci = {};
5471 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5472 sampler_ci.pNext = NULL;
5473 sampler_ci.magFilter = VK_FILTER_NEAREST;
5474 sampler_ci.minFilter = VK_FILTER_NEAREST;
5475 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5476 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5477 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5478 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5479 sampler_ci.mipLodBias = 1.0;
5480 sampler_ci.anisotropyEnable = VK_FALSE;
5481 sampler_ci.maxAnisotropy = 1;
5482 sampler_ci.compareEnable = VK_FALSE;
5483 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5484 sampler_ci.minLod = 1.0;
5485 sampler_ci.maxLod = 1.0;
5486 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5487 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5488 VkSampler sampler;
5489 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5490 ASSERT_VK_SUCCESS(err);
5491 // Update descriptor with image and sampler
5492 VkDescriptorImageInfo img_info = {};
5493 img_info.sampler = sampler;
5494 img_info.imageView = view;
5495 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5496
5497 VkWriteDescriptorSet descriptor_write;
5498 memset(&descriptor_write, 0, sizeof(descriptor_write));
5499 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5500 descriptor_write.dstSet = descriptor_set;
5501 descriptor_write.dstBinding = 0;
5502 descriptor_write.descriptorCount = 1;
5503 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5504 descriptor_write.pImageInfo = &img_info;
5505
5506 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5507
5508 // Create PSO to be used for draw-time errors below
5509 char const *vsSource = "#version 450\n"
5510 "\n"
5511 "out gl_PerVertex { \n"
5512 " vec4 gl_Position;\n"
5513 "};\n"
5514 "void main(){\n"
5515 " gl_Position = vec4(1);\n"
5516 "}\n";
5517 char const *fsSource = "#version 450\n"
5518 "\n"
5519 "layout(set=0, binding=0) uniform sampler2D s;\n"
5520 "layout(location=0) out vec4 x;\n"
5521 "void main(){\n"
5522 " x = texture(s, vec2(1));\n"
5523 "}\n";
5524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5526 VkPipelineObj pipe(m_device);
5527 pipe.AddShader(&vs);
5528 pipe.AddShader(&fs);
5529 pipe.AddColorAttachment();
5530 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5531
Tony Barbour552f6c02016-12-21 14:34:07 -07005532 m_commandBuffer->BeginCommandBuffer();
5533 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005534 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5535 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5536 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005537
5538 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5539 VkRect2D scissor = {{0, 0}, {16, 16}};
5540 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5541 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5542
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005543 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005544 m_commandBuffer->EndRenderPass();
5545 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005546 // Submit cmd buffer to put pool in-flight
5547 VkSubmitInfo submit_info = {};
5548 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5549 submit_info.commandBufferCount = 1;
5550 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5551 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5552 // Destroy pool while in-flight, causing error
5553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5555 m_errorMonitor->VerifyFound();
5556 vkQueueWaitIdle(m_device->m_queue);
5557 // Cleanup
5558 vkDestroySampler(m_device->device(), sampler, NULL);
5559 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5560 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5561 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005562 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005563}
5564
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005565TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5566 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5567 ASSERT_NO_FATAL_FAILURE(InitState());
5568 ASSERT_NO_FATAL_FAILURE(InitViewport());
5569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5570
5571 VkDescriptorPoolSize ds_type_count = {};
5572 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5573 ds_type_count.descriptorCount = 1;
5574
5575 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5576 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5577 ds_pool_ci.pNext = NULL;
5578 ds_pool_ci.maxSets = 1;
5579 ds_pool_ci.poolSizeCount = 1;
5580 ds_pool_ci.pPoolSizes = &ds_type_count;
5581
5582 VkDescriptorPool ds_pool;
5583 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5584 ASSERT_VK_SUCCESS(err);
5585
5586 VkDescriptorSetLayoutBinding dsl_binding = {};
5587 dsl_binding.binding = 0;
5588 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5589 dsl_binding.descriptorCount = 1;
5590 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5591 dsl_binding.pImmutableSamplers = NULL;
5592
5593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5595 ds_layout_ci.pNext = NULL;
5596 ds_layout_ci.bindingCount = 1;
5597 ds_layout_ci.pBindings = &dsl_binding;
5598 VkDescriptorSetLayout ds_layout;
5599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5600 ASSERT_VK_SUCCESS(err);
5601
5602 VkDescriptorSet descriptorSet;
5603 VkDescriptorSetAllocateInfo alloc_info = {};
5604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5605 alloc_info.descriptorSetCount = 1;
5606 alloc_info.descriptorPool = ds_pool;
5607 alloc_info.pSetLayouts = &ds_layout;
5608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5609 ASSERT_VK_SUCCESS(err);
5610
5611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5613 pipeline_layout_ci.pNext = NULL;
5614 pipeline_layout_ci.setLayoutCount = 1;
5615 pipeline_layout_ci.pSetLayouts = &ds_layout;
5616
5617 VkPipelineLayout pipeline_layout;
5618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5619 ASSERT_VK_SUCCESS(err);
5620
5621 // Create images to update the descriptor with
5622 VkImage image;
5623 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5624 const int32_t tex_width = 32;
5625 const int32_t tex_height = 32;
5626 VkImageCreateInfo image_create_info = {};
5627 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5628 image_create_info.pNext = NULL;
5629 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5630 image_create_info.format = tex_format;
5631 image_create_info.extent.width = tex_width;
5632 image_create_info.extent.height = tex_height;
5633 image_create_info.extent.depth = 1;
5634 image_create_info.mipLevels = 1;
5635 image_create_info.arrayLayers = 1;
5636 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5637 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5638 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5639 image_create_info.flags = 0;
5640 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5641 ASSERT_VK_SUCCESS(err);
5642 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5643 VkMemoryRequirements memory_reqs;
5644 VkDeviceMemory image_memory;
5645 bool pass;
5646 VkMemoryAllocateInfo memory_info = {};
5647 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5648 memory_info.pNext = NULL;
5649 memory_info.allocationSize = 0;
5650 memory_info.memoryTypeIndex = 0;
5651 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5652 // Allocate enough memory for image
5653 memory_info.allocationSize = memory_reqs.size;
5654 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5655 ASSERT_TRUE(pass);
5656 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5657 ASSERT_VK_SUCCESS(err);
5658 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5659 ASSERT_VK_SUCCESS(err);
5660
5661 VkImageViewCreateInfo image_view_create_info = {};
5662 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5663 image_view_create_info.image = image;
5664 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5665 image_view_create_info.format = tex_format;
5666 image_view_create_info.subresourceRange.layerCount = 1;
5667 image_view_create_info.subresourceRange.baseMipLevel = 0;
5668 image_view_create_info.subresourceRange.levelCount = 1;
5669 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5670
5671 VkImageView view;
5672 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5673 ASSERT_VK_SUCCESS(err);
5674 // Create Samplers
5675 VkSamplerCreateInfo sampler_ci = {};
5676 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5677 sampler_ci.pNext = NULL;
5678 sampler_ci.magFilter = VK_FILTER_NEAREST;
5679 sampler_ci.minFilter = VK_FILTER_NEAREST;
5680 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5681 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5682 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5683 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5684 sampler_ci.mipLodBias = 1.0;
5685 sampler_ci.anisotropyEnable = VK_FALSE;
5686 sampler_ci.maxAnisotropy = 1;
5687 sampler_ci.compareEnable = VK_FALSE;
5688 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5689 sampler_ci.minLod = 1.0;
5690 sampler_ci.maxLod = 1.0;
5691 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5692 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5693 VkSampler sampler;
5694 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5695 ASSERT_VK_SUCCESS(err);
5696 // Update descriptor with image and sampler
5697 VkDescriptorImageInfo img_info = {};
5698 img_info.sampler = sampler;
5699 img_info.imageView = view;
5700 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5701
5702 VkWriteDescriptorSet descriptor_write;
5703 memset(&descriptor_write, 0, sizeof(descriptor_write));
5704 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5705 descriptor_write.dstSet = descriptorSet;
5706 descriptor_write.dstBinding = 0;
5707 descriptor_write.descriptorCount = 1;
5708 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5709 descriptor_write.pImageInfo = &img_info;
5710 // Break memory binding and attempt update
5711 vkFreeMemory(m_device->device(), image_memory, nullptr);
5712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005713 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5715 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5717 m_errorMonitor->VerifyFound();
5718 // Cleanup
5719 vkDestroyImage(m_device->device(), image, NULL);
5720 vkDestroySampler(m_device->device(), sampler, NULL);
5721 vkDestroyImageView(m_device->device(), view, NULL);
5722 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5725}
5726
Karl Schultz6addd812016-02-02 17:17:23 -07005727TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005728 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5729 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005730 // Create a valid cmd buffer
5731 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005732 uint64_t fake_pipeline_handle = 0xbaad6001;
5733 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005734 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5736
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005738 m_commandBuffer->BeginCommandBuffer();
5739 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005740 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005741 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005742
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005743 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005744 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 -06005745 Draw(1, 0, 0, 0);
5746 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005747
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005748 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005749 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 +12005750 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005751 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5752 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005753}
5754
Karl Schultz6addd812016-02-02 17:17:23 -07005755TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005756 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005757 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005760
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005761 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005764 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5766 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005767
5768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5770 ds_pool_ci.pNext = NULL;
5771 ds_pool_ci.maxSets = 1;
5772 ds_pool_ci.poolSizeCount = 1;
5773 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005774
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005777 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005778
Tony Barboureb254902015-07-15 12:50:33 -06005779 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 dsl_binding.binding = 0;
5781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5782 dsl_binding.descriptorCount = 1;
5783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005785
Tony Barboureb254902015-07-15 12:50:33 -06005786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5788 ds_layout_ci.pNext = NULL;
5789 ds_layout_ci.bindingCount = 1;
5790 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005791 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005793 ASSERT_VK_SUCCESS(err);
5794
5795 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005796 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005798 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005799 alloc_info.descriptorPool = ds_pool;
5800 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005802 ASSERT_VK_SUCCESS(err);
5803
Tony Barboureb254902015-07-15 12:50:33 -06005804 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005805 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5806 pipeline_layout_ci.pNext = NULL;
5807 pipeline_layout_ci.setLayoutCount = 1;
5808 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005809
5810 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005812 ASSERT_VK_SUCCESS(err);
5813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005814 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005815 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005816 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005817 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005818
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005819 VkPipelineObj pipe(m_device);
5820 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005821 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005822 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005823 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005824
Tony Barbour552f6c02016-12-21 14:34:07 -07005825 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005826 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5827 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5828 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005830 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005831
Chia-I Wuf7458c52015-10-26 21:10:41 +08005832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005835}
5836
Karl Schultz6addd812016-02-02 17:17:23 -07005837TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005838 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005839 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005840
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005842
5843 ASSERT_NO_FATAL_FAILURE(InitState());
5844 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005845 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5846 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005847
5848 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005849 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5850 ds_pool_ci.pNext = NULL;
5851 ds_pool_ci.maxSets = 1;
5852 ds_pool_ci.poolSizeCount = 1;
5853 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005854
5855 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005856 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005857 ASSERT_VK_SUCCESS(err);
5858
5859 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005860 dsl_binding.binding = 0;
5861 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5862 dsl_binding.descriptorCount = 1;
5863 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5864 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005865
5866 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005867 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5868 ds_layout_ci.pNext = NULL;
5869 ds_layout_ci.bindingCount = 1;
5870 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005871 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005872 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005873 ASSERT_VK_SUCCESS(err);
5874
5875 VkDescriptorSet descriptorSet;
5876 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005877 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005878 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005879 alloc_info.descriptorPool = ds_pool;
5880 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005881 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005882 ASSERT_VK_SUCCESS(err);
5883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005884 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005885 VkWriteDescriptorSet descriptor_write;
5886 memset(&descriptor_write, 0, sizeof(descriptor_write));
5887 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5888 descriptor_write.dstSet = descriptorSet;
5889 descriptor_write.dstBinding = 0;
5890 descriptor_write.descriptorCount = 1;
5891 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5892 descriptor_write.pTexelBufferView = &view;
5893
5894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5895
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005896 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005897
5898 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5899 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5900}
5901
Mark Youngd339ba32016-05-30 13:28:35 -06005902TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005903 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 -06005904
5905 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005907 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005908
5909 ASSERT_NO_FATAL_FAILURE(InitState());
5910
5911 // Create a buffer with no bound memory and then attempt to create
5912 // a buffer view.
5913 VkBufferCreateInfo buff_ci = {};
5914 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005915 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005916 buff_ci.size = 256;
5917 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5918 VkBuffer buffer;
5919 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5920 ASSERT_VK_SUCCESS(err);
5921
5922 VkBufferViewCreateInfo buff_view_ci = {};
5923 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5924 buff_view_ci.buffer = buffer;
5925 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5926 buff_view_ci.range = VK_WHOLE_SIZE;
5927 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005928 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005929
5930 m_errorMonitor->VerifyFound();
5931 vkDestroyBuffer(m_device->device(), buffer, NULL);
5932 // If last error is success, it still created the view, so delete it.
5933 if (err == VK_SUCCESS) {
5934 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5935 }
5936}
5937
Karl Schultz6addd812016-02-02 17:17:23 -07005938TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5939 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5940 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005941 // 1. No dynamicOffset supplied
5942 // 2. Too many dynamicOffsets supplied
5943 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005944 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5946 "0 dynamicOffsets are left in "
5947 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005948
5949 ASSERT_NO_FATAL_FAILURE(InitState());
5950 ASSERT_NO_FATAL_FAILURE(InitViewport());
5951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5952
5953 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005954 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5955 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005956
5957 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005958 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5959 ds_pool_ci.pNext = NULL;
5960 ds_pool_ci.maxSets = 1;
5961 ds_pool_ci.poolSizeCount = 1;
5962 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005963
5964 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005965 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005966 ASSERT_VK_SUCCESS(err);
5967
5968 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005969 dsl_binding.binding = 0;
5970 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5971 dsl_binding.descriptorCount = 1;
5972 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5973 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005974
5975 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005976 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5977 ds_layout_ci.pNext = NULL;
5978 ds_layout_ci.bindingCount = 1;
5979 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005980 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005981 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 ASSERT_VK_SUCCESS(err);
5983
5984 VkDescriptorSet descriptorSet;
5985 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005986 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005987 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005988 alloc_info.descriptorPool = ds_pool;
5989 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005990 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005991 ASSERT_VK_SUCCESS(err);
5992
5993 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005994 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5995 pipeline_layout_ci.pNext = NULL;
5996 pipeline_layout_ci.setLayoutCount = 1;
5997 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005998
5999 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006000 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006001 ASSERT_VK_SUCCESS(err);
6002
6003 // Create a buffer to update the descriptor with
6004 uint32_t qfi = 0;
6005 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006006 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6007 buffCI.size = 1024;
6008 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6009 buffCI.queueFamilyIndexCount = 1;
6010 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006011
6012 VkBuffer dyub;
6013 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6014 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006015 // Allocate memory and bind to buffer so we can make it to the appropriate
6016 // error
6017 VkMemoryAllocateInfo mem_alloc = {};
6018 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6019 mem_alloc.pNext = NULL;
6020 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006021 mem_alloc.memoryTypeIndex = 0;
6022
6023 VkMemoryRequirements memReqs;
6024 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006025 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006026 if (!pass) {
6027 vkDestroyBuffer(m_device->device(), dyub, NULL);
6028 return;
6029 }
6030
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006031 VkDeviceMemory mem;
6032 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6033 ASSERT_VK_SUCCESS(err);
6034 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6035 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006036 // Correctly update descriptor to avoid "NOT_UPDATED" error
6037 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006038 buffInfo.buffer = dyub;
6039 buffInfo.offset = 0;
6040 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006041
6042 VkWriteDescriptorSet descriptor_write;
6043 memset(&descriptor_write, 0, sizeof(descriptor_write));
6044 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6045 descriptor_write.dstSet = descriptorSet;
6046 descriptor_write.dstBinding = 0;
6047 descriptor_write.descriptorCount = 1;
6048 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6049 descriptor_write.pBufferInfo = &buffInfo;
6050
6051 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6052
Tony Barbour552f6c02016-12-21 14:34:07 -07006053 m_commandBuffer->BeginCommandBuffer();
6054 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6056 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006057 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006058 uint32_t pDynOff[2] = {512, 756};
6059 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6061 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6062 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6063 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006064 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006065 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6067 "offset 0 and range 1024 that "
6068 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006069 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006070 char const *vsSource = "#version 450\n"
6071 "\n"
6072 "out gl_PerVertex { \n"
6073 " vec4 gl_Position;\n"
6074 "};\n"
6075 "void main(){\n"
6076 " gl_Position = vec4(1);\n"
6077 "}\n";
6078 char const *fsSource = "#version 450\n"
6079 "\n"
6080 "layout(location=0) out vec4 x;\n"
6081 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6082 "void main(){\n"
6083 " x = vec4(bar.y);\n"
6084 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006085 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6086 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6087 VkPipelineObj pipe(m_device);
6088 pipe.AddShader(&vs);
6089 pipe.AddShader(&fs);
6090 pipe.AddColorAttachment();
6091 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6092
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006093 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6094 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6095 VkRect2D scissor = {{0, 0}, {16, 16}};
6096 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006098 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006099 // This update should succeed, but offset size of 512 will overstep buffer
6100 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006101 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6102 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006103 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006104 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006105
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006106 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006107 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006108
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006109 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006111 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6112}
6113
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006114TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6115 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6116 "that doesn't have memory bound");
6117 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006119 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6121 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006122
6123 ASSERT_NO_FATAL_FAILURE(InitState());
6124 ASSERT_NO_FATAL_FAILURE(InitViewport());
6125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6126
6127 VkDescriptorPoolSize ds_type_count = {};
6128 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6129 ds_type_count.descriptorCount = 1;
6130
6131 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6132 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6133 ds_pool_ci.pNext = NULL;
6134 ds_pool_ci.maxSets = 1;
6135 ds_pool_ci.poolSizeCount = 1;
6136 ds_pool_ci.pPoolSizes = &ds_type_count;
6137
6138 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006139 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006140 ASSERT_VK_SUCCESS(err);
6141
6142 VkDescriptorSetLayoutBinding dsl_binding = {};
6143 dsl_binding.binding = 0;
6144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6145 dsl_binding.descriptorCount = 1;
6146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6147 dsl_binding.pImmutableSamplers = NULL;
6148
6149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6151 ds_layout_ci.pNext = NULL;
6152 ds_layout_ci.bindingCount = 1;
6153 ds_layout_ci.pBindings = &dsl_binding;
6154 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006155 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006156 ASSERT_VK_SUCCESS(err);
6157
6158 VkDescriptorSet descriptorSet;
6159 VkDescriptorSetAllocateInfo alloc_info = {};
6160 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6161 alloc_info.descriptorSetCount = 1;
6162 alloc_info.descriptorPool = ds_pool;
6163 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006164 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006165 ASSERT_VK_SUCCESS(err);
6166
6167 // Create a buffer to update the descriptor with
6168 uint32_t qfi = 0;
6169 VkBufferCreateInfo buffCI = {};
6170 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6171 buffCI.size = 1024;
6172 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6173 buffCI.queueFamilyIndexCount = 1;
6174 buffCI.pQueueFamilyIndices = &qfi;
6175
6176 VkBuffer dyub;
6177 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6178 ASSERT_VK_SUCCESS(err);
6179
6180 // Attempt to update descriptor without binding memory to it
6181 VkDescriptorBufferInfo buffInfo = {};
6182 buffInfo.buffer = dyub;
6183 buffInfo.offset = 0;
6184 buffInfo.range = 1024;
6185
6186 VkWriteDescriptorSet descriptor_write;
6187 memset(&descriptor_write, 0, sizeof(descriptor_write));
6188 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6189 descriptor_write.dstSet = descriptorSet;
6190 descriptor_write.dstBinding = 0;
6191 descriptor_write.descriptorCount = 1;
6192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6193 descriptor_write.pBufferInfo = &buffInfo;
6194
6195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6196 m_errorMonitor->VerifyFound();
6197
6198 vkDestroyBuffer(m_device->device(), dyub, NULL);
6199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6200 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6201}
6202
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006203TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006204 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006205 ASSERT_NO_FATAL_FAILURE(InitState());
6206 ASSERT_NO_FATAL_FAILURE(InitViewport());
6207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6208
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006209 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006210 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006211 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6212 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6213 pipeline_layout_ci.pushConstantRangeCount = 1;
6214 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6215
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006216 //
6217 // Check for invalid push constant ranges in pipeline layouts.
6218 //
6219 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006220 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006221 char const *msg;
6222 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006223
Karl Schultzc81037d2016-05-12 08:11:23 -06006224 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6225 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6226 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6227 "vkCreatePipelineLayout() call has push constants index 0 with "
6228 "size 0."},
6229 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6230 "vkCreatePipelineLayout() call has push constants index 0 with "
6231 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006232 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006233 "vkCreatePipelineLayout() call has push constants index 0 with "
6234 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006235 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006236 "vkCreatePipelineLayout() call has push constants index 0 with "
6237 "size 0."},
6238 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6239 "vkCreatePipelineLayout() call has push constants index 0 with "
6240 "offset 1. Offset must"},
6241 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6242 "vkCreatePipelineLayout() call has push constants index 0 "
6243 "with offset "},
6244 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6245 "vkCreatePipelineLayout() call has push constants "
6246 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006247 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006248 "vkCreatePipelineLayout() call has push constants index 0 "
6249 "with offset "},
6250 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6251 "vkCreatePipelineLayout() call has push "
6252 "constants index 0 with offset "},
6253 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6254 "vkCreatePipelineLayout() call has push "
6255 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006256 }};
6257
6258 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006259 for (const auto &iter : range_tests) {
6260 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6262 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006263 m_errorMonitor->VerifyFound();
6264 if (VK_SUCCESS == err) {
6265 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6266 }
6267 }
6268
6269 // Check for invalid stage flag
6270 pc_range.offset = 0;
6271 pc_range.size = 16;
6272 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006273 m_errorMonitor->SetDesiredFailureMsg(
6274 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6275 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006276 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006277 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006278 if (VK_SUCCESS == err) {
6279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6280 }
6281
6282 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006283 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006284 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006285 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006286 char const *msg;
6287 };
6288
Karl Schultzc81037d2016-05-12 08:11:23 -06006289 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006290 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6292 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6293 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6294 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006295 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006296 {
6297 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6298 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6299 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6300 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6301 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006302 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006303 },
6304 {
6305 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6306 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6307 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6308 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6309 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006310 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006311 },
6312 {
6313 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6314 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6315 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6316 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6317 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006318 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006319 },
6320 {
6321 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6322 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6323 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6324 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6325 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006326 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006327 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006328
Karl Schultzc81037d2016-05-12 08:11:23 -06006329 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006330 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006331 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6333 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006334 m_errorMonitor->VerifyFound();
6335 if (VK_SUCCESS == err) {
6336 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6337 }
6338 }
6339
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006340 //
6341 // CmdPushConstants tests
6342 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006343 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006344
6345 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006346 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6347 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006348 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006349 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6350 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006351 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006352 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6353 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006354 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006355 "vkCmdPushConstants() call has push constants with offset 1. "
6356 "Offset must be a multiple of 4."},
6357 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6358 "vkCmdPushConstants() call has push constants with offset 1. "
6359 "Offset must be a multiple of 4."},
6360 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6361 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6362 "0x1 not within flag-matching ranges in pipeline layout"},
6363 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6364 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6365 "0x1 not within flag-matching ranges in pipeline layout"},
6366 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6367 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6368 "0x1 not within flag-matching ranges in pipeline layout"},
6369 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6370 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6371 "0x1 not within flag-matching ranges in pipeline layout"},
6372 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6373 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6374 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006376 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6377 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006378 }};
6379
Tony Barbour552f6c02016-12-21 14:34:07 -07006380 m_commandBuffer->BeginCommandBuffer();
6381 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006382
6383 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006384 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006386 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006387 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006388 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006389 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006390 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006391 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6393 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006394 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006395 m_errorMonitor->VerifyFound();
6396 }
6397
6398 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006400 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006401 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006402 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006403
Karl Schultzc81037d2016-05-12 08:11:23 -06006404 // overlapping range tests with cmd
6405 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6406 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6407 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6408 "0x1 not within flag-matching ranges in pipeline layout"},
6409 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6410 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6411 "0x1 not within flag-matching ranges in pipeline layout"},
6412 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6413 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6414 "0x1 not within flag-matching ranges in pipeline layout"},
6415 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006416 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006417 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006418 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6419 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006420 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006421 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006422 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006424 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006425 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6427 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006428 iter.range.size, dummy_values);
6429 m_errorMonitor->VerifyFound();
6430 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006431 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6432
Tony Barbour552f6c02016-12-21 14:34:07 -07006433 m_commandBuffer->EndRenderPass();
6434 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006435}
6436
Karl Schultz6addd812016-02-02 17:17:23 -07006437TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006438 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006439 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006440
6441 ASSERT_NO_FATAL_FAILURE(InitState());
6442 ASSERT_NO_FATAL_FAILURE(InitViewport());
6443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6444
Mike Stroyanb8a61002016-06-20 16:00:28 -06006445 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6446 VkImageTiling tiling;
6447 VkFormatProperties format_properties;
6448 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006450 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006451 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006452 tiling = VK_IMAGE_TILING_OPTIMAL;
6453 } else {
6454 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6455 "skipped.\n");
6456 return;
6457 }
6458
Tobin Ehlis559c6382015-11-05 09:52:49 -07006459 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6460 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006461 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6462 ds_type_count[0].descriptorCount = 10;
6463 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6464 ds_type_count[1].descriptorCount = 2;
6465 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6466 ds_type_count[2].descriptorCount = 2;
6467 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6468 ds_type_count[3].descriptorCount = 5;
6469 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6470 // type
6471 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6472 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6473 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006474
6475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6477 ds_pool_ci.pNext = NULL;
6478 ds_pool_ci.maxSets = 5;
6479 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6480 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481
6482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006484 ASSERT_VK_SUCCESS(err);
6485
6486 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6487 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006488 dsl_binding[0].binding = 0;
6489 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6490 dsl_binding[0].descriptorCount = 5;
6491 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6492 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006493
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006494 // Create layout identical to set0 layout but w/ different stageFlags
6495 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006496 dsl_fs_stage_only.binding = 0;
6497 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6498 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006499 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6500 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006501 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006502 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006503 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6504 ds_layout_ci.pNext = NULL;
6505 ds_layout_ci.bindingCount = 1;
6506 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006507 static const uint32_t NUM_LAYOUTS = 4;
6508 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006509 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006510 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6511 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006512 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006513 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006514 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006516 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006517 dsl_binding[0].binding = 0;
6518 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006519 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006520 dsl_binding[1].binding = 1;
6521 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6522 dsl_binding[1].descriptorCount = 2;
6523 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6524 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006525 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006526 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006528 ASSERT_VK_SUCCESS(err);
6529 dsl_binding[0].binding = 0;
6530 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006531 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006532 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006533 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006534 ASSERT_VK_SUCCESS(err);
6535 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006538 ASSERT_VK_SUCCESS(err);
6539
6540 static const uint32_t NUM_SETS = 4;
6541 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6542 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006543 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006544 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006545 alloc_info.descriptorPool = ds_pool;
6546 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006547 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006549 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006550 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006551 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006553 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006554
6555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6557 pipeline_layout_ci.pNext = NULL;
6558 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6559 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006560
6561 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006563 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006564 // Create pipelineLayout with only one setLayout
6565 pipeline_layout_ci.setLayoutCount = 1;
6566 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006567 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006568 ASSERT_VK_SUCCESS(err);
6569 // Create pipelineLayout with 2 descriptor setLayout at index 0
6570 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6571 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006572 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006573 ASSERT_VK_SUCCESS(err);
6574 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6575 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6576 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006577 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006578 ASSERT_VK_SUCCESS(err);
6579 // Create pipelineLayout with UB type, but stageFlags for FS only
6580 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6581 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006583 ASSERT_VK_SUCCESS(err);
6584 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6585 VkDescriptorSetLayout pl_bad_s0[2] = {};
6586 pl_bad_s0[0] = ds_layout_fs_only;
6587 pl_bad_s0[1] = ds_layout[1];
6588 pipeline_layout_ci.setLayoutCount = 2;
6589 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6590 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006592 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006593
6594 // Create a buffer to update the descriptor with
6595 uint32_t qfi = 0;
6596 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006597 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6598 buffCI.size = 1024;
6599 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6600 buffCI.queueFamilyIndexCount = 1;
6601 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006602
6603 VkBuffer dyub;
6604 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6605 ASSERT_VK_SUCCESS(err);
6606 // Correctly update descriptor to avoid "NOT_UPDATED" error
6607 static const uint32_t NUM_BUFFS = 5;
6608 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006609 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006610 buffInfo[i].buffer = dyub;
6611 buffInfo[i].offset = 0;
6612 buffInfo[i].range = 1024;
6613 }
Karl Schultz6addd812016-02-02 17:17:23 -07006614 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006615 const int32_t tex_width = 32;
6616 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006617 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006618 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6619 image_create_info.pNext = NULL;
6620 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6621 image_create_info.format = tex_format;
6622 image_create_info.extent.width = tex_width;
6623 image_create_info.extent.height = tex_height;
6624 image_create_info.extent.depth = 1;
6625 image_create_info.mipLevels = 1;
6626 image_create_info.arrayLayers = 1;
6627 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006628 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006630 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006631 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6632 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006633
Karl Schultz6addd812016-02-02 17:17:23 -07006634 VkMemoryRequirements memReqs;
6635 VkDeviceMemory imageMem;
6636 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006637 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006638 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6639 memAlloc.pNext = NULL;
6640 memAlloc.allocationSize = 0;
6641 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006642 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6643 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006644 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006645 ASSERT_TRUE(pass);
6646 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6647 ASSERT_VK_SUCCESS(err);
6648 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6649 ASSERT_VK_SUCCESS(err);
6650
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006651 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006652 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6653 image_view_create_info.image = image;
6654 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6655 image_view_create_info.format = tex_format;
6656 image_view_create_info.subresourceRange.layerCount = 1;
6657 image_view_create_info.subresourceRange.baseMipLevel = 0;
6658 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006659 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006660
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006661 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006662 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006663 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006664 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006665 imageInfo[0].imageView = view;
6666 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6667 imageInfo[1].imageView = view;
6668 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006669 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006670 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006671 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006672 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006673
6674 static const uint32_t NUM_SET_UPDATES = 3;
6675 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6676 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6677 descriptor_write[0].dstSet = descriptorSet[0];
6678 descriptor_write[0].dstBinding = 0;
6679 descriptor_write[0].descriptorCount = 5;
6680 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6681 descriptor_write[0].pBufferInfo = buffInfo;
6682 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6683 descriptor_write[1].dstSet = descriptorSet[1];
6684 descriptor_write[1].dstBinding = 0;
6685 descriptor_write[1].descriptorCount = 2;
6686 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6687 descriptor_write[1].pImageInfo = imageInfo;
6688 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6689 descriptor_write[2].dstSet = descriptorSet[1];
6690 descriptor_write[2].dstBinding = 1;
6691 descriptor_write[2].descriptorCount = 2;
6692 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006693 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006694
6695 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006696
Tobin Ehlis88452832015-12-03 09:40:56 -07006697 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006698 char const *vsSource = "#version 450\n"
6699 "\n"
6700 "out gl_PerVertex {\n"
6701 " vec4 gl_Position;\n"
6702 "};\n"
6703 "void main(){\n"
6704 " gl_Position = vec4(1);\n"
6705 "}\n";
6706 char const *fsSource = "#version 450\n"
6707 "\n"
6708 "layout(location=0) out vec4 x;\n"
6709 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6710 "void main(){\n"
6711 " x = vec4(bar.y);\n"
6712 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006715 VkPipelineObj pipe(m_device);
6716 pipe.AddShader(&vs);
6717 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006718 pipe.AddColorAttachment();
6719 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006720
Tony Barbour552f6c02016-12-21 14:34:07 -07006721 m_commandBuffer->BeginCommandBuffer();
6722 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006724 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006725 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6726 // of PSO
6727 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6728 // cmd_pipeline.c
6729 // due to the fact that cmd_alloc_dset_data() has not been called in
6730 // cmd_bind_graphics_pipeline()
6731 // TODO : Want to cause various binding incompatibility issues here to test
6732 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006733 // First cause various verify_layout_compatibility() fails
6734 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006735 // verify_set_layout_compatibility fail cases:
6736 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6739 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
6741
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006742 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6745 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006746 m_errorMonitor->VerifyFound();
6747
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006748 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6750 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6752 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6753 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006754 m_errorMonitor->VerifyFound();
6755
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006756 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6757 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6759 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6760 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006761 m_errorMonitor->VerifyFound();
6762
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006763 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6764 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6766 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6767 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6768 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006769 m_errorMonitor->VerifyFound();
6770
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006771 // Cause INFO messages due to disturbing previously bound Sets
6772 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006773 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6774 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006775 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6777 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6778 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006779 m_errorMonitor->VerifyFound();
6780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006781 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6782 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006783 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6785 "any subsequent sets were disturbed ");
6786 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6787 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006788 m_errorMonitor->VerifyFound();
6789
Tobin Ehlis10fad692016-07-07 12:00:36 -06006790 // Now that we're done actively using the pipelineLayout that gfx pipeline
6791 // was created with, we should be able to delete it. Do that now to verify
6792 // that validation obeys pipelineLayout lifetime
6793 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6794
Tobin Ehlis88452832015-12-03 09:40:56 -07006795 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006796 // 1. Error due to not binding required set (we actually use same code as
6797 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006798 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6799 &descriptorSet[0], 0, NULL);
6800 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6801 &descriptorSet[1], 0, NULL);
6802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07006803
6804 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6805 VkRect2D scissor = {{0, 0}, {16, 16}};
6806 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6807 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6808
Tobin Ehlis88452832015-12-03 09:40:56 -07006809 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006810 m_errorMonitor->VerifyFound();
6811
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006812 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006813 // 2. Error due to bound set not being compatible with PSO's
6814 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6816 &descriptorSet[0], 0, NULL);
6817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006818 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006819 m_errorMonitor->VerifyFound();
6820
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006821 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006822 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006823 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6824 }
6825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006826 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006827 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6828 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006829 vkFreeMemory(m_device->device(), imageMem, NULL);
6830 vkDestroyImage(m_device->device(), image, NULL);
6831 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006832}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006833
Karl Schultz6addd812016-02-02 17:17:23 -07006834TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006835
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6837 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006838
6839 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006840 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006841 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006842 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006843
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006844 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006845}
6846
Karl Schultz6addd812016-02-02 17:17:23 -07006847TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6848 VkResult err;
6849 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006850
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006852
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006853 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006854
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006855 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006856 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006857 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006858 cmd.commandPool = m_commandPool;
6859 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006860 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006861
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006862 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006863 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006864
6865 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006866 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006867 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006868 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006869 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006870 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 -07006871 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006872
6873 // The error should be caught by validation of the BeginCommandBuffer call
6874 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6875
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006876 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006877 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006878}
6879
Karl Schultz6addd812016-02-02 17:17:23 -07006880TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006881 // Cause error due to Begin while recording CB
6882 // Then cause 2 errors for attempting to reset CB w/o having
6883 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6884 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006886
6887 ASSERT_NO_FATAL_FAILURE(InitState());
6888
6889 // Calls AllocateCommandBuffers
6890 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6891
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006892 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006893 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006894 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6895 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006896 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6897 cmd_buf_info.pNext = NULL;
6898 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006899 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006900
6901 // Begin CB to transition to recording state
6902 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6903 // Can't re-begin. This should trigger error
6904 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006905 m_errorMonitor->VerifyFound();
6906
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006908 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6909 // Reset attempt will trigger error due to incorrect CommandPool state
6910 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006911 m_errorMonitor->VerifyFound();
6912
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006914 // Transition CB to RECORDED state
6915 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6916 // Now attempting to Begin will implicitly reset, which triggers error
6917 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006918 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006919}
6920
Karl Schultz6addd812016-02-02 17:17:23 -07006921TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006922 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006923 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006924
Mike Weiblencce7ec72016-10-17 19:33:05 -06006925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006926
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006927 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006929
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006930 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006931 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6932 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006933
6934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6936 ds_pool_ci.pNext = NULL;
6937 ds_pool_ci.maxSets = 1;
6938 ds_pool_ci.poolSizeCount = 1;
6939 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006940
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006941 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006943 ASSERT_VK_SUCCESS(err);
6944
Tony Barboureb254902015-07-15 12:50:33 -06006945 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006946 dsl_binding.binding = 0;
6947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6948 dsl_binding.descriptorCount = 1;
6949 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6950 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006951
Tony Barboureb254902015-07-15 12:50:33 -06006952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006953 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6954 ds_layout_ci.pNext = NULL;
6955 ds_layout_ci.bindingCount = 1;
6956 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006957
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006958 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006960 ASSERT_VK_SUCCESS(err);
6961
6962 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006963 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006964 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006965 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006966 alloc_info.descriptorPool = ds_pool;
6967 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006969 ASSERT_VK_SUCCESS(err);
6970
Tony Barboureb254902015-07-15 12:50:33 -06006971 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006972 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6973 pipeline_layout_ci.setLayoutCount = 1;
6974 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006975
6976 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006978 ASSERT_VK_SUCCESS(err);
6979
Tobin Ehlise68360f2015-10-01 11:15:13 -06006980 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006981 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006982
6983 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006984 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6985 vp_state_ci.scissorCount = 1;
6986 vp_state_ci.pScissors = &sc;
6987 vp_state_ci.viewportCount = 1;
6988 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006989
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006990 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6991 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6992 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6993 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6994 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6995 rs_state_ci.depthClampEnable = VK_FALSE;
6996 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6997 rs_state_ci.depthBiasEnable = VK_FALSE;
6998
Tony Barboureb254902015-07-15 12:50:33 -06006999 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007000 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7001 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007002 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007003 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7004 gp_ci.layout = pipeline_layout;
7005 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06007006
7007 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007008 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7009 pc_ci.initialDataSize = 0;
7010 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007011
7012 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007013 VkPipelineCache pipelineCache;
7014
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007016 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007017 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007018
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007019 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007020
Chia-I Wuf7458c52015-10-26 21:10:41 +08007021 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7022 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7023 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7024 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007025}
Tobin Ehlis912df022015-09-17 08:46:18 -06007026/*// TODO : This test should be good, but needs Tess support in compiler to run
7027TEST_F(VkLayerTest, InvalidPatchControlPoints)
7028{
7029 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007030 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007031
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007033 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7034primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007035
Tobin Ehlis912df022015-09-17 08:46:18 -06007036 ASSERT_NO_FATAL_FAILURE(InitState());
7037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007038
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007039 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007040 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007041 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007042
7043 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7044 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7045 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007046 ds_pool_ci.poolSizeCount = 1;
7047 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007048
7049 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007050 err = vkCreateDescriptorPool(m_device->device(),
7051VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007055 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007057 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7059 dsl_binding.pImmutableSamplers = NULL;
7060
7061 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007062 ds_layout_ci.sType =
7063VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007064 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007065 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007066 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007067
7068 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007069 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7070&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007071 ASSERT_VK_SUCCESS(err);
7072
7073 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007074 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7075VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007076 ASSERT_VK_SUCCESS(err);
7077
7078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 pipeline_layout_ci.sType =
7080VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007081 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007082 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007083 pipeline_layout_ci.pSetLayouts = &ds_layout;
7084
7085 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007086 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7087&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007088 ASSERT_VK_SUCCESS(err);
7089
7090 VkPipelineShaderStageCreateInfo shaderStages[3];
7091 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7092
Karl Schultz6addd812016-02-02 17:17:23 -07007093 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7094this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007095 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007096 VkShaderObj
7097tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7098this);
7099 VkShaderObj
7100te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7101this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007102
Karl Schultz6addd812016-02-02 17:17:23 -07007103 shaderStages[0].sType =
7104VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007105 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007106 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007107 shaderStages[1].sType =
7108VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007109 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007110 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007111 shaderStages[2].sType =
7112VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007113 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007114 shaderStages[2].shader = te.handle();
7115
7116 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007117 iaCI.sType =
7118VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007119 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007120
7121 VkPipelineTessellationStateCreateInfo tsCI = {};
7122 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7123 tsCI.patchControlPoints = 0; // This will cause an error
7124
7125 VkGraphicsPipelineCreateInfo gp_ci = {};
7126 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7127 gp_ci.pNext = NULL;
7128 gp_ci.stageCount = 3;
7129 gp_ci.pStages = shaderStages;
7130 gp_ci.pVertexInputState = NULL;
7131 gp_ci.pInputAssemblyState = &iaCI;
7132 gp_ci.pTessellationState = &tsCI;
7133 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007134 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007135 gp_ci.pMultisampleState = NULL;
7136 gp_ci.pDepthStencilState = NULL;
7137 gp_ci.pColorBlendState = NULL;
7138 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7139 gp_ci.layout = pipeline_layout;
7140 gp_ci.renderPass = renderPass();
7141
7142 VkPipelineCacheCreateInfo pc_ci = {};
7143 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7144 pc_ci.pNext = NULL;
7145 pc_ci.initialSize = 0;
7146 pc_ci.initialData = 0;
7147 pc_ci.maxSize = 0;
7148
7149 VkPipeline pipeline;
7150 VkPipelineCache pipelineCache;
7151
Karl Schultz6addd812016-02-02 17:17:23 -07007152 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7153&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007154 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007155 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7156&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007157
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007158 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007159
Chia-I Wuf7458c52015-10-26 21:10:41 +08007160 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7162 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7163 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007164}
7165*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007166
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007167TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007168 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007169
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007170 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007171
Tobin Ehlise68360f2015-10-01 11:15:13 -06007172 ASSERT_NO_FATAL_FAILURE(InitState());
7173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007175 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7177 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
7179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7181 ds_pool_ci.maxSets = 1;
7182 ds_pool_ci.poolSizeCount = 1;
7183 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184
7185 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007186 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007187 ASSERT_VK_SUCCESS(err);
7188
7189 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007190 dsl_binding.binding = 0;
7191 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7192 dsl_binding.descriptorCount = 1;
7193 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194
7195 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007196 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7197 ds_layout_ci.bindingCount = 1;
7198 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007199
7200 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007202 ASSERT_VK_SUCCESS(err);
7203
7204 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007205 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007206 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007207 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007208 alloc_info.descriptorPool = ds_pool;
7209 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007210 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007211 ASSERT_VK_SUCCESS(err);
7212
7213 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007214 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7215 pipeline_layout_ci.setLayoutCount = 1;
7216 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007217
7218 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007219 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007220 ASSERT_VK_SUCCESS(err);
7221
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007222 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007223 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007224 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007225 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007226 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007227 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007229 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7230 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7231 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7232 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7233 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7234 rs_state_ci.depthClampEnable = VK_FALSE;
7235 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7236 rs_state_ci.depthBiasEnable = VK_FALSE;
7237
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007238 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7239 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7240 vi_ci.pNext = nullptr;
7241 vi_ci.vertexBindingDescriptionCount = 0;
7242 vi_ci.pVertexBindingDescriptions = nullptr;
7243 vi_ci.vertexAttributeDescriptionCount = 0;
7244 vi_ci.pVertexAttributeDescriptions = nullptr;
7245
7246 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7247 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7248 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7249
7250 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7251 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7252 pipe_ms_state_ci.pNext = NULL;
7253 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7254 pipe_ms_state_ci.sampleShadingEnable = 0;
7255 pipe_ms_state_ci.minSampleShading = 1.0;
7256 pipe_ms_state_ci.pSampleMask = NULL;
7257
Cody Northropeb3a6c12015-10-05 14:44:45 -06007258 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007259 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007261 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007262 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007263 shaderStages[0] = vs.GetStageCreateInfo();
7264 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265
7266 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007267 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7268 gp_ci.stageCount = 2;
7269 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007270 gp_ci.pVertexInputState = &vi_ci;
7271 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007272 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007273 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007274 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007275 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7276 gp_ci.layout = pipeline_layout;
7277 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007278
7279 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007280 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007281
7282 VkPipeline pipeline;
7283 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007286
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007287 if (!m_device->phy().features().multiViewport) {
7288 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7289
7290 // Check case where multiViewport is disabled and viewport count is not 1
7291 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7294 vp_state_ci.scissorCount = 0;
7295 vp_state_ci.viewportCount = 0;
7296 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7297 m_errorMonitor->VerifyFound();
7298 } else {
7299 if (m_device->props.limits.maxViewports == 1) {
7300 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7301 } else {
7302 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7303
7304 // Check is that viewportcount and scissorcount match
7305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7306 vp_state_ci.scissorCount = 1;
7307 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7308 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7309 m_errorMonitor->VerifyFound();
7310
7311
7312 // Check case where multiViewport is enabled and viewport count is greater than max
7313 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7316 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7317 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7318 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7319 m_errorMonitor->VerifyFound();
7320 }
7321 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
Chia-I Wuf7458c52015-10-26 21:10:41 +08007323 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7324 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7325 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7326 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007327}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007328
7329// Don't set viewport state in PSO. This is an error b/c we always need this state for the counts even if the data is going to be
7330// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007331TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007332 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007333
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007334 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7335
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007337
Tobin Ehlise68360f2015-10-01 11:15:13 -06007338 ASSERT_NO_FATAL_FAILURE(InitState());
7339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007341 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007342 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7343 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344
7345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7347 ds_pool_ci.maxSets = 1;
7348 ds_pool_ci.poolSizeCount = 1;
7349 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007350
7351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007353 ASSERT_VK_SUCCESS(err);
7354
7355 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007356 dsl_binding.binding = 0;
7357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7358 dsl_binding.descriptorCount = 1;
7359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007360
7361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7363 ds_layout_ci.bindingCount = 1;
7364 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365
7366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007368 ASSERT_VK_SUCCESS(err);
7369
7370 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007371 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007373 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007374 alloc_info.descriptorPool = ds_pool;
7375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007377 ASSERT_VK_SUCCESS(err);
7378
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007379 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7380 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7381 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7382
7383 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7384 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7385 vi_ci.pNext = nullptr;
7386 vi_ci.vertexBindingDescriptionCount = 0;
7387 vi_ci.pVertexBindingDescriptions = nullptr;
7388 vi_ci.vertexAttributeDescriptionCount = 0;
7389 vi_ci.pVertexAttributeDescriptions = nullptr;
7390
7391 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7392 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7393 pipe_ms_state_ci.pNext = NULL;
7394 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7395 pipe_ms_state_ci.sampleShadingEnable = 0;
7396 pipe_ms_state_ci.minSampleShading = 1.0;
7397 pipe_ms_state_ci.pSampleMask = NULL;
7398
Tobin Ehlise68360f2015-10-01 11:15:13 -06007399 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007400 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7401 pipeline_layout_ci.setLayoutCount = 1;
7402 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007403
7404 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007405 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007406 ASSERT_VK_SUCCESS(err);
7407
7408 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7409 // Set scissor as dynamic to avoid second error
7410 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007411 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7412 dyn_state_ci.dynamicStateCount = 1;
7413 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007414
Cody Northropeb3a6c12015-10-05 14:44:45 -06007415 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007416 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007418 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007419 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7420 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007421 shaderStages[0] = vs.GetStageCreateInfo();
7422 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007423
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007424 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7425 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7426 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7427 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7428 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7429 rs_state_ci.depthClampEnable = VK_FALSE;
7430 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7431 rs_state_ci.depthBiasEnable = VK_FALSE;
7432
Tobin Ehlise68360f2015-10-01 11:15:13 -06007433 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007434 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7435 gp_ci.stageCount = 2;
7436 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007437 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007438 // Not setting VP state w/o dynamic vp state should cause validation error
7439 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007440 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007441 gp_ci.pVertexInputState = &vi_ci;
7442 gp_ci.pInputAssemblyState = &ia_ci;
7443 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007444 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7445 gp_ci.layout = pipeline_layout;
7446 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447
7448 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007449 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007450
7451 VkPipeline pipeline;
7452 VkPipelineCache pipelineCache;
7453
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007454 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007455 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007456 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007458 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459
Chia-I Wuf7458c52015-10-26 21:10:41 +08007460 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7462 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7463 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007464}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007465
7466// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7467// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007468TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7469 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007470
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007472
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007474
7475 if (!m_device->phy().features().multiViewport) {
7476 printf("Device does not support multiple viewports/scissors; skipped.\n");
7477 return;
7478 }
7479
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007481
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007482 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007483 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7484 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485
7486 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007487 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7488 ds_pool_ci.maxSets = 1;
7489 ds_pool_ci.poolSizeCount = 1;
7490 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007491
7492 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007493 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007494 ASSERT_VK_SUCCESS(err);
7495
7496 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007497 dsl_binding.binding = 0;
7498 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7499 dsl_binding.descriptorCount = 1;
7500 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007501
7502 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007503 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7504 ds_layout_ci.bindingCount = 1;
7505 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007506
7507 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007509 ASSERT_VK_SUCCESS(err);
7510
7511 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007512 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007513 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007514 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007515 alloc_info.descriptorPool = ds_pool;
7516 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007517 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007518 ASSERT_VK_SUCCESS(err);
7519
7520 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007521 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7522 pipeline_layout_ci.setLayoutCount = 1;
7523 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007524
7525 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007526 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007527 ASSERT_VK_SUCCESS(err);
7528
7529 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007530 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7531 vp_state_ci.viewportCount = 1;
7532 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7533 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007535
7536 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7537 // Set scissor as dynamic to avoid that error
7538 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007539 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7540 dyn_state_ci.dynamicStateCount = 1;
7541 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007542
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007543 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7544 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7545 pipe_ms_state_ci.pNext = NULL;
7546 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7547 pipe_ms_state_ci.sampleShadingEnable = 0;
7548 pipe_ms_state_ci.minSampleShading = 1.0;
7549 pipe_ms_state_ci.pSampleMask = NULL;
7550
Cody Northropeb3a6c12015-10-05 14:44:45 -06007551 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007552 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007553
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007554 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007555 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7556 // We shouldn't need a fragment shader but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007557 shaderStages[0] = vs.GetStageCreateInfo();
7558 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007559
Cody Northropf6622dc2015-10-06 10:33:21 -06007560 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7561 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7562 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007563 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007564 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007565 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007566 vi_ci.pVertexAttributeDescriptions = nullptr;
7567
7568 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7569 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7570 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7571
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007572 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007573 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007574 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007575 rs_ci.pNext = nullptr;
7576
Mark Youngc89c6312016-03-31 16:03:20 -06007577 VkPipelineColorBlendAttachmentState att = {};
7578 att.blendEnable = VK_FALSE;
7579 att.colorWriteMask = 0xf;
7580
Cody Northropf6622dc2015-10-06 10:33:21 -06007581 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7582 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7583 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007584 cb_ci.attachmentCount = 1;
7585 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007586
Tobin Ehlise68360f2015-10-01 11:15:13 -06007587 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007588 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7589 gp_ci.stageCount = 2;
7590 gp_ci.pStages = shaderStages;
7591 gp_ci.pVertexInputState = &vi_ci;
7592 gp_ci.pInputAssemblyState = &ia_ci;
7593 gp_ci.pViewportState = &vp_state_ci;
7594 gp_ci.pRasterizationState = &rs_ci;
7595 gp_ci.pColorBlendState = &cb_ci;
7596 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007597 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007598 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7599 gp_ci.layout = pipeline_layout;
7600 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007601
7602 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007603 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007604
7605 VkPipeline pipeline;
7606 VkPipelineCache pipelineCache;
7607
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007608 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007609 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007610 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007611
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007612 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007613
Tobin Ehlisd332f282015-10-02 11:00:56 -06007614 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007615 // First need to successfully create the PSO from above by setting
7616 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, ");
Karl Schultz6addd812016-02-02 17:17:23 -07007618
7619 VkViewport vp = {}; // Just need dummy vp to point to
7620 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007621 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007622 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007623 m_commandBuffer->BeginCommandBuffer();
7624 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007625 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007626 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007627 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007628 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007629 Draw(1, 0, 0, 0);
7630
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007631 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007632
7633 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7634 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7635 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7636 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007637 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007638}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007639
7640// Create PSO w/o non-zero scissorCount but no scissor data, then run second test where dynamic viewportCount doesn't match PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007641// viewportCount
7642TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7643 VkResult err;
7644
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007646
7647 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007648
7649 if (!m_device->phy().features().multiViewport) {
7650 printf("Device does not support multiple viewports/scissors; skipped.\n");
7651 return;
7652 }
7653
Karl Schultz6addd812016-02-02 17:17:23 -07007654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7655
7656 VkDescriptorPoolSize ds_type_count = {};
7657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7658 ds_type_count.descriptorCount = 1;
7659
7660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7662 ds_pool_ci.maxSets = 1;
7663 ds_pool_ci.poolSizeCount = 1;
7664 ds_pool_ci.pPoolSizes = &ds_type_count;
7665
7666 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007667 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007668 ASSERT_VK_SUCCESS(err);
7669
7670 VkDescriptorSetLayoutBinding dsl_binding = {};
7671 dsl_binding.binding = 0;
7672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7673 dsl_binding.descriptorCount = 1;
7674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7675
7676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7678 ds_layout_ci.bindingCount = 1;
7679 ds_layout_ci.pBindings = &dsl_binding;
7680
7681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007683 ASSERT_VK_SUCCESS(err);
7684
7685 VkDescriptorSet descriptorSet;
7686 VkDescriptorSetAllocateInfo alloc_info = {};
7687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7688 alloc_info.descriptorSetCount = 1;
7689 alloc_info.descriptorPool = ds_pool;
7690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007692 ASSERT_VK_SUCCESS(err);
7693
7694 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7695 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7696 pipeline_layout_ci.setLayoutCount = 1;
7697 pipeline_layout_ci.pSetLayouts = &ds_layout;
7698
7699 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007700 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007701 ASSERT_VK_SUCCESS(err);
7702
7703 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7704 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7705 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007706 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007707 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007709
7710 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7711 // Set scissor as dynamic to avoid that error
7712 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7713 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7714 dyn_state_ci.dynamicStateCount = 1;
7715 dyn_state_ci.pDynamicStates = &vp_state;
7716
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007717 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7718 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7719 pipe_ms_state_ci.pNext = NULL;
7720 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7721 pipe_ms_state_ci.sampleShadingEnable = 0;
7722 pipe_ms_state_ci.minSampleShading = 1.0;
7723 pipe_ms_state_ci.pSampleMask = NULL;
7724
Karl Schultz6addd812016-02-02 17:17:23 -07007725 VkPipelineShaderStageCreateInfo shaderStages[2];
7726 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007729 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7730 // We shouldn't need a fragment shader but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007731 shaderStages[0] = vs.GetStageCreateInfo();
7732 shaderStages[1] = fs.GetStageCreateInfo();
7733
7734 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7735 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7736 vi_ci.pNext = nullptr;
7737 vi_ci.vertexBindingDescriptionCount = 0;
7738 vi_ci.pVertexBindingDescriptions = nullptr;
7739 vi_ci.vertexAttributeDescriptionCount = 0;
7740 vi_ci.pVertexAttributeDescriptions = nullptr;
7741
7742 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7743 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7744 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7745
7746 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7747 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007748 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007749 rs_ci.pNext = nullptr;
7750
Mark Youngc89c6312016-03-31 16:03:20 -06007751 VkPipelineColorBlendAttachmentState att = {};
7752 att.blendEnable = VK_FALSE;
7753 att.colorWriteMask = 0xf;
7754
Karl Schultz6addd812016-02-02 17:17:23 -07007755 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7756 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7757 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007758 cb_ci.attachmentCount = 1;
7759 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007760
7761 VkGraphicsPipelineCreateInfo gp_ci = {};
7762 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7763 gp_ci.stageCount = 2;
7764 gp_ci.pStages = shaderStages;
7765 gp_ci.pVertexInputState = &vi_ci;
7766 gp_ci.pInputAssemblyState = &ia_ci;
7767 gp_ci.pViewportState = &vp_state_ci;
7768 gp_ci.pRasterizationState = &rs_ci;
7769 gp_ci.pColorBlendState = &cb_ci;
7770 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007771 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007772 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7773 gp_ci.layout = pipeline_layout;
7774 gp_ci.renderPass = renderPass();
7775
7776 VkPipelineCacheCreateInfo pc_ci = {};
7777 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7778
7779 VkPipeline pipeline;
7780 VkPipelineCache pipelineCache;
7781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007782 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007783 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007784 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007785
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007786 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007787
7788 // Now hit second fail case where we set scissor w/ different count than PSO
7789 // First need to successfully create the PSO from above by setting
7790 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007792
Tobin Ehlisd332f282015-10-02 11:00:56 -06007793 VkRect2D sc = {}; // Just need dummy vp to point to
7794 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007796 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007797 m_commandBuffer->BeginCommandBuffer();
7798 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007799 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007800 VkViewport viewports[1] = {};
7801 viewports[0].width = 8;
7802 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007803 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007804 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007805 Draw(1, 0, 0, 0);
7806
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007807 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007808
Chia-I Wuf7458c52015-10-26 21:10:41 +08007809 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7810 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7811 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7812 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007813 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007814}
7815
Mark Young7394fdd2016-03-31 14:56:43 -06007816TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7817 VkResult err;
7818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007820
7821 ASSERT_NO_FATAL_FAILURE(InitState());
7822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7823
7824 VkDescriptorPoolSize ds_type_count = {};
7825 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7826 ds_type_count.descriptorCount = 1;
7827
7828 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7829 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7830 ds_pool_ci.maxSets = 1;
7831 ds_pool_ci.poolSizeCount = 1;
7832 ds_pool_ci.pPoolSizes = &ds_type_count;
7833
7834 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007835 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007836 ASSERT_VK_SUCCESS(err);
7837
7838 VkDescriptorSetLayoutBinding dsl_binding = {};
7839 dsl_binding.binding = 0;
7840 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7841 dsl_binding.descriptorCount = 1;
7842 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7843
7844 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7845 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7846 ds_layout_ci.bindingCount = 1;
7847 ds_layout_ci.pBindings = &dsl_binding;
7848
7849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007851 ASSERT_VK_SUCCESS(err);
7852
7853 VkDescriptorSet descriptorSet;
7854 VkDescriptorSetAllocateInfo alloc_info = {};
7855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7856 alloc_info.descriptorSetCount = 1;
7857 alloc_info.descriptorPool = ds_pool;
7858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007860 ASSERT_VK_SUCCESS(err);
7861
7862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7864 pipeline_layout_ci.setLayoutCount = 1;
7865 pipeline_layout_ci.pSetLayouts = &ds_layout;
7866
7867 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007869 ASSERT_VK_SUCCESS(err);
7870
7871 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7872 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7873 vp_state_ci.scissorCount = 1;
7874 vp_state_ci.pScissors = NULL;
7875 vp_state_ci.viewportCount = 1;
7876 vp_state_ci.pViewports = NULL;
7877
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007878 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007879 // Set scissor as dynamic to avoid that error
7880 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7881 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7882 dyn_state_ci.dynamicStateCount = 2;
7883 dyn_state_ci.pDynamicStates = dynamic_states;
7884
7885 VkPipelineShaderStageCreateInfo shaderStages[2];
7886 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007888 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7889 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007890 this); // TODO - We shouldn't need a fragment shader
7891 // but add it to be able to run on more devices
7892 shaderStages[0] = vs.GetStageCreateInfo();
7893 shaderStages[1] = fs.GetStageCreateInfo();
7894
7895 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7896 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7897 vi_ci.pNext = nullptr;
7898 vi_ci.vertexBindingDescriptionCount = 0;
7899 vi_ci.pVertexBindingDescriptions = nullptr;
7900 vi_ci.vertexAttributeDescriptionCount = 0;
7901 vi_ci.pVertexAttributeDescriptions = nullptr;
7902
7903 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7904 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7905 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7906
7907 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7908 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7909 rs_ci.pNext = nullptr;
7910
Mark Young47107952016-05-02 15:59:55 -06007911 // Check too low (line width of -1.0f).
7912 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007913
7914 VkPipelineColorBlendAttachmentState att = {};
7915 att.blendEnable = VK_FALSE;
7916 att.colorWriteMask = 0xf;
7917
7918 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7919 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7920 cb_ci.pNext = nullptr;
7921 cb_ci.attachmentCount = 1;
7922 cb_ci.pAttachments = &att;
7923
7924 VkGraphicsPipelineCreateInfo gp_ci = {};
7925 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7926 gp_ci.stageCount = 2;
7927 gp_ci.pStages = shaderStages;
7928 gp_ci.pVertexInputState = &vi_ci;
7929 gp_ci.pInputAssemblyState = &ia_ci;
7930 gp_ci.pViewportState = &vp_state_ci;
7931 gp_ci.pRasterizationState = &rs_ci;
7932 gp_ci.pColorBlendState = &cb_ci;
7933 gp_ci.pDynamicState = &dyn_state_ci;
7934 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7935 gp_ci.layout = pipeline_layout;
7936 gp_ci.renderPass = renderPass();
7937
7938 VkPipelineCacheCreateInfo pc_ci = {};
7939 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7940
7941 VkPipeline pipeline;
7942 VkPipelineCache pipelineCache;
7943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007945 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007946 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007947
7948 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007949 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007952
7953 // Check too high (line width of 65536.0f).
7954 rs_ci.lineWidth = 65536.0f;
7955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007956 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007957 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007958 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007959
7960 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007961 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007964
7965 dyn_state_ci.dynamicStateCount = 3;
7966
7967 rs_ci.lineWidth = 1.0f;
7968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007970 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007971 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007972 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007974
7975 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007976 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007977 m_errorMonitor->VerifyFound();
7978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007980
7981 // Check too high with dynamic setting.
7982 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7983 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007984 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007985
7986 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007990 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007991}
7992
Karl Schultz6addd812016-02-02 17:17:23 -07007993TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007994 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007996 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007997
7998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008000
Tony Barbour552f6c02016-12-21 14:34:07 -07008001 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008002 // Don't care about RenderPass handle b/c error should be flagged before
8003 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008005
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008006 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008007}
8008
Karl Schultz6addd812016-02-02 17:17:23 -07008009TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008010 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8012 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008013
8014 ASSERT_NO_FATAL_FAILURE(InitState());
8015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008016
Tony Barbour552f6c02016-12-21 14:34:07 -07008017 m_commandBuffer->BeginCommandBuffer();
8018 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008019 // Just create a dummy Renderpass that's non-NULL so we can get to the
8020 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008022
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008023 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008024}
8025
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008026TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8027 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8028 "the number of renderPass attachments that use loadOp"
8029 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8030
8031 ASSERT_NO_FATAL_FAILURE(InitState());
8032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8033
8034 // Create a renderPass with a single attachment that uses loadOp CLEAR
8035 VkAttachmentReference attach = {};
8036 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8037 VkSubpassDescription subpass = {};
8038 subpass.inputAttachmentCount = 1;
8039 subpass.pInputAttachments = &attach;
8040 VkRenderPassCreateInfo rpci = {};
8041 rpci.subpassCount = 1;
8042 rpci.pSubpasses = &subpass;
8043 rpci.attachmentCount = 1;
8044 VkAttachmentDescription attach_desc = {};
8045 attach_desc.format = VK_FORMAT_UNDEFINED;
8046 // Set loadOp to CLEAR
8047 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8048 rpci.pAttachments = &attach_desc;
8049 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8050 VkRenderPass rp;
8051 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8052
8053 VkCommandBufferInheritanceInfo hinfo = {};
8054 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8055 hinfo.renderPass = VK_NULL_HANDLE;
8056 hinfo.subpass = 0;
8057 hinfo.framebuffer = VK_NULL_HANDLE;
8058 hinfo.occlusionQueryEnable = VK_FALSE;
8059 hinfo.queryFlags = 0;
8060 hinfo.pipelineStatistics = 0;
8061 VkCommandBufferBeginInfo info = {};
8062 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8063 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8064 info.pInheritanceInfo = &hinfo;
8065
8066 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8067 VkRenderPassBeginInfo rp_begin = {};
8068 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8069 rp_begin.pNext = NULL;
8070 rp_begin.renderPass = renderPass();
8071 rp_begin.framebuffer = framebuffer();
8072 rp_begin.clearValueCount = 0; // Should be 1
8073
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008075
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008076 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008077
8078 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008079
8080 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008081}
8082
Slawomir Cygan0808f392016-11-28 17:53:23 +01008083TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8084 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8085 "the number of renderPass attachments that use loadOp"
8086 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8087
8088 ASSERT_NO_FATAL_FAILURE(InitState());
8089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8090
8091 // Create a renderPass with a single attachment that uses loadOp CLEAR
8092 VkAttachmentReference attach = {};
8093 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8094 VkSubpassDescription subpass = {};
8095 subpass.inputAttachmentCount = 1;
8096 subpass.pInputAttachments = &attach;
8097 VkRenderPassCreateInfo rpci = {};
8098 rpci.subpassCount = 1;
8099 rpci.pSubpasses = &subpass;
8100 rpci.attachmentCount = 1;
8101 VkAttachmentDescription attach_desc = {};
8102 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8103 // Set loadOp to CLEAR
8104 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8105 rpci.pAttachments = &attach_desc;
8106 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8107 VkRenderPass rp;
8108 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8109
8110 VkCommandBufferBeginInfo info = {};
8111 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8112 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8113
8114 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8115 VkRenderPassBeginInfo rp_begin = {};
8116 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8117 rp_begin.pNext = NULL;
8118 rp_begin.renderPass = renderPass();
8119 rp_begin.framebuffer = framebuffer();
8120 rp_begin.clearValueCount = 2; // Should be 1
8121
8122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8123 " 2 but only first 1 entries in pClearValues array are used");
8124
8125 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8126
8127 m_errorMonitor->VerifyFound();
8128
8129 vkDestroyRenderPass(m_device->device(), rp, NULL);
8130}
8131
8132
Cody Northrop3bb4d962016-05-09 16:15:57 -06008133TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8134
8135 TEST_DESCRIPTION("End a command buffer with an active render pass");
8136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8138 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008139
8140 ASSERT_NO_FATAL_FAILURE(InitState());
8141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8142
Tony Barbour552f6c02016-12-21 14:34:07 -07008143 m_commandBuffer->BeginCommandBuffer();
8144 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8145 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008146
8147 m_errorMonitor->VerifyFound();
8148
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008149 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8150 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008151}
8152
Karl Schultz6addd812016-02-02 17:17:23 -07008153TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008154 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8156 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008157
8158 ASSERT_NO_FATAL_FAILURE(InitState());
8159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008160
Tony Barbour552f6c02016-12-21 14:34:07 -07008161 m_commandBuffer->BeginCommandBuffer();
8162 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008163
8164 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008165 vk_testing::Buffer dstBuffer;
8166 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008167
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008168 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008169
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008170 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008171}
8172
Karl Schultz6addd812016-02-02 17:17:23 -07008173TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008174 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8176 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008177
8178 ASSERT_NO_FATAL_FAILURE(InitState());
8179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008180
Tony Barbour552f6c02016-12-21 14:34:07 -07008181 m_commandBuffer->BeginCommandBuffer();
8182 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008183
8184 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008185 vk_testing::Buffer dstBuffer;
8186 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008187
Karl Schultz6addd812016-02-02 17:17:23 -07008188 VkDeviceSize dstOffset = 0;
8189 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008190 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008191
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008192 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008193
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008194 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008195}
8196
Karl Schultz6addd812016-02-02 17:17:23 -07008197TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008198 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8200 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008201
8202 ASSERT_NO_FATAL_FAILURE(InitState());
8203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204
Tony Barbour552f6c02016-12-21 14:34:07 -07008205 m_commandBuffer->BeginCommandBuffer();
8206 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008207
Michael Lentine0a369f62016-02-03 16:51:46 -06008208 VkClearColorValue clear_color;
8209 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008210 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8211 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8212 const int32_t tex_width = 32;
8213 const int32_t tex_height = 32;
8214 VkImageCreateInfo image_create_info = {};
8215 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8216 image_create_info.pNext = NULL;
8217 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8218 image_create_info.format = tex_format;
8219 image_create_info.extent.width = tex_width;
8220 image_create_info.extent.height = tex_height;
8221 image_create_info.extent.depth = 1;
8222 image_create_info.mipLevels = 1;
8223 image_create_info.arrayLayers = 1;
8224 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8225 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8226 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008227
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008228 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008229 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008231 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008233 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008234
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008235 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008236}
8237
Karl Schultz6addd812016-02-02 17:17:23 -07008238TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008239 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8241 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008242
8243 ASSERT_NO_FATAL_FAILURE(InitState());
8244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008245
Tony Barbour552f6c02016-12-21 14:34:07 -07008246 m_commandBuffer->BeginCommandBuffer();
8247 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008248
8249 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008250 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008251 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8252 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8253 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8254 image_create_info.extent.width = 64;
8255 image_create_info.extent.height = 64;
8256 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8257 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008258
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008259 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008264 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8265 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008266
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008267 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008268}
8269
Karl Schultz6addd812016-02-02 17:17:23 -07008270TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008271 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008272 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8275 "must be issued inside an active "
8276 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008277
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008278 ASSERT_NO_FATAL_FAILURE(InitState());
8279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008280
8281 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008282 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008283 ASSERT_VK_SUCCESS(err);
8284
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008285 VkClearAttachment color_attachment;
8286 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8287 color_attachment.clearValue.color.float32[0] = 0;
8288 color_attachment.clearValue.color.float32[1] = 0;
8289 color_attachment.clearValue.color.float32[2] = 0;
8290 color_attachment.clearValue.color.float32[3] = 0;
8291 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008292 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008293 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008294
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008295 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008296}
8297
Chris Forbes3b97e932016-09-07 11:29:24 +12008298TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8299 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8300 "called too many times in a renderpass instance");
8301
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8303 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008304
8305 ASSERT_NO_FATAL_FAILURE(InitState());
8306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8307
Tony Barbour552f6c02016-12-21 14:34:07 -07008308 m_commandBuffer->BeginCommandBuffer();
8309 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008310
8311 // error here.
8312 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8313 m_errorMonitor->VerifyFound();
8314
Tony Barbour552f6c02016-12-21 14:34:07 -07008315 m_commandBuffer->EndRenderPass();
8316 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008317}
8318
Chris Forbes6d624702016-09-07 13:57:05 +12008319TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8320 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8321 "called before the final subpass has been reached");
8322
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8324 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008325
8326 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8328 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008329
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008331
8332 VkRenderPass rp;
8333 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8334 ASSERT_VK_SUCCESS(err);
8335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008337
8338 VkFramebuffer fb;
8339 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8340 ASSERT_VK_SUCCESS(err);
8341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 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 +12008345
8346 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8347
8348 // Error here.
8349 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8350 m_errorMonitor->VerifyFound();
8351
8352 // Clean up.
8353 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8354 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8355}
8356
Karl Schultz9e66a292016-04-21 15:57:51 -06008357TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8358 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8360 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008361
8362 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008363 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008364
8365 VkBufferMemoryBarrier buf_barrier = {};
8366 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8367 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8368 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8369 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8370 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8371 buf_barrier.buffer = VK_NULL_HANDLE;
8372 buf_barrier.offset = 0;
8373 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8375 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008376
8377 m_errorMonitor->VerifyFound();
8378}
8379
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008380TEST_F(VkLayerTest, InvalidBarriers) {
8381 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008384
8385 ASSERT_NO_FATAL_FAILURE(InitState());
8386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8387
8388 VkMemoryBarrier mem_barrier = {};
8389 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8390 mem_barrier.pNext = NULL;
8391 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8392 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008393 m_commandBuffer->BeginCommandBuffer();
8394 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008395 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008397 &mem_barrier, 0, nullptr, 0, nullptr);
8398 m_errorMonitor->VerifyFound();
8399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008401 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008402 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 -06008403 ASSERT_TRUE(image.initialized());
8404 VkImageMemoryBarrier img_barrier = {};
8405 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8406 img_barrier.pNext = NULL;
8407 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8408 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8409 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8410 // New layout can't be UNDEFINED
8411 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8412 img_barrier.image = image.handle();
8413 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8414 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8415 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8416 img_barrier.subresourceRange.baseArrayLayer = 0;
8417 img_barrier.subresourceRange.baseMipLevel = 0;
8418 img_barrier.subresourceRange.layerCount = 1;
8419 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8421 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008422 m_errorMonitor->VerifyFound();
8423 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8424
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8426 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008427 // baseArrayLayer + layerCount must be <= image's arrayLayers
8428 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8430 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008431 m_errorMonitor->VerifyFound();
8432 img_barrier.subresourceRange.baseArrayLayer = 0;
8433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008435 // baseMipLevel + levelCount must be <= image's mipLevels
8436 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008437 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8438 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008439 m_errorMonitor->VerifyFound();
8440 img_barrier.subresourceRange.baseMipLevel = 0;
8441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 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 -06008443 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008444 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8445 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008446 VkBufferMemoryBarrier buf_barrier = {};
8447 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8448 buf_barrier.pNext = NULL;
8449 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8450 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8451 buf_barrier.buffer = buffer.handle();
8452 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8453 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8454 buf_barrier.offset = 0;
8455 buf_barrier.size = VK_WHOLE_SIZE;
8456 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008457 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8458 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008459 m_errorMonitor->VerifyFound();
8460 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008463 buf_barrier.offset = 257;
8464 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8466 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008467 m_errorMonitor->VerifyFound();
8468 buf_barrier.offset = 0;
8469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008471 buf_barrier.size = 257;
8472 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008473 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8474 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008475 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008476
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008477 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008478 m_errorMonitor->SetDesiredFailureMsg(
8479 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8480 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8481 m_errorMonitor->SetDesiredFailureMsg(
8482 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8483 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008484 VkDepthStencilObj ds_image(m_device);
8485 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8486 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008487 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8488 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008489 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008490 // Use of COLOR aspect on DS image is error
8491 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8493 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008494 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008495 // Now test depth-only
8496 VkFormatProperties format_props;
8497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8499 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8501 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8503 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008504 VkDepthStencilObj d_image(m_device);
8505 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8506 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008508 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008509 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008510 // Use of COLOR aspect on depth image is error
8511 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8513 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008514 m_errorMonitor->VerifyFound();
8515 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008516 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8517 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008518 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8520 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008521 VkDepthStencilObj s_image(m_device);
8522 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8523 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008524 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008525 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008526 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008527 // Use of COLOR aspect on depth image is error
8528 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8530 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008531 m_errorMonitor->VerifyFound();
8532 }
8533 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8535 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8537 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008538 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 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 -06008540 ASSERT_TRUE(c_image.initialized());
8541 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8542 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8543 img_barrier.image = c_image.handle();
8544 // Set aspect to depth (non-color)
8545 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008546 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8547 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008548 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008549
8550 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8551
8552 // Create command pool with incompatible queueflags
8553 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8554 uint32_t queue_family_index = UINT32_MAX;
8555 for (uint32_t i = 0; i < queue_props.size(); i++) {
8556 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8557 queue_family_index = i;
8558 break;
8559 }
8560 }
8561 if (queue_family_index == UINT32_MAX) {
8562 printf("No non-compute queue found; skipped.\n");
8563 return;
8564 }
8565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8566
8567 VkCommandPool command_pool;
8568 VkCommandPoolCreateInfo pool_create_info{};
8569 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8570 pool_create_info.queueFamilyIndex = queue_family_index;
8571 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8572 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8573
8574 // Allocate a command buffer
8575 VkCommandBuffer bad_command_buffer;
8576 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8577 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8578 command_buffer_allocate_info.commandPool = command_pool;
8579 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8580 command_buffer_allocate_info.commandBufferCount = 1;
8581 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8582
8583 VkCommandBufferBeginInfo cbbi = {};
8584 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8585 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8586 buf_barrier.offset = 0;
8587 buf_barrier.size = VK_WHOLE_SIZE;
8588 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8589 &buf_barrier, 0, nullptr);
8590 m_errorMonitor->VerifyFound();
8591
8592 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8593 vkEndCommandBuffer(bad_command_buffer);
8594 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8595 printf("The non-compute queue does not support graphics; skipped.\n");
8596 return;
8597 }
8598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8599 VkEvent event;
8600 VkEventCreateInfo event_create_info{};
8601 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8602 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8603 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8604 nullptr, 0, nullptr);
8605 m_errorMonitor->VerifyFound();
8606
8607 vkEndCommandBuffer(bad_command_buffer);
8608 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008609}
8610
Tony Barbour18ba25c2016-09-29 13:42:40 -06008611TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8612 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8613
8614 m_errorMonitor->SetDesiredFailureMsg(
8615 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8616 "must have required access bit");
8617 ASSERT_NO_FATAL_FAILURE(InitState());
8618 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008619 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06008620 ASSERT_TRUE(image.initialized());
8621
8622 VkImageMemoryBarrier barrier = {};
8623 VkImageSubresourceRange range;
8624 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8625 barrier.srcAccessMask = 0;
8626 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8627 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8628 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8629 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8630 barrier.image = image.handle();
8631 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8632 range.baseMipLevel = 0;
8633 range.levelCount = 1;
8634 range.baseArrayLayer = 0;
8635 range.layerCount = 1;
8636 barrier.subresourceRange = range;
8637 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8638 cmdbuf.BeginCommandBuffer();
8639 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8640 &barrier);
8641 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8642 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8643 barrier.srcAccessMask = 0;
8644 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8645 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8646 &barrier);
8647
8648 m_errorMonitor->VerifyFound();
8649}
8650
Karl Schultz6addd812016-02-02 17:17:23 -07008651TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008652 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008653 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008654
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008656
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008657 ASSERT_NO_FATAL_FAILURE(InitState());
8658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008659 uint32_t qfi = 0;
8660 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008661 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8662 buffCI.size = 1024;
8663 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8664 buffCI.queueFamilyIndexCount = 1;
8665 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008666
8667 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008668 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008669 ASSERT_VK_SUCCESS(err);
8670
Tony Barbour552f6c02016-12-21 14:34:07 -07008671 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008672 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008673 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8674 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008675 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008676 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008677
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008678 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008679
Chia-I Wuf7458c52015-10-26 21:10:41 +08008680 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008681}
8682
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008683TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8684 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8686 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8687 "of the indices specified when the device was created, via the "
8688 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008689
8690 ASSERT_NO_FATAL_FAILURE(InitState());
8691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8692 VkBufferCreateInfo buffCI = {};
8693 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8694 buffCI.size = 1024;
8695 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8696 buffCI.queueFamilyIndexCount = 1;
8697 // Introduce failure by specifying invalid queue_family_index
8698 uint32_t qfi = 777;
8699 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008700 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008701
8702 VkBuffer ib;
8703 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8704
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008705 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008706 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008707}
8708
Karl Schultz6addd812016-02-02 17:17:23 -07008709TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008710TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008711 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008712
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008713 ASSERT_NO_FATAL_FAILURE(InitState());
8714 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008715
Chris Forbesf29a84f2016-10-06 18:39:28 +13008716 // An empty primary command buffer
8717 VkCommandBufferObj cb(m_device, m_commandPool);
8718 cb.BeginCommandBuffer();
8719 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008720
Chris Forbesf29a84f2016-10-06 18:39:28 +13008721 m_commandBuffer->BeginCommandBuffer();
8722 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8723 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008724
Chris Forbesf29a84f2016-10-06 18:39:28 +13008725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8726 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008727 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008728}
8729
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008730TEST_F(VkLayerTest, DSUsageBitsErrors) {
8731 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8732 "that do not have correct usage bits sets.");
8733 VkResult err;
8734
8735 ASSERT_NO_FATAL_FAILURE(InitState());
8736 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8737 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8738 ds_type_count[i].type = VkDescriptorType(i);
8739 ds_type_count[i].descriptorCount = 1;
8740 }
8741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8743 ds_pool_ci.pNext = NULL;
8744 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8745 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8746 ds_pool_ci.pPoolSizes = ds_type_count;
8747
8748 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008750 ASSERT_VK_SUCCESS(err);
8751
8752 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008754 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8755 dsl_binding[i].binding = 0;
8756 dsl_binding[i].descriptorType = VkDescriptorType(i);
8757 dsl_binding[i].descriptorCount = 1;
8758 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8759 dsl_binding[i].pImmutableSamplers = NULL;
8760 }
8761
8762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8764 ds_layout_ci.pNext = NULL;
8765 ds_layout_ci.bindingCount = 1;
8766 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8767 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8768 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008770 ASSERT_VK_SUCCESS(err);
8771 }
8772 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8773 VkDescriptorSetAllocateInfo alloc_info = {};
8774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8775 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8776 alloc_info.descriptorPool = ds_pool;
8777 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008779 ASSERT_VK_SUCCESS(err);
8780
8781 // Create a buffer & bufferView to be used for invalid updates
8782 VkBufferCreateInfo buff_ci = {};
8783 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8784 // This usage is not valid for any descriptor type
8785 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8786 buff_ci.size = 256;
8787 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8788 VkBuffer buffer;
8789 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8790 ASSERT_VK_SUCCESS(err);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008791 VkMemoryRequirements mem_reqs;
8792 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8793 VkMemoryAllocateInfo mem_alloc_info = {};
8794 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8795 mem_alloc_info.pNext = NULL;
8796 mem_alloc_info.memoryTypeIndex = 0;
8797 mem_alloc_info.allocationSize = mem_reqs.size;
8798 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8799 if (!pass) {
8800 vkDestroyBuffer(m_device->device(), buffer, NULL);
8801 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8802 return;
8803 }
8804 VkDeviceMemory mem;
8805 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8806 ASSERT_VK_SUCCESS(err);
8807 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8808 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008809
8810 VkBufferViewCreateInfo buff_view_ci = {};
8811 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8812 buff_view_ci.buffer = buffer;
8813 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8814 buff_view_ci.range = VK_WHOLE_SIZE;
8815 VkBufferView buff_view;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008816 // Note that this hits VALIDATION_ERROR_00694 due to no usage bit set, but we want call to go through
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008817 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008818 ASSERT_VK_SUCCESS(err);
8819
8820 // Create an image to be used for invalid updates
8821 VkImageCreateInfo image_ci = {};
8822 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8823 image_ci.imageType = VK_IMAGE_TYPE_2D;
8824 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8825 image_ci.extent.width = 64;
8826 image_ci.extent.height = 64;
8827 image_ci.extent.depth = 1;
8828 image_ci.mipLevels = 1;
8829 image_ci.arrayLayers = 1;
8830 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8831 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8832 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8833 // This usage is not valid for any descriptor type
8834 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8835 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8836 VkImage image;
8837 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8838 ASSERT_VK_SUCCESS(err);
8839 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008840 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008841
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008842 VkMemoryAllocateInfo mem_alloc = {};
8843 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8844 mem_alloc.pNext = NULL;
8845 mem_alloc.allocationSize = 0;
8846 mem_alloc.memoryTypeIndex = 0;
8847 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8848 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008850 ASSERT_TRUE(pass);
8851 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8852 ASSERT_VK_SUCCESS(err);
8853 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8854 ASSERT_VK_SUCCESS(err);
8855 // Now create view for image
8856 VkImageViewCreateInfo image_view_ci = {};
8857 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8858 image_view_ci.image = image;
8859 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8860 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8861 image_view_ci.subresourceRange.layerCount = 1;
8862 image_view_ci.subresourceRange.baseArrayLayer = 0;
8863 image_view_ci.subresourceRange.levelCount = 1;
8864 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8865 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008866 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008867 ASSERT_VK_SUCCESS(err);
8868
8869 VkDescriptorBufferInfo buff_info = {};
8870 buff_info.buffer = buffer;
8871 VkDescriptorImageInfo img_info = {};
8872 img_info.imageView = image_view;
8873 VkWriteDescriptorSet descriptor_write = {};
8874 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8875 descriptor_write.dstBinding = 0;
8876 descriptor_write.descriptorCount = 1;
8877 descriptor_write.pTexelBufferView = &buff_view;
8878 descriptor_write.pBufferInfo = &buff_info;
8879 descriptor_write.pImageInfo = &img_info;
8880
8881 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008882 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
8883 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8884 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8885 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8886 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8887 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8888 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8889 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8890 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8891 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8892 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8893 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
8894 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008895 // Start loop at 1 as SAMPLER desc type has no usage bit error
8896 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8897 descriptor_write.descriptorType = VkDescriptorType(i);
8898 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008901 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008902
8903 m_errorMonitor->VerifyFound();
8904 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8905 }
8906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8907 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008908 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008909 vkDestroyImageView(m_device->device(), image_view, NULL);
8910 vkDestroyBuffer(m_device->device(), buffer, NULL);
8911 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008912 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008913 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8914}
8915
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008916TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8918 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8919 "1. offset value greater than buffer size\n"
8920 "2. range value of 0\n"
8921 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008922 VkResult err;
8923
8924 ASSERT_NO_FATAL_FAILURE(InitState());
8925 VkDescriptorPoolSize ds_type_count = {};
8926 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8927 ds_type_count.descriptorCount = 1;
8928
8929 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8930 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8931 ds_pool_ci.pNext = NULL;
8932 ds_pool_ci.maxSets = 1;
8933 ds_pool_ci.poolSizeCount = 1;
8934 ds_pool_ci.pPoolSizes = &ds_type_count;
8935
8936 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008937 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008938 ASSERT_VK_SUCCESS(err);
8939
8940 // Create layout with single uniform buffer descriptor
8941 VkDescriptorSetLayoutBinding dsl_binding = {};
8942 dsl_binding.binding = 0;
8943 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8944 dsl_binding.descriptorCount = 1;
8945 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8946 dsl_binding.pImmutableSamplers = NULL;
8947
8948 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8949 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8950 ds_layout_ci.pNext = NULL;
8951 ds_layout_ci.bindingCount = 1;
8952 ds_layout_ci.pBindings = &dsl_binding;
8953 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008955 ASSERT_VK_SUCCESS(err);
8956
8957 VkDescriptorSet descriptor_set = {};
8958 VkDescriptorSetAllocateInfo alloc_info = {};
8959 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8960 alloc_info.descriptorSetCount = 1;
8961 alloc_info.descriptorPool = ds_pool;
8962 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008963 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008964 ASSERT_VK_SUCCESS(err);
8965
8966 // Create a buffer to be used for invalid updates
8967 VkBufferCreateInfo buff_ci = {};
8968 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8969 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8970 buff_ci.size = 256;
8971 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8972 VkBuffer buffer;
8973 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8974 ASSERT_VK_SUCCESS(err);
8975 // Have to bind memory to buffer before descriptor update
8976 VkMemoryAllocateInfo mem_alloc = {};
8977 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8978 mem_alloc.pNext = NULL;
8979 mem_alloc.allocationSize = 256;
8980 mem_alloc.memoryTypeIndex = 0;
8981
8982 VkMemoryRequirements mem_reqs;
8983 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008984 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008985 if (!pass) {
8986 vkDestroyBuffer(m_device->device(), buffer, NULL);
8987 return;
8988 }
8989
8990 VkDeviceMemory mem;
8991 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8992 ASSERT_VK_SUCCESS(err);
8993 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8994 ASSERT_VK_SUCCESS(err);
8995
8996 VkDescriptorBufferInfo buff_info = {};
8997 buff_info.buffer = buffer;
8998 // First make offset 1 larger than buffer size
8999 buff_info.offset = 257;
9000 buff_info.range = VK_WHOLE_SIZE;
9001 VkWriteDescriptorSet descriptor_write = {};
9002 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9003 descriptor_write.dstBinding = 0;
9004 descriptor_write.descriptorCount = 1;
9005 descriptor_write.pTexelBufferView = nullptr;
9006 descriptor_write.pBufferInfo = &buff_info;
9007 descriptor_write.pImageInfo = nullptr;
9008
9009 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9010 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009012
9013 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9014
9015 m_errorMonitor->VerifyFound();
9016 // Now cause error due to range of 0
9017 buff_info.offset = 0;
9018 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009020
9021 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9022
9023 m_errorMonitor->VerifyFound();
9024 // Now cause error due to range exceeding buffer size - offset
9025 buff_info.offset = 128;
9026 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009028
9029 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9030
9031 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009032 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9034 vkDestroyBuffer(m_device->device(), buffer, NULL);
9035 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9036 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9037}
9038
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009039TEST_F(VkLayerTest, DSAspectBitsErrors) {
9040 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9041 // are set, but could expand this test to hit more cases.
9042 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9043 "that do not have correct aspect bits sets.");
9044 VkResult err;
9045
9046 ASSERT_NO_FATAL_FAILURE(InitState());
9047 VkDescriptorPoolSize ds_type_count = {};
9048 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9049 ds_type_count.descriptorCount = 1;
9050
9051 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9052 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9053 ds_pool_ci.pNext = NULL;
9054 ds_pool_ci.maxSets = 5;
9055 ds_pool_ci.poolSizeCount = 1;
9056 ds_pool_ci.pPoolSizes = &ds_type_count;
9057
9058 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009059 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009060 ASSERT_VK_SUCCESS(err);
9061
9062 VkDescriptorSetLayoutBinding dsl_binding = {};
9063 dsl_binding.binding = 0;
9064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9065 dsl_binding.descriptorCount = 1;
9066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9067 dsl_binding.pImmutableSamplers = NULL;
9068
9069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9071 ds_layout_ci.pNext = NULL;
9072 ds_layout_ci.bindingCount = 1;
9073 ds_layout_ci.pBindings = &dsl_binding;
9074 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009076 ASSERT_VK_SUCCESS(err);
9077
9078 VkDescriptorSet descriptor_set = {};
9079 VkDescriptorSetAllocateInfo alloc_info = {};
9080 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9081 alloc_info.descriptorSetCount = 1;
9082 alloc_info.descriptorPool = ds_pool;
9083 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009085 ASSERT_VK_SUCCESS(err);
9086
9087 // Create an image to be used for invalid updates
9088 VkImageCreateInfo image_ci = {};
9089 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9090 image_ci.imageType = VK_IMAGE_TYPE_2D;
9091 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9092 image_ci.extent.width = 64;
9093 image_ci.extent.height = 64;
9094 image_ci.extent.depth = 1;
9095 image_ci.mipLevels = 1;
9096 image_ci.arrayLayers = 1;
9097 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9098 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9099 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9100 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9101 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9102 VkImage image;
9103 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9104 ASSERT_VK_SUCCESS(err);
9105 // Bind memory to image
9106 VkMemoryRequirements mem_reqs;
9107 VkDeviceMemory image_mem;
9108 bool pass;
9109 VkMemoryAllocateInfo mem_alloc = {};
9110 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9111 mem_alloc.pNext = NULL;
9112 mem_alloc.allocationSize = 0;
9113 mem_alloc.memoryTypeIndex = 0;
9114 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9115 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009116 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009117 ASSERT_TRUE(pass);
9118 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9119 ASSERT_VK_SUCCESS(err);
9120 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9121 ASSERT_VK_SUCCESS(err);
9122 // Now create view for image
9123 VkImageViewCreateInfo image_view_ci = {};
9124 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9125 image_view_ci.image = image;
9126 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9127 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9128 image_view_ci.subresourceRange.layerCount = 1;
9129 image_view_ci.subresourceRange.baseArrayLayer = 0;
9130 image_view_ci.subresourceRange.levelCount = 1;
9131 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009132 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009133
9134 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009135 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009136 ASSERT_VK_SUCCESS(err);
9137
9138 VkDescriptorImageInfo img_info = {};
9139 img_info.imageView = image_view;
9140 VkWriteDescriptorSet descriptor_write = {};
9141 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9142 descriptor_write.dstBinding = 0;
9143 descriptor_write.descriptorCount = 1;
9144 descriptor_write.pTexelBufferView = NULL;
9145 descriptor_write.pBufferInfo = NULL;
9146 descriptor_write.pImageInfo = &img_info;
9147 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9148 descriptor_write.dstSet = descriptor_set;
9149 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9150 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009152
9153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9154
9155 m_errorMonitor->VerifyFound();
9156 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9157 vkDestroyImage(m_device->device(), image, NULL);
9158 vkFreeMemory(m_device->device(), image_mem, NULL);
9159 vkDestroyImageView(m_device->device(), image_view, NULL);
9160 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9162}
9163
Karl Schultz6addd812016-02-02 17:17:23 -07009164TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009165 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009166 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009167
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9169 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9170 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009171
Tobin Ehlis3b780662015-05-28 12:11:26 -06009172 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009173 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009174 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9176 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009177
9178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9180 ds_pool_ci.pNext = NULL;
9181 ds_pool_ci.maxSets = 1;
9182 ds_pool_ci.poolSizeCount = 1;
9183 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009184
Tobin Ehlis3b780662015-05-28 12:11:26 -06009185 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009186 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009187 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009188 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009189 dsl_binding.binding = 0;
9190 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9191 dsl_binding.descriptorCount = 1;
9192 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9193 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009194
Tony Barboureb254902015-07-15 12:50:33 -06009195 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009196 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9197 ds_layout_ci.pNext = NULL;
9198 ds_layout_ci.bindingCount = 1;
9199 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009200
Tobin Ehlis3b780662015-05-28 12:11:26 -06009201 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009202 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009203 ASSERT_VK_SUCCESS(err);
9204
9205 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009206 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009207 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009208 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009209 alloc_info.descriptorPool = ds_pool;
9210 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009211 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009212 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009213
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009214 VkSamplerCreateInfo sampler_ci = {};
9215 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9216 sampler_ci.pNext = NULL;
9217 sampler_ci.magFilter = VK_FILTER_NEAREST;
9218 sampler_ci.minFilter = VK_FILTER_NEAREST;
9219 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9220 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9221 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9222 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9223 sampler_ci.mipLodBias = 1.0;
9224 sampler_ci.anisotropyEnable = VK_FALSE;
9225 sampler_ci.maxAnisotropy = 1;
9226 sampler_ci.compareEnable = VK_FALSE;
9227 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9228 sampler_ci.minLod = 1.0;
9229 sampler_ci.maxLod = 1.0;
9230 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9231 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9232 VkSampler sampler;
9233 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9234 ASSERT_VK_SUCCESS(err);
9235
9236 VkDescriptorImageInfo info = {};
9237 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009238
9239 VkWriteDescriptorSet descriptor_write;
9240 memset(&descriptor_write, 0, sizeof(descriptor_write));
9241 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009242 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009243 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009244 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009245 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009246 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009247
9248 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9249
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009250 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009251
Chia-I Wuf7458c52015-10-26 21:10:41 +08009252 vkDestroySampler(m_device->device(), sampler, NULL);
9253 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9254 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009255}
9256
Karl Schultz6addd812016-02-02 17:17:23 -07009257TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009258 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009259 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009260
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009262
Tobin Ehlis3b780662015-05-28 12:11:26 -06009263 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009264 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009265 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009266 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9267 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009268
9269 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009270 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9271 ds_pool_ci.pNext = NULL;
9272 ds_pool_ci.maxSets = 1;
9273 ds_pool_ci.poolSizeCount = 1;
9274 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009275
Tobin Ehlis3b780662015-05-28 12:11:26 -06009276 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009277 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009278 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009279
Tony Barboureb254902015-07-15 12:50:33 -06009280 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009281 dsl_binding.binding = 0;
9282 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9283 dsl_binding.descriptorCount = 1;
9284 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9285 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009286
9287 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009288 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9289 ds_layout_ci.pNext = NULL;
9290 ds_layout_ci.bindingCount = 1;
9291 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009292
Tobin Ehlis3b780662015-05-28 12:11:26 -06009293 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009294 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009295 ASSERT_VK_SUCCESS(err);
9296
9297 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009298 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009299 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009300 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009301 alloc_info.descriptorPool = ds_pool;
9302 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009303 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009304 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009305
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009306 // Correctly update descriptor to avoid "NOT_UPDATED" error
9307 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009308 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009309 buff_info.offset = 0;
9310 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009311
9312 VkWriteDescriptorSet descriptor_write;
9313 memset(&descriptor_write, 0, sizeof(descriptor_write));
9314 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009315 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009316 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009317 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009318 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9319 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009320
9321 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9322
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009323 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009324
Chia-I Wuf7458c52015-10-26 21:10:41 +08009325 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9326 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009327}
9328
Karl Schultz6addd812016-02-02 17:17:23 -07009329TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009330 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009331 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009332
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009334
Tobin Ehlis3b780662015-05-28 12:11:26 -06009335 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009336 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009337 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009338 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9339 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009340
9341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9343 ds_pool_ci.pNext = NULL;
9344 ds_pool_ci.maxSets = 1;
9345 ds_pool_ci.poolSizeCount = 1;
9346 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009347
Tobin Ehlis3b780662015-05-28 12:11:26 -06009348 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009349 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009350 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009351
Tony Barboureb254902015-07-15 12:50:33 -06009352 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009353 dsl_binding.binding = 0;
9354 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9355 dsl_binding.descriptorCount = 1;
9356 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9357 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009358
9359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9361 ds_layout_ci.pNext = NULL;
9362 ds_layout_ci.bindingCount = 1;
9363 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009364 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009365 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009366 ASSERT_VK_SUCCESS(err);
9367
9368 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009369 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009370 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009371 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009372 alloc_info.descriptorPool = ds_pool;
9373 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009374 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009375 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009376
Tony Barboureb254902015-07-15 12:50:33 -06009377 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009378 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9379 sampler_ci.pNext = NULL;
9380 sampler_ci.magFilter = VK_FILTER_NEAREST;
9381 sampler_ci.minFilter = VK_FILTER_NEAREST;
9382 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9383 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9384 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9385 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9386 sampler_ci.mipLodBias = 1.0;
9387 sampler_ci.anisotropyEnable = VK_FALSE;
9388 sampler_ci.maxAnisotropy = 1;
9389 sampler_ci.compareEnable = VK_FALSE;
9390 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9391 sampler_ci.minLod = 1.0;
9392 sampler_ci.maxLod = 1.0;
9393 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9394 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009395
Tobin Ehlis3b780662015-05-28 12:11:26 -06009396 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009397 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009398 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009399
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009400 VkDescriptorImageInfo info = {};
9401 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009402
9403 VkWriteDescriptorSet descriptor_write;
9404 memset(&descriptor_write, 0, sizeof(descriptor_write));
9405 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009406 descriptor_write.dstSet = descriptorSet;
9407 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009408 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009409 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009410 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009411 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009412
9413 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9414
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009415 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009416
Chia-I Wuf7458c52015-10-26 21:10:41 +08009417 vkDestroySampler(m_device->device(), sampler, NULL);
9418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9419 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009420}
9421
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009422TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9423 // Create layout w/ empty binding and attempt to update it
9424 VkResult err;
9425
9426 ASSERT_NO_FATAL_FAILURE(InitState());
9427
9428 VkDescriptorPoolSize ds_type_count = {};
9429 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9430 ds_type_count.descriptorCount = 1;
9431
9432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9434 ds_pool_ci.pNext = NULL;
9435 ds_pool_ci.maxSets = 1;
9436 ds_pool_ci.poolSizeCount = 1;
9437 ds_pool_ci.pPoolSizes = &ds_type_count;
9438
9439 VkDescriptorPool ds_pool;
9440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9441 ASSERT_VK_SUCCESS(err);
9442
9443 VkDescriptorSetLayoutBinding dsl_binding = {};
9444 dsl_binding.binding = 0;
9445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9446 dsl_binding.descriptorCount = 0;
9447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9448 dsl_binding.pImmutableSamplers = NULL;
9449
9450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9452 ds_layout_ci.pNext = NULL;
9453 ds_layout_ci.bindingCount = 1;
9454 ds_layout_ci.pBindings = &dsl_binding;
9455 VkDescriptorSetLayout ds_layout;
9456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9457 ASSERT_VK_SUCCESS(err);
9458
9459 VkDescriptorSet descriptor_set;
9460 VkDescriptorSetAllocateInfo alloc_info = {};
9461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9462 alloc_info.descriptorSetCount = 1;
9463 alloc_info.descriptorPool = ds_pool;
9464 alloc_info.pSetLayouts = &ds_layout;
9465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9466 ASSERT_VK_SUCCESS(err);
9467
9468 VkSamplerCreateInfo sampler_ci = {};
9469 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9470 sampler_ci.magFilter = VK_FILTER_NEAREST;
9471 sampler_ci.minFilter = VK_FILTER_NEAREST;
9472 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9473 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9474 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9475 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9476 sampler_ci.mipLodBias = 1.0;
9477 sampler_ci.maxAnisotropy = 1;
9478 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9479 sampler_ci.minLod = 1.0;
9480 sampler_ci.maxLod = 1.0;
9481 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9482
9483 VkSampler sampler;
9484 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9485 ASSERT_VK_SUCCESS(err);
9486
9487 VkDescriptorImageInfo info = {};
9488 info.sampler = sampler;
9489
9490 VkWriteDescriptorSet descriptor_write;
9491 memset(&descriptor_write, 0, sizeof(descriptor_write));
9492 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9493 descriptor_write.dstSet = descriptor_set;
9494 descriptor_write.dstBinding = 0;
9495 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9496 // This is the wrong type, but empty binding error will be flagged first
9497 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9498 descriptor_write.pImageInfo = &info;
9499
9500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9501 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9502 m_errorMonitor->VerifyFound();
9503
9504 vkDestroySampler(m_device->device(), sampler, NULL);
9505 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9506 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9507}
9508
Karl Schultz6addd812016-02-02 17:17:23 -07009509TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9510 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9511 // types
9512 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009514 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 -06009515
Tobin Ehlis3b780662015-05-28 12:11:26 -06009516 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009517
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009518 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009519 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9520 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009521
9522 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009523 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9524 ds_pool_ci.pNext = NULL;
9525 ds_pool_ci.maxSets = 1;
9526 ds_pool_ci.poolSizeCount = 1;
9527 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009528
Tobin Ehlis3b780662015-05-28 12:11:26 -06009529 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009531 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009532 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009533 dsl_binding.binding = 0;
9534 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9535 dsl_binding.descriptorCount = 1;
9536 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9537 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009538
Tony Barboureb254902015-07-15 12:50:33 -06009539 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009540 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9541 ds_layout_ci.pNext = NULL;
9542 ds_layout_ci.bindingCount = 1;
9543 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009544
Tobin Ehlis3b780662015-05-28 12:11:26 -06009545 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009547 ASSERT_VK_SUCCESS(err);
9548
9549 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009550 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009551 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009552 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009553 alloc_info.descriptorPool = ds_pool;
9554 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009555 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009556 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009557
Tony Barboureb254902015-07-15 12:50:33 -06009558 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009559 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9560 sampler_ci.pNext = NULL;
9561 sampler_ci.magFilter = VK_FILTER_NEAREST;
9562 sampler_ci.minFilter = VK_FILTER_NEAREST;
9563 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9564 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9565 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9566 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9567 sampler_ci.mipLodBias = 1.0;
9568 sampler_ci.anisotropyEnable = VK_FALSE;
9569 sampler_ci.maxAnisotropy = 1;
9570 sampler_ci.compareEnable = VK_FALSE;
9571 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9572 sampler_ci.minLod = 1.0;
9573 sampler_ci.maxLod = 1.0;
9574 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9575 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009576 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009577 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009578 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009579
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009580 VkDescriptorImageInfo info = {};
9581 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009582
9583 VkWriteDescriptorSet descriptor_write;
9584 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009586 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009587 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009588 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009589 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009590 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009591
9592 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9593
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009594 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009595
Chia-I Wuf7458c52015-10-26 21:10:41 +08009596 vkDestroySampler(m_device->device(), sampler, NULL);
9597 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9598 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009599}
9600
Karl Schultz6addd812016-02-02 17:17:23 -07009601TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009602 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009603 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009604
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009606
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009607 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009608 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9609 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009610 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009611 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9612 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009613
9614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9616 ds_pool_ci.pNext = NULL;
9617 ds_pool_ci.maxSets = 1;
9618 ds_pool_ci.poolSizeCount = 1;
9619 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009620
9621 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009623 ASSERT_VK_SUCCESS(err);
9624
9625 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009626 dsl_binding.binding = 0;
9627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9628 dsl_binding.descriptorCount = 1;
9629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9630 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009631
9632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9634 ds_layout_ci.pNext = NULL;
9635 ds_layout_ci.bindingCount = 1;
9636 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009637 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009639 ASSERT_VK_SUCCESS(err);
9640
9641 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009642 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009643 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009644 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009645 alloc_info.descriptorPool = ds_pool;
9646 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009648 ASSERT_VK_SUCCESS(err);
9649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009651
9652 VkDescriptorImageInfo descriptor_info;
9653 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9654 descriptor_info.sampler = sampler;
9655
9656 VkWriteDescriptorSet descriptor_write;
9657 memset(&descriptor_write, 0, sizeof(descriptor_write));
9658 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009659 descriptor_write.dstSet = descriptorSet;
9660 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009661 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009662 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9663 descriptor_write.pImageInfo = &descriptor_info;
9664
9665 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9666
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009667 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009668
Chia-I Wuf7458c52015-10-26 21:10:41 +08009669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009671}
9672
Karl Schultz6addd812016-02-02 17:17:23 -07009673TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9674 // Create a single combined Image/Sampler descriptor and send it an invalid
9675 // imageView
9676 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009677
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009679
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009680 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009681 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009682 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9683 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009684
9685 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009686 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9687 ds_pool_ci.pNext = NULL;
9688 ds_pool_ci.maxSets = 1;
9689 ds_pool_ci.poolSizeCount = 1;
9690 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009691
9692 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009693 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009694 ASSERT_VK_SUCCESS(err);
9695
9696 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009697 dsl_binding.binding = 0;
9698 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9699 dsl_binding.descriptorCount = 1;
9700 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9701 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009702
9703 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009704 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9705 ds_layout_ci.pNext = NULL;
9706 ds_layout_ci.bindingCount = 1;
9707 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009708 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009710 ASSERT_VK_SUCCESS(err);
9711
9712 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009713 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009714 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009715 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009716 alloc_info.descriptorPool = ds_pool;
9717 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009718 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009719 ASSERT_VK_SUCCESS(err);
9720
9721 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009722 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9723 sampler_ci.pNext = NULL;
9724 sampler_ci.magFilter = VK_FILTER_NEAREST;
9725 sampler_ci.minFilter = VK_FILTER_NEAREST;
9726 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9727 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9728 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9729 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9730 sampler_ci.mipLodBias = 1.0;
9731 sampler_ci.anisotropyEnable = VK_FALSE;
9732 sampler_ci.maxAnisotropy = 1;
9733 sampler_ci.compareEnable = VK_FALSE;
9734 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9735 sampler_ci.minLod = 1.0;
9736 sampler_ci.maxLod = 1.0;
9737 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9738 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009739
9740 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009741 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009742 ASSERT_VK_SUCCESS(err);
9743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009745
9746 VkDescriptorImageInfo descriptor_info;
9747 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9748 descriptor_info.sampler = sampler;
9749 descriptor_info.imageView = view;
9750
9751 VkWriteDescriptorSet descriptor_write;
9752 memset(&descriptor_write, 0, sizeof(descriptor_write));
9753 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009754 descriptor_write.dstSet = descriptorSet;
9755 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009756 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009757 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9758 descriptor_write.pImageInfo = &descriptor_info;
9759
9760 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9761
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009762 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009763
Chia-I Wuf7458c52015-10-26 21:10:41 +08009764 vkDestroySampler(m_device->device(), sampler, NULL);
9765 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9766 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009767}
9768
Karl Schultz6addd812016-02-02 17:17:23 -07009769TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9770 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9771 // into the other
9772 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009773
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9775 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9776 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009777
Tobin Ehlis04356f92015-10-27 16:35:27 -06009778 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009779 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009780 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009781 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9782 ds_type_count[0].descriptorCount = 1;
9783 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9784 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009785
9786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9788 ds_pool_ci.pNext = NULL;
9789 ds_pool_ci.maxSets = 1;
9790 ds_pool_ci.poolSizeCount = 2;
9791 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009792
9793 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009795 ASSERT_VK_SUCCESS(err);
9796 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009797 dsl_binding[0].binding = 0;
9798 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9799 dsl_binding[0].descriptorCount = 1;
9800 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9801 dsl_binding[0].pImmutableSamplers = NULL;
9802 dsl_binding[1].binding = 1;
9803 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9804 dsl_binding[1].descriptorCount = 1;
9805 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9806 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009807
9808 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009809 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9810 ds_layout_ci.pNext = NULL;
9811 ds_layout_ci.bindingCount = 2;
9812 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009813
9814 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009816 ASSERT_VK_SUCCESS(err);
9817
9818 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009819 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009820 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009821 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009822 alloc_info.descriptorPool = ds_pool;
9823 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009824 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009825 ASSERT_VK_SUCCESS(err);
9826
9827 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009828 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9829 sampler_ci.pNext = NULL;
9830 sampler_ci.magFilter = VK_FILTER_NEAREST;
9831 sampler_ci.minFilter = VK_FILTER_NEAREST;
9832 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9833 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9834 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9835 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9836 sampler_ci.mipLodBias = 1.0;
9837 sampler_ci.anisotropyEnable = VK_FALSE;
9838 sampler_ci.maxAnisotropy = 1;
9839 sampler_ci.compareEnable = VK_FALSE;
9840 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9841 sampler_ci.minLod = 1.0;
9842 sampler_ci.maxLod = 1.0;
9843 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9844 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009845
9846 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009847 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009848 ASSERT_VK_SUCCESS(err);
9849
9850 VkDescriptorImageInfo info = {};
9851 info.sampler = sampler;
9852
9853 VkWriteDescriptorSet descriptor_write;
9854 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9855 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009856 descriptor_write.dstSet = descriptorSet;
9857 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009858 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009859 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9860 descriptor_write.pImageInfo = &info;
9861 // This write update should succeed
9862 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9863 // Now perform a copy update that fails due to type mismatch
9864 VkCopyDescriptorSet copy_ds_update;
9865 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9866 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9867 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009868 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009869 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009870 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009871 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009872 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9873
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009874 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009875 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009876 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 -06009877 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9878 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9879 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009880 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009881 copy_ds_update.dstSet = descriptorSet;
9882 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009883 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009884 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9885
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009886 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009887
Tobin Ehlis04356f92015-10-27 16:35:27 -06009888 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9890 "update array offset of 0 and update of "
9891 "5 descriptors oversteps total number "
9892 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009893
Tobin Ehlis04356f92015-10-27 16:35:27 -06009894 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9895 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9896 copy_ds_update.srcSet = descriptorSet;
9897 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009898 copy_ds_update.dstSet = descriptorSet;
9899 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009901 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9902
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009903 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009904
Chia-I Wuf7458c52015-10-26 21:10:41 +08009905 vkDestroySampler(m_device->device(), sampler, NULL);
9906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009908}
9909
Karl Schultz6addd812016-02-02 17:17:23 -07009910TEST_F(VkLayerTest, NumSamplesMismatch) {
9911 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9912 // sampleCount
9913 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009916
Tobin Ehlis3b780662015-05-28 12:11:26 -06009917 ASSERT_NO_FATAL_FAILURE(InitState());
9918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009919 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009920 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009921 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009922
9923 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009924 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9925 ds_pool_ci.pNext = NULL;
9926 ds_pool_ci.maxSets = 1;
9927 ds_pool_ci.poolSizeCount = 1;
9928 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009929
Tobin Ehlis3b780662015-05-28 12:11:26 -06009930 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009932 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009933
Tony Barboureb254902015-07-15 12:50:33 -06009934 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009935 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009936 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009937 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009938 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9939 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009940
Tony Barboureb254902015-07-15 12:50:33 -06009941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9943 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009944 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009945 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009946
Tobin Ehlis3b780662015-05-28 12:11:26 -06009947 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009949 ASSERT_VK_SUCCESS(err);
9950
9951 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009952 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009953 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009954 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009955 alloc_info.descriptorPool = ds_pool;
9956 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009958 ASSERT_VK_SUCCESS(err);
9959
Tony Barboureb254902015-07-15 12:50:33 -06009960 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009961 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009962 pipe_ms_state_ci.pNext = NULL;
9963 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9964 pipe_ms_state_ci.sampleShadingEnable = 0;
9965 pipe_ms_state_ci.minSampleShading = 1.0;
9966 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009967
Tony Barboureb254902015-07-15 12:50:33 -06009968 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009969 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9970 pipeline_layout_ci.pNext = NULL;
9971 pipeline_layout_ci.setLayoutCount = 1;
9972 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009973
9974 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009976 ASSERT_VK_SUCCESS(err);
9977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009978 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9979 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9980 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009981 VkPipelineObj pipe(m_device);
9982 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009983 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009984 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009985 pipe.SetMSAA(&pipe_ms_state_ci);
9986 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009987
Tony Barbour552f6c02016-12-21 14:34:07 -07009988 m_commandBuffer->BeginCommandBuffer();
9989 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009990 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009991
Rene Lindsay3bdc7a42017-01-06 13:20:15 -07009992 VkViewport viewport = {0, 0, 16, 16, 0, 1};
9993 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
9994 VkRect2D scissor = {{0, 0}, {16, 16}};
9995 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
9996
Mark Young29927482016-05-04 14:38:51 -06009997 // Render triangle (the error should trigger on the attempt to draw).
9998 Draw(3, 1, 0, 0);
9999
10000 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010001 m_commandBuffer->EndRenderPass();
10002 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010003
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010004 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010005
Chia-I Wuf7458c52015-10-26 21:10:41 +080010006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10008 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010009}
Mark Young29927482016-05-04 14:38:51 -060010010
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010011TEST_F(VkLayerTest, RenderPassIncompatible) {
10012 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
10013 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -060010014 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010015 VkResult err;
10016
10017 ASSERT_NO_FATAL_FAILURE(InitState());
10018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10019
10020 VkDescriptorSetLayoutBinding dsl_binding = {};
10021 dsl_binding.binding = 0;
10022 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10023 dsl_binding.descriptorCount = 1;
10024 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10025 dsl_binding.pImmutableSamplers = NULL;
10026
10027 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10028 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10029 ds_layout_ci.pNext = NULL;
10030 ds_layout_ci.bindingCount = 1;
10031 ds_layout_ci.pBindings = &dsl_binding;
10032
10033 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010034 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010035 ASSERT_VK_SUCCESS(err);
10036
10037 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10038 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10039 pipeline_layout_ci.pNext = NULL;
10040 pipeline_layout_ci.setLayoutCount = 1;
10041 pipeline_layout_ci.pSetLayouts = &ds_layout;
10042
10043 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010045 ASSERT_VK_SUCCESS(err);
10046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010047 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10048 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10049 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010050 // Create a renderpass that will be incompatible with default renderpass
10051 VkAttachmentReference attach = {};
10052 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10053 VkAttachmentReference color_att = {};
10054 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10055 VkSubpassDescription subpass = {};
10056 subpass.inputAttachmentCount = 1;
10057 subpass.pInputAttachments = &attach;
10058 subpass.colorAttachmentCount = 1;
10059 subpass.pColorAttachments = &color_att;
10060 VkRenderPassCreateInfo rpci = {};
10061 rpci.subpassCount = 1;
10062 rpci.pSubpasses = &subpass;
10063 rpci.attachmentCount = 1;
10064 VkAttachmentDescription attach_desc = {};
10065 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010066 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10067 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010068 rpci.pAttachments = &attach_desc;
10069 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10070 VkRenderPass rp;
10071 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10072 VkPipelineObj pipe(m_device);
10073 pipe.AddShader(&vs);
10074 pipe.AddShader(&fs);
10075 pipe.AddColorAttachment();
10076 VkViewport view_port = {};
10077 m_viewports.push_back(view_port);
10078 pipe.SetViewport(m_viewports);
10079 VkRect2D rect = {};
10080 m_scissors.push_back(rect);
10081 pipe.SetScissor(m_scissors);
10082 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10083
10084 VkCommandBufferInheritanceInfo cbii = {};
10085 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10086 cbii.renderPass = rp;
10087 cbii.subpass = 0;
10088 VkCommandBufferBeginInfo cbbi = {};
10089 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10090 cbbi.pInheritanceInfo = &cbii;
10091 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10092 VkRenderPassBeginInfo rpbi = {};
10093 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10094 rpbi.framebuffer = m_framebuffer;
10095 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010096 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10097 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010100 // Render triangle (the error should trigger on the attempt to draw).
10101 Draw(3, 1, 0, 0);
10102
10103 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010104 m_commandBuffer->EndRenderPass();
10105 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010106
10107 m_errorMonitor->VerifyFound();
10108
10109 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10111 vkDestroyRenderPass(m_device->device(), rp, NULL);
10112}
10113
Mark Youngc89c6312016-03-31 16:03:20 -060010114TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10115 // Create Pipeline where the number of blend attachments doesn't match the
10116 // number of color attachments. In this case, we don't add any color
10117 // blend attachments even though we have a color attachment.
10118 VkResult err;
10119
10120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010121 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010122
10123 ASSERT_NO_FATAL_FAILURE(InitState());
10124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10125 VkDescriptorPoolSize ds_type_count = {};
10126 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10127 ds_type_count.descriptorCount = 1;
10128
10129 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10130 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10131 ds_pool_ci.pNext = NULL;
10132 ds_pool_ci.maxSets = 1;
10133 ds_pool_ci.poolSizeCount = 1;
10134 ds_pool_ci.pPoolSizes = &ds_type_count;
10135
10136 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010138 ASSERT_VK_SUCCESS(err);
10139
10140 VkDescriptorSetLayoutBinding dsl_binding = {};
10141 dsl_binding.binding = 0;
10142 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10143 dsl_binding.descriptorCount = 1;
10144 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10145 dsl_binding.pImmutableSamplers = NULL;
10146
10147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10149 ds_layout_ci.pNext = NULL;
10150 ds_layout_ci.bindingCount = 1;
10151 ds_layout_ci.pBindings = &dsl_binding;
10152
10153 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010155 ASSERT_VK_SUCCESS(err);
10156
10157 VkDescriptorSet descriptorSet;
10158 VkDescriptorSetAllocateInfo alloc_info = {};
10159 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10160 alloc_info.descriptorSetCount = 1;
10161 alloc_info.descriptorPool = ds_pool;
10162 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010163 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010164 ASSERT_VK_SUCCESS(err);
10165
10166 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010168 pipe_ms_state_ci.pNext = NULL;
10169 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10170 pipe_ms_state_ci.sampleShadingEnable = 0;
10171 pipe_ms_state_ci.minSampleShading = 1.0;
10172 pipe_ms_state_ci.pSampleMask = NULL;
10173
10174 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10175 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10176 pipeline_layout_ci.pNext = NULL;
10177 pipeline_layout_ci.setLayoutCount = 1;
10178 pipeline_layout_ci.pSetLayouts = &ds_layout;
10179
10180 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010182 ASSERT_VK_SUCCESS(err);
10183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010184 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10185 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10186 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010187 VkPipelineObj pipe(m_device);
10188 pipe.AddShader(&vs);
10189 pipe.AddShader(&fs);
10190 pipe.SetMSAA(&pipe_ms_state_ci);
10191 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10192
Tony Barbour552f6c02016-12-21 14:34:07 -070010193 m_commandBuffer->BeginCommandBuffer();
10194 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010196
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010197 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10198 VkRect2D scissor = {{0, 0}, {16, 16}};
10199 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10200 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10201
Mark Young29927482016-05-04 14:38:51 -060010202 // Render triangle (the error should trigger on the attempt to draw).
10203 Draw(3, 1, 0, 0);
10204
10205 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010206 m_commandBuffer->EndRenderPass();
10207 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010208
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010209 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010210
10211 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10212 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10213 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10214}
Mark Young29927482016-05-04 14:38:51 -060010215
Mark Muellerd4914412016-06-13 17:52:06 -060010216TEST_F(VkLayerTest, MissingClearAttachment) {
10217 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10218 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010219 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010221
10222 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10223 m_errorMonitor->VerifyFound();
10224}
10225
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010226TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010227
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010228 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10229 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010230
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010231 ASSERT_NO_FATAL_FAILURE(InitState());
10232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010233
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010234 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010235 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10236 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010237
10238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10240 ds_pool_ci.pNext = NULL;
10241 ds_pool_ci.maxSets = 1;
10242 ds_pool_ci.poolSizeCount = 1;
10243 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010244
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010245 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010247 ASSERT_VK_SUCCESS(err);
10248
Tony Barboureb254902015-07-15 12:50:33 -060010249 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010250 dsl_binding.binding = 0;
10251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10252 dsl_binding.descriptorCount = 1;
10253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10254 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010255
Tony Barboureb254902015-07-15 12:50:33 -060010256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10258 ds_layout_ci.pNext = NULL;
10259 ds_layout_ci.bindingCount = 1;
10260 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010261
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010262 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010264 ASSERT_VK_SUCCESS(err);
10265
10266 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010267 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010268 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010269 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010270 alloc_info.descriptorPool = ds_pool;
10271 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010273 ASSERT_VK_SUCCESS(err);
10274
Tony Barboureb254902015-07-15 12:50:33 -060010275 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010276 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010277 pipe_ms_state_ci.pNext = NULL;
10278 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10279 pipe_ms_state_ci.sampleShadingEnable = 0;
10280 pipe_ms_state_ci.minSampleShading = 1.0;
10281 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010282
Tony Barboureb254902015-07-15 12:50:33 -060010283 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010284 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10285 pipeline_layout_ci.pNext = NULL;
10286 pipeline_layout_ci.setLayoutCount = 1;
10287 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010288
10289 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010290 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010291 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010293 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010294 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010295 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010296 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010297
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010298 VkPipelineObj pipe(m_device);
10299 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010300 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010301 pipe.SetMSAA(&pipe_ms_state_ci);
10302 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010303
Tony Barbour552f6c02016-12-21 14:34:07 -070010304 m_commandBuffer->BeginCommandBuffer();
10305 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010306
Karl Schultz6addd812016-02-02 17:17:23 -070010307 // Main thing we care about for this test is that the VkImage obj we're
10308 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010309 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010310 VkClearAttachment color_attachment;
10311 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10312 color_attachment.clearValue.color.float32[0] = 1.0;
10313 color_attachment.clearValue.color.float32[1] = 1.0;
10314 color_attachment.clearValue.color.float32[2] = 1.0;
10315 color_attachment.clearValue.color.float32[3] = 1.0;
10316 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010317 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010318
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010319 // Call for full-sized FB Color attachment prior to issuing a Draw
10320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10321 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010323 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010324
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010325
10326 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10327 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10329 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10330 m_errorMonitor->VerifyFound();
10331
10332 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10333 clear_rect.layerCount = 2;
10334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10335 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010336 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010337
Chia-I Wuf7458c52015-10-26 21:10:41 +080010338 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10339 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10340 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010341}
10342
Karl Schultz6addd812016-02-02 17:17:23 -070010343TEST_F(VkLayerTest, VtxBufferBadIndex) {
10344 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10347 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010348
Tobin Ehlis502480b2015-06-24 15:53:07 -060010349 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010350 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010352
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010353 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010354 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10355 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010356
10357 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010358 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10359 ds_pool_ci.pNext = NULL;
10360 ds_pool_ci.maxSets = 1;
10361 ds_pool_ci.poolSizeCount = 1;
10362 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010363
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010364 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010365 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010366 ASSERT_VK_SUCCESS(err);
10367
Tony Barboureb254902015-07-15 12:50:33 -060010368 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010369 dsl_binding.binding = 0;
10370 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10371 dsl_binding.descriptorCount = 1;
10372 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10373 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010374
Tony Barboureb254902015-07-15 12:50:33 -060010375 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010376 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10377 ds_layout_ci.pNext = NULL;
10378 ds_layout_ci.bindingCount = 1;
10379 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010380
Tobin Ehlis502480b2015-06-24 15:53:07 -060010381 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010382 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010383 ASSERT_VK_SUCCESS(err);
10384
10385 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010386 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010387 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010388 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010389 alloc_info.descriptorPool = ds_pool;
10390 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010391 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010392 ASSERT_VK_SUCCESS(err);
10393
Tony Barboureb254902015-07-15 12:50:33 -060010394 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010395 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010396 pipe_ms_state_ci.pNext = NULL;
10397 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10398 pipe_ms_state_ci.sampleShadingEnable = 0;
10399 pipe_ms_state_ci.minSampleShading = 1.0;
10400 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010401
Tony Barboureb254902015-07-15 12:50:33 -060010402 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010403 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10404 pipeline_layout_ci.pNext = NULL;
10405 pipeline_layout_ci.setLayoutCount = 1;
10406 pipeline_layout_ci.pSetLayouts = &ds_layout;
10407 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010410 ASSERT_VK_SUCCESS(err);
10411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10413 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10414 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010415 VkPipelineObj pipe(m_device);
10416 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010417 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010418 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010419 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010420 pipe.SetViewport(m_viewports);
10421 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010422 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010423
Tony Barbour552f6c02016-12-21 14:34:07 -070010424 m_commandBuffer->BeginCommandBuffer();
10425 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010426 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010427 // Don't care about actual data, just need to get to draw to flag error
10428 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010429 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010430 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010431 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010432
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010433 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010434
Chia-I Wuf7458c52015-10-26 21:10:41 +080010435 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10436 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10437 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010438}
Mark Muellerdfe37552016-07-07 14:47:42 -060010439
Mark Mueller2ee294f2016-08-04 12:59:48 -060010440TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10441 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10442 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010443 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010445 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10446 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10449 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010451 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010454 // The following test fails with recent NVidia drivers.
10455 // By the time core_validation is reached, the NVidia
10456 // driver has sanitized the invalid condition and core_validation
10457 // is not introduced to the failure condition. This is not the case
10458 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 // uint32_t count = static_cast<uint32_t>(~0);
10460 // VkPhysicalDevice physical_device;
10461 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10462 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010465 float queue_priority = 0.0;
10466
10467 VkDeviceQueueCreateInfo queue_create_info = {};
10468 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10469 queue_create_info.queueCount = 1;
10470 queue_create_info.pQueuePriorities = &queue_priority;
10471 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10472
10473 VkPhysicalDeviceFeatures features = m_device->phy().features();
10474 VkDevice testDevice;
10475 VkDeviceCreateInfo device_create_info = {};
10476 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10477 device_create_info.queueCreateInfoCount = 1;
10478 device_create_info.pQueueCreateInfos = &queue_create_info;
10479 device_create_info.pEnabledFeatures = &features;
10480 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10481 m_errorMonitor->VerifyFound();
10482
10483 queue_create_info.queueFamilyIndex = 1;
10484
10485 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10486 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10487 for (unsigned i = 0; i < feature_count; i++) {
10488 if (VK_FALSE == feature_array[i]) {
10489 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010491 device_create_info.pEnabledFeatures = &features;
10492 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10493 m_errorMonitor->VerifyFound();
10494 break;
10495 }
10496 }
10497}
10498
Tobin Ehlis16edf082016-11-21 12:33:49 -070010499TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10500 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10501
10502 ASSERT_NO_FATAL_FAILURE(InitState());
10503
10504 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10505 std::vector<VkDeviceQueueCreateInfo> queue_info;
10506 queue_info.reserve(queue_props.size());
10507 std::vector<std::vector<float>> queue_priorities;
10508 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10509 VkDeviceQueueCreateInfo qi{};
10510 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10511 qi.queueFamilyIndex = i;
10512 qi.queueCount = queue_props[i].queueCount;
10513 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10514 qi.pQueuePriorities = queue_priorities[i].data();
10515 queue_info.push_back(qi);
10516 }
10517
10518 std::vector<const char *> device_extension_names;
10519
10520 VkDevice local_device;
10521 VkDeviceCreateInfo device_create_info = {};
10522 auto features = m_device->phy().features();
10523 // Intentionally disable pipeline stats
10524 features.pipelineStatisticsQuery = VK_FALSE;
10525 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10526 device_create_info.pNext = NULL;
10527 device_create_info.queueCreateInfoCount = queue_info.size();
10528 device_create_info.pQueueCreateInfos = queue_info.data();
10529 device_create_info.enabledLayerCount = 0;
10530 device_create_info.ppEnabledLayerNames = NULL;
10531 device_create_info.pEnabledFeatures = &features;
10532 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10533 ASSERT_VK_SUCCESS(err);
10534
10535 VkQueryPoolCreateInfo qpci{};
10536 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10537 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10538 qpci.queryCount = 1;
10539 VkQueryPool query_pool;
10540
10541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10542 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10543 m_errorMonitor->VerifyFound();
10544
10545 vkDestroyDevice(local_device, nullptr);
10546}
10547
Mark Mueller2ee294f2016-08-04 12:59:48 -060010548TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10549 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10550 "End a command buffer with a query still in progress.");
10551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010552 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10553 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10554 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010559
10560 ASSERT_NO_FATAL_FAILURE(InitState());
10561
10562 VkEvent event;
10563 VkEventCreateInfo event_create_info{};
10564 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10565 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10566
Mark Mueller2ee294f2016-08-04 12:59:48 -060010567 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010568 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010569
Tony Barbour552f6c02016-12-21 14:34:07 -070010570 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010571
10572 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010573 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 -060010574 ASSERT_TRUE(image.initialized());
10575 VkImageMemoryBarrier img_barrier = {};
10576 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10577 img_barrier.pNext = NULL;
10578 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10579 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10580 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10581 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10582 img_barrier.image = image.handle();
10583 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010584
10585 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10586 // that layer validation catches the case when it is not.
10587 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010588 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10589 img_barrier.subresourceRange.baseArrayLayer = 0;
10590 img_barrier.subresourceRange.baseMipLevel = 0;
10591 img_barrier.subresourceRange.layerCount = 1;
10592 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010593 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10594 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010595 m_errorMonitor->VerifyFound();
10596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010598
10599 VkQueryPool query_pool;
10600 VkQueryPoolCreateInfo query_pool_create_info = {};
10601 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10602 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10603 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010604 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010606 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010607 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10608
10609 vkEndCommandBuffer(m_commandBuffer->handle());
10610 m_errorMonitor->VerifyFound();
10611
10612 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10613 vkDestroyEvent(m_device->device(), event, nullptr);
10614}
10615
Mark Muellerdfe37552016-07-07 14:47:42 -060010616TEST_F(VkLayerTest, VertexBufferInvalid) {
10617 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10618 "delete a buffer twice, use an invalid offset for each "
10619 "buffer type, and attempt to bind a null buffer");
10620
10621 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10622 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010623 const char *invalid_offset_message = "vkBindBufferMemory(): "
10624 "memoryOffset is 0x";
10625 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10626 "storage memoryOffset "
10627 "is 0x";
10628 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10629 "texel memoryOffset "
10630 "is 0x";
10631 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10632 "uniform memoryOffset "
10633 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010634
10635 ASSERT_NO_FATAL_FAILURE(InitState());
10636 ASSERT_NO_FATAL_FAILURE(InitViewport());
10637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10638
10639 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010641 pipe_ms_state_ci.pNext = NULL;
10642 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10643 pipe_ms_state_ci.sampleShadingEnable = 0;
10644 pipe_ms_state_ci.minSampleShading = 1.0;
10645 pipe_ms_state_ci.pSampleMask = nullptr;
10646
10647 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10648 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10649 VkPipelineLayout pipeline_layout;
10650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010651 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010652 ASSERT_VK_SUCCESS(err);
10653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10655 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010656 VkPipelineObj pipe(m_device);
10657 pipe.AddShader(&vs);
10658 pipe.AddShader(&fs);
10659 pipe.AddColorAttachment();
10660 pipe.SetMSAA(&pipe_ms_state_ci);
10661 pipe.SetViewport(m_viewports);
10662 pipe.SetScissor(m_scissors);
10663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10664
Tony Barbour552f6c02016-12-21 14:34:07 -070010665 m_commandBuffer->BeginCommandBuffer();
10666 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010668
10669 {
10670 // Create and bind a vertex buffer in a reduced scope, which will cause
10671 // it to be deleted upon leaving this scope
10672 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010673 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010674 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10675 draw_verticies.AddVertexInputToPipe(pipe);
10676 }
10677
10678 Draw(1, 0, 0, 0);
10679
Tony Barbour552f6c02016-12-21 14:34:07 -070010680 m_commandBuffer->EndRenderPass();
10681 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010684 QueueCommandBuffer(false);
10685 m_errorMonitor->VerifyFound();
10686
10687 {
10688 // Create and bind a vertex buffer in a reduced scope, and delete it
10689 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010690 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010692 buffer_test.TestDoubleDestroy();
10693 }
10694 m_errorMonitor->VerifyFound();
10695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010696 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010697 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10699 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10700 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010701 m_errorMonitor->VerifyFound();
10702 }
10703
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010704 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10705 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010706 // Create and bind a memory buffer with an invalid offset again,
10707 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10709 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10710 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010711 m_errorMonitor->VerifyFound();
10712 }
10713
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010714 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010715 // Create and bind a memory buffer with an invalid offset again, but
10716 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10718 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10719 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010720 m_errorMonitor->VerifyFound();
10721 }
10722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010723 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010724 // Create and bind a memory buffer with an invalid offset again, but
10725 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10727 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10728 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010729 m_errorMonitor->VerifyFound();
10730 }
10731
10732 {
10733 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010735 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10736 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010737 m_errorMonitor->VerifyFound();
10738 }
10739
10740 {
10741 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010743 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10744 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010745 }
10746 m_errorMonitor->VerifyFound();
10747
10748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10749}
10750
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010751// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10752TEST_F(VkLayerTest, InvalidImageLayout) {
10753 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10755 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010756 // 3 in ValidateCmdBufImageLayouts
10757 // * -1 Attempt to submit cmd buf w/ deleted image
10758 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10759 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010760
10761 ASSERT_NO_FATAL_FAILURE(InitState());
10762 // Create src & dst images to use for copy operations
10763 VkImage src_image;
10764 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010765 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010766
10767 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10768 const int32_t tex_width = 32;
10769 const int32_t tex_height = 32;
10770
10771 VkImageCreateInfo image_create_info = {};
10772 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10773 image_create_info.pNext = NULL;
10774 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10775 image_create_info.format = tex_format;
10776 image_create_info.extent.width = tex_width;
10777 image_create_info.extent.height = tex_height;
10778 image_create_info.extent.depth = 1;
10779 image_create_info.mipLevels = 1;
10780 image_create_info.arrayLayers = 4;
10781 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10782 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10783 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010784 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010785 image_create_info.flags = 0;
10786
10787 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10788 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010789 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010790 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10791 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010792 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10793 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10795 ASSERT_VK_SUCCESS(err);
10796
10797 // Allocate memory
10798 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010799 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010800 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010801 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10802 mem_alloc.pNext = NULL;
10803 mem_alloc.allocationSize = 0;
10804 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010805
10806 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010807 mem_alloc.allocationSize = img_mem_reqs.size;
10808 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010809 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010810 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010811 ASSERT_VK_SUCCESS(err);
10812
10813 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010814 mem_alloc.allocationSize = img_mem_reqs.size;
10815 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010816 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010817 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010818 ASSERT_VK_SUCCESS(err);
10819
10820 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010821 mem_alloc.allocationSize = img_mem_reqs.size;
10822 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010823 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010824 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010825 ASSERT_VK_SUCCESS(err);
10826
10827 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10828 ASSERT_VK_SUCCESS(err);
10829 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10830 ASSERT_VK_SUCCESS(err);
10831 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10832 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010833
Tony Barbour552f6c02016-12-21 14:34:07 -070010834 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010835 VkImageCopy copy_region;
10836 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10837 copy_region.srcSubresource.mipLevel = 0;
10838 copy_region.srcSubresource.baseArrayLayer = 0;
10839 copy_region.srcSubresource.layerCount = 1;
10840 copy_region.srcOffset.x = 0;
10841 copy_region.srcOffset.y = 0;
10842 copy_region.srcOffset.z = 0;
10843 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10844 copy_region.dstSubresource.mipLevel = 0;
10845 copy_region.dstSubresource.baseArrayLayer = 0;
10846 copy_region.dstSubresource.layerCount = 1;
10847 copy_region.dstOffset.x = 0;
10848 copy_region.dstOffset.y = 0;
10849 copy_region.dstOffset.z = 0;
10850 copy_region.extent.width = 1;
10851 copy_region.extent.height = 1;
10852 copy_region.extent.depth = 1;
10853
10854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10855 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10856 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010857 m_errorMonitor->VerifyFound();
10858 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10860 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10861 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010862 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010863 m_errorMonitor->VerifyFound();
10864 // Final src error is due to bad layout type
10865 m_errorMonitor->SetDesiredFailureMsg(
10866 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10867 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010868 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010869 m_errorMonitor->VerifyFound();
10870 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10872 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010873 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010874 m_errorMonitor->VerifyFound();
10875 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10877 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10878 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010879 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010880 m_errorMonitor->VerifyFound();
10881 m_errorMonitor->SetDesiredFailureMsg(
10882 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10883 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010884 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010885 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010886
Cort3b021012016-12-07 12:00:57 -080010887 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10888 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10889 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10890 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10891 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10892 transfer_dst_image_barrier[0].srcAccessMask = 0;
10893 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10894 transfer_dst_image_barrier[0].image = dst_image;
10895 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10896 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10897 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10898 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10899 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10900 transfer_dst_image_barrier[0].image = depth_image;
10901 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10902 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10903 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10904
10905 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010906 VkClearColorValue color_clear_value = {};
10907 VkImageSubresourceRange clear_range;
10908 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10909 clear_range.baseMipLevel = 0;
10910 clear_range.baseArrayLayer = 0;
10911 clear_range.layerCount = 1;
10912 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010913
Cort3b021012016-12-07 12:00:57 -080010914 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10915 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010918 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010919 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010920 // Fail due to provided layout not matching actual current layout for color clear.
10921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010922 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010923 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010924
Cort530cf382016-12-08 09:59:47 -080010925 VkClearDepthStencilValue depth_clear_value = {};
10926 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010927
10928 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10929 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010932 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010933 m_errorMonitor->VerifyFound();
10934 // Fail due to provided layout not matching actual current layout for depth clear.
10935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010936 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010937 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010938
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010939 // Now cause error due to bad image layout transition in PipelineBarrier
10940 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010941 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010942 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010943 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010944 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010945 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10946 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010947 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Alex Smithc4659e42017-01-10 09:51:22 +000010948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout of aspect 1 from "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010949 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10950 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10951 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10952 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010953 m_errorMonitor->VerifyFound();
10954
10955 // Finally some layout errors at RenderPass create time
10956 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10957 VkAttachmentReference attach = {};
10958 // perf warning for GENERAL layout w/ non-DS input attachment
10959 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10960 VkSubpassDescription subpass = {};
10961 subpass.inputAttachmentCount = 1;
10962 subpass.pInputAttachments = &attach;
10963 VkRenderPassCreateInfo rpci = {};
10964 rpci.subpassCount = 1;
10965 rpci.pSubpasses = &subpass;
10966 rpci.attachmentCount = 1;
10967 VkAttachmentDescription attach_desc = {};
10968 attach_desc.format = VK_FORMAT_UNDEFINED;
10969 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010970 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010971 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10973 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010974 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10975 m_errorMonitor->VerifyFound();
10976 // error w/ non-general layout
10977 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10978
10979 m_errorMonitor->SetDesiredFailureMsg(
10980 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10981 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10982 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10983 m_errorMonitor->VerifyFound();
10984 subpass.inputAttachmentCount = 0;
10985 subpass.colorAttachmentCount = 1;
10986 subpass.pColorAttachments = &attach;
10987 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10988 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10990 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010991 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10992 m_errorMonitor->VerifyFound();
10993 // error w/ non-color opt or GENERAL layout for color attachment
10994 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10995 m_errorMonitor->SetDesiredFailureMsg(
10996 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10997 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10998 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10999 m_errorMonitor->VerifyFound();
11000 subpass.colorAttachmentCount = 0;
11001 subpass.pDepthStencilAttachment = &attach;
11002 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11003 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11005 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011006 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11007 m_errorMonitor->VerifyFound();
11008 // error w/ non-ds opt or GENERAL layout for color attachment
11009 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11011 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11012 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011013 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11014 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011015 // For this error we need a valid renderpass so create default one
11016 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11017 attach.attachment = 0;
11018 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11019 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11020 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11021 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11022 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11023 // Can't do a CLEAR load on READ_ONLY initialLayout
11024 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11025 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11026 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
11028 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11029 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011030 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11031 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011032
Cort3b021012016-12-07 12:00:57 -080011033 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11034 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11035 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011036 vkDestroyImage(m_device->device(), src_image, NULL);
11037 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011038 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011039}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011040
Tobin Ehlise0936662016-10-11 08:10:51 -060011041TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11042 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11043 VkResult err;
11044
11045 ASSERT_NO_FATAL_FAILURE(InitState());
11046
11047 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11048 VkImageTiling tiling;
11049 VkFormatProperties format_properties;
11050 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11051 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11052 tiling = VK_IMAGE_TILING_LINEAR;
11053 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11054 tiling = VK_IMAGE_TILING_OPTIMAL;
11055 } else {
11056 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11057 "skipped.\n");
11058 return;
11059 }
11060
11061 VkDescriptorPoolSize ds_type = {};
11062 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11063 ds_type.descriptorCount = 1;
11064
11065 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11066 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11067 ds_pool_ci.maxSets = 1;
11068 ds_pool_ci.poolSizeCount = 1;
11069 ds_pool_ci.pPoolSizes = &ds_type;
11070 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11071
11072 VkDescriptorPool ds_pool;
11073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11074 ASSERT_VK_SUCCESS(err);
11075
11076 VkDescriptorSetLayoutBinding dsl_binding = {};
11077 dsl_binding.binding = 0;
11078 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11079 dsl_binding.descriptorCount = 1;
11080 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11081 dsl_binding.pImmutableSamplers = NULL;
11082
11083 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11084 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11085 ds_layout_ci.pNext = NULL;
11086 ds_layout_ci.bindingCount = 1;
11087 ds_layout_ci.pBindings = &dsl_binding;
11088
11089 VkDescriptorSetLayout ds_layout;
11090 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11091 ASSERT_VK_SUCCESS(err);
11092
11093 VkDescriptorSetAllocateInfo alloc_info = {};
11094 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11095 alloc_info.descriptorSetCount = 1;
11096 alloc_info.descriptorPool = ds_pool;
11097 alloc_info.pSetLayouts = &ds_layout;
11098 VkDescriptorSet descriptor_set;
11099 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11100 ASSERT_VK_SUCCESS(err);
11101
11102 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11103 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11104 pipeline_layout_ci.pNext = NULL;
11105 pipeline_layout_ci.setLayoutCount = 1;
11106 pipeline_layout_ci.pSetLayouts = &ds_layout;
11107 VkPipelineLayout pipeline_layout;
11108 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11109 ASSERT_VK_SUCCESS(err);
11110
11111 VkImageObj image(m_device);
11112 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11113 ASSERT_TRUE(image.initialized());
11114 VkImageView view = image.targetView(tex_format);
11115
11116 VkDescriptorImageInfo image_info = {};
11117 image_info.imageView = view;
11118 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11119
11120 VkWriteDescriptorSet descriptor_write = {};
11121 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11122 descriptor_write.dstSet = descriptor_set;
11123 descriptor_write.dstBinding = 0;
11124 descriptor_write.descriptorCount = 1;
11125 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11126 descriptor_write.pImageInfo = &image_info;
11127
11128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11129 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11130 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11131 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11132 m_errorMonitor->VerifyFound();
11133
11134 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11136 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11137 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11138}
11139
Mark Mueller93b938f2016-08-18 10:27:40 -060011140TEST_F(VkLayerTest, SimultaneousUse) {
11141 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11142 "in primary and secondary command buffers.");
11143
11144 ASSERT_NO_FATAL_FAILURE(InitState());
11145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11146
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011147 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011148 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11149 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011150
11151 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011153 command_buffer_allocate_info.commandPool = m_commandPool;
11154 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11155 command_buffer_allocate_info.commandBufferCount = 1;
11156
11157 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011158 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011159 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11160 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011161 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011162 command_buffer_inheritance_info.renderPass = m_renderPass;
11163 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011164
Mark Mueller93b938f2016-08-18 10:27:40 -060011165 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011166 command_buffer_begin_info.flags =
11167 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011168 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11169
11170 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11171 vkEndCommandBuffer(secondary_command_buffer);
11172
Mark Mueller93b938f2016-08-18 10:27:40 -060011173 VkSubmitInfo submit_info = {};
11174 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11175 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011177
Mark Mueller4042b652016-09-05 22:52:21 -060011178 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011179 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11181 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011182 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011183 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011184 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11185 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011186
11187 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011188 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11189
Mark Mueller4042b652016-09-05 22:52:21 -060011190 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011191 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11195 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011196 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011197 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11198 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011199
11200 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011201}
11202
Tobin Ehlisb093da82017-01-19 12:05:27 -070011203TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
11204 TEST_DESCRIPTION("Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11205 "disabled on the device.");
11206
11207 ASSERT_NO_FATAL_FAILURE(InitState());
11208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11209
11210 std::vector<const char *> device_extension_names;
11211 auto features = m_device->phy().features();
11212 // Make sure gs & ts are disabled
11213 features.geometryShader = false;
11214 features.tessellationShader = false;
11215 // The sacrificial device object
11216 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11217
11218 VkCommandPoolCreateInfo pool_create_info{};
11219 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11220 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11221
11222 VkCommandPool command_pool;
11223 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11224
11225 VkCommandBufferAllocateInfo cmd = {};
11226 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11227 cmd.pNext = NULL;
11228 cmd.commandPool = command_pool;
11229 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11230 cmd.commandBufferCount = 1;
11231
11232 VkCommandBuffer cmd_buffer;
11233 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11234 ASSERT_VK_SUCCESS(err);
11235
11236 VkEvent event;
11237 VkEventCreateInfo evci = {};
11238 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11239 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11240 ASSERT_VK_SUCCESS(result);
11241
11242 VkCommandBufferBeginInfo cbbi = {};
11243 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11244 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11246 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11247 m_errorMonitor->VerifyFound();
11248
11249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11250 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11251 m_errorMonitor->VerifyFound();
11252
11253 vkDestroyEvent(test_device.handle(), event, NULL);
11254 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11255}
11256
Mark Mueller917f6bc2016-08-30 10:57:19 -060011257TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11258 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11259 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011260 "Delete objects that are inuse. Call VkQueueSubmit "
11261 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011262
11263 ASSERT_NO_FATAL_FAILURE(InitState());
11264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011267 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011268
Tony Barbour552f6c02016-12-21 14:34:07 -070011269 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011270
11271 VkEvent event;
11272 VkEventCreateInfo event_create_info = {};
11273 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11274 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011275 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011276
Tony Barbour552f6c02016-12-21 14:34:07 -070011277 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011278 vkDestroyEvent(m_device->device(), event, nullptr);
11279
11280 VkSubmitInfo submit_info = {};
11281 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11282 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011283 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11286 m_errorMonitor->VerifyFound();
11287
11288 m_errorMonitor->SetDesiredFailureMsg(0, "");
11289 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11290
11291 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11292
Mark Mueller917f6bc2016-08-30 10:57:19 -060011293 VkSemaphoreCreateInfo semaphore_create_info = {};
11294 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11295 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011297 VkFenceCreateInfo fence_create_info = {};
11298 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11299 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011300 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011301
11302 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011303 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011304 descriptor_pool_type_count.descriptorCount = 1;
11305
11306 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11307 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11308 descriptor_pool_create_info.maxSets = 1;
11309 descriptor_pool_create_info.poolSizeCount = 1;
11310 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011311 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011312
11313 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011314 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011315
11316 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011317 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011318 descriptorset_layout_binding.descriptorCount = 1;
11319 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11320
11321 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011322 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011323 descriptorset_layout_create_info.bindingCount = 1;
11324 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11325
11326 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011327 ASSERT_VK_SUCCESS(
11328 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011329
11330 VkDescriptorSet descriptorset;
11331 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011333 descriptorset_allocate_info.descriptorSetCount = 1;
11334 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11335 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011337
Mark Mueller4042b652016-09-05 22:52:21 -060011338 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11339
11340 VkDescriptorBufferInfo buffer_info = {};
11341 buffer_info.buffer = buffer_test.GetBuffer();
11342 buffer_info.offset = 0;
11343 buffer_info.range = 1024;
11344
11345 VkWriteDescriptorSet write_descriptor_set = {};
11346 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11347 write_descriptor_set.dstSet = descriptorset;
11348 write_descriptor_set.descriptorCount = 1;
11349 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11350 write_descriptor_set.pBufferInfo = &buffer_info;
11351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011352 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011354 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11355 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011356
11357 VkPipelineObj pipe(m_device);
11358 pipe.AddColorAttachment();
11359 pipe.AddShader(&vs);
11360 pipe.AddShader(&fs);
11361
11362 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011363 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011364 pipeline_layout_create_info.setLayoutCount = 1;
11365 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11366
11367 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011368 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011369
11370 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11371
Tony Barbour552f6c02016-12-21 14:34:07 -070011372 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011373 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11376 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11377 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011378
Tony Barbour552f6c02016-12-21 14:34:07 -070011379 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011380
Mark Mueller917f6bc2016-08-30 10:57:19 -060011381 submit_info.signalSemaphoreCount = 1;
11382 submit_info.pSignalSemaphores = &semaphore;
11383 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011384
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011386 vkDestroyEvent(m_device->device(), event, nullptr);
11387 m_errorMonitor->VerifyFound();
11388
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011390 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11391 m_errorMonitor->VerifyFound();
11392
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011394 vkDestroyFence(m_device->device(), fence, nullptr);
11395 m_errorMonitor->VerifyFound();
11396
Tobin Ehlis122207b2016-09-01 08:50:06 -070011397 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011398 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11399 vkDestroyFence(m_device->device(), fence, nullptr);
11400 vkDestroyEvent(m_device->device(), event, nullptr);
11401 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011402 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011403 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11404}
11405
Tobin Ehlis2adda372016-09-01 08:51:06 -070011406TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11407 TEST_DESCRIPTION("Delete in-use query pool.");
11408
11409 ASSERT_NO_FATAL_FAILURE(InitState());
11410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11411
11412 VkQueryPool query_pool;
11413 VkQueryPoolCreateInfo query_pool_ci{};
11414 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11415 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11416 query_pool_ci.queryCount = 1;
11417 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011418 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011419 // Reset query pool to create binding with cmd buffer
11420 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11421
Tony Barbour552f6c02016-12-21 14:34:07 -070011422 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011423
11424 VkSubmitInfo submit_info = {};
11425 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11426 submit_info.commandBufferCount = 1;
11427 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11428 // Submit cmd buffer and then destroy query pool while in-flight
11429 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11430
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011432 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11433 m_errorMonitor->VerifyFound();
11434
11435 vkQueueWaitIdle(m_device->m_queue);
11436 // Now that cmd buffer done we can safely destroy query_pool
11437 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11438}
11439
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011440TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11441 TEST_DESCRIPTION("Delete in-use pipeline.");
11442
11443 ASSERT_NO_FATAL_FAILURE(InitState());
11444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11445
11446 // Empty pipeline layout used for binding PSO
11447 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11448 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11449 pipeline_layout_ci.setLayoutCount = 0;
11450 pipeline_layout_ci.pSetLayouts = NULL;
11451
11452 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011454 ASSERT_VK_SUCCESS(err);
11455
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011457 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011458 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11459 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011460 // Store pipeline handle so we can actually delete it before test finishes
11461 VkPipeline delete_this_pipeline;
11462 { // Scope pipeline so it will be auto-deleted
11463 VkPipelineObj pipe(m_device);
11464 pipe.AddShader(&vs);
11465 pipe.AddShader(&fs);
11466 pipe.AddColorAttachment();
11467 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11468 delete_this_pipeline = pipe.handle();
11469
Tony Barbour552f6c02016-12-21 14:34:07 -070011470 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011471 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011472 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011473
Tony Barbour552f6c02016-12-21 14:34:07 -070011474 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011475
11476 VkSubmitInfo submit_info = {};
11477 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11478 submit_info.commandBufferCount = 1;
11479 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11480 // Submit cmd buffer and then pipeline destroyed while in-flight
11481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11482 } // Pipeline deletion triggered here
11483 m_errorMonitor->VerifyFound();
11484 // Make sure queue finished and then actually delete pipeline
11485 vkQueueWaitIdle(m_device->m_queue);
11486 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11487 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11488}
11489
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011490TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11491 TEST_DESCRIPTION("Delete in-use imageView.");
11492
11493 ASSERT_NO_FATAL_FAILURE(InitState());
11494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11495
11496 VkDescriptorPoolSize ds_type_count;
11497 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11498 ds_type_count.descriptorCount = 1;
11499
11500 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11501 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11502 ds_pool_ci.maxSets = 1;
11503 ds_pool_ci.poolSizeCount = 1;
11504 ds_pool_ci.pPoolSizes = &ds_type_count;
11505
11506 VkDescriptorPool ds_pool;
11507 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11508 ASSERT_VK_SUCCESS(err);
11509
11510 VkSamplerCreateInfo sampler_ci = {};
11511 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11512 sampler_ci.pNext = NULL;
11513 sampler_ci.magFilter = VK_FILTER_NEAREST;
11514 sampler_ci.minFilter = VK_FILTER_NEAREST;
11515 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11516 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11517 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11518 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11519 sampler_ci.mipLodBias = 1.0;
11520 sampler_ci.anisotropyEnable = VK_FALSE;
11521 sampler_ci.maxAnisotropy = 1;
11522 sampler_ci.compareEnable = VK_FALSE;
11523 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11524 sampler_ci.minLod = 1.0;
11525 sampler_ci.maxLod = 1.0;
11526 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11527 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11528 VkSampler sampler;
11529
11530 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11531 ASSERT_VK_SUCCESS(err);
11532
11533 VkDescriptorSetLayoutBinding layout_binding;
11534 layout_binding.binding = 0;
11535 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11536 layout_binding.descriptorCount = 1;
11537 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11538 layout_binding.pImmutableSamplers = NULL;
11539
11540 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11541 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11542 ds_layout_ci.bindingCount = 1;
11543 ds_layout_ci.pBindings = &layout_binding;
11544 VkDescriptorSetLayout ds_layout;
11545 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11546 ASSERT_VK_SUCCESS(err);
11547
11548 VkDescriptorSetAllocateInfo alloc_info = {};
11549 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11550 alloc_info.descriptorSetCount = 1;
11551 alloc_info.descriptorPool = ds_pool;
11552 alloc_info.pSetLayouts = &ds_layout;
11553 VkDescriptorSet descriptor_set;
11554 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11555 ASSERT_VK_SUCCESS(err);
11556
11557 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11558 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11559 pipeline_layout_ci.pNext = NULL;
11560 pipeline_layout_ci.setLayoutCount = 1;
11561 pipeline_layout_ci.pSetLayouts = &ds_layout;
11562
11563 VkPipelineLayout pipeline_layout;
11564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11565 ASSERT_VK_SUCCESS(err);
11566
11567 VkImageObj image(m_device);
11568 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11569 ASSERT_TRUE(image.initialized());
11570
11571 VkImageView view;
11572 VkImageViewCreateInfo ivci = {};
11573 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11574 ivci.image = image.handle();
11575 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11576 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11577 ivci.subresourceRange.layerCount = 1;
11578 ivci.subresourceRange.baseMipLevel = 0;
11579 ivci.subresourceRange.levelCount = 1;
11580 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11581
11582 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11583 ASSERT_VK_SUCCESS(err);
11584
11585 VkDescriptorImageInfo image_info{};
11586 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11587 image_info.imageView = view;
11588 image_info.sampler = sampler;
11589
11590 VkWriteDescriptorSet descriptor_write = {};
11591 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11592 descriptor_write.dstSet = descriptor_set;
11593 descriptor_write.dstBinding = 0;
11594 descriptor_write.descriptorCount = 1;
11595 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11596 descriptor_write.pImageInfo = &image_info;
11597
11598 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11599
11600 // Create PSO to use the sampler
11601 char const *vsSource = "#version 450\n"
11602 "\n"
11603 "out gl_PerVertex { \n"
11604 " vec4 gl_Position;\n"
11605 "};\n"
11606 "void main(){\n"
11607 " gl_Position = vec4(1);\n"
11608 "}\n";
11609 char const *fsSource = "#version 450\n"
11610 "\n"
11611 "layout(set=0, binding=0) uniform sampler2D s;\n"
11612 "layout(location=0) out vec4 x;\n"
11613 "void main(){\n"
11614 " x = texture(s, vec2(1));\n"
11615 "}\n";
11616 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11617 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11618 VkPipelineObj pipe(m_device);
11619 pipe.AddShader(&vs);
11620 pipe.AddShader(&fs);
11621 pipe.AddColorAttachment();
11622 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11623
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011625
Tony Barbour552f6c02016-12-21 14:34:07 -070011626 m_commandBuffer->BeginCommandBuffer();
11627 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011628 // Bind pipeline to cmd buffer
11629 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11630 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11631 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011632
11633 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11634 VkRect2D scissor = {{0, 0}, {16, 16}};
11635 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11636 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11637
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011638 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011639 m_commandBuffer->EndRenderPass();
11640 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011641 // Submit cmd buffer then destroy sampler
11642 VkSubmitInfo submit_info = {};
11643 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11644 submit_info.commandBufferCount = 1;
11645 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11646 // Submit cmd buffer and then destroy imageView while in-flight
11647 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11648
11649 vkDestroyImageView(m_device->device(), view, nullptr);
11650 m_errorMonitor->VerifyFound();
11651 vkQueueWaitIdle(m_device->m_queue);
11652 // Now we can actually destroy imageView
11653 vkDestroyImageView(m_device->device(), view, NULL);
11654 vkDestroySampler(m_device->device(), sampler, nullptr);
11655 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11658}
11659
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011660TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11661 TEST_DESCRIPTION("Delete in-use bufferView.");
11662
11663 ASSERT_NO_FATAL_FAILURE(InitState());
11664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11665
11666 VkDescriptorPoolSize ds_type_count;
11667 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11668 ds_type_count.descriptorCount = 1;
11669
11670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11672 ds_pool_ci.maxSets = 1;
11673 ds_pool_ci.poolSizeCount = 1;
11674 ds_pool_ci.pPoolSizes = &ds_type_count;
11675
11676 VkDescriptorPool ds_pool;
11677 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11678 ASSERT_VK_SUCCESS(err);
11679
11680 VkDescriptorSetLayoutBinding layout_binding;
11681 layout_binding.binding = 0;
11682 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11683 layout_binding.descriptorCount = 1;
11684 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11685 layout_binding.pImmutableSamplers = NULL;
11686
11687 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11688 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11689 ds_layout_ci.bindingCount = 1;
11690 ds_layout_ci.pBindings = &layout_binding;
11691 VkDescriptorSetLayout ds_layout;
11692 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11693 ASSERT_VK_SUCCESS(err);
11694
11695 VkDescriptorSetAllocateInfo alloc_info = {};
11696 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11697 alloc_info.descriptorSetCount = 1;
11698 alloc_info.descriptorPool = ds_pool;
11699 alloc_info.pSetLayouts = &ds_layout;
11700 VkDescriptorSet descriptor_set;
11701 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11702 ASSERT_VK_SUCCESS(err);
11703
11704 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11705 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11706 pipeline_layout_ci.pNext = NULL;
11707 pipeline_layout_ci.setLayoutCount = 1;
11708 pipeline_layout_ci.pSetLayouts = &ds_layout;
11709
11710 VkPipelineLayout pipeline_layout;
11711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11712 ASSERT_VK_SUCCESS(err);
11713
11714 VkBuffer buffer;
11715 uint32_t queue_family_index = 0;
11716 VkBufferCreateInfo buffer_create_info = {};
11717 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11718 buffer_create_info.size = 1024;
11719 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11720 buffer_create_info.queueFamilyIndexCount = 1;
11721 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11722
11723 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11724 ASSERT_VK_SUCCESS(err);
11725
11726 VkMemoryRequirements memory_reqs;
11727 VkDeviceMemory buffer_memory;
11728
11729 VkMemoryAllocateInfo memory_info = {};
11730 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11731 memory_info.allocationSize = 0;
11732 memory_info.memoryTypeIndex = 0;
11733
11734 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11735 memory_info.allocationSize = memory_reqs.size;
11736 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11737 ASSERT_TRUE(pass);
11738
11739 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11740 ASSERT_VK_SUCCESS(err);
11741 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11742 ASSERT_VK_SUCCESS(err);
11743
11744 VkBufferView view;
11745 VkBufferViewCreateInfo bvci = {};
11746 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11747 bvci.buffer = buffer;
11748 bvci.format = VK_FORMAT_R8_UNORM;
11749 bvci.range = VK_WHOLE_SIZE;
11750
11751 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11752 ASSERT_VK_SUCCESS(err);
11753
11754 VkWriteDescriptorSet descriptor_write = {};
11755 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11756 descriptor_write.dstSet = descriptor_set;
11757 descriptor_write.dstBinding = 0;
11758 descriptor_write.descriptorCount = 1;
11759 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11760 descriptor_write.pTexelBufferView = &view;
11761
11762 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11763
11764 char const *vsSource = "#version 450\n"
11765 "\n"
11766 "out gl_PerVertex { \n"
11767 " vec4 gl_Position;\n"
11768 "};\n"
11769 "void main(){\n"
11770 " gl_Position = vec4(1);\n"
11771 "}\n";
11772 char const *fsSource = "#version 450\n"
11773 "\n"
11774 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11775 "layout(location=0) out vec4 x;\n"
11776 "void main(){\n"
11777 " x = imageLoad(s, 0);\n"
11778 "}\n";
11779 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11780 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11781 VkPipelineObj pipe(m_device);
11782 pipe.AddShader(&vs);
11783 pipe.AddShader(&fs);
11784 pipe.AddColorAttachment();
11785 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11786
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011788
Tony Barbour552f6c02016-12-21 14:34:07 -070011789 m_commandBuffer->BeginCommandBuffer();
11790 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011791 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11792 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11793 VkRect2D scissor = {{0, 0}, {16, 16}};
11794 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11795 // Bind pipeline to cmd buffer
11796 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11797 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11798 &descriptor_set, 0, nullptr);
11799 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011800 m_commandBuffer->EndRenderPass();
11801 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011802
11803 VkSubmitInfo submit_info = {};
11804 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11805 submit_info.commandBufferCount = 1;
11806 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11807 // Submit cmd buffer and then destroy bufferView while in-flight
11808 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11809
11810 vkDestroyBufferView(m_device->device(), view, nullptr);
11811 m_errorMonitor->VerifyFound();
11812 vkQueueWaitIdle(m_device->m_queue);
11813 // Now we can actually destroy bufferView
11814 vkDestroyBufferView(m_device->device(), view, NULL);
11815 vkDestroyBuffer(m_device->device(), buffer, NULL);
11816 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11817 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11819 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11820}
11821
Tobin Ehlis209532e2016-09-07 13:52:18 -060011822TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11823 TEST_DESCRIPTION("Delete in-use sampler.");
11824
11825 ASSERT_NO_FATAL_FAILURE(InitState());
11826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11827
11828 VkDescriptorPoolSize ds_type_count;
11829 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11830 ds_type_count.descriptorCount = 1;
11831
11832 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11833 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11834 ds_pool_ci.maxSets = 1;
11835 ds_pool_ci.poolSizeCount = 1;
11836 ds_pool_ci.pPoolSizes = &ds_type_count;
11837
11838 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011839 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011840 ASSERT_VK_SUCCESS(err);
11841
11842 VkSamplerCreateInfo sampler_ci = {};
11843 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11844 sampler_ci.pNext = NULL;
11845 sampler_ci.magFilter = VK_FILTER_NEAREST;
11846 sampler_ci.minFilter = VK_FILTER_NEAREST;
11847 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11848 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11849 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11850 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11851 sampler_ci.mipLodBias = 1.0;
11852 sampler_ci.anisotropyEnable = VK_FALSE;
11853 sampler_ci.maxAnisotropy = 1;
11854 sampler_ci.compareEnable = VK_FALSE;
11855 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11856 sampler_ci.minLod = 1.0;
11857 sampler_ci.maxLod = 1.0;
11858 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11859 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11860 VkSampler sampler;
11861
11862 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11863 ASSERT_VK_SUCCESS(err);
11864
11865 VkDescriptorSetLayoutBinding layout_binding;
11866 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011867 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011868 layout_binding.descriptorCount = 1;
11869 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11870 layout_binding.pImmutableSamplers = NULL;
11871
11872 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11873 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11874 ds_layout_ci.bindingCount = 1;
11875 ds_layout_ci.pBindings = &layout_binding;
11876 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011878 ASSERT_VK_SUCCESS(err);
11879
11880 VkDescriptorSetAllocateInfo alloc_info = {};
11881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11882 alloc_info.descriptorSetCount = 1;
11883 alloc_info.descriptorPool = ds_pool;
11884 alloc_info.pSetLayouts = &ds_layout;
11885 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011887 ASSERT_VK_SUCCESS(err);
11888
11889 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11890 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11891 pipeline_layout_ci.pNext = NULL;
11892 pipeline_layout_ci.setLayoutCount = 1;
11893 pipeline_layout_ci.pSetLayouts = &ds_layout;
11894
11895 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011897 ASSERT_VK_SUCCESS(err);
11898
11899 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011900 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 -060011901 ASSERT_TRUE(image.initialized());
11902
11903 VkImageView view;
11904 VkImageViewCreateInfo ivci = {};
11905 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11906 ivci.image = image.handle();
11907 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11908 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11909 ivci.subresourceRange.layerCount = 1;
11910 ivci.subresourceRange.baseMipLevel = 0;
11911 ivci.subresourceRange.levelCount = 1;
11912 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11913
11914 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11915 ASSERT_VK_SUCCESS(err);
11916
11917 VkDescriptorImageInfo image_info{};
11918 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11919 image_info.imageView = view;
11920 image_info.sampler = sampler;
11921
11922 VkWriteDescriptorSet descriptor_write = {};
11923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11924 descriptor_write.dstSet = descriptor_set;
11925 descriptor_write.dstBinding = 0;
11926 descriptor_write.descriptorCount = 1;
11927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11928 descriptor_write.pImageInfo = &image_info;
11929
11930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11931
11932 // Create PSO to use the sampler
11933 char const *vsSource = "#version 450\n"
11934 "\n"
11935 "out gl_PerVertex { \n"
11936 " vec4 gl_Position;\n"
11937 "};\n"
11938 "void main(){\n"
11939 " gl_Position = vec4(1);\n"
11940 "}\n";
11941 char const *fsSource = "#version 450\n"
11942 "\n"
11943 "layout(set=0, binding=0) uniform sampler2D s;\n"
11944 "layout(location=0) out vec4 x;\n"
11945 "void main(){\n"
11946 " x = texture(s, vec2(1));\n"
11947 "}\n";
11948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11950 VkPipelineObj pipe(m_device);
11951 pipe.AddShader(&vs);
11952 pipe.AddShader(&fs);
11953 pipe.AddColorAttachment();
11954 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11955
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011957
Tony Barbour552f6c02016-12-21 14:34:07 -070011958 m_commandBuffer->BeginCommandBuffer();
11959 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011960 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11962 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11963 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070011964
11965 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11966 VkRect2D scissor = {{0, 0}, {16, 16}};
11967 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11968 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11969
Tobin Ehlis209532e2016-09-07 13:52:18 -060011970 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011971 m_commandBuffer->EndRenderPass();
11972 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060011973 // Submit cmd buffer then destroy sampler
11974 VkSubmitInfo submit_info = {};
11975 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11976 submit_info.commandBufferCount = 1;
11977 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11978 // Submit cmd buffer and then destroy sampler while in-flight
11979 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11980
Rene Lindsay4da11732017-01-13 14:42:10 -070011981 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060011982 m_errorMonitor->VerifyFound();
11983 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070011984
Tobin Ehlis209532e2016-09-07 13:52:18 -060011985 // Now we can actually destroy sampler
Rene Lindsay4da11732017-01-13 14:42:10 -070011986 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060011987 vkDestroyImageView(m_device->device(), view, NULL);
11988 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11989 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11990 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11991}
11992
Mark Mueller1cd9f412016-08-25 13:23:52 -060011993TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011994 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011995 "signaled but not waited on by the queue. Wait on a "
11996 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011997
11998 ASSERT_NO_FATAL_FAILURE(InitState());
11999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012001 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12002 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12003 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012004
Tony Barbour552f6c02016-12-21 14:34:07 -070012005 m_commandBuffer->BeginCommandBuffer();
12006 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012007
12008 VkSemaphoreCreateInfo semaphore_create_info = {};
12009 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12010 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012011 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012012 VkSubmitInfo submit_info = {};
12013 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12014 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012015 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012016 submit_info.signalSemaphoreCount = 1;
12017 submit_info.pSignalSemaphores = &semaphore;
12018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12019 m_errorMonitor->SetDesiredFailureMsg(0, "");
12020 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012021 m_commandBuffer->BeginCommandBuffer();
12022 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012024 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12025 m_errorMonitor->VerifyFound();
12026
Mark Mueller1cd9f412016-08-25 13:23:52 -060012027 VkFenceCreateInfo fence_create_info = {};
12028 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12029 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012030 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012033 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12034 m_errorMonitor->VerifyFound();
12035
Mark Mueller4042b652016-09-05 22:52:21 -060012036 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012037 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012038 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12039}
12040
Tobin Ehlis4af23302016-07-19 10:50:30 -060012041TEST_F(VkLayerTest, FramebufferIncompatible) {
12042 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12043 "that does not match the framebuffer for the active "
12044 "renderpass.");
12045 ASSERT_NO_FATAL_FAILURE(InitState());
12046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12047
12048 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 VkAttachmentDescription attachment = {0,
12050 VK_FORMAT_B8G8R8A8_UNORM,
12051 VK_SAMPLE_COUNT_1_BIT,
12052 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12053 VK_ATTACHMENT_STORE_OP_STORE,
12054 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12055 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12056 VK_IMAGE_LAYOUT_UNDEFINED,
12057 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012059 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012061 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012063 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012064
12065 VkRenderPass rp;
12066 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12067 ASSERT_VK_SUCCESS(err);
12068
12069 // A compatible framebuffer.
12070 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 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 -060012072 ASSERT_TRUE(image.initialized());
12073
12074 VkImageViewCreateInfo ivci = {
12075 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12076 nullptr,
12077 0,
12078 image.handle(),
12079 VK_IMAGE_VIEW_TYPE_2D,
12080 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012081 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12082 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012083 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12084 };
12085 VkImageView view;
12086 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12087 ASSERT_VK_SUCCESS(err);
12088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012089 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012090 VkFramebuffer fb;
12091 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12092 ASSERT_VK_SUCCESS(err);
12093
12094 VkCommandBufferAllocateInfo cbai = {};
12095 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12096 cbai.commandPool = m_commandPool;
12097 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12098 cbai.commandBufferCount = 1;
12099
12100 VkCommandBuffer sec_cb;
12101 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12102 ASSERT_VK_SUCCESS(err);
12103 VkCommandBufferBeginInfo cbbi = {};
12104 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012105 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012106 cbii.renderPass = renderPass();
12107 cbii.framebuffer = fb;
12108 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12109 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012110 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 -060012111 cbbi.pInheritanceInfo = &cbii;
12112 vkBeginCommandBuffer(sec_cb, &cbbi);
12113 vkEndCommandBuffer(sec_cb);
12114
Chris Forbes3400bc52016-09-13 18:10:34 +120012115 VkCommandBufferBeginInfo cbbi2 = {
12116 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12117 0, nullptr
12118 };
12119 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12120 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012123 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012124 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12125 m_errorMonitor->VerifyFound();
12126 // Cleanup
12127 vkDestroyImageView(m_device->device(), view, NULL);
12128 vkDestroyRenderPass(m_device->device(), rp, NULL);
12129 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12130}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012131
12132TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12133 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12134 "invalid value. If logicOp is not available, attempt to "
12135 "use it and verify that we see the correct error.");
12136 ASSERT_NO_FATAL_FAILURE(InitState());
12137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12138
12139 auto features = m_device->phy().features();
12140 // Set the expected error depending on whether or not logicOp available
12141 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12143 "enabled, logicOpEnable must be "
12144 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012145 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012147 }
12148 // Create a pipeline using logicOp
12149 VkResult err;
12150
12151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12153
12154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012156 ASSERT_VK_SUCCESS(err);
12157
12158 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12159 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12160 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012161 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012162 vp_state_ci.pViewports = &vp;
12163 vp_state_ci.scissorCount = 1;
12164 VkRect2D scissors = {}; // Dummy scissors to point to
12165 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012166
12167 VkPipelineShaderStageCreateInfo shaderStages[2];
12168 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012170 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12171 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012172 shaderStages[0] = vs.GetStageCreateInfo();
12173 shaderStages[1] = fs.GetStageCreateInfo();
12174
12175 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12176 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12177
12178 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12179 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12180 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12181
12182 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12183 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012184 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012185
12186 VkPipelineColorBlendAttachmentState att = {};
12187 att.blendEnable = VK_FALSE;
12188 att.colorWriteMask = 0xf;
12189
12190 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12191 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12192 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12193 cb_ci.logicOpEnable = VK_TRUE;
12194 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12195 cb_ci.attachmentCount = 1;
12196 cb_ci.pAttachments = &att;
12197
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012198 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12199 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12200 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12201
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012202 VkGraphicsPipelineCreateInfo gp_ci = {};
12203 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12204 gp_ci.stageCount = 2;
12205 gp_ci.pStages = shaderStages;
12206 gp_ci.pVertexInputState = &vi_ci;
12207 gp_ci.pInputAssemblyState = &ia_ci;
12208 gp_ci.pViewportState = &vp_state_ci;
12209 gp_ci.pRasterizationState = &rs_ci;
12210 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012211 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012212 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12213 gp_ci.layout = pipeline_layout;
12214 gp_ci.renderPass = renderPass();
12215
12216 VkPipelineCacheCreateInfo pc_ci = {};
12217 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12218
12219 VkPipeline pipeline;
12220 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012221 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012222 ASSERT_VK_SUCCESS(err);
12223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012224 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012225 m_errorMonitor->VerifyFound();
12226 if (VK_SUCCESS == err) {
12227 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12228 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012229 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12231}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012232#endif // DRAW_STATE_TESTS
12233
Tobin Ehlis0788f522015-05-26 16:11:58 -060012234#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012235#if GTEST_IS_THREADSAFE
12236struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012237 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012238 VkEvent event;
12239 bool bailout;
12240};
12241
Karl Schultz6addd812016-02-02 17:17:23 -070012242extern "C" void *AddToCommandBuffer(void *arg) {
12243 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012244
Mike Stroyana6d14942016-07-13 15:10:05 -060012245 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012246 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012247 if (data->bailout) {
12248 break;
12249 }
12250 }
12251 return NULL;
12252}
12253
Karl Schultz6addd812016-02-02 17:17:23 -070012254TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012255 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012258
Mike Stroyanaccf7692015-05-12 16:00:45 -060012259 ASSERT_NO_FATAL_FAILURE(InitState());
12260 ASSERT_NO_FATAL_FAILURE(InitViewport());
12261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12262
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012263 // Calls AllocateCommandBuffers
12264 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012265
12266 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012267 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012268
12269 VkEventCreateInfo event_info;
12270 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012271 VkResult err;
12272
12273 memset(&event_info, 0, sizeof(event_info));
12274 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12275
Chia-I Wuf7458c52015-10-26 21:10:41 +080012276 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012277 ASSERT_VK_SUCCESS(err);
12278
Mike Stroyanaccf7692015-05-12 16:00:45 -060012279 err = vkResetEvent(device(), event);
12280 ASSERT_VK_SUCCESS(err);
12281
12282 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012283 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012284 data.event = event;
12285 data.bailout = false;
12286 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012287
12288 // First do some correct operations using multiple threads.
12289 // Add many entries to command buffer from another thread.
12290 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12291 // Make non-conflicting calls from this thread at the same time.
12292 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012293 uint32_t count;
12294 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012295 }
12296 test_platform_thread_join(thread, NULL);
12297
12298 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012299 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012300 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012301 // Add many entries to command buffer from this thread at the same time.
12302 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012303
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012304 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012305 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012306
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012307 m_errorMonitor->SetBailout(NULL);
12308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012309 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012310
Chia-I Wuf7458c52015-10-26 21:10:41 +080012311 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012312}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012313#endif // GTEST_IS_THREADSAFE
12314#endif // THREADING_TESTS
12315
Chris Forbes9f7ff632015-05-25 11:13:08 +120012316#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012317TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012318 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12319 "with an impossible code size");
12320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012322
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012323 ASSERT_NO_FATAL_FAILURE(InitState());
12324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12325
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012326 VkShaderModule module;
12327 VkShaderModuleCreateInfo moduleCreateInfo;
12328 struct icd_spv_header spv;
12329
12330 spv.magic = ICD_SPV_MAGIC;
12331 spv.version = ICD_SPV_VERSION;
12332 spv.gen_magic = 0;
12333
12334 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12335 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012336 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012337 moduleCreateInfo.codeSize = 4;
12338 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012339 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012341 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012342}
12343
Karl Schultz6addd812016-02-02 17:17:23 -070012344TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012345 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12346 "with a bad magic number");
12347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012349
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012350 ASSERT_NO_FATAL_FAILURE(InitState());
12351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12352
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012353 VkShaderModule module;
12354 VkShaderModuleCreateInfo moduleCreateInfo;
12355 struct icd_spv_header spv;
12356
12357 spv.magic = ~ICD_SPV_MAGIC;
12358 spv.version = ICD_SPV_VERSION;
12359 spv.gen_magic = 0;
12360
12361 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12362 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012363 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012364 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12365 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012366 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012368 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012369}
12370
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012371#if 0
12372// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012373TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012375 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012376
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012377 ASSERT_NO_FATAL_FAILURE(InitState());
12378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12379
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012380 VkShaderModule module;
12381 VkShaderModuleCreateInfo moduleCreateInfo;
12382 struct icd_spv_header spv;
12383
12384 spv.magic = ICD_SPV_MAGIC;
12385 spv.version = ~ICD_SPV_VERSION;
12386 spv.gen_magic = 0;
12387
12388 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12389 moduleCreateInfo.pNext = NULL;
12390
Karl Schultz6addd812016-02-02 17:17:23 -070012391 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012392 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12393 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012394 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012395
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012396 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012397}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012398#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012399
Karl Schultz6addd812016-02-02 17:17:23 -070012400TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012401 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12402 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012404
Chris Forbes9f7ff632015-05-25 11:13:08 +120012405 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 char const *vsSource = "#version 450\n"
12409 "\n"
12410 "layout(location=0) out float x;\n"
12411 "out gl_PerVertex {\n"
12412 " vec4 gl_Position;\n"
12413 "};\n"
12414 "void main(){\n"
12415 " gl_Position = vec4(1);\n"
12416 " x = 0;\n"
12417 "}\n";
12418 char const *fsSource = "#version 450\n"
12419 "\n"
12420 "layout(location=0) out vec4 color;\n"
12421 "void main(){\n"
12422 " color = vec4(1);\n"
12423 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012424
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012427
12428 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012429 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012430 pipe.AddShader(&vs);
12431 pipe.AddShader(&fs);
12432
Chris Forbes9f7ff632015-05-25 11:13:08 +120012433 VkDescriptorSetObj descriptorSet(m_device);
12434 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012436
Tony Barbour5781e8f2015-08-04 16:23:11 -060012437 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012438
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012439 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012440}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012441
Mark Mueller098c9cb2016-09-08 09:01:57 -060012442TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12443 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12444
12445 ASSERT_NO_FATAL_FAILURE(InitState());
12446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12447
12448 const char *bad_specialization_message =
12449 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12450
12451 char const *vsSource =
12452 "#version 450\n"
12453 "\n"
12454 "out gl_PerVertex {\n"
12455 " vec4 gl_Position;\n"
12456 "};\n"
12457 "void main(){\n"
12458 " gl_Position = vec4(1);\n"
12459 "}\n";
12460
12461 char const *fsSource =
12462 "#version 450\n"
12463 "\n"
12464 "layout (constant_id = 0) const float r = 0.0f;\n"
12465 "layout(location = 0) out vec4 uFragColor;\n"
12466 "void main(){\n"
12467 " uFragColor = vec4(r,1,0,1);\n"
12468 "}\n";
12469
12470 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12471 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12472
12473 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12474 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12475
12476 VkPipelineLayout pipeline_layout;
12477 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12478
12479 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12480 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12481 vp_state_create_info.viewportCount = 1;
12482 VkViewport viewport = {};
12483 vp_state_create_info.pViewports = &viewport;
12484 vp_state_create_info.scissorCount = 1;
12485 VkRect2D scissors = {};
12486 vp_state_create_info.pScissors = &scissors;
12487
12488 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12489
12490 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12491 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12492 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12493 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12494
12495 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12496 vs.GetStageCreateInfo(),
12497 fs.GetStageCreateInfo()
12498 };
12499
12500 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12501 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12502
12503 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12504 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12505 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12506
12507 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12508 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12509 rasterization_state_create_info.pNext = nullptr;
12510 rasterization_state_create_info.lineWidth = 1.0f;
12511 rasterization_state_create_info.rasterizerDiscardEnable = true;
12512
12513 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12514 color_blend_attachment_state.blendEnable = VK_FALSE;
12515 color_blend_attachment_state.colorWriteMask = 0xf;
12516
12517 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12518 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12519 color_blend_state_create_info.attachmentCount = 1;
12520 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12521
12522 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12523 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12524 graphicspipe_create_info.stageCount = 2;
12525 graphicspipe_create_info.pStages = shader_stage_create_info;
12526 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12527 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12528 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12529 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12530 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12531 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12532 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12533 graphicspipe_create_info.layout = pipeline_layout;
12534 graphicspipe_create_info.renderPass = renderPass();
12535
12536 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12537 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12538
12539 VkPipelineCache pipelineCache;
12540 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12541
12542 // This structure maps constant ids to data locations.
12543 const VkSpecializationMapEntry entry =
12544 // id, offset, size
12545 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12546
12547 uint32_t data = 1;
12548
12549 // Set up the info describing spec map and data
12550 const VkSpecializationInfo specialization_info = {
12551 1,
12552 &entry,
12553 1 * sizeof(float),
12554 &data,
12555 };
12556 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12557
12558 VkPipeline pipeline;
12559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12560 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12561 m_errorMonitor->VerifyFound();
12562
12563 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12564 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12565}
12566
12567TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12568 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12569
12570 ASSERT_NO_FATAL_FAILURE(InitState());
12571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12572
12573 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12574
12575 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12576 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12577 descriptor_pool_type_count[0].descriptorCount = 1;
12578 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12579 descriptor_pool_type_count[1].descriptorCount = 1;
12580
12581 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12582 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12583 descriptor_pool_create_info.maxSets = 1;
12584 descriptor_pool_create_info.poolSizeCount = 2;
12585 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12586 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12587
12588 VkDescriptorPool descriptorset_pool;
12589 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12590
12591 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12592 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12593 descriptorset_layout_binding.descriptorCount = 1;
12594 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12595
12596 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12597 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12598 descriptorset_layout_create_info.bindingCount = 1;
12599 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12600
12601 VkDescriptorSetLayout descriptorset_layout;
12602 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12603
12604 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12605 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12606 descriptorset_allocate_info.descriptorSetCount = 1;
12607 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12608 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12609 VkDescriptorSet descriptorset;
12610 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12611
12612 // Challenge core_validation with a non uniform buffer type.
12613 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12614
Mark Mueller098c9cb2016-09-08 09:01:57 -060012615 char const *vsSource =
12616 "#version 450\n"
12617 "\n"
12618 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12619 " mat4 mvp;\n"
12620 "} ubuf;\n"
12621 "out gl_PerVertex {\n"
12622 " vec4 gl_Position;\n"
12623 "};\n"
12624 "void main(){\n"
12625 " gl_Position = ubuf.mvp * vec4(1);\n"
12626 "}\n";
12627
12628 char const *fsSource =
12629 "#version 450\n"
12630 "\n"
12631 "layout(location = 0) out vec4 uFragColor;\n"
12632 "void main(){\n"
12633 " uFragColor = vec4(0,1,0,1);\n"
12634 "}\n";
12635
12636 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12637 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12638
12639 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12640 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12641 pipeline_layout_create_info.setLayoutCount = 1;
12642 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12643
12644 VkPipelineLayout pipeline_layout;
12645 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12646
12647 VkPipelineObj pipe(m_device);
12648 pipe.AddColorAttachment();
12649 pipe.AddShader(&vs);
12650 pipe.AddShader(&fs);
12651
12652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12653 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12654 m_errorMonitor->VerifyFound();
12655
12656 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12657 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12658 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12659}
12660
12661TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12662 TEST_DESCRIPTION(
12663 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12664
12665 ASSERT_NO_FATAL_FAILURE(InitState());
12666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12667
12668 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12669
12670 VkDescriptorPoolSize descriptor_pool_type_count = {};
12671 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12672 descriptor_pool_type_count.descriptorCount = 1;
12673
12674 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12675 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12676 descriptor_pool_create_info.maxSets = 1;
12677 descriptor_pool_create_info.poolSizeCount = 1;
12678 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12679 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12680
12681 VkDescriptorPool descriptorset_pool;
12682 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12683
12684 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12685 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12686 descriptorset_layout_binding.descriptorCount = 1;
12687 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12688 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12689
12690 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12691 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12692 descriptorset_layout_create_info.bindingCount = 1;
12693 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12694
12695 VkDescriptorSetLayout descriptorset_layout;
12696 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12697 nullptr, &descriptorset_layout));
12698
12699 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12700 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12701 descriptorset_allocate_info.descriptorSetCount = 1;
12702 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12703 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12704 VkDescriptorSet descriptorset;
12705 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12706
12707 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12708
Mark Mueller098c9cb2016-09-08 09:01:57 -060012709 char const *vsSource =
12710 "#version 450\n"
12711 "\n"
12712 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12713 " mat4 mvp;\n"
12714 "} ubuf;\n"
12715 "out gl_PerVertex {\n"
12716 " vec4 gl_Position;\n"
12717 "};\n"
12718 "void main(){\n"
12719 " gl_Position = ubuf.mvp * vec4(1);\n"
12720 "}\n";
12721
12722 char const *fsSource =
12723 "#version 450\n"
12724 "\n"
12725 "layout(location = 0) out vec4 uFragColor;\n"
12726 "void main(){\n"
12727 " uFragColor = vec4(0,1,0,1);\n"
12728 "}\n";
12729
12730 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12731 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12732
12733 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12734 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12735 pipeline_layout_create_info.setLayoutCount = 1;
12736 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12737
12738 VkPipelineLayout pipeline_layout;
12739 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12740
12741 VkPipelineObj pipe(m_device);
12742 pipe.AddColorAttachment();
12743 pipe.AddShader(&vs);
12744 pipe.AddShader(&fs);
12745
12746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12747 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12748 m_errorMonitor->VerifyFound();
12749
12750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12751 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12752 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12753}
12754
12755TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12756 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12757 "accessible from the current shader stage.");
12758
12759 ASSERT_NO_FATAL_FAILURE(InitState());
12760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12761
12762 const char *push_constant_not_accessible_message =
12763 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12764
12765 char const *vsSource =
12766 "#version 450\n"
12767 "\n"
12768 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12769 "out gl_PerVertex {\n"
12770 " vec4 gl_Position;\n"
12771 "};\n"
12772 "void main(){\n"
12773 " gl_Position = vec4(consts.x);\n"
12774 "}\n";
12775
12776 char const *fsSource =
12777 "#version 450\n"
12778 "\n"
12779 "layout(location = 0) out vec4 uFragColor;\n"
12780 "void main(){\n"
12781 " uFragColor = vec4(0,1,0,1);\n"
12782 "}\n";
12783
12784 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12785 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12786
12787 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12788 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12789
12790 // Set up a push constant range
12791 VkPushConstantRange push_constant_ranges = {};
12792 // Set to the wrong stage to challenge core_validation
12793 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12794 push_constant_ranges.size = 4;
12795
12796 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12797 pipeline_layout_create_info.pushConstantRangeCount = 1;
12798
12799 VkPipelineLayout pipeline_layout;
12800 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12801
12802 VkPipelineObj pipe(m_device);
12803 pipe.AddColorAttachment();
12804 pipe.AddShader(&vs);
12805 pipe.AddShader(&fs);
12806
12807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12808 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12809 m_errorMonitor->VerifyFound();
12810
12811 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12812}
12813
12814TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12815 TEST_DESCRIPTION(
12816 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12817
12818 ASSERT_NO_FATAL_FAILURE(InitState());
12819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12820
12821 const char *feature_not_enabled_message =
12822 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12823
12824 // Some awkward steps are required to test with custom device features.
12825 std::vector<const char *> device_extension_names;
12826 auto features = m_device->phy().features();
12827 // Disable support for 64 bit floats
12828 features.shaderFloat64 = false;
12829 // The sacrificial device object
12830 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12831
12832 char const *vsSource = "#version 450\n"
12833 "\n"
12834 "out gl_PerVertex {\n"
12835 " vec4 gl_Position;\n"
12836 "};\n"
12837 "void main(){\n"
12838 " gl_Position = vec4(1);\n"
12839 "}\n";
12840 char const *fsSource = "#version 450\n"
12841 "\n"
12842 "layout(location=0) out vec4 color;\n"
12843 "void main(){\n"
12844 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12845 " color = vec4(green);\n"
12846 "}\n";
12847
12848 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12849 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12850
12851 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012852
12853 VkPipelineObj pipe(&test_device);
12854 pipe.AddColorAttachment();
12855 pipe.AddShader(&vs);
12856 pipe.AddShader(&fs);
12857
12858 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12859 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12860 VkPipelineLayout pipeline_layout;
12861 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12862
12863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12864 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12865 m_errorMonitor->VerifyFound();
12866
12867 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12868}
12869
12870TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12871 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12872
12873 ASSERT_NO_FATAL_FAILURE(InitState());
12874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12875
12876 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12877
12878 char const *vsSource = "#version 450\n"
12879 "\n"
12880 "out gl_PerVertex {\n"
12881 " vec4 gl_Position;\n"
12882 "};\n"
12883 "layout(xfb_buffer = 1) out;"
12884 "void main(){\n"
12885 " gl_Position = vec4(1);\n"
12886 "}\n";
12887 char const *fsSource = "#version 450\n"
12888 "\n"
12889 "layout(location=0) out vec4 color;\n"
12890 "void main(){\n"
12891 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12892 " color = vec4(green);\n"
12893 "}\n";
12894
12895 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12896 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12897
12898 VkPipelineObj pipe(m_device);
12899 pipe.AddColorAttachment();
12900 pipe.AddShader(&vs);
12901 pipe.AddShader(&fs);
12902
12903 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12904 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12905 VkPipelineLayout pipeline_layout;
12906 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12907
12908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12909 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12910 m_errorMonitor->VerifyFound();
12911
12912 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12913}
12914
Karl Schultz6addd812016-02-02 17:17:23 -070012915TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012916 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12917 "which is not present in the outputs of the previous stage");
12918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012920
Chris Forbes59cb88d2015-05-25 11:13:13 +120012921 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012924 char const *vsSource = "#version 450\n"
12925 "\n"
12926 "out gl_PerVertex {\n"
12927 " vec4 gl_Position;\n"
12928 "};\n"
12929 "void main(){\n"
12930 " gl_Position = vec4(1);\n"
12931 "}\n";
12932 char const *fsSource = "#version 450\n"
12933 "\n"
12934 "layout(location=0) in float x;\n"
12935 "layout(location=0) out vec4 color;\n"
12936 "void main(){\n"
12937 " color = vec4(x);\n"
12938 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012939
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012942
12943 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012944 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012945 pipe.AddShader(&vs);
12946 pipe.AddShader(&fs);
12947
Chris Forbes59cb88d2015-05-25 11:13:13 +120012948 VkDescriptorSetObj descriptorSet(m_device);
12949 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012951
Tony Barbour5781e8f2015-08-04 16:23:11 -060012952 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012953
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012954 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012955}
12956
Karl Schultz6addd812016-02-02 17:17:23 -070012957TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012958 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12959 "within an interace block, which is not present in the outputs "
12960 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012962
12963 ASSERT_NO_FATAL_FAILURE(InitState());
12964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012966 char const *vsSource = "#version 450\n"
12967 "\n"
12968 "out gl_PerVertex {\n"
12969 " vec4 gl_Position;\n"
12970 "};\n"
12971 "void main(){\n"
12972 " gl_Position = vec4(1);\n"
12973 "}\n";
12974 char const *fsSource = "#version 450\n"
12975 "\n"
12976 "in block { layout(location=0) float x; } ins;\n"
12977 "layout(location=0) out vec4 color;\n"
12978 "void main(){\n"
12979 " color = vec4(ins.x);\n"
12980 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012981
12982 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12983 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12984
12985 VkPipelineObj pipe(m_device);
12986 pipe.AddColorAttachment();
12987 pipe.AddShader(&vs);
12988 pipe.AddShader(&fs);
12989
12990 VkDescriptorSetObj descriptorSet(m_device);
12991 descriptorSet.AppendDummy();
12992 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12993
12994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12995
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012996 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012997}
12998
Karl Schultz6addd812016-02-02 17:17:23 -070012999TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013000 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013001 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13003 "output arr[2] of float32' vs 'ptr to "
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013004 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013005
13006 ASSERT_NO_FATAL_FAILURE(InitState());
13007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013009 char const *vsSource = "#version 450\n"
13010 "\n"
13011 "layout(location=0) out float x[2];\n"
13012 "out gl_PerVertex {\n"
13013 " vec4 gl_Position;\n"
13014 "};\n"
13015 "void main(){\n"
13016 " x[0] = 0; x[1] = 0;\n"
13017 " gl_Position = vec4(1);\n"
13018 "}\n";
13019 char const *fsSource = "#version 450\n"
13020 "\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013021 "layout(location=0) in float x[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013022 "layout(location=0) out vec4 color;\n"
13023 "void main(){\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013024 " color = vec4(x[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013025 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013026
13027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13029
13030 VkPipelineObj pipe(m_device);
13031 pipe.AddColorAttachment();
13032 pipe.AddShader(&vs);
13033 pipe.AddShader(&fs);
13034
13035 VkDescriptorSetObj descriptorSet(m_device);
13036 descriptorSet.AppendDummy();
13037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13038
13039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013041 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013042}
13043
Karl Schultz6addd812016-02-02 17:17:23 -070013044TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013045 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013046 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013048
Chris Forbesb56af562015-05-25 11:13:17 +120013049 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 char const *vsSource = "#version 450\n"
13053 "\n"
13054 "layout(location=0) out int x;\n"
13055 "out gl_PerVertex {\n"
13056 " vec4 gl_Position;\n"
13057 "};\n"
13058 "void main(){\n"
13059 " x = 0;\n"
13060 " gl_Position = vec4(1);\n"
13061 "}\n";
13062 char const *fsSource = "#version 450\n"
13063 "\n"
13064 "layout(location=0) in float x;\n" /* VS writes int */
13065 "layout(location=0) out vec4 color;\n"
13066 "void main(){\n"
13067 " color = vec4(x);\n"
13068 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013069
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013070 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13071 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013072
13073 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013074 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013075 pipe.AddShader(&vs);
13076 pipe.AddShader(&fs);
13077
Chris Forbesb56af562015-05-25 11:13:17 +120013078 VkDescriptorSetObj descriptorSet(m_device);
13079 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013080 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013081
Tony Barbour5781e8f2015-08-04 16:23:11 -060013082 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013083
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013084 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013085}
13086
Karl Schultz6addd812016-02-02 17:17:23 -070013087TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013088 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013089 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120013090 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013092
13093 ASSERT_NO_FATAL_FAILURE(InitState());
13094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 char const *vsSource = "#version 450\n"
13097 "\n"
13098 "out block { layout(location=0) int x; } outs;\n"
13099 "out gl_PerVertex {\n"
13100 " vec4 gl_Position;\n"
13101 "};\n"
13102 "void main(){\n"
13103 " outs.x = 0;\n"
13104 " gl_Position = vec4(1);\n"
13105 "}\n";
13106 char const *fsSource = "#version 450\n"
13107 "\n"
13108 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13109 "layout(location=0) out vec4 color;\n"
13110 "void main(){\n"
13111 " color = vec4(ins.x);\n"
13112 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013113
13114 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13115 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13116
13117 VkPipelineObj pipe(m_device);
13118 pipe.AddColorAttachment();
13119 pipe.AddShader(&vs);
13120 pipe.AddShader(&fs);
13121
13122 VkDescriptorSetObj descriptorSet(m_device);
13123 descriptorSet.AppendDummy();
13124 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13125
13126 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13127
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013128 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013129}
13130
13131TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013132 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013133 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013134 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013135 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 +130013136
13137 ASSERT_NO_FATAL_FAILURE(InitState());
13138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 char const *vsSource = "#version 450\n"
13141 "\n"
13142 "out block { layout(location=1) float x; } outs;\n"
13143 "out gl_PerVertex {\n"
13144 " vec4 gl_Position;\n"
13145 "};\n"
13146 "void main(){\n"
13147 " outs.x = 0;\n"
13148 " gl_Position = vec4(1);\n"
13149 "}\n";
13150 char const *fsSource = "#version 450\n"
13151 "\n"
13152 "in block { layout(location=0) float x; } ins;\n"
13153 "layout(location=0) out vec4 color;\n"
13154 "void main(){\n"
13155 " color = vec4(ins.x);\n"
13156 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013157
13158 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13159 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13160
13161 VkPipelineObj pipe(m_device);
13162 pipe.AddColorAttachment();
13163 pipe.AddShader(&vs);
13164 pipe.AddShader(&fs);
13165
13166 VkDescriptorSetObj descriptorSet(m_device);
13167 descriptorSet.AppendDummy();
13168 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13169
13170 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13171
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013172 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013173}
13174
13175TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013176 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013177 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013178 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 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 +130013180
13181 ASSERT_NO_FATAL_FAILURE(InitState());
13182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013184 char const *vsSource = "#version 450\n"
13185 "\n"
13186 "out block { layout(location=0, component=0) float x; } outs;\n"
13187 "out gl_PerVertex {\n"
13188 " vec4 gl_Position;\n"
13189 "};\n"
13190 "void main(){\n"
13191 " outs.x = 0;\n"
13192 " gl_Position = vec4(1);\n"
13193 "}\n";
13194 char const *fsSource = "#version 450\n"
13195 "\n"
13196 "in block { layout(location=0, component=1) float x; } ins;\n"
13197 "layout(location=0) out vec4 color;\n"
13198 "void main(){\n"
13199 " color = vec4(ins.x);\n"
13200 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013201
13202 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13203 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13204
13205 VkPipelineObj pipe(m_device);
13206 pipe.AddColorAttachment();
13207 pipe.AddShader(&vs);
13208 pipe.AddShader(&fs);
13209
13210 VkDescriptorSetObj descriptorSet(m_device);
13211 descriptorSet.AppendDummy();
13212 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13213
13214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013216 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013217}
13218
Chris Forbes1f3b0152016-11-30 12:48:40 +130013219TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13220 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13221
13222 ASSERT_NO_FATAL_FAILURE(InitState());
13223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13224
13225 char const *vsSource = "#version 450\n"
13226 "layout(location=0) out mediump float x;\n"
13227 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13228 char const *fsSource = "#version 450\n"
13229 "layout(location=0) in highp float x;\n"
13230 "layout(location=0) out vec4 color;\n"
13231 "void main() { color = vec4(x); }\n";
13232
13233 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13234 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13235
13236 VkPipelineObj pipe(m_device);
13237 pipe.AddColorAttachment();
13238 pipe.AddShader(&vs);
13239 pipe.AddShader(&fs);
13240
13241 VkDescriptorSetObj descriptorSet(m_device);
13242 descriptorSet.AppendDummy();
13243 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13244
13245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13246
13247 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13248
13249 m_errorMonitor->VerifyFound();
13250}
13251
Chris Forbes870a39e2016-11-30 12:55:56 +130013252TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13253 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13254
13255 ASSERT_NO_FATAL_FAILURE(InitState());
13256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13257
13258 char const *vsSource = "#version 450\n"
13259 "out block { layout(location=0) mediump float x; };\n"
13260 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13261 char const *fsSource = "#version 450\n"
13262 "in block { layout(location=0) highp float x; };\n"
13263 "layout(location=0) out vec4 color;\n"
13264 "void main() { color = vec4(x); }\n";
13265
13266 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13267 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13268
13269 VkPipelineObj pipe(m_device);
13270 pipe.AddColorAttachment();
13271 pipe.AddShader(&vs);
13272 pipe.AddShader(&fs);
13273
13274 VkDescriptorSetObj descriptorSet(m_device);
13275 descriptorSet.AppendDummy();
13276 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13277
13278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13279
13280 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13281
13282 m_errorMonitor->VerifyFound();
13283}
13284
Karl Schultz6addd812016-02-02 17:17:23 -070013285TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013286 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13287 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013289
Chris Forbesde136e02015-05-25 11:13:28 +120013290 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013292
13293 VkVertexInputBindingDescription input_binding;
13294 memset(&input_binding, 0, sizeof(input_binding));
13295
13296 VkVertexInputAttributeDescription input_attrib;
13297 memset(&input_attrib, 0, sizeof(input_attrib));
13298 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013300 char const *vsSource = "#version 450\n"
13301 "\n"
13302 "out gl_PerVertex {\n"
13303 " vec4 gl_Position;\n"
13304 "};\n"
13305 "void main(){\n"
13306 " gl_Position = vec4(1);\n"
13307 "}\n";
13308 char const *fsSource = "#version 450\n"
13309 "\n"
13310 "layout(location=0) out vec4 color;\n"
13311 "void main(){\n"
13312 " color = vec4(1);\n"
13313 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013314
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013315 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13316 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013317
13318 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013319 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013320 pipe.AddShader(&vs);
13321 pipe.AddShader(&fs);
13322
13323 pipe.AddVertexInputBindings(&input_binding, 1);
13324 pipe.AddVertexInputAttribs(&input_attrib, 1);
13325
Chris Forbesde136e02015-05-25 11:13:28 +120013326 VkDescriptorSetObj descriptorSet(m_device);
13327 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013328 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013329
Tony Barbour5781e8f2015-08-04 16:23:11 -060013330 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013331
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013332 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013333}
13334
Karl Schultz6addd812016-02-02 17:17:23 -070013335TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013336 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13337 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013339
13340 ASSERT_NO_FATAL_FAILURE(InitState());
13341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13342
13343 VkVertexInputBindingDescription input_binding;
13344 memset(&input_binding, 0, sizeof(input_binding));
13345
13346 VkVertexInputAttributeDescription input_attrib;
13347 memset(&input_attrib, 0, sizeof(input_attrib));
13348 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013350 char const *vsSource = "#version 450\n"
13351 "\n"
13352 "layout(location=1) in float x;\n"
13353 "out gl_PerVertex {\n"
13354 " vec4 gl_Position;\n"
13355 "};\n"
13356 "void main(){\n"
13357 " gl_Position = vec4(x);\n"
13358 "}\n";
13359 char const *fsSource = "#version 450\n"
13360 "\n"
13361 "layout(location=0) out vec4 color;\n"
13362 "void main(){\n"
13363 " color = vec4(1);\n"
13364 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013365
13366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13368
13369 VkPipelineObj pipe(m_device);
13370 pipe.AddColorAttachment();
13371 pipe.AddShader(&vs);
13372 pipe.AddShader(&fs);
13373
13374 pipe.AddVertexInputBindings(&input_binding, 1);
13375 pipe.AddVertexInputAttribs(&input_attrib, 1);
13376
13377 VkDescriptorSetObj descriptorSet(m_device);
13378 descriptorSet.AppendDummy();
13379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13380
13381 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13382
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013383 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013384}
13385
Karl Schultz6addd812016-02-02 17:17:23 -070013386TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013387 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013388 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013390
Chris Forbes62e8e502015-05-25 11:13:29 +120013391 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013394 char const *vsSource = "#version 450\n"
13395 "\n"
13396 "layout(location=0) in vec4 x;\n" /* not provided */
13397 "out gl_PerVertex {\n"
13398 " vec4 gl_Position;\n"
13399 "};\n"
13400 "void main(){\n"
13401 " gl_Position = x;\n"
13402 "}\n";
13403 char const *fsSource = "#version 450\n"
13404 "\n"
13405 "layout(location=0) out vec4 color;\n"
13406 "void main(){\n"
13407 " color = vec4(1);\n"
13408 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013409
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013410 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13411 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013412
13413 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013414 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013415 pipe.AddShader(&vs);
13416 pipe.AddShader(&fs);
13417
Chris Forbes62e8e502015-05-25 11:13:29 +120013418 VkDescriptorSetObj descriptorSet(m_device);
13419 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013420 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013421
Tony Barbour5781e8f2015-08-04 16:23:11 -060013422 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013423
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013424 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013425}
13426
Karl Schultz6addd812016-02-02 17:17:23 -070013427TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013428 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13429 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013430 "vertex shader input that consumes it");
13431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "location 0 does not match vertex shader input type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013432
Chris Forbesc97d98e2015-05-25 11:13:31 +120013433 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013434 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013435
13436 VkVertexInputBindingDescription input_binding;
13437 memset(&input_binding, 0, sizeof(input_binding));
13438
13439 VkVertexInputAttributeDescription input_attrib;
13440 memset(&input_attrib, 0, sizeof(input_attrib));
13441 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 char const *vsSource = "#version 450\n"
13444 "\n"
13445 "layout(location=0) in int x;\n" /* attrib provided float */
13446 "out gl_PerVertex {\n"
13447 " vec4 gl_Position;\n"
13448 "};\n"
13449 "void main(){\n"
13450 " gl_Position = vec4(x);\n"
13451 "}\n";
13452 char const *fsSource = "#version 450\n"
13453 "\n"
13454 "layout(location=0) out vec4 color;\n"
13455 "void main(){\n"
13456 " color = vec4(1);\n"
13457 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013458
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013461
13462 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013463 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013464 pipe.AddShader(&vs);
13465 pipe.AddShader(&fs);
13466
13467 pipe.AddVertexInputBindings(&input_binding, 1);
13468 pipe.AddVertexInputAttribs(&input_attrib, 1);
13469
Chris Forbesc97d98e2015-05-25 11:13:31 +120013470 VkDescriptorSetObj descriptorSet(m_device);
13471 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013473
Tony Barbour5781e8f2015-08-04 16:23:11 -060013474 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013475
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013476 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013477}
13478
Chris Forbesc68b43c2016-04-06 11:18:47 +120013479TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013480 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13481 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13483 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013484
13485 ASSERT_NO_FATAL_FAILURE(InitState());
13486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013488 char const *vsSource = "#version 450\n"
13489 "\n"
13490 "out gl_PerVertex {\n"
13491 " vec4 gl_Position;\n"
13492 "};\n"
13493 "void main(){\n"
13494 " gl_Position = vec4(1);\n"
13495 "}\n";
13496 char const *fsSource = "#version 450\n"
13497 "\n"
13498 "layout(location=0) out vec4 color;\n"
13499 "void main(){\n"
13500 " color = vec4(1);\n"
13501 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013502
13503 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13504 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13505
13506 VkPipelineObj pipe(m_device);
13507 pipe.AddColorAttachment();
13508 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013509 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013510 pipe.AddShader(&fs);
13511
13512 VkDescriptorSetObj descriptorSet(m_device);
13513 descriptorSet.AppendDummy();
13514 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13515
13516 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13517
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013518 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013519}
13520
Chris Forbes82ff92a2016-09-09 10:50:24 +120013521TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13523 "No entrypoint found named `foo`");
13524
13525 ASSERT_NO_FATAL_FAILURE(InitState());
13526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13527
13528 char const *vsSource = "#version 450\n"
13529 "out gl_PerVertex {\n"
13530 " vec4 gl_Position;\n"
13531 "};\n"
13532 "void main(){\n"
13533 " gl_Position = vec4(0);\n"
13534 "}\n";
13535 char const *fsSource = "#version 450\n"
13536 "\n"
13537 "layout(location=0) out vec4 color;\n"
13538 "void main(){\n"
13539 " color = vec4(1);\n"
13540 "}\n";
13541
13542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13544
13545 VkPipelineObj pipe(m_device);
13546 pipe.AddColorAttachment();
13547 pipe.AddShader(&vs);
13548 pipe.AddShader(&fs);
13549
13550 VkDescriptorSetObj descriptorSet(m_device);
13551 descriptorSet.AppendDummy();
13552 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13553
13554 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13555
13556 m_errorMonitor->VerifyFound();
13557}
13558
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013559TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13560 m_errorMonitor->SetDesiredFailureMsg(
13561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13562 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13563 "uses a depth/stencil attachment");
13564
13565 ASSERT_NO_FATAL_FAILURE(InitState());
13566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13567
13568 char const *vsSource = "#version 450\n"
13569 "void main(){ gl_Position = vec4(0); }\n";
13570 char const *fsSource = "#version 450\n"
13571 "\n"
13572 "layout(location=0) out vec4 color;\n"
13573 "void main(){\n"
13574 " color = vec4(1);\n"
13575 "}\n";
13576
13577 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13578 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13579
13580 VkPipelineObj pipe(m_device);
13581 pipe.AddColorAttachment();
13582 pipe.AddShader(&vs);
13583 pipe.AddShader(&fs);
13584
13585 VkDescriptorSetObj descriptorSet(m_device);
13586 descriptorSet.AppendDummy();
13587 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13588
13589 VkAttachmentDescription attachments[] = {
13590 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13591 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13592 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13593 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13594 },
13595 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13596 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13597 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13598 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13599 },
13600 };
13601 VkAttachmentReference refs[] = {
13602 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13603 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13604 };
13605 VkSubpassDescription subpass = {
13606 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13607 1, &refs[0], nullptr, &refs[1],
13608 0, nullptr
13609 };
13610 VkRenderPassCreateInfo rpci = {
13611 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13612 0, 2, attachments, 1, &subpass, 0, nullptr
13613 };
13614 VkRenderPass rp;
13615 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13616 ASSERT_VK_SUCCESS(err);
13617
13618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13619
13620 m_errorMonitor->VerifyFound();
13621
13622 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13623}
13624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013625TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013626 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13627 "the TCS without the patch decoration, but consumed in the TES "
13628 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13630 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013631
13632 ASSERT_NO_FATAL_FAILURE(InitState());
13633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13634
Chris Forbesc1e852d2016-04-04 19:26:42 +120013635 if (!m_device->phy().features().tessellationShader) {
13636 printf("Device does not support tessellation shaders; skipped.\n");
13637 return;
13638 }
13639
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013640 char const *vsSource = "#version 450\n"
13641 "void main(){}\n";
13642 char const *tcsSource = "#version 450\n"
13643 "layout(location=0) out int x[];\n"
13644 "layout(vertices=3) out;\n"
13645 "void main(){\n"
13646 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13647 " gl_TessLevelInner[0] = 1;\n"
13648 " x[gl_InvocationID] = gl_InvocationID;\n"
13649 "}\n";
13650 char const *tesSource = "#version 450\n"
13651 "layout(triangles, equal_spacing, cw) in;\n"
13652 "layout(location=0) patch in int x;\n"
13653 "out gl_PerVertex { vec4 gl_Position; };\n"
13654 "void main(){\n"
13655 " gl_Position.xyz = gl_TessCoord;\n"
13656 " gl_Position.w = x;\n"
13657 "}\n";
13658 char const *fsSource = "#version 450\n"
13659 "layout(location=0) out vec4 color;\n"
13660 "void main(){\n"
13661 " color = vec4(1);\n"
13662 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013663
13664 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13665 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13666 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13667 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13670 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013672 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013673
13674 VkPipelineObj pipe(m_device);
13675 pipe.SetInputAssembly(&iasci);
13676 pipe.SetTessellation(&tsci);
13677 pipe.AddColorAttachment();
13678 pipe.AddShader(&vs);
13679 pipe.AddShader(&tcs);
13680 pipe.AddShader(&tes);
13681 pipe.AddShader(&fs);
13682
13683 VkDescriptorSetObj descriptorSet(m_device);
13684 descriptorSet.AppendDummy();
13685 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13686
13687 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13688
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013689 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013690}
13691
Karl Schultz6addd812016-02-02 17:17:23 -070013692TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013693 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13694 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13696 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013697
Chris Forbes280ba2c2015-06-12 11:16:41 +120013698 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013700
13701 /* Two binding descriptions for binding 0 */
13702 VkVertexInputBindingDescription input_bindings[2];
13703 memset(input_bindings, 0, sizeof(input_bindings));
13704
13705 VkVertexInputAttributeDescription input_attrib;
13706 memset(&input_attrib, 0, sizeof(input_attrib));
13707 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013709 char const *vsSource = "#version 450\n"
13710 "\n"
13711 "layout(location=0) in float x;\n" /* attrib provided float */
13712 "out gl_PerVertex {\n"
13713 " vec4 gl_Position;\n"
13714 "};\n"
13715 "void main(){\n"
13716 " gl_Position = vec4(x);\n"
13717 "}\n";
13718 char const *fsSource = "#version 450\n"
13719 "\n"
13720 "layout(location=0) out vec4 color;\n"
13721 "void main(){\n"
13722 " color = vec4(1);\n"
13723 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013724
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013725 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13726 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013727
13728 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013729 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013730 pipe.AddShader(&vs);
13731 pipe.AddShader(&fs);
13732
13733 pipe.AddVertexInputBindings(input_bindings, 2);
13734 pipe.AddVertexInputAttribs(&input_attrib, 1);
13735
Chris Forbes280ba2c2015-06-12 11:16:41 +120013736 VkDescriptorSetObj descriptorSet(m_device);
13737 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013738 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013739
Tony Barbour5781e8f2015-08-04 16:23:11 -060013740 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013741
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013742 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013743}
Chris Forbes8f68b562015-05-25 11:13:32 +120013744
Karl Schultz6addd812016-02-02 17:17:23 -070013745TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013746 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013747 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013749
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013750 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013752 char const *vsSource = "#version 450\n"
13753 "\n"
13754 "out gl_PerVertex {\n"
13755 " vec4 gl_Position;\n"
13756 "};\n"
13757 "void main(){\n"
13758 " gl_Position = vec4(1);\n"
13759 "}\n";
13760 char const *fsSource = "#version 450\n"
13761 "\n"
13762 "void main(){\n"
13763 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013764
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013767
13768 VkPipelineObj pipe(m_device);
13769 pipe.AddShader(&vs);
13770 pipe.AddShader(&fs);
13771
Chia-I Wu08accc62015-07-07 11:50:03 +080013772 /* set up CB 0, not written */
13773 pipe.AddColorAttachment();
13774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013775
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013776 VkDescriptorSetObj descriptorSet(m_device);
13777 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013778 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013779
Tony Barbour5781e8f2015-08-04 16:23:11 -060013780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013781
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013782 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013783}
13784
Karl Schultz6addd812016-02-02 17:17:23 -070013785TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013786 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013787 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013789 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013790
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013791 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013793 char const *vsSource = "#version 450\n"
13794 "\n"
13795 "out gl_PerVertex {\n"
13796 " vec4 gl_Position;\n"
13797 "};\n"
13798 "void main(){\n"
13799 " gl_Position = vec4(1);\n"
13800 "}\n";
13801 char const *fsSource = "#version 450\n"
13802 "\n"
13803 "layout(location=0) out vec4 x;\n"
13804 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13805 "void main(){\n"
13806 " x = vec4(1);\n"
13807 " y = vec4(1);\n"
13808 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013809
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013812
13813 VkPipelineObj pipe(m_device);
13814 pipe.AddShader(&vs);
13815 pipe.AddShader(&fs);
13816
Chia-I Wu08accc62015-07-07 11:50:03 +080013817 /* set up CB 0, not written */
13818 pipe.AddColorAttachment();
13819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013820 /* FS writes CB 1, but we don't configure it */
13821
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013822 VkDescriptorSetObj descriptorSet(m_device);
13823 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013824 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013825
Tony Barbour5781e8f2015-08-04 16:23:11 -060013826 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013827
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013828 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013829}
13830
Karl Schultz6addd812016-02-02 17:17:23 -070013831TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013832 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013833 "type of an fragment shader output variable, and the format of the corresponding attachment");
13834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013835
Chris Forbesa36d69e2015-05-25 11:13:44 +120013836 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013838 char const *vsSource = "#version 450\n"
13839 "\n"
13840 "out gl_PerVertex {\n"
13841 " vec4 gl_Position;\n"
13842 "};\n"
13843 "void main(){\n"
13844 " gl_Position = vec4(1);\n"
13845 "}\n";
13846 char const *fsSource = "#version 450\n"
13847 "\n"
13848 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13849 "void main(){\n"
13850 " x = ivec4(1);\n"
13851 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013852
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013855
13856 VkPipelineObj pipe(m_device);
13857 pipe.AddShader(&vs);
13858 pipe.AddShader(&fs);
13859
Chia-I Wu08accc62015-07-07 11:50:03 +080013860 /* set up CB 0; type is UNORM by default */
13861 pipe.AddColorAttachment();
13862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013863
Chris Forbesa36d69e2015-05-25 11:13:44 +120013864 VkDescriptorSetObj descriptorSet(m_device);
13865 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013866 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013867
Tony Barbour5781e8f2015-08-04 16:23:11 -060013868 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013869
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013870 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013871}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013872
Karl Schultz6addd812016-02-02 17:17:23 -070013873TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013874 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13875 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013877
Chris Forbes556c76c2015-08-14 12:04:59 +120013878 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013880 char const *vsSource = "#version 450\n"
13881 "\n"
13882 "out gl_PerVertex {\n"
13883 " vec4 gl_Position;\n"
13884 "};\n"
13885 "void main(){\n"
13886 " gl_Position = vec4(1);\n"
13887 "}\n";
13888 char const *fsSource = "#version 450\n"
13889 "\n"
13890 "layout(location=0) out vec4 x;\n"
13891 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13892 "void main(){\n"
13893 " x = vec4(bar.y);\n"
13894 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013895
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013898
Chris Forbes556c76c2015-08-14 12:04:59 +120013899 VkPipelineObj pipe(m_device);
13900 pipe.AddShader(&vs);
13901 pipe.AddShader(&fs);
13902
13903 /* set up CB 0; type is UNORM by default */
13904 pipe.AddColorAttachment();
13905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13906
13907 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013908 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013909
13910 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13911
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013912 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013913}
13914
Chris Forbes5c59e902016-02-26 16:56:09 +130013915TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013916 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13917 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013919
13920 ASSERT_NO_FATAL_FAILURE(InitState());
13921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013922 char const *vsSource = "#version 450\n"
13923 "\n"
13924 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13925 "out gl_PerVertex {\n"
13926 " vec4 gl_Position;\n"
13927 "};\n"
13928 "void main(){\n"
13929 " gl_Position = vec4(consts.x);\n"
13930 "}\n";
13931 char const *fsSource = "#version 450\n"
13932 "\n"
13933 "layout(location=0) out vec4 x;\n"
13934 "void main(){\n"
13935 " x = vec4(1);\n"
13936 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013937
13938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13940
13941 VkPipelineObj pipe(m_device);
13942 pipe.AddShader(&vs);
13943 pipe.AddShader(&fs);
13944
13945 /* set up CB 0; type is UNORM by default */
13946 pipe.AddColorAttachment();
13947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13948
13949 VkDescriptorSetObj descriptorSet(m_device);
13950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13951
13952 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13953
13954 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013955 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013956}
13957
Chris Forbes3fb17902016-08-22 14:57:55 +120013958TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13959 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13960 "which is not included in the subpass description");
13961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13962 "consumes input attachment index 0 but not provided in subpass");
13963
13964 ASSERT_NO_FATAL_FAILURE(InitState());
13965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 char const *vsSource = "#version 450\n"
13967 "\n"
13968 "out gl_PerVertex {\n"
13969 " vec4 gl_Position;\n"
13970 "};\n"
13971 "void main(){\n"
13972 " gl_Position = vec4(1);\n"
13973 "}\n";
13974 char const *fsSource = "#version 450\n"
13975 "\n"
13976 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13977 "layout(location=0) out vec4 color;\n"
13978 "void main() {\n"
13979 " color = subpassLoad(x);\n"
13980 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013981
13982 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13983 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13984
13985 VkPipelineObj pipe(m_device);
13986 pipe.AddShader(&vs);
13987 pipe.AddShader(&fs);
13988 pipe.AddColorAttachment();
13989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13992 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013993 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013995 ASSERT_VK_SUCCESS(err);
13996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013997 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013998 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013999 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014000 ASSERT_VK_SUCCESS(err);
14001
14002 // error here.
14003 pipe.CreateVKPipeline(pl, renderPass());
14004
14005 m_errorMonitor->VerifyFound();
14006
14007 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14008 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14009}
14010
Chris Forbes5a9a0472016-08-22 16:02:09 +120014011TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14012 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14013 "with a format having a different fundamental type");
14014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14015 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14016
14017 ASSERT_NO_FATAL_FAILURE(InitState());
14018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014019 char const *vsSource = "#version 450\n"
14020 "\n"
14021 "out gl_PerVertex {\n"
14022 " vec4 gl_Position;\n"
14023 "};\n"
14024 "void main(){\n"
14025 " gl_Position = vec4(1);\n"
14026 "}\n";
14027 char const *fsSource = "#version 450\n"
14028 "\n"
14029 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14030 "layout(location=0) out vec4 color;\n"
14031 "void main() {\n"
14032 " color = subpassLoad(x);\n"
14033 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014034
14035 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14036 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14037
14038 VkPipelineObj pipe(m_device);
14039 pipe.AddShader(&vs);
14040 pipe.AddShader(&fs);
14041 pipe.AddColorAttachment();
14042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14043
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014044 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14045 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014046 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014047 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014048 ASSERT_VK_SUCCESS(err);
14049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014051 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014053 ASSERT_VK_SUCCESS(err);
14054
14055 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014056 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14057 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14058 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14059 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14060 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 +120014061 };
14062 VkAttachmentReference color = {
14063 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14064 };
14065 VkAttachmentReference input = {
14066 1, VK_IMAGE_LAYOUT_GENERAL,
14067 };
14068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014069 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014071 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014072 VkRenderPass rp;
14073 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14074 ASSERT_VK_SUCCESS(err);
14075
14076 // error here.
14077 pipe.CreateVKPipeline(pl, rp);
14078
14079 m_errorMonitor->VerifyFound();
14080
14081 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14082 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14083 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14084}
14085
Chris Forbes541f7b02016-08-22 15:30:27 +120014086TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14087 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14088 "which is not included in the subpass description -- array case");
14089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014090 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014091
14092 ASSERT_NO_FATAL_FAILURE(InitState());
14093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014094 char const *vsSource = "#version 450\n"
14095 "\n"
14096 "out gl_PerVertex {\n"
14097 " vec4 gl_Position;\n"
14098 "};\n"
14099 "void main(){\n"
14100 " gl_Position = vec4(1);\n"
14101 "}\n";
14102 char const *fsSource = "#version 450\n"
14103 "\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014104 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105 "layout(location=0) out vec4 color;\n"
14106 "void main() {\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014107 " color = subpassLoad(xs[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014108 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014109
14110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14112
14113 VkPipelineObj pipe(m_device);
14114 pipe.AddShader(&vs);
14115 pipe.AddShader(&fs);
14116 pipe.AddColorAttachment();
14117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14120 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014121 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014122 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014123 ASSERT_VK_SUCCESS(err);
14124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014125 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014126 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014127 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014128 ASSERT_VK_SUCCESS(err);
14129
14130 // error here.
14131 pipe.CreateVKPipeline(pl, renderPass());
14132
14133 m_errorMonitor->VerifyFound();
14134
14135 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14136 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14137}
14138
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014139TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014140 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14141 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014143
14144 ASSERT_NO_FATAL_FAILURE(InitState());
14145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014146 char const *csSource = "#version 450\n"
14147 "\n"
14148 "layout(local_size_x=1) in;\n"
14149 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14150 "void main(){\n"
14151 " x = vec4(1);\n"
14152 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014153
14154 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14155
14156 VkDescriptorSetObj descriptorSet(m_device);
14157 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14160 nullptr,
14161 0,
14162 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14163 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14164 descriptorSet.GetPipelineLayout(),
14165 VK_NULL_HANDLE,
14166 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014167
14168 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014169 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014170
14171 m_errorMonitor->VerifyFound();
14172
14173 if (err == VK_SUCCESS) {
14174 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14175 }
14176}
14177
Chris Forbes22a9b092016-07-19 14:34:05 +120014178TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014179 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14180 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14182 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014183
14184 ASSERT_NO_FATAL_FAILURE(InitState());
14185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014186 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14187 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014188 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014189 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014190 ASSERT_VK_SUCCESS(err);
14191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014192 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014193 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014194 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014195 ASSERT_VK_SUCCESS(err);
14196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014197 char const *csSource = "#version 450\n"
14198 "\n"
14199 "layout(local_size_x=1) in;\n"
14200 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14201 "void main() {\n"
14202 " x.x = 1.0f;\n"
14203 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014204 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014206 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14207 nullptr,
14208 0,
14209 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14210 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14211 pl,
14212 VK_NULL_HANDLE,
14213 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014214
14215 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014216 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014217
14218 m_errorMonitor->VerifyFound();
14219
14220 if (err == VK_SUCCESS) {
14221 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14222 }
14223
14224 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14225 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14226}
14227
Chris Forbes50020592016-07-27 13:52:41 +120014228TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14229 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14230 "does not match the dimensionality declared in the shader");
14231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014232 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 +120014233
14234 ASSERT_NO_FATAL_FAILURE(InitState());
14235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014237 char const *vsSource = "#version 450\n"
14238 "\n"
14239 "out gl_PerVertex { vec4 gl_Position; };\n"
14240 "void main() { gl_Position = vec4(0); }\n";
14241 char const *fsSource = "#version 450\n"
14242 "\n"
14243 "layout(set=0, binding=0) uniform sampler3D s;\n"
14244 "layout(location=0) out vec4 color;\n"
14245 "void main() {\n"
14246 " color = texture(s, vec3(0));\n"
14247 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014248 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14249 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14250
14251 VkPipelineObj pipe(m_device);
14252 pipe.AddShader(&vs);
14253 pipe.AddShader(&fs);
14254 pipe.AddColorAttachment();
14255
14256 VkTextureObj texture(m_device, nullptr);
14257 VkSamplerObj sampler(m_device);
14258
14259 VkDescriptorSetObj descriptorSet(m_device);
14260 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14261 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14262
14263 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14264 ASSERT_VK_SUCCESS(err);
14265
Tony Barbour552f6c02016-12-21 14:34:07 -070014266 m_commandBuffer->BeginCommandBuffer();
14267 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014268
14269 m_commandBuffer->BindPipeline(pipe);
14270 m_commandBuffer->BindDescriptorSet(descriptorSet);
14271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014273 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014274 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014275 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14276
14277 // error produced here.
14278 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14279
14280 m_errorMonitor->VerifyFound();
14281
Tony Barbour552f6c02016-12-21 14:34:07 -070014282 m_commandBuffer->EndRenderPass();
14283 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014284}
14285
Chris Forbes5533bfc2016-07-27 14:12:34 +120014286TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14287 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14288 "are consumed via singlesample images types in the shader, or vice versa.");
14289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014291
14292 ASSERT_NO_FATAL_FAILURE(InitState());
14293 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014295 char const *vsSource = "#version 450\n"
14296 "\n"
14297 "out gl_PerVertex { vec4 gl_Position; };\n"
14298 "void main() { gl_Position = vec4(0); }\n";
14299 char const *fsSource = "#version 450\n"
14300 "\n"
14301 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14302 "layout(location=0) out vec4 color;\n"
14303 "void main() {\n"
14304 " color = texelFetch(s, ivec2(0), 0);\n"
14305 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14308
14309 VkPipelineObj pipe(m_device);
14310 pipe.AddShader(&vs);
14311 pipe.AddShader(&fs);
14312 pipe.AddColorAttachment();
14313
14314 VkTextureObj texture(m_device, nullptr);
14315 VkSamplerObj sampler(m_device);
14316
14317 VkDescriptorSetObj descriptorSet(m_device);
14318 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14319 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14320
14321 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14322 ASSERT_VK_SUCCESS(err);
14323
Tony Barbour552f6c02016-12-21 14:34:07 -070014324 m_commandBuffer->BeginCommandBuffer();
14325 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014326
14327 m_commandBuffer->BindPipeline(pipe);
14328 m_commandBuffer->BindDescriptorSet(descriptorSet);
14329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014331 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014332 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014333 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14334
14335 // error produced here.
14336 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14337
14338 m_errorMonitor->VerifyFound();
14339
Tony Barbour552f6c02016-12-21 14:34:07 -070014340 m_commandBuffer->EndRenderPass();
14341 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014342}
14343
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014344#endif // SHADER_CHECKER_TESTS
14345
14346#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014347TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014349
14350 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014351
14352 // Create an image
14353 VkImage image;
14354
Karl Schultz6addd812016-02-02 17:17:23 -070014355 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14356 const int32_t tex_width = 32;
14357 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014358
14359 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14361 image_create_info.pNext = NULL;
14362 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14363 image_create_info.format = tex_format;
14364 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014365 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014366 image_create_info.extent.depth = 1;
14367 image_create_info.mipLevels = 1;
14368 image_create_info.arrayLayers = 1;
14369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14370 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14371 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14372 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014373
14374 // Introduce error by sending down a bogus width extent
14375 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014376 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014377
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014378 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014379}
14380
Mark Youngc48c4c12016-04-11 14:26:49 -060014381TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14383 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014384
14385 ASSERT_NO_FATAL_FAILURE(InitState());
14386
14387 // Create an image
14388 VkImage image;
14389
14390 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14391 const int32_t tex_width = 32;
14392 const int32_t tex_height = 32;
14393
14394 VkImageCreateInfo image_create_info = {};
14395 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14396 image_create_info.pNext = NULL;
14397 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14398 image_create_info.format = tex_format;
14399 image_create_info.extent.width = tex_width;
14400 image_create_info.extent.height = tex_height;
14401 image_create_info.extent.depth = 1;
14402 image_create_info.mipLevels = 1;
14403 image_create_info.arrayLayers = 1;
14404 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14405 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14406 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14407 image_create_info.flags = 0;
14408
14409 // Introduce error by sending down a bogus width extent
14410 image_create_info.extent.width = 0;
14411 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14412
14413 m_errorMonitor->VerifyFound();
14414}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014415#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014416
Tobin Ehliscde08892015-09-22 10:11:37 -060014417#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014418
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014419TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14420 TEST_DESCRIPTION("Create a render pass with an attachment description "
14421 "format set to VK_FORMAT_UNDEFINED");
14422
14423 ASSERT_NO_FATAL_FAILURE(InitState());
14424 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014427
14428 VkAttachmentReference color_attach = {};
14429 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14430 color_attach.attachment = 0;
14431 VkSubpassDescription subpass = {};
14432 subpass.colorAttachmentCount = 1;
14433 subpass.pColorAttachments = &color_attach;
14434
14435 VkRenderPassCreateInfo rpci = {};
14436 rpci.subpassCount = 1;
14437 rpci.pSubpasses = &subpass;
14438 rpci.attachmentCount = 1;
14439 VkAttachmentDescription attach_desc = {};
14440 attach_desc.format = VK_FORMAT_UNDEFINED;
14441 rpci.pAttachments = &attach_desc;
14442 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14443 VkRenderPass rp;
14444 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14445
14446 m_errorMonitor->VerifyFound();
14447
14448 if (result == VK_SUCCESS) {
14449 vkDestroyRenderPass(m_device->device(), rp, NULL);
14450 }
14451}
14452
Karl Schultz6addd812016-02-02 17:17:23 -070014453TEST_F(VkLayerTest, InvalidImageView) {
14454 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014455
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014457
Tobin Ehliscde08892015-09-22 10:11:37 -060014458 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014459
Mike Stroyana3082432015-09-25 13:39:21 -060014460 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014461 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014462
Karl Schultz6addd812016-02-02 17:17:23 -070014463 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14464 const int32_t tex_width = 32;
14465 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014466
14467 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014468 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14469 image_create_info.pNext = NULL;
14470 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14471 image_create_info.format = tex_format;
14472 image_create_info.extent.width = tex_width;
14473 image_create_info.extent.height = tex_height;
14474 image_create_info.extent.depth = 1;
14475 image_create_info.mipLevels = 1;
14476 image_create_info.arrayLayers = 1;
14477 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14478 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14479 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14480 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014481
Chia-I Wuf7458c52015-10-26 21:10:41 +080014482 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014483 ASSERT_VK_SUCCESS(err);
14484
14485 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014486 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014487 image_view_create_info.image = image;
14488 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14489 image_view_create_info.format = tex_format;
14490 image_view_create_info.subresourceRange.layerCount = 1;
14491 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14492 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014493 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014494
14495 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014496 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014497
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014498 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014499 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014500}
Mike Stroyana3082432015-09-25 13:39:21 -060014501
Mark Youngd339ba32016-05-30 13:28:35 -060014502TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14503 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014505 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014506
14507 ASSERT_NO_FATAL_FAILURE(InitState());
14508
14509 // Create an image and try to create a view with no memory backing the image
14510 VkImage image;
14511
14512 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14513 const int32_t tex_width = 32;
14514 const int32_t tex_height = 32;
14515
14516 VkImageCreateInfo image_create_info = {};
14517 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14518 image_create_info.pNext = NULL;
14519 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14520 image_create_info.format = tex_format;
14521 image_create_info.extent.width = tex_width;
14522 image_create_info.extent.height = tex_height;
14523 image_create_info.extent.depth = 1;
14524 image_create_info.mipLevels = 1;
14525 image_create_info.arrayLayers = 1;
14526 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14527 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14528 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14529 image_create_info.flags = 0;
14530
14531 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14532 ASSERT_VK_SUCCESS(err);
14533
14534 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014535 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014536 image_view_create_info.image = image;
14537 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14538 image_view_create_info.format = tex_format;
14539 image_view_create_info.subresourceRange.layerCount = 1;
14540 image_view_create_info.subresourceRange.baseMipLevel = 0;
14541 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014542 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014543
14544 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014545 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014546
14547 m_errorMonitor->VerifyFound();
14548 vkDestroyImage(m_device->device(), image, NULL);
14549 // If last error is success, it still created the view, so delete it.
14550 if (err == VK_SUCCESS) {
14551 vkDestroyImageView(m_device->device(), view, NULL);
14552 }
Mark Youngd339ba32016-05-30 13:28:35 -060014553}
14554
Karl Schultz6addd812016-02-02 17:17:23 -070014555TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014556 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014558
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014559 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014560
Karl Schultz6addd812016-02-02 17:17:23 -070014561 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014562 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014563 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014564 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014565
14566 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014567 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014568 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014569 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14570 image_view_create_info.format = tex_format;
14571 image_view_create_info.subresourceRange.baseMipLevel = 0;
14572 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014573 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014574 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014575 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014576
14577 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014578 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014579
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014580 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014581}
14582
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014583TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014584 VkResult err;
14585 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014586
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014588
Mike Stroyana3082432015-09-25 13:39:21 -060014589 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014590
14591 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014592 VkImage srcImage;
14593 VkImage dstImage;
14594 VkDeviceMemory srcMem;
14595 VkDeviceMemory destMem;
14596 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014597
14598 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014599 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14600 image_create_info.pNext = NULL;
14601 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14602 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14603 image_create_info.extent.width = 32;
14604 image_create_info.extent.height = 32;
14605 image_create_info.extent.depth = 1;
14606 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014607 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014608 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14609 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14610 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14611 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014613 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014614 ASSERT_VK_SUCCESS(err);
14615
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014617 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014618 ASSERT_VK_SUCCESS(err);
14619
14620 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014621 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014622 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14623 memAlloc.pNext = NULL;
14624 memAlloc.allocationSize = 0;
14625 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014626
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014627 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014628 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014629 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014630 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014631 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014632 ASSERT_VK_SUCCESS(err);
14633
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014634 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014635 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014636 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014637 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014638 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014639 ASSERT_VK_SUCCESS(err);
14640
14641 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14642 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014643 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014644 ASSERT_VK_SUCCESS(err);
14645
Tony Barbour552f6c02016-12-21 14:34:07 -070014646 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014647 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014648 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014649 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014650 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014651 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014652 copyRegion.srcOffset.x = 0;
14653 copyRegion.srcOffset.y = 0;
14654 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014655 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014656 copyRegion.dstSubresource.mipLevel = 0;
14657 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014658 // Introduce failure by forcing the dst layerCount to differ from src
14659 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014660 copyRegion.dstOffset.x = 0;
14661 copyRegion.dstOffset.y = 0;
14662 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014663 copyRegion.extent.width = 1;
14664 copyRegion.extent.height = 1;
14665 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014666 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014667 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014668
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014669 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014670
Chia-I Wuf7458c52015-10-26 21:10:41 +080014671 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014672 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014673 vkFreeMemory(m_device->device(), srcMem, NULL);
14674 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014675}
14676
Tony Barbourd6673642016-05-05 14:46:39 -060014677TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14678
14679 TEST_DESCRIPTION("Creating images with unsuported formats ");
14680
14681 ASSERT_NO_FATAL_FAILURE(InitState());
14682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14683 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014684 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 -060014685 VK_IMAGE_TILING_OPTIMAL, 0);
14686 ASSERT_TRUE(image.initialized());
14687
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014688 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014689 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014690 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014691 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14692 image_create_info.format = VK_FORMAT_UNDEFINED;
14693 image_create_info.extent.width = 32;
14694 image_create_info.extent.height = 32;
14695 image_create_info.extent.depth = 1;
14696 image_create_info.mipLevels = 1;
14697 image_create_info.arrayLayers = 1;
14698 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14699 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14700 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14703 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014704
14705 VkImage localImage;
14706 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14707 m_errorMonitor->VerifyFound();
14708
Tony Barbourd6673642016-05-05 14:46:39 -060014709 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014710 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014711 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14712 VkFormat format = static_cast<VkFormat>(f);
14713 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014714 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014715 unsupported = format;
14716 break;
14717 }
14718 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014719
Tony Barbourd6673642016-05-05 14:46:39 -060014720 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014721 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014723
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014724 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014725 m_errorMonitor->VerifyFound();
14726 }
14727}
14728
14729TEST_F(VkLayerTest, ImageLayerViewTests) {
14730 VkResult ret;
14731 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14732
14733 ASSERT_NO_FATAL_FAILURE(InitState());
14734
14735 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014736 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 -060014737 VK_IMAGE_TILING_OPTIMAL, 0);
14738 ASSERT_TRUE(image.initialized());
14739
14740 VkImageView imgView;
14741 VkImageViewCreateInfo imgViewInfo = {};
14742 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14743 imgViewInfo.image = image.handle();
14744 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14745 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14746 imgViewInfo.subresourceRange.layerCount = 1;
14747 imgViewInfo.subresourceRange.baseMipLevel = 0;
14748 imgViewInfo.subresourceRange.levelCount = 1;
14749 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14750
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014752 // View can't have baseMipLevel >= image's mipLevels - Expect
14753 // VIEW_CREATE_ERROR
14754 imgViewInfo.subresourceRange.baseMipLevel = 1;
14755 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14756 m_errorMonitor->VerifyFound();
14757 imgViewInfo.subresourceRange.baseMipLevel = 0;
14758
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014760 // View can't have baseArrayLayer >= image's arraySize - Expect
14761 // VIEW_CREATE_ERROR
14762 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14763 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14764 m_errorMonitor->VerifyFound();
14765 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14768 "pCreateInfo->subresourceRange."
14769 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014770 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14771 imgViewInfo.subresourceRange.levelCount = 0;
14772 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14773 m_errorMonitor->VerifyFound();
14774 imgViewInfo.subresourceRange.levelCount = 1;
14775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14777 "pCreateInfo->subresourceRange."
14778 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014779 m_errorMonitor->SetDesiredFailureMsg(
14780 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14781 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014782 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14783 imgViewInfo.subresourceRange.layerCount = 0;
14784 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14785 m_errorMonitor->VerifyFound();
14786 imgViewInfo.subresourceRange.layerCount = 1;
14787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14790 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14791 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014792 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14793 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14794 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14795 m_errorMonitor->VerifyFound();
14796 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14797
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014799 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14800 // VIEW_CREATE_ERROR
14801 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14802 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14803 m_errorMonitor->VerifyFound();
14804 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14805
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014807 // TODO: Update framework to easily passing mutable flag into ImageObj init
14808 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014809 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14810 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14811 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014812 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14813 // VIEW_CREATE_ERROR
14814 VkImageCreateInfo mutImgInfo = image.create_info();
14815 VkImage mutImage;
14816 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014817 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014818 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14819 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14820 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14821 ASSERT_VK_SUCCESS(ret);
14822 imgViewInfo.image = mutImage;
14823 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14824 m_errorMonitor->VerifyFound();
14825 imgViewInfo.image = image.handle();
14826 vkDestroyImage(m_device->handle(), mutImage, NULL);
14827}
14828
14829TEST_F(VkLayerTest, MiscImageLayerTests) {
14830
14831 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14832
14833 ASSERT_NO_FATAL_FAILURE(InitState());
14834
Rene Lindsay135204f2016-12-22 17:11:09 -070014835 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014836 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014837 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14838 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014839 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014840 vk_testing::Buffer buffer;
14841 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014842 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014843 VkBufferImageCopy region = {};
14844 region.bufferRowLength = 128;
14845 region.bufferImageHeight = 128;
14846 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14847 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014848 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014849 region.imageExtent.height = 4;
14850 region.imageExtent.width = 4;
14851 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014852
14853 VkImageObj image2(m_device);
14854 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14855 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14856 ASSERT_TRUE(image2.initialized());
14857 vk_testing::Buffer buffer2;
14858 VkMemoryPropertyFlags reqs2 = 0;
14859 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14860 VkBufferImageCopy region2 = {};
14861 region2.bufferRowLength = 128;
14862 region2.bufferImageHeight = 128;
14863 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14864 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14865 region2.imageSubresource.layerCount = 1;
14866 region2.imageExtent.height = 4;
14867 region2.imageExtent.width = 4;
14868 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014869 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014870
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014871 // Image must have offset.z of 0 and extent.depth of 1
14872 // Introduce failure by setting imageExtent.depth to 0
14873 region.imageExtent.depth = 0;
14874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14875 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14876 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14877 m_errorMonitor->VerifyFound();
14878
14879 region.imageExtent.depth = 1;
14880
14881 // Image must have offset.z of 0 and extent.depth of 1
14882 // Introduce failure by setting imageOffset.z to 4
14883 region.imageOffset.z = 4;
14884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14885 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14886 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14887 m_errorMonitor->VerifyFound();
14888
14889 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014890 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14891 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014892 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014894 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14895 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014896 m_errorMonitor->VerifyFound();
14897
14898 // BufferOffset must be a multiple of 4
14899 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014900 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014902 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14903 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014904 m_errorMonitor->VerifyFound();
14905
14906 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14907 region.bufferOffset = 0;
14908 region.imageExtent.height = 128;
14909 region.imageExtent.width = 128;
14910 // Introduce failure by setting bufferRowLength > 0 but less than width
14911 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014913 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14914 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014915 m_errorMonitor->VerifyFound();
14916
14917 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14918 region.bufferRowLength = 128;
14919 // Introduce failure by setting bufferRowHeight > 0 but less than height
14920 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014922 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14923 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014924 m_errorMonitor->VerifyFound();
14925
14926 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014928 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014929 // Expect INVALID_FILTER
14930 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014931 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14932 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014933 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014934 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14935 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014936 VkImageBlit blitRegion = {};
14937 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14938 blitRegion.srcSubresource.baseArrayLayer = 0;
14939 blitRegion.srcSubresource.layerCount = 1;
14940 blitRegion.srcSubresource.mipLevel = 0;
14941 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14942 blitRegion.dstSubresource.baseArrayLayer = 0;
14943 blitRegion.dstSubresource.layerCount = 1;
14944 blitRegion.dstSubresource.mipLevel = 0;
14945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014946 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014947 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014948 m_errorMonitor->VerifyFound();
14949
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014950 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14952 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14953 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014954 m_errorMonitor->VerifyFound();
14955
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014957 VkImageMemoryBarrier img_barrier;
14958 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14959 img_barrier.pNext = NULL;
14960 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14961 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14962 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14963 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14964 img_barrier.image = image.handle();
14965 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14966 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14967 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14968 img_barrier.subresourceRange.baseArrayLayer = 0;
14969 img_barrier.subresourceRange.baseMipLevel = 0;
14970 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14971 img_barrier.subresourceRange.layerCount = 0;
14972 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014973 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14974 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014975 m_errorMonitor->VerifyFound();
14976 img_barrier.subresourceRange.layerCount = 1;
14977}
14978
14979TEST_F(VkLayerTest, ImageFormatLimits) {
14980
14981 TEST_DESCRIPTION("Exceed the limits of image format ");
14982
Cody Northropc31a84f2016-08-22 10:41:47 -060014983 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014985 VkImageCreateInfo image_create_info = {};
14986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14987 image_create_info.pNext = NULL;
14988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14989 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14990 image_create_info.extent.width = 32;
14991 image_create_info.extent.height = 32;
14992 image_create_info.extent.depth = 1;
14993 image_create_info.mipLevels = 1;
14994 image_create_info.arrayLayers = 1;
14995 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14996 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14997 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14998 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14999 image_create_info.flags = 0;
15000
15001 VkImage nullImg;
15002 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15004 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015005 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015006 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15007 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15008 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015009 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015012 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15013 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15014 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15015 m_errorMonitor->VerifyFound();
15016 image_create_info.mipLevels = 1;
15017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015019 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15020 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15021 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15022 m_errorMonitor->VerifyFound();
15023 image_create_info.arrayLayers = 1;
15024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015026 int samples = imgFmtProps.sampleCounts >> 1;
15027 image_create_info.samples = (VkSampleCountFlagBits)samples;
15028 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15029 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15030 m_errorMonitor->VerifyFound();
15031 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
15034 "VK_IMAGE_LAYOUT_UNDEFINED or "
15035 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015036 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15037 // Expect INVALID_LAYOUT
15038 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15039 m_errorMonitor->VerifyFound();
15040 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15041}
15042
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015043TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
15044
15045 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015047
15048 ASSERT_NO_FATAL_FAILURE(InitState());
15049
15050 VkImageObj src_image(m_device);
15051 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15052 VkImageObj dst_image(m_device);
15053 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15054
Tony Barbour552f6c02016-12-21 14:34:07 -070015055 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015056 VkImageCopy copy_region;
15057 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15058 copy_region.srcSubresource.mipLevel = 0;
15059 copy_region.srcSubresource.baseArrayLayer = 0;
15060 copy_region.srcSubresource.layerCount = 0;
15061 copy_region.srcOffset.x = 0;
15062 copy_region.srcOffset.y = 0;
15063 copy_region.srcOffset.z = 0;
15064 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15065 copy_region.dstSubresource.mipLevel = 0;
15066 copy_region.dstSubresource.baseArrayLayer = 0;
15067 copy_region.dstSubresource.layerCount = 0;
15068 copy_region.dstOffset.x = 0;
15069 copy_region.dstOffset.y = 0;
15070 copy_region.dstOffset.z = 0;
15071 copy_region.extent.width = 64;
15072 copy_region.extent.height = 64;
15073 copy_region.extent.depth = 1;
15074 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15075 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015076 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015077
15078 m_errorMonitor->VerifyFound();
15079}
15080
15081TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
15082
15083 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015085
15086 ASSERT_NO_FATAL_FAILURE(InitState());
15087
15088 VkImageObj src_image(m_device);
15089 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15090 VkImageObj dst_image(m_device);
15091 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15092
Tony Barbour552f6c02016-12-21 14:34:07 -070015093 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015094 VkImageCopy copy_region;
15095 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15096 copy_region.srcSubresource.mipLevel = 0;
15097 copy_region.srcSubresource.baseArrayLayer = 0;
15098 copy_region.srcSubresource.layerCount = 0;
15099 copy_region.srcOffset.x = 0;
15100 copy_region.srcOffset.y = 0;
15101 copy_region.srcOffset.z = 0;
15102 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15103 copy_region.dstSubresource.mipLevel = 0;
15104 copy_region.dstSubresource.baseArrayLayer = 0;
15105 copy_region.dstSubresource.layerCount = 0;
15106 copy_region.dstOffset.x = 0;
15107 copy_region.dstOffset.y = 0;
15108 copy_region.dstOffset.z = 0;
15109 copy_region.extent.width = 64;
15110 copy_region.extent.height = 64;
15111 copy_region.extent.depth = 1;
15112 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15113 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015114 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015115
15116 m_errorMonitor->VerifyFound();
15117}
15118
Karl Schultz6addd812016-02-02 17:17:23 -070015119TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015120 VkResult err;
15121 bool pass;
15122
15123 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015125
15126 ASSERT_NO_FATAL_FAILURE(InitState());
15127
15128 // Create two images of different types and try to copy between them
15129 VkImage srcImage;
15130 VkImage dstImage;
15131 VkDeviceMemory srcMem;
15132 VkDeviceMemory destMem;
15133 VkMemoryRequirements memReqs;
15134
15135 VkImageCreateInfo image_create_info = {};
15136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15137 image_create_info.pNext = NULL;
15138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15139 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15140 image_create_info.extent.width = 32;
15141 image_create_info.extent.height = 32;
15142 image_create_info.extent.depth = 1;
15143 image_create_info.mipLevels = 1;
15144 image_create_info.arrayLayers = 1;
15145 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15146 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15147 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15148 image_create_info.flags = 0;
15149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015150 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015151 ASSERT_VK_SUCCESS(err);
15152
15153 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15154 // Introduce failure by creating second image with a different-sized format.
15155 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15156
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015157 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015158 ASSERT_VK_SUCCESS(err);
15159
15160 // Allocate memory
15161 VkMemoryAllocateInfo memAlloc = {};
15162 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15163 memAlloc.pNext = NULL;
15164 memAlloc.allocationSize = 0;
15165 memAlloc.memoryTypeIndex = 0;
15166
15167 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15168 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015169 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015170 ASSERT_TRUE(pass);
15171 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15172 ASSERT_VK_SUCCESS(err);
15173
15174 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15175 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015176 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015177 ASSERT_TRUE(pass);
15178 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15179 ASSERT_VK_SUCCESS(err);
15180
15181 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15182 ASSERT_VK_SUCCESS(err);
15183 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15184 ASSERT_VK_SUCCESS(err);
15185
Tony Barbour552f6c02016-12-21 14:34:07 -070015186 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015187 VkImageCopy copyRegion;
15188 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15189 copyRegion.srcSubresource.mipLevel = 0;
15190 copyRegion.srcSubresource.baseArrayLayer = 0;
15191 copyRegion.srcSubresource.layerCount = 0;
15192 copyRegion.srcOffset.x = 0;
15193 copyRegion.srcOffset.y = 0;
15194 copyRegion.srcOffset.z = 0;
15195 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15196 copyRegion.dstSubresource.mipLevel = 0;
15197 copyRegion.dstSubresource.baseArrayLayer = 0;
15198 copyRegion.dstSubresource.layerCount = 0;
15199 copyRegion.dstOffset.x = 0;
15200 copyRegion.dstOffset.y = 0;
15201 copyRegion.dstOffset.z = 0;
15202 copyRegion.extent.width = 1;
15203 copyRegion.extent.height = 1;
15204 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015206 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015207
15208 m_errorMonitor->VerifyFound();
15209
15210 vkDestroyImage(m_device->device(), srcImage, NULL);
15211 vkDestroyImage(m_device->device(), dstImage, NULL);
15212 vkFreeMemory(m_device->device(), srcMem, NULL);
15213 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015214}
15215
Karl Schultz6addd812016-02-02 17:17:23 -070015216TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15217 VkResult err;
15218 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015219
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015220 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15222 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015223
Mike Stroyana3082432015-09-25 13:39:21 -060015224 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015225
15226 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015227 VkImage srcImage;
15228 VkImage dstImage;
15229 VkDeviceMemory srcMem;
15230 VkDeviceMemory destMem;
15231 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015232
15233 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015234 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15235 image_create_info.pNext = NULL;
15236 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15237 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15238 image_create_info.extent.width = 32;
15239 image_create_info.extent.height = 32;
15240 image_create_info.extent.depth = 1;
15241 image_create_info.mipLevels = 1;
15242 image_create_info.arrayLayers = 1;
15243 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15244 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15245 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15246 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015248 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015249 ASSERT_VK_SUCCESS(err);
15250
Karl Schultzbdb75952016-04-19 11:36:49 -060015251 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15252
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015253 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015254 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015255 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015256 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015258 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015259 ASSERT_VK_SUCCESS(err);
15260
15261 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015262 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015263 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15264 memAlloc.pNext = NULL;
15265 memAlloc.allocationSize = 0;
15266 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015267
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015268 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015269 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015271 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015272 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015273 ASSERT_VK_SUCCESS(err);
15274
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015275 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015276 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015277 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015278 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015279 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015280 ASSERT_VK_SUCCESS(err);
15281
15282 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15283 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015284 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015285 ASSERT_VK_SUCCESS(err);
15286
Tony Barbour552f6c02016-12-21 14:34:07 -070015287 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015288 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015289 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015290 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015291 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015292 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015293 copyRegion.srcOffset.x = 0;
15294 copyRegion.srcOffset.y = 0;
15295 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015296 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015297 copyRegion.dstSubresource.mipLevel = 0;
15298 copyRegion.dstSubresource.baseArrayLayer = 0;
15299 copyRegion.dstSubresource.layerCount = 0;
15300 copyRegion.dstOffset.x = 0;
15301 copyRegion.dstOffset.y = 0;
15302 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015303 copyRegion.extent.width = 1;
15304 copyRegion.extent.height = 1;
15305 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015307 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015309 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015310
Chia-I Wuf7458c52015-10-26 21:10:41 +080015311 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015312 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015313 vkFreeMemory(m_device->device(), srcMem, NULL);
15314 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015315}
15316
Karl Schultz6addd812016-02-02 17:17:23 -070015317TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15318 VkResult err;
15319 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15322 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015323
Mike Stroyana3082432015-09-25 13:39:21 -060015324 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015325
15326 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015327 VkImage srcImage;
15328 VkImage dstImage;
15329 VkDeviceMemory srcMem;
15330 VkDeviceMemory destMem;
15331 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015332
15333 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015334 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15335 image_create_info.pNext = NULL;
15336 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15337 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15338 image_create_info.extent.width = 32;
15339 image_create_info.extent.height = 1;
15340 image_create_info.extent.depth = 1;
15341 image_create_info.mipLevels = 1;
15342 image_create_info.arrayLayers = 1;
15343 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15344 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15346 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015348 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015349 ASSERT_VK_SUCCESS(err);
15350
Karl Schultz6addd812016-02-02 17:17:23 -070015351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015354 ASSERT_VK_SUCCESS(err);
15355
15356 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015357 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015358 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15359 memAlloc.pNext = NULL;
15360 memAlloc.allocationSize = 0;
15361 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015362
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015363 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015364 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015365 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015366 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015367 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015368 ASSERT_VK_SUCCESS(err);
15369
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015370 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015371 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015372 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015373 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015374 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015375 ASSERT_VK_SUCCESS(err);
15376
15377 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15378 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015379 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015380 ASSERT_VK_SUCCESS(err);
15381
Tony Barbour552f6c02016-12-21 14:34:07 -070015382 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015383 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015384 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15385 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015386 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015387 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015388 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015389 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015390 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015391 resolveRegion.srcOffset.x = 0;
15392 resolveRegion.srcOffset.y = 0;
15393 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015394 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015395 resolveRegion.dstSubresource.mipLevel = 0;
15396 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015397 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015398 resolveRegion.dstOffset.x = 0;
15399 resolveRegion.dstOffset.y = 0;
15400 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015401 resolveRegion.extent.width = 1;
15402 resolveRegion.extent.height = 1;
15403 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015404 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015405 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015406
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015407 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015408
Chia-I Wuf7458c52015-10-26 21:10:41 +080015409 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015410 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015411 vkFreeMemory(m_device->device(), srcMem, NULL);
15412 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015413}
15414
Karl Schultz6addd812016-02-02 17:17:23 -070015415TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15416 VkResult err;
15417 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15420 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015421
Mike Stroyana3082432015-09-25 13:39:21 -060015422 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015423
Chris Forbesa7530692016-05-08 12:35:39 +120015424 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015425 VkImage srcImage;
15426 VkImage dstImage;
15427 VkDeviceMemory srcMem;
15428 VkDeviceMemory destMem;
15429 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015430
15431 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015432 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15433 image_create_info.pNext = NULL;
15434 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15435 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15436 image_create_info.extent.width = 32;
15437 image_create_info.extent.height = 1;
15438 image_create_info.extent.depth = 1;
15439 image_create_info.mipLevels = 1;
15440 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015441 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015442 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15443 // Note: Some implementations expect color attachment usage for any
15444 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015446 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015448 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015449 ASSERT_VK_SUCCESS(err);
15450
Karl Schultz6addd812016-02-02 17:17:23 -070015451 // Note: Some implementations expect color attachment usage for any
15452 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015453 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015455 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015456 ASSERT_VK_SUCCESS(err);
15457
15458 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015459 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015460 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15461 memAlloc.pNext = NULL;
15462 memAlloc.allocationSize = 0;
15463 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015464
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015465 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015466 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015467 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015468 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015469 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015470 ASSERT_VK_SUCCESS(err);
15471
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015472 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015473 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015474 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015475 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015476 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015477 ASSERT_VK_SUCCESS(err);
15478
15479 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15480 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015481 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015482 ASSERT_VK_SUCCESS(err);
15483
Tony Barbour552f6c02016-12-21 14:34:07 -070015484 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015485 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015486 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15487 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015488 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015489 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015490 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015491 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015492 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015493 resolveRegion.srcOffset.x = 0;
15494 resolveRegion.srcOffset.y = 0;
15495 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015496 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015497 resolveRegion.dstSubresource.mipLevel = 0;
15498 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015499 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015500 resolveRegion.dstOffset.x = 0;
15501 resolveRegion.dstOffset.y = 0;
15502 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015503 resolveRegion.extent.width = 1;
15504 resolveRegion.extent.height = 1;
15505 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015506 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015507 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015509 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015510
Chia-I Wuf7458c52015-10-26 21:10:41 +080015511 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015512 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015513 vkFreeMemory(m_device->device(), srcMem, NULL);
15514 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015515}
15516
Karl Schultz6addd812016-02-02 17:17:23 -070015517TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15518 VkResult err;
15519 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15522 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015523
Mike Stroyana3082432015-09-25 13:39:21 -060015524 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015525
15526 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015527 VkImage srcImage;
15528 VkImage dstImage;
15529 VkDeviceMemory srcMem;
15530 VkDeviceMemory destMem;
15531 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015532
15533 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15535 image_create_info.pNext = NULL;
15536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15537 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15538 image_create_info.extent.width = 32;
15539 image_create_info.extent.height = 1;
15540 image_create_info.extent.depth = 1;
15541 image_create_info.mipLevels = 1;
15542 image_create_info.arrayLayers = 1;
15543 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15544 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15545 // Note: Some implementations expect color attachment usage for any
15546 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015547 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015548 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015550 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015551 ASSERT_VK_SUCCESS(err);
15552
Karl Schultz6addd812016-02-02 17:17:23 -070015553 // Set format to something other than source image
15554 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15555 // Note: Some implementations expect color attachment usage for any
15556 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015557 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015558 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015560 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015561 ASSERT_VK_SUCCESS(err);
15562
15563 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015564 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015565 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15566 memAlloc.pNext = NULL;
15567 memAlloc.allocationSize = 0;
15568 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015569
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015570 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015571 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015572 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015573 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015574 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015575 ASSERT_VK_SUCCESS(err);
15576
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015577 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015578 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015580 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015581 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015582 ASSERT_VK_SUCCESS(err);
15583
15584 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15585 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015586 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015587 ASSERT_VK_SUCCESS(err);
15588
Tony Barbour552f6c02016-12-21 14:34:07 -070015589 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015590 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015591 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15592 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015593 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015594 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015595 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015596 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015597 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015598 resolveRegion.srcOffset.x = 0;
15599 resolveRegion.srcOffset.y = 0;
15600 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015601 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015602 resolveRegion.dstSubresource.mipLevel = 0;
15603 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015604 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015605 resolveRegion.dstOffset.x = 0;
15606 resolveRegion.dstOffset.y = 0;
15607 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015608 resolveRegion.extent.width = 1;
15609 resolveRegion.extent.height = 1;
15610 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015611 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015612 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015614 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015615
Chia-I Wuf7458c52015-10-26 21:10:41 +080015616 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015617 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015618 vkFreeMemory(m_device->device(), srcMem, NULL);
15619 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015620}
15621
Karl Schultz6addd812016-02-02 17:17:23 -070015622TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15623 VkResult err;
15624 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15627 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015628
Mike Stroyana3082432015-09-25 13:39:21 -060015629 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015630
15631 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015632 VkImage srcImage;
15633 VkImage dstImage;
15634 VkDeviceMemory srcMem;
15635 VkDeviceMemory destMem;
15636 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015637
15638 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015639 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15640 image_create_info.pNext = NULL;
15641 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15642 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15643 image_create_info.extent.width = 32;
15644 image_create_info.extent.height = 1;
15645 image_create_info.extent.depth = 1;
15646 image_create_info.mipLevels = 1;
15647 image_create_info.arrayLayers = 1;
15648 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15649 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15650 // Note: Some implementations expect color attachment usage for any
15651 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015652 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015653 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015656 ASSERT_VK_SUCCESS(err);
15657
Karl Schultz6addd812016-02-02 17:17:23 -070015658 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15659 // Note: Some implementations expect color attachment usage for any
15660 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015661 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015662 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015664 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015665 ASSERT_VK_SUCCESS(err);
15666
15667 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015668 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015669 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15670 memAlloc.pNext = NULL;
15671 memAlloc.allocationSize = 0;
15672 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015673
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015674 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015675 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015676 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015677 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015678 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015679 ASSERT_VK_SUCCESS(err);
15680
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015681 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015682 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015683 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015684 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015685 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015686 ASSERT_VK_SUCCESS(err);
15687
15688 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15689 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015690 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015691 ASSERT_VK_SUCCESS(err);
15692
Tony Barbour552f6c02016-12-21 14:34:07 -070015693 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015694 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015695 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15696 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015697 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015698 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015699 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015700 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015701 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015702 resolveRegion.srcOffset.x = 0;
15703 resolveRegion.srcOffset.y = 0;
15704 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015705 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015706 resolveRegion.dstSubresource.mipLevel = 0;
15707 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015708 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015709 resolveRegion.dstOffset.x = 0;
15710 resolveRegion.dstOffset.y = 0;
15711 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015712 resolveRegion.extent.width = 1;
15713 resolveRegion.extent.height = 1;
15714 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015715 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015716 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015718 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015719
Chia-I Wuf7458c52015-10-26 21:10:41 +080015720 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015721 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015722 vkFreeMemory(m_device->device(), srcMem, NULL);
15723 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015724}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015725
Karl Schultz6addd812016-02-02 17:17:23 -070015726TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015727 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015728 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15729 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015730 // The image format check comes 2nd in validation so we trigger it first,
15731 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015732 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15735 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015736
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015737 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015738
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015739 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015740 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15741 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015742
15743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15745 ds_pool_ci.pNext = NULL;
15746 ds_pool_ci.maxSets = 1;
15747 ds_pool_ci.poolSizeCount = 1;
15748 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015749
15750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015752 ASSERT_VK_SUCCESS(err);
15753
15754 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015755 dsl_binding.binding = 0;
15756 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15757 dsl_binding.descriptorCount = 1;
15758 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15759 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015760
15761 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015762 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15763 ds_layout_ci.pNext = NULL;
15764 ds_layout_ci.bindingCount = 1;
15765 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015768 ASSERT_VK_SUCCESS(err);
15769
15770 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015771 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015772 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015773 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015774 alloc_info.descriptorPool = ds_pool;
15775 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015777 ASSERT_VK_SUCCESS(err);
15778
Karl Schultz6addd812016-02-02 17:17:23 -070015779 VkImage image_bad;
15780 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015781 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015782 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015783 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015784 const int32_t tex_width = 32;
15785 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015786
15787 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015788 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15789 image_create_info.pNext = NULL;
15790 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15791 image_create_info.format = tex_format_bad;
15792 image_create_info.extent.width = tex_width;
15793 image_create_info.extent.height = tex_height;
15794 image_create_info.extent.depth = 1;
15795 image_create_info.mipLevels = 1;
15796 image_create_info.arrayLayers = 1;
15797 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15798 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015799 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015800 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015801
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015802 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015803 ASSERT_VK_SUCCESS(err);
15804 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015805 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15806 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015807 ASSERT_VK_SUCCESS(err);
15808
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015809 // ---Bind image memory---
15810 VkMemoryRequirements img_mem_reqs;
15811 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15812 VkMemoryAllocateInfo image_alloc_info = {};
15813 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15814 image_alloc_info.pNext = NULL;
15815 image_alloc_info.memoryTypeIndex = 0;
15816 image_alloc_info.allocationSize = img_mem_reqs.size;
15817 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15818 ASSERT_TRUE(pass);
15819 VkDeviceMemory mem;
15820 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15821 ASSERT_VK_SUCCESS(err);
15822 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15823 ASSERT_VK_SUCCESS(err);
15824 // -----------------------
15825
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015826 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015827 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015828 image_view_create_info.image = image_bad;
15829 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15830 image_view_create_info.format = tex_format_bad;
15831 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15832 image_view_create_info.subresourceRange.baseMipLevel = 0;
15833 image_view_create_info.subresourceRange.layerCount = 1;
15834 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015835 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015836
15837 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015838 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015840 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015841
Chia-I Wuf7458c52015-10-26 21:10:41 +080015842 vkDestroyImage(m_device->device(), image_bad, NULL);
15843 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15845 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015846
15847 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015848}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015849
15850TEST_F(VkLayerTest, ClearImageErrors) {
15851 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15852 "ClearDepthStencilImage with a color image.");
15853
15854 ASSERT_NO_FATAL_FAILURE(InitState());
15855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15856
Tony Barbour552f6c02016-12-21 14:34:07 -070015857 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015858
15859 // Color image
15860 VkClearColorValue clear_color;
15861 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15862 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15863 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15864 const int32_t img_width = 32;
15865 const int32_t img_height = 32;
15866 VkImageCreateInfo image_create_info = {};
15867 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15868 image_create_info.pNext = NULL;
15869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15870 image_create_info.format = color_format;
15871 image_create_info.extent.width = img_width;
15872 image_create_info.extent.height = img_height;
15873 image_create_info.extent.depth = 1;
15874 image_create_info.mipLevels = 1;
15875 image_create_info.arrayLayers = 1;
15876 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15877 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15878 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15879
15880 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015881 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015883 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015884
15885 // Depth/Stencil image
15886 VkClearDepthStencilValue clear_value = {0};
15887 reqs = 0; // don't need HOST_VISIBLE DS image
15888 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15889 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15890 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15891 ds_image_create_info.extent.width = 64;
15892 ds_image_create_info.extent.height = 64;
15893 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015894 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015895
15896 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015897 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015899 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 -060015900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015902
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015903 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015904 &color_range);
15905
15906 m_errorMonitor->VerifyFound();
15907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15909 "image created without "
15910 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015911
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015912 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015913 &color_range);
15914
15915 m_errorMonitor->VerifyFound();
15916
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015917 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15919 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015920
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015921 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015922 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015923
15924 m_errorMonitor->VerifyFound();
15925}
Tobin Ehliscde08892015-09-22 10:11:37 -060015926#endif // IMAGE_TESTS
15927
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015928
15929// WSI Enabled Tests
15930//
Chris Forbes09368e42016-10-13 11:59:22 +130015931#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015932TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15933
15934#if defined(VK_USE_PLATFORM_XCB_KHR)
15935 VkSurfaceKHR surface = VK_NULL_HANDLE;
15936
15937 VkResult err;
15938 bool pass;
15939 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15940 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15941 // uint32_t swapchain_image_count = 0;
15942 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15943 // uint32_t image_index = 0;
15944 // VkPresentInfoKHR present_info = {};
15945
15946 ASSERT_NO_FATAL_FAILURE(InitState());
15947
15948 // Use the create function from one of the VK_KHR_*_surface extension in
15949 // order to create a surface, testing all known errors in the process,
15950 // before successfully creating a surface:
15951 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15953 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15954 pass = (err != VK_SUCCESS);
15955 ASSERT_TRUE(pass);
15956 m_errorMonitor->VerifyFound();
15957
15958 // Next, try to create a surface with the wrong
15959 // VkXcbSurfaceCreateInfoKHR::sType:
15960 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15961 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15963 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15964 pass = (err != VK_SUCCESS);
15965 ASSERT_TRUE(pass);
15966 m_errorMonitor->VerifyFound();
15967
15968 // Create a native window, and then correctly create a surface:
15969 xcb_connection_t *connection;
15970 xcb_screen_t *screen;
15971 xcb_window_t xcb_window;
15972 xcb_intern_atom_reply_t *atom_wm_delete_window;
15973
15974 const xcb_setup_t *setup;
15975 xcb_screen_iterator_t iter;
15976 int scr;
15977 uint32_t value_mask, value_list[32];
15978 int width = 1;
15979 int height = 1;
15980
15981 connection = xcb_connect(NULL, &scr);
15982 ASSERT_TRUE(connection != NULL);
15983 setup = xcb_get_setup(connection);
15984 iter = xcb_setup_roots_iterator(setup);
15985 while (scr-- > 0)
15986 xcb_screen_next(&iter);
15987 screen = iter.data;
15988
15989 xcb_window = xcb_generate_id(connection);
15990
15991 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15992 value_list[0] = screen->black_pixel;
15993 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15994
15995 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15996 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15997
15998 /* Magic code that will send notification when window is destroyed */
15999 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16000 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16001
16002 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16003 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16004 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16005 free(reply);
16006
16007 xcb_map_window(connection, xcb_window);
16008
16009 // Force the x/y coordinates to 100,100 results are identical in consecutive
16010 // runs
16011 const uint32_t coords[] = { 100, 100 };
16012 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16013
16014 // Finally, try to correctly create a surface:
16015 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16016 xcb_create_info.pNext = NULL;
16017 xcb_create_info.flags = 0;
16018 xcb_create_info.connection = connection;
16019 xcb_create_info.window = xcb_window;
16020 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16021 pass = (err == VK_SUCCESS);
16022 ASSERT_TRUE(pass);
16023
16024 // Check if surface supports presentation:
16025
16026 // 1st, do so without having queried the queue families:
16027 VkBool32 supported = false;
16028 // TODO: Get the following error to come out:
16029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16030 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16031 "function");
16032 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16033 pass = (err != VK_SUCCESS);
16034 // ASSERT_TRUE(pass);
16035 // m_errorMonitor->VerifyFound();
16036
16037 // Next, query a queue family index that's too large:
16038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16039 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16040 pass = (err != VK_SUCCESS);
16041 ASSERT_TRUE(pass);
16042 m_errorMonitor->VerifyFound();
16043
16044 // Finally, do so correctly:
16045 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16046 // SUPPORTED
16047 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16048 pass = (err == VK_SUCCESS);
16049 ASSERT_TRUE(pass);
16050
16051 // Before proceeding, try to create a swapchain without having called
16052 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16053 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16054 swapchain_create_info.pNext = NULL;
16055 swapchain_create_info.flags = 0;
16056 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16057 swapchain_create_info.surface = surface;
16058 swapchain_create_info.imageArrayLayers = 1;
16059 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16060 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16062 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16063 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16064 pass = (err != VK_SUCCESS);
16065 ASSERT_TRUE(pass);
16066 m_errorMonitor->VerifyFound();
16067
16068 // Get the surface capabilities:
16069 VkSurfaceCapabilitiesKHR surface_capabilities;
16070
16071 // Do so correctly (only error logged by this entrypoint is if the
16072 // extension isn't enabled):
16073 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16074 pass = (err == VK_SUCCESS);
16075 ASSERT_TRUE(pass);
16076
16077 // Get the surface formats:
16078 uint32_t surface_format_count;
16079
16080 // First, try without a pointer to surface_format_count:
16081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16082 "specified as NULL");
16083 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16084 pass = (err == VK_SUCCESS);
16085 ASSERT_TRUE(pass);
16086 m_errorMonitor->VerifyFound();
16087
16088 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16089 // correctly done a 1st try (to get the count):
16090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16091 surface_format_count = 0;
16092 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16093 pass = (err == VK_SUCCESS);
16094 ASSERT_TRUE(pass);
16095 m_errorMonitor->VerifyFound();
16096
16097 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16098 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16099 pass = (err == VK_SUCCESS);
16100 ASSERT_TRUE(pass);
16101
16102 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16103 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16104
16105 // Next, do a 2nd try with surface_format_count being set too high:
16106 surface_format_count += 5;
16107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16108 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16109 pass = (err == VK_SUCCESS);
16110 ASSERT_TRUE(pass);
16111 m_errorMonitor->VerifyFound();
16112
16113 // Finally, do a correct 1st and 2nd try:
16114 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16115 pass = (err == VK_SUCCESS);
16116 ASSERT_TRUE(pass);
16117 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16118 pass = (err == VK_SUCCESS);
16119 ASSERT_TRUE(pass);
16120
16121 // Get the surface present modes:
16122 uint32_t surface_present_mode_count;
16123
16124 // First, try without a pointer to surface_format_count:
16125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16126 "specified as NULL");
16127
16128 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16129 pass = (err == VK_SUCCESS);
16130 ASSERT_TRUE(pass);
16131 m_errorMonitor->VerifyFound();
16132
16133 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16134 // correctly done a 1st try (to get the count):
16135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16136 surface_present_mode_count = 0;
16137 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16138 (VkPresentModeKHR *)&surface_present_mode_count);
16139 pass = (err == VK_SUCCESS);
16140 ASSERT_TRUE(pass);
16141 m_errorMonitor->VerifyFound();
16142
16143 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16144 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16145 pass = (err == VK_SUCCESS);
16146 ASSERT_TRUE(pass);
16147
16148 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16149 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16150
16151 // Next, do a 2nd try with surface_format_count being set too high:
16152 surface_present_mode_count += 5;
16153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16154 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16155 pass = (err == VK_SUCCESS);
16156 ASSERT_TRUE(pass);
16157 m_errorMonitor->VerifyFound();
16158
16159 // Finally, do a correct 1st and 2nd try:
16160 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16161 pass = (err == VK_SUCCESS);
16162 ASSERT_TRUE(pass);
16163 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16164 pass = (err == VK_SUCCESS);
16165 ASSERT_TRUE(pass);
16166
16167 // Create a swapchain:
16168
16169 // First, try without a pointer to swapchain_create_info:
16170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16171 "specified as NULL");
16172
16173 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16174 pass = (err != VK_SUCCESS);
16175 ASSERT_TRUE(pass);
16176 m_errorMonitor->VerifyFound();
16177
16178 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16179 // sType:
16180 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16182
16183 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16184 pass = (err != VK_SUCCESS);
16185 ASSERT_TRUE(pass);
16186 m_errorMonitor->VerifyFound();
16187
16188 // Next, call with a NULL swapchain pointer:
16189 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16190 swapchain_create_info.pNext = NULL;
16191 swapchain_create_info.flags = 0;
16192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16193 "specified as NULL");
16194
16195 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16196 pass = (err != VK_SUCCESS);
16197 ASSERT_TRUE(pass);
16198 m_errorMonitor->VerifyFound();
16199
16200 // TODO: Enhance swapchain layer so that
16201 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16202
16203 // Next, call with a queue family index that's too large:
16204 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16205 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16206 swapchain_create_info.queueFamilyIndexCount = 2;
16207 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16209 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16210 pass = (err != VK_SUCCESS);
16211 ASSERT_TRUE(pass);
16212 m_errorMonitor->VerifyFound();
16213
16214 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16215 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16216 swapchain_create_info.queueFamilyIndexCount = 1;
16217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16218 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16219 "pCreateInfo->pQueueFamilyIndices).");
16220 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16221 pass = (err != VK_SUCCESS);
16222 ASSERT_TRUE(pass);
16223 m_errorMonitor->VerifyFound();
16224
16225 // Next, call with an invalid imageSharingMode:
16226 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16227 swapchain_create_info.queueFamilyIndexCount = 1;
16228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16229 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16230 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16231 pass = (err != VK_SUCCESS);
16232 ASSERT_TRUE(pass);
16233 m_errorMonitor->VerifyFound();
16234 // Fix for the future:
16235 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16236 // SUPPORTED
16237 swapchain_create_info.queueFamilyIndexCount = 0;
16238 queueFamilyIndex[0] = 0;
16239 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16240
16241 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16242 // Get the images from a swapchain:
16243 // Acquire an image from a swapchain:
16244 // Present an image to a swapchain:
16245 // Destroy the swapchain:
16246
16247 // TODOs:
16248 //
16249 // - Try destroying the device without first destroying the swapchain
16250 //
16251 // - Try destroying the device without first destroying the surface
16252 //
16253 // - Try destroying the surface without first destroying the swapchain
16254
16255 // Destroy the surface:
16256 vkDestroySurfaceKHR(instance(), surface, NULL);
16257
16258 // Tear down the window:
16259 xcb_destroy_window(connection, xcb_window);
16260 xcb_disconnect(connection);
16261
16262#else // VK_USE_PLATFORM_XCB_KHR
16263 return;
16264#endif // VK_USE_PLATFORM_XCB_KHR
16265}
Chris Forbes09368e42016-10-13 11:59:22 +130016266#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016267
16268//
16269// POSITIVE VALIDATION TESTS
16270//
16271// These tests do not expect to encounter ANY validation errors pass only if this is true
16272
Tobin Ehlise0006882016-11-03 10:14:28 -060016273TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16274 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16275 "by a transition in the primary.");
16276 VkResult err;
16277 m_errorMonitor->ExpectSuccess();
16278 ASSERT_NO_FATAL_FAILURE(InitState());
16279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16280 // Allocate a secondary and primary cmd buffer
16281 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16282 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16283 command_buffer_allocate_info.commandPool = m_commandPool;
16284 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16285 command_buffer_allocate_info.commandBufferCount = 1;
16286
16287 VkCommandBuffer secondary_command_buffer;
16288 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16289 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16290 VkCommandBuffer primary_command_buffer;
16291 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16292 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16293 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16294 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16295 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16296 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16297 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16298
16299 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16300 ASSERT_VK_SUCCESS(err);
16301 VkImageObj image(m_device);
16302 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16303 ASSERT_TRUE(image.initialized());
16304 VkImageMemoryBarrier img_barrier = {};
16305 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16306 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16307 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16308 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16309 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16310 img_barrier.image = image.handle();
16311 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16312 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16313 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16314 img_barrier.subresourceRange.baseArrayLayer = 0;
16315 img_barrier.subresourceRange.baseMipLevel = 0;
16316 img_barrier.subresourceRange.layerCount = 1;
16317 img_barrier.subresourceRange.levelCount = 1;
16318 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16319 0, nullptr, 1, &img_barrier);
16320 err = vkEndCommandBuffer(secondary_command_buffer);
16321 ASSERT_VK_SUCCESS(err);
16322
16323 // Now update primary cmd buffer to execute secondary and transitions image
16324 command_buffer_begin_info.pInheritanceInfo = nullptr;
16325 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16326 ASSERT_VK_SUCCESS(err);
16327 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16328 VkImageMemoryBarrier img_barrier2 = {};
16329 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16330 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16331 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16332 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16333 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16334 img_barrier2.image = image.handle();
16335 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16336 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16337 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16338 img_barrier2.subresourceRange.baseArrayLayer = 0;
16339 img_barrier2.subresourceRange.baseMipLevel = 0;
16340 img_barrier2.subresourceRange.layerCount = 1;
16341 img_barrier2.subresourceRange.levelCount = 1;
16342 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16343 nullptr, 1, &img_barrier2);
16344 err = vkEndCommandBuffer(primary_command_buffer);
16345 ASSERT_VK_SUCCESS(err);
16346 VkSubmitInfo submit_info = {};
16347 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16348 submit_info.commandBufferCount = 1;
16349 submit_info.pCommandBuffers = &primary_command_buffer;
16350 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16351 ASSERT_VK_SUCCESS(err);
16352 m_errorMonitor->VerifyNotFound();
16353 err = vkDeviceWaitIdle(m_device->device());
16354 ASSERT_VK_SUCCESS(err);
16355 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16356 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16357}
16358
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016359// This is a positive test. No failures are expected.
16360TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16361 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16362 "is ignoring VkWriteDescriptorSet members that are not "
16363 "related to the descriptor type specified by "
16364 "VkWriteDescriptorSet::descriptorType. Correct "
16365 "validation behavior will result in the test running to "
16366 "completion without validation errors.");
16367
16368 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16369
16370 ASSERT_NO_FATAL_FAILURE(InitState());
16371
16372 // Image Case
16373 {
16374 m_errorMonitor->ExpectSuccess();
16375
16376 VkImage image;
16377 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16378 const int32_t tex_width = 32;
16379 const int32_t tex_height = 32;
16380 VkImageCreateInfo image_create_info = {};
16381 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16382 image_create_info.pNext = NULL;
16383 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16384 image_create_info.format = tex_format;
16385 image_create_info.extent.width = tex_width;
16386 image_create_info.extent.height = tex_height;
16387 image_create_info.extent.depth = 1;
16388 image_create_info.mipLevels = 1;
16389 image_create_info.arrayLayers = 1;
16390 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16391 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16392 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16393 image_create_info.flags = 0;
16394 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16395 ASSERT_VK_SUCCESS(err);
16396
16397 VkMemoryRequirements memory_reqs;
16398 VkDeviceMemory image_memory;
16399 bool pass;
16400 VkMemoryAllocateInfo memory_info = {};
16401 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16402 memory_info.pNext = NULL;
16403 memory_info.allocationSize = 0;
16404 memory_info.memoryTypeIndex = 0;
16405 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16406 memory_info.allocationSize = memory_reqs.size;
16407 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16408 ASSERT_TRUE(pass);
16409 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16410 ASSERT_VK_SUCCESS(err);
16411 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16412 ASSERT_VK_SUCCESS(err);
16413
16414 VkImageViewCreateInfo image_view_create_info = {};
16415 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16416 image_view_create_info.image = image;
16417 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16418 image_view_create_info.format = tex_format;
16419 image_view_create_info.subresourceRange.layerCount = 1;
16420 image_view_create_info.subresourceRange.baseMipLevel = 0;
16421 image_view_create_info.subresourceRange.levelCount = 1;
16422 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16423
16424 VkImageView view;
16425 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16426 ASSERT_VK_SUCCESS(err);
16427
16428 VkDescriptorPoolSize ds_type_count = {};
16429 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16430 ds_type_count.descriptorCount = 1;
16431
16432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16434 ds_pool_ci.pNext = NULL;
16435 ds_pool_ci.maxSets = 1;
16436 ds_pool_ci.poolSizeCount = 1;
16437 ds_pool_ci.pPoolSizes = &ds_type_count;
16438
16439 VkDescriptorPool ds_pool;
16440 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16441 ASSERT_VK_SUCCESS(err);
16442
16443 VkDescriptorSetLayoutBinding dsl_binding = {};
16444 dsl_binding.binding = 0;
16445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16446 dsl_binding.descriptorCount = 1;
16447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16448 dsl_binding.pImmutableSamplers = NULL;
16449
16450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16452 ds_layout_ci.pNext = NULL;
16453 ds_layout_ci.bindingCount = 1;
16454 ds_layout_ci.pBindings = &dsl_binding;
16455 VkDescriptorSetLayout ds_layout;
16456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16457 ASSERT_VK_SUCCESS(err);
16458
16459 VkDescriptorSet descriptor_set;
16460 VkDescriptorSetAllocateInfo alloc_info = {};
16461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16462 alloc_info.descriptorSetCount = 1;
16463 alloc_info.descriptorPool = ds_pool;
16464 alloc_info.pSetLayouts = &ds_layout;
16465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16466 ASSERT_VK_SUCCESS(err);
16467
16468 VkDescriptorImageInfo image_info = {};
16469 image_info.imageView = view;
16470 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16471
16472 VkWriteDescriptorSet descriptor_write;
16473 memset(&descriptor_write, 0, sizeof(descriptor_write));
16474 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16475 descriptor_write.dstSet = descriptor_set;
16476 descriptor_write.dstBinding = 0;
16477 descriptor_write.descriptorCount = 1;
16478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16479 descriptor_write.pImageInfo = &image_info;
16480
16481 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16482 // be
16483 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16484 // This will most likely produce a crash if the parameter_validation
16485 // layer
16486 // does not correctly ignore pBufferInfo.
16487 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16488 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16489
16490 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16491
16492 m_errorMonitor->VerifyNotFound();
16493
16494 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16495 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16496 vkDestroyImageView(m_device->device(), view, NULL);
16497 vkDestroyImage(m_device->device(), image, NULL);
16498 vkFreeMemory(m_device->device(), image_memory, NULL);
16499 }
16500
16501 // Buffer Case
16502 {
16503 m_errorMonitor->ExpectSuccess();
16504
16505 VkBuffer buffer;
16506 uint32_t queue_family_index = 0;
16507 VkBufferCreateInfo buffer_create_info = {};
16508 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16509 buffer_create_info.size = 1024;
16510 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16511 buffer_create_info.queueFamilyIndexCount = 1;
16512 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16513
16514 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16515 ASSERT_VK_SUCCESS(err);
16516
16517 VkMemoryRequirements memory_reqs;
16518 VkDeviceMemory buffer_memory;
16519 bool pass;
16520 VkMemoryAllocateInfo memory_info = {};
16521 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16522 memory_info.pNext = NULL;
16523 memory_info.allocationSize = 0;
16524 memory_info.memoryTypeIndex = 0;
16525
16526 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16527 memory_info.allocationSize = memory_reqs.size;
16528 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16529 ASSERT_TRUE(pass);
16530
16531 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16532 ASSERT_VK_SUCCESS(err);
16533 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16534 ASSERT_VK_SUCCESS(err);
16535
16536 VkDescriptorPoolSize ds_type_count = {};
16537 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16538 ds_type_count.descriptorCount = 1;
16539
16540 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16541 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16542 ds_pool_ci.pNext = NULL;
16543 ds_pool_ci.maxSets = 1;
16544 ds_pool_ci.poolSizeCount = 1;
16545 ds_pool_ci.pPoolSizes = &ds_type_count;
16546
16547 VkDescriptorPool ds_pool;
16548 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16549 ASSERT_VK_SUCCESS(err);
16550
16551 VkDescriptorSetLayoutBinding dsl_binding = {};
16552 dsl_binding.binding = 0;
16553 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16554 dsl_binding.descriptorCount = 1;
16555 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16556 dsl_binding.pImmutableSamplers = NULL;
16557
16558 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16559 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16560 ds_layout_ci.pNext = NULL;
16561 ds_layout_ci.bindingCount = 1;
16562 ds_layout_ci.pBindings = &dsl_binding;
16563 VkDescriptorSetLayout ds_layout;
16564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16565 ASSERT_VK_SUCCESS(err);
16566
16567 VkDescriptorSet descriptor_set;
16568 VkDescriptorSetAllocateInfo alloc_info = {};
16569 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16570 alloc_info.descriptorSetCount = 1;
16571 alloc_info.descriptorPool = ds_pool;
16572 alloc_info.pSetLayouts = &ds_layout;
16573 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16574 ASSERT_VK_SUCCESS(err);
16575
16576 VkDescriptorBufferInfo buffer_info = {};
16577 buffer_info.buffer = buffer;
16578 buffer_info.offset = 0;
16579 buffer_info.range = 1024;
16580
16581 VkWriteDescriptorSet descriptor_write;
16582 memset(&descriptor_write, 0, sizeof(descriptor_write));
16583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16584 descriptor_write.dstSet = descriptor_set;
16585 descriptor_write.dstBinding = 0;
16586 descriptor_write.descriptorCount = 1;
16587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16588 descriptor_write.pBufferInfo = &buffer_info;
16589
16590 // Set pImageInfo and pTexelBufferView to invalid values, which should
16591 // be
16592 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16593 // This will most likely produce a crash if the parameter_validation
16594 // layer
16595 // does not correctly ignore pImageInfo.
16596 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16597 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16598
16599 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16600
16601 m_errorMonitor->VerifyNotFound();
16602
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16604 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16605 vkDestroyBuffer(m_device->device(), buffer, NULL);
16606 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16607 }
16608
16609 // Texel Buffer Case
16610 {
16611 m_errorMonitor->ExpectSuccess();
16612
16613 VkBuffer buffer;
16614 uint32_t queue_family_index = 0;
16615 VkBufferCreateInfo buffer_create_info = {};
16616 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16617 buffer_create_info.size = 1024;
16618 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16619 buffer_create_info.queueFamilyIndexCount = 1;
16620 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16621
16622 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16623 ASSERT_VK_SUCCESS(err);
16624
16625 VkMemoryRequirements memory_reqs;
16626 VkDeviceMemory buffer_memory;
16627 bool pass;
16628 VkMemoryAllocateInfo memory_info = {};
16629 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16630 memory_info.pNext = NULL;
16631 memory_info.allocationSize = 0;
16632 memory_info.memoryTypeIndex = 0;
16633
16634 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16635 memory_info.allocationSize = memory_reqs.size;
16636 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16637 ASSERT_TRUE(pass);
16638
16639 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16640 ASSERT_VK_SUCCESS(err);
16641 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16642 ASSERT_VK_SUCCESS(err);
16643
16644 VkBufferViewCreateInfo buff_view_ci = {};
16645 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16646 buff_view_ci.buffer = buffer;
16647 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16648 buff_view_ci.range = VK_WHOLE_SIZE;
16649 VkBufferView buffer_view;
16650 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16651
16652 VkDescriptorPoolSize ds_type_count = {};
16653 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16654 ds_type_count.descriptorCount = 1;
16655
16656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16658 ds_pool_ci.pNext = NULL;
16659 ds_pool_ci.maxSets = 1;
16660 ds_pool_ci.poolSizeCount = 1;
16661 ds_pool_ci.pPoolSizes = &ds_type_count;
16662
16663 VkDescriptorPool ds_pool;
16664 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16665 ASSERT_VK_SUCCESS(err);
16666
16667 VkDescriptorSetLayoutBinding dsl_binding = {};
16668 dsl_binding.binding = 0;
16669 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16670 dsl_binding.descriptorCount = 1;
16671 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16672 dsl_binding.pImmutableSamplers = NULL;
16673
16674 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16675 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16676 ds_layout_ci.pNext = NULL;
16677 ds_layout_ci.bindingCount = 1;
16678 ds_layout_ci.pBindings = &dsl_binding;
16679 VkDescriptorSetLayout ds_layout;
16680 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16681 ASSERT_VK_SUCCESS(err);
16682
16683 VkDescriptorSet descriptor_set;
16684 VkDescriptorSetAllocateInfo alloc_info = {};
16685 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16686 alloc_info.descriptorSetCount = 1;
16687 alloc_info.descriptorPool = ds_pool;
16688 alloc_info.pSetLayouts = &ds_layout;
16689 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16690 ASSERT_VK_SUCCESS(err);
16691
16692 VkWriteDescriptorSet descriptor_write;
16693 memset(&descriptor_write, 0, sizeof(descriptor_write));
16694 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16695 descriptor_write.dstSet = descriptor_set;
16696 descriptor_write.dstBinding = 0;
16697 descriptor_write.descriptorCount = 1;
16698 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16699 descriptor_write.pTexelBufferView = &buffer_view;
16700
16701 // Set pImageInfo and pBufferInfo to invalid values, which should be
16702 // ignored for descriptorType ==
16703 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16704 // This will most likely produce a crash if the parameter_validation
16705 // layer
16706 // does not correctly ignore pImageInfo and pBufferInfo.
16707 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16708 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16709
16710 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16711
16712 m_errorMonitor->VerifyNotFound();
16713
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16715 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16716 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16717 vkDestroyBuffer(m_device->device(), buffer, NULL);
16718 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16719 }
16720}
16721
Tobin Ehlisf7428442016-10-25 07:58:24 -060016722TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16723 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16724
16725 ASSERT_NO_FATAL_FAILURE(InitState());
16726 // Create layout where two binding #s are "1"
16727 static const uint32_t NUM_BINDINGS = 3;
16728 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16729 dsl_binding[0].binding = 1;
16730 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16731 dsl_binding[0].descriptorCount = 1;
16732 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16733 dsl_binding[0].pImmutableSamplers = NULL;
16734 dsl_binding[1].binding = 0;
16735 dsl_binding[1].descriptorCount = 1;
16736 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16737 dsl_binding[1].descriptorCount = 1;
16738 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16739 dsl_binding[1].pImmutableSamplers = NULL;
16740 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16741 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16742 dsl_binding[2].descriptorCount = 1;
16743 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16744 dsl_binding[2].pImmutableSamplers = NULL;
16745
16746 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16747 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16748 ds_layout_ci.pNext = NULL;
16749 ds_layout_ci.bindingCount = NUM_BINDINGS;
16750 ds_layout_ci.pBindings = dsl_binding;
16751 VkDescriptorSetLayout ds_layout;
16752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16753 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16754 m_errorMonitor->VerifyFound();
16755}
16756
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016757TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016758 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16759
16760 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016761
Tony Barbour552f6c02016-12-21 14:34:07 -070016762 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016763
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016764 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16765
16766 {
16767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16768 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16769 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16770 m_errorMonitor->VerifyFound();
16771 }
16772
16773 {
16774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16775 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16776 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16777 m_errorMonitor->VerifyFound();
16778 }
16779
16780 {
16781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16782 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16783 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16784 m_errorMonitor->VerifyFound();
16785 }
16786
16787 {
16788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16789 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16790 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16791 m_errorMonitor->VerifyFound();
16792 }
16793
16794 {
16795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16796 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16797 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16798 m_errorMonitor->VerifyFound();
16799 }
16800
16801 {
16802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16803 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16804 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16805 m_errorMonitor->VerifyFound();
16806 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016807
16808 {
16809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16810 VkRect2D scissor = {{-1, 0}, {16, 16}};
16811 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16812 m_errorMonitor->VerifyFound();
16813 }
16814
16815 {
16816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16817 VkRect2D scissor = {{0, -2}, {16, 16}};
16818 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16819 m_errorMonitor->VerifyFound();
16820 }
16821
16822 {
16823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16824 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16825 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16826 m_errorMonitor->VerifyFound();
16827 }
16828
16829 {
16830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16831 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16832 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16833 m_errorMonitor->VerifyFound();
16834 }
16835
Tony Barbour552f6c02016-12-21 14:34:07 -070016836 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016837}
16838
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016839// This is a positive test. No failures are expected.
16840TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16841 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16842 VkResult err;
16843
16844 ASSERT_NO_FATAL_FAILURE(InitState());
16845 m_errorMonitor->ExpectSuccess();
16846 VkDescriptorPoolSize ds_type_count = {};
16847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16848 ds_type_count.descriptorCount = 2;
16849
16850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16852 ds_pool_ci.pNext = NULL;
16853 ds_pool_ci.maxSets = 1;
16854 ds_pool_ci.poolSizeCount = 1;
16855 ds_pool_ci.pPoolSizes = &ds_type_count;
16856
16857 VkDescriptorPool ds_pool;
16858 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16859 ASSERT_VK_SUCCESS(err);
16860
16861 // Create layout with two uniform buffer descriptors w/ empty binding between them
16862 static const uint32_t NUM_BINDINGS = 3;
16863 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16864 dsl_binding[0].binding = 0;
16865 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16866 dsl_binding[0].descriptorCount = 1;
16867 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16868 dsl_binding[0].pImmutableSamplers = NULL;
16869 dsl_binding[1].binding = 1;
16870 dsl_binding[1].descriptorCount = 0; // empty binding
16871 dsl_binding[2].binding = 2;
16872 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16873 dsl_binding[2].descriptorCount = 1;
16874 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16875 dsl_binding[2].pImmutableSamplers = NULL;
16876
16877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16879 ds_layout_ci.pNext = NULL;
16880 ds_layout_ci.bindingCount = NUM_BINDINGS;
16881 ds_layout_ci.pBindings = dsl_binding;
16882 VkDescriptorSetLayout ds_layout;
16883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16884 ASSERT_VK_SUCCESS(err);
16885
16886 VkDescriptorSet descriptor_set = {};
16887 VkDescriptorSetAllocateInfo alloc_info = {};
16888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16889 alloc_info.descriptorSetCount = 1;
16890 alloc_info.descriptorPool = ds_pool;
16891 alloc_info.pSetLayouts = &ds_layout;
16892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16893 ASSERT_VK_SUCCESS(err);
16894
16895 // Create a buffer to be used for update
16896 VkBufferCreateInfo buff_ci = {};
16897 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16898 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16899 buff_ci.size = 256;
16900 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16901 VkBuffer buffer;
16902 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16903 ASSERT_VK_SUCCESS(err);
16904 // Have to bind memory to buffer before descriptor update
16905 VkMemoryAllocateInfo mem_alloc = {};
16906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16907 mem_alloc.pNext = NULL;
16908 mem_alloc.allocationSize = 512; // one allocation for both buffers
16909 mem_alloc.memoryTypeIndex = 0;
16910
16911 VkMemoryRequirements mem_reqs;
16912 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16913 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16914 if (!pass) {
16915 vkDestroyBuffer(m_device->device(), buffer, NULL);
16916 return;
16917 }
16918
16919 VkDeviceMemory mem;
16920 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16921 ASSERT_VK_SUCCESS(err);
16922 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16923 ASSERT_VK_SUCCESS(err);
16924
16925 // Only update the descriptor at binding 2
16926 VkDescriptorBufferInfo buff_info = {};
16927 buff_info.buffer = buffer;
16928 buff_info.offset = 0;
16929 buff_info.range = VK_WHOLE_SIZE;
16930 VkWriteDescriptorSet descriptor_write = {};
16931 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16932 descriptor_write.dstBinding = 2;
16933 descriptor_write.descriptorCount = 1;
16934 descriptor_write.pTexelBufferView = nullptr;
16935 descriptor_write.pBufferInfo = &buff_info;
16936 descriptor_write.pImageInfo = nullptr;
16937 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16938 descriptor_write.dstSet = descriptor_set;
16939
16940 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16941
16942 m_errorMonitor->VerifyNotFound();
16943 // Cleanup
16944 vkFreeMemory(m_device->device(), mem, NULL);
16945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16946 vkDestroyBuffer(m_device->device(), buffer, NULL);
16947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16948}
16949
16950// This is a positive test. No failures are expected.
16951TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16952 VkResult err;
16953 bool pass;
16954
16955 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16956 "the buffer, create an image, and bind the same memory to "
16957 "it");
16958
16959 m_errorMonitor->ExpectSuccess();
16960
16961 ASSERT_NO_FATAL_FAILURE(InitState());
16962
16963 VkBuffer buffer;
16964 VkImage image;
16965 VkDeviceMemory mem;
16966 VkMemoryRequirements mem_reqs;
16967
16968 VkBufferCreateInfo buf_info = {};
16969 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16970 buf_info.pNext = NULL;
16971 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16972 buf_info.size = 256;
16973 buf_info.queueFamilyIndexCount = 0;
16974 buf_info.pQueueFamilyIndices = NULL;
16975 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16976 buf_info.flags = 0;
16977 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16978 ASSERT_VK_SUCCESS(err);
16979
16980 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16981
16982 VkMemoryAllocateInfo alloc_info = {};
16983 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16984 alloc_info.pNext = NULL;
16985 alloc_info.memoryTypeIndex = 0;
16986
16987 // Ensure memory is big enough for both bindings
16988 alloc_info.allocationSize = 0x10000;
16989
16990 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16991 if (!pass) {
16992 vkDestroyBuffer(m_device->device(), buffer, NULL);
16993 return;
16994 }
16995
16996 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16997 ASSERT_VK_SUCCESS(err);
16998
16999 uint8_t *pData;
17000 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17001 ASSERT_VK_SUCCESS(err);
17002
17003 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17004
17005 vkUnmapMemory(m_device->device(), mem);
17006
17007 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17008 ASSERT_VK_SUCCESS(err);
17009
17010 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17011 // memory. In fact, it was never used by the GPU.
17012 // Just be be sure, wait for idle.
17013 vkDestroyBuffer(m_device->device(), buffer, NULL);
17014 vkDeviceWaitIdle(m_device->device());
17015
Tobin Ehlis6a005702016-12-28 15:25:56 -070017016 // Use optimal as some platforms report linear support but then fail image creation
17017 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17018 VkImageFormatProperties image_format_properties;
17019 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17020 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17021 if (image_format_properties.maxExtent.width == 0) {
17022 printf("Image format not supported; skipped.\n");
17023 vkFreeMemory(m_device->device(), mem, NULL);
17024 return;
17025 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017026 VkImageCreateInfo image_create_info = {};
17027 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17028 image_create_info.pNext = NULL;
17029 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17030 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17031 image_create_info.extent.width = 64;
17032 image_create_info.extent.height = 64;
17033 image_create_info.extent.depth = 1;
17034 image_create_info.mipLevels = 1;
17035 image_create_info.arrayLayers = 1;
17036 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017037 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017038 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17039 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17040 image_create_info.queueFamilyIndexCount = 0;
17041 image_create_info.pQueueFamilyIndices = NULL;
17042 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17043 image_create_info.flags = 0;
17044
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017045 /* Create a mappable image. It will be the texture if linear images are ok
17046 * to be textures or it will be the staging image if they are not.
17047 */
17048 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17049 ASSERT_VK_SUCCESS(err);
17050
17051 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17052
Tobin Ehlis6a005702016-12-28 15:25:56 -070017053 VkMemoryAllocateInfo mem_alloc = {};
17054 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17055 mem_alloc.pNext = NULL;
17056 mem_alloc.allocationSize = 0;
17057 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017058 mem_alloc.allocationSize = mem_reqs.size;
17059
17060 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17061 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017062 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017063 vkDestroyImage(m_device->device(), image, NULL);
17064 return;
17065 }
17066
17067 // VALIDATION FAILURE:
17068 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17069 ASSERT_VK_SUCCESS(err);
17070
17071 m_errorMonitor->VerifyNotFound();
17072
17073 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017074 vkDestroyImage(m_device->device(), image, NULL);
17075}
17076
Tobin Ehlis953e8392016-11-17 10:54:13 -070017077TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17078 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17079 // We previously had a bug where dynamic offset of inactive bindings was still being used
17080 VkResult err;
17081 m_errorMonitor->ExpectSuccess();
17082
17083 ASSERT_NO_FATAL_FAILURE(InitState());
17084 ASSERT_NO_FATAL_FAILURE(InitViewport());
17085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17086
17087 VkDescriptorPoolSize ds_type_count = {};
17088 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17089 ds_type_count.descriptorCount = 3;
17090
17091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17093 ds_pool_ci.pNext = NULL;
17094 ds_pool_ci.maxSets = 1;
17095 ds_pool_ci.poolSizeCount = 1;
17096 ds_pool_ci.pPoolSizes = &ds_type_count;
17097
17098 VkDescriptorPool ds_pool;
17099 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17100 ASSERT_VK_SUCCESS(err);
17101
17102 const uint32_t BINDING_COUNT = 3;
17103 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017104 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017105 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17106 dsl_binding[0].descriptorCount = 1;
17107 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17108 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017109 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017110 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17111 dsl_binding[1].descriptorCount = 1;
17112 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17113 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017114 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017115 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17116 dsl_binding[2].descriptorCount = 1;
17117 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17118 dsl_binding[2].pImmutableSamplers = NULL;
17119
17120 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17121 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17122 ds_layout_ci.pNext = NULL;
17123 ds_layout_ci.bindingCount = BINDING_COUNT;
17124 ds_layout_ci.pBindings = dsl_binding;
17125 VkDescriptorSetLayout ds_layout;
17126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17127 ASSERT_VK_SUCCESS(err);
17128
17129 VkDescriptorSet descriptor_set;
17130 VkDescriptorSetAllocateInfo alloc_info = {};
17131 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17132 alloc_info.descriptorSetCount = 1;
17133 alloc_info.descriptorPool = ds_pool;
17134 alloc_info.pSetLayouts = &ds_layout;
17135 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17136 ASSERT_VK_SUCCESS(err);
17137
17138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17140 pipeline_layout_ci.pNext = NULL;
17141 pipeline_layout_ci.setLayoutCount = 1;
17142 pipeline_layout_ci.pSetLayouts = &ds_layout;
17143
17144 VkPipelineLayout pipeline_layout;
17145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17146 ASSERT_VK_SUCCESS(err);
17147
17148 // Create two buffers to update the descriptors with
17149 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17150 uint32_t qfi = 0;
17151 VkBufferCreateInfo buffCI = {};
17152 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17153 buffCI.size = 2048;
17154 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17155 buffCI.queueFamilyIndexCount = 1;
17156 buffCI.pQueueFamilyIndices = &qfi;
17157
17158 VkBuffer dyub1;
17159 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17160 ASSERT_VK_SUCCESS(err);
17161 // buffer2
17162 buffCI.size = 1024;
17163 VkBuffer dyub2;
17164 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17165 ASSERT_VK_SUCCESS(err);
17166 // Allocate memory and bind to buffers
17167 VkMemoryAllocateInfo mem_alloc[2] = {};
17168 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17169 mem_alloc[0].pNext = NULL;
17170 mem_alloc[0].memoryTypeIndex = 0;
17171 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17172 mem_alloc[1].pNext = NULL;
17173 mem_alloc[1].memoryTypeIndex = 0;
17174
17175 VkMemoryRequirements mem_reqs1;
17176 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17177 VkMemoryRequirements mem_reqs2;
17178 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17179 mem_alloc[0].allocationSize = mem_reqs1.size;
17180 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17181 mem_alloc[1].allocationSize = mem_reqs2.size;
17182 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17183 if (!pass) {
17184 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17185 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17186 return;
17187 }
17188
17189 VkDeviceMemory mem1;
17190 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17191 ASSERT_VK_SUCCESS(err);
17192 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17193 ASSERT_VK_SUCCESS(err);
17194 VkDeviceMemory mem2;
17195 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17196 ASSERT_VK_SUCCESS(err);
17197 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17198 ASSERT_VK_SUCCESS(err);
17199 // Update descriptors
17200 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17201 buff_info[0].buffer = dyub1;
17202 buff_info[0].offset = 0;
17203 buff_info[0].range = 256;
17204 buff_info[1].buffer = dyub1;
17205 buff_info[1].offset = 256;
17206 buff_info[1].range = 512;
17207 buff_info[2].buffer = dyub2;
17208 buff_info[2].offset = 0;
17209 buff_info[2].range = 512;
17210
17211 VkWriteDescriptorSet descriptor_write;
17212 memset(&descriptor_write, 0, sizeof(descriptor_write));
17213 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17214 descriptor_write.dstSet = descriptor_set;
17215 descriptor_write.dstBinding = 0;
17216 descriptor_write.descriptorCount = BINDING_COUNT;
17217 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17218 descriptor_write.pBufferInfo = buff_info;
17219
17220 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17221
Tony Barbour552f6c02016-12-21 14:34:07 -070017222 m_commandBuffer->BeginCommandBuffer();
17223 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017224
17225 // Create PSO to be used for draw-time errors below
17226 char const *vsSource = "#version 450\n"
17227 "\n"
17228 "out gl_PerVertex { \n"
17229 " vec4 gl_Position;\n"
17230 "};\n"
17231 "void main(){\n"
17232 " gl_Position = vec4(1);\n"
17233 "}\n";
17234 char const *fsSource = "#version 450\n"
17235 "\n"
17236 "layout(location=0) out vec4 x;\n"
17237 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17238 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17239 "void main(){\n"
17240 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17241 "}\n";
17242 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17244 VkPipelineObj pipe(m_device);
17245 pipe.SetViewport(m_viewports);
17246 pipe.SetScissor(m_scissors);
17247 pipe.AddShader(&vs);
17248 pipe.AddShader(&fs);
17249 pipe.AddColorAttachment();
17250 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17251
17252 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17253 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17254 // we used to have a bug in this case.
17255 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17257 &descriptor_set, BINDING_COUNT, dyn_off);
17258 Draw(1, 0, 0, 0);
17259 m_errorMonitor->VerifyNotFound();
17260
17261 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17262 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17263 vkFreeMemory(m_device->device(), mem1, NULL);
17264 vkFreeMemory(m_device->device(), mem2, NULL);
17265
17266 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17267 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17268 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17269}
17270
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017271TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17272
17273 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17274 "mapping while using VK_WHOLE_SIZE does not cause access "
17275 "violations");
17276 VkResult err;
17277 uint8_t *pData;
17278 ASSERT_NO_FATAL_FAILURE(InitState());
17279
17280 VkDeviceMemory mem;
17281 VkMemoryRequirements mem_reqs;
17282 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017283 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017284 VkMemoryAllocateInfo alloc_info = {};
17285 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17286 alloc_info.pNext = NULL;
17287 alloc_info.memoryTypeIndex = 0;
17288
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017289 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017290 alloc_info.allocationSize = allocation_size;
17291
17292 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17293 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17294 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17295 if (!pass) {
17296 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17297 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17298 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17299 if (!pass) {
17300 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17301 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17302 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17303 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17304 if (!pass) {
17305 return;
17306 }
17307 }
17308 }
17309
17310 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17311 ASSERT_VK_SUCCESS(err);
17312
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017313 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017314 m_errorMonitor->ExpectSuccess();
17315 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17316 ASSERT_VK_SUCCESS(err);
17317 VkMappedMemoryRange mmr = {};
17318 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17319 mmr.memory = mem;
17320 mmr.offset = 0;
17321 mmr.size = VK_WHOLE_SIZE;
17322 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17323 ASSERT_VK_SUCCESS(err);
17324 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17325 ASSERT_VK_SUCCESS(err);
17326 m_errorMonitor->VerifyNotFound();
17327 vkUnmapMemory(m_device->device(), mem);
17328
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017329 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017330 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017331 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017332 ASSERT_VK_SUCCESS(err);
17333 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17334 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017335 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017336 mmr.size = VK_WHOLE_SIZE;
17337 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17338 ASSERT_VK_SUCCESS(err);
17339 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17340 ASSERT_VK_SUCCESS(err);
17341 m_errorMonitor->VerifyNotFound();
17342 vkUnmapMemory(m_device->device(), mem);
17343
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017344 // Map with offset and size
17345 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017346 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017347 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017348 ASSERT_VK_SUCCESS(err);
17349 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17350 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017351 mmr.offset = 4 * atom_size;
17352 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017353 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17354 ASSERT_VK_SUCCESS(err);
17355 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17356 ASSERT_VK_SUCCESS(err);
17357 m_errorMonitor->VerifyNotFound();
17358 vkUnmapMemory(m_device->device(), mem);
17359
17360 // Map without offset and flush WHOLE_SIZE with two separate offsets
17361 m_errorMonitor->ExpectSuccess();
17362 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17363 ASSERT_VK_SUCCESS(err);
17364 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17365 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017366 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017367 mmr.size = VK_WHOLE_SIZE;
17368 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17369 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017370 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017371 mmr.size = VK_WHOLE_SIZE;
17372 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17373 ASSERT_VK_SUCCESS(err);
17374 m_errorMonitor->VerifyNotFound();
17375 vkUnmapMemory(m_device->device(), mem);
17376
17377 vkFreeMemory(m_device->device(), mem, NULL);
17378}
17379
17380// This is a positive test. We used to expect error in this case but spec now allows it
17381TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17382 m_errorMonitor->ExpectSuccess();
17383 vk_testing::Fence testFence;
17384 VkFenceCreateInfo fenceInfo = {};
17385 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17386 fenceInfo.pNext = NULL;
17387
17388 ASSERT_NO_FATAL_FAILURE(InitState());
17389 testFence.init(*m_device, fenceInfo);
17390 VkFence fences[1] = { testFence.handle() };
17391 VkResult result = vkResetFences(m_device->device(), 1, fences);
17392 ASSERT_VK_SUCCESS(result);
17393
17394 m_errorMonitor->VerifyNotFound();
17395}
17396
17397TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17398 m_errorMonitor->ExpectSuccess();
17399
17400 ASSERT_NO_FATAL_FAILURE(InitState());
17401 VkResult err;
17402
17403 // Record (empty!) command buffer that can be submitted multiple times
17404 // simultaneously.
17405 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17406 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17407 m_commandBuffer->BeginCommandBuffer(&cbbi);
17408 m_commandBuffer->EndCommandBuffer();
17409
17410 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17411 VkFence fence;
17412 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17413 ASSERT_VK_SUCCESS(err);
17414
17415 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17416 VkSemaphore s1, s2;
17417 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17418 ASSERT_VK_SUCCESS(err);
17419 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17420 ASSERT_VK_SUCCESS(err);
17421
17422 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17423 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17424 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17425 ASSERT_VK_SUCCESS(err);
17426
17427 // Submit CB again, signaling s2.
17428 si.pSignalSemaphores = &s2;
17429 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17430 ASSERT_VK_SUCCESS(err);
17431
17432 // Wait for fence.
17433 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17434 ASSERT_VK_SUCCESS(err);
17435
17436 // CB is still in flight from second submission, but semaphore s1 is no
17437 // longer in flight. delete it.
17438 vkDestroySemaphore(m_device->device(), s1, nullptr);
17439
17440 m_errorMonitor->VerifyNotFound();
17441
17442 // Force device idle and clean up remaining objects
17443 vkDeviceWaitIdle(m_device->device());
17444 vkDestroySemaphore(m_device->device(), s2, nullptr);
17445 vkDestroyFence(m_device->device(), fence, nullptr);
17446}
17447
17448TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17449 m_errorMonitor->ExpectSuccess();
17450
17451 ASSERT_NO_FATAL_FAILURE(InitState());
17452 VkResult err;
17453
17454 // A fence created signaled
17455 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17456 VkFence f1;
17457 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17458 ASSERT_VK_SUCCESS(err);
17459
17460 // A fence created not
17461 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17462 VkFence f2;
17463 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17464 ASSERT_VK_SUCCESS(err);
17465
17466 // Submit the unsignaled fence
17467 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17468 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17469
17470 // Wait on both fences, with signaled first.
17471 VkFence fences[] = { f1, f2 };
17472 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17473
17474 // Should have both retired!
17475 vkDestroyFence(m_device->device(), f1, nullptr);
17476 vkDestroyFence(m_device->device(), f2, nullptr);
17477
17478 m_errorMonitor->VerifyNotFound();
17479}
17480
17481TEST_F(VkPositiveLayerTest, ValidUsage) {
17482 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17483 "doesn't generate validation errors");
17484
17485 ASSERT_NO_FATAL_FAILURE(InitState());
17486
17487 m_errorMonitor->ExpectSuccess();
17488 // Verify that we can create a view with usage INPUT_ATTACHMENT
17489 VkImageObj image(m_device);
17490 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17491 ASSERT_TRUE(image.initialized());
17492 VkImageView imageView;
17493 VkImageViewCreateInfo ivci = {};
17494 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17495 ivci.image = image.handle();
17496 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17497 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17498 ivci.subresourceRange.layerCount = 1;
17499 ivci.subresourceRange.baseMipLevel = 0;
17500 ivci.subresourceRange.levelCount = 1;
17501 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17502
17503 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17504 m_errorMonitor->VerifyNotFound();
17505 vkDestroyImageView(m_device->device(), imageView, NULL);
17506}
17507
17508// This is a positive test. No failures are expected.
17509TEST_F(VkPositiveLayerTest, BindSparse) {
17510 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17511 "and then free the memory");
17512
17513 ASSERT_NO_FATAL_FAILURE(InitState());
17514
17515 auto index = m_device->graphics_queue_node_index_;
17516 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17517 return;
17518
17519 m_errorMonitor->ExpectSuccess();
17520
17521 VkImage image;
17522 VkImageCreateInfo image_create_info = {};
17523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17524 image_create_info.pNext = NULL;
17525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17526 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17527 image_create_info.extent.width = 64;
17528 image_create_info.extent.height = 64;
17529 image_create_info.extent.depth = 1;
17530 image_create_info.mipLevels = 1;
17531 image_create_info.arrayLayers = 1;
17532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17534 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17535 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17536 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17537 ASSERT_VK_SUCCESS(err);
17538
17539 VkMemoryRequirements memory_reqs;
17540 VkDeviceMemory memory_one, memory_two;
17541 bool pass;
17542 VkMemoryAllocateInfo memory_info = {};
17543 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17544 memory_info.pNext = NULL;
17545 memory_info.allocationSize = 0;
17546 memory_info.memoryTypeIndex = 0;
17547 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17548 // Find an image big enough to allow sparse mapping of 2 memory regions
17549 // Increase the image size until it is at least twice the
17550 // size of the required alignment, to ensure we can bind both
17551 // allocated memory blocks to the image on aligned offsets.
17552 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17553 vkDestroyImage(m_device->device(), image, nullptr);
17554 image_create_info.extent.width *= 2;
17555 image_create_info.extent.height *= 2;
17556 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17557 ASSERT_VK_SUCCESS(err);
17558 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17559 }
17560 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17561 // at the end of the first
17562 memory_info.allocationSize = memory_reqs.alignment;
17563 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17564 ASSERT_TRUE(pass);
17565 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17566 ASSERT_VK_SUCCESS(err);
17567 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17568 ASSERT_VK_SUCCESS(err);
17569 VkSparseMemoryBind binds[2];
17570 binds[0].flags = 0;
17571 binds[0].memory = memory_one;
17572 binds[0].memoryOffset = 0;
17573 binds[0].resourceOffset = 0;
17574 binds[0].size = memory_info.allocationSize;
17575 binds[1].flags = 0;
17576 binds[1].memory = memory_two;
17577 binds[1].memoryOffset = 0;
17578 binds[1].resourceOffset = memory_info.allocationSize;
17579 binds[1].size = memory_info.allocationSize;
17580
17581 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17582 opaqueBindInfo.image = image;
17583 opaqueBindInfo.bindCount = 2;
17584 opaqueBindInfo.pBinds = binds;
17585
17586 VkFence fence = VK_NULL_HANDLE;
17587 VkBindSparseInfo bindSparseInfo = {};
17588 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17589 bindSparseInfo.imageOpaqueBindCount = 1;
17590 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17591
17592 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17593 vkQueueWaitIdle(m_device->m_queue);
17594 vkDestroyImage(m_device->device(), image, NULL);
17595 vkFreeMemory(m_device->device(), memory_one, NULL);
17596 vkFreeMemory(m_device->device(), memory_two, NULL);
17597 m_errorMonitor->VerifyNotFound();
17598}
17599
17600TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17601 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17602 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17603 "the command buffer has prior knowledge of that "
17604 "attachment's layout.");
17605
17606 m_errorMonitor->ExpectSuccess();
17607
17608 ASSERT_NO_FATAL_FAILURE(InitState());
17609
17610 // A renderpass with one color attachment.
17611 VkAttachmentDescription attachment = { 0,
17612 VK_FORMAT_R8G8B8A8_UNORM,
17613 VK_SAMPLE_COUNT_1_BIT,
17614 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17615 VK_ATTACHMENT_STORE_OP_STORE,
17616 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17617 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17618 VK_IMAGE_LAYOUT_UNDEFINED,
17619 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17620
17621 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17622
17623 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17624
17625 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17626
17627 VkRenderPass rp;
17628 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17629 ASSERT_VK_SUCCESS(err);
17630
17631 // A compatible framebuffer.
17632 VkImageObj image(m_device);
17633 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17634 ASSERT_TRUE(image.initialized());
17635
17636 VkImageViewCreateInfo ivci = {
17637 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17638 nullptr,
17639 0,
17640 image.handle(),
17641 VK_IMAGE_VIEW_TYPE_2D,
17642 VK_FORMAT_R8G8B8A8_UNORM,
17643 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17644 VK_COMPONENT_SWIZZLE_IDENTITY },
17645 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17646 };
17647 VkImageView view;
17648 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17649 ASSERT_VK_SUCCESS(err);
17650
17651 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17652 VkFramebuffer fb;
17653 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17654 ASSERT_VK_SUCCESS(err);
17655
17656 // Record a single command buffer which uses this renderpass twice. The
17657 // bug is triggered at the beginning of the second renderpass, when the
17658 // command buffer already has a layout recorded for the attachment.
17659 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017660 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017661 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17662 vkCmdEndRenderPass(m_commandBuffer->handle());
17663 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17664
17665 m_errorMonitor->VerifyNotFound();
17666
17667 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017668 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017669
17670 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17671 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17672 vkDestroyImageView(m_device->device(), view, nullptr);
17673}
17674
17675TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17676 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17677 "command buffer, bind them together, then destroy "
17678 "command pool and framebuffer and verify there are no "
17679 "errors.");
17680
17681 m_errorMonitor->ExpectSuccess();
17682
17683 ASSERT_NO_FATAL_FAILURE(InitState());
17684
17685 // A renderpass with one color attachment.
17686 VkAttachmentDescription attachment = { 0,
17687 VK_FORMAT_R8G8B8A8_UNORM,
17688 VK_SAMPLE_COUNT_1_BIT,
17689 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17690 VK_ATTACHMENT_STORE_OP_STORE,
17691 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17692 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17693 VK_IMAGE_LAYOUT_UNDEFINED,
17694 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17695
17696 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17697
17698 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17699
17700 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17701
17702 VkRenderPass rp;
17703 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17704 ASSERT_VK_SUCCESS(err);
17705
17706 // A compatible framebuffer.
17707 VkImageObj image(m_device);
17708 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17709 ASSERT_TRUE(image.initialized());
17710
17711 VkImageViewCreateInfo ivci = {
17712 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17713 nullptr,
17714 0,
17715 image.handle(),
17716 VK_IMAGE_VIEW_TYPE_2D,
17717 VK_FORMAT_R8G8B8A8_UNORM,
17718 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17719 VK_COMPONENT_SWIZZLE_IDENTITY },
17720 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17721 };
17722 VkImageView view;
17723 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17724 ASSERT_VK_SUCCESS(err);
17725
17726 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17727 VkFramebuffer fb;
17728 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17729 ASSERT_VK_SUCCESS(err);
17730
17731 // Explicitly create a command buffer to bind the FB to so that we can then
17732 // destroy the command pool in order to implicitly free command buffer
17733 VkCommandPool command_pool;
17734 VkCommandPoolCreateInfo pool_create_info{};
17735 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17736 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17737 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17738 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17739
17740 VkCommandBuffer command_buffer;
17741 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17742 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17743 command_buffer_allocate_info.commandPool = command_pool;
17744 command_buffer_allocate_info.commandBufferCount = 1;
17745 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17746 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17747
17748 // Begin our cmd buffer with renderpass using our framebuffer
17749 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17750 VkCommandBufferBeginInfo begin_info{};
17751 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17752 vkBeginCommandBuffer(command_buffer, &begin_info);
17753
17754 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17755 vkCmdEndRenderPass(command_buffer);
17756 vkEndCommandBuffer(command_buffer);
17757 vkDestroyImageView(m_device->device(), view, nullptr);
17758 // Destroy command pool to implicitly free command buffer
17759 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17760 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17761 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17762 m_errorMonitor->VerifyNotFound();
17763}
17764
17765TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17766 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17767 "transitions for the first subpass");
17768
17769 m_errorMonitor->ExpectSuccess();
17770
17771 ASSERT_NO_FATAL_FAILURE(InitState());
17772
17773 // A renderpass with one color attachment.
17774 VkAttachmentDescription attachment = { 0,
17775 VK_FORMAT_R8G8B8A8_UNORM,
17776 VK_SAMPLE_COUNT_1_BIT,
17777 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17778 VK_ATTACHMENT_STORE_OP_STORE,
17779 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17780 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17781 VK_IMAGE_LAYOUT_UNDEFINED,
17782 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17783
17784 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17785
17786 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17787
17788 VkSubpassDependency dep = { 0,
17789 0,
17790 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17791 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17792 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17793 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17794 VK_DEPENDENCY_BY_REGION_BIT };
17795
17796 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17797
17798 VkResult err;
17799 VkRenderPass rp;
17800 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17801 ASSERT_VK_SUCCESS(err);
17802
17803 // A compatible framebuffer.
17804 VkImageObj image(m_device);
17805 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17806 ASSERT_TRUE(image.initialized());
17807
17808 VkImageViewCreateInfo ivci = {
17809 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17810 nullptr,
17811 0,
17812 image.handle(),
17813 VK_IMAGE_VIEW_TYPE_2D,
17814 VK_FORMAT_R8G8B8A8_UNORM,
17815 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17816 VK_COMPONENT_SWIZZLE_IDENTITY },
17817 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17818 };
17819 VkImageView view;
17820 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17821 ASSERT_VK_SUCCESS(err);
17822
17823 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17824 VkFramebuffer fb;
17825 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17826 ASSERT_VK_SUCCESS(err);
17827
17828 // Record a single command buffer which issues a pipeline barrier w/
17829 // image memory barrier for the attachment. This detects the previously
17830 // missing tracking of the subpass layout by throwing a validation error
17831 // if it doesn't occur.
17832 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017833 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017834 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17835
17836 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17837 nullptr,
17838 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17839 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17840 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17841 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17842 VK_QUEUE_FAMILY_IGNORED,
17843 VK_QUEUE_FAMILY_IGNORED,
17844 image.handle(),
17845 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17846 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17847 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17848 &imb);
17849
17850 vkCmdEndRenderPass(m_commandBuffer->handle());
17851 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017852 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017853
17854 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17855 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17856 vkDestroyImageView(m_device->device(), view, nullptr);
17857}
17858
17859TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17860 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17861 "is used as a depth/stencil framebuffer attachment, the "
17862 "aspectMask is ignored and both depth and stencil image "
17863 "subresources are used.");
17864
17865 VkFormatProperties format_properties;
17866 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17867 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17868 return;
17869 }
17870
17871 m_errorMonitor->ExpectSuccess();
17872
17873 ASSERT_NO_FATAL_FAILURE(InitState());
17874
17875 VkAttachmentDescription attachment = { 0,
17876 VK_FORMAT_D32_SFLOAT_S8_UINT,
17877 VK_SAMPLE_COUNT_1_BIT,
17878 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17879 VK_ATTACHMENT_STORE_OP_STORE,
17880 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17881 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17882 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17883 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17884
17885 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17886
17887 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17888
17889 VkSubpassDependency dep = { 0,
17890 0,
17891 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17892 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17893 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17894 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17895 VK_DEPENDENCY_BY_REGION_BIT};
17896
17897 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17898
17899 VkResult err;
17900 VkRenderPass rp;
17901 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17902 ASSERT_VK_SUCCESS(err);
17903
17904 VkImageObj image(m_device);
17905 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17906 0x26, // usage
17907 VK_IMAGE_TILING_OPTIMAL, 0);
17908 ASSERT_TRUE(image.initialized());
17909 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17910
17911 VkImageViewCreateInfo ivci = {
17912 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17913 nullptr,
17914 0,
17915 image.handle(),
17916 VK_IMAGE_VIEW_TYPE_2D,
17917 VK_FORMAT_D32_SFLOAT_S8_UINT,
17918 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17919 { 0x2, 0, 1, 0, 1 },
17920 };
17921 VkImageView view;
17922 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17923 ASSERT_VK_SUCCESS(err);
17924
17925 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17926 VkFramebuffer fb;
17927 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17928 ASSERT_VK_SUCCESS(err);
17929
17930 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017931 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017932 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17933
17934 VkImageMemoryBarrier imb = {};
17935 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17936 imb.pNext = nullptr;
17937 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17938 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17939 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17940 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17941 imb.srcQueueFamilyIndex = 0;
17942 imb.dstQueueFamilyIndex = 0;
17943 imb.image = image.handle();
17944 imb.subresourceRange.aspectMask = 0x6;
17945 imb.subresourceRange.baseMipLevel = 0;
17946 imb.subresourceRange.levelCount = 0x1;
17947 imb.subresourceRange.baseArrayLayer = 0;
17948 imb.subresourceRange.layerCount = 0x1;
17949
17950 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17951 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17952 &imb);
17953
17954 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017955 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017956 QueueCommandBuffer(false);
17957 m_errorMonitor->VerifyNotFound();
17958
17959 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17960 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17961 vkDestroyImageView(m_device->device(), view, nullptr);
17962}
17963
17964TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17965 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17966 "errors, when an attachment reference is "
17967 "VK_ATTACHMENT_UNUSED");
17968
17969 m_errorMonitor->ExpectSuccess();
17970
17971 ASSERT_NO_FATAL_FAILURE(InitState());
17972
17973 // A renderpass with no attachments
17974 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17975
17976 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17977
17978 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17979
17980 VkRenderPass rp;
17981 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17982 ASSERT_VK_SUCCESS(err);
17983
17984 // A compatible framebuffer.
17985 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17986 VkFramebuffer fb;
17987 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17988 ASSERT_VK_SUCCESS(err);
17989
17990 // Record a command buffer which just begins and ends the renderpass. The
17991 // bug manifests in BeginRenderPass.
17992 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
Tony Barbour552f6c02016-12-21 14:34:07 -070017993 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017994 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17995 vkCmdEndRenderPass(m_commandBuffer->handle());
17996 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017997 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017998
17999 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18000 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18001}
18002
18003// This is a positive test. No errors are expected.
18004TEST_F(VkPositiveLayerTest, StencilLoadOp) {
18005 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
18006 "CLEAR. stencil[Load|Store]Op used to be ignored.");
18007 VkResult result = VK_SUCCESS;
18008 VkImageFormatProperties formatProps;
18009 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18010 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18011 &formatProps);
18012 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18013 return;
18014 }
18015
18016 ASSERT_NO_FATAL_FAILURE(InitState());
18017 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18018 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
18019 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
18020 VkAttachmentDescription att = {};
18021 VkAttachmentReference ref = {};
18022 att.format = depth_stencil_fmt;
18023 att.samples = VK_SAMPLE_COUNT_1_BIT;
18024 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18025 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18026 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18027 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18028 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18029 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18030
18031 VkClearValue clear;
18032 clear.depthStencil.depth = 1.0;
18033 clear.depthStencil.stencil = 0;
18034 ref.attachment = 0;
18035 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18036
18037 VkSubpassDescription subpass = {};
18038 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18039 subpass.flags = 0;
18040 subpass.inputAttachmentCount = 0;
18041 subpass.pInputAttachments = NULL;
18042 subpass.colorAttachmentCount = 0;
18043 subpass.pColorAttachments = NULL;
18044 subpass.pResolveAttachments = NULL;
18045 subpass.pDepthStencilAttachment = &ref;
18046 subpass.preserveAttachmentCount = 0;
18047 subpass.pPreserveAttachments = NULL;
18048
18049 VkRenderPass rp;
18050 VkRenderPassCreateInfo rp_info = {};
18051 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18052 rp_info.attachmentCount = 1;
18053 rp_info.pAttachments = &att;
18054 rp_info.subpassCount = 1;
18055 rp_info.pSubpasses = &subpass;
18056 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18057 ASSERT_VK_SUCCESS(result);
18058
18059 VkImageView *depthView = m_depthStencil->BindInfo();
18060 VkFramebufferCreateInfo fb_info = {};
18061 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18062 fb_info.pNext = NULL;
18063 fb_info.renderPass = rp;
18064 fb_info.attachmentCount = 1;
18065 fb_info.pAttachments = depthView;
18066 fb_info.width = 100;
18067 fb_info.height = 100;
18068 fb_info.layers = 1;
18069 VkFramebuffer fb;
18070 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18071 ASSERT_VK_SUCCESS(result);
18072
18073 VkRenderPassBeginInfo rpbinfo = {};
18074 rpbinfo.clearValueCount = 1;
18075 rpbinfo.pClearValues = &clear;
18076 rpbinfo.pNext = NULL;
18077 rpbinfo.renderPass = rp;
18078 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18079 rpbinfo.renderArea.extent.width = 100;
18080 rpbinfo.renderArea.extent.height = 100;
18081 rpbinfo.renderArea.offset.x = 0;
18082 rpbinfo.renderArea.offset.y = 0;
18083 rpbinfo.framebuffer = fb;
18084
18085 VkFence fence = {};
18086 VkFenceCreateInfo fence_ci = {};
18087 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18088 fence_ci.pNext = nullptr;
18089 fence_ci.flags = 0;
18090 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18091 ASSERT_VK_SUCCESS(result);
18092
18093 m_commandBuffer->BeginCommandBuffer();
18094 m_commandBuffer->BeginRenderPass(rpbinfo);
18095 m_commandBuffer->EndRenderPass();
18096 m_commandBuffer->EndCommandBuffer();
18097 m_commandBuffer->QueueCommandBuffer(fence);
18098
18099 VkImageObj destImage(m_device);
18100 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18101 VK_IMAGE_TILING_OPTIMAL, 0);
18102 VkImageMemoryBarrier barrier = {};
18103 VkImageSubresourceRange range;
18104 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18105 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18106 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18107 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18108 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18109 barrier.image = m_depthStencil->handle();
18110 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18111 range.baseMipLevel = 0;
18112 range.levelCount = 1;
18113 range.baseArrayLayer = 0;
18114 range.layerCount = 1;
18115 barrier.subresourceRange = range;
18116 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18117 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18118 cmdbuf.BeginCommandBuffer();
18119 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18120 &barrier);
18121 barrier.srcAccessMask = 0;
18122 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18123 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18124 barrier.image = destImage.handle();
18125 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18126 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18127 &barrier);
18128 VkImageCopy cregion;
18129 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18130 cregion.srcSubresource.mipLevel = 0;
18131 cregion.srcSubresource.baseArrayLayer = 0;
18132 cregion.srcSubresource.layerCount = 1;
18133 cregion.srcOffset.x = 0;
18134 cregion.srcOffset.y = 0;
18135 cregion.srcOffset.z = 0;
18136 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18137 cregion.dstSubresource.mipLevel = 0;
18138 cregion.dstSubresource.baseArrayLayer = 0;
18139 cregion.dstSubresource.layerCount = 1;
18140 cregion.dstOffset.x = 0;
18141 cregion.dstOffset.y = 0;
18142 cregion.dstOffset.z = 0;
18143 cregion.extent.width = 100;
18144 cregion.extent.height = 100;
18145 cregion.extent.depth = 1;
18146 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18147 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18148 cmdbuf.EndCommandBuffer();
18149
18150 VkSubmitInfo submit_info;
18151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18152 submit_info.pNext = NULL;
18153 submit_info.waitSemaphoreCount = 0;
18154 submit_info.pWaitSemaphores = NULL;
18155 submit_info.pWaitDstStageMask = NULL;
18156 submit_info.commandBufferCount = 1;
18157 submit_info.pCommandBuffers = &cmdbuf.handle();
18158 submit_info.signalSemaphoreCount = 0;
18159 submit_info.pSignalSemaphores = NULL;
18160
18161 m_errorMonitor->ExpectSuccess();
18162 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18163 m_errorMonitor->VerifyNotFound();
18164
18165 vkQueueWaitIdle(m_device->m_queue);
18166 vkDestroyFence(m_device->device(), fence, nullptr);
18167 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18168 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18169}
18170
18171// This is a positive test. No errors should be generated.
18172TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18173 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18174
18175 m_errorMonitor->ExpectSuccess();
18176 ASSERT_NO_FATAL_FAILURE(InitState());
18177
18178 VkEvent event;
18179 VkEventCreateInfo event_create_info{};
18180 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18181 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18182
18183 VkCommandPool command_pool;
18184 VkCommandPoolCreateInfo pool_create_info{};
18185 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18186 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18187 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18188 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18189
18190 VkCommandBuffer command_buffer;
18191 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18192 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18193 command_buffer_allocate_info.commandPool = command_pool;
18194 command_buffer_allocate_info.commandBufferCount = 1;
18195 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18196 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18197
18198 VkQueue queue = VK_NULL_HANDLE;
18199 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18200
18201 {
18202 VkCommandBufferBeginInfo begin_info{};
18203 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18204 vkBeginCommandBuffer(command_buffer, &begin_info);
18205
18206 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18207 nullptr, 0, nullptr);
18208 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18209 vkEndCommandBuffer(command_buffer);
18210 }
18211 {
18212 VkSubmitInfo submit_info{};
18213 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18214 submit_info.commandBufferCount = 1;
18215 submit_info.pCommandBuffers = &command_buffer;
18216 submit_info.signalSemaphoreCount = 0;
18217 submit_info.pSignalSemaphores = nullptr;
18218 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18219 }
18220 { vkSetEvent(m_device->device(), event); }
18221
18222 vkQueueWaitIdle(queue);
18223
18224 vkDestroyEvent(m_device->device(), event, nullptr);
18225 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18226 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18227
18228 m_errorMonitor->VerifyNotFound();
18229}
18230// This is a positive test. No errors should be generated.
18231TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18232 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18233
18234 ASSERT_NO_FATAL_FAILURE(InitState());
18235 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18236 return;
18237
18238 m_errorMonitor->ExpectSuccess();
18239
18240 VkQueryPool query_pool;
18241 VkQueryPoolCreateInfo query_pool_create_info{};
18242 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18243 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18244 query_pool_create_info.queryCount = 1;
18245 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18246
18247 VkCommandPool command_pool;
18248 VkCommandPoolCreateInfo pool_create_info{};
18249 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18250 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18251 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18252 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18253
18254 VkCommandBuffer command_buffer;
18255 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18256 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18257 command_buffer_allocate_info.commandPool = command_pool;
18258 command_buffer_allocate_info.commandBufferCount = 1;
18259 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18260 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18261
18262 VkCommandBuffer secondary_command_buffer;
18263 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18264 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18265
18266 VkQueue queue = VK_NULL_HANDLE;
18267 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18268
18269 uint32_t qfi = 0;
18270 VkBufferCreateInfo buff_create_info = {};
18271 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18272 buff_create_info.size = 1024;
18273 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18274 buff_create_info.queueFamilyIndexCount = 1;
18275 buff_create_info.pQueueFamilyIndices = &qfi;
18276
18277 VkResult err;
18278 VkBuffer buffer;
18279 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18280 ASSERT_VK_SUCCESS(err);
18281 VkMemoryAllocateInfo mem_alloc = {};
18282 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18283 mem_alloc.pNext = NULL;
18284 mem_alloc.allocationSize = 1024;
18285 mem_alloc.memoryTypeIndex = 0;
18286
18287 VkMemoryRequirements memReqs;
18288 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18289 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18290 if (!pass) {
18291 vkDestroyBuffer(m_device->device(), buffer, NULL);
18292 return;
18293 }
18294
18295 VkDeviceMemory mem;
18296 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18297 ASSERT_VK_SUCCESS(err);
18298 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18299 ASSERT_VK_SUCCESS(err);
18300
18301 VkCommandBufferInheritanceInfo hinfo = {};
18302 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18303 hinfo.renderPass = VK_NULL_HANDLE;
18304 hinfo.subpass = 0;
18305 hinfo.framebuffer = VK_NULL_HANDLE;
18306 hinfo.occlusionQueryEnable = VK_FALSE;
18307 hinfo.queryFlags = 0;
18308 hinfo.pipelineStatistics = 0;
18309
18310 {
18311 VkCommandBufferBeginInfo begin_info{};
18312 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18313 begin_info.pInheritanceInfo = &hinfo;
18314 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18315
18316 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18317 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18318
18319 vkEndCommandBuffer(secondary_command_buffer);
18320
18321 begin_info.pInheritanceInfo = nullptr;
18322 vkBeginCommandBuffer(command_buffer, &begin_info);
18323
18324 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18325 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18326
18327 vkEndCommandBuffer(command_buffer);
18328 }
18329 {
18330 VkSubmitInfo submit_info{};
18331 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18332 submit_info.commandBufferCount = 1;
18333 submit_info.pCommandBuffers = &command_buffer;
18334 submit_info.signalSemaphoreCount = 0;
18335 submit_info.pSignalSemaphores = nullptr;
18336 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18337 }
18338
18339 vkQueueWaitIdle(queue);
18340
18341 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18342 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18343 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18344 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18345 vkDestroyBuffer(m_device->device(), buffer, NULL);
18346 vkFreeMemory(m_device->device(), mem, NULL);
18347
18348 m_errorMonitor->VerifyNotFound();
18349}
18350
18351// This is a positive test. No errors should be generated.
18352TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18353 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18354
18355 ASSERT_NO_FATAL_FAILURE(InitState());
18356 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18357 return;
18358
18359 m_errorMonitor->ExpectSuccess();
18360
18361 VkQueryPool query_pool;
18362 VkQueryPoolCreateInfo query_pool_create_info{};
18363 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18364 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18365 query_pool_create_info.queryCount = 1;
18366 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18367
18368 VkCommandPool command_pool;
18369 VkCommandPoolCreateInfo pool_create_info{};
18370 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18371 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18372 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18373 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18374
18375 VkCommandBuffer command_buffer[2];
18376 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18377 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18378 command_buffer_allocate_info.commandPool = command_pool;
18379 command_buffer_allocate_info.commandBufferCount = 2;
18380 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18381 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18382
18383 VkQueue queue = VK_NULL_HANDLE;
18384 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18385
18386 uint32_t qfi = 0;
18387 VkBufferCreateInfo buff_create_info = {};
18388 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18389 buff_create_info.size = 1024;
18390 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18391 buff_create_info.queueFamilyIndexCount = 1;
18392 buff_create_info.pQueueFamilyIndices = &qfi;
18393
18394 VkResult err;
18395 VkBuffer buffer;
18396 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18397 ASSERT_VK_SUCCESS(err);
18398 VkMemoryAllocateInfo mem_alloc = {};
18399 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18400 mem_alloc.pNext = NULL;
18401 mem_alloc.allocationSize = 1024;
18402 mem_alloc.memoryTypeIndex = 0;
18403
18404 VkMemoryRequirements memReqs;
18405 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18406 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18407 if (!pass) {
18408 vkDestroyBuffer(m_device->device(), buffer, NULL);
18409 return;
18410 }
18411
18412 VkDeviceMemory mem;
18413 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18414 ASSERT_VK_SUCCESS(err);
18415 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18416 ASSERT_VK_SUCCESS(err);
18417
18418 {
18419 VkCommandBufferBeginInfo begin_info{};
18420 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18421 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18422
18423 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18424 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18425
18426 vkEndCommandBuffer(command_buffer[0]);
18427
18428 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18429
18430 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18431
18432 vkEndCommandBuffer(command_buffer[1]);
18433 }
18434 {
18435 VkSubmitInfo submit_info{};
18436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18437 submit_info.commandBufferCount = 2;
18438 submit_info.pCommandBuffers = command_buffer;
18439 submit_info.signalSemaphoreCount = 0;
18440 submit_info.pSignalSemaphores = nullptr;
18441 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18442 }
18443
18444 vkQueueWaitIdle(queue);
18445
18446 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18447 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18448 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18449 vkDestroyBuffer(m_device->device(), buffer, NULL);
18450 vkFreeMemory(m_device->device(), mem, NULL);
18451
18452 m_errorMonitor->VerifyNotFound();
18453}
18454
Tony Barbourc46924f2016-11-04 11:49:52 -060018455TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018456 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18457
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018458 ASSERT_NO_FATAL_FAILURE(InitState());
18459 VkEvent event;
18460 VkEventCreateInfo event_create_info{};
18461 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18462 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18463
18464 VkCommandPool command_pool;
18465 VkCommandPoolCreateInfo pool_create_info{};
18466 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18467 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18468 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18469 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18470
18471 VkCommandBuffer command_buffer;
18472 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18473 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18474 command_buffer_allocate_info.commandPool = command_pool;
18475 command_buffer_allocate_info.commandBufferCount = 1;
18476 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18477 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18478
18479 VkQueue queue = VK_NULL_HANDLE;
18480 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18481
18482 {
18483 VkCommandBufferBeginInfo begin_info{};
18484 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18485 vkBeginCommandBuffer(command_buffer, &begin_info);
18486
18487 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018488 vkEndCommandBuffer(command_buffer);
18489 }
18490 {
18491 VkSubmitInfo submit_info{};
18492 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18493 submit_info.commandBufferCount = 1;
18494 submit_info.pCommandBuffers = &command_buffer;
18495 submit_info.signalSemaphoreCount = 0;
18496 submit_info.pSignalSemaphores = nullptr;
18497 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18498 }
18499 {
18500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18501 "command buffer.");
18502 vkSetEvent(m_device->device(), event);
18503 m_errorMonitor->VerifyFound();
18504 }
18505
18506 vkQueueWaitIdle(queue);
18507
18508 vkDestroyEvent(m_device->device(), event, nullptr);
18509 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18510 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18511}
18512
18513// This is a positive test. No errors should be generated.
18514TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18515 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18516 "run through a Submit & WaitForFences cycle 3 times. This "
18517 "previously revealed a bug so running this positive test "
18518 "to prevent a regression.");
18519 m_errorMonitor->ExpectSuccess();
18520
18521 ASSERT_NO_FATAL_FAILURE(InitState());
18522 VkQueue queue = VK_NULL_HANDLE;
18523 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18524
18525 static const uint32_t NUM_OBJECTS = 2;
18526 static const uint32_t NUM_FRAMES = 3;
18527 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18528 VkFence fences[NUM_OBJECTS] = {};
18529
18530 VkCommandPool cmd_pool;
18531 VkCommandPoolCreateInfo cmd_pool_ci = {};
18532 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18533 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18534 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18535 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18536 ASSERT_VK_SUCCESS(err);
18537
18538 VkCommandBufferAllocateInfo cmd_buf_info = {};
18539 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18540 cmd_buf_info.commandPool = cmd_pool;
18541 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18542 cmd_buf_info.commandBufferCount = 1;
18543
18544 VkFenceCreateInfo fence_ci = {};
18545 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18546 fence_ci.pNext = nullptr;
18547 fence_ci.flags = 0;
18548
18549 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18550 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18551 ASSERT_VK_SUCCESS(err);
18552 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18553 ASSERT_VK_SUCCESS(err);
18554 }
18555
18556 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18557 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18558 // Create empty cmd buffer
18559 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18560 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18561
18562 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18563 ASSERT_VK_SUCCESS(err);
18564 err = vkEndCommandBuffer(cmd_buffers[obj]);
18565 ASSERT_VK_SUCCESS(err);
18566
18567 VkSubmitInfo submit_info = {};
18568 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18569 submit_info.commandBufferCount = 1;
18570 submit_info.pCommandBuffers = &cmd_buffers[obj];
18571 // Submit cmd buffer and wait for fence
18572 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18573 ASSERT_VK_SUCCESS(err);
18574 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18575 ASSERT_VK_SUCCESS(err);
18576 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18577 ASSERT_VK_SUCCESS(err);
18578 }
18579 }
18580 m_errorMonitor->VerifyNotFound();
18581 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18582 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18583 vkDestroyFence(m_device->device(), fences[i], nullptr);
18584 }
18585}
18586// This is a positive test. No errors should be generated.
18587TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18588
18589 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18590 "submitted on separate queues followed by a QueueWaitIdle.");
18591
18592 ASSERT_NO_FATAL_FAILURE(InitState());
18593 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18594 return;
18595
18596 m_errorMonitor->ExpectSuccess();
18597
18598 VkSemaphore semaphore;
18599 VkSemaphoreCreateInfo semaphore_create_info{};
18600 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18601 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18602
18603 VkCommandPool command_pool;
18604 VkCommandPoolCreateInfo pool_create_info{};
18605 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18606 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18607 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18608 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18609
18610 VkCommandBuffer command_buffer[2];
18611 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18612 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18613 command_buffer_allocate_info.commandPool = command_pool;
18614 command_buffer_allocate_info.commandBufferCount = 2;
18615 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18616 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18617
18618 VkQueue queue = VK_NULL_HANDLE;
18619 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18620
18621 {
18622 VkCommandBufferBeginInfo begin_info{};
18623 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18624 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18625
18626 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18627 nullptr, 0, nullptr, 0, nullptr);
18628
18629 VkViewport viewport{};
18630 viewport.maxDepth = 1.0f;
18631 viewport.minDepth = 0.0f;
18632 viewport.width = 512;
18633 viewport.height = 512;
18634 viewport.x = 0;
18635 viewport.y = 0;
18636 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18637 vkEndCommandBuffer(command_buffer[0]);
18638 }
18639 {
18640 VkCommandBufferBeginInfo begin_info{};
18641 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18642 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18643
18644 VkViewport viewport{};
18645 viewport.maxDepth = 1.0f;
18646 viewport.minDepth = 0.0f;
18647 viewport.width = 512;
18648 viewport.height = 512;
18649 viewport.x = 0;
18650 viewport.y = 0;
18651 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18652 vkEndCommandBuffer(command_buffer[1]);
18653 }
18654 {
18655 VkSubmitInfo submit_info{};
18656 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18657 submit_info.commandBufferCount = 1;
18658 submit_info.pCommandBuffers = &command_buffer[0];
18659 submit_info.signalSemaphoreCount = 1;
18660 submit_info.pSignalSemaphores = &semaphore;
18661 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18662 }
18663 {
18664 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18665 VkSubmitInfo submit_info{};
18666 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18667 submit_info.commandBufferCount = 1;
18668 submit_info.pCommandBuffers = &command_buffer[1];
18669 submit_info.waitSemaphoreCount = 1;
18670 submit_info.pWaitSemaphores = &semaphore;
18671 submit_info.pWaitDstStageMask = flags;
18672 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18673 }
18674
18675 vkQueueWaitIdle(m_device->m_queue);
18676
18677 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18678 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18679 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18680
18681 m_errorMonitor->VerifyNotFound();
18682}
18683
18684// This is a positive test. No errors should be generated.
18685TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18686
18687 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18688 "submitted on separate queues, the second having a fence"
18689 "followed by a QueueWaitIdle.");
18690
18691 ASSERT_NO_FATAL_FAILURE(InitState());
18692 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18693 return;
18694
18695 m_errorMonitor->ExpectSuccess();
18696
18697 VkFence fence;
18698 VkFenceCreateInfo fence_create_info{};
18699 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18700 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18701
18702 VkSemaphore semaphore;
18703 VkSemaphoreCreateInfo semaphore_create_info{};
18704 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18705 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18706
18707 VkCommandPool command_pool;
18708 VkCommandPoolCreateInfo pool_create_info{};
18709 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18710 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18711 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18712 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18713
18714 VkCommandBuffer command_buffer[2];
18715 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18716 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18717 command_buffer_allocate_info.commandPool = command_pool;
18718 command_buffer_allocate_info.commandBufferCount = 2;
18719 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18720 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18721
18722 VkQueue queue = VK_NULL_HANDLE;
18723 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18724
18725 {
18726 VkCommandBufferBeginInfo begin_info{};
18727 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18728 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18729
18730 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18731 nullptr, 0, nullptr, 0, nullptr);
18732
18733 VkViewport viewport{};
18734 viewport.maxDepth = 1.0f;
18735 viewport.minDepth = 0.0f;
18736 viewport.width = 512;
18737 viewport.height = 512;
18738 viewport.x = 0;
18739 viewport.y = 0;
18740 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18741 vkEndCommandBuffer(command_buffer[0]);
18742 }
18743 {
18744 VkCommandBufferBeginInfo begin_info{};
18745 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18746 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18747
18748 VkViewport viewport{};
18749 viewport.maxDepth = 1.0f;
18750 viewport.minDepth = 0.0f;
18751 viewport.width = 512;
18752 viewport.height = 512;
18753 viewport.x = 0;
18754 viewport.y = 0;
18755 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18756 vkEndCommandBuffer(command_buffer[1]);
18757 }
18758 {
18759 VkSubmitInfo submit_info{};
18760 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18761 submit_info.commandBufferCount = 1;
18762 submit_info.pCommandBuffers = &command_buffer[0];
18763 submit_info.signalSemaphoreCount = 1;
18764 submit_info.pSignalSemaphores = &semaphore;
18765 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18766 }
18767 {
18768 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18769 VkSubmitInfo submit_info{};
18770 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18771 submit_info.commandBufferCount = 1;
18772 submit_info.pCommandBuffers = &command_buffer[1];
18773 submit_info.waitSemaphoreCount = 1;
18774 submit_info.pWaitSemaphores = &semaphore;
18775 submit_info.pWaitDstStageMask = flags;
18776 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18777 }
18778
18779 vkQueueWaitIdle(m_device->m_queue);
18780
18781 vkDestroyFence(m_device->device(), fence, nullptr);
18782 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18783 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18784 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18785
18786 m_errorMonitor->VerifyNotFound();
18787}
18788
18789// This is a positive test. No errors should be generated.
18790TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18791
18792 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18793 "submitted on separate queues, the second having a fence"
18794 "followed by two consecutive WaitForFences calls on the same fence.");
18795
18796 ASSERT_NO_FATAL_FAILURE(InitState());
18797 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18798 return;
18799
18800 m_errorMonitor->ExpectSuccess();
18801
18802 VkFence fence;
18803 VkFenceCreateInfo fence_create_info{};
18804 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18805 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18806
18807 VkSemaphore semaphore;
18808 VkSemaphoreCreateInfo semaphore_create_info{};
18809 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18810 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18811
18812 VkCommandPool command_pool;
18813 VkCommandPoolCreateInfo pool_create_info{};
18814 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18815 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18816 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18817 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18818
18819 VkCommandBuffer command_buffer[2];
18820 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18821 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18822 command_buffer_allocate_info.commandPool = command_pool;
18823 command_buffer_allocate_info.commandBufferCount = 2;
18824 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18825 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18826
18827 VkQueue queue = VK_NULL_HANDLE;
18828 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18829
18830 {
18831 VkCommandBufferBeginInfo begin_info{};
18832 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18833 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18834
18835 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18836 nullptr, 0, nullptr, 0, nullptr);
18837
18838 VkViewport viewport{};
18839 viewport.maxDepth = 1.0f;
18840 viewport.minDepth = 0.0f;
18841 viewport.width = 512;
18842 viewport.height = 512;
18843 viewport.x = 0;
18844 viewport.y = 0;
18845 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18846 vkEndCommandBuffer(command_buffer[0]);
18847 }
18848 {
18849 VkCommandBufferBeginInfo begin_info{};
18850 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18851 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18852
18853 VkViewport viewport{};
18854 viewport.maxDepth = 1.0f;
18855 viewport.minDepth = 0.0f;
18856 viewport.width = 512;
18857 viewport.height = 512;
18858 viewport.x = 0;
18859 viewport.y = 0;
18860 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18861 vkEndCommandBuffer(command_buffer[1]);
18862 }
18863 {
18864 VkSubmitInfo submit_info{};
18865 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18866 submit_info.commandBufferCount = 1;
18867 submit_info.pCommandBuffers = &command_buffer[0];
18868 submit_info.signalSemaphoreCount = 1;
18869 submit_info.pSignalSemaphores = &semaphore;
18870 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18871 }
18872 {
18873 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18874 VkSubmitInfo submit_info{};
18875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18876 submit_info.commandBufferCount = 1;
18877 submit_info.pCommandBuffers = &command_buffer[1];
18878 submit_info.waitSemaphoreCount = 1;
18879 submit_info.pWaitSemaphores = &semaphore;
18880 submit_info.pWaitDstStageMask = flags;
18881 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18882 }
18883
18884 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18885 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18886
18887 vkDestroyFence(m_device->device(), fence, nullptr);
18888 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18889 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18890 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18891
18892 m_errorMonitor->VerifyNotFound();
18893}
18894
18895TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18896
18897 ASSERT_NO_FATAL_FAILURE(InitState());
18898 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18899 printf("Test requires two queues, skipping\n");
18900 return;
18901 }
18902
18903 VkResult err;
18904
18905 m_errorMonitor->ExpectSuccess();
18906
18907 VkQueue q0 = m_device->m_queue;
18908 VkQueue q1 = nullptr;
18909 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18910 ASSERT_NE(q1, nullptr);
18911
18912 // An (empty) command buffer. We must have work in the first submission --
18913 // the layer treats unfenced work differently from fenced work.
18914 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18915 VkCommandPool pool;
18916 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18917 ASSERT_VK_SUCCESS(err);
18918 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18919 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18920 VkCommandBuffer cb;
18921 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18922 ASSERT_VK_SUCCESS(err);
18923 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18924 err = vkBeginCommandBuffer(cb, &cbbi);
18925 ASSERT_VK_SUCCESS(err);
18926 err = vkEndCommandBuffer(cb);
18927 ASSERT_VK_SUCCESS(err);
18928
18929 // A semaphore
18930 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18931 VkSemaphore s;
18932 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18933 ASSERT_VK_SUCCESS(err);
18934
18935 // First submission, to q0
18936 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18937
18938 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18939 ASSERT_VK_SUCCESS(err);
18940
18941 // Second submission, to q1, waiting on s
18942 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18943 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18944
18945 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18946 ASSERT_VK_SUCCESS(err);
18947
18948 // Wait for q0 idle
18949 err = vkQueueWaitIdle(q0);
18950 ASSERT_VK_SUCCESS(err);
18951
18952 // Command buffer should have been completed (it was on q0); reset the pool.
18953 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18954
18955 m_errorMonitor->VerifyNotFound();
18956
18957 // Force device completely idle and clean up resources
18958 vkDeviceWaitIdle(m_device->device());
18959 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18960 vkDestroySemaphore(m_device->device(), s, nullptr);
18961}
18962
18963// This is a positive test. No errors should be generated.
18964TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18965
18966 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18967 "submitted on separate queues, the second having a fence, "
18968 "followed by a WaitForFences call.");
18969
18970 ASSERT_NO_FATAL_FAILURE(InitState());
18971 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18972 return;
18973
18974 m_errorMonitor->ExpectSuccess();
18975
18976 ASSERT_NO_FATAL_FAILURE(InitState());
18977 VkFence fence;
18978 VkFenceCreateInfo fence_create_info{};
18979 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18980 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18981
18982 VkSemaphore semaphore;
18983 VkSemaphoreCreateInfo semaphore_create_info{};
18984 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18985 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18986
18987 VkCommandPool command_pool;
18988 VkCommandPoolCreateInfo pool_create_info{};
18989 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18990 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18991 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18992 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18993
18994 VkCommandBuffer command_buffer[2];
18995 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18996 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18997 command_buffer_allocate_info.commandPool = command_pool;
18998 command_buffer_allocate_info.commandBufferCount = 2;
18999 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19000 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19001
19002 VkQueue queue = VK_NULL_HANDLE;
19003 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19004
19005 {
19006 VkCommandBufferBeginInfo begin_info{};
19007 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19008 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19009
19010 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19011 nullptr, 0, nullptr, 0, nullptr);
19012
19013 VkViewport viewport{};
19014 viewport.maxDepth = 1.0f;
19015 viewport.minDepth = 0.0f;
19016 viewport.width = 512;
19017 viewport.height = 512;
19018 viewport.x = 0;
19019 viewport.y = 0;
19020 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19021 vkEndCommandBuffer(command_buffer[0]);
19022 }
19023 {
19024 VkCommandBufferBeginInfo begin_info{};
19025 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19026 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19027
19028 VkViewport viewport{};
19029 viewport.maxDepth = 1.0f;
19030 viewport.minDepth = 0.0f;
19031 viewport.width = 512;
19032 viewport.height = 512;
19033 viewport.x = 0;
19034 viewport.y = 0;
19035 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19036 vkEndCommandBuffer(command_buffer[1]);
19037 }
19038 {
19039 VkSubmitInfo submit_info{};
19040 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19041 submit_info.commandBufferCount = 1;
19042 submit_info.pCommandBuffers = &command_buffer[0];
19043 submit_info.signalSemaphoreCount = 1;
19044 submit_info.pSignalSemaphores = &semaphore;
19045 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19046 }
19047 {
19048 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19049 VkSubmitInfo submit_info{};
19050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19051 submit_info.commandBufferCount = 1;
19052 submit_info.pCommandBuffers = &command_buffer[1];
19053 submit_info.waitSemaphoreCount = 1;
19054 submit_info.pWaitSemaphores = &semaphore;
19055 submit_info.pWaitDstStageMask = flags;
19056 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19057 }
19058
19059 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19060
19061 vkDestroyFence(m_device->device(), fence, nullptr);
19062 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19063 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19064 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19065
19066 m_errorMonitor->VerifyNotFound();
19067}
19068
19069// This is a positive test. No errors should be generated.
19070TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
19071
19072 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19073 "on the same queue, sharing a signal/wait semaphore, the "
19074 "second having a fence, "
19075 "followed by a WaitForFences call.");
19076
19077 m_errorMonitor->ExpectSuccess();
19078
19079 ASSERT_NO_FATAL_FAILURE(InitState());
19080 VkFence fence;
19081 VkFenceCreateInfo fence_create_info{};
19082 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19083 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19084
19085 VkSemaphore semaphore;
19086 VkSemaphoreCreateInfo semaphore_create_info{};
19087 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19088 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19089
19090 VkCommandPool command_pool;
19091 VkCommandPoolCreateInfo pool_create_info{};
19092 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19093 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19094 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19095 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19096
19097 VkCommandBuffer command_buffer[2];
19098 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19099 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19100 command_buffer_allocate_info.commandPool = command_pool;
19101 command_buffer_allocate_info.commandBufferCount = 2;
19102 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19103 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19104
19105 {
19106 VkCommandBufferBeginInfo begin_info{};
19107 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19108 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19109
19110 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19111 nullptr, 0, nullptr, 0, nullptr);
19112
19113 VkViewport viewport{};
19114 viewport.maxDepth = 1.0f;
19115 viewport.minDepth = 0.0f;
19116 viewport.width = 512;
19117 viewport.height = 512;
19118 viewport.x = 0;
19119 viewport.y = 0;
19120 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19121 vkEndCommandBuffer(command_buffer[0]);
19122 }
19123 {
19124 VkCommandBufferBeginInfo begin_info{};
19125 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19126 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19127
19128 VkViewport viewport{};
19129 viewport.maxDepth = 1.0f;
19130 viewport.minDepth = 0.0f;
19131 viewport.width = 512;
19132 viewport.height = 512;
19133 viewport.x = 0;
19134 viewport.y = 0;
19135 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19136 vkEndCommandBuffer(command_buffer[1]);
19137 }
19138 {
19139 VkSubmitInfo submit_info{};
19140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19141 submit_info.commandBufferCount = 1;
19142 submit_info.pCommandBuffers = &command_buffer[0];
19143 submit_info.signalSemaphoreCount = 1;
19144 submit_info.pSignalSemaphores = &semaphore;
19145 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19146 }
19147 {
19148 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19149 VkSubmitInfo submit_info{};
19150 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19151 submit_info.commandBufferCount = 1;
19152 submit_info.pCommandBuffers = &command_buffer[1];
19153 submit_info.waitSemaphoreCount = 1;
19154 submit_info.pWaitSemaphores = &semaphore;
19155 submit_info.pWaitDstStageMask = flags;
19156 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19157 }
19158
19159 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19160
19161 vkDestroyFence(m_device->device(), fence, nullptr);
19162 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19163 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19164 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19165
19166 m_errorMonitor->VerifyNotFound();
19167}
19168
19169// This is a positive test. No errors should be generated.
19170TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19171
19172 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19173 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19174 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19175
19176 m_errorMonitor->ExpectSuccess();
19177
19178 ASSERT_NO_FATAL_FAILURE(InitState());
19179 VkFence fence;
19180 VkFenceCreateInfo fence_create_info{};
19181 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19182 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19183
19184 VkCommandPool command_pool;
19185 VkCommandPoolCreateInfo pool_create_info{};
19186 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19187 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19188 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19189 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19190
19191 VkCommandBuffer command_buffer[2];
19192 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19193 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19194 command_buffer_allocate_info.commandPool = command_pool;
19195 command_buffer_allocate_info.commandBufferCount = 2;
19196 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19197 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19198
19199 {
19200 VkCommandBufferBeginInfo begin_info{};
19201 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19202 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19203
19204 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19205 nullptr, 0, nullptr, 0, nullptr);
19206
19207 VkViewport viewport{};
19208 viewport.maxDepth = 1.0f;
19209 viewport.minDepth = 0.0f;
19210 viewport.width = 512;
19211 viewport.height = 512;
19212 viewport.x = 0;
19213 viewport.y = 0;
19214 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19215 vkEndCommandBuffer(command_buffer[0]);
19216 }
19217 {
19218 VkCommandBufferBeginInfo begin_info{};
19219 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19220 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19221
19222 VkViewport viewport{};
19223 viewport.maxDepth = 1.0f;
19224 viewport.minDepth = 0.0f;
19225 viewport.width = 512;
19226 viewport.height = 512;
19227 viewport.x = 0;
19228 viewport.y = 0;
19229 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19230 vkEndCommandBuffer(command_buffer[1]);
19231 }
19232 {
19233 VkSubmitInfo submit_info{};
19234 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19235 submit_info.commandBufferCount = 1;
19236 submit_info.pCommandBuffers = &command_buffer[0];
19237 submit_info.signalSemaphoreCount = 0;
19238 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19239 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19240 }
19241 {
19242 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19243 VkSubmitInfo submit_info{};
19244 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19245 submit_info.commandBufferCount = 1;
19246 submit_info.pCommandBuffers = &command_buffer[1];
19247 submit_info.waitSemaphoreCount = 0;
19248 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19249 submit_info.pWaitDstStageMask = flags;
19250 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19251 }
19252
19253 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19254
19255 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19256 ASSERT_VK_SUCCESS(err);
19257
19258 vkDestroyFence(m_device->device(), fence, nullptr);
19259 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19260 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19261
19262 m_errorMonitor->VerifyNotFound();
19263}
19264
19265// This is a positive test. No errors should be generated.
19266TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19267
19268 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19269 "on the same queue, the second having a fence, followed "
19270 "by a WaitForFences call.");
19271
19272 m_errorMonitor->ExpectSuccess();
19273
19274 ASSERT_NO_FATAL_FAILURE(InitState());
19275 VkFence fence;
19276 VkFenceCreateInfo fence_create_info{};
19277 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19278 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19279
19280 VkCommandPool command_pool;
19281 VkCommandPoolCreateInfo pool_create_info{};
19282 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19283 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19284 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19285 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19286
19287 VkCommandBuffer command_buffer[2];
19288 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19289 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19290 command_buffer_allocate_info.commandPool = command_pool;
19291 command_buffer_allocate_info.commandBufferCount = 2;
19292 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19293 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19294
19295 {
19296 VkCommandBufferBeginInfo begin_info{};
19297 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19298 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19299
19300 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19301 nullptr, 0, nullptr, 0, nullptr);
19302
19303 VkViewport viewport{};
19304 viewport.maxDepth = 1.0f;
19305 viewport.minDepth = 0.0f;
19306 viewport.width = 512;
19307 viewport.height = 512;
19308 viewport.x = 0;
19309 viewport.y = 0;
19310 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19311 vkEndCommandBuffer(command_buffer[0]);
19312 }
19313 {
19314 VkCommandBufferBeginInfo begin_info{};
19315 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19316 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19317
19318 VkViewport viewport{};
19319 viewport.maxDepth = 1.0f;
19320 viewport.minDepth = 0.0f;
19321 viewport.width = 512;
19322 viewport.height = 512;
19323 viewport.x = 0;
19324 viewport.y = 0;
19325 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19326 vkEndCommandBuffer(command_buffer[1]);
19327 }
19328 {
19329 VkSubmitInfo submit_info{};
19330 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19331 submit_info.commandBufferCount = 1;
19332 submit_info.pCommandBuffers = &command_buffer[0];
19333 submit_info.signalSemaphoreCount = 0;
19334 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19335 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19336 }
19337 {
19338 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19339 VkSubmitInfo submit_info{};
19340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19341 submit_info.commandBufferCount = 1;
19342 submit_info.pCommandBuffers = &command_buffer[1];
19343 submit_info.waitSemaphoreCount = 0;
19344 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19345 submit_info.pWaitDstStageMask = flags;
19346 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19347 }
19348
19349 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19350
19351 vkDestroyFence(m_device->device(), fence, nullptr);
19352 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19353 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19354
19355 m_errorMonitor->VerifyNotFound();
19356}
19357
19358// This is a positive test. No errors should be generated.
19359TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19360
19361 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19362 "QueueSubmit call followed by a WaitForFences call.");
19363 ASSERT_NO_FATAL_FAILURE(InitState());
19364
19365 m_errorMonitor->ExpectSuccess();
19366
19367 VkFence fence;
19368 VkFenceCreateInfo fence_create_info{};
19369 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19370 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19371
19372 VkSemaphore semaphore;
19373 VkSemaphoreCreateInfo semaphore_create_info{};
19374 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19375 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19376
19377 VkCommandPool command_pool;
19378 VkCommandPoolCreateInfo pool_create_info{};
19379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19382 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19383
19384 VkCommandBuffer command_buffer[2];
19385 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19386 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19387 command_buffer_allocate_info.commandPool = command_pool;
19388 command_buffer_allocate_info.commandBufferCount = 2;
19389 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19390 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19391
19392 {
19393 VkCommandBufferBeginInfo begin_info{};
19394 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19395 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19396
19397 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19398 nullptr, 0, nullptr, 0, nullptr);
19399
19400 VkViewport viewport{};
19401 viewport.maxDepth = 1.0f;
19402 viewport.minDepth = 0.0f;
19403 viewport.width = 512;
19404 viewport.height = 512;
19405 viewport.x = 0;
19406 viewport.y = 0;
19407 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19408 vkEndCommandBuffer(command_buffer[0]);
19409 }
19410 {
19411 VkCommandBufferBeginInfo begin_info{};
19412 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19413 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19414
19415 VkViewport viewport{};
19416 viewport.maxDepth = 1.0f;
19417 viewport.minDepth = 0.0f;
19418 viewport.width = 512;
19419 viewport.height = 512;
19420 viewport.x = 0;
19421 viewport.y = 0;
19422 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19423 vkEndCommandBuffer(command_buffer[1]);
19424 }
19425 {
19426 VkSubmitInfo submit_info[2];
19427 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19428
19429 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19430 submit_info[0].pNext = NULL;
19431 submit_info[0].commandBufferCount = 1;
19432 submit_info[0].pCommandBuffers = &command_buffer[0];
19433 submit_info[0].signalSemaphoreCount = 1;
19434 submit_info[0].pSignalSemaphores = &semaphore;
19435 submit_info[0].waitSemaphoreCount = 0;
19436 submit_info[0].pWaitSemaphores = NULL;
19437 submit_info[0].pWaitDstStageMask = 0;
19438
19439 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19440 submit_info[1].pNext = NULL;
19441 submit_info[1].commandBufferCount = 1;
19442 submit_info[1].pCommandBuffers = &command_buffer[1];
19443 submit_info[1].waitSemaphoreCount = 1;
19444 submit_info[1].pWaitSemaphores = &semaphore;
19445 submit_info[1].pWaitDstStageMask = flags;
19446 submit_info[1].signalSemaphoreCount = 0;
19447 submit_info[1].pSignalSemaphores = NULL;
19448 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19449 }
19450
19451 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19452
19453 vkDestroyFence(m_device->device(), fence, nullptr);
19454 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19455 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19456 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19457
19458 m_errorMonitor->VerifyNotFound();
19459}
19460
19461TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19462 m_errorMonitor->ExpectSuccess();
19463
19464 ASSERT_NO_FATAL_FAILURE(InitState());
19465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19466
Tony Barbour552f6c02016-12-21 14:34:07 -070019467 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019468
19469 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19470 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19471 m_errorMonitor->VerifyNotFound();
19472 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19473 m_errorMonitor->VerifyNotFound();
19474 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19475 m_errorMonitor->VerifyNotFound();
19476
19477 m_commandBuffer->EndCommandBuffer();
19478 m_errorMonitor->VerifyNotFound();
19479}
19480
19481TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19482 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19483 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19484 "has a valid layout, and a second subpass then uses a "
19485 "valid *READ_ONLY* layout.");
19486 m_errorMonitor->ExpectSuccess();
19487 ASSERT_NO_FATAL_FAILURE(InitState());
19488
19489 VkAttachmentReference attach[2] = {};
19490 attach[0].attachment = 0;
19491 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19492 attach[1].attachment = 0;
19493 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19494 VkSubpassDescription subpasses[2] = {};
19495 // First subpass clears DS attach on load
19496 subpasses[0].pDepthStencilAttachment = &attach[0];
19497 // 2nd subpass reads in DS as input attachment
19498 subpasses[1].inputAttachmentCount = 1;
19499 subpasses[1].pInputAttachments = &attach[1];
19500 VkAttachmentDescription attach_desc = {};
19501 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19502 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19503 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19504 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19505 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19506 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19507 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19508 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19509 VkRenderPassCreateInfo rpci = {};
19510 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19511 rpci.attachmentCount = 1;
19512 rpci.pAttachments = &attach_desc;
19513 rpci.subpassCount = 2;
19514 rpci.pSubpasses = subpasses;
19515
19516 // Now create RenderPass and verify no errors
19517 VkRenderPass rp;
19518 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19519 m_errorMonitor->VerifyNotFound();
19520
19521 vkDestroyRenderPass(m_device->device(), rp, NULL);
19522}
19523
19524TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19525 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19526 "as vertex attributes");
19527 m_errorMonitor->ExpectSuccess();
19528
19529 ASSERT_NO_FATAL_FAILURE(InitState());
19530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19531
19532 VkVertexInputBindingDescription input_binding;
19533 memset(&input_binding, 0, sizeof(input_binding));
19534
19535 VkVertexInputAttributeDescription input_attribs[2];
19536 memset(input_attribs, 0, sizeof(input_attribs));
19537
19538 for (int i = 0; i < 2; i++) {
19539 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19540 input_attribs[i].location = i;
19541 }
19542
19543 char const *vsSource = "#version 450\n"
19544 "\n"
19545 "layout(location=0) in mat2x4 x;\n"
19546 "out gl_PerVertex {\n"
19547 " vec4 gl_Position;\n"
19548 "};\n"
19549 "void main(){\n"
19550 " gl_Position = x[0] + x[1];\n"
19551 "}\n";
19552 char const *fsSource = "#version 450\n"
19553 "\n"
19554 "layout(location=0) out vec4 color;\n"
19555 "void main(){\n"
19556 " color = vec4(1);\n"
19557 "}\n";
19558
19559 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19560 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19561
19562 VkPipelineObj pipe(m_device);
19563 pipe.AddColorAttachment();
19564 pipe.AddShader(&vs);
19565 pipe.AddShader(&fs);
19566
19567 pipe.AddVertexInputBindings(&input_binding, 1);
19568 pipe.AddVertexInputAttribs(input_attribs, 2);
19569
19570 VkDescriptorSetObj descriptorSet(m_device);
19571 descriptorSet.AppendDummy();
19572 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19573
19574 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19575
19576 /* expect success */
19577 m_errorMonitor->VerifyNotFound();
19578}
19579
19580TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19581 m_errorMonitor->ExpectSuccess();
19582
19583 ASSERT_NO_FATAL_FAILURE(InitState());
19584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19585
19586 VkVertexInputBindingDescription input_binding;
19587 memset(&input_binding, 0, sizeof(input_binding));
19588
19589 VkVertexInputAttributeDescription input_attribs[2];
19590 memset(input_attribs, 0, sizeof(input_attribs));
19591
19592 for (int i = 0; i < 2; i++) {
19593 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19594 input_attribs[i].location = i;
19595 }
19596
19597 char const *vsSource = "#version 450\n"
19598 "\n"
19599 "layout(location=0) in vec4 x[2];\n"
19600 "out gl_PerVertex {\n"
19601 " vec4 gl_Position;\n"
19602 "};\n"
19603 "void main(){\n"
19604 " gl_Position = x[0] + x[1];\n"
19605 "}\n";
19606 char const *fsSource = "#version 450\n"
19607 "\n"
19608 "layout(location=0) out vec4 color;\n"
19609 "void main(){\n"
19610 " color = vec4(1);\n"
19611 "}\n";
19612
19613 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19615
19616 VkPipelineObj pipe(m_device);
19617 pipe.AddColorAttachment();
19618 pipe.AddShader(&vs);
19619 pipe.AddShader(&fs);
19620
19621 pipe.AddVertexInputBindings(&input_binding, 1);
19622 pipe.AddVertexInputAttribs(input_attribs, 2);
19623
19624 VkDescriptorSetObj descriptorSet(m_device);
19625 descriptorSet.AppendDummy();
19626 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19627
19628 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19629
19630 m_errorMonitor->VerifyNotFound();
19631}
19632
19633TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19634 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19635 "through multiple vertex shader inputs, each consuming a different "
19636 "subset of the components.");
19637 m_errorMonitor->ExpectSuccess();
19638
19639 ASSERT_NO_FATAL_FAILURE(InitState());
19640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19641
19642 VkVertexInputBindingDescription input_binding;
19643 memset(&input_binding, 0, sizeof(input_binding));
19644
19645 VkVertexInputAttributeDescription input_attribs[3];
19646 memset(input_attribs, 0, sizeof(input_attribs));
19647
19648 for (int i = 0; i < 3; i++) {
19649 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19650 input_attribs[i].location = i;
19651 }
19652
19653 char const *vsSource = "#version 450\n"
19654 "\n"
19655 "layout(location=0) in vec4 x;\n"
19656 "layout(location=1) in vec3 y1;\n"
19657 "layout(location=1, component=3) in float y2;\n"
19658 "layout(location=2) in vec4 z;\n"
19659 "out gl_PerVertex {\n"
19660 " vec4 gl_Position;\n"
19661 "};\n"
19662 "void main(){\n"
19663 " gl_Position = x + vec4(y1, y2) + z;\n"
19664 "}\n";
19665 char const *fsSource = "#version 450\n"
19666 "\n"
19667 "layout(location=0) out vec4 color;\n"
19668 "void main(){\n"
19669 " color = vec4(1);\n"
19670 "}\n";
19671
19672 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19673 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19674
19675 VkPipelineObj pipe(m_device);
19676 pipe.AddColorAttachment();
19677 pipe.AddShader(&vs);
19678 pipe.AddShader(&fs);
19679
19680 pipe.AddVertexInputBindings(&input_binding, 1);
19681 pipe.AddVertexInputAttribs(input_attribs, 3);
19682
19683 VkDescriptorSetObj descriptorSet(m_device);
19684 descriptorSet.AppendDummy();
19685 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19686
19687 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19688
19689 m_errorMonitor->VerifyNotFound();
19690}
19691
19692TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19693 m_errorMonitor->ExpectSuccess();
19694
19695 ASSERT_NO_FATAL_FAILURE(InitState());
19696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19697
19698 char const *vsSource = "#version 450\n"
19699 "out gl_PerVertex {\n"
19700 " vec4 gl_Position;\n"
19701 "};\n"
19702 "void main(){\n"
19703 " gl_Position = vec4(0);\n"
19704 "}\n";
19705 char const *fsSource = "#version 450\n"
19706 "\n"
19707 "layout(location=0) out vec4 color;\n"
19708 "void main(){\n"
19709 " color = vec4(1);\n"
19710 "}\n";
19711
19712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19714
19715 VkPipelineObj pipe(m_device);
19716 pipe.AddColorAttachment();
19717 pipe.AddShader(&vs);
19718 pipe.AddShader(&fs);
19719
19720 VkDescriptorSetObj descriptorSet(m_device);
19721 descriptorSet.AppendDummy();
19722 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19723
19724 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19725
19726 m_errorMonitor->VerifyNotFound();
19727}
19728
19729TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19730 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19731 "set out in 14.1.3: fundamental type must match, and producer side must "
19732 "have at least as many components");
19733 m_errorMonitor->ExpectSuccess();
19734
19735 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19736
19737 ASSERT_NO_FATAL_FAILURE(InitState());
19738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19739
19740 char const *vsSource = "#version 450\n"
19741 "out gl_PerVertex {\n"
19742 " vec4 gl_Position;\n"
19743 "};\n"
19744 "layout(location=0) out vec3 x;\n"
19745 "layout(location=1) out ivec3 y;\n"
19746 "layout(location=2) out vec3 z;\n"
19747 "void main(){\n"
19748 " gl_Position = vec4(0);\n"
19749 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19750 "}\n";
19751 char const *fsSource = "#version 450\n"
19752 "\n"
19753 "layout(location=0) out vec4 color;\n"
19754 "layout(location=0) in float x;\n"
19755 "layout(location=1) flat in int y;\n"
19756 "layout(location=2) in vec2 z;\n"
19757 "void main(){\n"
19758 " color = vec4(1 + x + y + z.x);\n"
19759 "}\n";
19760
19761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19763
19764 VkPipelineObj pipe(m_device);
19765 pipe.AddColorAttachment();
19766 pipe.AddShader(&vs);
19767 pipe.AddShader(&fs);
19768
19769 VkDescriptorSetObj descriptorSet(m_device);
19770 descriptorSet.AppendDummy();
19771 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19772
19773 VkResult err = VK_SUCCESS;
19774 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19775 ASSERT_VK_SUCCESS(err);
19776
19777 m_errorMonitor->VerifyNotFound();
19778}
19779
19780TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19781 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19782 "passed between the TCS and TES stages");
19783 m_errorMonitor->ExpectSuccess();
19784
19785 ASSERT_NO_FATAL_FAILURE(InitState());
19786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19787
19788 if (!m_device->phy().features().tessellationShader) {
19789 printf("Device does not support tessellation shaders; skipped.\n");
19790 return;
19791 }
19792
19793 char const *vsSource = "#version 450\n"
19794 "void main(){}\n";
19795 char const *tcsSource = "#version 450\n"
19796 "layout(location=0) out int x[];\n"
19797 "layout(vertices=3) out;\n"
19798 "void main(){\n"
19799 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19800 " gl_TessLevelInner[0] = 1;\n"
19801 " x[gl_InvocationID] = gl_InvocationID;\n"
19802 "}\n";
19803 char const *tesSource = "#version 450\n"
19804 "layout(triangles, equal_spacing, cw) in;\n"
19805 "layout(location=0) in int x[];\n"
19806 "out gl_PerVertex { vec4 gl_Position; };\n"
19807 "void main(){\n"
19808 " gl_Position.xyz = gl_TessCoord;\n"
19809 " gl_Position.w = x[0] + x[1] + x[2];\n"
19810 "}\n";
19811 char const *fsSource = "#version 450\n"
19812 "layout(location=0) out vec4 color;\n"
19813 "void main(){\n"
19814 " color = vec4(1);\n"
19815 "}\n";
19816
19817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19818 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19819 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19820 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19821
19822 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19823 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19824
19825 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19826
19827 VkPipelineObj pipe(m_device);
19828 pipe.SetInputAssembly(&iasci);
19829 pipe.SetTessellation(&tsci);
19830 pipe.AddColorAttachment();
19831 pipe.AddShader(&vs);
19832 pipe.AddShader(&tcs);
19833 pipe.AddShader(&tes);
19834 pipe.AddShader(&fs);
19835
19836 VkDescriptorSetObj descriptorSet(m_device);
19837 descriptorSet.AppendDummy();
19838 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19839
19840 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19841
19842 m_errorMonitor->VerifyNotFound();
19843}
19844
19845TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19846 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19847 "interface block passed into the geometry shader. This "
19848 "is interesting because the 'extra' array level is not "
19849 "present on the member type, but on the block instance.");
19850 m_errorMonitor->ExpectSuccess();
19851
19852 ASSERT_NO_FATAL_FAILURE(InitState());
19853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19854
19855 if (!m_device->phy().features().geometryShader) {
19856 printf("Device does not support geometry shaders; skipped.\n");
19857 return;
19858 }
19859
19860 char const *vsSource = "#version 450\n"
19861 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19862 "void main(){\n"
19863 " vs_out.x = vec4(1);\n"
19864 "}\n";
19865 char const *gsSource = "#version 450\n"
19866 "layout(triangles) in;\n"
19867 "layout(triangle_strip, max_vertices=3) out;\n"
19868 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19869 "out gl_PerVertex { vec4 gl_Position; };\n"
19870 "void main() {\n"
19871 " gl_Position = gs_in[0].x;\n"
19872 " EmitVertex();\n"
19873 "}\n";
19874 char const *fsSource = "#version 450\n"
19875 "layout(location=0) out vec4 color;\n"
19876 "void main(){\n"
19877 " color = vec4(1);\n"
19878 "}\n";
19879
19880 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19881 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19883
19884 VkPipelineObj pipe(m_device);
19885 pipe.AddColorAttachment();
19886 pipe.AddShader(&vs);
19887 pipe.AddShader(&gs);
19888 pipe.AddShader(&fs);
19889
19890 VkDescriptorSetObj descriptorSet(m_device);
19891 descriptorSet.AppendDummy();
19892 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19893
19894 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19895
19896 m_errorMonitor->VerifyNotFound();
19897}
19898
19899TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19900 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19901 "attributes. This is interesting because they consume multiple "
19902 "locations.");
19903 m_errorMonitor->ExpectSuccess();
19904
19905 ASSERT_NO_FATAL_FAILURE(InitState());
19906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19907
19908 if (!m_device->phy().features().shaderFloat64) {
19909 printf("Device does not support 64bit vertex attributes; skipped.\n");
19910 return;
19911 }
19912
19913 VkVertexInputBindingDescription input_bindings[1];
19914 memset(input_bindings, 0, sizeof(input_bindings));
19915
19916 VkVertexInputAttributeDescription input_attribs[4];
19917 memset(input_attribs, 0, sizeof(input_attribs));
19918 input_attribs[0].location = 0;
19919 input_attribs[0].offset = 0;
19920 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19921 input_attribs[1].location = 2;
19922 input_attribs[1].offset = 32;
19923 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19924 input_attribs[2].location = 4;
19925 input_attribs[2].offset = 64;
19926 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19927 input_attribs[3].location = 6;
19928 input_attribs[3].offset = 96;
19929 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19930
19931 char const *vsSource = "#version 450\n"
19932 "\n"
19933 "layout(location=0) in dmat4 x;\n"
19934 "out gl_PerVertex {\n"
19935 " vec4 gl_Position;\n"
19936 "};\n"
19937 "void main(){\n"
19938 " gl_Position = vec4(x[0][0]);\n"
19939 "}\n";
19940 char const *fsSource = "#version 450\n"
19941 "\n"
19942 "layout(location=0) out vec4 color;\n"
19943 "void main(){\n"
19944 " color = vec4(1);\n"
19945 "}\n";
19946
19947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19949
19950 VkPipelineObj pipe(m_device);
19951 pipe.AddColorAttachment();
19952 pipe.AddShader(&vs);
19953 pipe.AddShader(&fs);
19954
19955 pipe.AddVertexInputBindings(input_bindings, 1);
19956 pipe.AddVertexInputAttribs(input_attribs, 4);
19957
19958 VkDescriptorSetObj descriptorSet(m_device);
19959 descriptorSet.AppendDummy();
19960 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19961
19962 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19963
19964 m_errorMonitor->VerifyNotFound();
19965}
19966
19967TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19968 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19969 m_errorMonitor->ExpectSuccess();
19970
19971 ASSERT_NO_FATAL_FAILURE(InitState());
19972
19973 char const *vsSource = "#version 450\n"
19974 "\n"
19975 "out gl_PerVertex {\n"
19976 " vec4 gl_Position;\n"
19977 "};\n"
19978 "void main(){\n"
19979 " gl_Position = vec4(1);\n"
19980 "}\n";
19981 char const *fsSource = "#version 450\n"
19982 "\n"
19983 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19984 "layout(location=0) out vec4 color;\n"
19985 "void main() {\n"
19986 " color = subpassLoad(x);\n"
19987 "}\n";
19988
19989 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19990 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19991
19992 VkPipelineObj pipe(m_device);
19993 pipe.AddShader(&vs);
19994 pipe.AddShader(&fs);
19995 pipe.AddColorAttachment();
19996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19997
19998 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19999 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
20000 VkDescriptorSetLayout dsl;
20001 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20002 ASSERT_VK_SUCCESS(err);
20003
20004 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20005 VkPipelineLayout pl;
20006 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20007 ASSERT_VK_SUCCESS(err);
20008
20009 VkAttachmentDescription descs[2] = {
20010 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20011 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20012 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
20013 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20014 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
20015 };
20016 VkAttachmentReference color = {
20017 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20018 };
20019 VkAttachmentReference input = {
20020 1, VK_IMAGE_LAYOUT_GENERAL,
20021 };
20022
20023 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
20024
20025 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
20026 VkRenderPass rp;
20027 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20028 ASSERT_VK_SUCCESS(err);
20029
20030 // should be OK. would go wrong here if it's going to...
20031 pipe.CreateVKPipeline(pl, rp);
20032
20033 m_errorMonitor->VerifyNotFound();
20034
20035 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20036 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20037 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20038}
20039
20040TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
20041 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
20042 "descriptor-backed resource which is not provided, but the shader does not "
20043 "statically use it. This is interesting because it requires compute pipelines "
20044 "to have a proper descriptor use walk, which they didn't for some time.");
20045 m_errorMonitor->ExpectSuccess();
20046
20047 ASSERT_NO_FATAL_FAILURE(InitState());
20048
20049 char const *csSource = "#version 450\n"
20050 "\n"
20051 "layout(local_size_x=1) in;\n"
20052 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20053 "void main(){\n"
20054 " // x is not used.\n"
20055 "}\n";
20056
20057 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20058
20059 VkDescriptorSetObj descriptorSet(m_device);
20060 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20061
20062 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20063 nullptr,
20064 0,
20065 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20066 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20067 descriptorSet.GetPipelineLayout(),
20068 VK_NULL_HANDLE,
20069 -1 };
20070
20071 VkPipeline pipe;
20072 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20073
20074 m_errorMonitor->VerifyNotFound();
20075
20076 if (err == VK_SUCCESS) {
20077 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20078 }
20079}
20080
20081TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
20082 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20083 "sampler portion of a combined image + sampler");
20084 m_errorMonitor->ExpectSuccess();
20085
20086 ASSERT_NO_FATAL_FAILURE(InitState());
20087
20088 VkDescriptorSetLayoutBinding bindings[] = {
20089 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20090 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20091 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20092 };
20093 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20094 VkDescriptorSetLayout dsl;
20095 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20096 ASSERT_VK_SUCCESS(err);
20097
20098 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20099 VkPipelineLayout pl;
20100 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20101 ASSERT_VK_SUCCESS(err);
20102
20103 char const *csSource = "#version 450\n"
20104 "\n"
20105 "layout(local_size_x=1) in;\n"
20106 "layout(set=0, binding=0) uniform sampler s;\n"
20107 "layout(set=0, binding=1) uniform texture2D t;\n"
20108 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20109 "void main() {\n"
20110 " x = texture(sampler2D(t, s), vec2(0));\n"
20111 "}\n";
20112 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20113
20114 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20115 nullptr,
20116 0,
20117 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20118 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20119 pl,
20120 VK_NULL_HANDLE,
20121 -1 };
20122
20123 VkPipeline pipe;
20124 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20125
20126 m_errorMonitor->VerifyNotFound();
20127
20128 if (err == VK_SUCCESS) {
20129 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20130 }
20131
20132 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20133 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20134}
20135
20136TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20137 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20138 "image portion of a combined image + sampler");
20139 m_errorMonitor->ExpectSuccess();
20140
20141 ASSERT_NO_FATAL_FAILURE(InitState());
20142
20143 VkDescriptorSetLayoutBinding bindings[] = {
20144 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20145 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20146 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20147 };
20148 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20149 VkDescriptorSetLayout dsl;
20150 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20151 ASSERT_VK_SUCCESS(err);
20152
20153 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20154 VkPipelineLayout pl;
20155 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20156 ASSERT_VK_SUCCESS(err);
20157
20158 char const *csSource = "#version 450\n"
20159 "\n"
20160 "layout(local_size_x=1) in;\n"
20161 "layout(set=0, binding=0) uniform texture2D t;\n"
20162 "layout(set=0, binding=1) uniform sampler s;\n"
20163 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20164 "void main() {\n"
20165 " x = texture(sampler2D(t, s), vec2(0));\n"
20166 "}\n";
20167 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20168
20169 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20170 nullptr,
20171 0,
20172 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20173 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20174 pl,
20175 VK_NULL_HANDLE,
20176 -1 };
20177
20178 VkPipeline pipe;
20179 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20180
20181 m_errorMonitor->VerifyNotFound();
20182
20183 if (err == VK_SUCCESS) {
20184 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20185 }
20186
20187 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20188 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20189}
20190
20191TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20192 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20193 "both the sampler and the image of a combined image+sampler "
20194 "but via separate variables");
20195 m_errorMonitor->ExpectSuccess();
20196
20197 ASSERT_NO_FATAL_FAILURE(InitState());
20198
20199 VkDescriptorSetLayoutBinding bindings[] = {
20200 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20201 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20202 };
20203 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20204 VkDescriptorSetLayout dsl;
20205 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20206 ASSERT_VK_SUCCESS(err);
20207
20208 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20209 VkPipelineLayout pl;
20210 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20211 ASSERT_VK_SUCCESS(err);
20212
20213 char const *csSource = "#version 450\n"
20214 "\n"
20215 "layout(local_size_x=1) in;\n"
20216 "layout(set=0, binding=0) uniform texture2D t;\n"
20217 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20218 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20219 "void main() {\n"
20220 " x = texture(sampler2D(t, s), vec2(0));\n"
20221 "}\n";
20222 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20223
20224 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20225 nullptr,
20226 0,
20227 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20228 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20229 pl,
20230 VK_NULL_HANDLE,
20231 -1 };
20232
20233 VkPipeline pipe;
20234 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20235
20236 m_errorMonitor->VerifyNotFound();
20237
20238 if (err == VK_SUCCESS) {
20239 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20240 }
20241
20242 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20243 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20244}
20245
20246TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20247 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20248
20249 ASSERT_NO_FATAL_FAILURE(InitState());
20250
20251 // Positive test to check parameter_validation and unique_objects support
20252 // for NV_dedicated_allocation
20253 uint32_t extension_count = 0;
20254 bool supports_nv_dedicated_allocation = false;
20255 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20256 ASSERT_VK_SUCCESS(err);
20257
20258 if (extension_count > 0) {
20259 std::vector<VkExtensionProperties> available_extensions(extension_count);
20260
20261 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20262 ASSERT_VK_SUCCESS(err);
20263
20264 for (const auto &extension_props : available_extensions) {
20265 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20266 supports_nv_dedicated_allocation = true;
20267 }
20268 }
20269 }
20270
20271 if (supports_nv_dedicated_allocation) {
20272 m_errorMonitor->ExpectSuccess();
20273
20274 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20275 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20276 dedicated_buffer_create_info.pNext = nullptr;
20277 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20278
20279 uint32_t queue_family_index = 0;
20280 VkBufferCreateInfo buffer_create_info = {};
20281 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20282 buffer_create_info.pNext = &dedicated_buffer_create_info;
20283 buffer_create_info.size = 1024;
20284 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20285 buffer_create_info.queueFamilyIndexCount = 1;
20286 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20287
20288 VkBuffer buffer;
20289 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20290 ASSERT_VK_SUCCESS(err);
20291
20292 VkMemoryRequirements memory_reqs;
20293 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20294
20295 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20296 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20297 dedicated_memory_info.pNext = nullptr;
20298 dedicated_memory_info.buffer = buffer;
20299 dedicated_memory_info.image = VK_NULL_HANDLE;
20300
20301 VkMemoryAllocateInfo memory_info = {};
20302 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20303 memory_info.pNext = &dedicated_memory_info;
20304 memory_info.allocationSize = memory_reqs.size;
20305
20306 bool pass;
20307 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20308 ASSERT_TRUE(pass);
20309
20310 VkDeviceMemory buffer_memory;
20311 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20312 ASSERT_VK_SUCCESS(err);
20313
20314 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20315 ASSERT_VK_SUCCESS(err);
20316
20317 vkDestroyBuffer(m_device->device(), buffer, NULL);
20318 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20319
20320 m_errorMonitor->VerifyNotFound();
20321 }
20322}
20323
20324TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20325 VkResult err;
20326
20327 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20328
20329 ASSERT_NO_FATAL_FAILURE(InitState());
20330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20331
20332 std::vector<const char *> device_extension_names;
20333 auto features = m_device->phy().features();
20334 // Artificially disable support for non-solid fill modes
20335 features.fillModeNonSolid = false;
20336 // The sacrificial device object
20337 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20338
20339 VkRenderpassObj render_pass(&test_device);
20340
20341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20343 pipeline_layout_ci.setLayoutCount = 0;
20344 pipeline_layout_ci.pSetLayouts = NULL;
20345
20346 VkPipelineLayout pipeline_layout;
20347 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20348 ASSERT_VK_SUCCESS(err);
20349
20350 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20351 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20352 rs_ci.pNext = nullptr;
20353 rs_ci.lineWidth = 1.0f;
20354 rs_ci.rasterizerDiscardEnable = true;
20355
20356 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20357 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20358
20359 // Set polygonMode=FILL. No error is expected
20360 m_errorMonitor->ExpectSuccess();
20361 {
20362 VkPipelineObj pipe(&test_device);
20363 pipe.AddShader(&vs);
20364 pipe.AddShader(&fs);
20365 pipe.AddColorAttachment();
20366 // Set polygonMode to a good value
20367 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20368 pipe.SetRasterization(&rs_ci);
20369 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20370 }
20371 m_errorMonitor->VerifyNotFound();
20372
20373 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20374}
20375
20376TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20377 VkResult err;
20378 ASSERT_NO_FATAL_FAILURE(InitState());
20379 ASSERT_NO_FATAL_FAILURE(InitViewport());
20380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20381
20382 VkPipelineLayout pipeline_layout;
20383 VkPushConstantRange pc_range = {};
20384 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20385 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20386 pipeline_layout_ci.pushConstantRangeCount = 1;
20387 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20388
20389 //
20390 // Check for invalid push constant ranges in pipeline layouts.
20391 //
20392 struct PipelineLayoutTestCase {
20393 VkPushConstantRange const range;
20394 char const *msg;
20395 };
20396
20397 // Check for overlapping ranges
20398 const uint32_t ranges_per_test = 5;
20399 struct OverlappingRangeTestCase {
20400 VkPushConstantRange const ranges[ranges_per_test];
20401 char const *msg;
20402 };
20403
20404 // Run some positive tests to make sure overlap checking in the layer is OK
20405 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20406 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20407 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20408 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20409 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20410 "" },
20411 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20412 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20413 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20414 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20415 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20416 "" } } };
20417 for (const auto &iter : overlapping_range_tests_pos) {
20418 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20419 m_errorMonitor->ExpectSuccess();
20420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20421 m_errorMonitor->VerifyNotFound();
20422 if (VK_SUCCESS == err) {
20423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20424 }
20425 }
20426
20427 //
20428 // CmdPushConstants tests
20429 //
20430 const uint8_t dummy_values[100] = {};
20431
Tony Barbour552f6c02016-12-21 14:34:07 -070020432 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020433
20434 // positive overlapping range tests with cmd
20435 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20436 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20437 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20438 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20439 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20440 } };
20441
20442 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20443 const VkPushConstantRange pc_range4[] = {
20444 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20445 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20446 };
20447
20448 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20449 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20451 ASSERT_VK_SUCCESS(err);
20452 for (const auto &iter : cmd_overlap_tests_pos) {
20453 m_errorMonitor->ExpectSuccess();
20454 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20455 iter.range.size, dummy_values);
20456 m_errorMonitor->VerifyNotFound();
20457 }
20458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20459
Tony Barbour552f6c02016-12-21 14:34:07 -070020460 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020461}
20462
20463
20464
20465
20466
20467
20468
20469#if 0 // A few devices have issues with this test so disabling for now
20470TEST_F(VkPositiveLayerTest, LongFenceChain)
20471{
20472 m_errorMonitor->ExpectSuccess();
20473
20474 ASSERT_NO_FATAL_FAILURE(InitState());
20475 VkResult err;
20476
20477 std::vector<VkFence> fences;
20478
20479 const int chainLength = 32768;
20480
20481 for (int i = 0; i < chainLength; i++) {
20482 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20483 VkFence fence;
20484 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20485 ASSERT_VK_SUCCESS(err);
20486
20487 fences.push_back(fence);
20488
20489 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20490 0, nullptr, 0, nullptr };
20491 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20492 ASSERT_VK_SUCCESS(err);
20493
20494 }
20495
20496 // BOOM, stack overflow.
20497 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20498
20499 for (auto fence : fences)
20500 vkDestroyFence(m_device->device(), fence, nullptr);
20501
20502 m_errorMonitor->VerifyNotFound();
20503}
20504#endif
20505
20506
Cody Northrop1242dfd2016-07-13 17:24:59 -060020507#if defined(ANDROID) && defined(VALIDATION_APK)
20508static bool initialized = false;
20509static bool active = false;
20510
20511// Convert Intents to argv
20512// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020513std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020514 std::vector<std::string> args;
20515 JavaVM &vm = *app.activity->vm;
20516 JNIEnv *p_env;
20517 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20518 return args;
20519
20520 JNIEnv &env = *p_env;
20521 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020522 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020523 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020524 jmethodID get_string_extra_method =
20525 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020526 jvalue get_string_extra_args;
20527 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020528 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020529
20530 std::string args_str;
20531 if (extra_str) {
20532 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20533 args_str = extra_utf;
20534 env.ReleaseStringUTFChars(extra_str, extra_utf);
20535 env.DeleteLocalRef(extra_str);
20536 }
20537
20538 env.DeleteLocalRef(get_string_extra_args.l);
20539 env.DeleteLocalRef(intent);
20540 vm.DetachCurrentThread();
20541
20542 // split args_str
20543 std::stringstream ss(args_str);
20544 std::string arg;
20545 while (std::getline(ss, arg, ' ')) {
20546 if (!arg.empty())
20547 args.push_back(arg);
20548 }
20549
20550 return args;
20551}
20552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020553static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020555static void processCommand(struct android_app *app, int32_t cmd) {
20556 switch (cmd) {
20557 case APP_CMD_INIT_WINDOW: {
20558 if (app->window) {
20559 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020560 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020561 break;
20562 }
20563 case APP_CMD_GAINED_FOCUS: {
20564 active = true;
20565 break;
20566 }
20567 case APP_CMD_LOST_FOCUS: {
20568 active = false;
20569 break;
20570 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020571 }
20572}
20573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020574void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020575 app_dummy();
20576
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020577 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020578
20579 int vulkanSupport = InitVulkan();
20580 if (vulkanSupport == 0) {
20581 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20582 return;
20583 }
20584
20585 app->onAppCmd = processCommand;
20586 app->onInputEvent = processInput;
20587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020588 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020589 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020590 struct android_poll_source *source;
20591 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020592 if (source) {
20593 source->process(app, source);
20594 }
20595
20596 if (app->destroyRequested != 0) {
20597 VkTestFramework::Finish();
20598 return;
20599 }
20600 }
20601
20602 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020603 // Use the following key to send arguments to gtest, i.e.
20604 // --es args "--gtest_filter=-VkLayerTest.foo"
20605 const char key[] = "args";
20606 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020608 std::string filter = "";
20609 if (args.size() > 0) {
20610 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20611 filter += args[0];
20612 } else {
20613 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20614 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020616 int argc = 2;
20617 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20618 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020620 // Route output to files until we can override the gtest output
20621 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20622 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020624 ::testing::InitGoogleTest(&argc, argv);
20625 VkTestFramework::InitArgs(&argc, argv);
20626 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020627
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020628 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020630 if (result != 0) {
20631 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20632 } else {
20633 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20634 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020636 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020638 fclose(stdout);
20639 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020641 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020643 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020644 }
20645 }
20646}
20647#endif
20648
Tony Barbour300a6082015-04-07 13:44:53 -060020649int main(int argc, char **argv) {
20650 int result;
20651
Cody Northrop8e54a402016-03-08 22:25:52 -070020652#ifdef ANDROID
20653 int vulkanSupport = InitVulkan();
20654 if (vulkanSupport == 0)
20655 return 1;
20656#endif
20657
Tony Barbour300a6082015-04-07 13:44:53 -060020658 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020659 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020660
20661 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20662
20663 result = RUN_ALL_TESTS();
20664
Tony Barbour6918cd52015-04-09 12:58:51 -060020665 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020666 return result;
20667}